Jeffrey Ratcliffe
2008-09-15 07:11:26 UTC
Having got the C-Perl interface working (1:1 C:XS mapping) and seen
what I already new, that it wasn't very OO or Perlish, I wrote a
pure-Perl interface, which calls, of course, the XS.
All that works nicely, but I see I have many Perl subs which exist
solely to take a blessed hash reference and return the type that the
XS and C expects. i.e. a bit of complexity in the XS would eliminate
90% of the .pm.
I now have some code working with the hash reference, but the blessed
bit of the typemap is eluding me.
As an example, below is a DESTROY routine:
MODULE = SANE PACKAGE = SANE::Device PREFIX = sane_
PROTOTYPES: ENABLE
void
sane_DESTROY (dev)
SV * dev
INIT:
HV * hv;
SV ** shandle;
SANE_Handle phandle;
CODE:
hv = (HV *) SvRV (dev);
shandle = hv_fetch (hv, "_h", 2, 0);
if (shandle == NULL || ! SvIOK(*shandle))
croak("Invalid SANE_Handle");
phandle = INT2PTR(SANE_Handle, SvIV(*shandle));
sane_close(phandle);
It seems to me that I should be able to have
SANE::Device dev
instead of
SV * dev
and add
SANE::Device T_PTROBJ
to the typemap, but I get
SANE.c:485: error: `SANE__Device' undeclared (first use in this function)
What am I missing?
Jeff
what I already new, that it wasn't very OO or Perlish, I wrote a
pure-Perl interface, which calls, of course, the XS.
All that works nicely, but I see I have many Perl subs which exist
solely to take a blessed hash reference and return the type that the
XS and C expects. i.e. a bit of complexity in the XS would eliminate
90% of the .pm.
I now have some code working with the hash reference, but the blessed
bit of the typemap is eluding me.
As an example, below is a DESTROY routine:
MODULE = SANE PACKAGE = SANE::Device PREFIX = sane_
PROTOTYPES: ENABLE
void
sane_DESTROY (dev)
SV * dev
INIT:
HV * hv;
SV ** shandle;
SANE_Handle phandle;
CODE:
hv = (HV *) SvRV (dev);
shandle = hv_fetch (hv, "_h", 2, 0);
if (shandle == NULL || ! SvIOK(*shandle))
croak("Invalid SANE_Handle");
phandle = INT2PTR(SANE_Handle, SvIV(*shandle));
sane_close(phandle);
It seems to me that I should be able to have
SANE::Device dev
instead of
SV * dev
and add
SANE::Device T_PTROBJ
to the typemap, but I get
SANE.c:485: error: `SANE__Device' undeclared (first use in this function)
What am I missing?
Jeff