Erland Sommarskog
2009-07-22 20:48:20 UTC
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.)
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, ***@sommarskog.se
Erland Sommarskog, Stockholm, ***@sommarskog.se