flush
[m6w6/ext-pq] / src / php_pq_object.c
index 78db20f2c56d04be1f55d08a3ac1c73965ef197e..bfab4101402fb98bdd50bd7aadeb0804ddf94dea 100644 (file)
 
 #include "php_pq_object.h"
 
-void php_pq_object_to_zval(void *o, zval **zv TSRMLS_DC)
+void php_pq_object_to_zval(void *o, zval *zv)
 {
        php_pq_object_t *obj = o;
 
-       if (!*zv) {
-               MAKE_STD_ZVAL(*zv);
-       }
-
-       zend_objects_store_add_ref_by_handle(obj->zv.handle TSRMLS_CC);
-
-       (*zv)->type = IS_OBJECT;
-       (*zv)->value.obj = obj->zv;
+       ZVAL_OBJ(zv, &obj->zo);
+       Z_ADDREF_P(zv);
 }
 
-void php_pq_object_to_zval_no_addref(void *o, zval **zv TSRMLS_DC)
+void php_pq_object_to_zval_no_addref(void *o, zval *zv)
 {
        php_pq_object_t *obj = o;
 
-       if (!*zv) {
-               MAKE_STD_ZVAL(*zv);
-       }
-
-       /* no add ref */
-
-       (*zv)->type = IS_OBJECT;
-       (*zv)->value.obj = obj->zv;
+       ZVAL_OBJ(zv, &obj->zo);
 }
 
-void php_pq_object_addref(void *o TSRMLS_DC)
+void php_pq_object_addref(void *o)
 {
        php_pq_object_t *obj = o;
-       zend_objects_store_add_ref_by_handle(obj->zv.handle TSRMLS_CC);
+       ++GC_REFCOUNT(&obj->zo);
 }
 
 void php_pq_object_delref(void *o TSRMLS_DC)
 {
        php_pq_object_t *obj = o;
-       zend_objects_store_del_ref_by_handle_ex(obj->zv.handle, obj->zv.handlers TSRMLS_CC);
+       zend_objects_store_del(&obj->zo);
 }
 
-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(zval *p, void *a)
 {
-       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);
-
-       if (addref) {
-               Z_ADDREF_P(property);
+       zend_property_info *pi = Z_PTR_P(p);
+       struct apply_pi_to_ht_arg *arg = a;
+       zval tmp_prop, *property = zend_read_property(arg->pq_obj->zo.ce, arg->object, pi->name->val, pi->name->len, 0, &tmp_prop);
+
+       if (arg->addref) {
+               Z_TRY_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, property);
 
        return ZEND_HASH_APPLY_KEEP;
 }
 
-HashTable *php_pq_object_debug_info(zval *object, int *temp TSRMLS_DC)
+HashTable *php_pq_object_debug_info(zval *object, int *temp)
 {
-       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);
 
-       zend_hash_apply_with_arguments(&obj->zo.ce->properties_info TSRMLS_CC, apply_pi_to_ht, 4, ht, object, obj, 1);
+       arg.object = object;
+       arg.pq_obj = PHP_PQ_OBJ(object, NULL);
+       arg.addref = 1;
 
-       return ht;
+       zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg);
+
+       return arg.ht;
+}
+
+HashTable *php_pq_object_properties(zval *object)
+{
+       struct apply_pi_to_ht_arg arg = {NULL};
+
+       arg.ht = zend_get_std_object_handlers()->get_properties(object);
+       arg.object = object;
+       arg.pq_obj = PHP_PQ_OBJ(object, NULL);
+       arg.addref = 1;
+
+       zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg);
+
+       return arg.ht;
 }
 
 zend_class_entry *ancestor(zend_class_entry *ce)
@@ -97,43 +105,42 @@ zend_class_entry *ancestor(zend_class_entry *ce)
        return ce;
 }
 
-zval *php_pq_object_read_prop(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC)
+zval *php_pq_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
 {
-       php_pq_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
+       php_pq_object_t *obj = PHP_PQ_OBJ(object, NULL);
        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;
-               }
+               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, cache_slot, tmp);
+       } else if (!(handler= zend_hash_find_ptr(obj->prophandler, Z_STR_P(member))) || !handler->read) {
+               return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
+       } 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->val);
+               return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
        } else {
-               return_value = zend_get_std_object_handlers()->read_property(object, member, type, key TSRMLS_CC);
+               return_value = tmp;
+               handler->read(object, obj, return_value);
        }
 
        return return_value;
 }
 
-void php_pq_object_write_prop(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC)
+void php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot)
 {
-       php_pq_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
+       php_pq_object_t *obj = PHP_PQ_OBJ(object, NULL);
        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->val);
+               zend_get_std_object_handlers()->write_property(object, member, value, cache_slot);
+       } else if ((handler = zend_hash_find_ptr(obj->prophandler, Z_STR_P(member)))) {
                if (handler->write) {
-                       handler->write(object, obj, value TSRMLS_CC);
+                       handler->write(object, obj, value);
                }
        } else {
-               zend_get_std_object_handlers()->write_property(object, member, value, key TSRMLS_CC);
+               zend_get_std_object_handlers()->write_property(object, member, value, cache_slot);
        }
 }