On Fri, 05 Sep 2008, Jeffrey Ratcliffe wrote:
> 
> void
> sane_open(class, name)
>               SANE_String_Const       name
>       INIT:
>               SANE_Status             status;
>                 SANE_Handle           h;
>         PPCODE:
>               status = sane_open(name, &h);
>                 XPUSHs(sv_2mortal(newSViv(status)));
> 126->                XPUSHs(sv_2mortal(newSVpv(h, 0)));
> 
> SANE_Handle is a void pointer:

You probably want to use

        XPUSHs(sv_2mortal(newSViv(PTR2IV(h))));

[...]

> So in the typemap I have:
> 
> SANE_Handle                   T_OPAQUEPTR

I think you want just T_PTR instead.  Or you can explicitly
restore the pointer from the IV as e.g.:
 
        h = INT2PTR(SANE_Handle, ST(0));

The T_OPAQUEPTR type would pack your pointer into a string, which is
less efficient than just converting it to an IV and back.

It is somewhat confusing that you are using the typemap for your INPUT
parameter but then try to encode the OUTPUT parameter yourself.  You
should consistently do one or the other and not mix things (just for the
sake of maintaining the code later).

Cheers,
-Jan

Reply via email to