예제 #1
0
파일: ast.c 프로젝트: billschaller/php-ast
static void ast_create_virtual_node(
		zval *zv, zend_ast_kind kind, zend_ast *ast, zend_long version) {
	zval tmp_zv, tmp_zv2;

	object_init_ex(zv, ast_node_ce);

	ZVAL_LONG(&tmp_zv, kind);
	ast_update_property(zv, AST_STR(kind), &tmp_zv, AST_CACHE_SLOT_KIND);

	ZVAL_LONG(&tmp_zv, ast->attr);
	ast_update_property(zv, AST_STR(flags), &tmp_zv, AST_CACHE_SLOT_FLAGS);

	ZVAL_LONG(&tmp_zv, zend_ast_get_lineno(ast));
	ast_update_property(zv, AST_STR(lineno), &tmp_zv, AST_CACHE_SLOT_LINENO);

	array_init(&tmp_zv);
	ast_update_property(zv, AST_STR(children), &tmp_zv, AST_CACHE_SLOT_CHILDREN);

	ZVAL_COPY(&tmp_zv2, zend_ast_get_zval(ast));
	if (version >= 30) {
		zend_hash_add_new(Z_ARRVAL(tmp_zv), ast_kind_child_name(kind, 0), &tmp_zv2);
	} else {
		zend_hash_next_index_insert(Z_ARRVAL(tmp_zv), &tmp_zv2);
	}
}
예제 #2
0
파일: source.c 프로젝트: gtkforphp/glib
static gboolean
php_glib_source_prepare(GSource *source, gint *timeout)
{
	gboolean retval = FALSE;
	zend_long php_timeout = -1;
	zval php_retval;
	GPhpSource *glib_source = (GPhpSource*) source;

	glib_source_callback_helper(&php_retval, &glib_source->source_zval, "prepare", NULL, 0);

	/* Our return must be array [retval, timeout]
	   we can cast those values if they're not bool, long
	   but we must have that format ...
	   TODO: return struct instead? */
	if(Z_ISUNDEF(php_retval)
	    || Z_TYPE(php_retval) != IS_ARRAY
		|| zend_array_count(Z_ARRVAL(php_retval)) < 2
		|| zend_hash_index_exists(Z_ARRVAL(php_retval), 0) == FALSE
		|| zend_hash_index_exists(Z_ARRVAL(php_retval), 1) == FALSE) {
		zend_throw_exception(spl_ce_BadFunctionCallException,
			"Prepare must return an array with bool return at [0] and int timeout at [1]", 0);
		if(!Z_ISUNDEF(php_retval)) {
			zval_ptr_dtor(&php_retval);
		}
		return FALSE;
	}

	php_timeout = Z_LVAL_P(zend_hash_index_find(Z_ARRVAL(php_retval), 1));
	*timeout = php_timeout;
	if(Z_TYPE_P(zend_hash_index_find(Z_ARRVAL(php_retval), 0)) == IS_TRUE) {
		retval = TRUE;
	}
	zval_ptr_dtor(&php_retval);
	return retval;
}
예제 #3
0
/**
 * @brief Phalcon\Registry Phalcon\Registry::unserialize(string $str)
 */
PHP_METHOD(Phalcon_Registry, unserialize){
	zval data = {}, *str, zv = {};
	php_unserialize_data_t var_hash;
	const unsigned char *buf, *max;

	phalcon_fetch_params(0, 1, 0, &str);
	PHALCON_ENSURE_IS_STRING(str);

	phalcon_read_property(&data, getThis(), SL("_data"), PH_NOISY);

	if (zend_hash_num_elements(Z_ARRVAL(data))) {
		zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot call unserialize() on an already constructed object");
		return;
	}

	buf = (unsigned char*)(Z_STRVAL_P(str));
	max = buf + Z_STRLEN_P(str);

	PHP_VAR_UNSERIALIZE_INIT(var_hash);
	if (php_var_unserialize(&zv, &buf, max, &var_hash) && Z_TYPE(zv) == IS_ARRAY) {
		if (zend_hash_num_elements(Z_ARRVAL(zv)) != 0) {
			zend_hash_copy(Z_ARRVAL(data), Z_ARRVAL(zv), (copy_ctor_func_t) zval_add_ref);
		}
	} else {
		zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Bad parameters passed to Phalcon\\Registry::unserialize()");
	}

	zval_dtor(&zv);
	PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
}
예제 #4
0
static zend_bool php_auto_globals_create_server(zend_string *name)
{
	if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) {
		php_register_server_variables();

		if (PG(register_argc_argv)) {
			if (SG(request_info).argc) {
				zval *argc, *argv;

				if ((argc = zend_hash_str_find(&EG(symbol_table), "argc", sizeof("argc")-1)) != NULL &&
					(argv = zend_hash_str_find(&EG(symbol_table), "argv", sizeof("argv")-1)) != NULL) {
					Z_ADDREF_P(argv);
					zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv")-1, argv);
					zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argc", sizeof("argc")-1, argc);
				}
			} else {
				php_build_argv(SG(request_info).query_string, &PG(http_globals)[TRACK_VARS_SERVER]);
			}
		}

	} else {
		zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]);
		array_init(&PG(http_globals)[TRACK_VARS_SERVER]);
	}

	zend_hash_update(&EG(symbol_table), name, &PG(http_globals)[TRACK_VARS_SERVER]);
	Z_ADDREF(PG(http_globals)[TRACK_VARS_SERVER]);

	return 0; /* don't rearm */
}
예제 #5
0
static HashTable *zend_closure_get_debug_info(zval *object, int *is_temp) /* {{{ */
{
	zend_closure *closure = (zend_closure *)Z_OBJ_P(object);
	zval val;
	struct _zend_arg_info *arg_info = closure->func.common.arg_info;

	*is_temp = 0;

	if (closure->debug_info == NULL) {
		ALLOC_HASHTABLE(closure->debug_info);
		zend_hash_init(closure->debug_info, 8, NULL, ZVAL_PTR_DTOR, 0);
	}
	if (closure->debug_info->u.v.nApplyCount == 0) {
		if (closure->func.type == ZEND_USER_FUNCTION && closure->func.op_array.static_variables) {
			HashTable *static_variables = closure->func.op_array.static_variables;
			ZVAL_NEW_ARR(&val);
			zend_array_dup(Z_ARRVAL(val), static_variables);
			zend_hash_str_update(closure->debug_info, "static", sizeof("static")-1, &val);
		}

		if (Z_TYPE(closure->this_ptr) != IS_UNDEF) {
			Z_ADDREF(closure->this_ptr);
			zend_hash_str_update(closure->debug_info, "this", sizeof("this")-1, &closure->this_ptr);
		}

		if (arg_info) {
			uint32_t i, num_args, required = closure->func.common.required_num_args;

			array_init(&val);

			num_args = closure->func.common.num_args;
			if (closure->func.common.fn_flags & ZEND_ACC_VARIADIC) {
				num_args++;
			}
			for (i = 0; i < num_args; i++) {
				zend_string *name;
				zval info;
				if (arg_info->name) {
					name = zend_strpprintf(0, "%s$%s",
							arg_info->pass_by_reference ? "&" : "",
							arg_info->name->val);
				} else {
					name = zend_strpprintf(0, "%s$param%d",
							arg_info->pass_by_reference ? "&" : "",
							i + 1);
				}
				ZVAL_NEW_STR(&info, zend_strpprintf(0, "%s", i >= required ? "<optional>" : "<required>"));
				zend_hash_update(Z_ARRVAL(val), name, &info);
				zend_string_release(name);
				arg_info++;
			}
			zend_hash_str_update(closure->debug_info, "parameter", sizeof("parameter")-1, &val);
		}
	}

	return closure->debug_info;
}
예제 #6
0
PHP_METHOD(MIME, load) {
	zval *array, *arg, retval;

	/* Fetch allowHEAD */
	MAKE_STD_ZVAL(array);
	array_init_size(array, 2);
	add_next_index_stringl(array, "Pancake\\Config", sizeof("Pancake\\Config") - 1, 1);
	add_next_index_stringl(array, "get", 3, 1);

	MAKE_STD_ZVAL(arg);
	Z_TYPE_P(arg) = IS_STRING;
	Z_STRLEN_P(arg) = 4;
	Z_STRVAL_P(arg) = estrndup("mime", 4);

	call_user_function(CG(function_table), NULL, array, &retval, 1, &arg TSRMLS_CC);

	if(Z_TYPE(retval) != IS_ARRAY) {
		zend_error(E_ERROR, "Bad MIME type array - Please check Pancake MIME type configuration");
	}

	ALLOC_HASHTABLE(PANCAKE_GLOBALS(mimeTable));
	zend_hash_init(PANCAKE_GLOBALS(mimeTable), 0, NULL, ZVAL_PTR_DTOR, 0);

	zval **data, **ext;
	char *key;

	for(zend_hash_internal_pointer_reset(Z_ARRVAL(retval));
		zend_hash_get_current_data(Z_ARRVAL(retval), (void**) &data) == SUCCESS &&
		zend_hash_get_current_key(Z_ARRVAL(retval), &key, NULL, 0) == HASH_KEY_IS_STRING;
		zend_hash_move_forward(Z_ARRVAL(retval))) {

		for(zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data));
			zend_hash_get_current_data(Z_ARRVAL_PP(data), (void**) &ext) == SUCCESS;
			zend_hash_move_forward(Z_ARRVAL_PP(data))) {

			zval *zkey;
			MAKE_STD_ZVAL(zkey);
			Z_TYPE_P(zkey) = IS_STRING;
			Z_STRLEN_P(zkey) = strlen(key);
			Z_STRVAL_P(zkey) = estrndup(key, Z_STRLEN_P(zkey));

			zend_hash_add(PANCAKE_GLOBALS(mimeTable), Z_STRVAL_PP(ext), Z_STRLEN_PP(ext), (void*) &zkey, sizeof(zval*), NULL);
		}
	}

	MAKE_STD_ZVAL(PANCAKE_GLOBALS(defaultMimeType));
	Z_TYPE_P(PANCAKE_GLOBALS(defaultMimeType)) = IS_STRING;
	Z_STRLEN_P(PANCAKE_GLOBALS(defaultMimeType)) = sizeof("application/octet-stream") - 1;
	Z_STRVAL_P(PANCAKE_GLOBALS(defaultMimeType)) = estrndup("application/octet-stream", sizeof("application/octet-stream") - 1);

	free:
	zval_dtor(&retval);
	zval_ptr_dtor(&array);
	zval_ptr_dtor(&arg);
}
예제 #7
0
/* {{{ MYSQLI_WARNING *php_get_warnings(MYSQL *mysql) */
MYSQLI_WARNING * php_get_warnings(MYSQLND_CONN_DATA * mysql)
{
	MYSQLI_WARNING	*w, *first = NULL, *prev = NULL;
	MYSQL_RES		*result;
	zval			row;

	if (mysql->m->query(mysql, "SHOW WARNINGS", 13)) {
		return NULL;
	}

	result = mysql->m->use_result(mysql, 0);

	for (;;) {
		zval *entry;
		int errno;

		mysqlnd_fetch_into(result, MYSQLND_FETCH_NUM, &row, MYSQLND_MYSQLI);
		if (Z_TYPE(row) != IS_ARRAY) {
			zval_ptr_dtor(&row);
			break;
		}
		zend_hash_internal_pointer_reset(Z_ARRVAL(row));
		/* 0. we don't care about the first */
		zend_hash_move_forward(Z_ARRVAL(row));

		/* 1. Here comes the error no */
		entry = zend_hash_get_current_data(Z_ARRVAL(row));
		convert_to_long_ex(entry);
		errno = Z_LVAL_P(entry);
		zend_hash_move_forward(Z_ARRVAL(row));

		/* 2. Here comes the reason */
		entry = zend_hash_get_current_data(Z_ARRVAL(row));

		w = php_new_warning(entry, errno);
		/*
		  Don't destroy entry, because the row destroy will decrease
		  the refcounter. Decreased twice then mysqlnd_free_result()
		  will crash, because it will try to access already freed memory.
		*/
		if (!first) {
			first = w;
		}
		if (prev) {
			prev->next = (void *)w;
		}
		prev = w;

		zval_ptr_dtor(&row);
	}

	mysql_free_result(result);
	return first;
}
예제 #8
0
파일: object.c 프로젝트: phalcon/zephir
/**
 * Updates an array property
 */
int zephir_update_property_array(zval *object, const char *property, zend_uint property_length, const zval *index, zval *value)
{
	zval tmp;
	int separated = 0;

	if (Z_TYPE_P(object) == IS_OBJECT) {
		zephir_read_property(&tmp, object, property, property_length, PH_NOISY | PH_READONLY);

		/** Separation only when refcount > 1 */
		if (Z_REFCOUNTED(tmp)) {
			if (Z_REFCOUNT(tmp) > 1) {
				if (!Z_ISREF(tmp)) {
					zval new_zv;
					ZVAL_DUP(&new_zv, &tmp);
					ZVAL_COPY_VALUE(&tmp, &new_zv);
					Z_TRY_DELREF(new_zv);
					separated = 1;
				}
			}
		} else {
			zval new_zv;
			ZVAL_DUP(&new_zv, &tmp);
			ZVAL_COPY_VALUE(&tmp, &new_zv);
			Z_TRY_DELREF(new_zv);
			separated = 1;
		}

		/** Convert the value to array if not is an array */
		if (Z_TYPE(tmp) != IS_ARRAY) {
			if (separated) {
				convert_to_array(&tmp);
			} else {
				array_init(&tmp);
				separated = 1;
			}
			Z_DELREF(tmp);
		}
		Z_TRY_ADDREF_P(value);

		if (Z_TYPE_P(index) == IS_STRING) {
			zend_symtable_str_update(Z_ARRVAL(tmp), Z_STRVAL_P(index), Z_STRLEN_P(index), value);
		} else if (Z_TYPE_P(index) == IS_LONG) {
			zend_hash_index_update(Z_ARRVAL(tmp), Z_LVAL_P(index), value);
		} else if (Z_TYPE_P(index) == IS_NULL) {
			zend_hash_next_index_insert(Z_ARRVAL(tmp), value);
		}

		if (separated) {
			zephir_update_property_zval(object, property, property_length, &tmp);
		}
	}

	return SUCCESS;
}
예제 #9
0
/* {{{ proto array SplDoublyLinkedList::__serialize() */
SPL_METHOD(SplDoublyLinkedList, __serialize)
{
	spl_dllist_object *intern = Z_SPLDLLIST_P(ZEND_THIS);
	spl_ptr_llist_element *current = intern->llist->head;
	zval tmp;

	if (zend_parse_parameters_none_throw() == FAILURE) {
		return;
	}

	array_init(return_value);

	/* flags */
	ZVAL_LONG(&tmp, intern->flags);
	zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &tmp);

	/* elements */
	array_init_size(&tmp, intern->llist->count);
	while (current) {
		zend_hash_next_index_insert(Z_ARRVAL(tmp), &current->data);
		current = current->next;
	}
	zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &tmp);

	/* members */
	ZVAL_ARR(&tmp, zend_std_get_properties(&intern->std));
	Z_TRY_ADDREF(tmp);
	zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &tmp);
} /* }}} */
예제 #10
0
/**
 * @brief void Phalcon\Registry::rewind()
 */
PHP_METHOD(Phalcon_Registry, rewind){

	zval data = {};

	phalcon_read_property(&data, getThis(), SL("_data"), PH_NOISY);
	zend_hash_internal_pointer_reset(Z_ARRVAL(data));
}
예제 #11
0
/**
 * @brief void Phalcon\Registry::next()
 */
PHP_METHOD(Phalcon_Registry, next){

	zval data = {};

	phalcon_read_property(&data, getThis(), SL("_data"), PH_NOISY);
	zend_hash_move_forward(Z_ARRVAL(data));
}
예제 #12
0
/**
 * @brief string|int|null Phalcon\Registry::key()
 */
PHP_METHOD(Phalcon_Registry, key){

	zval data = {};

	phalcon_read_property(&data, getThis(), SL("_data"), PH_NOISY);
	zend_hash_get_current_key_zval(Z_ARRVAL(data), return_value);
}
예제 #13
0
/**
 * Interpolates context values into the message placeholders
 *
 * @see http://www.php-fig.org/psr/psr-3/ Section 1.2 Message
 * @param string $message
 * @param array $context
 */
PHP_METHOD(Phalcon_Logger_Formatter, interpolate)
{
	zval *message, *context;
	zval replace, *val;
	zend_string *str_key;
	ulong idx;

	phalcon_fetch_params(0, 2, 0, &message, &context);

	if (Z_TYPE_P(context) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(context)) > 0) {
		array_init(&replace);

		ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(context), idx, str_key, val) {
			zval index;
			char *tmp;
			uint str_length;

			if (str_key) {;
				str_length = spprintf(&tmp, 0, "{%s}", str_key->val);
				ZVAL_STRINGL(&index, tmp, str_length);
			} else {
				str_length = spprintf(&tmp, 0, "{%ld}", idx);
				ZVAL_STRINGL(&index, tmp, str_length);
			}

			Z_TRY_ADDREF_P(val);
			zend_hash_add(Z_ARRVAL(replace), Z_STR(index), val);
			efree(tmp);
		} ZEND_HASH_FOREACH_END();
예제 #14
0
파일: mysql.c 프로젝트: dreamsxin/cphalcon7
/**
 * Gets the column name in MySQL
 *
 * @param Phalcon\Db\ColumnInterface $column
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnDefinition){

	zval *column, size = {}, column_type = {}, column_sql = {}, type_values = {}, slash = {}, *value, value_cslashes = {}, is_unsigned = {}, scale = {}, name = {};
	int c, i = 0;

	phalcon_fetch_params(0, 1, 0, &column);
	PHALCON_VERIFY_INTERFACE_EX(column, phalcon_db_columninterface_ce, phalcon_db_exception_ce, 0);

	PHALCON_CALL_METHODW(&size, column, "getsize");
	PHALCON_CALL_METHODW(&column_type, column, "gettype");

	if (Z_TYPE(column_type) == IS_STRING) {
		PHALCON_CPY_WRT(&column_sql, &column_type);
		PHALCON_CALL_METHODW(&type_values, column, "gettypevalues");
		if (PHALCON_IS_NOT_EMPTY(&type_values)) {
			ZVAL_STRING(&slash, "\"");
			if (Z_TYPE(type_values) == IS_ARRAY) {
				c = phalcon_fast_count_int(&type_values);
				phalcon_concat_self_str(&column_sql, SL("("));
				ZEND_HASH_FOREACH_VAL(Z_ARRVAL(type_values), value) {
					i++;
					PHALCON_CALL_FUNCTIONW(&value_cslashes, "addcslashes", value, &slash);
					if (i < c) {
						PHALCON_SCONCAT_SVS(&column_sql, "\"", &value_cslashes, "\", ");
					} else {
						PHALCON_SCONCAT_SVS(&column_sql, "\"", &value_cslashes, "\"");
					}
				} ZEND_HASH_FOREACH_END();
예제 #15
0
/* {{{ proto array SolrInputDocument::toArray(void)
   Returns an array representation of the object. */
PHP_METHOD(SolrInputDocument, toArray)
{
	solr_document_t *doc_entry = NULL;
	zval fields_array;

	/* Retrieve the document entry for the SolrDocument instance */
	if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS)
	{
		HashTable *fields_ht;
		array_init(return_value);
		array_init(&fields_array);
		zend_hash_init(Z_ARRVAL(fields_array), zend_hash_num_elements(doc_entry->fields), NULL, ZVAL_PTR_DTOR, 0);

		add_assoc_double(return_value, "document_boost", doc_entry->document_boost);
		add_assoc_long(return_value,   "field_count", doc_entry->field_count);
		add_assoc_zval(return_value,   "fields", &fields_array);

		fields_ht = doc_entry->fields;

		SOLR_HASHTABLE_FOR_LOOP(fields_ht)
		{
			solr_field_list_t *field = NULL;
			zval current_field;
			zval *current_field_ptr = &current_field;

			field = zend_hash_get_current_data_ptr(fields_ht);
			/* create SolrDocumentField */
			solr_create_document_field_object(field, &current_field_ptr TSRMLS_CC);
			/* create SolrDocumentField to the fields HT */
			add_next_index_zval(&fields_array, current_field_ptr);
		}
		/* We are done */
		return;
	}
예제 #16
0
int GetN(structlpsolvecaller *lpsolvecaller, zval arg)
{
        int n, n1;
        HashTable *arr_hash;
        zval    *data;
        zend_string *key;
        long i;

        switch (Z_TYPE(arg)) {
        case IS_LONG:
        case IS_DOUBLE:
                n = 1;
                break;
        case IS_ARRAY:
                //n = 1; /* only 1-dim arrays supported at this time */
                arr_hash = Z_ARRVAL(arg);

                n = 0;
                ZEND_HASH_FOREACH_KEY_VAL(arr_hash, i, key, data) {

                    if (key || (i < 0)) {
                        ErrMsgTxt(lpsolvecaller, "invalid vector.");
                    }
                    n1 = GetM(lpsolvecaller, *data);
                    if (n1 >= n)
                        n = n1;
                } ZEND_HASH_FOREACH_END();
                break;
        default:
                n = 0;
                break;
        }
        return(n);
}
예제 #17
0
/* This is not the number of elements in the array, but the maximum index number in it.
   This to allow sparse arrays */
int GetM(structlpsolvecaller *lpsolvecaller, zval arg)
{
        int m;
        HashTable *arr_hash;
        zval    *data;
        long i;
        zend_string *key;
        int key_len;

        switch (Z_TYPE(arg)) {
        case IS_LONG:
        case IS_DOUBLE:
                m = 1;
                break;
        case IS_ARRAY:
                arr_hash = Z_ARRVAL(arg);
                /* m = zend_hash_num_elements(arr_hash); */

                m = 0;
                ZEND_HASH_FOREACH_KEY_VAL(arr_hash, i, key, data) {

                    if (key || (i < 0)) {
                        ErrMsgTxt(lpsolvecaller, "invalid vector.");
                    }
                    if (i + 1 >= m)
                        m = i + 1;
                } ZEND_HASH_FOREACH_END();
                break;
        default:
                m = 0;
                break;
        }
        return(m);
}
예제 #18
0
/**
 * @brief bool Phalcon\Registry::valid()
 */
PHP_METHOD(Phalcon_Registry, valid){

	zval data = {};

	phalcon_read_property(&data, getThis(), SL("_data"), PH_NOISY);

	RETURN_BOOL(zend_hash_has_more_elements(Z_ARRVAL(data)));
}
예제 #19
0
파일: smd.c 프로젝트: buglloc/php-smd
static void smd_mark_global(char *name, int len, zend_uchar mark) /* {{{ */ {
    zend_string * str = zend_string_init(name, len, 0);
    if (zend_is_auto_global(str)) {
        zval *zv = zend_hash_find(&EG(symbol_table), str);
        SMD_SET_MARK(Z_ARRVAL(*zv), mark);
    }

    efree(str);
} /* }}} */
/**
 * @ret 父亲zval
 * @name 父亲name
 * @r 子zval
 * @son_name 子name
 */
static void php_xml2array_add_val (zval *ret, const xmlChar *name, zval *r, char *son_key) {
	zval **tmp = NULL;
	char *key = (char *)name;//要插入的node 的key

	int has_tmp = zend_symtable_find(Z_ARRVAL(*ret),  key, strlen(key) + 1, (void**)&tmp);

	if (has_tmp == SUCCESS && tmp != NULL && Z_TYPE_PP(tmp) == IS_ARRAY && son_key == NULL && Z_TYPE_P(r) == IS_STRING) {//avoid <xx></xx>,<xx></xx>
		zval_ptr_dtor(&r);
		return;
	}

	if(son_key != NULL && zend_symtable_find(Z_ARRVAL(*ret),  key, strlen(key) + 1, (void**)&tmp) != FAILURE
		&& Z_TYPE_PP(tmp) == IS_ARRAY) {

		zval **son_val = NULL;
		zend_symtable_find(Z_ARRVAL_P(r),  son_key , strlen(son_key)+1, (void**)&son_val);

		zval *son_val_copy;
		MAKE_STD_ZVAL(son_val_copy);
		MAKE_COPY_ZVAL(son_val, son_val_copy);

		zval **tmp_val = NULL;
		if (zend_symtable_find(Z_ARRVAL_P(*tmp),  son_key , strlen(son_key)+1, (void**)&tmp_val) != FAILURE) {//已经包含同名子元素
			if (Z_TYPE_PP(tmp_val)  == IS_ARRAY && zend_hash_index_exists(Z_ARRVAL_PP(tmp_val), 0)) {
				add_next_index_zval(*tmp_val, son_val_copy);
			} else {
				zval *son_arr = init_zval_array();
				zval *copy;
				MAKE_STD_ZVAL(copy);
				MAKE_COPY_ZVAL(tmp_val, copy);
				add_next_index_zval(son_arr, copy);
				add_next_index_zval(son_arr, son_val_copy);
				zend_symtable_update(Z_ARRVAL_PP(tmp), son_key, strlen(son_key)+1, (void *) &son_arr, sizeof(zval *), NULL);
			}
		} else {
			add_assoc_zval(*tmp, son_key, son_val_copy);
		}
		zval_ptr_dtor(&r);//accept a zval** param
	} else {
		add_assoc_zval(ret, key, r);
	}


}
예제 #21
0
static HashTable *ds_queue_get_debug_info(zval *obj, int *is_temp)
{
    zval arr;
    ds_queue_t *q = Z_DS_QUEUE_P(obj);

    *is_temp = 1;

    ds_queue_to_array(q, &arr);
    return Z_ARRVAL(arr);
}
예제 #22
0
파일: lsapi_main.c 프로젝트: SammyK/php-src
static void litespeed_php_import_environment_variables(zval *array_ptr)
{
    char buf[128];
    char **env, *p, *t = buf;
    size_t alloc_size = sizeof(buf);
    unsigned long nlen; /* ptrdiff_t is not portable */

    if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
        Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV]) &&
        zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_ENV])) > 0
    ) {
        zval_ptr_dtor_nogc(array_ptr);
        ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_ENV]);
        return;
    } else if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
        Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_SERVER]) &&
        zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])) > 0
    ) {
        zval_ptr_dtor_nogc(array_ptr);
        ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_SERVER]);
        return;
    }

    tsrm_env_lock();
    for (env = environ; env != NULL && *env != NULL; env++) {
        p = strchr(*env, '=');
        if (!p) {               /* malformed entry? */
            continue;
        }
        nlen = p - *env;
        if (nlen >= alloc_size) {
            alloc_size = nlen + 64;
            t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
        }
        memcpy(t, *env, nlen);
        t[nlen] = '\0';
        add_variable(t, nlen, p + 1, strlen( p + 1 ), array_ptr);
    }
    tsrm_env_unlock();
    if (t != buf && t != NULL) {
        efree(t);
    }
}
예제 #23
0
static HashTable *php_ds_vector_get_debug_info(zval *obj, int *is_temp)
{
    zval arr;
    ds_vector_t *vector = Z_DS_VECTOR_P(obj);

    *is_temp = 1;

    ds_vector_to_array(vector, &arr);
    return Z_ARRVAL(arr);
}
예제 #24
0
static HashTable *ds_set_get_debug_info(zval *obj, int *is_temp)
{
    zval arr;
    ds_set_t *set = Z_DS_SET_P(obj);

    *is_temp = 1;

    ds_set_to_array(set, &arr);
    return Z_ARRVAL(arr);
}
예제 #25
0
int yaf_loader_register(yaf_loader_t *loader) /* {{{ */ {
	zval autoload, function, method, ret;

	array_init(&autoload);

    ZVAL_STRING(&method, YAF_AUTOLOAD_FUNC_NAME);
	zend_hash_next_index_insert(Z_ARRVAL(autoload), loader);
	zend_hash_next_index_insert(Z_ARRVAL(autoload), &method);

	ZVAL_STRING(&function, YAF_SPL_AUTOLOAD_REGISTER_NAME);

	do {
		zend_fcall_info fci = {
			sizeof(fci),
#if PHP_VERSION_ID < 70100
			EG(function_table),
#endif
			function,
#if PHP_VERSION_ID < 70100
			NULL,
#endif
			&ret,
			&autoload,
			NULL,
			1,
			1
		};

		if (zend_call_function(&fci, NULL) == FAILURE) {
			zval_ptr_dtor(&function);
			zval_ptr_dtor(&autoload);
			php_error_docref(NULL,
					E_WARNING,
					"Unable to register autoload function %s",
					YAF_AUTOLOAD_FUNC_NAME);
			return 0;
		}
		zval_ptr_dtor(&function);
		zval_ptr_dtor(&autoload);
	} while (0);
	return 1;
}
예제 #26
0
/**
 * @brief mixed& Phalcon\Registry::current()
 */
PHP_METHOD(Phalcon_Registry, current){

	zval data = {}, *callback;

	phalcon_read_property(&data, getThis(), SL("_data"), PH_NOISY);
	if ((callback = zend_hash_get_current_data(Z_ARRVAL(data))) != NULL) {
		RETURN_ZVAL(callback, 1, 0);
	}

	RETURN_NULL();
}
예제 #27
0
void
ra_index_keys(zval *z_pairs, zval *z_redis) {

    /* Initialize key array */
    zval z_keys;
    zend_string *key;
    unsigned long num_key;

    array_init_size(&z_keys, zend_hash_num_elements(Z_ARRVAL_P(z_pairs)));

    /* Go through input array and add values to the key array */
    ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(z_pairs), num_key, key) {
        zval z_new;
        if (key) {
            ZVAL_STR_COPY(&z_new, key);
            zend_hash_next_index_insert(Z_ARRVAL(z_keys), &z_new);
        } else {
			ZVAL_LONG(&z_new, num_key);
            zend_hash_next_index_insert(Z_ARRVAL(z_keys), &z_new);
        }
    } ZEND_HASH_FOREACH_END();
예제 #28
0
static char *oauth_provider_get_current_uri()
{
	zval *host, *port, *uri, *proto, *https;

	zend_is_auto_global_str("_SERVER", sizeof("_SERVER")-1);

	host = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_HOST", sizeof("HTTP_HOST") - 1);
	port = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "SERVER_PORT", sizeof("SERVER_PORT") - 1);
	uri = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_URI", sizeof("REQUEST_URI") - 1);
	proto = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_X_FORWARDED_PROTO", sizeof("HTTP_X_FORWARDED_PROTO") - 1);
	https = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTPS", sizeof("HTTPS") - 1);

	if (host && port && uri)
	{
		char *tmp,*hostname,*colon_in_hostname;

		spprintf(&hostname, 0, "%s", Z_STRVAL_P(host));
		colon_in_hostname=strrchr(hostname,':');
		if(colon_in_hostname && ((https && Z_LVAL_P(port)==443) || (!https && Z_LVAL_P(port)==80)))
		{
			*colon_in_hostname=0;
		}
		if(proto && Z_STRLEN_P(proto))
		{
			spprintf(&tmp, 0, "%s://%s%s", Z_STRVAL_P(proto), hostname, Z_STRVAL_P(uri));
		}
		else if(https && Z_STRLEN_P(https)>0 && strcasecmp(Z_STRVAL_P(https),"off")!=0)
		{
			spprintf(&tmp, 0, "https://%s%s", hostname, Z_STRVAL_P(uri));
		}
		else
		{
			spprintf(&tmp, 0, "http://%s%s", hostname, Z_STRVAL_P(uri));
		}
		efree(hostname);
		return tmp;
	}

	return NULL;
}
예제 #29
0
파일: simd.c 프로젝트: krakjoe/SIMD
static HashTable *php_float32x4_dump(zval *obj, int *is_temp) /* {{{ */
{
	php_float32x4_t *p = php_float32x4_fetch_ex(obj);
	zval zv;
	
	array_init(&zv);
	add_next_index_double(&zv, (*p->v)[0]);
	add_next_index_double(&zv, (*p->v)[1]);
	add_next_index_double(&zv, (*p->v)[2]);
	add_next_index_double(&zv, (*p->v)[3]);

	*is_temp = 1;

	return Z_ARRVAL(zv);
}
예제 #30
0
파일: stack.c 프로젝트: 471207225/pthreads
void pthreads_stack_tohash(pthreads_stack_t *stack, HashTable *hash) {
	zval stacked;
	zval waiting;
	zval gc;

	array_init(&stacked);
	array_init(&waiting);	
	array_init(&gc);

	zend_hash_str_add(Z_ARRVAL(stacked), ":stacked:", sizeof(":stacked:")-1, &waiting);
	zend_hash_str_add(Z_ARRVAL(stacked), ":gc:", sizeof(":gc:")-1, &gc);

	if (pthreads_monitor_lock(stack->monitor)) {
		pthreads_stack_item_t *item = stack->head;
		
		while (item) {
			if (add_next_index_zval(
					&waiting, &item->value)) {
				Z_ADDREF(item->value);
			}
			item = item->next;
		}

		item = stack->gc->head;
		while (item) {
			if (add_next_index_zval(
					&gc, &item->value)) {
				Z_ADDREF(item->value);
			}
			item = item->next;
		}
		pthreads_monitor_unlock(stack->monitor);
	}

	zend_hash_str_add(hash, ":stack:", sizeof(":stack:")-1, &stacked);
}