Skip to content

Commit

Permalink
Added compile-time assertion macros, and added our first check that I…
Browse files Browse the repository at this point in the history
…NTVAL and opcode_t are the same size
  • Loading branch information
petdance committed Mar 23, 2012
1 parent 2f0e851 commit 707e83c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/parrot/api.h
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/global_setup.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 707e83c

Please sign in to comment.