On Sun, 26 Oct 2003, Melvin Smith wrote: > At 07:21 PM 10/26/2003 +0100, Leopold Toetsch wrote: > >Steve Fink <[EMAIL PROTECTED]> wrote: > > > > > Although this does bring up another issue -- should parrot really be > > > seg faulting when it gets a uninitialized (null) PMC? > > > >The problem is of course that we call pmc->vtable->some_meth_od() on a > >NULL PMC. We could do the checks always, slowing down each PMC > >operation. But OTOH a correct HLL compiler wouldn't produce such broken > >code (hopefully). So that's probably something for the bounds-checking > > This is an old discussion. While I agree with Leo (and Dan) on not putting > checks everywhere, I also think segfaulting on faulty bytecode is > violating the "Virtual Machine" contract. > > I also don't wan't to see the performance hit of checking PMC regs everywhere. > > I think a compromise would be to do define a interpreter global PMCNull > and point (or init) all Px registers to it. > > All methods in this class would be implemented to throw an exception or > dump the bytecode for debugging and we could always trap a "NULL" > register access. > > This way we never have a NULL pointer access with regards to Px regs.
This works. The safe code still needs to check, and null registers are still a possibility but the null op and the register block-clearing code can do this when they clear out register blocks. The Null PMC should pitch a fatal exception for everything it does, so we can catch this stuff. Probably should be a compile-time option so it can be turned on for debugging/development runs and off for general usage. Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk