mirror of
https://github.com/php/php-src.git
synced 2024-11-26 19:33:55 +08:00
Make globals const (part 2) (#10610)
* Zend/zend_enum: make `forbidden_methods` static+const * main/php_syslog: make `xdigits` static * sapi/fpm: make several globals `const` * sapi/phpdbg: make `OPTIONS` static * sapi/phpdbg/help: make help texts const * sapi/cli: make `template_map` const * ext/ffi: make `zend_ffi_types` static * ext/bcmath: make `ref_str` const * ext/phar: make several globals static+const
This commit is contained in:
parent
c0d89e54c8
commit
d46dea169c
@ -85,7 +85,7 @@ static void zend_verify_enum_magic_methods(zend_class_entry *ce)
|
||||
ZEND_ENUM_DISALLOW_MAGIC_METHOD(__serialize, "__serialize");
|
||||
ZEND_ENUM_DISALLOW_MAGIC_METHOD(__unserialize, "__unserialize");
|
||||
|
||||
const char *forbidden_methods[] = {
|
||||
static const char *const forbidden_methods[] = {
|
||||
"__sleep",
|
||||
"__wakeup",
|
||||
"__set_state",
|
||||
|
@ -48,7 +48,7 @@ typedef struct stk_rec {
|
||||
} stk_rec;
|
||||
|
||||
/* The reference string for digits. */
|
||||
static char ref_str[] = "0123456789ABCDEF";
|
||||
static const char ref_str[] = "0123456789ABCDEF";
|
||||
|
||||
|
||||
/* A special output routine for "multi-character digits." Exactly
|
||||
|
@ -5538,7 +5538,7 @@ static const zend_ffi_type zend_ffi_type_long_double = {.kind=ZEND_FFI_TYPE_LONG
|
||||
|
||||
static const zend_ffi_type zend_ffi_type_ptr = {.kind=ZEND_FFI_TYPE_POINTER, .size=sizeof(void*), .align=_Alignof(void*), .pointer.type = (zend_ffi_type*)&zend_ffi_type_void};
|
||||
|
||||
const struct {
|
||||
static const struct {
|
||||
const char *name;
|
||||
const zend_ffi_type *type;
|
||||
} zend_ffi_types[] = {
|
||||
|
@ -1622,10 +1622,10 @@ static inline char *phar_strnstr(const char *buf, int buf_len, const char *searc
|
||||
*/
|
||||
static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char *alias, size_t alias_len, uint32_t options, phar_archive_data** pphar, int is_data, char **error) /* {{{ */
|
||||
{
|
||||
const char token[] = "__HALT_COMPILER();";
|
||||
const char zip_magic[] = "PK\x03\x04";
|
||||
const char gz_magic[] = "\x1f\x8b\x08";
|
||||
const char bz_magic[] = "BZh";
|
||||
static const char token[] = "__HALT_COMPILER();";
|
||||
static const char zip_magic[] = "PK\x03\x04";
|
||||
static const char gz_magic[] = "\x1f\x8b\x08";
|
||||
static const char bz_magic[] = "BZh";
|
||||
char *pos, test = '\0';
|
||||
int recursion_count = 3; // arbitrary limit to avoid too deep or even infinite recursion
|
||||
const int window_size = 1024;
|
||||
|
@ -1975,7 +1975,7 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /*
|
||||
char *ext_pos = NULL;
|
||||
/* Array of PHAR extensions, Must be in order, starting with longest
|
||||
* ending with the shortest. */
|
||||
char *phar_ext_list[] = {
|
||||
static const char *const phar_ext_list[] = {
|
||||
".phar.tar.bz2",
|
||||
".phar.tar.gz",
|
||||
".phar.php",
|
||||
|
@ -58,7 +58,7 @@ PHPAPI void php_syslog_str(int priority, const zend_string* message)
|
||||
} else if ((c < 0x20) && (PG(syslog_filter) == PHP_SYSLOG_FILTER_ALL)) {
|
||||
smart_string_appendc(&sbuf, c);
|
||||
} else {
|
||||
const char xdigits[] = "0123456789abcdef";
|
||||
static const char xdigits[] = "0123456789abcdef";
|
||||
|
||||
smart_string_appendl(&sbuf, "\\x", 2);
|
||||
smart_string_appendc(&sbuf, xdigits[c >> 4]);
|
||||
|
@ -208,7 +208,7 @@ typedef struct php_cli_server_http_response_status_code_pair {
|
||||
const char *str;
|
||||
} php_cli_server_http_response_status_code_pair;
|
||||
|
||||
static php_cli_server_http_response_status_code_pair template_map[] = {
|
||||
static const php_cli_server_http_response_status_code_pair template_map[] = {
|
||||
{ 400, "<h1>%s</h1><p>Your browser sent a request that this server could not understand.</p>" },
|
||||
{ 404, "<h1>%s</h1><p>The requested resource <code class=\"url\">%s</code> was not found on this server.</p>" },
|
||||
{ 405, "<h1>%s</h1><p>Requested method not allowed.</p>" },
|
||||
|
@ -84,7 +84,7 @@ static char *ini_include = NULL;
|
||||
/*
|
||||
* Please keep the same order as in fpm_conf.h and in php-fpm.conf.in
|
||||
*/
|
||||
static struct ini_value_parser_s ini_fpm_global_options[] = {
|
||||
static const struct ini_value_parser_s ini_fpm_global_options[] = {
|
||||
{ "pid", &fpm_conf_set_string, GO(pid_file) },
|
||||
{ "error_log", &fpm_conf_set_string, GO(error_log) },
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
@ -112,7 +112,7 @@ static struct ini_value_parser_s ini_fpm_global_options[] = {
|
||||
/*
|
||||
* Please keep the same order as in fpm_conf.h and in php-fpm.conf.in
|
||||
*/
|
||||
static struct ini_value_parser_s ini_fpm_pool_options[] = {
|
||||
static const struct ini_value_parser_s ini_fpm_pool_options[] = {
|
||||
{ "prefix", &fpm_conf_set_string, WPO(prefix) },
|
||||
{ "user", &fpm_conf_set_string, WPO(user) },
|
||||
{ "group", &fpm_conf_set_string, WPO(group) },
|
||||
@ -1183,11 +1183,10 @@ static int fpm_conf_process_all_pools(void)
|
||||
/* env[], php_value[], php_admin_values[] */
|
||||
if (!wp->config->chroot) {
|
||||
struct key_value_s *kv;
|
||||
char *options[] = FPM_PHP_INI_TO_EXPAND;
|
||||
char **p;
|
||||
static const char *const options[] = FPM_PHP_INI_TO_EXPAND;
|
||||
|
||||
for (kv = wp->config->php_values; kv; kv = kv->next) {
|
||||
for (p = options; *p; p++) {
|
||||
for (const char *const*p = options; *p; p++) {
|
||||
if (!strcasecmp(kv->key, *p)) {
|
||||
fpm_evaluate_full_path(&kv->value, wp, NULL, 0);
|
||||
}
|
||||
@ -1197,7 +1196,7 @@ static int fpm_conf_process_all_pools(void)
|
||||
if (!strcasecmp(kv->key, "error_log") && !strcasecmp(kv->value, "syslog")) {
|
||||
continue;
|
||||
}
|
||||
for (p = options; *p; p++) {
|
||||
for (const char *const*p = options; *p; p++) {
|
||||
if (!strcasecmp(kv->key, *p)) {
|
||||
fpm_evaluate_full_path(&kv->value, wp, NULL, 0);
|
||||
}
|
||||
@ -1464,7 +1463,7 @@ static void fpm_conf_ini_parser_section(zval *section, void *arg) /* {{{ */
|
||||
|
||||
static void fpm_conf_ini_parser_entry(zval *name, zval *value, void *arg) /* {{{ */
|
||||
{
|
||||
struct ini_value_parser_s *parser;
|
||||
const struct ini_value_parser_s *parser;
|
||||
void *config = NULL;
|
||||
|
||||
int *error = (int *)arg;
|
||||
|
@ -267,7 +267,7 @@ int fpm_signals_init_mask(void)
|
||||
/* Subset of signals from fpm_signals_init_main() and fpm_got_signal()
|
||||
blocked to avoid unexpected death during early init
|
||||
or during reload just after execvp() or fork */
|
||||
int init_signal_array[] = { SIGUSR1, SIGUSR2, SIGCHLD };
|
||||
static const int init_signal_array[] = { SIGUSR1, SIGUSR2, SIGCHLD };
|
||||
size_t size = sizeof(init_signal_array)/sizeof(init_signal_array[0]);
|
||||
size_t i = 0;
|
||||
if (0 > sigemptyset(&block_sigset) ||
|
||||
|
@ -963,7 +963,7 @@ static sapi_module_struct phpdbg_sapi_module = {
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
const opt_struct OPTIONS[] = { /* {{{ */
|
||||
static const opt_struct OPTIONS[] = { /* {{{ */
|
||||
{'c', 1, "ini path override"},
|
||||
{'d', 1, "define ini entry on command line"},
|
||||
{'n', 0, "no php.ini"},
|
||||
|
@ -38,9 +38,9 @@ const phpdbg_command_t phpdbg_help_commands[] = {
|
||||
}; /* }}} */
|
||||
|
||||
/* {{{ pretty_print. Formatting escapes and wrapping text in a string before printing it. */
|
||||
void pretty_print(char *text)
|
||||
static void pretty_print(const char *text)
|
||||
{
|
||||
char *new, *p, *q;
|
||||
char *new, *q;
|
||||
|
||||
const char *prompt_escape = phpdbg_get_prompt();
|
||||
size_t prompt_escape_len = strlen(prompt_escape);
|
||||
@ -60,6 +60,7 @@ void pretty_print(char *text)
|
||||
uint32_t line_count = 0; /* number printable chars on current line */
|
||||
|
||||
/* First pass calculates a safe size for the pretty print version */
|
||||
const char *p;
|
||||
for (p = text; *p; p++) {
|
||||
if (UNEXPECTED(p[0] == '*') && p[1] == '*') {
|
||||
size += bold_escape_len - 2;
|
||||
@ -143,9 +144,9 @@ void summary_print(phpdbg_command_t const * const cmd)
|
||||
}
|
||||
|
||||
/* {{{ get_help. Retries and formats text from the phpdbg help text table */
|
||||
static char *get_help(const char * const key)
|
||||
static const char *get_help(const char * const key)
|
||||
{
|
||||
phpdbg_help_text_t *p;
|
||||
const phpdbg_help_text_t *p;
|
||||
|
||||
/* Note that phpdbg_help_text is not assumed to be collated in key order. This is an
|
||||
inconvenience that means that help can't be logically grouped Not worth
|
||||
@ -201,8 +202,8 @@ static int get_command(
|
||||
|
||||
} /* }}} */
|
||||
|
||||
void phpdbg_do_help_cmd(char *type) { /* {{{ */
|
||||
char *help;
|
||||
void phpdbg_do_help_cmd(const char *type) { /* {{{ */
|
||||
const char *help;
|
||||
|
||||
if (!type) {
|
||||
pretty_print(get_help("overview!"));
|
||||
@ -329,7 +330,7 @@ PHPDBG_HELP(aliases) /* {{{ */
|
||||
* has a key ending in !
|
||||
*/
|
||||
#define CR "\n"
|
||||
phpdbg_help_text_t phpdbg_help_text[] = {
|
||||
const phpdbg_help_text_t phpdbg_help_text[] = {
|
||||
|
||||
/******************************** General Help Topics ********************************/
|
||||
{"overview!", CR
|
||||
|
@ -42,7 +42,7 @@ typedef struct _phpdbg_help_text_t {
|
||||
char *text;
|
||||
} phpdbg_help_text_t;
|
||||
|
||||
extern phpdbg_help_text_t phpdbg_help_text[];
|
||||
extern const phpdbg_help_text_t phpdbg_help_text[];
|
||||
|
||||
extern void phpdbg_do_help_cmd(char *type);
|
||||
extern void phpdbg_do_help_cmd(const char *type);
|
||||
#endif /* PHPDBG_HELP_H */
|
||||
|
Loading…
Reference in New Issue
Block a user