Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

hashtable - why the marco "ZVAL_COPY_VALUE(z,v)" seems to work unexpectly in PHP Internal?

My question is about HashTable:

The PHP VERSION debugged is PHP-7.0.12, i coundn't find out where the zval's str member is updated within the macro "ZVAL_COPY_VALUE(z, v)" when i add one new string, however it indeed updated successfuly by GDB trcacing the macro context, that is to say, the zval's str member within the Bucket struct indeed had got the string address.

Expand the macro then finally get the code as follow:

zval *_z1 = z; 
const zval *_z2 = v; 
zend_refcounted *_gc = (*_z2).value.counted      
uint32_t _t = (*_z2).u1.type_info;
uint32_t _w2 = _z2->value.ww.w2; 
(*_z1).value.counted = _gc;
_z1->value.ww.w2 = _w2;
(*_z1).u1.type_info = _t;

Any help will be appreciated very much, thks.

question from:https://stackoverflow.com/questions/65858459/why-the-marco-zval-copy-valuez-v-seems-to-work-unexpectly-in-php-internal

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

zend_value is a union type, which means that all members share the same starting address. Copying both value.counted and value.ww.w2 copies the whole zend_value structure. It does not matter which of the members is actually in use at the time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...