Commit graph

7 commits

Author SHA1 Message Date
Elliott Hughes
00211554a7 Remove strtoq() and strtouq().
These have been aliases for strtoll() and strtoull() since L, by
accident. We've never exposed them in the headers, and they're unused by
any apps. Let's fix the inconsistency between libc.so and its headers by
removing the aliases.

Bug: https://github.com/android/ndk/issues/1803
Test: treehugger
Change-Id: I87de7831c04b3e450a44e9f0386cacb73793e393
2022-11-09 16:15:05 +00:00
Elliott Hughes
1f462dec34 Add %b and %B support to the scanf/wscanf and strto*/wcsto* families.
Coming to C23 via WG14 N2630.

This one is a little interesting, because it actually changes existing
behavior. Previously "0b101" would be parsed as "0", "b", "101" by these
functions. I'm led to believe that glibc plans to actually have separate
versions of these functions for C23 and pre-C23, so callers can have the
behavior they (implicitly) specify by virtue of which -std= they compile
with. Android has never really done anything like that, and I'm pretty
sure app developers have more than enough to worry about with API levels
without having to deal with the cartesian product of API level and C
standard.

Therefore, my plan A is "if you're running on Android >= U, you get C23
behavior". My plan B in the (I think unlikely) event that that actually
causes trouble for anyone is "if you're _targeting_ Android >= U, you
get C23 behavior". I don't think we'd actually want to have two versions
of each of these functions under any circumstances --- that seems by far
the most confusing option.

Test: treehugger
Change-Id: I0bbb30315d3fabd306905ad1484361f5d8745935
2022-08-11 00:25:08 +00:00
Elliott Hughes
7cebf835f3 Various coverage improvements.
Mostly from extra test cases, but also:

* Move the fgets size < 0 assertion into fgets.

* Use ELF aliases for strtoq/strtouq rather than duplicating code.

* Don't check uname() succeeded, since it can't fail.

Test: treehugger
Change-Id: I2e6b3b88b0a3eb16bd68be68b9bc9f40d8043291
2020-08-12 15:52:14 -07:00
Elliott Hughes
bf03c01b38 Remove bionic's internal ctype-like inlines.
Bug: http://b/144165498
Test: treehugger
Change-Id: Ifcf352525abc74850053a1a019f90c72e488b71c
2020-02-05 11:39:35 -08:00
Elliott Hughes
cb239bda65 Simplify atoi*/strto* for signed integers.
Make the cost of strto<signed> closer to the cost of strto<unsigned>
by removing an `if` from the inner loop. Previously a signed conversion
cost 10ns more than an unsigned one.

After:

  BM_inttypes_strtoimax         81 ns         81 ns    8603362
  BM_inttypes_strtoumax         78 ns         78 ns    8967174
  BM_stdlib_strtol              81 ns         81 ns    8685537
  BM_stdlib_strtoll             81 ns         81 ns    8685481
  BM_stdlib_strtoul             78 ns         78 ns    8962569
  BM_stdlib_strtoull            78 ns         78 ns    8972023

Bug: N/A
Test: ran tests, benchmarks
Change-Id: I72dd5499427b6a940bd94c4d6f727f7efe134d7e
2017-12-21 17:44:22 -08:00
Elliott Hughes
1133fecde3 Use inline ctype functions for ato*/strto* and scanf.
This also let us remove the `unsigned char` casts, since we define our
inlines to work for all values.

Before:

  Benchmark                      Time           CPU Iterations
  -------------------------------------------------------------
  BM_inttypes_strtoimax        112 ns        112 ns    6222193
  BM_inttypes_strtoumax        104 ns        104 ns    6725010
  BM_stdlib_strtol             113 ns        113 ns    6195861
  BM_stdlib_strtoll            113 ns        113 ns    6195633
  BM_stdlib_strtoul            105 ns        105 ns    6691394
  BM_stdlib_strtoull           105 ns        105 ns    6690695

  BM_stdio_scanf_d                    504 ns        503 ns    1385224
  BM_stdio_scanf_maps                1900 ns       1898 ns     369260
  BM_stdio_scanf_maps_baseline       1030 ns       1030 ns     678832
  BM_stdio_scanf_s                    433 ns        432 ns    1619086

After:

  BM_inttypes_strtoimax         91 ns         91 ns    7718194
  BM_inttypes_strtoumax         82 ns         82 ns    8508052
  BM_stdlib_strtol              92 ns         92 ns    7674694
  BM_stdlib_strtoll             91 ns         91 ns    7639228
  BM_stdlib_strtoul             83 ns         82 ns    8500304
  BM_stdlib_strtoull            82 ns         82 ns    8504929

  BM_stdio_scanf_d                    465 ns        465 ns    1507891
  BM_stdio_scanf_maps                1836 ns       1836 ns     381082
  BM_stdio_scanf_maps_baseline        846 ns        845 ns     830881
  BM_stdio_scanf_s                    419 ns        419 ns    1671979

Bug: N/A
Test: ran tests, benchmarks
Change-Id: I44681daf16c4328b060770cf11fc0633157c427f
2017-12-19 16:37:01 -08:00
Elliott Hughes
1921dce886 Refactor the ato* and strto* family.
There are no meaningful changes here, just a minimal conversion to two
C++ templates to make further changes easier.

Bug: N/A
Test: ran tests, benchmarks
Change-Id: I958fbf17a85f19dd8f17bfb4bbb9314d220daa3b
2017-12-19 13:55:54 -08:00