Hi, I recently came to the realization that it is possible to wrap C pointers with structs. This might satisfy some of the things that Marco was looking at.
The basic idea is to make a struct with a "uo" or "ur" slot, which wraps an untagged C word. You then set the slot value in C via the normal methods, as the second word of the struct cell is the array of scheme-accessible values in the struct. You can set a free function, but you have to do it per instance, with the apparently misnamed SCM_SET_VTABLE_DESTRUCTOR macro (misnamed because it can work on all struct instances). Unfortunately you still have to chain up to the previous value of the free function, which is a pain. This solution is not ideal for other reasons: the wasted two words because a struct is a double-cell; the fact that the struct data is allocated with scm_gc_malloc, more heavyweight than a SMOB; that the struct data has a bunch of padding -- besides the free function, some other slots, and extra padding to ensure 8-byte alignment; and the general undocumented state of everything. On the plus side, GOOPS objects are structs, so you can make a pointer wrapper that really is an object. You have one GOOPS object instead of GOOPS with a slot for a SMOB. Marginally less memory and marshalling bloat. It seems like what you need to do is to have `compute-get-n-set' return a <foreign-slot>, and then set it from C. Instantiating a wrapper from C would probably have to be done via `allocate-instance', setting the foreign slot, the `initialize' on the instance. This works one layer down in the initialization MOP. I have yet to code this up, but I'm thinking of doing so in Guile-GNOME, which will cut out a layer from the code. I just wanted to throw these ideas out there if anyone had experience with similar things. Cheers, Andy -- http://wingolog.org/ _______________________________________________ Guile-user mailing list [email protected] http://lists.gnu.org/mailman/listinfo/guile-user
