develooper Front page | perl.perl5.porters | Postings from July 2014

atoi/strtoblah banished

Thread Next
From:
Jarkko Hietaniemi
Date:
July 23, 2014 03:05
Subject:
atoi/strtoblah banished
Message ID:
53CF266D.2080002@iki.fi
In 6313e544..f4379102 I implement a new rabid^Wthoughtful
interface for parsing unsigned integers.  This was then used
to replace the uses of atoi/atoll?/strtoll?/strtoull? in the core.

atoi is notoriously bad in detecting failures, it cannot be used
for incremental parsing ("how far did we get?"), and to top it all,
it believes locale settings (at least the amusingly badly named
"thousands separator", maybe even isdigit?).

strtol family is much better in the first two items, but it fails the 
third one.

The new interface is called "grok_atou" (the branch name was 
"krakatau"... I'll be here all week, folks, please tip the waiters).

It *only* handles unsigned integers (Size_t), by design.  If fancy 
features like negative inputs or optional leading whitespace are 
required-- use the C, Luke.

I extended my new toy, t/porting/libperl.t, to detect and punish if
someone attempts to reintroduce any of the atoi/atol/strtoblah back to 
the core.

For earlier discussion, see:
http://www.nntp.perl.org/group/perl.perl5.porters/2013/10/msg208680.html
https://rt.perl.org/Public/Bug/Display.html?id=116118#txn-1250187

grok_atou is completely new code, instead of trying to bolt
new parameters/flags to grok_number.  This makes it easier to
be extremely strict, and not worry about breaking grok_number.




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About