Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent Descriptor Pool #6899

Merged
merged 16 commits into from Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
244 changes: 175 additions & 69 deletions php/ext/google/protobuf/def.c

Large diffs are not rendered by default.

107 changes: 45 additions & 62 deletions php/ext/google/protobuf/encode_decode.c

Large diffs are not rendered by default.

37 changes: 15 additions & 22 deletions php/ext/google/protobuf/message.c
Expand Up @@ -255,7 +255,7 @@ void* message_data(MessageHeader* msg) {

void custom_data_init(const zend_class_entry* ce,
MessageHeader* intern PHP_PROTO_TSRMLS_DC) {
Descriptor* desc = UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(ce));
DescriptorInternal* desc = get_ce_desc(ce);
intern->data = ALLOC_N(uint8_t, desc->layout->size);
// We wrap first so that everything in the message object is GC-rooted in
// case a collection happens during object creation in layout_init().
Expand All @@ -279,15 +279,15 @@ void build_class_from_descriptor(
Descriptor* desc = UNBOX_HASHTABLE_VALUE(Descriptor, php_descriptor);

// Map entries don't have existing php class.
if (upb_msgdef_mapentry(desc->msgdef)) {
if (upb_msgdef_mapentry(desc->intern->msgdef)) {
return;
}

zend_class_entry* registered_ce = desc->klass;
zend_class_entry* registered_ce = desc->intern->klass;

if (desc->layout == NULL) {
MessageLayout* layout = create_layout(desc->msgdef);
desc->layout = layout;
if (desc->intern->layout == NULL) {
MessageLayout* layout = create_layout(desc->intern->msgdef);
desc->intern->layout = layout;
}

registered_ce->create_object = message_create;
Expand Down Expand Up @@ -395,8 +395,7 @@ void Message_construct(zval* msg, zval* array_wrapper) {
is_wrapper = is_wrapper_msg(submsgdef);

if (is_wrapper) {
PHP_PROTO_HASHTABLE_VALUE subdesc_php = get_def_obj(submsgdef);
Descriptor* subdesc = UNBOX_HASHTABLE_VALUE(Descriptor, subdesc_php);
DescriptorInternal* subdesc = get_msgdef_desc(submsgdef);
subklass = subdesc->klass;
}
}
Expand Down Expand Up @@ -435,8 +434,7 @@ void Message_construct(zval* msg, zval* array_wrapper) {
is_wrapper = is_wrapper_msg(submsgdef);

if (is_wrapper) {
PHP_PROTO_HASHTABLE_VALUE subdesc_php = get_def_obj(submsgdef);
Descriptor* subdesc = UNBOX_HASHTABLE_VALUE(Descriptor, subdesc_php);
DescriptorInternal* subdesc = get_msgdef_desc(submsgdef);
subklass = subdesc->klass;
}
}
Expand All @@ -459,8 +457,7 @@ void Message_construct(zval* msg, zval* array_wrapper) {
}
} else if (upb_fielddef_issubmsg(field)) {
const upb_msgdef* submsgdef = upb_fielddef_msgsubdef(field);
PHP_PROTO_HASHTABLE_VALUE desc_php = get_def_obj(submsgdef);
Descriptor* desc = UNBOX_HASHTABLE_VALUE(Descriptor, desc_php);
DescriptorInternal* desc = get_msgdef_desc(submsgdef);

CACHED_VALUE* cached = NULL;
if (upb_fielddef_containingoneof(field)) {
Expand Down Expand Up @@ -530,7 +527,7 @@ PHP_METHOD(Message, __construct) {

PHP_METHOD(Message, clear) {
MessageHeader* msg = UNBOX(MessageHeader, getThis());
Descriptor* desc = msg->descriptor;
DescriptorInternal* desc = msg->descriptor;
zend_class_entry* ce = desc->klass;

zend_object_std_dtor(&msg->std TSRMLS_CC);
Expand Down Expand Up @@ -1536,14 +1533,13 @@ PHP_METHOD(Any, unpack) {
}

const char* fully_qualified_name = type_url + url_prefix_len;
PHP_PROTO_HASHTABLE_VALUE desc_php = get_proto_obj(fully_qualified_name);
if (desc_php == NULL) {
DescriptorInternal* desc = get_proto_desc(fully_qualified_name);
if (desc == NULL) {
zend_throw_exception(
NULL, "Specified message in any hasn't been added to descriptor pool",
0 TSRMLS_CC);
return;
}
Descriptor* desc = UNBOX_HASHTABLE_VALUE(Descriptor, desc_php);
zend_class_entry* klass = desc->klass;
ZVAL_OBJ(return_value, klass->create_object(klass TSRMLS_CC));
MessageHeader* msg = UNBOX(MessageHeader, return_value);
Expand Down Expand Up @@ -1589,8 +1585,7 @@ PHP_METHOD(Any, pack) {
PHP_PROTO_FAKE_SCOPE_END;

// Set type url.
Descriptor* desc =
UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(val)));
DescriptorInternal* desc = get_ce_desc(Z_OBJCE_P(val));
const char* fully_qualified_name = upb_msgdef_fullname(desc->msgdef);
size_t type_url_len =
strlen(TYPE_URL_PREFIX) + strlen(fully_qualified_name) + 1;
Expand All @@ -1617,14 +1612,12 @@ PHP_METHOD(Any, is) {
return;
}

PHP_PROTO_HASHTABLE_VALUE desc_php = get_ce_obj(klass);
if (desc_php == NULL) {
DescriptorInternal* desc = get_ce_desc(klass);
if (desc == NULL) {
RETURN_BOOL(false);
}

// Create corresponded type url.
Descriptor* desc =
UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(klass));
const char* fully_qualified_name = upb_msgdef_fullname(desc->msgdef);
size_t type_url_len =
strlen(TYPE_URL_PREFIX) + strlen(fully_qualified_name) + 1;
Expand Down