Re: Perl bindings for libaosd: v0.01



On Sat, 2008-03-15 at 15:51 +0100, JÃrn Reder wrote:

  - You expose aosd_destroy.  Try to avoid binding memory management
related functions.  In this case, you can automate releasing the object
by writing a DESTROY xsub which calls aosd_destroy:

void
DESTROY (Aosd *aosd)
    CODE:
    aosd_destroy (aosd);

DESTROY is automatically called by perl when a variable goes out of
scope.

Ok, just tried it but it doesn't work, because my Perl object is a 
scalar reference to Aosd*, so DESTROY doesn't get a Aosd* here, but a 
Perl scalar, which needs to be dereferenced first.

I completely forgot to take a look at Aosd.pm.  Nearly everything in
there should be removed.  When you specify a PREFIX in Aosd.xs, xsubpp
automatically strips it off of the xsub names.  So aosd_get_screen_size
becomes get_screen_size and so on.

So:

MODULE = X11::Aosd      PACKAGE = X11::Aosd     PREFIX = aosd_

Then you need to alter the constructor so it can be used as
X11::Aosd->new and just ignores the class name:

Aosd *
aosd_new(class)
    C_ARGS:
        /* void */

Then remove every method in Aosd.pm.

Is there a better way than building the Perl object on a scalar 
reference to Aosd*?

In typemap, you specify that T_PTROBJ is to be used for Aosd*.  That
means that whenever a Aosd* pointer is encountered, it automatically
gets wrapped as an opaque scalar.  So that should be fine.

-- 
Bye,
-Torsten




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