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 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 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
2 changes: 1 addition & 1 deletion Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message);
void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
ZEND_API char *(*zend_getenv)(const char *name, size_t name_len);
ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
ZEND_API int (*zend_post_startup_cb)(void) = NULL;
ZEND_API void (*zend_post_shutdown_cb)(void) = NULL;
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ typedef struct _zend_utility_functions {
int (*stream_open_function)(const char *filename, zend_file_handle *handle);
void (*printf_to_smart_string_function)(smart_string *buf, const char *format, va_list ap);
void (*printf_to_smart_str_function)(smart_str *buf, const char *format, va_list ap);
char *(*getenv_function)(char *name, size_t name_len);
char *(*getenv_function)(const char *name, size_t name_len);
zend_string *(*resolve_path_function)(const char *filename, size_t filename_len);
} zend_utility_functions;

Expand Down Expand Up @@ -286,7 +286,7 @@ extern ZEND_API void (*zend_on_timeout)(int seconds);
extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
extern void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
extern ZEND_API char *(*zend_getenv)(const char *name, size_t name_len);
extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);

/* These two callbacks are especially for opcache */
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
2 changes: 1 addition & 1 deletion ext/com_dotnet/com_olechar.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "php_com_dotnet_internal.h"


PHP_COM_DOTNET_API OLECHAR *php_com_string_to_olestring(char *string, size_t string_len, int codepage)
PHP_COM_DOTNET_API OLECHAR *php_com_string_to_olestring(const char *string, size_t string_len, int codepage)
{
OLECHAR *olestring = NULL;
DWORD flags = codepage == CP_UTF8 ? 0 : MB_PRECOMPOSED | MB_ERR_INVALID_CHARS;
Expand Down
2 changes: 1 addition & 1 deletion ext/com_dotnet/com_typeinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ ITypeLib *php_com_cache_typelib(ITypeLib* TL, char *cache_key, zend_long cache_k
return result;
}

PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib_via_cache(char *search_string,
PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib_via_cache(const char *search_string,
int codepage, int *cached)
{
ITypeLib *TL;
Expand Down
4 changes: 2 additions & 2 deletions ext/com_dotnet/php_com_dotnet_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int php_com_saproxy_create(zend_object *com_object, zval *proxy_out, zval *index
/* com_olechar.c */
PHP_COM_DOTNET_API char *php_com_olestring_to_string(OLECHAR *olestring,
size_t *string_len, int codepage);
PHP_COM_DOTNET_API OLECHAR *php_com_string_to_olestring(char *string,
PHP_COM_DOTNET_API OLECHAR *php_com_string_to_olestring(const char *string,
size_t string_len, int codepage);


Expand Down Expand Up @@ -130,7 +130,7 @@ PHP_COM_DOTNET_API void php_com_wrap_variant(zval *z, VARIANT *v,
PHP_COM_DOTNET_API int php_com_safearray_get_elem(VARIANT *array, VARIANT *dest, LONG dim1);

/* com_typeinfo.c */
PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib_via_cache(char *search_string,
PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib_via_cache(const char *search_string,
int codepage, int *cached);
PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib(char *search_string, int codepage);
PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode,
Expand Down
23 changes: 16 additions & 7 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, const char *format, zval *timezone_object, int ctor) /* {{{ */
{
timelib_time *now;
timelib_tzinfo *tzi = NULL;
Expand All @@ -2202,9 +2202,18 @@ 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 = "";
}
// TODO: drop this const casts
dateobj->time = timelib_parse_from_format((char *) 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;
}
// TODO: drop this const casts
dateobj->time = timelib_strtotime((char *) time_str, time_str_len, &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
}

/* update last errors and warnings */
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, const char *format, zval *timezone_object, int ctor);


#endif /* PHP_DATE_H */
4 changes: 2 additions & 2 deletions ext/filter/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static const filter_list_entry filter_list[] = {
#define PARSE_SESSION 6
#endif

static unsigned int php_sapi_filter(int arg, char *var, char **val, size_t val_len, size_t *new_val_len);
static unsigned int php_sapi_filter(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len);
static unsigned int php_sapi_filter_init(void);

/* {{{ filter_module_entry
Expand Down Expand Up @@ -360,7 +360,7 @@ static void php_zval_filter(zval *value, zend_long filter, zend_long flags, zval
}
/* }}} */

static unsigned int php_sapi_filter(int arg, char *var, char **val, size_t val_len, size_t *new_val_len) /* {{{ */
static unsigned int php_sapi_filter(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len) /* {{{ */
{
zval new_var, raw_var;
zval *array_ptr = NULL, *orig_array_ptr = NULL;
Expand Down
2 changes: 1 addition & 1 deletion ext/json/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static const char *php_json_get_error_msg(php_json_error_code error_code) /* {{{
}
/* }}} */

PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth) /* {{{ */
PHP_JSON_API int php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth) /* {{{ */
{
php_json_parser parser;

Expand Down
4 changes: 2 additions & 2 deletions ext/json/json_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static const php_json_parser_methods default_parser_methods =

PHP_JSON_API void php_json_parser_init_ex(php_json_parser *parser,
zval *return_value,
char *str,
const char *str,
size_t str_len,
int options,
int max_depth,
Expand All @@ -317,7 +317,7 @@ PHP_JSON_API void php_json_parser_init_ex(php_json_parser *parser,

PHP_JSON_API void php_json_parser_init(php_json_parser *parser,
zval *return_value,
char *str,
const char *str,
size_t str_len,
int options,
int max_depth)
Expand Down
2 changes: 1 addition & 1 deletion ext/json/json_scanner.re
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static int php_json_ucs2_to_int(php_json_scanner *s, int size)
return php_json_ucs2_to_int_ex(s, size, 1);
}

void php_json_scanner_init(php_json_scanner *s, char *str, size_t str_len, int options)
void php_json_scanner_init(php_json_scanner *s, const char *str, size_t str_len, int options)
{
s->cursor = (php_json_ctype *) str;
s->limit = (php_json_ctype *) str + str_len;
Expand Down
4 changes: 2 additions & 2 deletions ext/json/php_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ ZEND_TSRMLS_CACHE_EXTERN()

PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth);
PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options);
PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth);
PHP_JSON_API int php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth);

static inline int php_json_decode(zval *return_value, char *str, int str_len, zend_bool assoc, zend_long depth)
static inline int php_json_decode(zval *return_value, const char *str, int str_len, zend_bool assoc, zend_long depth)
{
return php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth);
}
Expand Down
4 changes: 2 additions & 2 deletions ext/json/php_json_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct _php_json_parser {
PHP_JSON_API void php_json_parser_init_ex(
php_json_parser *parser,
zval *return_value,
char *str,
const char *str,
size_t str_len,
int options,
int max_depth,
Expand All @@ -70,7 +70,7 @@ PHP_JSON_API void php_json_parser_init_ex(
PHP_JSON_API void php_json_parser_init(
php_json_parser *parser,
zval *return_value,
char *str,
const char *str,
size_t str_len,
int options,
int max_depth);
Expand Down
2 changes: 1 addition & 1 deletion ext/json/php_json_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef struct _php_json_scanner {
} php_json_scanner;


void php_json_scanner_init(php_json_scanner *scanner, char *str, size_t str_len, int options);
void php_json_scanner_init(php_json_scanner *scanner, const char *str, size_t str_len, int options);
int php_json_scan(php_json_scanner *s);

#endif /* PHP_JSON_SCANNER_H */
2 changes: 1 addition & 1 deletion ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -4798,7 +4798,7 @@ static int accel_finish_startup(void)
int (*orig_header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) = sapi_module.header_handler;
int (*orig_send_headers)(sapi_headers_struct *sapi_headers) = sapi_module.send_headers;
void (*orig_send_header)(sapi_header_struct *sapi_header, void *server_context)= sapi_module.send_header;
char *(*orig_getenv)(char *name, size_t name_len) = sapi_module.getenv;
char *(*orig_getenv)(const char *name, size_t name_len) = sapi_module.getenv;
size_t (*orig_ub_write)(const char *str, size_t str_length) = sapi_module.ub_write;
void (*orig_flush)(void *server_context) = sapi_module.flush;
uint32_t orig_compiler_options = CG(compiler_options);
Expand Down
Loading