Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101974 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3562 invoked from network); 13 Mar 2018 07:53:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Mar 2018 07:53:22 -0000 Authentication-Results: pb1.pair.com header.from=richard@klingler.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=richard@klingler.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain klingler.net designates 212.254.248.170 as permitted sender) X-PHP-List-Original-Sender: richard@klingler.net X-Host-Fingerprint: 212.254.248.170 marvin.klingler.net Received: from [212.254.248.170] ([212.254.248.170:34853] helo=marvin.klingler.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/92-24487-17387AA5 for ; Tue, 13 Mar 2018 02:53:22 -0500 Received: from [192.168.178.202] (unknown [81.6.53.70]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by marvin.klingler.net (Postfix) with ESMTPSA id A8732B5630B; Tue, 13 Mar 2018 08:53:18 +0100 (CET) Date: Tue, 13 Mar 2018 08:52:56 +0100 To: Sara Golemon Cc: PHP internals Message-ID: <20180313085256811754.b59ffa5c@klingler.net> In-Reply-To: References: <64.2E.24487.2D7A6AA5@pb1.pair.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: GyazMail version 1.5.19 Subject: Re: [PHP-DEV] Migrating php extension from 5 to 7, ZVAL_STRINGL no value returned From: richard@klingler.net (Richard Klingler) Hello Sara Seems my post to news.php.net went somehow through though my NNTP client complained about errors...anyway (o; "mycount" is defined in here: FUN_ACCESSOR(mycount) Which is the updated by the read function. 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. thanks in advance richard On Mon, 12 Mar 2018 13:18:30 -0400, Sara Golemon wrote: > On Mon, Mar 12, 2018 at 12:16 PM, Richard Klingler > 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