[KinoSearch] Towards a stable C API... via indirect dispatch
Nathan Kurz
nate at verse.com
Tue Oct 30 14:47:14 PDT 2007
On 10/30/07, Marvin Humphrey <marvin at rectangular.com> wrote:
> The method_OFFSET var should hold the distance, in *bytes*, from the
> top of the vtable struct. To get the address of the proper function
> pointer, just add method_OFFSET and the address of the vtable together.
Check. You are probably familiar with it, but the offsetof() macro
may useful for generating these offsets. The Apache Portable Runtime
might be worth checking for portabalized macros for this. It also
might be worth considering for its mmap support.
The Linux kernel builds on this to add container_of, which may or may
not help as well. Here's a blog post that talks about its use within
the VFS, which I referred to earlier:
http://modal-echoes.blogspot.com/2007/03/implementing-polymorphism-in-c.html
> This is the assembler we should see when attempting to load the
> correct function pointer:
>
> movl self, %edx # load self into %edx
> movl method_OFFSET, %eax # load method_OFFSET into %eax
> addl (%edx), %eax # add the address of self->_ to %eax
Realize that things are going to be a little less efficient once you
are using a shared library. I think the method_OFFSET variable is
going to require another level of indirection to allow for the symbol
relocation. But I'm fuzzy on this.
Nathan Kurz
nate at verse.com
_______________________________________________
KinoSearch mailing list
KinoSearch at rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch
More information about the kinosearch
mailing list