Skip to content

Commit 8265319

Browse files
committed
Add fiber flag to exceptions
1 parent f439fea commit 8265319

10 files changed

+30
-9
lines changed

Zend/tests/fibers/failing-fiber.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ string(4) "test"
2020
Fatal error: Uncaught Exception: test in %sfailing-fiber.php:%d
2121
Stack trace:
2222
#0 [internal function]: {closure}()
23-
#1 {main}
23+
#1 {fiber}
2424
thrown in %sfailing-fiber.php on line %d

Zend/tests/fibers/fiber-throw-in-destruct.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ int(1)
2323
Fatal error: Uncaught Exception: test in %sfiber-throw-in-destruct.php:%d
2424
Stack trace:
2525
#0 [internal function]: class@anonymous::{closure}()
26-
#1 {main}
26+
#1 {fiber}
2727
thrown in %sfiber-throw-in-destruct.php on line %d

Zend/tests/fibers/resume-running-fiber.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Fatal error: Uncaught FiberError: Cannot resume a fiber that is not suspended in
1616
Stack trace:
1717
#0 %sresume-running-fiber.php(%d): Fiber->resume()
1818
#1 [internal function]: {closure}()
19-
#2 {main}
19+
#2 {fiber}
2020
thrown in %sresume-running-fiber.php on line %d

Zend/tests/fibers/start-arguments.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ int(1)
2424
Fatal error: Uncaught TypeError: {closure}(): Argument #1 ($x) must be of type int, string given in %sstart-arguments.php:%d
2525
Stack trace:
2626
#0 [internal function]: {closure}('test')
27-
#1 {main}
27+
#1 {fiber}
2828
thrown in %sstart-arguments.php on line %d

Zend/tests/fibers/suspend-in-force-close-fiber-after-shutdown.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ Fatal error: Uncaught FiberError: Cannot suspend in a force closed fiber in %ssu
2323
Stack trace:
2424
#0 %ssuspend-in-force-close-fiber-after-shutdown.php(%d): Fiber::suspend()
2525
#1 [internal function]: {closure}()
26-
#2 {main}
26+
#2 {fiber}
2727
thrown in %ssuspend-in-force-close-fiber-after-shutdown.php on line %d

Zend/tests/fibers/suspend-in-force-close-fiber.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ Fatal error: Uncaught FiberError: Cannot suspend in a force closed fiber in %ssu
2121
Stack trace:
2222
#0 %ssuspend-in-force-close-fiber.php(%d): Fiber::suspend()
2323
#1 [internal function]: {closure}()
24-
#2 {main}
24+
#2 {fiber}
2525
thrown in %ssuspend-in-force-close-fiber.php on line %d

Zend/zend_exceptions.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type,
267267
}
268268
zend_update_property_ex(base_ce, object, ZSTR_KNOWN(ZEND_STR_TRACE), &trace);
269269

270+
ZVAL_BOOL(&tmp, EG(current_fiber));
271+
zend_update_property_ex(base_ce, object, ZSTR_KNOWN(ZEND_STR_FIBER), &tmp);
272+
270273
return object;
271274
}
272275
/* }}} */
@@ -340,6 +343,7 @@ ZEND_METHOD(Exception, __wakeup)
340343
CHECK_EXC_TYPE(ZEND_STR_CODE, IS_LONG);
341344
CHECK_EXC_TYPE(ZEND_STR_FILE, IS_STRING);
342345
CHECK_EXC_TYPE(ZEND_STR_LINE, IS_LONG);
346+
CHECK_EXC_TYPE(ZEND_STR_FIBER, _IS_BOOL);
343347
/* The type of $trace and $previous is enforced through typed properties. */
344348
}
345349
/* }}} */
@@ -606,7 +610,7 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /*
606610
/* {{{ Obtain the backtrace for the exception as a string (instead of an array) */
607611
ZEND_METHOD(Exception, getTraceAsString)
608612
{
609-
zval *trace, *frame, rv;
613+
zval *trace, *frame, *fiber, rv;
610614
zend_ulong index;
611615
zval *object;
612616
zend_class_entry *base_ce;
@@ -634,9 +638,11 @@ ZEND_METHOD(Exception, getTraceAsString)
634638
_build_trace_string(&str, Z_ARRVAL_P(frame), num++);
635639
} ZEND_HASH_FOREACH_END();
636640

641+
fiber = zend_read_property_ex(base_ce, Z_OBJ_P(object), ZSTR_KNOWN(ZEND_STR_FIBER), 1, &rv);
642+
637643
smart_str_appendc(&str, '#');
638644
smart_str_append_long(&str, num);
639-
smart_str_appends(&str, " {main}");
645+
smart_str_appends(&str, Z_TYPE_P(fiber) == IS_TRUE ? " {fiber}" : " {main}");
640646
smart_str_0(&str);
641647

642648
RETURN_NEW_STR(str.s);

Zend/zend_exceptions.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Exception implements Throwable
3434
protected $line = null;
3535
private array $trace = [];
3636
private ?Throwable $previous = null;
37+
private bool $fiber = false;
3738

3839
final private function __clone(): void {}
3940

@@ -91,6 +92,7 @@ class Error implements Throwable
9192
protected $line = null;
9293
private array $trace = [];
9394
private ?Throwable $previous = null;
95+
private bool $fiber = false;
9496

9597
/** @implementation-alias Exception::__clone */
9698
final private function __clone(): void {}

Zend/zend_exceptions_arginfo.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: f322ba2ed3e636b6e99400edfbff98102b7e3d06 */
2+
* Stub hash: 419a4fbca0e2c95b8a2f71597fab4625a15aa0b4 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0)
55
ZEND_END_ARG_INFO()
@@ -248,6 +248,12 @@ static zend_class_entry *register_class_Exception(zend_class_entry *class_entry_
248248
zend_declare_typed_property(class_entry, property_previous_name, &property_previous_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_CLASS(property_previous_class_Throwable, 0, MAY_BE_NULL));
249249
zend_string_release(property_previous_name);
250250

251+
zval property_fiber_default_value;
252+
ZVAL_BOOL(&property_fiber_default_value, 0);
253+
zend_string *property_fiber_name = zend_string_init("fiber", sizeof("fiber") - 1, 1);
254+
zend_declare_typed_property(class_entry, property_fiber_name, &property_fiber_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
255+
zend_string_release(property_fiber_name);
256+
251257
return class_entry;
252258
}
253259

@@ -312,6 +318,12 @@ static zend_class_entry *register_class_Error(zend_class_entry *class_entry_Thro
312318
zend_declare_typed_property(class_entry, property_previous_name, &property_previous_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_CLASS(property_previous_class_Throwable, 0, MAY_BE_NULL));
313319
zend_string_release(property_previous_name);
314320

321+
zval property_fiber_default_value;
322+
ZVAL_BOOL(&property_fiber_default_value, 0);
323+
zend_string *property_fiber_name = zend_string_init("fiber", sizeof("fiber") - 1, 1);
324+
zend_declare_typed_property(class_entry, property_fiber_name, &property_fiber_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
325+
zend_string_release(property_fiber_name);
326+
315327
return class_entry;
316328
}
317329

Zend/zend_string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ EMPTY_SWITCH_DEFAULT_CASE()
555555
_(ZEND_STR_WAKEUP, "__wakeup") \
556556
_(ZEND_STR_CASES, "cases") \
557557
_(ZEND_STR_FROM, "from") \
558+
_(ZEND_STR_FIBER, "fiber") \
558559
_(ZEND_STR_TRYFROM, "tryFrom") \
559560
_(ZEND_STR_TRYFROM_LOWERCASE, "tryfrom") \
560561
_(ZEND_STR_AUTOGLOBAL_SERVER, "_SERVER") \

0 commit comments

Comments
 (0)