[KinoSearch] Towards a stable C API... via indirect dispatch
Marvin Humphrey
marvin at rectangular.com
Mon Oct 29 12:11:15 PDT 2007
On Oct 29, 2007, at 11:35 AM, Nathan Kurz wrote:
> OK, so then the user upgrades KinoSearch.so (or a second user grabs
> MyScorer.so and a newer version of KinoSearch.so). From what I can
> tell, the MyScorer vtable is still going to work fine. Pointers to
> functions local to MyScorer.so will work as before, and pointers to
> functions in the new KinoSearch.so, since they are found by ld.so by
> name, should work fine as well. Thus, in my view,
> MyScorer_Foo(myscorer) should work as expected so long as the symbol
> names don't change, even if the format of the parent Scorer vtables
> change completely. No?
Crap, I muffed the example. :( Yu et al do a better job of
explaining things:
http://www.usenix.org/events/javavm02/yu/yu_html/node5.html
I'll take another stab at it, nonetheless.
Say MyScorer iterates over a PostingList by calling PList_Next(self-
>plist) repeatedly. When MyScorer.so is compiled, PList_Next is
located at (say) offset 48 in the PostingList vtable. If we add a
method to Obj (PostingList's ancestor), that bumps everything in
PostingList's vtable down by sizeof(kino_method_t). Now, when
MyScorer.so tries to call PList_Next, it looks for the function
pointer at offset 48 -- and jumps into PList_Seek_Lex instead of
PList_Next (which is now at offset 52).
So, if we make the vtable layout part of the binary API, we can never
add any new virtual methods without breaking compat.
> I think I can see (through a glass, darkly) that this technique could
> work for a language where vtables are chained and crawled at runtime,
> but even then I'm not sure it is really a good thing.
That's exactly what's being proposed: generating the vtables at runtime.
Incidentally, some vtables already *are* being created at runtime in
KS. All subclasses of Schema and FieldSpec use
KinoSearch::Util::DynVirtualTable to acquire one.
However, all that DynVirtualTable does right now is change the class
name. Under "indirect dispatch", the layout of the methods in the
vtable would be dynamically generated as well.
Marvin Humphrey
Rectangular Research
http://www.rectangular.com/
_______________________________________________
KinoSearch mailing list
KinoSearch at rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch
More information about the kinosearch
mailing list