Created
April 25, 2016 16:24
-
-
Save abiusx/4c21899a2e73ce5352d1a119ed271daf to your computer and use it in GitHub Desktop.
An implementation of zval_id in C for PHP extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZEND_BEGIN_ARG_INFO_EX(phpx_byref_arginfo, | |
1 /*pass_rest_by_reference*/, | |
0/*return_reference*/, | |
1/*required_num_args*/) | |
ZEND_ARG_PASS_INFO(1/*by_ref*/) | |
ZEND_END_ARG_INFO(); | |
PHP_FUNCTION(zval_id) | |
{ | |
//computes the address of first zval sent to it, | |
//and the remainder are ided after it. | |
zval *z; | |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"z",&z)==FAILURE) | |
return; | |
long id=*(( long*)(&z->value)); //return_value will become the address | |
static long base=0; | |
if (base==0) base=id-1; | |
id=(id^base)>>3; //zval is at least 16 bytes | |
RETURN_LONG(id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment