Skip to content

Commit 8fca87a

Browse files
author
Andrei Zmievski
committed
Updated to match TSRM changes.
1 parent 33e0590 commit 8fca87a

File tree

2 files changed

+12
-40
lines changed

2 files changed

+12
-40
lines changed

ext/pcre/php_pcre.c

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@
4040

4141
#define PREG_REPLACE_EVAL (1<<0)
4242

43-
#ifdef ZTS
44-
int pcre_globals_id;
45-
#else
46-
php_pcre_globals pcre_globals;
47-
#endif
43+
44+
ZEND_DECLARE_MODULE_GLOBALS(pcre)
4845

4946

5047
static void *php_pcre_malloc(size_t size)
@@ -69,16 +66,15 @@ static void php_free_pcre_cache(void *data)
6966
}
7067

7168

72-
#ifdef ZTS
73-
static void php_pcre_init_globals(php_pcre_globals *pcre_globals TSRMLS_DC)
69+
static void php_pcre_init_globals(zend_pcre_globals *pcre_globals TSRMLS_DC)
7470
{
75-
zend_hash_init(&PCRE_G(pcre_cache), 0, NULL, php_free_pcre_cache, 1);
71+
zend_hash_init(&pcre_globals->pcre_cache, 0, NULL, php_free_pcre_cache, 1);
7672
}
7773

78-
79-
static void php_pcre_shutdown_globals(php_pcre_globals *pcre_globals TSRMLS_DC)
74+
#ifdef ZTS
75+
static void php_pcre_shutdown_globals(zend_pcre_globals *pcre_globals TSRMLS_DC)
8076
{
81-
zend_hash_destroy(&PCRE_G(pcre_cache));
77+
zend_hash_destroy(&pcre_globals->pcre_cache);
8278
}
8379
#endif
8480

@@ -96,15 +92,7 @@ PHP_MINFO_FUNCTION(pcre)
9692
/* {{{ PHP_MINIT_FUNCTION(pcre) */
9793
static PHP_MINIT_FUNCTION(pcre)
9894
{
99-
#ifdef ZTS
100-
ts_allocate_id(
101-
&pcre_globals_id,
102-
sizeof(php_pcre_globals),
103-
(ts_allocate_ctor) php_pcre_init_globals,
104-
(ts_allocate_dtor) php_pcre_shutdown_globals);
105-
#else
106-
zend_hash_init(&PCRE_G(pcre_cache), 0, NULL, php_free_pcre_cache, 1);
107-
#endif
95+
ZEND_INIT_MODULE_GLOBALS(pcre, php_pcre_init_globals, php_pcre_shutdown_globals);
10896

10997
REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT);
11098
REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT);
@@ -117,11 +105,6 @@ static PHP_MINIT_FUNCTION(pcre)
117105
/* {{{ PHP_MSHUTDOWN_FUNCTION(pcre) */
118106
static PHP_MSHUTDOWN_FUNCTION(pcre)
119107
{
120-
#ifndef ZTS
121-
zend_hash_destroy(&PCRE_G(pcre_cache));
122-
#else
123-
ts_free_id(pcre_globals_id);
124-
#endif
125108
return SUCCESS;
126109
}
127110
/* }}} */
@@ -158,7 +141,7 @@ static pcre* pcre_get_compiled_regex(char *regex, pcre_extra *extra, int *preg_o
158141
#endif
159142
pcre_cache_entry *pce;
160143
pcre_cache_entry new_entry;
161-
PCRE_LS_FETCH();
144+
TSRMLS_FETCH();
162145

163146
/* Try to lookup the cached regex entry, and if successful, just pass
164147
back the compiled pattern, otherwise go on and compile it. */

ext/pcre/php_pcre.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,14 @@ typedef struct {
5454
#endif
5555
} pcre_cache_entry;
5656

57-
typedef struct {
57+
ZEND_BEGIN_MODULE_GLOBALS(pcre)
5858
HashTable pcre_cache;
59-
} php_pcre_globals;
59+
ZEND_END_MODULE_GLOBALS(pcre)
6060

6161
#ifdef ZTS
62-
# define PCRE_LS_D php_pcre_globals *pcre_globals
63-
# define PCRE_LS_DC , PCRE_LS_D
64-
# define PCRE_LS_C pcre_globals
65-
# define PCRE_LS_CC , PCRE_LS_C
66-
# define PCRE_G(v) (pcre_globals->v)
67-
# define PCRE_LS_FETCH() php_pcre_globals *pcre_globals = ts_resource(pcre_globals_id);
62+
# define PCRE_G(v) TSRMG(pcre_globals_id, zend_pcre_globals *, v)
6863
#else
69-
# define PCRE_LS_D
70-
# define PCRE_LS_DC
71-
# define PCRE_LS_C
72-
# define PCRE_LS_CC
7364
# define PCRE_G(v) (pcre_globals.v)
74-
# define PCRE_LS_FETCH()
75-
extern ZEND_API php_pcre_globals pcre_globals;
7665
#endif
7766

7867
#else

0 commit comments

Comments
 (0)