add macro PHP_GRPC_INIT_HANDLER

pull/7543/head
thinkerou 8 years ago
parent 3e03e1651e
commit 6972af492d
  1. 20
      src/php/ext/grpc/call.c
  2. 11
      src/php/ext/grpc/call_credentials.c
  3. 6
      src/php/ext/grpc/call_credentials.h
  4. 8
      src/php/ext/grpc/channel.c
  5. 11
      src/php/ext/grpc/channel_credentials.c
  6. 5
      src/php/ext/grpc/channel_credentials.h
  7. 11
      src/php/ext/grpc/php7_wrapper.h
  8. 9
      src/php/ext/grpc/server.c
  9. 3
      src/php/ext/grpc/server.h
  10. 13
      src/php/ext/grpc/server_credentials.c
  11. 4
      src/php/ext/grpc/server_credentials.h
  12. 8
      src/php/ext/grpc/timeval.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);
}

@ -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);
}

@ -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) \

@ -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);
}

@ -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);
}

@ -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) \

@ -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 */

@ -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);
}

@ -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 */

@ -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);
}

@ -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) \

@ -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) {}

Loading…
Cancel
Save