Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96376 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62073 invoked from network); 15 Oct 2016 06:23:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Oct 2016 06:23:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@ohgaki.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@ohgaki.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ohgaki.net designates 180.42.98.130 as permitted sender) X-PHP-List-Original-Sender: yohgaki@ohgaki.net X-Host-Fingerprint: 180.42.98.130 ns1.es-i.jp Received: from [180.42.98.130] ([180.42.98.130:59239] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 19/20-59423-77BC1085 for ; Sat, 15 Oct 2016 02:23:54 -0400 Received: (qmail 6899 invoked by uid 89); 15 Oct 2016 06:23:48 -0000 Received: from unknown (HELO mail-qt0-f171.google.com) (yohgaki@ohgaki.net@209.85.216.171) by 0 with ESMTPA; 15 Oct 2016 06:23:48 -0000 Received: by mail-qt0-f171.google.com with SMTP id s49so86765287qta.0 for ; Fri, 14 Oct 2016 23:23:47 -0700 (PDT) X-Gm-Message-State: AA6/9RkCLb4FoWYbnsLZbHiGR185YZInVQft3gyC4h+BAg2S5H8dhJHFKYq9TIH1BSs6ejfdtLOEsmRN5zxAHQ== X-Received: by 10.200.54.144 with SMTP id a16mr14142039qtc.126.1476512621775; Fri, 14 Oct 2016 23:23:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.84.168 with HTTP; Fri, 14 Oct 2016 23:23:01 -0700 (PDT) Date: Sat, 15 Oct 2016 15:23:01 +0900 X-Gmail-Original-Message-ID: Message-ID: To: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Best practice of initializing zval array hash? From: yohgaki@ohgaki.net (Yasuo Ohgaki) Hi all, I'm wandering what is the best practice of zval array hash initialization. Following code leaks 56 bytes on ZVAL_NEW_ARR() chash = php_mb_convert_encoding_recursive(HASH_OF(entry), _to_encoding, _from_encodings); if (chash) { ZVAL_NEW_ARR(&entry_tmp); // _array_init() is called. Should leak by next line. Z_ARRVAL(entry_tmp) = chash; } I thought there would be API that replaces or initialize ZVAL array hash to existing hash, but I couldn't find one. So I fixed above code like chash = php_mb_convert_encoding_recursive(HASH_OF(entry), _to_encoding, _from_encodings); if (chash) { Z_TYPE_INFO(entry_tmp) = IS_ARRAY_EX; Z_ARRVAL(entry_tmp) = chash; } I used IS_ARRAY_EX like ZVAL_NEW_ARR(). However, this code seemed a little strange to me, so I grepped source tree and found no other .c code uses IS_ARRAY_EX. What's the best practice for this? It seems API does not expect to replace zval array hash by existing hash. Should I pass entry_tmp to php_mb_covert_encoding_recursive() instead? i.e. ZVAL_NEW_ARR(&entry_tmp); php_mb_convert_encoding_recursive(HASH_OF(&entry_tmp), HASH_OF(entry), _to_encoding, _from_encodings); Thank you. -- Yasuo Ohgaki yohgaki@ohgaki.net