From e053e730d29c4a09cac8a8785349aeb33bfb6e76 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Thu, 14 Jul 2016 00:42:07 +0200 Subject: [PATCH 01/32] Avoid using certain C++11-isms with grpc::thread, as it's not necessarily std::thread. --- test/cpp/end2end/server_builder_plugin_test.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/cpp/end2end/server_builder_plugin_test.cc b/test/cpp/end2end/server_builder_plugin_test.cc index 778a2be573e..b967a5d1e99 100644 --- a/test/cpp/end2end/server_builder_plugin_test.cc +++ b/test/cpp/end2end/server_builder_plugin_test.cc @@ -191,7 +191,7 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam { // we run some tests without a service, and for those we need to supply a // frequently polled completion queue cq_ = builder_->AddCompletionQueue(); - cq_thread_ = grpc::thread(std::bind(&ServerBuilderPluginTest::RunCQ, this)); + cq_thread_ = new grpc::thread(&ServerBuilderPluginTest::RunCQ, this); server_ = builder_->BuildAndStart(); EXPECT_TRUE(CheckPresent()); } @@ -209,7 +209,8 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam { EXPECT_TRUE(plugin->finish_is_called()); server_->Shutdown(); cq_->Shutdown(); - cq_thread_.join(); + cq_thread_->join(); + delete cq_thread_; } string to_string(const int number) { @@ -224,7 +225,7 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam { std::unique_ptr stub_; std::unique_ptr cq_; std::unique_ptr server_; - grpc::thread cq_thread_; + grpc::thread* cq_thread_; TestServiceImpl service_; int port_; From ef55d7e02f719d56b9abfb4fb785e9e5b7c44e77 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 14 Jul 2016 13:22:22 -0700 Subject: [PATCH 02/32] Fix a memory leak in Node call credentials --- src/node/ext/call_credentials.cc | 30 +++++++++++++++++++++--------- src/node/src/credentials.js | 5 +++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/node/ext/call_credentials.cc b/src/node/ext/call_credentials.cc index 3c8f0c56da4..81fc552fd10 100644 --- a/src/node/ext/call_credentials.cc +++ b/src/node/ext/call_credentials.cc @@ -68,6 +68,8 @@ using v8::Value; Nan::Callback *CallCredentials::constructor; Persistent CallCredentials::fun_tpl; +static Callback *plugin_callback; + CallCredentials::CallCredentials(grpc_call_credentials *credentials) : wrapped_credentials(credentials) {} @@ -88,6 +90,11 @@ void CallCredentials::Init(Local exports) { Nan::New(CreateFromPlugin)).ToLocalChecked()); Nan::Set(exports, Nan::New("CallCredentials").ToLocalChecked(), ctr); constructor = new Nan::Callback(ctr); + + Local callback_tpl = + Nan::New(PluginCallback); + plugin_callback = new Callback( + Nan::GetFunction(callback_tpl).ToLocalChecked()); } bool CallCredentials::HasInstance(Local val) { @@ -195,23 +202,28 @@ NAN_METHOD(PluginCallback) { return Nan::ThrowTypeError( "The callback's third argument must be an object"); } + if (!info[3]->IsObject()) { + return Nan::ThrowTypeError( + "The callback's fourth argument must be an object"); + } shared_ptr resources(new Resources); grpc_status_code code = static_cast( Nan::To(info[0]).FromJust()); Utf8String details_utf8_str(info[1]); char *details = *details_utf8_str; grpc_metadata_array array; + Local callback_data = Nan::To(info[3]).ToLocalChecked(); if (!CreateMetadataArray(Nan::To(info[2]).ToLocalChecked(), &array, resources)){ return Nan::ThrowError("Failed to parse metadata"); } grpc_credentials_plugin_metadata_cb cb = reinterpret_cast( - Nan::Get(info.Callee(), + Nan::Get(callback_data, Nan::New("cb").ToLocalChecked() ).ToLocalChecked().As()->Value()); void *user_data = - Nan::Get(info.Callee(), + Nan::Get(callback_data, Nan::New("user_data").ToLocalChecked() ).ToLocalChecked().As()->Value(); cb(user_data, array.metadata, array.count, code, details); @@ -227,17 +239,17 @@ NAUV_WORK_CB(SendPluginCallback) { while (!callbacks.empty()) { plugin_callback_data *data = callbacks.front(); callbacks.pop_front(); - // Attach cb and user_data to plugin_callback so that it can access them later - v8::Local plugin_callback = Nan::GetFunction( - Nan::New(PluginCallback)).ToLocalChecked(); - Nan::Set(plugin_callback, Nan::New("cb").ToLocalChecked(), + Local callback_data = Nan::New(); + Nan::Set(callback_data, Nan::New("cb").ToLocalChecked(), Nan::New(reinterpret_cast(data->cb))); - Nan::Set(plugin_callback, Nan::New("user_data").ToLocalChecked(), + Nan::Set(callback_data, Nan::New("user_data").ToLocalChecked(), Nan::New(data->user_data)); - const int argc = 2; + const int argc = 3; v8::Local argv[argc] = { Nan::New(data->service_url).ToLocalChecked(), - plugin_callback + callback_data, + // Get Local from Nan::Callback* + **plugin_callback }; Nan::Callback *callback = state->callback; callback->Call(argc, argv); diff --git a/src/node/src/credentials.js b/src/node/src/credentials.js index b746d0625df..043df06a669 100644 --- a/src/node/src/credentials.js +++ b/src/node/src/credentials.js @@ -92,7 +92,8 @@ exports.createSsl = ChannelCredentials.createSsl; * @return {CallCredentials} The credentials object */ exports.createFromMetadataGenerator = function(metadata_generator) { - return CallCredentials.createFromPlugin(function(service_url, callback) { + return CallCredentials.createFromPlugin(function(service_url, cb_data, + callback) { metadata_generator({service_url: service_url}, function(error, metadata) { var code = grpc.status.OK; var message = ''; @@ -107,7 +108,7 @@ exports.createFromMetadataGenerator = function(metadata_generator) { metadata = new Metadata(); } } - callback(code, message, metadata._getCoreRepresentation()); + callback(code, message, metadata._getCoreRepresentation(), cb_data); }); }); }; From 6e2832af29f8e726002f41cb4554aab6a08a7316 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Tue, 19 Jul 2016 16:43:03 -0700 Subject: [PATCH 03/32] Downloaded plist with new keys needed by Firebase SDK --- .../auth_sample/Misc/GoogleService-Info.plist | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/examples/objective-c/auth_sample/Misc/GoogleService-Info.plist b/examples/objective-c/auth_sample/Misc/GoogleService-Info.plist index 86909d84a31..ff225074238 100644 --- a/examples/objective-c/auth_sample/Misc/GoogleService-Info.plist +++ b/examples/objective-c/auth_sample/Misc/GoogleService-Info.plist @@ -2,9 +2,39 @@ + AD_UNIT_ID_FOR_BANNER_TEST + redacted + AD_UNIT_ID_FOR_INTERSTITIAL_TEST + redacted CLIENT_ID 15087385131-lh9bpkiai9nls53uadju0if6k7un3uih.apps.googleusercontent.com REVERSED_CLIENT_ID com.googleusercontent.apps.15087385131-lh9bpkiai9nls53uadju0if6k7un3uih + API_KEY + redacted + GCM_SENDER_ID + redacted + PLIST_VERSION + 1 + BUNDLE_ID + io.grpc.AuthSample + PROJECT_ID + grpc-authsample + STORAGE_BUCKET + grpc-authsample.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:15087385131:ios:d547168abe3c362f + DATABASE_URL + https://grpc-authsample.firebaseio.com - \ No newline at end of file + From bce3fb07cea5c9367fd5557a42148f5d0a505a9a Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 21 Jul 2016 11:28:35 -0700 Subject: [PATCH 04/32] Fixed typo in Node health check package.json --- src/node/health_check/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node/health_check/package.json b/src/node/health_check/package.json index b68e8b1a804..582d5601016 100644 --- a/src/node/health_check/package.json +++ b/src/node/health_check/package.json @@ -19,11 +19,11 @@ "lodash": "^3.9.3", "google-protobuf": "^3.0.0-alpha.5" }, - "files": { + "files": [ "LICENSE", "health.js", "v1" - }, + ], "main": "src/node/index.js", "license": "BSD-3-Clause" } From 9ee78aa17d2dbb6bdbe86cc3f110d0f832bf0d4d Mon Sep 17 00:00:00 2001 From: thinkerou Date: Fri, 22 Jul 2016 03:02:56 +0800 Subject: [PATCH 05/32] use php7_wrapper to reduce dup-codes --- src/php/ext/grpc/call.c | 31 +-------------- src/php/ext/grpc/call.h | 3 ++ src/php/ext/grpc/call_credentials.c | 15 ++------ src/php/ext/grpc/call_credentials.h | 2 + src/php/ext/grpc/channel.c | 40 ++------------------ src/php/ext/grpc/channel.h | 3 ++ src/php/ext/grpc/channel_credentials.c | 26 ++++--------- src/php/ext/grpc/channel_credentials.h | 3 ++ src/php/ext/grpc/php7_wrapper.h | 52 ++++++++++++++++++++++++++ src/php/ext/grpc/php_grpc.h | 2 + src/php/ext/grpc/server.c | 36 ++---------------- src/php/ext/grpc/server.h | 3 ++ src/php/ext/grpc/server_credentials.c | 8 ++-- src/php/ext/grpc/server_credentials.h | 3 ++ src/php/ext/grpc/timeval.c | 3 +- src/php/ext/grpc/timeval.h | 3 ++ 16 files changed, 97 insertions(+), 136 deletions(-) create mode 100644 src/php/ext/grpc/php7_wrapper.h diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index bd1eccb01b4..3f96db7ccb1 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -341,18 +341,11 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { PHP_METHOD(Call, __construct) { zval *channel_obj; char *method; + php_grpc_int method_len; zval *deadline_obj; char *host_override = NULL; -#if PHP_MAJOR_VERSION < 7 - 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; + php_grpc_int host_override_len = 0; wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); -#endif /* "OsO|s" == 1 Object, 1 string, 1 Object, 1 optional string */ 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); 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); -#endif if (channel->wrapped == NULL) { zend_throw_exception(spl_ce_InvalidArgumentException, "Call cannot be constructed from a closed Channel", @@ -378,13 +365,7 @@ PHP_METHOD(Call, __construct) { return; } 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); -#endif call->wrapped = grpc_channel_create_call(channel->wrapped, NULL, GRPC_PROPAGATE_DEFAULTS, completion_queue, method, host_override, @@ -889,17 +870,9 @@ PHP_METHOD(Call, setCredentials) { 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 = Z_WRAPPED_GRPC_CALL_CREDS_P(creds_obj); wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); -#endif grpc_call_error error = GRPC_CALL_ERROR; error = grpc_call_set_credentials(call->wrapped, creds->wrapped); diff --git a/src/php/ext/grpc/call.h b/src/php/ext/grpc/call.h index 9fc52d78209..4931bf392ec 100644 --- a/src/php/ext/grpc/call.h +++ b/src/php/ext/grpc/call.h @@ -64,6 +64,9 @@ zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC); * call metadata */ 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 /* Wrapper struct for grpc_call that can be associated with a PHP object */ diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c index 70aaffb848a..24ee0a465e7 100644 --- a/src/php/ext/grpc/call_credentials.c +++ b/src/php/ext/grpc/call_credentials.c @@ -153,26 +153,17 @@ PHP_METHOD(CallCredentials, createComposite) { 1 TSRMLS_CC); return; } -#if PHP_MAJOR_VERSION < 7 wrapped_grpc_call_credentials *cred1 = - (wrapped_grpc_call_credentials *)zend_object_store_get_object( - cred1_obj TSRMLS_CC); + Z_WRAPPED_GRPC_CALL_CREDS_P(cred1_obj); wrapped_grpc_call_credentials *cred2 = - (wrapped_grpc_call_credentials *)zend_object_store_get_object( - cred2_obj TSRMLS_CC); + Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj); grpc_call_credentials *creds = grpc_composite_call_credentials_create(cred1->wrapped, cred2->wrapped, NULL); +#if PHP_MAJOR_VERSION < 7 zval *creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); #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); RETURN_DESTROY_ZVAL(return_value); #endif diff --git a/src/php/ext/grpc/call_credentials.h b/src/php/ext/grpc/call_credentials.h index e05e14698b2..e9688288de6 100755 --- a/src/php/ext/grpc/call_credentials.h +++ b/src/php/ext/grpc/call_credentials.h @@ -58,6 +58,8 @@ typedef struct wrapped_grpc_call_credentials { grpc_call_credentials *wrapped; } 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 /* Wrapper struct for grpc_call_credentials that can be associated diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index 6737e340f91..085a51b5607 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -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) */ PHP_METHOD(Channel, __construct) { + wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis()); #if PHP_MAJOR_VERSION < 7 - wrapped_grpc_channel *channel = - (wrapped_grpc_channel *)zend_object_store_get_object( - getThis() TSRMLS_CC); zval **creds_obj = NULL; - int target_length; #else - wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis()); zval *creds_obj = NULL; - size_t target_length; #endif char *target; + php_grpc_int target_length; zval *args_array = NULL; grpc_channel_args args; HashTable *array_hash; @@ -277,14 +273,8 @@ PHP_METHOD(Channel, __construct) { * @return string The URI of the endpoint */ 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()); - RETURN_STRING(grpc_channel_get_target(channel->wrapped)); -#endif + PHP_GRPC_RETURN_STRING(grpc_channel_get_target(channel->wrapped), 1); } /** @@ -293,12 +283,7 @@ PHP_METHOD(Channel, getTarget) { * @return long The grpc connectivity state */ 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()); -#endif bool try_to_connect = false; /* "|b" == 1 optional bool */ @@ -320,14 +305,8 @@ PHP_METHOD(Channel, getConnectivityState) { * before deadline */ 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()); -#endif + php_grpc_long last_state; zval *deadline_obj; /* "lO" == 1 long 1 object */ @@ -339,13 +318,7 @@ PHP_METHOD(Channel, watchConnectivityState) { 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); -#endif grpc_channel_watch_connectivity_state(channel->wrapped, (grpc_connectivity_state)last_state, deadline->wrapped, completion_queue, @@ -360,12 +333,7 @@ PHP_METHOD(Channel, watchConnectivityState) { * Close the channel */ 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()); -#endif if (channel->wrapped != NULL) { grpc_channel_destroy(channel->wrapped); channel->wrapped = NULL; diff --git a/src/php/ext/grpc/channel.h b/src/php/ext/grpc/channel.h index ea5efeaf864..94c633408ed 100755 --- a/src/php/ext/grpc/channel.h +++ b/src/php/ext/grpc/channel.h @@ -56,6 +56,9 @@ typedef struct wrapped_grpc_channel { grpc_channel *wrapped; } wrapped_grpc_channel; +#define Z_WRAPPED_GRPC_CHANNEL_P(zv) \ + (wrapped_grpc_channel *)zend_object_store_get_object(zv TSRMLS_CC) + #else /* Wrapper struct for grpc_channel that can be associated with a PHP object */ diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c index 16ba0368ebb..e255b3004b0 100644 --- a/src/php/ext/grpc/channel_credentials.c +++ b/src/php/ext/grpc/channel_credentials.c @@ -152,11 +152,7 @@ void grpc_php_wrap_channel_credentials(grpc_channel_credentials *wrapped, */ PHP_METHOD(ChannelCredentials, setDefaultRootsPem) { char *pem_roots; -#if PHP_MAJOR_VERSION < 7 - int pem_roots_length; -#else - size_t pem_roots_length; -#endif + php_grpc_int pem_roots_length; /* "s" == 1 string */ 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; grpc_ssl_pem_key_cert_pair pem_key_cert_pair; -#if PHP_MAJOR_VERSION < 7 - int root_certs_length = 0, private_key_length = 0, cert_chain_length = 0; -#else - size_t root_certs_length = 0, private_key_length = 0, cert_chain_length = 0; -#endif + php_grpc_int root_certs_length = 0; + php_grpc_int private_key_length = 0; + php_grpc_int cert_chain_length = 0; 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); return; } -#if PHP_MAJOR_VERSION < 7 wrapped_grpc_channel_credentials *cred1 = - (wrapped_grpc_channel_credentials *)zend_object_store_get_object( - cred1_obj TSRMLS_CC); + Z_WRAPPED_GRPC_CHANNEL_CREDS_P(cred1_obj); wrapped_grpc_call_credentials *cred2 = - (wrapped_grpc_call_credentials *)zend_object_store_get_object( - cred2_obj TSRMLS_CC); + Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj); +#if PHP_MAJOR_VERSION < 7 grpc_channel_credentials *creds = grpc_composite_channel_credentials_create(cred1->wrapped, cred2->wrapped, NULL); zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); #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_composite_channel_credentials_create(cred1->wrapped, cred2->wrapped, NULL); diff --git a/src/php/ext/grpc/channel_credentials.h b/src/php/ext/grpc/channel_credentials.h index 44071b10f10..0f7759daa68 100755 --- a/src/php/ext/grpc/channel_credentials.h +++ b/src/php/ext/grpc/channel_credentials.h @@ -58,6 +58,9 @@ typedef struct wrapped_grpc_channel_credentials { grpc_channel_credentials *wrapped; } 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 /* Wrapper struct for grpc_channel_credentials that can be associated diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h new file mode 100644 index 00000000000..98b2aaeef5f --- /dev/null +++ b/src/php/ext/grpc/php7_wrapper.h @@ -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 */ diff --git a/src/php/ext/grpc/php_grpc.h b/src/php/ext/grpc/php_grpc.h index bd7ee75a6fb..e57a06545e6 100644 --- a/src/php/ext/grpc/php_grpc.h +++ b/src/php/ext/grpc/php_grpc.h @@ -57,6 +57,8 @@ extern zend_module_entry grpc_module_entry; #include "php.h" +#include "php7_wrapper.h" + #include "grpc/grpc.h" #define RETURN_DESTROY_ZVAL(val) \ diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index 50fb2d0cf94..e67e62c34e1 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -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) */ 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()); -#endif zval *args_array = NULL; grpc_channel_args args; @@ -172,14 +167,12 @@ PHP_METHOD(Server, requestCall) { grpc_metadata_array metadata; grpc_event event; + wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis()); #if PHP_MAJOR_VERSION < 7 - wrapped_grpc_server *server = - (wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC); zval *result; MAKE_STD_ZVAL(result); object_init(result); #else - wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis()); object_init(return_value); #endif @@ -245,14 +238,8 @@ cleanup: */ PHP_METHOD(Server, addHttp2Port) { const char *addr; -#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; + php_grpc_int addr_len; wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis()); -#endif /* "s" == 1 string */ 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) { const char *addr; + php_grpc_int addr_len; 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()); -#endif /* "sO" == 1 string, 1 object */ 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); 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 = Z_WRAPPED_GRPC_SERVER_CREDS_P(creds_obj); -#endif RETURN_LONG(grpc_server_add_secure_http2_port(server->wrapped, addr, creds->wrapped)); } @@ -302,12 +277,7 @@ PHP_METHOD(Server, addSecureHttp2Port) { * @return Void */ 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()); -#endif grpc_server_start(server->wrapped); } diff --git a/src/php/ext/grpc/server.h b/src/php/ext/grpc/server.h index a7df456a111..603b9a71026 100755 --- a/src/php/ext/grpc/server.h +++ b/src/php/ext/grpc/server.h @@ -56,6 +56,9 @@ typedef struct wrapped_grpc_server { grpc_server *wrapped; } wrapped_grpc_server; +#define Z_WRAPPED_GRPC_SERVER_P(zv) \ + (wrapped_grpc_server *)zend_object_store_get_object(zv TSRMLS_CC) + #else /* Wrapper struct for grpc_server that can be associated with a PHP object */ diff --git a/src/php/ext/grpc/server_credentials.c b/src/php/ext/grpc/server_credentials.c index 296632d5bdd..e61fc5b4a12 100644 --- a/src/php/ext/grpc/server_credentials.c +++ b/src/php/ext/grpc/server_credentials.c @@ -144,11 +144,9 @@ PHP_METHOD(ServerCredentials, createSsl) { char *pem_root_certs = 0; grpc_ssl_pem_key_cert_pair pem_key_cert_pair; -#if PHP_MAJOR_VERSION < 7 - int root_certs_length = 0, private_key_length, cert_chain_length; -#else - size_t root_certs_length = 0, private_key_length, cert_chain_length; -#endif + php_grpc_int root_certs_length = 0; + php_grpc_int private_key_length; + php_grpc_int cert_chain_length; /* "s!ss" == 1 nullable string, 2 strings */ /* TODO: support multiple key cert pairs. */ diff --git a/src/php/ext/grpc/server_credentials.h b/src/php/ext/grpc/server_credentials.h index d37fafc0dc0..9df5950fa7d 100755 --- a/src/php/ext/grpc/server_credentials.h +++ b/src/php/ext/grpc/server_credentials.h @@ -58,6 +58,9 @@ typedef struct wrapped_grpc_server_credentials { grpc_server_credentials *wrapped; } 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 typedef struct wrapped_grpc_server_credentials { diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index 8dc997c2dda..db0f8a7aaf4 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -127,11 +127,10 @@ PHP_METHOD(Timeval, __construct) { #if PHP_MAJOR_VERSION < 7 wrapped_grpc_timeval *timeval = (wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC); - long microseconds; #else wrapped_grpc_timeval *timeval = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); - zend_long microseconds; #endif + php_grpc_long microseconds; /* "l" == 1 long */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", µseconds) == diff --git a/src/php/ext/grpc/timeval.h b/src/php/ext/grpc/timeval.h index d4eb2facde9..d362460c050 100755 --- a/src/php/ext/grpc/timeval.h +++ b/src/php/ext/grpc/timeval.h @@ -57,6 +57,9 @@ typedef struct wrapped_grpc_timeval { gpr_timespec wrapped; } wrapped_grpc_timeval; +#define Z_WRAPPED_GRPC_TIMEVAL_P(zv) \ + (wrapped_grpc_timeval *)zend_object_store_get_object(zv TSRMLS_CC) + #else typedef struct wrapped_grpc_timeval { From 4b9740bfe0946344084a812d34cf2a759fc3dc21 Mon Sep 17 00:00:00 2001 From: thinkerou Date: Fri, 22 Jul 2016 09:20:12 +0800 Subject: [PATCH 06/32] use php7_wrapper to reduce dup-codes --- src/php/ext/grpc/call.c | 17 ++------------- src/php/ext/grpc/timeval.c | 44 ++++---------------------------------- 2 files changed, 6 insertions(+), 55 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 3f96db7ccb1..d455002de6d 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -380,8 +380,6 @@ PHP_METHOD(Call, __construct) { */ PHP_METHOD(Call, startBatch) { #if PHP_MAJOR_VERSION < 7 - wrapped_grpc_call *call = - (wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC); zval **value; zval **inner_value; HashPosition array_pointer; @@ -395,7 +393,6 @@ PHP_METHOD(Call, startBatch) { MAKE_STD_ZVAL(result); object_init(result); #else - wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); zval *value; zval *inner_value; zval *message_value; @@ -405,6 +402,7 @@ PHP_METHOD(Call, startBatch) { zval recv_status; object_init(return_value); #endif + wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); grpc_op ops[8]; size_t op_num = 0; @@ -829,14 +827,8 @@ cleanup: * @return string The URI of the endpoint */ PHP_METHOD(Call, getPeer) { -#if PHP_MAJOR_VERSION < 7 - wrapped_grpc_call *call = - (wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC); - RETURN_STRING(grpc_call_get_peer(call->wrapped), 1); -#else wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); - RETURN_STRING(grpc_call_get_peer(call->wrapped)); -#endif + PHP_GRPC_RETURN_STRING(grpc_call_get_peer(call->wrapped), 1); } /** @@ -844,12 +836,7 @@ PHP_METHOD(Call, getPeer) { * has not already ended with another status. */ PHP_METHOD(Call, cancel) { -#if PHP_MAJOR_VERSION < 7 - wrapped_grpc_call *call = - (wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC); -#else wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); -#endif grpc_call_cancel(call->wrapped, NULL); } diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index db0f8a7aaf4..a3ec62f13f4 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -124,12 +124,7 @@ void grpc_php_wrap_timeval(gpr_timespec wrapped, zval *timeval_object) { * @param long $usec The number of microseconds in the interval */ PHP_METHOD(Timeval, __construct) { -#if PHP_MAJOR_VERSION < 7 - wrapped_grpc_timeval *timeval = - (wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC); -#else wrapped_grpc_timeval *timeval = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); -#endif php_grpc_long microseconds; /* "l" == 1 long */ @@ -159,19 +154,14 @@ PHP_METHOD(Timeval, add) { "add expects a Timeval", 1 TSRMLS_CC); return; } + wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); + wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj); #if PHP_MAJOR_VERSION < 7 - wrapped_grpc_timeval *self = - (wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC); - wrapped_grpc_timeval *other = - (wrapped_grpc_timeval *)zend_object_store_get_object(other_obj TSRMLS_CC); zval *sum = grpc_php_wrap_timeval(gpr_time_add(self->wrapped, other->wrapped) TSRMLS_CC); RETURN_DESTROY_ZVAL(sum); #else - wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); - wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj); - grpc_php_wrap_timeval(gpr_time_add(self->wrapped, other->wrapped), return_value); RETURN_DESTROY_ZVAL(return_value); @@ -194,18 +184,14 @@ PHP_METHOD(Timeval, subtract) { "subtract expects a Timeval", 1 TSRMLS_CC); return; } + wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); + wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj); #if PHP_MAJOR_VERSION < 7 - wrapped_grpc_timeval *self = - (wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC); - wrapped_grpc_timeval *other = - (wrapped_grpc_timeval *)zend_object_store_get_object(other_obj TSRMLS_CC); zval *diff = grpc_php_wrap_timeval(gpr_time_sub(self->wrapped, other->wrapped) TSRMLS_CC); RETURN_DESTROY_ZVAL(diff); #else - wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); - wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj); grpc_php_wrap_timeval(gpr_time_sub(self->wrapped, other->wrapped), return_value); RETURN_DESTROY_ZVAL(return_value); @@ -231,15 +217,8 @@ PHP_METHOD(Timeval, compare) { "compare expects two Timevals", 1 TSRMLS_CC); return; } -#if PHP_MAJOR_VERSION < 7 - wrapped_grpc_timeval *a = - (wrapped_grpc_timeval *)zend_object_store_get_object(a_obj TSRMLS_CC); - wrapped_grpc_timeval *b = - (wrapped_grpc_timeval *)zend_object_store_get_object(b_obj TSRMLS_CC); -#else wrapped_grpc_timeval *a = Z_WRAPPED_GRPC_TIMEVAL_P(a_obj); wrapped_grpc_timeval *b = Z_WRAPPED_GRPC_TIMEVAL_P(b_obj); -#endif long result = gpr_time_cmp(a->wrapped, b->wrapped); RETURN_LONG(result); } @@ -264,19 +243,9 @@ PHP_METHOD(Timeval, similar) { "compare expects three Timevals", 1 TSRMLS_CC); return; } -#if PHP_MAJOR_VERSION < 7 - wrapped_grpc_timeval *a = - (wrapped_grpc_timeval *)zend_object_store_get_object(a_obj TSRMLS_CC); - wrapped_grpc_timeval *b = - (wrapped_grpc_timeval *)zend_object_store_get_object(b_obj TSRMLS_CC); - wrapped_grpc_timeval *thresh = - (wrapped_grpc_timeval *)zend_object_store_get_object( - thresh_obj TSRMLS_CC); -#else wrapped_grpc_timeval *a = Z_WRAPPED_GRPC_TIMEVAL_P(a_obj); wrapped_grpc_timeval *b = Z_WRAPPED_GRPC_TIMEVAL_P(b_obj); wrapped_grpc_timeval *thresh = Z_WRAPPED_GRPC_TIMEVAL_P(thresh_obj); -#endif int result = gpr_time_similar(a->wrapped, b->wrapped, thresh->wrapped); RETURN_BOOL(result); } @@ -349,12 +318,7 @@ PHP_METHOD(Timeval, infPast) { * @return void */ PHP_METHOD(Timeval, sleepUntil) { -#if PHP_MAJOR_VERSION < 7 - wrapped_grpc_timeval *this = - (wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC); -#else wrapped_grpc_timeval *this = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); -#endif gpr_sleep_until(this->wrapped); } From c0810acce7db8259ec28e334fab9557d5330e7d3 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Fri, 22 Jul 2016 12:40:29 -0700 Subject: [PATCH 07/32] node: fix health check package.json template --- templates/src/node/health_check/package.json.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/src/node/health_check/package.json.template b/templates/src/node/health_check/package.json.template index 1248ced1e16..96b9748aa74 100644 --- a/templates/src/node/health_check/package.json.template +++ b/templates/src/node/health_check/package.json.template @@ -21,11 +21,11 @@ "lodash": "^3.9.3", "google-protobuf": "^3.0.0-alpha.5" }, - "files": { + "files": [ "LICENSE", "health.js", "v1" - }, + ], "main": "src/node/index.js", "license": "BSD-3-Clause" } From ca931e4167967b3678743b407c54433d62eea657 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Mon, 25 Jul 2016 12:46:21 -0700 Subject: [PATCH 08/32] add new file to build.yaml --- build.yaml | 1 + package.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/build.yaml b/build.yaml index c5d92c1e63a..3198f516a4a 100644 --- a/build.yaml +++ b/build.yaml @@ -3367,6 +3367,7 @@ php_config_m4: - src/php/ext/grpc/channel.h - src/php/ext/grpc/channel_credentials.h - src/php/ext/grpc/completion_queue.h + - src/php/ext/grpc/php7_wrapper.h - src/php/ext/grpc/php_grpc.h - src/php/ext/grpc/server.h - src/php/ext/grpc/server_credentials.h diff --git a/package.xml b/package.xml index c5006dade57..164709a6b48 100644 --- a/package.xml +++ b/package.xml @@ -47,6 +47,7 @@ + From d8f77f63dc287df7403ed784e7b1ef522bb72180 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Mon, 25 Jul 2016 15:27:18 -0700 Subject: [PATCH 09/32] update copyright --- src/php/ext/grpc/php7_wrapper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h index 98b2aaeef5f..e4d0d4c90bb 100644 --- a/src/php/ext/grpc/php7_wrapper.h +++ b/src/php/ext/grpc/php7_wrapper.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without From 6d62ada98390f0fbf545f17cfbab8a7baa0ceaf2 Mon Sep 17 00:00:00 2001 From: thinkerou Date: Wed, 27 Jul 2016 03:47:44 +0800 Subject: [PATCH 10/32] add macro to php7_wrapper for reduce duplicate code --- src/php/ext/grpc/call.c | 259 ++++++++++--------------- src/php/ext/grpc/call.h | 30 +-- src/php/ext/grpc/call_credentials.c | 73 +++---- src/php/ext/grpc/call_credentials.h | 19 +- src/php/ext/grpc/channel.c | 84 ++++---- src/php/ext/grpc/channel.h | 17 +- src/php/ext/grpc/channel_credentials.c | 53 ++--- src/php/ext/grpc/channel_credentials.h | 18 +- src/php/ext/grpc/php7_wrapper.h | 32 +++ src/php/ext/grpc/server.c | 38 ++-- src/php/ext/grpc/server.h | 17 +- src/php/ext/grpc/server_credentials.c | 32 +-- src/php/ext/grpc/server_credentials.h | 19 +- src/php/ext/grpc/timeval.c | 78 +++----- src/php/ext/grpc/timeval.h | 20 +- 15 files changed, 304 insertions(+), 485 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index d455002de6d..fc832dacc23 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -90,34 +90,54 @@ zend_object_value create_wrapped_grpc_call(zend_class_entry *class_type return retval; } -/* Wraps a grpc_call struct in a PHP object. Owned indicates whether the struct - should be destroyed at the end of the object's lifecycle */ -zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC) { - zval *call_object; - MAKE_STD_ZVAL(call_object); - object_init_ex(call_object, grpc_ce_call); - wrapped_grpc_call *call = - (wrapped_grpc_call *)zend_object_store_get_object(call_object TSRMLS_CC); - call->wrapped = wrapped; - call->owned = owned; - return call_object; +#else + +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) { + wrapped_grpc_call *intern; + intern = ecalloc(1, sizeof(wrapped_grpc_call) + + zend_object_properties_size(class_type)); + zend_object_std_init(&intern->std, class_type); + object_properties_init(&intern->std, class_type); + intern->std.handlers = &call_ce_handlers; + return &intern->std; } +#endif + /* Creates and returns a PHP array object with the data in a * grpc_metadata_array. Returns NULL on failure */ -zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC) { +zval *grpc_parse_metadata_array(grpc_metadata_array + *metadata_array TSRMLS_DC) { int count = metadata_array->count; grpc_metadata *elements = metadata_array->metadata; - int i; zval *array; - zval **data = NULL; + PHP_GRPC_MAKE_STD_ZVAL(array); + array_init(array); + int i; HashTable *array_hash; zval *inner_array; char *str_key; char *str_val; size_t key_len; - MAKE_STD_ZVAL(array); - array_init(array); +#if PHP_MAJOR_VERSION < 7 + zval **data = NULL; +#else + zval *data; +#endif + array_hash = Z_ARRVAL_P(array); grpc_metadata *elem; for (i = 0; i < count; i++) { @@ -127,9 +147,14 @@ zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC) { 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_MAJOR_VERSION < 7 if (zend_hash_find(array_hash, str_key, key_len, (void **)data) == SUCCESS) { if (Z_TYPE_P(*data) != IS_ARRAY) { +#else + if ((data = zend_hash_str_find(array_hash, str_key, key_len)) != NULL) { + if (Z_TYPE_P(data) != IS_ARRAY) { +#endif zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Metadata hash somehow contains wrong types.", 1 TSRMLS_CC); @@ -137,11 +162,18 @@ zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC) { efree(str_val); return NULL; } - add_next_index_stringl(*data, str_val, elem->value_length, false); +#if PHP_MAJOR_VERSION < 7 + php_grpc_add_next_index_stringl(*data, str_val, elem->value_length, + false); +#else + php_grpc_add_next_index_stringl(data, str_val, elem->value_length, + false); +#endif } else { - MAKE_STD_ZVAL(inner_array); + PHP_GRPC_MAKE_STD_ZVAL(inner_array); array_init(inner_array); - add_next_index_stringl(inner_array, str_val, elem->value_length, false); + php_grpc_add_next_index_stringl(inner_array, str_val, + elem->value_length, false); add_assoc_zval(array, str_key, inner_array); } } @@ -151,20 +183,27 @@ zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC) { /* Populates a grpc_metadata_array with the data in a PHP array object. Returns true on success and false on failure */ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { + HashTable *array_hash; + HashTable *inner_array_hash; +#if PHP_MAJOR_VERSION < 7 zval **inner_array; zval **value; - HashTable *array_hash; HashPosition array_pointer; - HashTable *inner_array_hash; HashPosition inner_array_pointer; char *key; uint key_len; ulong index; +#else + zval *inner_array; + zval *value; + zend_string *key; +#endif if (Z_TYPE_P(array) != IS_ARRAY) { return false; } grpc_metadata_array_init(metadata); array_hash = Z_ARRVAL_P(array); +#if PHP_MAJOR_VERSION < 7 for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer); zend_hash_get_current_data_ex(array_hash, (void**)&inner_array, &array_pointer) == SUCCESS; @@ -179,7 +218,22 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { inner_array_hash = Z_ARRVAL_P(*inner_array); metadata->capacity += zend_hash_num_elements(inner_array_hash); } +#else + ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, inner_array) { + if (key == NULL) { + return false; + } + if (Z_TYPE_P(inner_array) != IS_ARRAY) { + return false; + } + inner_array_hash = HASH_OF(inner_array); + metadata->capacity += zend_hash_num_elements(inner_array_hash); + } ZEND_HASH_FOREACH_END(); +#endif + metadata->metadata = gpr_malloc(metadata->capacity * sizeof(grpc_metadata)); + +#if PHP_MAJOR_VERSION < 7 for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer); zend_hash_get_current_data_ex(array_hash, (void**)&inner_array, &array_pointer) == SUCCESS; @@ -203,113 +257,7 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { metadata->count += 1; } } - return true; -} - #else - -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) { - wrapped_grpc_call *intern; - intern = ecalloc(1, sizeof(wrapped_grpc_call) + - zend_object_properties_size(class_type)); - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); - intern->std.handlers = &call_ce_handlers; - return &intern->std; -} - -/* Wraps a grpc_call struct in a PHP object. Owned indicates whether the - struct should be destroyed at the end of the object's lifecycle */ -void grpc_php_wrap_call(grpc_call *wrapped, bool owned, zval *call_object) { - object_init_ex(call_object, grpc_ce_call); - wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(call_object); - call->wrapped = wrapped; - call->owned = owned; -} - -/* Creates and returns a PHP array object with the data in a - * grpc_metadata_array. Returns NULL on failure */ -void grpc_parse_metadata_array(grpc_metadata_array *metadata_array, - zval *array) { - int count = metadata_array->count; - grpc_metadata *elements = metadata_array->metadata; - int i; - zval *data; - HashTable *array_hash; - zval inner_array; - char *str_key; - char *str_val; - size_t key_len; - - array_init(array); - array_hash = HASH_OF(array); - grpc_metadata *elem; - for (i = 0; i < count; i++) { - elem = &elements[i]; - key_len = strlen(elem->key); - str_key = ecalloc(key_len + 1, sizeof(char)); - 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 ((data = zend_hash_str_find(array_hash, str_key, key_len)) != NULL) { - if (Z_TYPE_P(data) != IS_ARRAY) { - zend_throw_exception(zend_exception_get_default(), - "Metadata hash somehow contains wrong types.", - 1); - efree(str_key); - efree(str_val); - return; - } - add_next_index_stringl(data, str_val, elem->value_length); - } else { - array_init(&inner_array); - add_next_index_stringl(&inner_array, str_val, elem->value_length); - add_assoc_zval(array, str_key, &inner_array); - } - } -} - -/* Populates a grpc_metadata_array with the data in a PHP array object. - Returns true on success and false on failure */ -bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { - zval *inner_array; - zval *value; - HashTable *array_hash; - HashTable *inner_array_hash; - zend_string *key; - if (Z_TYPE_P(array) != IS_ARRAY) { - return false; - } - grpc_metadata_array_init(metadata); - array_hash = HASH_OF(array); - - ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, inner_array) { - if (key == NULL) { - return false; - } - if (Z_TYPE_P(inner_array) != IS_ARRAY) { - return false; - } - inner_array_hash = HASH_OF(inner_array); - metadata->capacity += zend_hash_num_elements(inner_array_hash); - } - ZEND_HASH_FOREACH_END(); - - metadata->metadata = gpr_malloc(metadata->capacity * sizeof(grpc_metadata)); - ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, inner_array) { if (key == NULL) { return false; @@ -326,10 +274,21 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { metadata->count += 1; } ZEND_HASH_FOREACH_END(); } ZEND_HASH_FOREACH_END(); +#endif return true; } -#endif +/* Wraps a grpc_call struct in a PHP object. Owned indicates whether the + struct should be destroyed at the end of the object's lifecycle */ +zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC) { + zval *call_object; + PHP_GRPC_MAKE_STD_ZVAL(call_object); + object_init_ex(call_object, grpc_ce_call); + wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(call_object); + call->wrapped = wrapped; + call->owned = owned; + return call_object; +} /** * Constructs a new instance of the Call class. @@ -379,6 +338,10 @@ PHP_METHOD(Call, __construct) { * @return object Object with results of all actions */ PHP_METHOD(Call, startBatch) { + zval *result; + PHP_GRPC_MAKE_STD_ZVAL(result); + object_init(result); + php_grpc_ulong index; #if PHP_MAJOR_VERSION < 7 zval **value; zval **inner_value; @@ -387,20 +350,14 @@ PHP_METHOD(Call, startBatch) { zval **message_flags; char *key; uint key_len; - ulong index; - zval *result; zval *recv_status; - MAKE_STD_ZVAL(result); - object_init(result); #else zval *value; zval *inner_value; zval *message_value; zval *message_flags; zend_string *key; - zend_ulong index; zval recv_status; - object_init(return_value); #endif wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); @@ -574,7 +531,7 @@ PHP_METHOD(Call, startBatch) { #else -array_hash = HASH_OF(array); + array_hash = HASH_OF(array); ZEND_HASH_FOREACH_KEY_VAL(array_hash, index, key, value) { if (key) { zend_throw_exception(spl_ce_InvalidArgumentException, @@ -692,8 +649,7 @@ array_hash = HASH_OF(array); ops[op_num].flags = 0; ops[op_num].reserved = NULL; op_num++; - } - ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); #endif @@ -755,43 +711,44 @@ array_hash = HASH_OF(array); } } #else + zval recv_md; for (int i = 0; i < op_num; i++) { switch(ops[i].op) { case GRPC_OP_SEND_INITIAL_METADATA: - add_property_bool(return_value, "send_metadata", true); + add_property_bool(result, "send_metadata", true); break; case GRPC_OP_SEND_MESSAGE: - add_property_bool(return_value, "send_message", true); + add_property_bool(result, "send_message", true); break; case GRPC_OP_SEND_CLOSE_FROM_CLIENT: - add_property_bool(return_value, "send_close", true); + add_property_bool(result, "send_close", true); break; case GRPC_OP_SEND_STATUS_FROM_SERVER: - add_property_bool(return_value, "send_status", true); + add_property_bool(result, "send_status", true); break; case GRPC_OP_RECV_INITIAL_METADATA: - grpc_parse_metadata_array(&recv_metadata, array); - add_property_zval(return_value, "metadata", array); + recv_md = *grpc_parse_metadata_array(&recv_metadata); + add_property_zval(result, "metadata", &recv_md); break; case GRPC_OP_RECV_MESSAGE: byte_buffer_to_string(message, &message_str, &message_len); if (message_str == NULL) { - add_property_null(return_value, "message"); + add_property_null(result, "message"); } else { - add_property_stringl(return_value, "message", message_str, + add_property_stringl(result, "message", message_str, message_len); } break; case GRPC_OP_RECV_STATUS_ON_CLIENT: object_init(&recv_status); - grpc_parse_metadata_array(&recv_trailing_metadata, array); - add_property_zval(&recv_status, "metadata", array); + recv_md = *grpc_parse_metadata_array(&recv_trailing_metadata); + add_property_zval(&recv_status, "metadata", &recv_md); add_property_long(&recv_status, "code", status); add_property_string(&recv_status, "details", status_details); - add_property_zval(return_value, "status", &recv_status); + add_property_zval(result, "status", &recv_status); break; case GRPC_OP_RECV_CLOSE_ON_SERVER: - add_property_bool(return_value, "cancelled", cancelled); + add_property_bool(result, "cancelled", cancelled); break; default: break; @@ -815,11 +772,7 @@ cleanup: grpc_byte_buffer_destroy(message); } } -#if PHP_MAJOR_VERSION < 7 RETURN_DESTROY_ZVAL(result); -#else - RETURN_DESTROY_ZVAL(return_value); -#endif } /** diff --git a/src/php/ext/grpc/call.h b/src/php/ext/grpc/call.h index 4931bf392ec..e49f9b382ae 100644 --- a/src/php/ext/grpc/call.h +++ b/src/php/ext/grpc/call.h @@ -48,34 +48,19 @@ /* Class entry for the Call PHP class */ extern zend_class_entry *grpc_ce_call; -#if PHP_MAJOR_VERSION < 7 - /* Wrapper struct for grpc_call that can be associated with a PHP object */ -typedef struct wrapped_grpc_call { - zend_object std; +PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_call) bool owned; grpc_call *wrapped; -} wrapped_grpc_call; - -/* Creates a Call object that wraps the given grpc_call struct */ -zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC); +PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_call) -/* Creates and returns a PHP associative array of metadata from a C array of - * call metadata */ -zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC); +#if PHP_MAJOR_VERSION < 7 #define Z_WRAPPED_GRPC_CALL_P(zv) \ (wrapped_grpc_call *)zend_object_store_get_object(zv TSRMLS_CC) #else -/* Wrapper struct for grpc_call that can be associated with a PHP object */ -typedef struct wrapped_grpc_call { - bool owned; - grpc_call *wrapped; - zend_object std; -} wrapped_grpc_call; - static inline wrapped_grpc_call *wrapped_grpc_call_from_obj(zend_object *obj) { return (wrapped_grpc_call*)((char*)(obj) - @@ -84,15 +69,14 @@ static inline wrapped_grpc_call #define Z_WRAPPED_GRPC_CALL_P(zv) wrapped_grpc_call_from_obj(Z_OBJ_P((zv))) -/* Creates a Call object that wraps the given grpc_call struct */ -void grpc_php_wrap_call(grpc_call *wrapped, bool owned, zval *call_object); +#endif /* PHP_MAJOR_VERSION */ /* Creates and returns a PHP associative array of metadata from a C array of * call metadata */ -void grpc_parse_metadata_array(grpc_metadata_array *metadata_array, - zval *array); +zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC); -#endif /* PHP_MAJOR_VERSION */ +/* Creates a Call object that wraps the given grpc_call struct */ +zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC); /* Initializes the Call PHP class */ void grpc_init_call(TSRMLS_D); diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c index 24ee0a465e7..29762afb297 100644 --- a/src/php/ext/grpc/call_credentials.c +++ b/src/php/ext/grpc/call_credentials.c @@ -86,17 +86,6 @@ zend_object_value create_wrapped_grpc_call_credentials( return retval; } -zval *grpc_php_wrap_call_credentials(grpc_call_credentials *wrapped TSRMLS_DC) { - zval *credentials_object; - MAKE_STD_ZVAL(credentials_object); - object_init_ex(credentials_object, grpc_ce_call_credentials); - wrapped_grpc_call_credentials *credentials = - (wrapped_grpc_call_credentials *)zend_object_store_get_object( - credentials_object TSRMLS_CC); - credentials->wrapped = wrapped; - return credentials_object; -} - #else static zend_object_handlers call_credentials_ce_handlers; @@ -124,16 +113,19 @@ zend_object *create_wrapped_grpc_call_credentials(zend_class_entry return &intern->std; } -void grpc_php_wrap_call_credentials(grpc_call_credentials *wrapped, - zval *credentials_object) { +#endif + +zval *grpc_php_wrap_call_credentials(grpc_call_credentials + *wrapped TSRMLS_DC) { + zval *credentials_object; + PHP_GRPC_MAKE_STD_ZVAL(credentials_object); object_init_ex(credentials_object, grpc_ce_call_credentials); wrapped_grpc_call_credentials *credentials = Z_WRAPPED_GRPC_CALL_CREDS_P(credentials_object); credentials->wrapped = wrapped; + return credentials_object; } -#endif - /** * Create composite credentials from two existing credentials. * @param CallCredentials cred1 The first credential @@ -160,13 +152,10 @@ PHP_METHOD(CallCredentials, createComposite) { grpc_call_credentials *creds = grpc_composite_call_credentials_create(cred1->wrapped, cred2->wrapped, NULL); -#if PHP_MAJOR_VERSION < 7 - zval *creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC); + zval *creds_object; + PHP_GRPC_MAKE_STD_ZVAL(creds_object); + creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); -#else - grpc_php_wrap_call_credentials(creds, return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } /** @@ -207,13 +196,10 @@ PHP_METHOD(CallCredentials, createFromPlugin) { grpc_call_credentials *creds = grpc_metadata_credentials_create_from_plugin(plugin, NULL); -#if PHP_MAJOR_VERSION < 7 - zval *creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC); + zval *creds_object; + PHP_GRPC_MAKE_STD_ZVAL(creds_object); + creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); -#else - grpc_php_wrap_call_credentials(creds, return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } /* Callback function for plugin creds API */ @@ -226,37 +212,28 @@ void plugin_get_metadata(void *ptr, grpc_auth_metadata_context context, /* prepare to call the user callback function with info from the * grpc_auth_metadata_context */ -#if PHP_MAJOR_VERSION < 7 - zval **params[1]; zval *arg; - zval *retval; - MAKE_STD_ZVAL(arg); + PHP_GRPC_MAKE_STD_ZVAL(arg); object_init(arg); - add_property_string(arg, "service_url", context.service_url, true); - add_property_string(arg, "method_name", context.method_name, true); + php_grpc_add_property_string(arg, "service_url", context.service_url, true); + php_grpc_add_property_string(arg, "method_name", context.method_name, true); + zval *retval; + PHP_GRPC_MAKE_STD_ZVAL(retval); +#if PHP_MAJOR_VERSION < 7 + zval **params[1]; params[0] = &arg; - state->fci->param_count = 1; state->fci->params = params; state->fci->retval_ptr_ptr = &retval; #else - zval arg; - zval retval; - object_init(&arg); - add_property_string(&arg, "service_url", context.service_url); - add_property_string(&arg, "method_name", context.method_name); - state->fci->param_count = 1; - state->fci->params = &arg; - state->fci->retval = &retval; + state->fci->params = arg; + state->fci->retval = retval; #endif + state->fci->param_count = 1; /* call the user callback function */ zend_call_function(state->fci, state->fci_cache TSRMLS_CC); -#if PHP_MAJOR_VERSION < 7 if (Z_TYPE_P(retval) != IS_ARRAY) { -#else - if (Z_TYPE_P(&retval) != IS_ARRAY) { -#endif zend_throw_exception(spl_ce_InvalidArgumentException, "plugin callback must return metadata array", 1 TSRMLS_CC); @@ -264,11 +241,7 @@ void plugin_get_metadata(void *ptr, grpc_auth_metadata_context context, } grpc_metadata_array metadata; -#if PHP_MAJOR_VERSION < 7 if (!create_metadata_array(retval, &metadata)) { -#else - if (!create_metadata_array(&retval, &metadata)) { -#endif zend_throw_exception(spl_ce_InvalidArgumentException, "invalid metadata", 1 TSRMLS_CC); grpc_metadata_array_destroy(&metadata); diff --git a/src/php/ext/grpc/call_credentials.h b/src/php/ext/grpc/call_credentials.h index e9688288de6..822d077ccb0 100755 --- a/src/php/ext/grpc/call_credentials.h +++ b/src/php/ext/grpc/call_credentials.h @@ -49,25 +49,18 @@ /* Class entry for the CallCredentials PHP class */ extern zend_class_entry *grpc_ce_call_credentials; -#if PHP_MAJOR_VERSION < 7 - /* Wrapper struct for grpc_call_credentials that can be associated * with a PHP object */ -typedef struct wrapped_grpc_call_credentials { - zend_object std; +PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_call_credentials) grpc_call_credentials *wrapped; -} wrapped_grpc_call_credentials; +PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_call_credentials) + +#if PHP_MAJOR_VERSION < 7 #define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \ (wrapped_grpc_call_credentials *)zend_object_store_get_object(zv TSRMLS_CC) -#else -/* Wrapper struct for grpc_call_credentials that can be associated - * with a PHP object */ -typedef struct wrapped_grpc_call_credentials { - grpc_call_credentials *wrapped; - zend_object std; -} wrapped_grpc_call_credentials; +#else static inline wrapped_grpc_call_credentials *wrapped_grpc_call_creds_from_obj(zend_object *obj) { @@ -77,7 +70,7 @@ static inline wrapped_grpc_call_credentials std)); } -#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))) #endif /* PHP_MAJOR_VERSION */ diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index 085a51b5607..18ebcabc26f 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -86,19 +86,58 @@ zend_object_value create_wrapped_grpc_channel(zend_class_entry *class_type return retval; } +#else + +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) { + wrapped_grpc_channel *intern; + intern = ecalloc(1, sizeof(wrapped_grpc_channel) + + zend_object_properties_size(class_type)); + zend_object_std_init(&intern->std, class_type); + object_properties_init(&intern->std, class_type); + intern->std.handlers = &channel_ce_handlers; + return &intern->std; +} + +#endif + void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args TSRMLS_DC) { HashTable *array_hash; - HashPosition array_pointer; int args_index; +#if PHP_MAJOR_VERSION < 7 + HashPosition array_pointer; zval **data; char *key; uint key_len; ulong index; +#else + zval *data; + zend_string *key; +#endif array_hash = Z_ARRVAL_P(args_array); + if (!array_hash) { + zend_throw_exception(spl_ce_InvalidArgumentException, + "array_hash is NULL", 1); + return; + } args->num_args = zend_hash_num_elements(array_hash); args->args = ecalloc(args->num_args, sizeof(grpc_arg)); args_index = 0; + +#if PHP_MAJOR_VERSION < 7 for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer); zend_hash_get_current_data_ex(array_hash, (void **)&data, &array_pointer) == SUCCESS; @@ -126,47 +165,7 @@ void php_grpc_read_args_array(zval *args_array, } args_index++; } -} - #else - -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) { - wrapped_grpc_channel *intern; - intern = ecalloc(1, sizeof(wrapped_grpc_channel) + - zend_object_properties_size(class_type)); - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); - intern->std.handlers = &channel_ce_handlers; - return &intern->std; -} - -void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args) { - HashTable *array_hash; - int args_index; - zval *data; - zend_string *key; - array_hash = HASH_OF(args_array); - if (!array_hash) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "array_hash is NULL", 1); - return; - } - args->num_args = zend_hash_num_elements(array_hash); - args->args = ecalloc(args->num_args, sizeof(grpc_arg)); - args_index = 0; ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, data) { if (key == NULL) { zend_throw_exception(spl_ce_InvalidArgumentException, @@ -189,9 +188,8 @@ void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args) { } args_index++; } ZEND_HASH_FOREACH_END(); -} - #endif +} /** * Construct an instance of the Channel class. If the $args array contains a diff --git a/src/php/ext/grpc/channel.h b/src/php/ext/grpc/channel.h index 94c633408ed..0b815657d33 100755 --- a/src/php/ext/grpc/channel.h +++ b/src/php/ext/grpc/channel.h @@ -48,32 +48,25 @@ /* Class entry for the PHP Channel class */ extern zend_class_entry *grpc_ce_channel; -#if PHP_MAJOR_VERSION < 7 - /* Wrapper struct for grpc_channel that can be associated with a PHP object */ -typedef struct wrapped_grpc_channel { - zend_object std; +PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_channel) grpc_channel *wrapped; -} wrapped_grpc_channel; +PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_channel) + +#if PHP_MAJOR_VERSION < 7 #define Z_WRAPPED_GRPC_CHANNEL_P(zv) \ (wrapped_grpc_channel *)zend_object_store_get_object(zv TSRMLS_CC) #else -/* Wrapper struct for grpc_channel that can be associated with a PHP object */ -typedef struct wrapped_grpc_channel { - grpc_channel *wrapped; - zend_object std; -} wrapped_grpc_channel; - static inline wrapped_grpc_channel *wrapped_grpc_channel_from_obj(zend_object *obj) { return (wrapped_grpc_channel*)((char*)(obj) - XtOffsetOf(wrapped_grpc_channel, std)); } -#define Z_WRAPPED_GRPC_CHANNEL_P(zv) \ +#define Z_WRAPPED_GRPC_CHANNEL_P(zv) \ wrapped_grpc_channel_from_obj(Z_OBJ_P((zv))) #endif /* PHP_MAJOR_VERSION */ diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c index e255b3004b0..1c2ea5ba829 100644 --- a/src/php/ext/grpc/channel_credentials.c +++ b/src/php/ext/grpc/channel_credentials.c @@ -96,18 +96,6 @@ zend_object_value create_wrapped_grpc_channel_credentials( return retval; } -zval *grpc_php_wrap_channel_credentials(grpc_channel_credentials - *wrapped TSRMLS_DC) { - zval *credentials_object; - MAKE_STD_ZVAL(credentials_object); - object_init_ex(credentials_object, grpc_ce_channel_credentials); - wrapped_grpc_channel_credentials *credentials = - (wrapped_grpc_channel_credentials *)zend_object_store_get_object( - credentials_object TSRMLS_CC); - credentials->wrapped = wrapped; - return credentials_object; -} - #else static zend_object_handlers channel_credentials_ce_handlers; @@ -135,16 +123,19 @@ zend_object *create_wrapped_grpc_channel_credentials(zend_class_entry return &intern->std; } -void grpc_php_wrap_channel_credentials(grpc_channel_credentials *wrapped, - zval *credentials_object) { +#endif + +zval *grpc_php_wrap_channel_credentials(grpc_channel_credentials + *wrapped TSRMLS_DC) { + zval *credentials_object; + PHP_GRPC_MAKE_STD_ZVAL(credentials_object); object_init_ex(credentials_object, grpc_ce_channel_credentials); wrapped_grpc_channel_credentials *credentials = Z_WRAPPED_GRPC_CHANNEL_CREDS_P(credentials_object); credentials->wrapped = wrapped; + return credentials_object; } -#endif - /** * Set default roots pem. * @param string pem_roots PEM encoding of the server root certificates @@ -171,13 +162,10 @@ PHP_METHOD(ChannelCredentials, setDefaultRootsPem) { */ PHP_METHOD(ChannelCredentials, createDefault) { grpc_channel_credentials *creds = grpc_google_default_credentials_create(); -#if PHP_MAJOR_VERSION < 7 - zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); + zval *creds_object; + PHP_GRPC_MAKE_STD_ZVAL(creds_object); + creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); -#else - grpc_php_wrap_channel_credentials(creds, return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } /** @@ -213,13 +201,10 @@ PHP_METHOD(ChannelCredentials, createSsl) { grpc_channel_credentials *creds = grpc_ssl_credentials_create( pem_root_certs, pem_key_cert_pair.private_key == NULL ? NULL : &pem_key_cert_pair, NULL); -#if PHP_MAJOR_VERSION < 7 - zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); + zval *creds_object; + PHP_GRPC_MAKE_STD_ZVAL(creds_object); + creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); -#else - grpc_php_wrap_channel_credentials(creds, return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } /** @@ -244,19 +229,13 @@ PHP_METHOD(ChannelCredentials, createComposite) { Z_WRAPPED_GRPC_CHANNEL_CREDS_P(cred1_obj); wrapped_grpc_call_credentials *cred2 = Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj); -#if PHP_MAJOR_VERSION < 7 grpc_channel_credentials *creds = grpc_composite_channel_credentials_create(cred1->wrapped, cred2->wrapped, NULL); - zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); + zval *creds_object; + PHP_GRPC_MAKE_STD_ZVAL(creds_object); + creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); -#else - grpc_channel_credentials *creds = - grpc_composite_channel_credentials_create(cred1->wrapped, - cred2->wrapped, NULL); - grpc_php_wrap_channel_credentials(creds, return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } /** diff --git a/src/php/ext/grpc/channel_credentials.h b/src/php/ext/grpc/channel_credentials.h index 0f7759daa68..21225db5fb9 100755 --- a/src/php/ext/grpc/channel_credentials.h +++ b/src/php/ext/grpc/channel_credentials.h @@ -49,27 +49,19 @@ /* Class entry for the ChannelCredentials PHP class */ extern zend_class_entry *grpc_ce_channel_credentials; -#if PHP_MAJOR_VERSION < 7 - /* Wrapper struct for grpc_channel_credentials that can be associated * with a PHP object */ -typedef struct wrapped_grpc_channel_credentials { - zend_object std; +PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_channel_credentials) grpc_channel_credentials *wrapped; -} wrapped_grpc_channel_credentials; +PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_channel_credentials) + +#if PHP_MAJOR_VERSION < 7 #define Z_WRAPPED_GRPC_CHANNEL_CREDS_P(zv) \ (wrapped_grpc_channel_credentials *)zend_object_store_get_object(zv TSRMLS_CC) #else -/* Wrapper struct for grpc_channel_credentials that can be associated - * with a PHP object */ -typedef struct wrapped_grpc_channel_credentials { - grpc_channel_credentials *wrapped; - zend_object std; -} wrapped_grpc_channel_credentials; - static inline wrapped_grpc_channel_credentials *wrapped_grpc_channel_creds_from_obj(zend_object *obj) { return @@ -78,7 +70,7 @@ static inline wrapped_grpc_channel_credentials 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))) #endif /* PHP_MAJOR_VERSION */ diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h index e4d0d4c90bb..58dffc38dc0 100644 --- a/src/php/ext/grpc/php7_wrapper.h +++ b/src/php/ext/grpc/php7_wrapper.h @@ -39,13 +39,45 @@ #define php_grpc_int int #define php_grpc_long long +#define php_grpc_ulong ulong +#define php_grpc_add_property_string(arg, name, context, b) \ + add_property_string(arg, name, context, b) +#define php_grpc_add_property_stringl(res, name, str, len, b) \ + add_property_stringl(res, name, str, len, b) +#define php_grpc_add_next_index_stringl(data, str, len, b) \ + add_next_index_stringl(data, str, len, b) + #define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val, dup) +#define PHP_GRPC_MAKE_STD_ZVAL(pzv) MAKE_STD_ZVAL(pzv) + +#define PHP_GRPC_WRAP_OBJECT_START(name) \ + typedef struct name { \ + zend_object std; +#define PHP_GRPC_WRAP_OBJECT_END(name) \ + } name; #else #define php_grpc_int size_t #define php_grpc_long zend_long +#define php_grpc_ulong zend_ulong +#define php_grpc_add_property_string(arg, name, context, b) \ + add_property_string(arg, name, context) +#define php_grpc_add_property_stringl(res, name, str, len, b) \ + add_property_stringl(res, name, str, len) +#define php_grpc_add_next_index_stringl(data, str, len, b) \ + add_next_index_stringl(data, str, len) + #define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val) +#define PHP_GRPC_MAKE_STD_ZVAL(pzv) \ + zval _stack_zval_##pzv; \ + pzv = &(_stack_zval_##pzv) + +#define PHP_GRPC_WRAP_OBJECT_START(name) \ + typedef struct name { +#define PHP_GRPC_WRAP_OBJECT_END(name) \ + zend_object std; \ + } name; #endif /* PHP_MAJOR_VERSION */ diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index e67e62c34e1..577b7070892 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -168,13 +168,9 @@ PHP_METHOD(Server, requestCall) { grpc_event event; wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis()); -#if PHP_MAJOR_VERSION < 7 zval *result; - MAKE_STD_ZVAL(result); + PHP_GRPC_MAKE_STD_ZVAL(result); object_init(result); -#else - object_init(return_value); -#endif grpc_call_details_init(&details); grpc_metadata_array_init(&metadata); @@ -195,40 +191,32 @@ PHP_METHOD(Server, requestCall) { 1 TSRMLS_CC); goto cleanup; } + php_grpc_add_property_string(result, "method", details.method, true); + php_grpc_add_property_string(result, "host", details.host, true); #if PHP_MAJOR_VERSION < 7 add_property_zval(result, "call", grpc_php_wrap_call(call, true TSRMLS_CC)); - add_property_string(result, "method", details.method, true); - add_property_string(result, "host", details.host, true); add_property_zval(result, "absolute_deadline", grpc_php_wrap_timeval(details.deadline TSRMLS_CC)); add_property_zval(result, "metadata", grpc_parse_metadata_array(&metadata TSRMLS_CC)); - -cleanup: - grpc_call_details_destroy(&details); - grpc_metadata_array_destroy(&metadata); - RETURN_DESTROY_ZVAL(result); - #else - zval zv_call; zval zv_timeval; zval zv_md; - grpc_php_wrap_call(call, true, &zv_call); - grpc_php_wrap_timeval(details.deadline, &zv_timeval); - grpc_parse_metadata_array(&metadata, &zv_md); - - add_property_zval(return_value, "call", &zv_call); - add_property_string(return_value, "method", details.method); - add_property_string(return_value, "host", details.host); - add_property_zval(return_value, "absolute_deadline", &zv_timeval); - add_property_zval(return_value, "metadata", &zv_md); + //TODO(thinkerou): why use zval* to unit test error? + zv_call = *grpc_php_wrap_call(call, true); + zv_timeval = *grpc_php_wrap_timeval(details.deadline); + zv_md = *grpc_parse_metadata_array(&metadata); + + add_property_zval(result, "call", &zv_call); + add_property_zval(result, "absolute_deadline", &zv_timeval); + add_property_zval(result, "metadata", &zv_md); +#endif cleanup: grpc_call_details_destroy(&details); grpc_metadata_array_destroy(&metadata); - RETURN_DESTROY_ZVAL(return_value); -#endif + RETURN_DESTROY_ZVAL(result); } /** diff --git a/src/php/ext/grpc/server.h b/src/php/ext/grpc/server.h index 603b9a71026..02ef1f79757 100755 --- a/src/php/ext/grpc/server.h +++ b/src/php/ext/grpc/server.h @@ -48,32 +48,25 @@ /* Class entry for the Server PHP class */ extern zend_class_entry *grpc_ce_server; -#if PHP_MAJOR_VERSION < 7 - /* Wrapper struct for grpc_server that can be associated with a PHP object */ -typedef struct wrapped_grpc_server { - zend_object std; +PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_server) grpc_server *wrapped; -} wrapped_grpc_server; +PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_server) + +#if PHP_MAJOR_VERSION < 7 #define Z_WRAPPED_GRPC_SERVER_P(zv) \ (wrapped_grpc_server *)zend_object_store_get_object(zv TSRMLS_CC) #else -/* Wrapper struct for grpc_server that can be associated with a PHP object */ -typedef struct wrapped_grpc_server { - grpc_server *wrapped; - zend_object std; -} wrapped_grpc_server; - static inline wrapped_grpc_server *wrapped_grpc_server_from_obj(zend_object *obj) { return (wrapped_grpc_server*)((char*)(obj) - XtOffsetOf(wrapped_grpc_server, std)); } -#define Z_WRAPPED_GRPC_SERVER_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 e61fc5b4a12..46416f5b47a 100644 --- a/src/php/ext/grpc/server_credentials.c +++ b/src/php/ext/grpc/server_credentials.c @@ -84,18 +84,6 @@ zend_object_value create_wrapped_grpc_server_credentials( return retval; } -zval *grpc_php_wrap_server_credentials(grpc_server_credentials - *wrapped TSRMLS_DC) { - zval *server_credentials_object; - MAKE_STD_ZVAL(server_credentials_object); - object_init_ex(server_credentials_object, grpc_ce_server_credentials); - wrapped_grpc_server_credentials *server_credentials = - (wrapped_grpc_server_credentials *)zend_object_store_get_object( - server_credentials_object TSRMLS_CC); - server_credentials->wrapped = wrapped; - return server_credentials_object; -} - #else static zend_object_handlers server_credentials_ce_handlers; @@ -123,16 +111,19 @@ zend_object *create_wrapped_grpc_server_credentials(zend_class_entry return &intern->std; } -void grpc_php_wrap_server_credentials(grpc_server_credentials *wrapped, - zval *server_credentials_object) { +#endif + +zval *grpc_php_wrap_server_credentials(grpc_server_credentials + *wrapped TSRMLS_DC) { + zval *server_credentials_object; + PHP_GRPC_MAKE_STD_ZVAL(server_credentials_object); object_init_ex(server_credentials_object, grpc_ce_server_credentials); wrapped_grpc_server_credentials *server_credentials = Z_WRAPPED_GRPC_SERVER_CREDS_P(server_credentials_object); server_credentials->wrapped = wrapped; + return server_credentials_object; } -#endif - /** * Create SSL credentials. * @param string pem_root_certs PEM encoding of the server root certificates @@ -163,13 +154,10 @@ PHP_METHOD(ServerCredentials, createSsl) { grpc_server_credentials *creds = grpc_ssl_server_credentials_create_ex( pem_root_certs, &pem_key_cert_pair, 1, GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, NULL); -#if PHP_MAJOR_VERSION < 7 - zval *creds_object = grpc_php_wrap_server_credentials(creds TSRMLS_CC); + zval *creds_object; + PHP_GRPC_MAKE_STD_ZVAL(creds_object); + creds_object = grpc_php_wrap_server_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); -#else - grpc_php_wrap_server_credentials(creds, return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } static zend_function_entry server_credentials_methods[] = { diff --git a/src/php/ext/grpc/server_credentials.h b/src/php/ext/grpc/server_credentials.h index 9df5950fa7d..2a90aa69a29 100755 --- a/src/php/ext/grpc/server_credentials.h +++ b/src/php/ext/grpc/server_credentials.h @@ -49,33 +49,26 @@ /* Class entry for the Server_Credentials PHP class */ extern zend_class_entry *grpc_ce_server_credentials; -#if PHP_MAJOR_VERSION < 7 - /* Wrapper struct for grpc_server_credentials that can be associated with a PHP * object */ -typedef struct wrapped_grpc_server_credentials { - zend_object std; +PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_server_credentials) grpc_server_credentials *wrapped; -} wrapped_grpc_server_credentials; +PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_server_credentials) + +#if PHP_MAJOR_VERSION < 7 #define Z_WRAPPED_GRPC_SERVER_CREDS_P(zv) \ (wrapped_grpc_server_credentials *)zend_object_store_get_object(zv TSRMLS_CC) #else -typedef struct wrapped_grpc_server_credentials { - grpc_server_credentials *wrapped; - zend_object std; -} wrapped_grpc_server_credentials; - static inline wrapped_grpc_server_credentials *wrapped_grpc_server_creds_from_obj(zend_object *obj) { 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))) #endif /* PHP_MAJOR_VERSION */ diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index a3ec62f13f4..18635ae46cc 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -78,17 +78,6 @@ zend_object_value create_wrapped_grpc_timeval(zend_class_entry *class_type return retval; } -zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC) { - zval *timeval_object; - MAKE_STD_ZVAL(timeval_object); - object_init_ex(timeval_object, grpc_ce_timeval); - wrapped_grpc_timeval *timeval = - (wrapped_grpc_timeval *)zend_object_store_get_object( - timeval_object TSRMLS_CC); - memcpy(&timeval->wrapped, &wrapped, sizeof(gpr_timespec)); - return timeval_object; -} - #else static zend_object_handlers timeval_ce_handlers; @@ -111,14 +100,17 @@ zend_object *create_wrapped_grpc_timeval(zend_class_entry *class_type) { return &intern->std; } -void grpc_php_wrap_timeval(gpr_timespec wrapped, zval *timeval_object) { +#endif + +zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC) { + zval *timeval_object; + PHP_GRPC_MAKE_STD_ZVAL(timeval_object); object_init_ex(timeval_object, grpc_ce_timeval); wrapped_grpc_timeval *timeval = Z_WRAPPED_GRPC_TIMEVAL_P(timeval_object); memcpy(&timeval->wrapped, &wrapped, sizeof(gpr_timespec)); + return timeval_object; } -#endif - /** * Constructs a new instance of the Timeval class * @param long $usec The number of microseconds in the interval @@ -156,16 +148,12 @@ PHP_METHOD(Timeval, add) { } wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj); -#if PHP_MAJOR_VERSION < 7 - zval *sum = + zval *sum; + PHP_GRPC_MAKE_STD_ZVAL(sum); + sum = grpc_php_wrap_timeval(gpr_time_add(self->wrapped, other->wrapped) TSRMLS_CC); RETURN_DESTROY_ZVAL(sum); -#else - grpc_php_wrap_timeval(gpr_time_add(self->wrapped, other->wrapped), - return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } /** @@ -186,16 +174,12 @@ PHP_METHOD(Timeval, subtract) { } wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj); -#if PHP_MAJOR_VERSION < 7 - zval *diff = + zval *diff; + PHP_GRPC_MAKE_STD_ZVAL(diff); + diff = grpc_php_wrap_timeval(gpr_time_sub(self->wrapped, other->wrapped) TSRMLS_CC); RETURN_DESTROY_ZVAL(diff); -#else - grpc_php_wrap_timeval(gpr_time_sub(self->wrapped, other->wrapped), - return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } /** @@ -255,13 +239,10 @@ PHP_METHOD(Timeval, similar) { * @return Timeval The current time */ PHP_METHOD(Timeval, now) { -#if PHP_MAJOR_VERSION < 7 - zval *now = grpc_php_wrap_timeval(gpr_now(GPR_CLOCK_REALTIME) TSRMLS_CC); + zval *now; + PHP_GRPC_MAKE_STD_ZVAL(now); + now = grpc_php_wrap_timeval(gpr_now(GPR_CLOCK_REALTIME) TSRMLS_CC); RETURN_DESTROY_ZVAL(now); -#else - grpc_php_wrap_timeval(gpr_now(GPR_CLOCK_REALTIME), return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } /** @@ -269,18 +250,13 @@ PHP_METHOD(Timeval, now) { * @return Timeval Zero length time interval */ PHP_METHOD(Timeval, zero) { -#if PHP_MAJOR_VERSION < 7 - zval *grpc_php_timeval_zero = + zval *grpc_php_timeval_zero; + PHP_GRPC_MAKE_STD_ZVAL(grpc_php_timeval_zero); + grpc_php_timeval_zero = grpc_php_wrap_timeval(gpr_time_0(GPR_CLOCK_REALTIME) TSRMLS_CC); RETURN_ZVAL(grpc_php_timeval_zero, false, /* Copy original before returning? */ true /* Destroy original before returning */); -#else - grpc_php_wrap_timeval(gpr_time_0(GPR_CLOCK_REALTIME), return_value); - RETURN_ZVAL(return_value, - false, /* Copy original before returning? */ - true /* Destroy original before returning */); -#endif } /** @@ -288,14 +264,11 @@ PHP_METHOD(Timeval, zero) { * @return Timeval Infinite future time value */ PHP_METHOD(Timeval, infFuture) { -#if PHP_MAJOR_VERSION < 7 - zval *grpc_php_timeval_inf_future = + zval *grpc_php_timeval_inf_future; + PHP_GRPC_MAKE_STD_ZVAL(grpc_php_timeval_inf_future); + grpc_php_timeval_inf_future = grpc_php_wrap_timeval(gpr_inf_future(GPR_CLOCK_REALTIME) TSRMLS_CC); RETURN_DESTROY_ZVAL(grpc_php_timeval_inf_future); -#else - grpc_php_wrap_timeval(gpr_inf_future(GPR_CLOCK_REALTIME), return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } /** @@ -303,14 +276,11 @@ PHP_METHOD(Timeval, infFuture) { * @return Timeval Infinite past time value */ PHP_METHOD(Timeval, infPast) { -#if PHP_MAJOR_VERSION < 7 - zval *grpc_php_timeval_inf_past = + zval *grpc_php_timeval_inf_past; + PHP_GRPC_MAKE_STD_ZVAL(grpc_php_timeval_inf_past); + grpc_php_timeval_inf_past = grpc_php_wrap_timeval(gpr_inf_past(GPR_CLOCK_REALTIME) TSRMLS_CC); RETURN_DESTROY_ZVAL(grpc_php_timeval_inf_past); -#else - grpc_php_wrap_timeval(gpr_inf_past(GPR_CLOCK_REALTIME), return_value); - RETURN_DESTROY_ZVAL(return_value); -#endif } /** diff --git a/src/php/ext/grpc/timeval.h b/src/php/ext/grpc/timeval.h index d362460c050..63a1d702f37 100755 --- a/src/php/ext/grpc/timeval.h +++ b/src/php/ext/grpc/timeval.h @@ -50,30 +50,24 @@ extern zend_class_entry *grpc_ce_timeval; /* Wrapper struct for timeval that can be associated with a PHP object */ -#if PHP_MAJOR_VERSION < 7 - -typedef struct wrapped_grpc_timeval { - zend_object std; +PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_timeval) gpr_timespec wrapped; -} wrapped_grpc_timeval; +PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_timeval) + +#if PHP_MAJOR_VERSION < 7 #define Z_WRAPPED_GRPC_TIMEVAL_P(zv) \ (wrapped_grpc_timeval *)zend_object_store_get_object(zv TSRMLS_CC) #else -typedef struct wrapped_grpc_timeval { - gpr_timespec wrapped; - zend_object std; -} wrapped_grpc_timeval; - static inline wrapped_grpc_timeval *wrapped_grpc_timeval_from_obj(zend_object *obj) { return (wrapped_grpc_timeval*)((char*)(obj) - XtOffsetOf(wrapped_grpc_timeval, std)); } -#define Z_WRAPPED_GRPC_TIMEVAL_P(zv) \ +#define Z_WRAPPED_GRPC_TIMEVAL_P(zv) \ wrapped_grpc_timeval_from_obj(Z_OBJ_P((zv))) #endif /* PHP_MAJOR_VERSION */ @@ -85,10 +79,6 @@ void grpc_init_timeval(TSRMLS_D); void grpc_shutdown_timeval(TSRMLS_D); /* Creates a Timeval object that wraps the given timeval struct */ -#if PHP_MAJOR_VERSION < 7 zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC); -#else -void grpc_php_wrap_timeval(gpr_timespec wrapped, zval *timeval_object); -#endif /* PHP_MAJOR_VERSION */ #endif /* NET_GRPC_PHP_GRPC_TIMEVAL_H_ */ From 8fa9d31cd7196dfe3af0ac1152f4166eec4ce5be Mon Sep 17 00:00:00 2001 From: thinkerou Date: Wed, 27 Jul 2016 04:13:59 +0800 Subject: [PATCH 11/32] fix indent use two spaces --- src/php/ext/grpc/timeval.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index 18635ae46cc..7d1ee2178ae 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -56,9 +56,9 @@ zend_class_entry *grpc_ce_timeval; /* 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); + wrapped_grpc_timeval *timeval = (wrapped_grpc_timeval *)object; + zend_object_std_dtor(&timeval->std TSRMLS_CC); + efree(timeval); } /* Initializes an instance of wrapped_grpc_timeval to be associated with an From b5282c7628b8373a3ebee30d525ed12937ae2004 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 26 Jul 2016 13:14:27 -0700 Subject: [PATCH 12/32] Remove .rb suffix from grpc-tools scripts, to be consistent with other gems --- .../bin/{grpc_tools_ruby_protoc.rb => grpc_tools_ruby_protoc} | 0 ...ools_ruby_protoc_plugin.rb => grpc_tools_ruby_protoc_plugin} | 0 src/ruby/tools/grpc-tools.gemspec | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename src/ruby/tools/bin/{grpc_tools_ruby_protoc.rb => grpc_tools_ruby_protoc} (100%) rename src/ruby/tools/bin/{grpc_tools_ruby_protoc_plugin.rb => grpc_tools_ruby_protoc_plugin} (100%) diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc.rb b/src/ruby/tools/bin/grpc_tools_ruby_protoc similarity index 100% rename from src/ruby/tools/bin/grpc_tools_ruby_protoc.rb rename to src/ruby/tools/bin/grpc_tools_ruby_protoc diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin.rb b/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin similarity index 100% rename from src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin.rb rename to src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin diff --git a/src/ruby/tools/grpc-tools.gemspec b/src/ruby/tools/grpc-tools.gemspec index 9fa4b66392d..68e2a7a1133 100644 --- a/src/ruby/tools/grpc-tools.gemspec +++ b/src/ruby/tools/grpc-tools.gemspec @@ -18,5 +18,5 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY - s.executables = %w( grpc_tools_ruby_protoc.rb grpc_tools_ruby_protoc_plugin.rb ) + s.executables = %w( grpc_tools_ruby_protoc grpc_tools_ruby_protoc_plugin ) end From b95870d85b3fdb95810034909d40527aebd2d82a Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Fri, 22 Jul 2016 12:37:10 -0700 Subject: [PATCH 13/32] php: fix composer.json --- examples/php/composer.json | 2 +- src/php/composer.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/php/composer.json b/examples/php/composer.json index a8b790b1de1..d40b5db059e 100644 --- a/examples/php/composer.json +++ b/examples/php/composer.json @@ -3,6 +3,6 @@ "description": "gRPC example for PHP", "minimum-stability": "dev", "require": { - "grpc/grpc": "v0.15.0" + "grpc/grpc": "v0.15.2" } } diff --git a/src/php/composer.json b/src/php/composer.json index 88418206e82..1eacc643a22 100644 --- a/src/php/composer.json +++ b/src/php/composer.json @@ -8,7 +8,9 @@ "version": "1.0.0", "require": { "php": ">=5.5.0", - "stanley-cheung/protobuf-php": "v0.6", + "stanley-cheung/protobuf-php": "v0.6" + }, + "require-dev": { "google/auth": "v0.9" }, "autoload": { From fdf27a49bb84f956ad8ef9c731e58e7755b78b0a Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Tue, 26 Jul 2016 17:46:59 -0700 Subject: [PATCH 14/32] remove reference to homebrew --- src/php/bin/determine_extension_dir.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/php/bin/determine_extension_dir.sh b/src/php/bin/determine_extension_dir.sh index b4342ac89fa..a59882506f9 100755 --- a/src/php/bin/determine_extension_dir.sh +++ b/src/php/bin/determine_extension_dir.sh @@ -29,11 +29,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. set -e default_extension_dir=$(php-config --extension-dir) -if command -v brew > /dev/null && \ - brew ls --versions | grep php5[56]-grpc > /dev/null; then - # the grpc php extension was installed by homebrew - : -elif [ ! -e $default_extension_dir/grpc.so ]; then +if [ ! -e $default_extension_dir/grpc.so ]; then # the grpc extension is not found in the default PHP extension dir # try the source modules directory module_dir=../ext/grpc/modules From b2d590463f9aacfa543a3171a040290b6f67a28e Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Tue, 26 Jul 2016 17:55:52 -0700 Subject: [PATCH 15/32] update README --- src/php/README.md | 43 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/src/php/README.md b/src/php/README.md index 8abedc40a3b..7e9819b256d 100644 --- a/src/php/README.md +++ b/src/php/README.md @@ -9,23 +9,12 @@ GA ## Environment -Prerequisite: `php` >=5.5, `phpize`, `pecl`, `phpunit` - -**Linux (Debian):** - -```sh -$ sudo apt-get install php5 php5-dev php-pear -``` - -**Linux (CentOS):** - -```sh -$ yum install php55w -$ yum --enablerepo=remi,remi-php55 install php-devel php-pear -``` - -**Mac OS X:** +Prerequisite: +* `php` 5.5 or above, 7.0 or above +* `pear` and `pecl` +* `phpunit` +**PEAR:** ```sh $ curl -O http://pear.php.net/go-pear.phar $ sudo php -d detect_unicode=0 go-pear.phar @@ -72,13 +61,7 @@ $ sudo make install ### gRPC PHP extension -Install the gRPC PHP extension from PECL - -```sh -$ sudo pecl install grpc -``` - -Or, compile from source +Compile the gRPC PHP extension ```sh $ cd grpc/src/php/ext/grpc @@ -148,12 +131,8 @@ Alternatively, you can download `protoc` binaries from [the protocol buffers Git You need to install `protoc-gen-php` to generate stub class `.php` files from service definition `.proto` files. ```sh -$ cd grpc/src/php/vendor/stanley-cheung/protobuf-php # if you had run `composer install` in the previous step - -OR - -$ git clone https://github.com/stanley-cheung/Protobuf-PHP # clone from github repo - +$ git clone https://github.com/stanley-cheung/Protobuf-PHP +$ cd Protobuf-PHP $ gem install rake ronn $ rake pear:package version=1.0 $ sudo pear install Protobuf-1.0.tgz @@ -175,7 +154,7 @@ Run a local server serving the math services. Please see [Node][] for how to run ```sh $ cd grpc $ npm install -$ nodejs src/node/test/math/math_server.js +$ node src/node/test/math/math_server.js ``` ### Run test client @@ -212,7 +191,7 @@ Make sure the Node math server is still running, as above. ```sh $ cd grpc $ npm install -$ nodejs src/node/test/math/math_server.js +$ node src/node/test/math/math_server.js ``` Make sure you have run `composer install` to generate the `vendor/autoload.php` file @@ -282,7 +261,7 @@ Make sure the Node math server is still running, as above. ```sh $ cd grpc $ npm install -$ nodejs src/node/test/math/math_server.js +$ node src/node/test/math/math_server.js ``` Make sure you have run `composer install` to generate the `vendor/autoload.php` file From 5a2c91806f49cc10362284c8f0d86771791a9692 Mon Sep 17 00:00:00 2001 From: Ken Payson Date: Tue, 26 Jul 2016 17:15:08 -0700 Subject: [PATCH 16/32] Updated ruby protos to use new _pb filename --- src/compiler/ruby_generator_helpers-inl.h | 4 +- src/ruby/.rubocop.yml | 4 +- src/ruby/bin/math_client.rb | 2 +- src/ruby/bin/{math.rb => math_pb.rb} | 0 src/ruby/bin/math_server.rb | 2 +- .../{math_services.rb => math_services_pb.rb} | 8 +- src/ruby/pb/grpc/health/checker.rb | 2 +- .../health/v1/{health.rb => health_pb.rb} | 0 ...alth_services.rb => health_services_pb.rb} | 2 +- ...vices.rb => echo_duplicate_services_pb.rb} | 4 +- .../testing/{metrics.rb => metrics_pb.rb} | 2 +- ...ics_services.rb => metrics_services_pb.rb} | 4 +- .../grpc/testing/{empty.rb => empty_pb.rb} | 0 .../testing/{messages.rb => messages_pb.rb} | 18 ++--- .../grpc/testing/{test.rb => test_pb.rb} | 4 +- .../{test_services.rb => test_services_pb.rb} | 2 +- src/ruby/pb/test/client.rb | 6 +- src/ruby/pb/test/proto/empty.rb | 15 ---- src/ruby/pb/test/proto/messages.rb | 80 ------------------- src/ruby/pb/test/proto/test.rb | 14 ---- src/ruby/pb/test/proto/test_services.rb | 64 --------------- src/ruby/pb/test/server.rb | 6 +- src/ruby/qps/client.rb | 2 +- src/ruby/qps/server.rb | 6 +- .../testing/{control.rb => control_pb.rb} | 6 +- .../testing/{messages.rb => messages_pb.rb} | 18 ++--- .../testing/{payloads.rb => payloads_pb.rb} | 0 .../testing/{services.rb => services_pb.rb} | 4 +- ...es_services.rb => services_services_pb.rb} | 2 +- .../grpc/testing/{stats.rb => stats_pb.rb} | 0 src/ruby/qps/worker.rb | 2 +- src/ruby/spec/pb/duplicate/codegen_spec.rb | 4 +- src/ruby/spec/pb/health/checker_spec.rb | 8 +- src/ruby/stress/metrics_server.rb | 4 +- 34 files changed, 62 insertions(+), 237 deletions(-) rename src/ruby/bin/{math.rb => math_pb.rb} (100%) mode change 100755 => 100644 rename src/ruby/bin/{math_services.rb => math_services_pb.rb} (92%) mode change 100755 => 100644 rename src/ruby/pb/grpc/health/v1/{health.rb => health_pb.rb} (100%) rename src/ruby/pb/grpc/health/v1/{health_services.rb => health_services_pb.rb} (98%) rename src/ruby/pb/grpc/testing/duplicate/{echo_duplicate_services.rb => echo_duplicate_services_pb.rb} (93%) rename src/ruby/pb/grpc/testing/{metrics.rb => metrics_pb.rb} (94%) rename src/ruby/pb/grpc/testing/{metrics_services.rb => metrics_services_pb.rb} (95%) rename src/ruby/pb/src/proto/grpc/testing/{empty.rb => empty_pb.rb} (100%) rename src/ruby/pb/src/proto/grpc/testing/{messages.rb => messages_pb.rb} (88%) rename src/ruby/pb/src/proto/grpc/testing/{test.rb => test_pb.rb} (72%) rename src/ruby/pb/src/proto/grpc/testing/{test_services.rb => test_services_pb.rb} (99%) delete mode 100644 src/ruby/pb/test/proto/empty.rb delete mode 100644 src/ruby/pb/test/proto/messages.rb delete mode 100644 src/ruby/pb/test/proto/test.rb delete mode 100644 src/ruby/pb/test/proto/test_services.rb rename src/ruby/qps/src/proto/grpc/testing/{control.rb => control_pb.rb} (97%) rename src/ruby/qps/src/proto/grpc/testing/{messages.rb => messages_pb.rb} (88%) rename src/ruby/qps/src/proto/grpc/testing/{payloads.rb => payloads_pb.rb} (100%) rename src/ruby/qps/src/proto/grpc/testing/{services.rb => services_pb.rb} (72%) rename src/ruby/qps/src/proto/grpc/testing/{services_services.rb => services_services_pb.rb} (98%) rename src/ruby/qps/src/proto/grpc/testing/{stats.rb => stats_pb.rb} (100%) diff --git a/src/compiler/ruby_generator_helpers-inl.h b/src/compiler/ruby_generator_helpers-inl.h index ff6939ed9fe..aa3c22fea6d 100644 --- a/src/compiler/ruby_generator_helpers-inl.h +++ b/src/compiler/ruby_generator_helpers-inl.h @@ -48,7 +48,7 @@ inline bool ServicesFilename(const grpc::protobuf::FileDescriptor *file, file->name().find_last_of(".proto") == file->name().size() - 1) { *file_name_or_error = file->name().substr(0, file->name().size() - proto_suffix_length) + - "_services.rb"; + "_services_pb.rb"; return true; } else { *file_name_or_error = "Invalid proto file name: must end with .proto"; @@ -58,7 +58,7 @@ inline bool ServicesFilename(const grpc::protobuf::FileDescriptor *file, inline grpc::string MessagesRequireName( const grpc::protobuf::FileDescriptor *file) { - return Replace(file->name(), ".proto", ""); + return Replace(file->name(), ".proto", "_pb"); } // Get leading or trailing comments in a string. Comment lines start with "# ". diff --git a/src/ruby/.rubocop.yml b/src/ruby/.rubocop.yml index 34bb4775435..0f61ccfa812 100644 --- a/src/ruby/.rubocop.yml +++ b/src/ruby/.rubocop.yml @@ -5,8 +5,8 @@ inherit_from: .rubocop_todo.yml AllCops: Exclude: - 'bin/apis/**/*' - - 'bin/math.rb' - - 'bin/math_services.rb' + - 'bin/math_pb.rb' + - 'bin/math_services_pb.rb' - 'pb/grpc/health/v1/*' - 'pb/test/**/*' diff --git a/src/ruby/bin/math_client.rb b/src/ruby/bin/math_client.rb index d7e00e42938..1f238a798ba 100755 --- a/src/ruby/bin/math_client.rb +++ b/src/ruby/bin/math_client.rb @@ -40,7 +40,7 @@ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) require 'grpc' -require 'math_services' +require 'math_services_pb' require 'optparse' include GRPC::Core::TimeConsts diff --git a/src/ruby/bin/math.rb b/src/ruby/bin/math_pb.rb old mode 100755 new mode 100644 similarity index 100% rename from src/ruby/bin/math.rb rename to src/ruby/bin/math_pb.rb diff --git a/src/ruby/bin/math_server.rb b/src/ruby/bin/math_server.rb index 1ee4c5632d9..751a6ebcab7 100755 --- a/src/ruby/bin/math_server.rb +++ b/src/ruby/bin/math_server.rb @@ -42,7 +42,7 @@ $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) require 'forwardable' require 'grpc' require 'logger' -require 'math_services' +require 'math_services_pb' require 'optparse' # RubyLogger defines a logger for gRPC based on the standard ruby logger. diff --git a/src/ruby/bin/math_services.rb b/src/ruby/bin/math_services_pb.rb old mode 100755 new mode 100644 similarity index 92% rename from src/ruby/bin/math_services.rb rename to src/ruby/bin/math_services_pb.rb index 34c36abddae..2ba1825d4f4 --- a/src/ruby/bin/math_services.rb +++ b/src/ruby/bin/math_services_pb.rb @@ -32,7 +32,7 @@ # require 'grpc' -require 'math' +require 'math_pb' module Math module Math @@ -44,15 +44,15 @@ module Math self.unmarshal_class_method = :decode self.service_name = 'math.Math' - # Div divides args.dividend by args.divisor and returns the quotient and - # remainder. + # Div divides DivArgs.dividend by DivArgs.divisor and returns the quotient + # and remainder. rpc :Div, DivArgs, DivReply # DivMany accepts an arbitrary number of division args from the client stream # and sends back the results in the reply stream. The stream continues until # the client closes its end; the server does the same after sending all the # replies. The stream ends immediately if either end aborts. rpc :DivMany, stream(DivArgs), stream(DivReply) - # Fib generates numbers in the Fibonacci sequence. If args.limit > 0, Fib + # Fib generates numbers in the Fibonacci sequence. If FibArgs.limit > 0, Fib # generates up to limit numbers; otherwise it continues until the call is # canceled. Unlike Fib above, Fib has no final FibReply. rpc :Fib, FibArgs, stream(Num) diff --git a/src/ruby/pb/grpc/health/checker.rb b/src/ruby/pb/grpc/health/checker.rb index f7310d92894..4bce1744c48 100644 --- a/src/ruby/pb/grpc/health/checker.rb +++ b/src/ruby/pb/grpc/health/checker.rb @@ -28,7 +28,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require 'grpc' -require 'grpc/health/v1/health_services' +require 'grpc/health/v1/health_services_pb' require 'thread' module Grpc diff --git a/src/ruby/pb/grpc/health/v1/health.rb b/src/ruby/pb/grpc/health/v1/health_pb.rb similarity index 100% rename from src/ruby/pb/grpc/health/v1/health.rb rename to src/ruby/pb/grpc/health/v1/health_pb.rb diff --git a/src/ruby/pb/grpc/health/v1/health_services.rb b/src/ruby/pb/grpc/health/v1/health_services_pb.rb similarity index 98% rename from src/ruby/pb/grpc/health/v1/health_services.rb rename to src/ruby/pb/grpc/health/v1/health_services_pb.rb index 68a3956f54a..8cc01e91dc5 100644 --- a/src/ruby/pb/grpc/health/v1/health_services.rb +++ b/src/ruby/pb/grpc/health/v1/health_services_pb.rb @@ -32,7 +32,7 @@ # require 'grpc' -require 'grpc/health/v1/health' +require 'grpc/health/v1/health_pb' module Grpc module Health diff --git a/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services.rb b/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb similarity index 93% rename from src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services.rb rename to src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb index eb523ffa6f0..e51c2f087a0 100644 --- a/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services.rb +++ b/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb @@ -1,5 +1,5 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! -# Source: grpc/testing/duplicate/echo_duplicate.proto for package 'grpc.testing.duplicate' +# Source: src/proto/grpc/testing/duplicate/echo_duplicate.proto for package 'grpc.testing.duplicate' # Original file comments: # Copyright 2015, Google Inc. # All rights reserved. @@ -34,7 +34,7 @@ # require 'grpc' -require 'grpc/testing/duplicate/echo_duplicate' +require 'src/proto/grpc/testing/duplicate/echo_duplicate_pb' module Grpc module Testing diff --git a/src/ruby/pb/grpc/testing/metrics.rb b/src/ruby/pb/grpc/testing/metrics_pb.rb similarity index 94% rename from src/ruby/pb/grpc/testing/metrics.rb rename to src/ruby/pb/grpc/testing/metrics_pb.rb index 3b3c8cd61bb..77b6c90970f 100644 --- a/src/ruby/pb/grpc/testing/metrics.rb +++ b/src/ruby/pb/grpc/testing/metrics_pb.rb @@ -1,5 +1,5 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! -# source: grpc/testing/metrics.proto +# source: src/proto/grpc/testing/metrics.proto require 'google/protobuf' diff --git a/src/ruby/pb/grpc/testing/metrics_services.rb b/src/ruby/pb/grpc/testing/metrics_services_pb.rb similarity index 95% rename from src/ruby/pb/grpc/testing/metrics_services.rb rename to src/ruby/pb/grpc/testing/metrics_services_pb.rb index 467b7b3ee50..e46366b1fbe 100644 --- a/src/ruby/pb/grpc/testing/metrics_services.rb +++ b/src/ruby/pb/grpc/testing/metrics_services_pb.rb @@ -1,5 +1,5 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! -# Source: grpc/testing/metrics.proto for package 'grpc.testing' +# Source: src/proto/grpc/testing/metrics.proto for package 'grpc.testing' # Original file comments: # Copyright 2015-2016, Google Inc. # All rights reserved. @@ -38,7 +38,7 @@ # service. require 'grpc' -require 'grpc/testing/metrics' +require 'src/proto/grpc/testing/metrics_pb' module Grpc module Testing diff --git a/src/ruby/pb/src/proto/grpc/testing/empty.rb b/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb similarity index 100% rename from src/ruby/pb/src/proto/grpc/testing/empty.rb rename to src/ruby/pb/src/proto/grpc/testing/empty_pb.rb diff --git a/src/ruby/pb/src/proto/grpc/testing/messages.rb b/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb similarity index 88% rename from src/ruby/pb/src/proto/grpc/testing/messages.rb rename to src/ruby/pb/src/proto/grpc/testing/messages_pb.rb index 2bdfe0eade3..e27ccd0dc04 100644 --- a/src/ruby/pb/src/proto/grpc/testing/messages.rb +++ b/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb @@ -4,6 +4,9 @@ require 'google/protobuf' Google::Protobuf::DescriptorPool.generated_pool.build do + add_message "grpc.testing.BoolValue" do + optional :value, :bool, 1 + end add_message "grpc.testing.Payload" do optional :type, :enum, 1, "grpc.testing.PayloadType" optional :body, :bytes, 2 @@ -18,8 +21,9 @@ Google::Protobuf::DescriptorPool.generated_pool.build do optional :payload, :message, 3, "grpc.testing.Payload" optional :fill_username, :bool, 4 optional :fill_oauth_scope, :bool, 5 - optional :response_compression, :enum, 6, "grpc.testing.CompressionType" + optional :response_compressed, :message, 6, "grpc.testing.BoolValue" optional :response_status, :message, 7, "grpc.testing.EchoStatus" + optional :expect_compressed, :message, 8, "grpc.testing.BoolValue" end add_message "grpc.testing.SimpleResponse" do optional :payload, :message, 1, "grpc.testing.Payload" @@ -28,6 +32,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do end add_message "grpc.testing.StreamingInputCallRequest" do optional :payload, :message, 1, "grpc.testing.Payload" + optional :expect_compressed, :message, 2, "grpc.testing.BoolValue" end add_message "grpc.testing.StreamingInputCallResponse" do optional :aggregated_payload_size, :int32, 1 @@ -35,12 +40,12 @@ Google::Protobuf::DescriptorPool.generated_pool.build do add_message "grpc.testing.ResponseParameters" do optional :size, :int32, 1 optional :interval_us, :int32, 2 + optional :compressed, :message, 3, "grpc.testing.BoolValue" end add_message "grpc.testing.StreamingOutputCallRequest" do optional :response_type, :enum, 1, "grpc.testing.PayloadType" repeated :response_parameters, :message, 2, "grpc.testing.ResponseParameters" optional :payload, :message, 3, "grpc.testing.Payload" - optional :response_compression, :enum, 6, "grpc.testing.CompressionType" optional :response_status, :message, 7, "grpc.testing.EchoStatus" end add_message "grpc.testing.StreamingOutputCallResponse" do @@ -55,18 +60,12 @@ Google::Protobuf::DescriptorPool.generated_pool.build do end add_enum "grpc.testing.PayloadType" do value :COMPRESSABLE, 0 - value :UNCOMPRESSABLE, 1 - value :RANDOM, 2 - end - add_enum "grpc.testing.CompressionType" do - value :NONE, 0 - value :GZIP, 1 - value :DEFLATE, 2 end end module Grpc module Testing + BoolValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.BoolValue").msgclass Payload = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.Payload").msgclass EchoStatus = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.EchoStatus").msgclass SimpleRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.SimpleRequest").msgclass @@ -79,6 +78,5 @@ module Grpc ReconnectParams = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.ReconnectParams").msgclass ReconnectInfo = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.ReconnectInfo").msgclass PayloadType = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.PayloadType").enummodule - CompressionType = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.CompressionType").enummodule end end diff --git a/src/ruby/pb/src/proto/grpc/testing/test.rb b/src/ruby/pb/src/proto/grpc/testing/test_pb.rb similarity index 72% rename from src/ruby/pb/src/proto/grpc/testing/test.rb rename to src/ruby/pb/src/proto/grpc/testing/test_pb.rb index 245b5ce00cd..2cc98630314 100644 --- a/src/ruby/pb/src/proto/grpc/testing/test.rb +++ b/src/ruby/pb/src/proto/grpc/testing/test_pb.rb @@ -3,8 +3,8 @@ require 'google/protobuf' -require 'src/proto/grpc/testing/empty' -require 'src/proto/grpc/testing/messages' +require 'src/proto/grpc/testing/empty_pb' +require 'src/proto/grpc/testing/messages_pb' Google::Protobuf::DescriptorPool.generated_pool.build do end diff --git a/src/ruby/pb/src/proto/grpc/testing/test_services.rb b/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb similarity index 99% rename from src/ruby/pb/src/proto/grpc/testing/test_services.rb rename to src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb index 2652de5e6d2..fde328e4c5d 100644 --- a/src/ruby/pb/src/proto/grpc/testing/test_services.rb +++ b/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb @@ -35,7 +35,7 @@ # require 'grpc' -require 'src/proto/grpc/testing/test' +require 'src/proto/grpc/testing/test_pb' module Grpc module Testing diff --git a/src/ruby/pb/test/client.rb b/src/ruby/pb/test/client.rb index 066a7bb90f1..b9af160e7a3 100755 --- a/src/ruby/pb/test/client.rb +++ b/src/ruby/pb/test/client.rb @@ -52,9 +52,9 @@ require_relative '../../lib/grpc' require 'googleauth' require 'google/protobuf' -require_relative 'proto/empty' -require_relative 'proto/messages' -require_relative 'proto/test_services' +require_relative '../src/proto/grpc/testing/empty_pb' +require_relative '../src/proto/grpc/testing/messages_pb' +require_relative '../src/proto/grpc/testing/test_services_pb' AUTH_ENV = Google::Auth::CredentialsLoader::ENV_VAR diff --git a/src/ruby/pb/test/proto/empty.rb b/src/ruby/pb/test/proto/empty.rb deleted file mode 100644 index 559adcc85e7..00000000000 --- a/src/ruby/pb/test/proto/empty.rb +++ /dev/null @@ -1,15 +0,0 @@ -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: test/proto/empty.proto - -require 'google/protobuf' - -Google::Protobuf::DescriptorPool.generated_pool.build do - add_message "grpc.testing.Empty" do - end -end - -module Grpc - module Testing - Empty = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.Empty").msgclass - end -end diff --git a/src/ruby/pb/test/proto/messages.rb b/src/ruby/pb/test/proto/messages.rb deleted file mode 100644 index 5222c9824a7..00000000000 --- a/src/ruby/pb/test/proto/messages.rb +++ /dev/null @@ -1,80 +0,0 @@ -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: test/proto/messages.proto - -require 'google/protobuf' - -Google::Protobuf::DescriptorPool.generated_pool.build do - add_message "grpc.testing.Payload" do - optional :type, :enum, 1, "grpc.testing.PayloadType" - optional :body, :bytes, 2 - end - add_message "grpc.testing.EchoStatus" do - optional :code, :int32, 1 - optional :message, :string, 2 - end - add_message "grpc.testing.SimpleRequest" do - optional :response_type, :enum, 1, "grpc.testing.PayloadType" - optional :response_size, :int32, 2 - optional :payload, :message, 3, "grpc.testing.Payload" - optional :fill_username, :bool, 4 - optional :fill_oauth_scope, :bool, 5 - optional :response_compression, :enum, 6, "grpc.testing.CompressionType" - optional :response_status, :message, 7, "grpc.testing.EchoStatus" - end - add_message "grpc.testing.SimpleResponse" do - optional :payload, :message, 1, "grpc.testing.Payload" - optional :username, :string, 2 - optional :oauth_scope, :string, 3 - end - add_message "grpc.testing.StreamingInputCallRequest" do - optional :payload, :message, 1, "grpc.testing.Payload" - end - add_message "grpc.testing.StreamingInputCallResponse" do - optional :aggregated_payload_size, :int32, 1 - end - add_message "grpc.testing.ResponseParameters" do - optional :size, :int32, 1 - optional :interval_us, :int32, 2 - end - add_message "grpc.testing.StreamingOutputCallRequest" do - optional :response_type, :enum, 1, "grpc.testing.PayloadType" - repeated :response_parameters, :message, 2, "grpc.testing.ResponseParameters" - optional :payload, :message, 3, "grpc.testing.Payload" - optional :response_compression, :enum, 6, "grpc.testing.CompressionType" - optional :response_status, :message, 7, "grpc.testing.EchoStatus" - end - add_message "grpc.testing.StreamingOutputCallResponse" do - optional :payload, :message, 1, "grpc.testing.Payload" - end - add_message "grpc.testing.ReconnectInfo" do - optional :passed, :bool, 1 - repeated :backoff_ms, :int32, 2 - end - add_enum "grpc.testing.PayloadType" do - value :COMPRESSABLE, 0 - value :UNCOMPRESSABLE, 1 - value :RANDOM, 2 - end - add_enum "grpc.testing.CompressionType" do - value :NONE, 0 - value :GZIP, 1 - value :DEFLATE, 2 - end -end - -module Grpc - module Testing - Payload = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.Payload").msgclass - EchoStatus = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.EchoStatus").msgclass - SimpleRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.SimpleRequest").msgclass - SimpleResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.SimpleResponse").msgclass - StreamingInputCallRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.StreamingInputCallRequest").msgclass - StreamingInputCallResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.StreamingInputCallResponse").msgclass - ResponseParameters = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.ResponseParameters").msgclass - StreamingOutputCallRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.StreamingOutputCallRequest").msgclass - StreamingOutputCallResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.StreamingOutputCallResponse").msgclass - ReconnectInfo = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.ReconnectInfo").msgclass - PayloadType = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.PayloadType").enummodule - CompressionType = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.CompressionType").enummodule - end -end diff --git a/src/ruby/pb/test/proto/test.rb b/src/ruby/pb/test/proto/test.rb deleted file mode 100644 index 100eb6505c9..00000000000 --- a/src/ruby/pb/test/proto/test.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: test/proto/test.proto - -require 'google/protobuf' - -require 'test/proto/empty' -require 'test/proto/messages' -Google::Protobuf::DescriptorPool.generated_pool.build do -end - -module Grpc - module Testing - end -end diff --git a/src/ruby/pb/test/proto/test_services.rb b/src/ruby/pb/test/proto/test_services.rb deleted file mode 100644 index 9df9cc5860b..00000000000 --- a/src/ruby/pb/test/proto/test_services.rb +++ /dev/null @@ -1,64 +0,0 @@ -# Generated by the protocol buffer compiler. DO NOT EDIT! -# Source: test/proto/test.proto for package 'grpc.testing' - -require 'grpc' -require 'test/proto/test' - -module Grpc - module Testing - module TestService - - # TODO: add proto service documentation here - class Service - - include GRPC::GenericService - - self.marshal_class_method = :encode - self.unmarshal_class_method = :decode - self.service_name = 'grpc.testing.TestService' - - rpc :EmptyCall, Empty, Empty - rpc :UnaryCall, SimpleRequest, SimpleResponse - rpc :StreamingOutputCall, StreamingOutputCallRequest, stream(StreamingOutputCallResponse) - rpc :StreamingInputCall, stream(StreamingInputCallRequest), StreamingInputCallResponse - rpc :FullDuplexCall, stream(StreamingOutputCallRequest), stream(StreamingOutputCallResponse) - rpc :HalfDuplexCall, stream(StreamingOutputCallRequest), stream(StreamingOutputCallResponse) - end - - Stub = Service.rpc_stub_class - end - module UnimplementedService - - # TODO: add proto service documentation here - class Service - - include GRPC::GenericService - - self.marshal_class_method = :encode - self.unmarshal_class_method = :decode - self.service_name = 'grpc.testing.UnimplementedService' - - rpc :UnimplementedCall, Empty, Empty - end - - Stub = Service.rpc_stub_class - end - module ReconnectService - - # TODO: add proto service documentation here - class Service - - include GRPC::GenericService - - self.marshal_class_method = :encode - self.unmarshal_class_method = :decode - self.service_name = 'grpc.testing.ReconnectService' - - rpc :Start, Empty, Empty - rpc :Stop, Empty, ReconnectInfo - end - - Stub = Service.rpc_stub_class - end - end -end diff --git a/src/ruby/pb/test/server.rb b/src/ruby/pb/test/server.rb index 088f281dc47..0808121661c 100755 --- a/src/ruby/pb/test/server.rb +++ b/src/ruby/pb/test/server.rb @@ -50,9 +50,9 @@ require 'optparse' require 'grpc' -require 'test/proto/empty' -require 'test/proto/messages' -require 'test/proto/test_services' +require_relative '../src/proto/grpc/testing/empty_pb' +require_relative '../src/proto/grpc/testing/messages_pb' +require_relative '../src/proto/grpc/testing/test_services_pb' # DebugIsTruncated extends the default Logger to truncate debug messages class DebugIsTruncated < Logger diff --git a/src/ruby/qps/client.rb b/src/ruby/qps/client.rb index 917b01271e8..7ed648acefc 100644 --- a/src/ruby/qps/client.rb +++ b/src/ruby/qps/client.rb @@ -38,7 +38,7 @@ $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) require 'grpc' require 'histogram' -require 'src/proto/grpc/testing/services_services' +require 'src/proto/grpc/testing/services_services_pb' class Poisson def interarrival diff --git a/src/ruby/qps/server.rb b/src/ruby/qps/server.rb index 52a89ce847c..cd98ee1fd94 100644 --- a/src/ruby/qps/server.rb +++ b/src/ruby/qps/server.rb @@ -38,9 +38,9 @@ $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) require 'grpc' require 'qps-common' -require 'src/proto/grpc/testing/messages' -require 'src/proto/grpc/testing/services_services' -require 'src/proto/grpc/testing/stats' +require 'src/proto/grpc/testing/messages_pb' +require 'src/proto/grpc/testing/services_services_pb' +require 'src/proto/grpc/testing/stats_pb' class BenchmarkServiceImpl < Grpc::Testing::BenchmarkService::Service def unary_call(req, _call) diff --git a/src/ruby/qps/src/proto/grpc/testing/control.rb b/src/ruby/qps/src/proto/grpc/testing/control_pb.rb similarity index 97% rename from src/ruby/qps/src/proto/grpc/testing/control.rb rename to src/ruby/qps/src/proto/grpc/testing/control_pb.rb index 958fca320bc..02207a2b5d8 100644 --- a/src/ruby/qps/src/proto/grpc/testing/control.rb +++ b/src/ruby/qps/src/proto/grpc/testing/control_pb.rb @@ -3,8 +3,8 @@ require 'google/protobuf' -require 'src/proto/grpc/testing/payloads' -require 'src/proto/grpc/testing/stats' +require 'src/proto/grpc/testing/payloads_pb' +require 'src/proto/grpc/testing/stats_pb' Google::Protobuf::DescriptorPool.generated_pool.build do add_message "grpc.testing.PoissonParams" do optional :offered_load, :double, 1 @@ -109,6 +109,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do repeated :server_stats, :message, 4, "grpc.testing.ServerStats" repeated :server_cores, :int32, 5 optional :summary, :message, 6, "grpc.testing.ScenarioResultSummary" + repeated :client_success, :bool, 7 + repeated :server_success, :bool, 8 end add_enum "grpc.testing.ClientType" do value :SYNC_CLIENT, 0 diff --git a/src/ruby/qps/src/proto/grpc/testing/messages.rb b/src/ruby/qps/src/proto/grpc/testing/messages_pb.rb similarity index 88% rename from src/ruby/qps/src/proto/grpc/testing/messages.rb rename to src/ruby/qps/src/proto/grpc/testing/messages_pb.rb index 2bdfe0eade3..e27ccd0dc04 100644 --- a/src/ruby/qps/src/proto/grpc/testing/messages.rb +++ b/src/ruby/qps/src/proto/grpc/testing/messages_pb.rb @@ -4,6 +4,9 @@ require 'google/protobuf' Google::Protobuf::DescriptorPool.generated_pool.build do + add_message "grpc.testing.BoolValue" do + optional :value, :bool, 1 + end add_message "grpc.testing.Payload" do optional :type, :enum, 1, "grpc.testing.PayloadType" optional :body, :bytes, 2 @@ -18,8 +21,9 @@ Google::Protobuf::DescriptorPool.generated_pool.build do optional :payload, :message, 3, "grpc.testing.Payload" optional :fill_username, :bool, 4 optional :fill_oauth_scope, :bool, 5 - optional :response_compression, :enum, 6, "grpc.testing.CompressionType" + optional :response_compressed, :message, 6, "grpc.testing.BoolValue" optional :response_status, :message, 7, "grpc.testing.EchoStatus" + optional :expect_compressed, :message, 8, "grpc.testing.BoolValue" end add_message "grpc.testing.SimpleResponse" do optional :payload, :message, 1, "grpc.testing.Payload" @@ -28,6 +32,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do end add_message "grpc.testing.StreamingInputCallRequest" do optional :payload, :message, 1, "grpc.testing.Payload" + optional :expect_compressed, :message, 2, "grpc.testing.BoolValue" end add_message "grpc.testing.StreamingInputCallResponse" do optional :aggregated_payload_size, :int32, 1 @@ -35,12 +40,12 @@ Google::Protobuf::DescriptorPool.generated_pool.build do add_message "grpc.testing.ResponseParameters" do optional :size, :int32, 1 optional :interval_us, :int32, 2 + optional :compressed, :message, 3, "grpc.testing.BoolValue" end add_message "grpc.testing.StreamingOutputCallRequest" do optional :response_type, :enum, 1, "grpc.testing.PayloadType" repeated :response_parameters, :message, 2, "grpc.testing.ResponseParameters" optional :payload, :message, 3, "grpc.testing.Payload" - optional :response_compression, :enum, 6, "grpc.testing.CompressionType" optional :response_status, :message, 7, "grpc.testing.EchoStatus" end add_message "grpc.testing.StreamingOutputCallResponse" do @@ -55,18 +60,12 @@ Google::Protobuf::DescriptorPool.generated_pool.build do end add_enum "grpc.testing.PayloadType" do value :COMPRESSABLE, 0 - value :UNCOMPRESSABLE, 1 - value :RANDOM, 2 - end - add_enum "grpc.testing.CompressionType" do - value :NONE, 0 - value :GZIP, 1 - value :DEFLATE, 2 end end module Grpc module Testing + BoolValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.BoolValue").msgclass Payload = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.Payload").msgclass EchoStatus = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.EchoStatus").msgclass SimpleRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.SimpleRequest").msgclass @@ -79,6 +78,5 @@ module Grpc ReconnectParams = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.ReconnectParams").msgclass ReconnectInfo = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.ReconnectInfo").msgclass PayloadType = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.PayloadType").enummodule - CompressionType = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.testing.CompressionType").enummodule end end diff --git a/src/ruby/qps/src/proto/grpc/testing/payloads.rb b/src/ruby/qps/src/proto/grpc/testing/payloads_pb.rb similarity index 100% rename from src/ruby/qps/src/proto/grpc/testing/payloads.rb rename to src/ruby/qps/src/proto/grpc/testing/payloads_pb.rb diff --git a/src/ruby/qps/src/proto/grpc/testing/services.rb b/src/ruby/qps/src/proto/grpc/testing/services_pb.rb similarity index 72% rename from src/ruby/qps/src/proto/grpc/testing/services.rb rename to src/ruby/qps/src/proto/grpc/testing/services_pb.rb index b2675c2afe5..5ce13bf8b04 100644 --- a/src/ruby/qps/src/proto/grpc/testing/services.rb +++ b/src/ruby/qps/src/proto/grpc/testing/services_pb.rb @@ -3,8 +3,8 @@ require 'google/protobuf' -require 'src/proto/grpc/testing/messages' -require 'src/proto/grpc/testing/control' +require 'src/proto/grpc/testing/messages_pb' +require 'src/proto/grpc/testing/control_pb' Google::Protobuf::DescriptorPool.generated_pool.build do end diff --git a/src/ruby/qps/src/proto/grpc/testing/services_services.rb b/src/ruby/qps/src/proto/grpc/testing/services_services_pb.rb similarity index 98% rename from src/ruby/qps/src/proto/grpc/testing/services_services.rb rename to src/ruby/qps/src/proto/grpc/testing/services_services_pb.rb index 94b9a1e164e..bdbb9c86d00 100644 --- a/src/ruby/qps/src/proto/grpc/testing/services_services.rb +++ b/src/ruby/qps/src/proto/grpc/testing/services_services_pb.rb @@ -34,7 +34,7 @@ # of unary/streaming requests/responses. require 'grpc' -require 'src/proto/grpc/testing/services' +require 'src/proto/grpc/testing/services_pb' module Grpc module Testing diff --git a/src/ruby/qps/src/proto/grpc/testing/stats.rb b/src/ruby/qps/src/proto/grpc/testing/stats_pb.rb similarity index 100% rename from src/ruby/qps/src/proto/grpc/testing/stats.rb rename to src/ruby/qps/src/proto/grpc/testing/stats_pb.rb diff --git a/src/ruby/qps/worker.rb b/src/ruby/qps/worker.rb index 665fb863526..12b8087ca05 100755 --- a/src/ruby/qps/worker.rb +++ b/src/ruby/qps/worker.rb @@ -44,7 +44,7 @@ require 'facter' require 'client' require 'qps-common' require 'server' -require 'src/proto/grpc/testing/services_services' +require 'src/proto/grpc/testing/services_services_pb' class WorkerServiceImpl < Grpc::Testing::WorkerService::Service def cpu_cores diff --git a/src/ruby/spec/pb/duplicate/codegen_spec.rb b/src/ruby/spec/pb/duplicate/codegen_spec.rb index 54c136c5102..ea0240965ca 100644 --- a/src/ruby/spec/pb/duplicate/codegen_spec.rb +++ b/src/ruby/spec/pb/duplicate/codegen_spec.rb @@ -44,7 +44,7 @@ describe 'Ping protobuf code generation' do # Get the current content service_path = File.join(root_dir, 'src', 'ruby', 'pb', 'grpc', 'testing', 'duplicate', - 'echo_duplicate_services.rb') + 'echo_duplicate_services_pb.rb') want = nil File.open(service_path) { |f| want = f.read } @@ -54,7 +54,7 @@ describe 'Ping protobuf code generation' do got = nil Dir.mktmpdir do |tmp_dir| gen_out = File.join(tmp_dir, 'src', 'proto', 'grpc', 'testing', - 'duplicate', 'echo_duplicate_services.rb') + 'duplicate', 'echo_duplicate_services_pb.rb') pid = spawn( 'protoc', '-I.', diff --git a/src/ruby/spec/pb/health/checker_spec.rb b/src/ruby/spec/pb/health/checker_spec.rb index de11c9fedf7..1b2fa968271 100644 --- a/src/ruby/spec/pb/health/checker_spec.rb +++ b/src/ruby/spec/pb/health/checker_spec.rb @@ -28,7 +28,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require 'grpc' -require 'grpc/health/v1/health' +require 'grpc/health/v1/health_pb' require 'grpc/health/checker' require 'open3' require 'tmpdir' @@ -43,7 +43,7 @@ describe 'Health protobuf code generation' do skip 'protoc || grpc_ruby_plugin missing, cannot verify health code-gen' else it 'should already be loaded indirectly i.e, used by the other specs' do - expect(require('grpc/health/v1/health_services')).to be(false) + expect(require('grpc/health/v1/health_services_pb')).to be(false) end it 'should have the same content as created by code generation' do @@ -52,7 +52,7 @@ describe 'Health protobuf code generation' do # Get the current content service_path = File.join(root_dir, 'ruby', 'pb', 'grpc', - 'health', 'v1', 'health_services.rb') + 'health', 'v1', 'health_services_pb.rb') want = nil File.open(service_path) { |f| want = f.read } @@ -62,7 +62,7 @@ describe 'Health protobuf code generation' do got = nil Dir.mktmpdir do |tmp_dir| gen_out = File.join(tmp_dir, 'grpc', 'health', 'v1', - 'health_services.rb') + 'health_services_pb.rb') pid = spawn( 'protoc', '-I.', diff --git a/src/ruby/stress/metrics_server.rb b/src/ruby/stress/metrics_server.rb index 13638c4d211..2b7f78577d9 100644 --- a/src/ruby/stress/metrics_server.rb +++ b/src/ruby/stress/metrics_server.rb @@ -27,8 +27,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -require_relative '../pb/grpc/testing/metrics.rb' -require_relative '../pb/grpc/testing/metrics_services.rb' +require_relative '../pb/grpc/testing/metrics_pb.rb' +require_relative '../pb/grpc/testing/metrics_services_pb.rb' class Gauge def get_name From d2583007f57da83579814086d5c811b72852d5aa Mon Sep 17 00:00:00 2001 From: thinkerou Date: Wed, 27 Jul 2016 09:48:45 +0800 Subject: [PATCH 17/32] add macro to php7_wrapper for reduce duplicate code --- src/php/ext/grpc/call.c | 24 +++++-------------- src/php/ext/grpc/call_credentials.c | 26 +++++---------------- src/php/ext/grpc/call_credentials.h | 4 ++-- src/php/ext/grpc/channel.c | 24 +++++-------------- src/php/ext/grpc/channel_credentials.c | 26 +++++---------------- src/php/ext/grpc/channel_credentials.h | 7 +++--- src/php/ext/grpc/php7_wrapper.h | 18 +++++++++++++++ src/php/ext/grpc/server.c | 32 +++++++------------------- src/php/ext/grpc/server_credentials.c | 26 +++++---------------- src/php/ext/grpc/server_credentials.h | 4 ++-- src/php/ext/grpc/timeval.c | 17 ++++---------- 11 files changed, 67 insertions(+), 141 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index fc832dacc23..add6841039f 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 29762afb297..aa589b0387f 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 822d077ccb0..8014b75c703 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 18ebcabc26f..9c4b265e947 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 1c2ea5ba829..938134cd9c0 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 21225db5fb9..39dc85283d5 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 58dffc38dc0..868432eb33c 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 577b7070892..dc815f4d7c5 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 46416f5b47a..b1471d06e22 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 2a90aa69a29..9551ec6c24f 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 7d1ee2178ae..e19bfe15656 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) { From 7b672f84735ec62d2c6ac374b95225c9861d78ba Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Fri, 22 Jul 2016 16:02:20 -0700 Subject: [PATCH 18/32] remove outdated php dockerfile dependency --- templates/tools/dockerfile/php_deps.include | 6 ------ tools/dockerfile/interoptest/grpc_interop_php/Dockerfile | 6 ------ .../stress_test/grpc_interop_stress_php/Dockerfile | 6 ------ tools/dockerfile/test/multilang_jessie_x64/Dockerfile | 6 ------ tools/dockerfile/test/php_jessie_x64/Dockerfile | 6 ------ 5 files changed, 30 deletions(-) diff --git a/templates/tools/dockerfile/php_deps.include b/templates/tools/dockerfile/php_deps.include index 739049b5ea0..da071e23ba4 100644 --- a/templates/tools/dockerfile/php_deps.include +++ b/templates/tools/dockerfile/php_deps.include @@ -3,11 +3,5 @@ # Install dependencies -RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' ${'\\'} - >> /etc/apt/sources.list.d/dotdeb.list" -RUN /bin/bash -l -c "echo 'deb-src http://packages.dotdeb.org wheezy-php55 all' ${'\\'} - >> /etc/apt/sources.list.d/dotdeb.list" -RUN wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add - - RUN apt-get update && apt-get install -y ${'\\'} git php5 php5-dev phpunit unzip diff --git a/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile b/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile index af83ee61646..a4115319976 100644 --- a/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile +++ b/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile @@ -83,12 +83,6 @@ RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc" # Install dependencies -RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' \ - >> /etc/apt/sources.list.d/dotdeb.list" -RUN /bin/bash -l -c "echo 'deb-src http://packages.dotdeb.org wheezy-php55 all' \ - >> /etc/apt/sources.list.d/dotdeb.list" -RUN wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add - - RUN apt-get update && apt-get install -y \ git php5 php5-dev phpunit unzip diff --git a/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile b/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile index 3092bd955e2..bdac01ae867 100644 --- a/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile +++ b/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile @@ -88,12 +88,6 @@ RUN pip install --upgrade google-api-python-client # Install dependencies -RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' \ - >> /etc/apt/sources.list.d/dotdeb.list" -RUN /bin/bash -l -c "echo 'deb-src http://packages.dotdeb.org wheezy-php55 all' \ - >> /etc/apt/sources.list.d/dotdeb.list" -RUN wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add - - RUN apt-get update && apt-get install -y \ git php5 php5-dev phpunit unzip diff --git a/tools/dockerfile/test/multilang_jessie_x64/Dockerfile b/tools/dockerfile/test/multilang_jessie_x64/Dockerfile index bd7728580fd..8790b0d4797 100644 --- a/tools/dockerfile/test/multilang_jessie_x64/Dockerfile +++ b/tools/dockerfile/test/multilang_jessie_x64/Dockerfile @@ -100,12 +100,6 @@ RUN /bin/bash -l -c "nvm alias default 4" # Install dependencies -RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' \ - >> /etc/apt/sources.list.d/dotdeb.list" -RUN /bin/bash -l -c "echo 'deb-src http://packages.dotdeb.org wheezy-php55 all' \ - >> /etc/apt/sources.list.d/dotdeb.list" -RUN wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add - - RUN apt-get update && apt-get install -y \ git php5 php5-dev phpunit unzip diff --git a/tools/dockerfile/test/php_jessie_x64/Dockerfile b/tools/dockerfile/test/php_jessie_x64/Dockerfile index e477295722a..91e8a90ac98 100644 --- a/tools/dockerfile/test/php_jessie_x64/Dockerfile +++ b/tools/dockerfile/test/php_jessie_x64/Dockerfile @@ -68,12 +68,6 @@ RUN apt-get update && apt-get install -y time && apt-get clean # Install dependencies -RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' \ - >> /etc/apt/sources.list.d/dotdeb.list" -RUN /bin/bash -l -c "echo 'deb-src http://packages.dotdeb.org wheezy-php55 all' \ - >> /etc/apt/sources.list.d/dotdeb.list" -RUN wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add - - RUN apt-get update && apt-get install -y \ git php5 php5-dev phpunit unzip From 99955ab0af074ef768968f25c72fbf15d2bd1862 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Fri, 22 Jul 2016 17:55:31 -0700 Subject: [PATCH 19/32] php: remove protobuf-php clone hack --- .../interoptest/grpc_interop_php/Dockerfile.template | 5 ----- .../stress_test/grpc_interop_stress_php/Dockerfile.template | 5 ----- tools/dockerfile/interoptest/grpc_interop_php/Dockerfile | 5 ----- .../stress_test/grpc_interop_stress_php/Dockerfile | 5 ----- 4 files changed, 20 deletions(-) diff --git a/templates/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile.template b/templates/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile.template index 476f9d3d3eb..a293bae8bc1 100644 --- a/templates/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile.template +++ b/templates/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile.template @@ -45,11 +45,6 @@ RUN curl -sS https://getcomposer.org/installer | php RUN mv composer.phar /usr/local/bin/composer - # As an attempt to work around #4212, try to prefetch Protobuf-PHP dependency - # into composer cache to prevent "composer install" from cloning on each build. - RUN git clone --mirror https://github.com/stanley-cheung/Protobuf-PHP.git ${'\\'} - /root/.composer/cache/vcs/git-github.com-stanley-cheung-Protobuf-PHP.git/ - # Download the patched PHP protobuf so that PHP gRPC clients can be generated # from proto3 schemas. RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php diff --git a/templates/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile.template b/templates/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile.template index 4cd069da34e..df61808937f 100644 --- a/templates/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile.template +++ b/templates/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile.template @@ -46,11 +46,6 @@ RUN curl -sS https://getcomposer.org/installer | php RUN mv composer.phar /usr/local/bin/composer - # As an attempt to work around #4212, try to prefetch Protobuf-PHP dependency - # into composer cache to prevent "composer install" from cloning on each build. - RUN git clone --mirror https://github.com/stanley-cheung/Protobuf-PHP.git ${'\\'} - /root/.composer/cache/vcs/git-github.com-stanley-cheung-Protobuf-PHP.git/ - # Download the patched PHP protobuf so that PHP gRPC clients can be generated # from proto3 schemas. RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php diff --git a/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile b/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile index a4115319976..4e94db24789 100644 --- a/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile +++ b/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile @@ -107,11 +107,6 @@ RUN /bin/bash -l -c "rvm all do gem install ronn rake" RUN curl -sS https://getcomposer.org/installer | php RUN mv composer.phar /usr/local/bin/composer -# As an attempt to work around #4212, try to prefetch Protobuf-PHP dependency -# into composer cache to prevent "composer install" from cloning on each build. -RUN git clone --mirror https://github.com/stanley-cheung/Protobuf-PHP.git \ - /root/.composer/cache/vcs/git-github.com-stanley-cheung-Protobuf-PHP.git/ - # Download the patched PHP protobuf so that PHP gRPC clients can be generated # from proto3 schemas. RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php diff --git a/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile b/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile index bdac01ae867..13afa1577f9 100644 --- a/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile +++ b/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile @@ -112,11 +112,6 @@ RUN /bin/bash -l -c "rvm all do gem install ronn rake" RUN curl -sS https://getcomposer.org/installer | php RUN mv composer.phar /usr/local/bin/composer -# As an attempt to work around #4212, try to prefetch Protobuf-PHP dependency -# into composer cache to prevent "composer install" from cloning on each build. -RUN git clone --mirror https://github.com/stanley-cheung/Protobuf-PHP.git \ - /root/.composer/cache/vcs/git-github.com-stanley-cheung-Protobuf-PHP.git/ - # Download the patched PHP protobuf so that PHP gRPC clients can be generated # from proto3 schemas. RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php From fa1e4fa7f130f770f9a24c419865975ea0fbac22 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Sat, 23 Jul 2016 19:07:36 -0700 Subject: [PATCH 20/32] php: add php7 to jenkins basic and interop tests --- .../grpc_interop_php/Dockerfile.template | 24 +--- .../grpc_interop_php7/Dockerfile.template | 37 ++++++ templates/tools/dockerfile/php7_deps.include | 45 +++++++ .../tools/dockerfile/php_common_deps.include | 21 +++ .../test/php7_jessie_x64/Dockerfile.template | 38 ++++++ .../interoptest/grpc_interop_php/Dockerfile | 3 +- .../interoptest/grpc_interop_php7/Dockerfile | 125 ++++++++++++++++++ .../grpc_interop_php7/build_interop.sh | 52 ++++++++ .../test/php7_jessie_x64/Dockerfile | 105 +++++++++++++++ tools/run_tests/run_interop_tests.py | 28 +++- tools/run_tests/run_tests.py | 37 ++++++ 11 files changed, 491 insertions(+), 24 deletions(-) create mode 100644 templates/tools/dockerfile/interoptest/grpc_interop_php7/Dockerfile.template create mode 100644 templates/tools/dockerfile/php7_deps.include create mode 100644 templates/tools/dockerfile/php_common_deps.include create mode 100644 templates/tools/dockerfile/test/php7_jessie_x64/Dockerfile.template create mode 100644 tools/dockerfile/interoptest/grpc_interop_php7/Dockerfile create mode 100755 tools/dockerfile/interoptest/grpc_interop_php7/build_interop.sh create mode 100644 tools/dockerfile/test/php7_jessie_x64/Dockerfile diff --git a/templates/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile.template b/templates/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile.template index a293bae8bc1..f37eadad745 100644 --- a/templates/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile.template +++ b/templates/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile.template @@ -1,6 +1,6 @@ %YAML 1.2 --- | - # Copyright 2015, Google Inc. + # Copyright 2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -35,25 +35,5 @@ <%include file="../../ruby_deps.include"/> <%include file="../../php_deps.include"/> <%include file="../../run_tests_addons.include"/> - # ronn: a ruby tool used to convert markdown to man pages, used during the - # install of Protobuf extensions - # - # rake: a ruby version of make used to build the PHP Protobuf extension - RUN /bin/bash -l -c "rvm all do gem install ronn rake" - - # Install composer - RUN curl -sS https://getcomposer.org/installer | php - RUN mv composer.phar /usr/local/bin/composer - - # Download the patched PHP protobuf so that PHP gRPC clients can be generated - # from proto3 schemas. - RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php - - RUN /bin/bash -l -c "rvm use ruby-2.1 ${'\\'} - && cd /var/local/git/protobuf-php ${'\\'} - && rvm all do rake pear:package version=1.0 ${'\\'} - && pear install Protobuf-1.0.tgz" - - # Define the default command. - CMD ["bash"] + <%include file="../../php_common_deps.include"/> diff --git a/templates/tools/dockerfile/interoptest/grpc_interop_php7/Dockerfile.template b/templates/tools/dockerfile/interoptest/grpc_interop_php7/Dockerfile.template new file mode 100644 index 00000000000..42157ee062c --- /dev/null +++ b/templates/tools/dockerfile/interoptest/grpc_interop_php7/Dockerfile.template @@ -0,0 +1,37 @@ +%YAML 1.2 +--- | + # Copyright 2016, 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. + + FROM debian:jessie + + <%include file="../../php7_deps.include"/> + <%include file="../../ruby_deps.include"/> + <%include file="../../run_tests_addons.include"/> + <%include file="../../php_common_deps.include"/> diff --git a/templates/tools/dockerfile/php7_deps.include b/templates/tools/dockerfile/php7_deps.include new file mode 100644 index 00000000000..a24e5064428 --- /dev/null +++ b/templates/tools/dockerfile/php7_deps.include @@ -0,0 +1,45 @@ +#================= +# PHP7 dependencies + +# Install Git and basic packages. +RUN apt-get update && apt-get install -y ${'\\'} + autoconf ${'\\'} + automake ${'\\'} + build-essential ${'\\'} + ccache ${'\\'} + curl ${'\\'} + git ${'\\'} + libcurl4-openssl-dev ${'\\'} + libgmp-dev ${'\\'} + libgmp3-dev ${'\\'} + libssl-dev ${'\\'} + libtool ${'\\'} + libxml2-dev ${'\\'} + pkg-config ${'\\'} + re2c ${'\\'} + time ${'\\'} + unzip ${'\\'} + wget ${'\\'} + zip && apt-get clean + +# Install other dependencies +RUN ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h +RUN wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz -O /var/local/bison-2.6.4.tar.gz +RUN cd /var/local ${'\\'} + && tar -zxvf bison-2.6.4.tar.gz ${'\\'} + && cd /var/local/bison-2.6.4 ${'\\'} + && ./configure ${'\\'} + && make ${'\\'} + && make install + +# Compile PHP7 from source +RUN git clone https://github.com/php/php-src /var/local/git/php-src +RUN cd /var/local/git/php-src ${'\\'} + && git checkout PHP-7.0.9 ${'\\'} + && ./buildconf --force ${'\\'} + && ./configure ${'\\'} + --with-gmp ${'\\'} + --with-openssl ${'\\'} + --with-zlib ${'\\'} + && make ${'\\'} + && make install diff --git a/templates/tools/dockerfile/php_common_deps.include b/templates/tools/dockerfile/php_common_deps.include new file mode 100644 index 00000000000..8839bb51554 --- /dev/null +++ b/templates/tools/dockerfile/php_common_deps.include @@ -0,0 +1,21 @@ +# ronn: a ruby tool used to convert markdown to man pages, used during the +# install of Protobuf extensions +# +# rake: a ruby version of make used to build the PHP Protobuf extension +RUN /bin/bash -l -c "rvm all do gem install ronn rake" + +# Install composer +RUN curl -sS https://getcomposer.org/installer | php +RUN mv composer.phar /usr/local/bin/composer + +# Download the patched PHP protobuf so that PHP gRPC clients can be generated +# from proto3 schemas. +RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php + +RUN /bin/bash -l -c "rvm use ruby-2.1 ${'\\'} + && cd /var/local/git/protobuf-php ${'\\'} + && rvm all do rake pear:package version=1.0 ${'\\'} + && pear install Protobuf-1.0.tgz" + +# Define the default command. +CMD ["bash"] diff --git a/templates/tools/dockerfile/test/php7_jessie_x64/Dockerfile.template b/templates/tools/dockerfile/test/php7_jessie_x64/Dockerfile.template new file mode 100644 index 00000000000..8cd86f03df5 --- /dev/null +++ b/templates/tools/dockerfile/test/php7_jessie_x64/Dockerfile.template @@ -0,0 +1,38 @@ +%YAML 1.2 +--- | + # 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. + + FROM debian:jessie + + <%include file="../../php7_deps.include"/> + <%include file="../../python_deps.include"/> + <%include file="../../run_tests_addons.include"/> + # Define the default command. + CMD ["bash"] diff --git a/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile b/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile index 4e94db24789..0d6171c1705 100644 --- a/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile +++ b/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -118,3 +118,4 @@ RUN /bin/bash -l -c "rvm use ruby-2.1 \ # Define the default command. CMD ["bash"] + diff --git a/tools/dockerfile/interoptest/grpc_interop_php7/Dockerfile b/tools/dockerfile/interoptest/grpc_interop_php7/Dockerfile new file mode 100644 index 00000000000..be8f25f8ffa --- /dev/null +++ b/tools/dockerfile/interoptest/grpc_interop_php7/Dockerfile @@ -0,0 +1,125 @@ +# Copyright 2016, 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. + +FROM debian:jessie + +#================= +# PHP7 dependencies + +# Install Git and basic packages. +RUN apt-get update && apt-get install -y \ + autoconf \ + automake \ + build-essential \ + ccache \ + curl \ + git \ + libcurl4-openssl-dev \ + libgmp-dev \ + libgmp3-dev \ + libssl-dev \ + libtool \ + libxml2-dev \ + pkg-config \ + re2c \ + time \ + unzip \ + wget \ + zip && apt-get clean + +# Install other dependencies +RUN ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h +RUN wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz -O /var/local/bison-2.6.4.tar.gz +RUN cd /var/local \ + && tar -zxvf bison-2.6.4.tar.gz \ + && cd /var/local/bison-2.6.4 \ + && ./configure \ + && make \ + && make install + +# Compile PHP7 from source +RUN git clone https://github.com/php/php-src /var/local/git/php-src +RUN cd /var/local/git/php-src \ + && git checkout PHP-7.0.9 \ + && ./buildconf --force \ + && ./configure \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + && make \ + && make install + +#================== +# Ruby dependencies + +# Install rvm +RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 +RUN \curl -sSL https://get.rvm.io | bash -s stable + +# Install Ruby 2.1 +RUN /bin/bash -l -c "rvm install ruby-2.1" +RUN /bin/bash -l -c "rvm use --default ruby-2.1" +RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc" +RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc" +RUN /bin/bash -l -c "echo 'rvm --default use ruby-2.1' >> ~/.bashrc" +RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc" + +# Prepare ccache +RUN ln -s /usr/bin/ccache /usr/local/bin/gcc +RUN ln -s /usr/bin/ccache /usr/local/bin/g++ +RUN ln -s /usr/bin/ccache /usr/local/bin/cc +RUN ln -s /usr/bin/ccache /usr/local/bin/c++ +RUN ln -s /usr/bin/ccache /usr/local/bin/clang +RUN ln -s /usr/bin/ccache /usr/local/bin/clang++ + + +RUN mkdir /var/local/jenkins + +# ronn: a ruby tool used to convert markdown to man pages, used during the +# install of Protobuf extensions +# +# rake: a ruby version of make used to build the PHP Protobuf extension +RUN /bin/bash -l -c "rvm all do gem install ronn rake" + +# Install composer +RUN curl -sS https://getcomposer.org/installer | php +RUN mv composer.phar /usr/local/bin/composer + +# Download the patched PHP protobuf so that PHP gRPC clients can be generated +# from proto3 schemas. +RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php + +RUN /bin/bash -l -c "rvm use ruby-2.1 \ + && cd /var/local/git/protobuf-php \ + && rvm all do rake pear:package version=1.0 \ + && pear install Protobuf-1.0.tgz" + +# Define the default command. +CMD ["bash"] + diff --git a/tools/dockerfile/interoptest/grpc_interop_php7/build_interop.sh b/tools/dockerfile/interoptest/grpc_interop_php7/build_interop.sh new file mode 100755 index 00000000000..261dded2821 --- /dev/null +++ b/tools/dockerfile/interoptest/grpc_interop_php7/build_interop.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Copyright 2016, 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. +# +# Builds PHP interop server and client in a base image. +set -ex + +mkdir -p /var/local/git +git clone --recursive /var/local/jenkins/grpc /var/local/git/grpc + +# copy service account keys if available +cp -r /var/local/jenkins/service_account $HOME || true + +cd /var/local/git/grpc +rvm --default use ruby-2.1 + +# gRPC core and protobuf need to be installed +make install + +(cd src/php/ext/grpc && phpize && ./configure && make) + +(cd third_party/protobuf && make install) + +(cd src/php && composer install) + +(cd src/php && protoc-gen-php -i tests/interop/ -o tests/interop/ tests/interop/test.proto) diff --git a/tools/dockerfile/test/php7_jessie_x64/Dockerfile b/tools/dockerfile/test/php7_jessie_x64/Dockerfile new file mode 100644 index 00000000000..5a0bf28f234 --- /dev/null +++ b/tools/dockerfile/test/php7_jessie_x64/Dockerfile @@ -0,0 +1,105 @@ +# 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. + +FROM debian:jessie + +#================= +# PHP7 dependencies + +# Install Git and basic packages. +RUN apt-get update && apt-get install -y \ + autoconf \ + automake \ + build-essential \ + ccache \ + curl \ + git \ + libcurl4-openssl-dev \ + libgmp-dev \ + libgmp3-dev \ + libssl-dev \ + libtool \ + libxml2-dev \ + pkg-config \ + re2c \ + time \ + unzip \ + wget \ + zip && apt-get clean + +# Install other dependencies +RUN ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h +RUN wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz -O /var/local/bison-2.6.4.tar.gz +RUN cd /var/local \ + && tar -zxvf bison-2.6.4.tar.gz \ + && cd /var/local/bison-2.6.4 \ + && ./configure \ + && make \ + && make install + +# Compile PHP7 from source +RUN git clone https://github.com/php/php-src /var/local/git/php-src +RUN cd /var/local/git/php-src \ + && git checkout PHP-7.0.9 \ + && ./buildconf --force \ + && ./configure \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + && make \ + && make install + +#==================== +# Python dependencies + +# Install dependencies + +RUN apt-get update && apt-get install -y \ + python-all-dev \ + python3-all-dev \ + python-pip + +# Install Python packages from PyPI +RUN pip install pip --upgrade +RUN pip install virtualenv +RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 six==1.10.0 + +# Prepare ccache +RUN ln -s /usr/bin/ccache /usr/local/bin/gcc +RUN ln -s /usr/bin/ccache /usr/local/bin/g++ +RUN ln -s /usr/bin/ccache /usr/local/bin/cc +RUN ln -s /usr/bin/ccache /usr/local/bin/c++ +RUN ln -s /usr/bin/ccache /usr/local/bin/clang +RUN ln -s /usr/bin/ccache /usr/local/bin/clang++ + + +RUN mkdir /var/local/jenkins + +# Define the default command. +CMD ["bash"] diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py index 13a4a49325a..782e316c37c 100755 --- a/tools/run_tests/run_interop_tests.py +++ b/tools/run_tests/run_interop_tests.py @@ -266,6 +266,31 @@ class PHPLanguage: return 'php' +class PHP7Language: + + def __init__(self): + self.client_cwd = None + self.safename = str(self) + + def client_cmd(self, args): + return ['src/php/bin/interop_client.sh'] + args + + def cloud_to_prod_env(self): + return {} + + def global_env(self): + return {} + + def unimplemented_test_cases(self): + return _SKIP_COMPRESSION + + def unimplemented_test_cases_server(self): + return [] + + def __str__(self): + return 'php7' + + class RubyLanguage: def __init__(self): @@ -344,6 +369,7 @@ _LANGUAGES = { 'java' : JavaLanguage(), 'node' : NodeLanguage(), 'php' : PHPLanguage(), + 'php7' : PHP7Language(), 'ruby' : RubyLanguage(), 'python' : PythonLanguage(), } @@ -407,7 +433,7 @@ def auth_options(language, test_case): default_account_arg = '--default_service_account=830293263384-compute@developer.gserviceaccount.com' if test_case in ['jwt_token_creds', 'per_rpc_creds', 'oauth2_auth_token']: - if language in ['csharp', 'node', 'php', 'python', 'ruby']: + if language in ['csharp', 'node', 'php', 'php7', 'python', 'ruby']: env['GOOGLE_APPLICATION_CREDENTIALS'] = key_filepath else: cmdargs += [key_file_arg] diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index d5f28fce6b5..5002bf47a41 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -379,6 +379,42 @@ class PhpLanguage(object): return 'php' +class Php7Language(object): + + def configure(self, config, args): + self.config = config + self.args = args + _check_compiler(self.args.compiler, ['default']) + + def test_specs(self): + return [self.config.job_spec(['src/php/bin/run_tests.sh'], None, + environ=_FORCE_ENVIRON_FOR_WRAPPERS)] + + def pre_build_steps(self): + return [] + + def make_targets(self): + return ['static_c', 'shared_c'] + + def make_options(self): + return [] + + def build_steps(self): + return [['tools/run_tests/build_php.sh']] + + def post_tests_steps(self): + return [['tools/run_tests/post_tests_php.sh']] + + def makefile_name(self): + return 'Makefile' + + def dockerfile_dir(self): + return 'tools/dockerfile/test/php7_jessie_%s' % _docker_arch_suffix(self.args.arch) + + def __str__(self): + return 'php7' + + class PythonConfig(collections.namedtuple('PythonConfig', [ 'name', 'build', 'run'])): """Tuple of commands (named s.t. 'what it says on the tin' applies)""" @@ -738,6 +774,7 @@ _LANGUAGES = { 'c': CLanguage('c', 'c'), 'node': NodeLanguage(), 'php': PhpLanguage(), + 'php7': Php7Language(), 'python': PythonLanguage(), 'ruby': RubyLanguage(), 'csharp': CSharpLanguage(), From 78f0fd4715e3fdd6cc412e4335cd6be834ae7b9d Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Mon, 25 Jul 2016 13:01:48 -0700 Subject: [PATCH 21/32] fix copyright --- .../tools/dockerfile/test/php7_jessie_x64/Dockerfile.template | 2 +- tools/dockerfile/test/php7_jessie_x64/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/tools/dockerfile/test/php7_jessie_x64/Dockerfile.template b/templates/tools/dockerfile/test/php7_jessie_x64/Dockerfile.template index 8cd86f03df5..e6a213d90d3 100644 --- a/templates/tools/dockerfile/test/php7_jessie_x64/Dockerfile.template +++ b/templates/tools/dockerfile/test/php7_jessie_x64/Dockerfile.template @@ -1,6 +1,6 @@ %YAML 1.2 --- | - # Copyright 2015, Google Inc. + # Copyright 2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/tools/dockerfile/test/php7_jessie_x64/Dockerfile b/tools/dockerfile/test/php7_jessie_x64/Dockerfile index 5a0bf28f234..221338956ef 100644 --- a/tools/dockerfile/test/php7_jessie_x64/Dockerfile +++ b/tools/dockerfile/test/php7_jessie_x64/Dockerfile @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without From 7d8c543d64c254612c594d1dc2e70fc3c4006e59 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Tue, 26 Jul 2016 19:39:04 -0700 Subject: [PATCH 22/32] regenerate from template --- tools/dockerfile/test/php7_jessie_x64/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/dockerfile/test/php7_jessie_x64/Dockerfile b/tools/dockerfile/test/php7_jessie_x64/Dockerfile index 221338956ef..c0b394e5d0c 100644 --- a/tools/dockerfile/test/php7_jessie_x64/Dockerfile +++ b/tools/dockerfile/test/php7_jessie_x64/Dockerfile @@ -88,7 +88,7 @@ RUN apt-get update && apt-get install -y \ # Install Python packages from PyPI RUN pip install pip --upgrade RUN pip install virtualenv -RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 six==1.10.0 +RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 # Prepare ccache RUN ln -s /usr/bin/ccache /usr/local/bin/gcc From 4f8df873b00a2778535fe71a8cb360d3dfd677b6 Mon Sep 17 00:00:00 2001 From: thinkerou Date: Wed, 27 Jul 2016 18:45:37 +0800 Subject: [PATCH 23/32] add php_grpc_zend_object macro and rename klass --- src/php/ext/grpc/call.c | 35 ++++++++++---------------- src/php/ext/grpc/call_credentials.c | 34 +++++++++---------------- src/php/ext/grpc/channel.c | 33 ++++++++++-------------- src/php/ext/grpc/channel_credentials.c | 34 +++++++++---------------- src/php/ext/grpc/php7_wrapper.h | 18 +++++++------ src/php/ext/grpc/server.c | 35 ++++++++++---------------- src/php/ext/grpc/server_credentials.c | 34 +++++++++---------------- src/php/ext/grpc/timeval.c | 33 ++++++++++-------------- 8 files changed, 98 insertions(+), 158 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index add6841039f..706c7d8c3ae 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -58,6 +58,9 @@ #include "byte_buffer.h" zend_class_entry *grpc_ce_call; +#if PHP_MAJOR_VERSION >= 7 +static zend_object_handlers call_ce_handlers; +#endif /* Frees and destroys an instance of wrapped_grpc_call */ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_call) @@ -66,44 +69,32 @@ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_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 */ -zend_object_value create_wrapped_grpc_call(zend_class_entry *class_type - TSRMLS_DC) { - zend_object_value retval; +php_grpc_zend_object create_wrapped_grpc_call(zend_class_entry *class_type + TSRMLS_DC) { wrapped_grpc_call *intern; - +#if PHP_MAJOR_VERSION < 7 + zend_object_value retval; intern = (wrapped_grpc_call *)emalloc(sizeof(wrapped_grpc_call)); memset(intern, 0, sizeof(wrapped_grpc_call)); - +#else + intern = ecalloc(1, sizeof(wrapped_grpc_call) + + zend_object_properties_size(class_type)); +#endif zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); +#if PHP_MAJOR_VERSION < 7 retval.handle = zend_objects_store_put( intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, free_wrapped_grpc_call, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); return retval; -} - #else - -static zend_object_handlers call_ce_handlers; - -/* 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) { - wrapped_grpc_call *intern; - intern = ecalloc(1, sizeof(wrapped_grpc_call) + - zend_object_properties_size(class_type)); - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); intern->std.handlers = &call_ce_handlers; return &intern->std; -} - #endif +} /* Creates and returns a PHP array object with the data in a * grpc_metadata_array. Returns NULL on failure */ diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c index aa589b0387f..0c55745524e 100644 --- a/src/php/ext/grpc/call_credentials.c +++ b/src/php/ext/grpc/call_credentials.c @@ -52,6 +52,9 @@ #include zend_class_entry *grpc_ce_call_credentials; +#if PHP_MAJOR_VERSION >= 7 +static zend_object_handlers call_credentials_ce_handlers; +#endif /* Frees and destroys an instance of wrapped_grpc_call_credentials */ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_call_credentials) @@ -60,46 +63,33 @@ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_call_credentials) } 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 */ -zend_object_value create_wrapped_grpc_call_credentials( +php_grpc_zend_object create_wrapped_grpc_call_credentials( zend_class_entry *class_type TSRMLS_DC) { - zend_object_value retval; wrapped_grpc_call_credentials *intern; - +#if PHP_MAJOR_VERSION < 7 + zend_object_value retval; intern = (wrapped_grpc_call_credentials *)emalloc( sizeof(wrapped_grpc_call_credentials)); memset(intern, 0, sizeof(wrapped_grpc_call_credentials)); - +#else + intern = ecalloc(1, sizeof(wrapped_grpc_call_credentials) + + zend_object_properties_size(class_type)); +#endif zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); +#if PHP_MAJOR_VERSION < 7 retval.handle = zend_objects_store_put( intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, free_wrapped_grpc_call_credentials, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); return retval; -} - #else - -static zend_object_handlers call_credentials_ce_handlers; - -/* 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 - *class_type) { - wrapped_grpc_call_credentials *intern; - intern = ecalloc(1, sizeof(wrapped_grpc_call_credentials) + - zend_object_properties_size(class_type)); - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); intern->std.handlers = &call_credentials_ce_handlers; return &intern->std; -} - #endif +} zval *grpc_php_wrap_call_credentials(grpc_call_credentials *wrapped TSRMLS_DC) { diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index 9c4b265e947..69264842f0c 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -56,6 +56,9 @@ #include "timeval.h" zend_class_entry *grpc_ce_channel; +#if PHP_MAJOR_VERSION >= 7 +static zend_object_handlers channel_ce_handlers; +#endif /* Frees and destroys an instance of wrapped_grpc_channel */ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_channel) @@ -64,42 +67,32 @@ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_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 */ -zend_object_value create_wrapped_grpc_channel(zend_class_entry *class_type - TSRMLS_DC) { - zend_object_value retval; +php_grpc_zend_object create_wrapped_grpc_channel(zend_class_entry *class_type + TSRMLS_DC) { wrapped_grpc_channel *intern; +#if PHP_MAJOR_VERSION < 7 + zend_object_value retval; intern = (wrapped_grpc_channel *)emalloc(sizeof(wrapped_grpc_channel)); memset(intern, 0, sizeof(wrapped_grpc_channel)); +#else + intern = ecalloc(1, sizeof(wrapped_grpc_channel) + + zend_object_properties_size(class_type)); +#endif zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); +#if PHP_MAJOR_VERSION < 7 retval.handle = zend_objects_store_put( intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, free_wrapped_grpc_channel, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); return retval; -} - #else - -static zend_object_handlers channel_ce_handlers; - -/* 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) { - wrapped_grpc_channel *intern; - intern = ecalloc(1, sizeof(wrapped_grpc_channel) + - zend_object_properties_size(class_type)); - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); intern->std.handlers = &channel_ce_handlers; return &intern->std; -} - #endif +} void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args TSRMLS_DC) { diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c index 938134cd9c0..cef435cc6ea 100644 --- a/src/php/ext/grpc/channel_credentials.c +++ b/src/php/ext/grpc/channel_credentials.c @@ -52,6 +52,9 @@ #include zend_class_entry *grpc_ce_channel_credentials; +#if PHP_MAJOR_VERSION >= 7 +static zend_object_handlers channel_credentials_ce_handlers; +#endif static char *default_pem_root_certs = NULL; static grpc_ssl_roots_override_result get_ssl_roots_override( @@ -70,46 +73,33 @@ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_channel_credentials) } 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 */ -zend_object_value create_wrapped_grpc_channel_credentials( +php_grpc_zend_object create_wrapped_grpc_channel_credentials( zend_class_entry *class_type TSRMLS_DC) { - zend_object_value retval; wrapped_grpc_channel_credentials *intern; - +#if PHP_MAJOR_VERSION < 7 + zend_object_value retval; intern = (wrapped_grpc_channel_credentials *)emalloc( sizeof(wrapped_grpc_channel_credentials)); memset(intern, 0, sizeof(wrapped_grpc_channel_credentials)); - +#else + intern = ecalloc(1, sizeof(wrapped_grpc_channel_credentials) + + zend_object_properties_size(class_type)); +#endif zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); +#if PHP_MAJOR_VERSION < 7 retval.handle = zend_objects_store_put( intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, free_wrapped_grpc_channel_credentials, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); return retval; -} - #else - -static zend_object_handlers channel_credentials_ce_handlers; - -/* 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 - *class_type) { - wrapped_grpc_channel_credentials *intern; - intern = ecalloc(1, sizeof(wrapped_grpc_channel_credentials) + - zend_object_properties_size(class_type)); - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); intern->std.handlers = &channel_credentials_ce_handlers; return &intern->std; -} - #endif +} zval *grpc_php_wrap_channel_credentials(grpc_channel_credentials *wrapped TSRMLS_DC) { diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h index 868432eb33c..7d7470f8a91 100644 --- a/src/php/ext/grpc/php7_wrapper.h +++ b/src/php/ext/grpc/php7_wrapper.h @@ -40,6 +40,7 @@ #define php_grpc_int int #define php_grpc_long long #define php_grpc_ulong ulong +#define php_grpc_zend_object zend_object_value #define php_grpc_add_property_string(arg, name, context, b) \ add_property_string(arg, name, context, b) #define php_grpc_add_property_stringl(res, name, str, len, b) \ @@ -56,9 +57,9 @@ #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_START(class_object) \ + void free_##class_object(void *object TSRMLS_DC) { \ + class_object *p = (class_object *)object; #define PHP_GRPC_FREE_WRAPPED_FUNC_END() \ zend_object_std_dtor(&p->std TSRMLS_CC); \ efree(p); \ @@ -69,6 +70,7 @@ #define php_grpc_int size_t #define php_grpc_long zend_long #define php_grpc_ulong zend_ulong +#define php_grpc_zend_object zend_object* #define php_grpc_add_property_string(arg, name, context, b) \ add_property_string(arg, name, context) #define php_grpc_add_property_stringl(res, name, str, len, b) \ @@ -87,12 +89,12 @@ zend_object std; \ } name; -#define WRAPPED_OBJECT_FROM_OBJ(klass, obj) \ - klass##_from_obj(obj); +#define WRAPPED_OBJECT_FROM_OBJ(class_object, obj) \ + class_object##_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_START(class_object) \ + static void free_##class_object(zend_object *object) { \ + class_object *p = WRAPPED_OBJECT_FROM_OBJ(class_object, object) #define PHP_GRPC_FREE_WRAPPED_FUNC_END() \ zend_object_std_dtor(&p->std); \ } diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index dc815f4d7c5..d8ebd4472d6 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -57,6 +57,9 @@ #include "timeval.h" zend_class_entry *grpc_ce_server; +#if PHP_MAJOR_VERSION >= 7 +static zend_object_handlers server_ce_handlers; +#endif /* Frees and destroys an instance of wrapped_grpc_server */ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_server) @@ -69,44 +72,32 @@ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_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 */ -zend_object_value create_wrapped_grpc_server(zend_class_entry *class_type - TSRMLS_DC) { - zend_object_value retval; +php_grpc_zend_object create_wrapped_grpc_server(zend_class_entry *class_type + TSRMLS_DC) { wrapped_grpc_server *intern; - +#if PHP_MAJOR_VERSION < 7 + zend_object_value retval; intern = (wrapped_grpc_server *)emalloc(sizeof(wrapped_grpc_server)); memset(intern, 0, sizeof(wrapped_grpc_server)); - +#else + intern = ecalloc(1, sizeof(wrapped_grpc_server) + + zend_object_properties_size(class_type)); +#endif zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); +#if PHP_MAJOR_VERSION < 7 retval.handle = zend_objects_store_put( intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, free_wrapped_grpc_server, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); return retval; -} - #else - -static zend_object_handlers server_ce_handlers; - -/* 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) { - wrapped_grpc_server *intern; - intern = ecalloc(1, sizeof(wrapped_grpc_server) + - zend_object_properties_size(class_type)); - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); intern->std.handlers = &server_ce_handlers; return &intern->std; -} - #endif +} /** * Constructs a new instance of the Server class diff --git a/src/php/ext/grpc/server_credentials.c b/src/php/ext/grpc/server_credentials.c index b1471d06e22..921436a1bba 100644 --- a/src/php/ext/grpc/server_credentials.c +++ b/src/php/ext/grpc/server_credentials.c @@ -50,6 +50,9 @@ #include zend_class_entry *grpc_ce_server_credentials; +#if PHP_MAJOR_VERSION >= 7 +static zend_object_handlers server_credentials_ce_handlers; +#endif /* Frees and destroys an instace of wrapped_grpc_server_credentials */ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_server_credentials) @@ -58,46 +61,33 @@ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_server_credentials) } 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 */ -zend_object_value create_wrapped_grpc_server_credentials( +php_grpc_zend_object create_wrapped_grpc_server_credentials( zend_class_entry *class_type TSRMLS_DC) { - zend_object_value retval; wrapped_grpc_server_credentials *intern; - +#if PHP_MAJOR_VERSION < 7 + zend_object_value retval; intern = (wrapped_grpc_server_credentials *)emalloc( sizeof(wrapped_grpc_server_credentials)); memset(intern, 0, sizeof(wrapped_grpc_server_credentials)); - +#else + intern = ecalloc(1, sizeof(wrapped_grpc_server_credentials) + + zend_object_properties_size(class_type)); +#endif zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); +#if PHP_MAJOR_VERSION < 7 retval.handle = zend_objects_store_put( intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, free_wrapped_grpc_server_credentials, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); return retval; -} - #else - -static zend_object_handlers server_credentials_ce_handlers; - -/* 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 - *class_type) { - wrapped_grpc_server_credentials *intern; - intern = ecalloc(1, sizeof(wrapped_grpc_server_credentials) + - zend_object_properties_size(class_type)); - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); intern->std.handlers = &server_credentials_ce_handlers; return &intern->std; -} - #endif +} zval *grpc_php_wrap_server_credentials(grpc_server_credentials *wrapped TSRMLS_DC) { diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index e19bfe15656..33d11f83cce 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -51,47 +51,40 @@ #include zend_class_entry *grpc_ce_timeval; +#if PHP_MAJOR_VERSION >= 7 +static zend_object_handlers timeval_ce_handlers; +#endif /* Frees and destroys an instance of wrapped_grpc_call */ 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 */ -zend_object_value create_wrapped_grpc_timeval(zend_class_entry *class_type - TSRMLS_DC) { - zend_object_value retval; +php_grpc_zend_object create_wrapped_grpc_timeval(zend_class_entry *class_type + TSRMLS_DC) { wrapped_grpc_timeval *intern; +#if PHP_MAJOR_VERSION < 7 + zend_object_value retval; intern = (wrapped_grpc_timeval *)emalloc(sizeof(wrapped_grpc_timeval)); memset(intern, 0, sizeof(wrapped_grpc_timeval)); +#else + intern = ecalloc(1, sizeof(wrapped_grpc_timeval) + + zend_object_properties_size(class_type)); +#endif zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); +#if PHP_MAJOR_VERSION < 7 retval.handle = zend_objects_store_put( intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, free_wrapped_grpc_timeval, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); return retval; -} - #else - -static zend_object_handlers timeval_ce_handlers; - -/* 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) { - wrapped_grpc_timeval *intern; - intern = ecalloc(1, sizeof(wrapped_grpc_timeval) + - zend_object_properties_size(class_type)); - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); intern->std.handlers = &timeval_ce_handlers; return &intern->std; -} - #endif +} zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC) { zval *timeval_object; From 0b316b041f9e26df523d47906705d10ff931191e Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 27 Jul 2016 11:11:32 -0700 Subject: [PATCH 24/32] Ruby Tools: automatically include plugin argument in protoc command --- src/ruby/tools/bin/grpc_tools_ruby_protoc.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc.rb b/src/ruby/tools/bin/grpc_tools_ruby_protoc.rb index 3a2a5b8dc96..dab06e7958d 100755 --- a/src/ruby/tools/bin/grpc_tools_ruby_protoc.rb +++ b/src/ruby/tools/bin/grpc_tools_ruby_protoc.rb @@ -32,10 +32,17 @@ require 'rbconfig' require_relative '../os_check' -protoc_name = 'protoc' + RbConfig::CONFIG['EXEEXT'] +ext = RbConfig::CONFIG['EXEEXT'] -protoc_path = File.join(File.dirname(__FILE__), - RbConfig::CONFIG['host_cpu'] + '-' + OS.os_name, - protoc_name) +protoc_name = 'protoc' + ext -exec([ protoc_path, protoc_path ], *ARGV) +plugin_name = 'grpc_ruby_plugin' + ext + +protoc_dir = File.join(File.dirname(__FILE__), + RbConfig::CONFIG['host_cpu'] + '-' + OS.os_name) + +protoc_path = File.join(protoc_dir, protoc_name) + +plugin_path = File.join(protoc_dir, plugin_name) + +exec([ protoc_path, protoc_path ], "--plugin=protoc-gen-grpc=#{plugin_path}", *ARGV) From eb9c54574662b5f9cc6812ef67d43fe654a3052e Mon Sep 17 00:00:00 2001 From: thinkerou Date: Thu, 28 Jul 2016 02:35:26 +0800 Subject: [PATCH 25/32] add some macro to reduce duplicate code --- src/php/ext/grpc/call.c | 382 +++++-------------------- src/php/ext/grpc/call_credentials.c | 11 +- src/php/ext/grpc/channel.c | 100 ++----- src/php/ext/grpc/channel_credentials.c | 11 +- src/php/ext/grpc/php7_wrapper.h | 93 ++++++ src/php/ext/grpc/server.c | 10 +- src/php/ext/grpc/server_credentials.c | 11 +- src/php/ext/grpc/timeval.c | 10 +- 8 files changed, 184 insertions(+), 444 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 706c7d8c3ae..46591d87385 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -73,15 +73,7 @@ PHP_GRPC_FREE_WRAPPED_FUNC_END() * of a class specified by class_type */ php_grpc_zend_object create_wrapped_grpc_call(zend_class_entry *class_type TSRMLS_DC) { - wrapped_grpc_call *intern; -#if PHP_MAJOR_VERSION < 7 - zend_object_value retval; - intern = (wrapped_grpc_call *)emalloc(sizeof(wrapped_grpc_call)); - memset(intern, 0, sizeof(wrapped_grpc_call)); -#else - intern = ecalloc(1, sizeof(wrapped_grpc_call) + - zend_object_properties_size(class_type)); -#endif + PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_call); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); #if PHP_MAJOR_VERSION < 7 @@ -111,11 +103,7 @@ zval *grpc_parse_metadata_array(grpc_metadata_array char *str_key; char *str_val; size_t key_len; -#if PHP_MAJOR_VERSION < 7 - zval **data = NULL; -#else - zval *data; -#endif + zval *data = NULL; array_hash = Z_ARRVAL_P(array); grpc_metadata *elem; @@ -126,14 +114,9 @@ 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_MAJOR_VERSION < 7 - if (zend_hash_find(array_hash, str_key, key_len, (void **)data) == + if (php_grpc_zend_hash_find(array_hash, str_key, key_len, (void **)&data) == SUCCESS) { - if (Z_TYPE_P(*data) != IS_ARRAY) { -#else - if ((data = zend_hash_str_find(array_hash, str_key, key_len)) != NULL) { if (Z_TYPE_P(data) != IS_ARRAY) { -#endif zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Metadata hash somehow contains wrong types.", 1 TSRMLS_CC); @@ -141,13 +124,8 @@ zval *grpc_parse_metadata_array(grpc_metadata_array efree(str_val); return NULL; } -#if PHP_MAJOR_VERSION < 7 - php_grpc_add_next_index_stringl(*data, str_val, elem->value_length, - false); -#else php_grpc_add_next_index_stringl(data, str_val, elem->value_length, false); -#endif } else { PHP_GRPC_MAKE_STD_ZVAL(inner_array); array_init(inner_array); @@ -164,96 +142,48 @@ zval *grpc_parse_metadata_array(grpc_metadata_array bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { HashTable *array_hash; HashTable *inner_array_hash; -#if PHP_MAJOR_VERSION < 7 - zval **inner_array; - zval **value; - HashPosition array_pointer; - HashPosition inner_array_pointer; - char *key; - uint key_len; - ulong index; -#else - zval *inner_array; zval *value; - zend_string *key; -#endif + zval *inner_array; if (Z_TYPE_P(array) != IS_ARRAY) { return false; } grpc_metadata_array_init(metadata); array_hash = Z_ARRVAL_P(array); -#if PHP_MAJOR_VERSION < 7 - for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer); - zend_hash_get_current_data_ex(array_hash, (void**)&inner_array, - &array_pointer) == SUCCESS; - zend_hash_move_forward_ex(array_hash, &array_pointer)) { - if (zend_hash_get_current_key_ex(array_hash, &key, &key_len, &index, 0, - &array_pointer) != HASH_KEY_IS_STRING) { - return false; - } - if (Z_TYPE_P(*inner_array) != IS_ARRAY) { - return false; - } - inner_array_hash = Z_ARRVAL_P(*inner_array); - metadata->capacity += zend_hash_num_elements(inner_array_hash); - } -#else - ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, inner_array) { - if (key == NULL) { + + char *key = NULL; + int key_type; + PHP_GRPC_HASH_FOREACH_STR_KEY_VAL_START(array_hash, key, key_type, + inner_array) + if (key_type != HASH_KEY_IS_STRING) { return false; } if (Z_TYPE_P(inner_array) != IS_ARRAY) { return false; } - inner_array_hash = HASH_OF(inner_array); + inner_array_hash = Z_ARRVAL_P(inner_array); metadata->capacity += zend_hash_num_elements(inner_array_hash); - } ZEND_HASH_FOREACH_END(); -#endif + PHP_GRPC_HASH_FOREACH_END() metadata->metadata = gpr_malloc(metadata->capacity * sizeof(grpc_metadata)); -#if PHP_MAJOR_VERSION < 7 - for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer); - zend_hash_get_current_data_ex(array_hash, (void**)&inner_array, - &array_pointer) == SUCCESS; - zend_hash_move_forward_ex(array_hash, &array_pointer)) { - if (zend_hash_get_current_key_ex(array_hash, &key, &key_len, &index, 0, - &array_pointer) != HASH_KEY_IS_STRING) { + char *key1 = NULL; + int key_type1; + PHP_GRPC_HASH_FOREACH_STR_KEY_VAL_START(array_hash, key1, key_type1, + inner_array) + if (key_type1 != HASH_KEY_IS_STRING) { return false; } - inner_array_hash = Z_ARRVAL_P(*inner_array); - for (zend_hash_internal_pointer_reset_ex(inner_array_hash, - &inner_array_pointer); - zend_hash_get_current_data_ex(inner_array_hash, (void**)&value, - &inner_array_pointer) == SUCCESS; - zend_hash_move_forward_ex(inner_array_hash, &inner_array_pointer)) { - if (Z_TYPE_P(*value) != IS_STRING) { - return false; - } - metadata->metadata[metadata->count].key = key; - metadata->metadata[metadata->count].value = Z_STRVAL_P(*value); - metadata->metadata[metadata->count].value_length = Z_STRLEN_P(*value); - metadata->count += 1; - } - } -#else - ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, inner_array) { - if (key == NULL) { - return false; - } - inner_array_hash = HASH_OF(inner_array); - - ZEND_HASH_FOREACH_VAL(inner_array_hash, value) { + inner_array_hash = Z_ARRVAL_P(inner_array); + PHP_GRPC_HASH_FOREACH_VAL_START(inner_array_hash, value) if (Z_TYPE_P(value) != IS_STRING) { return false; } - metadata->metadata[metadata->count].key = ZSTR_VAL(key); + metadata->metadata[metadata->count].key = key1; metadata->metadata[metadata->count].value = Z_STRVAL_P(value); metadata->metadata[metadata->count].value_length = Z_STRLEN_P(value); metadata->count += 1; - } ZEND_HASH_FOREACH_END(); - } ZEND_HASH_FOREACH_END(); -#endif + PHP_GRPC_HASH_FOREACH_END() + PHP_GRPC_HASH_FOREACH_END() return true; } @@ -321,23 +251,13 @@ PHP_METHOD(Call, startBatch) { PHP_GRPC_MAKE_STD_ZVAL(result); object_init(result); php_grpc_ulong index; -#if PHP_MAJOR_VERSION < 7 - zval **value; - zval **inner_value; - HashPosition array_pointer; - zval **message_value; - zval **message_flags; - char *key; - uint key_len; zval *recv_status; -#else + PHP_GRPC_MAKE_STD_ZVAL(recv_status); + object_init(recv_status); zval *value; zval *inner_value; zval *message_value; zval *message_flags; - zend_string *key; - zval recv_status; -#endif wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); grpc_op ops[8]; @@ -371,26 +291,23 @@ PHP_METHOD(Call, startBatch) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) { zend_throw_exception(spl_ce_InvalidArgumentException, - "start_batch expects an array", 1 TSRMLS_CC); - goto cleanup; + "start_batch expects an array", 1 TSRMLS_CC); goto cleanup; } -#if PHP_MAJOR_VERSION < 7 - array_hash = Z_ARRVAL_P(array); - for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer); - zend_hash_get_current_data_ex(array_hash, (void**)&value, - &array_pointer) == SUCCESS; - zend_hash_move_forward_ex(array_hash, &array_pointer)) { - if (zend_hash_get_current_key_ex(array_hash, &key, &key_len, &index, 0, - &array_pointer) != HASH_KEY_IS_LONG) { + + char *key = NULL; + int key_type; + PHP_GRPC_HASH_FOREACH_LONG_KEY_VAL_START(array_hash, key, key_type, index, + value) + if (key_type != HASH_KEY_IS_LONG) { zend_throw_exception(spl_ce_InvalidArgumentException, "batch keys must be integers", 1 TSRMLS_CC); goto cleanup; } switch(index) { case GRPC_OP_SEND_INITIAL_METADATA: - if (!create_metadata_array(*value, &metadata)) { + if (!create_metadata_array(value, &metadata)) { zend_throw_exception(spl_ce_InvalidArgumentException, "Bad metadata value given", 1 TSRMLS_CC); goto cleanup; @@ -401,41 +318,41 @@ PHP_METHOD(Call, startBatch) { metadata.metadata; break; case GRPC_OP_SEND_MESSAGE: - if (Z_TYPE_PP(value) != IS_ARRAY) { + if (Z_TYPE_P(value) != IS_ARRAY) { zend_throw_exception(spl_ce_InvalidArgumentException, "Expected an array for send message", 1 TSRMLS_CC); goto cleanup; } - message_hash = Z_ARRVAL_PP(value); - if (zend_hash_find(message_hash, "flags", sizeof("flags"), + message_hash = Z_ARRVAL_P(value); + if (php_grpc_zend_hash_find(message_hash, "flags", sizeof("flags"), (void **)&message_flags) == SUCCESS) { - if (Z_TYPE_PP(message_flags) != IS_LONG) { + if (Z_TYPE_P(message_flags) != IS_LONG) { zend_throw_exception(spl_ce_InvalidArgumentException, "Expected an int for message flags", 1 TSRMLS_CC); } - ops[op_num].flags = Z_LVAL_PP(message_flags) & GRPC_WRITE_USED_MASK; + ops[op_num].flags = Z_LVAL_P(message_flags) & GRPC_WRITE_USED_MASK; } - if (zend_hash_find(message_hash, "message", sizeof("message"), + if (php_grpc_zend_hash_find(message_hash, "message", sizeof("message"), (void **)&message_value) != SUCCESS || - Z_TYPE_PP(message_value) != IS_STRING) { + Z_TYPE_P(message_value) != IS_STRING) { zend_throw_exception(spl_ce_InvalidArgumentException, "Expected a string for send message", 1 TSRMLS_CC); goto cleanup; } ops[op_num].data.send_message = - string_to_byte_buffer(Z_STRVAL_PP(message_value), - Z_STRLEN_PP(message_value)); + string_to_byte_buffer(Z_STRVAL_P(message_value), + Z_STRLEN_P(message_value)); break; case GRPC_OP_SEND_CLOSE_FROM_CLIENT: break; case GRPC_OP_SEND_STATUS_FROM_SERVER: - status_hash = Z_ARRVAL_PP(value); - if (zend_hash_find(status_hash, "metadata", sizeof("metadata"), + status_hash = Z_ARRVAL_P(value); + if (php_grpc_zend_hash_find(status_hash, "metadata", sizeof("metadata"), (void **)&inner_value) == SUCCESS) { - if (!create_metadata_array(*inner_value, &trailing_metadata)) { + if (!create_metadata_array(inner_value, &trailing_metadata)) { zend_throw_exception(spl_ce_InvalidArgumentException, "Bad trailing metadata value given", 1 TSRMLS_CC); @@ -446,32 +363,32 @@ PHP_METHOD(Call, startBatch) { ops[op_num].data.send_status_from_server.trailing_metadata_count = trailing_metadata.count; } - if (zend_hash_find(status_hash, "code", sizeof("code"), + if (php_grpc_zend_hash_find(status_hash, "code", sizeof("code"), (void**)&inner_value) == SUCCESS) { - if (Z_TYPE_PP(inner_value) != IS_LONG) { + if (Z_TYPE_P(inner_value) != IS_LONG) { zend_throw_exception(spl_ce_InvalidArgumentException, "Status code must be an integer", 1 TSRMLS_CC); goto cleanup; } ops[op_num].data.send_status_from_server.status = - Z_LVAL_PP(inner_value); + Z_LVAL_P(inner_value); } else { zend_throw_exception(spl_ce_InvalidArgumentException, "Integer status code is required", 1 TSRMLS_CC); goto cleanup; } - if (zend_hash_find(status_hash, "details", sizeof("details"), + if (php_grpc_zend_hash_find(status_hash, "details", sizeof("details"), (void**)&inner_value) == SUCCESS) { - if (Z_TYPE_PP(inner_value) != IS_STRING) { + if (Z_TYPE_P(inner_value) != IS_STRING) { zend_throw_exception(spl_ce_InvalidArgumentException, "Status details must be a string", 1 TSRMLS_CC); goto cleanup; } ops[op_num].data.send_status_from_server.status_details = - Z_STRVAL_PP(inner_value); + Z_STRVAL_P(inner_value); } else { zend_throw_exception(spl_ce_InvalidArgumentException, "String status details is required", @@ -506,131 +423,7 @@ PHP_METHOD(Call, startBatch) { ops[op_num].flags = 0; ops[op_num].reserved = NULL; op_num++; - } - -#else - - array_hash = HASH_OF(array); - ZEND_HASH_FOREACH_KEY_VAL(array_hash, index, key, value) { - if (key) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "batch keys must be integers", 1); - goto cleanup; - } - - switch(index) { - case GRPC_OP_SEND_INITIAL_METADATA: - if (!create_metadata_array(value, &metadata)) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "Bad metadata value given", 1); - goto cleanup; - } - 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) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "Expected an array for send message", 1); - goto cleanup; - } - message_hash = HASH_OF(value); - if ((message_flags = - zend_hash_str_find(message_hash, "flags", - sizeof("flags") - 1)) != NULL) { - if (Z_TYPE_P(message_flags) != IS_LONG) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "Expected an int for message flags", 1); - } - ops[op_num].flags = Z_LVAL_P(message_flags) & GRPC_WRITE_USED_MASK; - } - if ((message_value = zend_hash_str_find(message_hash, "message", - sizeof("message") - 1)) - == NULL || Z_TYPE_P(message_value) != IS_STRING) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "Expected a string for send message", 1); - goto cleanup; - } - ops[op_num].data.send_message = - string_to_byte_buffer(Z_STRVAL_P(message_value), - Z_STRLEN_P(message_value)); - break; - case GRPC_OP_SEND_CLOSE_FROM_CLIENT: - break; - case GRPC_OP_SEND_STATUS_FROM_SERVER: - status_hash = HASH_OF(value); - if ((inner_value = zend_hash_str_find(status_hash, "metadata", - sizeof("metadata") - 1)) - != NULL) { - if (!create_metadata_array(inner_value, &trailing_metadata)) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "Bad trailing metadata value given", 1); - goto cleanup; - } - ops[op_num].data.send_status_from_server.trailing_metadata = - trailing_metadata.metadata; - ops[op_num].data.send_status_from_server.trailing_metadata_count = - trailing_metadata.count; - } - if ((inner_value = zend_hash_str_find(status_hash, "code", - sizeof("code") - 1)) != NULL) { - if (Z_TYPE_P(inner_value) != IS_LONG) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "Status code must be an integer", 1); - goto cleanup; - } - ops[op_num].data.send_status_from_server.status = - Z_LVAL_P(inner_value); - } else { - zend_throw_exception(spl_ce_InvalidArgumentException, - "Integer status code is required", 1); - goto cleanup; - } - if ((inner_value = zend_hash_str_find(status_hash, "details", - sizeof("details") - 1)) != NULL) { - if (Z_TYPE_P(inner_value) != IS_STRING) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "Status details must be a string", 1); - goto cleanup; - } - ops[op_num].data.send_status_from_server.status_details = - Z_STRVAL_P(inner_value); - } else { - zend_throw_exception(spl_ce_InvalidArgumentException, - "String status details is required", 1); - goto cleanup; - } - break; - case GRPC_OP_RECV_INITIAL_METADATA: - ops[op_num].data.recv_initial_metadata = &recv_metadata; - break; - case GRPC_OP_RECV_MESSAGE: - ops[op_num].data.recv_message = &message; - break; - case GRPC_OP_RECV_STATUS_ON_CLIENT: - ops[op_num].data.recv_status_on_client.trailing_metadata = - &recv_trailing_metadata; - ops[op_num].data.recv_status_on_client.status = &status; - ops[op_num].data.recv_status_on_client.status_details = - &status_details; - ops[op_num].data.recv_status_on_client.status_details_capacity = - &status_details_capacity; - break; - case GRPC_OP_RECV_CLOSE_ON_SERVER: - ops[op_num].data.recv_close_on_server.cancelled = &cancelled; - break; - default: - zend_throw_exception(spl_ce_InvalidArgumentException, - "Unrecognized key in batch", 1); - goto cleanup; - } - ops[op_num].op = (grpc_op_type)index; - ops[op_num].flags = 0; - ops[op_num].reserved = NULL; - op_num++; - } ZEND_HASH_FOREACH_END(); - -#endif + PHP_GRPC_HASH_FOREACH_END() error = grpc_call_start_batch(call->wrapped, ops, op_num, call->wrapped, NULL); @@ -642,7 +435,9 @@ PHP_METHOD(Call, startBatch) { } grpc_completion_queue_pluck(completion_queue, call->wrapped, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); -#if PHP_MAJOR_VERSION < 7 +#if PHP_MAJOR_VERSION >= 7 + zval recv_md; +#endif for (int i = 0; i < op_num; i++) { switch(ops[i].op) { case GRPC_OP_SEND_INITIAL_METADATA: @@ -658,73 +453,37 @@ PHP_METHOD(Call, startBatch) { add_property_bool(result, "send_status", true); break; case GRPC_OP_RECV_INITIAL_METADATA: +#if PHP_MAJOR_VERSION < 7 array = grpc_parse_metadata_array(&recv_metadata TSRMLS_CC); add_property_zval(result, "metadata", array); - Z_DELREF_P(array); - break; - case GRPC_OP_RECV_MESSAGE: - byte_buffer_to_string(message, &message_str, &message_len); - if (message_str == NULL) { - add_property_null(result, "message"); - } else { - add_property_stringl(result, "message", message_str, message_len, - false); - } - break; - case GRPC_OP_RECV_STATUS_ON_CLIENT: - MAKE_STD_ZVAL(recv_status); - object_init(recv_status); - array = grpc_parse_metadata_array(&recv_trailing_metadata TSRMLS_CC); - add_property_zval(recv_status, "metadata", array); - Z_DELREF_P(array); - add_property_long(recv_status, "code", status); - add_property_string(recv_status, "details", status_details, true); - add_property_zval(result, "status", recv_status); - Z_DELREF_P(recv_status); - break; - case GRPC_OP_RECV_CLOSE_ON_SERVER: - add_property_bool(result, "cancelled", cancelled); - break; - default: - break; - } - } #else - zval recv_md; - for (int i = 0; i < op_num; i++) { - switch(ops[i].op) { - case GRPC_OP_SEND_INITIAL_METADATA: - add_property_bool(result, "send_metadata", true); - break; - case GRPC_OP_SEND_MESSAGE: - add_property_bool(result, "send_message", true); - break; - case GRPC_OP_SEND_CLOSE_FROM_CLIENT: - add_property_bool(result, "send_close", true); - break; - case GRPC_OP_SEND_STATUS_FROM_SERVER: - add_property_bool(result, "send_status", true); - break; - case GRPC_OP_RECV_INITIAL_METADATA: recv_md = *grpc_parse_metadata_array(&recv_metadata); add_property_zval(result, "metadata", &recv_md); +#endif + PHP_GRPC_DELREF(array); break; case GRPC_OP_RECV_MESSAGE: byte_buffer_to_string(message, &message_str, &message_len); if (message_str == NULL) { add_property_null(result, "message"); } else { - add_property_stringl(result, "message", message_str, - message_len); + php_grpc_add_property_stringl(result, "message", message_str, + message_len, false); } break; case GRPC_OP_RECV_STATUS_ON_CLIENT: - object_init(&recv_status); +#if PHP_MAJOR_VERSION < 7 + array = grpc_parse_metadata_array(&recv_trailing_metadata TSRMLS_CC); + add_property_zval(recv_status, "metadata", array); +#else recv_md = *grpc_parse_metadata_array(&recv_trailing_metadata); - add_property_zval(&recv_status, "metadata", &recv_md); - add_property_long(&recv_status, "code", status); - add_property_string(&recv_status, "details", status_details); - add_property_zval(result, "status", &recv_status); + add_property_zval(recv_status, "metadata", &recv_md); +#endif + PHP_GRPC_DELREF(array); + add_property_long(recv_status, "code", status); + php_grpc_add_property_string(recv_status, "details", status_details, true); + add_property_zval(result, "status", recv_status); + PHP_GRPC_DELREF(recv_status); break; case GRPC_OP_RECV_CLOSE_ON_SERVER: add_property_bool(result, "cancelled", cancelled); @@ -733,7 +492,6 @@ PHP_METHOD(Call, startBatch) { break; } } -#endif cleanup: grpc_metadata_array_destroy(&metadata); diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c index 0c55745524e..b7d33d72394 100644 --- a/src/php/ext/grpc/call_credentials.c +++ b/src/php/ext/grpc/call_credentials.c @@ -67,16 +67,7 @@ PHP_GRPC_FREE_WRAPPED_FUNC_END() * associated with an object of a class specified by class_type */ php_grpc_zend_object create_wrapped_grpc_call_credentials( zend_class_entry *class_type TSRMLS_DC) { - wrapped_grpc_call_credentials *intern; -#if PHP_MAJOR_VERSION < 7 - zend_object_value retval; - intern = (wrapped_grpc_call_credentials *)emalloc( - sizeof(wrapped_grpc_call_credentials)); - memset(intern, 0, sizeof(wrapped_grpc_call_credentials)); -#else - intern = ecalloc(1, sizeof(wrapped_grpc_call_credentials) + - zend_object_properties_size(class_type)); -#endif + PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_call_credentials); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); #if PHP_MAJOR_VERSION < 7 diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index 69264842f0c..325e8f495ec 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -71,15 +71,7 @@ PHP_GRPC_FREE_WRAPPED_FUNC_END() * object of a class specified by class_type */ php_grpc_zend_object create_wrapped_grpc_channel(zend_class_entry *class_type TSRMLS_DC) { - wrapped_grpc_channel *intern; -#if PHP_MAJOR_VERSION < 7 - zend_object_value retval; - intern = (wrapped_grpc_channel *)emalloc(sizeof(wrapped_grpc_channel)); - memset(intern, 0, sizeof(wrapped_grpc_channel)); -#else - intern = ecalloc(1, sizeof(wrapped_grpc_channel) + - zend_object_properties_size(class_type)); -#endif + PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_channel); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); #if PHP_MAJOR_VERSION < 7 @@ -98,16 +90,6 @@ void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args TSRMLS_DC) { HashTable *array_hash; int args_index; -#if PHP_MAJOR_VERSION < 7 - HashPosition array_pointer; - zval **data; - char *key; - uint key_len; - ulong index; -#else - zval *data; - zend_string *key; -#endif array_hash = Z_ARRVAL_P(args_array); if (!array_hash) { zend_throw_exception(spl_ce_InvalidArgumentException, @@ -118,41 +100,17 @@ void php_grpc_read_args_array(zval *args_array, args->args = ecalloc(args->num_args, sizeof(grpc_arg)); args_index = 0; -#if PHP_MAJOR_VERSION < 7 - for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer); - zend_hash_get_current_data_ex(array_hash, (void **)&data, - &array_pointer) == SUCCESS; - zend_hash_move_forward_ex(array_hash, &array_pointer)) { - if (zend_hash_get_current_key_ex(array_hash, &key, &key_len, &index, 0, - &array_pointer) != HASH_KEY_IS_STRING) { + char *key = NULL; + zval *data; + int key_type; + + PHP_GRPC_HASH_FOREACH_STR_KEY_VAL_START(array_hash, key, key_type, data) + if (key_type != HASH_KEY_IS_STRING) { zend_throw_exception(spl_ce_InvalidArgumentException, "args keys must be strings", 1 TSRMLS_CC); return; } args->args[args_index].key = key; - switch (Z_TYPE_P(*data)) { - case IS_LONG: - args->args[args_index].value.integer = (int)Z_LVAL_P(*data); - args->args[args_index].type = GRPC_ARG_INTEGER; - break; - case IS_STRING: - args->args[args_index].value.string = Z_STRVAL_P(*data); - args->args[args_index].type = GRPC_ARG_STRING; - break; - default: - zend_throw_exception(spl_ce_InvalidArgumentException, - "args values must be int or string", 1 TSRMLS_CC); - return; - } - args_index++; - } -#else - ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, data) { - if (key == NULL) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "args keys must be strings", 1); - } - args->args[args_index].key = ZSTR_VAL(key); switch (Z_TYPE_P(data)) { case IS_LONG: args->args[args_index].value.integer = (int)Z_LVAL_P(data); @@ -164,12 +122,11 @@ void php_grpc_read_args_array(zval *args_array, break; default: zend_throw_exception(spl_ce_InvalidArgumentException, - "args values must be int or string", 1); + "args values must be int or string", 1 TSRMLS_CC); return; } args_index++; - } ZEND_HASH_FOREACH_END(); -#endif + PHP_GRPC_HASH_FOREACH_END() } /** @@ -181,11 +138,7 @@ void php_grpc_read_args_array(zval *args_array, */ PHP_METHOD(Channel, __construct) { wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis()); -#if PHP_MAJOR_VERSION < 7 - zval **creds_obj = NULL; -#else zval *creds_obj = NULL; -#endif char *target; php_grpc_int target_length; zval *args_array = NULL; @@ -200,43 +153,23 @@ PHP_METHOD(Channel, __construct) { "Channel expects a string and an array", 1 TSRMLS_CC); return; } -#if PHP_MAJOR_VERSION < 7 array_hash = Z_ARRVAL_P(args_array); - if (zend_hash_find(array_hash, "credentials", sizeof("credentials"), + if (php_grpc_zend_hash_find(array_hash, "credentials", sizeof("credentials"), (void **)&creds_obj) == SUCCESS) { - if (Z_TYPE_P(*creds_obj) == IS_NULL) { - creds = NULL; - zend_hash_del(array_hash, "credentials", 12); - } else if (zend_get_class_entry(*creds_obj TSRMLS_CC) != - grpc_ce_channel_credentials) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "credentials must be a ChannelCredentials object", - 1 TSRMLS_CC); - return; - } else { - creds = (wrapped_grpc_channel_credentials *)zend_object_store_get_object( - *creds_obj TSRMLS_CC); - zend_hash_del(array_hash, "credentials", 12); - } - } -#else - array_hash = HASH_OF(args_array); - if ((creds_obj = zend_hash_str_find(array_hash, "credentials", - sizeof("credentials") - 1)) != NULL) { if (Z_TYPE_P(creds_obj) == IS_NULL) { creds = NULL; - zend_hash_str_del(array_hash, "credentials", sizeof("credentials") - 1); - } else if (Z_OBJ_P(creds_obj)->ce != grpc_ce_channel_credentials) { + php_grpc_zend_hash_del(array_hash, "credentials", sizeof("credentials")); + } else if (PHP_GRPC_GET_CLASS_ENTRY(creds_obj) != + grpc_ce_channel_credentials) { zend_throw_exception(spl_ce_InvalidArgumentException, "credentials must be a ChannelCredentials object", - 1); + 1 TSRMLS_CC); return; } else { creds = Z_WRAPPED_GRPC_CHANNEL_CREDS_P(creds_obj); - zend_hash_str_del(array_hash, "credentials", sizeof("credentials") - 1); + php_grpc_zend_hash_del(array_hash, "credentials", sizeof("credentials")); } } -#endif php_grpc_read_args_array(args_array, &args TSRMLS_CC); if (creds == NULL) { channel->wrapped = grpc_insecure_channel_create(target, &args, NULL); @@ -292,8 +225,7 @@ PHP_METHOD(Channel, watchConnectivityState) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lO", &last_state, &deadline_obj, grpc_ce_timeval) == FAILURE) { zend_throw_exception(spl_ce_InvalidArgumentException, - "watchConnectivityState expects 1 long 1 timeval", - 1 TSRMLS_CC); + "watchConnectivityState expects 1 long 1 timeval", 1 TSRMLS_CC); return; } diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c index cef435cc6ea..32f24e5751f 100644 --- a/src/php/ext/grpc/channel_credentials.c +++ b/src/php/ext/grpc/channel_credentials.c @@ -77,16 +77,7 @@ PHP_GRPC_FREE_WRAPPED_FUNC_END() * associated with an object of a class specified by class_type */ php_grpc_zend_object create_wrapped_grpc_channel_credentials( zend_class_entry *class_type TSRMLS_DC) { - wrapped_grpc_channel_credentials *intern; -#if PHP_MAJOR_VERSION < 7 - zend_object_value retval; - intern = (wrapped_grpc_channel_credentials *)emalloc( - sizeof(wrapped_grpc_channel_credentials)); - memset(intern, 0, sizeof(wrapped_grpc_channel_credentials)); -#else - intern = ecalloc(1, sizeof(wrapped_grpc_channel_credentials) + - zend_object_properties_size(class_type)); -#endif + PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_channel_credentials); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); #if PHP_MAJOR_VERSION < 7 diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h index 7d7470f8a91..ba7f163676d 100644 --- a/src/php/ext/grpc/php7_wrapper.h +++ b/src/php/ext/grpc/php7_wrapper.h @@ -50,6 +50,7 @@ #define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val, dup) #define PHP_GRPC_MAKE_STD_ZVAL(pzv) MAKE_STD_ZVAL(pzv) +#define PHP_GRPC_DELREF(zv) Z_DELREF_P(zv) #define PHP_GRPC_WRAP_OBJECT_START(name) \ typedef struct name { \ @@ -65,6 +66,58 @@ efree(p); \ } +#define PHP_GRPC_ALLOC_CLASS_OBJECT(class_object) \ + class_object *intern; \ + zend_object_value retval; \ + intern = (class_object *)emalloc(sizeof(class_object)); \ + memset(intern, 0, sizeof(class_object)); + +#define PHP_GRPC_HASH_FOREACH_VAL_START(ht, data) \ + zval **tmp_data = NULL; \ + for (zend_hash_internal_pointer_reset(ht); \ + zend_hash_get_current_data(ht, (void**)&tmp_data) == SUCCESS; \ + zend_hash_move_forward(ht)) { \ + data = *tmp_data; + +#define PHP_GRPC_HASH_FOREACH_STR_KEY_VAL_START(ht, key, key_type, data) \ + zval **tmp##key = NULL; \ + ulong index##key; \ + uint len##key; \ + for (zend_hash_internal_pointer_reset(ht); \ + zend_hash_get_current_data(ht, (void**)&tmp##key) == SUCCESS; \ + zend_hash_move_forward(ht)) { \ + key_type = zend_hash_get_current_key_ex(ht, &key, &len##key, &index##key,\ + 0, NULL); \ + data = *tmp##key; + +#define PHP_GRPC_HASH_FOREACH_LONG_KEY_VAL_START(ht, key, key_type, index,\ + data) \ + zval **tmp##key = NULL; \ + uint len##key; \ + for (zend_hash_internal_pointer_reset(ht); \ + zend_hash_get_current_data(ht, (void**)&tmp##key) == SUCCESS; \ + zend_hash_move_forward(ht)) { \ + key_type = zend_hash_get_current_key_ex(ht, &key, &len##key, &index,\ + 0, NULL); \ + data = *tmp##key; + +#define PHP_GRPC_HASH_FOREACH_END() } + +static inline int php_grpc_zend_hash_find(HashTable *ht, char *key, int len, void **value) { + zval **data = NULL; + if (zend_hash_find(ht, key, len, (void **)&data) == SUCCESS) { + *value = *data; + return SUCCESS; + } else { + *value = NULL; + return FAILURE; + } +} + +#define php_grpc_zend_hash_del zend_hash_del + +#define PHP_GRPC_GET_CLASS_ENTRY(object) zend_get_class_entry(object TSRMLS_CC) + #else #define php_grpc_int size_t @@ -82,6 +135,7 @@ #define PHP_GRPC_MAKE_STD_ZVAL(pzv) \ zval _stack_zval_##pzv; \ pzv = &(_stack_zval_##pzv) +#define PHP_GRPC_DELREF(zv) #define PHP_GRPC_WRAP_OBJECT_START(name) \ typedef struct name { @@ -99,6 +153,45 @@ zend_object_std_dtor(&p->std); \ } +#define PHP_GRPC_ALLOC_CLASS_OBJECT(class_object) \ + class_object *intern; \ + intern = ecalloc(1, sizeof(class_object) + \ + zend_object_properties_size(class_type)); + +#define PHP_GRPC_HASH_FOREACH_VAL_START(ht, data) \ + ZEND_HASH_FOREACH_VAL(ht, data) { + +#define PHP_GRPC_HASH_FOREACH_STR_KEY_VAL_START(ht, key, key_type, data) \ + zend_string *(zs_##key); \ + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, (zs_##key), data) { \ + if ((zs_##key) == NULL) {key = NULL; key_type = HASH_KEY_IS_LONG;} \ + else {key = (zs_##key)->val; key_type = HASH_KEY_IS_STRING;} + +#define PHP_GRPC_HASH_FOREACH_LONG_KEY_VAL_START(ht, key, key_type, index, \ + data) \ + zend_string *(zs_##key); \ + ZEND_HASH_FOREACH_KEY_VAL(ht, index, zs_##key, data) { \ + if ((zs_##key) == NULL) {key = NULL; key_type = HASH_KEY_IS_LONG;} \ + else {key = (zs_##key)->val; key_type = HASH_KEY_IS_STRING;} + +#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) { + zval *value_tmp = zend_hash_str_find(ht, key, len -1); + if (value_tmp == NULL) { + return FAILURE; + } else { + *value = (void *)value_tmp; + return SUCCESS; + } +} + +static inline int php_grpc_zend_hash_del(HashTable *ht, char *key, int len) { + return zend_hash_str_del(ht, key, len - 1); +} + +#define PHP_GRPC_GET_CLASS_ENTRY(object) Z_OBJ_P(object)->ce + #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 d8ebd4472d6..2fc785eb31f 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -76,15 +76,7 @@ PHP_GRPC_FREE_WRAPPED_FUNC_END() * of a class specified by class_type */ php_grpc_zend_object create_wrapped_grpc_server(zend_class_entry *class_type TSRMLS_DC) { - wrapped_grpc_server *intern; -#if PHP_MAJOR_VERSION < 7 - zend_object_value retval; - intern = (wrapped_grpc_server *)emalloc(sizeof(wrapped_grpc_server)); - memset(intern, 0, sizeof(wrapped_grpc_server)); -#else - intern = ecalloc(1, sizeof(wrapped_grpc_server) + - zend_object_properties_size(class_type)); -#endif + PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_server); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); #if PHP_MAJOR_VERSION < 7 diff --git a/src/php/ext/grpc/server_credentials.c b/src/php/ext/grpc/server_credentials.c index 921436a1bba..4c147e09912 100644 --- a/src/php/ext/grpc/server_credentials.c +++ b/src/php/ext/grpc/server_credentials.c @@ -65,16 +65,7 @@ PHP_GRPC_FREE_WRAPPED_FUNC_END() * with an object of a class specified by class_type */ php_grpc_zend_object create_wrapped_grpc_server_credentials( zend_class_entry *class_type TSRMLS_DC) { - wrapped_grpc_server_credentials *intern; -#if PHP_MAJOR_VERSION < 7 - zend_object_value retval; - intern = (wrapped_grpc_server_credentials *)emalloc( - sizeof(wrapped_grpc_server_credentials)); - memset(intern, 0, sizeof(wrapped_grpc_server_credentials)); -#else - intern = ecalloc(1, sizeof(wrapped_grpc_server_credentials) + - zend_object_properties_size(class_type)); -#endif + PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_server_credentials); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); #if PHP_MAJOR_VERSION < 7 diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index 33d11f83cce..d0f75bef82c 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -63,15 +63,7 @@ PHP_GRPC_FREE_WRAPPED_FUNC_END() * object of a class specified by class_type */ php_grpc_zend_object create_wrapped_grpc_timeval(zend_class_entry *class_type TSRMLS_DC) { - wrapped_grpc_timeval *intern; -#if PHP_MAJOR_VERSION < 7 - zend_object_value retval; - intern = (wrapped_grpc_timeval *)emalloc(sizeof(wrapped_grpc_timeval)); - memset(intern, 0, sizeof(wrapped_grpc_timeval)); -#else - intern = ecalloc(1, sizeof(wrapped_grpc_timeval) + - zend_object_properties_size(class_type)); -#endif + PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_timeval); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); #if PHP_MAJOR_VERSION < 7 From dacb2e3a5c5b07b66aa2d999b2d2df682e4a9b1d Mon Sep 17 00:00:00 2001 From: thinkerou Date: Thu, 28 Jul 2016 08:25:41 +0800 Subject: [PATCH 26/32] fix unused var --- src/php/ext/grpc/call.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 46591d87385..10fc3feb63d 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -150,11 +150,11 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { grpc_metadata_array_init(metadata); array_hash = Z_ARRVAL_P(array); - char *key = NULL; + char *key; int key_type; PHP_GRPC_HASH_FOREACH_STR_KEY_VAL_START(array_hash, key, key_type, inner_array) - if (key_type != HASH_KEY_IS_STRING) { + if (key_type != HASH_KEY_IS_STRING || key == NULL) { return false; } if (Z_TYPE_P(inner_array) != IS_ARRAY) { @@ -291,7 +291,8 @@ PHP_METHOD(Call, startBatch) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) { zend_throw_exception(spl_ce_InvalidArgumentException, - "start_batch expects an array", 1 TSRMLS_CC); goto cleanup; + "start_batch expects an array", 1 TSRMLS_CC); + goto cleanup; } array_hash = Z_ARRVAL_P(array); @@ -300,7 +301,7 @@ PHP_METHOD(Call, startBatch) { int key_type; PHP_GRPC_HASH_FOREACH_LONG_KEY_VAL_START(array_hash, key, key_type, index, value) - if (key_type != HASH_KEY_IS_LONG) { + if (key_type != HASH_KEY_IS_LONG || key != NULL) { zend_throw_exception(spl_ce_InvalidArgumentException, "batch keys must be integers", 1 TSRMLS_CC); goto cleanup; From a24a0dd784570d88282a61c6fdd1a4870b8554d8 Mon Sep 17 00:00:00 2001 From: thinkerou Date: Thu, 28 Jul 2016 09:51:08 +0800 Subject: [PATCH 27/32] add PHP_GRPC_FREE_CLASS_OBJECT macro --- src/php/ext/grpc/call.c | 11 +---------- src/php/ext/grpc/call_credentials.c | 12 ++---------- src/php/ext/grpc/channel.c | 11 +---------- src/php/ext/grpc/channel_credentials.c | 12 ++---------- src/php/ext/grpc/php7_wrapper.h | 11 +++++++++++ src/php/ext/grpc/server.c | 11 +---------- src/php/ext/grpc/server_credentials.c | 12 ++---------- src/php/ext/grpc/timeval.c | 5 +++-- 8 files changed, 23 insertions(+), 62 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 10fc3feb63d..840ac71364f 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -76,16 +76,7 @@ php_grpc_zend_object create_wrapped_grpc_call(zend_class_entry *class_type PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_call); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_call, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &call_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_call, call_ce_handlers); } /* Creates and returns a PHP array object with the data in a diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c index b7d33d72394..34a88af47f0 100644 --- a/src/php/ext/grpc/call_credentials.c +++ b/src/php/ext/grpc/call_credentials.c @@ -70,16 +70,8 @@ php_grpc_zend_object create_wrapped_grpc_call_credentials( PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_call_credentials); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_call_credentials, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &call_credentials_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_call_credentials, + call_credentials_ce_handlers); } zval *grpc_php_wrap_call_credentials(grpc_call_credentials diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index 325e8f495ec..1d3f68af7c2 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -74,16 +74,7 @@ php_grpc_zend_object create_wrapped_grpc_channel(zend_class_entry *class_type PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_channel); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_channel, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &channel_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_channel, channel_ce_handlers); } void php_grpc_read_args_array(zval *args_array, diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c index 32f24e5751f..7ef95cc5e2b 100644 --- a/src/php/ext/grpc/channel_credentials.c +++ b/src/php/ext/grpc/channel_credentials.c @@ -80,16 +80,8 @@ php_grpc_zend_object create_wrapped_grpc_channel_credentials( PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_channel_credentials); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_channel_credentials, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &channel_credentials_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_channel_credentials, + channel_credentials_ce_handlers); } zval *grpc_php_wrap_channel_credentials(grpc_channel_credentials diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h index ba7f163676d..44d6cd8dd73 100644 --- a/src/php/ext/grpc/php7_wrapper.h +++ b/src/php/ext/grpc/php7_wrapper.h @@ -72,6 +72,13 @@ intern = (class_object *)emalloc(sizeof(class_object)); \ memset(intern, 0, sizeof(class_object)); +#define PHP_GRPC_FREE_CLASS_OBJECT(class_object, handler) \ + retval.handle = zend_objects_store_put( \ + intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, \ + free_##class_object, NULL TSRMLS_CC); \ + retval.handlers = zend_get_std_object_handlers(); \ + return retval; + #define PHP_GRPC_HASH_FOREACH_VAL_START(ht, data) \ zval **tmp_data = NULL; \ for (zend_hash_internal_pointer_reset(ht); \ @@ -158,6 +165,10 @@ static inline int php_grpc_zend_hash_find(HashTable *ht, char *key, int len, voi intern = ecalloc(1, sizeof(class_object) + \ zend_object_properties_size(class_type)); +#define PHP_GRPC_FREE_CLASS_OBJECT(class_object, handler) \ + intern->std.handlers = &handler; \ + return &intern->std; + #define PHP_GRPC_HASH_FOREACH_VAL_START(ht, data) \ ZEND_HASH_FOREACH_VAL(ht, data) { diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index 2fc785eb31f..452ccca3e10 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -79,16 +79,7 @@ php_grpc_zend_object create_wrapped_grpc_server(zend_class_entry *class_type PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_server); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_server, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &server_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_server, server_ce_handlers); } /** diff --git a/src/php/ext/grpc/server_credentials.c b/src/php/ext/grpc/server_credentials.c index 4c147e09912..61041b4cb37 100644 --- a/src/php/ext/grpc/server_credentials.c +++ b/src/php/ext/grpc/server_credentials.c @@ -68,16 +68,8 @@ php_grpc_zend_object create_wrapped_grpc_server_credentials( PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_server_credentials); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_server_credentials, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &server_credentials_ce_handlers; - return &intern->std; -#endif + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_server_credentials, + server_credentials_ce_handlers); } zval *grpc_php_wrap_server_credentials(grpc_server_credentials diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index d0f75bef82c..0d739f16083 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -66,7 +66,8 @@ php_grpc_zend_object create_wrapped_grpc_timeval(zend_class_entry *class_type PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_timeval); zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); -#if PHP_MAJOR_VERSION < 7 + PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_timeval, timeval_ce_handlers); +/*#if PHP_MAJOR_VERSION < 7 retval.handle = zend_objects_store_put( intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, free_wrapped_grpc_timeval, NULL TSRMLS_CC); @@ -75,7 +76,7 @@ php_grpc_zend_object create_wrapped_grpc_timeval(zend_class_entry *class_type #else intern->std.handlers = &timeval_ce_handlers; return &intern->std; -#endif +#endif*/ } zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC) { From 3e03e1651ec8c8b4ab23b986f0ad17ded48f9a32 Mon Sep 17 00:00:00 2001 From: thinkerou Date: Thu, 28 Jul 2016 10:18:27 +0800 Subject: [PATCH 28/32] delete commented-code for missing --- src/php/ext/grpc/timeval.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index 0d739f16083..28d360f09fb 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -67,16 +67,6 @@ php_grpc_zend_object create_wrapped_grpc_timeval(zend_class_entry *class_type zend_object_std_init(&intern->std, class_type TSRMLS_CC); object_properties_init(&intern->std, class_type); PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_timeval, timeval_ce_handlers); -/*#if PHP_MAJOR_VERSION < 7 - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - free_wrapped_grpc_timeval, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -#else - intern->std.handlers = &timeval_ce_handlers; - return &intern->std; -#endif*/ } zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC) { From 6972af492da588a39e64cc13a04ad9a7f0a05097 Mon Sep 17 00:00:00 2001 From: thinkerou Date: Thu, 28 Jul 2016 22:46:07 +0800 Subject: [PATCH 29/32] add macro PHP_GRPC_INIT_HANDLER --- src/php/ext/grpc/call.c | 20 ++++++-------------- src/php/ext/grpc/call_credentials.c | 11 ++--------- src/php/ext/grpc/call_credentials.h | 6 ++---- src/php/ext/grpc/channel.c | 8 +------- src/php/ext/grpc/channel_credentials.c | 11 ++--------- src/php/ext/grpc/channel_credentials.h | 5 ++--- src/php/ext/grpc/php7_wrapper.h | 11 ++++++++++- src/php/ext/grpc/server.c | 9 ++------- src/php/ext/grpc/server.h | 3 +-- src/php/ext/grpc/server_credentials.c | 13 +++---------- src/php/ext/grpc/server_credentials.h | 4 ++-- src/php/ext/grpc/timeval.c | 8 +------- 12 files changed, 34 insertions(+), 75 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 840ac71364f..429dbf52d0b 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 34a88af47f0..6921a5df17b 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 8014b75c703..c1d85c0fb28 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 1d3f68af7c2..e96ead582f4 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 7ef95cc5e2b..0b356aa25fc 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 39dc85283d5..b043d91fa69 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 44d6cd8dd73..f2976c26cd9 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 452ccca3e10..fc20c42b169 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 02ef1f79757..a635bc11df9 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 61041b4cb37..b05896af4af 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 9551ec6c24f..6781a614b17 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 28d360f09fb..e145d967726 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) {} From 526a9f908627d686827f8abb34e16f211a679261 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 28 Jul 2016 10:32:43 -0700 Subject: [PATCH 30/32] php: cleanup for GA --- package.xml | 19 +++- src/php/ext/grpc/call.c | 3 +- src/php/ext/grpc/package.xml | 156 -------------------------------- src/php/ext/grpc/php7_wrapper.h | 3 +- templates/package.xml.template | 19 +++- 5 files changed, 38 insertions(+), 162 deletions(-) delete mode 100644 src/php/ext/grpc/package.xml diff --git a/package.xml b/package.xml index 13928290630..65764e88889 100644 --- a/package.xml +++ b/package.xml @@ -10,7 +10,7 @@ grpc-packages@google.com yes - 2016-07-21 + 2016-07-28 1.0.0 @@ -22,7 +22,7 @@ BSD -- PHP7 Support #7464 +- PHP7 Support continued, reduce code duplication #7543 @@ -1116,5 +1116,20 @@ Update to wrap gRPC C Core version 0.10.0 - PHP7 Support #7464 + + + 1.0.0RC3 + 1.0.0RC3 + + + stable + stable + + 2016-07-28 + BSD + +- PHP7 Support continued, reduce code duplication #7543 + + diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 429dbf52d0b..66ca1513ed7 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -470,7 +470,8 @@ PHP_METHOD(Call, startBatch) { #endif PHP_GRPC_DELREF(array); add_property_long(recv_status, "code", status); - php_grpc_add_property_string(recv_status, "details", status_details, true); + php_grpc_add_property_string(recv_status, "details", status_details, + true); add_property_zval(result, "status", recv_status); PHP_GRPC_DELREF(recv_status); break; diff --git a/src/php/ext/grpc/package.xml b/src/php/ext/grpc/package.xml deleted file mode 100644 index daf2ee5a53d..00000000000 --- a/src/php/ext/grpc/package.xml +++ /dev/null @@ -1,156 +0,0 @@ - - - grpc - pecl.php.net - A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. - Remote Procedure Calls (RPCs) provide a useful abstraction for building distributed applications and services. The libraries in this repository provide a concrete implementation of the gRPC protocol, layered over HTTP/2. These libraries enable communication between clients and servers using any combination of the supported languages. - - Stanley Cheung - stanleycheung - grpc-packages@google.com - yes - - 2016-01-13 - - - 0.7.0 - 0.7.0 - - - beta - beta - - BSD - -- Breaking change to Credentials class (removed) #3765 -- Replaced by ChannelCredentials and CallCredentials class #3765 -- New plugin based metadata auth API #4394 -- Explicit ChannelCredentials::createInsecure() call - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5.5.0 - - - 1.4.0 - - - - grpc - - - - - 0.5.0 - 0.5.0 - - - alpha - alpha - - 2015-06-16 - BSD - -First alpha release - - - - - 0.5.1 - 0.5.1 - - - alpha - alpha - - 2015-07-09 - BSD - -Update to wrap gRPC C Core version 0.10.0 - - - - - 0.6.0 - 0.6.0 - - - beta - beta - - 2015-09-24 - BSD - -- support per message compression disable -- expose per-call host override option -- expose connectivity API -- expose channel target and call peer -- add user-agent -- update to wrap gRPC C core library beta version 0.11.0 - - - - - 0.6.1 - 0.6.0 - - - beta - beta - - 2015-10-21 - BSD - -- fixed undefined constant fatal error when run with apache/nginx #2275 - - - - - 0.7.0 - 0.7.0 - - - beta - beta - - 2016-01-13 - BSD - -- Breaking change to Credentials class (removed) #3765 -- Replaced by ChannelCredentials and CallCredentials class #3765 -- New plugin based metadata auth API #4394 -- Explicit ChannelCredentials::createInsecure() call - - - - diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h index f2976c26cd9..fd8d35636f0 100644 --- a/src/php/ext/grpc/php7_wrapper.h +++ b/src/php/ext/grpc/php7_wrapper.h @@ -110,7 +110,8 @@ #define PHP_GRPC_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 **data = NULL; if (zend_hash_find(ht, key, len, (void **)&data) == SUCCESS) { *value = *data; diff --git a/templates/package.xml.template b/templates/package.xml.template index 76c6fff7a7c..87b10389598 100644 --- a/templates/package.xml.template +++ b/templates/package.xml.template @@ -12,7 +12,7 @@ grpc-packages@google.com yes - 2016-07-21 + 2016-07-28 ${settings.php_version.php()} @@ -24,7 +24,7 @@ BSD - - PHP7 Support #7464 + - PHP7 Support continued, reduce code duplication #7543 @@ -234,5 +234,20 @@ - PHP7 Support #7464 + + + 1.0.0RC3 + 1.0.0RC3 + + + stable + stable + + 2016-07-28 + BSD + + - PHP7 Support continued, reduce code duplication #7543 + + From 161767771bff220f05d4a82b8e2c11df49a70808 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Thu, 28 Jul 2016 10:32:49 -0700 Subject: [PATCH 31/32] update to use new nuget client in tests --- src/csharp/.nuget/packages.config | 6 -- src/csharp/Grpc.Core.Tests/packages.config | 5 +- src/csharp/Grpc.Core.Tests/project.json | 5 +- .../Grpc.Examples.MathClient/packages.config | 3 + .../Grpc.Examples.MathServer/packages.config | 3 + .../packages.config | 3 + .../packages.config | 3 + .../Grpc.Core.Tests/project.json.template | 5 +- tools/run_tests/pre_build_csharp.bat | 55 ++++++++++++++++++- tools/run_tests/pre_build_csharp.sh | 51 ++++++++++++++++- 10 files changed, 128 insertions(+), 11 deletions(-) delete mode 100644 src/csharp/.nuget/packages.config create mode 100644 src/csharp/Grpc.Examples.MathClient/packages.config create mode 100644 src/csharp/Grpc.Examples.MathServer/packages.config create mode 100644 src/csharp/Grpc.IntegrationTesting.QpsWorker/packages.config create mode 100644 src/csharp/Grpc.IntegrationTesting.StressClient/packages.config diff --git a/src/csharp/.nuget/packages.config b/src/csharp/.nuget/packages.config deleted file mode 100644 index 6154b3561f4..00000000000 --- a/src/csharp/.nuget/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/csharp/Grpc.Core.Tests/packages.config b/src/csharp/Grpc.Core.Tests/packages.config index aa7d951fdc7..6a930c17ee6 100644 --- a/src/csharp/Grpc.Core.Tests/packages.config +++ b/src/csharp/Grpc.Core.Tests/packages.config @@ -4,4 +4,7 @@ - \ No newline at end of file + + + + diff --git a/src/csharp/Grpc.Core.Tests/project.json b/src/csharp/Grpc.Core.Tests/project.json index d4c9a2ef316..4a682d927e4 100644 --- a/src/csharp/Grpc.Core.Tests/project.json +++ b/src/csharp/Grpc.Core.Tests/project.json @@ -54,7 +54,10 @@ }, "Newtonsoft.Json": "8.0.3", "NUnit": "3.2.0", - "NUnitLite": "3.2.0-*" + "NUnitLite": "3.2.0-*", + "NUnit.ConsoleRunner": "3.2.0", + "OpenCover": "4.6.519", + "ReportGenerator": "2.4.4.0" }, "frameworks": { "net45": { }, diff --git a/src/csharp/Grpc.Examples.MathClient/packages.config b/src/csharp/Grpc.Examples.MathClient/packages.config new file mode 100644 index 00000000000..79ece06bef6 --- /dev/null +++ b/src/csharp/Grpc.Examples.MathClient/packages.config @@ -0,0 +1,3 @@ + + + diff --git a/src/csharp/Grpc.Examples.MathServer/packages.config b/src/csharp/Grpc.Examples.MathServer/packages.config new file mode 100644 index 00000000000..79ece06bef6 --- /dev/null +++ b/src/csharp/Grpc.Examples.MathServer/packages.config @@ -0,0 +1,3 @@ + + + diff --git a/src/csharp/Grpc.IntegrationTesting.QpsWorker/packages.config b/src/csharp/Grpc.IntegrationTesting.QpsWorker/packages.config new file mode 100644 index 00000000000..79ece06bef6 --- /dev/null +++ b/src/csharp/Grpc.IntegrationTesting.QpsWorker/packages.config @@ -0,0 +1,3 @@ + + + diff --git a/src/csharp/Grpc.IntegrationTesting.StressClient/packages.config b/src/csharp/Grpc.IntegrationTesting.StressClient/packages.config new file mode 100644 index 00000000000..79ece06bef6 --- /dev/null +++ b/src/csharp/Grpc.IntegrationTesting.StressClient/packages.config @@ -0,0 +1,3 @@ + + + diff --git a/templates/src/csharp/Grpc.Core.Tests/project.json.template b/templates/src/csharp/Grpc.Core.Tests/project.json.template index bc9fa3e63a9..d1ab9316f61 100644 --- a/templates/src/csharp/Grpc.Core.Tests/project.json.template +++ b/templates/src/csharp/Grpc.Core.Tests/project.json.template @@ -8,7 +8,10 @@ }, "Newtonsoft.Json": "8.0.3", "NUnit": "3.2.0", - "NUnitLite": "3.2.0-*" + "NUnitLite": "3.2.0-*", + "NUnit.ConsoleRunner": "3.2.0", + "OpenCover": "4.6.519", + "ReportGenerator": "2.4.4.0" }, "frameworks": { "net45": { }, diff --git a/tools/run_tests/pre_build_csharp.bat b/tools/run_tests/pre_build_csharp.bat index e7131d504c8..580d5638fda 100644 --- a/tools/run_tests/pre_build_csharp.bat +++ b/tools/run_tests/pre_build_csharp.bat @@ -38,8 +38,61 @@ cd /d %~dp0\..\.. set NUGET=C:\nuget\nuget.exe if exist %NUGET% ( + @rem Restore Grpc packages by packages since Nuget client 3.4.4 doesnt support restore + @rem by solution + @rem Moving into each directory to let the restores work with both nuget 3.4 and 2.8 %NUGET% restore vsprojects/grpc_csharp_ext.sln || goto :error - %NUGET% restore src/csharp/Grpc.sln || goto :error + + cd src/csharp + + cd Grpc.Auth || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.Core || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.Core.Tests || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.Examples.MathClient || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.Examples.MathServer || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.Examples || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.HealthCheck.Tests || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.HealthCheck || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.IntegrationTesting.Client || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.IntegrationTesting.QpsWorker || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.IntegrationTesting.StressClient || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + cd .. + + cd Grpc.IntegrationTesting || goto :error + %NUGET% restore -PackagesDirectory ../packages || goto :error + + cd /d %~dp0\..\.. || goto :error ) endlocal diff --git a/tools/run_tests/pre_build_csharp.sh b/tools/run_tests/pre_build_csharp.sh index 3ff1a4e5a8b..0fd3b92a951 100755 --- a/tools/run_tests/pre_build_csharp.sh +++ b/tools/run_tests/pre_build_csharp.sh @@ -37,5 +37,54 @@ root=`pwd` if [ -x "$(command -v nuget)" ] then - nuget restore Grpc.sln + # Restoring Nuget packages by packages rather than by solution because of + # inability to restore by solution with Nuget client 3.4.4 + # Moving into each directory to let the restores work with nuget 3.4 and 2.8 + cd Grpc.Auth + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.Core.Tests + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.Core + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.Examples.MathClient + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.Examples.MathServer + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.Examples + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.HealthCheck.Tests + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.HealthCheck + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.IntegrationTesting.Client + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.IntegrationTesting.QpsWorker + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.IntegrationTesting.StressClient + nuget restore -PackagesDirectory ../packages + cd .. + + cd Grpc.IntegrationTesting + nuget restore -PackagesDirectory ../packages + cd .. fi From 5a363258961e01fc53c28955141d16fcdf8bcd38 Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Thu, 28 Jul 2016 18:28:17 -0700 Subject: [PATCH 32/32] Merge pull request #7502 from dgquintas/cpp_compression_level C++ Compression Level set properly --- include/grpc++/impl/codegen/async_stream.h | 27 +++++++++++++++++++ .../grpc++/impl/codegen/async_unary_call.h | 9 +++++++ include/grpc++/impl/codegen/call.h | 12 ++++++--- .../grpc++/impl/codegen/method_handler_impl.h | 15 +++++++++++ include/grpc++/impl/codegen/server_context.h | 9 ++++++- include/grpc++/impl/codegen/sync_stream.h | 15 +++++++++++ src/cpp/server/server_context.cc | 15 +++-------- 7 files changed, 87 insertions(+), 15 deletions(-) diff --git a/include/grpc++/impl/codegen/async_stream.h b/include/grpc++/impl/codegen/async_stream.h index e96d224ddbe..70533aa4d9f 100644 --- a/include/grpc++/impl/codegen/async_stream.h +++ b/include/grpc++/impl/codegen/async_stream.h @@ -330,6 +330,9 @@ class ServerAsyncReader GRPC_FINAL : public ServerAsyncReaderInterface { meta_ops_.set_output_tag(tag); meta_ops_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + meta_ops_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; call_.PerformOps(&meta_ops_); } @@ -345,6 +348,9 @@ class ServerAsyncReader GRPC_FINAL : public ServerAsyncReaderInterface { if (!ctx_->sent_initial_metadata_) { finish_ops_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + finish_ops_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; } // The response is dropped if the status is not OK. @@ -363,6 +369,9 @@ class ServerAsyncReader GRPC_FINAL : public ServerAsyncReaderInterface { if (!ctx_->sent_initial_metadata_) { finish_ops_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + finish_ops_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; } finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status); @@ -400,6 +409,9 @@ class ServerAsyncWriter GRPC_FINAL : public ServerAsyncWriterInterface { meta_ops_.set_output_tag(tag); meta_ops_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + meta_ops_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; call_.PerformOps(&meta_ops_); } @@ -409,6 +421,9 @@ class ServerAsyncWriter GRPC_FINAL : public ServerAsyncWriterInterface { if (!ctx_->sent_initial_metadata_) { write_ops_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + write_ops_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; } // TODO(ctiller): don't assert @@ -421,6 +436,9 @@ class ServerAsyncWriter GRPC_FINAL : public ServerAsyncWriterInterface { if (!ctx_->sent_initial_metadata_) { finish_ops_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + finish_ops_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; } finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status); @@ -459,6 +477,9 @@ class ServerAsyncReaderWriter GRPC_FINAL meta_ops_.set_output_tag(tag); meta_ops_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + meta_ops_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; call_.PerformOps(&meta_ops_); } @@ -474,6 +495,9 @@ class ServerAsyncReaderWriter GRPC_FINAL if (!ctx_->sent_initial_metadata_) { write_ops_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + write_ops_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; } // TODO(ctiller): don't assert @@ -486,6 +510,9 @@ class ServerAsyncReaderWriter GRPC_FINAL if (!ctx_->sent_initial_metadata_) { finish_ops_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + finish_ops_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; } finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status); diff --git a/include/grpc++/impl/codegen/async_unary_call.h b/include/grpc++/impl/codegen/async_unary_call.h index 47ac5bee925..544dace32b9 100644 --- a/include/grpc++/impl/codegen/async_unary_call.h +++ b/include/grpc++/impl/codegen/async_unary_call.h @@ -126,6 +126,9 @@ class ServerAsyncResponseWriter GRPC_FINAL meta_buf_.set_output_tag(tag); meta_buf_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + meta_buf_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; call_.PerformOps(&meta_buf_); } @@ -135,6 +138,9 @@ class ServerAsyncResponseWriter GRPC_FINAL if (!ctx_->sent_initial_metadata_) { finish_buf_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + finish_buf_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; } // The response is dropped if the status is not OK. @@ -153,6 +159,9 @@ class ServerAsyncResponseWriter GRPC_FINAL if (!ctx_->sent_initial_metadata_) { finish_buf_.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + finish_buf_.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; } finish_buf_.ServerSendStatus(ctx_->trailing_metadata_, status); diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index fab85d15176..dfac177970a 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -180,17 +180,23 @@ class CallNoOp { class CallOpSendInitialMetadata { public: - CallOpSendInitialMetadata() : send_(false) {} + CallOpSendInitialMetadata() : send_(false) { + maybe_compression_level_.is_set = false; + } void SendInitialMetadata( const std::multimap& metadata, uint32_t flags) { + maybe_compression_level_.is_set = false; send_ = true; flags_ = flags; initial_metadata_count_ = metadata.size(); initial_metadata_ = FillMetadataArray(metadata); - // TODO(dgq): expose compression level in API so it can be properly set. - maybe_compression_level_.is_set = false; + } + + void set_compression_level(grpc_compression_level level) { + maybe_compression_level_.is_set = true; + maybe_compression_level_.level = level; } protected: diff --git a/include/grpc++/impl/codegen/method_handler_impl.h b/include/grpc++/impl/codegen/method_handler_impl.h index 21ac6c4fb55..2f4be644bae 100644 --- a/include/grpc++/impl/codegen/method_handler_impl.h +++ b/include/grpc++/impl/codegen/method_handler_impl.h @@ -65,6 +65,9 @@ class RpcMethodHandler : public MethodHandler { ops; ops.SendInitialMetadata(param.server_context->initial_metadata_, param.server_context->initial_metadata_flags()); + if (param.server_context->compression_level_set()) { + ops.set_compression_level(param.server_context->compression_level()); + } if (status.ok()) { status = ops.SendMessage(rsp); } @@ -104,6 +107,9 @@ class ClientStreamingHandler : public MethodHandler { ops; ops.SendInitialMetadata(param.server_context->initial_metadata_, param.server_context->initial_metadata_flags()); + if (param.server_context->compression_level_set()) { + ops.set_compression_level(param.server_context->compression_level()); + } if (status.ok()) { status = ops.SendMessage(rsp); } @@ -144,6 +150,9 @@ class ServerStreamingHandler : public MethodHandler { if (!param.server_context->sent_initial_metadata_) { ops.SendInitialMetadata(param.server_context->initial_metadata_, param.server_context->initial_metadata_flags()); + if (param.server_context->compression_level_set()) { + ops.set_compression_level(param.server_context->compression_level()); + } } ops.ServerSendStatus(param.server_context->trailing_metadata_, status); param.call->PerformOps(&ops); @@ -177,6 +186,9 @@ class BidiStreamingHandler : public MethodHandler { if (!param.server_context->sent_initial_metadata_) { ops.SendInitialMetadata(param.server_context->initial_metadata_, param.server_context->initial_metadata_flags()); + if (param.server_context->compression_level_set()) { + ops.set_compression_level(param.server_context->compression_level()); + } } ops.ServerSendStatus(param.server_context->trailing_metadata_, status); param.call->PerformOps(&ops); @@ -199,6 +211,9 @@ class UnknownMethodHandler : public MethodHandler { if (!context->sent_initial_metadata_) { ops->SendInitialMetadata(context->initial_metadata_, context->initial_metadata_flags()); + if (context->compression_level_set()) { + ops->set_compression_level(context->compression_level()); + } context->sent_initial_metadata_ = true; } ops->ServerSendStatus(context->trailing_metadata_, status); diff --git a/include/grpc++/impl/codegen/server_context.h b/include/grpc++/impl/codegen/server_context.h index cea13a513f6..08212af861b 100644 --- a/include/grpc++/impl/codegen/server_context.h +++ b/include/grpc++/impl/codegen/server_context.h @@ -130,7 +130,13 @@ class ServerContext { grpc_compression_level compression_level() const { return compression_level_; } - void set_compression_level(grpc_compression_level level); + + void set_compression_level(grpc_compression_level level) { + compression_level_set_ = true; + compression_level_ = level; + } + + bool compression_level_set() const { return compression_level_set_; } grpc_compression_algorithm compression_algorithm() const { return compression_algorithm_; @@ -217,6 +223,7 @@ class ServerContext { std::multimap initial_metadata_; std::multimap trailing_metadata_; + bool compression_level_set_; grpc_compression_level compression_level_; grpc_compression_algorithm compression_algorithm_; }; diff --git a/include/grpc++/impl/codegen/sync_stream.h b/include/grpc++/impl/codegen/sync_stream.h index cbfa4106995..b2b972760db 100644 --- a/include/grpc++/impl/codegen/sync_stream.h +++ b/include/grpc++/impl/codegen/sync_stream.h @@ -347,6 +347,9 @@ class ServerReader GRPC_FINAL : public ReaderInterface { CallOpSet ops; ops.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + ops.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; call_->PerformOps(&ops); call_->cq()->Pluck(&ops); @@ -375,6 +378,9 @@ class ServerWriter GRPC_FINAL : public WriterInterface { CallOpSet ops; ops.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + ops.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; call_->PerformOps(&ops); call_->cq()->Pluck(&ops); @@ -389,6 +395,9 @@ class ServerWriter GRPC_FINAL : public WriterInterface { if (!ctx_->sent_initial_metadata_) { ops.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + ops.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; } call_->PerformOps(&ops); @@ -413,6 +422,9 @@ class ServerReaderWriter GRPC_FINAL : public WriterInterface, CallOpSet ops; ops.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + ops.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; call_->PerformOps(&ops); call_->cq()->Pluck(&ops); @@ -434,6 +446,9 @@ class ServerReaderWriter GRPC_FINAL : public WriterInterface, if (!ctx_->sent_initial_metadata_) { ops.SendInitialMetadata(ctx_->initial_metadata_, ctx_->initial_metadata_flags()); + if (ctx_->compression_level_set()) { + ops.set_compression_level(ctx_->compression_level()); + } ctx_->sent_initial_metadata_ = true; } call_->PerformOps(&ops); diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index 43117fd1e95..1ca6a2b906e 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -129,7 +129,8 @@ ServerContext::ServerContext() deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)), call_(nullptr), cq_(nullptr), - sent_initial_metadata_(false) {} + sent_initial_metadata_(false), + compression_level_set_(false) {} ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, size_t metadata_count) @@ -139,7 +140,8 @@ ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, deadline_(deadline), call_(nullptr), cq_(nullptr), - sent_initial_metadata_(false) { + sent_initial_metadata_(false), + compression_level_set_(false) { for (size_t i = 0; i < metadata_count; i++) { client_metadata_.insert(std::pair( metadata[i].key, @@ -194,15 +196,6 @@ bool ServerContext::IsCancelled() const { } } -void ServerContext::set_compression_level(grpc_compression_level level) { - // TODO(dgq): get rid of grpc_call_compression_for_level and propagate the - // compression level by adding a new argument to - // CallOpSendInitialMetadata::SendInitialMetadata. - const grpc_compression_algorithm algorithm_for_level = - grpc_call_compression_for_level(call_, level); - set_compression_algorithm(algorithm_for_level); -} - void ServerContext::set_compression_algorithm( grpc_compression_algorithm algorithm) { char* algorithm_name = NULL;