Re: Best practice of initializing zval array hash?

From: Date: Sat, 15 Oct 2016 09:22:24 +0000
Subject: Re: Best practice of initializing zval array hash?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-96377@lists.php.net to get a copy of this message
On Sat, Oct 15, 2016 at 8:23 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> 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

« previous php.internals (#96377) next »