/* {{{ proto ProtocolBuffers\EnumDescriptor ProtocolBuffersDescriptorBuilder::build() */ PHP_METHOD(protocolbuffers_enum_descriptor_builder, build) { zval *result, *container, **fields, **entry, *key, *value; char *property; int property_len; HashPosition pos; MAKE_STD_ZVAL(result); object_init_ex(result, php_protocol_buffers_enum_descriptor_class_entry); MAKE_STD_ZVAL(container); array_init(container); zend_mangle_property_name(&property, &property_len, (char*)"*", 1, (char*)ZEND_STRS("values"), 0); if (zend_hash_find(Z_OBJPROP_P(getThis()), property, property_len, (void **)&fields) == SUCCESS) { zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(fields), &pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(fields), (void **)&entry, &pos) == SUCCESS) { zval *tmp = NULL; MAKE_STD_ZVAL(tmp); php_protocolbuffers_read_protected_property(*entry, ZEND_STRS("name"), &key TSRMLS_CC); php_protocolbuffers_read_protected_property(*entry, ZEND_STRS("value"), &value TSRMLS_CC); ZVAL_ZVAL(tmp, value, 1, 0); zend_hash_update(Z_ARRVAL_P(container), Z_STRVAL_P(key), Z_STRLEN_P(key), &tmp, sizeof(zval), NULL); zend_hash_move_forward_ex(Z_ARRVAL_PP(fields), &pos); } } efree(property); php_protocolbuffers_set_protected_property(result, ZEND_STRS("values"), container TSRMLS_CC); RETURN_ZVAL(result, 0, 1); }
/* {{{ proto void ProtocolBuffersDescriptorBuilder::addValue(ProtocolBuffers\EnumValueDescriptor $value[, bool $force = false]) */ PHP_METHOD(protocolbuffers_enum_descriptor_builder, addValue) { zval *instance = getThis(); zval *value, **fields, *name; zend_bool force = 0; char *property; int property_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &value, php_protocol_buffers_enum_value_descriptor_class_entry, &force) == FAILURE) { return; } zend_mangle_property_name(&property, &property_len, (char*)"*", 1, (char*)ZEND_STRS("values"), 0); if (zend_hash_find(Z_OBJPROP_P(instance), property, property_len, (void **)&fields) == SUCCESS) { if (php_protocolbuffers_read_protected_property(value, ZEND_STRS("name"), &name TSRMLS_CC)) { if (zend_hash_exists(Z_ARRVAL_PP(fields), Z_STRVAL_P(name), Z_STRLEN_P(name))) { if (force < 1) { zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "name `%s` has already registered.", Z_STRVAL_P(name)); } efree(property); return; } } Z_ADDREF_P(value); zend_hash_update(Z_ARRVAL_PP(fields), Z_STRVAL_P(name), Z_STRLEN_P(name)+1, &value, sizeof(zval), NULL); } efree(property); }
/* {{{ pip_hash_to_list(zval **hash) Convert a PHP hash to a Python list */ PyObject * pip_hash_to_list(zval **hash) { PyObject *list, *item; zval **entry; long pos = 0; /* Make sure we were given a PHP hash */ if (Z_TYPE_PP(hash) != IS_ARRAY) { return NULL; } /* Create a list with the same number of elements as the hash */ list = PyList_New(zend_hash_num_elements(Z_ARRVAL_PP(hash))); /* Let's start at the very beginning, a very good place to start. */ zend_hash_internal_pointer_reset(Z_ARRVAL_PP(hash)); /* Iterate over the hash's elements */ while (zend_hash_get_current_data(Z_ARRVAL_PP(hash), (void **)&entry) == SUCCESS) { /* Convert the PHP value to its Python equivalent */ item = pip_zval_to_pyobject(entry); /* Add this item to the list and increment the position */ PyList_SetItem(list, pos++, item); /* Advance to the next entry */ zend_hash_move_forward(Z_ARRVAL_PP(hash)); } return list; }
PHP_METHOD(WinGdiPath, beizerTo) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; zval ***parameters, **x, **y; POINT *points = NULL; DWORD points_total = 0; int param_count, i; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶meters, ¶m_count) == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); points = emalloc(param_count * sizeof(POINT)); for (i = 0; i < param_count; i++) { // We expect only arrays if (Z_TYPE_PP(parameters[i]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected array for parameter %d, got %s", i + 1, zend_zval_type_name(*(parameters[i]))); goto CLEANUP; } else { // We want 2 elements if (zend_hash_num_elements(Z_ARRVAL_PP(parameters[i])) != 2) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected 2 elements for array at parameter %d, got %d", i + 1, zend_hash_num_elements(Z_ARRVAL_PP(parameters[i]))); goto CLEANUP; } else { zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 0, (void **)&x); zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 1, (void **)&y); if (Z_TYPE_PP(x) != IS_LONG) convert_to_long(*x); if (Z_TYPE_PP(y) != IS_LONG) convert_to_long(*y); points[i].x = Z_LVAL_PP(x); points[i].y = Z_LVAL_PP(y); points_total++; } } } RETVAL_BOOL(PolyBezierTo(dc_obj->hdc, points, points_total)); CLEANUP: efree(points); }
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); }
static void browscap_entry_dtor_persistent(zval **zvalue) /* {{{ */ { if (Z_TYPE_PP(zvalue) == IS_ARRAY) { zend_hash_destroy(Z_ARRVAL_PP(zvalue)); free(Z_ARRVAL_PP(zvalue)); } else if (Z_TYPE_PP(zvalue) == IS_STRING) { if (Z_STRVAL_PP(zvalue)) { free(Z_STRVAL_PP(zvalue)); } } free(*zvalue); }
static void php_jq_filter(zval **return_value, jq_state *jq, jv json, int flags TSRMLS_DC) { jv result; jq_start(jq, jv_copy(json), 0); if (jv_is_valid(result = jq_next(jq))) { int multiple = 0; while (1) { zval *zv; ALLOC_INIT_ZVAL(zv); if (flags == JQ_OPT_RAW) { if (jv_get_kind(result) == JV_KIND_STRING) { ZVAL_STRING(zv, jv_string_value(result), 1); } else { jv dump = jv_dump_string(result, 0); if (jv_is_valid(dump)) { ZVAL_STRING(zv, jv_string_value(dump), 1); } jv_free(dump); } } else { php_jv_dump(&zv, result TSRMLS_CC); } if (!jv_is_valid(result = jq_next(jq))) { if (multiple) { zend_hash_next_index_insert(Z_ARRVAL_PP(return_value), &zv, sizeof(zv), NULL); } else { ZVAL_ZVAL(*return_value, zv, 1, 1); } break; } if (!multiple) { multiple = 1; array_init(*return_value); } zend_hash_next_index_insert(Z_ARRVAL_PP(return_value), &zv, sizeof(zv), NULL); } } else { jv_free(result); if (PHP_JQ_G(display_errors)) { PHP_JQ_ERR(E_WARNING, "filter parse error"); } ZVAL_BOOL(*return_value, 0); } }
static void cpManagerReload(int sig) { zval *group_conf = NULL; group_conf = cpGetConfig(CPGC.ini_file); if (!Z_BVAL_P(group_conf)) { cpLog("parse ini file[%s] error,%s reload error!", CPGC.ini_file, CPGC.title); } else { zval **v, **conf; if (zend_hash_find(Z_ARRVAL_P(group_conf), CPGC.title, strlen(CPGC.title) + 1, (void **) &conf) == SUCCESS) { if (pthread_mutex_lock(CPGS->mutex_lock) == 0) { if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("pool_max"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGS->worker_max = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("pool_min"), (void **) &v) == SUCCESS) { convert_to_long(*v); int new_min = (int) Z_LVAL_PP(v); if (new_min > CPGC.worker_min) {//增加最小 while (CPGS->worker_num < new_min) { cpCreate_worker_mem(CPGS->worker_num); CPGS->workers_status[CPGS->worker_num] = CP_WORKER_IDLE; CPGS->worker_num++; //先加 线程安全 int new_pid = cpFork_one_worker(CPGS->worker_num - 1); if (new_pid < 0) { cpLog("Fork worker process failed. Error: %s [%d]", strerror(errno), errno); } else { CPGS->workers[CPGS->worker_num - 1].pid = new_pid; } } } CPGC.worker_min = new_min; } if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("recycle_num"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.recycle_num = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("idel_time"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.idel_time = (int) Z_LVAL_PP(v); } if (pthread_mutex_unlock(CPGS->mutex_lock) != 0) { cpLog("pthread_mutex_unlock. Error: %s [%d]", strerror(errno), errno); } } } else { cpLog("find %s failed,The reload can only modify 'pool_min','pool_max','recycle_num' and 'idel_time',if you want modify other options please restart pool", CPGC.title); } zval_ptr_dtor(&group_conf); } }
/** * Updates values on arrays by string or long indexes */ int phalcon_array_update_zval(zval **arr, zval *index, zval **value, int flags TSRMLS_DC){ if (Z_TYPE_PP(arr) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot use a scalar value as an array"); return FAILURE; } if (Z_TYPE_P(index) == IS_NULL) { convert_to_string(index); } else { if (Z_TYPE_P(index) == IS_BOOL || Z_TYPE_P(index) == IS_DOUBLE) { convert_to_long(index); } } if ((flags & PH_CTOR) == PH_CTOR) { zval *new_zv; Z_DELREF_PP(value); ALLOC_ZVAL(new_zv); INIT_PZVAL_COPY(new_zv, *value); *value = new_zv; zval_copy_ctor(new_zv); } if ((flags & PH_SEPARATE) == PH_SEPARATE) { if (Z_REFCOUNT_PP(arr) > 1) { zval *new_zv; Z_DELREF_PP(arr); ALLOC_ZVAL(new_zv); INIT_PZVAL_COPY(new_zv, *arr); *arr = new_zv; zval_copy_ctor(new_zv); } } if ((flags & PH_COPY) == PH_COPY) { Z_ADDREF_PP(value); } if(Z_TYPE_P(index) == IS_STRING){ return zend_hash_update(Z_ARRVAL_PP(arr), Z_STRVAL_P(index), Z_STRLEN_P(index)+1, value, sizeof(zval *), NULL); } else { if (Z_TYPE_P(index) == IS_LONG) { return zend_hash_index_update(Z_ARRVAL_PP(arr), Z_LVAL_P(index), value, sizeof(zval *), NULL); } else { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Illegal offset type"); } } return FAILURE; }
/** * 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; phalcon_fetch_params_ex(2, 0, &message, &context); if (Z_TYPE_PP(context) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_PP(context)) > 0) { HashTable *ht = Z_ARRVAL_PP(context); HashPosition hp; zval *replace, **val; PHALCON_ALLOC_GHOST_ZVAL(replace); array_init_size(replace, zend_hash_num_elements(ht)); for ( zend_hash_internal_pointer_reset_ex(ht, &hp); zend_hash_get_current_data_ex(ht, (void**)&val, &hp) == SUCCESS; zend_hash_move_forward_ex(ht, &hp) ) { char *str_index, *idx; uint str_length; ulong num_index; int type = zend_hash_get_current_key_ex(ht, &str_index, &str_length, &num_index, 0, &hp); if (HASH_KEY_IS_STRING == type) { str_length += 2; idx = emalloc(str_length); idx[0] = '{'; idx[str_length-2] = '}'; idx[str_length-1] = '\0'; memcpy(idx + 1, str_index, str_length - 3); } else if (HASH_KEY_IS_LONG == type) { str_length = spprintf(&idx, 0, "{%ld}", num_index); } else { /* Better safe than sorry */ continue; } Z_ADDREF_PP(val); zend_hash_add(Z_ARRVAL_P(replace), idx, str_length, (void*)val, sizeof(zval*), NULL); efree(idx); } PHALCON_RETURN_CALL_FUNCTIONW("strtr", *message, replace); return; } RETURN_ZVAL(*message, 1, 0); }
void php_functional_append_array_value(int hash_key_type, zval **return_value, zval **value, char *string_key, uint string_key_len, int int_key) { zval_add_ref(return_value); zval_add_ref(value); switch (hash_key_type) { case HASH_KEY_IS_LONG: zend_hash_index_update(Z_ARRVAL_PP(return_value), int_key, (void *)value, sizeof(zval *), NULL); break; case HASH_KEY_IS_STRING: zend_hash_update(Z_ARRVAL_PP(return_value), string_key, string_key_len, (void *)value, sizeof(zval *), NULL); break; } }
/** * Unsets zval index from array */ int PHALCON_FASTCALL phalcon_array_unset(zval **arr, zval *index, int flags) { zval *copy; int exists, copied = 0; if (Z_TYPE_PP(arr) != IS_ARRAY) { return 0; } if (Z_TYPE_P(index) == IS_NULL) { ALLOC_INIT_ZVAL(copy); ZVAL_ZVAL(copy, index, 1, 0); convert_to_string(copy); index = copy; copied = 1; } else { if (Z_TYPE_P(index) == IS_BOOL || Z_TYPE_P(index) == IS_DOUBLE) { ALLOC_INIT_ZVAL(copy); ZVAL_ZVAL(copy, index, 1, 0); convert_to_long(copy); index = copy; copied = 1; } } if ((flags & PH_SEPARATE) == PH_SEPARATE) { if (Z_REFCOUNT_PP(arr) > 1) { zval *new_zv; Z_DELREF_PP(arr); ALLOC_ZVAL(new_zv); INIT_PZVAL_COPY(new_zv, *arr); *arr = new_zv; zval_copy_ctor(new_zv); } } if (Z_TYPE_P(index) == IS_STRING) { exists = zend_hash_del(Z_ARRVAL_PP(arr), Z_STRVAL_P(index), Z_STRLEN_P(index) + 1); } else { exists = zend_hash_index_del(Z_ARRVAL_PP(arr), Z_LVAL_P(index)); } if (copied) { zval_ptr_dtor(©); } return exists; }
/** * @brief Updates value in @a arr at position @a index with @a value * @param[in,out] arr Array * @param index Index * @param[in,out] value Value * @param flags Flags * @return Whether the operation succeeded * @retval @c FAILURE Failure, @a arr is not an array * @retval @c SUCCESS Success * @throw @c E_WARNING if @c arr is not an array * * Equivalent to <tt>$arr[$index] = $value</tt> in PHP where @c $index is an integer. * Flags may be a bitwise OR of the following values: * @arg @c PH_CTOR: create a copy of @a value and work with that copy; @c *value will be updated with the newly constructed value * @arg @c PH_SEPARATE: separate @a arr if its reference count is greater than 1; @c *arr will contain the separated version * @arg @c PH_COPY: increment the reference count on @c **value */ int zephir_array_update_long(zval **arr, unsigned long index, zval **value, int flags ZEPHIR_DEBUG_PARAMS) { if (Z_TYPE_PP(arr) != IS_ARRAY) { zend_error(E_WARNING, "Cannot use a scalar value as an array in %s on line %d", file, line); return FAILURE; } if ((flags & PH_CTOR) == PH_CTOR) { zval *new_zv; Z_DELREF_PP(value); ALLOC_ZVAL(new_zv); INIT_PZVAL_COPY(new_zv, *value); *value = new_zv; zval_copy_ctor(new_zv); } if ((flags & PH_SEPARATE) == PH_SEPARATE) { SEPARATE_ZVAL_IF_NOT_REF(arr); } if ((flags & PH_COPY) == PH_COPY) { Z_ADDREF_PP(value); } return zend_hash_index_update(Z_ARRVAL_PP(arr), index, value, sizeof(zval *), NULL); }
/** * Updates values on arrays by long indexes only */ int phalcon_array_update_long(zval **arr, ulong index, zval **value, int flags TSRMLS_DC){ if (Z_TYPE_PP(arr) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot use a scalar value as an array"); return FAILURE; } if ((flags & PH_CTOR) == PH_CTOR) { zval *new_zv; Z_DELREF_PP(value); ALLOC_ZVAL(new_zv); INIT_PZVAL_COPY(new_zv, *value); *value = new_zv; zval_copy_ctor(new_zv); } if ((flags & PH_SEPARATE) == PH_SEPARATE) { if (Z_REFCOUNT_PP(arr) > 1) { zval *new_zv; Z_DELREF_PP(arr); ALLOC_ZVAL(new_zv); INIT_PZVAL_COPY(new_zv, *arr); *arr = new_zv; zval_copy_ctor(new_zv); } } if ((flags & PH_COPY) == PH_COPY) { Z_ADDREF_PP(value); } return zend_hash_index_update(Z_ARRVAL_PP(arr), index, value, sizeof(zval *), NULL); }
/** * @brief Unsets @a index from array @a arr * @param[in,out] arr Array * @param index Index * @param flags Flags (@c PH_SEPARATE: separate array if its reference count is greater than 1; @c arr will contain the separated array) * @return Whether the operation succeeded * @retval @c FAILURE Failure, @a arr is not an array or @a index is of not supported type * @retval @c SUCCESS Success * @note @c index will be handled as follows: @c NULL is treated as an empty string, @c double values are cast to @c integer, @c bool or @c resource are treated as @c integer * @throw @c E_WARNING if @a offset is not a scalar */ int ZEPHIR_FASTCALL zephir_array_unset(zval **arr, zval *index, int flags) { HashTable *ht; if (Z_TYPE_PP(arr) != IS_ARRAY) { return FAILURE; } if ((flags & PH_SEPARATE) == PH_SEPARATE) { SEPARATE_ZVAL_IF_NOT_REF(arr); } ht = Z_ARRVAL_PP(arr); switch (Z_TYPE_P(index)) { case IS_NULL: return (zend_hash_del(ht, "", 1) == SUCCESS); case IS_DOUBLE: return (zend_hash_index_del(ht, (ulong)Z_DVAL_P(index)) == SUCCESS); case IS_LONG: case IS_BOOL: case IS_RESOURCE: return (zend_hash_index_del(ht, Z_LVAL_P(index)) == SUCCESS); case IS_STRING: return (zend_symtable_del(ht, Z_STRVAL_P(index), Z_STRLEN_P(index)+1) == SUCCESS); default: zend_error(E_WARNING, "Illegal offset type"); return 0; } }
/* {{{ php_tmpl_parse_check_memory */ inline void php_tmpl_parse_check_memory(t_template* tmpl, HashPosition *dup_tag_pos, t_tmpl_tag* tag, uint tag_mod, zval** iteration, zval** dest, uint* offset) { zval **dup_ztag; t_tmpl_tag *dup_tag; if(NULL == *dup_tag_pos || !zend_hash_num_elements(Z_ARRVAL_P(tmpl->dup_tag))) return; /* The next line has been added to avoid skiping of duplicate tags in some circumstances. This is sort of a dirty fix and needs to be optimized for speed. */ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tmpl->dup_tag), dup_tag_pos); do { if(FAILURE == zend_hash_get_current_data_ex(Z_ARRVAL_P(tmpl->dup_tag), (void*)&dup_ztag, dup_tag_pos)) break; dup_tag = Z_TMPL_TAG(dup_ztag); if(*offset > dup_tag->loff) continue; if(TMPL_TAG == tag_mod) { if(dup_tag->ctx != tag->ctx && dup_tag->loff < tag->loff) continue; if(dup_tag->ctx != tag->ctx || dup_tag->loff >= tag->loff) break; } else { if(dup_tag->ctx != tag && dup_tag->loff < tag->roff) continue; if(dup_tag->ctx != tag || dup_tag->loff > tag->roff) break; } TMPL_PARSE_DEST_ADD(*offset, dup_tag->loff - *offset); *offset = dup_tag->roff; if(FAILURE == zend_hash_find(Z_ARRVAL_PP(iteration), ZV(dup_tag->name), ZL(dup_tag->name)+1, (void*)&dup_ztag)) continue; TMPL_PARSE_DEST_ADD(Z_STRVAL_PP(dup_ztag)-Z_STRVAL_P(tmpl->original), Z_STRLEN_PP(dup_ztag)); } while(SUCCESS == zend_hash_move_forward_ex(Z_ARRVAL_P(tmpl->dup_tag), dup_tag_pos)); }
void binary_serialize_spec(zval* zthis, PHPOutputTransport& transport, HashTable* spec) { HashPosition key_ptr; zval** val_ptr; TSRMLS_FETCH(); zend_class_entry* ce = zend_get_class_entry(zthis TSRMLS_CC); for (zend_hash_internal_pointer_reset_ex(spec, &key_ptr); zend_hash_get_current_data_ex(spec, (void**)&val_ptr, &key_ptr) == SUCCESS; zend_hash_move_forward_ex(spec, &key_ptr)) { ulong fieldno; if (zend_hash_get_current_key_ex(spec, NULL, NULL, &fieldno, 0, &key_ptr) != HASH_KEY_IS_LONG) { throw_tprotocolexception("Bad keytype in TSPEC (expected 'long')", INVALID_DATA); return; } HashTable* fieldspec = Z_ARRVAL_PP(val_ptr); // field name zend_hash_find(fieldspec, "var", 4, (void**)&val_ptr); char* varname = Z_STRVAL_PP(val_ptr); // thrift type zend_hash_find(fieldspec, "type", 5, (void**)&val_ptr); if (Z_TYPE_PP(val_ptr) != IS_LONG) convert_to_long(*val_ptr); int8_t ttype = Z_LVAL_PP(val_ptr); zval* prop = zend_read_property(ce, zthis, varname, strlen(varname), false TSRMLS_CC); if (Z_TYPE_P(prop) != IS_NULL) { transport.writeI8(ttype); transport.writeI16(fieldno); binary_serialize(ttype, transport, &prop, fieldspec); } } transport.writeI8(T_STOP); // struct end }
/** * @brief Updates value in @a arr at position @a index with @a value using the precomputed hash @a key * @param[in,out] arr Array * @param index Index * @param index_length Length of the index, should include the trailing zero * @param key Precomputed hash of @c value * @param value Value * @param flags Flags * @return Whether the operation succeeded * @retval @c FAILURE Failure, @a arr is not an array * @retval @c SUCCESS Success * @throw @c E_WARNING if @a arr is not an array * * Equivalent to <tt>$arr[$index] = $value</tt> in PHP. * * Flags may be a bitwise OR of the following values: * @arg @c PH_CTOR: create a copy of @a value and work with that copy; @c *value will be updated with the newly constructed value * @arg @c PH_SEPARATE: separate @a arr if its reference count is greater than 1; @c *arr will contain the separated version * @arg @c PH_COPY: increment the reference count on @c **value */ int zephir_array_update_quick_string(zval **arr, const char *index, uint index_length, unsigned long key, zval **value, int flags) { if (Z_TYPE_PP(arr) != IS_ARRAY) { zend_error(E_WARNING, "Cannot use a scalar value as an array (3)"); return FAILURE; } if ((flags & PH_CTOR) == PH_CTOR) { zval *new_zv; Z_DELREF_PP(value); ALLOC_ZVAL(new_zv); INIT_PZVAL_COPY(new_zv, *value); *value = new_zv; zval_copy_ctor(new_zv); } if ((flags & PH_SEPARATE) == PH_SEPARATE) { SEPARATE_ZVAL_IF_NOT_REF(arr); } if ((flags & PH_COPY) == PH_COPY) { Z_ADDREF_PP(value); } return zend_hash_quick_update(Z_ARRVAL_PP(arr), index, index_length, key, value, sizeof(zval *), NULL); }
/* {{{ pip_hash_to_dict(zval **hash) Convert a PHP hash to a Python dictionary */ PyObject * pip_hash_to_dict(zval **hash) { PyObject *dict, *item, *integer; zval **entry; char *string_key; long num_key = 0; /* Make sure we were given a PHP hash */ if (Z_TYPE_PP(hash) != IS_ARRAY) { return NULL; } /* Create a new empty dictionary */ dict = PyDict_New(); /* Let's start at the very beginning, a very good place to start. */ zend_hash_internal_pointer_reset(Z_ARRVAL_PP(hash)); /* Iterate over the hash's elements */ while (zend_hash_get_current_data(Z_ARRVAL_PP(hash), (void **)&entry) == SUCCESS) { /* Convert the PHP value to its Python equivalent (recursion) */ item = pip_zval_to_pyobject(entry); /* Assign the item with the appropriate key type (string or integer) */ switch (zend_hash_get_current_key(Z_ARRVAL_PP(hash), &string_key, &num_key, 0)) { case HASH_KEY_IS_STRING: PyDict_SetItemString(dict, string_key, item); break; case HASH_KEY_IS_LONG: integer = PyInt_FromLong(num_key); PyDict_SetItem(dict, integer, item); Py_DECREF(integer); break; } /* Advance to the next entry */ zend_hash_move_forward(Z_ARRVAL_PP(hash)); } return dict; }
/** * @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); } }
/* ****************************************************************************************************** Applies a UDF to a record at the Aerospike DB. * * @param aerospike_obj_p The C client's aerospike object. * @param as_key_p The C client's as_key that identifies the * record on which UDF will be applied. * @param error_p The C client's as_error to be set to the encountered error. * @param module_p The name of the UDF module registered * against the Aerospike DB. * @param function_p The name of the function to be applied to * the record. * @param args_pp An array of arguments for the UDF. * @param return_value_p It will contain result value of calling the * UDF. * @param options_p The optional policy. * * @return AEROSPIKE_OK if success. Otherwise AEROSPIKE_x. ****************************************************************************************************** */ extern as_status aerospike_udf_apply(Aerospike_object* aerospike_obj_p, as_key* as_key_p, as_error* error_p, char* module_p, char* function_p, zval** args_pp, zval* return_value_p, zval* options_p) { as_arraylist args_list; as_arraylist* args_list_p = NULL; as_static_pool udf_pool = {0}; as_val* udf_result_p = NULL; foreach_callback_udata udf_result_callback_udata; uint32_t serializer_policy = -1; as_policy_apply apply_policy; TSRMLS_FETCH_FROM_CTX(aerospike_obj_p->ts); set_policy_udf_apply(&aerospike_obj_p->as_ref_p->as_p->config, &apply_policy, &serializer_policy, options_p, error_p TSRMLS_CC); if (AEROSPIKE_OK != (error_p->code)) { DEBUG_PHP_EXT_DEBUG("Unable to set policy"); goto exit; } if ((*args_pp)) { as_arraylist_inita(&args_list, zend_hash_num_elements(Z_ARRVAL_PP(args_pp))); args_list_p = &args_list; AS_LIST_PUT(NULL, args_pp, args_list_p, &udf_pool, serializer_policy, error_p TSRMLS_CC); } if (AEROSPIKE_OK != (aerospike_key_apply(aerospike_obj_p->as_ref_p->as_p, error_p, &apply_policy, as_key_p, module_p, function_p, (as_list *) args_list_p, &udf_result_p))) { DEBUG_PHP_EXT_DEBUG("%s", error_p->message); goto exit; } if (return_value_p) { udf_result_callback_udata.udata_p = return_value_p; udf_result_callback_udata.error_p = error_p; AS_DEFAULT_GET(NULL, udf_result_p, &udf_result_callback_udata); } exit: if (udf_result_p) { as_val_destroy(udf_result_p); } if (args_list_p) { as_arraylist_destroy(args_list_p); } /* clean up the as_* objects that were initialised */ aerospike_helper_free_static_pool(&udf_pool); return error_p->code; }
inline int validate_request_method(zval **z_route_options_pp, int current_request_method TSRMLS_DC) { zval **z_route_method = NULL; if ( zend_hash_find( Z_ARRVAL_PP(z_route_options_pp) , "method", sizeof("method"), (void**) &z_route_method ) == SUCCESS ) { if ( Z_TYPE_PP(z_route_method) == IS_LONG && Z_LVAL_PP(z_route_method) != current_request_method ) { return 0; } } return 1; }
void php_functional_prepare_array_key(int hash_key_type, zval **key, zval ***value, char *string_key, uint string_key_len, int int_key, zval **return_value, int collect) { switch (hash_key_type) { case HASH_KEY_IS_LONG: Z_TYPE_PP(key) = IS_LONG; Z_LVAL_PP(key) = int_key; if (collect) { zend_hash_index_update(Z_ARRVAL_PP(return_value), int_key, *value, sizeof(zval *), NULL); } break; case HASH_KEY_IS_STRING: ZVAL_STRINGL(*key, string_key, string_key_len - 1, 1); if (collect) { zend_hash_update(Z_ARRVAL_PP(return_value), string_key, string_key_len, *value, sizeof(zval *), NULL); } break; } }
/* Extract a single optional/required or multiple repeated sub messages from native php types into the given protobuf message. Allocates memory for the created messages */ int message_proto (const ProtobufCMessage* message, const ProtobufCFieldDescriptor* field, zval** val) { if (Z_TYPE_PP(val) != IS_ARRAY) return 1; const void* member = get_member(message, field); unsigned int* quantifier = get_quantifier(message, field); ProtobufCMessageDescriptor* descriptor = (ProtobufCMessageDescriptor*)field->descriptor; if (field->label == PROTOBUF_C_LABEL_REQUIRED) { ProtobufCMessage* base = emalloc(descriptor->sizeof_message); protobuf_c_message_init(descriptor, base); php_message(base, val[0]); memcpy((void*)member, (void*)&base, sizeof(void*)); } else if (field->label == PROTOBUF_C_LABEL_REPEATED) { HashPosition pos; HashTable* hash_table = Z_ARRVAL_PP(val); size_t* num_elements = emalloc(sizeof(size_t)); num_elements[0] = (size_t)zend_hash_num_elements(hash_table); zval** data; char* key; int i, key_len, curr = 0; long index; void** values = emalloc(sizeof(void*) * *num_elements); zend_hash_internal_pointer_reset_ex(hash_table, &pos); for (;; zend_hash_move_forward_ex(hash_table, &pos)) { zend_hash_get_current_data_ex(hash_table, (void**)&data, &pos); i = zend_hash_get_current_key_ex(hash_table, &key, &key_len, &index, 0, &pos); if (i == HASH_KEY_NON_EXISTANT) { break; } void* curr_value = emalloc(descriptor->sizeof_message); protobuf_c_message_init(descriptor, curr_value); php_message((ProtobufCMessage*)curr_value, data[0]); values[curr] = curr_value; curr++; } memcpy((void*)member, (void*)&values, sizeof(void*)); memcpy((void*)quantifier, (void*)num_elements, sizeof(void*)); } return 0; }
inline int validate_https(zval **z_route_options_pp, int https TSRMLS_DC) { zval **z_route_secure = NULL; if ( zend_hash_find( Z_ARRVAL_PP(z_route_options_pp) , "secure", sizeof("secure"), (void**) &z_route_secure ) == SUCCESS ) { // check HTTPS flag if ( https && ! Z_BVAL_PP(z_route_secure) ) { return 0; } } return 1; }
/* {{{ php_tmpl_set */ int php_tmpl_set(t_template* tmpl, zval* path, zval** data) { zval **iteration, *cp_data, **ztag; t_tmpl_tag *tag; char *p; if(FAILURE == zend_hash_find(Z_ARRVAL_P(tmpl->tags), ZV(path), ZL(path)+1, (void*)&ztag)) { /* php_error(E_NOTICE, "Can't set value for tag/context \"%s\" which doesn't exist", ZV(path)); */ return FAILURE; } tag = Z_TMPL_TAG(ztag); if(TMPL_TAG == tag->typ) { if((iteration = (zval**)php_tmpl_get_iteration(tmpl, path, TMPL_ITERATION_CURRENT)) == NULL) { return FAILURE; } } else { for(p = ZV(path)+ZL(path); p >= ZV(path) && *p != '/'; p--); *(p > ZV(path) ? p++ : ++p) = 0; ZL(path) = strlen(ZV(path)); if((iteration = (zval**)php_tmpl_get_iteration(tmpl, path, TMPL_ITERATION_CURRENT)) == NULL) { return FAILURE; } } convert_to_string_ex(data); MAKE_STD_ZVAL(cp_data); ZVAL_STRINGL(cp_data, Z_STRVAL_PP(data), Z_STRLEN_PP(data), 1); if(SUCCESS == zend_hash_find(Z_ARRVAL_PP(iteration), ZV(tag->name), ZL(tag->name)+1, (void*)&ztag)) { if(IS_ARRAY == Z_TYPE_PP(ztag)) { /* MEMORY LEAK CAUSED BY THE NEXT LINE !!! */ zend_hash_del(Z_ARRVAL_PP(iteration), ZV(tag->name), ZL(tag->name)+1); } else { tmpl->size -= (Z_STRLEN_PP(ztag) * tag->tag_num); } } zend_hash_update(Z_ARRVAL_PP(iteration), ZV(tag->name), ZL(tag->name)+1, (void*)&cp_data, sizeof(zval**), NULL); tmpl->size += (ZL(cp_data) * tag->tag_num); return SUCCESS; }
/* Extract uint32_t values from the given zval** and write them into the given protobuf message pointer. handle optional/required/repeated */ int uint32_proto (const ProtobufCMessage* message, const ProtobufCFieldDescriptor* field, zval** val) { uint32_t* member = (uint32_t*)get_member(message, field); unsigned int* quantifier = get_quantifier(message, field); if (field->label == PROTOBUF_C_LABEL_REQUIRED || field->label == PROTOBUF_C_LABEL_OPTIONAL) { if (Z_TYPE_PP(val) == IS_LONG) *member = (uint32_t)Z_LVAL_PP(val); else if (Z_TYPE_PP(val) == IS_DOUBLE) *member = (uint32_t)Z_DVAL_PP(val); else return 1; if (field->label == PROTOBUF_C_LABEL_OPTIONAL) *quantifier = 1; } else if (field->label == PROTOBUF_C_LABEL_REPEATED) { if (Z_TYPE_PP(val) != IS_ARRAY) return 1; HashPosition pos; HashTable* hash_table = Z_ARRVAL_PP(val); size_t num_elements = (size_t)zend_hash_num_elements(hash_table); zval** data; char* key; int i, key_len, curr = 0; long index; uint32_t* values = emalloc(sizeof(uint32_t) * num_elements); zend_hash_internal_pointer_reset_ex(hash_table, &pos); for (;; zend_hash_move_forward_ex(hash_table, &pos)) { zend_hash_get_current_data_ex(hash_table, (void**)&data, &pos); i = zend_hash_get_current_key_ex(hash_table, &key, &key_len, &index, 0, &pos); if (i == HASH_KEY_NON_EXISTANT) break; if (Z_TYPE_PP(data) == IS_LONG) values[curr++] = (uint32_t)(Z_LVAL_PP(data)); else if (Z_TYPE_PP(data) == IS_DOUBLE) values[curr++] = (uint32_t)(Z_DVAL_PP(data)); } *quantifier = num_elements; memcpy((void*)member, (void*)&values, sizeof(void*)); } return 0; }
/** * @brief Unsets string @a index from array @a arr * @param[in,out] arr Array * @param index Index * @param index_length strlen(index)+1 * @param flags Flags (@c PH_SEPARATE: separate array if its reference count is greater than 1; @c arr will contain the separated array) * @return Whether the operation succeeded * @retval @c FAILURE Failure or @a arr is not an array * @retval @c SUCCESS Success */ int ZEPHIR_FASTCALL zephir_array_unset_string(zval **arr, const char *index, uint index_length, int flags) { if (Z_TYPE_PP(arr) != IS_ARRAY) { return 0; } if ((flags & PH_SEPARATE) == PH_SEPARATE) { SEPARATE_ZVAL_IF_NOT_REF(arr); } return zend_hash_del(Z_ARRVAL_PP(arr), index, index_length); }
/** * @brief Unsets numeric @a index from array @a arr * @param[in,out] arr Array * @param index Index * @param flags Flags (@c PH_SEPARATE: separate array if its reference count is greater than 1; @c arr will contain the separated array) * @return Whether the operation succeeded * @retval @c FAILURE Failure or @a arr is not an array * @retval @c SUCCESS Success */ int ZEPHIR_FASTCALL zephir_array_unset_long(zval **arr, unsigned long index, int flags) { if (Z_TYPE_PP(arr) != IS_ARRAY) { return 0; } if ((flags & PH_SEPARATE) == PH_SEPARATE) { SEPARATE_ZVAL_IF_NOT_REF(arr); } return zend_hash_index_del(Z_ARRVAL_PP(arr), index); }
extern void xslt_assign_handler(struct xslt_function **func, zval **zfunc) { char error[] = "Invalid function passed to %s"; *func = emalloc(sizeof(struct xslt_function)); if (Z_TYPE_PP(zfunc) == IS_STRING) { (*func)->obj = NULL; zval_add_ref(zfunc); (*func)->func = *zfunc; } else if (Z_TYPE_PP(zfunc) == IS_ARRAY) { zval **obj; zval **function; if (zend_hash_index_find(Z_ARRVAL_PP(zfunc), 0, (void **) &obj) == FAILURE) { efree(*func); php_error(E_WARNING, error, get_active_function_name()); return; } if (zend_hash_index_find(Z_ARRVAL_PP(zfunc), 1, (void **) &function) == FAILURE) { efree(*func); php_error(E_WARNING, error, get_active_function_name()); return; } zval_add_ref(obj); zval_add_ref(function); (*func)->obj = *obj; (*func)->func = *function; } else { efree(*func); php_error(E_WARNING, error, get_active_function_name()); } }