diff --git a/include/parrot/api.h b/include/parrot/api.h index 2b006ce56b..63b812a3d8 100644 --- a/include/parrot/api.h +++ b/include/parrot/api.h @@ -64,6 +64,11 @@ Parrot_confess(ARGIN(const char *cond), ARGIN(const char *file), unsigned int li #endif /* NDEBUG */ +/* Static assertions are checked at compile type */ +#define PARROT_STATIC_ASSERT_HELPER(COND,MSG) typedef char static_assertion_##MSG[(!!(COND))*2-1] +#define PARROT_STATIC_ASSERT3(X,L) PARROT_STATIC_ASSERT_HELPER(X,static_assertion_at_line_##L) +#define PARROT_STATIC_ASSERT2(X,L) PARROT_STATIC_ASSERT3(X,L) +#define PARROT_STATIC_ASSERT(X) PARROT_STATIC_ASSERT2(X,__LINE__) typedef struct _Parrot_Init_Args { void *stacktop; diff --git a/src/global_setup.c b/src/global_setup.c index 18f6afe59b..24b6fa3796 100644 --- a/src/global_setup.c +++ b/src/global_setup.c @@ -24,6 +24,7 @@ I #include "parrot/parrot.h" #include "parrot/oplib/core_ops.h" #include "global_setup.str" +#include "parrot/api.h" /* These functions are defined in the auto-generated file core_pmcs.c */ /* XXX Get it into some public place */ @@ -179,6 +180,9 @@ init_world(PARROT_INTERP) ASSERT_ARGS(init_world) PMC *iglobals, *self, *pmc; + /* Check assumptions about our config */ + PARROT_STATIC_ASSERT( sizeof(INTVAL) == sizeof(opcode_t) ); + Parrot_platform_init_code(); /* Call base vtable class constructor methods */ @@ -248,7 +252,7 @@ Parrot_gbl_setup_2(PARROT_INTERP) interp->op_hash = interp->parent_interpreter->op_hash; } else { - op_lib_t *core_ops = PARROT_CORE_OPLIB_INIT(interp, 1); + op_lib_t * const core_ops = PARROT_CORE_OPLIB_INIT(interp, 1); interp->op_hash = Parrot_hash_create_sized(interp, enum_type_ptr, Hash_key_type_cstring, core_ops->op_count); parrot_hash_oplib(interp, core_ops);