Nitin Madnani wrote:
Hi Guys

I figured out why my code was segfaulting ... I was trying to access a perl scalar using get_sv(). The scalar has been lexically scoped with a my() but .. and here's the rub .. the perl subroutine that I am replacing with my C code occurs in the same scope as the my declaration and can see the scalar. So how come the C code can't?


Do you need to access the variable that way ?

Usually it's just a matter of passing the variable to the Inline C subroutine as an argument:

my $x = 'whatever';
my $ret = my_inline_c_sub($x);

Assuming you really *do* need to use get_sv(), let me fail to answer your question another way. If the first argument that get_sv() receives is (for example) "x", then it goes looking for $main::x. But it can't find it because $x, having been declared as a 'my' variable is not in the "main" package - in fact it doesn't belong to any package at all.

If you can change 'my' to 'our', then that will work.

If it needs to stay as 'my', then there might be a way around the problem .... but I don't know what it is.

Cheers,
Rob

Reply via email to