/* {{{ php_foreach_all */ static int php_foreach_all (int instatus, char *inkey, int inkeylen, char *inval, int invallen, char *indata) { int is_stop = 0; zval *args; zval *retval; TSRMLS_FETCH(); MAKE_STD_ZVAL(args); array_init(args); add_index_long(args, 0, instatus); add_index_stringl(args, 1, inkey, inkeylen, 1); add_index_stringl(args, 2, inval, invallen, 1); php_yp_all_callback *cb = (php_yp_all_callback *) indata; zend_fcall_info_args(&cb->fci, args TSRMLS_CC); zend_fcall_info_call(&cb->fci, &cb->fcc, &retval, args TSRMLS_CC); zend_fcall_info_args_clear(&cb->fci, 1); if (retval) { is_stop = zval_is_true(retval); zval_ptr_dtor(&retval); } return is_stop; }
static zval *oauth_provider_call_cb(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ { php_oauth_provider *sop; php_oauth_provider_fcall *cb = NULL; zval args, *pthis; char *errstr = ""; zend_string *callable = NULL; pthis = getThis(); sop = fetch_sop_object(pthis); switch(type) { case OAUTH_PROVIDER_CONSUMER_CB: cb = sop->consumer_handler; errstr = "Consumer key/secret handler not specified, did you set a valid callback via OAuthProvider::consumerHandler()?"; break; case OAUTH_PROVIDER_TOKEN_CB: cb = sop->token_handler; errstr = "Token handler not specified, did you set a valid callback via OAuthProvider::tokenHandler()?"; break; case OAUTH_PROVIDER_TSNONCE_CB: cb = sop->tsnonce_handler; errstr = "Timestamp/nonce handler not specified, did you set a valid callback via OAuthProvider::timestampNonceHandler()?"; break; default: php_error_docref(NULL, E_ERROR, "Invalid callback type for OAuthProvider"); return NULL; } if(!cb) { php_error_docref(NULL, E_ERROR, "%s", errstr); return NULL; } array_init(&args); add_next_index_zval(&args, pthis); Z_ADDREF_P(pthis); Z_ADDREF(args); errstr = NULL; if (!zend_is_callable(&cb->fcall_info->function_name, 0, &callable)) { if (errstr) { php_error_docref(NULL, E_WARNING, "Invalid callback: %s, %s", Z_STRVAL(cb->fcall_info->function_name), errstr); efree(errstr); } else { php_error_docref(NULL, E_WARNING, "Invalid callback: %s.", Z_STRVAL(cb->fcall_info->function_name)); } } else if (errstr) { php_error_docref(NULL, E_WARNING, "%s", errstr); efree(errstr); } if (zend_fcall_info_call(cb->fcall_info, &cb->fcall_info_cache, return_value, &args)!=SUCCESS) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Failed calling callback %s", Z_STRVAL(cb->fcall_info->function_name)); } zval_ptr_dtor(&args); return return_value; }
/* {{{ proto resource clmandelbrot(int width, int height[, float unit]) */ static PHP_FUNCTION(clmandelbrot) { long width = 0; long height = 0; double unit = 0.0; long device = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; zval *zim = NULL, *callable, *args, *zwidth, *zheight; int err; gdImagePtr im; RETVAL_FALSE; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|dl", &width, &height, &unit, &device) == FAILURE) { return; } MAKE_STD_ZVAL(callable); ZVAL_STRING(callable, "imagecreatetruecolor", 1); err = zend_fcall_info_init(callable, 0, &fci, &fcc, NULL, NULL TSRMLS_CC); if (err != SUCCESS) { zval_ptr_dtor(&callable); return; } MAKE_STD_ZVAL(args); MAKE_STD_ZVAL(zwidth); MAKE_STD_ZVAL(zheight); ZVAL_LONG(zwidth, width); ZVAL_LONG(zheight, height); array_init(args); add_next_index_zval(args, zwidth); add_next_index_zval(args, zheight); zend_fcall_info_call(&fci, &fcc, &zim, args TSRMLS_CC); zval_ptr_dtor(&callable); zval_ptr_dtor(&args); if (!zim) { return; } ZEND_FETCH_RESOURCE_NO_RETURN(im, gdImagePtr, &zim, -1, "Image", phpi_get_le_gd()); if (im) { size_t len; clmandelbrot_t ctx = { 0 }; ctx.deviceId = (cl_uint)device; ctx.width = gdImageSX(im); ctx.height = gdImageSY(im); if (unit > 0.0) { ctx.unit = (float)unit; } else { ctx.unit = 10.0f / (float)(ctx.width + ctx.height); } len = ctx.width * ctx.height; ctx.bitmap = ecalloc(len, sizeof(unsigned char)); if (!ctx.bitmap) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot allocate memory"); } else { if (clm_process(im, &ctx TSRMLS_CC) == SUCCESS) { RETVAL_ZVAL(zim, 1, 0); } } clm_release(&ctx); } zval_ptr_dtor(&zim); }