#include "php_propro_api.h"
-#if PHP_VERSION_ID < 50500
-#undef SUCCESS
-#undef FAILURE
-typedef enum {
- SUCCESS = 0,
- FAILURE = -1
-} ZEND_RESULT_CODE;
-#endif
-
#define DEBUG_PROPRO 0
-#if PHP_VERSION_ID < 50400
-# define object_properties_init(o, ce) \
- zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), \
- (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*))
+static inline php_property_proxy_object_t *get_propro(zval *object);
+static inline zval *get_proxied_value(zval *object, zval *return_value);
+static inline void set_proxied_value(zval *object, zval *value);
+
+static zval *read_dimension(zval *object, zval *offset, int type, zval *return_value);
+static ZEND_RESULT_CODE cast_obj(zval *object, zval *return_value, int type);
+static void write_dimension(zval *object, zval *offset, zval *input_value);
+
+#if DEBUG_PROPRO
+/* we do not really care about TS when debugging */
+static int level = 1;
+static const char *inoutstr[] = {"< return","= "," > enter "};
+static const char *types[] = {
+ "UNDEF",
+ "NULL",
+ "FALSE",
+ "TRUE",
+ "int",
+ "float",
+ "string",
+ "Array",
+ "Object",
+ "resource",
+ "reference",
+ "constant",
+ "constant AST",
+ "_BOOL",
+ "callable",
+ "indirect",
+ "---",
+ "pointer"
+};
+
+static int _walk(php_property_proxy_object_t *obj)
+{
+ int p = 0;
+
+ if (obj) {
+ if (!Z_ISUNDEF(obj->parent)) {
+ p += _walk(get_propro(&obj->parent));
+ }
+ if (obj->proxy) {
+ p += fprintf(stderr, ".%s", obj->proxy->member->val);
+ }
+ }
+
+ return p;
+}
+
+static void debug_propro(int inout, const char *f,
+ php_property_proxy_object_t *obj,
+ php_property_proxy_t *proxy,
+ zval *offset, zval *value)
+{
+ int width;
+
+ if (!proxy && obj) {
+ proxy = obj->proxy;
+ }
+
+ fprintf(stderr, "#PP %14p %*c %s %s\t", proxy, level, ' ', inoutstr[inout + 1], f);
+
+ level += inout;
+
+ if (proxy) {
+ fprintf(stderr, " container= %-10p <%12s rc=%d ",
+ Z_REFCOUNTED(proxy->container) ? Z_COUNTED(proxy->container) : NULL,
+ types[Z_TYPE(proxy->container)],
+ Z_REFCOUNTED(proxy->container) ? Z_REFCOUNT(proxy->container) : 0);
+ if (Z_ISREF(proxy->container)) {
+ zval *ref = Z_REFVAL(proxy->container);
+ fprintf(stderr, " %-12s %p rc=% 2d",
+ types[Z_TYPE_P(ref)],
+ ref->value.counted,
+ Z_REFCOUNTED_P(ref) ? Z_REFCOUNT_P(ref) : -1);
+ }
+ fprintf(stderr, "> ");
+ }
+
+ width = _walk(obj);
+
+ if (*f++=='d'
+ && *f++=='i'
+ && *f++=='m'
+ ) {
+ char *offset_str = "[]";
+ zval *o = offset;
+
+ if (o) {
+ convert_to_string_ex(o);
+ offset_str = Z_STRVAL_P(o);
+ }
+
+ width += fprintf(stderr, ".%s", offset_str);
+
+ if (o && o != offset) {
+ zval_ptr_dtor(o);
+ }
+ }
+ if (value) {
+ fprintf(stderr, "%.*s", 32-width, " ");
+ if (Z_ISUNDEF_P(value)) {
+ fprintf(stderr, " =UNDEF ");
+ } else {
+ fprintf(stderr, " = %-10p <%12s rc=%d %3s> ",
+ Z_REFCOUNTED_P(value) ? Z_COUNTED_P(value) : NULL,
+ types[Z_TYPE_P(value)&0xf],
+ Z_REFCOUNTED_P(value) ? Z_REFCOUNT_P(value) : 0,
+ Z_ISREF_P(value) ? "ref" : "");
+ if (!Z_ISUNDEF_P(value) && Z_TYPE_P(value) != IS_INDIRECT) {
+ zend_print_flat_zval_r(value TSRMLS_CC);
+ }
+ }
+ }
+
+ fprintf(stderr, "\n");
+}
+#else
+#define debug_propro(l, f, obj, proxy, off, val)
#endif
-php_property_proxy_t *php_property_proxy_init(zval *container,
- const char *member_str, size_t member_len TSRMLS_DC)
+php_property_proxy_t *php_property_proxy_init(zval *container, zend_string *member)
{
php_property_proxy_t *proxy = ecalloc(1, sizeof(*proxy));
+#if DEBUG_PROPRO
+ zval offset;
+
+ ZVAL_STR_COPY(&offset, member);
+#endif
+
+ debug_propro(1, "init", NULL, proxy, &offset, NULL);
+
+ ZVAL_COPY(&proxy->container, container);
+ proxy->member = zend_string_copy(member);
- Z_ADDREF_P(container);
- proxy->container = container;
- proxy->member_str = estrndup(member_str, member_len);
- proxy->member_len = member_len;
+ debug_propro(-1, "init", NULL, proxy, &offset, NULL);
+
+#if DEBUG_PROPRO
+ zval_dtor(&offset);
+#endif
return proxy;
}
void php_property_proxy_free(php_property_proxy_t **proxy)
{
+#if DEBUG_PROPRO
+ zval offset;
+
+ ZVAL_STR_COPY(&offset, (*proxy)->member);
+ debug_propro(1, "dtor", NULL, *proxy, &offset, NULL);
+#endif
+
if (*proxy) {
zval_ptr_dtor(&(*proxy)->container);
- efree((*proxy)->member_str);
+
+ ZVAL_UNDEF(&(*proxy)->container);
+ zend_string_release((*proxy)->member);
+ (*proxy)->member = NULL;
efree(*proxy);
*proxy = NULL;
}
+
+#if DEBUG_PROPRO
+ debug_propro(-1, "dtor", NULL, NULL, &offset, NULL);
+
+ zval_dtor(&offset);
+#endif
}
static zend_class_entry *php_property_proxy_class_entry;
return php_property_proxy_class_entry;
}
-zend_object_value php_property_proxy_object_new(zend_class_entry *ce TSRMLS_DC)
+php_property_proxy_object_t *php_property_proxy_object_new_ex(
+ zend_class_entry *ce, php_property_proxy_t *proxy)
{
- return php_property_proxy_object_new_ex(ce, NULL, NULL TSRMLS_CC);
+ php_property_proxy_object_t *o;
+
+ if (!ce) {
+ ce = php_property_proxy_class_entry;
+ }
+
+ o = ecalloc(1, sizeof(*o) + sizeof(zval) * (ce->default_properties_count - 1));
+ zend_object_std_init(&o->zo, ce);
+ object_properties_init(&o->zo, ce);
+
+ o->proxy = proxy;
+ o->zo.handlers = &php_property_proxy_object_handlers;
+
+ return o;
}
-static void php_property_proxy_object_free(void *object TSRMLS_DC)
+zend_object *php_property_proxy_object_new(zend_class_entry *ce)
{
- php_property_proxy_object_t *o = object;
+ return &php_property_proxy_object_new_ex(ce, NULL)->zo;
+}
-#if DEBUG_PROPRO
- fprintf(stderr, "#PP %p free\n", o);
-#endif
+static void destroy_obj(zend_object *object)
+{
+ php_property_proxy_object_t *o = PHP_PROPRO_PTR(object);
if (o->proxy) {
php_property_proxy_free(&o->proxy);
}
- if (o->parent) {
- zend_objects_store_del_ref_by_handle_ex(o->parent->zv.handle,
- o->parent->zv.handlers TSRMLS_CC);
- o->parent = NULL;
+ if (!Z_ISUNDEF(o->parent)) {
+ zval_ptr_dtor(&o->parent);
+ ZVAL_UNDEF(&o->parent);
}
- zend_object_std_dtor((zend_object *) o TSRMLS_CC);
- efree(o);
+ zend_object_std_dtor(object);
}
-zend_object_value php_property_proxy_object_new_ex(zend_class_entry *ce,
- php_property_proxy_t *proxy, php_property_proxy_object_t **ptr TSRMLS_DC)
+static ZEND_RESULT_CODE cast_obj(zval *object, zval *return_value, int type)
{
- php_property_proxy_object_t *o;
+ zval tmp;
- o = ecalloc(1, sizeof(*o));
- zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
- object_properties_init((zend_object *) o, ce);
+ ZVAL_UNDEF(&tmp);
+ RETVAL_ZVAL(get_proxied_value(object, &tmp), 1, 0);
- if (ptr) {
- *ptr = o;
+ debug_propro(0, "cast", get_propro(object), NULL, NULL, return_value);
+
+ if (!Z_ISUNDEF_P(return_value)) {
+ ZVAL_DEREF(return_value);
+ convert_to_explicit_type_ex(return_value, type);
+ return SUCCESS;
}
- o->proxy = proxy;
- o->zv.handle = zend_objects_store_put(o, NULL,
- php_property_proxy_object_free, NULL TSRMLS_CC);
- o->zv.handlers = &php_property_proxy_object_handlers;
+ return FAILURE;
+}
-#if DEBUG_PROPRO
- fprintf(stderr, "#PP %p init\n", o);
-#endif
+static zval *get_obj(zval *object, zval *return_value)
+{
+ zval tmp;
- return o->zv;
+ ZVAL_UNDEF(&tmp);
+ RETVAL_ZVAL(get_proxied_value(object, &tmp), 1, 0);
+ return return_value;
}
-#if DEBUG_PROPRO
-/* we do not really care about TS when debugging */
-static int level = 1;
-static const char space[] = " ";
-static const char *inoutstr[] = {"< return",""," > enter"};
-static void _walk(php_property_proxy_object_t *obj TSRMLS_DC)
-{
- if (obj) {
- _walk(obj->parent TSRMLS_CC);
- fprintf(stderr, ".%s", obj->proxy->member_str);
- }
+static void set_obj(zval *object, zval *value) {
+ set_proxied_value(object, value);
}
-static void debug_propro(int inout, const char *f, zval *object, zval *offset,
- zval *value TSRMLS_DC)
+static inline php_property_proxy_object_t *get_propro(zval *object)
{
- php_property_proxy_object_t *obj;
-
- obj = zend_object_store_get_object(object TSRMLS_CC);
- fprintf(stderr, "#PP %p %s %s %s ", obj, &space[sizeof(space)-level],
- inoutstr[inout+1], f);
-
- level += inout;
-
- _walk(obj TSRMLS_CC);
-
- if (*f++=='d'
- && *f++=='i'
- && *f++=='m'
- ) {
- char *offset_str = "[]";
- zval *o = offset;
+ ZEND_ASSERT(Z_TYPE_P(object) == IS_OBJECT);
+ return PHP_PROPRO_PTR(Z_OBJ_P(object));
+}
- if (o) {
- convert_to_string_ex(&o);
- offset_str = Z_STRVAL_P(o);
- }
+static inline zval *get_container(zval *object)
+{
+ php_property_proxy_object_t *obj = get_propro(object);
- fprintf(stderr, ".%s", offset_str);
+ if (!Z_ISUNDEF(obj->parent)) {
+ zval *parent_value, tmp;
- if (o && o != offset) {
- zval_ptr_dtor(&o);
+ ZVAL_UNDEF(&tmp);
+ parent_value = get_proxied_value(&obj->parent, &tmp);
+ ZVAL_DEREF(parent_value);
+ switch (Z_TYPE_P(parent_value)) {
+ case IS_OBJECT:
+ case IS_ARRAY:
+ zend_assign_to_variable(&obj->proxy->container, parent_value, IS_CV);
+ break;
+ default:
+ break;
}
}
- if (value) {
- const char *t[] = {
- "NULL",
- "int",
- "float",
- "bool",
- "Array",
- "Object",
- "string",
- "resource",
- "const",
- "const Array",
- "callable"
- };
- fprintf(stderr, " = (%s) ", t[Z_TYPE_P(value)&0xf]);
- zend_print_flat_zval_r(value TSRMLS_CC);
- }
- fprintf(stderr, "\n");
+ return &obj->proxy->container;
}
-#else
-#define debug_propro(l, f, obj, off, val)
-#endif
-static zval *get_parent_proxied_value(zval *object TSRMLS_DC);
-static zval *get_proxied_value(zval *object TSRMLS_DC);
-static zval *read_dimension(zval *object, zval *offset, int type TSRMLS_DC);
-static ZEND_RESULT_CODE cast_proxied_value(zval *object, zval *return_value,
- int type TSRMLS_DC);
-static void write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC);
-static void set_proxied_value(zval **object, zval *value TSRMLS_DC);
-
-static zval *get_parent_proxied_value(zval *object TSRMLS_DC)
+static inline void set_container(zval *object, zval *container)
{
- zval *value = NULL;
- php_property_proxy_object_t *obj;
+ php_property_proxy_object_t *obj = get_propro(object);
+ zend_assign_to_variable(&obj->proxy->container, container, IS_CV);
- obj = zend_object_store_get_object(object TSRMLS_CC);
- if (obj->proxy) {
- if (obj->parent) {
- zval *parent;
-
- MAKE_STD_ZVAL(parent);
- parent->type = IS_OBJECT;
- parent->value.obj = obj->parent->zv;
- zend_objects_store_add_ref_by_handle(
- obj->parent->zv.handle TSRMLS_CC);
- value = get_proxied_value(parent TSRMLS_CC);
- zval_ptr_dtor(&parent);
- }
+ if (!Z_ISUNDEF(obj->parent)) {
+ set_proxied_value(&obj->parent, &obj->proxy->container);
}
-
- return value;
}
-static zval *get_proxied_value(zval *object TSRMLS_DC)
+static inline zval *get_container_value(zval *container, zend_string *member, zval *return_value)
{
- zval **hash_value, *value = NULL;
- php_property_proxy_object_t *obj;
- ZEND_RESULT_CODE rv;
-
- obj = zend_object_store_get_object(object TSRMLS_CC);
- debug_propro(1, "get", object, NULL, NULL TSRMLS_CC);
-
- if (obj->proxy) {
- if (obj->parent) {
- zval *parent_value = get_parent_proxied_value(object TSRMLS_CC);
+ zval *found_value = NULL, prop_tmp;
- if (parent_value && parent_value != obj->proxy->container) {
- Z_ADDREF_P(parent_value);
- zval_ptr_dtor(&obj->proxy->container);
- obj->proxy->container = parent_value;
- }
- }
- switch (Z_TYPE_P(obj->proxy->container)) {
- case IS_OBJECT:
- value = zend_read_property(Z_OBJCE_P(obj->proxy->container),
- obj->proxy->container, obj->proxy->member_str,
- obj->proxy->member_len, 0 TSRMLS_CC);
- break;
+ ZVAL_DEREF(container);
+ switch (Z_TYPE_P(container)) {
+ case IS_OBJECT:
+ found_value = zend_read_property(Z_OBJCE_P(container), container,
+ member->val, member->len, 0, &prop_tmp);
- case IS_ARRAY:
- rv = zend_symtable_find(Z_ARRVAL_P(obj->proxy->container),
- obj->proxy->member_str, obj->proxy->member_len + 1,
- (void *) &hash_value);
+ break;
- if (SUCCESS == rv) {
- value = *hash_value;
- }
- break;
- }
+ case IS_ARRAY:
+ found_value = zend_symtable_find(Z_ARRVAL_P(container), member);
+ break;
}
- debug_propro(-1, "get", object, NULL, value TSRMLS_CC);
+ if (found_value) {
+ RETVAL_ZVAL(found_value, 0, 0);
+ }
- return value;
+ return return_value;
}
-static ZEND_RESULT_CODE cast_proxied_value(zval *object, zval *return_value,
- int type TSRMLS_DC)
+static inline void set_container_value(zval *container, zend_string *member, zval *value)
{
- zval *proxied_value;
-
- if ((proxied_value = get_proxied_value(object TSRMLS_CC))) {
- RETVAL_ZVAL(proxied_value, 1, 0);
- if (Z_TYPE_P(proxied_value) != type) {
- convert_to_explicit_type(return_value, type);
+ ZVAL_DEREF(container);
+ switch (Z_TYPE_P(container)) {
+ case IS_OBJECT:
+ zend_update_property(Z_OBJCE_P(container), container,
+ member->val, member->len, value);
+ break;
+
+ case IS_UNDEF:
+ array_init(container);
+ /* no break */
+ default:
+ SEPARATE_ZVAL(container);
+ convert_to_array(container);
+ /* no break */
+ case IS_ARRAY:
+ SEPARATE_ARRAY(container);
+ Z_TRY_ADDREF_P(value);
+ if (member) {
+ zend_symtable_update(Z_ARRVAL_P(container), member, value);
+ } else {
+ zend_hash_next_index_insert(Z_ARRVAL_P(container), value);
}
- return SUCCESS;
+ break;
}
-
- return FAILURE;
}
-static void set_proxied_value(zval **object, zval *value TSRMLS_DC)
+
+static zval *get_proxied_value(zval *object, zval *return_value)
{
- php_property_proxy_object_t *obj;
+ php_property_proxy_object_t *obj = get_propro(object);
- obj = zend_object_store_get_object(*object TSRMLS_CC);
- debug_propro(1, "set", *object, NULL, value TSRMLS_CC);
+ debug_propro(1, "get", obj, NULL, NULL, NULL);
if (obj->proxy) {
- if (obj->parent) {
- zval *parent_value = get_parent_proxied_value(*object TSRMLS_CC);
+ zval *container = get_container(object);
- if (parent_value && parent_value != obj->proxy->container) {
- Z_ADDREF_P(parent_value);
- zval_ptr_dtor(&obj->proxy->container);
- obj->proxy->container = parent_value;
- }
- }
+ return_value = get_container_value(container, obj->proxy->member, return_value);
+ }
- switch (Z_TYPE_P(obj->proxy->container)) {
- case IS_OBJECT:
- zend_update_property(Z_OBJCE_P(obj->proxy->container),
- obj->proxy->container, obj->proxy->member_str,
- obj->proxy->member_len, value TSRMLS_CC);
- break;
+ debug_propro(-1, "get", obj, NULL, NULL, return_value);
- case IS_ARRAY:
- Z_ADDREF_P(value);
- zend_symtable_update(Z_ARRVAL_P(obj->proxy->container),
- obj->proxy->member_str, obj->proxy->member_len + 1,
- (void *) &value, sizeof(zval *), NULL);
- break;
- }
+ return return_value;
+}
- if (obj->parent) {
- zval *zparent;
- MAKE_STD_ZVAL(zparent);
- zparent->type = IS_OBJECT;
- zparent->value.obj = obj->parent->zv;
- zend_objects_store_add_ref_by_handle(
- obj->parent->zv.handle TSRMLS_CC);
- set_proxied_value(&zparent, obj->proxy->container TSRMLS_CC);
- zval_ptr_dtor(&zparent);
- }
+static void set_proxied_value(zval *object, zval *value)
+{
+ php_property_proxy_object_t *obj = get_propro(object);
+
+ debug_propro(1, "set", obj, NULL, NULL, value);
+
+ if (obj->proxy) {
+ zval *container = get_container(object);
+
+ set_container_value(container, obj->proxy->member, value);
+ set_container(object, container);
+
+ debug_propro(0, "set", obj, NULL, NULL, value);
}
- debug_propro(-1, "set", *object, NULL, NULL TSRMLS_CC);
+ debug_propro(-1, "set", obj, NULL, NULL, value);
}
-static zval *read_dimension(zval *object, zval *offset, int type TSRMLS_DC)
+static zval *read_dimension(zval *object, zval *offset, int type, zval *return_value)
{
- zval *value = NULL;
- zval *proxied_value;
- zval *o = offset;
+ zval *value, tmp;
+ zend_string *member = offset ? zval_get_string(offset) : NULL;
- debug_propro(1, type == BP_VAR_R ? "dim_read" : "dim_read_ref", object,
- offset, NULL TSRMLS_CC);
+ debug_propro(1, type == BP_VAR_R ? "dim_r" : "dim_R",
+ get_propro(object), NULL, offset, NULL);
- proxied_value = get_proxied_value(object TSRMLS_CC);
- convert_to_string_ex(&o);
+ ZVAL_UNDEF(&tmp);
+ value = get_proxied_value(object, &tmp);
- if (BP_VAR_R == type && proxied_value) {
- if (Z_TYPE_P(proxied_value) == IS_ARRAY) {
- zval **hash_value;
- ZEND_RESULT_CODE rv = zend_symtable_find(Z_ARRVAL_P(proxied_value),
- Z_STRVAL_P(o), Z_STRLEN_P(o), (void *) &hash_value);
+ if (type == BP_VAR_R) {
+ ZEND_ASSERT(member);
- if (SUCCESS == rv) {
- Z_ADDREF_PP(hash_value);
- value = *hash_value;
- }
+ if (!Z_ISUNDEF_P(value)) {
+ zval tmp;
+
+ ZVAL_UNDEF(&tmp);
+ RETVAL_ZVAL(get_container_value(value, member, &tmp), 1, 0);
}
} else {
php_property_proxy_t *proxy;
php_property_proxy_object_t *proxy_obj;
+ zval *array = value;
+ zend_bool created = Z_ISUNDEF_P(value);
- if (proxied_value) {
- convert_to_array(proxied_value);
- Z_ADDREF_P(proxied_value);
- } else {
- MAKE_STD_ZVAL(proxied_value);
- array_init(proxied_value);
- set_proxied_value(&object, proxied_value TSRMLS_CC);
+ ZVAL_DEREF(array);
+ if (Z_REFCOUNTED_P(array) && Z_REFCOUNT_P(array) > 1) {
+ created = 1;
+ SEPARATE_ZVAL_NOREF(array);
+ }
+ if (Z_TYPE_P(array) != IS_ARRAY) {
+ created = 1;
+ if (Z_ISUNDEF_P(array)) {
+ array_init(array);
+ } else {
+ convert_to_array(array);
+ }
+ }
+
+ if (!member) {
+ member = zend_long_to_str(zend_hash_next_free_element(
+ Z_ARRVAL_P(array)));
+ }
+
+ proxy = php_property_proxy_init(value, member);
+ proxy_obj = php_property_proxy_object_new_ex(NULL, proxy);
+ ZVAL_COPY(&proxy_obj->parent, object);
+ RETVAL_OBJ(&proxy_obj->zo);
+
+ if (created) {
+ Z_DELREF_P(value);
}
- proxy = php_property_proxy_init(proxied_value, Z_STRVAL_P(o),
- Z_STRLEN_P(o) TSRMLS_CC);
- zval_ptr_dtor(&proxied_value);
- MAKE_STD_ZVAL(value);
- Z_SET_REFCOUNT_P(value, 0);
- value->type = IS_OBJECT;
- value->value.obj = php_property_proxy_object_new_ex(
- php_property_proxy_get_class_entry(), proxy,
- &proxy_obj TSRMLS_CC);
- proxy_obj->parent = zend_object_store_get_object(object TSRMLS_CC);
- zend_objects_store_add_ref_by_handle(
- proxy_obj->parent->zv.handle TSRMLS_CC);
+ debug_propro(0, created ? "dim_R pp C" : "dim_R pp", get_propro(object), NULL, offset, return_value);
}
- if (o && o != offset) {
- zval_ptr_dtor(&o);
+
+ if (member) {
+ zend_string_release(member);
}
- debug_propro(-1, type == BP_VAR_R ? "dim_read" : "dim_read_ref", object,
- offset, value TSRMLS_CC);
+ debug_propro(-1, type == BP_VAR_R ? "dim_r" : "dim_R",
+ get_propro(object), NULL, offset, return_value);
- return value;
+ return return_value;
}
-static int has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC)
+static int has_dimension(zval *object, zval *offset, int check_empty)
{
- zval *proxied_value;
+ zval *value, tmp;
int exists = 0;
- debug_propro(1, "dim_exists", object, offset, NULL TSRMLS_CC);
+ debug_propro(1, "dim_e", get_propro(object), NULL, offset, NULL);
- proxied_value = get_proxied_value(object TSRMLS_CC);
- if (!proxied_value) {
- exists = 0;
- } else {
- zval *o = offset;
+ ZVAL_UNDEF(&tmp);
+ value = get_proxied_value(object, &tmp);
- convert_to_string_ex(&o);
+ exists = 0;
+ if (!Z_ISUNDEF_P(value)) {
+ zend_string *zs = zval_get_string(offset);
- if (Z_TYPE_P(proxied_value) == IS_ARRAY) {
- zval **zentry;
- ZEND_RESULT_CODE rv = zend_symtable_find(Z_ARRVAL_P(proxied_value), Z_STRVAL_P(o), Z_STRLEN_P(o) + 1, (void *) &zentry);
+ ZVAL_DEREF(value);
+ if (Z_TYPE_P(value) == IS_ARRAY) {
+ zval *zentry = zend_symtable_find(Z_ARRVAL_P(value), zs);
- if (SUCCESS != rv) {
+ if (!zentry) {
exists = 0;
} else {
if (check_empty) {
- exists = Z_TYPE_PP(zentry) != IS_NULL;
+ exists = !Z_ISNULL_P(zentry);
} else {
exists = 1;
}
}
}
- if (o != offset) {
- zval_ptr_dtor(&o);
- }
+ zend_string_release(zs);
}
- debug_propro(-1, "dim_exists", object, offset, NULL TSRMLS_CC);
+ debug_propro(-1, "dim_e", get_propro(object), NULL, offset, NULL);
return exists;
}
-static void write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC)
+static void write_dimension(zval *object, zval *offset, zval *input_value)
{
- zval *proxied_value, *o = offset;
-
- debug_propro(1, "dim_write", object, offset, value TSRMLS_CC);
+ zval *array, tmp;
+ zend_string *zs = NULL;
- proxied_value = get_proxied_value(object TSRMLS_CC);
+ debug_propro(1, "dim_w", get_propro(object), NULL, offset, input_value);
- if (proxied_value) {
- convert_to_array(proxied_value);
- Z_ADDREF_P(proxied_value);
- } else {
- MAKE_STD_ZVAL(proxied_value);
- array_init(proxied_value);
- }
-
- if (Z_REFCOUNT_P(value) > 1) {
- SEPARATE_ZVAL(&value);
- }
- Z_ADDREF_P(value);
+ ZVAL_UNDEF(&tmp);
+ array = get_proxied_value(object, &tmp);
- if (o) {
- convert_to_string_ex(&o);
- zend_symtable_update(Z_ARRVAL_P(proxied_value), Z_STRVAL_P(o),
- Z_STRLEN_P(o) + 1, (void *) &value, sizeof(zval *), NULL);
- } else {
- zend_hash_next_index_insert(Z_ARRVAL_P(proxied_value), (void *) &value,
- sizeof(zval *), NULL);
+ if (offset) {
+ zs = zval_get_string(offset);
}
-
- if (o && o != offset) {
- zval_ptr_dtor(&o);
+ set_container_value(array, zs, input_value);
+ if (zs) {
+ zend_string_release(zs);
}
- set_proxied_value(&object, proxied_value TSRMLS_CC);
+ set_proxied_value(object, array);
- debug_propro(-1, "dim_write", object, offset, proxied_value TSRMLS_CC);
-
- zval_ptr_dtor(&proxied_value);
+ debug_propro(-1, "dim_w", get_propro(object), NULL, offset, input_value);
}
-static void unset_dimension(zval *object, zval *offset TSRMLS_DC)
+static void unset_dimension(zval *object, zval *offset)
{
- zval *proxied_value;
+ zval *array, *value, tmp;
- debug_propro(1, "dim_unset", object, offset, NULL TSRMLS_CC);
+ debug_propro(1, "dim_u", get_propro(object), NULL, offset, NULL);
- proxied_value = get_proxied_value(object TSRMLS_CC);
+ ZVAL_UNDEF(&tmp);
+ value = get_proxied_value(object, &tmp);
+ array = value;
+ ZVAL_DEREF(array);
- if (proxied_value && Z_TYPE_P(proxied_value) == IS_ARRAY) {
- zval *o = offset;
- ZEND_RESULT_CODE rv;
+ if (Z_TYPE_P(array) == IS_ARRAY) {
+ zend_string *o = zval_get_string(offset);
- convert_to_string_ex(&o);
- rv = zend_symtable_del(Z_ARRVAL_P(proxied_value), Z_STRVAL_P(o),
- Z_STRLEN_P(o) + 1);
+ SEPARATE_ARRAY(array);
+ zend_symtable_del(Z_ARRVAL_P(array), o);
- if (SUCCESS == rv) {
- set_proxied_value(&object, proxied_value TSRMLS_CC);
- }
+ set_proxied_value(object, value);
- if (o != offset) {
- zval_ptr_dtor(&o);
- }
+ zend_string_release(o);
}
- debug_propro(-1, "dim_unset", object, offset, proxied_value TSRMLS_CC);
+ debug_propro(-1, "dim_u", get_propro(object), NULL, offset, NULL);
}
ZEND_BEGIN_ARG_INFO_EX(ai_propro_construct, 0, 0, 2)
ZEND_END_ARG_INFO();
static PHP_METHOD(propro, __construct) {
zend_error_handling zeh;
- zval *container, *parent = NULL;
- char *member_str;
- int member_len;
+ zval *reference, *container, *parent = NULL;
+ zend_string *member;
- zend_replace_error_handling(EH_THROW, NULL, &zeh TSRMLS_CC);
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs|O!",
- &container, &member_str, &member_len, &parent,
+ zend_replace_error_handling(EH_THROW, NULL, &zeh);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "zS|O!",
+ &reference, &member, &parent,
php_property_proxy_class_entry)) {
php_property_proxy_object_t *obj;
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- obj->proxy = php_property_proxy_init(container, member_str,
- member_len TSRMLS_CC);
+ container = reference;
+ ZVAL_DEREF(container);
+ switch (Z_TYPE_P(container)) {
+ case IS_ARRAY:
+ SEPARATE_ARRAY(container);
+ break;
+ case IS_OBJECT:
+ break;
+ default:
+ SEPARATE_ZVAL(container);
+ convert_to_array(container);
+ break;
+ }
+
+ obj = get_propro(getThis());
+ obj->proxy = php_property_proxy_init(reference, member);
+
if (parent) {
- zend_objects_store_add_ref(parent TSRMLS_CC);
- obj->parent = zend_object_store_get_object(parent TSRMLS_CC);
+ ZVAL_COPY(&obj->parent, parent);
}
}
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
}
static const zend_function_entry php_property_proxy_method_entry[] = {
INIT_NS_CLASS_ENTRY(ce, "php", "PropertyProxy",
php_property_proxy_method_entry);
- php_property_proxy_class_entry = zend_register_internal_class_ex(&ce, NULL,
- NULL TSRMLS_CC);
- php_property_proxy_class_entry->create_object =
- php_property_proxy_object_new;
- php_property_proxy_class_entry->ce_flags |= ZEND_ACC_FINAL_CLASS;
+ php_property_proxy_class_entry = zend_register_internal_class(&ce);
+ php_property_proxy_class_entry->create_object = php_property_proxy_object_new;
+ php_property_proxy_class_entry->ce_flags |= ZEND_ACC_FINAL;
memcpy(&php_property_proxy_object_handlers, zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
- php_property_proxy_object_handlers.set = set_proxied_value;
- php_property_proxy_object_handlers.get = get_proxied_value;
- php_property_proxy_object_handlers.cast_object = cast_proxied_value;
+ php_property_proxy_object_handlers.offset = XtOffsetOf(php_property_proxy_object_t, zo);
+ php_property_proxy_object_handlers.free_obj = destroy_obj;
+ php_property_proxy_object_handlers.set = set_obj;
+ php_property_proxy_object_handlers.get = get_obj;
+ php_property_proxy_object_handlers.cast_object = cast_obj;
php_property_proxy_object_handlers.read_dimension = read_dimension;
php_property_proxy_object_handlers.write_dimension = write_dimension;
php_property_proxy_object_handlers.has_dimension = has_dimension;