Skip to content

Instantly share code, notes, and snippets.

@abiusx
Created April 25, 2016 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abiusx/4c21899a2e73ce5352d1a119ed271daf to your computer and use it in GitHub Desktop.
Save abiusx/4c21899a2e73ce5352d1a119ed271daf to your computer and use it in GitHub Desktop.
An implementation of zval_id in C for PHP extensions
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