Hi, hopefully this is pretty straightforward.

I'm using perl v5.6.1 and building an XS wrapper around
FreeBSD's kevent/kqueue functions.
The library passes around poiunters to structures,
which I'm blessing into a package using the T_PTROBJ
typemap entry.

This works fine if the pointers are non-null, but if I
return a null pointer, it seems like the blessing fails.

The code is pretty simple:

        /* Kqueue.xs */
        typedef struct kevent *_Kevent;
        ...
        MODULE = Kqueue         PACKAGE = _Kevent
        ...
        _Kevent
        create(size=1)
            u_int       size
            CODE:
                if (size > 0) {
                    RETVAL = (_Kevent) calloc(size, sizeof(struct kevent));
                } else {
                    RETVAL = (_Kevent) 0;
                }
            OUTPUT:
                RETVAL
        ...
        MODULE = Kqueue         PACKAGE = Kqueue
        int
        _kevent(kq, changelist, nchanges, eventlist, nevents, timeout = NULL)
            Kqueue      kq
            _Kevent     changelist
            int         nchanges
            _Kevent     eventlist
            int         nevents
            Timeout     timeout
            INIT:

        /* typemap */
        _Kevent T_PTROBJ

The call to Kqueue::_kevent() fails with:

Use of uninitialized value in subroutine entry at blib/lib/Kqueue.pm line 228.
eventlist is not of type _Kevent at blib/lib/Kqueue.pm line 228.

Where eventlist is what _Kevent::create(0) returned, i.e. a blessed reference to a 
null pointer.

On inspection of the C output, this reduces to

        ST(0) = sv_newmortal();
        sv_setref_pv(ST(0), "_Kevent", (void*)0);

Does sv_setref_pv assume undef if its 3rd arg is null?

-- 
Bill Hails, Technical Yahoo!  Y!M:billhails  +44(0)20 7808 4457
---------------------------------------------------------------
perl -e 'print sub{"Do you ${[shift]}[0]?\n"}->("Yahoo!")'

Reply via email to