On 14-9-2013 22:48, Markus Engel wrote:

> I think it is important that we preserve run-time checking of these casts (from parent to child). Would this be acceptable for now? :
>    #define SP_ITEM(obj)      ( SP_IS_ITEM(obj) ? (SPItem*)obj : NULL  )

> I'm afraid that otherwise, bad casts will be much harder to track down.

As far as I can see this won’t happen, at least not in the existing code. It always looks like this:

void *p …

if (SP_IS_RECT(p)) {

    SP_RECT(p)->doWhatever();

}

 

Every bad cast would have caused an error message on the console…

And for new code, well, be careful with your casts until there’s some more refactoring progress. If too many of these to-child-casts appear, it looks to me like a design error. There should probably be a virtual method then.



You are right, in all cases we know of, the code does the correct checks :-).
But I vaguely remember fixing bugs where the code did not properly check for SP_TYPE.
It's just that there might be bad code somewhere, and then a NULL exception is that much easier to kill. The performance hit is not an issue I think, and is something that is easy to measure.

Cheers,
  Johan