From: Yuval Kogman Date: Thu, 21 Aug 2008 11:17:08 +0000 (+0000) Subject: use grok_number instead of strtol X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4d0ab1b993694997cc11b307b966d6e0cf5b9f8a;p=gitmo%2FMoose.git use grok_number instead of strtol --- diff --git a/Moose.xs b/Moose.xs index 685f565..facae15 100644 --- a/Moose.xs +++ b/Moose.xs @@ -434,23 +434,10 @@ STATIC bool check_sv_type (TC type, SV *sv) { if ( SvIOK(sv) ) { return 1; } else if ( SvPOK(sv) ) { - /* FIXME i really don't like this */ - int i; STRLEN len; char *pv = SvPV(sv, len); - char *end = pv + len; - char *tail = end; - - errno = 0; - i = strtol(pv, &tail, 0); - - if ( errno ) return 0; - - while ( tail != end ) { - if ( !isspace(*tail++) ) return 0; - } - - return 1; + int flags = grok_number(pv, len, NULL); + return ( flags && !(flags & IS_NUMBER_NOT_INT) ); } return 0; break; diff --git a/t/700_xs/001_basic.t b/t/700_xs/001_basic.t index f9c9c0a..27d3460 100644 --- a/t/700_xs/001_basic.t +++ b/t/700_xs/001_basic.t @@ -215,6 +215,7 @@ ok( !eval { $foo->i(1.3); 1 }, "Int" ); ok( !eval { $foo->i("1.3"); 1 }, "Int" ); ok( !eval { $foo->i("foo"); 1 }, "Int" ); ok( !eval { $foo->i(undef); 1 }, "Int" ); +ok( !eval { $foo->i(\undef); 1 }, "Int" ); ok( !eval { $foo->s(undef); 1 }, "Str" ); ok( !eval { $foo->s([]); 1 }, "Str" ); ok( !eval { $foo->o({}); 1 }, "Object" );