in reply to Re^2: XS: exposing C++ library constant as package variable
in thread XS: exposing C++ library constant as package variable

Address 0x18 is not stack'd, malloc'd or (recently) free'd

That suggests that get_sv() is returning an invalid SV*; which it shouldn't, if the docs are to be believed:

get_sv Returns the SV of the specified Perl scalar. flags are passed to gv_fe +tchpv. If GV_ADD is set and the Perl variable does not exist then it +will be created. If flags is zero and the variable does not exist the +n NULL is returned. NOTE: the perl_ form of this function is deprecated. SV* get_sv(const char *name, I32 flags)

I think your only course of action (other than sticking with the way you have that works) is to write a minimal testcase and raise a perlbug.

P5p will either: correct the code; or correct my interpretation of the docs.

Of course, any resolution will take time, so you'll probably need to stick with what you originally had for now anyway. Sorry for the bum steer.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: XS: exposing C++ library constant as package variable ( sv_setiv , SvIV_set )
by Anonymous Monk on Oct 08, 2015 at 22:42 UTC

    That suggests that get_sv() is returning an invalid SV*; which it shouldn't, if the docs are to be believed:

    :) nope, its the call to SvIV_set thats causing it, solution i use is sv_setiv

    SV* const_sv = get_sv( "Soivro::SOIVRO", GV_ADD ); sv_setiv( const_sv, FILENAME_MAX ); SvREADONLY_on( const_sv );

      It was crashing because you forgot to upgrade the scalar to one that has an IV slot before trying to change the IV slot. sv_setiv works because it performs the upgrade.

        Ah, now that is useful information; thanks. The Perl XS documentation was not very helpful in making it clear what the implicit preconditions for each function are, I'm afraid.

      Thanks. Though it might have been better to address the information to the OP.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Thanks. Though it might have been better to address the information to the OP.

        :) Maybe , but your node is why I poked at the problem, so thats where I put it

Re^4: XS: exposing C++ library constant as package variable
by wisnij (Novice) on Oct 08, 2015 at 18:00 UTC

    Fair enough. Hopefully in the near future I'll have some time to look into this more deeply. For now, as long as my original approach looks valid (if perhaps not stylistically optimal) I'll stick with that. Thanks for the input.