Skip to content

Constify char* arguments of APIs #5676

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

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 TSRM/TSRM.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ TSRM_TLS uint8_t in_main_thread = 0;
TSRM_TLS uint8_t is_thread_shutdown = 0;

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


void tsrm_error_set(int level, char *debug_filename)
void tsrm_error_set(int level, const char *debug_filename)
{/*{{{*/
tsrm_error_level = level;

Expand Down
4 changes: 2 additions & 2 deletions TSRM/TSRM.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extern "C" {
#endif

/* startup/shutdown */
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename);
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, const char *debug_filename);
TSRM_API void tsrm_shutdown(void);

/* environ lock API */
Expand Down Expand Up @@ -115,7 +115,7 @@ typedef void (*tsrm_shutdown_func_t)(void);


TSRM_API int tsrm_error(int level, const char *format, ...);
TSRM_API void tsrm_error_set(int level, char *debug_filename);
TSRM_API void tsrm_error_set(int level, const char *debug_filename);

/* utility functions */
TSRM_API THREAD_T tsrm_thread_id(void);
Expand Down
2 changes: 1 addition & 1 deletion TSRM/tsrm_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ TSRM_API FILE *popen(const char *command, const char *type)
return popen_ex(command, type, NULL, NULL);
}/*}}}*/

TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env)
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, const char *env)
{/*{{{*/
FILE *stream = NULL;
int fno, type_len, read, mode;
Expand Down
2 changes: 1 addition & 1 deletion TSRM/tsrm_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const char * tsrm_win32_get_path_sid_key(const char *pathname, size_t pathname_l
TSRM_API void tsrm_win32_startup(void);
TSRM_API void tsrm_win32_shutdown(void);

TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env);
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, const char *env);
TSRM_API FILE *popen(const char *command, const char *type);
TSRM_API int pclose(FILE *stream);
TSRM_API int tsrm_win32_access(const char *pathname, int mode);
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -2716,7 +2716,7 @@ ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_lengt

/* Disabled functions support */

ZEND_API int zend_disable_function(char *function_name, size_t function_name_length) /* {{{ */
ZEND_API int zend_disable_function(const char *function_name, size_t function_name_length) /* {{{ */
{
return zend_hash_str_del(CG(function_table), function_name, function_name_length);
}
Expand Down Expand Up @@ -2753,7 +2753,7 @@ static const zend_function_entry disabled_class_new[] = {
ZEND_FE_END
};

ZEND_API int zend_disable_class(char *class_name, size_t class_name_length) /* {{{ */
ZEND_API int zend_disable_class(const char *class_name, size_t class_name_length) /* {{{ */
{
zend_class_entry *disabled_class;
zend_string *key;
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zen
#define zend_register_ns_class_alias(ns, name, ce) \
zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce, 1)

ZEND_API int zend_disable_function(char *function_name, size_t function_name_length);
ZEND_API int zend_disable_class(char *class_name, size_t class_name_length);
ZEND_API int zend_disable_function(const char *function_name, size_t function_name_length);
ZEND_API int zend_disable_class(const char *class_name, size_t class_name_length);

ZEND_API ZEND_COLD void zend_wrong_param_count(void);

Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ void zend_do_extended_fcall_end(void) /* {{{ */
}
/* }}} */

zend_bool zend_is_auto_global_str(char *name, size_t len) /* {{{ */ {
zend_bool zend_is_auto_global_str(const char *name, size_t len) /* {{{ */ {
zend_auto_global *auto_global;

if ((auto_global = zend_hash_str_find_ptr(CG(auto_globals), name, len)) != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ typedef struct _zend_auto_global {
ZEND_API int zend_register_auto_global(zend_string *name, zend_bool jit, zend_auto_global_callback auto_global_callback);
ZEND_API void zend_activate_auto_globals(void);
ZEND_API zend_bool zend_is_auto_global(zend_string *name);
ZEND_API zend_bool zend_is_auto_global_str(char *name, size_t len);
ZEND_API zend_bool zend_is_auto_global_str(const char *name, size_t len);
ZEND_API size_t zend_dirname(char *path, size_t len);
ZEND_API void zend_set_function_arg_flags(zend_function *func);

Expand Down
23 changes: 15 additions & 8 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ static const char *php_date_short_day_name(timelib_sll y, timelib_sll m, timelib
/* }}} */

/* {{{ date_format - (gm)date helper */
static zend_string *date_format(char *format, size_t format_len, timelib_time *t, int localtime)
static zend_string *date_format(const char *format, size_t format_len, timelib_time *t, int localtime)
{
smart_str string = {0};
size_t i;
Expand Down Expand Up @@ -798,7 +798,7 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime)
}
/* }}} */

PHPAPI zend_string *php_format_date(char *format, size_t format_len, time_t ts, int localtime) /* {{{ */
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, int localtime) /* {{{ */
{
timelib_time *t;
timelib_tzinfo *tzi;
Expand Down Expand Up @@ -982,14 +982,14 @@ PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb)
/* }}} */

/* {{{ php_parse_date: Backwards compatibility function */
PHPAPI zend_long php_parse_date(char *string, zend_long *now)
PHPAPI zend_long php_parse_date(const char *string, zend_long *now)
{
timelib_time *parsed_time;
timelib_error_container *error = NULL;
int error2;
zend_long retval;

parsed_time = timelib_strtotime(string, strlen(string), &error, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
parsed_time = timelib_strtotime((char *) string, strlen(string), &error, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also submit a PR to https://github.com/derickr/timelib, so we can drop these const casts in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not change it because I was worried whether this modification will affect other projects
but I will try to submit a PR soon

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TODO comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (error->error_count) {
timelib_time_dtor(parsed_time);
timelib_error_container_dtor(error);
Expand Down Expand Up @@ -2187,7 +2187,7 @@ static void php_date_get_current_time_with_fraction(time_t *sec, suseconds_t *us
#endif
}

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) /* {{{ */
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) /* {{{ */
{
timelib_time *now;
timelib_tzinfo *tzi = NULL;
Expand All @@ -2202,9 +2202,16 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str,
timelib_time_dtor(dateobj->time);
}
if (format) {
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);
if (time_str_len == 0) {
time_str = "";
}
dateobj->time = timelib_parse_from_format(format, (char *) time_str, time_str_len, &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
} else {
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);
if (time_str_len == 0) {
time_str = "now";
time_str_len = sizeof("now") - 1;
}
dateobj->time = timelib_strtotime((char *) time_str, time_str_len, &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
}

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

if (ctor && err && err->error_count) {
/* spit out the first library error message, at least */
php_error_docref(NULL, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", time_str,
php_error_docref(NULL, E_WARNING, "Failed to parse time string (%.*s) at position %d (%c): %s", (int) time_str_len, time_str,
err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message);
}
if (err && err->error_count) {
Expand Down
6 changes: 3 additions & 3 deletions ext/date/php_date.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ ZEND_END_MODULE_GLOBALS(date)
PHPAPI time_t php_time();

/* Backwards compatibility wrapper */
PHPAPI zend_long php_parse_date(char *string, zend_long *now);
PHPAPI zend_long php_parse_date(const char *string, zend_long *now);
PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt);
PHPAPI int php_idate(char format, time_t ts, int localtime);

#define _php_strftime php_strftime

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

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

/* Functions for creating DateTime objects, and initializing them from a string */
PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object);
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);
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);


#endif /* PHP_DATE_H */
7 changes: 3 additions & 4 deletions ext/session/php_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ PHPAPI zend_string *php_session_create_id(PS_CREATE_SID_ARGS);
PHPAPI int php_session_validate_sid(PS_VALIDATE_SID_ARGS);
PHPAPI int php_session_update_timestamp(PS_UPDATE_TIMESTAMP_ARGS);

PHPAPI void session_adapt_url(const char *, size_t, char **, size_t *);
PHPAPI void session_adapt_url(const char *url, size_t urllen, char **new, size_t *newlen);

PHPAPI int php_session_destroy(void);
PHPAPI void php_add_session_var(zend_string *name);
Expand All @@ -260,12 +260,11 @@ PHPAPI int php_session_register_serializer(const char *name,
zend_string *(*encode)(PS_SERIALIZER_ENCODE_ARGS),
int (*decode)(PS_SERIALIZER_DECODE_ARGS));

PHPAPI void php_session_set_id(char *id);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can not find any implementation of php_session_set_id

PHPAPI int php_session_start(void);
PHPAPI int php_session_flush(int write);

PHPAPI const ps_module *_php_find_ps_module(char *name);
PHPAPI const ps_serializer *_php_find_ps_serializer(char *name);
PHPAPI const ps_module *_php_find_ps_module(const char *name);
PHPAPI const ps_serializer *_php_find_ps_serializer(const char *name);

PHPAPI int php_session_valid_key(const char *key);
PHPAPI int php_session_reset_id(void);
Expand Down
4 changes: 2 additions & 2 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ static int php_session_send_cookie(void) /* {{{ */
}
/* }}} */

PHPAPI const ps_module *_php_find_ps_module(char *name) /* {{{ */
PHPAPI const ps_module *_php_find_ps_module(const char *name) /* {{{ */
{
const ps_module *ret = NULL;
const ps_module **mod;
Expand All @@ -1390,7 +1390,7 @@ PHPAPI const ps_module *_php_find_ps_module(char *name) /* {{{ */
}
/* }}} */

PHPAPI const ps_serializer *_php_find_ps_serializer(char *name) /* {{{ */
PHPAPI const ps_serializer *_php_find_ps_serializer(const char *name) /* {{{ */
{
const ps_serializer *ret = NULL;
const ps_serializer *mod;
Expand Down
10 changes: 5 additions & 5 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1472,13 +1472,13 @@ PHP_FUNCTION(error_log)
/* }}} */

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

PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, char *opt, char *headers) /* {{{ */
PHPAPI int _php_error_log_ex(int opt_err, const char *message, size_t message_len, const char *opt, const char *headers) /* {{{ */
{
php_stream *stream = NULL;
size_t nbytes;
Expand Down Expand Up @@ -1510,7 +1510,7 @@ PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, cha

case 4: /* send to SAPI */
if (sapi_module.log_message) {
sapi_module.log_message(message, -1);
sapi_module.log_message((char *) message, -1);
} else {
return FAILURE;
}
Expand Down Expand Up @@ -1870,7 +1870,7 @@ PHP_FUNCTION(register_shutdown_function)
}
/* }}} */

PHPAPI zend_bool register_user_shutdown_function(char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry) /* {{{ */
PHPAPI zend_bool register_user_shutdown_function(const char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry) /* {{{ */
{
if (!BG(user_shutdown_function_names)) {
ALLOC_HASHTABLE(BG(user_shutdown_function_names));
Expand All @@ -1882,7 +1882,7 @@ PHPAPI zend_bool register_user_shutdown_function(char *function_name, size_t fun
}
/* }}} */

PHPAPI zend_bool remove_user_shutdown_function(char *function_name, size_t function_len) /* {{{ */
PHPAPI zend_bool remove_user_shutdown_function(const char *function_name, size_t function_len) /* {{{ */
{
if (BG(user_shutdown_function_names)) {
return zend_hash_str_del(BG(user_shutdown_function_names), function_name, function_len) != FAILURE;
Expand Down
8 changes: 4 additions & 4 deletions ext/standard/basic_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ PHP_RSHUTDOWN_FUNCTION(user_filters);
PHP_RSHUTDOWN_FUNCTION(browscap);

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

#define MT_N (624)
Expand Down Expand Up @@ -150,8 +150,8 @@ typedef struct _php_shutdown_function_entry {
int arg_count;
} php_shutdown_function_entry;

PHPAPI extern zend_bool register_user_shutdown_function(char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry);
PHPAPI extern zend_bool remove_user_shutdown_function(char *function_name, size_t function_len);
PHPAPI extern zend_bool register_user_shutdown_function(const char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry);
PHPAPI extern zend_bool remove_user_shutdown_function(const char *function_name, size_t function_len);
PHPAPI extern zend_bool append_user_shutdown_function(php_shutdown_function_entry shutdown_function_entry);

PHPAPI void php_call_shutdown_functions(void);
Expand Down
54 changes: 33 additions & 21 deletions ext/standard/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ PHPAPI PHP_FUNCTION(dl)

/* {{{ php_load_shlib
*/
PHPAPI void *php_load_shlib(char *path, char **errp)
PHPAPI void *php_load_shlib(const char *path, char **errp)
{
void *handle;
char *err;
Expand Down Expand Up @@ -98,7 +98,7 @@ PHPAPI void *php_load_shlib(char *path, char **errp)

/* {{{ php_load_extension
*/
PHPAPI int php_load_extension(char *filename, int type, int start_now)
PHPAPI int php_load_extension(const char *filename, int type, int start_now)
{
void *handle;
char *libpath;
Expand Down Expand Up @@ -243,35 +243,47 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now)
}
/* }}} */

/* {{{ php_dl
*/
PHPAPI void php_dl(char *file, int type, zval *return_value, int start_now)
#else

static void php_dl_error(const char *filename)
{
/* Load extension */
if (php_load_extension(file, type, start_now) == FAILURE) {
RETVAL_FALSE;
} else {
RETVAL_TRUE;
}
php_error_docref(NULL, E_WARNING, "Cannot dynamically load %s - dynamic modules are not supported", filename);
}
/* }}} */

PHP_MINFO_FUNCTION(dl)
PHPAPI void *php_load_shlib(const char *path, char **errp)
{
php_info_print_table_row(2, "Dynamic Library Support", "enabled");
php_dl_error(filename);
(*errp) = estrdup("No DL support");
}

#else
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice: missing function implementations here, so I made some changes


PHPAPI void php_dl(char *file, int type, zval *return_value, int start_now)
PHPAPI int php_load_extension(const char *filename, int type, int start_now)
{
php_error_docref(NULL, E_WARNING, "Cannot dynamically load %s - dynamic modules are not supported", file);
RETVAL_FALSE;
php_dl_error(filename);

return FAILURE;
}

PHP_MINFO_FUNCTION(dl)
#endif

/* {{{ php_dl
*/
PHPAPI void php_dl(const char *file, int type, zval *return_value, int start_now)
{
PUTS("Dynamic Library support not available<br />.\n");
/* Load extension */
if (php_load_extension(file, type, start_now) == FAILURE) {
RETVAL_FALSE;
} else {
RETVAL_TRUE;
}
}
/* }}} */

PHP_MINFO_FUNCTION(dl)
{
#if defined(HAVE_LIBDL)
#define PHP_DL_SUPPORT_STATUS "enabled"
#else
#define PHP_DL_SUPPORT_STATUS "unavailable"
#endif
php_info_print_table_row(2, "Dynamic Library Support", PHP_DL_SUPPORT_STATUS);
}
Loading