[Kde-bindings] Blowin' smoke your way

Ashley Winters jahqueel at yahoo.com
Wed Sep 10 19:41:47 UTC 2003


--- Adam Treat <manyoso at yahoo.com> wrote:
> Have you given thought to a unified way of dealing with Qt <-->
> binding 
> inheritance?  I ran into a pretty fundamental barrier with the Qt#
> bindings 
> where I could not reliably inherit and override Qt/C++ virtual
> functions in 
> C#.  The collective marshalling, redirections and method prototypes
> was just 
> to much for the binding to handle.  I have been lurking and watching
> you and 
> Richard waiting for some breakthrough bindings technology...  let me
> know if 
> you have anything interesting in the way of handling Qt virtual
> functions and 
> inheritance for bindings.

> > [ libqt-mt.so ]   target library
> > [   mirror    ]   low level interface  =>  JavaQt
> > [    smoke    ]   high level interface =>  PerlQt and RubyQt
> >
> > The mirror library provides access to library functions using the
> URIs,
> > and not much more.

Adam, you brought up the other thing mirror does. :)

The mirror library will handle virtual functions thusly:

1. It will override every virtual function in every class, like always.
Even though I have stripped enough information to completely abuse the
GCC virtual function table ABI, I'm not going to (although the
interface I'm defining WILL allow it, without changing the binding
source-code).

2. It will allow the allocation of a "new" virtual function table for
each class.

3. It will allow that "new" virtual function table to be assigned to
any object at any time, and it can be modified by changing the delegate
function being called by that function at any time (mostly to allow
runtime initialization of the vtbl pointer in a 'private static'
variable).

// Think of this as a stub constructor function in an anonymous
language

// Mirror will use PLACEMENT new; it will NEVER ALLOCATE MEMORY except
// by calling ::new(size_t) explicitly.

// Accordingly, it will NEVER DELETE MEMORY except by ::delete(void*)
// If you *really* want to call a destructor from a Java/C# finalizer,
// go for it. Mirror will provide an interface to the this->~QFoo()
// destructor method.

// Therefore, each language binding needs to somehow allocate
// enough memory for the object using some mechanism.
// The mirror library will give a proper sizeof() for the object
// Qt will allocate its own memory as usual, of course.
pointer = call_function("&smoke;new(size_t)",
                        smoke_sizeof("&qt;QWidget"));

// like a normal function call, except returns an object -- somehow?
object = call_constructor("&qt;QWidget/QWidget(...)", pointer);

// allocate a new virtual table for your custom class
vtbl = new_vtbl("&qt;QWidget");

// make the new object a member of that custom class
assign_vtbl(object, vtbl);

// generic virtual function override thingy -- alters all objects
// which use vtbl as their virtual function table. Assume &className
// is an appropriate delegate pointer.
override(vtbl, "&qt;QWidget/className()", &className);

The high-level Smoke interface for Perl/Ruby/etc will do
argument-marshalling for the virtual functions and will automatically
generate vtables for dynamic languages using the underlying Mirror
interface.

That's about it,
Ashley Winters

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


More information about the Kde-bindings mailing list