This patch removes unnecessary function pointer conversions (which have undefined behavior in ANSI C). This gets rid of several warnings encountered with the lcc compiler and isolates our function pointer misbehavior to only the jit code.
--Josh Index: core.ops =================================================================== RCS file: /home/perlcvs/parrot/core.ops,v retrieving revision 1.94 diff -u -r1.94 core.ops --- core.ops 15 Feb 2002 02:30:02 -0000 1.94 +++ core.ops 15 Feb 2002 06:16:31 -0000 @@ -2227,22 +2227,22 @@ inline op save(in INT) { INTVAL i = $1; - stack_push(interpreter, interpreter->user_stack, &i, STACK_ENTRY_INT, NULL); + stack_push(interpreter, interpreter->user_stack, &i, STACK_ENTRY_INT, +STACK_CLEANUP_NULL); goto NEXT(); } inline op save(in NUM) { - stack_push(interpreter, interpreter->user_stack, &($1), STACK_ENTRY_FLOAT, NULL); + stack_push(interpreter, interpreter->user_stack, &($1), STACK_ENTRY_FLOAT, +STACK_CLEANUP_NULL); goto NEXT(); } inline op save(in PMC) { - stack_push(interpreter, interpreter->user_stack, $1, STACK_ENTRY_PMC, NULL); + stack_push(interpreter, interpreter->user_stack, $1, STACK_ENTRY_PMC, +STACK_CLEANUP_NULL); goto NEXT(); } inline op save(in STR) { - stack_push(interpreter, interpreter->user_stack, $1, STACK_ENTRY_STRING, NULL); + stack_push(interpreter, interpreter->user_stack, $1, STACK_ENTRY_STRING, +STACK_CLEANUP_NULL); goto NEXT(); } @@ -2339,7 +2339,7 @@ =cut inline op bsr (in INT) { - stack_push(interpreter, interpreter->control_stack, expr NEXT(), STACK_ENTRY_DESTINATION, NULL); + stack_push(interpreter, interpreter->control_stack, expr NEXT(), +STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL); goto OFFSET($1); } Index: interpreter.c =================================================================== RCS file: /home/perlcvs/parrot/interpreter.c,v retrieving revision 1.69 diff -u -r1.69 interpreter.c --- interpreter.c 14 Feb 2002 05:53:58 -0000 1.69 +++ interpreter.c 15 Feb 2002 06:16:32 -0000 @@ -88,7 +88,7 @@ */ static void * prederef_oplib_handle = NULL; -static oplib_init_f prederef_oplib_init = NULL; +static oplib_init_f prederef_oplib_init = (oplib_init_f)NULLfunc; static op_lib_t * prederef_oplib = NULL; static INTVAL prederef_op_count = 0; static op_info_t * prederef_op_info = NULL; @@ -195,7 +195,7 @@ Parrot_dlclose(prederef_oplib_handle); prederef_oplib = NULL; - prederef_oplib_init = NULL; + prederef_oplib_init = (oplib_init_f)NULLfunc; prederef_oplib_handle = NULL; } @@ -466,8 +466,8 @@ /* Initialize interpreter's flags */ interpreter->flags = flags; - interpreter->warns = mem_sys_allocate(sizeof(struct warnings_t)); - PARROT_WARNINGS_off(interpreter, PARROT_WARNINGS_ALL_FLAG); + interpreter->warns = mem_sys_allocate(sizeof(struct warnings_t)); + PARROT_WARNINGS_off(interpreter, PARROT_WARNINGS_ALL_FLAG); interpreter->pmc_count = 0; interpreter->string_count = 0; Index: ops2c.pl =================================================================== RCS file: /home/perlcvs/parrot/ops2c.pl,v retrieving revision 1.17 diff -u -r1.17 ops2c.pl --- ops2c.pl 14 Feb 2002 19:33:05 -0000 1.17 +++ ops2c.pl 15 Feb 2002 06:16:33 -0000 @@ -187,7 +187,7 @@ print SOURCE @op_func_table; print SOURCE <<END_C; - NULL + (op_func${suffix}_t)0 /* NULL function pointer */ }; Index: stacks.c =================================================================== RCS file: /home/perlcvs/parrot/stacks.c,v retrieving revision 1.19 diff -u -r1.19 stacks.c --- stacks.c 15 Feb 2002 02:30:02 -0000 1.19 +++ stacks.c 15 Feb 2002 06:16:33 -0000 @@ -97,7 +97,7 @@ */ void stack_push(struct Parrot_Interp *interpreter, Stack stack, - void *thing, INTVAL type, void (*cleanup)(Stack_Entry)) + void *thing, INTVAL type, stack_cleanup_method_t cleanup) { Stack_Chunk chunk = stack->prev; Stack_Entry entry = &chunk->entry[chunk->used]; Index: string.c =================================================================== RCS file: /home/perlcvs/parrot/string.c,v retrieving revision 1.46 diff -u -r1.46 string.c --- string.c 5 Feb 2002 11:41:27 -0000 1.46 +++ string.c 15 Feb 2002 06:16:34 -0000 @@ -151,8 +151,8 @@ const CHARTYPE *type, STRING **dest_ptr) { STRING *dest; - CHARTYPE_TRANSCODER transcoder1 = NULL; - CHARTYPE_TRANSCODER transcoder2 = NULL; + CHARTYPE_TRANSCODER transcoder1 = (CHARTYPE_TRANSCODER)NULLfunc; + CHARTYPE_TRANSCODER transcoder2 = (CHARTYPE_TRANSCODER)NULLfunc; char *srcstart; char *srcend; char *deststart; Index: include/parrot/parrot.h =================================================================== RCS file: /home/perlcvs/parrot/include/parrot/parrot.h,v retrieving revision 1.25 diff -u -r1.25 parrot.h --- include/parrot/parrot.h 8 Feb 2002 11:42:13 -0000 1.25 +++ include/parrot/parrot.h 15 Feb 2002 06:16:35 -0000 @@ -73,6 +73,13 @@ typedef void* BIGINT; typedef void* BIGFLOAT; +/* define some shortcuts for dealing with function pointers */ +/* according to ANSI C, casting between function and non-function pointers is + * no good. So we should use "funcptr_t" in place of void* when dealing with + * function pointers and NULLfunc in place of NULL */ +typedef void (*funcptr_t)(void); +#define NULLfunc (funcptr_t)0 + /* define a macro to acknowledge an unused argument, and silence a "helpful" compiler warning. gcc will emit a warning on an empty if body unless {} is used to make an empty block. */ Index: include/parrot/stacks.h =================================================================== RCS file: /home/perlcvs/parrot/include/parrot/stacks.h,v retrieving revision 1.16 diff -u -r1.16 stacks.h --- include/parrot/stacks.h 10 Jan 2002 23:14:58 -0000 1.16 +++ include/parrot/stacks.h 15 Feb 2002 06:16:36 -0000 @@ -39,6 +39,9 @@ typedef Stack_Chunk Stack; +typedef void (*stack_cleanup_method_t)(Stack_Entry); +#define STACK_CLEANUP_NULL (stack_cleanup_method_t)NULLfunc + Stack new_stack(struct Parrot_Interp *); @@ -53,7 +56,7 @@ void stack_push(struct Parrot_Interp *, Stack, - void *thing, INTVAL type, void (*cleanup)(Stack_Entry)); + void *thing, INTVAL type, stack_cleanup_method_t cleanup); void * stack_pop(struct Parrot_Interp *, Stack, void *where, INTVAL type);