Skip to content

Make globals const #10303

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 8 commits into from
Jan 23, 2023
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
2 changes: 1 addition & 1 deletion Zend/zend_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static int zend_signal_register(int signo, void (*handler)(int, siginfo_t*, void
#define TIMEOUT_SIG SIGPROF
#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)

Expand Down
16 changes: 8 additions & 8 deletions ext/dba/dba.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ PHP_MSHUTDOWN_FUNCTION(dba);
PHP_MINFO_FUNCTION(dba);

ZEND_BEGIN_MODULE_GLOBALS(dba)
char *default_handler;
dba_handler *default_hptr;
const char *default_handler;
const dba_handler *default_hptr;
ZEND_END_MODULE_GLOBALS(dba)

ZEND_DECLARE_MODULE_GLOBALS(dba)
Expand Down Expand Up @@ -159,7 +159,7 @@ static zend_string* php_dba_make_key(HashTable *key)

/* {{{ globals */

static dba_handler handler[] = {
static const dba_handler handler[] = {
#ifdef DBA_GDBM
DBA_HND(gdbm, DBA_LOCK_EXT) /* Locking done in library if set */
#endif
Expand Down Expand Up @@ -249,7 +249,7 @@ PHPAPI void dba_fetch_resource(dba_info **pinfo, zval **id)
/* {{{ dba_get_handler
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++);
return hptr;
}
Expand Down Expand Up @@ -320,7 +320,7 @@ static void dba_close_pe_rsrc(zend_resource *rsrc)
/* {{{ PHP_INI */
ZEND_INI_MH(OnUpdateDefaultHandler)
{
dba_handler *hptr;
const dba_handler *hptr;

if (!ZSTR_LEN(new_value)) {
DBA_G(default_hptr) = NULL;
Expand Down Expand Up @@ -377,7 +377,7 @@ PHP_MSHUTDOWN_FUNCTION(dba)
/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(dba)
{
dba_handler *hptr;
const dba_handler *hptr;
smart_str handlers = {0};

for(hptr = handler; hptr->name; hptr++) {
Expand Down Expand Up @@ -461,7 +461,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
{
dba_mode_t modenr;
dba_info *info, *other;
dba_handler *hptr;
const dba_handler *hptr;
char *error = NULL;
int lock_mode, lock_flag = 0;
char *file_mode;
Expand Down Expand Up @@ -1165,7 +1165,7 @@ PHP_FUNCTION(dba_sync)
/* {{{ List configured database handlers */
PHP_FUNCTION(dba_handlers)
{
dba_handler *hptr;
const dba_handler *hptr;
bool full_info = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &full_info) == FAILURE) {
Expand Down
6 changes: 3 additions & 3 deletions ext/dba/php_dba.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef struct dba_info {
zend_long driver_flags;
/* private */
int flags; /* whether and how dba did locking and other flags*/
struct dba_handler *hnd;
const struct dba_handler *hnd;
dba_lock lock;
} dba_info;

Expand Down Expand Up @@ -85,7 +85,7 @@ typedef struct dba_handler {
zend_string* (*nextkey)(dba_info *);
zend_result (*optimize)(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_handler;

Expand All @@ -112,7 +112,7 @@ typedef struct dba_handler {
#define DBA_SYNC_FUNC(x) \
zend_result dba_sync_##x(dba_info *info)
#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) \
DBA_OPEN_FUNC(x); \
Expand Down
10 changes: 5 additions & 5 deletions ext/exif/exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ static size_t php_strnlen(char* str, size_t maxlen) {
/* }}} */

/* {{{ error messages */
static const char * EXIF_ERROR_FILEEOF = "Unexpected end of file reached";
static const char * EXIF_ERROR_CORRUPT = "File structure corrupted";
static const char * 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_FILEEOF = "Unexpected end of file reached";
static const char *const EXIF_ERROR_CORRUPT = "File structure corrupted";
static const char *const EXIF_ERROR_THUMBEOF = "Thumbnail goes IFD boundary or end of file reached";
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_CORRUPT(ImageInfo) exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "%s", EXIF_ERROR_CORRUPT);
Expand All @@ -244,7 +244,7 @@ static const char * EXIF_ERROR_FSREALLOC = "Illegal reallocating of undefined fi
/* {{{ format description defines
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 TAG_FMT_BYTE 1
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/grapheme/grapheme_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ grapheme_extract_count_iter(UBreakIterator *bi, int32_t size, unsigned char *pst
/* {{{ grapheme extract iter function pointer array */
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_bytecount_iter,
&grapheme_extract_charcount_iter,
Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/gen_rare_cp_bitvec.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* as less likely to be the correct one.
*/

static uint32_t rare_codepoint_bitvec[] = {
static const uint32_t rare_codepoint_bitvec[] = {
HEADER;

for ($i = 0; $i < 0xFFFF / 32; $i++) {
Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/rare_cp_bitvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* 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,
0x70ff0f0f, 0xfffcffff, 0x70fcfe61, 0x81fc3fcc, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/shared_alloc_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static size_t segment_type_size(void)
return sizeof(zend_shared_segment);
}

zend_shared_memory_handlers zend_alloc_mmap_handlers = {
const zend_shared_memory_handlers zend_alloc_mmap_handlers = {
create_segments,
detach_segment,
segment_type_size
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/shared_alloc_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static size_t segment_type_size(void)
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,
(detach_segment_t)detach_segment,
segment_type_size
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/shared_alloc_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static size_t segment_type_size(void)
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,
(detach_segment_t)detach_segment,
segment_type_size
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/shared_alloc_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ static size_t segment_type_size(void)
return sizeof(zend_shared_segment);
}

zend_shared_memory_handlers zend_alloc_win32_handlers = {
const zend_shared_memory_handlers zend_alloc_win32_handlers = {
create_segments,
detach_segment,
segment_type_size
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/zend_accelerator_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include "zend_shared_alloc.h"

/* 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 };
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)
{
Expand Down
10 changes: 5 additions & 5 deletions ext/opcache/zend_shared_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ typedef struct {

typedef struct _handler_entry {
const char *name;
zend_shared_memory_handlers *handler;
const zend_shared_memory_handlers *handler;
} zend_shared_memory_handler_entry;

typedef struct _zend_shared_memory_state {
Expand Down Expand Up @@ -197,19 +197,19 @@ const char *zend_accel_get_shared_model(void);
void zend_accel_shared_protect(int mode);

#ifdef USE_MMAP
extern zend_shared_memory_handlers zend_alloc_mmap_handlers;
extern const zend_shared_memory_handlers zend_alloc_mmap_handlers;
#endif

#ifdef USE_SHM
extern zend_shared_memory_handlers zend_alloc_shm_handlers;
extern const zend_shared_memory_handlers zend_alloc_shm_handlers;
#endif

#ifdef USE_SHM_OPEN
extern zend_shared_memory_handlers zend_alloc_posix_handlers;
extern const zend_shared_memory_handlers zend_alloc_posix_handlers;
#endif

#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_lock_win32(void);
void zend_shared_alloc_unlock_win32(void);
Expand Down
4 changes: 2 additions & 2 deletions ext/snmp/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ZEND_DECLARE_MODULE_GLOBALS(snmp)
static PHP_GINIT_FUNCTION(snmp);

/* 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 */
static zend_object_handlers php_snmp_object_handlers;
Expand Down Expand Up @@ -765,7 +765,7 @@ static bool php_snmp_parse_oid(
return false;
}
} 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);
}
} else {
Expand Down