Skip to content

typeof #1932

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 7 commits into from
Closed

typeof #1932

wants to merge 7 commits into from

Conversation

Fleshgrinder
Copy link
Contributor

@Fleshgrinder Fleshgrinder commented Jun 4, 2016

Proposal for a gettype() successor.

@Fleshgrinder
Copy link
Contributor Author

Fleshgrinder commented Jun 4, 2016

I will try to reproduce the build failure on my setup and fix it.

PS: Please do not tell me where the problem is, I would prefer to find it on my own. I already prepared a Linux VM to run the tests similarly to Travis CI.

Previously not enough memory was allocated and it was just pure luck that it worked in my initial tests.
The problem is actually extremely obvious to the experienced C developer.
The allocated memory for the type variable must be freed after it was
copied for returning to userland.
@@ -2563,6 +2564,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_is_callable, 0, 0, 1)
ZEND_ARG_INFO(0, syntax_only)
ZEND_ARG_INFO(1, callable_name)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_typeof, 0, 0, 1)
Copy link
Member

Choose a reason for hiding this comment

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

nit; Use ZEND_RETURN_VALUE instead of 0 in the third arg. It's better for BC and more readable.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think anybody does this in core.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it now, the readability argument directly convinced me.

@nikic nikic added the RFC label Jun 4, 2016
@@ -434,6 +450,135 @@ PHP_FUNCTION(is_callable)
}
/* }}} */

#define RETURN_TYPE_NAME(t) { RETURN_STRINGL(t, sizeof(t) - 1) }
Copy link
Member

Choose a reason for hiding this comment

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

minor; Create interned strings for these return values so that you're not creating a new string on every invocation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would only apply to the extended mode, right? The constants are already constant and the sizeof will be replaced with the actual number anyways during compilation. Just asking to gain a better understanding of C.

Reading up on interned strings now.

More readable and better for BC; according to @sgolemons feedback.
@Fleshgrinder Fleshgrinder mentioned this pull request Jun 7, 2016
5 tasks
@Fleshgrinder
Copy link
Contributor Author

Closing in favor of #1935.

@Fleshgrinder Fleshgrinder deleted the typeof branch April 30, 2017 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants