Skip to content

Commit fa8d9b1

Browse files
committed
Improve type declarations for Zend APIs
Voidification of Zend API which always succeeded Use bool argument types instead of int for boolean arguments Use bool return type for functions which return true/false (1/0) Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics Closes GH-6002
1 parent 7690439 commit fa8d9b1

Some content is hidden

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

81 files changed

+1064
-908
lines changed

UPGRADING.INTERNALS

Lines changed: 183 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,28 @@ PHP 8.0 INTERNALS UPGRADE NOTES
158158
- zend_fcall_info_argp()
159159
- zend_fcall_info_argv()
160160
- zend_fcall_info_argn()
161+
- zend_startup()
162+
- zend_set_memory_limit()
163+
- pass_two()
164+
- zend_startup_constants()
165+
- zend_shutdown_constants()
166+
- zend_startup_extensions_mechanism()
167+
- zend_startup_extensions()
168+
- zend_register_extension()
169+
- highlight_string()
170+
- zend_ini_startup()
171+
- zend_ini_shutdown()
172+
- zend_ini_global_shutdown()
173+
- zend_ini_deactivate()
174+
- zend_copy_ini_directives()
175+
- zend_prepare_string_for_scanning()
176+
- zend_init_rsrc_list()
177+
- zend_list_close()
178+
- zend_signal()
179+
- zend_sigaction()
180+
- zend_stack_init()
181+
- zend_stack_del_top()
182+
- zend_stack_destroy()
161183
2. Argument int to uint32_t in Zend Engine 4.0:
162184
- _zend_get_parameters_array_ex()
163185
- zend_copy_parameters_array()
@@ -169,8 +191,39 @@ PHP 8.0 INTERNALS UPGRADE NOTES
169191
- zend_wrong_parameter*()
170192
- zend_wrong_callback_error()
171193
- zend_parse_arg_class()
172-
3. Argument int to zend_bool in Zend Engine 4.0:
194+
3. Argument int to bool in Zend Engine 4.0:
173195
- add_next_index_bool()
196+
- zend_register_class_alias_ex()
197+
- add_assoc_bool_ex()
198+
- add_index_bool()
199+
- zend_fcall_info_args_clear()
200+
- zend_set_local_var()
201+
- zend_set_local_var_str()
202+
- zend_parse_arg_*()
203+
- shutdown_memory_manager()
204+
- zend_memory_usage()
205+
- zend_memory_peak_usage()
206+
- zend_mm_shutdown()
207+
- zend_eval_string*()
208+
- zend_set_timeout()
209+
- _zend_hash_append_ex()
210+
- _zend_hash_append_ptr_ex()
211+
- zend_alter_ini_entry_ex()
212+
- (*zend_encoding_list_parser) typedef
213+
- zend_multibyte_parse_encoding_list()
214+
- zend_safe_address()
215+
- zend_string_tolower_ex()
216+
- zend_string_alloc()
217+
- zend_string_safe_alloc()
218+
- zend_string_init()
219+
- zend_string_dup()
220+
- zend_string_realloc()
221+
- zend_string_extend()
222+
- zend_string_truncate()
223+
- zend_string_safe_realloc()
224+
- zend_string_release_ex()
225+
- zend_ts_hash_merge()
226+
- zend_ts_hash_sort()
174227
4. Argument int to size_t in Zend Engine 4.0:
175228
- zend_set_hash_symbol()
176229
5. Argument zval* to zend_object* in Zend Engine 4.0:
@@ -185,6 +238,135 @@ PHP 8.0 INTERNALS UPGRADE NOTES
185238
- zend_get_exception_base()
186239
6. Argument zval* to zend_long in Zend Engine 4.0:
187240
- _php_math_longtobase()
241+
7. Return type from int to zend_result in Zend Engine 4.0:
242+
- (*stream_open_function) in _zend_utility_functions
243+
- (*zend_post_startup_cb)
244+
- (*zend_preload_autoload)
245+
- zend_execute_scripts()
246+
- zend_post_startup()
247+
- _zend_get_parameters_array_ex()
248+
- zend_copy_parameters_array()
249+
- zend_parse_parameters()
250+
- zend_parse_parameters_ex()
251+
- zend_parse_method_parameters()
252+
- zend_parse_method_parameters_ex()
253+
- zend_parse_method_parameters()
254+
- zend_register_functions()
255+
- zend_startup_module()
256+
- zend_startup_module_ex()
257+
- zend_register_class_alias_ex()
258+
- zend_disable_function()
259+
- zend_disable_class()
260+
- zend_update_class_constants()
261+
- zend_update_static_property*()
262+
- object_init_ex()
263+
- object_and_properties_init()
264+
- add_index_zval()
265+
- add_next_index_long_*()
266+
- array_set_zval_key()
267+
- _call_user_function_impl()
268+
- zend_fcall_info_*()
269+
- zend_call_function()
270+
- zend_set_hash_symbol()
271+
- zend_delete_global_variable()
272+
- zend_set_local_var()
273+
- zend_set_local_var_str()
274+
- zend_forbid_dynamic_call()
275+
- zend_get_default_from_internal_arg_info()
276+
- zend_try_assign_typed_ref*()
277+
- zend_ast_evaluate()
278+
- zend_startup_builtin_functions()
279+
- do_bind_function()
280+
- do_bind_class()
281+
- zend_unmangle_property_name_ex()
282+
- zend_register_auto_global()
283+
- zend_register_constant()
284+
- zend_exception_error()
285+
- zend_eval_string*()
286+
- zend_undefined_offset_write()
287+
- zend_undefined_index_write()
288+
- zval_update_constant(_ex)()
289+
- zend_load_extension()
290+
- zend_load_extension_handle()
291+
- zend_hash_del(_ind)()
292+
- zend_hash_str_del(_ind)()
293+
- zend_hash_index_del()
294+
- zend_hash_move_forward_ex()
295+
- zend_hash_move_backward_ex()
296+
- zend_hash_get_current_key_ex()
297+
- zend_hash_get_current_key_type_ex()
298+
- zend_symtable_del(_ind)()
299+
- zend_symtable_str_del(_ind)()
300+
- highlight_file()
301+
- zend_do_link_class()
302+
- zend_alter_ini_entry*()
303+
- zend_restore_ini_entry()
304+
- zend_ini_register_displayer()
305+
- zend_ini_open_file_for_scanning()
306+
- zend_ini_prepare_string_for_scanning()
307+
- zend_user_it_valid()
308+
- zend_create_internal_iterator_zval()
309+
- zend_multibyte_set_filter()
310+
- zend_lex_tstring()
311+
- _zend_module_entry module_startup_func, module_shutdown_func,
312+
request_startup_func, and request_shutdown_func function pointers
313+
- (*zend_encoding_list_parser) typedef
314+
- (*zend_encoding_internal_encoding_setter) typedef
315+
- zend_multibyte_set_functions()
316+
- zend_multibyte_set_script_encoding_by_string()
317+
- add_function()
318+
- sub_function()
319+
- mul_function()
320+
- pow_function()
321+
- div_function()
322+
- mod_function()
323+
- boolean_xor_function()
324+
- boolean_not_function()
325+
- bitwise_not_function()
326+
- bitwise_or_function()
327+
- bitwise_and_function()
328+
- bitwise_xor_function()
329+
- shift_left_function()
330+
- shift_right_function()
331+
- concat_function()
332+
- is_equal_function(
333+
- is_identical_function()
334+
- is_not_identical_function()
335+
- is_not_equal_function()
336+
- is_smaller_function()
337+
- is_smaller_or_equal_function(zv
338+
- increment_function()
339+
- decrement_function()
340+
- zend_stream_open()
341+
- zend_stream_fixup()
342+
- zend_ts_hash_del()
343+
- zend_ts_hash_index_del()
344+
8. Return type from int to bool in Zend Engine 4.0:
345+
- zend_make_printable_zval()
346+
- zend_parse_arg_*()
347+
- is_zend_mm()
348+
- is_zend_ptr()
349+
- zend_mm_is_custom_heap()
350+
- (*zend_mm_chunk_truncate_t)
351+
- (*zend_mm_chunk_extend_t)
352+
- zend_bitset_empty()
353+
- zend_is_smart_branch()
354+
- zend_check_arg_send_type()
355+
- zend_verify_const_access()
356+
- zend_gdb_register_code()
357+
- zend_gdb_present()
358+
- _zend_handle_numeric_str(_ex)()
359+
- zend_hash_exists_ind()
360+
- zend_hash_str_exists_ind()
361+
- zend_symtable_exists(_ind)()
362+
- zend_symtable_str_exists()
363+
- (*zend_encoding_lexer_compatibility_checker)
364+
- zend_object_is_true()
365+
- i_zend_is_true()
366+
- zendi_smart_streq()
367+
- zend_stack_is_empty()
368+
- zend_ts_hash_exists()
369+
- zend_ts_hash_index_exists()
188370

189371
u. Instead of overwriting zend_error_cb extensions with debugging, monitoring
190372
use-cases catching Errors/Exceptions are strongly encouraged to use

Zend/zend.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ ZEND_API zend_class_entry *zend_standard_class_def = NULL;
7474
ZEND_API size_t (*zend_printf)(const char *format, ...);
7575
ZEND_API zend_write_func_t zend_write;
7676
ZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path);
77-
ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
77+
ZEND_API zend_result (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
7878
ZEND_API void (*zend_ticks_function)(int ticks);
7979
ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
8080
ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message);
8181
void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
8282
void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
8383
ZEND_API char *(*zend_getenv)(const char *name, size_t name_len);
8484
ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
85-
ZEND_API int (*zend_post_startup_cb)(void) = NULL;
85+
ZEND_API zend_result (*zend_post_startup_cb)(void) = NULL;
8686
ZEND_API void (*zend_post_shutdown_cb)(void) = NULL;
87-
ZEND_API int (*zend_preload_autoload)(zend_string *filename) = NULL;
87+
ZEND_API zend_result (*zend_preload_autoload)(zend_string *filename) = NULL;
8888

8989
/* This callback must be signal handler safe! */
9090
void (*zend_on_timeout)(int seconds);
@@ -365,7 +365,7 @@ static void print_flat_hash(HashTable *ht) /* {{{ */
365365
}
366366
/* }}} */
367367

368-
ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
368+
ZEND_API bool zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
369369
{
370370
if (Z_TYPE_P(expr) == IS_STRING) {
371371
return 0;
@@ -757,9 +757,8 @@ static void executor_globals_dtor(zend_executor_globals *executor_globals) /* {{
757757

758758
static void zend_new_thread_end_handler(THREAD_T thread_id) /* {{{ */
759759
{
760-
if (zend_copy_ini_directives() == SUCCESS) {
761-
zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP);
762-
}
760+
zend_copy_ini_directives();
761+
zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP);
763762
}
764763
/* }}} */
765764
#endif
@@ -803,7 +802,7 @@ static zend_bool php_auto_globals_create_globals(zend_string *name) /* {{{ */
803802
}
804803
/* }}} */
805804

806-
int zend_startup(zend_utility_functions *utility_functions) /* {{{ */
805+
void zend_startup(zend_utility_functions *utility_functions) /* {{{ */
807806
{
808807
#ifdef ZTS
809808
zend_compiler_globals *compiler_globals;
@@ -969,8 +968,6 @@ int zend_startup(zend_utility_functions *utility_functions) /* {{{ */
969968
tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
970969
tsrm_set_shutdown_handler(zend_interned_strings_dtor);
971970
#endif
972-
973-
return SUCCESS;
974971
}
975972
/* }}} */
976973

@@ -1021,7 +1018,7 @@ static void zend_resolve_property_types(void) /* {{{ */
10211018
/* Unlink the global (r/o) copies of the class, function and constant tables,
10221019
* and use a fresh r/w copy for the startup thread
10231020
*/
1024-
int zend_post_startup(void) /* {{{ */
1021+
zend_result zend_post_startup(void) /* {{{ */
10251022
{
10261023
#ifdef ZTS
10271024
zend_encoding **script_encoding_list;
@@ -1033,7 +1030,7 @@ int zend_post_startup(void) /* {{{ */
10331030
zend_resolve_property_types();
10341031

10351032
if (zend_post_startup_cb) {
1036-
int (*cb)(void) = zend_post_startup_cb;
1033+
zend_result (*cb)(void) = zend_post_startup_cb;
10371034

10381035
zend_post_startup_cb = NULL;
10391036
if (cb() != SUCCESS) {
@@ -1665,13 +1662,13 @@ ZEND_API ZEND_COLD void zend_user_exception_handler(void) /* {{{ */
16651662
}
16661663
} /* }}} */
16671664

1668-
ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...) /* {{{ */
1665+
ZEND_API zend_result zend_execute_scripts(int type, zval *retval, int file_count, ...) /* {{{ */
16691666
{
16701667
va_list files;
16711668
int i;
16721669
zend_file_handle *file_handle;
16731670
zend_op_array *op_array;
1674-
int ret = SUCCESS;
1671+
zend_result ret = SUCCESS;
16751672

16761673
va_start(files, file_count);
16771674
for (i = 0; i < file_count; i++) {

Zend/zend.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ typedef struct _zend_utility_functions {
195195
zval *(*get_configuration_directive)(zend_string *name);
196196
void (*ticks_function)(int ticks);
197197
void (*on_timeout)(int seconds);
198-
int (*stream_open_function)(const char *filename, zend_file_handle *handle);
198+
zend_result (*stream_open_function)(const char *filename, zend_file_handle *handle);
199199
void (*printf_to_smart_string_function)(smart_string *buf, const char *format, va_list ap);
200200
void (*printf_to_smart_str_function)(smart_str *buf, const char *format, va_list ap);
201201
char *(*getenv_function)(const char *name, size_t name_len);
@@ -227,10 +227,10 @@ typedef size_t (*zend_write_func_t)(const char *str, size_t str_length);
227227
#define zend_first_try EG(bailout)=NULL; zend_try
228228

229229
BEGIN_EXTERN_C()
230-
int zend_startup(zend_utility_functions *utility_functions);
230+
void zend_startup(zend_utility_functions *utility_functions);
231231
void zend_shutdown(void);
232232
void zend_register_standard_ini_entries(void);
233-
int zend_post_startup(void);
233+
zend_result zend_post_startup(void);
234234
void zend_set_utility_values(zend_utility_values *utility_values);
235235

236236
ZEND_API ZEND_COLD ZEND_NORETURN void _zend_bailout(const char *filename, uint32_t lineno);
@@ -246,7 +246,7 @@ ZEND_API size_t zend_spprintf_unchecked(char **message, size_t max_len, const ch
246246
ZEND_API zend_string *zend_strpprintf_unchecked(size_t max_len, const char *format, ...);
247247

248248
ZEND_API const char *get_zend_version(void);
249-
ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy);
249+
ZEND_API bool zend_make_printable_zval(zval *expr, zval *expr_copy);
250250
ZEND_API size_t zend_print_zval(zval *expr, int indent);
251251
ZEND_API void zend_print_zval_r(zval *expr, int indent);
252252
ZEND_API zend_string *zend_print_zval_r_to_str(zval *expr, int indent);
@@ -283,18 +283,18 @@ extern ZEND_API void (*zend_ticks_function)(int ticks);
283283
extern ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
284284
extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message);
285285
extern ZEND_API void (*zend_on_timeout)(int seconds);
286-
extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
286+
extern ZEND_API zend_result (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
287287
extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
288288
extern void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
289289
extern ZEND_API char *(*zend_getenv)(const char *name, size_t name_len);
290290
extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
291291

292292
/* These two callbacks are especially for opcache */
293-
extern ZEND_API int (*zend_post_startup_cb)(void);
293+
extern ZEND_API zend_result (*zend_post_startup_cb)(void);
294294
extern ZEND_API void (*zend_post_shutdown_cb)(void);
295295

296296
/* Callback for loading of not preloaded part of the script */
297-
extern ZEND_API int (*zend_preload_autoload)(zend_string *filename);
297+
extern ZEND_API zend_result (*zend_preload_autoload)(zend_string *filename);
298298

299299
ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
300300
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);

0 commit comments

Comments
 (0)