On Mon, Mar 12, 2018 at 12:16 PM, Richard Klingler <rich...@klingler.net> wrote: > ZEND_FUNCTION(readmydevice) > { > zend_long n; > zval *z; > size_t len; > char *p; > long r; > > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lzl", &n, > &z, &len) == FAILURE) { > return; > } > > p = (char *) emalloc(len + 1); > memset(p,0,len+1); > > r = myread(n, p, len); > printf("Read %d bytes from device %d up to %d bytes\n", mycount, > n, len); > p[ibcnt] = '\0'; > ZVAL_STRINGL(z, p, mycount); > printf("Returned %s\n", p); > efree(p); > RETURN_LONG(r); > } > > > Any ideas why ZVAL_STRINGL is not doing anything? > Or did I miss something? > Well, ZVAL_STRINGL is probably doing something, but there are two reasons there's no way to be certain:
1. What is 'mycount' and where does it come from / how is it set? If it's zero, then you'll be saving a zero length string. In any case, it doesn't seem to have any relationship to the data read into `p`. I'm guessing you wanted to use `r` rather than `mycount` both here and in your debug message. 2. I'm inferring that you want argument 2 to your function to be a pass-by-ref argument. Are you specifying any arg_info in the function entry list? (where you have your PHP_FE macro -- or perhaps ZEND_FE macro, since you seem to be using those versions). In order to pass by ref, you need that structure to specify that the argument is by-ref. This *might* have worked without it in PHP 5, but only by accident and would have probably failed in hard-to-diagnose ways. 2a. Also, when using by-ref args, you need to destruct any previously held value. In this case, with a zval_dtor(z); prior to the ZVAL_STRINGL() macro. -Sara -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php