From c0fdee650ccddaa4a1d2adf7745aed02dbb0a602 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Thu, 28 Oct 2010 14:57:13 +0100 Subject: [PATCH] Refactor FastCalc to initialise BASE and BASE_LEN as part of bootstrap. 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 | 11 ++--------- dist/Math-BigInt-FastCalc/FastCalc.xs | 15 +++++++-------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/dist/Math-BigInt-FastCalc/FastCalc.pm b/dist/Math-BigInt-FastCalc/FastCalc.pm index e574655..bc7ab94 100644 --- a/dist/Math-BigInt-FastCalc/FastCalc.pm +++ b/dist/Math-BigInt-FastCalc/FastCalc.pm @@ -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); ############################################################################## ############################################################################## diff --git a/dist/Math-BigInt-FastCalc/FastCalc.xs b/dist/Math-BigInt-FastCalc/FastCalc.xs index 33f4b13..dfff9f4 100644 --- a/dist/Math-BigInt-FastCalc/FastCalc.xs +++ b/dist/Math-BigInt-FastCalc/FastCalc.xs @@ -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 -- 2.7.4