aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar thinkerou <thinkerou@gmail.com>2016-07-28 22:43:38 +0800
committerGravatar thinkerou <thinkerou@gmail.com>2016-07-28 22:43:38 +0800
commit5dafd82b7ef99952889e0e862aac38b80595b15e (patch)
tree9603a9ad666a0946408a3b5a67c86b2f348f7be8
parent514d296a5d463252dccf6d75a2c1cfed385eb07a (diff)
add macro PHP_GRPC_INIT_HANDLER
-rw-r--r--src/php/ext/grpc/call.c20
-rw-r--r--src/php/ext/grpc/call_credentials.c11
-rwxr-xr-xsrc/php/ext/grpc/call_credentials.h6
-rw-r--r--src/php/ext/grpc/channel.c8
-rw-r--r--src/php/ext/grpc/channel_credentials.c11
-rwxr-xr-xsrc/php/ext/grpc/channel_credentials.h5
-rw-r--r--src/php/ext/grpc/php7_wrapper.h11
-rw-r--r--src/php/ext/grpc/server.c9
-rwxr-xr-xsrc/php/ext/grpc/server.h3
-rw-r--r--src/php/ext/grpc/server_credentials.c13
-rwxr-xr-xsrc/php/ext/grpc/server_credentials.h4
-rw-r--r--src/php/ext/grpc/timeval.c8
12 files changed, 34 insertions, 75 deletions
diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c
index 840ac71364..429dbf52d0 100644
--- a/src/php/ext/grpc/call.c
+++ b/src/php/ext/grpc/call.c
@@ -105,8 +105,8 @@ zval *grpc_parse_metadata_array(grpc_metadata_array
memcpy(str_key, elem->key, key_len);
str_val = ecalloc(elem->value_length + 1, sizeof(char));
memcpy(str_val, elem->value, elem->value_length);
- if (php_grpc_zend_hash_find(array_hash, str_key, key_len, (void **)&data) ==
- SUCCESS) {
+ if (php_grpc_zend_hash_find(array_hash, str_key, key_len, (void **)&data)
+ == SUCCESS) {
if (Z_TYPE_P(data) != IS_ARRAY) {
zend_throw_exception(zend_exception_get_default(TSRMLS_C),
"Metadata hash somehow contains wrong types.",
@@ -271,7 +271,6 @@ PHP_METHOD(Call, startBatch) {
char *message_str;
size_t message_len;
-
grpc_metadata_array_init(&metadata);
grpc_metadata_array_init(&trailing_metadata);
grpc_metadata_array_init(&recv_metadata);
@@ -291,7 +290,7 @@ PHP_METHOD(Call, startBatch) {
char *key = NULL;
int key_type;
PHP_GRPC_HASH_FOREACH_LONG_KEY_VAL_START(array_hash, key, key_type, index,
- value)
+ value)
if (key_type != HASH_KEY_IS_LONG || key != NULL) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"batch keys must be integers", 1 TSRMLS_CC);
@@ -304,10 +303,8 @@ PHP_METHOD(Call, startBatch) {
"Bad metadata value given", 1 TSRMLS_CC);
goto cleanup;
}
- ops[op_num].data.send_initial_metadata.count =
- metadata.count;
- ops[op_num].data.send_initial_metadata.metadata =
- metadata.metadata;
+ ops[op_num].data.send_initial_metadata.count = metadata.count;
+ ops[op_num].data.send_initial_metadata.metadata = metadata.metadata;
break;
case GRPC_OP_SEND_MESSAGE:
if (Z_TYPE_P(value) != IS_ARRAY) {
@@ -562,10 +559,5 @@ void grpc_init_call(TSRMLS_D) {
INIT_CLASS_ENTRY(ce, "Grpc\\Call", call_methods);
ce.create_object = create_wrapped_grpc_call;
grpc_ce_call = zend_register_internal_class(&ce TSRMLS_CC);
-#if PHP_MAJOR_VERSION >= 7
- memcpy(&call_ce_handlers, zend_get_std_object_handlers(),
- sizeof(zend_object_handlers));
- call_ce_handlers.offset = XtOffsetOf(wrapped_grpc_call, std);
- call_ce_handlers.free_obj = free_wrapped_grpc_call;
-#endif
+ PHP_GRPC_INIT_HANDLER(wrapped_grpc_call, call_ce_handlers);
}
diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c
index 34a88af47f..6921a5df17 100644
--- a/src/php/ext/grpc/call_credentials.c
+++ b/src/php/ext/grpc/call_credentials.c
@@ -235,13 +235,6 @@ void grpc_init_call_credentials(TSRMLS_D) {
INIT_CLASS_ENTRY(ce, "Grpc\\CallCredentials", call_credentials_methods);
ce.create_object = create_wrapped_grpc_call_credentials;
grpc_ce_call_credentials = zend_register_internal_class(&ce TSRMLS_CC);
-#if PHP_MAJOR_VERSION >= 7
- memcpy(&call_credentials_ce_handlers,
- zend_get_std_object_handlers(),
- sizeof(zend_object_handlers));
- call_credentials_ce_handlers.offset =
- XtOffsetOf(wrapped_grpc_call_credentials, std);
- call_credentials_ce_handlers.free_obj =
- free_wrapped_grpc_call_credentials;
-#endif
+ PHP_GRPC_INIT_HANDLER(wrapped_grpc_call_credentials,
+ call_credentials_ce_handlers);
}
diff --git a/src/php/ext/grpc/call_credentials.h b/src/php/ext/grpc/call_credentials.h
index 8014b75c70..c1d85c0fb2 100755
--- a/src/php/ext/grpc/call_credentials.h
+++ b/src/php/ext/grpc/call_credentials.h
@@ -64,10 +64,8 @@ PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_call_credentials)
static inline wrapped_grpc_call_credentials
*wrapped_grpc_call_credentials_from_obj(zend_object *obj) {
- return
- (wrapped_grpc_call_credentials*)((char*)(obj) -
- XtOffsetOf(wrapped_grpc_call_credentials,
- std));
+ return (wrapped_grpc_call_credentials*)(
+ (char*)(obj) - XtOffsetOf(wrapped_grpc_call_credentials, std));
}
#define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \
diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c
index 1d3f68af7c..e96ead582f 100644
--- a/src/php/ext/grpc/channel.c
+++ b/src/php/ext/grpc/channel.c
@@ -256,11 +256,5 @@ void grpc_init_channel(TSRMLS_D) {
INIT_CLASS_ENTRY(ce, "Grpc\\Channel", channel_methods);
ce.create_object = create_wrapped_grpc_channel;
grpc_ce_channel = zend_register_internal_class(&ce TSRMLS_CC);
-#if PHP_MAJOR_VERSION >= 7
- memcpy(&channel_ce_handlers, zend_get_std_object_handlers(),
- sizeof(zend_object_handlers));
- channel_ce_handlers.offset =
- XtOffsetOf(wrapped_grpc_channel, std);
- channel_ce_handlers.free_obj = free_wrapped_grpc_channel;
-#endif
+ PHP_GRPC_INIT_HANDLER(wrapped_grpc_channel, channel_ce_handlers);
}
diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c
index 7ef95cc5e2..0b356aa25f 100644
--- a/src/php/ext/grpc/channel_credentials.c
+++ b/src/php/ext/grpc/channel_credentials.c
@@ -226,13 +226,6 @@ void grpc_init_channel_credentials(TSRMLS_D) {
grpc_set_ssl_roots_override_callback(get_ssl_roots_override);
ce.create_object = create_wrapped_grpc_channel_credentials;
grpc_ce_channel_credentials = zend_register_internal_class(&ce TSRMLS_CC);
-#if PHP_MAJOR_VERSION >= 7
- memcpy(&channel_credentials_ce_handlers,
- zend_get_std_object_handlers(),
- sizeof(zend_object_handlers));
- channel_credentials_ce_handlers.offset =
- XtOffsetOf(wrapped_grpc_channel_credentials, std);
- channel_credentials_ce_handlers.free_obj =
- free_wrapped_grpc_channel_credentials;
-#endif
+ PHP_GRPC_INIT_HANDLER(wrapped_grpc_channel_credentials,
+ channel_credentials_ce_handlers);
}
diff --git a/src/php/ext/grpc/channel_credentials.h b/src/php/ext/grpc/channel_credentials.h
index 39dc85283d..b043d91fa6 100755
--- a/src/php/ext/grpc/channel_credentials.h
+++ b/src/php/ext/grpc/channel_credentials.h
@@ -64,9 +64,8 @@ PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_channel_credentials)
static inline wrapped_grpc_channel_credentials
*wrapped_grpc_channel_credentials_from_obj(zend_object *obj) {
- return
- (wrapped_grpc_channel_credentials *)
- ((char*)(obj) - XtOffsetOf(wrapped_grpc_channel_credentials, std));
+ return (wrapped_grpc_channel_credentials *)(
+ (char*)(obj) - XtOffsetOf(wrapped_grpc_channel_credentials, std));
}
#define Z_WRAPPED_GRPC_CHANNEL_CREDS_P(zv) \
diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h
index 44d6cd8dd7..f2976c26cd 100644
--- a/src/php/ext/grpc/php7_wrapper.h
+++ b/src/php/ext/grpc/php7_wrapper.h
@@ -125,6 +125,8 @@ static inline int php_grpc_zend_hash_find(HashTable *ht, char *key, int len, voi
#define PHP_GRPC_GET_CLASS_ENTRY(object) zend_get_class_entry(object TSRMLS_CC)
+#define PHP_GRPC_INIT_HANDLER(class_object, handler_name)
+
#else
#define php_grpc_int size_t
@@ -187,7 +189,8 @@ static inline int php_grpc_zend_hash_find(HashTable *ht, char *key, int len, voi
#define PHP_GRPC_HASH_FOREACH_END() } ZEND_HASH_FOREACH_END();
-static inline int php_grpc_zend_hash_find(HashTable *ht, char *key, int len, void **value) {
+static inline int php_grpc_zend_hash_find(HashTable *ht, char *key, int len,
+ void **value) {
zval *value_tmp = zend_hash_str_find(ht, key, len -1);
if (value_tmp == NULL) {
return FAILURE;
@@ -203,6 +206,12 @@ static inline int php_grpc_zend_hash_del(HashTable *ht, char *key, int len) {
#define PHP_GRPC_GET_CLASS_ENTRY(object) Z_OBJ_P(object)->ce
+#define PHP_GRPC_INIT_HANDLER(class_object, handler_name) \
+ memcpy(&handler_name, zend_get_std_object_handlers(), \
+ sizeof(zend_object_handlers)); \
+ handler_name.offset = XtOffsetOf(class_object, std); \
+ handler_name.free_obj = free_##class_object
+
#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 452ccca3e1..fc20c42b16 100644
--- a/src/php/ext/grpc/server.c
+++ b/src/php/ext/grpc/server.c
@@ -233,7 +233,7 @@ static zend_function_entry server_methods[] = {
PHP_ME(Server, addHttp2Port, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Server, addSecureHttp2Port, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Server, start, NULL, ZEND_ACC_PUBLIC)
- PHP_FE_END
+ PHP_FE_END
};
void grpc_init_server(TSRMLS_D) {
@@ -241,10 +241,5 @@ void grpc_init_server(TSRMLS_D) {
INIT_CLASS_ENTRY(ce, "Grpc\\Server", server_methods);
ce.create_object = create_wrapped_grpc_server;
grpc_ce_server = zend_register_internal_class(&ce TSRMLS_CC);
-#if PHP_MAJOR_VERSION >= 7
- memcpy(&server_ce_handlers, zend_get_std_object_handlers(),
- sizeof(zend_object_handlers));
- server_ce_handlers.offset = XtOffsetOf(wrapped_grpc_server, std);
- server_ce_handlers.free_obj = free_wrapped_grpc_server;
-#endif
+ PHP_GRPC_INIT_HANDLER(wrapped_grpc_server, server_ce_handlers);
}
diff --git a/src/php/ext/grpc/server.h b/src/php/ext/grpc/server.h
index 02ef1f7975..a635bc11df 100755
--- a/src/php/ext/grpc/server.h
+++ b/src/php/ext/grpc/server.h
@@ -66,8 +66,7 @@ static inline wrapped_grpc_server
XtOffsetOf(wrapped_grpc_server, std));
}
-#define Z_WRAPPED_GRPC_SERVER_P(zv) \
- wrapped_grpc_server_from_obj(Z_OBJ_P((zv)))
+#define Z_WRAPPED_GRPC_SERVER_P(zv) wrapped_grpc_server_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */
diff --git a/src/php/ext/grpc/server_credentials.c b/src/php/ext/grpc/server_credentials.c
index 61041b4cb3..b05896af4a 100644
--- a/src/php/ext/grpc/server_credentials.c
+++ b/src/php/ext/grpc/server_credentials.c
@@ -122,7 +122,7 @@ PHP_METHOD(ServerCredentials, createSsl) {
static zend_function_entry server_credentials_methods[] = {
PHP_ME(ServerCredentials, createSsl, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
- PHP_FE_END
+ PHP_FE_END
};
void grpc_init_server_credentials(TSRMLS_D) {
@@ -130,13 +130,6 @@ void grpc_init_server_credentials(TSRMLS_D) {
INIT_CLASS_ENTRY(ce, "Grpc\\ServerCredentials", server_credentials_methods);
ce.create_object = create_wrapped_grpc_server_credentials;
grpc_ce_server_credentials = zend_register_internal_class(&ce TSRMLS_CC);
-#if PHP_MAJOR_VERSION >= 7
- memcpy(&server_credentials_ce_handlers,
- zend_get_std_object_handlers(),
- sizeof(zend_object_handlers));
- server_credentials_ce_handlers.offset =
- XtOffsetOf(wrapped_grpc_server_credentials, std);
- server_credentials_ce_handlers.free_obj =
- free_wrapped_grpc_server_credentials;
-#endif
+ PHP_GRPC_INIT_HANDLER(wrapped_grpc_server_credentials,
+ server_credentials_ce_handlers);
}
diff --git a/src/php/ext/grpc/server_credentials.h b/src/php/ext/grpc/server_credentials.h
index 9551ec6c24..6781a614b1 100755
--- a/src/php/ext/grpc/server_credentials.h
+++ b/src/php/ext/grpc/server_credentials.h
@@ -64,8 +64,8 @@ PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_server_credentials)
static inline wrapped_grpc_server_credentials
*wrapped_grpc_server_credentials_from_obj(zend_object *obj) {
- return (wrapped_grpc_server_credentials*)
- ((char*)(obj) - XtOffsetOf(wrapped_grpc_server_credentials, std));
+ return (wrapped_grpc_server_credentials*)(
+ (char*)(obj) - XtOffsetOf(wrapped_grpc_server_credentials, std));
}
#define Z_WRAPPED_GRPC_SERVER_CREDS_P(zv) \
diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c
index 28d360f09f..e145d96772 100644
--- a/src/php/ext/grpc/timeval.c
+++ b/src/php/ext/grpc/timeval.c
@@ -278,13 +278,7 @@ void grpc_init_timeval(TSRMLS_D) {
INIT_CLASS_ENTRY(ce, "Grpc\\Timeval", timeval_methods);
ce.create_object = create_wrapped_grpc_timeval;
grpc_ce_timeval = zend_register_internal_class(&ce TSRMLS_CC);
-#if PHP_MAJOR_VERSION >= 7
- memcpy(&timeval_ce_handlers, zend_get_std_object_handlers(),
- sizeof(zend_object_handlers));
- timeval_ce_handlers.offset =
- XtOffsetOf(wrapped_grpc_timeval, std);
- timeval_ce_handlers.free_obj = free_wrapped_grpc_timeval;
-#endif
+ PHP_GRPC_INIT_HANDLER(wrapped_grpc_timeval, timeval_ce_handlers);
}
void grpc_shutdown_timeval(TSRMLS_D) {}