Skip to content

Commit

Permalink
Make globals const (part 2) (#10610)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MaxKellermann committed Feb 18, 2023
1 parent c0d89e5 commit d46dea1
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Zend/zend_enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ext/bcmath/libbcmath/src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
8 changes: 4 additions & 4 deletions ext/phar/phar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion main/php_syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>" },
Expand Down
13 changes: 6 additions & 7 deletions sapi/fpm/fpm/fpm_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) },
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sapi/fpm/fpm/fpm_signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
2 changes: 1 addition & 1 deletion sapi/phpdbg/phpdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
15 changes: 8 additions & 7 deletions sapi/phpdbg/phpdbg_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!"));
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sapi/phpdbg/phpdbg_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit d46dea1

Please sign in to comment.