From b401faa6060bd887e9cc00d0f30fb30a18546e0c Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 5 Jul 2013 23:10:52 +0200 Subject: [PATCH] code alignment --- package.xml | 12 ++--- php_propro.c | 130 +++++++++++++++++++++++++++++++++++---------------- php_propro.h | 10 ++-- 3 files changed, 104 insertions(+), 48 deletions(-) diff --git a/package.xml b/package.xml index bdc20de..be11e7e 100644 --- a/package.xml +++ b/package.xml @@ -19,18 +19,18 @@ http://pear.php.net/dtd/package-2.0.xsd"> mike@php.net yes - 2013-02-16 + 2013-07-07 - 0.1.0 - 0.1.0 + 1.0.0 + 1.0.0 - beta - beta + stable + stable BSD, revised diff --git a/php_propro.c b/php_propro.c index b63caa7..cb9f5fe 100644 --- a/php_propro.c +++ b/php_propro.c @@ -25,10 +25,13 @@ typedef int STATUS; #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*)) +# 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*)) #endif -PHP_PROPRO_API php_property_proxy_t *php_property_proxy_init(zval *container, const char *member_str, size_t member_len TSRMLS_DC) +PHP_PROPRO_API php_property_proxy_t *php_property_proxy_init(zval *container, + const char *member_str, size_t member_len TSRMLS_DC) { php_property_proxy_t *proxy = ecalloc(1, sizeof(*proxy)); @@ -58,7 +61,8 @@ PHP_PROPRO_API zend_class_entry *php_property_proxy_get_class_entry(void) return php_property_proxy_class_entry; } -PHP_PROPRO_API zend_object_value php_property_proxy_object_new(zend_class_entry *ce TSRMLS_DC) +PHP_PROPRO_API zend_object_value php_property_proxy_object_new( + zend_class_entry *ce TSRMLS_DC) { return php_property_proxy_object_new_ex(ce, NULL, NULL TSRMLS_CC); } @@ -75,14 +79,17 @@ static void php_property_proxy_object_free(void *object TSRMLS_DC) 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); + zend_objects_store_del_ref_by_handle_ex(o->parent->zv.handle, + o->parent->zv.handlers TSRMLS_CC); o->parent = NULL; } zend_object_std_dtor((zend_object *) o TSRMLS_CC); efree(o); } -PHP_PROPRO_API 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) +PHP_PROPRO_API 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) { php_property_proxy_object_t *o; @@ -95,7 +102,8 @@ PHP_PROPRO_API zend_object_value php_property_proxy_object_new_ex(zend_class_ent } o->proxy = proxy; - o->zv.handle = zend_objects_store_put(o, NULL, php_property_proxy_object_free, NULL TSRMLS_CC); + 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; #if DEBUG_PROPRO @@ -118,11 +126,14 @@ static void _walk(php_property_proxy_object_t *obj TSRMLS_DC) } } -static void debug_propro(int inout, const char *f, zval *object, zval *offset, zval *value TSRMLS_DC) +static void debug_propro(int inout, const char *f, zval *object, zval *offset, + zval *value TSRMLS_DC) { - php_property_proxy_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); + php_property_proxy_object_t *obj; - fprintf(stderr, "#PP %p %s %s %s ", obj, &space[sizeof(space)-level], inoutstr[inout+1], f); + 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; @@ -173,15 +184,17 @@ static void debug_propro(int inout, const char *f, zval *object, zval *offset, z 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 STATUS cast_proxied_value(zval *object, zval *return_value, int type TSRMLS_DC); +static STATUS 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) { zval *value = NULL; - php_property_proxy_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); + php_property_proxy_object_t *obj; + obj = zend_object_store_get_object(object TSRMLS_CC); if (obj->proxy) { if (obj->parent) { zval *parent; @@ -189,7 +202,8 @@ static zval *get_parent_proxied_value(zval *object TSRMLS_DC) 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); + zend_objects_store_add_ref_by_handle( + obj->parent->zv.handle TSRMLS_CC); value = get_proxied_value(parent TSRMLS_CC); zval_ptr_dtor(&parent); } @@ -201,8 +215,10 @@ static zval *get_parent_proxied_value(zval *object TSRMLS_DC) static zval *get_proxied_value(zval *object TSRMLS_DC) { zval **hash_value, *value = NULL; - php_property_proxy_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); + php_property_proxy_object_t *obj; + STATUS rv; + obj = zend_object_store_get_object(object TSRMLS_CC); debug_propro(1, "get", object, NULL, NULL TSRMLS_CC); if (obj->proxy) { @@ -217,11 +233,17 @@ static zval *get_proxied_value(zval *object TSRMLS_DC) } 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); + 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; case IS_ARRAY: - if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(obj->proxy->container), obj->proxy->member_str, obj->proxy->member_len + 1, (void *) &hash_value)) { + rv = zend_symtable_find(Z_ARRVAL_P(obj->proxy->container), + obj->proxy->member_str, obj->proxy->member_len + 1, + (void *) &hash_value); + + if (SUCCESS == rv) { value = *hash_value; } break; @@ -233,7 +255,8 @@ static zval *get_proxied_value(zval *object TSRMLS_DC) return value; } -static STATUS cast_proxied_value(zval *object, zval *return_value, int type TSRMLS_DC) +static STATUS cast_proxied_value(zval *object, zval *return_value, + int type TSRMLS_DC) { zval *proxied_value; @@ -250,8 +273,9 @@ static STATUS cast_proxied_value(zval *object, zval *return_value, int type TSRM static void set_proxied_value(zval **object, zval *value TSRMLS_DC) { - php_property_proxy_object_t *obj = zend_object_store_get_object(*object TSRMLS_CC); + php_property_proxy_object_t *obj; + obj = zend_object_store_get_object(*object TSRMLS_CC); debug_propro(1, "set", *object, NULL, value TSRMLS_CC); if (obj->proxy) { @@ -267,12 +291,16 @@ static void set_proxied_value(zval **object, zval *value TSRMLS_DC) 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); + zend_update_property(Z_OBJCE_P(obj->proxy->container), + obj->proxy->container, obj->proxy->member_str, + obj->proxy->member_len, value TSRMLS_CC); break; 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); + zend_symtable_update(Z_ARRVAL_P(obj->proxy->container), + obj->proxy->member_str, obj->proxy->member_len + 1, + (void *) &value, sizeof(zval *), NULL); break; } @@ -281,7 +309,8 @@ static void set_proxied_value(zval **object, zval *value TSRMLS_DC) 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); + 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); } @@ -296,7 +325,8 @@ static zval *read_dimension(zval *object, zval *offset, int type TSRMLS_DC) zval *proxied_value; zval *o = offset; - 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_read" : "dim_read_ref", object, + offset, NULL TSRMLS_CC); proxied_value = get_proxied_value(object TSRMLS_CC); convert_to_string_ex(&o); @@ -304,7 +334,10 @@ static zval *read_dimension(zval *object, zval *offset, int type TSRMLS_DC) if (BP_VAR_R == type && proxied_value) { if (Z_TYPE_P(proxied_value) == IS_ARRAY) { zval **hash_value; - if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(proxied_value), Z_STRVAL_P(o), Z_STRLEN_P(o), (void *) &hash_value)) { + STATUS rv = zend_symtable_find(Z_ARRVAL_P(proxied_value), + Z_STRVAL_P(o), Z_STRLEN_P(o), (void *) &hash_value); + + if (SUCCESS == rv) { Z_ADDREF_PP(hash_value); value = *hash_value; } @@ -322,20 +355,25 @@ static zval *read_dimension(zval *object, zval *offset, int type TSRMLS_DC) set_proxied_value(&object, proxied_value TSRMLS_CC); } - proxy = php_property_proxy_init(proxied_value, Z_STRVAL_P(o), Z_STRLEN_P(o) TSRMLS_CC); + 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); + 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); + zend_objects_store_add_ref_by_handle( + proxy_obj->parent->zv.handle TSRMLS_CC); } if (o && o != offset) { zval_ptr_dtor(&o); } - 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_read" : "dim_read_ref", object, + offset, value TSRMLS_CC); return value; } @@ -357,8 +395,9 @@ static int has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC) if (Z_TYPE_P(proxied_value) == IS_ARRAY) { zval **zentry; + STATUS rv = zend_symtable_find(Z_ARRVAL_P(proxied_value), Z_STRVAL_P(o), Z_STRLEN_P(o) + 1, (void *) &zentry); - if (SUCCESS != zend_symtable_find(Z_ARRVAL_P(proxied_value), Z_STRVAL_P(o), Z_STRLEN_P(o) + 1, (void *) &zentry)) { + if (SUCCESS != rv) { exists = 0; } else { if (check_empty) { @@ -402,9 +441,11 @@ static void write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) 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); + 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); + zend_hash_next_index_insert(Z_ARRVAL_P(proxied_value), (void *) &value, + sizeof(zval *), NULL); } if (o && o != offset) { @@ -428,10 +469,13 @@ static void unset_dimension(zval *object, zval *offset TSRMLS_DC) if (proxied_value && Z_TYPE_P(proxied_value) == IS_ARRAY) { zval *o = offset; + STATUS rv; convert_to_string_ex(&o); + rv = zend_symtable_del(Z_ARRVAL_P(proxied_value), Z_STRVAL_P(o), + Z_STRLEN_P(o) + 1); - if (SUCCESS == zend_symtable_del(Z_ARRVAL_P(proxied_value), Z_STRVAL_P(o), Z_STRLEN_P(o) + 1)) { + if (SUCCESS == rv) { set_proxied_value(&object, proxied_value TSRMLS_CC); } @@ -455,10 +499,14 @@ static PHP_METHOD(propro, __construct) { int member_len; 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, php_property_proxy_class_entry)) { - php_property_proxy_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); - - obj->proxy = php_property_proxy_init(container, member_str, member_len TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs|O!", + &container, &member_str, &member_len, &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); if (parent) { zend_objects_store_add_ref(parent TSRMLS_CC); obj->parent = zend_object_store_get_object(parent TSRMLS_CC); @@ -468,7 +516,7 @@ static PHP_METHOD(propro, __construct) { } static const zend_function_entry php_property_proxy_method_entry[] = { - PHP_ME(propro, __construct, ai_propro_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(propro, __construct, ai_propro_construct, ZEND_ACC_PUBLIC) {0} }; @@ -476,12 +524,16 @@ static PHP_MINIT_FUNCTION(propro) { zend_class_entry ce = {0}; - 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; + 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; - memcpy(&php_property_proxy_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + 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; diff --git a/php_propro.h b/php_propro.h index f26cab0..5d01740 100644 --- a/php_propro.h +++ b/php_propro.h @@ -43,13 +43,17 @@ typedef struct php_property_proxy_object { struct php_property_proxy_object *parent; } php_property_proxy_object_t; -PHP_PROPRO_API php_property_proxy_t *php_property_proxy_init(zval *container, const char *member_str, size_t member_len TSRMLS_DC); +PHP_PROPRO_API php_property_proxy_t *php_property_proxy_init(zval *container, + const char *member_str, size_t member_len TSRMLS_DC); PHP_PROPRO_API void php_property_proxy_free(php_property_proxy_t **proxy); PHP_PROPRO_API zend_class_entry *php_property_proxy_get_class_entry(void); -PHP_PROPRO_API zend_object_value php_property_proxy_object_new(zend_class_entry *ce TSRMLS_DC); -PHP_PROPRO_API 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); +PHP_PROPRO_API zend_object_value php_property_proxy_object_new( + zend_class_entry *ce TSRMLS_DC); +PHP_PROPRO_API 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); #endif /* PHP_PROPRO_H */ -- 2.30.2