use php7_wrapper to reduce dup-codes

pull/7499/head
thinkerou 8 years ago
parent 104ae8dad6
commit 9ee78aa17d
  1. 31
      src/php/ext/grpc/call.c
  2. 3
      src/php/ext/grpc/call.h
  3. 15
      src/php/ext/grpc/call_credentials.c
  4. 2
      src/php/ext/grpc/call_credentials.h
  5. 40
      src/php/ext/grpc/channel.c
  6. 3
      src/php/ext/grpc/channel.h
  7. 26
      src/php/ext/grpc/channel_credentials.c
  8. 3
      src/php/ext/grpc/channel_credentials.h
  9. 52
      src/php/ext/grpc/php7_wrapper.h
  10. 2
      src/php/ext/grpc/php_grpc.h
  11. 36
      src/php/ext/grpc/server.c
  12. 3
      src/php/ext/grpc/server.h
  13. 8
      src/php/ext/grpc/server_credentials.c
  14. 3
      src/php/ext/grpc/server_credentials.h
  15. 3
      src/php/ext/grpc/timeval.c
  16. 3
      src/php/ext/grpc/timeval.h

@ -341,18 +341,11 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) {
PHP_METHOD(Call, __construct) { PHP_METHOD(Call, __construct) {
zval *channel_obj; zval *channel_obj;
char *method; char *method;
php_grpc_int method_len;
zval *deadline_obj; zval *deadline_obj;
char *host_override = NULL; char *host_override = NULL;
#if PHP_MAJOR_VERSION < 7 php_grpc_int host_override_len = 0;
int method_len;
int host_override_len = 0;
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
size_t method_len;
size_t host_override_len = 0;
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis());
#endif
/* "OsO|s" == 1 Object, 1 string, 1 Object, 1 optional string */ /* "OsO|s" == 1 Object, 1 string, 1 Object, 1 optional string */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OsO|s", &channel_obj, if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OsO|s", &channel_obj,
@ -364,13 +357,7 @@ PHP_METHOD(Call, __construct) {
"an optional String", 1 TSRMLS_CC); "an optional String", 1 TSRMLS_CC);
return; return;
} }
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(
channel_obj TSRMLS_CC);
#else
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(channel_obj); wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(channel_obj);
#endif
if (channel->wrapped == NULL) { if (channel->wrapped == NULL) {
zend_throw_exception(spl_ce_InvalidArgumentException, zend_throw_exception(spl_ce_InvalidArgumentException,
"Call cannot be constructed from a closed Channel", "Call cannot be constructed from a closed Channel",
@ -378,13 +365,7 @@ PHP_METHOD(Call, __construct) {
return; return;
} }
add_property_zval(getThis(), "channel", channel_obj); add_property_zval(getThis(), "channel", channel_obj);
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *deadline =
(wrapped_grpc_timeval *)zend_object_store_get_object(
deadline_obj TSRMLS_CC);
#else
wrapped_grpc_timeval *deadline = Z_WRAPPED_GRPC_TIMEVAL_P(deadline_obj); wrapped_grpc_timeval *deadline = Z_WRAPPED_GRPC_TIMEVAL_P(deadline_obj);
#endif
call->wrapped = call->wrapped =
grpc_channel_create_call(channel->wrapped, NULL, GRPC_PROPAGATE_DEFAULTS, grpc_channel_create_call(channel->wrapped, NULL, GRPC_PROPAGATE_DEFAULTS,
completion_queue, method, host_override, completion_queue, method, host_override,
@ -889,17 +870,9 @@ PHP_METHOD(Call, setCredentials) {
return; return;
} }
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_call_credentials *creds =
(wrapped_grpc_call_credentials *)zend_object_store_get_object(
creds_obj TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_call_credentials *creds = wrapped_grpc_call_credentials *creds =
Z_WRAPPED_GRPC_CALL_CREDS_P(creds_obj); Z_WRAPPED_GRPC_CALL_CREDS_P(creds_obj);
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis());
#endif
grpc_call_error error = GRPC_CALL_ERROR; grpc_call_error error = GRPC_CALL_ERROR;
error = grpc_call_set_credentials(call->wrapped, creds->wrapped); error = grpc_call_set_credentials(call->wrapped, creds->wrapped);

@ -64,6 +64,9 @@ zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC);
* call metadata */ * call metadata */
zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC); zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC);
#define Z_WRAPPED_GRPC_CALL_P(zv) \
(wrapped_grpc_call *)zend_object_store_get_object(zv TSRMLS_CC)
#else #else
/* Wrapper struct for grpc_call that can be associated with a PHP object */ /* Wrapper struct for grpc_call that can be associated with a PHP object */

@ -153,26 +153,17 @@ PHP_METHOD(CallCredentials, createComposite) {
1 TSRMLS_CC); 1 TSRMLS_CC);
return; return;
} }
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_call_credentials *cred1 = wrapped_grpc_call_credentials *cred1 =
(wrapped_grpc_call_credentials *)zend_object_store_get_object( Z_WRAPPED_GRPC_CALL_CREDS_P(cred1_obj);
cred1_obj TSRMLS_CC);
wrapped_grpc_call_credentials *cred2 = wrapped_grpc_call_credentials *cred2 =
(wrapped_grpc_call_credentials *)zend_object_store_get_object( Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj);
cred2_obj TSRMLS_CC);
grpc_call_credentials *creds = grpc_call_credentials *creds =
grpc_composite_call_credentials_create(cred1->wrapped, cred2->wrapped, grpc_composite_call_credentials_create(cred1->wrapped, cred2->wrapped,
NULL); NULL);
#if PHP_MAJOR_VERSION < 7
zval *creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC); zval *creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC);
RETURN_DESTROY_ZVAL(creds_object); RETURN_DESTROY_ZVAL(creds_object);
#else #else
wrapped_grpc_call_credentials *cred1 =
Z_WRAPPED_GRPC_CALL_CREDS_P(cred1_obj);
wrapped_grpc_call_credentials *cred2 =
Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj);
grpc_call_credentials *creds =
grpc_composite_call_credentials_create(cred1->wrapped,
cred2->wrapped, NULL);
grpc_php_wrap_call_credentials(creds, return_value); grpc_php_wrap_call_credentials(creds, return_value);
RETURN_DESTROY_ZVAL(return_value); RETURN_DESTROY_ZVAL(return_value);
#endif #endif

@ -58,6 +58,8 @@ typedef struct wrapped_grpc_call_credentials {
grpc_call_credentials *wrapped; grpc_call_credentials *wrapped;
} wrapped_grpc_call_credentials; } wrapped_grpc_call_credentials;
#define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \
(wrapped_grpc_call_credentials *)zend_object_store_get_object(zv TSRMLS_CC)
#else #else
/* Wrapper struct for grpc_call_credentials that can be associated /* Wrapper struct for grpc_call_credentials that can be associated

@ -201,18 +201,14 @@ void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args) {
* @param array $args The arguments to pass to the Channel (optional) * @param array $args The arguments to pass to the Channel (optional)
*/ */
PHP_METHOD(Channel, __construct) { PHP_METHOD(Channel, __construct) {
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
#if PHP_MAJOR_VERSION < 7 #if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(
getThis() TSRMLS_CC);
zval **creds_obj = NULL; zval **creds_obj = NULL;
int target_length;
#else #else
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
zval *creds_obj = NULL; zval *creds_obj = NULL;
size_t target_length;
#endif #endif
char *target; char *target;
php_grpc_int target_length;
zval *args_array = NULL; zval *args_array = NULL;
grpc_channel_args args; grpc_channel_args args;
HashTable *array_hash; HashTable *array_hash;
@ -277,14 +273,8 @@ PHP_METHOD(Channel, __construct) {
* @return string The URI of the endpoint * @return string The URI of the endpoint
*/ */
PHP_METHOD(Channel, getTarget) { PHP_METHOD(Channel, getTarget) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC);
RETURN_STRING(grpc_channel_get_target(channel->wrapped), 1);
#else
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis()); wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
RETURN_STRING(grpc_channel_get_target(channel->wrapped)); PHP_GRPC_RETURN_STRING(grpc_channel_get_target(channel->wrapped), 1);
#endif
} }
/** /**
@ -293,12 +283,7 @@ PHP_METHOD(Channel, getTarget) {
* @return long The grpc connectivity state * @return long The grpc connectivity state
*/ */
PHP_METHOD(Channel, getConnectivityState) { PHP_METHOD(Channel, getConnectivityState) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis()); wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
#endif
bool try_to_connect = false; bool try_to_connect = false;
/* "|b" == 1 optional bool */ /* "|b" == 1 optional bool */
@ -320,14 +305,8 @@ PHP_METHOD(Channel, getConnectivityState) {
* before deadline * before deadline
*/ */
PHP_METHOD(Channel, watchConnectivityState) { PHP_METHOD(Channel, watchConnectivityState) {
#if PHP_MAJOR_VERSION < 7
long last_state;
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
zend_long last_state;
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis()); wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
#endif php_grpc_long last_state;
zval *deadline_obj; zval *deadline_obj;
/* "lO" == 1 long 1 object */ /* "lO" == 1 long 1 object */
@ -339,13 +318,7 @@ PHP_METHOD(Channel, watchConnectivityState) {
return; return;
} }
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *deadline =
(wrapped_grpc_timeval *)zend_object_store_get_object(
deadline_obj TSRMLS_CC);
#else
wrapped_grpc_timeval *deadline = Z_WRAPPED_GRPC_TIMEVAL_P(deadline_obj); wrapped_grpc_timeval *deadline = Z_WRAPPED_GRPC_TIMEVAL_P(deadline_obj);
#endif
grpc_channel_watch_connectivity_state(channel->wrapped, grpc_channel_watch_connectivity_state(channel->wrapped,
(grpc_connectivity_state)last_state, (grpc_connectivity_state)last_state,
deadline->wrapped, completion_queue, deadline->wrapped, completion_queue,
@ -360,12 +333,7 @@ PHP_METHOD(Channel, watchConnectivityState) {
* Close the channel * Close the channel
*/ */
PHP_METHOD(Channel, close) { PHP_METHOD(Channel, close) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis()); wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
#endif
if (channel->wrapped != NULL) { if (channel->wrapped != NULL) {
grpc_channel_destroy(channel->wrapped); grpc_channel_destroy(channel->wrapped);
channel->wrapped = NULL; channel->wrapped = NULL;

@ -56,6 +56,9 @@ typedef struct wrapped_grpc_channel {
grpc_channel *wrapped; grpc_channel *wrapped;
} wrapped_grpc_channel; } wrapped_grpc_channel;
#define Z_WRAPPED_GRPC_CHANNEL_P(zv) \
(wrapped_grpc_channel *)zend_object_store_get_object(zv TSRMLS_CC)
#else #else
/* Wrapper struct for grpc_channel that can be associated with a PHP object */ /* Wrapper struct for grpc_channel that can be associated with a PHP object */

@ -152,11 +152,7 @@ void grpc_php_wrap_channel_credentials(grpc_channel_credentials *wrapped,
*/ */
PHP_METHOD(ChannelCredentials, setDefaultRootsPem) { PHP_METHOD(ChannelCredentials, setDefaultRootsPem) {
char *pem_roots; char *pem_roots;
#if PHP_MAJOR_VERSION < 7 php_grpc_int pem_roots_length;
int pem_roots_length;
#else
size_t pem_roots_length;
#endif
/* "s" == 1 string */ /* "s" == 1 string */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pem_roots, if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pem_roots,
@ -197,11 +193,9 @@ PHP_METHOD(ChannelCredentials, createSsl) {
char *pem_root_certs = NULL; char *pem_root_certs = NULL;
grpc_ssl_pem_key_cert_pair pem_key_cert_pair; grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
#if PHP_MAJOR_VERSION < 7 php_grpc_int root_certs_length = 0;
int root_certs_length = 0, private_key_length = 0, cert_chain_length = 0; php_grpc_int private_key_length = 0;
#else php_grpc_int cert_chain_length = 0;
size_t root_certs_length = 0, private_key_length = 0, cert_chain_length = 0;
#endif
pem_key_cert_pair.private_key = pem_key_cert_pair.cert_chain = NULL; pem_key_cert_pair.private_key = pem_key_cert_pair.cert_chain = NULL;
@ -246,23 +240,17 @@ PHP_METHOD(ChannelCredentials, createComposite) {
"createComposite expects 2 Credentials", 1 TSRMLS_CC); "createComposite expects 2 Credentials", 1 TSRMLS_CC);
return; return;
} }
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel_credentials *cred1 = wrapped_grpc_channel_credentials *cred1 =
(wrapped_grpc_channel_credentials *)zend_object_store_get_object( Z_WRAPPED_GRPC_CHANNEL_CREDS_P(cred1_obj);
cred1_obj TSRMLS_CC);
wrapped_grpc_call_credentials *cred2 = wrapped_grpc_call_credentials *cred2 =
(wrapped_grpc_call_credentials *)zend_object_store_get_object( Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj);
cred2_obj TSRMLS_CC); #if PHP_MAJOR_VERSION < 7
grpc_channel_credentials *creds = grpc_channel_credentials *creds =
grpc_composite_channel_credentials_create(cred1->wrapped, cred2->wrapped, grpc_composite_channel_credentials_create(cred1->wrapped, cred2->wrapped,
NULL); NULL);
zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC);
RETURN_DESTROY_ZVAL(creds_object); RETURN_DESTROY_ZVAL(creds_object);
#else #else
wrapped_grpc_channel_credentials *cred1 =
Z_WRAPPED_GRPC_CHANNEL_CREDS_P(cred1_obj);
wrapped_grpc_call_credentials *cred2 =
Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj);
grpc_channel_credentials *creds = grpc_channel_credentials *creds =
grpc_composite_channel_credentials_create(cred1->wrapped, grpc_composite_channel_credentials_create(cred1->wrapped,
cred2->wrapped, NULL); cred2->wrapped, NULL);

@ -58,6 +58,9 @@ typedef struct wrapped_grpc_channel_credentials {
grpc_channel_credentials *wrapped; grpc_channel_credentials *wrapped;
} wrapped_grpc_channel_credentials; } wrapped_grpc_channel_credentials;
#define Z_WRAPPED_GRPC_CHANNEL_CREDS_P(zv) \
(wrapped_grpc_channel_credentials *)zend_object_store_get_object(zv TSRMLS_CC)
#else #else
/* Wrapper struct for grpc_channel_credentials that can be associated /* Wrapper struct for grpc_channel_credentials that can be associated

@ -0,0 +1,52 @@
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef PHP7_WRAPPER_GRPC_H
#define PHP7_WRAPPER_GRPC_H
#if PHP_MAJOR_VERSION < 7
#define php_grpc_int int
#define php_grpc_long long
#define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val, dup)
#else
#define php_grpc_int size_t
#define php_grpc_long zend_long
#define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val)
#endif /* PHP_MAJOR_VERSION */
#endif /* PHP7_WRAPPER_GRPC_H */

@ -57,6 +57,8 @@ extern zend_module_entry grpc_module_entry;
#include "php.h" #include "php.h"
#include "php7_wrapper.h"
#include "grpc/grpc.h" #include "grpc/grpc.h"
#define RETURN_DESTROY_ZVAL(val) \ #define RETURN_DESTROY_ZVAL(val) \

@ -129,12 +129,7 @@ zend_object *create_wrapped_grpc_server(zend_class_entry *class_type) {
* @param array $args The arguments to pass to the server (optional) * @param array $args The arguments to pass to the server (optional)
*/ */
PHP_METHOD(Server, __construct) { PHP_METHOD(Server, __construct) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis()); wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
#endif
zval *args_array = NULL; zval *args_array = NULL;
grpc_channel_args args; grpc_channel_args args;
@ -172,14 +167,12 @@ PHP_METHOD(Server, requestCall) {
grpc_metadata_array metadata; grpc_metadata_array metadata;
grpc_event event; grpc_event event;
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
#if PHP_MAJOR_VERSION < 7 #if PHP_MAJOR_VERSION < 7
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
zval *result; zval *result;
MAKE_STD_ZVAL(result); MAKE_STD_ZVAL(result);
object_init(result); object_init(result);
#else #else
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
object_init(return_value); object_init(return_value);
#endif #endif
@ -245,14 +238,8 @@ cleanup:
*/ */
PHP_METHOD(Server, addHttp2Port) { PHP_METHOD(Server, addHttp2Port) {
const char *addr; const char *addr;
#if PHP_MAJOR_VERSION < 7 php_grpc_int addr_len;
int addr_len;
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
size_t addr_len;
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis()); wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
#endif
/* "s" == 1 string */ /* "s" == 1 string */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len)
@ -266,15 +253,9 @@ PHP_METHOD(Server, addHttp2Port) {
PHP_METHOD(Server, addSecureHttp2Port) { PHP_METHOD(Server, addSecureHttp2Port) {
const char *addr; const char *addr;
php_grpc_int addr_len;
zval *creds_obj; zval *creds_obj;
#if PHP_MAJOR_VERSION < 7
int addr_len;
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
size_t addr_len;
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis()); wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
#endif
/* "sO" == 1 string, 1 object */ /* "sO" == 1 string, 1 object */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO", &addr, &addr_len, if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO", &addr, &addr_len,
@ -285,14 +266,8 @@ PHP_METHOD(Server, addSecureHttp2Port) {
"add_http2_port expects a string and a ServerCredentials", 1 TSRMLS_CC); "add_http2_port expects a string and a ServerCredentials", 1 TSRMLS_CC);
return; return;
} }
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_server_credentials *creds =
(wrapped_grpc_server_credentials *)zend_object_store_get_object(
creds_obj TSRMLS_CC);
#else
wrapped_grpc_server_credentials *creds = wrapped_grpc_server_credentials *creds =
Z_WRAPPED_GRPC_SERVER_CREDS_P(creds_obj); Z_WRAPPED_GRPC_SERVER_CREDS_P(creds_obj);
#endif
RETURN_LONG(grpc_server_add_secure_http2_port(server->wrapped, addr, RETURN_LONG(grpc_server_add_secure_http2_port(server->wrapped, addr,
creds->wrapped)); creds->wrapped));
} }
@ -302,12 +277,7 @@ PHP_METHOD(Server, addSecureHttp2Port) {
* @return Void * @return Void
*/ */
PHP_METHOD(Server, start) { PHP_METHOD(Server, start) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis()); wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
#endif
grpc_server_start(server->wrapped); grpc_server_start(server->wrapped);
} }

@ -56,6 +56,9 @@ typedef struct wrapped_grpc_server {
grpc_server *wrapped; grpc_server *wrapped;
} wrapped_grpc_server; } wrapped_grpc_server;
#define Z_WRAPPED_GRPC_SERVER_P(zv) \
(wrapped_grpc_server *)zend_object_store_get_object(zv TSRMLS_CC)
#else #else
/* Wrapper struct for grpc_server that can be associated with a PHP object */ /* Wrapper struct for grpc_server that can be associated with a PHP object */

@ -144,11 +144,9 @@ PHP_METHOD(ServerCredentials, createSsl) {
char *pem_root_certs = 0; char *pem_root_certs = 0;
grpc_ssl_pem_key_cert_pair pem_key_cert_pair; grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
#if PHP_MAJOR_VERSION < 7 php_grpc_int root_certs_length = 0;
int root_certs_length = 0, private_key_length, cert_chain_length; php_grpc_int private_key_length;
#else php_grpc_int cert_chain_length;
size_t root_certs_length = 0, private_key_length, cert_chain_length;
#endif
/* "s!ss" == 1 nullable string, 2 strings */ /* "s!ss" == 1 nullable string, 2 strings */
/* TODO: support multiple key cert pairs. */ /* TODO: support multiple key cert pairs. */

@ -58,6 +58,9 @@ typedef struct wrapped_grpc_server_credentials {
grpc_server_credentials *wrapped; grpc_server_credentials *wrapped;
} wrapped_grpc_server_credentials; } wrapped_grpc_server_credentials;
#define Z_WRAPPED_GRPC_SERVER_CREDS_P(zv) \
(wrapped_grpc_server_credentials *)zend_object_store_get_object(zv TSRMLS_CC)
#else #else
typedef struct wrapped_grpc_server_credentials { typedef struct wrapped_grpc_server_credentials {

@ -127,11 +127,10 @@ PHP_METHOD(Timeval, __construct) {
#if PHP_MAJOR_VERSION < 7 #if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *timeval = wrapped_grpc_timeval *timeval =
(wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC); (wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC);
long microseconds;
#else #else
wrapped_grpc_timeval *timeval = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); wrapped_grpc_timeval *timeval = Z_WRAPPED_GRPC_TIMEVAL_P(getThis());
zend_long microseconds;
#endif #endif
php_grpc_long microseconds;
/* "l" == 1 long */ /* "l" == 1 long */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &microseconds) == if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &microseconds) ==

@ -57,6 +57,9 @@ typedef struct wrapped_grpc_timeval {
gpr_timespec wrapped; gpr_timespec wrapped;
} wrapped_grpc_timeval; } wrapped_grpc_timeval;
#define Z_WRAPPED_GRPC_TIMEVAL_P(zv) \
(wrapped_grpc_timeval *)zend_object_store_get_object(zv TSRMLS_CC)
#else #else
typedef struct wrapped_grpc_timeval { typedef struct wrapped_grpc_timeval {

Loading…
Cancel
Save