X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=blobdiff_plain;f=src%2Fphp_pq_object.c;h=f362060804fae79602242d9d90b2fbdd74832bda;hp=78db20f2c56d04be1f55d08a3ac1c73965ef197e;hb=da7b5981c5ae28504434c492d468913645111d66;hpb=9f5cecf26bd70a92ed013f31afec59e272623ac1 diff --git a/src/php_pq_object.c b/src/php_pq_object.c index 78db20f..f362060 100644 --- a/src/php_pq_object.c +++ b/src/php_pq_object.c @@ -58,35 +58,56 @@ void php_pq_object_delref(void *o TSRMLS_DC) zend_objects_store_del_ref_by_handle_ex(obj->zv.handle, obj->zv.handlers TSRMLS_CC); } -static int apply_pi_to_ht(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key) +struct apply_pi_to_ht_arg { + HashTable *ht; + zval *object; + php_pq_object_t *pq_obj; + unsigned addref:1; +}; + +static int apply_pi_to_ht(void *p, void *a TSRMLS_DC) { zend_property_info *pi = p; - HashTable *ht = va_arg(argv, HashTable *); - zval *object = va_arg(argv, zval *); - php_pq_object_t *obj = va_arg(argv, php_pq_object_t *); - int addref = va_arg(argv, int); - zval *property = zend_read_property(obj->zo.ce, object, pi->name, pi->name_length, 0 TSRMLS_CC); + struct apply_pi_to_ht_arg *arg = a; + zval *property = zend_read_property(arg->pq_obj->zo.ce, arg->object, pi->name, pi->name_length, 0 TSRMLS_CC); - if (addref) { + if (arg->addref) { Z_ADDREF_P(property); } - zend_hash_add(ht, pi->name, pi->name_length + 1, (void *) &property, sizeof(zval *), NULL); + zend_hash_update(arg->ht, pi->name, pi->name_length + 1, (void *) &property, sizeof(zval *), NULL); return ZEND_HASH_APPLY_KEEP; } HashTable *php_pq_object_debug_info(zval *object, int *temp TSRMLS_DC) { - HashTable *ht; - php_pq_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); + struct apply_pi_to_ht_arg arg = {NULL}; *temp = 1; - ALLOC_HASHTABLE(ht); - ZEND_INIT_SYMTABLE(ht); + ALLOC_HASHTABLE(arg.ht); + ZEND_INIT_SYMTABLE(arg.ht); + + arg.object = object; + arg.pq_obj = zend_object_store_get_object(object TSRMLS_CC); + arg.addref = 1; - zend_hash_apply_with_arguments(&obj->zo.ce->properties_info TSRMLS_CC, apply_pi_to_ht, 4, ht, object, obj, 1); + zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg TSRMLS_CC); - return ht; + return arg.ht; +} + +HashTable *php_pq_object_properties(zval *object TSRMLS_DC) +{ + struct apply_pi_to_ht_arg arg = {NULL}; + + arg.ht = zend_get_std_object_handlers()->get_properties(object TSRMLS_CC); + arg.object = object; + arg.pq_obj = zend_object_store_get_object(object TSRMLS_CC); + arg.addref = 1; + + zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg TSRMLS_CC); + + return arg.ht; } zend_class_entry *ancestor(zend_class_entry *ce) @@ -101,23 +122,22 @@ zval *php_pq_object_read_prop(zval *object, zval *member, int type, const zend_l { php_pq_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); php_pq_object_prophandler_t *handler; - zval *return_value; + zval *return_value = NULL; if (!obj->intern) { - zend_error(E_WARNING, "%s not initialized", ancestor(obj->zo.ce)->name); - } else if ((SUCCESS == zend_hash_find(obj->prophandler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void *) &handler)) && handler->read) { - if (type == BP_VAR_R) { - ALLOC_ZVAL(return_value); - Z_SET_REFCOUNT_P(return_value, 0); - Z_UNSET_ISREF_P(return_value); - - handler->read(object, obj, return_value TSRMLS_CC); - } else { - zend_error(E_ERROR, "Cannot access %s properties by reference or array key/index", ancestor(obj->zo.ce)->name); - return_value = NULL; - } - } else { + php_error(E_RECOVERABLE_ERROR, "%s not initialized", ancestor(obj->zo.ce)->name); + return_value = zend_get_std_object_handlers()->read_property(object, member, type, key TSRMLS_CC); + } else if ((SUCCESS != zend_hash_find(obj->prophandler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void *) &handler)) || !handler->read) { + return_value = zend_get_std_object_handlers()->read_property(object, member, type, key TSRMLS_CC); + } else if (type != BP_VAR_R) { + php_error(E_WARNING, "Cannot access %s properties by reference or array key/index", ancestor(obj->zo.ce)->name); return_value = zend_get_std_object_handlers()->read_property(object, member, type, key TSRMLS_CC); + } else { + ALLOC_ZVAL(return_value); + Z_SET_REFCOUNT_P(return_value, 0); + Z_UNSET_ISREF_P(return_value); + + handler->read(object, obj, return_value TSRMLS_CC); } return return_value; @@ -128,7 +148,10 @@ void php_pq_object_write_prop(zval *object, zval *member, zval *value, const zen php_pq_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); php_pq_object_prophandler_t *handler; - if (SUCCESS == zend_hash_find(obj->prophandler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void *) &handler)) { + if (!obj->intern) { + php_error(E_RECOVERABLE_ERROR, "%s not initialized", ancestor(obj->zo.ce)->name); + zend_get_std_object_handlers()->write_property(object, member, value, key TSRMLS_CC); + } else if (SUCCESS == zend_hash_find(obj->prophandler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void *) &handler)) { if (handler->write) { handler->write(object, obj, value TSRMLS_CC); }