Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to detect an undefined SV* value in XS?

Reply
Thread Tools

How to detect an undefined SV* value in XS?

 
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      12-12-2004
Also sprach Sisyphus:

> Sisyphus wrote:
>
>>
>> use warnings;
>> use Inline C => Config =>
>> BUILD_NOISY => 1; # to make sure we get to
>> # see compiler warnings
>>
>> use Inline C => <<'END_OF_C_CODE';
>>
>> void set_undef(SV * a) {
>>
>> sv_setsv(a, &PL_sv_undef);

>
> Another thread, and another list - and it has just been drawn to my
> attention that's not the right way to assign PL_sv_undef to an SV. The
> above line should be replaced by:
>
> a = &PL_sv_undef


Wont help either. You cannot change 'a' in-place thusly. If you want
that you'd have to have something like:

void set_undef (SV **a) {
*a = &PL_sv_undef;
}

But I don't think that Inline::C or XS know about an SV** prototype. The
reason is again the difference between changing a C-structure internally
(this is what sv_setsv does) or having a variable point to something
else. If you want to do the latter, you need to pass the pointer by
reference. These are the usual C-semantics.

>> if(a == &PL_sv_undef)
>> printf("A valid means of testing for &PL_sv_undef\n");
>>
>> else printf("An INVALID means of testing for &PL_sv_undef\n");
>>
>> }
>>

>
> I haven't tested, but I expect one would then find that the script
> reports "A valid means of testing for &PL_sv_undef".


Only if the variable passed to set_undef() was a real PL_sv_undef in the
first place. What you are thinking of is a no-op.

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
 
Reply With Quote
 
 
 
 
Sisyphus
Guest
Posts: n/a
 
      12-14-2004
Tassilo v. Parseval wrote:
> Also sprach Sisyphus:
>
>
>>Sisyphus wrote:
>>
>>
>>>use warnings;
>>>use Inline C => Config =>
>>> BUILD_NOISY => 1; # to make sure we get to
>>> # see compiler warnings
>>>
>>>use Inline C => <<'END_OF_C_CODE';
>>>
>>>void set_undef(SV * a) {
>>>
>>>sv_setsv(a, &PL_sv_undef);

>>
>>Another thread, and another list - and it has just been drawn to my
>>attention that's not the right way to assign PL_sv_undef to an SV. The
>>above line should be replaced by:
>>
>>a = &PL_sv_undef

>
>
> Wont help either. You cannot change 'a' in-place thusly. If you want
> that you'd have to have something like:
>
> void set_undef (SV **a) {
> *a = &PL_sv_undef;
> }
>
> But I don't think that Inline::C or XS know about an SV** prototype. The
> reason is again the difference between changing a C-structure internally
> (this is what sv_setsv does) or having a variable point to something
> else. If you want to do the latter, you need to pass the pointer by
> reference. These are the usual C-semantics.
>
>
>>>if(a == &PL_sv_undef)
>>> printf("A valid means of testing for &PL_sv_undef\n");
>>>
>>>else printf("An INVALID means of testing for &PL_sv_undef\n");
>>>
>>>}
>>>

>>
>>I haven't tested, but I expect one would then find that the script
>>reports "A valid means of testing for &PL_sv_undef".

>
>
> Only if the variable passed to set_undef() was a real PL_sv_undef in the
> first place. What you are thinking of is a no-op.
>
> Tassilo


A tree ... and some rope .... that's all I *really* need

Cheers,
Rob

--
To reply by email u have to take out the u in kalinaubears.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
pyOpenGL Error unable to detect undefined names Ron Python 0 12-02-2010 05:18 PM
How to Detect Use of Unassigned(Undefined) Variable(Function) ++imanshu Python 3 11-28-2009 04:15 AM
Help using Spreadsheet::ParseExcel Module - Can't call method "value"on an undefined value perl Newbie Perl Misc 2 05-06-2009 09:43 AM
B::Lint does not detect undefined subs Alexander Frink Perl Misc 5 08-07-2006 09:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57