Skip to content

Declare ext/pcre constants in stubs #9077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 14 additions & 29 deletions ext/pcre/php_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "php_ini.h"
#include "php_globals.h"
#include "php_pcre.h"
#include "php_pcre_arginfo.h"
#include "ext/standard/info.h"
#include "ext/standard/basic_functions.h"
#include "zend_smart_str.h"
Expand All @@ -43,6 +42,16 @@

#define PCRE_CACHE_SIZE 4096

#ifdef HAVE_PCRE_JIT_SUPPORT
#define PHP_PCRE_JIT_SUPPORT 1
#else
#define PHP_PCRE_JIT_SUPPORT 0
#endif

char *php_pcre_version;

#include "php_pcre_arginfo.h"

struct _pcre_cache_entry {
pcre2_code *re;
uint32_t preg_options;
Expand Down Expand Up @@ -422,8 +431,6 @@ static PHP_MINFO_FUNCTION(pcre)
/* {{{ PHP_MINIT_FUNCTION(pcre) */
static PHP_MINIT_FUNCTION(pcre)
{
char *version;

#ifdef HAVE_PCRE_JIT_SUPPORT
if (UNEXPECTED(!pcre2_init_ok)) {
/* Retry. */
Expand All @@ -436,33 +443,9 @@ static PHP_MINIT_FUNCTION(pcre)

REGISTER_INI_ENTRIES();

REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_UNMATCHED_AS_NULL", PREG_UNMATCHED_AS_NULL, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT);

REGISTER_LONG_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_OFFSET_ERROR", PHP_PCRE_BAD_UTF8_OFFSET_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_JIT_STACKLIMIT_ERROR", PHP_PCRE_JIT_STACKLIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
version = _pcre2_config_str(PCRE2_CONFIG_VERSION);
REGISTER_STRING_CONSTANT("PCRE_VERSION", version, CONST_CS | CONST_PERSISTENT);
free(version);
REGISTER_LONG_CONSTANT("PCRE_VERSION_MAJOR", PCRE2_MAJOR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PCRE_VERSION_MINOR", PCRE2_MINOR, CONST_CS | CONST_PERSISTENT);
php_pcre_version = _pcre2_config_str(PCRE2_CONFIG_VERSION);

#ifdef HAVE_PCRE_JIT_SUPPORT
REGISTER_BOOL_CONSTANT("PCRE_JIT_SUPPORT", 1, CONST_CS | CONST_PERSISTENT);
#else
REGISTER_BOOL_CONSTANT("PCRE_JIT_SUPPORT", 0, CONST_CS | CONST_PERSISTENT);
#endif
register_php_pcre_symbols(module_number);

return SUCCESS;
}
Expand All @@ -473,6 +456,8 @@ static PHP_MSHUTDOWN_FUNCTION(pcre)
{
UNREGISTER_INI_ENTRIES();

free(php_pcre_version);

return SUCCESS;
}
/* }}} */
Expand Down
96 changes: 96 additions & 0 deletions ext/pcre/php_pcre.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,102 @@

/** @generate-class-entries */

/**
* @var int
* @cvalue PREG_PATTERN_ORDER
*/
const PREG_PATTERN_ORDER = UNKNOWN;
/**
* @var int
* @cvalue PREG_SET_ORDER
*/
const PREG_SET_ORDER = UNKNOWN;
/**
* @var int
* @cvalue PREG_OFFSET_CAPTURE
*/
const PREG_OFFSET_CAPTURE = UNKNOWN;
/**
* @var int
* @cvalue PREG_UNMATCHED_AS_NULL
*/
const PREG_UNMATCHED_AS_NULL = UNKNOWN;
/**
* @var int
* @cvalue PREG_SPLIT_NO_EMPTY
*/
const PREG_SPLIT_NO_EMPTY = UNKNOWN;
/**
* @var int
* @cvalue PREG_SPLIT_DELIM_CAPTURE
*/
const PREG_SPLIT_DELIM_CAPTURE = UNKNOWN;
/**
* @var int
* @cvalue PREG_SPLIT_OFFSET_CAPTURE
*/
const PREG_SPLIT_OFFSET_CAPTURE = UNKNOWN;
/**
* @var int
* @cvalue PREG_GREP_INVERT
*/
const PREG_GREP_INVERT = UNKNOWN;
/**
* @var int
* @cvalue PHP_PCRE_NO_ERROR
*/
const PREG_NO_ERROR = UNKNOWN;
/**
* @var int
* @cvalue PHP_PCRE_INTERNAL_ERROR
*/
const PREG_INTERNAL_ERROR = UNKNOWN;
/**
* @var int
* @cvalue PHP_PCRE_BACKTRACK_LIMIT_ERROR
*/
const PREG_BACKTRACK_LIMIT_ERROR = UNKNOWN;
/**
* @var int
* @cvalue PHP_PCRE_RECURSION_LIMIT_ERROR
*/
const PREG_RECURSION_LIMIT_ERROR = UNKNOWN;
/**
* @var int
* @cvalue PHP_PCRE_BAD_UTF8_ERROR
*/
const PREG_BAD_UTF8_ERROR = UNKNOWN;
/**
* @var int
* @cvalue PHP_PCRE_BAD_UTF8_OFFSET_ERROR
*/
const PREG_BAD_UTF8_OFFSET_ERROR = UNKNOWN;
/**
* @var int
* @cvalue PHP_PCRE_JIT_STACKLIMIT_ERROR
*/
const PREG_JIT_STACKLIMIT_ERROR = UNKNOWN;
/**
* @var string
* @cvalue php_pcre_version
*/
const PCRE_VERSION = UNKNOWN;
/**
* @var int
* @cvalue PCRE2_MAJOR
*/
const PCRE_VERSION_MAJOR = UNKNOWN;
/**
* @var int
* @cvalue PCRE2_MINOR
*/
const PCRE_VERSION_MINOR = UNKNOWN;
/**
* @var bool
* @cvalue PHP_PCRE_JIT_SUPPORT
*/
const PCRE_JIT_SUPPORT = UNKNOWN;

/** @param array $matches */
function preg_match(string $pattern, string $subject, &$matches = null, int $flags = 0, int $offset = 0): int|false {}

Expand Down
25 changes: 24 additions & 1 deletion ext/pcre/php_pcre_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.