I tried just using GV_ADD, but it gave me a segfault:

==44885== Invalid write of size 8
==44885==    at 0x6BA4D37: boot_MyModule (mymodule.xs:113)
==44885==    by 0x4CB944F: Perl_pp_entersub (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4CB7785: Perl_runops_standard (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C59496: Perl_call_sv (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C5999C: Perl_call_list (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C45138: S_process_special_blocks (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C533EC: Perl_newATTRSUB (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C53AA2: Perl_utilize (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C82FFF: Perl_yyparse (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4CF0918: S_doeval (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4CF143A: Perl_pp_entereval (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4CB7785: Perl_runops_standard (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==  Address 0x18 is not stack'd, malloc'd or (recently) free'd
==44885==
==44885==
==44885== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==44885==  Access not within mapped region at address 0x18
==44885==    at 0x6BA4D37: boot_MyModule (mymodule.xs:113)
==44885==    by 0x4CB944F: Perl_pp_entersub (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4CB7785: Perl_runops_standard (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C59496: Perl_call_sv (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C5999C: Perl_call_list (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C45138: S_process_special_blocks (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C533EC: Perl_newATTRSUB (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C53AA2: Perl_utilize (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4C82FFF: Perl_yyparse (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4CF0918: S_doeval (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4CF143A: Perl_pp_entereval (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==    by 0x4CB7785: Perl_runops_standard (in /export/my_company/Linux_RHEL6_x86_64/lang/perl/5.12/lib/5.12.5/x86_64-linux-thread-multi/CORE/libperl.so)
==44885==  If you believe this happened as a result of a stack
==44885==  overflow in your program's main thread (unlikely but
==44885==  possible), you can try to increase the size of the
==44885==  main thread stack using the --main-stacksize= flag.
==44885==  The main thread stack size used in this run was 10485760.

mymodule.xs:113 is where I'm calling SvIV_set. The same thing happens if I leave $CONSTANT_NAME in the use vars statement, but don't initialize it in BEGIN.


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.