-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Labels
Description
Description
Code: https://github.com/swoole/phpy/blob/main/src/php/operator.cc#L319
In the phpy extension, we use opcode handlers to implement operator overloading for Python objects. However, when an exception is thrown in the opcode handler function, it causes a crash.
My question is how to safely throw an exception in a custom opcode handler?
#define ZEND_USER_OPCODE_CONTINUE 0 /* execute next opcode */
#define ZEND_USER_OPCODE_RETURN 1 /* exit from executor (return from function) */
#define ZEND_USER_OPCODE_DISPATCH 2 /* call original opcode handler */
#define ZEND_USER_OPCODE_ENTER 3 /* enter into new op_array without recursion */
#define ZEND_USER_OPCODE_LEAVE 4 /* return to calling op_array within the same executor */Which value should be returned?
There is no documentation or example code to refer to, so I can only submit an issue.
php code
$np = PyCore::import('numpy');
$arr = $np->array([3, 4]);
// Custom opcode handler is used here, which calls the Python C API to
// implement the multiplication operation of objects and may throw exceptions.
$arr2 = $arr * 3;
PyCore::print($arr2);