Refactor FastCalc to initialise BASE and BASE_LEN as part of bootstrap.
authorNicholas Clark <nick@ccl4.org>
Thu, 28 Oct 2010 13:57:13 +0000 (14:57 +0100)
committerNicholas Clark <nick@ccl4.org>
Fri, 29 Oct 2010 13:42:41 +0000 (14:42 +0100)
This avoids the need for a separate, special, one-shot _set_XS_BASE routine.
We take advantage of the fact that all arguments to XSLoader::load() are passed
on to the module's bootstrap routine.

dist/Math-BigInt-FastCalc/FastCalc.pm
dist/Math-BigInt-FastCalc/FastCalc.xs

index e574655..bc7ab94 100644 (file)
@@ -10,9 +10,6 @@ use vars qw/$VERSION $BASE $BASE_LEN/;
 
 $VERSION = '0.24';
 
-require XSLoader;
-XSLoader::load(__PACKAGE__);
-
 ##############################################################################
 # global constants, flags and accessory
 
@@ -41,15 +38,11 @@ BEGIN
     *{'Math::BigInt::FastCalc::_' . $method} = \&{'Math::BigInt::Calc::_' . $method};
     }
 
-  # store BASE_LEN and BASE to later pass it to XS code 
   ($BASE_LEN, $BASE) = Math::BigInt::Calc::_base_len();
-
   }
 
-sub import
-  {
-  _set_XS_BASE($BASE, $BASE_LEN);
-  }
+require XSLoader;
+XSLoader::load(__PACKAGE__, $VERSION, $BASE_LEN, $BASE);
 
 ##############################################################################
 ##############################################################################
index 33f4b13..dfff9f4 100644 (file)
@@ -34,14 +34,13 @@ PROTOTYPES: DISABLE
       ST(0) = sv_2mortal(newSViv(value));      \
       XSRETURN(1);
 
-void 
-_set_XS_BASE(BASE, BASE_LEN)
-  SV* BASE
-  SV* BASE_LEN
-
-  CODE:
-    XS_BASE = SvNV(BASE); 
-    XS_BASE_LEN = SvIV(BASE_LEN); 
+BOOT:
+{
+    if (items < 4)
+       S_croak_xs_usage(aTHX_ cv, "package, version, base_len, base");
+    XS_BASE_LEN = SvIV(ST(2)); 
+    XS_BASE = SvNV(ST(3)); 
+}
 
 ##############################################################################
 # _new