Skip to content

Make lots of string pointers const #10646

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 7 commits into from
Feb 21, 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
4 changes: 2 additions & 2 deletions ext/curl/curl_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ PHP_FUNCTION(curl_file_create)
}
/* }}} */

static void curlfile_get_property(char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
static void curlfile_get_property(const char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
{
zval *res, rv;

Expand All @@ -74,7 +74,7 @@ static void curlfile_get_property(char *name, size_t name_len, INTERNAL_FUNCTION
RETURN_COPY_DEREF(res);
}

static void curlfile_set_property(char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
static void curlfile_set_property(const char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
{
zend_string *arg;

Expand Down
2 changes: 1 addition & 1 deletion ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
struct curl_slist *slist = NULL;

if (Z_TYPE_P(zvalue) != IS_ARRAY) {
char *name = NULL;
const char *name = NULL;
switch (option) {
case CURLOPT_HTTPHEADER:
name = "CURLOPT_HTTPHEADER";
Expand Down
13 changes: 6 additions & 7 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ PHPAPI time_t php_time(void)

#include "php_date_arginfo.h"

static char* guess_timezone(const timelib_tzdb *tzdb);
static const char* guess_timezone(const timelib_tzdb *tzdb);
static void date_register_classes(void);
/* }}} */

Expand Down Expand Up @@ -549,7 +549,7 @@ static PHP_INI_MH(OnUpdate_date_timezone)
/* }}} */

/* {{{ Helper functions */
static char* guess_timezone(const timelib_tzdb *tzdb)
static const char* guess_timezone(const timelib_tzdb *tzdb)
{
/* Checking whether timezone has been set with date_default_timezone_set() */
if (DATEG(timezone) && (strlen(DATEG(timezone))) > 0) {
Expand All @@ -573,10 +573,9 @@ static char* guess_timezone(const timelib_tzdb *tzdb)

PHPAPI timelib_tzinfo *get_timezone_info(void)
{
char *tz;
timelib_tzinfo *tzi;

tz = guess_timezone(DATE_TIMEZONEDB);
const char *tz = guess_timezone(DATE_TIMEZONEDB);
tzi = php_date_parse_tzfile(tz, DATE_TIMEZONEDB);
if (! tzi) {
zend_throw_error(date_ce_date_error, "Timezone database is corrupt. Please file a bug report as this should never happen");
Expand Down Expand Up @@ -607,7 +606,7 @@ static const char * const day_short_names[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};

static char *english_suffix(timelib_sll number)
static const char *english_suffix(timelib_sll number)
{
if (number >= 10 && number <= 19) {
return "th";
Expand Down Expand Up @@ -1667,7 +1666,7 @@ static const zend_object_iterator_funcs date_period_it_funcs = {
NULL, /* get_gc */
};

zend_object_iterator *date_object_period_get_iterator(zend_class_entry *ce, zval *object, int by_ref) /* {{{ */
static zend_object_iterator *date_object_period_get_iterator(zend_class_entry *ce, zval *object, int by_ref) /* {{{ */
{
date_period_it *iterator;

Expand Down Expand Up @@ -2043,7 +2042,7 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
}
}

void date_timezone_object_to_hash(php_timezone_obj *tzobj, HashTable *props)
static void date_timezone_object_to_hash(php_timezone_obj *tzobj, HashTable *props)
{
zval zv;

Expand Down
6 changes: 3 additions & 3 deletions ext/dba/dba.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
dba_mode_t modenr;
dba_info *info, *other;
const dba_handler *hptr;
char *error = NULL;
const char *error = NULL;
int lock_mode, lock_flag = 0;
char *file_mode;
char *lock_file_mode = NULL;
const char *file_mode;
const char *lock_file_mode = NULL;
int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0;
zend_string *opened_path = NULL;
char *lock_name;
Expand Down
2 changes: 1 addition & 1 deletion ext/dba/libcdb/cdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int cdb_find(struct cdb *c, char *key, unsigned int len)
/* }}} */

/* {{{ cdb_version */
char *cdb_version()
const char *cdb_version()
{
return "0.75, $Id$";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/dba/libcdb/cdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ int cdb_find(struct cdb *, char *, unsigned int);
#define cdb_datapos(c) ((c)->dpos)
#define cdb_datalen(c) ((c)->dlen)

char *cdb_version(void);
const char *cdb_version(void);

#endif
2 changes: 1 addition & 1 deletion ext/dba/libcdb/cdb_make.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ int cdb_make_finish(struct cdb_make *c)
/* }}} */

/* {{{ cdb_make_version */
char *cdb_make_version()
const char *cdb_make_version()
{
return "0.75, $Id$";
}
2 changes: 1 addition & 1 deletion ext/dba/libcdb/cdb_make.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ int cdb_make_addbegin(struct cdb_make *, unsigned int, unsigned int);
int cdb_make_addend(struct cdb_make *, unsigned int, unsigned int, uint32);
int cdb_make_add(struct cdb_make *, char *, unsigned int, char *, unsigned int);
int cdb_make_finish(struct cdb_make *);
char *cdb_make_version(void);
const char *cdb_make_version(void);

#endif
2 changes: 1 addition & 1 deletion ext/dba/libflatfile/flatfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ datum flatfile_nextkey(flatfile *dba) {
/* }}} */

/* {{{ flatfile_version */
char *flatfile_version()
const char *flatfile_version()
{
return "1.0, $Id$";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/dba/libflatfile/flatfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ int flatfile_delete(flatfile *dba, datum key_datum);
int flatfile_findkey(flatfile *dba, datum key_datum);
datum flatfile_firstkey(flatfile *dba);
datum flatfile_nextkey(flatfile *dba);
char *flatfile_version(void);
const char *flatfile_version(void);

#endif
2 changes: 1 addition & 1 deletion ext/dba/libinifile/inifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/

/* {{{ inifile_version */
char *inifile_version()
const char *inifile_version()
{
return "1.0, $Id$";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/dba/libinifile/inifile.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int inifile_delete_ex(inifile *dba, const key_type *key, bool *found);
int inifile_replace(inifile *dba, const key_type *key, const val_type *val);
int inifile_replace_ex(inifile *dba, const key_type *key, const val_type *val, bool *found);
int inifile_append(inifile *dba, const key_type *key, const val_type *val);
char *inifile_version(void);
const char *inifile_version(void);

key_type inifile_key_split(const char *group_name);
char * inifile_key_string(const key_type *key);
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 @@ -73,9 +73,9 @@ extern zend_module_entry dba_module_entry;
#define dba_module_ptr &dba_module_entry

typedef struct dba_handler {
char *name; /* handler name */
const char *name; /* handler name */
int flags; /* whether and how dba does locking and other flags*/
zend_result (*open)(dba_info *, char **error);
zend_result (*open)(dba_info *, const char **error);
void (*close)(dba_info *);
zend_string* (*fetch)(dba_info *, zend_string *, int);
zend_result (*update)(dba_info *, zend_string *, zend_string *, int);
Expand All @@ -92,7 +92,7 @@ typedef struct dba_handler {
/* common prototypes which must be supplied by modules */

#define DBA_OPEN_FUNC(x) \
zend_result dba_open_##x(dba_info *info, char **error)
zend_result dba_open_##x(dba_info *info, const char **error)
#define DBA_CLOSE_FUNC(x) \
void dba_close_##x(dba_info *info)
#define DBA_FETCH_FUNC(x) \
Expand Down
6 changes: 3 additions & 3 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ zend_accel_shared_globals *accel_shared_globals = NULL;
char accel_uname_id[32];
#endif
bool accel_startup_ok = false;
static char *zps_failure_reason = NULL;
char *zps_api_failure_reason = NULL;
static const char *zps_failure_reason = NULL;
const char *zps_api_failure_reason = NULL;
bool file_cache_only = false; /* process uses file cache only */
#if ENABLE_FILE_CACHE_FALLBACK
bool fallback_process = false; /* process uses file cache fallback */
Expand Down Expand Up @@ -2809,7 +2809,7 @@ static int accelerator_remove_cb(zend_extension *element1, zend_extension *eleme
return 0;
}

static void zps_startup_failure(char *reason, char *api_reason, int (*cb)(zend_extension *, zend_extension *))
static void zps_startup_failure(const char *reason, const char *api_reason, int (*cb)(zend_extension *, zend_extension *))
{
accel_startup_ok = false;
zps_failure_reason = reason;
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/ZendAccelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ ZEND_TSRMLS_CACHE_EXTERN()
extern zend_accel_globals accel_globals;
#endif

extern char *zps_api_failure_reason;
extern const char *zps_api_failure_reason;

BEGIN_EXTERN_C()

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 @@ -154,7 +154,7 @@ static void *find_prefered_mmap_base(size_t requested_size)
}
#endif

static int create_segments(size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, char **error_in)
static int create_segments(size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, const char **error_in)
{
zend_shared_segment *shared_segment;
int flags = PROT_READ | PROT_WRITE, fd = -1;
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 @@ -36,7 +36,7 @@ typedef struct {
int shm_fd;
} zend_shared_segment_posix;

static int create_segments(size_t requested_size, zend_shared_segment_posix ***shared_segments_p, int *shared_segments_count, char **error_in)
static int create_segments(size_t requested_size, zend_shared_segment_posix ***shared_segments_p, int *shared_segments_count, const char **error_in)
{
zend_shared_segment_posix *shared_segment;
char shared_segment_name[sizeof("/ZendAccelerator.") + 20];
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 @@ -50,7 +50,7 @@ typedef struct {
int shm_id;
} zend_shared_segment_shm;

static int create_segments(size_t requested_size, zend_shared_segment_shm ***shared_segments_p, int *shared_segments_count, char **error_in)
static int create_segments(size_t requested_size, zend_shared_segment_shm ***shared_segments_p, int *shared_segments_count, const char **error_in)
{
int i;
size_t allocate_size = 0, remaining_bytes = requested_size, seg_allocate_size;
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/shared_alloc_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void zend_shared_alloc_unlock_win32(void)
ReleaseMutex(memory_mutex);
}

static int zend_shared_alloc_reattach(size_t requested_size, char **error_in)
static int zend_shared_alloc_reattach(size_t requested_size, const char **error_in)
{
int err;
void *wanted_mapping_base;
Expand Down Expand Up @@ -199,7 +199,7 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in)
return SUCCESSFULLY_REATTACHED;
}

static int create_segments(size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, char **error_in)
static int create_segments(size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, const char **error_in)
{
int err = 0, ret;
zend_shared_segment *shared_segment;
Expand Down
8 changes: 4 additions & 4 deletions ext/opcache/zend_shared_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void zend_shared_alloc_create_lock(char *lockfile_path)
}
#endif

static void no_memory_bailout(size_t allocate_size, char *error)
static void no_memory_bailout(size_t allocate_size, const char *error)
{
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Unable to allocate shared memory segment of %zu bytes: %s: %s (%d)", allocate_size, error?error:"unknown", strerror(errno), errno );
}
Expand All @@ -117,7 +117,7 @@ static void copy_shared_segments(void *to, void *from, int count, int size)
}
}

static int zend_shared_alloc_try(const zend_shared_memory_handler_entry *he, size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, char **error_in)
static int zend_shared_alloc_try(const zend_shared_memory_handler_entry *he, size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, const char **error_in)
{
int res;
g_shared_alloc_handler = he->handler;
Expand Down Expand Up @@ -151,7 +151,7 @@ int zend_shared_alloc_startup(size_t requested_size, size_t reserved_size)
zend_shared_segment **tmp_shared_segments;
size_t shared_segments_array_size;
zend_smm_shared_globals tmp_shared_globals, *p_tmp_shared_globals;
char *error_in = NULL;
const char *error_in = NULL;
const zend_shared_memory_handler_entry *he;
int res = ALLOC_FAILURE;
int i;
Expand All @@ -169,7 +169,7 @@ int zend_shared_alloc_startup(size_t requested_size, size_t reserved_size)
#endif

if (ZCG(accel_directives).memory_model && ZCG(accel_directives).memory_model[0]) {
char *model = ZCG(accel_directives).memory_model;
const char *model = ZCG(accel_directives).memory_model;
/* "cgi" is really "shm"... */
if (strncmp(ZCG(accel_directives).memory_model, "cgi", sizeof("cgi")) == 0) {
model = "shm";
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/zend_shared_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ typedef struct _zend_shared_segment {
void *p;
} zend_shared_segment;

typedef int (*create_segments_t)(size_t requested_size, zend_shared_segment ***shared_segments, int *shared_segment_count, char **error_in);
typedef int (*create_segments_t)(size_t requested_size, zend_shared_segment ***shared_segments, int *shared_segment_count, const char **error_in);
typedef int (*detach_segment_t)(zend_shared_segment *shared_segment);

typedef struct {
Expand Down
4 changes: 2 additions & 2 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ PHP_METHOD(SQLite3, openBlob)
{
php_sqlite3_db_object *db_obj;
zval *object = ZEND_THIS;
char *table, *column, *dbname = "main", *mode = "rb";
const char *table, *column, *dbname = "main", *mode = "rb";
size_t table_len, column_len, dbname_len;
zend_long rowid, flags = SQLITE_OPEN_READONLY, sqlite_flags = 0;
sqlite3_blob *blob = NULL;
Expand Down Expand Up @@ -1338,7 +1338,7 @@ PHP_METHOD(SQLite3, backup)
{
php_sqlite3_db_object *source_obj;
php_sqlite3_db_object *destination_obj;
char *source_dbname = "main", *destination_dbname = "main";
const char *source_dbname = "main", *destination_dbname = "main";
size_t source_dbname_length, destination_dbname_length;
zval *source_zval = ZEND_THIS;
zval *destination_zval;
Expand Down