Re: [AD] 4.3 graphic drivers |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Fri, 2005-11-11 at 21:54 +0000, Peter Hull wrote:
> I've been playing around with an implementation of the 'versioned structures'
> option, which I think is similar to Peter's.
> In the case where a function's prototype is altered, and an old plugin tries
> to register a vtable with a newer Allegro, I think it's possible for the
> 'register' function to build a compatible vtable by allocating extra private
> fields at the end, in which it will store the old function pointer. Assuming
> that every vtable function will take an object pointer as its first argument,
> you can get the vtable and then cast it to the version that contains the
> private fields. However, the code looks rather confusing... something like
> this:
>
> struct private_vt {
> VTABLE_VER_2 vt;
> int (*old_somefunction)(OBJECT*, int);
> };
>
> and the adaptor like this:
> int somefunction_v1_to_v2_adaptor(OBJECT* o, float arg) {
> struct private_vt* pvt2=(struct private_vt*) o->vtable;
> return (pvt2->oldsomefunction)(o, (int) arg);
> }
>
> where the API change was from int somefunction(int) in v1 to int
> somefunction(float) in v2. The definition of OBJECT is
> typedef struct {
> void* vtable;
> int field1, field2, ..
> } OBJECT;
>
> Does that make sense? I need to polish up my code a bit and check it works,
> then I'll post it, which might make everything clearer.
>
Makes sense. But do we need the casting? We could explicitly specify the
vtable, like so (using the above example):
struct OBJECT { VTABLE_v9 *vtable; ...} // OBJECT is e.g. GFX_DRIVER or BITMAP
struct VTABLE_v9 { int (*somefunction)(OBJECT *, float); VTABLE_v8 *old;}
struct VTABLE_v8 { int (*somefunction)(OBJECT *, int); VTABLE_v7 *old;}
int somefunction_v9_with_v8_adaptor(OBJECT *o, float arg)
{
VTABLE_v8 *old = o->old;
return old->somefunction(old, (int)arg);
}
Of course, we would need as many adaptors as vtable versions, so I'm
actually getting afraid of the whole adaptors idea. Simply detecting a
version mismatch and failing to load an outdated driver would make this
much simpler..
--
Elias Pschernig