Permalink
Browse files

Added compile-time assertion macros, and added our first check that I…

…NTVAL and opcode_t are the same size
  • Loading branch information...
1 parent 2f0e851 commit 707e83cb8959d85d4d2c3de755f4456da21a9eca @petdance petdance committed Mar 23, 2012
Showing with 10 additions and 1 deletion.
  1. +5 −0 include/parrot/api.h
  2. +5 −1 src/global_setup.c
View
@@ -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;
View
@@ -24,6 +24,7 @@ I<What are these global variables?>
#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);

0 comments on commit 707e83c

Please sign in to comment.