Skip to content

Conversation

vodik
Copy link
Collaborator

@vodik vodik commented Sep 14, 2021

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 to PHPException. Currently working around this by shoving the ZendObject into Error, but this feels icky.

Comment on lines +23 to +24
unsafe { ext_php_rs_executor_globals().as_mut() }
.expect("Static executor globals were invalid")
Copy link
Collaborator Author

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) })
Copy link
Collaborator Author

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 error type which is passed by the library inside the custom
/// [`Result`] type.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone)]
Copy link
Collaborator Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparison.

@vodik
Copy link
Collaborator Author

vodik commented Sep 14, 2021

Example in use:

#[php_function]
pub fn example_eval() -> Result<Vec<String>> {
    ext_php_rs::php::eval::eval("['a', 'b', 'c']").unwrap().extract()
}

@vodik
Copy link
Collaborator Author

vodik commented Sep 14, 2021

Also I suspect this might be a bug, but it seems like wrapped functions are unable to directly return zvals? pub fn example_eval() -> Result<Zval> won't compile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants