-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add wrapper for zend_exec_stringl with exception handling #67
base: master
Are you sure you want to change the base?
Conversation
unsafe { ext_php_rs_executor_globals().as_mut() } | ||
.expect("Static executor globals were invalid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept this private because I don't know in general if this is thread safe. As I understand it, the take_exception
function should be safe.
std::mem::swap(&mut exception_ptr, &mut globals.exception); | ||
|
||
if !exception_ptr.is_null() { | ||
Some(unsafe { Box::from_raw(exception_ptr) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand the php source code, we're responsible for freeing it if we take it.
}; | ||
|
||
/// The main result type which is passed by the library. | ||
pub type Result<T> = std::result::Result<T, Error>; | ||
|
||
/// The main error type which is passed by the library inside the custom | ||
/// [`Result`] type. | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
#[derive(Debug, Clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, what's the benefit of having ordering on an error enum?
Example in use: #[php_function]
pub fn example_eval() -> Result<Vec<String>> {
ext_php_rs::php::eval::eval("['a', 'b', 'c']").unwrap().extract()
} |
Also I suspect this might be a bug, but it seems like wrapped functions are unable to directly return zvals? |
Add a wrapper around eval. This function exposes zend's behaviour (expects an expression which is automatically prepended with "return"), which is different PHP's builtin's behaviour.
I'm not sure if it would make sense to make a PHP equivalent
eval
as well (should be really easy to make), so I don't know if we want to be conservative with the exported name.The eval portion works nicely, but I have no idea how to go from
ZendObject
toPHPException
. Currently working around this by shoving theZendObject
intoError
, but this feels icky.