add macro to php7_wrapper for reduce duplicate code

pull/7543/head
thinkerou 8 years ago
parent ee70fa7022
commit d2583007f5
  1. 24
      src/php/ext/grpc/call.c
  2. 26
      src/php/ext/grpc/call_credentials.c
  3. 4
      src/php/ext/grpc/call_credentials.h
  4. 24
      src/php/ext/grpc/channel.c
  5. 26
      src/php/ext/grpc/channel_credentials.c
  6. 7
      src/php/ext/grpc/channel_credentials.h
  7. 18
      src/php/ext/grpc/php7_wrapper.h
  8. 32
      src/php/ext/grpc/server.c
  9. 26
      src/php/ext/grpc/server_credentials.c
  10. 4
      src/php/ext/grpc/server_credentials.h
  11. 17
      src/php/ext/grpc/timeval.c

@ -59,17 +59,14 @@
zend_class_entry *grpc_ce_call; zend_class_entry *grpc_ce_call;
#if PHP_MAJOR_VERSION < 7
/* Frees and destroys an instance of wrapped_grpc_call */ /* Frees and destroys an instance of wrapped_grpc_call */
void free_wrapped_grpc_call(void *object TSRMLS_DC) { PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_call)
wrapped_grpc_call *call = (wrapped_grpc_call *)object; if (p->owned && p->wrapped != NULL) {
if (call->owned && call->wrapped != NULL) { grpc_call_destroy(p->wrapped);
grpc_call_destroy(call->wrapped);
} }
zend_object_std_dtor(&call->std TSRMLS_CC); PHP_GRPC_FREE_WRAPPED_FUNC_END()
efree(call);
} #if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_call to be associated with an object /* Initializes an instance of wrapped_grpc_call to be associated with an object
* of a class specified by class_type */ * 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; 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 /* Initializes an instance of wrapped_grpc_call to be associated with an
* object of a class specified by class_type */ * object of a class specified by class_type */
zend_object *create_wrapped_grpc_call(zend_class_entry *class_type) { zend_object *create_wrapped_grpc_call(zend_class_entry *class_type) {

@ -53,18 +53,14 @@
zend_class_entry *grpc_ce_call_credentials; zend_class_entry *grpc_ce_call_credentials;
#if PHP_MAJOR_VERSION < 7
/* Frees and destroys an instance of wrapped_grpc_call_credentials */ /* Frees and destroys an instance of wrapped_grpc_call_credentials */
void free_wrapped_grpc_call_credentials(void *object TSRMLS_DC) { PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_call_credentials)
wrapped_grpc_call_credentials *creds = if (p->wrapped != NULL) {
(wrapped_grpc_call_credentials *)object; grpc_call_credentials_release(p->wrapped);
if (creds->wrapped != NULL) {
grpc_call_credentials_release(creds->wrapped);
} }
zend_object_std_dtor(&creds->std TSRMLS_CC); PHP_GRPC_FREE_WRAPPED_FUNC_END()
efree(creds);
} #if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_call_credentials to be /* Initializes an instance of wrapped_grpc_call_credentials to be
* associated with an object of a class specified by class_type */ * 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; 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 /* Initializes an instance of wrapped_grpc_call_credentials to be
* associated with an object of a class specified by class_type */ * associated with an object of a class specified by class_type */
zend_object *create_wrapped_grpc_call_credentials(zend_class_entry zend_object *create_wrapped_grpc_call_credentials(zend_class_entry

@ -63,7 +63,7 @@ PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_call_credentials)
#else #else
static inline wrapped_grpc_call_credentials 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 return
(wrapped_grpc_call_credentials*)((char*)(obj) - (wrapped_grpc_call_credentials*)((char*)(obj) -
XtOffsetOf(wrapped_grpc_call_credentials, XtOffsetOf(wrapped_grpc_call_credentials,
@ -71,7 +71,7 @@ static inline wrapped_grpc_call_credentials
} }
#define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \ #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 */ #endif /* PHP_MAJOR_VERSION */

@ -57,17 +57,14 @@
zend_class_entry *grpc_ce_channel; zend_class_entry *grpc_ce_channel;
#if PHP_MAJOR_VERSION < 7
/* Frees and destroys an instance of wrapped_grpc_channel */ /* Frees and destroys an instance of wrapped_grpc_channel */
void free_wrapped_grpc_channel(void *object TSRMLS_DC) { PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_channel)
wrapped_grpc_channel *channel = (wrapped_grpc_channel *)object; if (p->wrapped != NULL) {
if (channel->wrapped != NULL) { grpc_channel_destroy(p->wrapped);
grpc_channel_destroy(channel->wrapped);
} }
zend_object_std_dtor(&channel->std TSRMLS_CC); PHP_GRPC_FREE_WRAPPED_FUNC_END()
efree(channel);
} #if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_channel to be associated with an /* Initializes an instance of wrapped_grpc_channel to be associated with an
* object of a class specified by class_type */ * 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; 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 /* Initializes an instance of wrapped_grpc_channel to be associated with an
* object of a class specified by class_type */ * object of a class specified by class_type */
zend_object *create_wrapped_grpc_channel(zend_class_entry *class_type) { zend_object *create_wrapped_grpc_channel(zend_class_entry *class_type) {

@ -63,18 +63,14 @@ static grpc_ssl_roots_override_result get_ssl_roots_override(
return GRPC_SSL_ROOTS_OVERRIDE_OK; return GRPC_SSL_ROOTS_OVERRIDE_OK;
} }
#if PHP_MAJOR_VERSION < 7
/* Frees and destroys an instance of wrapped_grpc_channel_credentials */ /* Frees and destroys an instance of wrapped_grpc_channel_credentials */
void free_wrapped_grpc_channel_credentials(void *object TSRMLS_DC) { PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_channel_credentials)
wrapped_grpc_channel_credentials *creds = if (p->wrapped != NULL) {
(wrapped_grpc_channel_credentials *)object; grpc_channel_credentials_release(p->wrapped);
if (creds->wrapped != NULL) {
grpc_channel_credentials_release(creds->wrapped);
} }
zend_object_std_dtor(&creds->std TSRMLS_CC); PHP_GRPC_FREE_WRAPPED_FUNC_END()
efree(creds);
} #if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_channel_credentials to be /* Initializes an instance of wrapped_grpc_channel_credentials to be
* associated with an object of a class specified by class_type */ * 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; 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 /* Initializes an instance of wrapped_grpc_channel_credentials to be
* associated with an object of a class specified by class_type */ * associated with an object of a class specified by class_type */
zend_object *create_wrapped_grpc_channel_credentials(zend_class_entry zend_object *create_wrapped_grpc_channel_credentials(zend_class_entry

@ -63,15 +63,14 @@ PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_channel_credentials)
#else #else
static inline wrapped_grpc_channel_credentials 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 return
(wrapped_grpc_channel_credentials *) (wrapped_grpc_channel_credentials *)
((char*)(obj) - ((char*)(obj) - XtOffsetOf(wrapped_grpc_channel_credentials, std));
XtOffsetOf(wrapped_grpc_channel_credentials, std));
} }
#define Z_WRAPPED_GRPC_CHANNEL_CREDS_P(zv) \ #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 */ #endif /* PHP_MAJOR_VERSION */

@ -56,6 +56,14 @@
#define PHP_GRPC_WRAP_OBJECT_END(name) \ #define PHP_GRPC_WRAP_OBJECT_END(name) \
} 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 #else
#define php_grpc_int size_t #define php_grpc_int size_t
@ -79,6 +87,16 @@
zend_object std; \ zend_object std; \
} name; } 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 /* PHP_MAJOR_VERSION */
#endif /* PHP7_WRAPPER_GRPC_H */ #endif /* PHP7_WRAPPER_GRPC_H */

@ -58,21 +58,18 @@
zend_class_entry *grpc_ce_server; zend_class_entry *grpc_ce_server;
#if PHP_MAJOR_VERSION < 7
/* Frees and destroys an instance of wrapped_grpc_server */ /* Frees and destroys an instance of wrapped_grpc_server */
void free_wrapped_grpc_server(void *object TSRMLS_DC) { PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_server)
wrapped_grpc_server *server = (wrapped_grpc_server *)object; if (p->wrapped != NULL) {
if (server->wrapped != NULL) { grpc_server_shutdown_and_notify(p->wrapped, completion_queue, NULL);
grpc_server_shutdown_and_notify(server->wrapped, completion_queue, NULL); grpc_server_cancel_all_calls(p->wrapped);
grpc_server_cancel_all_calls(server->wrapped);
grpc_completion_queue_pluck(completion_queue, NULL, grpc_completion_queue_pluck(completion_queue, NULL,
gpr_inf_future(GPR_CLOCK_REALTIME), 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); PHP_GRPC_FREE_WRAPPED_FUNC_END()
efree(server);
} #if PHP_MAJOR_VERSION < 7
/* Initializes an instance of wrapped_grpc_call to be associated with an object /* Initializes an instance of wrapped_grpc_call to be associated with an object
* of a class specified by class_type */ * 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; 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 /* Initializes an instance of wrapped_grpc_call to be associated with an object
* of a class specified by class_type */ * of a class specified by class_type */
zend_object *create_wrapped_grpc_server(zend_class_entry *class_type) { zend_object *create_wrapped_grpc_server(zend_class_entry *class_type) {

@ -51,18 +51,14 @@
zend_class_entry *grpc_ce_server_credentials; zend_class_entry *grpc_ce_server_credentials;
#if PHP_MAJOR_VERSION < 7
/* Frees and destroys an instace of wrapped_grpc_server_credentials */ /* Frees and destroys an instace of wrapped_grpc_server_credentials */
void free_wrapped_grpc_server_credentials(void *object TSRMLS_DC) { PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_server_credentials)
wrapped_grpc_server_credentials *creds = if (p->wrapped != NULL) {
(wrapped_grpc_server_credentials *)object; grpc_server_credentials_release(p->wrapped);
if (creds->wrapped != NULL) {
grpc_server_credentials_release(creds->wrapped);
} }
zend_object_std_dtor(&creds->std TSRMLS_CC); PHP_GRPC_FREE_WRAPPED_FUNC_END()
efree(creds);
} #if PHP_MAJOR_VERSION < 7
/* Initializes an instace of wrapped_grpc_server_credentials to be associated /* Initializes an instace of wrapped_grpc_server_credentials to be associated
* with an object of a class specified by class_type */ * 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; 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 /* Initializes an instace of wrapped_grpc_server_credentials to be associated
* with an object of a class specified by class_type */ * with an object of a class specified by class_type */
zend_object *create_wrapped_grpc_server_credentials(zend_class_entry zend_object *create_wrapped_grpc_server_credentials(zend_class_entry

@ -63,13 +63,13 @@ PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_server_credentials)
#else #else
static inline wrapped_grpc_server_credentials 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*) return (wrapped_grpc_server_credentials*)
((char*)(obj) - XtOffsetOf(wrapped_grpc_server_credentials, std)); ((char*)(obj) - XtOffsetOf(wrapped_grpc_server_credentials, std));
} }
#define Z_WRAPPED_GRPC_SERVER_CREDS_P(zv) \ #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 */ #endif /* PHP_MAJOR_VERSION */

@ -52,14 +52,11 @@
zend_class_entry *grpc_ce_timeval; zend_class_entry *grpc_ce_timeval;
#if PHP_MAJOR_VERSION < 7
/* Frees and destroys an instance of wrapped_grpc_call */ /* Frees and destroys an instance of wrapped_grpc_call */
void free_wrapped_grpc_timeval(void *object TSRMLS_DC) { PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_timeval)
wrapped_grpc_timeval *timeval = (wrapped_grpc_timeval *)object; PHP_GRPC_FREE_WRAPPED_FUNC_END()
zend_object_std_dtor(&timeval->std TSRMLS_CC);
efree(timeval); #if PHP_MAJOR_VERSION < 7
}
/* Initializes an instance of wrapped_grpc_timeval to be associated with an /* Initializes an instance of wrapped_grpc_timeval to be associated with an
* object of a class specified by class_type */ * 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; 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 /* Initializes an instance of wrapped_grpc_timeval to be associated with an
* object of a class specified by class_type */ * object of a class specified by class_type */
zend_object *create_wrapped_grpc_timeval(zend_class_entry *class_type) { zend_object *create_wrapped_grpc_timeval(zend_class_entry *class_type) {

Loading…
Cancel
Save