fixes
authorMichael Wallner <mike@php.net>
Thu, 5 Nov 2015 11:44:39 +0000 (12:44 +0100)
committerMichael Wallner <mike@php.net>
Thu, 5 Nov 2015 11:44:39 +0000 (12:44 +0100)
src/module.c
src/parser.h
src/validator.c
tests/pipe/pipe.psi

index e3658a7ac9a52e0db41e0e19db598759f9857e00..3e222b0d2bb80b47cc004425efdd5aaf84dc8bf1 100644 (file)
@@ -131,11 +131,11 @@ void psi_to_string(zval *return_value, token_t t, impl_val *ret_val, decl_var *v
        case PSI_T_CHAR:
        case PSI_T_SINT8:
        case PSI_T_UINT8:
-               if (var->pointer_level == var->arg->var->pointer_level) {
+               if (!var->arg->var->pointer_level) {
                        RETVAL_STRINGL(&ret_val->cval, 1);
                } else {
                        ret_val = deref_impl_val(ret_val, var);
-                       if (ret_val->ptr) {
+                       if (ret_val) {
                                RETVAL_STRING(ret_val->ptr);
                        } else {
                                RETVAL_EMPTY_STRING();
@@ -365,7 +365,7 @@ void psi_to_array(zval *return_value, token_t t, impl_val *ret_val, decl_var *va
                        decl_struct_layout layout = s->layout[i];
                        impl_val tmp;
                        zval ztmp;
-                       char *ptr = (char *) ret_val->ptr + layout.pos;
+                       char *ptr = (char *) ret_val + layout.pos;
 
                        memset(&tmp, 0, sizeof(tmp));
                        memcpy(&tmp, ptr, layout.len);
@@ -578,15 +578,17 @@ void psi_do_set(zval *return_value, set_func *func, decl_vars *vars)
 
 void psi_do_return(impl *impl, impl_val *ret_val, zval *return_value)
 {
-       switch (impl->stmts->ret.list[0]->func->type) {
+       return_stmt *ret = impl->stmts->ret.list[0];
+
+       switch (ret->func->type) {
        case PSI_T_TO_STRING:
-               psi_to_string(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, impl->decl->func->var);
+               psi_to_string(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, ret->decl);
                break;
        case PSI_T_TO_INT:
-               psi_to_int(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, impl->decl->func->var);
+               psi_to_int(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, ret->decl);
                break;
        case PSI_T_TO_ARRAY:
-               psi_to_array(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, impl->decl->func->var);
+               psi_to_array(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, ret->decl);
                break;
        EMPTY_SWITCH_DEFAULT_CASE();
        }
index 28913f6dbcd84015f9652120fd63629988fc345c..7424414f9cdcf9a30925d399cbd39ca9e9945969 100644 (file)
@@ -336,7 +336,7 @@ typedef union impl_val {
 static inline impl_val *deref_impl_val(impl_val *ret_val, decl_var *var) {
        unsigned i;
 
-       for (i = 0; i < var->arg->var->pointer_level; ++i) {
+       if (var->arg->var != var) for (i = 0; i < var->pointer_level; ++i) {
                ret_val = *(void **) ret_val;
        }
        return ret_val;
index 7bc2f701989c698c63a0e491f4031ab38b30dd19..510bba1ad7280ceb0b262177f77f57c1b289ab5f 100644 (file)
@@ -266,11 +266,13 @@ static inline int validate_impl_func(PSI_Validator *V, impl *impl, impl_func *fu
        }
        return 1;
 }
+
 static inline decl *locate_impl_decl(decls *decls, return_stmt *ret) {
        size_t i;
 
        for (i = 0; i < decls->count; ++i) {
                if (!strcmp(decls->list[i]->func->var->name, ret->decl->name)) {
+                       ret->decl->arg = decls->list[i]->func;
                        return decls->list[i];
                }
        }
index 5bc3cd655184bd09bd12f9c7949218df328ef552..deb11d01711243d2787992287971386175780034 100644 (file)
@@ -4,5 +4,5 @@ extern int pipe(int fds[2]);
 function \pipe(array &$fds = null) : int {
        return to_int(pipe);
        let fds = calloc(2, int);
-       set $fds = to_array(fds);
+       set $fds = to_array(fds[2]);
 }