Guest User

zend_call_method_multi

a guest
Oct 22nd, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.61 KB | None | 0 0
  1. diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c
  2. index 9301bbd..2716859 100755
  3. --- a/Zend/zend_interfaces.c
  4. +++ b/Zend/zend_interfaces.c
  5. @@ -29,89 +29,98 @@ ZEND_API zend_class_entry *zend_ce_iterator;
  6.  ZEND_API zend_class_entry *zend_ce_arrayaccess;
  7.  ZEND_API zend_class_entry *zend_ce_serializable;
  8.  
  9. +/* {{{ zend_call_method_multi; accepts an arbitrary number of paramters
  10. + Only returns the returned zval if retval_ptr != NULL */
  11. +ZEND_API zval* zend_call_method_multi(zval **object_pp, zend_class_entry *obj_ce, zend_function **fn_proxy, const char *function_name, int function_name_len, zval **retval_ptr_ptr, int param_count, zval **params[] TSRMLS_DC)
  12. +{
  13. +    int result;
  14. +    zend_fcall_info fci;
  15. +    zval z_fname;
  16. +    zval *retval;
  17. +    HashTable *function_table;
  18. +
  19. +    fci.size = sizeof(fci);
  20. +    /*fci.function_table = NULL; will be read form zend_class_entry of object if needed */
  21. +    fci.object_ptr = object_pp ? *object_pp : NULL;
  22. +    fci.function_name = &z_fname;
  23. +    fci.retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &retval;
  24. +    fci.param_count = param_count;
  25. +    fci.params = params;
  26. +    fci.no_separation = 1;
  27. +    fci.symbol_table = NULL;
  28. +
  29. +    if (!fn_proxy && !obj_ce) {
  30. +        /* no interest in caching and no information already present that is
  31. +         * needed later inside zend_call_function. */
  32. +        ZVAL_STRINGL(&z_fname, function_name, function_name_len, 0);
  33. +        fci.function_table = !object_pp ? EG(function_table) : NULL;
  34. +        result = zend_call_function(&fci, NULL TSRMLS_CC);
  35. +    } else {
  36. +        zend_fcall_info_cache fcic;
  37. +
  38. +        fcic.initialized = 1;
  39. +        if (!obj_ce) {
  40. +            obj_ce = object_pp ? Z_OBJCE_PP(object_pp) : NULL;
  41. +        }
  42. +        if (obj_ce) {
  43. +            function_table = &obj_ce->function_table;
  44. +        } else {
  45. +            function_table = EG(function_table);
  46. +        }
  47. +        if (!fn_proxy || !*fn_proxy) {
  48. +            if (zend_hash_find(function_table, function_name, function_name_len+1, (void **) &fcic.function_handler) == FAILURE) {
  49. +                /* error at c-level */
  50. +                zend_error(E_CORE_ERROR, "Couldn't find implementation for method %s%s%s", obj_ce ? obj_ce->name : "", obj_ce ? "::" : "", function_name);
  51. +            }
  52. +            if (fn_proxy) {
  53. +                *fn_proxy = fcic.function_handler;
  54. +            }
  55. +        } else {
  56. +            fcic.function_handler = *fn_proxy;
  57. +        }
  58. +        fcic.calling_scope = obj_ce;
  59. +        if (object_pp) {
  60. +            fcic.called_scope = Z_OBJCE_PP(object_pp);
  61. +        } else if (obj_ce &&
  62. +                   !(EG(called_scope) &&
  63. +                     instanceof_function(EG(called_scope), obj_ce TSRMLS_CC))) {
  64. +            fcic.called_scope = obj_ce;
  65. +        } else {
  66. +            fcic.called_scope = EG(called_scope);
  67. +        }
  68. +        fcic.object_ptr = object_pp ? *object_pp : NULL;
  69. +        result = zend_call_function(&fci, &fcic TSRMLS_CC);
  70. +    }
  71. +    if (result == FAILURE) {
  72. +        /* error at c-level */
  73. +        if (!obj_ce) {
  74. +            obj_ce = object_pp ? Z_OBJCE_PP(object_pp) : NULL;
  75. +        }
  76. +        if (!EG(exception)) {
  77. +            zend_error(E_CORE_ERROR, "Couldn't execute method %s%s%s", obj_ce ? obj_ce->name : "", obj_ce ? "::" : "", function_name);
  78. +        }
  79. +    }
  80. +    if (!retval_ptr_ptr) {
  81. +        if (retval) {
  82. +            zval_ptr_dtor(&retval);
  83. +        }
  84. +        return NULL;
  85. +    }
  86. +    return *retval_ptr_ptr;
  87. +}
  88. +/* }}} */
  89. +
  90.  /* {{{ zend_call_method
  91. +    zend_call_method which supports up to 2 parameters.  For more parameters invoke zend_call_method_multi directly
  92.   Only returns the returned zval if retval_ptr != NULL */
  93.  ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend_function **fn_proxy, const char *function_name, int function_name_len, zval **retval_ptr_ptr, int param_count, zval* arg1, zval* arg2 TSRMLS_DC)
  94.  {
  95. -   int result;
  96. -   zend_fcall_info fci;
  97. -   zval z_fname;
  98. -   zval *retval;
  99. -   HashTable *function_table;
  100. -
  101. -   zval **params[2];
  102. -
  103. -   params[0] = &arg1;
  104. -   params[1] = &arg2;
  105. -
  106. -   fci.size = sizeof(fci);
  107. -   /*fci.function_table = NULL; will be read form zend_class_entry of object if needed */
  108. -   fci.object_ptr = object_pp ? *object_pp : NULL;
  109. -   fci.function_name = &z_fname;
  110. -   fci.retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &retval;
  111. -   fci.param_count = param_count;
  112. -   fci.params = params;
  113. -   fci.no_separation = 1;
  114. -   fci.symbol_table = NULL;
  115. -
  116. -   if (!fn_proxy && !obj_ce) {
  117. -       /* no interest in caching and no information already present that is
  118. -        * needed later inside zend_call_function. */
  119. -       ZVAL_STRINGL(&z_fname, function_name, function_name_len, 0);
  120. -       fci.function_table = !object_pp ? EG(function_table) : NULL;
  121. -       result = zend_call_function(&fci, NULL TSRMLS_CC);
  122. -   } else {
  123. -       zend_fcall_info_cache fcic;
  124. +    zval **args[2];
  125.  
  126. -       fcic.initialized = 1;
  127. -       if (!obj_ce) {
  128. -           obj_ce = object_pp ? Z_OBJCE_PP(object_pp) : NULL;
  129. -       }
  130. -       if (obj_ce) {
  131. -           function_table = &obj_ce->function_table;
  132. -       } else {
  133. -           function_table = EG(function_table);
  134. -       }
  135. -       if (!fn_proxy || !*fn_proxy) {
  136. -           if (zend_hash_find(function_table, function_name, function_name_len+1, (void **) &fcic.function_handler) == FAILURE) {
  137. -               /* error at c-level */
  138. -               zend_error(E_CORE_ERROR, "Couldn't find implementation for method %s%s%s", obj_ce ? obj_ce->name : "", obj_ce ? "::" : "", function_name);
  139. -           }
  140. -           if (fn_proxy) {
  141. -               *fn_proxy = fcic.function_handler;
  142. -           }
  143. -       } else {
  144. -           fcic.function_handler = *fn_proxy;
  145. -       }
  146. -       fcic.calling_scope = obj_ce;
  147. -       if (object_pp) {
  148. -           fcic.called_scope = Z_OBJCE_PP(object_pp);
  149. -       } else if (obj_ce &&
  150. -                  !(EG(called_scope) &&
  151. -                    instanceof_function(EG(called_scope), obj_ce TSRMLS_CC))) {
  152. -           fcic.called_scope = obj_ce;
  153. -       } else {
  154. -           fcic.called_scope = EG(called_scope);
  155. -       }
  156. -       fcic.object_ptr = object_pp ? *object_pp : NULL;
  157. -       result = zend_call_function(&fci, &fcic TSRMLS_CC);
  158. -   }
  159. -   if (result == FAILURE) {
  160. -       /* error at c-level */
  161. -       if (!obj_ce) {
  162. -           obj_ce = object_pp ? Z_OBJCE_PP(object_pp) : NULL;
  163. -       }
  164. -       if (!EG(exception)) {
  165. -           zend_error(E_CORE_ERROR, "Couldn't execute method %s%s%s", obj_ce ? obj_ce->name : "", obj_ce ? "::" : "", function_name);
  166. -       }
  167. -   }
  168. -   if (!retval_ptr_ptr) {
  169. -       if (retval) {
  170. -           zval_ptr_dtor(&retval);
  171. -       }
  172. -       return NULL;
  173. -   }
  174. -   return *retval_ptr_ptr;
  175. +    args[0] = &arg1;
  176. +    args[1] = &arg2;
  177. +
  178. +    return zend_call_method_multi(object_pp, obj_ce, fn_proxy, function_name, function_name_len, retval_ptr_ptr, param_count, args TSRMLS_CC);
  179.  }
  180.  /* }}} */
  181.  
Advertisement
Add Comment
Please, Sign In to add comment