Re: Migrating php extension from 5 to 7, ZVAL_STRINGL no value returned

From: Date: Tue, 13 Mar 2018 15:12:29 +0000
Subject: Re: Migrating php extension from 5 to 7, ZVAL_STRINGL no value returned
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-101975@lists.php.net to get a copy of this message
On Tue, Mar 13, 2018 at 3:52 AM, Richard Klingler <richard@klingler.net> wrote: > Hello Sara > The function macro itself is defined as: > > ZEND_FE(readmydevice, NULL) > > So would the arg_info go in here? There isn't any arg_info in the original code. > Yep. You'll want something like this: ZEND_BEGIN_ARG_INFO(arginfo_readmydevice, 0) ZEND_ARG_INFO(0, device) ZEND_ARG_INFO(1, string) ZEND_ARG_INFO(0, length) ZEND_END_ARG_INFO(); ZEND_FUNCTION(readmydevice) { /* do your stuff to build p and mycount */ zval_dtor(z); ZVAL_STRINGL(z, p, mycount); /* finish up */ } zend_function_entry whateveryoucallit[] = { /* other FEs.... */ ZEND_FE(readmydevice, arginfo_readmydevice) /* other FEs... */ ZEND_FE_END }; That "1" in ZEND_ARG_INFO(1, string) is what tells the engine that the argument is pass-by-ref. You should have had this in PHP 5 as well. It *appeared* to work purely by the accident of how you were calling it from userspace. The reality is that you could easily have wound up with memory leaks and/or "randomly" changing values unrelated to your initial variable. I assume your extension isn't open source or you'd have linked it by now, but if you can share it, I'd be happy to offer other suggestions. Based on what I've seen so far, I'm willing to bet there are other small, subtle bugs hiding in there. -Sara P.S. - Side benefit of defining these arginfo structures is that ReflectionFunction will actually give you parameter info now.

« previous php.internals (#101975) next »