1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
This commit is contained in:
stefanocasazza 2016-10-14 17:55:51 +02:00
parent 0b4ca03ac7
commit c6683d1e1b
8 changed files with 56 additions and 38 deletions

View File

@ -523,6 +523,7 @@ static inline unsigned long u_strtoul(const char* restrict s, const char* restri
U_INTERNAL_ASSERT_POINTER(s)
U_INTERNAL_ASSERT_POINTER(e)
#ifndef U_COVERITY_FALSE_POSITIVE /* Control flow issues (MISSING_BREAK) */
switch (len)
{
case 10: val += (s[len-10] - '0') * 1000000000UL;
@ -536,6 +537,7 @@ static inline unsigned long u_strtoul(const char* restrict s, const char* restri
case 2: val += (s[len- 2] - '0') * 10UL;
case 1: val += (s[len- 1] - '0');
}
#endif
U_INTERNAL_PRINT("val = %lu", val)
@ -552,6 +554,7 @@ static inline uint64_t u_strtoull(const char* restrict s, const char* restrict e
U_INTERNAL_ASSERT_POINTER(s)
U_INTERNAL_ASSERT_POINTER(e)
#ifndef U_COVERITY_FALSE_POSITIVE /* Control flow issues (MISSING_BREAK) */
switch (len)
{
case 20: val += (s[len-20] - '0') * 10000000000000000000ULL;
@ -575,6 +578,7 @@ static inline uint64_t u_strtoull(const char* restrict s, const char* restrict e
case 2: val += (s[len- 2] - '0') * 10ULL;
case 1: val += (s[len- 1] - '0');
}
#endif
U_INTERNAL_PRINT("val = %llu", val)
@ -583,7 +587,7 @@ static inline uint64_t u_strtoull(const char* restrict s, const char* restrict e
extern U_EXPORT long u_strtol( const char* restrict s, const char* restrict e) __pure;
extern U_EXPORT int64_t u_strtoll(const char* restrict s, const char* restrict e) __pure;
extern U_EXPORT double u_strtod( const char* restrict s, const char* restrict e, int point_pos) __pure;
extern U_EXPORT double u_strtod( const char* restrict s, const char* restrict e, int pos) __pure;
static inline unsigned u__octc2int(unsigned char c) { return ((c - '0') & 07); }

View File

@ -135,7 +135,7 @@ __pure int64_t u_strtoll(const char* restrict s, const char* restrict e)
return (neg ? -val : val);
}
__pure double u_strtod(const char* restrict s, const char* restrict e, int point_pos)
__pure double u_strtod(const char* restrict s, const char* restrict e, int pos)
{
static const double pow10[] = {
1e+0,
@ -146,11 +146,10 @@ __pure double u_strtod(const char* restrict s, const char* restrict e, int point
const char* restrict p;
uint64_t integerPart, fractionPart;
U_INTERNAL_TRACE("u_strtod(%p,%p,%d)", s, e, -point_pos)
U_INTERNAL_TRACE("u_strtod(%p,%p,%d)", s, e, pos)
U_INTERNAL_ASSERT_POINTER(s)
U_INTERNAL_ASSERT_POINTER(e)
U_INTERNAL_ASSERT_MINOR(point_pos, 0)
// while (u__isspace(*s)) ++s;
@ -164,7 +163,7 @@ __pure double u_strtod(const char* restrict s, const char* restrict e, int point
p = s;
integerPart = u_strtoull(p, (point_pos != (INT_MIN+1) ? (s += -point_pos) : ++s));
integerPart = u_strtoull(p, (s += ((unsigned char*)&pos)[1]));
U_INTERNAL_ASSERT_EQUALS(*s, '.')

View File

@ -41,15 +41,16 @@
char* UValue::pstringify;
UTokenizer* UValue::ptok;
UValue::UValue(const UString& _key, const UString& value_)
UValue::UValue(const UString& _key, const UString& _value)
{
U_TRACE_REGISTER_OBJECT(0, UValue, "%V,%V", _key.rep, value_.rep)
U_TRACE_REGISTER_OBJECT(0, UValue, "%V,%V", _key.rep, _value.rep)
parent =
prev =
next = 0;
key = 0;
value.ptr_ = 0;
size = _key.size() + _value.size() + U_CONSTANT_SIZE("{\"\": \"\"}");
type_ = OBJECT_VALUE;
UValue* child;
@ -60,7 +61,7 @@ UValue::UValue(const UString& _key, const UString& value_)
children.tail = child;
U_NEW(UString, child->key, UString(_key));
U_NEW(UString, child->value.ptr_, UString(value_));
U_NEW(UString, child->value.ptr_, UString(_value));
U_INTERNAL_DUMP("this = %p", this)
}
@ -1249,12 +1250,14 @@ case_number:
if (type_num != 0)
{
if (type_num < 0)
unsigned char* ptr = (unsigned char*)&type_num;
if (ptr[0] == '-')
{
type_ = REAL_VALUE;
value.real_ = (type_num == INT_MIN // scientific notation (Ex: 1.45e10)
? strtod(start, 0)
: u_strtod(start, ptok->getPointer(), type_num));
value.real_ = (ptr[2] != 0 // scientific notation (Ex: 1.45e10)
? strtod(start, 0)
: u_strtod(start, ptok->getPointer(), type_num));
U_INTERNAL_DUMP("value.real_ = %g", value.real_)

View File

@ -2149,11 +2149,13 @@ double UString::strtod() const
if (type_num != 0)
{
if (type_num < 0)
unsigned char* ptr = (unsigned char*)&type_num;
if (ptr[0] == '-')
{
double real = (type_num == INT_MIN // scientific notation (Ex: 1.45e10)
? ::strtod(start, 0)
: u_strtod(start, t.getPointer(), type_num));
double real = (ptr[2] != 0 // scientific notation (Ex: 1.45e10)
? ::strtod(start, 0)
: u_strtod(start, t.getPointer(), type_num));
U_INTERNAL_DUMP("real = %g", real)

View File

@ -260,9 +260,10 @@ int UTokenizer::getTypeNumber()
int type_num = u__isdigit(*(s-1));
for (const char* start = s; s < end; ++s)
if (s < end)
{
char c = *s;
const char* start = s;
char c = *s;
U_INTERNAL_DUMP("c = %C type_num = %d", c, type_num)
@ -289,13 +290,13 @@ int UTokenizer::getTypeNumber()
{
int pos = (s-start);
if (pos == 0) type_num = INT_MIN+1; // -2147483647
else
{
if (u__isdigit(*(start-1))) ++pos;
U_INTERNAL_DUMP("pos = %u s = %.4S", (s-start), s)
type_num = -pos;
}
unsigned char* ptr = (unsigned char*)&type_num;
ptr[0] = (unsigned char)'-';
ptr[1] = (pos == 0 ? 1 : (unsigned char)(u__isdigit(*(start-1))
? pos+1 : pos));
while (u__isdigit(*++s)) {}
@ -307,19 +308,30 @@ int UTokenizer::getTypeNumber()
}
c = *s;
}
U_INTERNAL_DUMP("c = %C type_num = %d", c, type_num)
U_INTERNAL_DUMP("c = %C type_num = [%u:%u:%u:%u]", c, ptr[0], ptr[1], ptr[2], ptr[3])
}
if (u__toupper(c) == 'E') // scientific notation (Ex: 1.45e-10)
{
// int pos = (s-start);
int pos = (s-start);
U_INTERNAL_DUMP("pos = %u s = %.4S", (s-start), s)
unsigned char* ptr = (unsigned char*)&type_num;
ptr[0] = (unsigned char)'-';
ptr[2] = (pos == 0 ? 1 : (unsigned char)(u__isdigit(*(start-1))
? pos+1 : pos));
c = *++s;
if (u__issign(c)) c = *++s;
if (u__issign(c))
{
ptr[3] = (unsigned char)c;
c = *++s;
}
if (u__isdigit(c))
{
@ -327,15 +339,13 @@ int UTokenizer::getTypeNumber()
if (s >= end) s = end;
U_RETURN(INT_MIN); // -2147483648
U_INTERNAL_DUMP("type_num = [%u:%u:%u:%u]", ptr[0], ptr[1], ptr[2], ptr[3])
U_RETURN(type_num);
}
U_RETURN(0);
}
U_INTERNAL_DUMP("c = %C type_num = %d", c, type_num)
break;
}
U_RETURN(type_num);

View File

@ -42,7 +42,7 @@ plugin/product1.lo: plugin/product1.cpp /usr/include/stdc-predef.h \
/usr/include/bits/stdlib-bsearch.h /usr/include/bits/stdlib-float.h \
/usr/include/ctype.h ../../include/ulib/base/replace/replace.h \
/usr/src/linux/include/generated/uapi/linux/version.h \
/opt/openssl/include/openssl/opensslv.h /usr/include/string.h \
/usr/include/openssl/opensslv.h /usr/include/string.h \
/usr/include/fcntl.h /usr/include/bits/fcntl.h \
/usr/include/bits/fcntl-linux.h /usr/include/errno.h \
/usr/include/bits/errno.h /usr/include/linux/errno.h \
@ -313,7 +313,7 @@ plugin/product.h:
/usr/src/linux/include/generated/uapi/linux/version.h:
/opt/openssl/include/openssl/opensslv.h:
/usr/include/openssl/opensslv.h:
/usr/include/string.h:

View File

@ -42,7 +42,7 @@ plugin/product2.lo: plugin/product2.cpp /usr/include/stdc-predef.h \
/usr/include/bits/stdlib-bsearch.h /usr/include/bits/stdlib-float.h \
/usr/include/ctype.h ../../include/ulib/base/replace/replace.h \
/usr/src/linux/include/generated/uapi/linux/version.h \
/opt/openssl/include/openssl/opensslv.h /usr/include/string.h \
/usr/include/openssl/opensslv.h /usr/include/string.h \
/usr/include/fcntl.h /usr/include/bits/fcntl.h \
/usr/include/bits/fcntl-linux.h /usr/include/errno.h \
/usr/include/bits/errno.h /usr/include/linux/errno.h \
@ -313,7 +313,7 @@ plugin/product.h:
/usr/src/linux/include/generated/uapi/linux/version.h:
/opt/openssl/include/openssl/opensslv.h:
/usr/include/openssl/opensslv.h:
/usr/include/string.h:

View File

@ -9,7 +9,7 @@ rm -rf /tmp/ssl_session.txt
start_msg ssl_server
start_msg ssl_client
UTRACE="0 5M 0"
#UTRACE="0 5M 0"
#UOBJDUMP="0 100k 10"
#USIMERR="error.sim"
export UTRACE UOBJDUMP USIMERR