On Tue, Mar 13, 2018 at 3:52 AM, Richard Klingler <rich...@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_FUNCTION(readmydevice) {

  /* do your stuff to build p and mycount */

  ZVAL_STRINGL(z, p, mycount);

  /* finish up */

zend_function_entry whateveryoucallit[] = {
    /* other FEs.... */
    ZEND_FE(readmydevice, arginfo_readmydevice)
    /* other FEs... */

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.


P.S. - Side benefit of defining these arginfo structures is that
ReflectionFunction will actually give you parameter info now.

PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to