Mark globals as const (#10303)

This moves them from ``.data`` to ``.rodata`` and allows more compiler optimizations.

* ext/opcache/zend_accelerator_hash: make prime_numbers const

* Zend/zend_signal: make zend_sigs const

* ext/dba: make dba_handler pointers const

* ext/exif: make php_tiff_bytes_per_format and other globals const

* ext/intl/grapheme: make grapheme_extract_iters const

* ext/mstring: make rare_codepoint_bitvec const

* ext/snmp: make objid_mib const

* ext/opcache: make all zend_shared_memory_handlers const
This commit is contained in:
Max Kellermann 2023-01-23 14:46:58 +01:00 committed by GitHub
parent d9c2cf7e3d
commit d3facbe283
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 33 additions and 33 deletions

View file

@ -71,7 +71,7 @@ static int zend_signal_register(int signo, void (*handler)(int, siginfo_t*, void
#define TIMEOUT_SIG SIGPROF #define TIMEOUT_SIG SIGPROF
#endif #endif
static int zend_sigs[] = { TIMEOUT_SIG, SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2 }; static const int zend_sigs[] = { TIMEOUT_SIG, SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2 };
#define SA_FLAGS_MASK ~(SA_NODEFER | SA_RESETHAND) #define SA_FLAGS_MASK ~(SA_NODEFER | SA_RESETHAND)

View file

@ -55,8 +55,8 @@ PHP_MSHUTDOWN_FUNCTION(dba);
PHP_MINFO_FUNCTION(dba); PHP_MINFO_FUNCTION(dba);
ZEND_BEGIN_MODULE_GLOBALS(dba) ZEND_BEGIN_MODULE_GLOBALS(dba)
char *default_handler; const char *default_handler;
dba_handler *default_hptr; const dba_handler *default_hptr;
ZEND_END_MODULE_GLOBALS(dba) ZEND_END_MODULE_GLOBALS(dba)
ZEND_DECLARE_MODULE_GLOBALS(dba) ZEND_DECLARE_MODULE_GLOBALS(dba)
@ -159,7 +159,7 @@ static zend_string* php_dba_make_key(HashTable *key)
/* {{{ globals */ /* {{{ globals */
static dba_handler handler[] = { static const dba_handler handler[] = {
#ifdef DBA_GDBM #ifdef DBA_GDBM
DBA_HND(gdbm, DBA_LOCK_EXT) /* Locking done in library if set */ DBA_HND(gdbm, DBA_LOCK_EXT) /* Locking done in library if set */
#endif #endif
@ -249,7 +249,7 @@ PHPAPI void dba_fetch_resource(dba_info **pinfo, zval **id)
/* {{{ dba_get_handler /* {{{ dba_get_handler
PHPAPI dba_handler *dba_get_handler(const char* handler_name) PHPAPI dba_handler *dba_get_handler(const char* handler_name)
{ {
dba_handler *hptr; const dba_handler *hptr;
for (hptr = handler; hptr->name && strcasecmp(hptr->name, handler_name); hptr++); for (hptr = handler; hptr->name && strcasecmp(hptr->name, handler_name); hptr++);
return hptr; return hptr;
} }
@ -320,7 +320,7 @@ static void dba_close_pe_rsrc(zend_resource *rsrc)
/* {{{ PHP_INI */ /* {{{ PHP_INI */
ZEND_INI_MH(OnUpdateDefaultHandler) ZEND_INI_MH(OnUpdateDefaultHandler)
{ {
dba_handler *hptr; const dba_handler *hptr;
if (!ZSTR_LEN(new_value)) { if (!ZSTR_LEN(new_value)) {
DBA_G(default_hptr) = NULL; DBA_G(default_hptr) = NULL;
@ -377,7 +377,7 @@ PHP_MSHUTDOWN_FUNCTION(dba)
/* {{{ PHP_MINFO_FUNCTION */ /* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(dba) PHP_MINFO_FUNCTION(dba)
{ {
dba_handler *hptr; const dba_handler *hptr;
smart_str handlers = {0}; smart_str handlers = {0};
for(hptr = handler; hptr->name; hptr++) { for(hptr = handler; hptr->name; hptr++) {
@ -461,7 +461,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
{ {
dba_mode_t modenr; dba_mode_t modenr;
dba_info *info, *other; dba_info *info, *other;
dba_handler *hptr; const dba_handler *hptr;
char *error = NULL; char *error = NULL;
int lock_mode, lock_flag = 0; int lock_mode, lock_flag = 0;
char *file_mode; char *file_mode;
@ -1165,7 +1165,7 @@ PHP_FUNCTION(dba_sync)
/* {{{ List configured database handlers */ /* {{{ List configured database handlers */
PHP_FUNCTION(dba_handlers) PHP_FUNCTION(dba_handlers)
{ {
dba_handler *hptr; const dba_handler *hptr;
bool full_info = 0; bool full_info = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &full_info) == FAILURE) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &full_info) == FAILURE) {

View file

@ -48,7 +48,7 @@ typedef struct dba_info {
zend_long driver_flags; zend_long driver_flags;
/* private */ /* private */
int flags; /* whether and how dba did locking and other flags*/ int flags; /* whether and how dba did locking and other flags*/
struct dba_handler *hnd; const struct dba_handler *hnd;
dba_lock lock; dba_lock lock;
} dba_info; } dba_info;
@ -85,7 +85,7 @@ typedef struct dba_handler {
zend_string* (*nextkey)(dba_info *); zend_string* (*nextkey)(dba_info *);
zend_result (*optimize)(dba_info *); zend_result (*optimize)(dba_info *);
zend_result (*sync)(dba_info *); zend_result (*sync)(dba_info *);
char* (*info)(struct dba_handler *hnd, dba_info *); char* (*info)(const struct dba_handler *hnd, dba_info *);
/* dba_info==NULL: Handler info, dba_info!=NULL: Database info */ /* dba_info==NULL: Handler info, dba_info!=NULL: Database info */
} dba_handler; } dba_handler;
@ -112,7 +112,7 @@ typedef struct dba_handler {
#define DBA_SYNC_FUNC(x) \ #define DBA_SYNC_FUNC(x) \
zend_result dba_sync_##x(dba_info *info) zend_result dba_sync_##x(dba_info *info)
#define DBA_INFO_FUNC(x) \ #define DBA_INFO_FUNC(x) \
char *dba_info_##x(dba_handler *hnd, dba_info *info) char *dba_info_##x(const dba_handler *hnd, dba_info *info)
#define DBA_FUNCS(x) \ #define DBA_FUNCS(x) \
DBA_OPEN_FUNC(x); \ DBA_OPEN_FUNC(x); \

View file

@ -230,10 +230,10 @@ static size_t php_strnlen(char* str, size_t maxlen) {
/* }}} */ /* }}} */
/* {{{ error messages */ /* {{{ error messages */
static const char * EXIF_ERROR_FILEEOF = "Unexpected end of file reached"; static const char *const EXIF_ERROR_FILEEOF = "Unexpected end of file reached";
static const char * EXIF_ERROR_CORRUPT = "File structure corrupted"; static const char *const EXIF_ERROR_CORRUPT = "File structure corrupted";
static const char * EXIF_ERROR_THUMBEOF = "Thumbnail goes IFD boundary or end of file reached"; static const char *const EXIF_ERROR_THUMBEOF = "Thumbnail goes IFD boundary or end of file reached";
static const char * EXIF_ERROR_FSREALLOC = "Illegal reallocating of undefined file section"; static const char *const EXIF_ERROR_FSREALLOC = "Illegal reallocating of undefined file section";
#define EXIF_ERRLOG_FILEEOF(ImageInfo) exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "%s", EXIF_ERROR_FILEEOF); #define EXIF_ERRLOG_FILEEOF(ImageInfo) exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "%s", EXIF_ERROR_FILEEOF);
#define EXIF_ERRLOG_CORRUPT(ImageInfo) exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "%s", EXIF_ERROR_CORRUPT); #define EXIF_ERRLOG_CORRUPT(ImageInfo) exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "%s", EXIF_ERROR_CORRUPT);
@ -244,7 +244,7 @@ static const char * EXIF_ERROR_FSREALLOC = "Illegal reallocating of undefined fi
/* {{{ format description defines /* {{{ format description defines
Describes format descriptor Describes format descriptor
*/ */
static int php_tiff_bytes_per_format[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 1}; static const int php_tiff_bytes_per_format[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 1};
#define NUM_FORMATS 13 #define NUM_FORMATS 13
#define TAG_FMT_BYTE 1 #define TAG_FMT_BYTE 1

View file

@ -679,7 +679,7 @@ grapheme_extract_count_iter(UBreakIterator *bi, int32_t size, unsigned char *pst
/* {{{ grapheme extract iter function pointer array */ /* {{{ grapheme extract iter function pointer array */
typedef int32_t (*grapheme_extract_iter)(UBreakIterator * /*bi*/, int32_t /*size*/, unsigned char * /*pstr*/, int32_t /*str_len*/); typedef int32_t (*grapheme_extract_iter)(UBreakIterator * /*bi*/, int32_t /*size*/, unsigned char * /*pstr*/, int32_t /*str_len*/);
static grapheme_extract_iter grapheme_extract_iters[] = { static const grapheme_extract_iter grapheme_extract_iters[] = {
&grapheme_extract_count_iter, &grapheme_extract_count_iter,
&grapheme_extract_bytecount_iter, &grapheme_extract_bytecount_iter,
&grapheme_extract_charcount_iter, &grapheme_extract_charcount_iter,

View file

@ -40,7 +40,7 @@ $result = <<<'HEADER'
* as less likely to be the correct one. * as less likely to be the correct one.
*/ */
static uint32_t rare_codepoint_bitvec[] = { static const uint32_t rare_codepoint_bitvec[] = {
HEADER; HEADER;
for ($i = 0; $i < 0xFFFF / 32; $i++) { for ($i = 0; $i < 0xFFFF / 32; $i++) {

View file

@ -9,7 +9,7 @@
* as less likely to be the correct one. * as less likely to be the correct one.
*/ */
static uint32_t rare_codepoint_bitvec[] = { static const uint32_t rare_codepoint_bitvec[] = {
0xffffd9ff, 0x00000000, 0x00000000, 0x80000000, 0xffffffff, 0x00002001, 0x00000000, 0x00000000, 0xffffd9ff, 0x00000000, 0x00000000, 0x80000000, 0xffffffff, 0x00002001, 0x00000000, 0x00000000,
0x70ff0f0f, 0xfffcffff, 0x70fcfe61, 0x81fc3fcc, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x70ff0f0f, 0xfffcffff, 0x70fcfe61, 0x81fc3fcc, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,

View file

@ -276,7 +276,7 @@ static size_t segment_type_size(void)
return sizeof(zend_shared_segment); return sizeof(zend_shared_segment);
} }
zend_shared_memory_handlers zend_alloc_mmap_handlers = { const zend_shared_memory_handlers zend_alloc_mmap_handlers = {
create_segments, create_segments,
detach_segment, detach_segment,
segment_type_size segment_type_size

View file

@ -89,7 +89,7 @@ static size_t segment_type_size(void)
return sizeof(zend_shared_segment_posix); return sizeof(zend_shared_segment_posix);
} }
zend_shared_memory_handlers zend_alloc_posix_handlers = { const zend_shared_memory_handlers zend_alloc_posix_handlers = {
(create_segments_t)create_segments, (create_segments_t)create_segments,
(detach_segment_t)detach_segment, (detach_segment_t)detach_segment,
segment_type_size segment_type_size

View file

@ -135,7 +135,7 @@ static size_t segment_type_size(void)
return sizeof(zend_shared_segment_shm); return sizeof(zend_shared_segment_shm);
} }
zend_shared_memory_handlers zend_alloc_shm_handlers = { const zend_shared_memory_handlers zend_alloc_shm_handlers = {
(create_segments_t)create_segments, (create_segments_t)create_segments,
(detach_segment_t)detach_segment, (detach_segment_t)detach_segment,
segment_type_size segment_type_size

View file

@ -352,7 +352,7 @@ static size_t segment_type_size(void)
return sizeof(zend_shared_segment); return sizeof(zend_shared_segment);
} }
zend_shared_memory_handlers zend_alloc_win32_handlers = { const zend_shared_memory_handlers zend_alloc_win32_handlers = {
create_segments, create_segments,
detach_segment, detach_segment,
segment_type_size segment_type_size

View file

@ -25,9 +25,9 @@
#include "zend_shared_alloc.h" #include "zend_shared_alloc.h"
/* Generated on an Octa-ALPHA 300MHz CPU & 2.5GB RAM monster */ /* Generated on an Octa-ALPHA 300MHz CPU & 2.5GB RAM monster */
static uint32_t prime_numbers[] = static const uint32_t prime_numbers[] =
{5, 11, 19, 53, 107, 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987, 262237, 524521, 1048793 }; {5, 11, 19, 53, 107, 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987, 262237, 524521, 1048793 };
static uint32_t num_prime_numbers = sizeof(prime_numbers) / sizeof(uint32_t); static const uint32_t num_prime_numbers = sizeof(prime_numbers) / sizeof(uint32_t);
void zend_accel_hash_clean(zend_accel_hash *accel_hash) void zend_accel_hash_clean(zend_accel_hash *accel_hash)
{ {

View file

@ -91,7 +91,7 @@ typedef struct {
typedef struct _handler_entry { typedef struct _handler_entry {
const char *name; const char *name;
zend_shared_memory_handlers *handler; const zend_shared_memory_handlers *handler;
} zend_shared_memory_handler_entry; } zend_shared_memory_handler_entry;
typedef struct _zend_shared_memory_state { typedef struct _zend_shared_memory_state {
@ -197,19 +197,19 @@ const char *zend_accel_get_shared_model(void);
void zend_accel_shared_protect(int mode); void zend_accel_shared_protect(int mode);
#ifdef USE_MMAP #ifdef USE_MMAP
extern zend_shared_memory_handlers zend_alloc_mmap_handlers; extern const zend_shared_memory_handlers zend_alloc_mmap_handlers;
#endif #endif
#ifdef USE_SHM #ifdef USE_SHM
extern zend_shared_memory_handlers zend_alloc_shm_handlers; extern const zend_shared_memory_handlers zend_alloc_shm_handlers;
#endif #endif
#ifdef USE_SHM_OPEN #ifdef USE_SHM_OPEN
extern zend_shared_memory_handlers zend_alloc_posix_handlers; extern const zend_shared_memory_handlers zend_alloc_posix_handlers;
#endif #endif
#ifdef ZEND_WIN32 #ifdef ZEND_WIN32
extern zend_shared_memory_handlers zend_alloc_win32_handlers; extern const zend_shared_memory_handlers zend_alloc_win32_handlers;
void zend_shared_alloc_create_lock(void); void zend_shared_alloc_create_lock(void);
void zend_shared_alloc_lock_win32(void); void zend_shared_alloc_lock_win32(void);
void zend_shared_alloc_unlock_win32(void); void zend_shared_alloc_unlock_win32(void);

View file

@ -91,7 +91,7 @@ ZEND_DECLARE_MODULE_GLOBALS(snmp)
static PHP_GINIT_FUNCTION(snmp); static PHP_GINIT_FUNCTION(snmp);
/* constant - can be shared among threads */ /* constant - can be shared among threads */
static oid objid_mib[] = {1, 3, 6, 1, 2, 1}; static const oid objid_mib[] = {1, 3, 6, 1, 2, 1};
/* Handlers */ /* Handlers */
static zend_object_handlers php_snmp_object_handlers; static zend_object_handlers php_snmp_object_handlers;
@ -765,7 +765,7 @@ static bool php_snmp_parse_oid(
return false; return false;
} }
} else { } else {
memmove((char *)objid_query->vars[0].name, (char *)objid_mib, sizeof(objid_mib)); memmove((char *)objid_query->vars[0].name, (const char *)objid_mib, sizeof(objid_mib));
objid_query->vars[0].name_length = sizeof(objid_mib) / sizeof(oid); objid_query->vars[0].name_length = sizeof(objid_mib) / sizeof(oid);
} }
} else { } else {