- Rename 'oset_test' as 'unit_oset' to make its meaning more clear.
- Remove VG_(atoll36), VG_(strtoll8)() and VG_(strtoll36)(); they're not
used and so untested, but easy to crib from similar functions if they need
to be added again later.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9204
Converting strings to numbers
------------------------------------------------------------------ */
-static Bool is_oct_digit(Char c, Long* digit)
-{
- if (c >= '0' && c <= '7') { *digit = (Long)(c - '0'); return True; }
- return False;
-}
-
static Bool is_dec_digit(Char c, Long* digit)
{
if (c >= '0' && c <= '9') { *digit = (Long)(c - '0'); return True; }
return False;
}
-static Bool is_base36_digit(Char c, Long* digit)
-{
- if (c >= '0' && c <= '9') { *digit = (Long)(c - '0'); return True; }
- if (c >= 'A' && c <= 'Z') { *digit = (Long)((c - 'A') + 10); return True; }
- if (c >= 'a' && c <= 'z') { *digit = (Long)((c - 'a') + 10); return True; }
- return False;
-}
-
-Long VG_(strtoll8) ( Char* str, Char** endptr )
-{
- Bool neg = False;
- Long n = 0, digit = 0;
-
- // Skip leading whitespace.
- while (VG_(isspace)(*str)) str++;
-
- // Allow a leading '-' or '+'.
- if (*str == '-') { str++; neg = True; }
- else if (*str == '+') { str++; }
-
- while (is_oct_digit(*str, &digit)) {
- n = 8*n + digit;
- str++;
- }
-
- if (neg) n = -n;
- if (endptr) *endptr = str; // Record first failing character.
- return n;
-}
-
Long VG_(strtoll10) ( Char* str, Char** endptr )
{
- Bool neg = False;
+ Bool neg = False, converted = False;
Long n = 0, digit = 0;
+ Char* str0 = str;
// Skip leading whitespace.
while (VG_(isspace)(*str)) str++;
else if (*str == '+') { str++; }
while (is_dec_digit(*str, &digit)) {
+ converted = True; // Ok, we've actually converted a digit.
n = 10*n + digit;
str++;
}
- if (neg) n = -n;
+ if (!converted) str = str0; // If nothing converted, endptr points to
+ if (neg) n = -n; // the start of the string.
if (endptr) *endptr = str; // Record first failing character.
return n;
}
Long VG_(strtoll16) ( Char* str, Char** endptr )
{
- Bool neg = False;
+ Bool neg = False, converted = False;
Long n = 0, digit = 0;
+ Char* str0 = str;
// Skip leading whitespace.
while (VG_(isspace)(*str)) str++;
}
while (is_hex_digit(*str, &digit)) {
+ converted = True; // Ok, we've actually converted a digit.
n = 16*n + digit;
str++;
}
- if (neg) n = -n;
- if (endptr) *endptr = str; // Record first failing character.
- return n;
-}
-
-Long VG_(strtoll36) ( Char* str, Char** endptr )
-{
- Bool neg = False;
- Long n = 0, digit = 0;
-
- // Skip leading whitespace.
- while (VG_(isspace)(*str)) str++;
-
- // Allow a leading '-' or '+'.
- if (*str == '-') { str++; neg = True; }
- else if (*str == '+') { str++; }
-
- while (is_base36_digit(*str, &digit)) {
- n = 36*n + digit;
- str++;
- }
-
- if (neg) n = -n;
+ if (!converted) str = str0; // If nothing converted, endptr points to
+ if (neg) n = -n; // the start of the string.
if (endptr) *endptr = str; // Record first failing character.
return n;
}
return VG_(strtoll16)(str, NULL);
}
-Long VG_(atoll36) ( Char* str )
-{
- return VG_(strtoll36)(str, NULL);
-}
-
/* ---------------------------------------------------------------------
String functions
------------------------------------------------------------------ */
// accepts an initial "0x" or "0X" prefix, but only if it's followed by a
// hex digit (if not, the '0' will be read and then it will stop on the
// "x"/"X".) If 'endptr' isn't NULL, it gets filled in with the first
-// non-digit char. None of them test that the number fits into 64 bits.
+// non-digit char. Returns 0 if no number could be converted, and 'endptr'
+// is set to the start of the string. None of them test that the number
+// fits into 64 bits.
//
// Nb: if you're wondering why we don't just have a single VG_(strtol) which
// takes a base, it's because I wanted it to assert if it was given a bogus
// base (the standard glibc one sets 'errno' in this case). But
// m_libcbase.c doesn't import any code, not even vg_assert. --njn
-extern Long VG_(strtoll8) ( Char* str, Char** endptr );
extern Long VG_(strtoll10) ( Char* str, Char** endptr );
extern Long VG_(strtoll16) ( Char* str, Char** endptr );
-extern Long VG_(strtoll36) ( Char* str, Char** endptr );
- // Convert a string to a double. After leading whitespace is ignored,
- // it accepts a non-empty sequence of decimal digits possibly containing
- // a '.'.
+ // Convert a string to a double. After leading whitespace is ignored, a
+ // '+' or '-' is allowed, and then it accepts a non-empty sequence of
+ // decimal digits possibly containing a '.'. Hexadecimal floats are not
+ // accepted, nor are "fancy" floats (eg. "3.4e-5", "NAN").
extern double VG_(strtod) ( Char* str, Char** endptr );
+ // These are just like their VG_(strtoll*) counterparts, except that you
+ // cannot tell if an error occurred (because 0 is returned) or if there
+ // is any trailing non-numeric characterws (eg. in "123xyz").
extern Long VG_(atoll) ( Char* str ); // base 10
extern Long VG_(atoll16) ( Char* str ); // base 16; leading 0x accepted
-extern Long VG_(atoll36) ( Char* str ); // base 36
/* ---------------------------------------------------------------------
String functions and macros
memcmptest.stderr.exp memcmptest.stderr.exp2 \
memcmptest.stdout.exp memcmptest.vgtest \
mempool.stderr.exp mempool.stderr.exp64 mempool.vgtest \
+ metadata.stderr.exp metadata.stdout.exp metadata.vgtest \
mismatches.stderr.exp mismatches.stderr.exp64 mismatches.vgtest \
mmaptest.stderr.exp mmaptest.vgtest \
nanoleak.stderr.exp nanoleak.vgtest \
origin6-fp.vgtest origin6-fp.stdout.exp \
origin6-fp.stderr.exp-glibc25-amd64 \
origin6-fp.stderr.exp-glibc27-ppc64 \
- oset_test.stderr.exp oset_test.stdout.exp oset_test.vgtest \
overlap.stderr.exp overlap.stdout.exp overlap.vgtest \
partiallydefinedeq.vgtest partiallydefinedeq.stderr.exp \
partiallydefinedeq.stderr.exp2 \
suppfree.stderr.exp suppfree.vgtest \
toobig-allocs.stderr.exp toobig-allocs.vgtest \
trivialleak.stderr.exp trivialleak.vgtest \
- metadata.stderr.exp metadata.stdout.exp metadata.vgtest \
+ unit_libcbase.stderr.exp unit_libcbase.stdout.exp unit_libcbase.vgtest \
+ unit_oset.stderr.exp unit_oset.stdout.exp unit_oset.vgtest \
varinfo1.vgtest varinfo1.stdout.exp varinfo1.stderr.exp \
varinfo2.vgtest varinfo2.stdout.exp varinfo2.stderr.exp \
varinfo3.vgtest varinfo3.stdout.exp varinfo3.stderr.exp \
malloc_usable malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \
match-overrun \
memalign_test memalign2 memcmptest mempool mmaptest \
+ mismatches new_override metadata \
nanoleak nanoleak2 new_nothrow \
noisy_child \
- null_socket oset_test \
+ null_socket \
origin1-yes origin2-not-quite origin3-no \
origin4-many origin5-bz2 origin6-fp \
overlap \
stack_changes strchr str_tester \
supp_unknown supp1 supp2 suppfree \
trivialleak \
- mismatches new_override metadata \
+ unit_libcbase unit_oset \
varinfo1 varinfo2 varinfo3 varinfo4 \
varinfo5 varinfo5so.so varinfo6 \
vcpu_fbench vcpu_fnfns \
--- /dev/null
+vgopts: -q
+prog: unit_libcbase
Int i, n;
Word v = 0, prev;
Word vs[NN];
- Word *pv;
// Create a static OSet of Ints. This one uses fast (built-in)
// comparisons.