From: Michael Wallner Date: Wed, 17 Dec 2014 07:29:46 +0000 (+0100) Subject: zend_object must be the last struct member X-Git-Tag: release-2.0.0RC1~24 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=78ce5324565228f14ec2f32c96ad2f3972c8440f;p=m6w6%2Fext-propro zend_object must be the last struct member --- diff --git a/php_propro.c b/php_propro.c index 8d96e94..8c9e945 100644 --- a/php_propro.c +++ b/php_propro.c @@ -156,9 +156,9 @@ static php_property_proxy_object_t *new_propro(zend_class_entry *ce, ce = php_property_proxy_class_entry; } - o = ecalloc(1, sizeof(*o) + sizeof(zval) * ce->default_properties_count); - zend_object_std_init((zend_object *) o, ce TSRMLS_CC); - object_properties_init((zend_object *) o, ce); + o = ecalloc(1, sizeof(*o) + sizeof(zval) * (ce->default_properties_count - 1)); + zend_object_std_init(&o->zo, ce TSRMLS_CC); + object_properties_init(&o->zo, ce); o->proxy = proxy; o->zo.handlers = &php_property_proxy_object_handlers; @@ -170,12 +170,12 @@ static php_property_proxy_object_t *new_propro(zend_class_entry *ce, static zend_object *create_obj(zend_class_entry *ce TSRMLS_DC) { - return (zend_object *) new_propro(ce, NULL TSRMLS_CC); + return &new_propro(ce, NULL TSRMLS_CC)->zo; } static void destroy_obj(zend_object *object TSRMLS_DC) { - php_property_proxy_object_t *o = (php_property_proxy_object_t *) object; + php_property_proxy_object_t *o = PHP_PROPRO_PTR(object); debug_propro(0, "dtor", o, NULL, NULL TSRMLS_CC); @@ -197,7 +197,7 @@ static inline php_property_proxy_object_t *get_propro(zval *object) EMPTY_SWITCH_DEFAULT_CASE(); } - return (php_property_proxy_object_t *) Z_OBJ_P(object); + return PHP_PROPRO_PTR(Z_OBJ_P(object)); } static inline zend_bool got_value(zval *container, zval *value TSRMLS_DC) @@ -393,7 +393,7 @@ static zval *read_dimension(zval *object, zval *offset, int type, zval *return_v proxy_obj = new_propro(NULL, proxy TSRMLS_CC); ZVAL_COPY(&proxy_obj->parent, object); - RETVAL_OBJ((zend_object *) proxy_obj); + RETVAL_OBJ(&proxy_obj->zo); } if (o && o != offset) { @@ -558,10 +558,11 @@ static PHP_MINIT_FUNCTION(propro) php_property_proxy_method_entry); php_property_proxy_class_entry = zend_register_internal_class(&ce TSRMLS_CC); php_property_proxy_class_entry->create_object = create_obj; - php_property_proxy_class_entry->ce_flags |= ZEND_ACC_FINAL_CLASS; + 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.offset = XtOffsetOf(php_property_proxy_object_t, zo); php_property_proxy_object_handlers.dtor_obj = destroy_obj; php_property_proxy_object_handlers.set = set_proxied_value; php_property_proxy_object_handlers.get = get_proxied_value; diff --git a/php_propro.h b/php_propro.h index 9d845bf..511f468 100644 --- a/php_propro.h +++ b/php_propro.h @@ -32,7 +32,9 @@ extern zend_module_entry propro_module_entry; # include #endif -#endif +#define PHP_PROPRO_PTR(zo) (void*)(((char*)(zo))-(zo)->handlers->offset) + +#endif /* DOXYGEN */ /** * The internal property proxy. @@ -93,12 +95,12 @@ typedef struct php_property_proxy php_property_proxy_t; * ~~~~~~~~~~ */ struct php_property_proxy_object { - /** The std zend_object */ - zend_object zo; /** The actual property proxy */ php_property_proxy_t *proxy; /** Any parent property proxy object */ zval parent; + /** The std zend_object */ + zend_object zo; }; typedef struct php_property_proxy_object php_property_proxy_object_t;