Skip to content

Commit 3daf370

Browse files
committed
PHPC-854: Initialize persistent client hash directly in GINIT
Previous initialization during MINIT and using the accessor macro was causing crashes in Apache. This also declares externs for TSRMLS_CACHE, as is done in other extensions.
1 parent 0341455 commit 3daf370

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

php_phongo.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,18 @@ PHP_INI_BEGIN()
19841984
PHP_INI_END()
19851985
/* }}} */
19861986

1987+
#if PHP_VERSION_ID >= 70000
1988+
static void php_phongo_client_dtor(zval *zv)
1989+
{
1990+
mongoc_client_destroy((mongoc_client_t *) Z_PTR_P(zv));
1991+
}
1992+
#else
1993+
static void php_phongo_client_dtor(void *client)
1994+
{
1995+
mongoc_client_destroy(*((mongoc_client_t **) client));
1996+
}
1997+
#endif
1998+
19871999
/* {{{ PHP_GINIT_FUNCTION */
19882000
PHP_GINIT_FUNCTION(mongodb)
19892001
{
@@ -1998,24 +2010,13 @@ PHP_GINIT_FUNCTION(mongodb)
19982010
ZEND_TSRMLS_CACHE_UPDATE();
19992011
#endif
20002012
#endif
2001-
mongodb_globals->debug_fd = NULL;
2013+
memset(mongodb_globals, 0, sizeof(zend_mongodb_globals));
20022014
mongodb_globals->bsonMemVTable = bsonMemVTable;
2003-
2015+
/* Initialize HashTable for persistent clients */
2016+
zend_hash_init_ex(&mongodb_globals->clients, 0, NULL, php_phongo_client_dtor, 1, 0);
20042017
}
20052018
/* }}} */
20062019

2007-
#if PHP_VERSION_ID >= 70000
2008-
static void php_phongo_client_dtor(zval *zv)
2009-
{
2010-
mongoc_client_destroy((mongoc_client_t *) Z_PTR_P(zv));
2011-
}
2012-
#else
2013-
static void php_phongo_client_dtor(void *client)
2014-
{
2015-
mongoc_client_destroy(*((mongoc_client_t **) client));
2016-
}
2017-
#endif
2018-
20192020
/* {{{ PHP_MINIT_FUNCTION */
20202021
PHP_MINIT_FUNCTION(mongodb)
20212022
{
@@ -2037,9 +2038,6 @@ PHP_MINIT_FUNCTION(mongodb)
20372038
/* Initialize libbson */
20382039
bson_mem_set_vtable(&MONGODB_G(bsonMemVTable));
20392040

2040-
/* Initialize HashTable for persistent clients */
2041-
zend_hash_init(&MONGODB_G(clients), 0, NULL, php_phongo_client_dtor, 1);
2042-
20432041
/* Prep default object handlers to be used when we register the classes */
20442042
memcpy(&phongo_std_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
20452043
phongo_std_object_handlers.clone_obj = NULL;

php_phongo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ ZEND_BEGIN_MODULE_GLOBALS(mongodb)
4848
ZEND_END_MODULE_GLOBALS(mongodb)
4949

5050
#if PHP_VERSION_ID >= 70000
51-
# define MONGODB_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(mongodb, v)
51+
# define MONGODB_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(mongodb, v)
52+
# if defined(ZTS) && defined(COMPILE_DL_MONGODB)
53+
ZEND_TSRMLS_CACHE_EXTERN()
54+
# endif
5255
#else
5356
# ifdef ZTS
5457
# define MONGODB_G(v) TSRMG(mongodb_globals_id, zend_mongodb_globals *, v)

0 commit comments

Comments
 (0)