I'd like to be able to accept Math::BigInt::GMP objects as arguments to some of the functions, and then be able to make use of the underlying mpz_t within the XS code, but i can't see how to do that.
Math::BigInt::GMP version 1.36 has a typemap that claims to be able to extract an mpz_t with:
mpz_from_sv($arg);But this is declared within GMP.xs itself as:
Since these are static (and therefore internal to GMP.so), i'm pretty sure i can't use them directly in my own XS. And given that they have #if blocks based on preprocessor directives, i don't think i can reasonably even cargo-cult the code into my own .xs file and make sure that it works portably :/STATIC mpz_t * mpz_from_sv_nofail (SV *sv) { MAGIC *mg; if (!sv_derived_from(sv, "Math::BigInt::GMP")) croak("not of type Math::BigInt::GMP"); for (mg = SvMAGIC(SvRV(sv)); mg; mg = mg->mg_moremagic) { if (mg->mg_type == PERL_MAGIC_ext #if GMP_HAS_MAGICEXT && mg->mg_virtual == &vtbl_gmp #endif ) { #if GMP_HAS_MAGICEXT return (mpz_t *)mg->mg_ptr; #else return INT2PTR(mpz_t *, SvIV((SV *)mg->mg_ptr)); #endif } } return (mpz_t *)NULL; } STATIC mpz_t * mpz_from_sv (SV *sv) { mpz_t *mpz; if (!(mpz = mpz_from_sv_nofail(sv))) croak("failed to fetch mpz pointer"); return mpz; }
Is there some clue i'm missing? Should i give up on direct mpz_t access, and force the communication across the XS boundaries to be laundered through some more primitive type (like an ASCII representation of a hex string)? That would allow me to work with more than just Math::BigInt::GMPs, but it's also much more inefficient than i'd like it to be.
Any suggestions for how i should approach this?
In reply to accessing mpz_t * of Math::BigInt::GMP from XS by dkg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |