Hello, I have two pmc classes PjsNumber and PjsBoolean, which define bitwise_and like this:
PMC* bitwise_and(PMC* value, PMC* dest) { FLOATVAL a, b; if (! dest) { dest = pmc_new(INTERP, dynpmc_PjsNumber); } else if (dest->vtable->base_type != dynpmc_PjsNumber) { VTABLE_morph(INTERP, dest, dynpmc_PjsNumber); } a = DYNSELF.get_number(); b = VTABLE_get_number(INTERP, value); VTABLE_set_number_native(INTERP, dest, (INTVAL)a & (INTVAL)b); return dest; } It seems to work in general, but in some cases (especially when I allocate too much memory) it causes me a segfault or an error like: Trace/breakpoint trap (core dumped) An example of such a case: .HLL 'Pjs', 'pjs_group' .loadlib 'pjs_group_ops' .sub _ :main use_much_memory() test() .end .sub test :anon .local pmc a, b, c, d, e a = new .PjsBoolean b = new .PjsNumber c = new .PjsNumber d = new .PjsNumber e = new .PjsNumber c = a & b trace 1 e = c & d .end .sub use_much_memory $P0 = new .ResizablePMCArray $I0 = 0 loop: $P1 = new .String $P1 = 'hello world' $P0[$I0] = $P1 inc $I0 if $I0 < 100000 goto loop .return ($P0) .end ~/parrot_svn/parrot/languages/pjs$ parrot mmd.pir 43 bitwise_and P4, P2, P3 P4=PjsNumber=PMC(0xb62aa00c) P2=PjsNumber=PMC(0xb62aa034) P3=PjsNumber=PMC(0xb62aa020) Trace/breakpoint trap (core dumped) ~/parrot_svn/parrot/languages/pjs$ parrot --no-gc mmd.pir 43 bitwise_and P4, P2, P3 P4=PjsNumber=PMC(0xb60c0fa8) P2=PjsNumber=PMC(0xb60c0fd0) P3=PjsNumber=PMC(0xb60c0fbc) Segmentation fault (core dumped) I am new to debugging, but (if I didn't do anything wrong) I think that the problem resides in the mmd table of bitwise_and. in function mmd_dispatch_p_ppp in src/mmd.c, while executing the second bitwise_and: real_function = (mmd_f_p_ppp)get_mmd_dispatcher(interp, left, right, func_nr, &is_pmc); // is_pmc is set to 0 here, but I set it to 1 from the debugger if (is_pmc) { PMC * const sub = (PMC*)real_function; // if I look at the contents of sub, it is a .String pmc with content "Hello world" I have the same problem with bitwise_or. I am suspecting that the mmd table gets somehow overwritten, but I wasn't capable of finding out if/how it's. Any ideas? Did I do something wrong implementing my PMC's, or could it be a general parrot problem? But I couldn't trigger the same problem with parrot .Integer or .Float types. -- Mehmet