Skip to content

Commit 28944b8

Browse files
authored
Declare ext/pcre constants in stubs (#9077)
1 parent 8487d8f commit 28944b8

File tree

3 files changed

+134
-30
lines changed

3 files changed

+134
-30
lines changed

ext/pcre/php_pcre.c

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "php_ini.h"
1919
#include "php_globals.h"
2020
#include "php_pcre.h"
21-
#include "php_pcre_arginfo.h"
2221
#include "ext/standard/info.h"
2322
#include "ext/standard/basic_functions.h"
2423
#include "zend_smart_str.h"
@@ -43,6 +42,16 @@
4342

4443
#define PCRE_CACHE_SIZE 4096
4544

45+
#ifdef HAVE_PCRE_JIT_SUPPORT
46+
#define PHP_PCRE_JIT_SUPPORT 1
47+
#else
48+
#define PHP_PCRE_JIT_SUPPORT 0
49+
#endif
50+
51+
char *php_pcre_version;
52+
53+
#include "php_pcre_arginfo.h"
54+
4655
struct _pcre_cache_entry {
4756
pcre2_code *re;
4857
uint32_t preg_options;
@@ -422,8 +431,6 @@ static PHP_MINFO_FUNCTION(pcre)
422431
/* {{{ PHP_MINIT_FUNCTION(pcre) */
423432
static PHP_MINIT_FUNCTION(pcre)
424433
{
425-
char *version;
426-
427434
#ifdef HAVE_PCRE_JIT_SUPPORT
428435
if (UNEXPECTED(!pcre2_init_ok)) {
429436
/* Retry. */
@@ -436,33 +443,9 @@ static PHP_MINIT_FUNCTION(pcre)
436443

437444
REGISTER_INI_ENTRIES();
438445

439-
REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT);
440-
REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT);
441-
REGISTER_LONG_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT);
442-
REGISTER_LONG_CONSTANT("PREG_UNMATCHED_AS_NULL", PREG_UNMATCHED_AS_NULL, CONST_CS | CONST_PERSISTENT);
443-
REGISTER_LONG_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT);
444-
REGISTER_LONG_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT);
445-
REGISTER_LONG_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT);
446-
REGISTER_LONG_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT);
447-
448-
REGISTER_LONG_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT);
449-
REGISTER_LONG_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT);
450-
REGISTER_LONG_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
451-
REGISTER_LONG_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
452-
REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT);
453-
REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_OFFSET_ERROR", PHP_PCRE_BAD_UTF8_OFFSET_ERROR, CONST_CS | CONST_PERSISTENT);
454-
REGISTER_LONG_CONSTANT("PREG_JIT_STACKLIMIT_ERROR", PHP_PCRE_JIT_STACKLIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
455-
version = _pcre2_config_str(PCRE2_CONFIG_VERSION);
456-
REGISTER_STRING_CONSTANT("PCRE_VERSION", version, CONST_CS | CONST_PERSISTENT);
457-
free(version);
458-
REGISTER_LONG_CONSTANT("PCRE_VERSION_MAJOR", PCRE2_MAJOR, CONST_CS | CONST_PERSISTENT);
459-
REGISTER_LONG_CONSTANT("PCRE_VERSION_MINOR", PCRE2_MINOR, CONST_CS | CONST_PERSISTENT);
446+
php_pcre_version = _pcre2_config_str(PCRE2_CONFIG_VERSION);
460447

461-
#ifdef HAVE_PCRE_JIT_SUPPORT
462-
REGISTER_BOOL_CONSTANT("PCRE_JIT_SUPPORT", 1, CONST_CS | CONST_PERSISTENT);
463-
#else
464-
REGISTER_BOOL_CONSTANT("PCRE_JIT_SUPPORT", 0, CONST_CS | CONST_PERSISTENT);
465-
#endif
448+
register_php_pcre_symbols(module_number);
466449

467450
return SUCCESS;
468451
}
@@ -473,6 +456,8 @@ static PHP_MSHUTDOWN_FUNCTION(pcre)
473456
{
474457
UNREGISTER_INI_ENTRIES();
475458

459+
free(php_pcre_version);
460+
476461
return SUCCESS;
477462
}
478463
/* }}} */

ext/pcre/php_pcre.stub.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,102 @@
22

33
/** @generate-class-entries */
44

5+
/**
6+
* @var int
7+
* @cvalue PREG_PATTERN_ORDER
8+
*/
9+
const PREG_PATTERN_ORDER = UNKNOWN;
10+
/**
11+
* @var int
12+
* @cvalue PREG_SET_ORDER
13+
*/
14+
const PREG_SET_ORDER = UNKNOWN;
15+
/**
16+
* @var int
17+
* @cvalue PREG_OFFSET_CAPTURE
18+
*/
19+
const PREG_OFFSET_CAPTURE = UNKNOWN;
20+
/**
21+
* @var int
22+
* @cvalue PREG_UNMATCHED_AS_NULL
23+
*/
24+
const PREG_UNMATCHED_AS_NULL = UNKNOWN;
25+
/**
26+
* @var int
27+
* @cvalue PREG_SPLIT_NO_EMPTY
28+
*/
29+
const PREG_SPLIT_NO_EMPTY = UNKNOWN;
30+
/**
31+
* @var int
32+
* @cvalue PREG_SPLIT_DELIM_CAPTURE
33+
*/
34+
const PREG_SPLIT_DELIM_CAPTURE = UNKNOWN;
35+
/**
36+
* @var int
37+
* @cvalue PREG_SPLIT_OFFSET_CAPTURE
38+
*/
39+
const PREG_SPLIT_OFFSET_CAPTURE = UNKNOWN;
40+
/**
41+
* @var int
42+
* @cvalue PREG_GREP_INVERT
43+
*/
44+
const PREG_GREP_INVERT = UNKNOWN;
45+
/**
46+
* @var int
47+
* @cvalue PHP_PCRE_NO_ERROR
48+
*/
49+
const PREG_NO_ERROR = UNKNOWN;
50+
/**
51+
* @var int
52+
* @cvalue PHP_PCRE_INTERNAL_ERROR
53+
*/
54+
const PREG_INTERNAL_ERROR = UNKNOWN;
55+
/**
56+
* @var int
57+
* @cvalue PHP_PCRE_BACKTRACK_LIMIT_ERROR
58+
*/
59+
const PREG_BACKTRACK_LIMIT_ERROR = UNKNOWN;
60+
/**
61+
* @var int
62+
* @cvalue PHP_PCRE_RECURSION_LIMIT_ERROR
63+
*/
64+
const PREG_RECURSION_LIMIT_ERROR = UNKNOWN;
65+
/**
66+
* @var int
67+
* @cvalue PHP_PCRE_BAD_UTF8_ERROR
68+
*/
69+
const PREG_BAD_UTF8_ERROR = UNKNOWN;
70+
/**
71+
* @var int
72+
* @cvalue PHP_PCRE_BAD_UTF8_OFFSET_ERROR
73+
*/
74+
const PREG_BAD_UTF8_OFFSET_ERROR = UNKNOWN;
75+
/**
76+
* @var int
77+
* @cvalue PHP_PCRE_JIT_STACKLIMIT_ERROR
78+
*/
79+
const PREG_JIT_STACKLIMIT_ERROR = UNKNOWN;
80+
/**
81+
* @var string
82+
* @cvalue php_pcre_version
83+
*/
84+
const PCRE_VERSION = UNKNOWN;
85+
/**
86+
* @var int
87+
* @cvalue PCRE2_MAJOR
88+
*/
89+
const PCRE_VERSION_MAJOR = UNKNOWN;
90+
/**
91+
* @var int
92+
* @cvalue PCRE2_MINOR
93+
*/
94+
const PCRE_VERSION_MINOR = UNKNOWN;
95+
/**
96+
* @var bool
97+
* @cvalue PHP_PCRE_JIT_SUPPORT
98+
*/
99+
const PCRE_JIT_SUPPORT = UNKNOWN;
100+
5101
/** @param array $matches */
6102
function preg_match(string $pattern, string $subject, &$matches = null, int $flags = 0, int $offset = 0): int|false {}
7103

ext/pcre/php_pcre_arginfo.h

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)