aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/ext
diff options
context:
space:
mode:
authorGravatar Paul Yang <TeBoring@users.noreply.github.com>2017-11-04 09:33:56 -0700
committerGravatar GitHub <noreply@github.com>2017-11-04 09:33:56 -0700
commit2df472690ec878ff75a2ccea0c7ff6df0ff69ee3 (patch)
tree560036eac52891238eb3b805c90f6099bc7801ea /php/ext
parentcbe250591fca9d2e776776be065a72c5550a5556 (diff)
Fix php well known type conformance tests (#3828) (#3840)
* Fix php well known type conformance tests * Properly generate code for test.proto * Provide GPBMetadata files in c extensions for generated files to import. * Remove unnecessary test * Clean up code * Add declaration for initOnce. * Refactoring
Diffstat (limited to 'php/ext')
-rw-r--r--php/ext/google/protobuf/message.c42
-rw-r--r--php/ext/google/protobuf/protobuf.c11
-rw-r--r--php/ext/google/protobuf/protobuf.h24
3 files changed, 75 insertions, 2 deletions
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c
index 291f5c24..3fce2c17 100644
--- a/php/ext/google/protobuf/message.c
+++ b/php/ext/google/protobuf/message.c
@@ -2029,3 +2029,45 @@ PHP_PROTO_ONEOF_FIELD_ACCESSORS(Value, value, BoolValue, "bool_value")
PHP_PROTO_ONEOF_FIELD_ACCESSORS(Value, value, StructValue, "struct_value")
PHP_PROTO_ONEOF_FIELD_ACCESSORS(Value, value, ListValue, "list_value")
PHP_PROTO_ONEOF_ACCESSORS(Value, value, Kind, "kind")
+
+// -----------------------------------------------------------------------------
+// GPBMetadata files for well known types
+// -----------------------------------------------------------------------------
+
+#define DEFINE_GPBMETADATA_FILE(LOWERNAME, CAMELNAME, CLASSNAME) \
+ zend_class_entry* gpb_metadata_##LOWERNAME##_type; \
+ static zend_function_entry gpb_metadata_##LOWERNAME##_methods[] = { \
+ PHP_ME(GPBMetadata_##CAMELNAME, initOnce, NULL, \
+ ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) \
+ ZEND_FE_END \
+ }; \
+ void gpb_metadata_##LOWERNAME##_init(TSRMLS_D) { \
+ zend_class_entry class_type; \
+ INIT_CLASS_ENTRY(class_type, CLASSNAME, \
+ gpb_metadata_##LOWERNAME##_methods); \
+ gpb_metadata_##LOWERNAME##_type = \
+ zend_register_internal_class(&class_type TSRMLS_CC); \
+ } \
+ PHP_METHOD(GPBMetadata_##CAMELNAME, initOnce) { \
+ init_file_##LOWERNAME(TSRMLS_C); \
+ }
+
+DEFINE_GPBMETADATA_FILE(any, Any, "GPBMetadata\\Google\\Protobuf\\Any");
+DEFINE_GPBMETADATA_FILE(api, Api, "GPBMetadata\\Google\\Protobuf\\Api");
+DEFINE_GPBMETADATA_FILE(duration, Duration,
+ "GPBMetadata\\Google\\Protobuf\\Duration");
+DEFINE_GPBMETADATA_FILE(field_mask, FieldMask,
+ "GPBMetadata\\Google\\Protobuf\\FieldMask");
+DEFINE_GPBMETADATA_FILE(empty, Empty,
+ "GPBMetadata\\Google\\Protobuf\\GPBEmpty");
+DEFINE_GPBMETADATA_FILE(source_context, SourceContext,
+ "GPBMetadata\\Google\\Protobuf\\SourceContext");
+DEFINE_GPBMETADATA_FILE(struct, Struct,
+ "GPBMetadata\\Google\\Protobuf\\Struct");
+DEFINE_GPBMETADATA_FILE(timestamp, Timestamp,
+ "GPBMetadata\\Google\\Protobuf\\Timestamp");
+DEFINE_GPBMETADATA_FILE(type, Type, "GPBMetadata\\Google\\Protobuf\\Type");
+DEFINE_GPBMETADATA_FILE(wrappers, Wrappers,
+ "GPBMetadata\\Google\\Protobuf\\Wrappers");
+
+#undef DEFINE_GPBMETADATA_FILE
diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c
index b67089e0..265d636e 100644
--- a/php/ext/google/protobuf/protobuf.c
+++ b/php/ext/google/protobuf/protobuf.c
@@ -300,6 +300,17 @@ static PHP_MINIT_FUNCTION(protobuf) {
repeated_field_iter_init(TSRMLS_C);
util_init(TSRMLS_C);
+ gpb_metadata_any_init(TSRMLS_C);
+ gpb_metadata_api_init(TSRMLS_C);
+ gpb_metadata_duration_init(TSRMLS_C);
+ gpb_metadata_field_mask_init(TSRMLS_C);
+ gpb_metadata_empty_init(TSRMLS_C);
+ gpb_metadata_source_context_init(TSRMLS_C);
+ gpb_metadata_struct_init(TSRMLS_C);
+ gpb_metadata_timestamp_init(TSRMLS_C);
+ gpb_metadata_type_init(TSRMLS_C);
+ gpb_metadata_wrappers_init(TSRMLS_C);
+
any_init(TSRMLS_C);
api_init(TSRMLS_C);
bool_value_init(TSRMLS_C);
diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h
index cb098747..18343772 100644
--- a/php/ext/google/protobuf/protobuf.h
+++ b/php/ext/google/protobuf/protobuf.h
@@ -610,7 +610,6 @@ typedef struct BytesValue BytesValue;
typedef struct Descriptor Descriptor;
typedef struct Descriptor Descriptor;
typedef struct DescriptorPool DescriptorPool;
-typedef struct DescriptorPool DescriptorPool;
typedef struct DoubleValue DoubleValue;
typedef struct Duration Duration;
typedef struct Enum Enum;
@@ -630,7 +629,6 @@ typedef struct GPBEmpty GPBEmpty;
typedef struct Int32Value Int32Value;
typedef struct Int64Value Int64Value;
typedef struct InternalDescriptorPool InternalDescriptorPool;
-typedef struct InternalDescriptorPool InternalDescriptorPool;
typedef struct ListValue ListValue;
typedef struct Map Map;
typedef struct Map Map;
@@ -714,6 +712,17 @@ void uint64_value_init(TSRMLS_D);
void util_init(TSRMLS_D);
void value_init(TSRMLS_D);
+void gpb_metadata_any_init(TSRMLS_D);
+void gpb_metadata_api_init(TSRMLS_D);
+void gpb_metadata_duration_init(TSRMLS_D);
+void gpb_metadata_field_mask_init(TSRMLS_D);
+void gpb_metadata_empty_init(TSRMLS_D);
+void gpb_metadata_source_context_init(TSRMLS_D);
+void gpb_metadata_struct_init(TSRMLS_D);
+void gpb_metadata_timestamp_init(TSRMLS_D);
+void gpb_metadata_type_init(TSRMLS_D);
+void gpb_metadata_wrappers_init(TSRMLS_D);
+
// Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
// instances.
void add_def_obj(const void* def, PHP_PROTO_HASHTABLE_VALUE value);
@@ -1170,6 +1179,17 @@ extern zend_class_entry* oneof_descriptor_type;
// Well Known Type.
// -----------------------------------------------------------------------------
+PHP_METHOD(GPBMetadata_Any, initOnce);
+PHP_METHOD(GPBMetadata_Api, initOnce);
+PHP_METHOD(GPBMetadata_Duration, initOnce);
+PHP_METHOD(GPBMetadata_FieldMask, initOnce);
+PHP_METHOD(GPBMetadata_Empty, initOnce);
+PHP_METHOD(GPBMetadata_SourceContext, initOnce);
+PHP_METHOD(GPBMetadata_Struct, initOnce);
+PHP_METHOD(GPBMetadata_Timestamp, initOnce);
+PHP_METHOD(GPBMetadata_Type, initOnce);
+PHP_METHOD(GPBMetadata_Wrappers, initOnce);
+
PHP_METHOD(Any, __construct);
PHP_METHOD(Any, getTypeUrl);
PHP_METHOD(Any, setTypeUrl);