aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar thinkerou <thinkerou@gmail.com>2016-07-27 09:44:49 +0800
committerGravatar thinkerou <thinkerou@gmail.com>2016-07-27 09:44:49 +0800
commit011d1efc8f109a392304b51985fce790ae2d8c22 (patch)
tree7f04b716f929610786a178d3a568cca83baf963a
parent31fd05318099c64d2bd5688a6c3cea341e4b566e (diff)
add macro to php7_wrapper for reduce duplicate code
-rw-r--r--src/php/ext/grpc/call.c24
-rw-r--r--src/php/ext/grpc/call_credentials.c26
-rwxr-xr-xsrc/php/ext/grpc/call_credentials.h4
-rw-r--r--src/php/ext/grpc/channel.c24
-rw-r--r--src/php/ext/grpc/channel_credentials.c26
-rwxr-xr-xsrc/php/ext/grpc/channel_credentials.h7
-rw-r--r--src/php/ext/grpc/php7_wrapper.h18
-rw-r--r--src/php/ext/grpc/server.c32
-rw-r--r--src/php/ext/grpc/server_credentials.c26
-rwxr-xr-xsrc/php/ext/grpc/server_credentials.h4
-rw-r--r--src/php/ext/grpc/timeval.c17
11 files changed, 67 insertions, 141 deletions
diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c
index fc832dacc2..add6841039 100644
--- a/src/php/ext/grpc/call.c
+++ b/src/php/ext/grpc/call.c
@@ -59,17 +59,14 @@
zend_class_entry *grpc_ce_call;
-#if PHP_MAJOR_VERSION < 7
-
/* Frees and destroys an instance of wrapped_grpc_call */
-void free_wrapped_grpc_call(void *object TSRMLS_DC) {
- wrapped_grpc_call *call = (wrapped_grpc_call *)object;
- if (call->owned && call->wrapped != NULL) {
- grpc_call_destroy(call->wrapped);
+PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_call)
+ if (p->owned && p->wrapped != NULL) {
+ grpc_call_destroy(p->wrapped);
}
- zend_object_std_dtor(&call->std TSRMLS_CC);
- efree(call);
-}
+PHP_GRPC_FREE_WRAPPED_FUNC_END()
+
+#if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_call to be associated with an object
* of a class specified by class_type */
@@ -94,15 +91,6 @@ zend_object_value create_wrapped_grpc_call(zend_class_entry *class_type
static zend_object_handlers call_ce_handlers;
-/* Frees and destroys an instance of wrapped_grpc_call */
-static void free_wrapped_grpc_call(zend_object *object) {
- wrapped_grpc_call *call = wrapped_grpc_call_from_obj(object);
- if (call->owned && call->wrapped != NULL) {
- grpc_call_destroy(call->wrapped);
- }
- zend_object_std_dtor(&call->std);
-}
-
/* Initializes an instance of wrapped_grpc_call to be associated with an
* object of a class specified by class_type */
zend_object *create_wrapped_grpc_call(zend_class_entry *class_type) {
diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c
index 29762afb29..aa589b0387 100644
--- a/src/php/ext/grpc/call_credentials.c
+++ b/src/php/ext/grpc/call_credentials.c
@@ -53,18 +53,14 @@
zend_class_entry *grpc_ce_call_credentials;
-#if PHP_MAJOR_VERSION < 7
-
/* Frees and destroys an instance of wrapped_grpc_call_credentials */
-void free_wrapped_grpc_call_credentials(void *object TSRMLS_DC) {
- wrapped_grpc_call_credentials *creds =
- (wrapped_grpc_call_credentials *)object;
- if (creds->wrapped != NULL) {
- grpc_call_credentials_release(creds->wrapped);
+PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_call_credentials)
+ if (p->wrapped != NULL) {
+ grpc_call_credentials_release(p->wrapped);
}
- zend_object_std_dtor(&creds->std TSRMLS_CC);
- efree(creds);
-}
+PHP_GRPC_FREE_WRAPPED_FUNC_END()
+
+#if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_call_credentials to be
* associated with an object of a class specified by class_type */
@@ -90,16 +86,6 @@ zend_object_value create_wrapped_grpc_call_credentials(
static zend_object_handlers call_credentials_ce_handlers;
-/* Frees and destroys an instance of wrapped_grpc_call_credentials */
-static void free_wrapped_grpc_call_credentials(zend_object *object) {
- wrapped_grpc_call_credentials *creds =
- wrapped_grpc_call_creds_from_obj(object);
- if (creds->wrapped != NULL) {
- grpc_call_credentials_release(creds->wrapped);
- }
- zend_object_std_dtor(&creds->std);
-}
-
/* Initializes an instance of wrapped_grpc_call_credentials to be
* associated with an object of a class specified by class_type */
zend_object *create_wrapped_grpc_call_credentials(zend_class_entry
diff --git a/src/php/ext/grpc/call_credentials.h b/src/php/ext/grpc/call_credentials.h
index 822d077ccb..8014b75c70 100755
--- a/src/php/ext/grpc/call_credentials.h
+++ b/src/php/ext/grpc/call_credentials.h
@@ -63,7 +63,7 @@ PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_call_credentials)
#else
static inline wrapped_grpc_call_credentials
-*wrapped_grpc_call_creds_from_obj(zend_object *obj) {
+*wrapped_grpc_call_credentials_from_obj(zend_object *obj) {
return
(wrapped_grpc_call_credentials*)((char*)(obj) -
XtOffsetOf(wrapped_grpc_call_credentials,
@@ -71,7 +71,7 @@ static inline wrapped_grpc_call_credentials
}
#define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \
- wrapped_grpc_call_creds_from_obj(Z_OBJ_P((zv)))
+ wrapped_grpc_call_credentials_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */
diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c
index 18ebcabc26..9c4b265e94 100644
--- a/src/php/ext/grpc/channel.c
+++ b/src/php/ext/grpc/channel.c
@@ -57,17 +57,14 @@
zend_class_entry *grpc_ce_channel;
-#if PHP_MAJOR_VERSION < 7
-
/* Frees and destroys an instance of wrapped_grpc_channel */
-void free_wrapped_grpc_channel(void *object TSRMLS_DC) {
- wrapped_grpc_channel *channel = (wrapped_grpc_channel *)object;
- if (channel->wrapped != NULL) {
- grpc_channel_destroy(channel->wrapped);
+PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_channel)
+ if (p->wrapped != NULL) {
+ grpc_channel_destroy(p->wrapped);
}
- zend_object_std_dtor(&channel->std TSRMLS_CC);
- efree(channel);
-}
+PHP_GRPC_FREE_WRAPPED_FUNC_END()
+
+#if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_channel to be associated with an
* object of a class specified by class_type */
@@ -90,15 +87,6 @@ zend_object_value create_wrapped_grpc_channel(zend_class_entry *class_type
static zend_object_handlers channel_ce_handlers;
-/* Frees and destroys an instance of wrapped_grpc_channel */
-static void free_wrapped_grpc_channel(zend_object *object) {
- wrapped_grpc_channel *channel = wrapped_grpc_channel_from_obj(object);
- if (channel->wrapped != NULL) {
- grpc_channel_destroy(channel->wrapped);
- }
- zend_object_std_dtor(&channel->std);
-}
-
/* Initializes an instance of wrapped_grpc_channel to be associated with an
* object of a class specified by class_type */
zend_object *create_wrapped_grpc_channel(zend_class_entry *class_type) {
diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c
index 1c2ea5ba82..938134cd9c 100644
--- a/src/php/ext/grpc/channel_credentials.c
+++ b/src/php/ext/grpc/channel_credentials.c
@@ -63,18 +63,14 @@ static grpc_ssl_roots_override_result get_ssl_roots_override(
return GRPC_SSL_ROOTS_OVERRIDE_OK;
}
-#if PHP_MAJOR_VERSION < 7
-
/* Frees and destroys an instance of wrapped_grpc_channel_credentials */
-void free_wrapped_grpc_channel_credentials(void *object TSRMLS_DC) {
- wrapped_grpc_channel_credentials *creds =
- (wrapped_grpc_channel_credentials *)object;
- if (creds->wrapped != NULL) {
- grpc_channel_credentials_release(creds->wrapped);
+PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_channel_credentials)
+ if (p->wrapped != NULL) {
+ grpc_channel_credentials_release(p->wrapped);
}
- zend_object_std_dtor(&creds->std TSRMLS_CC);
- efree(creds);
-}
+PHP_GRPC_FREE_WRAPPED_FUNC_END()
+
+#if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_channel_credentials to be
* associated with an object of a class specified by class_type */
@@ -100,16 +96,6 @@ zend_object_value create_wrapped_grpc_channel_credentials(
static zend_object_handlers channel_credentials_ce_handlers;
-/* Frees and destroys an instance of wrapped_grpc_channel_credentials */
-static void free_wrapped_grpc_channel_credentials(zend_object *object) {
- wrapped_grpc_channel_credentials *creds =
- wrapped_grpc_channel_creds_from_obj(object);
- if (creds->wrapped != NULL) {
- grpc_channel_credentials_release(creds->wrapped);
- }
- zend_object_std_dtor(&creds->std);
-}
-
/* Initializes an instance of wrapped_grpc_channel_credentials to be
* associated with an object of a class specified by class_type */
zend_object *create_wrapped_grpc_channel_credentials(zend_class_entry
diff --git a/src/php/ext/grpc/channel_credentials.h b/src/php/ext/grpc/channel_credentials.h
index 21225db5fb..39dc85283d 100755
--- a/src/php/ext/grpc/channel_credentials.h
+++ b/src/php/ext/grpc/channel_credentials.h
@@ -63,15 +63,14 @@ PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_channel_credentials)
#else
static inline wrapped_grpc_channel_credentials
-*wrapped_grpc_channel_creds_from_obj(zend_object *obj) {
+*wrapped_grpc_channel_credentials_from_obj(zend_object *obj) {
return
(wrapped_grpc_channel_credentials *)
- ((char*)(obj) -
- XtOffsetOf(wrapped_grpc_channel_credentials, std));
+ ((char*)(obj) - XtOffsetOf(wrapped_grpc_channel_credentials, std));
}
#define Z_WRAPPED_GRPC_CHANNEL_CREDS_P(zv) \
- wrapped_grpc_channel_creds_from_obj(Z_OBJ_P((zv)))
+ wrapped_grpc_channel_credentials_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */
diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h
index 58dffc38dc..868432eb33 100644
--- a/src/php/ext/grpc/php7_wrapper.h
+++ b/src/php/ext/grpc/php7_wrapper.h
@@ -56,6 +56,14 @@
#define PHP_GRPC_WRAP_OBJECT_END(name) \
} name;
+#define PHP_GRPC_FREE_WRAPPED_FUNC_START(klass) \
+ void free_##klass(void *object TSRMLS_DC) { \
+ klass *p = (klass *)object;
+#define PHP_GRPC_FREE_WRAPPED_FUNC_END() \
+ zend_object_std_dtor(&p->std TSRMLS_CC); \
+ efree(p); \
+ }
+
#else
#define php_grpc_int size_t
@@ -79,6 +87,16 @@
zend_object std; \
} name;
+#define WRAPPED_OBJECT_FROM_OBJ(klass, obj) \
+ klass##_from_obj(obj);
+
+#define PHP_GRPC_FREE_WRAPPED_FUNC_START(klass) \
+ static void free_##klass(zend_object *object) { \
+ klass *p = WRAPPED_OBJECT_FROM_OBJ(klass, object)
+#define PHP_GRPC_FREE_WRAPPED_FUNC_END() \
+ zend_object_std_dtor(&p->std); \
+ }
+
#endif /* PHP_MAJOR_VERSION */
#endif /* PHP7_WRAPPER_GRPC_H */
diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c
index 577b707089..dc815f4d7c 100644
--- a/src/php/ext/grpc/server.c
+++ b/src/php/ext/grpc/server.c
@@ -58,21 +58,18 @@
zend_class_entry *grpc_ce_server;
-#if PHP_MAJOR_VERSION < 7
-
/* Frees and destroys an instance of wrapped_grpc_server */
-void free_wrapped_grpc_server(void *object TSRMLS_DC) {
- wrapped_grpc_server *server = (wrapped_grpc_server *)object;
- if (server->wrapped != NULL) {
- grpc_server_shutdown_and_notify(server->wrapped, completion_queue, NULL);
- grpc_server_cancel_all_calls(server->wrapped);
+PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_server)
+ if (p->wrapped != NULL) {
+ grpc_server_shutdown_and_notify(p->wrapped, completion_queue, NULL);
+ grpc_server_cancel_all_calls(p->wrapped);
grpc_completion_queue_pluck(completion_queue, NULL,
gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
- grpc_server_destroy(server->wrapped);
+ grpc_server_destroy(p->wrapped);
}
- zend_object_std_dtor(&server->std TSRMLS_CC);
- efree(server);
-}
+PHP_GRPC_FREE_WRAPPED_FUNC_END()
+
+#if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_call to be associated with an object
* of a class specified by class_type */
@@ -97,19 +94,6 @@ zend_object_value create_wrapped_grpc_server(zend_class_entry *class_type
static zend_object_handlers server_ce_handlers;
-/* Frees and destroys an instance of wrapped_grpc_server */
-static void free_wrapped_grpc_server(zend_object *object) {
- wrapped_grpc_server *server = wrapped_grpc_server_from_obj(object);
- if (server->wrapped != NULL) {
- grpc_server_shutdown_and_notify(server->wrapped, completion_queue, NULL);
- grpc_server_cancel_all_calls(server->wrapped);
- grpc_completion_queue_pluck(completion_queue, NULL,
- gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
- grpc_server_destroy(server->wrapped);
- }
- zend_object_std_dtor(&server->std);
-}
-
/* Initializes an instance of wrapped_grpc_call to be associated with an object
* of a class specified by class_type */
zend_object *create_wrapped_grpc_server(zend_class_entry *class_type) {
diff --git a/src/php/ext/grpc/server_credentials.c b/src/php/ext/grpc/server_credentials.c
index 46416f5b47..b1471d06e2 100644
--- a/src/php/ext/grpc/server_credentials.c
+++ b/src/php/ext/grpc/server_credentials.c
@@ -51,18 +51,14 @@
zend_class_entry *grpc_ce_server_credentials;
-#if PHP_MAJOR_VERSION < 7
-
/* Frees and destroys an instace of wrapped_grpc_server_credentials */
-void free_wrapped_grpc_server_credentials(void *object TSRMLS_DC) {
- wrapped_grpc_server_credentials *creds =
- (wrapped_grpc_server_credentials *)object;
- if (creds->wrapped != NULL) {
- grpc_server_credentials_release(creds->wrapped);
+PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_server_credentials)
+ if (p->wrapped != NULL) {
+ grpc_server_credentials_release(p->wrapped);
}
- zend_object_std_dtor(&creds->std TSRMLS_CC);
- efree(creds);
-}
+PHP_GRPC_FREE_WRAPPED_FUNC_END()
+
+#if PHP_MAJOR_VERSION < 7
/* Initializes an instace of wrapped_grpc_server_credentials to be associated
* with an object of a class specified by class_type */
@@ -88,16 +84,6 @@ zend_object_value create_wrapped_grpc_server_credentials(
static zend_object_handlers server_credentials_ce_handlers;
-/* Frees and destroys an instace of wrapped_grpc_server_credentials */
-static void free_wrapped_grpc_server_credentials(zend_object *object) {
- wrapped_grpc_server_credentials *creds =
- wrapped_grpc_server_creds_from_obj(object);
- if (creds->wrapped != NULL) {
- grpc_server_credentials_release(creds->wrapped);
- }
- zend_object_std_dtor(&creds->std);
-}
-
/* Initializes an instace of wrapped_grpc_server_credentials to be associated
* with an object of a class specified by class_type */
zend_object *create_wrapped_grpc_server_credentials(zend_class_entry
diff --git a/src/php/ext/grpc/server_credentials.h b/src/php/ext/grpc/server_credentials.h
index 2a90aa69a2..9551ec6c24 100755
--- a/src/php/ext/grpc/server_credentials.h
+++ b/src/php/ext/grpc/server_credentials.h
@@ -63,13 +63,13 @@ PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_server_credentials)
#else
static inline wrapped_grpc_server_credentials
-*wrapped_grpc_server_creds_from_obj(zend_object *obj) {
+*wrapped_grpc_server_credentials_from_obj(zend_object *obj) {
return (wrapped_grpc_server_credentials*)
((char*)(obj) - XtOffsetOf(wrapped_grpc_server_credentials, std));
}
#define Z_WRAPPED_GRPC_SERVER_CREDS_P(zv) \
- wrapped_grpc_server_creds_from_obj(Z_OBJ_P((zv)))
+ wrapped_grpc_server_credentials_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */
diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c
index 7d1ee2178a..e19bfe1565 100644
--- a/src/php/ext/grpc/timeval.c
+++ b/src/php/ext/grpc/timeval.c
@@ -52,14 +52,11 @@
zend_class_entry *grpc_ce_timeval;
-#if PHP_MAJOR_VERSION < 7
-
/* Frees and destroys an instance of wrapped_grpc_call */
-void free_wrapped_grpc_timeval(void *object TSRMLS_DC) {
- wrapped_grpc_timeval *timeval = (wrapped_grpc_timeval *)object;
- zend_object_std_dtor(&timeval->std TSRMLS_CC);
- efree(timeval);
-}
+PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_timeval)
+PHP_GRPC_FREE_WRAPPED_FUNC_END()
+
+#if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_timeval to be associated with an
* object of a class specified by class_type */
@@ -82,12 +79,6 @@ zend_object_value create_wrapped_grpc_timeval(zend_class_entry *class_type
static zend_object_handlers timeval_ce_handlers;
-/* Frees and destroys an instance of wrapped_grpc_call */
-static void free_wrapped_grpc_timeval(zend_object *object) {
- wrapped_grpc_timeval *timeval = wrapped_grpc_timeval_from_obj(object);
- zend_object_std_dtor(&timeval->std);
-}
-
/* Initializes an instance of wrapped_grpc_timeval to be associated with an
* object of a class specified by class_type */
zend_object *create_wrapped_grpc_timeval(zend_class_entry *class_type) {