@@ -77,6 +77,9 @@ static int _php_free_pcre_cache(void *data)
77
77
{
78
78
pcre_cache_entry * pce = (pcre_cache_entry * ) data ;
79
79
pefree (pce -> re , 1 );
80
+ #if HAVE_SETLOCALE
81
+ pefree ((void * )pce -> tables , 1 );
82
+ #endif
80
83
return 1 ;
81
84
}
82
85
@@ -163,6 +166,10 @@ static pcre* _pcre_get_compiled_regex(char *regex, pcre_extra *extra, int *preg_
163
166
int regex_len ;
164
167
int do_study = 0 ;
165
168
int poptions = 0 ;
169
+ unsigned const char * tables = NULL ;
170
+ #if HAVE_SETLOCALE
171
+ char * locale = setlocale (LC_CTYPE , NULL );
172
+ #endif
166
173
pcre_cache_entry * pce ;
167
174
pcre_cache_entry new_entry ;
168
175
PCRE_LS_FETCH ();
@@ -171,9 +178,15 @@ static pcre* _pcre_get_compiled_regex(char *regex, pcre_extra *extra, int *preg_
171
178
back the compiled pattern, otherwise go on and compile it. */
172
179
regex_len = strlen (regex );
173
180
if (zend_hash_find (& PCRE_G (pcre_cache ), regex , regex_len + 1 , (void * * )& pce ) == SUCCESS ) {
174
- extra = pce -> extra ;
175
- * preg_options = pce -> preg_options ;
176
- return pce -> re ;
181
+ #if HAVE_SETLOCALE
182
+ if (!strcmp (pce -> locale , locale )) {
183
+ #endif
184
+ extra = pce -> extra ;
185
+ * preg_options = pce -> preg_options ;
186
+ return pce -> re ;
187
+ #if HAVE_SETLOCALE
188
+ }
189
+ #endif
177
190
}
178
191
179
192
p = regex ;
@@ -247,13 +260,18 @@ static pcre* _pcre_get_compiled_regex(char *regex, pcre_extra *extra, int *preg_
247
260
return NULL ;
248
261
}
249
262
}
263
+
264
+ #if HAVE_SETLOCALE
265
+ if (strcmp (locale , "C" ))
266
+ tables = pcre_maketables ();
267
+ #endif
250
268
251
269
/* Compile pattern and display a warning if compilation failed. */
252
270
re = pcre_compile (pattern ,
253
271
coptions ,
254
272
& error ,
255
273
& erroffset ,
256
- NULL );
274
+ tables );
257
275
258
276
if (re == NULL ) {
259
277
zend_error (E_WARNING , "Compilation failed: %s at offset %d\n" , error , erroffset );
@@ -278,6 +296,10 @@ static pcre* _pcre_get_compiled_regex(char *regex, pcre_extra *extra, int *preg_
278
296
new_entry .re = re ;
279
297
new_entry .extra = extra ;
280
298
new_entry .preg_options = poptions ;
299
+ #if HAVE_SETLOCALE
300
+ new_entry .locale = locale ;
301
+ new_entry .tables = tables ;
302
+ #endif
281
303
zend_hash_update (& PCRE_G (pcre_cache ), regex , regex_len + 1 , (void * )& new_entry ,
282
304
sizeof (pcre_cache_entry ), NULL );
283
305
0 commit comments