static void php_xml2array_get_properties (xmlNodePtr cur_node, zval * nodes, char *name) { if (cur_node->properties) { xmlAttrPtr attr = NULL; zval **tmp; if (zend_symtable_find(Z_ARRVAL_P(nodes), name, strlen(name) + 1, (void**)&tmp) == FAILURE) { return;//this should not happen } zval *target = *tmp; if (Z_TYPE_PP(tmp) != IS_ARRAY) { zval *value_zval = init_zval_array(); target = value_zval; zval *copy; MAKE_STD_ZVAL(copy); MAKE_COPY_ZVAL(tmp, copy); add_assoc_zval(value_zval, "value", copy); zend_symtable_update(Z_ARRVAL_P(nodes), name, strlen(name)+1, (void *) &value_zval, sizeof(zval *), NULL); } for(attr = cur_node->properties; NULL != attr; attr = attr->next) { xmlChar * prop = NULL; prop = xmlGetProp(cur_node, attr->name); char *attr_name = (char*)attr->name; zval *attr_zval; MAKE_STD_ZVAL(attr_zval); ZVAL_STRING(attr_zval, prop, 1); zend_symtable_update(Z_ARRVAL_P(target), attr_name, strlen(attr_name)+1, (void *) &attr_zval, sizeof(zval *), NULL); xmlFree(prop); } } }
/** * @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); } }
static inline long gmp_get_long(zval *zv) /* {{{ */ { if (Z_TYPE_P(zv) == IS_LONG) { return Z_LVAL_P(zv); } else { zval tmp_zv; MAKE_COPY_ZVAL(&zv, &tmp_zv); convert_to_long(&tmp_zv); return Z_LVAL(tmp_zv); } }
/** * Adds an option to the current options * * @param array $option * @return $this */ PHP_METHOD(Phalcon_Forms_Element_Select, addOption){ zval **option, *values, *tmp; phalcon_fetch_params_ex(1, 0, &option); PHALCON_ENSURE_IS_ARRAY(option); values = phalcon_fetch_nproperty_this(getThis(), SL("_optionsValues"), PH_NOISY TSRMLS_CC); ALLOC_ZVAL(tmp); if (Z_TYPE_P(values) != IS_ARRAY) { MAKE_COPY_ZVAL(option, tmp); } else { add_function(tmp, *option, values TSRMLS_CC); } Z_SET_REFCOUNT_P(tmp, 0); phalcon_update_property_this(getThis(), SL("_optionsValues"), tmp TSRMLS_CC); RETURN_THISW(); }
/* {{{ _php_array_to_envp */ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent TSRMLS_DC) { zval **element; php_process_env_t env; char *string_key, *data; #ifndef PHP_WIN32 char **ep; #endif char *p; uint string_length, cnt, l, sizeenv=0, el_len; ulong num_key; HashTable *target_hash; HashPosition pos; memset(&env, 0, sizeof(env)); if (!environment) { return env; } cnt = zend_hash_num_elements(Z_ARRVAL_P(environment)); if (cnt < 1) { #ifndef PHP_WIN32 env.envarray = (char **) pecalloc(1, sizeof(char *), is_persistent); #endif env.envp = (char *) pecalloc(4, 1, is_persistent); return env; } target_hash = HASH_OF(environment); if (!target_hash) { return env; } /* first, we have to get the size of all the elements in the hash */ for (zend_hash_internal_pointer_reset_ex(target_hash, &pos); zend_hash_get_current_data_ex(target_hash, (void **) &element, &pos) == SUCCESS; zend_hash_move_forward_ex(target_hash, &pos)) { if (Z_TYPE_PP(element) != IS_STRING) { zval tmp; MAKE_COPY_ZVAL(element, &tmp); convert_to_string(&tmp); el_len = Z_STRLEN(tmp); zval_dtor(&tmp); } else { el_len = Z_STRLEN_PP(element); } if (el_len == 0) { continue; } sizeenv += el_len+1; switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_length, &num_key, 0, &pos)) { case HASH_KEY_IS_STRING: if (string_length == 0) { continue; } sizeenv += string_length; break; } } #ifndef PHP_WIN32 ep = env.envarray = (char **) pecalloc(cnt + 1, sizeof(char *), is_persistent); #endif p = env.envp = (char *) pecalloc(sizeenv + 4, 1, is_persistent); for (zend_hash_internal_pointer_reset_ex(target_hash, &pos); zend_hash_get_current_data_ex(target_hash, (void **) &element, &pos) == SUCCESS; zend_hash_move_forward_ex(target_hash, &pos)) { zval tmp; if (Z_TYPE_PP(element) != IS_STRING) { MAKE_COPY_ZVAL(element, &tmp); convert_to_string(&tmp); } else { tmp = **element; } el_len = Z_STRLEN(tmp); if (el_len == 0) { goto next_element; } data = Z_STRVAL(tmp); switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_length, &num_key, 0, &pos)) { case HASH_KEY_IS_STRING: if (string_length == 0) { goto next_element; } l = string_length + el_len + 1; memcpy(p, string_key, string_length); strncat(p, "=", 1); strncat(p, data, el_len); #ifndef PHP_WIN32 *ep = p; ++ep; #endif p += l; break; case HASH_KEY_IS_LONG: memcpy(p,data,el_len); #ifndef PHP_WIN32 *ep = p; ++ep; #endif p += el_len + 1; break; case HASH_KEY_NON_EXISTENT: break; } next_element: if (Z_TYPE_PP(element) != IS_STRING) { zval_dtor(&tmp); } } assert((uint)(p - env.envp) <= sizeenv); zend_hash_internal_pointer_reset_ex(target_hash, &pos); return env; }
zval *value_to_zval(VALUE v) { zval *zv; MAKE_STD_ZVAL(zv); switch (TYPE(v)) { case T_FALSE: ZVAL_FALSE(zv); return zv; case T_TRUE: ZVAL_TRUE(zv); return zv; case T_UNDEF: case T_NIL: ZVAL_NULL(zv); return zv; case T_FIXNUM: ZVAL_LONG(zv, rb_fix2int(v)); return zv; case T_BIGNUM: ZVAL_LONG(zv, rb_big2long(v)); // FIXME: bignum over long return zv; case T_FLOAT: ZVAL_DOUBLE(zv, RFLOAT_VALUE(v)); return zv; case T_ARRAY: { int i; array_init(zv); for(i=0;i<RARRAY_LEN(v);++i) { zval *add = value_to_zval(RARRAY_PTR(v)[i]); zend_hash_next_index_insert(Z_ARRVAL_P(zv), &add, sizeof(zval *), NULL); } return zv; } case T_HASH: { array_init(zv); rb_hash_foreach(v, hash_to_zval, (VALUE)zv); return zv; } case T_SYMBOL: { VALUE symbol_str = rb_sym_to_s(v); ZVAL_STRINGL(zv, StringValuePtr(symbol_str), RSTRING_LEN(symbol_str), 1); return zv; } case T_STRING: { ZVAL_STRINGL(zv, StringValuePtr(v), RSTRING_LEN(v), 1); return zv; } default: { if (CLASS_OF(v) == cPhpEmbedValue) { php_value* pv; Data_Get_Struct(v, php_value, pv); MAKE_COPY_ZVAL(&pv->value, zv); return zv; } } FREE_ZVAL(zv); rb_raise(rb_eRuntimeError, "no implemented"); } }