Re: Re: How do I save TSRMLS_CACHE for a new thread in PHP7?
| From: | Ruslan Osmanov | Date: | Thu, 26 Nov 2015 07:22:23 +0000 |
| Subject: | Re: Re: How do I save TSRMLS_CACHE for a new thread in PHP7? | ||
| References: | 1 2 3 4 5 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-13362@lists.php.net to get a copy of this message | ||
On Wed, 25 Nov 2015 22:45:29 +0100
Ángel González <keisial@gmail.com> wrote:
> On 25/11/15 20:25, Ruslan Osmanov wrote:
> > I'll try to explain the problem.
> >
> > I have a function(let's call it
Attachment: [application/pgp-signature] signature.asc
execF), which is
> > passed to a
> > library(libeio) as a callback. This function is invoked afterwards
> > by the library in separate thread.
> >
> > The function is calling Zend API, particularly ZVAL_STRINGL(). The
> > Zend API uses TSRMLS_CACHE internally. For instance, ZVAL_STRINGL()
> > allocates zend_string which implies using AG() macro. The AG() macro
> > relies on TSRMLS_CACHE.
> >
> > Since TSRMLS_CACHE becomes invalid in new thread, the AG() macro (as
> > well as other macros relying on TSRMLS_CACHE) fails with
> > segmentation fault.
> Why are you allocating a string? Are you expecting to later use it on
> the php request?
> What's the goal of your extension? I suspect you may have an earlier
> misstep.
I'm allocating a string for zend_fcall_info.function_name:
https://goo.gl/MYoJcw (just like zend_call_method). Called by
php_eio_custom_execute().
Well, I can pre-allocate zend_string for the callback. Then a few lines
further I'm trying to fetch EG(function_table), which eventually refers
to TSRMLS_CACHE. Since the latter is invalid, I catch a segmentation
fault, again.
So I'm asking how do I save the context for a thread created by libeio
library.
The flow looks like the following:
1. User passes a callable to eio_custom()
2. The callable is saved as libeio user custom data(void*):
eio_custom(php_eio_custom_execute, pri, php_eio_res_cb_custom, eio_cb);
3. User calls eio_event_loop()
4. Libeio invokes php_eio_custom_execute() *in separate thread*
5. php_eio_custom_execute() unsuccessfully tries to use Zend API
Thanks.
--
Ruslan Osmanov
Attachment: [application/pgp-signature] signature.asc