这篇教程C++ zend_hash_num_elements函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中zend_hash_num_elements函数的典型用法代码示例。如果您正苦于以下问题:C++ zend_hash_num_elements函数的具体用法?C++ zend_hash_num_elements怎么用?C++ zend_hash_num_elements使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了zend_hash_num_elements函数的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: ONPHP_METHODONPHP_METHOD(Joiner, getTablesCount){ zval *tables = ONPHP_READ_PROPERTY(getThis(), "tables"); RETURN_LONG(zend_hash_num_elements(Z_ARRVAL_P(tables)));}
开发者ID:suquant,项目名称:soloweb-onphp,代码行数:6,
示例2: zend_optimizer_compact_literals//.........这里部分代码省略......... LITERAL_NUM_RELATED(info[i].flags) == LITERAL_NUM_RELATED(info[Z_LVAL_P(pos)].flags) && (LITERAL_NUM_RELATED(info[i].flags) != 2 || ((info[i].flags & LITERAL_KIND_MASK) != LITERAL_VALUE && (info[Z_LVAL_P(pos)].flags & LITERAL_KIND_MASK) != LITERAL_VALUE))) { zend_string_release_ex(key, 0); map[i] = Z_LVAL_P(pos); zval_ptr_dtor_nogc(&op_array->literals[i]); n = LITERAL_NUM_RELATED(info[i].flags); while (n > 1) { i++; zval_ptr_dtor_nogc(&op_array->literals[i]); n--; } } else { map[i] = j; ZVAL_LONG(&zv, j); zend_hash_add_new(&hash, key, &zv); zend_string_release_ex(key, 0); if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; n = LITERAL_NUM_RELATED(info[i].flags); while (n > 1) { i++; if (i != j) op_array->literals[j] = op_array->literals[i]; j++; n--; } } break; case IS_ARRAY: if (zend_hash_num_elements(Z_ARRVAL(op_array->literals[i])) == 0) { if (l_empty_arr < 0) { l_empty_arr = j; if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; } else { zval_ptr_dtor_nogc(&op_array->literals[i]); } map[i] = l_empty_arr; break; } /* break missing intentionally */ default: /* don't merge other types */ map[i] = j; if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; break; } } zend_hash_clean(&hash); op_array->last_literal = j; const_slot = zend_arena_alloc(&ctx->arena, j * 6 * sizeof(int)); memset(const_slot, -1, j * 6 * sizeof(int)); class_slot = const_slot + j; func_slot = class_slot + j;
开发者ID:crrodriguez,项目名称:php-src,代码行数:67,
示例3: Z_ADDREF_P#include "msgformat_helpers.h"#include "intl_convert.h"#ifndef Z_ADDREF_P#define Z_ADDREF_P(z) ((z)->refcount++)#endif/* {{{ */static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *return_value TSRMLS_DC){ int count; UChar* formatted = NULL; int formatted_len = 0; HashTable *args_copy; count = zend_hash_num_elements(Z_ARRVAL_P(args)); ALLOC_HASHTABLE(args_copy); zend_hash_init(args_copy, count, NULL, ZVAL_PTR_DTOR, 0); zend_hash_copy(args_copy, Z_ARRVAL_P(args), (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*)); umsg_format_helper(mfo, args_copy, &formatted, &formatted_len TSRMLS_CC); zend_hash_destroy(args_copy); efree(args_copy); if (formatted && U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) { efree(formatted); }
开发者ID:huangjialin,项目名称:php-src,代码行数:30,
示例4: binary_serializevoid binary_serialize(int8_t thrift_typeID, PHPOutputTransport& transport, zval** value, HashTable* fieldspec) { // At this point the typeID (and field num, if applicable) should've already been written to the output so all we need to do is write the payload. switch (thrift_typeID) { case T_STOP: case T_VOID: return; case T_STRUCT: { TSRMLS_FETCH(); if (Z_TYPE_PP(value) != IS_OBJECT) { throw_tprotocolexception("Attempt to send non-object type as a T_STRUCT", INVALID_DATA); } zval* spec = zend_read_static_property(zend_get_class_entry(*value TSRMLS_CC), "_TSPEC", 6, false TSRMLS_CC); binary_serialize_spec(*value, transport, Z_ARRVAL_P(spec)); } return; case T_BOOL: if (Z_TYPE_PP(value) != IS_BOOL) convert_to_boolean(*value); transport.writeI8(Z_BVAL_PP(value) ? 1 : 0); return; case T_BYTE: if (Z_TYPE_PP(value) != IS_LONG) convert_to_long(*value); transport.writeI8(Z_LVAL_PP(value)); return; case T_I16: if (Z_TYPE_PP(value) != IS_LONG) convert_to_long(*value); transport.writeI16(Z_LVAL_PP(value)); return; case T_I32: if (Z_TYPE_PP(value) != IS_LONG) convert_to_long(*value); transport.writeI32(Z_LVAL_PP(value)); return; case T_I64: case T_U64: if (Z_TYPE_PP(value) != IS_LONG) convert_to_long(*value); transport.writeI64(Z_LVAL_PP(value)); return; case T_DOUBLE: { union { int64_t c; double d; } a; if (Z_TYPE_PP(value) != IS_DOUBLE) convert_to_double(*value); a.d = Z_DVAL_PP(value); transport.writeI64(a.c); } return; //case T_UTF7: case T_UTF8: case T_UTF16: case T_STRING: if (Z_TYPE_PP(value) != IS_STRING) convert_to_string(*value); transport.writeString(Z_STRVAL_PP(value), Z_STRLEN_PP(value)); return; case T_MAP: { if (Z_TYPE_PP(value) != IS_ARRAY) convert_to_array(*value); if (Z_TYPE_PP(value) != IS_ARRAY) { throw_tprotocolexception("Attempt to send an incompatible type as an array (T_MAP)", INVALID_DATA); } HashTable* ht = Z_ARRVAL_PP(value); zval** val_ptr; zend_hash_find(fieldspec, "ktype", 6, (void**)&val_ptr); if (Z_TYPE_PP(val_ptr) != IS_LONG) convert_to_long(*val_ptr); uint8_t keytype = Z_LVAL_PP(val_ptr); transport.writeI8(keytype); zend_hash_find(fieldspec, "vtype", 6, (void**)&val_ptr); if (Z_TYPE_PP(val_ptr) != IS_LONG) convert_to_long(*val_ptr); uint8_t valtype = Z_LVAL_PP(val_ptr); transport.writeI8(valtype); zend_hash_find(fieldspec, "val", 4, (void**)&val_ptr); HashTable* valspec = Z_ARRVAL_PP(val_ptr); transport.writeI32(zend_hash_num_elements(ht)); HashPosition key_ptr; for (zend_hash_internal_pointer_reset_ex(ht, &key_ptr); zend_hash_get_current_data_ex(ht, (void**)&val_ptr, &key_ptr) == SUCCESS; zend_hash_move_forward_ex(ht, &key_ptr)) { binary_serialize_hashtable_key(keytype, transport, ht, key_ptr); binary_serialize(valtype, transport, val_ptr, valspec); } } return; case T_LIST: { if (Z_TYPE_PP(value) != IS_ARRAY) convert_to_array(*value); if (Z_TYPE_PP(value) != IS_ARRAY) { throw_tprotocolexception("Attempt to send an incompatible type as an array (T_LIST)", INVALID_DATA); } HashTable* ht = Z_ARRVAL_PP(value); zval** val_ptr; zend_hash_find(fieldspec, "etype", 6, (void**)&val_ptr); if (Z_TYPE_PP(val_ptr) != IS_LONG) convert_to_long(*val_ptr); uint8_t valtype = Z_LVAL_PP(val_ptr); transport.writeI8(valtype); zend_hash_find(fieldspec, "elem", 5, (void**)&val_ptr); HashTable* valspec = Z_ARRVAL_PP(val_ptr); transport.writeI32(zend_hash_num_elements(ht)); HashPosition key_ptr; for (zend_hash_internal_pointer_reset_ex(ht, &key_ptr); zend_hash_get_current_data_ex(ht, (void**)&val_ptr, &key_ptr) == SUCCESS; zend_hash_move_forward_ex(ht, &key_ptr)) {//.........这里部分代码省略.........
开发者ID:wmorgan,项目名称:thrift,代码行数:101,
示例5: _php_array_to_envp/* {{{ _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) { 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)) { convert_to_string_ex(element); 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+1; 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)) { convert_to_string_ex(element); el_len = Z_STRLEN_PP(element); if (el_len == 0) { continue; } data = Z_STRVAL_PP(element); 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; } l = string_length + el_len + 1; memcpy(p, string_key, string_length); strcat(p, "="); strcat(p, data); #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_EXISTANT: break; } } //.........这里部分代码省略.........
开发者ID:Skull-Li,项目名称:dezend,代码行数:101,
示例6: pgsql_stmt_param_hookstatic int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, enum pdo_param_event event_type){ pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; if (stmt->supports_placeholders == PDO_PLACEHOLDER_NAMED && param->is_param) { switch (event_type) { case PDO_PARAM_EVT_FREE: if (param->driver_data) { efree(param->driver_data); } break; case PDO_PARAM_EVT_NORMALIZE: /* decode name from $1, $2 into 0, 1 etc. */ if (param->name) { if (param->name->val[0] == '$') { ZEND_ATOL(param->paramno, param->name->val + 1); } else { /* resolve parameter name to rewritten name */ char *namevar; if (stmt->bound_param_map && (namevar = zend_hash_find_ptr(stmt->bound_param_map, param->name)) != NULL) { ZEND_ATOL(param->paramno, namevar + 1); param->paramno--; } else { pdo_raise_impl_error(stmt->dbh, stmt, "HY093", param->name->val); return 0; } } } break; case PDO_PARAM_EVT_ALLOC: case PDO_PARAM_EVT_EXEC_POST: case PDO_PARAM_EVT_FETCH_PRE: case PDO_PARAM_EVT_FETCH_POST: /* work is handled by EVT_NORMALIZE */ return 1; case PDO_PARAM_EVT_EXEC_PRE: if (!stmt->bound_param_map) { return 0; } if (!S->param_values) { S->param_values = ecalloc( zend_hash_num_elements(stmt->bound_param_map), sizeof(char*)); S->param_lengths = ecalloc( zend_hash_num_elements(stmt->bound_param_map), sizeof(int)); S->param_formats = ecalloc( zend_hash_num_elements(stmt->bound_param_map), sizeof(int)); S->param_types = ecalloc( zend_hash_num_elements(stmt->bound_param_map), sizeof(Oid)); } if (param->paramno >= 0) { zval *parameter; if (param->paramno >= zend_hash_num_elements(stmt->bound_params)) { pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined"); return 0; } if (Z_ISREF(param->parameter)) { parameter = Z_REFVAL(param->parameter); } else { parameter = ¶m->parameter; } if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB && Z_TYPE_P(parameter) == IS_RESOURCE) { php_stream *stm; php_stream_from_zval_no_verify(stm, parameter); if (stm) { if (php_stream_is(stm, &pdo_pgsql_lob_stream_ops)) { struct pdo_pgsql_lob_self *self = (struct pdo_pgsql_lob_self*)stm->abstract; pdo_pgsql_bound_param *P = param->driver_data; if (P == NULL) { P = ecalloc(1, sizeof(*P)); param->driver_data = P; } P->oid = htonl(self->oid); S->param_values[param->paramno] = (char*)&P->oid; S->param_lengths[param->paramno] = sizeof(P->oid); S->param_formats[param->paramno] = 1; S->param_types[param->paramno] = OIDOID; return 1; } else { zend_string *str = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); if (str != NULL) { //??SEPARATE_ZVAL_IF_NOT_REF(¶m->parameter); ZVAL_STR(parameter, str); } else { ZVAL_EMPTY_STRING(parameter); }//.........这里部分代码省略.........
开发者ID:0xhacking,项目名称:php-src,代码行数:101,
示例7: zend_accel_copy_internal_functionsvoid zend_accel_copy_internal_functions(void){ zend_hash_apply_with_argument(CG(function_table), (apply_func_arg_t)copy_internal_function, &ZCG(function_table)); ZCG(internal_functions_count) = zend_hash_num_elements(&ZCG(function_table));}
开发者ID:erikjwaxx,项目名称:php-src,代码行数:5,
示例8: switchstatic inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, uint32_t type, HashTable *vars) /* {{{ */{ char *decode = NULL; switch (type &~ EXT_TYPE_UNUSED) { case IS_CV: { zend_string *var = ops->vars[EX_VAR_TO_NUM(op->var)]; asprintf(&decode, "$%.*s%c", var->len <= 19 ? (int) var->len : 18, var->val, var->len <= 19 ? 0 : '+'); } break; case IS_VAR: case IS_TMP_VAR: { zend_ulong id = 0, *pid = NULL; if (vars != NULL) { if ((pid = zend_hash_index_find_ptr(vars, (zend_ulong) ops->vars - op->var))) { id = *pid; } else { id = zend_hash_num_elements(vars); zend_hash_index_update_mem(vars, (zend_ulong) ops->vars - op->var, &id, sizeof(zend_ulong)); } } asprintf(&decode, "@" ZEND_ULONG_FMT, id); } break; case IS_CONST: { zval *literal = RT_CONSTANT(ops, *op); switch (Z_TYPE_P(literal)) { case IS_UNDEF: decode = zend_strndup("", 0); break; case IS_NULL: decode = zend_strndup(ZEND_STRL("null")); break; case IS_FALSE: decode = zend_strndup(ZEND_STRL("false")); break; case IS_TRUE: decode = zend_strndup(ZEND_STRL("true")); break; case IS_LONG: asprintf(&decode, "%lld", Z_LVAL_P(literal)); break; case IS_DOUBLE: asprintf(&decode, "%.*G", 14, Z_DVAL_P(literal)); break; case IS_STRING: { int i; zend_string *str = php_addcslashes(Z_STR_P(literal), 0, "///"", 2); for (i = 0; i < str->len; i++) { if (str->val[i] < 32) { str->val[i] = ' '; } } asprintf(&decode, "/"%.*s/"%c", str->len <= 18 ? (int) str->len : 17, str->val, str->len <= 18 ? 0 : '+'); zend_string_release(str); } break; case IS_RESOURCE: asprintf(&decode, "Rsrc #%d", Z_RES_HANDLE_P(literal)); break; case IS_ARRAY: asprintf(&decode, "array(%d)", zend_hash_num_elements(Z_ARR_P(literal))); break; case IS_OBJECT: { zend_string *str = Z_OBJCE_P(literal)->name; asprintf(&decode, "%.*s%c", str->len <= 18 ? (int) str->len : 18, str->val, str->len <= 18 ? 0 : '+'); } break; case IS_CONSTANT: decode = zend_strndup(ZEND_STRL("<constant>")); break; case IS_CONSTANT_AST: decode = zend_strndup(ZEND_STRL("<ast>")); break; default: asprintf(&decode, "unknown type: %d", Z_TYPE_P(literal)); break; } } break; case IS_UNUSED: asprintf(&decode, "<unused>"); break; } return decode;} /* }}} */
开发者ID:lllito,项目名称:php-src,代码行数:84,
示例9: xc_coverager_save_cov/* }}} */static void xc_coverager_save_cov(char *srcfile, char *outfilename, coverager_t cov TSRMLS_DC) /* {{{ */{ long *buf = NULL, *p; long covlines, *phits; int fd = -1; int size; int newfile; struct stat srcstat, outstat; HashPosition pos; char *contents = NULL; long len; if (stat(srcfile, &srcstat) != 0) { return; } newfile = 0; if (stat(outfilename, &outstat) != 0) { newfile = 1; } else { if (srcstat.st_mtime > outstat.st_mtime) { newfile = 1; } } fd = open(outfilename, O_RDWR | O_CREAT, 0600); if (fd < 0) { char *chr; chr = strrchr(srcfile, PHP_DIR_SEPARATOR); if (chr) { *chr = '/0'; xcache_mkdirs_ex(xc_coveragedump_dir, strlen(xc_coveragedump_dir), srcfile, chr - srcfile TSRMLS_CC); *chr = PHP_DIR_SEPARATOR; } fd = open(outfilename, O_RDWR | O_CREAT, 0600); if (fd < 0) { goto bailout; } } if (flock(fd, LOCK_EX) != SUCCESS) { goto bailout; } if (newfile) { TRACE("%s", "new file"); } else if (outstat.st_size) { len = outstat.st_size; contents = emalloc(len); if (read(fd, (void *) contents, len) != len) { goto bailout; } TRACE("oldsize %d", (int) len); do { p = (long *) contents; len -= sizeof(long); if (len < 0) { break; } if (*p++ != PCOV_HEADER_MAGIC) { TRACE("wrong magic in file %s", outfilename); break; } p += 2; /* skip covliens */ len -= sizeof(long) * 2; if (len < 0) { break; } for (; len >= (int) sizeof(long) * 2; len -= sizeof(long) * 2, p += 2) { if (zend_hash_index_find(cov, p[0], (void**)&phits) == SUCCESS) { if (p[1] == -1) { /* OPTIMIZE: already marked */ continue; } if (*phits != -1) { p[1] += *phits; } } zend_hash_index_update(cov, p[0], &p[1], sizeof(p[1]), NULL); } } while (0); efree(contents); contents = NULL; } /* serialize */ size = (zend_hash_num_elements(cov) + 1) * sizeof(long) * 2 + sizeof(long); p = buf = emalloc(size); *p++ = PCOV_HEADER_MAGIC; p += 2; /* for covlines */ covlines = 0; zend_hash_internal_pointer_reset_ex(cov, &pos); while (zend_hash_get_current_data_ex(cov, (void**)&phits, &pos) == SUCCESS) { *p++ = pos->h;//.........这里部分代码省略.........
开发者ID:alepharchives,项目名称:xcache,代码行数:101,
示例10: PHP_METHOD/** * Load config file * * @param string $filePath */PHP_METHOD(Phalcon_Config_Adapter_Ini, read){ zval *file_path, *absolute_path = NULL, *scanner_mode = NULL, config_dir_path = {}, base_path = {}, ini_config = {}, config = {}, *directives; zend_string *str_key; ulong idx; phalcon_fetch_params(0, 1, 2, &file_path, &absolute_path, &scanner_mode); PHALCON_ENSURE_IS_STRING(file_path); if (!absolute_path) { absolute_path = &PHALCON_GLOBAL(z_false); } if (zend_is_true(absolute_path)) { PHALCON_CPY_WRT_CTOR(&config_dir_path, file_path); } else { phalcon_return_static_property_ce(&base_path, phalcon_config_adapter_ce, SL("_basePath")); PHALCON_CONCAT_VV(&config_dir_path, &base_path, file_path); } /** * Use the standard parse_ini_file */ if (scanner_mode && Z_TYPE_P(scanner_mode) == IS_LONG) { PHALCON_CALL_FUNCTIONW(&ini_config, "parse_ini_file", &config_dir_path, &PHALCON_GLOBAL(z_true), scanner_mode); } else { PHALCON_CALL_FUNCTIONW(&ini_config, "parse_ini_file", &config_dir_path, &PHALCON_GLOBAL(z_true)); } /** * Check if the file had errors */ if (Z_TYPE(ini_config) != IS_ARRAY) { zend_throw_exception_ex(phalcon_config_exception_ce, 0, "Configuration file '%s' cannot be read", Z_STRVAL(config_dir_path)); return; } array_init(&config); ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(ini_config), idx, str_key, directives) { zval section = {}, *value; if (str_key) { ZVAL_STR(§ion, str_key); } else { ZVAL_LONG(§ion, idx); } if (unlikely(Z_TYPE_P(directives) != IS_ARRAY) || zend_hash_num_elements(Z_ARRVAL_P(directives)) == 0) { phalcon_array_update_zval(&config, §ion, directives, PH_COPY); } else { ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(directives), idx, str_key, value) { zval key = {}, directive_parts = {}; if (str_key) { ZVAL_STR(&key, str_key); } else { ZVAL_LONG(&key, idx); } if (str_key && memchr(Z_STRVAL(key), '.', Z_STRLEN(key))) { phalcon_fast_explode_str(&directive_parts, SL("."), &key); phalcon_config_adapter_ini_update_zval_directive(&config, §ion, &directive_parts, value); } else { phalcon_array_update_multi_2(&config, §ion, &key, value, PH_COPY); } } ZEND_HASH_FOREACH_END(); }
开发者ID:dreamsxin,项目名称:cphalcon7,代码行数:72,
示例11: zend_create_closureZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_entry *scope, zval *this_ptr) /* {{{ */{ zend_closure *closure; object_init_ex(res, zend_ce_closure); closure = (zend_closure *)Z_OBJ_P(res); closure->func = *func; closure->func.common.prototype = NULL; if ((scope == NULL) && this_ptr && (Z_TYPE_P(this_ptr) != IS_UNDEF)) { /* use dummy scope if we're binding an object without specifying a scope */ /* maybe it would be better to create one for this purpose */ scope = zend_ce_closure; } if (closure->func.type == ZEND_USER_FUNCTION) { if (closure->func.op_array.static_variables) { HashTable *static_variables = closure->func.op_array.static_variables; ALLOC_HASHTABLE(closure->func.op_array.static_variables); zend_hash_init(closure->func.op_array.static_variables, zend_hash_num_elements(static_variables), NULL, ZVAL_PTR_DTOR, 0); zend_hash_apply_with_arguments(static_variables, zval_copy_static_var, 1, closure->func.op_array.static_variables); } closure->func.op_array.run_time_cache = NULL; (*closure->func.op_array.refcount)++; } else { /* verify that we aren't binding internal function to a wrong scope */ if(func->common.scope != NULL) { if(scope && !instanceof_function(scope, func->common.scope)) { zend_error(E_WARNING, "Cannot bind function %s::%s to scope class %s", func->common.scope->name->val, func->common.function_name->val, scope->name->val); scope = NULL; } if(scope && this_ptr && (func->common.fn_flags & ZEND_ACC_STATIC) == 0 && !instanceof_function(Z_OBJCE_P(this_ptr), closure->func.common.scope)) { zend_error(E_WARNING, "Cannot bind function %s::%s to object of class %s", func->common.scope->name->val, func->common.function_name->val, Z_OBJCE_P(this_ptr)->name->val); scope = NULL; this_ptr = NULL; } } else { /* if it's a free function, we won't set scope & this since they're meaningless */ this_ptr = NULL; scope = NULL; } } ZVAL_UNDEF(&closure->this_ptr); /* Invariants: * If the closure is unscoped, it has no bound object. * The the closure is scoped, it's either static or it's bound */ closure->func.common.scope = scope; if (scope) { closure->func.common.fn_flags |= ZEND_ACC_PUBLIC; if (this_ptr && Z_TYPE_P(this_ptr) == IS_OBJECT && (closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0) { ZVAL_COPY(&closure->this_ptr, this_ptr); } else { closure->func.common.fn_flags |= ZEND_ACC_STATIC; } }}
开发者ID:ahamid,项目名称:php-src,代码行数:61,
示例12: php_runkit_import_functions/* {{{ php_runkit_import_functions */static int php_runkit_import_functions(HashTable *function_table, long flags TSRMLS_DC){ HashPosition pos; int i, func_count = zend_hash_num_elements(function_table); zend_hash_internal_pointer_reset_ex(function_table, &pos); for(i = 0; i < func_count; i++) { zend_function *fe = NULL; char *key, *new_key; int key_len, new_key_len, type; long idx; zend_bool add_function = 1; zend_bool exists = 0; zend_hash_get_current_data_ex(function_table, (void**)&fe, &pos); new_key = fe->common.function_name; new_key_len = strlen(new_key) + 1; if (((type = zend_hash_get_current_key_ex(function_table, &key, &key_len, &idx, 0, &pos)) != HASH_KEY_NON_EXISTANT) && fe && fe->type == ZEND_USER_FUNCTION) { if (type == HASH_KEY_IS_STRING) { new_key = key; new_key_len = key_len; exists = zend_hash_exists(EG(function_table), new_key, new_key_len); } else { exists = zend_hash_index_exists(EG(function_table), idx); } if (exists) { if (flags & PHP_RUNKIT_IMPORT_OVERRIDE) { if (type == HASH_KEY_IS_STRING) { if (zend_hash_del(EG(function_table), new_key, new_key_len) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Inconsistency cleaning up import environment"); return FAILURE; } } else { if (zend_hash_index_del(EG(function_table), idx) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Inconsistency cleaning up import environment"); return FAILURE; } } } else { add_function = 0; } } } if (add_function) { if (zend_hash_add(EG(function_table), new_key, new_key_len, fe, sizeof(zend_function), NULL) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failure importing %s()", fe->common.function_name); PHP_RUNKIT_DESTROY_FUNCTION(fe); return FAILURE; } else { PHP_RUNKIT_FUNCTION_ADD_REF(fe); } } zend_hash_move_forward_ex(function_table, &pos); } return SUCCESS;}
开发者ID:nkresge,项目名称:runkit,代码行数:65,
示例13: php_runkit_import_functions/* $Id$ */#include "php_runkit.h"#include "php_runkit_zval.h"#ifdef PHP_RUNKIT_MANIPULATION/* {{{ php_runkit_import_functions */static int php_runkit_import_functions(HashTable *function_table, long flags#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION > 5) , zend_bool *clear_cache#endif TSRMLS_DC){ HashPosition pos; int i, func_count = zend_hash_num_elements(function_table); zend_hash_internal_pointer_reset_ex(function_table, &pos); for(i = 0; i < func_count; i++) { zend_function *fe = NULL, *orig_fe; char *key; const char *new_key; uint key_len, new_key_len; int type; ulong idx; zend_bool add_function = 1; zend_bool exists = 0; zend_hash_get_current_data_ex(function_table, (void*)&fe, &pos); new_key = fe->common.function_name;
开发者ID:Ben1225513527,项目名称:runkit,代码行数:31,
示例14: zend_hash_num_elementsvoid *php_array_to_c_array(zval *param,int type,int size,int *array_size){ HashTable *param_ht = param->value.ht; zval **cur; void *params; int i,tmp_size = zend_hash_num_elements(param_ht); zend_hash_internal_pointer_reset(param_ht); params = (void *)emalloc(size * tmp_size); i = 0; while(zend_hash_get_current_data(param_ht,(void **)&cur) == SUCCESS) { if((*cur)->type == IS_ARRAY) { int new_array_size; void *array = php_array_to_c_array(*cur,type,size,&new_array_size); params = erealloc(params, (tmp_size + new_array_size) * size); memcpy(&((char*)params)[i*size],array,new_array_size * size); i += (new_array_size - 1); efree(array); } else { switch(type) { case TO_C_FLOAT: convert_to_double(*cur); ((float*)params)[i] = (float)Z_DVAL_P(*cur); break; case TO_C_DOUBLE: convert_to_double(*cur); ((double*)params)[i] = Z_DVAL_P(*cur); break; case TO_C_INT: convert_to_long(*cur); ((int*)params)[i] = (int)Z_LVAL_P(*cur); break; case TO_C_LONG: convert_to_long(*cur); ((long*)params)[i] = Z_LVAL_P(*cur); break; case TO_C_UCHAR: convert_to_long(*cur); ((unsigned char*)params)[i] = (unsigned char)Z_LVAL_P(*cur); break; case TO_C_SCHAR: convert_to_long(*cur); ((signed char*)params)[i] = (signed char)Z_LVAL_P(*cur); break; case TO_C_USHORT: convert_to_long(*cur); ((unsigned short*)params)[i] = (unsigned short)Z_LVAL_P(*cur); break; case TO_C_SHORT: convert_to_long(*cur); ((short*)params)[i] = (short)Z_LVAL_P(*cur); break; case TO_C_UINT: convert_to_long(*cur); ((unsigned int*)params)[i] = (unsigned int)Z_LVAL_P(*cur); break; case TO_C_STRING: convert_to_string(*cur); ((char **)params)[i] = estrdup(Z_STRVAL_P(*cur)); } } zend_hash_move_forward(param_ht); i++; } if(array_size != NULL) *array_size = i; return (void *)params;}
开发者ID:esix,项目名称:phpopengl,代码行数:74,
示例15: pgsql_stmt_executestatic int pgsql_stmt_execute(pdo_stmt_t *stmt){ pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; pdo_pgsql_db_handle *H = S->H; ExecStatusType status; /* ensure that we free any previous unfetched results */ if(S->result) { PQclear(S->result); S->result = NULL; } S->current_row = 0; if (S->cursor_name) { char *q = NULL; if (S->is_prepared) { spprintf(&q, 0, "CLOSE %s", S->cursor_name); S->result = PQexec(H->server, q); efree(q); } spprintf(&q, 0, "DECLARE %s SCROLL CURSOR WITH HOLD FOR %s", S->cursor_name, stmt->active_query_string); S->result = PQexec(H->server, q); efree(q); /* check if declare failed */ status = PQresultStatus(S->result); if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) { pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result)); return 0; } /* the cursor was declared correctly */ S->is_prepared = 1; /* fetch to be able to get the number of tuples later, but don't advance the cursor pointer */ spprintf(&q, 0, "FETCH FORWARD 0 FROM %s", S->cursor_name); S->result = PQexec(H->server, q); efree(q); } else if (S->stmt_name) { /* using a prepared statement */ if (!S->is_prepared) {stmt_retry: /* we deferred the prepare until now, because we didn't * know anything about the parameter types; now we do */ S->result = PQprepare(H->server, S->stmt_name, S->query, stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0, S->param_types); status = PQresultStatus(S->result); switch (status) { case PGRES_COMMAND_OK: case PGRES_TUPLES_OK: /* it worked */ S->is_prepared = 1; PQclear(S->result); break; default: { char *sqlstate = pdo_pgsql_sqlstate(S->result); /* 42P05 means that the prepared statement already existed. this can happen if you use * a connection pooling software line pgpool which doesn't close the db-connection once * php disconnects. if php dies (no chance to run RSHUTDOWN) during execution it has no * chance to DEALLOCATE the prepared statements it has created. so, if we hit a 42P05 we * deallocate it and retry ONCE (thies 2005.12.15) */ if (sqlstate && !strcmp(sqlstate, "42P05")) { char buf[100]; /* stmt_name == "pdo_crsr_%08x" */ PGresult *res; snprintf(buf, sizeof(buf), "DEALLOCATE %s", S->stmt_name); res = PQexec(H->server, buf); if (res) { PQclear(res); } goto stmt_retry; } else { pdo_pgsql_error_stmt(stmt, status, sqlstate); return 0; } } } } S->result = PQexecPrepared(H->server, S->stmt_name, stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0, (const char**)S->param_values, S->param_lengths, S->param_formats, 0); } else if (stmt->supports_placeholders == PDO_PLACEHOLDER_NAMED) { /* execute query with parameters */ S->result = PQexecParams(H->server, S->query, stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0, S->param_types, (const char**)S->param_values, S->param_lengths, S->param_formats, 0);//.........这里部分代码省略.........
开发者ID:0xhacking,项目名称:php-src,代码行数:101,
示例16: HASH_OF/* {{{ void *get_pointinfo_array(zval *coordinate_array, int *num_elements TSRMLS_DC)*/void *get_pointinfo_array(zval *coordinate_array, int *num_elements TSRMLS_DC){ PointInfo *coordinates; long elements_count, sub_elements_count, i; HashTable *coords; zval *current, *pz_x, *pz_y; HashTable *sub_array; *num_elements = 0; i = 0; coords = HASH_OF(coordinate_array); elements_count = zend_hash_num_elements(coords); if (elements_count < 1) { coordinates = (PointInfo *)NULL; return coordinates; } coordinates = (PointInfo *)emalloc(sizeof(PointInfo) * elements_count); ZEND_HASH_FOREACH_VAL(coords, current) { ZVAL_DEREF(current); /* If its something than array lets error here */ if(current == NULL || Z_TYPE_P(current) != IS_ARRAY) { efree(coordinates); coordinates = (PointInfo *)NULL; return coordinates;
开发者ID:vitoc,项目名称:gmagick,代码行数:30,
示例17: umsg_format_helperU_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, HashTable *args, UChar **formatted, int32_t *formatted_len){ int arg_count = zend_hash_num_elements(args); std::vector<Formattable> fargs; std::vector<UnicodeString> farg_names; MessageFormat *mf = (MessageFormat *)mfo->mf_data.umsgf; HashTable *types; intl_error& err = INTL_DATA_ERROR(mfo); if (U_FAILURE(err.code)) { return; } types = umsg_get_types(mfo, err); umsg_set_timezone(mfo, err); fargs.resize(arg_count); farg_names.resize(arg_count); int argNum = 0; zval *elem; // Key related variables zend_string *str_index; zend_ulong num_index; ZEND_HASH_FOREACH_KEY_VAL(args, num_index, str_index, elem) { Formattable& formattable = fargs[argNum]; UnicodeString& key = farg_names[argNum]; Formattable::Type argType = Formattable::kObject, //unknown *storedArgType = NULL; if (!U_SUCCESS(err.code)) { break; } /* Process key and retrieve type */ if (str_index == NULL) { /* includes case where index < 0 because it's exposed as unsigned */ if (num_index > (zend_ulong)INT32_MAX) { intl_errors_set(&err, U_ILLEGAL_ARGUMENT_ERROR, "Found negative or too large array key", 0); continue; } UChar temp[16]; int32_t len = u_sprintf(temp, "%u", (uint32_t)num_index); key.append(temp, len); storedArgType = (Formattable::Type*)zend_hash_index_find_ptr(types, (zend_ulong)num_index); } else { //string; assumed to be in UTF-8 intl_stringFromChar(key, ZSTR_VAL(str_index), ZSTR_LEN(str_index), &err.code); if (U_FAILURE(err.code)) { char *message; spprintf(&message, 0, "Invalid UTF-8 data in argument key: '%s'", ZSTR_VAL(str_index)); intl_errors_set(&err, err.code, message, 1); efree(message); continue; } storedArgType = (Formattable::Type*)zend_hash_str_find_ptr(types, (char*)key.getBuffer(), key.length()); } if (storedArgType != NULL) { argType = *storedArgType; } /* Convert zval to formattable according to message format type * or (as a fallback) the zval type */ if (argType != Formattable::kObject) { switch (argType) { case Formattable::kString: { string_arg: /* This implicitly converts objects * Note that our vectors will leak if object conversion fails * and PHP ends up with a fatal error and calls longjmp * as a result of that. */ convert_to_string_ex(elem); UnicodeString *text = new UnicodeString(); intl_stringFromChar(*text, Z_STRVAL_P(elem), Z_STRLEN_P(elem), &err.code); if (U_FAILURE(err.code)) { char *message; spprintf(&message, 0, "Invalid UTF-8 data in string argument: " "'%s'", Z_STRVAL_P(elem)); intl_errors_set(&err, err.code, message, 1); efree(message); delete text; continue; } formattable.adoptString(text); break;//.........这里部分代码省略.........
开发者ID:13572293130,项目名称:php-src,代码行数:101,
示例18: zlib_create_dictionary_stringstatic zend_bool zlib_create_dictionary_string(HashTable *options, char **dict, size_t *dictlen) { zval *option_buffer; if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("dictionary"))) != NULL) { ZVAL_DEREF(option_buffer); switch (Z_TYPE_P(option_buffer)) { case IS_STRING: { zend_string *str = Z_STR_P(option_buffer); int i; zend_bool last_null = 1; for (i = 0; i < ZSTR_LEN(str); i++) { if (ZSTR_VAL(str)[i]) { last_null = 0; } else { if (last_null) { php_error_docref(NULL, E_WARNING, "dictionary string must not contain empty entries (two consecutive NULL-bytes or one at the very beginning)"); return 0; } last_null = 1; } } if (!last_null) { php_error_docref(NULL, E_WARNING, "dictionary string must be NULL-byte terminated (each dictionary entry has to be NULL-terminated)"); } *dict = emalloc(ZSTR_LEN(str)); memcpy(*dict, ZSTR_VAL(str), ZSTR_LEN(str)); *dictlen = ZSTR_LEN(str); } break; case IS_ARRAY: { HashTable *dictionary = Z_ARR_P(option_buffer); if (zend_hash_num_elements(dictionary) > 0) { char *dictptr; zval *cur; zend_string **strings = emalloc(sizeof(zend_string *) * zend_hash_num_elements(dictionary)); zend_string **end, **ptr = strings - 1; ZEND_HASH_FOREACH_VAL(dictionary, cur) { int i; *++ptr = zval_get_string(cur); if (!*ptr || ZSTR_LEN(*ptr) == 0) { if (*ptr) { efree(*ptr); } while (--ptr >= strings) { efree(ptr); } efree(strings); php_error_docref(NULL, E_WARNING, "dictionary entries must be non-empty strings"); return 0; } for (i = 0; i < ZSTR_LEN(*ptr); i++) { if (ZSTR_VAL(*ptr)[i] == 0) { do { efree(ptr); } while (--ptr >= strings); efree(strings); php_error_docref(NULL, E_WARNING, "dictionary entries must not contain a NULL-byte"); return 0; } } *dictlen += ZSTR_LEN(*ptr) + 1; } ZEND_HASH_FOREACH_END(); dictptr = *dict = emalloc(*dictlen); ptr = strings; end = strings + zend_hash_num_elements(dictionary); do { memcpy(dictptr, ZSTR_VAL(*ptr), ZSTR_LEN(*ptr)); dictptr += ZSTR_LEN(*ptr); *dictptr++ = 0; zend_string_release(*ptr); } while (++ptr != end); efree(strings); } } break;
开发者ID:Furgas,项目名称:php-src,代码行数:81,
示例19: zend_accel_load_scriptzend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script, int from_shared_memory){ zend_op_array *op_array; op_array = (zend_op_array *) emalloc(sizeof(zend_op_array)); *op_array = persistent_script->main_op_array; if (EXPECTED(from_shared_memory)) { zend_hash_init(&ZCG(bind_hash), 10, NULL, NULL, 0); ZCG(current_persistent_script) = persistent_script; ZCG(arena_mem) = NULL; if (EXPECTED(persistent_script->arena_size)) {#ifdef __SSE2__ /* Target address must be aligned to 64-byte boundary */ ZCG(arena_mem) = zend_arena_alloc(&CG(arena), persistent_script->arena_size + 64); ZCG(arena_mem) = (void*)(((zend_uintptr_t)ZCG(arena_mem) + 63L) & ~63L); fast_memcpy(ZCG(arena_mem), persistent_script->arena_mem, persistent_script->arena_size);#else ZCG(arena_mem) = zend_arena_alloc(&CG(arena), persistent_script->arena_size); memcpy(ZCG(arena_mem), persistent_script->arena_mem, persistent_script->arena_size);#endif } /* Copy all the necessary stuff from shared memory to regular memory, and protect the shared script */ if (zend_hash_num_elements(&persistent_script->class_table) > 0) { zend_accel_class_hash_copy(CG(class_table), &persistent_script->class_table, (unique_copy_ctor_func_t) zend_class_copy_ctor); } /* we must first to copy all classes and then prepare functions, since functions may try to bind classes - which depend on pre-bind class entries existent in the class table */ if (zend_hash_num_elements(&persistent_script->function_table) > 0) { zend_accel_function_hash_copy_from_shm(CG(function_table), &persistent_script->function_table); } /* Register __COMPILER_HALT_OFFSET__ constant */ if (persistent_script->compiler_halt_offset != 0 && persistent_script->full_path) { zend_string *name; char haltoff[] = "__COMPILER_HALT_OFFSET__"; name = zend_mangle_property_name(haltoff, sizeof(haltoff) - 1, persistent_script->full_path->val, persistent_script->full_path->len, 0); if (!zend_hash_exists(EG(zend_constants), name)) { zend_register_long_constant(name->val, name->len, persistent_script->compiler_halt_offset, CONST_CS, 0); } zend_string_release(name); } zend_hash_destroy(&ZCG(bind_hash)); ZCG(current_persistent_script) = NULL; } else /* if (!from_shared_memory) */ { if (zend_hash_num_elements(&persistent_script->function_table) > 0) { zend_accel_function_hash_copy(CG(function_table), &persistent_script->function_table); } if (zend_hash_num_elements(&persistent_script->class_table) > 0) { zend_accel_class_hash_copy(CG(class_table), &persistent_script->class_table, NULL); } } if (op_array->early_binding != (uint32_t)-1) { zend_string *orig_compiled_filename = CG(compiled_filename); CG(compiled_filename) = persistent_script->full_path; zend_do_delayed_early_binding(op_array); CG(compiled_filename) = orig_compiled_filename; } if (UNEXPECTED(!from_shared_memory)) { free_persistent_script(persistent_script, 0); /* free only hashes */ } return op_array;}
开发者ID:erikjwaxx,项目名称:php-src,代码行数:71,
示例20: getfieldsstatic int getfields(zval * fields, char * output){ zval ** data; HashTable *fields_hash; HashPosition pointer; int fields_count; fields_hash = Z_ARRVAL_P(fields); fields_count = zend_hash_num_elements(fields_hash); char *key; int key_len; long index; zval ** type, ** min, ** max; char *temp; for(zend_hash_internal_pointer_reset_ex(fields_hash, &pointer); zend_hash_get_current_data_ex(fields_hash, (void**) &data, &pointer) == SUCCESS; zend_hash_move_forward_ex(fields_hash, &pointer)) { if (zend_hash_get_current_key_ex(fields_hash, &key, &key_len,&index, 0, &pointer) == HASH_KEY_IS_STRING) { switch(Z_TYPE_P(*data)){ case IS_ARRAY: if (zend_hash_index_find(Z_ARRVAL_PP(data), 0, (void**)&type) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "wrong value with:%s",key); } if (zend_hash_index_find(Z_ARRVAL_PP(data), 1, (void**)&min) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "wrong value with:%s",key); } if (zend_hash_index_find(Z_ARRVAL_PP(data), 2, (void**)&max) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "wrong value with:%s",key); } if(strcmp(Z_STRVAL_PP(type), "int") == 0) { temp = (char *)emalloc(Z_LVAL_PP(max) * sizeof(int) + 2); sprintf(temp, "%ld,", Z_LVAL_PP(min) + rand() % (Z_LVAL_PP(max) - Z_LVAL_PP(min))); strcat(output, temp); }else if(strcmp(Z_STRVAL_PP(type), "string") == 0) { temp = (char *)emalloc(Z_LVAL_PP(max) * sizeof(char) + 1); get_rand_str(temp, Z_LVAL_PP(min), Z_LVAL_PP(max)); strcat(output, temp); strcat(output, ","); }else if(strcmp(Z_STRVAL_PP(type), "increment") == 0){ int minvalue= Z_LVAL_PP(min); int step = Z_LVAL_PP(max); if(increment == 0){ increment = (int)minvalue; } if(step == 0){ step = 1; } increment+=(int)step; temp = (char *)emalloc(Z_LVAL_PP(max) * sizeof(int) + 2); sprintf(temp, "%d", increment); strcat(output, temp); strcat(output, ","); } break; case IS_STRING: temp = (char *)emalloc((Z_STRLEN_PP(data)) * sizeof(char) + 2); sprintf(temp, "%s,", Z_STRVAL_PP(data)); strcat(output, temp); break; case IS_LONG: temp = (char *)emalloc((Z_STRLEN_PP(data)) * sizeof(long) + 2); sprintf(temp, "%ld,", Z_LVAL_PP(data)); strcat(output, temp); break; case IS_DOUBLE: temp = (char *)emalloc((Z_STRLEN_PP(data)) * sizeof(double) + 2); sprintf(temp, "%f,", Z_DVAL_PP(data)); strcat(output, temp); break; default: break; } efree(temp); } } trim(output,',',2);}
开发者ID:justpaybank,项目名称:dataserv,代码行数:85,
示例21: pdo_parse_paramsPDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, size_t inquery_len, char **outquery, size_t *outquery_len){ Scanner s; char *ptr, *newbuffer; int t; int bindno = 0; int ret = 0; size_t newbuffer_len; HashTable *params; struct pdo_bound_param_data *param; int query_type = PDO_PLACEHOLDER_NONE; struct placeholder *placeholders = NULL, *placetail = NULL, *plc = NULL; ptr = *outquery; s.cur = inquery; s.end = inquery + inquery_len + 1; /* phase 1: look for args */ while((t = scan(&s)) != PDO_PARSER_EOI) { if (t == PDO_PARSER_BIND || t == PDO_PARSER_BIND_POS) { if (t == PDO_PARSER_BIND) { int len = s.cur - s.tok; if ((inquery < (s.cur - len)) && isalnum(*(s.cur - len - 1))) { continue; } query_type |= PDO_PLACEHOLDER_NAMED; } else { query_type |= PDO_PLACEHOLDER_POSITIONAL; } plc = emalloc(sizeof(*plc)); memset(plc, 0, sizeof(*plc)); plc->next = NULL; plc->pos = s.tok; plc->len = s.cur - s.tok; plc->bindno = bindno++; if (placetail) { placetail->next = plc; } else { placeholders = plc; } placetail = plc; } } if (bindno == 0) { /* nothing to do; good! */ return 0; } /* did the query make sense to me? */ if (query_type == (PDO_PLACEHOLDER_NAMED|PDO_PLACEHOLDER_POSITIONAL)) { /* they mixed both types; punt */ pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "mixed named and positional parameters"); ret = -1; goto clean_up; } if (stmt->supports_placeholders == query_type && !stmt->named_rewrite_template) { /* query matches native syntax */ ret = 0; goto clean_up; } if (stmt->named_rewrite_template) { /* magic/hack. * We we pretend that the query was positional even if * it was named so that we fall into the * named rewrite case below. Not too pretty, * but it works. */ query_type = PDO_PLACEHOLDER_POSITIONAL; } params = stmt->bound_params; /* Do we have placeholders but no bound params */ if (bindno && !params && stmt->supports_placeholders == PDO_PLACEHOLDER_NONE) { pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "no parameters were bound"); ret = -1; goto clean_up; } if (params && bindno != zend_hash_num_elements(params) && stmt->supports_placeholders == PDO_PLACEHOLDER_NONE) { /* extra bit of validation for instances when same params are bound more than once */ if (query_type != PDO_PLACEHOLDER_POSITIONAL && bindno > zend_hash_num_elements(params)) { int ok = 1; for (plc = placeholders; plc; plc = plc->next) { if ((param = zend_hash_str_find_ptr(params, plc->pos, plc->len)) == NULL) { ok = 0; break; } } if (ok) { goto safe; } } pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "number of bound variables does not match number of tokens"); ret = -1;//.........这里部分代码省略.........
开发者ID:13572293130,项目名称:php-src,代码行数:101,
示例22: php_formatted_print/* php_formatted_print() {{{ * New sprintf implementation for PHP. * * Modifiers: * * " " pad integers with spaces * "-" left adjusted field * n field size * "."n precision (floats only) * "+" Always place a sign (+ or -) in front of a number * * Type specifiers: * * "%" literal "%", modifiers are ignored. * "b" integer argument is printed as binary * "c" integer argument is printed as a single character * "d" argument is an integer * "f" the argument is a float * "o" integer argument is printed as octal * "s" argument is a string * "x" integer argument is printed as lowercase hexadecimal * "X" integer argument is printed as uppercase hexadecimal * */static char *php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC){ zval ***args, **z_format; int argc, size = 240, inpos = 0, outpos = 0, temppos; int alignment, currarg, adjusting, argnum, width, precision; char *format, *result, padding; int always_sign; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) { return NULL; } /* verify the number of args */ if ((use_array && argc != (2 + format_offset)) || (!use_array && argc < (1 + format_offset))) { efree(args); WRONG_PARAM_COUNT_WITH_RETVAL(NULL); } if (use_array) { int i = 1; zval ***newargs; zval **array; z_format = args[format_offset]; array = args[1 + format_offset]; SEPARATE_ZVAL(array); convert_to_array_ex(array); argc = 1 + zend_hash_num_elements(Z_ARRVAL_PP(array)); newargs = (zval ***)safe_emalloc(argc, sizeof(zval *), 0); newargs[0] = z_format; for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(array)); zend_hash_get_current_data(Z_ARRVAL_PP(array), (void **)&newargs[i++]) == SUCCESS; zend_hash_move_forward(Z_ARRVAL_PP(array))); efree(args); args = newargs; format_offset = 0; } convert_to_string_ex(args[format_offset]); format = Z_STRVAL_PP(args[format_offset]); result = emalloc(size); currarg = 1; while (inpos<Z_STRLEN_PP(args[format_offset])) { int expprec = 0, multiuse = 0; zval *tmp; PRINTF_DEBUG(("sprintf: format[%d]='%c'/n", inpos, format[inpos])); PRINTF_DEBUG(("sprintf: outpos=%d/n", outpos)); if (format[inpos] != '%') { php_sprintf_appendchar(&result, &outpos, &size, format[inpos++] TSRMLS_CC); } else if (format[inpos + 1] == '%') { php_sprintf_appendchar(&result, &outpos, &size, '%' TSRMLS_CC); inpos += 2; } else { /* starting a new format specifier, reset variables */ alignment = ALIGN_RIGHT; adjusting = 0; padding = ' '; always_sign = 0; inpos++; /* skip the '%' */ PRINTF_DEBUG(("sprintf: first looking at '%c', inpos=%d/n", format[inpos], inpos)); if (isascii((int)format[inpos]) && !isalpha((int)format[inpos])) { /* first look for argnum */ temppos = inpos; while (isdigit((int)format[temppos])) temppos++; if (format[temppos] == '$') {//.........这里部分代码省略.........
开发者ID:899,项目名称:php-src,代码行数:101,
示例23: php_info_print_table_start{ php_info_print_table_start(); php_info_print_table_row(2, "json support", "enabled"); php_info_print_table_row(2, "json version", PHP_JSON_VERSION); php_info_print_table_end();}/* }}} */static void json_escape_string(smart_str *buf, char *s, size_t len, int options TSRMLS_DC);static int json_determine_array_type(zval *val TSRMLS_DC) /* {{{ */{ int i; HashTable *myht = HASH_OF(val); i = myht ? zend_hash_num_elements(myht) : 0; if (i > 0) { zend_string *key; zend_ulong index, idx; idx = 0; ZEND_HASH_FOREACH_KEY(myht, index, key) { if (key) { return PHP_JSON_OUTPUT_OBJECT; } else { if (index != idx) { return PHP_JSON_OUTPUT_OBJECT; } } idx++; } ZEND_HASH_FOREACH_END();
开发者ID:0x1111,项目名称:php-src,代码行数:31,
示例24: php_mimepart_process_linestatic int php_mimepart_process_line(php_mimepart *workpart){ size_t origcount, linelen; char *c; /* sanity check */ if (zend_hash_num_elements(&workpart->children) > MAXPARTS) { php_error_docref(NULL, E_WARNING, "MIME message too complex"); return FAILURE; } c = workpart->parsedata.workbuf.c; smart_string_0(&workpart->parsedata.workbuf); /* strip trailing /r/n -- we always have a trailing /n */ origcount = workpart->parsedata.workbuf.len; linelen = origcount - 1; if (linelen && c[linelen-1] == '/r') --linelen; /* Discover which part we were last working on */ while (workpart->parsedata.lastpart) { size_t bound_len; php_mimepart *lastpart = workpart->parsedata.lastpart; if (lastpart->parsedata.completed) { php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + origcount, 1); return SUCCESS; } if (workpart->boundary == NULL || workpart->parsedata.in_header) { workpart = lastpart; continue; } bound_len = strlen(workpart->boundary); /* Look for a boundary */ if (c[0] == '-' && c[1] == '-' && linelen >= 2+bound_len && strncasecmp(workpart->boundary, c+2, bound_len) == 0) { php_mimepart *newpart; /* is it the final boundary ? */ if (linelen >= 4 + bound_len && strncmp(c+2+bound_len, "--", 2) == 0) { lastpart->parsedata.completed = 1; php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + origcount, 1); return SUCCESS; } newpart = alloc_new_child_part(workpart, workpart->endpos + origcount, 1); php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + linelen, 1); newpart->mime_version = estrdup(workpart->mime_version); newpart->parsedata.in_header = 1; return SUCCESS; } workpart = lastpart; } if (!workpart->parsedata.in_header) { if (!workpart->parsedata.completed && !workpart->parsedata.lastpart) { /* update the body/part end positions. * For multipart messages, the final newline belongs to the boundary. * Otherwise it belongs to the body * */ if (workpart->parent && CONTENT_TYPE_ISL(workpart->parent, "multipart/", 10)) { php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + linelen, 1); } else { php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + origcount, 1); } } } else { if (linelen > 0) { php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + linelen, 1); if(*c == ' ' || *c == '/t') { /* This doesn't technically confirm to rfc2822, as we're replacing /t with /s, but this seems to fix * cases where clients incorrectly fold by inserting a /t character. */ smart_string_appendl(&workpart->parsedata.headerbuf, " ", 1); c++; linelen--; } else { php_mimepart_process_header(workpart); } /* save header for possible continuation */ smart_string_appendl(&workpart->parsedata.headerbuf, c, linelen); } else { /* end of headers */ php_mimepart_process_header(workpart); /* start of body */ workpart->parsedata.in_header = 0; workpart->bodystart = workpart->endpos + origcount; php_mimepart_update_positions(workpart, workpart->bodystart, workpart->bodystart, 1); --workpart->nbodylines; /* some broken mailers include the content-type header but not a mime-version header. * Let's relax and pretend they said they were mime 1.0 compatible */ if (workpart->mime_version == NULL && workpart->content_type != NULL) workpart->mime_version = estrdup("1.0");//.........这里部分代码省略.........
开发者ID:php,项目名称:pecl-mail-mailparse,代码行数:101,
示例25: PHP_METHOD/* {{{ proto string PDO::pgsqlCopyFromArray(string $table_name , array $rows [, string $delimiter [, string $null_as ] [, string $fields]) Returns true if the copy worked fine or false if error */static PHP_METHOD(PDO, pgsqlCopyFromArray){ pdo_dbh_t *dbh; pdo_pgsql_db_handle *H; zval *pg_rows; char *table_name, *pg_delim = NULL, *pg_null_as = NULL, *pg_fields = NULL; size_t table_name_len, pg_delim_len = 0, pg_null_as_len = 0, pg_fields_len; char *query; PGresult *pgsql_result; ExecStatusType status; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s/a|sss", &table_name, &table_name_len, &pg_rows, &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len, &pg_fields, &pg_fields_len) == FAILURE) { return; } if (!zend_hash_num_elements(Z_ARRVAL_P(pg_rows))) { php_error_docref(NULL, E_WARNING, "Cannot copy from an empty array"); RETURN_FALSE; } dbh = Z_PDO_DBH_P(getThis()); PDO_CONSTRUCT_CHECK; PDO_DBH_CLEAR_ERR(); /* using pre-9.0 syntax as PDO_pgsql is 7.4+ compatible */ if (pg_fields) { spprintf(&query, 0, "COPY %s (%s) FROM STDIN WITH DELIMITER E'%c' NULL AS E'%s'", table_name, pg_fields, (pg_delim_len ? *pg_delim : '/t'), (pg_null_as_len ? pg_null_as : "////N")); } else { spprintf(&query, 0, "COPY %s FROM STDIN WITH DELIMITER E'%c' NULL AS E'%s'", table_name, (pg_delim_len ? *pg_delim : '/t'), (pg_null_as_len ? pg_null_as : "////N")); } /* Obtain db Handle */ H = (pdo_pgsql_db_handle *)dbh->driver_data; while ((pgsql_result = PQgetResult(H->server))) { PQclear(pgsql_result); } pgsql_result = PQexec(H->server, query); efree(query); query = NULL; if (pgsql_result) { status = PQresultStatus(pgsql_result); } else { status = (ExecStatusType) PQstatus(H->server); } if (status == PGRES_COPY_IN && pgsql_result) { int command_failed = 0; size_t buffer_len = 0; zval *tmp; PQclear(pgsql_result); ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pg_rows), tmp) { size_t query_len; convert_to_string_ex(tmp); if (buffer_len < Z_STRLEN_P(tmp)) { buffer_len = Z_STRLEN_P(tmp); query = erealloc(query, buffer_len + 2); /* room for /n/0 */ } memcpy(query, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); query_len = Z_STRLEN_P(tmp); if (query[query_len - 1] != '/n') { query[query_len++] = '/n'; } query[query_len] = '/0'; if (PQputCopyData(H->server, query, query_len) != 1) { efree(query); pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, NULL); PDO_HANDLE_DBH_ERR(); RETURN_FALSE; } } ZEND_HASH_FOREACH_END();
开发者ID:0xhacking,项目名称:php-src,代码行数:82,
示例26: phpdbg_add_watch_collision/* Must prevent duplicates ... if there are duplicates, replace new by old! */static void phpdbg_add_watch_collision(phpdbg_watchpoint_t *watch) { phpdbg_watch_collision *cur; /* Check for either recursive or (simple and/or implicit) */ ZEND_ASSERT(((watch->flags & PHPDBG_WATCH_RECURSIVE) == 0) ^ ((watch->flags & (PHPDBG_WATCH_IMPLICIT | PHPDBG_WATCH_SIMPLE)) == 0)); if ((cur = zend_hash_index_find_ptr(&PHPDBG_G(watch_collisions), (zend_ulong) watch->addr.ref))) { phpdbg_watchpoint_t *old; int flags = 0; if ((old = zend_hash_find_ptr(&cur->watches, watch->str)) || (old = zend_hash_find_ptr(&cur->implicit_watches, watch->str))) { if (((old->flags ^ watch->flags) & (PHPDBG_WATCH_NORMAL|PHPDBG_WATCH_IMPLICIT)) == 0) { return; /* there was no change ... */ } flags = old->flags; if (flags & PHPDBG_WATCH_RECURSIVE) { if (!(watch->flags & PHPDBG_WATCH_RECURSIVE) && !--cur->refs) { phpdbg_delete_watchpoints_recursive(watch); } } if (flags & PHPDBG_WATCH_NORMAL) { zend_hash_del(&cur->watches, watch->str); if (zend_hash_num_elements(&cur->watches) > 0) { cur->watch = Z_PTR_P(zend_hash_get_current_data_ex(&cur->watches, NULL)); } else { cur->watch = Z_PTR_P(zend_hash_get_current_data_ex(&cur->implicit_watches, NULL)); } } if (flags & PHPDBG_WATCH_IMPLICIT) { zend_hash_del(&cur->implicit_watches, watch->str); } old->flags = watch->flags; phpdbg_free_watch(watch); efree(watch); watch = old; } if (watch->flags & PHPDBG_WATCH_RECURSIVE) { if (!(flags & PHPDBG_WATCH_RECURSIVE) && !cur->refs++) { phpdbg_create_recursive_zval_watch(watch->parent); } } } else { phpdbg_watch_collision coll; coll.refs = (watch->flags & PHPDBG_WATCH_RECURSIVE) != 0; coll.watch = watch; zend_hash_init(&coll.watches, 8, arghs, NULL, 0); zend_hash_init(&coll.implicit_watches, 8, ..., NULL, 0); cur = zend_hash_index_add_mem(&PHPDBG_G(watch_collisions), (zend_ulong) watch->addr.ref, &coll, sizeof(phpdbg_watch_collision)); phpdbg_store_watchpoint(cur->watch); phpdbg_activate_watchpoint(cur->watch); if (coll.refs) { phpdbg_create_recursive_zval_watch(watch->parent); } } if (watch->flags & PHPDBG_WATCH_NORMAL) { cur->watch = watch; zend_hash_add_ptr(&cur->watches, watch->str, watch->parent); } if (watch->flags & PHPDBG_WATCH_IMPLICIT) { zend_hash_add_ptr(&cur->implicit_watches, watch->str, watch->parent); }}
开发者ID:MessyHack,项目名称:php-src,代码行数:66,
注:本文中的zend_hash_num_elements函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ zend_hash_str_find函数代码示例 C++ zend_hash_next_index_insert函数代码示例 |