aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/ext
diff options
context:
space:
mode:
authorGravatar Paul Yang <TeBoring@users.noreply.github.com>2018-01-05 13:05:07 -0800
committerGravatar GitHub <noreply@github.com>2018-01-05 13:05:07 -0800
commit3823897475df1a42229b15f970fbbdfa9d714804 (patch)
tree1efda4f74b5ba2aa86bfd9f6103d08908fb38e13 /php/ext
parent5aa8f98894523b92b1dadd54062546ede706c9a6 (diff)
Well known types are not initialized properly. (#4139)
Previously, within the same load period of protobuf module, well known types are not initialized correctly for the second request. The reason is that well known type are only initialized if a method local static variable is not set. However, that variable is not reset after request ends. Therefore, when the second request comes, the method local static variable is still set (by previous request) and well types are not initialized in this case.
Diffstat (limited to 'php/ext')
-rw-r--r--php/ext/google/protobuf/message.c50
-rw-r--r--php/ext/google/protobuf/protobuf.c37
-rw-r--r--php/ext/google/protobuf/protobuf.h11
3 files changed, 68 insertions, 30 deletions
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c
index 24472682..60f2225e 100644
--- a/php/ext/google/protobuf/message.c
+++ b/php/ext/google/protobuf/message.c
@@ -445,8 +445,7 @@ static void init_file_wrappers(TSRMLS_D);
// Define file init functions
static void init_file_any(TSRMLS_D) {
- static bool is_initialized = false;
- if (is_initialized) return;
+ if (is_inited_file_any) return;
init_generated_pool_once(TSRMLS_C);
const char* generated_file =
"0acd010a19676f6f676c652f70726f746f6275662f616e792e70726f746f"
@@ -461,12 +460,11 @@ static void init_file_any(TSRMLS_D) {
hex_to_binary(generated_file, &binary, &binary_len);
internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC);
FREE(binary);
- is_initialized = true;
+ is_inited_file_any = true;
}
static void init_file_api(TSRMLS_D) {
- static bool is_initialized = false;
- if (is_initialized) return;
+ if (is_inited_file_api) return;
init_file_source_context(TSRMLS_C);
init_file_type(TSRMLS_C);
init_generated_pool_once(TSRMLS_C);
@@ -502,12 +500,11 @@ static void init_file_api(TSRMLS_D) {
hex_to_binary(generated_file, &binary, &binary_len);
internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC);
FREE(binary);
- is_initialized = true;
+ is_inited_file_api = true;
}
static void init_file_duration(TSRMLS_D) {
- static bool is_initialized = false;
- if (is_initialized) return;
+ if (is_inited_file_duration) return;
init_generated_pool_once(TSRMLS_C);
const char* generated_file =
"0ae3010a1e676f6f676c652f70726f746f6275662f6475726174696f6e2e"
@@ -523,12 +520,11 @@ static void init_file_duration(TSRMLS_D) {
hex_to_binary(generated_file, &binary, &binary_len);
internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC);
FREE(binary);
- is_initialized = true;
+ is_inited_file_duration = true;
}
static void init_file_field_mask(TSRMLS_D) {
- static bool is_initialized = false;
- if (is_initialized) return;
+ if (is_inited_file_field_mask) return;
init_generated_pool_once(TSRMLS_C);
const char* generated_file =
"0ae3010a20676f6f676c652f70726f746f6275662f6669656c645f6d6173"
@@ -544,12 +540,11 @@ static void init_file_field_mask(TSRMLS_D) {
hex_to_binary(generated_file, &binary, &binary_len);
internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC);
FREE(binary);
- is_initialized = true;
+ is_inited_file_field_mask = true;
}
static void init_file_empty(TSRMLS_D) {
- static bool is_initialized = false;
- if (is_initialized) return;
+ if (is_inited_file_empty) return;
init_generated_pool_once(TSRMLS_C);
const char* generated_file =
"0ab7010a1b676f6f676c652f70726f746f6275662f656d7074792e70726f"
@@ -564,12 +559,11 @@ static void init_file_empty(TSRMLS_D) {
hex_to_binary(generated_file, &binary, &binary_len);
internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC);
FREE(binary);
- is_initialized = true;
+ is_inited_file_empty = true;
}
static void init_file_source_context(TSRMLS_D) {
- static bool is_initialized = false;
- if (is_initialized) return;
+ if (is_inited_file_source_context) return;
init_generated_pool_once(TSRMLS_C);
const char* generated_file =
"0afb010a24676f6f676c652f70726f746f6275662f736f757263655f636f"
@@ -586,12 +580,11 @@ static void init_file_source_context(TSRMLS_D) {
hex_to_binary(generated_file, &binary, &binary_len);
internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC);
FREE(binary);
- is_initialized = true;
+ is_inited_file_source_context = true;
}
static void init_file_struct(TSRMLS_D) {
- static bool is_initialized = false;
- if (is_initialized) return;
+ if (is_inited_file_struct) return;
init_generated_pool_once(TSRMLS_C);
const char* generated_file =
"0a81050a1c676f6f676c652f70726f746f6275662f7374727563742e7072"
@@ -621,12 +614,11 @@ static void init_file_struct(TSRMLS_D) {
hex_to_binary(generated_file, &binary, &binary_len);
internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC);
FREE(binary);
- is_initialized = true;
+ is_inited_file_struct = true;
}
static void init_file_timestamp(TSRMLS_D) {
- static bool is_initialized = false;
- if (is_initialized) return;
+ if (is_inited_file_timestamp) return;
init_generated_pool_once(TSRMLS_C);
const char* generated_file =
"0ae7010a1f676f6f676c652f70726f746f6275662f74696d657374616d70"
@@ -642,12 +634,11 @@ static void init_file_timestamp(TSRMLS_D) {
hex_to_binary(generated_file, &binary, &binary_len);
internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC);
FREE(binary);
- is_initialized = true;
+ is_inited_file_timestamp = true;
}
static void init_file_type(TSRMLS_D) {
- static bool is_initialized = false;
- if (is_initialized) return;
+ if (is_inited_file_type) return;
init_file_any(TSRMLS_C);
init_file_source_context(TSRMLS_C);
init_generated_pool_once(TSRMLS_C);
@@ -711,12 +702,11 @@ static void init_file_type(TSRMLS_D) {
hex_to_binary(generated_file, &binary, &binary_len);
internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC);
FREE(binary);
- is_initialized = true;
+ is_inited_file_type = true;
}
static void init_file_wrappers(TSRMLS_D) {
- static bool is_initialized = false;
- if (is_initialized) return;
+ if (is_inited_file_wrappers) return;
init_generated_pool_once(TSRMLS_C);
const char* generated_file =
"0abf030a1e676f6f676c652f70726f746f6275662f77726170706572732e"
@@ -739,7 +729,7 @@ static void init_file_wrappers(TSRMLS_D) {
hex_to_binary(generated_file, &binary, &binary_len);
internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC);
FREE(binary);
- is_initialized = true;
+ is_inited_file_wrappers = true;
}
// -----------------------------------------------------------------------------
diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c
index daebb460..da00302f 100644
--- a/php/ext/google/protobuf/protobuf.c
+++ b/php/ext/google/protobuf/protobuf.c
@@ -145,6 +145,21 @@ PHP_PROTO_HASHTABLE_VALUE get_proto_obj(const char* proto) {
}
// -----------------------------------------------------------------------------
+// Well Known Types.
+// -----------------------------------------------------------------------------
+
+bool is_inited_file_any;
+bool is_inited_file_api;
+bool is_inited_file_duration;
+bool is_inited_file_field_mask;
+bool is_inited_file_empty;
+bool is_inited_file_source_context;
+bool is_inited_file_struct;
+bool is_inited_file_timestamp;
+bool is_inited_file_type;
+bool is_inited_file_wrappers;
+
+// -----------------------------------------------------------------------------
// Reserved Name.
// -----------------------------------------------------------------------------
@@ -250,6 +265,17 @@ static PHP_RINIT_FUNCTION(protobuf) {
generated_pool_php = NULL;
internal_generated_pool_php = NULL;
+ is_inited_file_any = false;
+ is_inited_file_api = false;
+ is_inited_file_duration = false;
+ is_inited_file_field_mask = false;
+ is_inited_file_empty = false;
+ is_inited_file_source_context = false;
+ is_inited_file_struct = false;
+ is_inited_file_timestamp = false;
+ is_inited_file_type = false;
+ is_inited_file_wrappers = false;
+
return 0;
}
@@ -288,6 +314,17 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) {
}
#endif
+ is_inited_file_any = true;
+ is_inited_file_api = true;
+ is_inited_file_duration = true;
+ is_inited_file_field_mask = true;
+ is_inited_file_empty = true;
+ is_inited_file_source_context = true;
+ is_inited_file_struct = true;
+ is_inited_file_timestamp = true;
+ is_inited_file_type = true;
+ is_inited_file_wrappers = true;
+
return 0;
}
diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h
index 6ab0f134..be1de5cf 100644
--- a/php/ext/google/protobuf/protobuf.h
+++ b/php/ext/google/protobuf/protobuf.h
@@ -1172,6 +1172,17 @@ extern zend_class_entry* oneof_descriptor_type;
// Well Known Type.
// -----------------------------------------------------------------------------
+extern bool is_inited_file_any;
+extern bool is_inited_file_api;
+extern bool is_inited_file_duration;
+extern bool is_inited_file_field_mask;
+extern bool is_inited_file_empty;
+extern bool is_inited_file_source_context;
+extern bool is_inited_file_struct;
+extern bool is_inited_file_timestamp;
+extern bool is_inited_file_type;
+extern bool is_inited_file_wrappers;
+
PHP_METHOD(GPBMetadata_Any, initOnce);
PHP_METHOD(GPBMetadata_Api, initOnce);
PHP_METHOD(GPBMetadata_Duration, initOnce);