Skip to content

Commit 83a3905

Browse files
committed
zend_portability: Simplify definition of ZEND_NORETURN
1 parent c5cadc5 commit 83a3905

16 files changed

Lines changed: 41 additions & 40 deletions

‎UPGRADING.INTERNALS‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ PHP 8.7 INTERNALS UPGRADE NOTES
2121
- The sapi_force_http_10() function was removed.
2222
- The sapi_get_fd() function was removed.
2323
- The sapi_get_target_uid() and sapi_get_target_gid() functions were removed.
24+
- Removed HAVE_NORETURN and HAVE_NORETURN_ALIAS. ZEND_NORETURN is guaranteed to
25+
work.
26+
- Redefined ZEND_NORETURN to make use of the [[noreturn]] attribute for C++
27+
and C23, which means that ZEND_NORETURN needs to come first in the modifier
28+
list. Consider using noreturn (C11) / [[noreturn]] (C23) directly if
29+
header interoperability is not required.
2430

2531
========================
2632
2. Build system changes

‎Zend/zend.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ ZEND_COLD void zenderror(const char *error) /* {{{ */
12641264
}
12651265
/* }}} */
12661266

1267-
ZEND_API ZEND_COLD ZEND_NORETURN void _zend_bailout(const char *filename, uint32_t lineno) /* {{{ */
1267+
ZEND_NORETURN ZEND_API ZEND_COLD void _zend_bailout(const char *filename, uint32_t lineno) /* {{{ */
12681268
{
12691269

12701270
if (!EG(bailout)) {
@@ -1715,7 +1715,7 @@ ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...)
17151715
zend_error_impl(type, format);
17161716
}
17171717

1718-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(
1718+
ZEND_NORETURN ZEND_API ZEND_COLD void zend_error_at_noreturn(
17191719
int type, zend_string *filename, uint32_t lineno, const char *format, ...)
17201720
{
17211721
va_list args;
@@ -1744,17 +1744,17 @@ ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(
17441744
abort(); \
17451745
} while (0)
17461746

1747-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
1747+
ZEND_NORETURN ZEND_API ZEND_COLD void zend_error_noreturn(int type, const char *format, ...)
17481748
{
17491749
zend_error_noreturn_impl(type, format);
17501750
}
17511751

1752-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn_unchecked(int type, const char *format, ...)
1752+
ZEND_NORETURN ZEND_API ZEND_COLD void zend_error_noreturn_unchecked(int type, const char *format, ...)
17531753
{
17541754
zend_error_noreturn_impl(type, format);
17551755
}
17561756

1757-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_strerror_noreturn(int type, int errn, const char *message)
1757+
ZEND_NORETURN ZEND_API ZEND_COLD void zend_strerror_noreturn(int type, int errn, const char *message)
17581758
{
17591759
#ifdef HAVE_STRERROR_R
17601760
char b[1024];

‎Zend/zend.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ zend_result zend_post_startup(void);
298298
void zend_set_utility_values(zend_utility_values *utility_values);
299299
void zend_unload_modules(void);
300300

301-
ZEND_API ZEND_COLD ZEND_NORETURN void _zend_bailout(const char *filename, uint32_t lineno);
301+
ZEND_NORETURN ZEND_API ZEND_COLD void _zend_bailout(const char *filename, uint32_t lineno);
302302
ZEND_API size_t zend_get_page_size(void);
303303

304304
ZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap);
@@ -387,13 +387,13 @@ extern ZEND_API void (*zend_post_shutdown_cb)(void);
387387
extern ZEND_API void (*zend_accel_schedule_restart_hook)(int reason);
388388

389389
ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
390-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
391-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn_unchecked(int type, const char *format, ...);
390+
ZEND_NORETURN ZEND_API ZEND_COLD void zend_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
391+
ZEND_NORETURN ZEND_API ZEND_COLD void zend_error_noreturn_unchecked(int type, const char *format, ...);
392392
/* For custom format specifiers like H */
393393
ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...);
394394
/* If filename is NULL the default filename is used. */
395395
ZEND_API ZEND_COLD void zend_error_at(int type, zend_string *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
396-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(int type, zend_string *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
396+
ZEND_NORETURN ZEND_API ZEND_COLD void zend_error_at_noreturn(int type, zend_string *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
397397
ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message);
398398
ZEND_API ZEND_COLD void zend_error_zstr_at(int type, zend_string *filename, uint32_t lineno, zend_string *message);
399399

@@ -407,7 +407,7 @@ ZEND_API ZEND_COLD void zend_illegal_container_offset(const zend_string *contain
407407
ZEND_COLD void zenderror(const char *error);
408408

409409
/* For internal C errors */
410-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_strerror_noreturn(int type, int errn, const char *message);
410+
ZEND_NORETURN ZEND_API ZEND_COLD void zend_strerror_noreturn(int type, int errn, const char *message);
411411

412412
/* The following #define is used for code duality in PHP for Engine 1 & 2 */
413413
#define ZEND_STANDARD_CLASS_DEF_PTR zend_standard_class_def

‎Zend/zend_alloc.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static const uint32_t bin_pages[] = {
380380
ZEND_MM_BINS_INFO(_BIN_DATA_PAGES, x, y)
381381
};
382382

383-
static ZEND_COLD ZEND_NORETURN void zend_mm_panic(const char *message)
383+
ZEND_NORETURN static ZEND_COLD void zend_mm_panic(const char *message)
384384
{
385385
fprintf(stderr, "%s\n", message);
386386
/* See http://support.microsoft.com/kb/190351 */
@@ -393,7 +393,7 @@ static ZEND_COLD ZEND_NORETURN void zend_mm_panic(const char *message)
393393
abort();
394394
}
395395

396-
static ZEND_COLD ZEND_NORETURN void zend_mm_safe_error(zend_mm_heap *heap,
396+
ZEND_NORETURN static ZEND_COLD void zend_mm_safe_error(zend_mm_heap *heap,
397397
const char *format,
398398
size_t limit,
399399
#if ZEND_DEBUG
@@ -2995,7 +2995,7 @@ ZEND_API char* ZEND_FASTCALL _estrndup(const char *s, size_t length ZEND_FILE_LI
29952995
return p;
29962996
}
29972997

2998-
static ZEND_COLD ZEND_NORETURN void zend_out_of_memory(void);
2998+
ZEND_NORETURN static ZEND_COLD void zend_out_of_memory(void);
29992999

30003000
ZEND_API char* ZEND_FASTCALL zend_strndup(const char *s, size_t length)
30013001
{
@@ -3091,7 +3091,7 @@ ZEND_API void refresh_memory_manager(void)
30913091
zend_mm_refresh_key_child(AG(mm_heap));
30923092
}
30933093

3094-
static ZEND_COLD ZEND_NORETURN void zend_out_of_memory(void)
3094+
ZEND_NORETURN static ZEND_COLD void zend_out_of_memory(void)
30953095
{
30963096
fprintf(stderr, "Out of memory\n");
30973097
abort();

‎Zend/zend_compile.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ ZEND_API void function_add_ref(zend_function *function) /* {{{ */
12951295
}
12961296
/* }}} */
12971297

1298-
static zend_never_inline ZEND_COLD ZEND_NORETURN void do_bind_function_error(const zend_string *lcname, const zend_op_array *op_array, bool compile_time) /* {{{ */
1298+
ZEND_NORETURN static zend_never_inline ZEND_COLD void do_bind_function_error(const zend_string *lcname, const zend_op_array *op_array, bool compile_time) /* {{{ */
12991299
{
13001300
const zval *zv = zend_hash_find_known_hash(compile_time ? CG(function_table) : EG(function_table), lcname);
13011301
int error_level = compile_time ? E_COMPILE_ERROR : E_ERROR;

‎Zend/zend_execute.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_refe
525525

526526
ZEND_API void zend_set_timeout(zend_long seconds, bool reset_signals);
527527
ZEND_API void zend_unset_timeout(void);
528-
ZEND_API ZEND_NORETURN void ZEND_FASTCALL zend_timeout(void);
528+
ZEND_NORETURN ZEND_API void ZEND_FASTCALL zend_timeout(void);
529529
ZEND_API zend_class_entry *zend_fetch_class(zend_string *class_name, uint32_t fetch_type);
530530
ZEND_API zend_class_entry *zend_fetch_class_with_scope(zend_string *class_name, uint32_t fetch_type, zend_class_entry *scope);
531531
ZEND_API zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, zend_string *lcname, uint32_t fetch_type);

‎Zend/zend_execute_API.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ ZEND_API zend_result zend_eval_string_ex(const char *str, zval *retval_ptr, cons
14671467

14681468
static void zend_set_timeout_ex(zend_long seconds, bool reset_signals);
14691469

1470-
ZEND_API ZEND_NORETURN void ZEND_FASTCALL zend_timeout(void) /* {{{ */
1470+
ZEND_NORETURN ZEND_API void ZEND_FASTCALL zend_timeout(void) /* {{{ */
14711471
{
14721472
#if defined(PHP_WIN32)
14731473
# ifndef ZTS

‎Zend/zend_fibers.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ ZEND_API void* zend_fiber_stack_base(zend_fiber_stack *stack)
358358
#endif
359359

360360
#ifdef ZEND_FIBER_UCONTEXT
361-
static ZEND_NORETURN void zend_fiber_trampoline(void)
361+
ZEND_NORETURN static void zend_fiber_trampoline(void)
362362
#else
363-
static ZEND_NORETURN void zend_fiber_trampoline(boost_context_data data)
363+
ZEND_NORETURN static void zend_fiber_trampoline(boost_context_data data)
364364
#endif
365365
{
366366
/* Initialize transfer struct with a copy of passed data. */

‎Zend/zend_gc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,12 +1857,12 @@ static void zend_gc_remove_root_tmpvars(void);
18571857

18581858
static zend_internal_function gc_destructor_fiber;
18591859

1860-
static ZEND_COLD ZEND_NORETURN void gc_create_destructor_fiber_error(void)
1860+
ZEND_NORETURN static ZEND_COLD void gc_create_destructor_fiber_error(void)
18611861
{
18621862
zend_error_noreturn(E_ERROR, "Unable to create destructor fiber");
18631863
}
18641864

1865-
static ZEND_COLD ZEND_NORETURN void gc_start_destructor_fiber_error(void)
1865+
ZEND_NORETURN static ZEND_COLD void gc_start_destructor_fiber_error(void)
18661866
{
18671867
zend_error_noreturn(E_ERROR, "Unable to start destructor fiber");
18681868
}

‎Zend/zend_inheritance.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,13 +1779,13 @@ ZEND_API void zend_verify_hooked_property(const zend_class_entry *ce, zend_prope
17791779
}
17801780
}
17811781

1782-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_hooked_property_variance_error_ex(zend_string *value_param_name, zend_string *class_name, zend_string *prop_name)
1782+
ZEND_NORETURN ZEND_API ZEND_COLD void zend_hooked_property_variance_error_ex(zend_string *value_param_name, zend_string *class_name, zend_string *prop_name)
17831783
{
17841784
zend_error_noreturn(E_COMPILE_ERROR, "Type of parameter $%s of hook %s::$%s::set must be compatible with property type",
17851785
ZSTR_VAL(value_param_name), ZSTR_VAL(class_name), zend_get_unmangled_property_name(prop_name));
17861786
}
17871787

1788-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_hooked_property_variance_error(const zend_property_info *prop_info)
1788+
ZEND_NORETURN ZEND_API ZEND_COLD void zend_hooked_property_variance_error(const zend_property_info *prop_info)
17891789
{
17901790
zend_string *value_param_name = prop_info->hooks[ZEND_PROPERTY_HOOK_SET]->op_array.arg_info[0].name;
17911791
zend_hooked_property_variance_error_ex(value_param_name, prop_info->ce->name, prop_info->name);

0 commit comments

Comments
 (0)