Make lots of string pointers const (#10646)

This allows using string literals without implicitly casting away the
`const`.
This commit is contained in:
Max Kellermann 2023-02-21 15:01:37 +01:00 committed by GitHub
parent 373809c51b
commit 263b22f374
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 39 additions and 40 deletions

View file

@ -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;
@ -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;

View file

@ -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";

View file

@ -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);
/* }}} */
@ -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) {
@ -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");
@ -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";
@ -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;
@ -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;

View file

@ -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;

View file

@ -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$";
}

View file

@ -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

View file

@ -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$";
}

View file

@ -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

View file

@ -276,7 +276,7 @@ datum flatfile_nextkey(flatfile *dba) {
/* }}} */
/* {{{ flatfile_version */
char *flatfile_version()
const char *flatfile_version()
{
return "1.0, $Id$";
}

View file

@ -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

View file

@ -38,7 +38,7 @@
*/
/* {{{ inifile_version */
char *inifile_version()
const char *inifile_version()
{
return "1.0, $Id$";
}

View file

@ -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);

View file

@ -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);
@ -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) \

View file

@ -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 */
@ -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;

View file

@ -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()

View file

@ -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;

View file

@ -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];

View file

@ -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;

View file

@ -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;
@ -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;

View file

@ -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 );
}
@ -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;
@ -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;
@ -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";

View file

@ -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 {

View file

@ -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;
@ -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;