|
|
@ -66,7 +66,7 @@ ZEND_BEGIN_MODULE_GLOBALS(protobuf) |
|
|
|
// to rebuild it from scratch. When keep_descriptor_pool_after_request==true,
|
|
|
|
// to rebuild it from scratch. When keep_descriptor_pool_after_request==true,
|
|
|
|
// we steal the upb_symtab from the global DescriptorPool object just before
|
|
|
|
// we steal the upb_symtab from the global DescriptorPool object just before
|
|
|
|
// destroying it.
|
|
|
|
// destroying it.
|
|
|
|
upb_symtab *saved_symtab; |
|
|
|
upb_symtab *global_symtab; |
|
|
|
|
|
|
|
|
|
|
|
// Object cache (see interface in protobuf.h).
|
|
|
|
// Object cache (see interface in protobuf.h).
|
|
|
|
HashTable object_cache; |
|
|
|
HashTable object_cache; |
|
|
@ -82,6 +82,13 @@ ZEND_BEGIN_MODULE_GLOBALS(protobuf) |
|
|
|
HashTable descriptors; |
|
|
|
HashTable descriptors; |
|
|
|
ZEND_END_MODULE_GLOBALS(protobuf) |
|
|
|
ZEND_END_MODULE_GLOBALS(protobuf) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void free_protobuf_globals(zend_protobuf_globals *globals) { |
|
|
|
|
|
|
|
zend_hash_destroy(&globals->name_msg_cache); |
|
|
|
|
|
|
|
zend_hash_destroy(&globals->name_enum_cache); |
|
|
|
|
|
|
|
upb_symtab_free(globals->global_symtab); |
|
|
|
|
|
|
|
globals->global_symtab = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ZEND_DECLARE_MODULE_GLOBALS(protobuf) |
|
|
|
ZEND_DECLARE_MODULE_GLOBALS(protobuf) |
|
|
|
|
|
|
|
|
|
|
|
const zval *get_generated_pool() { |
|
|
|
const zval *get_generated_pool() { |
|
|
@ -146,14 +153,14 @@ const zval *get_generated_pool() { |
|
|
|
// discouraged by the documentation: https://serverfault.com/a/231660
|
|
|
|
// discouraged by the documentation: https://serverfault.com/a/231660
|
|
|
|
|
|
|
|
|
|
|
|
static PHP_GSHUTDOWN_FUNCTION(protobuf) { |
|
|
|
static PHP_GSHUTDOWN_FUNCTION(protobuf) { |
|
|
|
if (protobuf_globals->saved_symtab) { |
|
|
|
if (protobuf_globals->global_symtab) { |
|
|
|
upb_symtab_free(protobuf_globals->saved_symtab); |
|
|
|
free_protobuf_globals(protobuf_globals); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static PHP_GINIT_FUNCTION(protobuf) { |
|
|
|
static PHP_GINIT_FUNCTION(protobuf) { |
|
|
|
ZVAL_NULL(&protobuf_globals->generated_pool); |
|
|
|
ZVAL_NULL(&protobuf_globals->generated_pool); |
|
|
|
protobuf_globals->saved_symtab = NULL; |
|
|
|
protobuf_globals->global_symtab = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -164,12 +171,15 @@ static PHP_GINIT_FUNCTION(protobuf) { |
|
|
|
static PHP_RINIT_FUNCTION(protobuf) { |
|
|
|
static PHP_RINIT_FUNCTION(protobuf) { |
|
|
|
// Create the global generated pool.
|
|
|
|
// Create the global generated pool.
|
|
|
|
// Reuse the symtab (if any) left to us by the last request.
|
|
|
|
// Reuse the symtab (if any) left to us by the last request.
|
|
|
|
upb_symtab *symtab = PROTOBUF_G(saved_symtab); |
|
|
|
upb_symtab *symtab = PROTOBUF_G(global_symtab); |
|
|
|
|
|
|
|
if (!symtab) { |
|
|
|
|
|
|
|
PROTOBUF_G(global_symtab) = symtab = upb_symtab_new(); |
|
|
|
|
|
|
|
zend_hash_init(&PROTOBUF_G(name_msg_cache), 64, NULL, NULL, 0); |
|
|
|
|
|
|
|
zend_hash_init(&PROTOBUF_G(name_enum_cache), 64, NULL, NULL, 0); |
|
|
|
|
|
|
|
} |
|
|
|
DescriptorPool_CreateWithSymbolTable(&PROTOBUF_G(generated_pool), symtab); |
|
|
|
DescriptorPool_CreateWithSymbolTable(&PROTOBUF_G(generated_pool), symtab); |
|
|
|
|
|
|
|
|
|
|
|
zend_hash_init(&PROTOBUF_G(object_cache), 64, NULL, NULL, 0); |
|
|
|
zend_hash_init(&PROTOBUF_G(object_cache), 64, NULL, NULL, 0); |
|
|
|
zend_hash_init(&PROTOBUF_G(name_msg_cache), 64, NULL, NULL, 0); |
|
|
|
|
|
|
|
zend_hash_init(&PROTOBUF_G(name_enum_cache), 64, NULL, NULL, 0); |
|
|
|
|
|
|
|
zend_hash_init(&PROTOBUF_G(descriptors), 64, NULL, ZVAL_PTR_DTOR, 0); |
|
|
|
zend_hash_init(&PROTOBUF_G(descriptors), 64, NULL, ZVAL_PTR_DTOR, 0); |
|
|
|
|
|
|
|
|
|
|
|
return SUCCESS; |
|
|
|
return SUCCESS; |
|
|
@ -182,15 +192,12 @@ static PHP_RINIT_FUNCTION(protobuf) { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static PHP_RSHUTDOWN_FUNCTION(protobuf) { |
|
|
|
static PHP_RSHUTDOWN_FUNCTION(protobuf) { |
|
|
|
// Preserve the symtab if requested.
|
|
|
|
// Preserve the symtab if requested.
|
|
|
|
if (PROTOBUF_G(keep_descriptor_pool_after_request)) { |
|
|
|
if (!PROTOBUF_G(keep_descriptor_pool_after_request)) { |
|
|
|
zval *zv = &PROTOBUF_G(generated_pool); |
|
|
|
free_protobuf_globals(ZEND_MODULE_GLOBALS_BULK(protobuf)); |
|
|
|
PROTOBUF_G(saved_symtab) = DescriptorPool_Steal(zv); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
zval_dtor(&PROTOBUF_G(generated_pool)); |
|
|
|
zval_dtor(&PROTOBUF_G(generated_pool)); |
|
|
|
zend_hash_destroy(&PROTOBUF_G(object_cache)); |
|
|
|
zend_hash_destroy(&PROTOBUF_G(object_cache)); |
|
|
|
zend_hash_destroy(&PROTOBUF_G(name_msg_cache)); |
|
|
|
|
|
|
|
zend_hash_destroy(&PROTOBUF_G(name_enum_cache)); |
|
|
|
|
|
|
|
zend_hash_destroy(&PROTOBUF_G(descriptors)); |
|
|
|
zend_hash_destroy(&PROTOBUF_G(descriptors)); |
|
|
|
|
|
|
|
|
|
|
|
return SUCCESS; |
|
|
|
return SUCCESS; |
|
|
@ -296,7 +303,7 @@ static const zend_module_dep protobuf_deps[] = { |
|
|
|
|
|
|
|
|
|
|
|
PHP_INI_BEGIN() |
|
|
|
PHP_INI_BEGIN() |
|
|
|
STD_PHP_INI_ENTRY("protobuf.keep_descriptor_pool_after_request", "0", |
|
|
|
STD_PHP_INI_ENTRY("protobuf.keep_descriptor_pool_after_request", "0", |
|
|
|
PHP_INI_SYSTEM, OnUpdateBool, |
|
|
|
PHP_INI_ALL, OnUpdateBool, |
|
|
|
keep_descriptor_pool_after_request, zend_protobuf_globals, |
|
|
|
keep_descriptor_pool_after_request, zend_protobuf_globals, |
|
|
|
protobuf_globals) |
|
|
|
protobuf_globals) |
|
|
|
PHP_INI_END() |
|
|
|
PHP_INI_END() |
|
|
|