コード例 #1
0
/* {{{ MongoCursor->getCursorInfo: Return information about the current query (by @crodas)
 */
PHP_METHOD(MongoCursor, info)
{
  mongo_cursor *cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC);
  MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor);
  array_init(return_value);

  add_assoc_string(return_value, "ns", cursor->ns, 1);
  add_assoc_long(return_value, "limit", cursor->limit);
  add_assoc_long(return_value, "batchSize", cursor->batch_size);
  add_assoc_long(return_value, "skip", cursor->skip);
  if (cursor->query) {
    add_assoc_zval(return_value, "query", cursor->query);
    zval_add_ref(&cursor->query);
  } else {
    add_assoc_null(return_value, "query");
  }
  if (cursor->fields) {
    add_assoc_zval(return_value, "fields", cursor->fields);
    zval_add_ref(&cursor->fields);
  } else {
    add_assoc_null(return_value, "fields");
  }
    
  add_assoc_bool(return_value, "started_iterating", cursor->started_iterating);
  if (cursor->started_iterating) {
    add_assoc_long(return_value, "id", (long)cursor->cursor_id);
    add_assoc_long(return_value, "at", cursor->at);
    add_assoc_long(return_value, "numReturned", cursor->num);
    add_assoc_string(return_value, "server", cursor->server->label, 1);
  }
}
コード例 #2
0
static void
populate_result_for_get_exists_many(as_key *key_p, zval *outer_container_p,
        zval *inner_container_p, as_error *error_p, bool null_flag TSRMLS_DC)
{
    if (!(as_val*)(key_p->valuep)) {
        if (!null_flag) {
            if (0 != add_assoc_zval(outer_container_p, (char *) key_p->digest.value, inner_container_p)) {
                PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                        "Unable to get key of a record");
                DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
            }
        } else {
            if (0 != add_assoc_null(outer_container_p, (char *) key_p->digest.value)) {
                PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                        "Unable to get key of a record");
                DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
            }
        }
    } else {
        switch (((as_val*)(key_p->valuep))->type) {
            case AS_STRING:
                if (!null_flag) {
                    if (0 != add_assoc_zval(outer_container_p, key_p->value.string.value, inner_container_p)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                } else {
                    if (0 != add_assoc_null(outer_container_p, key_p->value.string.value)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                }
                break;
            case AS_INTEGER:
                if (!null_flag) {
                    if (FAILURE == add_index_zval(outer_container_p, key_p->value.integer.value,
                                inner_container_p)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                } else {
                    if (0 != add_index_null(outer_container_p, key_p->value.integer.value)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                }
                break;
            default:
                break;
        }
    }
}
コード例 #3
0
/* {{{ php_parsekit_parse_op */
static void php_parsekit_parse_op(zval *return_value, zend_op_array *op_array, zend_op *op, long options TSRMLS_DC)
{
	zval *result, *op1, *op2;
	long flags = 0;

	array_init(return_value);

	/* op->handler */
	add_assoc_long(return_value, "address", (unsigned int)(&(op->opcode)));
	add_assoc_long(return_value, "opcode", op->opcode);
	add_assoc_string(return_value, "opcode_name", php_parsekit_define_name_ex(op->opcode, php_parsekit_opcode_names, &flags, PHP_PARSEKIT_OPCODE_UNKNOWN) , 1);
	add_assoc_long(return_value, "flags", flags);

	/* args: result, op1, op2 */
	if ((options & PHP_PARSEKIT_ALL_ELEMENTS) ||
		(flags & PHP_PARSEKIT_RESULT_USED)) {
		MAKE_STD_ZVAL(result);
		php_parsekit_parse_node(result, op_array, &(op->result), flags & PHP_PARSEKIT_RESULT_USED, options TSRMLS_CC);
		add_assoc_zval(return_value, "result", result);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "result");
	}

	if ((options & PHP_PARSEKIT_ALL_ELEMENTS) ||
		(flags & PHP_PARSEKIT_OP1_USED)) {
		MAKE_STD_ZVAL(op1);
		php_parsekit_parse_node(op1, op_array, &(op->op1), flags & PHP_PARSEKIT_OP1_USED, options TSRMLS_CC);
		add_assoc_zval(return_value, "op1", op1);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "op1");
	}

	if ((options & PHP_PARSEKIT_ALL_ELEMENTS) ||
		(flags & PHP_PARSEKIT_OP2_USED)) {
		MAKE_STD_ZVAL(op2);
		php_parsekit_parse_node(op2, op_array, &(op->op2), flags & PHP_PARSEKIT_OP2_USED, options TSRMLS_CC);
		add_assoc_zval(return_value, "op2", op2);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "op2");
	}

	if ((options & PHP_PARSEKIT_ALL_ELEMENTS) ||
		(flags & PHP_PARSEKIT_EXTENDED_VALUE)) {
		add_assoc_long(return_value, "extended_value", op->extended_value);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "extended_value");
	}

	add_assoc_long(return_value, "lineno", op->lineno);
}
コード例 #4
0
ファイル: posix.c プロジェクト: RyanNerd/php-src
/* Takes a pointer to posix group and a pointer to an already initialized ZVAL
 * array container and fills the array with the posix group member data. */
int php_posix_group_to_array(struct group *g, zval *array_group) /* {{{ */
{
	zval array_members;
	int count;

	if (NULL == g)
		return 0;

	if (array_group == NULL || Z_TYPE_P(array_group) != IS_ARRAY)
		return 0;

	array_init(&array_members);

	add_assoc_string(array_group, "name", g->gr_name);
	if (g->gr_passwd) {
		add_assoc_string(array_group, "passwd", g->gr_passwd);
	} else {
		add_assoc_null(array_group, "passwd");
	}
	for (count = 0; g->gr_mem[count] != NULL; count++) {
		add_next_index_string(&array_members, g->gr_mem[count]);
	}
	zend_hash_str_update(Z_ARRVAL_P(array_group), "members", sizeof("members")-1, &array_members);
	add_assoc_long(array_group, "gid", g->gr_gid);
	return 1;
}
コード例 #5
0
ファイル: plphp_io.c プロジェクト: avsmips/PL-php
/*
 * plphp_zval_from_tuple
 *		 Build a PHP hash from a tuple.
 */
zval *
plphp_zval_from_tuple(HeapTuple tuple, TupleDesc tupdesc)
{
	int			i;
	char	   *attname = NULL;
	zval	   *array;

	MAKE_STD_ZVAL(array);
	array_init(array);

	for (i = 0; i < tupdesc->natts; i++)
	{
		char *attdata;

		/* Get the attribute name */
		attname = tupdesc->attrs[i]->attname.data;

		/* and get its value */
		if ((attdata = SPI_getvalue(tuple, tupdesc, i + 1)) != NULL)
		{
			/* "true" means strdup the string */
			add_assoc_string(array, attname, attdata, true);
			pfree(attdata);
		}
		else
			add_assoc_null(array, attname);
	}
	return array;
}
コード例 #6
0
ファイル: status.c プロジェクト: eixom/zoeeyphp
/** {{{ public ZeStatus::toArray()
 */
PHP_METHOD(ze_status, toArray) {
	zval *   self        = NULL;
	zval *   array       = NULL;
	zval *   label       = NULL;
	zval *   name        = NULL;
	zval *   brief       = NULL;

	self = getThis();

	label = zend_read_property(ze_status_ce, self, ZEND_STRL(ZE_LABEL), 0 TSRMLS_CC);
	name  = zend_read_property(ze_status_ce, self, ZEND_STRL(ZE_NAME) , 1 TSRMLS_CC);
	brief = zend_read_property(ze_status_ce, self, ZEND_STRL(ZE_BRIEF), 1 TSRMLS_CC);

	MAKE_STD_ZVAL(array);
	array_init(array);

	Z_ADDREF_P(label);
	add_assoc_zval(array, "label", label);

	if (name){

	   Z_ADDREF_P(name);
	   add_assoc_zval(array, "name", name);
	} else {

	   add_assoc_null(array, "name");
	}
	if (brief){

	   Z_ADDREF_P(brief);
	   add_assoc_zval(array, "brief", brief);
	} else {

	   add_assoc_null(array, "brief");
	}
	
	RETURN_ZVAL(array, 1, 1);

}
コード例 #7
0
ファイル: scanner_API.c プロジェクト: neorem/phpmeta
/* {{{ META_API void meta_token_zval_ex(TOKEN*, zval*)
 * create an array representation of token into the preallocated tok_repr */
META_API void meta_token_zval_ex(TOKEN *token, zval *tok_repr) {
    array_init_size(tok_repr, 8);/* 8 inwhich allow this to happenstead of 5, so zend_hash_init doesn't need to round up */
    add_assoc_long(tok_repr, "major", token->major);
    add_assoc_bool(tok_repr, "dirty", token->dirty);
    add_assoc_long(tok_repr, "start_line", token->start_line);
    add_assoc_long(tok_repr, "end_line", token->end_line);
    if(NULL != TOKEN_MINOR(token)) {
        //zval_add_ref(&token->minor);
        add_assoc_zval(tok_repr, "minor", token->minor);
    }
    else {
        add_assoc_null(tok_repr, "minor");
    }
}
コード例 #8
0
ファイル: scanner_API.c プロジェクト: neorem/phpmeta
/* {{{ META_API zval* meta_token_zval(TOKEN*)
 * Get the zval representation of a token */
META_API zval* meta_token_zval(TOKEN *token) {
    zval* tok_repr;
    MAKE_STD_ZVAL(tok_repr);
    array_init_size(tok_repr, 8);/* 8 instead of 5, so zend_hash_init doesn't need to round up */
    add_assoc_long(tok_repr, "major", token->major);
    add_assoc_bool(tok_repr, "dirty", token->dirty);
    add_assoc_long(tok_repr, "start_line", token->start_line);
    add_assoc_long(tok_repr, "end_line", token->end_line);
    if(NULL != TOKEN_MINOR(token)) {
        zval_add_ref(&token->minor);
        add_assoc_zval(tok_repr, "minor", token->minor);
    }
    else {
        add_assoc_null(tok_repr, "minor");
    }
    return tok_repr;
}
コード例 #9
0
    void KPHPArrayObject::AddKrollValueToPHPArray(KValueRef value, zval *phpArray, const char *key)
    {
        if (value->IsNull() || value->IsUndefined())
        {
            add_assoc_null(phpArray, (char *) key);
        }
        else if (value->IsBool())
        {
            if (value->ToBool())
                add_assoc_bool(phpArray, (char *) key, 1);
            else
                add_assoc_bool(phpArray, (char *) key, 0);
        }
        else if (value->IsNumber())
        {
            /* No way to check whether the number is an
               integer or a double here. All Kroll numbers
               are doubles, so return a double. This could
               cause some PHP to function incorrectly if it's
               doing strict type checking. */
            add_assoc_double(phpArray, (char *) key, value->ToNumber());
        }
        else if (value->IsString())
        {
            add_assoc_stringl(phpArray, (char *) key, (char *) value->ToString(), strlen(value->ToString()), 1);
        }
        else if (value->IsObject())
        {
            /*TODO: Implement*/
        }
        else if (value->IsMethod())
        {
            /*TODO: Implement*/
        }
        else if (value->IsList())
        {
            zval *phpValue;
            AutoPtr<KPHPArrayObject> pl = value->ToList().cast<KPHPArrayObject>();
            if (!pl.isNull())
                phpValue = pl->ToPHP();
            else
                phpValue = PHPUtils::ToPHPValue(value);

            add_assoc_zval(phpArray, (char *) key, phpValue);
        }
    }
コード例 #10
0
/* {{{ clm_get_platform_info() */
static zval *clm_get_platform_info(cl_platform_id platform TSRMLS_DC)
{
	const platform_info_param_t *param = platform_info_list;
	cl_int err = CL_SUCCESS;
	char buf[1024] = { 0 };
	size_t len = 0;
	zval *zinfo;

	MAKE_STD_ZVAL(zinfo);
	array_init_size(zinfo, 8);

	while (param->key != NULL) {
		err = clGetPlatformInfo(platform, param->name, sizeof(buf), buf, &len);
		if (err == CL_SUCCESS) {
			add_assoc_stringl(zinfo, param->key, buf, len, 1);
		} else {
			add_assoc_null(zinfo, param->key);
		}
		param++;
	}

	return zinfo;
}
コード例 #11
0
/* {{{ php_parsekit_parse_arginfo */
static void php_parsekit_parse_arginfo(zval *return_value, zend_uint num_args, zend_arg_info *arginfo, long options TSRMLS_DC)
{
	zend_uint i;

	array_init(return_value);

	for(i = 0; i < num_args; i++) {
		zval *tmpzval;

		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		add_assoc_stringl(tmpzval, "name", arginfo[i].name, arginfo[i].name_len, 1);
		if (arginfo[i].class_name_len) {
			add_assoc_stringl(tmpzval, "class_name", arginfo[i].class_name, arginfo[i].class_name_len, 1);
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(tmpzval, "class_name");
		}
		add_assoc_bool(tmpzval, "allow_null", arginfo[i].allow_null);
		add_assoc_bool(tmpzval, "pass_by_reference", arginfo[i].pass_by_reference);

		add_next_index_zval(return_value, tmpzval);
	}	
}
コード例 #12
0
ファイル: observe.c プロジェクト: gigablah/php-ext-couchbase
/**
 * Populates key-details for an oks structure
 */
static void oks_to_zvarray(struct observe_keystate *oks, zval *arry)
{
	add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_RESPONSES, oks->got.resp);
	add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_REPLICAS, oks->got.replicate);
	add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_PERSISTS, oks->got.persist);
	add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_TTR, oks->got.ttr);
	add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_TTP, oks->got.ttp);

	if (oks->got.errstr) {
		zval *zvtmp;
		ALLOC_INIT_ZVAL(zvtmp);
		ZVAL_STRING(zvtmp, oks->got.errstr, 0);
		add_assoc_zval(arry, COUCHBASE_OBSERVE_RESKEY_ERRSTR, zvtmp);

		oks->got.errstr = NULL; /* zend takes ownership */

	} else {
		add_assoc_null(arry, COUCHBASE_OBSERVE_RESKEY_ERRSTR);
	}
	if (oks->got.errcode) {
		add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_ERRNUM, oks->got.errcode);
	}
}
コード例 #13
0
ファイル: info.c プロジェクト: aerospike/aerospike-client-php
/* Callback function used for infoMany. Adds the response to an array, if the host info
 * is contained in the filter.
 */
static bool AerospikeClient_Info_each(as_error * err, const as_node * node,
		const char * req, char * res, void * udata) {

	bool should_include;
	info_each_cb_data* cb_data = (info_each_cb_data*)udata;
	if (!node) {
		as_error_update(cb_data->err, AEROSPIKE_ERR_CLIENT, "Null node passed in infoMany");
		return false;
	}

	/* We add the response if there are no hosts to select responses from, or if the list is provided
	 * and this node is one of them
	 */
	should_include = cb_data->filter_hosts ? node_in_hosts_list(node, cb_data->filter_hosts) : true;

	if (should_include) {
		if (res) {
			add_assoc_string(cb_data->response_array, node->name, res);
		} else {
			add_assoc_null(cb_data->response_array, node->name);
		}
	}
	return true;
}
コード例 #14
0
ファイル: jsr_server.c プロジェクト: guoyu07/JsonRPC
PHP_METHOD(jsonrpc_server, execute)
{
  zval *object;
  zval *func;

  zval **func_params, **exec_params;
  zval *data, *payload, *error, *response;
  zval **payload_method, **payload_params;
  zval **id = NULL;

  sapi_header_line ctr = {0};
  smart_str buf = {0};

  zend_bool response_type = 0; // type:0 =>json type:1 => array

  object = getThis();

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b",
    &response_type) == FAILURE)
  {
    return ;
  }
  
  payload = zend_read_property(
      php_jsonrpc_server_entry, getThis(), "payload", sizeof("payload")-1, 0 TSRMLS_CC
    );

  MAKE_STD_ZVAL(error);
  array_init(error);

  MAKE_STD_ZVAL(func);

  ZVAL_STRINGL(func, "jsonformat", sizeof("jsonformat") - 1, 0);
  if (call_user_function(NULL, &object, func, return_value, 0, NULL TSRMLS_CC) == FAILURE){
    php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed calling Jsonrpc_Server::jsonformat()");
    return ;
  }
  if (!Z_BVAL_P(return_value)){
    add_assoc_long(error, "code", -32700);
    add_assoc_string(error, "message", "Parse error", 1);
    
    zval_dtor(return_value);
    array_init(return_value);
    add_assoc_string(return_value, "jsonrpc", "2.0", 1);
    add_assoc_zval(return_value, "error", error);
    goto getresponse;
  }


  ZVAL_STRINGL(func, "rpcformat", sizeof("rpcformat") - 1, 0);
  if (call_user_function(NULL, &object, func, return_value, 0, NULL TSRMLS_CC) == FAILURE){
    php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed calling Jsonrpc_Server::rpcformat()");
    return ;
  }

  if (Z_LVAL_P(return_value) == -32600){
    add_assoc_long(error, "code", -32600);
    add_assoc_string(error, "message", "Invalid Request", 1);
    
    zval_dtor(return_value);
    array_init(return_value);
    add_assoc_string(return_value, "jsonrpc", "2.0", 1);
    add_assoc_zval(return_value, "error", error);
    goto getresponse;
  }else if (Z_LVAL_P(return_value) == -32601){
    add_assoc_long(error, "code", -32601);
    add_assoc_string(error, "message", "Method not found", 1);
   
    zval_dtor(return_value);
    array_init(return_value);
    add_assoc_string(return_value, "jsonrpc", "2.0", 1);
    add_assoc_zval(return_value, "error", error);
    goto getresponse;
  }else if (Z_LVAL_P(return_value) == -32602){
    add_assoc_long(error, "code", -32602);
    add_assoc_string(error, "message", "Invalid params", 1);
    
    zval_dtor(return_value);
    array_init(return_value);
    add_assoc_string(return_value, "jsonrpc", "2.0", 1);
    add_assoc_zval(return_value, "error", error);
    goto getresponse;
  }else if (Z_LVAL_P(return_value) == -32603){
    add_assoc_long(error, "code", -32603);
    add_assoc_string(error, "message", "Internal error", 1);
    
    zval_dtor(return_value);
    array_init(return_value);
    add_assoc_string(return_value, "jsonrpc", "2.0", 1);
    add_assoc_zval(return_value, "error", error);
    goto getresponse;
  }

  exec_params = emalloc(sizeof(zval *) * 2);
  payload = zend_read_property(
      php_jsonrpc_server_entry, getThis(), "payload", sizeof("payload")-1, 0 TSRMLS_CC
    );
  if (zend_hash_find(Z_ARRVAL_P(payload), "method", strlen("method")+1, (void **)&payload_method) == FAILURE)
  {
    php_error_docref(NULL TSRMLS_CC, E_WARNING, "method is not find");
    return ;
  }
  //jsr_dump_zval(*payload_method);
  exec_params[0] = *payload_method;

  if (zend_hash_find(Z_ARRVAL_P(payload), "params", strlen("params")+1, (void **)&payload_params) == FAILURE)
  {
    php_error_docref(NULL TSRMLS_CC, E_WARNING, "params is not find");
    return ;
  }
  //shurrik_dump_zval(*payload_params);
  exec_params[1] = *payload_params;

  MAKE_STD_ZVAL(data);
  ZVAL_STRINGL(func, "executeprocedure", sizeof("executeprocedure") - 1, 0);
  if (call_user_function(NULL, &object, func, data, 2, exec_params TSRMLS_CC) == FAILURE){
    php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed calling Jsonrpc_Server::executeprocedure()");
    return ;
  }

  efree(exec_params);

  if (Z_LVAL_P(data) == -32601){
    add_assoc_long(error, "code", -32601);
    add_assoc_string(error, "message", "Method not found", 1);

    zval_dtor(return_value);
    array_init(return_value);
    add_assoc_string(return_value, "jsonrpc", "2.0", 1);
    add_assoc_zval(return_value, "error", error);
    goto getresponse;
  }

  zval_dtor(return_value);
  array_init(return_value);
  add_assoc_string(return_value, "jsonrpc", "2.0", 1);
  add_assoc_zval(return_value, "result", data);
  goto getresponse;

  return ;

getresponse:
  
  if (Z_TYPE_P(payload) == IS_ARRAY){
    if (!zend_symtable_exists(Z_ARRVAL_P(payload), "id", strlen("id")+1))
    {
    }else {
      
      if (zend_hash_find(Z_ARRVAL_P(payload), "id", strlen("id")+1, (void **)&id ) == FAILURE)
      {
        //php_error_docref(NULL TSRMLS_CC, E_WARNING, "closeure is not expected to be a valid callback");
        //return ;
      }

      if (Z_TYPE_PP(id) == IS_NULL){
        add_assoc_null(return_value, "id");
      }else if(Z_TYPE_PP(id) == IS_STRING){
        convert_to_string(*id);
        add_assoc_string(return_value, "id", Z_STRVAL_PP(id), 0);
      }else if (Z_TYPE_PP(id) == IS_LONG){
        convert_to_long(*id);
        add_assoc_long(return_value, "id", Z_LVAL_PP(id));
      }
    }
  }else {
    add_assoc_null(return_value, "id");
  }
  

  ctr.line = "Content-Type: application/json";
  ctr.line_len = strlen(ctr.line);
  sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);

  /*if (!response_type){
    php_json_encode(&buf, return_value, 0 TSRMLS_CC);
    zval_dtor(return_value);
    zval_dtor(error);

    ZVAL_STRINGL(return_value, buf.c, buf.len, 1);
    smart_str_free(&buf);
  }*/

  if (!response_type){
    exec_params = emalloc(sizeof(zval *) * 1);
    exec_params[0] = return_value;

    ZVAL_STRINGL(func, "Jsonrpc_Yajl::generate", sizeof("Jsonrpc_Yajl::generate") - 1, 0);
    if (call_user_function(EG(function_table), NULL, func, return_value, 1, exec_params TSRMLS_CC) == FAILURE)
    {
      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed calling Jsonrpc_Yajl::generate()");
      return ;
    }

    //ZVAL_STRINGL(return_value, Z_STRVAL_P(return_value), Z_STRLEN_P(return_value), 1);

    zval_dtor(error);
    efree(exec_params);

  }

  efree(func);

  return ;

}
コード例 #15
0
/* {{{ clm_get_device_info() */
static zval *clm_get_device_info(cl_device_id device TSRMLS_DC)
{
	const device_info_param_t *param = device_info_list;
	cl_int err = CL_SUCCESS;
	char buf[1024] = { 0 };
	size_t len = 0;
	cl_uint max_work_item_dimensions = 0;
	zval *zinfo;

	err = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
	                      sizeof(max_work_item_dimensions),
	                      &max_work_item_dimensions, NULL);
	if (err != CL_SUCCESS) {
		max_work_item_dimensions = 0;
	}

	MAKE_STD_ZVAL(zinfo);
	array_init_size(zinfo, 64);

	while (param->key != NULL) {
		switch (param->type) {
			case PARAM_TYPE_BITFIELD: {
				cl_bitfield val = 0;
				err = clGetDeviceInfo(device, param->name, sizeof(val), &val, NULL);
				if (err == CL_SUCCESS) {
					long lval = (long)val;
					add_assoc_long(zinfo, param->key, lval);
				}
			}
			break;

			case PARAM_TYPE_BOOL: {
				cl_bool val = 0;
				err = clGetDeviceInfo(device, param->name, sizeof(val), &val, NULL);
				if (err == CL_SUCCESS) {
					zend_bool bval = (zend_bool)val;
					add_assoc_bool(zinfo, param->key, bval);
				}
			}
			break;

			case PARAM_TYPE_SIZE: {
				size_t val = 0;
				err = clGetDeviceInfo(device, param->name, sizeof(val), &val, NULL);
				if (err == CL_SUCCESS) {
					long lval = (long)val;
					add_assoc_long(zinfo, param->key, lval);
				}
			}
			break;

			case PARAM_TYPE_UINT: {
				cl_uint val = 0;
				err = clGetDeviceInfo(device, param->name, sizeof(val), &val, NULL);
				if (err == CL_SUCCESS) {
					long lval = (long)val;
					add_assoc_long(zinfo, param->key, lval);
				}
			}
			break;

			case PARAM_TYPE_ULONG: {
				cl_ulong val = 0;
				err = clGetDeviceInfo(device, param->name, sizeof(val), &val, NULL);
				if (err == CL_SUCCESS) {
					long lval = (long)val;
					add_assoc_long(zinfo, param->key, lval);
				}
			}
			break;

			case PARAM_TYPE_STRING: {
				err = clGetDeviceInfo(device, param->name, sizeof(buf), buf, &len);
				if (err == CL_SUCCESS) {
					add_assoc_stringl(zinfo, param->key, buf, len, 1);
				}
			}
			break;

			case PARAM_TYPE_PLATFORM: {
				cl_platform_id platform;
				err = clGetDeviceInfo(device, param->name, sizeof(platform), &platform, NULL);
				if (err == CL_SUCCESS) {
					zval *pinfo = clm_get_platform_info(platform TSRMLS_CC);
					add_assoc_zval(zinfo, param->key, pinfo);
				}
			}
			break;

			case PARAM_TYPE_MAX_WORK_ITEM_SIZES: {
				size_t siz = sizeof(size_t) * max_work_item_dimensions;
				size_t *sizes = ecalloc(max_work_item_dimensions, sizeof(size_t));
				if (!sizes) {
					break;
				}

				err = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_SIZES, siz, sizes, NULL);
				if (err == CL_SUCCESS) {
					cl_uint i;
					zval *zsizes;
					MAKE_STD_ZVAL(zsizes);
					array_init_size(zsizes, max_work_item_dimensions);
					for (i = 0; i < max_work_item_dimensions; i++) {
						long lval = (long)sizes[i];
						add_next_index_long(zsizes, lval);
					}
					add_assoc_zval(zinfo, param->key, zsizes);
				}

				efree(sizes);
			}
			break;
		}

		if (err != CL_SUCCESS) {
			add_assoc_null(zinfo, param->key);
		}

		param++;
	}

	return zinfo;
}
コード例 #16
0
/* {{{ php_parsekit_parse_op_array */
static void php_parsekit_parse_op_array(zval *return_value, zend_op_array *ops, long options TSRMLS_DC)
{
	zend_op *op;
	zval *tmpzval;
	int i = 0;

	/* TODO: Reorder / Organize */

	array_init(return_value);

	add_assoc_long(return_value, "type", (long)(ops->type));
	add_assoc_string(return_value, "type_name", php_parsekit_define_name(ops->type, php_parsekit_function_types, PHP_PARSEKIT_FUNCTYPE_UNKNOWN), 1);
	if (ops->function_name) {
		add_assoc_string(return_value, "function_name", ops->function_name, 1);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "function_name");
	}

#ifdef ZEND_ENGINE_2
/* ZE2 op_array members */
	if (ops->scope && ops->scope->name) {
		add_assoc_stringl(return_value, "scope", ops->scope->name, ops->scope->name_length, 1);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "scope");
	}
	add_assoc_long(return_value, "fn_flags", ops->fn_flags);
	if (ops->function_name && ops->prototype) {
		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		add_assoc_long(tmpzval, "type", ops->prototype->type);
		add_assoc_string(return_value, "type_name", php_parsekit_define_name(ops->prototype->type, php_parsekit_function_types, PHP_PARSEKIT_FUNCTYPE_UNKNOWN), 1);
		if (ops->prototype->common.function_name) {
			add_assoc_string(tmpzval, "function_name", ops->prototype->common.function_name, 1);
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(tmpzval, "function_name");
		}
		if (ops->prototype->common.scope && ops->prototype->common.scope->name) {
			add_assoc_stringl(tmpzval, "scope", ops->prototype->common.scope->name, ops->prototype->common.scope->name_length, 1);
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(tmpzval, "scope");
		}
		add_assoc_zval(return_value, "prototype", tmpzval);		
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "prototype");
	}
	add_assoc_long(return_value, "num_args", ops->num_args);
	add_assoc_long(return_value, "required_num_args", ops->required_num_args);
	add_assoc_bool(return_value, "pass_rest_by_reference", ops->pass_rest_by_reference);

	if (ops->num_args && ops->arg_info) {
		MAKE_STD_ZVAL(tmpzval);
		php_parsekit_parse_arginfo(tmpzval, ops->num_args, ops->arg_info, options TSRMLS_CC);
		add_assoc_zval(return_value, "arg_info", tmpzval);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "arg_info");
	}

	if (ops->last_try_catch > 0) {
		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		for(i = 0; i < ops->last_try_catch; i++) {
			zval *tmp_zval;

			MAKE_STD_ZVAL(tmp_zval);
			array_init(tmp_zval);
			add_assoc_long(tmp_zval, "try_op", ops->try_catch_array[i].try_op);
			add_assoc_long(tmp_zval, "catch_op", ops->try_catch_array[i].catch_op);
			add_index_zval(tmpzval, i, tmp_zval);
		}
		add_assoc_zval(return_value, "try_catch_array", tmpzval);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "try_catch_array");
	}

#ifndef ZEND_ACC_CLOSURE
/* PHP<5.3 */
	add_assoc_bool(return_value, "uses_this", ops->uses_this);
#endif
	add_assoc_long(return_value, "line_start", ops->line_start);
	add_assoc_long(return_value, "line_end", ops->line_end);

	if (ops->doc_comment && ops->doc_comment_len) {
		add_assoc_stringl(return_value, "doc_comment", ops->doc_comment, ops->doc_comment_len, 1);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "doc_comment");
	}

#else
/* ZE1 op_array members */

	if (ops->arg_types) {
		zend_uchar *arg_types = ops->arg_types;
		int numargs = *(ops->arg_types);

		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		add_assoc_long(tmpzval, "arg_count", numargs);

		for(i = 0; i < numargs; i++) {
			add_next_index_long(tmpzval, arg_types[i+1]);
		}

		add_assoc_zval(return_value, "arg_types", tmpzval);

		/* Emulated arg_info */
		MAKE_STD_ZVAL(tmpzval);
		php_parsekit_derive_arginfo(tmpzval, ops, options TSRMLS_CC);
		add_assoc_zval(return_value, "arg_info", tmpzval);
	} else {
		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		add_assoc_long(tmpzval, "arg_count", 0);

		add_assoc_zval(return_value, "arg_types", tmpzval);
		add_assoc_null(return_value, "arg_info");
	}

	add_assoc_bool(return_value, "uses_global", ops->uses_globals);
#endif
/* ZE1 and ZE2 */

	add_assoc_bool(return_value, "return_reference", ops->return_reference);
	add_assoc_long(return_value, "refcount", *(ops->refcount));
	add_assoc_long(return_value, "last", ops->last);
	add_assoc_long(return_value, "size", ops->size);
	add_assoc_long(return_value, "T", ops->T);
	add_assoc_long(return_value, "last_brk_cont", ops->last_brk_cont);
	add_assoc_long(return_value, "current_brk_cont", ops->current_brk_cont);
	add_assoc_long(return_value, "backpatch_count", ops->backpatch_count);
	add_assoc_bool(return_value, "done_pass_two", ops->done_pass_two);

	if (ops->last_brk_cont > 0) {
		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		for(i = 0; i < ops->last_brk_cont; i++) {
			zval *tmp_zval;

			MAKE_STD_ZVAL(tmp_zval);
			array_init(tmp_zval);
			add_assoc_long(tmp_zval, "cont", ops->brk_cont_array[i].cont);
			add_assoc_long(tmp_zval, "brk", ops->brk_cont_array[i].brk);
			add_assoc_long(tmp_zval, "parent", ops->brk_cont_array[i].parent);
			add_index_zval(tmpzval, i, tmp_zval);
		}
		add_assoc_zval(return_value, "brk_cont_array", tmpzval);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "brk_cont_array");
	}

	if (ops->static_variables) {
		zval *tmp_zval;

		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		zend_hash_copy(HASH_OF(tmpzval), ops->static_variables, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_zval, sizeof(zval *));
		add_assoc_zval(return_value, "static_variables", tmpzval);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "static_variables");
	}

	if (ops->start_op) {
		char sop[(sizeof(void *) * 2) + 1];

		snprintf(sop, sizeof(sop), "%X", (unsigned int)ops->start_op); 
		add_assoc_string(return_value, "start_op", sop, 1);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "start_op");
	}

	if (ops->filename) {
		add_assoc_string(return_value, "filename", ops->filename, 1);
	} else {
		add_assoc_null(return_value, "filename");
	}

	/* Leave this last, it simplifies readability */
	MAKE_STD_ZVAL(tmpzval);
	array_init(tmpzval);
	for(op = ops->opcodes, i = 0; op && i < ops->size; op++, i++) {
		zval *zop;

		MAKE_STD_ZVAL(zop);
		php_parsekit_parse_op(zop, ops, op, options TSRMLS_CC);
		add_next_index_zval(tmpzval, zop);
	}	
	add_assoc_zval(return_value, "opcodes", tmpzval);

}
コード例 #17
0
/* {{{ php_parsekit_parse_node */
static void php_parsekit_parse_node(zval *return_value, zend_op_array *op_array, znode *node, long flags, long options TSRMLS_DC)
{
	array_init(return_value);
	add_assoc_long(return_value, "type", node->op_type);
	add_assoc_string(return_value, "type_name", php_parsekit_define_name(node->op_type, php_parsekit_nodetype_names, PHP_PARSEKIT_NODETYPE_UNKNOWN), 1);
	if (node->op_type == IS_CONST) {
		zval *tmpzval;
		MAKE_STD_ZVAL(tmpzval);
		*tmpzval = node->u.constant;
		zval_copy_ctor(tmpzval);
		Z_SET_REFCOUNT_P(tmpzval, 1);
		add_assoc_zval(return_value, "constant", tmpzval);
#ifdef IS_CV
/* PHP >= 5.1 */
	} else if (node->op_type == IS_CV) {
		add_assoc_long(return_value, "var", node->u.var);
		add_assoc_stringl(return_value, "varname", op_array->vars[node->u.var].name, op_array->vars[node->u.var].name_len, 1);
#endif
	} else {
		/* IS_VAR || IS_TMP_VAR || IS_UNUSED */
		char sop[(sizeof(void *) * 2) + 1];

		snprintf(sop, (sizeof(void *) * 2) + 1, "%X", (unsigned int)node->u.var); 

		if ((flags & PHP_PARSEKIT_VAR) ||
			(options & PHP_PARSEKIT_ALL_ELEMENTS)) {
			add_assoc_long(return_value, "var", node->u.var / sizeof(temp_variable));
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(return_value, "var");
		}

		if ((flags & PHP_PARSEKIT_OPLINE) ||
			(options & PHP_PARSEKIT_ALL_ELEMENTS)) {
			add_assoc_string(return_value, "opline_num", sop, 1);
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(return_value, "opline_num");
		}

		if ((flags & PHP_PARSEKIT_OPARRAY) ||
			(options & PHP_PARSEKIT_ALL_ELEMENTS)) {
			add_assoc_string(return_value, "op_array", sop, 1);
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(return_value, "op_array");
		}

#ifdef ZEND_ENGINE_2
/* ZE2 Only */
		if ((flags & PHP_PARSEKIT_JMP_ADDR) ||
			(options & PHP_PARSEKIT_ALL_ELEMENTS)) {
			add_assoc_string(return_value, "jmp_addr", sop, 1);
			snprintf(sop, sizeof(sop)-1, "%u",
					((unsigned int)((char*)node->u.var - (char*)op_array->opcodes))/sizeof(zend_op));
			add_assoc_string(return_value, "jmp_offset", sop, 1); 
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(return_value, "jmp_addr");
		}
#endif

		if ((flags & PHP_PARSEKIT_EA_TYPE) ||
			(options & PHP_PARSEKIT_ALL_ELEMENTS)) {
			add_assoc_long(return_value, "EA.type", node->u.EA.type);
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(return_value, "EA.type");
		}
	}
}