- 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_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);
- }
- 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;
- EMPTY_SWITCH_DEFAULT_CASE();
- }