Am I checking for undef in the wrong way?
[email protected] (Erland Sommarskog)
| Newsgroups | perl.xs |
|---|---|
| Organization | Erland Sommarskog |
| Message-ID | <[email protected]> |
I have an issue with an XS module of mine. I lean towards that it is a
bug in threads::shared, but maybe I am doing something wrong?
To show the issue, I have this silly XS routine:
void
arraytest(arrayref)
SV * arrayref
CODE:
{
AV * av = (AV *) SvRV(arrayref);
SV ** svp = av_fetch(av, 0, 0);
SV * sv = *svp;
warn ("SvOK = %d\n", SvOK(sv));
warn ("SvIV = %d\n", SvIV(sv));
warn ("SvOK = %d\n", SvOK(sv));
}
The main script runs:
my $arrayref = [5678];
arraytest($arrayref);
my $shared_arrayref : shared = shared_clone($arrayref);
arraytest($shared_arrayref);
The output is:
SvOK = 4352
SvIV = 5678
SvOK = 4352
SvOK = 0
SvIV = 5678
SvOK = 4096
That is, when I send in a regular array reference, results are as
expected. But when the reference is a shared object, SvOK first
returns 0. When I retrieve the value with SvIV I get the correct
value nevertheless, and next time SvOK returns a true value!
Am I doing somethinug wrong? Or should I file a bug for threads::shared?
If it is a bug, any suggestion for a workaround? In the real module, the
value can be of any type, so SvIV does not seem like a good idea.
This happens on Win32 with ActivePerl builds 1005. I attach my test
module and test script (which also shows the same thing happens with a
hash reference.)
--
Erland Sommarskog, Stockholm, [email protected]
makefile.pl
(application/octet-stream, 598 B)
use strict;
use ExtUtils::MakeMaker;
WriteMakefile(
'NAME' => 'TestInSummertime',
'OBJECT' => 'TestInSummertime.obj',
'CCFLAGS' => '-MT',
'LIBS' => [":nosearch :nodefault delayimp.lib kernel32.lib user32.lib ole32.lib oleaut32.lib uuid.lib libcmt.lib"],
'VERSION_FROM' => 'TestInSummertime.pm',
'XS' => { 'TestInSummertime.xs' => 'TestInSummertime.cpp' }
);
sub MY::xs_c {
'
.xs.cpp:
$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >xstmp.c && $(MV) xstmp.c $*.cpp
';
}
TestInSummertime.pl
(application/octet-stream, 353 B)
use strict;
use threads;
use threads::shared;
use TestInSummertime;
my $arrayref = [5678];
my $hashref = {Key => 4711};
arraytest($arrayref);
hashtest($hashref);
my $shared_arrayref : shared = shared_clone($arrayref);
my $shared_hashref : shared = shared_clone($hashref);
arraytest($shared_arrayref);
hashtest($shared_hashref);
TestInSummertime.pm
(application/octet-stream, 247 B)
package TestInSummertime; use strict; use Exporter; use DynaLoader; use vars qw(@ISA @EXPORT $VERSION); $VERSION = '1.000'; @ISA = qw(Exporter DynaLoader); bootstrap TestInSummertime; @EXPORT = qw(arraytest hashtest); 1;
TestInSummertime.xs
(application/octet-stream, 785 B) - not displayed