Re: GLib/perl and GArray, GType



On Thu, Dec 11, 2008 at 12:31:09AM -0500, muppet wrote:

On Dec 9, 2008, at 5:09 PM, Wouter Verhelst wrote:

I've been using GObject and the GLib perl module to write some
object/relational mapper. Mostly for fun (stop looking at me weird!),
but it's working out quite well.

Hey, some of us like writing language bindings, so you're in good  
company for weird.

Heh :-)

One thing I'm not very happy about is the way I have to work with
GArrays and GTypes in the XS API. Every time my API returns more than
one object, it uses GArrays to do this (although I'm thinking of
changing that to GLists). As far as I can see in "perldoc  
Glib::xsapi",
the perl module doesn't do any black magic to make sure that GArrays  
(or
GLists, or GSLists, or whatever) are automatically converted from and 
to
perl lists. Is this correct? If so, it's not a huge deal--I can live
with having to allocate an array and deallocate after having converted
it to a perl list, but it would be nice to not have to do this *every
time*. It gets boring :-)

The GArray and GList do not specify the type of what they contain.   
Therefore, there's no generic way to convert them.  You're always open  
to somebody deciding to be cute and have the first element be an object, 
the second be an int cast as a pointer, and the third be a boxed type.  
You'll crash on the second one, and probably the third one, too.

Right, that makes sense.

Now, it's fairly easy for you to create a function that knows how to  
convert an array of whatever, and create a typemap for that.  Then you  
can use that all over the place in your own code.

Sounds like that could work. Having said that, I've not done much XS
code beyond this project, and since your code has generated all my
typemaps there (thanks, BTW), I wouldn't know where to start. Care to
give me a pointer? ;-)

[...]
Secondly, "perldoc Glib" suggests that every time you want to use a
GType, the Perl version will be that you use a package name. A
particular part of my API has a property that is a GType; it uses
g_param_spec_gtype(), and this works from C. Unfortunately, the Glib
module doesn't see this; I get errors about "Foo::Bar" not being a  
valid
integer (despite it having been registered as a GObject package). Is
there any way to make this work, other than an ugly hack of adding a
perl-specific 'foo_bar_get_type_property' sub in the XS file?

Hey, GParamSpecGType looks damned handy.  It's new in 2.10, and appears 
to be unsupported in trunk of perl-Glib.

I see; that explains it.

It looks like it uses GValues that hold G_TYPE_GTYPE, so we should be
able to set up marshaling logic in GValue.xs that calls
gperl_package_from_type() and  gperl_type_from_package() to do the
magical conversions.

I had knocked together a patch that implements this, but working the  
kinks out of value coercion in the unit test expanded to fill all my  
available time for the evening, which was about half an hour.  :-(   I'll 
try to get you a working patch later this week.

That'd be great, thanks; and if you don't make it this week, there's no
rush -- I know what's going on, and this is (mostly) a hobby project
anyway.

-- 
Wouter Verhelst
NixSys BVBA
Louizastraat 14, 2800 Mechelen
T: +32 15 27 69 50 / F: +32 15 27 69 51 / M: +32 486 836 198



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]