[svn:PHP-Sandwich] rev 1043 - PHP-Sandwich/trunk
[email protected] 6 May 2005 18:12:59 -0000
| Newsgroups | perl.php.sandwich.dev |
|---|---|
| Message-ID | <[email protected]> |
Author: gschlossnagle
Date: Fri May 6 11:12:58 2005
New Revision: 1043
Modified:
PHP-Sandwich/trunk/phpfuncs.c
Log:
improved code reuse
Modified: PHP-Sandwich/trunk/phpfuncs.c
==============================================================================
--- PHP-Sandwich/trunk/phpfuncs.c (original)
+++ PHP-Sandwich/trunk/phpfuncs.c Fri May 6 11:12:58 2005
@@ -168,64 +168,7 @@
RETURN_TRUE;
}
-PHP_METHOD(perl, call)
-{
- struct plobj *pl;
- SV *var;
- zval *retval;
- char *name;
- int namelen;
- zval *param;
- zval ***args;
- int argc, i;
- SV *sparam;
- SV *prv;
- pTHX;
- pl = zend_object_store_get_object(getThis() TSRMLS_CC);
- aTHX = pl->perl;
-
- {
- dSP;
-
- argc = ZEND_NUM_ARGS();
- if(argc < 1) {
- WRONG_PARAM_COUNT;
- }
- args = (zval ***) safe_emalloc(sizeof(zval **), argc, 0);
- if(zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
- name = Z_STRVAL_PP(args[0]);
-
- ENTER;
- SAVETMPS;
- PUSHMARK(SP);
- for(i = 1; i < argc; i++) {
- var = sv_2mortal(newSVzval(*args[i], SandwichG(php)));
- XPUSHs(var);
- }
- PUTBACK;
- call_pv(name, G_SCALAR);
- SPAGAIN;
- prv = POPs;
- /*
- if(coe && SvTRUE(ERRSV)) {
- croak(SvPVx(ERRSV, n_a));
- }
- */
- SvREFCNT_inc(prv);
- PUTBACK;
- retval = SvZval(prv);
- RETURN_ZVAL(retval, 1, 0);
- SvREFCNT_dec(prv);
- FREETMPS;
- LEAVE;
- efree(args);
- }
-}
-
-static int sandwich_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS)
+static int _sandwich_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS, int offset)
{
struct plobj *pl;
SV *var;
@@ -257,7 +200,7 @@
ENTER;
SAVETMPS;
PUSHMARK(SP);
- for(i = 0; i < argc; i++) {
+ for(i = offset; i < argc; i++) {
var = newSVzval(*args[i], SandwichG(php));
var = sv_2mortal(var);
XPUSHs(var);
@@ -282,11 +225,28 @@
}
}
+static int sandwich_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS)
+{
+ return _sandwich_call_method(method, INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+}
+
+PHP_METHOD(perl, call)
+{
+ zval **name[1];
+ if(ZEND_NUM_ARGS() < 1) {
+ WRONG_PARAM_COUNT;
+ }
+ if(zend_get_parameters_array_ex(1, name) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ _sandwich_call_method(Z_STRVAL_PP(name[0]), INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+
static PHP_FUNCTION(sandwich_method_handler)
{
- sandwich_call_method(
+ _sandwich_call_method(
((zend_internal_function*)EG(function_state_ptr)->function)->function_name,
- INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
static union _zend_function *sandwich_get_method(zval **object_ptr, char *name, int len TSRMLS_DC)