static void spl_ptr_heap_delete_top(spl_ptr_heap *heap, zval *elem, void *cmp_userdata) { /* {{{ */ int i, j; const int limit = (heap->count-1)/2; zval *bottom; if (heap->count == 0) { ZVAL_UNDEF(elem); return; } ZVAL_COPY_VALUE(elem, &heap->elements[0]); bottom = &heap->elements[--heap->count]; for (i = 0; i < limit; i = j) { /* Find smaller child */ j = i * 2 + 1; if(j != heap->count && heap->cmp(&heap->elements[j+1], &heap->elements[j], cmp_userdata) > 0) { j++; /* next child is bigger */ } /* swap elements between two levels */ if(heap->cmp(bottom, &heap->elements[j], cmp_userdata) < 0) { heap->elements[i] = heap->elements[j]; } else { break; } } if (EG(exception)) { /* exception thrown during comparison */ heap->flags |= SPL_HEAP_CORRUPTED; } ZVAL_COPY_VALUE(&heap->elements[i], bottom); }
static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_string *key, zval *pData, uint32_t flag ZEND_FILE_LINE_DC) { zend_ulong h; uint32_t nIndex; uint32_t idx; Bucket *p; IS_CONSISTENT(ht); if (UNEXPECTED(ht->nTableMask == 0)) { CHECK_INIT(ht, 0); goto add_to_hash; } else if (ht->u.flags & HASH_FLAG_PACKED) { zend_hash_packed_to_hash(ht); } else if ((flag & HASH_ADD_NEW) == 0) { p = zend_hash_find_bucket(ht, key); if (p) { zval *data; if (flag & HASH_ADD) { return NULL; } ZEND_ASSERT(&p->val != pData); data = &p->val; if ((flag & HASH_UPDATE_INDIRECT) && Z_TYPE_P(data) == IS_INDIRECT) { data = Z_INDIRECT_P(data); } HANDLE_BLOCK_INTERRUPTIONS(); if (ht->pDestructor) { ht->pDestructor(data); } ZVAL_COPY_VALUE(data, pData); HANDLE_UNBLOCK_INTERRUPTIONS(); return data; } } ZEND_HASH_IF_FULL_DO_RESIZE(ht); /* If the Hash table is full, resize it */ add_to_hash: HANDLE_BLOCK_INTERRUPTIONS(); idx = ht->nNumUsed++; ht->nNumOfElements++; if (ht->nInternalPointer == INVALID_IDX) { ht->nInternalPointer = idx; } p = ht->arData + idx; p->h = h = zend_string_hash_val(key); p->key = key; zend_string_addref(key); ZVAL_COPY_VALUE(&p->val, pData); nIndex = h & ht->nTableMask; Z_NEXT(p->val) = ht->arHash[nIndex]; ht->arHash[nIndex] = idx; HANDLE_UNBLOCK_INTERRUPTIONS(); return &p->val; }
static void com_write_dimension(zval *object, zval *offset, zval *value) { php_com_dotnet_object *obj; zval args[2]; VARIANT v; HRESULT res; obj = CDNO_FETCH(object); if (V_VT(&obj->v) == VT_DISPATCH) { ZVAL_COPY_VALUE(&args[0], offset); ZVAL_COPY_VALUE(&args[1], value); VariantInit(&v); if (SUCCESS == php_com_do_invoke_by_id(obj, DISPID_VALUE, DISPATCH_METHOD|DISPATCH_PROPERTYPUT, &v, 2, args, 0, 0)) { VariantClear(&v); } } else if (V_ISARRAY(&obj->v)) { LONG indices = 0; VARTYPE vt; if (SafeArrayGetDim(V_ARRAY(&obj->v)) == 1) { if (FAILED(SafeArrayGetVartype(V_ARRAY(&obj->v), &vt)) || vt == VT_EMPTY) { vt = V_VT(&obj->v) & ~VT_ARRAY; } convert_to_long(offset); indices = (LONG)Z_LVAL_P(offset); VariantInit(&v); php_com_variant_from_zval(&v, value, obj->code_page); if (V_VT(&v) != vt) { VariantChangeType(&v, &v, 0, vt); } if (vt == VT_VARIANT) { res = SafeArrayPutElement(V_ARRAY(&obj->v), &indices, &v); } else { res = SafeArrayPutElement(V_ARRAY(&obj->v), &indices, &v.lVal); } VariantClear(&v); if (FAILED(res)) { php_com_throw_exception(res, NULL); } } else { php_com_throw_exception(DISP_E_BADINDEX, "this variant has multiple dimensions; you can't set a new value without specifying *all* dimensions"); } } else { php_com_throw_exception(E_INVALIDARG, "this variant is not an array type"); } }
/** * Increments an object property */ int zephir_property_incr_decr(zval *object, char *property_name, unsigned int property_length, unsigned int increment) { zval tmp; zend_class_entry *ce; int separated = 0; ZVAL_UNDEF(&tmp); if (Z_TYPE_P(object) != IS_OBJECT) { php_error_docref(NULL, E_WARNING, "Attempt to assign property of non-object"); return FAILURE; } ce = Z_OBJCE_P(object); if (ce->parent) { ce = zephir_lookup_class_ce(ce, property_name, property_length); } zephir_read_property(&tmp, object, property_name, property_length, 0); if (Z_TYPE(tmp) > IS_UNDEF) { Z_TRY_DELREF(tmp); /** Separation only when refcount > 1 */ if (Z_REFCOUNTED(tmp)) { if (Z_REFCOUNT(tmp) > 1) { if (!Z_ISREF(tmp)) { zval new_zv; ZVAL_DUP(&new_zv, &tmp); ZVAL_COPY_VALUE(&tmp, &new_zv); Z_TRY_DELREF(new_zv); separated = 1; } } } else { zval new_zv; ZVAL_DUP(&new_zv, &tmp); ZVAL_COPY_VALUE(&tmp, &new_zv); Z_TRY_DELREF(new_zv); separated = 1; } if (increment) { zephir_increment(&tmp); } else { zephir_decrement(&tmp); } if (separated) { zephir_update_property_zval(object, property_name, property_length, &tmp); } } return SUCCESS; }
/** * Updates an array property */ int zephir_update_property_array(zval *object, const char *property, zend_uint property_length, const zval *index, zval *value) { zval tmp; int separated = 0; if (Z_TYPE_P(object) == IS_OBJECT) { zephir_read_property(&tmp, object, property, property_length, PH_NOISY | PH_READONLY); /** Separation only when refcount > 1 */ if (Z_REFCOUNTED(tmp)) { if (Z_REFCOUNT(tmp) > 1) { if (!Z_ISREF(tmp)) { zval new_zv; ZVAL_DUP(&new_zv, &tmp); ZVAL_COPY_VALUE(&tmp, &new_zv); Z_TRY_DELREF(new_zv); separated = 1; } } } else { zval new_zv; ZVAL_DUP(&new_zv, &tmp); ZVAL_COPY_VALUE(&tmp, &new_zv); Z_TRY_DELREF(new_zv); separated = 1; } /** Convert the value to array if not is an array */ if (Z_TYPE(tmp) != IS_ARRAY) { if (separated) { convert_to_array(&tmp); } else { array_init(&tmp); separated = 1; } Z_DELREF(tmp); } Z_TRY_ADDREF_P(value); if (Z_TYPE_P(index) == IS_STRING) { zend_symtable_str_update(Z_ARRVAL(tmp), Z_STRVAL_P(index), Z_STRLEN_P(index), value); } else if (Z_TYPE_P(index) == IS_LONG) { zend_hash_index_update(Z_ARRVAL(tmp), Z_LVAL_P(index), value); } else if (Z_TYPE_P(index) == IS_NULL) { zend_hash_next_index_insert(Z_ARRVAL(tmp), value); } if (separated) { zephir_update_property_zval(object, property, property_length, &tmp); } } return SUCCESS; }
/** * Appends a zval value to an array property */ int zephir_update_property_array_append(zval *object, char *property, unsigned int property_length, zval *value) { zval tmp; int separated = 0; ZVAL_UNDEF(&tmp); if (Z_TYPE_P(object) != IS_OBJECT) { return SUCCESS; } zephir_read_property(&tmp, object, property, property_length, PH_NOISY_CC); Z_TRY_DELREF(tmp); /** Separation only when refcount > 1 */ if (Z_REFCOUNTED(tmp)) { if (Z_REFCOUNT(tmp) > 1) { if (!Z_ISREF(tmp)) { zval new_zv; ZVAL_DUP(&new_zv, &tmp); ZVAL_COPY_VALUE(&tmp, &new_zv); Z_TRY_DELREF(new_zv); separated = 1; } } } else { zval new_zv; ZVAL_DUP(&new_zv, &tmp); ZVAL_COPY_VALUE(&tmp, &new_zv); Z_TRY_DELREF(new_zv); separated = 1; } /** Convert the value to array if not is an array */ if (Z_TYPE(tmp) != IS_ARRAY) { if (separated) { convert_to_array(&tmp); } else { array_init(&tmp); separated = 1; } Z_DELREF(tmp); } Z_TRY_ADDREF_P(value); add_next_index_zval(&tmp, value); if (separated) { zephir_update_property_zval(object, property, property_length, &tmp); } return SUCCESS; }
/** public function ION\Process\IPC::getContext() : mixed */ CLASS_METHOD(ION_Process_IPC, getContext) { ion_process_ipc * ipc = ION_THIS_OBJECT(ion_process_ipc); if(!Z_ISUNDEF(ipc->ctx)) { if(!Z_ISREF(ipc->ctx)) { zval ref; ZVAL_NEW_EMPTY_REF(&ref); ZVAL_COPY_VALUE(Z_REFVAL(ref), &ipc->ctx); ZVAL_COPY_VALUE(return_value, &ref); } else { ZVAL_COPY(return_value, &ipc->ctx); } } }
/* * Multiple array-offset update */ int zephir_update_static_property_array_multi_ce(zend_class_entry *ce, const char *property, zend_uint property_length, zval *value, const char *types, int types_length, int types_count, ...) { va_list ap; zval tmp_arr; int separated = 0; ZVAL_UNDEF(&tmp_arr); zephir_read_static_property_ce(&tmp_arr, ce, property, property_length, PH_NOISY | PH_READONLY); /** Separation only when refcount > 1 */ if (Z_REFCOUNTED(tmp_arr)) { if (Z_REFCOUNT(tmp_arr) > 1) { if (!Z_ISREF(tmp_arr)) { zval new_zv; ZVAL_DUP(&new_zv, &tmp_arr); ZVAL_COPY_VALUE(&tmp_arr, &new_zv); Z_TRY_DELREF(new_zv); separated = 1; } } } else { zval new_zv; ZVAL_DUP(&new_zv, &tmp_arr); ZVAL_COPY_VALUE(&tmp_arr, &new_zv); Z_TRY_DELREF(new_zv); separated = 1; } /** Convert the value to array if not is an array */ if (Z_TYPE(tmp_arr) != IS_ARRAY) { if (separated) { convert_to_array(&tmp_arr); } else { array_init(&tmp_arr); separated = 1; } Z_DELREF(tmp_arr); } va_start(ap, types_count); SEPARATE_ZVAL_IF_NOT_REF(&tmp_arr); zephir_array_update_multi_ex(&tmp_arr, value, types, types_length, types_count, ap); va_end(ap); if (separated) { zephir_update_static_property_ce(ce, property, property_length, &tmp_arr); } return SUCCESS; }
/* * This is PHP code snippet handling extend()s calls : $extended = function ($c) use ($callable, $factory) { return $callable($factory($c), $c); }; */ PHP_METHOD(PimpleClosure, invoker) { zval *arg = NULL, retval = {0}, newretval = {0}; zend_fcall_info fci = {0}; zval args[2]; FETCH_CUSTOM_OBJ_THIS(pimple_closure_object) if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) { OBJ_RELEASE((zend_object*)execute_data->func->common.prototype); return; } ZVAL_COPY_VALUE(&args[0], arg); fci.function_name = obj->factory; fci.params = args; fci.param_count = 1; fci.retval = &retval; fci.size = sizeof(fci); if (zend_call_function(&fci, NULL) == FAILURE || EG(exception)) { OBJ_RELEASE((zend_object*)execute_data->func->common.prototype); RETVAL_ZVAL(&EG(uninitialized_zval), 1, 0); return; } memset(&fci, 0, sizeof(fci)); fci.size = sizeof(fci); ZVAL_COPY_VALUE(&args[0], &retval); ZVAL_COPY_VALUE(&args[1], arg); fci.function_name = obj->callable; fci.params = args; fci.param_count = 2; fci.retval = &newretval; if (zend_call_function(&fci, NULL) == FAILURE || EG(exception)) { zval_ptr_dtor(&retval); OBJ_RELEASE((zend_object*)execute_data->func->common.prototype); RETVAL_ZVAL(&EG(uninitialized_zval), 1, 0); return; } zval_ptr_dtor(&retval); RETVAL_ZVAL(&newretval, 0 ,0); OBJ_RELEASE((zend_object*)execute_data->func->common.prototype); }
static void cli_register_file_handles(void) /* {{{ */ { zval zin, zout, zerr; php_stream *s_in, *s_out, *s_err; php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL; zend_constant ic, oc, ec; s_in = php_stream_open_wrapper_ex("php://stdin", "rb", 0, NULL, sc_in); s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out); s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err); if (s_in==NULL || s_out==NULL || s_err==NULL) { if (s_in) php_stream_close(s_in); if (s_out) php_stream_close(s_out); if (s_err) php_stream_close(s_err); return; } #if PHP_DEBUG /* do not close stdout and stderr */ s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE; s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE; #endif s_in_process = s_in; php_stream_to_zval(s_in, &zin); php_stream_to_zval(s_out, &zout); php_stream_to_zval(s_err, &zerr); ZVAL_COPY_VALUE(&ic.value, &zin); ic.flags = CONST_CS; ic.name = zend_string_init("STDIN", sizeof("STDIN")-1, 1); ic.module_number = 0; zend_register_constant(&ic); ZVAL_COPY_VALUE(&oc.value, &zout); oc.flags = CONST_CS; oc.name = zend_string_init("STDOUT", sizeof("STDOUT")-1, 1); oc.module_number = 0; zend_register_constant(&oc); ZVAL_COPY_VALUE(&ec.value, &zerr); ec.flags = CONST_CS; ec.name = zend_string_init("STDERR", sizeof("STDERR")-1, 1); ec.module_number = 0; zend_register_constant(&ec); }
void IntlIterator_from_BreakIterator_parts(zval *break_iter_zv, zval *object, parts_iter_key_type key_type) { IntlIterator_object *ii; object_init_ex(object, IntlPartsIterator_ce_ptr); ii = Z_INTL_ITERATOR_P(object); ii->iterator = (zend_object_iterator*)emalloc(sizeof(zoi_break_iter_parts)); zend_iterator_init(ii->iterator); ZVAL_COPY(&ii->iterator->data, break_iter_zv); ii->iterator->funcs = &breakiterator_parts_it_funcs; ii->iterator->index = 0; ((zoi_with_current*)ii->iterator)->destroy_it = _breakiterator_parts_destroy_it; ZVAL_COPY_VALUE(&((zoi_with_current*)ii->iterator)->wrapping_obj, object); ZVAL_UNDEF(&((zoi_with_current*)ii->iterator)->current); ((zoi_break_iter_parts*)ii->iterator)->bio = Z_INTL_BREAKITERATOR_P(break_iter_zv); assert(((zoi_break_iter_parts*)ii->iterator)->bio->biter != NULL); ((zoi_break_iter_parts*)ii->iterator)->key_type = key_type; }
static int zephir_update_static_property_ex(zend_class_entry *scope, const char *name, int name_length, zval *value, zend_property_info **property_info) { zval garbage; zval *property; zend_class_entry *old_scope; #if PHP_VERSION_ID >= 70100 old_scope = EG(fake_scope); EG(fake_scope) = scope; #else old_scope = EG(scope); EG(scope) = scope; #endif property = zephir_std_get_static_property(scope, name, name_length, 0, property_info); #if PHP_VERSION_ID >= 70100 EG(fake_scope) = old_scope; #else EG(scope) = old_scope; #endif if (!property) { return FAILURE; } else { ZVAL_COPY_VALUE(&garbage, property); if (Z_ISREF_P(value)) { SEPARATE_ZVAL(value); } ZVAL_COPY(property, value); zval_ptr_dtor(&garbage); return SUCCESS; } }
static php_stream *oci_create_lob_stream(zval *dbh, pdo_stmt_t *stmt, OCILobLocator *lob) { php_stream *stm; struct oci_lob_self *self = ecalloc(1, sizeof(*self)); ZVAL_COPY_VALUE(&self->dbh, dbh); self->lob = lob; self->offset = 1; /* 1-based */ self->stmt = stmt; self->S = (pdo_oci_stmt*)stmt->driver_data; self->E = ecalloc(1, sizeof(oci_lob_env)); self->E->svc = self->S->H->svc; self->E->err = self->S->err; stm = php_stream_alloc(&oci_blob_stream_ops, self, 0, "r+b"); if (stm) { zend_object *obj; obj = &stmt->std; Z_ADDREF(self->dbh); GC_ADDREF(obj); return stm; } efree(self); return NULL; }
/** * Unsets an index in an array property */ int zephir_unset_property_array(zval *object, char *property, unsigned int property_length, zval *index) { zval tmp; int separated = 0; if (Z_TYPE_P(object) == IS_OBJECT) { zephir_read_property(&tmp, object, property, property_length, PH_NOISY_CC); Z_TRY_DELREF(tmp); /** Separation only when refcount > 1 */ if (Z_REFCOUNTED(tmp) && Z_REFCOUNT(tmp) > 1) { if (!Z_ISREF(tmp)) { zval new_zv; ZVAL_DUP(&new_zv, &tmp); ZVAL_COPY_VALUE(&tmp, &new_zv); Z_TRY_DELREF(new_zv); separated = 1; } } zephir_array_unset(&tmp, index, PH_SEPARATE); if (separated) { zephir_update_property_zval(object, property, property_length, &tmp); } } return SUCCESS; }
/* {{{ proto mixed Closure::call(object $to [, mixed $parameter] [, mixed $...] ) Call closure, binding to a given object with its class as the scope */ ZEND_METHOD(Closure, call) { zval *zclosure, *newthis, closure_result; zend_closure *closure; zend_fcall_info fci; zend_fcall_info_cache fci_cache; zval *my_params; int my_param_count = 0; zend_function my_function; zend_object *newobj; if (zend_parse_parameters(ZEND_NUM_ARGS(), "o*", &newthis, &my_params, &my_param_count) == FAILURE) { return; } zclosure = getThis(); closure = (zend_closure *)Z_OBJ_P(zclosure); if (closure->func.common.fn_flags & ZEND_ACC_STATIC) { zend_error(E_WARNING, "Cannot bind an instance to a static closure"); return; } if (closure->func.type == ZEND_INTERNAL_FUNCTION) { /* verify that we aren't binding internal function to a wrong object */ if ((closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0 && !instanceof_function(Z_OBJCE_P(newthis), closure->func.common.scope)) { zend_error(E_WARNING, "Cannot bind function %s::%s to object of class %s", closure->func.common.scope->name->val, closure->func.common.function_name->val, Z_OBJCE_P(newthis)->name->val); return; } } newobj = Z_OBJ_P(newthis); if (newobj->ce != closure->func.common.scope && newobj->ce->type == ZEND_INTERNAL_CLASS) { /* rebinding to internal class is not allowed */ zend_error(E_WARNING, "Cannot bind closure to object of internal class %s", newobj->ce->name->val); return; } /* This should never happen as closures will always be callable */ if (zend_fcall_info_init(zclosure, 0, &fci, &fci_cache, NULL, NULL) != SUCCESS) { ZEND_ASSERT(0); } fci.retval = &closure_result; fci.params = my_params; fci.param_count = my_param_count; fci.object = fci_cache.object = newobj; fci_cache.initialized = 1; my_function = *fci_cache.function_handler; /* use scope of passed object */ my_function.common.scope = Z_OBJCE_P(newthis); fci_cache.function_handler = &my_function; if (zend_call_function(&fci, &fci_cache) == SUCCESS && Z_TYPE(closure_result) != IS_UNDEF) { ZVAL_COPY_VALUE(return_value, &closure_result); } }
/* {{{ proto void SplFixedArray::__wakeup() */ SPL_METHOD(SplFixedArray, __wakeup) { spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(getThis()); HashTable *intern_ht = zend_std_get_properties(getThis()); zval *data; if (zend_parse_parameters_none() == FAILURE) { return; } if (!intern->array) { int index = 0; int size = zend_hash_num_elements(intern_ht); intern->array = emalloc(sizeof(spl_fixedarray)); spl_fixedarray_init(intern->array, size); ZEND_HASH_FOREACH_VAL(intern_ht, data) { if (Z_REFCOUNTED_P(data)) { Z_ADDREF_P(data); } ZVAL_COPY_VALUE(&intern->array->elements[index], data); index++; } ZEND_HASH_FOREACH_END(); /* Remove the unserialised properties, since we now have the elements * within the spl_fixedarray_object structure. */ zend_hash_clean(intern_ht); }
static zend_function *oop_get_indirection_func( zend_class_entry *ce, zend_function *fbc, zval *method, zval *obj ) { indirection_function *ind = emalloc(sizeof(indirection_function)); zend_function *fn = (zend_function *) &ind->fn; long keep_flags = ZEND_ACC_RETURN_REFERENCE; ind->fn.type = ZEND_INTERNAL_FUNCTION; ind->fn.module = (ce->type == ZEND_INTERNAL_CLASS) ? ce->info.internal.module : NULL; ind->fn.handler = oop_indirection_func; ind->fn.scope = ce; ind->fn.fn_flags = ZEND_ACC_CALL_VIA_HANDLER | (fbc->common.fn_flags & keep_flags); ind->fn.num_args = fbc->common.num_args - 1; ind->fbc = fbc; if (fbc->common.arg_info) { fn->common.arg_info = &fbc->common.arg_info[1]; } else { fn->common.arg_info = NULL; } ind->fn.function_name = zend_string_copy(Z_STR_P(method)); zend_set_function_arg_flags(fn); ZVAL_COPY_VALUE(&ind->obj, obj); return fn; }
static void dom_xpath_iter(zval *baseobj, dom_object *intern) /* {{{ */ { dom_nnodemap_object *mapptr = (dom_nnodemap_object *) intern->ptr; ZVAL_COPY_VALUE(&mapptr->baseobj_zv, baseobj); mapptr->nodetype = DOM_NODESET; }
PHPAPI void var_push_dtor_no_addref(php_unserialize_data_t *var_hashx, zval *rval) { var_entries *var_hash; if (!var_hashx || !*var_hashx) { return; } var_hash = (*var_hashx)->last_dtor; #if VAR_ENTRIES_DBG fprintf(stderr, "var_push_dtor_no_addref(%p, %ld): %d (%d)\n", *rval, var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(rval), Z_REFCOUNT_PP(rval)); #endif if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) { var_hash = emalloc(sizeof(var_dtor_entries)); var_hash->used_slots = 0; var_hash->next = 0; if (!(*var_hashx)->first_dtor) { (*var_hashx)->first_dtor = var_hash; } else { ((var_entries *) (*var_hashx)->last_dtor)->next = var_hash; } (*var_hashx)->last_dtor = var_hash; } ZVAL_COPY_VALUE(&var_hash->data[var_hash->used_slots], rval); var_hash->used_slots++; }
/** * Throws a zval object as exception */ void zephir_throw_exception_debug(zval *object, const char *file, zend_uint line) { zend_class_entry *default_exception_ce; int ZEPHIR_LAST_CALL_STATUS = 0; zval curline; zval object_copy; ZVAL_UNDEF(&curline); ZEPHIR_MM_GROW(); if (Z_TYPE_P(object) != IS_OBJECT) { ZVAL_COPY_VALUE(&object_copy, object); object_init_ex(object, zend_exception_get_default()); ZEPHIR_CALL_METHOD(NULL, object, "__construct", NULL, 0, &object_copy); zval_ptr_dtor(&object_copy); } Z_ADDREF_P(object); if (line > 0) { ZEPHIR_CALL_METHOD(&curline, object, "getline", NULL, 0); zephir_check_call_status(); if (ZEPHIR_IS_LONG(&curline, 0)) { default_exception_ce = zend_exception_get_default(); zend_update_property_string(default_exception_ce, object, SL("file"), file); zend_update_property_long(default_exception_ce, object, SL("line"), line); } } if (ZEPHIR_LAST_CALL_STATUS != FAILURE) { zend_throw_exception_object(object); } ZEPHIR_MM_RESTORE(); }
void php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL) { zval retval; zval args[1]; int status; if (!option_array || !zend_is_callable(option_array, IS_CALLABLE_CHECK_NO_ACCESS, NULL)) { php_error_docref(NULL, E_WARNING, "First argument is expected to be a valid callback"); zval_ptr_dtor(value); ZVAL_NULL(value); return; } ZVAL_COPY(&args[0], value); status = call_user_function_ex(EG(function_table), NULL, option_array, &retval, 1, args, 0, NULL); if (status == SUCCESS && !Z_ISUNDEF(retval)) { zval_ptr_dtor(value); ZVAL_COPY_VALUE(value, &retval); } else { zval_ptr_dtor(value); ZVAL_NULL(value); } zval_ptr_dtor(&args[0]); }
/** * Gets the global zval into PG macro */ int zephir_get_global(zval *arr, const char *global, unsigned int global_length) { zval *gv; zend_bool jit_initialization = PG(auto_globals_jit); zend_string *str = zend_string_init(global, global_length, 0); if (jit_initialization) { zend_is_auto_global(str); } zval_ptr_dtor(arr); ZVAL_UNDEF(arr); if (&EG(symbol_table)) { if ((gv = zend_hash_find(&EG(symbol_table), str)) != NULL) { if (Z_TYPE_P(gv) == IS_ARRAY) { ZVAL_COPY_VALUE(arr, gv); zend_string_free(str); return SUCCESS; } } } array_init(arr); zend_hash_update(&EG(symbol_table), str, arr); zend_string_free(str); return SUCCESS; }
void skyray_promise_do_resolve(skyray_promise_t *self, zval *value, zend_bool is_copy_required) { zval *result, tmp; if (Z_TYPE(self->result) != IS_UNDEF) { return; } if (skyray_is_promise_instance(value)) { result = skyray_promise_unwrap_zval(value); } else { skyray_fulfilled_promise_t *promise = skyray_fulfilled_promise_new(value, is_copy_required); ZVAL_OBJ(&tmp, &promise->std); result = &tmp; } if (skyray_is_promise_instance(result)) { ZVAL_COPY_VALUE(&self->result, result); } else { ZVAL_COPY(&self->result, result); } if (skyray_is_resolved_promise(result)) { call_resolved_handlers(self, &self->on_fulfilled, &self->on_rejcted); } else { skyray_promise_t *result_promsie = skyray_promise_from_obj(Z_OBJ_P(result)); zend_hash_copy(&result_promsie->on_fulfilled, &self->on_fulfilled, (copy_ctor_func_t)context_copy_func); zend_hash_copy(&result_promsie->on_rejcted, &self->on_rejcted, (copy_ctor_func_t)context_copy_func); zend_hash_destroy(&self->on_fulfilled); zend_hash_destroy(&self->on_rejcted); } }
int zend_optimizer_add_literal(zend_op_array *op_array, zval *zv) { int i = op_array->last_literal; op_array->last_literal++; op_array->literals = (zval*)erealloc(op_array->literals, op_array->last_literal * sizeof(zval)); ZVAL_COPY_VALUE(&op_array->literals[i], zv); Z_CACHE_SLOT(op_array->literals[i]) = -1; return i; }
/** * Reads a property from an object */ int zephir_read_property(zval *result, zval *object, const char *property_name, zend_uint property_length, int flags) { zval property; zend_class_entry *ce, *old_scope; zval tmp; zval *res; ZVAL_UNDEF(&tmp); if (Z_TYPE_P(object) != IS_OBJECT) { if ((flags & PH_NOISY) == PH_NOISY) { php_error_docref(NULL, E_NOTICE, "Trying to get property \"%s\" of non-object", property_name); } ZVAL_NULL(result); return FAILURE; } ce = Z_OBJCE_P(object); if (ce->parent) { ce = zephir_lookup_class_ce(ce, property_name, property_length); } #if PHP_VERSION_ID >= 70100 old_scope = EG(fake_scope); EG(fake_scope) = ce; #else old_scope = EG(scope); EG(scope) = ce; #endif if (!Z_OBJ_HT_P(object)->read_property) { const char *class_name; class_name = Z_OBJ_P(object) ? ZSTR_VAL(Z_OBJCE_P(object)->name) : ""; zend_error(E_CORE_ERROR, "Property %s of class %s cannot be read", property_name, class_name); } ZVAL_STRINGL(&property, property_name, property_length); res = Z_OBJ_HT_P(object)->read_property(object, &property, flags ? BP_VAR_IS : BP_VAR_R, NULL, &tmp); if ((flags & PH_READONLY) == PH_READONLY) { ZVAL_COPY_VALUE(result, res); } else { ZVAL_COPY(result, res); } zval_ptr_dtor(&property); #if PHP_VERSION_ID >= 70100 EG(fake_scope) = old_scope; #else EG(scope) = old_scope; #endif return SUCCESS; }
void skyray_promise_then(skyray_promise_t *self, zval *on_fulfilled, zval *on_rejected, zval *retval) { zval *result, params[2], function_name; if (Z_TYPE(self->result) != IS_UNDEF) { result = skyray_promise_unwrap(self); ZVAL_NULL(¶ms[0]); ZVAL_NULL(¶ms[1]); ZVAL_STR(&function_name, intern_str_then); if (on_fulfilled) { ZVAL_COPY_VALUE(¶ms[0], on_fulfilled); } if (on_rejected) { ZVAL_COPY_VALUE(¶ms[1], on_rejected); } call_user_function(NULL, result, &function_name, retval, 2, params); assert(EG(exception) == NULL); } else { object_init_ex(retval, skyray_ce_Promise); skyray_promise_t *promise = skyray_promise_from_obj(Z_OBJ_P(retval)); promise_resolve_context_t *context; if (on_fulfilled != NULL && !ZVAL_IS_NULL(on_fulfilled)) { context = promise_resolve_context_create(promise, on_fulfilled, NULL); } else { context = promise_resolve_context_create(promise, NULL, self); } zend_hash_next_index_insert_ptr(&self->on_fulfilled, context); if (on_rejected != NULL && !ZVAL_IS_NULL(on_rejected)) { context = promise_resolve_context_create(promise, on_rejected, NULL); } else { context = promise_resolve_context_create(promise, NULL, self); } zend_hash_next_index_insert_ptr(&self->on_rejcted, context); } }
ZEND_API zend_ast *zend_ast_create_zval_ex(zval *zv, zend_ast_attr attr) { zend_ast_zval *ast; ast = zend_ast_alloc(sizeof(zend_ast_zval)); ast->kind = ZEND_AST_ZVAL; ast->attr = attr; ZVAL_COPY_VALUE(&ast->val, zv); ast->val.u2.lineno = CG(zend_lineno); return (zend_ast *) ast; }
ZEND_API zend_ast *zend_ast_create_zval_with_lineno(zval *zv, zend_ast_attr attr, uint32_t lineno) { zend_ast_zval *ast; ast = zend_ast_alloc(sizeof(zend_ast_zval)); ast->kind = ZEND_AST_ZVAL; ast->attr = attr; ZVAL_COPY_VALUE(&ast->val, zv); ast->val.u2.lineno = lineno; return (zend_ast *) ast; }
int zend_optimizer_add_literal(zend_op_array *op_array, zval *zv) { int i = op_array->last_literal; op_array->last_literal++; op_array->literals = (zval*)erealloc(op_array->literals, op_array->last_literal * sizeof(zval)); ZVAL_COPY_VALUE(&op_array->literals[i], zv); Z_CACHE_SLOT(op_array->literals[i]) = -1; //??? Z_SET_REFCOUNT(op_array->literals[i].constant, 2); //??? Z_SET_ISREF(op_array->literals[i].constant); return i; }
/* {{{ proto void SplDoublyLinkedList::add(mixed $index, mixed $newval) Inserts a new entry before the specified $index consisting of $newval. */ SPL_METHOD(SplDoublyLinkedList, add) { zval *zindex, *value; spl_dllist_object *intern; spl_ptr_llist_element *element; zend_long index; if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &zindex, &value) == FAILURE) { return; } intern = Z_SPLDLLIST_P(getThis()); index = spl_offset_convert_to_long(zindex); if (index < 0 || index > intern->llist->count) { zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0); return; } if (Z_REFCOUNTED_P(value)) { Z_ADDREF_P(value); } if (index == intern->llist->count) { /* If index is the last entry+1 then we do a push because we're not inserting before any entry */ spl_ptr_llist_push(intern->llist, value); } else { /* Create the new element we want to insert */ spl_ptr_llist_element *elem = emalloc(sizeof(spl_ptr_llist_element)); /* Get the element we want to insert before */ element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO); ZVAL_COPY_VALUE(&elem->data, value); elem->rc = 1; /* connect to the neighbours */ elem->next = element; elem->prev = element->prev; /* connect the neighbours to this new element */ if (elem->prev == NULL) { intern->llist->head = elem; } else { element->prev->next = elem; } element->prev = elem; intern->llist->count++; if (intern->llist->ctor) { intern->llist->ctor(elem); } } } /* }}} */