com php-src: get working mutators/accessors: Zend/zend_object _handlers.c

From: Date: Fri, 24 Oct 2014 13:10:32 +0000
Subject: com php-src: get working mutators/accessors: Zend/zend_object _handlers.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-82496@lists.php.net to get a copy of this message
Commit: e4e561452e706c6ad89df63923b3d88f66028876 Author: krakjoe <joe.watkins@live.co.uk> Fri, 24 Oct 2014 14:10:32 +0100 Parents: f9ec36e6f815e3f17cd53a432f818ec9a2e6dd14 Branches: mutators Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e4e561452e706c6ad89df63923b3d88f66028876 Log: get working mutators/accessors Changed paths: M Zend/zend_object_handlers.c Diff: diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 6b4e8f1..a86a560 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -436,6 +436,7 @@ zval *zend_std_read_property(zval *object, zval *member, int type, void **cache_ zval tmp_member; zval *retval; zend_property_info *property_info; + zend_function *accessor; zobj = Z_OBJ_P(object); @@ -450,6 +451,41 @@ zval *zend_std_read_property(zval *object, zval *member, int type, void **cache_ fprintf(stderr, "Read object #%d property: %s\n", Z_OBJ_HANDLE_P(object), Z_STRVAL_P(member)); #endif + if (EXPECTED((accessor = zend_hash_find_ptr(&Z_OBJCE_P(object)->accessor_table, Z_STR_P(member))))) { + zend_long *guard = zend_get_property_guard(zobj, Z_STR_P(member)); + if (!((*guard) & IN_GET)) { + zend_fcall_info fci; + zend_fcall_info_cache fcc; + + memset(&fci, 0, sizeof(zend_fcall_info)); + memset(&fcc, 0, sizeof(zend_fcall_info_cache)); + + fci.size = sizeof(zend_fcall_info); + fci.object = Z_OBJ_P(object); + fci.retval = rv; + fci.no_separation = 1; + fci.function_table = + &Z_OBJCE_P(object)->accessor_table; + + fcc.initialized = 1; + fcc.function_handler = accessor; + fcc.object = Z_OBJ_P(object); + fcc.calling_scope = EG(scope); + fcc..called_scope = Z_OBJCE_P(object); + + *guard |= IN_GET; /* prevent circular getting */ + + if (zend_call_function(&fci, &fcc TSRMLS_CC) != SUCCESS) { + *guard &= ~IN_GET; + goto exit; + } + + *guard &= ~IN_GET; + + return rv; + } + } + /* make zend_get_property_info silent if we have getter - we may want to use it */ property_info = zend_get_property_info_quick(zobj->ce, Z_STR_P(member), (type == BP_VAR_IS) || (zobj->ce->__get != NULL), cache_slot TSRMLS_CC); @@ -524,7 +560,8 @@ ZEND_API void zend_std_write_property(zval *object, zval *member, zval *value, v zval tmp_member; zval *variable_ptr; zend_property_info *property_info; - + zend_function *mutator = NULL; + zobj = Z_OBJ_P(object); ZVAL_UNDEF(&tmp_member); @@ -533,6 +570,46 @@ ZEND_API void zend_std_write_property(zval *object, zval *member, zval *value, v member = &tmp_member; cache_slot = NULL; } + + if (EXPECTED((mutator = zend_hash_find_ptr(&Z_OBJCE_P(object)->mutator_table, Z_STR_P(member))))) { + zend_long *guard = zend_get_property_guard(zobj, Z_STR_P(member)); + if (!((*guard) & IN_SET)) { + zend_fcall_info fci; + zend_fcall_info_cache fcc; + zval rv; + + memset(&fci, 0, sizeof(zend_fcall_info)); + memset(&fcc, 0, sizeof(zend_fcall_info_cache)); + + fci..size = sizeof(zend_fcall_info); + fci.object = Z_OBJ_P(object); + fci.retval = &rv; + fci.no_separation = 1; + fci.function_table = + &Z_OBJCE_P(object)->accessor_table; + + fcc.initialized = 1; + fcc.function_handler = mutator; + fcc.object = Z_OBJ_P(object); + fcc.calling_scope = EG(scope); + fcc.called_scope = Z_OBJCE_P(object); + + *guard |= IN_SET; /* prevent circular setting */ + + zend_fcall_info_argn(&fci TSRMLS_CC, 1, value); + + if (zend_call_function(&fci, &fcc TSRMLS_CC) != SUCCESS) { + *guard &= ~IN_SET; + goto exit; + } + + zend_fcall_info_args_clear(&fci, 1); + *guard &= ~IN_SET; + + zval_dtor(&rv); + return; + } + } property_info = zend_get_property_info_quick(zobj->ce, Z_STR_P(member), (zobj->ce->__set != NULL), cache_slot TSRMLS_CC);

« previous php.cvs (#82496) next »