Skip to content

pcre: various minor refactorings (2026-09 N1) - #23536

Open
Girgias wants to merge 6 commits into
php:masterfrom
Girgias:2026-09-pcre-minor-refactoring
Open

Girgias wants to merge 6 commits into
php:masterfrom
Girgias:2026-09-pcre-minor-refactoring

Conversation

@Girgias

@Girgias Girgias commented Sep 1, 2026

Copy link
Copy Markdown
Member

No description provided.

Comment thread ext/pcre/php_pcre.c Outdated

if (key != regex) {
zv = zend_hash_str_lookup(&char_tables, ZSTR_VAL(BG(ctype_string)), ZSTR_LEN(BG(ctype_string)));
zv = zend_hash_lookup(&char_tables, BG(ctype_string));

@devnexen devnexen Sep 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the only change that concerns me a bit. would it be possible to try at least locally this change (with ASAN) ?

❯ can you draft a test to trigger this issue ?zm_globals_dtor_pcre → zend_hash_destroy(&char_tables)).

--TEST--
preg_match(): locale-keyed char tables cache must not borrow a request-lifetime key
--SKIPIF--
<?php
if (setlocale(LC_CTYPE, 'C.UTF-8', 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8') === false) {
    die('skip no suitable non-C locale available');
}
?>
--FILE--
<?php
var_dump(setlocale(LC_CTYPE, 'C.UTF-8', 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8') !== false);
setlocale(LC_CTYPE, setlocale(LC_CTYPE, 0));
var_dump(preg_match('/[[:alpha:]]/', 'a'));
?>
--EXPECT--
bool(true)
int(1)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was already covered by ext/pcre/tests/bug76850.phpt and it does indeed cause issues.

@Girgias
Girgias force-pushed the 2026-09-pcre-minor-refactoring branch from 4554b1a to 37ade72 Compare September 23, 2026 01:31
@Girgias
Girgias marked this pull request as ready for review September 23, 2026 01:32
Comment thread ext/pcre/php_pcre.c
@@ -2924,12 +2916,9 @@ PHP_FUNCTION(preg_grep)

PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return_value, zend_long flags) /* {{{ */

@devnexen devnexen Sep 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I m almost certain you ll agree :) but I think pce can be const here (php_pcre_replace_impl too), wdyt ?

@devnexen devnexen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aside from the little nit, lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants