On Nov-21, Josh Wilmes wrote: > > This should correct warnings on a few compilers and outright breakage on tcc. > > It uses the D2FPTR/F2DPTR macros to cast between data and function pointers > where needed. > > --Josh
I don't have time to properly test it right now, but here's an updated version. It also eliminates one set of unneeded casts.
Index: nci.c =================================================================== RCS file: /cvs/public/parrot/nci.c,v retrieving revision 1.5 diff -p -u -r1.5 nci.c --- nci.c 22 Nov 2002 16:00:53 -0000 1.5 +++ nci.c 22 Nov 2002 20:42:26 -0000 @@ -51,8 +51,8 @@ pcf_i_v(struct Parrot_Interp *interprete { int (*pointer)(void); int return_data; - pointer = self->cache.struct_val; - return_data = (int)(*pointer)(); + pointer = (int (*)(void)) D2FPTR(self->cache.struct_val); + return_data = (*pointer)(); interpreter->ctx.int_reg.registers[5] = return_data; interpreter->ctx.int_reg.registers[0] = 0; interpreter->ctx.int_reg.registers[1] = 1; @@ -68,8 +68,8 @@ pcf_i_i(struct Parrot_Interp *interprete { int (*pointer)(INTVAL); int return_data; - pointer = self->cache.struct_val; - return_data = (int)(*pointer)(INT_REG(5)); + pointer = (int (*)(INTVAL)) D2FPTR(self->cache.struct_val); + return_data = (*pointer)(INT_REG(5)); interpreter->ctx.int_reg.registers[5] = return_data; interpreter->ctx.int_reg.registers[0] = 0; interpreter->ctx.int_reg.registers[1] = 1; @@ -85,8 +85,8 @@ pcf_d_v(struct Parrot_Interp *interprete { double (*pointer)(void); double return_data; - pointer = self->cache.struct_val; - return_data = (double)(*pointer)(); + pointer = (double (*)(void)) D2FPTR(self->cache.struct_val); + return_data = (*pointer)(); interpreter->ctx.num_reg.registers[5] = return_data; interpreter->ctx.int_reg.registers[0] = 0; interpreter->ctx.int_reg.registers[1] = 0; @@ -103,8 +103,8 @@ pcf_d_d(struct Parrot_Interp *interprete double (*pointer)(FLOATVAL); double return_data; - pointer = self->cache.struct_val; - return_data = (double)(*pointer)(NUM_REG(5)); + pointer = (double (*)(FLOATVAL)) D2FPTR(self->cache.struct_val); + return_data = (*pointer)(NUM_REG(5)); interpreter->ctx.num_reg.registers[5] = return_data; interpreter->ctx.int_reg.registers[0] = 0; interpreter->ctx.int_reg.registers[1] = 0; @@ -129,19 +129,19 @@ void *build_call_func(struct Parrot_Inte #else /* And in here is the platform-independent way. Which is to say "here there be hacks" */ - if (0 == string_length(signature)) return pcf_v_v; + if (0 == string_length(signature)) return F2DPTR(pcf_v_v); if (!string_compare(interpreter, signature, - string_from_c_string(interpreter, "i", 1))) - return pcf_i_v; + string_from_c_string(interpreter, "i", 1))) + return F2DPTR(pcf_i_v); if (!string_compare(interpreter, signature, - string_from_c_string(interpreter, "ii", 1))) - return pcf_i_i; + string_from_c_string(interpreter, "ii", 1))) + return F2DPTR(pcf_i_i); if (!string_compare(interpreter, signature, - string_from_c_string(interpreter, "d", 1))) - return pcf_d_v; + string_from_c_string(interpreter, "d", 1))) + return F2DPTR(pcf_d_v); if (!string_compare(interpreter, signature, - string_from_c_string(interpreter, "dd", 2))) - return pcf_d_d; + string_from_c_string(interpreter, "dd", 2))) + return F2DPTR(pcf_d_d); return NULL; #endif