Skip to content

Commit 4d2b8f2

Browse files
committed
Merge pull request #485
2 parents 0341455 + 0bf7264 commit 4d2b8f2

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

php_phongo.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,7 @@ void phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
15111511
bson_iter_t iter;
15121512

15131513
#if PHP_VERSION_ID >= 70000
1514-
zval *client_ptr;
1515-
zval new_client_ptr;
1514+
mongoc_client_t *client_ptr;
15161515
#else
15171516
mongoc_client_t **client_ptr;
15181517
#endif
@@ -1523,9 +1522,9 @@ void phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
15231522
}
15241523

15251524
#if PHP_VERSION_ID >= 70000
1526-
if ((client_ptr = zend_hash_str_find(&MONGODB_G(clients), hash, hash_len)) && Z_TYPE_P(client_ptr) == IS_PTR) {
1525+
if ((client_ptr = zend_hash_str_find_ptr(&MONGODB_G(clients), hash, hash_len)) != NULL) {
15271526
MONGOC_DEBUG("Found client for hash: %s\n", hash);
1528-
manager->client = (mongoc_client_t *)Z_PTR_P(client_ptr);
1527+
manager->client = client_ptr;
15291528
goto cleanup;
15301529
}
15311530
#else
@@ -1582,8 +1581,7 @@ void phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
15821581

15831582
MONGOC_DEBUG("Created client hash: %s\n", hash);
15841583
#if PHP_VERSION_ID >= 70000
1585-
ZVAL_PTR(&new_client_ptr, manager->client);
1586-
zend_hash_str_update(&MONGODB_G(clients), hash, hash_len, &new_client_ptr);
1584+
zend_hash_str_update_ptr(&MONGODB_G(clients), hash, hash_len, manager->client);
15871585
#else
15881586
zend_hash_update(&MONGODB_G(clients), hash, hash_len + 1, &manager->client, sizeof(mongoc_client_t *), NULL);
15891587
#endif
@@ -1984,6 +1982,18 @@ PHP_INI_BEGIN()
19841982
PHP_INI_END()
19851983
/* }}} */
19861984

1985+
#if PHP_VERSION_ID >= 70000
1986+
static void php_phongo_client_dtor(zval *zv)
1987+
{
1988+
mongoc_client_destroy((mongoc_client_t *) Z_PTR_P(zv));
1989+
}
1990+
#else
1991+
static void php_phongo_client_dtor(void *client)
1992+
{
1993+
mongoc_client_destroy(*((mongoc_client_t **) client));
1994+
}
1995+
#endif
1996+
19871997
/* {{{ PHP_GINIT_FUNCTION */
19881998
PHP_GINIT_FUNCTION(mongodb)
19891999
{
@@ -1998,24 +2008,13 @@ PHP_GINIT_FUNCTION(mongodb)
19982008
ZEND_TSRMLS_CACHE_UPDATE();
19992009
#endif
20002010
#endif
2001-
mongodb_globals->debug_fd = NULL;
2011+
memset(mongodb_globals, 0, sizeof(zend_mongodb_globals));
20022012
mongodb_globals->bsonMemVTable = bsonMemVTable;
2003-
2013+
/* Initialize HashTable for persistent clients */
2014+
zend_hash_init_ex(&mongodb_globals->clients, 0, NULL, php_phongo_client_dtor, 1, 0);
20042015
}
20052016
/* }}} */
20062017

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-
20192018
/* {{{ PHP_MINIT_FUNCTION */
20202019
PHP_MINIT_FUNCTION(mongodb)
20212020
{
@@ -2037,9 +2036,6 @@ PHP_MINIT_FUNCTION(mongodb)
20372036
/* Initialize libbson */
20382037
bson_mem_set_vtable(&MONGODB_G(bsonMemVTable));
20392038

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

php_phongo.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@ 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
53-
# ifdef ZTS
54-
# define MONGODB_G(v) TSRMG(mongodb_globals_id, zend_mongodb_globals *, v)
55-
# define mglo mongodb_globals_id
56-
# else
57-
# define MONGODB_G(v) (mongodb_globals.v)
58-
# define mglo mongodb_globals
59-
# endif
56+
# ifdef ZTS
57+
# define MONGODB_G(v) TSRMG(mongodb_globals_id, zend_mongodb_globals *, v)
58+
# define mglo mongodb_globals_id
59+
# else
60+
# define MONGODB_G(v) (mongodb_globals.v)
61+
# define mglo mongodb_globals
62+
# endif
6063
#endif
6164

6265
#define PHONGO_WRITE_CONCERN_W_MAJORITY "majority"

0 commit comments

Comments
 (0)