in reply to odd line in windows

try_pl_f4a3.xs:57:5: warning: passing argument 2 of 'Perl_newRV' from incompatible pointer type

This warning is in response to:
return newRV_inc(AV_procs);
and I think that's not quite the right thing to be doing.
According to perlapi, newRV_inc() takes an SV* arg, but AV_procs is an AV*.

Rewriting process_list() as follows avoids the warning, and intuitively strikes me as being a better approach:
AV* process_list(){ DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ); cProcesses = cbNeeded / sizeof(DWORD); AV* AV_procs = newAV(); for ( i = 0; i < cProcesses; i++ ) { if( aProcesses[i] != 0 ) { av_push(AV_procs, newSViv( aProcesses[i] ) ); } } return AV_procs; }
Cheers,
Rob

Replies are listed 'Best First'.
Re^2: odd line in windows
by xiaoyafeng (Deacon) on Sep 08, 2011 at 07:49 UTC
    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

      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 a.pl ... 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 ?

        Cheers,
        Rob
Re^2: odd line in windows
by ikegami (Patriarch) on Sep 08, 2011 at 07:13 UTC

    and I think that's not quite the right thing to be doing. According to perlapi, newRV_inc() takes an SV* arg, but AV_procs is an AV*.

    An AV is a type of SV. That's indeed the way to create a reference to an array. You just need to cast.

    newRV_noinc(MUTABLE_SV(av))