Permalink
Browse files

MFH: Handlerify get_closure

  • Loading branch information...
colder committed Aug 14, 2008
1 parent 99d3c31 commit f90255c66b8d276d86e61a5d467371fa5ea6c926
Showing with 83 additions and 58 deletions.
  1. +1 −1 Zend/zend_API.c
  2. +33 −51 Zend/zend_closures.c
  3. +36 −1 Zend/zend_object_handlers.c
  4. +3 −0 Zend/zend_object_handlers.h
  5. +2 −1 Zend/zend_vm_def.h
  6. +8 −4 Zend/zend_vm_execute.h
View
@@ -2719,7 +2719,7 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval **object_pp, uint ch
return 0;
case IS_OBJECT:
- if (zend_get_closure(callable, &fcc->calling_scope, &fcc->function_handler, NULL, &fcc->object_pp TSRMLS_CC) == SUCCESS) {
+ if (Z_OBJ_HANDLER_P(callable, get_closure) && Z_OBJ_HANDLER_P(callable, get_closure)(callable, &fcc->calling_scope, &fcc->function_handler, NULL, &fcc->object_pp TSRMLS_CC) == SUCCESS) {
fcc->called_scope = fcc->calling_scope;
if (callable_name) {
zend_class_entry *ce = Z_OBJCE_P(callable); /* TBFixed: what if it's overloaded? */
View
@@ -208,6 +208,38 @@ static zend_object_value zend_closure_new(zend_class_entry *class_type TSRMLS_DC
}
/* }}} */
+int zend_closure_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr, zval ***zobj_ptr_ptr TSRMLS_DC) /* {{{ */
+{
+ zend_closure *closure;
+
+ if (Z_TYPE_P(obj) != IS_OBJECT) {
+ return FAILURE;
+ }
+
+ closure = (zend_closure *)zend_object_store_get_object(obj TSRMLS_CC);
+ *fptr_ptr = &closure->func;
+
+ if (closure->this_ptr) {
+ if (zobj_ptr) {
+ *zobj_ptr = closure->this_ptr;
+ }
+ if (zobj_ptr_ptr) {
+ *zobj_ptr_ptr = &closure->this_ptr;
+ }
+ *ce_ptr = Z_OBJCE_P(closure->this_ptr);
+ } else {
+ if (zobj_ptr) {
+ *zobj_ptr = NULL;
+ }
+ if (zobj_ptr_ptr) {
+ *zobj_ptr_ptr = NULL;
+ }
+ *ce_ptr = closure->func.common.scope;
+ }
+ return SUCCESS;
+}
+/* }}} */
+
void zend_register_closure_ce(TSRMLS_D) /* {{{ */
{
zend_class_entry ce;
@@ -229,6 +261,7 @@ void zend_register_closure_ce(TSRMLS_D) /* {{{ */
closure_handlers.unset_property = zend_closure_unset_property;
closure_handlers.compare_objects = zend_closure_compare_objects;
closure_handlers.clone_obj = NULL;
+ closure_handlers.get_closure = zend_closure_get_closure;
}
/* }}} */
@@ -306,57 +339,6 @@ ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_ent
}
/* }}} */
-ZEND_API int zend_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr, zval ***zobj_ptr_ptr TSRMLS_DC) /* {{{ */
-{
- if (Z_TYPE_P(obj) == IS_OBJECT) {
- zend_class_entry *ce = Z_OBJCE_P(obj);
-
- if (ce == zend_ce_closure) {
- zend_closure *closure = (zend_closure *)zend_object_store_get_object(obj TSRMLS_CC);
-
- *fptr_ptr = &closure->func;
- if (closure->this_ptr) {
- if (zobj_ptr) {
- *zobj_ptr = closure->this_ptr;
- }
- if (zobj_ptr_ptr) {
- *zobj_ptr_ptr = &closure->this_ptr;
- }
- *ce_ptr = Z_OBJCE_P(closure->this_ptr);
- } else {
- if (zobj_ptr) {
- *zobj_ptr = NULL;
- }
- if (zobj_ptr_ptr) {
- *zobj_ptr_ptr = NULL;
- }
- *ce_ptr = closure->func.common.scope;
- }
- return SUCCESS;
- } else if (zend_hash_find(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME), (void**)fptr_ptr) == SUCCESS) {
- *ce_ptr = ce;
- if ((*fptr_ptr)->common.fn_flags & ZEND_ACC_STATIC) {
- if (zobj_ptr) {
- *zobj_ptr = NULL;
- }
- if (zobj_ptr_ptr) {
- *zobj_ptr_ptr = NULL;
- }
- } else {
- if (zobj_ptr) {
- *zobj_ptr = obj;
- }
- if (zobj_ptr_ptr) {
- *zobj_ptr_ptr = NULL;
- }
- }
- return SUCCESS;
- }
- }
- return FAILURE;
-}
-/* }}} */
-
/*
* Local variables:
* tab-width: 4
@@ -27,6 +27,7 @@
#include "zend_objects_API.h"
#include "zend_object_handlers.h"
#include "zend_interfaces.h"
+#include "zend_closures.h"
#define DEBUG_OBJECT_HANDLERS 0
@@ -1261,6 +1262,39 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty
}
/* }}} */
+int zend_std_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr, zval ***zobj_ptr_ptr TSRMLS_DC) /* {{{ */
+{
+ zend_class_entry *ce;
+ if (Z_TYPE_P(obj) != IS_OBJECT) {
+ return FAILURE;
+ }
+
+ ce = Z_OBJCE_P(obj);
+
+ if (zend_hash_find(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME), (void**)fptr_ptr) == FAILURE) {
+ return FAILURE;
+ }
+
+ *ce_ptr = ce;
+ if ((*fptr_ptr)->common.fn_flags & ZEND_ACC_STATIC) {
+ if (zobj_ptr) {
+ *zobj_ptr = NULL;
+ }
+ if (zobj_ptr_ptr) {
+ *zobj_ptr_ptr = NULL;
+ }
+ } else {
+ if (zobj_ptr) {
+ *zobj_ptr = obj;
+ }
+ if (zobj_ptr_ptr) {
+ *zobj_ptr_ptr = NULL;
+ }
+ }
+ return SUCCESS;
+}
+/* }}} */
+
ZEND_API zend_object_handlers std_object_handlers = {
zend_objects_store_add_ref, /* add_ref */
zend_objects_store_del_ref, /* del_ref */
@@ -1286,7 +1320,8 @@ ZEND_API zend_object_handlers std_object_handlers = {
zend_std_compare_objects, /* compare_objects */
zend_std_cast_object_tostring, /* cast_object */
NULL, /* count_elements */
- NULL, /* get_debug_info */
+ NULL, /* get_debug_info */
+ zend_std_get_closure, /* get_closure */
};
/*
@@ -108,6 +108,8 @@ typedef int (*zend_object_cast_t)(zval *readobj, zval *retval, int type TSRMLS_D
* Returns FAILURE if the object does not have any sense of overloaded dimensions */
typedef int (*zend_object_count_elements_t)(zval *object, long *count TSRMLS_DC);
+typedef int (*zend_object_get_closure_t)(zval *obj, zend_class_entry **ce_ptr, union _zend_function **fptr_ptr, zval **zobj_ptr, zval ***zobj_ptr_ptr TSRMLS_DC);
+
struct _zend_object_handlers {
/* general object functions */
zend_object_add_ref_t add_ref;
@@ -135,6 +137,7 @@ struct _zend_object_handlers {
zend_object_cast_t cast_object;
zend_object_count_elements_t count_elements;
zend_object_get_debug_info_t get_debug_info;
+ zend_object_get_closure_t get_closure;
};
extern ZEND_API zend_object_handlers std_object_handlers;
View
@@ -2073,7 +2073,8 @@ ZEND_VM_HANDLER(59, ZEND_INIT_FCALL_BY_NAME, ANY, CONST|TMP|VAR|CV)
function_name = GET_OP2_ZVAL_PTR(BP_VAR_R);
if (Z_TYPE_P(function_name) == IS_OBJECT &&
- zend_get_closure(function_name, &EX(called_scope), &EX(fbc), &EX(object), NULL TSRMLS_CC) == SUCCESS) {
+ Z_OBJ_HANDLER_P(function_name, get_closure) &&
+ Z_OBJ_HANDLER_P(function_name, get_closure)(function_name, &EX(called_scope), &EX(fbc), &EX(object), NULL TSRMLS_CC) == SUCCESS) {
if (EX(object)) {
Z_ADDREF_P(EX(object));
}
View
@@ -754,7 +754,8 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_CONST_HANDLER(ZEND_OPCODE
function_name = &opline->op2.u.constant;
if (Z_TYPE_P(function_name) == IS_OBJECT &&
- zend_get_closure(function_name, &EX(called_scope), &EX(fbc), &EX(object), NULL TSRMLS_CC) == SUCCESS) {
+ Z_OBJ_HANDLER_P(function_name, get_closure) &&
+ Z_OBJ_HANDLER_P(function_name, get_closure)(function_name, &EX(called_scope), &EX(fbc), &EX(object), NULL TSRMLS_CC) == SUCCESS) {
if (EX(object)) {
Z_ADDREF_P(EX(object));
}
@@ -951,7 +952,8 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_TMP_HANDLER(ZEND_OPCODE_H
function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC);
if (Z_TYPE_P(function_name) == IS_OBJECT &&
- zend_get_closure(function_name, &EX(called_scope), &EX(fbc), &EX(object), NULL TSRMLS_CC) == SUCCESS) {
+ Z_OBJ_HANDLER_P(function_name, get_closure) &&
+ Z_OBJ_HANDLER_P(function_name, get_closure)(function_name, &EX(called_scope), &EX(fbc), &EX(object), NULL TSRMLS_CC) == SUCCESS) {
if (EX(object)) {
Z_ADDREF_P(EX(object));
}
@@ -1056,7 +1058,8 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_VAR_HANDLER(ZEND_OPCODE_H
function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC);
if (Z_TYPE_P(function_name) == IS_OBJECT &&
- zend_get_closure(function_name, &EX(called_scope), &EX(fbc), &EX(object), NULL TSRMLS_CC) == SUCCESS) {
+ Z_OBJ_HANDLER_P(function_name, get_closure) &&
+ Z_OBJ_HANDLER_P(function_name, get_closure)(function_name, &EX(called_scope), &EX(fbc), &EX(object), NULL TSRMLS_CC) == SUCCESS) {
if (EX(object)) {
Z_ADDREF_P(EX(object));
}
@@ -1189,7 +1192,8 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_CV_HANDLER(ZEND_OPCODE_HA
function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC);
if (Z_TYPE_P(function_name) == IS_OBJECT &&
- zend_get_closure(function_name, &EX(called_scope), &EX(fbc), &EX(object), NULL TSRMLS_CC) == SUCCESS) {
+ Z_OBJ_HANDLER_P(function_name, get_closure) &&
+ Z_OBJ_HANDLER_P(function_name, get_closure)(function_name, &EX(called_scope), &EX(fbc), &EX(object), NULL TSRMLS_CC) == SUCCESS) {
if (EX(object)) {
Z_ADDREF_P(EX(object));
}

0 comments on commit f90255c

Please sign in to comment.