diff options
author | thinkerou <thinkerou@gmail.com> | 2016-07-28 09:49:38 +0800 |
---|---|---|
committer | thinkerou <thinkerou@gmail.com> | 2016-07-28 09:49:38 +0800 |
commit | dc673c5322efffecb6ded692c6f04ce911fe5551 (patch) | |
tree | 559d9672250257b5f1d016c2cc10ac1c4609a53d | |
parent | 11cb5c53cb15fc91ea51798cf6b8a0f10462ecd1 (diff) |
add PHP_GRPC_FREE_CLASS_OBJECT macro
-rw-r--r-- | src/php/ext/grpc/call.c | 11 | ||||
-rw-r--r-- | src/php/ext/grpc/call_credentials.c | 12 | ||||
-rw-r--r-- | src/php/ext/grpc/channel.c | 11 | ||||
-rw-r--r-- | src/php/ext/grpc/channel_credentials.c | 12 | ||||
-rw-r--r-- | src/php/ext/grpc/php7_wrapper.h | 11 | ||||
-rw-r--r-- | src/php/ext/grpc/server.c | 11 | ||||
-rw-r--r-- | src/php/ext/grpc/server_credentials.c | 12 | ||||
-rw-r--r-- | src/php/ext/grpc/timeval.c | 5 |
8 files changed, 23 insertions, 62 deletions
diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 10fc3feb63..840ac71364 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -76,16 +76,7 @@ php_grpc_zend_object create_wrapped_grpc_call(zend_class_entry *class_type PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_call); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_call, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &call_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_call, call_ce_handlers); } /* Creates and returns a PHP array object with the data in a diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c index b7d33d7239..34a88af47f 100644 --- a/src/php/ext/grpc/call_credentials.c +++ b/src/php/ext/grpc/call_credentials.c @@ -70,16 +70,8 @@ php_grpc_zend_object create_wrapped_grpc_call_credentials( PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_call_credentials); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_call_credentials, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &call_credentials_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_call_credentials, + call_credentials_ce_handlers); } zval *grpc_php_wrap_call_credentials(grpc_call_credentials diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index 325e8f495e..1d3f68af7c 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -74,16 +74,7 @@ php_grpc_zend_object create_wrapped_grpc_channel(zend_class_entry *class_type PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_channel); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_channel, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &channel_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_channel, channel_ce_handlers); } void php_grpc_read_args_array(zval *args_array, diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c index 32f24e5751..7ef95cc5e2 100644 --- a/src/php/ext/grpc/channel_credentials.c +++ b/src/php/ext/grpc/channel_credentials.c @@ -80,16 +80,8 @@ php_grpc_zend_object create_wrapped_grpc_channel_credentials( PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_channel_credentials); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_channel_credentials, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &channel_credentials_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_channel_credentials, + channel_credentials_ce_handlers); } zval *grpc_php_wrap_channel_credentials(grpc_channel_credentials diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h index ba7f163676..44d6cd8dd7 100644 --- a/src/php/ext/grpc/php7_wrapper.h +++ b/src/php/ext/grpc/php7_wrapper.h @@ -72,6 +72,13 @@ intern = (class_object *)emalloc(sizeof(class_object)); \ memset(intern, 0, sizeof(class_object)); +#define PHP_GRPC_FREE_CLASS_OBJECT(class_object, handler) \ + retval.handle = zend_objects_store_put( \ + intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, \ + free_##class_object, NULL TSRMLS_CC); \ + retval.handlers = zend_get_std_object_handlers(); \ + return retval; + #define PHP_GRPC_HASH_FOREACH_VAL_START(ht, data) \ zval **tmp_data = NULL; \ for (zend_hash_internal_pointer_reset(ht); \ @@ -158,6 +165,10 @@ static inline int php_grpc_zend_hash_find(HashTable *ht, char *key, int len, voi intern = ecalloc(1, sizeof(class_object) + \ zend_object_properties_size(class_type)); +#define PHP_GRPC_FREE_CLASS_OBJECT(class_object, handler) \ + intern->std.handlers = &handler; \ + return &intern->std; + #define PHP_GRPC_HASH_FOREACH_VAL_START(ht, data) \ ZEND_HASH_FOREACH_VAL(ht, data) { diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index 2fc785eb31..452ccca3e1 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -79,16 +79,7 @@ php_grpc_zend_object create_wrapped_grpc_server(zend_class_entry *class_type PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_server); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_server, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &server_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_server, server_ce_handlers); } /** diff --git a/src/php/ext/grpc/server_credentials.c b/src/php/ext/grpc/server_credentials.c index 4c147e0991..61041b4cb3 100644 --- a/src/php/ext/grpc/server_credentials.c +++ b/src/php/ext/grpc/server_credentials.c @@ -68,16 +68,8 @@ php_grpc_zend_object create_wrapped_grpc_server_credentials( PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_server_credentials); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_server_credentials, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &server_credentials_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_server_credentials, + server_credentials_ce_handlers); } zval *grpc_php_wrap_server_credentials(grpc_server_credentials diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index d0f75bef82..0d739f1608 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -66,7 +66,8 @@ php_grpc_zend_object create_wrapped_grpc_timeval(zend_class_entry *class_type PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_timeval); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_timeval, timeval_ce_handlers); +/*#if PHP_MAJOR_VERSION < 7 retval.handle = zend_objects_store_put( intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, free_wrapped_grpc_timeval, NULL TSRMLS_CC); @@ -75,7 +76,7 @@ php_grpc_zend_object create_wrapped_grpc_timeval(zend_class_entry *class_type #else intern->std.handlers = &timeval_ce_handlers; return &intern->std; -#endif +#endif*/ } zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC) { |