Eventually got it down to the following (which works correctly for me, afaik):
use Math::BigInt lib => 'GMP'; use Inline C => Config => LIBS => '-lgmp', USING => 'ParseRegExp', BUILD_NOISY => 1; use Inline C => <<'EOC'; #include <gmp.h> 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"); mg = SvMAGIC(SvRV(sv)); return (mpz_t *)mg->mg_ptr; } void _my_mul(SV * bi_rop, SV * bi_op, SV * si, SV * rop_sign, SV * op_ +sign) { mpz_t *t1, *t2; sv_setpv(rop_sign, SvPV_nolen(op_sign)); t1 = mpz_from_sv_nofail(bi_rop); t2 = mpz_from_sv_nofail(bi_op); mpz_abs(*t2, *t2); mpz_mul_si(*t1, *t2, abs(SvIV(si))); if(SvIV(si) < 0) { if(strEQ(SvPV_nolen(op_sign), "-")) sv_setpv(rop_sign, "+"); else sv_setpv(rop_sign, "-"); } } EOC my $rop = Math::BigInt->new(0); my $op = Math::BigInt->new(-123456); my $x = 1103; my_mul($rop, $op, $x); print $rop, "\n"; my_mul($op, $op, 5); print $op, "\n"; sub my_mul { _my_mul($_[0]->{value}, $_[1]->{value}, $_[2], $_[0]->{sign}, $_[1]- +>{sign}); }
Cheers,
Rob

In reply to Re^4: accessing mpz_t * of Math::BigInt::GMP from XS by syphilis
in thread accessing mpz_t * of Math::BigInt::GMP from XS by dkg

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.