Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96377 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68962 invoked from network); 15 Oct 2016 09:22:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Oct 2016 09:22:27 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.176 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.213.176 mail-yb0-f176.google.com Received: from [209.85.213.176] ([209.85.213.176:34253] helo=mail-yb0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/C0-59423-355F1085 for ; Sat, 15 Oct 2016 05:22:27 -0400 Received: by mail-yb0-f176.google.com with SMTP id o189so24863308yba.1 for ; Sat, 15 Oct 2016 02:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=9X3bUyb0gLy5sEih/NhPK6n5pqtZlfM3aNRoTcRkKRQ=; b=I1ZthTBk35i2tc1ZG8L5utSCBg35BYKC8jKolMXCB4UA0UartQZq41MRtX+TXjc26V oqQ1vhgIw1vb4/mIry6+4G9KKsrq1cOWXy0lU/qf42KJ7la+IrtlF+DP+OvjWgfg0ngB RyENkhBDcjCl3CvKp+n8/RDaKJU2Myq8c04yDi3mkeU4QX9Nheq3lJyw63263JwCqWLu 5oNQkhVZOPoTa34sIabqO/oSpQqm2N3vKLX2ApkdJ9umvkIPc66wijBxDt0V9EC0CQen v/FIHrpkQHgkerVnJZ/lJDNsqgxv6UoQYC62eivbqqlkmqS/SwXd4NNtSBmTtxRUDtPR iv1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=9X3bUyb0gLy5sEih/NhPK6n5pqtZlfM3aNRoTcRkKRQ=; b=ihuxDkxQRd95TCJfn5xXZJ+GqEXcnx3cl9Qx1bvoNMBbT59IaKO172dNFrCyuh24Uh 3qtVIRxjl0MyNTXsjOfc56IEf0gp70Ahi311gjBVD1gZl6gy13UkYz2mQ2sKqqKMYsXK k+mab6ktjOWQEfNK148RBl2p0TxuZjNqpmGiSlNAMjzTfCHnQG8BkbPueNphu5onO10W ogZ2W5cvG1luMgvIEYEyJ2CSnKdY26NXP4vB7tHCUHsr4nqwx414Dd29wXOasEY37Lyf 3N6SkY6ytPVe6xheU9u5Q3z0wiruqG5L8Lr79k8wvAykIyHw62p3OYT8PjtXHkBK5B1h iBxg== X-Gm-Message-State: AA6/9Rlaq8RaQehBzqcJFi7pK1OPD6mayOgDD+X5Oqy5JcZDjAKr/vN+3xn9t8d0LRn6ywNk0RsFt+g0Ks96vg== X-Received: by 10.37.248.34 with SMTP id u34mr14432027ybd.98.1476523344895; Sat, 15 Oct 2016 02:22:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.13.219.12 with HTTP; Sat, 15 Oct 2016 02:22:24 -0700 (PDT) In-Reply-To: References: Date: Sat, 15 Oct 2016 11:22:24 +0200 Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f403045dc87a79a1c2053ee3e1b0 Subject: Re: [PHP-DEV] Best practice of initializing zval array hash? From: nikita.ppv@gmail.com (Nikita Popov) --f403045dc87a79a1c2053ee3e1b0 Content-Type: text/plain; charset=UTF-8 On Sat, Oct 15, 2016 at 8:23 AM, Yasuo Ohgaki wrote: > 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. > Are you looking for ZVAL_ARR()? Nikita --f403045dc87a79a1c2053ee3e1b0--