static zend_always_inline int apc_array_dup_element(apc_context_t *ctxt, HashTable *source, HashTable *target, uint32_t idx, Bucket *p, Bucket *q, int packed, int static_keys, int with_holes) { zval *data = &p->val; if (with_holes) { if (!packed && Z_TYPE_INFO_P(data) == IS_INDIRECT) { data = Z_INDIRECT_P(data); } if (UNEXPECTED(Z_TYPE_INFO_P(data) == IS_UNDEF)) { return 0; } } else if (!packed) { /* INDIRECT element may point to UNDEF-ined slots */ if (Z_TYPE_INFO_P(data) == IS_INDIRECT) { data = Z_INDIRECT_P(data); if (UNEXPECTED(Z_TYPE_INFO_P(data) == IS_UNDEF)) { return 0; } } } do { if (Z_OPT_REFCOUNTED_P(data)) { if (Z_ISREF_P(data) && Z_REFCOUNT_P(data) == 1 && (Z_TYPE_P(Z_REFVAL_P(data)) != IS_ARRAY || Z_ARRVAL_P(Z_REFVAL_P(data)) != source)) { data = Z_REFVAL_P(data); if (!Z_OPT_REFCOUNTED_P(data)) { break; } } } } while (0); my_copy_zval(&q->val, data, ctxt); q->h = p->h; if (packed) { q->key = NULL; } else { uint32_t nIndex; q->key = p->key; if (!static_keys && q->key) { if (ctxt->copy == APC_COPY_IN) { q->key = apc_pstrcpy(q->key, ctxt->pool); } else q->key = p->key; } nIndex = q->h | target->nTableMask; Z_NEXT(q->val) = HT_HASH(target, nIndex); HT_HASH(target, nIndex) = HT_IDX_TO_HASH(idx); } return 1; }
/* {{{ my_serialize_object */ static zval* my_serialize_object(zval* dst, const zval* src, apc_context_t* ctxt) { unsigned char *buf = NULL; size_t buf_len = 0; apc_pool* pool = ctxt->pool; apc_serialize_t serialize = APC_SERIALIZER_NAME(php); void *config = NULL; zend_string *serial = NULL; if(ctxt->serializer) { serialize = ctxt->serializer->serialize; config = (ctxt->serializer->config != NULL) ? ctxt->serializer->config : ctxt; } ZVAL_NULL(dst); if(serialize((unsigned char**)&buf, &buf_len, src, config)) { if (!(serial = apc_pstrnew(buf, buf_len, pool))) { efree(buf); return dst; } ZVAL_STR(dst, serial); Z_TYPE_INFO_P(dst) = IS_OBJECT; efree(buf); } return dst; }
static zend_bool php_auto_globals_create_globals(zend_string *name) /* {{{ */ { zval globals; ZVAL_ARR(&globals, &EG(symbol_table)); Z_TYPE_INFO_P(&globals) = IS_ARRAY; ZVAL_NEW_REF(&globals, &globals); zend_hash_update(&EG(symbol_table), name, &globals); return 0; }
//is used to validate objects before serialization and after deserialization. For now, only required fields are validated. static void validate_thrift_object(zval* object) { zend_class_entry* object_class_entry = Z_OBJCE_P(object); zval* is_validate = zend_read_static_property(object_class_entry, "isValidate", sizeof("isValidate")-1, false); zval* spec = zend_read_static_property(object_class_entry, "_TSPEC", sizeof("_TSPEC")-1, false); HashPosition key_ptr; zval* val_ptr; if (Z_TYPE_INFO_P(is_validate) == IS_TRUE) { for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(spec), &key_ptr); (val_ptr = zend_hash_get_current_data_ex(Z_ARRVAL_P(spec), &key_ptr)) != nullptr; zend_hash_move_forward_ex(Z_ARRVAL_P(spec), &key_ptr)) { zend_ulong fieldno; if (zend_hash_get_current_key_ex(Z_ARRVAL_P(spec), nullptr, &fieldno, &key_ptr) != HASH_KEY_IS_LONG) { throw_tprotocolexception("Bad keytype in TSPEC (expected 'long')", INVALID_DATA); return; } HashTable* fieldspec = Z_ARRVAL_P(val_ptr); // field name zval* zvarname = zend_hash_str_find(fieldspec, "var", sizeof("var")-1); char* varname = Z_STRVAL_P(zvarname); zval* is_required = zend_hash_str_find(fieldspec, "isRequired", sizeof("isRequired")-1); zval rv; zval* prop = zend_read_property(object_class_entry, object, varname, strlen(varname), false, &rv); if (Z_TYPE_INFO_P(is_required) == IS_TRUE && Z_TYPE_P(prop) == IS_NULL) { char errbuf[128]; snprintf(errbuf, 128, "Required field %s.%s is unset!", ZSTR_VAL(object_class_entry->name), varname); throw_tprotocolexception(errbuf, INVALID_DATA); } } } }
void ZEND_FASTCALL zend_jit_copy_extra_args_helper(EXECUTE_DATA_D) { zend_op_array *op_array = &EX(func)->op_array; if (EXPECTED(!(op_array->fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))) { uint32_t first_extra_arg = op_array->num_args; uint32_t num_args = EX_NUM_ARGS(); zval *end, *src, *dst; uint32_t type_flags = 0; if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ #ifdef HAVE_GCC_GLOBAL_REGS opline += first_extra_arg; #endif } /* move extra args into separate array after all CV and TMP vars */ end = EX_VAR_NUM(first_extra_arg - 1); src = end + (num_args - first_extra_arg); dst = src + (op_array->last_var + op_array->T - first_extra_arg); if (EXPECTED(src != dst)) { do { type_flags |= Z_TYPE_INFO_P(src); ZVAL_COPY_VALUE(dst, src); ZVAL_UNDEF(src); src--; dst--; } while (src != end); if (type_flags & (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT)) { ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS); } } else { do { if (Z_REFCOUNTED_P(src)) { ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS); break; } src--; } while (src != end); } } }
void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa) { if (ctx->debug_level & ZEND_DUMP_BEFORE_DFA_PASS) { zend_dump_op_array(op_array, ZEND_DUMP_SSA, "before dfa pass", ssa); } if (ssa->var_info) { int op_1; int v; int remove_nops = 0; zend_op *opline; zval tmp; for (v = op_array->last_var; v < ssa->vars_count; v++) { op_1 = ssa->vars[v].definition; if (op_1 < 0) { continue; } opline = op_array->opcodes + op_1; /* Convert LONG constants to DOUBLE */ if (ssa->var_info[v].use_as_double) { if (opline->opcode == ZEND_ASSIGN && opline->op2_type == IS_CONST && ssa->ops[op_1].op1_def == v && !RETURN_VALUE_USED(opline) ) { // op_1: ASSIGN ? -> #v [use_as_double], long(?) => ASSIGN ? -> #v, double(?) zval *zv = CT_CONSTANT_EX(op_array, opline->op2.constant); ZEND_ASSERT(Z_TYPE_INFO_P(zv) == IS_LONG); ZVAL_DOUBLE(&tmp, zval_get_double(zv)); opline->op2.constant = zend_optimizer_add_literal(op_array, &tmp); } else if (opline->opcode == ZEND_QM_ASSIGN && opline->op1_type == IS_CONST ) { // op_1: QM_ASSIGN #v [use_as_double], long(?) => QM_ASSIGN #v, double(?) zval *zv = CT_CONSTANT_EX(op_array, opline->op1.constant); ZEND_ASSERT(Z_TYPE_INFO_P(zv) == IS_LONG); ZVAL_DOUBLE(&tmp, zval_get_double(zv)); opline->op1.constant = zend_optimizer_add_literal(op_array, &tmp); } } else { if (opline->opcode == ZEND_ADD || opline->opcode == ZEND_SUB || opline->opcode == ZEND_MUL || opline->opcode == ZEND_IS_EQUAL || opline->opcode == ZEND_IS_NOT_EQUAL || opline->opcode == ZEND_IS_SMALLER || opline->opcode == ZEND_IS_SMALLER_OR_EQUAL ) { if (opline->op1_type == IS_CONST && opline->op2_type != IS_CONST && (OP2_INFO() & MAY_BE_ANY) == MAY_BE_DOUBLE && Z_TYPE_INFO_P(CT_CONSTANT_EX(op_array, opline->op1.constant)) == IS_LONG ) { // op_1: #v.? = ADD long(?), #?.? [double] => #v.? = ADD double(?), #?.? [double] zval *zv = CT_CONSTANT_EX(op_array, opline->op1.constant); ZVAL_DOUBLE(&tmp, zval_get_double(zv)); opline->op1.constant = zend_optimizer_add_literal(op_array, &tmp); } else if (opline->op1_type != IS_CONST && opline->op2_type == IS_CONST && (OP1_INFO() & MAY_BE_ANY) == MAY_BE_DOUBLE && Z_TYPE_INFO_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == IS_LONG ) { // op_1: #v.? = ADD #?.? [double], long(?) => #v.? = ADD #?.? [double], double(?) zval *zv = CT_CONSTANT_EX(op_array, opline->op2.constant); ZVAL_DOUBLE(&tmp, zval_get_double(zv)); opline->op2.constant = zend_optimizer_add_literal(op_array, &tmp); } } } if (ssa->vars[v].var >= op_array->last_var) { /* skip TMP and VAR */ continue; } if (opline->opcode == ZEND_ASSIGN && ssa->ops[op_1].op1_def == v && !RETURN_VALUE_USED(opline) ) { int orig_var = ssa->ops[op_1].op1_use; if (orig_var >= 0 && !(ssa->var_info[orig_var].type & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) ) { int src_var = ssa->ops[op_1].op2_use; if ((opline->op2_type & (IS_TMP_VAR|IS_VAR)) && src_var >= 0 && !(ssa->var_info[src_var].type & MAY_BE_REF) && ssa->vars[src_var].definition >= 0 && ssa->ops[ssa->vars[src_var].definition].result_def == src_var && ssa->ops[ssa->vars[src_var].definition].result_use < 0 && ssa->vars[src_var].use_chain == op_1 && ssa->ops[op_1].op2_use_chain < 0 && !ssa->vars[src_var].phi_use_chain && !ssa->vars[src_var].sym_use_chain /* see Zend/tests/generators/aborted_yield_during_new.phpt */ && op_array->opcodes[ssa->vars[src_var].definition].opcode != ZEND_NEW ) { int op_2 = ssa->vars[src_var].definition; // op_2: #src_var.T = OP ... => #v.CV = OP ... // op_1: ASSIGN #orig_var.CV [undef,scalar] -> #v.CV, #src_var.T NOP if (zend_ssa_unlink_use_chain(ssa, op_1, orig_var)) { /* Reconstruct SSA */ ssa->vars[v].definition = op_2; ssa->ops[op_2].result_def = v; ssa->vars[src_var].definition = -1; ssa->vars[src_var].use_chain = -1; ssa->ops[op_1].op1_use = -1; ssa->ops[op_1].op2_use = -1; ssa->ops[op_1].op1_def = -1; ssa->ops[op_1].op1_use_chain = -1; /* Update opcodes */ op_array->opcodes[op_2].result_type = opline->op1_type; op_array->opcodes[op_2].result.var = opline->op1.var; MAKE_NOP(opline); remove_nops = 1; } } else if (opline->op2_type == IS_CONST || ((opline->op2_type & (IS_TMP_VAR|IS_VAR|IS_CV)) && ssa->ops[op_1].op2_use >= 0 && ssa->ops[op_1].op2_def < 0) ) { // op_1: ASSIGN #orig_var.CV [undef,scalar] -> #v.CV, CONST|TMPVAR => QM_ASSIGN v.CV, CONST|TMPVAR if (zend_ssa_unlink_use_chain(ssa, op_1, orig_var)) { /* Reconstruct SSA */ ssa->ops[op_1].result_def = v; ssa->ops[op_1].op1_def = -1; ssa->ops[op_1].op1_use = ssa->ops[op_1].op2_use; ssa->ops[op_1].op1_use_chain = ssa->ops[op_1].op2_use_chain; ssa->ops[op_1].op2_use = -1; ssa->ops[op_1].op2_use_chain = -1; /* Update opcode */ opline->result_type = opline->op1_type; opline->result.var = opline->op1.var; opline->op1_type = opline->op2_type; opline->op1.var = opline->op2.var; opline->op2_type = IS_UNUSED; opline->op2.var = 0; opline->opcode = ZEND_QM_ASSIGN; } } } } else if (opline->opcode == ZEND_ASSIGN_ADD && opline->extended_value == 0 && ssa->ops[op_1].op1_def == v && opline->op2_type == IS_CONST && Z_TYPE_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == IS_LONG && Z_LVAL_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == 1 && ssa->ops[op_1].op1_use >= 0 && !(ssa->var_info[ssa->ops[op_1].op1_use].type & (MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF))) { // op_1: ASSIGN_ADD #?.CV [undef,null,int,foat] ->#v.CV, int(1) => PRE_INC #?.CV ->#v.CV opline->opcode = ZEND_PRE_INC; SET_UNUSED(opline->op2); } else if (opline->opcode == ZEND_ASSIGN_SUB && opline->extended_value == 0 && ssa->ops[op_1].op1_def == v && opline->op2_type == IS_CONST && Z_TYPE_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == IS_LONG && Z_LVAL_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == 1 && ssa->ops[op_1].op1_use >= 0 && !(ssa->var_info[ssa->ops[op_1].op1_use].type & (MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF))) { // op_1: ASSIGN_SUB #?.CV [undef,null,int,foat] -> #v.CV, int(1) => PRE_DEC #?.CV ->#v.CV opline->opcode = ZEND_PRE_DEC; SET_UNUSED(opline->op2); } else if (opline->opcode == ZEND_VERIFY_RETURN_TYPE && ssa->ops[op_1].op1_def == v && ssa->ops[op_1].op1_use >= 0 && ssa->ops[op_1].op1_use_chain == -1 && ssa->vars[v].use_chain >= 0 && (ssa->var_info[ssa->ops[op_1].op1_use].type & (MAY_BE_ANY|MAY_BE_UNDEF)) == (ssa->var_info[ssa->ops[op_1].op1_def].type & MAY_BE_ANY)) { // op_1: VERIFY_RETURN_TYPE #orig_var.CV [T] -> #v.CV [T] => NOP int orig_var = ssa->ops[op_1].op1_use; int ret = ssa->vars[v].use_chain; ssa->vars[orig_var].use_chain = ret; ssa->ops[ret].op1_use = orig_var; ssa->vars[v].definition = -1; ssa->vars[v].use_chain = -1; ssa->ops[op_1].op1_def = -1; ssa->ops[op_1].op1_use = -1; MAKE_NOP(opline); remove_nops = 1; } else if (ssa->ops[op_1].op1_def == v && !RETURN_VALUE_USED(opline) && ssa->ops[op_1].op1_use >= 0 && !(ssa->var_info[ssa->ops[op_1].op1_use].type & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) && (opline->opcode == ZEND_ASSIGN_ADD || opline->opcode == ZEND_ASSIGN_SUB || opline->opcode == ZEND_ASSIGN_MUL || opline->opcode == ZEND_ASSIGN_DIV || opline->opcode == ZEND_ASSIGN_MOD || opline->opcode == ZEND_ASSIGN_SL || opline->opcode == ZEND_ASSIGN_SR || opline->opcode == ZEND_ASSIGN_BW_OR || opline->opcode == ZEND_ASSIGN_BW_AND || opline->opcode == ZEND_ASSIGN_BW_XOR) && opline->extended_value == 0) { // op_1: ASSIGN_ADD #orig_var.CV [undef,null,bool,int,double] -> #v.CV, ? => #v.CV = ADD #orig_var.CV, ? /* Reconstruct SSA */ ssa->ops[op_1].result_def = ssa->ops[op_1].op1_def; ssa->ops[op_1].op1_def = -1; /* Update opcode */ opline->opcode -= (ZEND_ASSIGN_ADD - ZEND_ADD); opline->result_type = opline->op1_type; opline->result.var = opline->op1.var; } } if (remove_nops) { zend_ssa_remove_nops(op_array, ssa); } } if (ctx->debug_level & ZEND_DUMP_AFTER_DFA_PASS) { zend_dump_op_array(op_array, ZEND_DUMP_SSA, "after dfa pass", ssa); } }
/** * * @param chinese * @param flag * @return */ py_row_data_list *py_split_sentence(const char *sentence, size_t flag) { if(PY_GLOBAL(can_access) == false) { php_error(E_WARNING, "拼音转汉字初始化加载配置文件失败,转化失败!"); return NULL; } char *chinese = estrdup(sentence); //正常的拼音化 py_data_list *wordListPtr; char *wordPtr = NULL, *splitItem = NULL, *splitItemPtr = NULL, tmpStr[100] = {0}; size_t splitLen = 0, isPinyin = 0, isChangeTone = 0, i = 0, j = 0, k = 0, m = 0; zend_ulong numKey; #if PHP_MAJOR_VERSION < 7 zval **entry, **splitIsPinyinEntry; #else zval *entry, *splitIsPinyinEntry; #endif zval *pinyinPieces = (zval *)py_malloc(sizeof(zval), 0), *splitIsPinyin = (zval *)py_malloc(sizeof(zval), 0); py_row_data_list *rowDataList = (py_row_data_list *)py_malloc(sizeof(py_row_data_list), 0), *rowDataListPtr = rowDataList, *rowDataListTmpPtr = NULL; array_init(pinyinPieces); array_init(splitIsPinyin); /* 替换姓名优先 */ if (flag & PINYIN_ISNAME) { wordListPtr = PY_GLOBAL(surnameList)->next; while(wordListPtr != NULL) { while (NULL != (wordPtr = py_strstr(chinese, wordListPtr->key))) { py_add_index_stringl(pinyinPieces, wordPtr-chinese, wordListPtr->val, py_strlen(wordListPtr->val), 1); py_add_index_bool(splitIsPinyin, wordPtr-chinese, 1); memset(wordPtr, CHINESE_SUB_CHAR, py_strlen(wordListPtr->key)); } wordListPtr = wordListPtr->next; } } wordListPtr = PY_GLOBAL(wordList)->next; while(wordListPtr != NULL) { while (NULL != (wordPtr = py_strstr(chinese, wordListPtr->key))) { py_add_index_stringl(pinyinPieces, wordPtr-chinese, wordListPtr->val, py_strlen(wordListPtr->val), 1); py_add_index_bool(splitIsPinyin, wordPtr-chinese, 1); memset(wordPtr, CHINESE_SUB_CHAR, py_strlen(wordListPtr->key)); } wordListPtr = wordListPtr->next; } /* 切分标点符号 */ wordPtr = chinese; for (; i<PY_CHAR_TRANS_MAP_NUM; i++) { while (NULL != (wordPtr = py_strstr(chinese, charTransMap[i][0]))) { py_add_index_stringl(pinyinPieces, wordPtr-chinese, charTransMap[i][0], py_strlen(charTransMap[i][0]), 1); py_add_index_bool(splitIsPinyin, wordPtr-chinese, 0); memset(wordPtr, CHINESE_SUB_CHAR, py_strlen(charTransMap[i][0])); } while (NULL != (wordPtr = py_strstr(chinese, charTransMap[i][1]))) { py_add_index_stringl(pinyinPieces, wordPtr-chinese, charTransMap[i][1], py_strlen(charTransMap[i][1]), 1); py_add_index_bool(splitIsPinyin, wordPtr-chinese, 0); memset(wordPtr, CHINESE_SUB_CHAR, py_strlen(charTransMap[i][1])); } } /* 切分非标点符号和汉字 */ wordPtr = chinese; while (*wordPtr) { if (CHINESE_SUB_CHAR == *wordPtr) { if (splitLen > 0) { *wordPtr = 0; py_add_index_stringl(pinyinPieces, wordPtr-chinese-splitLen,wordPtr - splitLen, py_strlen(wordPtr - splitLen), 1); py_add_index_bool(splitIsPinyin, wordPtr-chinese-splitLen, 0); } splitLen = 0; } else { splitLen++; } ++wordPtr; } /* 特殊情况:最后一个为非汉字的时候 */ if (splitLen > 0) { py_add_index_stringl(pinyinPieces, wordPtr-chinese-splitLen,wordPtr - splitLen, py_strlen(wordPtr - splitLen), 1); py_add_index_bool(splitIsPinyin, wordPtr-chinese-splitLen, 0); } /* 格式化数组,将汉字切分为单个的一个,去掉制表符 */ for (i=0; i<=strlen(sentence); i++) { isPinyin = 0; #if PHP_MAJOR_VERSION < 7 if (zend_hash_index_find(Z_ARRVAL_P(pinyinPieces), i, (void**)&entry) == FAILURE || py_strlen(Z_STRVAL_PP(entry)) <= 0) continue; splitItem = strtok(Z_STRVAL_PP(entry), "\t"); if (zend_hash_index_find(Z_ARRVAL_P(splitIsPinyin), i, (void**)&splitIsPinyinEntry) == SUCCESS) { if (Z_BVAL_PP(splitIsPinyinEntry)) { isPinyin = 1; } } #else entry = zend_hash_index_find(Z_ARRVAL_P(pinyinPieces), i); if (NULL == entry) continue; splitItem = strtok(Z_STRVAL_P(entry), "\t"); splitIsPinyinEntry = zend_hash_index_find(Z_ARRVAL_P(splitIsPinyin), i); if (NULL != splitIsPinyinEntry) { if(Z_TYPE_INFO_P(splitIsPinyinEntry) == IS_TRUE) { isPinyin = 1; } } #endif /* 不需要拼音声调 */ CREATE_ROW_DATA_ITEM(rowDataListTmpPtr); rowDataListTmpPtr->ori = py_strdup(splitItem, 0); rowDataListPtr->next = rowDataListTmpPtr; rowDataListPtr = rowDataListTmpPtr; if (flag & (PINYIN_NONE|PINYIN_ASCII|PINYIN_LCFIRST|PINYIN_UCFIRST)) { isChangeTone = 0; for(m=0 ; m<PY_TONE_INFO_NUM; m++) { if (NULL != (wordPtr=py_strstr(splitItem, toneInfos[m].complete))){ CHANGE_STR(tmpStr, splitItem, wordPtr, toneInfos[m].complete, toneInfos[m].simple, j, k); rowDataListTmpPtr->none = py_strdup(tmpStr, 0); rowDataListTmpPtr->tone = toneInfos[m].tone; isChangeTone = 1; break; } } if (!isChangeTone && isPinyin) { rowDataListTmpPtr->none = py_strdup(rowDataListTmpPtr->ori, 0); } } if (flag & (PINYIN_LCFIRST|PINYIN_UCFIRST)){ if (NULL != rowDataListTmpPtr->none) { rowDataListTmpPtr->lcfirst = *rowDataListTmpPtr->none; rowDataListTmpPtr->ucfirst = rowDataListTmpPtr->lcfirst - 32; if (!(rowDataListTmpPtr->lcfirst >= 65 && rowDataListTmpPtr->lcfirst <= 90) && !(rowDataListTmpPtr->lcfirst >= 97 && rowDataListTmpPtr->lcfirst <= 122)){ rowDataListTmpPtr->lcfirst = 0; rowDataListTmpPtr->ucfirst = 0; } } } while((splitItem = strtok(NULL, "\t"))) { CREATE_ROW_DATA_ITEM(rowDataListTmpPtr); rowDataListTmpPtr->ori = py_strdup(splitItem, 0); rowDataListPtr->next = rowDataListTmpPtr; rowDataListPtr = rowDataListTmpPtr; if (flag & (PINYIN_NONE|PINYIN_ASCII|PINYIN_LCFIRST|PINYIN_UCFIRST)) { isChangeTone = 0; for(m=0 ; m<PY_TONE_INFO_NUM; m++) { if (NULL != (wordPtr=py_strstr(splitItem, toneInfos[m].complete))){ CHANGE_STR(tmpStr, splitItem, wordPtr, toneInfos[m].complete, toneInfos[m].simple, j, k); rowDataListTmpPtr->none = py_strdup(tmpStr, 0); rowDataListTmpPtr->tone = toneInfos[m].tone; isChangeTone = 1; break; } } if (!isChangeTone && isPinyin) { rowDataListTmpPtr->none = py_strdup(rowDataListTmpPtr->ori, 0); } } if (flag & (PINYIN_LCFIRST|PINYIN_UCFIRST)){ if (NULL != rowDataListTmpPtr->none) { rowDataListTmpPtr->lcfirst = *rowDataListTmpPtr->none; rowDataListTmpPtr->ucfirst = rowDataListTmpPtr->lcfirst - 32; if (!(rowDataListTmpPtr->lcfirst >= 65 && rowDataListTmpPtr->lcfirst <= 90) && !(rowDataListTmpPtr->lcfirst >= 97 && rowDataListTmpPtr->lcfirst <= 122)){ rowDataListTmpPtr->lcfirst = 0; rowDataListTmpPtr->ucfirst = 0; } } } } } efree(chinese); zend_hash_destroy(Z_ARRVAL_P(pinyinPieces)); efree(Z_ARRVAL_P(pinyinPieces)); efree(pinyinPieces); zend_hash_destroy(Z_ARRVAL_P(splitIsPinyin)); efree(Z_ARRVAL_P(splitIsPinyin)); efree(splitIsPinyin); return rowDataList; }
static void 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: { if (Z_TYPE_P(value) != IS_OBJECT) { throw_tprotocolexception("Attempt to send non-object type as a T_STRUCT", INVALID_DATA); } zval* spec = zend_read_static_property(Z_OBJCE_P(value), "_TSPEC", sizeof("_TSPEC")-1, false); if (Z_TYPE_P(spec) != IS_ARRAY) { throw_tprotocolexception("Attempt to send non-Thrift object as a T_STRUCT", INVALID_DATA); } binary_serialize_spec(value, transport, Z_ARRVAL_P(spec)); } return; case T_BOOL: if (!zval_is_bool(value)) convert_to_boolean(value); transport.writeI8(Z_TYPE_INFO_P(value) == IS_TRUE ? 1 : 0); return; case T_BYTE: if (Z_TYPE_P(value) != IS_LONG) convert_to_long(value); transport.writeI8(Z_LVAL_P(value)); return; case T_I16: if (Z_TYPE_P(value) != IS_LONG) convert_to_long(value); transport.writeI16(Z_LVAL_P(value)); return; case T_I32: if (Z_TYPE_P(value) != IS_LONG) convert_to_long(value); transport.writeI32(Z_LVAL_P(value)); return; case T_I64: case T_U64: { int64_t l_data; #if defined(_LP64) || defined(_WIN64) if (Z_TYPE_P(value) != IS_LONG) convert_to_long(value); l_data = Z_LVAL_P(value); #else if (Z_TYPE_P(value) != IS_DOUBLE) convert_to_double(value); l_data = (int64_t)Z_DVAL_P(value); #endif transport.writeI64(l_data); } return; case T_DOUBLE: { union { int64_t c; double d; } a; if (Z_TYPE_P(value) != IS_DOUBLE) convert_to_double(value); a.d = Z_DVAL_P(value); transport.writeI64(a.c); } return; case T_UTF8: case T_UTF16: case T_STRING: if (Z_TYPE_P(value) != IS_STRING) convert_to_string(value); transport.writeString(Z_STRVAL_P(value), Z_STRLEN_P(value)); return; case T_MAP: { if (Z_TYPE_P(value) != IS_ARRAY) convert_to_array(value); if (Z_TYPE_P(value) != IS_ARRAY) { throw_tprotocolexception("Attempt to send an incompatible type as an array (T_MAP)", INVALID_DATA); } HashTable* ht = Z_ARRVAL_P(value); zval* val_ptr; val_ptr = zend_hash_str_find(fieldspec, "ktype", sizeof("ktype")-1); if (Z_TYPE_P(val_ptr) != IS_LONG) convert_to_long(val_ptr); uint8_t keytype = Z_LVAL_P(val_ptr); transport.writeI8(keytype); val_ptr = zend_hash_str_find(fieldspec, "vtype", sizeof("vtype")-1); if (Z_TYPE_P(val_ptr) != IS_LONG) convert_to_long(val_ptr); uint8_t valtype = Z_LVAL_P(val_ptr); transport.writeI8(valtype); val_ptr = zend_hash_str_find(fieldspec, "val", sizeof("val")-1); HashTable* valspec = Z_ARRVAL_P(val_ptr); transport.writeI32(zend_hash_num_elements(ht)); HashPosition key_ptr; for (zend_hash_internal_pointer_reset_ex(ht, &key_ptr); (val_ptr = zend_hash_get_current_data_ex(ht, &key_ptr)) != nullptr; 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_P(value) != IS_ARRAY) convert_to_array(value); if (Z_TYPE_P(value) != IS_ARRAY) { throw_tprotocolexception("Attempt to send an incompatible type as an array (T_LIST)", INVALID_DATA); } HashTable* ht = Z_ARRVAL_P(value); zval* val_ptr; val_ptr = zend_hash_str_find(fieldspec, "etype", sizeof("etype")-1); if (Z_TYPE_P(val_ptr) != IS_LONG) convert_to_long(val_ptr); uint8_t valtype = Z_LVAL_P(val_ptr); transport.writeI8(valtype); val_ptr = zend_hash_str_find(fieldspec, "elem", sizeof("elem")-1); HashTable* valspec = Z_ARRVAL_P(val_ptr); transport.writeI32(zend_hash_num_elements(ht)); HashPosition key_ptr; for (zend_hash_internal_pointer_reset_ex(ht, &key_ptr); (val_ptr = zend_hash_get_current_data_ex(ht, &key_ptr)) != nullptr; zend_hash_move_forward_ex(ht, &key_ptr)) { binary_serialize(valtype, transport, val_ptr, valspec); } } return; case T_SET: { if (Z_TYPE_P(value) != IS_ARRAY) convert_to_array(value); if (Z_TYPE_P(value) != IS_ARRAY) { throw_tprotocolexception("Attempt to send an incompatible type as an array (T_SET)", INVALID_DATA); } HashTable* ht = Z_ARRVAL_P(value); zval* val_ptr; val_ptr = zend_hash_str_find(fieldspec, "etype", sizeof("etype")-1); if (Z_TYPE_P(val_ptr) != IS_LONG) convert_to_long(val_ptr); uint8_t keytype = Z_LVAL_P(val_ptr); transport.writeI8(keytype); transport.writeI32(zend_hash_num_elements(ht)); HashPosition key_ptr; for (zend_hash_internal_pointer_reset_ex(ht, &key_ptr); (val_ptr = zend_hash_get_current_data_ex(ht, &key_ptr)) != nullptr; zend_hash_move_forward_ex(ht, &key_ptr)) { binary_serialize_hashtable_key(keytype, transport, ht, key_ptr); } } return; }; char errbuf[128]; snprintf(errbuf, 128, "Unknown thrift typeID %d", thrift_typeID); throw_tprotocolexception(errbuf, INVALID_DATA); }
/* {{{ my_copy_zval */ static APC_HOTSPOT void my_copy_zval(zval* dst, const zval* src, apc_context_t* ctxt) { apc_pool* pool = ctxt->pool; assert(dst != NULL); assert(src != NULL); memcpy(dst, src, sizeof(zval)); if (Z_REFCOUNTED_P(src)) { if (zend_hash_num_elements(&ctxt->copied)) { zval *rc = zend_hash_index_find( &ctxt->copied, (uintptr_t) Z_COUNTED_P(src)); if (rc) { ZVAL_COPY(dst, rc); return; } } } switch (Z_TYPE_P(src)) { case IS_RESOURCE: case IS_TRUE: case IS_FALSE: case IS_LONG: case IS_DOUBLE: case IS_NULL: break; case IS_REFERENCE: Z_REF_P(dst) = my_copy_reference(Z_REF_P(src), ctxt); break; case IS_INDIRECT: my_copy_zval(dst, Z_INDIRECT_P(src), ctxt); break; case IS_CONSTANT: case IS_STRING: if (ctxt->copy == APC_COPY_OUT) { ZVAL_DUP(dst, src); } else { Z_TYPE_INFO_P(dst) = IS_STRING_EX; Z_STR_P(dst) = apc_pstrcpy(Z_STR_P(src), pool); } break; case IS_ARRAY: if(ctxt->serializer == NULL) { Z_ARRVAL_P(dst) = my_copy_hashtable(Z_ARRVAL_P(src), ctxt); break; } /* break intentionally omitted */ case IS_OBJECT: if(ctxt->copy == APC_COPY_IN) { dst = my_serialize_object(dst, src, ctxt); } else dst = my_unserialize_object(dst, src, ctxt); break; case IS_CALLABLE: /* XXX implement this */ assert(0); break; default: assert(0); } if (Z_REFCOUNTED_P(dst) && ctxt->copied.nTableSize) { zend_hash_index_update(&ctxt->copied, (uintptr_t) Z_COUNTED_P(src), dst); } }