Author: faridz
Date: Thu Mar 27 07:42:09 2008
New Revision: 641835
URL: http://svn.apache.org/viewvc?rev=641835&view=rev
Log:
2008-03-27 Farid Zaripov <[EMAIL PROTECTED]>
STDCXX-798
* tests/self/0.printf.cpp (test_memptr): Corrected index calculations
according to endianness. Removed colon from expected resulting strings.
* tests/src/printf.cpp (_rw_fmtlong): Simplified code.
(_rw_fmtllong): Copied from _rw_fmtlong with changing corresponding
types to long long.
(_rw_fmtpointer): Corrected index calculations according to endianness.
Removed adding the colon separator.
Modified:
stdcxx/trunk/tests/self/0.printf.cpp
stdcxx/trunk/tests/src/printf.cpp
Modified: stdcxx/trunk/tests/self/0.printf.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/trunk/tests/self/0.printf.cpp?rev=641835&r1=641834&r2=641835&view=diff
==============================================================================
--- stdcxx/trunk/tests/self/0.printf.cpp (original)
+++ stdcxx/trunk/tests/self/0.printf.cpp Thu Mar 27 07:42:09 2008
@@ -2128,68 +2128,68 @@
static size_t big_endian = size_t (0 == u.bytes [0]);
- const size_t lo_inx = size_t (1 - big_endian);
- const size_t hi_inx = size_t (big_endian);
+ const size_t lo_inx = size_t (big_endian);
+ const size_t hi_inx = size_t (1 - big_endian);
#if 4 == _RWSTD_LONG_SIZE
uval.lval [hi_inx] = 0UL;
uval.lval [lo_inx] = 0UL;
- TEST ("%{M}", uval.mptr, 0, 0, "00000000:00000000");
- TEST ("%{#M}", uval.mptr, 0, 0, "0x00000000:00000000");
+ TEST ("%{M}", uval.mptr, 0, 0, "0000000000000000");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0x0000000000000000");
uval.lval [lo_inx] = 1UL;
- TEST ("%{M}", uval.mptr, 0, 0, "00000000:00000001");
- TEST ("%{#M}", uval.mptr, 0, 0, "0x00000000:00000001");
+ TEST ("%{M}", uval.mptr, 0, 0, "0000000000000001");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0x0000000000000001");
uval.lval [lo_inx] = 0xffffffffUL;
- TEST ("%{M}", uval.mptr, 0, 0, "00000000:ffffffff");
- TEST ("%{#M}", uval.mptr, 0, 0, "0x00000000:ffffffff");
+ TEST ("%{M}", uval.mptr, 0, 0, "00000000ffffffff");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0x00000000ffffffff");
uval.lval [hi_inx] = 0xdeadbeefUL;
uval.lval [lo_inx] = 0UL;
- TEST ("%{M}", uval.mptr, 0, 0, "deadbeef:00000000");
- TEST ("%{#M}", uval.mptr, 0, 0, "0xdeadbeef:00000000");
+ TEST ("%{M}", uval.mptr, 0, 0, "deadbeef00000000");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0xdeadbeef00000000");
uval.lval [lo_inx] = 0x1aUL;
- TEST ("%{M}", uval.mptr, 0, 0, "deadbeef:0000001a");
- TEST ("%{#M}", uval.mptr, 0, 0, "0xdeadbeef:0000001a");
+ TEST ("%{M}", uval.mptr, 0, 0, "deadbeef0000001a");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0xdeadbeef0000001a");
uval.lval [lo_inx] = 0x0fff1fffUL;
- TEST ("%{M}", uval.mptr, 0, 0, "deadbeef:0fff1fff");
- TEST ("%{#M}", uval.mptr, 0, 0, "0xdeadbeef:0fff1fff");
+ TEST ("%{M}", uval.mptr, 0, 0, "deadbeef0fff1fff");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0xdeadbeef0fff1fff");
#elif 8 == _RWSTD_LONG_SIZE
uval.lval [hi_inx] = 0UL;
uval.lval [lo_inx] = 0UL;
- TEST ("%{M}", uval.mptr, 0, 0, "0000000000000000:0000000000000000");
- TEST ("%{#M}", uval.mptr, 0, 0, "0x0000000000000000:0000000000000000");
+ TEST ("%{M}", uval.mptr, 0, 0, "00000000000000000000000000000000");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0x00000000000000000000000000000000");
uval.lval [lo_inx] = 1UL;
- TEST ("%{M}", uval.mptr, 0, 0, "0000000000000000:0000000000000001");
- TEST ("%{#M}", uval.mptr, 0, 0, "0x0000000000000000:0000000000000001");
+ TEST ("%{M}", uval.mptr, 0, 0, "00000000000000000000000000000001");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0x00000000000000000000000000000001");
uval.lval [lo_inx] = 0xffffffffUL;
- TEST ("%{M}", uval.mptr, 0, 0, "0000000000000000:00000000ffffffff");
- TEST ("%{#M}", uval.mptr, 0, 0, "0x0000000000000000:00000000ffffffff");
+ TEST ("%{M}", uval.mptr, 0, 0, "000000000000000000000000ffffffff");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0x000000000000000000000000ffffffff");
uval.lval [hi_inx] = 0x0123456789abcdefUL;
uval.lval [lo_inx] = 0UL;
- TEST ("%{M}", uval.mptr, 0, 0, "0123456789abcdef:0000000000000000");
- TEST ("%{#M}", uval.mptr, 0, 0, "0x0123456789abcdef:0000000000000000");
+ TEST ("%{M}", uval.mptr, 0, 0, "0123456789abcdef0000000000000000");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0x0123456789abcdef0000000000000000");
uval.lval [lo_inx] = 0x1aUL;
- TEST ("%{M}", uval.mptr, 0, 0, "0123456789abcdef:000000000000001a");
- TEST ("%{#M}", uval.mptr, 0, 0, "0x0123456789abcdef:000000000000001a");
+ TEST ("%{M}", uval.mptr, 0, 0, "0123456789abcdef000000000000001a");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0x0123456789abcdef000000000000001a");
uval.lval [lo_inx] = 0x0fff1fffUL;
- TEST ("%{M}", uval.mptr, 0, 0, "0123456789abcdef:000000000fff1fff");
- TEST ("%{#M}", uval.mptr, 0, 0, "0x0123456789abcdef:000000000fff1fff");
+ TEST ("%{M}", uval.mptr, 0, 0, "0123456789abcdef000000000fff1fff");
+ TEST ("%{#M}", uval.mptr, 0, 0, "0x0123456789abcdef000000000fff1fff");
#else
Modified: stdcxx/trunk/tests/src/printf.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/printf.cpp?rev=641835&r1=641834&r2=641835&view=diff
==============================================================================
--- stdcxx/trunk/tests/src/printf.cpp (original)
+++ stdcxx/trunk/tests/src/printf.cpp Thu Mar 27 07:42:09 2008
@@ -1054,73 +1054,51 @@
char buffer [130]; // big enough for a 128-bit long in base 2
char *end = buffer;
- long upoff = 0;
- const char *pfx = 0;
+ // 7.19.6.1 of ISO/IEC 9899:1999:
+ // The result of converting a zero value with a precision
+ // of zero is no characters.
+ if (spec.prec || val) {
+ const long upoff = 'X' == spec.cvtspec ? 36 : 0;
+ const int base = 1 < spec.base && spec.base < 37 ? spec.base : 10;
+ const bool is_signed = 'd' == spec.cvtspec || 'i' == spec.cvtspec;
+ const bool neg = 0 > val && is_signed;
+
+ ULong uval = ULong (neg ? -val : val);
+
+ do {
+ *end++ = _rw_digits [upoff + uval % base];
+ } while (uval /= base);
- if ('X' == spec.cvtspec)
- upoff = 36;
-
- if (spec.fl_pound) {
- if (16 == spec.base)
- pfx = upoff ? "0X" : "0x";
- else if (8 == spec.base && val)
- pfx = "0";
- }
-
- const int base = 1 < spec.base && spec.base < 37 ? spec.base : 10;
-
- ULong uval;
-
- bool neg;
-
- if (val < 0) {
- neg = 'd' == spec.cvtspec || 'i' == spec.cvtspec;
- uval = ULong (neg ? -val : val);
- }
- else {
- neg = false;
- uval = ULong (val);
- }
-
- do {
- *end++ = _rw_digits [upoff + uval % base];
- } while (uval /= base);
-
- int size = int (end - buffer);
-
- // insert as many zeros as specified by precision
- if (-1 < spec.prec && size < spec.prec) {
+ // insert as many zeros as specified by precision
// FIXME: prevent buffer overrun
- for (int i = size; i != spec.prec; ++i)
+ for (int i = int (end - buffer); i < spec.prec; ++i)
*end++ = '0';
- }
- // insert octal or hex prefix for non-zero values
- if (pfx && val) {
- if (pfx [1])
- *end++ = pfx [1];
- *end++ = pfx [0];
- }
-
- if (neg)
- *end++ = '-';
- else if (spec.fl_plus && ('d' == spec.cvtspec || 'i' == spec.cvtspec))
- *end++ = '+';
-
- if (0 == spec.prec && 0 == val) {
- // 7.19.6.1 of ISO/IEC 9899:1999:
- // The result of converting a zero value with a precision
- // of zero is no characters.
- end = buffer;
+ // insert octal or hex prefix for non-zero values
+ if (spec.fl_pound && val) {
+ switch (spec.base) {
+ case 16:
+ *end++ = upoff ? 'X' : 'x';
+ // fall through
+ case 8:
+ *end++ = '0';
+ break;
+ }
+ }
+
+ if (neg)
+ *end++ = '-';
+ else if (spec.fl_plus && is_signed)
+ *end++ = '+';
}
// not NUL-terminated
RW_ASSERT (buffer <= end);
- size = int (end - buffer);
+ const size_t size = size_t (end - buffer);
- for (char *pc = buffer; pc < end; ++pc) {
+ for (char *pc = buffer; pc < --end; ++pc) {
const char tmp = *pc;
- *pc = *--end;
+ *pc = *end;
*end = tmp;
}
@@ -1130,7 +1108,7 @@
newspec.prec = -1;
// handle justification by formatting the resulting string
- return _rw_fmtstr (newspec, buf, buffer, size_t (size));
+ return _rw_fmtstr (newspec, buf, buffer, size);
}
/********************************************************************/
@@ -1143,79 +1121,62 @@
char buffer [130]; // big enough for a 128-bit long long in base 2
char *end = buffer;
- long upoff = 0;
- const char *pfx = 0;
-
- if ('X' == spec.cvtspec)
- upoff = 36;
-
- if (spec.fl_pound) {
- if (16 == spec.base)
- pfx = upoff ? "0X" : "0x";
- else if (8 == spec.base && val)
- pfx = "0";
- }
-
- const int base = 1 < spec.base && spec.base < 37 ? spec.base : 10;
-
- typedef unsigned _RWSTD_LONG_LONG ULLong;
-
- ULLong uval;
-
- bool neg;
-
- if (val < 0) {
- neg = 'd' == spec.cvtspec || 'i' == spec.cvtspec;
- uval = ULLong (neg ? -val : val);
- }
- else {
- neg = false;
- uval = ULLong (val);
- }
-
- do {
- *end++ = _rw_digits [upoff + uval % base];
- } while (uval /= base);
-
- if (pfx) {
- if (pfx [1])
- *end++ = pfx [1];
- *end++ = pfx [0];
- }
-
- char sign;
+ // 7.19.6.1 of ISO/IEC 9899:1999:
+ // The result of converting a zero value with a precision
+ // of zero is no characters.
+ if (spec.prec || val) {
+ const long upoff = 'X' == spec.cvtspec ? 36 : 0;
+ const int base = 1 < spec.base && spec.base < 37 ? spec.base : 10;
+ const bool is_signed = 'd' == spec.cvtspec || 'i' == spec.cvtspec;
+ const bool neg = 0 > val && is_signed;
+
+ typedef unsigned _RWSTD_LONG_LONG ULLong;
+ ULLong uval = ULLong (neg ? -val : val);
+
+ do {
+ *end++ = _rw_digits [upoff + uval % base];
+ } while (uval /= base);
- if (neg)
- sign = '-';
- else if (spec.fl_plus && ('d' == spec.cvtspec || 'i' == spec.cvtspec))
- sign= '+';
- else
- sign = '\0';
-
- RW_ASSERT (buffer < end);
- size_t size = size_t (end - buffer);
-
- // FIXME: prevent buffer overrun
- if (0 < spec.prec && size < size_t (spec.prec)) {
- for (size_t i = size; i != size_t (spec.prec); ++i)
+ // insert as many zeros as specified by precision
+ // FIXME: prevent buffer overrun
+ for (int i = int (end - buffer); i < spec.prec; ++i)
*end++ = '0';
- }
- if (sign)
- *end++ = sign;
+ // insert octal or hex prefix for non-zero values
+ if (spec.fl_pound && val) {
+ switch (spec.base) {
+ case 16:
+ *end++ = upoff ? 'X' : 'x';
+ // fall through
+ case 8:
+ *end++ = '0';
+ break;
+ }
+ }
+
+ if (neg)
+ *end++ = '-';
+ else if (spec.fl_plus && is_signed)
+ *end++ = '+';
+ }
// not NUL-terminated
- RW_ASSERT (buffer < end);
- size = size_t (end - buffer);
+ RW_ASSERT (buffer <= end);
+ const size_t size = size_t (end - buffer);
- for (char *pc = buffer; pc < end; ++pc) {
+ for (char *pc = buffer; pc < --end; ++pc) {
const char tmp = *pc;
- *pc = *--end;
+ *pc = *end;
*end = tmp;
}
+ // reset precision to -1 (already handled above)
+ FmtSpec newspec (spec);
+ newspec.fl_pound = 0;
+ newspec.prec = -1;
+
// handle justification by formatting the resulting string
- return _rw_fmtstr (spec, buf, buffer, size);
+ return _rw_fmtstr (newspec, buf, buffer, size);
}
#endif // _RWSTD_LONG_LONG
@@ -1567,11 +1528,6 @@
// set the number of digits
newspec.prec = _RWSTD_LONG_SIZE * 2;
- const union {
- const void *ptr;
- const ULong *lptr;
- } uptr = { pptr };
-
int len = 0;
if (newspec.fl_pound) {
@@ -1585,21 +1541,17 @@
newspec.fl_pound = 0;
}
+ const union {
+ const void *ptr;
+ const ULong *lptr;
+ } uptr = { pptr };
+
for (size_t i = 0; i != nelems; ++i) {
- const size_t inx = _rw_big_endian ? nelems - i - 1 : i;
+ const size_t inx = _rw_big_endian ? i : nelems - i - 1;
int n = _rw_fmtlong (newspec, buf, uptr.lptr [inx]);
if (n < 0)
- return -1;
-
- len += n;
-
- // separate pointer components with colons
- n = 0;
- if (i + 1 < nelems) {
- if (0 == _rw_bufcat (buf, ":", size_t (n = 1)))
- return -1;
- }
+ return -1;
len += n;
}