changing inheritance == API breakage

[/me takes a few more swats at the horse, in case it's still breathing...]

Tim mentioned something the other day about glib's type system being completely dynamic, and that code must be prepared for the insertion of new types. This didn't sit well with me, but i couldn't express it, and got sidetracked.

It occurred to me on the plane this evening that the hierarchy actually cannot be dynamic, because it is encoded in structure definitions. By using same-size structures and casting you can avoid most problems, but changing the hierarchy of a GObject derivative does, indeed, result in API breakage.

Consider this code:

      if (widget->object.parent_instance.ref_count > 1) {

I know that it seems quite silly when the gtk+ idiom is to use a type- checking cast macro, but i have argued and argued with C++ die-hards who prefer this sort of compiler-type-checking to "dirty, evil casting".

Inserting GInitiallyUnowned into the ancestry of GtkObject will indeed not break at runtime, because of structure size coincidences, but it will cause the code above no longer to compile.

I think it worked on the Wiley Coyote model of project management - if
at any point you looked down and realised what you were doing was
impossible then you'd instantly fail.
  -- Simon Wistow

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]