Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88587 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49677 invoked from network); 30 Sep 2015 21:12:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Sep 2015 21:12:03 -0000 Authentication-Results: pb1.pair.com header.from=zardozrocks@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=zardozrocks@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.172 as permitted sender) X-PHP-List-Original-Sender: zardozrocks@gmail.com X-Host-Fingerprint: 209.85.223.172 mail-io0-f172.google.com Received: from [209.85.223.172] ([209.85.223.172:32952] helo=mail-io0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B2/91-38941-2205C065 for ; Wed, 30 Sep 2015 17:12:02 -0400 Received: by iofh134 with SMTP id h134so63461373iof.0 for ; Wed, 30 Sep 2015 14:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=n8V9VeN8Z0fROwtjmNnA8LGAp5zmAOLg4u/Y3k//RM0=; b=icaRp56uHMty6iuTnsnHpioNI+qWVtF4VAMA9d4e0nAlPQWguIKoKMaRU+xP0quT6p EY/6cAOrP69Y+4TToZr7GDtiYXCZ51l0bXMvZfl3gHloqyuPZNyr/RfqcR5nhqehmx4/ 0khjSnQXwsoKU20gfxwyt/jKbvMr2KNsDG+eVC+w7XOvBAubxuxkl920fb1pPegdDV38 kzeI/NP8M8UfhDnK+I4OOxCchk8d+i96XnJTG+IWdzkksv8pJH1f5m9d9OiiM9EMjSN1 D9olk3vAa5OlQR60fo54epEBMRDpuH2hu5c4vKx2lomDc3nREZm7CNnXYFyuZJu77iCm 1cUw== MIME-Version: 1.0 X-Received: by 10.107.25.71 with SMTP id 68mr6957972ioz.46.1443647519503; Wed, 30 Sep 2015 14:11:59 -0700 (PDT) Received: by 10.107.31.148 with HTTP; Wed, 30 Sep 2015 14:11:59 -0700 (PDT) In-Reply-To: <20150930205857.GA93503@3006.local> References: <20150930205857.GA93503@3006.local> Date: Wed, 30 Sep 2015 14:11:59 -0700 Message-ID: To: internals Content-Type: multipart/alternative; boundary=001a113ff20e94c3a70520fd6163 Subject: Re: [PHP-DEV] good example of unserialization fundamentals? From: zardozrocks@gmail.com (j adams) --001a113ff20e94c3a70520fd6163 Content-Type: text/plain; charset=UTF-8 Thanks for your response. I do follow the concept of macros (and my IDE expands them for me if I need), however, I just want to confirm that it's OK to be using these in a *recursive function*? I'm aware from S. Golemon's book that these (deeply nested) macros also have the effect of incrementing refcounts and such. For instance, I'm sure the RETURN_* macros will break your code if you don't have a zval *return_value defined in the current scope. Are there other caveats or heuristic rules to avoid abusing these macros? OH, and perhaps I forgot to ask with my original post. Can anyone point me to a good example of a function that takes some userland input and recursively interprets it as possibly nested arrays or objects? I've been looking at php_json_decode_ex[0] but it is allocating and freeing memory for utf16/8 converters and JSON_Parser_structs and so on. [0] http://lxr.php.net/xref/PHP_5_6/ext/json/json.c#683 On Wed, Sep 30, 2015 at 1:58 PM, Sean DuBois wrote: > On Wed, Sep 30, 2015 at 01:39:26PM -0700, j adams wrote: > > I have completed a first draft of serialization functionality which is > > intended to be an updated to amfext. It's on github[0] if anyone is > > interested. I would now like to write all the unserialization routines > and > > would like some suggestions from experienced php devs. I've been reading > > Sara Golemon's book, but am still a little unsure. > > > > In particular, I want my userland function, amf_decode to accept as a > > parameter a string (and possibly other args). This is not so difficult > but > > I must call upon another function, php_amf_decode, which needs to be able > > to handle recursive calls. > > > > Something like this: > > > > // userland function > > static PHP_FUNCTION(amf_decode) { > > char *buf; // char buffer, contains serialize data string > > int buf_len, buf_cursor=0; // the length of the buffer > > long flags = 0; > > > > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &buf, > > &buf_len, &flags) == FAILURE) { > > return; > > } > > > > if (!buf_len) { > > RETURN_NULL(); > > } > > > > php_amf_decode(return_value, buf, buf_len, &buf_cursor, flags > > TSRMLS_CC); > > } > > > > // proposed recursive decoding function > > PHP_AMF_API void php_amf_decode(zval *return_value, char *buf, int > buf_len, > > int *buf_cursor, long flags TSRMLS_DC) > > { > > > > // is it safe to use these macros in this recursive function? > > RETVAL_BOOL(1); > > > > // or this > > RETURN_LONG(42); > > > > > > } > > > > > > [0] https://github.com/sneakyimp/amfext > > Yep those are safe! > > RETVAL_* expands out so you don't have to repeat the variable > `return_value` > ZVAL_LONG(return_value, l) > > RETURN_* expands out so you don't have to call return OR specify the > variable `return_value` > ZVAL_LONG(return_value, l) > return; > > Here they are in 5.6 http://lxr.php.net/xref/PHP_5_6/Zend/zend_API.h#618 > --- > > A great tool to look these things up quickly is lxr, sure beats grep! > > http://lxr.php.net/search?q=&defs=RETURN_LONG&refs=&path=&hist=&project=PHP_5_6 > --001a113ff20e94c3a70520fd6163--