- zend_restore_error_handling(&zeh);
- return SUCCESS;
-}
-
-static inline void *psi_do_calloc(let_calloc *alloc)
-{
- decl_type *type = real_decl_type(alloc->type);
- size_t size;
-
- if (type->type == PSI_T_STRUCT) {
- /* psi_do_clean expects at least one NULL pointer after the struct */
- size = type->strct->size + sizeof(void *);
- } else {
- size = psi_t_size(type->type);
- }
-
- return ecalloc(alloc->n, size);
-}
-
-static inline void *psi_do_let(decl_arg *darg)
-{
- impl_arg *iarg = darg->let->arg;
- impl_val *arg_val;
-
- darg->let->ptr = &darg->let->out;
- arg_val = darg->let->ptr;
-
- if (!iarg) {
- /* let foo = calloc(1, long);
- * let foo = NULL;
- * let foo;
- */
- if (darg->let->val->func && darg->let->val->func->type == PSI_T_CALLOC) {
- arg_val->ptr = psi_do_calloc(darg->let->val->func->alloc);
- darg->let->mem = arg_val->ptr;
- } else if (darg->var->array_size) {
- arg_val->ptr = ecalloc(darg->var->array_size, sizeof(*arg_val));
- darg->let->mem = arg_val->ptr;
- } else {
- memset(arg_val, 0, sizeof(*arg_val));
- }
- } else {
-
- switch (darg->let->val->func->type) {
- case PSI_T_BOOLVAL:
- if (iarg->type->type == PSI_T_BOOL) {
- arg_val->cval = iarg->val.zend.bval;
- } else {
- arg_val->cval = zend_is_true(iarg->_zv);
- }
- break;
- case PSI_T_INTVAL:
- if (iarg->type->type == PSI_T_INT) {
- arg_val->lval = iarg->val.zend.lval;
- } else {
- arg_val->lval = zval_get_long(iarg->_zv);
- }
- break;
- case PSI_T_PATHVAL:
- case PSI_T_STRVAL:
- if (iarg->type->type == PSI_T_STRING) {
- arg_val->ptr = estrdup(iarg->val.zend.str->val);
- darg->let->mem = arg_val->ptr;
- zend_string_release(iarg->val.zend.str);
- } else {
- zend_string *zs = zval_get_string(iarg->_zv);
- arg_val->ptr = estrdup(zs->val);
- darg->let->mem = arg_val->ptr;
- zend_string_release(zs);
- }
- if (PSI_T_PATHVAL == darg->let->val->func->type) {
- if (SUCCESS != php_check_open_basedir(arg_val->ptr)) {
- efree(arg_val->ptr);
- return NULL;
- }
- }
- break;
- case PSI_T_STRLEN:
- if (iarg->type->type == PSI_T_STRING) {
- arg_val->lval = iarg->val.zend.str->len;
- zend_string_release(iarg->val.zend.str);
- } else {
- zend_string *zs = zval_get_string(iarg->_zv);
- arg_val->lval = zs->len;
- zend_string_release(zs);
- }
- break;
- case PSI_T_ARRVAL:
- if (iarg->type->type == PSI_T_ARRAY) {
- decl_type *type = real_decl_type(darg->type);
-
- switch (type->type) {
- case PSI_T_STRUCT:
- arg_val->ptr = psi_array_to_struct(type->strct, HASH_OF(iarg->_zv));
- darg->let->mem = arg_val->ptr;
- break;
- }
- }
- break;
- case PSI_T_OBJVAL:
- if (iarg->type->type == PSI_T_OBJECT) {
- psi_object *obj;
-
- if (!instanceof_function(Z_OBJCE_P(iarg->_zv), psi_class_entry)) {
- return NULL;
- }
-
- obj = PSI_OBJ(iarg->_zv, NULL);
- arg_val->ptr = obj->data;
- }
- break;
- EMPTY_SWITCH_DEFAULT_CASE();
- }