Skip to content

Add string or object ZPP macros #5788

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

Closed
wants to merge 2 commits into from
Closed

Conversation

kocsismate
Copy link
Member

@kocsismate kocsismate commented Jul 1, 2020

This is a preparation for OpenSSL's resource to object migration where quite a few parameters (e.g. most X.509-related ones) have to be parsed as string|object-of-type (see php_openssl_x509_from_zval()).

Copy link
Member Author

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

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

Is there any existing use-case for these ZPP macros? I can't think of any off the top of my head.

Zend/zend_API.h Outdated
@@ -1972,6 +2016,30 @@ static zend_always_inline int zend_parse_arg_class_name_or_obj(
return 1;
}

static zend_always_inline int zend_parse_arg_str_or_object(
zval *arg, zend_string **destination_string, zval **destination_object, zend_class_entry *base_ce, int allow_null
Copy link
Member Author

@kocsismate kocsismate Jul 1, 2020

Choose a reason for hiding this comment

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

I'm not sure what type the object destination should be. zval **? zend_object **?

Copy link
Member

Choose a reason for hiding this comment

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

I personally would use a zend_object as I find the current behaviour of the object ZPP a bit weird that it returns a zval, but that's only me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed it to zend_object :)

@nikic
Copy link
Member

nikic commented Jul 3, 2020

If we don't have any function to which this would apply right now, I would suggest adding some to zend_test and testing those. Might actually be better to do that than using random functions for zpp tests.

@kocsismate
Copy link
Member Author

Thanks for the suggestion! In my recent commit, I've added such tests, and the macros seem to work fine now.

ZEND_PARSE_PARAMETERS_END();

if (str) {
RETURN_STR(str);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
RETURN_STR(str);
RETURN_STR_COPY(str);

Zend/zend_API.c Outdated
return;
}

zend_argument_type_error(num, "must be of type string|%s, %s given", name, zend_zval_type_name(arg));
Copy link
Member

Choose a reason for hiding this comment

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

I believe the canonical type ordering is %s|string.

Copy link
Member Author

@kocsismate kocsismate Jul 6, 2020

Choose a reason for hiding this comment

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

What about the string|object case? Or that's okay, because object is an internal type?

Copy link
Member

Choose a reason for hiding this comment

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

$ sapi/cli/php -r '(function(string|object $x){})([]);'

Fatal error: Uncaught TypeError: {closure}(): Argument #1 ($x) must be of type object|string, array given

It's object|string as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've just adapted the argument types to follow this order, that's why the new commit.

Zend/zend_API.h Outdated
if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
*destination_string = Z_STR_P(arg);
*destination_object = NULL;
} else if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd move the object case first. I believe in places where it's used it's the "more expected" one.

@php-pulls php-pulls closed this in b18b2c8 Jul 6, 2020
@kocsismate kocsismate deleted the str-or-obj branch July 6, 2020 10:46
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.

3 participants