On Mon, Nov 17, 2014 at 10:25 AM, Dmitry Stogov <dmi...@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

Reply via email to