Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: odd line in windows

by xiaoyafeng (Chaplain)
on Sep 08, 2011 at 07:49 UTC ( #924744=note: print w/ replies, xml ) Need Help??

in reply to Re: odd line in windows
in thread odd line in windows

new function does avoid the warning, but what does AV* mean in perl? a SV* are able to be a reference of array other than a AV*. though I'm still digging how this warning come, I insist using SV* as returning.

I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Comment on Re^2: odd line in windows
Re^3: odd line in windows
by ikegami (Pope) on Sep 08, 2011 at 09:26 UTC

    The typemap automatically creates a reference to it and returns the reference. It's refcount is off by one, though.

    use strict; use warnings; use Devel::Peek qw( Dump ); use Inline C => <<'__EOI__'; AV* f() { return newAV(); } __EOI__ Dump(f());
    >perl -MInline=FORCE,NOISY,NOCLEAN ... SV = IV(0x7bbf18) at 0x7bbf1c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x7bc05c SV = PVAV(0x7bcec8) at 0x7bc05c REFCNT = 2 <--- XXX FLAGS = () ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL)

    Making it mortal doesn't help. So unless I'm missing something, this can only be used if you actually hold a reference to the array you return.

      So unless I'm missing something, this can only be used if you actually hold a reference to the array you return

      No way to alter that particular reference count before returning the newly created AV ?


        According to the example in the Inline C Cookbook, the correct way to return an AV* is:

        newRV_noinc( (SV*)array = newAV() )

        Which kind of makes sense given the info ikegami posted above.

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        No. Decrementing its refcount before returning it would free it. One would normally make it a mortal, but I tried that and it didn't work.

        I filed a ticket and was told that this is documented in perlxs.

        This is quite useful as it usually improves readability. While this works fine for an SV *, it's unfortunately not as easy to have AV * or HV * as a return value. You should be able to write:

        AV * array() CODE: RETVAL = newAV(); /* do something with RETVAL */ OUTPUT: RETVAL

        But due to an unfixable bug (fixing it would break lots of existing CPAN modules) in the typemap file, the reference count of the AV * is not properly decremented. Thus, the above XSUB would leak memory whenever it is being called. The same problem exists for HV *.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://924744]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (16)
As of 2015-07-06 13:39 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (74 votes), past polls