travis: update
[m6w6/ext-psi] / src / call.c
index 2c18e9b0ce9a7b85359b92a6cfc42220ecf8d09f..d7a742da4707883b1930b754400f367620c9782f 100644 (file)
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/
 
-#include "php_psi_stdinc.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# include "php_config.h"
+#endif
+
 #include "context.h"
 #include "data.h"
 #include "call.h"
 
+#include "php_psi.h"
+
 #include "php.h"
 #include "zend_exceptions.h"
-#include "ext/spl/spl_exceptions.h"
 
 struct psi_call_frame_argument *psi_call_frame_argument_init(struct psi_impl_arg *spec,
                impl_val *ival, zval *zptr, int is_vararg) {
@@ -199,13 +205,15 @@ zval *psi_call_frame_sub_argument(struct psi_call_frame *frame,
        if (!iarg) {
                struct psi_call_frame_argument *frame_arg;
                impl_val empty_val = {0};
+               zend_string *type_str = psi_string_init_interned(ZEND_STRL("mixed"), 1);
                struct psi_impl_arg *carg_spec = psi_impl_arg_init(
-                               psi_impl_type_init(PSI_T_MIXED, zend_string_init(ZEND_STRL("mixed"), 1)),
+                               psi_impl_type_init(PSI_T_MIXED, type_str),
                                psi_impl_var_copy(inner_var), NULL);
 
                psi_call_frame_push_auto_ex(frame, carg_spec, (void(*)(void*)) psi_impl_arg_free);
                frame_arg = psi_call_frame_argument_init(carg_spec, &empty_val, inner_zval, 0);
                zend_hash_add_ptr(&frame->arguments, name, frame_arg);
+               zend_string_release(type_str);
        }
 
        return inner_zval;
@@ -217,7 +225,8 @@ struct psi_call_frame_argument *psi_call_frame_get_argument(
 }
 
 size_t psi_call_frame_num_var_args(struct psi_call_frame *frame) {
-       return zend_hash_next_free_element(&frame->arguments);
+       zend_long nfe = zend_hash_next_free_element(&frame->arguments);
+       return nfe > 0 ? nfe : 0;
 }
 
 size_t psi_call_frame_num_fixed_args(struct psi_call_frame *frame) {
@@ -254,7 +263,7 @@ struct psi_context *psi_call_frame_get_context(struct psi_call_frame *frame) {
 #else
 #      define PARAM_PROLOGUE(separate) Z_PARAM_PROLOGUE(1, separate)
 #endif
-ZEND_RESULT_CODE psi_call_frame_parse_args(struct psi_call_frame *frame,
+bool psi_call_frame_parse_args(struct psi_call_frame *frame,
                zend_execute_data *execute_data) {
        size_t i, argc = psi_plist_count(frame->impl->func->args);
        zend_error_handling zeh;
@@ -266,7 +275,7 @@ ZEND_RESULT_CODE psi_call_frame_parse_args(struct psi_call_frame *frame,
 
                rv = zend_parse_parameters_none();
                zend_restore_error_handling(&zeh);
-               return rv;
+               return rv == SUCCESS;
        }
 
        ZEND_PARSE_PARAMETERS_START(
@@ -319,7 +328,7 @@ ZEND_RESULT_CODE psi_call_frame_parse_args(struct psi_call_frame *frame,
                                ival.zend.cb->fcc = fcc;
                        }
                } else {
-                       error_code = ZPP_ERROR_FAILURE;
+                       _error_code = ZPP_ERROR_FAILURE;
                        break;
                }
 
@@ -332,7 +341,7 @@ ZEND_RESULT_CODE psi_call_frame_parse_args(struct psi_call_frame *frame,
        }
        ZEND_PARSE_PARAMETERS_END_EX(
                zend_restore_error_handling(&zeh);
-               return FAILURE;
+               return false;
        );
 
        /* set up defaults */
@@ -347,7 +356,7 @@ ZEND_RESULT_CODE psi_call_frame_parse_args(struct psi_call_frame *frame,
        }
 
        zend_restore_error_handling(&zeh);
-       return SUCCESS;
+       return true;
 }
 
 void psi_call_frame_enter(struct psi_call_frame *frame) {
@@ -369,7 +378,7 @@ void psi_call_frame_enter(struct psi_call_frame *frame) {
        frame->rpointer = rv_sym->ptr = rv_sym->ival_ptr;
 }
 
-ZEND_RESULT_CODE psi_call_frame_do_let(struct psi_call_frame *frame) {
+bool psi_call_frame_do_let(struct psi_call_frame *frame) {
        size_t i;
        struct psi_let_stmt *let;
        struct psi_decl_arg *arg;
@@ -395,6 +404,9 @@ ZEND_RESULT_CODE psi_call_frame_do_let(struct psi_call_frame *frame) {
                        void *temp = NULL;
 
                        frame_arg = psi_call_frame_get_var_argument(frame, i);
+                       if (!frame_arg) {
+                               return false;
+                       }
                        switch (frame_arg->va_type) {
                        case PSI_T_BOOL:        let_fn = psi_let_boolval;       break;
                        case PSI_T_INT:         let_fn = psi_let_intval;        break;
@@ -403,6 +415,7 @@ ZEND_RESULT_CODE psi_call_frame_do_let(struct psi_call_frame *frame) {
                        case PSI_T_STRING:      let_fn = psi_let_strval;        break;
                        default:
                                assert(0);
+                               return false;
                        }
 
                        frame_arg->ival_ptr = let_fn(&frame_arg->temp_val, NULL, frame_arg->va_type,
@@ -415,27 +428,23 @@ ZEND_RESULT_CODE psi_call_frame_do_let(struct psi_call_frame *frame) {
                }
        }
 
-       return SUCCESS;
+       return true;
 }
 
-ZEND_RESULT_CODE psi_call_frame_do_assert(struct psi_call_frame *frame, enum psi_assert_kind kind) {
+bool psi_call_frame_do_assert(struct psi_call_frame *frame, enum psi_assert_kind kind) {
        size_t i = 0;
        struct psi_assert_stmt *ass;
 
        while (psi_plist_get(frame->impl->stmts.ass, i++, &ass)) {
                if (ass->kind == kind) {
                        if (!psi_assert_stmt_exec(ass, frame)) {
-                               char *message = psi_assert_stmt_message(ass);
-                               zend_throw_exception(kind == PSI_ASSERT_PRE
-                                               ? spl_ce_InvalidArgumentException
-                                               : spl_ce_UnexpectedValueException, message, 0);
-                               free(message);
-                               return FAILURE;
+                               psi_assert_stmt_throw(ass);
+                               return false;
                        }
                }
        }
 
-       return SUCCESS;
+       return true;
 }
 
 void psi_call_frame_do_call(struct psi_call_frame *frame) {
@@ -468,6 +477,9 @@ void psi_call_frame_do_callback(struct psi_call_frame *frame, struct psi_call_fr
        }
 
        frame_arg = psi_call_frame_get_argument(frame, cb->func->var->fqn);
+       if (!frame_arg) {
+               return;
+       }
 
        /* callback into userland */
        ZVAL_UNDEF(&return_value);
@@ -475,6 +487,7 @@ void psi_call_frame_do_callback(struct psi_call_frame *frame, struct psi_call_fr
        rc = zend_fcall_info_call(&frame_arg->ival_ptr->zend.cb->fci,
                        &frame_arg->ival_ptr->zend.cb->fcc,     &return_value, NULL);
        assert(rc == SUCCESS);
+       (void) rc;
 
        /* marshal return value of the userland call */
        frame_arg->zval_ptr = &return_value;
@@ -534,8 +547,6 @@ static void psi_call_frame_local_auto_dtor(void *auto_list)
        efree(auto_list);
 }
 
-#include "php_psi.h"
-
 void psi_call_frame_free(struct psi_call_frame *frame) {
        zend_hash_destroy(&frame->arguments);
        zend_hash_destroy(&frame->symbols);