# * added _is_two(), _is_ten(), _ten()
# 2007-04-02 0.08 Tels
# * plug leaks by creating mortals
+ # 2007-05-27 0.09 Tels
+ # * add _new()
#define RETURN_MORTAL_INT(value) \
ST(0) = sv_2mortal(newSViv(value)); \
XS_BASE_LEN = SvIV(BASE_LEN);
##############################################################################
+# _new
+
+AV *
+_new(class, x)
+ SV* x
+ INIT:
+ STRLEN len;
+ char* cur;
+ int part_len;
+
+ CODE:
+ /* create the array */
+ RETVAL = newAV();
+ sv_2mortal((SV*)RETVAL);
+ /* cur = SvPV(x, len); printf ("input '%s'\n", cur); */
+ if (SvIOK(x) && SvIV(x) < XS_BASE)
+ {
+ /* shortcut for integer arguments */
+ av_push (RETVAL, newSViv( SvIV(x) ));
+ }
+ else
+ {
+ /* split the input (as string) into XS_BASE_LEN long parts */
+ /* in perl:
+ [ reverse(unpack("a" . ($il % $BASE_LEN+1)
+ . ("a$BASE_LEN" x ($il / $BASE_LEN)), $_[1])) ];
+ */
+ cur = SvPV(x, len); /* convert to string & store length */
+ cur += len; /* doing "cur = SvEND(x)" does not work! */
+ # process the string from the back
+ while (len > 0)
+ {
+ /* use either BASE_LEN or the amount of remaining digits */
+ part_len = XS_BASE_LEN;
+ if (part_len > len)
+ {
+ part_len = len;
+ }
+ /* processed so many digits */
+ cur -= part_len;
+ len -= part_len;
+ /* printf ("part '%s' (part_len: %i, len: %i, BASE_LEN: %i)\n", cur, part_len, len, XS_BASE_LEN); */
+ if (part_len > 0)
+ {
+ av_push (RETVAL, newSVpvn(cur, part_len) );
+ }
+ }
+ }
+ OUTPUT:
+ RETVAL
+
+##############################################################################
# _copy
void
$| = 1;
chdir 't' if -d 't';
unshift @INC, ('../lib', '../blib/arch'); # for running manually
- plan tests => 20;
+ plan tests => 22;
}
+use Math::BigInt::FastCalc;
+
#############################################################################
package Math::BigInt::FastCalc::LeakCheck;
use base qw(Math::BigInt::FastCalc);
my $num_long = Math::BigInt::FastCalc->_new("1234567890");
my $num_long_2 = Math::BigInt::FastCalc->_new("12345678900987654321");
+is (Math::BigInt::FastCalc->_str($num_long), "1234567890");
+is (Math::BigInt::FastCalc->_str($num_long_2), "12345678900987654321");
+
# to hit all possible code branches
_test_acmp($num, $num);
_test_acmp($num_10, $num_10);