Skip to content

Commit 91615eb

Browse files
committed
Constify char* arguments of APIs
1 parent eae3bda commit 91615eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+167
-154
lines changed

TSRM/TSRM.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ TSRM_TLS uint8_t in_main_thread = 0;
116116
TSRM_TLS uint8_t is_thread_shutdown = 0;
117117

118118
/* Startup TSRM (call once for the entire process) */
119-
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename)
119+
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, const char *debug_filename)
120120
{/*{{{*/
121121
#ifdef TSRM_WIN32
122122
tls_key = TlsAlloc();
@@ -698,7 +698,7 @@ int tsrm_error(int level, const char *format, ...)
698698
#endif
699699

700700

701-
void tsrm_error_set(int level, char *debug_filename)
701+
void tsrm_error_set(int level, const char *debug_filename)
702702
{/*{{{*/
703703
tsrm_error_level = level;
704704

TSRM/TSRM.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ extern "C" {
7979
#endif
8080

8181
/* startup/shutdown */
82-
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename);
82+
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, const char *debug_filename);
8383
TSRM_API void tsrm_shutdown(void);
8484

8585
/* environ lock API */
@@ -115,7 +115,7 @@ typedef void (*tsrm_shutdown_func_t)(void);
115115

116116

117117
TSRM_API int tsrm_error(int level, const char *format, ...);
118-
TSRM_API void tsrm_error_set(int level, char *debug_filename);
118+
TSRM_API void tsrm_error_set(int level, const char *debug_filename);
119119

120120
/* utility functions */
121121
TSRM_API THREAD_T tsrm_thread_id(void);

TSRM/tsrm_win32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ TSRM_API FILE *popen(const char *command, const char *type)
443443
return popen_ex(command, type, NULL, NULL);
444444
}/*}}}*/
445445

446-
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env)
446+
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, const char *env)
447447
{/*{{{*/
448448
FILE *stream = NULL;
449449
int fno, type_len, read, mode;

TSRM/tsrm_win32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const char * tsrm_win32_get_path_sid_key(const char *pathname, size_t pathname_l
9494
TSRM_API void tsrm_win32_startup(void);
9595
TSRM_API void tsrm_win32_shutdown(void);
9696

97-
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env);
97+
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, const char *env);
9898
TSRM_API FILE *popen(const char *command, const char *type);
9999
TSRM_API int pclose(FILE *stream);
100100
TSRM_API int tsrm_win32_access(const char *pathname, int mode);

Zend/zend_API.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,7 +2716,7 @@ ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_lengt
27162716

27172717
/* Disabled functions support */
27182718

2719-
ZEND_API int zend_disable_function(char *function_name, size_t function_name_length) /* {{{ */
2719+
ZEND_API int zend_disable_function(const char *function_name, size_t function_name_length) /* {{{ */
27202720
{
27212721
return zend_hash_str_del(CG(function_table), function_name, function_name_length);
27222722
}
@@ -2753,7 +2753,7 @@ static const zend_function_entry disabled_class_new[] = {
27532753
ZEND_FE_END
27542754
};
27552755

2756-
ZEND_API int zend_disable_class(char *class_name, size_t class_name_length) /* {{{ */
2756+
ZEND_API int zend_disable_class(const char *class_name, size_t class_name_length) /* {{{ */
27572757
{
27582758
zend_class_entry *disabled_class;
27592759
zend_string *key;

Zend/zend_API.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zen
334334
#define zend_register_ns_class_alias(ns, name, ce) \
335335
zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce, 1)
336336

337-
ZEND_API int zend_disable_function(char *function_name, size_t function_name_length);
338-
ZEND_API int zend_disable_class(char *class_name, size_t class_name_length);
337+
ZEND_API int zend_disable_function(const char *function_name, size_t function_name_length);
338+
ZEND_API int zend_disable_class(const char *class_name, size_t class_name_length);
339339

340340
ZEND_API ZEND_COLD void zend_wrong_param_count(void);
341341

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ void zend_do_extended_fcall_end(void) /* {{{ */
17201720
}
17211721
/* }}} */
17221722

1723-
zend_bool zend_is_auto_global_str(char *name, size_t len) /* {{{ */ {
1723+
zend_bool zend_is_auto_global_str(const char *name, size_t len) /* {{{ */ {
17241724
zend_auto_global *auto_global;
17251725

17261726
if ((auto_global = zend_hash_str_find_ptr(CG(auto_globals), name, len)) != NULL) {

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ typedef struct _zend_auto_global {
844844
ZEND_API int zend_register_auto_global(zend_string *name, zend_bool jit, zend_auto_global_callback auto_global_callback);
845845
ZEND_API void zend_activate_auto_globals(void);
846846
ZEND_API zend_bool zend_is_auto_global(zend_string *name);
847-
ZEND_API zend_bool zend_is_auto_global_str(char *name, size_t len);
847+
ZEND_API zend_bool zend_is_auto_global_str(const char *name, size_t len);
848848
ZEND_API size_t zend_dirname(char *path, size_t len);
849849
ZEND_API void zend_set_function_arg_flags(zend_function *func);
850850

ext/date/php_date.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ static const char *php_date_short_day_name(timelib_sll y, timelib_sll m, timelib
617617
/* }}} */
618618

619619
/* {{{ date_format - (gm)date helper */
620-
static zend_string *date_format(char *format, size_t format_len, timelib_time *t, int localtime)
620+
static zend_string *date_format(const char *format, size_t format_len, timelib_time *t, int localtime)
621621
{
622622
smart_str string = {0};
623623
size_t i;
@@ -798,7 +798,7 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime)
798798
}
799799
/* }}} */
800800

801-
PHPAPI zend_string *php_format_date(char *format, size_t format_len, time_t ts, int localtime) /* {{{ */
801+
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, int localtime) /* {{{ */
802802
{
803803
timelib_time *t;
804804
timelib_tzinfo *tzi;
@@ -982,14 +982,14 @@ PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb)
982982
/* }}} */
983983

984984
/* {{{ php_parse_date: Backwards compatibility function */
985-
PHPAPI zend_long php_parse_date(char *string, zend_long *now)
985+
PHPAPI zend_long php_parse_date(const char *string, zend_long *now)
986986
{
987987
timelib_time *parsed_time;
988988
timelib_error_container *error = NULL;
989989
int error2;
990990
zend_long retval;
991991

992-
parsed_time = timelib_strtotime(string, strlen(string), &error, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
992+
parsed_time = timelib_strtotime((char *) string, strlen(string), &error, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
993993
if (error->error_count) {
994994
timelib_time_dtor(parsed_time);
995995
timelib_error_container_dtor(error);
@@ -2187,7 +2187,7 @@ static void php_date_get_current_time_with_fraction(time_t *sec, suseconds_t *us
21872187
#endif
21882188
}
21892189

2190-
PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, size_t time_str_len, char *format, zval *timezone_object, int ctor) /* {{{ */
2190+
PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size_t time_str_len, char *format, zval *timezone_object, int ctor) /* {{{ */
21912191
{
21922192
timelib_time *now;
21932193
timelib_tzinfo *tzi = NULL;
@@ -2202,9 +2202,16 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str,
22022202
timelib_time_dtor(dateobj->time);
22032203
}
22042204
if (format) {
2205-
dateobj->time = timelib_parse_from_format(format, time_str_len ? time_str : "", time_str_len ? time_str_len : 0, &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
2205+
if (time_str_len == 0) {
2206+
time_str = "";
2207+
}
2208+
dateobj->time = timelib_parse_from_format(format, (char *) time_str, time_str_len, &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
22062209
} else {
2207-
dateobj->time = timelib_strtotime(time_str_len ? time_str : "now", time_str_len ? time_str_len : sizeof("now") -1, &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
2210+
if (time_str_len == 0) {
2211+
time_str = "now";
2212+
time_str_len = sizeof("now") - 1;
2213+
}
2214+
dateobj->time = timelib_strtotime((char *) time_str, time_str_len, &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
22082215
}
22092216

22102217
/* update last errors and warnings */
@@ -2213,7 +2220,7 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str,
22132220

22142221
if (ctor && err && err->error_count) {
22152222
/* spit out the first library error message, at least */
2216-
php_error_docref(NULL, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", time_str,
2223+
php_error_docref(NULL, E_WARNING, "Failed to parse time string (%.*s) at position %d (%c): %s", (int) time_str_len, time_str,
22172224
err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message);
22182225
}
22192226
if (err && err->error_count) {

ext/date/php_date.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ ZEND_END_MODULE_GLOBALS(date)
108108
PHPAPI time_t php_time();
109109

110110
/* Backwards compatibility wrapper */
111-
PHPAPI zend_long php_parse_date(char *string, zend_long *now);
111+
PHPAPI zend_long php_parse_date(const char *string, zend_long *now);
112112
PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt);
113113
PHPAPI int php_idate(char format, time_t ts, int localtime);
114114

115115
#define _php_strftime php_strftime
116116

117117
PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm);
118-
PHPAPI zend_string *php_format_date(char *format, size_t format_len, time_t ts, int localtime);
118+
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, int localtime);
119119

120120
/* Mechanism to set new TZ database */
121121
PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);
@@ -131,7 +131,7 @@ PHPAPI zend_class_entry *php_date_get_period_ce(void);
131131

132132
/* Functions for creating DateTime objects, and initializing them from a string */
133133
PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object);
134-
PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, size_t time_str_len, char *format, zval *timezone_object, int ctor);
134+
PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size_t time_str_len, char *format, zval *timezone_object, int ctor);
135135

136136

137137
#endif /* PHP_DATE_H */

ext/session/php_session.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ PHPAPI zend_string *php_session_create_id(PS_CREATE_SID_ARGS);
247247
PHPAPI int php_session_validate_sid(PS_VALIDATE_SID_ARGS);
248248
PHPAPI int php_session_update_timestamp(PS_UPDATE_TIMESTAMP_ARGS);
249249

250-
PHPAPI void session_adapt_url(const char *, size_t, char **, size_t *);
250+
PHPAPI void session_adapt_url(const char *url, size_t urllen, char **new, size_t *newlen);
251251

252252
PHPAPI int php_session_destroy(void);
253253
PHPAPI void php_add_session_var(zend_string *name);
@@ -260,12 +260,11 @@ PHPAPI int php_session_register_serializer(const char *name,
260260
zend_string *(*encode)(PS_SERIALIZER_ENCODE_ARGS),
261261
int (*decode)(PS_SERIALIZER_DECODE_ARGS));
262262

263-
PHPAPI void php_session_set_id(char *id);
264263
PHPAPI int php_session_start(void);
265264
PHPAPI int php_session_flush(int write);
266265

267-
PHPAPI const ps_module *_php_find_ps_module(char *name);
268-
PHPAPI const ps_serializer *_php_find_ps_serializer(char *name);
266+
PHPAPI const ps_module *_php_find_ps_module(const char *name);
267+
PHPAPI const ps_serializer *_php_find_ps_serializer(const char *name);
269268

270269
PHPAPI int php_session_valid_key(const char *key);
271270
PHPAPI int php_session_reset_id(void);

ext/session/session.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ static int php_session_send_cookie(void) /* {{{ */
13741374
}
13751375
/* }}} */
13761376

1377-
PHPAPI const ps_module *_php_find_ps_module(char *name) /* {{{ */
1377+
PHPAPI const ps_module *_php_find_ps_module(const char *name) /* {{{ */
13781378
{
13791379
const ps_module *ret = NULL;
13801380
const ps_module **mod;
@@ -1390,7 +1390,7 @@ PHPAPI const ps_module *_php_find_ps_module(char *name) /* {{{ */
13901390
}
13911391
/* }}} */
13921392

1393-
PHPAPI const ps_serializer *_php_find_ps_serializer(char *name) /* {{{ */
1393+
PHPAPI const ps_serializer *_php_find_ps_serializer(const char *name) /* {{{ */
13941394
{
13951395
const ps_serializer *ret = NULL;
13961396
const ps_serializer *mod;

ext/standard/basic_functions.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,13 +1472,13 @@ PHP_FUNCTION(error_log)
14721472
/* }}} */
14731473

14741474
/* For BC (not binary-safe!) */
1475-
PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers) /* {{{ */
1475+
PHPAPI int _php_error_log(int opt_err, const char *message, const char *opt, const char *headers) /* {{{ */
14761476
{
14771477
return _php_error_log_ex(opt_err, message, (opt_err == 3) ? strlen(message) : 0, opt, headers);
14781478
}
14791479
/* }}} */
14801480

1481-
PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, char *opt, char *headers) /* {{{ */
1481+
PHPAPI int _php_error_log_ex(int opt_err, const char *message, size_t message_len, const char *opt, const char *headers) /* {{{ */
14821482
{
14831483
php_stream *stream = NULL;
14841484
size_t nbytes;
@@ -1510,7 +1510,7 @@ PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, cha
15101510

15111511
case 4: /* send to SAPI */
15121512
if (sapi_module.log_message) {
1513-
sapi_module.log_message(message, -1);
1513+
sapi_module.log_message((char *) message, -1);
15141514
} else {
15151515
return FAILURE;
15161516
}
@@ -1870,7 +1870,7 @@ PHP_FUNCTION(register_shutdown_function)
18701870
}
18711871
/* }}} */
18721872

1873-
PHPAPI zend_bool register_user_shutdown_function(char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry) /* {{{ */
1873+
PHPAPI zend_bool register_user_shutdown_function(const char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry) /* {{{ */
18741874
{
18751875
if (!BG(user_shutdown_function_names)) {
18761876
ALLOC_HASHTABLE(BG(user_shutdown_function_names));
@@ -1882,7 +1882,7 @@ PHPAPI zend_bool register_user_shutdown_function(char *function_name, size_t fun
18821882
}
18831883
/* }}} */
18841884

1885-
PHPAPI zend_bool remove_user_shutdown_function(char *function_name, size_t function_len) /* {{{ */
1885+
PHPAPI zend_bool remove_user_shutdown_function(const char *function_name, size_t function_len) /* {{{ */
18861886
{
18871887
if (BG(user_shutdown_function_names)) {
18881888
return zend_hash_str_del(BG(user_shutdown_function_names), function_name, function_len) != FAILURE;

ext/standard/basic_functions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ PHP_RSHUTDOWN_FUNCTION(user_filters);
4747
PHP_RSHUTDOWN_FUNCTION(browscap);
4848

4949
/* Left for BC (not binary safe!) */
50-
PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers);
51-
PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, char *opt, char *headers);
50+
PHPAPI int _php_error_log(int opt_err, const char *message, const char *opt, const char *headers);
51+
PHPAPI int _php_error_log_ex(int opt_err, const char *message, size_t message_len, const char *opt, const char *headers);
5252
PHPAPI int php_prefix_varname(zval *result, zend_string *prefix, const char *var_name, size_t var_name_len, zend_bool add_underscore);
5353

5454
#define MT_N (624)
@@ -150,8 +150,8 @@ typedef struct _php_shutdown_function_entry {
150150
int arg_count;
151151
} php_shutdown_function_entry;
152152

153-
PHPAPI extern zend_bool register_user_shutdown_function(char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry);
154-
PHPAPI extern zend_bool remove_user_shutdown_function(char *function_name, size_t function_len);
153+
PHPAPI extern zend_bool register_user_shutdown_function(const char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry);
154+
PHPAPI extern zend_bool remove_user_shutdown_function(const char *function_name, size_t function_len);
155155
PHPAPI extern zend_bool append_user_shutdown_function(php_shutdown_function_entry shutdown_function_entry);
156156

157157
PHPAPI void php_call_shutdown_functions(void);

ext/standard/dl.c

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ PHPAPI PHP_FUNCTION(dl)
7070

7171
/* {{{ php_load_shlib
7272
*/
73-
PHPAPI void *php_load_shlib(char *path, char **errp)
73+
PHPAPI void *php_load_shlib(const char *path, char **errp)
7474
{
7575
void *handle;
7676
char *err;
@@ -98,7 +98,7 @@ PHPAPI void *php_load_shlib(char *path, char **errp)
9898

9999
/* {{{ php_load_extension
100100
*/
101-
PHPAPI int php_load_extension(char *filename, int type, int start_now)
101+
PHPAPI int php_load_extension(const char *filename, int type, int start_now)
102102
{
103103
void *handle;
104104
char *libpath;
@@ -243,35 +243,47 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now)
243243
}
244244
/* }}} */
245245

246-
/* {{{ php_dl
247-
*/
248-
PHPAPI void php_dl(char *file, int type, zval *return_value, int start_now)
246+
#else
247+
248+
static void php_dl_error(const char *filename)
249249
{
250-
/* Load extension */
251-
if (php_load_extension(file, type, start_now) == FAILURE) {
252-
RETVAL_FALSE;
253-
} else {
254-
RETVAL_TRUE;
255-
}
250+
php_error_docref(NULL, E_WARNING, "Cannot dynamically load %s - dynamic modules are not supported", filename);
256251
}
257-
/* }}} */
258252

259-
PHP_MINFO_FUNCTION(dl)
253+
PHPAPI void *php_load_shlib(const char *path, char **errp)
260254
{
261-
php_info_print_table_row(2, "Dynamic Library Support", "enabled");
255+
php_dl_error(filename);
256+
(*errp) = estrdup("No DL support");
262257
}
263258

264-
#else
265-
266-
PHPAPI void php_dl(char *file, int type, zval *return_value, int start_now)
259+
PHPAPI int php_load_extension(const char *filename, int type, int start_now)
267260
{
268-
php_error_docref(NULL, E_WARNING, "Cannot dynamically load %s - dynamic modules are not supported", file);
269-
RETVAL_FALSE;
261+
php_dl_error(filename);
262+
263+
return FAILURE;
270264
}
271265

272-
PHP_MINFO_FUNCTION(dl)
266+
#endif
267+
268+
/* {{{ php_dl
269+
*/
270+
PHPAPI void php_dl(const char *file, int type, zval *return_value, int start_now)
273271
{
274-
PUTS("Dynamic Library support not available<br />.\n");
272+
/* Load extension */
273+
if (php_load_extension(file, type, start_now) == FAILURE) {
274+
RETVAL_FALSE;
275+
} else {
276+
RETVAL_TRUE;
277+
}
275278
}
279+
/* }}} */
276280

281+
PHP_MINFO_FUNCTION(dl)
282+
{
283+
#if defined(HAVE_LIBDL)
284+
#define PHP_DL_SUPPORT_STATUS "enabled"
285+
#else
286+
#define PHP_DL_SUPPORT_STATUS "unavailable"
277287
#endif
288+
php_info_print_table_row(2, "Dynamic Library Support", PHP_DL_SUPPORT_STATUS);
289+
}

0 commit comments

Comments
 (0)