in reply to Math::BigInt::GMP - direct access to the gmp integer value

I think that's because
sv_magicext(SvRV(sv), NULL, PERL_MAGIC_ext, &vtbl_gmp, (void *)mpz, 0 +);
(in attach_mpz_to_sv) uses pointer to vtbl_gmp defined in gmp.xs, and you're comparing with a pointer to an object defined in your file. Those are two different objects and have different addresses.

As for deleting the line && mg->mg_virtual == &vtbl_gmp, well, Perl's magic is like black magic to me :) but perlapi says: Note that "sv_magicext" will allow things that "sv_magic" will not. In particular, you can... add more than one instance of the same 'how' (so, some other module can add another PERL_MAGIC_ext struct to the linked list of magics).

Replies are listed 'Best First'.
Re^2: Math::BigInt::GMP - direct access to the gmp integer value
by syphilis (Archbishop) on Jan 10, 2016 at 05:26 UTC
    Perl's magic is like black magic to me :)

    Not only do I not know how it works, but I also don't even know what it does !!

    Those are two different objects and have different addresses

    Thank you for wading through the code and spotting that - much appreciated !!
    I'll need to chew this over for a while.

    It means I either have to do something that will ensure that the addresses match, or just remove the problematic condition from the code.
    The latter is appealing, as I know immediately how to do that (and it reduces overhead). But I'm initially loathe to take that action as I don't know what risks it might create.

    Anyway - that's something I can work on.
    Thanks again.

    Cheers,
    Rob
      Not only do I not know how it works, but I also don't even know what it does !!
      My reading of that code is that it uses magic mostly to store the pointer to mpz in mg->mg_ptr. perlguts says its okay: "Extensions can use "PERL_MAGIC_ext" magic to 'attach' private information to variables (typically objects). This is especially useful because there is no way for normal perl code to corrupt this private information (unlike using extra elements of a hash object)". Then there is also that copying function dup_gmp_mpz, apparently for use with ithreads.
      But I'm initially loathe to take that action as I don't know what risks it might create.
      As far as I can tell, the risk is that something else will attach magic (with tag PERL_MAGIC_ext) to your Math::BigInt::GMP variable, and then you'll get wrong mg->mg_ptr. How likely is that? Probably pretty unlikely...