in reply to Re^4: XS: SvPVLV examples?
in thread XS: SvPVLV examples?

Then maybe you're missing that there are no non-core magic types?

Replies are listed 'Best First'.
Re^6: XS: SvPVLV examples?
by BrowserUk (Patriarch) on Sep 25, 2009 at 02:42 UTC

    Just because there aren't, or at least, so far I haven't located any, doesn't mean there couldn't be. Otherwise there would be no point it the '~' magic type. See item 44 in the third table below Perlguts#magic virtual tables:

    ~ PERL_MAGIC_ext (none) Available for use by ext +ensions

    For my particular purpose, substr magic would work perfectly so long as I can adjust the offset/length appropriately.


    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".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Interesting! My last post was wrong. You can add ext magic using sv_magic (no vtable) or sv_magicext (with vtable).

      Then I guess you missed "The extra fields only have meaning to the associated magic handlers". That means it's entirely up to you what you put in them if you have your own magic.

      I wonder if each variables with ext magic has its own virtual table pointer.

        I wonder if each variables with ext magic has its own virtual table pointer.

        See SvPVMG & SvPVLV at PerlGuts Illustrated. It's probably somewhat out of date due to the 5.9/5.10 changes, but it is still the clearest guide around.

        As I say, for my purposes, the SvPVLV and the associated 'x' type magic would pretty much do everything I want, provided I can adjust the LV_ARGS.


        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".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        I wonder if each variables with ext magic has its own virtual table pointer.

        It does! That means that having only one extension type is not as limiting as it seems!

        use strict; use warnings; use Inline C => <<'__EOI__'; static const char* test1_str = "Hello, "; static int test1_mg_get(pTHX_ SV *sv, MAGIC *mg) { sv_setpvn(sv, test1_str, (STRLEN)strlen(test1_str)); return 0; } static const MGVTBL vtbl_test1 = { test1_mg_get, NULL, NULL, NULL, NULL }; SV* get_test1_var() { SV* sv = newSV_type(SVt_PVLV); sv_magicext(sv, NULL, PERL_MAGIC_ext, &vtbl_test1, NULL, 0); return sv; } static const char* test2_str = "World!"; static int test2_mg_get(pTHX_ SV *sv, MAGIC *mg) { sv_setpvn(sv, test2_str, (STRLEN)strlen(test2_str)); return 0; } static const MGVTBL vtbl_test2 = { test2_mg_get, NULL, NULL, NULL, NULL }; SV* get_test2_var() { SV* sv = newSV_type(SVt_PVLV); sv_magicext(sv, NULL, PERL_MAGIC_ext, &vtbl_test2, NULL, 0); return sv; } __EOI__ use Devel::Peek qw( Dump ); my $test1 = get_test1_var(); my $test2 = get_test2_var(); print("$test1$test2\n");