Re: Use zend_string* for op_array->arg_info[].name and class_name
| From: | Nikita Popov | Date: | Mon, 24 Nov 2014 14:27:30 +0000 |
| Subject: | Re: Use zend_string* for op_array->arg_info[].name and class_name | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79125@lists.php.net to get a copy of this message | ||
On Mon, Nov 17, 2014 at 10:25 AM, Dmitry Stogov <dmitry@zend.com> wrote:
> Hi,
>
> Please review the patch
> https://gist.github.com/dstogov/47a39aff37f0a6441ea0
>
> Thanks. Dmitry.
>
Hi Dmitry, sorry for late reply.
The problem we're trying to solve here is lack of ability to create a
zend_string at compile time. I just tried two ideas how we might be able to
do that, to avoid introducing different arginfos for internal/userland
functions.
My first approach was to create a zend_string as a string literal using
(zend_string *) ("\1\0\0\0" "\6\1\0\0" "\0\0\0\0" "\0\0\0\0"
str) (for
32bit LE) and then update the length in zend_register_functions. However
this didn't work because the string literal ends up in readonly
memprotected memory, so this causes a segfault.
My second approach was to use a C99 compound literal to create a temporary
zend_string-like structure with the correct length:
#define ZEND_STRING_CT(str) \
(zend_string *) (struct { \
uint32_t refcount; uint32_t type_info; \
zend_ulong h; size_t len; \
char val[sizeof(str)]; \
}[1]) {{ 1, IS_STRING | (IS_STR_PERSISTENT << 8), 0, sizeof(str)-1, str
}}
This seems to work fine (patch
https://github.com/nikic/php-src/commit/5d49321cd9728e0cc1c2939432e46159f9a78472).
However it requires C99, which we're currently not allowed to use.
Maybe someone has an idea how this can be done in C89?
Nikita