The MinGW.org Windows System Libraries
Revisão | 96666e31b322ff73f7ad6f70b0c556b25bbb9c2d (tree) |
---|---|
Hora | 2016-10-31 04:12:05 |
Autor | Keith Marshall <keithmarshall@user...> |
Commiter | Keith Marshall |
Merge post 2016-10-18 updates from legacy branch.
@@ -1,3 +1,31 @@ | ||
1 | +2016-10-30 Keith Marshall <keithmarshall@users.sourceforge.net> | |
2 | + | |
3 | + Merge post 2016-10-18 updates from legacy branch. | |
4 | + | |
5 | + * include/io.h include/wchar.h: Updated. | |
6 | + * mingwex/stdio/pformat.c: Likewise. | |
7 | + | |
8 | +2016-10-30 Keith Marshall <keithmarshall@users.sourceforge.net> | |
9 | + | |
10 | + Work around MSDN inconsistencies in _finddata_t naming. | |
11 | + | |
12 | + * include/io.h (_finddata64_t, _wfinddata64_): Define them | |
13 | + respectively as aberrant alternative data type names for each of... | |
14 | + (__finddata64_t, __wfinddata64_t): ...these original names. | |
15 | + (_wfinddata32_t): Similarly, define this with... | |
16 | + (__wfinddata32_t): ...this alternative name. | |
17 | + | |
18 | + * include/wchar.h (_wfinddata32_t): Correct references in comments. | |
19 | + | |
20 | +2016-10-30 Keith Marshall <keithmarshall@users.sourceforge.net> | |
21 | + | |
22 | + Fix a potentially infinite printf() format conversion loop. | |
23 | + | |
24 | + * mingwex/stdio/pformat.c (__pformat_emit_xfloat) | |
25 | + [value.__pformat_fpreg_mantissa == 0]: Do not attempt to normalize | |
26 | + it; there are no 1-bits to promote, so repeated shifting until one | |
27 | + appears in most significant position will never terminate. | |
28 | + | |
1 | 29 | 2016-10-18 Keith Marshall <keithmarshall@users.sourceforge.net> |
2 | 30 | |
3 | 31 | Merge mingwrt-3.22.4 updates into 5.0-active branch. |
@@ -221,6 +221,12 @@ int _findnexti64 (intptr_t, struct _finddatai64_t *); | ||
221 | 221 | * to the original generic _findfirst()/_findnext() implementation). |
222 | 222 | */ |
223 | 223 | struct __finddata64_t __struct_finddata_t (__time64_t, __int64); |
224 | +/* | |
225 | + * Some MSDN documents, (particularly more recent documents), may | |
226 | + * inconsistently refer to this structural type by the anomalous | |
227 | + * name of _finddata64_t; support this anomaly. | |
228 | + */ | |
229 | +#define _finddata64_t __finddata64_t | |
224 | 230 | |
225 | 231 | _CRTIMP __cdecl __MINGW_NOTHROW |
226 | 232 | intptr_t _findfirst64 (const char *, struct __finddata64_t *); |
@@ -360,6 +366,13 @@ int _wfindnexti64 (intptr_t, struct _wfinddatai64_t *); | ||
360 | 366 | * MSVCRT.DLL, after it originally appeared in MSVCR61.DLL. |
361 | 367 | */ |
362 | 368 | struct __wfinddata64_t __struct_finddata_t (__time64_t, __int64); |
369 | +/* | |
370 | + * As in the case of the __finddata64_t structure, some MSDN | |
371 | + * documents, (particularly more recent documents), may refer | |
372 | + * to __wfinddata64_t by the inconsistently anomalous name of | |
373 | + * _wfinddata64_t; also support this anomaly. | |
374 | + */ | |
375 | +#define _wfinddata64_t __wfinddata64_t | |
363 | 376 | |
364 | 377 | _CRTIMP __cdecl __MINGW_NOTHROW |
365 | 378 | intptr_t _wfindfirst64 (const wchar_t *, struct __wfinddata64_t *); |
@@ -372,15 +385,26 @@ int _wfindnext64 (intptr_t, struct __wfinddata64_t *); | ||
372 | 385 | * exclusive to it and its later derivatives; none of these are |
373 | 386 | * available in any version of MSVCRT.DLL. |
374 | 387 | */ |
375 | -struct __wfinddata32_t __struct_finddata_t (__time32_t, __int32); | |
388 | +struct _wfinddata32_t __struct_finddata_t (__time32_t, __int32); | |
376 | 389 | struct _wfinddata32i64_t __struct_finddata_t (__time32_t, __int64); |
377 | 390 | struct _wfinddata64i32_t __struct_finddata_t (__time64_t, __int32); |
391 | +/* | |
392 | + * As in the __finddata64_t vs. _finddata64_t, and __wfinddata64_t | |
393 | + * vs. _wfinddata64_t anomalous cases, there is at least one historic | |
394 | + * MSDN reference to a __wfinddata32_t structural type, in a context | |
395 | + * where _wfinddata32_t may be expected. In this case, it appears | |
396 | + * that __wfinddata32_t is the anomaly, and that it may be peculiar | |
397 | + * to the VS-2005 documentation; nevertheless, the corresponding | |
398 | + * definition is provided here, for the possible convenience of | |
399 | + * any user who may depend on it, (but please avoid it). | |
400 | + */ | |
401 | +#define __wfinddata32_t _wfinddata32_t | |
378 | 402 | |
379 | 403 | _CRTIMP __cdecl __MINGW_NOTHROW |
380 | -intptr_t _wfindfirst32 (const wchar_t *, struct __wfinddata32_t *); | |
404 | +intptr_t _wfindfirst32 (const wchar_t *, struct _wfinddata32_t *); | |
381 | 405 | |
382 | 406 | _CRTIMP __cdecl __MINGW_NOTHROW |
383 | -int _wfindnext32 (intptr_t, struct __wfinddata32_t *); | |
407 | +int _wfindnext32 (intptr_t, struct _wfinddata32_t *); | |
384 | 408 | |
385 | 409 | _CRTIMP __cdecl __MINGW_NOTHROW |
386 | 410 | intptr_t _wfindfirst32i64 (const wchar_t *, struct _wfinddata32i64_t *); |
@@ -406,11 +430,11 @@ int _wfindnext64i32 (intptr_t, struct _wfinddata64i32_t *); | ||
406 | 430 | */ |
407 | 431 | __CRT_ALIAS __cdecl __MINGW_NOTHROW |
408 | 432 | intptr_t _wfindfirst (const wchar_t *__filespec, struct _wfinddata_t *__search) |
409 | -{ return _wfindfirst32 (__filespec, (struct __wfinddata32_t *)(__search)); } | |
433 | +{ return _wfindfirst32 (__filespec, (struct _wfinddata32_t *)(__search)); } | |
410 | 434 | |
411 | 435 | __CRT_ALIAS __cdecl __MINGW_NOTHROW |
412 | 436 | int _wfindnext (intptr_t __handle, struct _wfinddata_t *__search) |
413 | -{ return _wfindnext32 (__handle, (struct __wfinddata32_t *)(__search)); } | |
437 | +{ return _wfindnext32 (__handle, (struct _wfinddata32_t *)(__search)); } | |
414 | 438 | |
415 | 439 | __CRT_ALIAS __cdecl __MINGW_NOTHROW |
416 | 440 | intptr_t _wfindfirsti64 (const wchar_t *__filespec, struct _wfinddatai64_t *__search) |
@@ -268,8 +268,8 @@ | ||
268 | 268 | * ...and these, which are only available in the non-free run-times |
269 | 269 | * from MSVCR80.DLL onwards: |
270 | 270 | * |
271 | - * intptr_t _wfindfirst32 (wchar_t *, struct __wfinddata32_t *); | |
272 | - * int _wfindnext32 (intptr_t, struct __wfinddata32_t *); | |
271 | + * intptr_t _wfindfirst32 (wchar_t *, struct _wfinddata32_t *); | |
272 | + * int _wfindnext32 (intptr_t, struct _wfinddata32_t *); | |
273 | 273 | * |
274 | 274 | * intptr_t _wfindfirst32i64 (wchar_t *, struct _wfinddata32i64_t *); |
275 | 275 | * int _wfindnext32i64 (intptr_t, struct _wfinddata32i64_t *); |
@@ -1629,121 +1629,126 @@ void __pformat_emit_xfloat( __pformat_fpreg_t value, __pformat_t *stream ) | ||
1629 | 1629 | * be placed before the radix point, leaving at most 15 digits |
1630 | 1630 | * to satisfy any requested precision; thus... |
1631 | 1631 | */ |
1632 | - if( (stream->precision >= 0) && (stream->precision < 15) ) | |
1632 | + if( value.__pformat_fpreg_mantissa ) | |
1633 | 1633 | { |
1634 | - /* When the user specifies a precision within this range, | |
1635 | - * we want to adjust the mantissa, to retain just the number | |
1636 | - * of digits required, rounding up when the high bit of the | |
1637 | - * leftmost discarded digit is set; (mask of 0x08 accounts | |
1638 | - * for exactly one digit discarded, shifting 4 bits per | |
1639 | - * digit, with up to 14 additional digits, to consume the | |
1640 | - * full availability of 15 precision digits). | |
1641 | - * | |
1642 | - * However, before we perform the rounding operation, we | |
1643 | - * normalise the mantissa, shifting it to the left by as many | |
1644 | - * bit positions may be necessary, until its highest order bit | |
1645 | - * is set, thus preserving the maximum number of bits in the | |
1646 | - * rounded result as possible. | |
1647 | - */ | |
1648 | - while( value.__pformat_fpreg_mantissa < (LLONG_MAX + 1ULL) ) | |
1649 | - value.__pformat_fpreg_mantissa <<= 1; | |
1650 | - | |
1651 | - /* We then shift the mantissa one bit position back to the | |
1652 | - * right, to guard against possible overflow when the rounding | |
1653 | - * adjustment is added. | |
1654 | - */ | |
1655 | - value.__pformat_fpreg_mantissa >>= 1; | |
1656 | - | |
1657 | - /* We now add the rounding adjustment, noting that to keep the | |
1658 | - * 0x08 mask aligned with the shifted mantissa, we also need to | |
1659 | - * shift it right by one bit initially, changing its starting | |
1660 | - * value to 0x04... | |
1661 | - */ | |
1662 | - value.__pformat_fpreg_mantissa += 0x04LL << (4 * (14 - stream->precision)); | |
1663 | - if( (value.__pformat_fpreg_mantissa & (LLONG_MAX + 1ULL)) == 0ULL ) | |
1664 | - /* | |
1665 | - * When the rounding adjustment would not have overflowed, | |
1666 | - * then we shift back to the left again, to fill the vacated | |
1667 | - * bit we reserved to accommodate the carry. | |
1634 | + /* ...provided the mantissa is non-zero... | |
1635 | + */ | |
1636 | + if( (stream->precision >= 0) && (stream->precision < 15) ) | |
1637 | + { | |
1638 | + /* ...when the user specifies a precision within this range, | |
1639 | + * we want to adjust the mantissa, to retain just the number | |
1640 | + * of digits required, rounding up when the high bit of the | |
1641 | + * leftmost discarded digit is set; (mask of 0x08 accounts | |
1642 | + * for exactly one digit discarded, shifting 4 bits per | |
1643 | + * digit, with up to 14 additional digits, to consume the | |
1644 | + * full availability of 15 precision digits). | |
1645 | + * | |
1646 | + * However, before we perform the rounding operation, we | |
1647 | + * normalise the mantissa, shifting it to the left by as many | |
1648 | + * bit positions may be necessary, until its highest order bit | |
1649 | + * is set, thus preserving the maximum number of bits in the | |
1650 | + * rounded result as possible. | |
1668 | 1651 | */ |
1669 | - value.__pformat_fpreg_mantissa <<= 1; | |
1652 | + while( value.__pformat_fpreg_mantissa < (LLONG_MAX + 1ULL) ) | |
1653 | + value.__pformat_fpreg_mantissa <<= 1; | |
1670 | 1654 | |
1671 | - else | |
1672 | - /* Otherwise the rounding adjustment would have overflowed, | |
1673 | - * so the carry has already filled the vacated bit; the effect | |
1674 | - * of this is equivalent to an increment of the exponent. | |
1655 | + /* We then shift the mantissa one bit position back to the | |
1656 | + * right, to guard against possible overflow when the rounding | |
1657 | + * adjustment is added. | |
1675 | 1658 | */ |
1676 | - value.__pformat_fpreg_exponent++; | |
1677 | - | |
1678 | - /* We now complete the rounding to the required precision, by | |
1679 | - * shifting the unwanted digits out, from the right hand end of | |
1680 | - * the mantissa. | |
1681 | - */ | |
1682 | - value.__pformat_fpreg_mantissa >>= 4 * (15 - stream->precision); | |
1683 | - } | |
1659 | + value.__pformat_fpreg_mantissa >>= 1; | |
1684 | 1660 | |
1685 | - /* Encode the significant digits of the mantissa in hexadecimal | |
1686 | - * ASCII notation, ready for transfer to the output stream... | |
1687 | - */ | |
1688 | - while( value.__pformat_fpreg_mantissa ) | |
1689 | - { | |
1690 | - /* taking the rightmost digit in each pass... | |
1691 | - */ | |
1692 | - int c = value.__pformat_fpreg_mantissa & 0xF; | |
1693 | - if( c == value.__pformat_fpreg_mantissa ) | |
1694 | - { | |
1695 | - /* inserting the radix point, when we reach the last, | |
1696 | - * (i.e. the most significant digit), unless we found no | |
1697 | - * less significant digits, with no mandatory radix point | |
1698 | - * inclusion, and no additional required precision... | |
1661 | + /* We now add the rounding adjustment, noting that to keep the | |
1662 | + * 0x08 mask aligned with the shifted mantissa, we also need to | |
1663 | + * shift it right by one bit initially, changing its starting | |
1664 | + * value to 0x04... | |
1699 | 1665 | */ |
1700 | - if( (p > buf) | |
1701 | - || (stream->flags & PFORMAT_HASHED) || (stream->precision > 0) ) | |
1666 | + value.__pformat_fpreg_mantissa += 0x04LL << (4 * (14 - stream->precision)); | |
1667 | + if( (value.__pformat_fpreg_mantissa & (LLONG_MAX + 1ULL)) == 0ULL ) | |
1702 | 1668 | /* |
1703 | - * Internally, we represent the radix point as an ASCII '.'; | |
1704 | - * we will replace it with any locale specific alternative, | |
1705 | - * at the time of transfer to the ultimate destination. | |
1669 | + * When the rounding adjustment would not have overflowed, | |
1670 | + * then we shift back to the left again, to fill the vacated | |
1671 | + * bit we reserved to accommodate the carry. | |
1706 | 1672 | */ |
1707 | - *p++ = '.'; | |
1673 | + value.__pformat_fpreg_mantissa <<= 1; | |
1674 | + | |
1675 | + else | |
1676 | + /* Otherwise the rounding adjustment would have overflowed, | |
1677 | + * so the carry has already filled the vacated bit; the effect | |
1678 | + * of this is equivalent to an increment of the exponent. | |
1679 | + */ | |
1680 | + value.__pformat_fpreg_exponent++; | |
1681 | + | |
1682 | + /* We now complete the rounding to the required precision, by | |
1683 | + * shifting the unwanted digits out, from the right hand end of | |
1684 | + * the mantissa. | |
1685 | + */ | |
1686 | + value.__pformat_fpreg_mantissa >>= 4 * (15 - stream->precision); | |
1687 | + } | |
1708 | 1688 | |
1709 | - /* If the most significant hexadecimal digit of the encoded | |
1710 | - * output value is greater than one, then the indicated value | |
1711 | - * will appear too large, by an additional binary exponent | |
1712 | - * corresponding to the number of higher order bit positions | |
1713 | - * which it occupies... | |
1689 | + /* Encode the significant digits of the mantissa in hexadecimal | |
1690 | + * ASCII notation, ready for transfer to the output stream... | |
1691 | + */ | |
1692 | + while( value.__pformat_fpreg_mantissa ) | |
1693 | + { | |
1694 | + /* taking the rightmost digit in each pass... | |
1714 | 1695 | */ |
1715 | - while( value.__pformat_fpreg_mantissa > 1 ) | |
1696 | + int c = value.__pformat_fpreg_mantissa & 0xF; | |
1697 | + if( c == value.__pformat_fpreg_mantissa ) | |
1716 | 1698 | { |
1717 | - /* so reduce the exponent value to compensate... | |
1699 | + /* inserting the radix point, when we reach the last, | |
1700 | + * (i.e. the most significant digit), unless we found no | |
1701 | + * less significant digits, with no mandatory radix point | |
1702 | + * inclusion, and no additional required precision... | |
1718 | 1703 | */ |
1719 | - value.__pformat_fpreg_exponent--; | |
1720 | - value.__pformat_fpreg_mantissa >>= 1; | |
1704 | + if( (p > buf) | |
1705 | + || (stream->flags & PFORMAT_HASHED) || (stream->precision > 0) ) | |
1706 | + /* | |
1707 | + * Internally, we represent the radix point as an ASCII '.'; | |
1708 | + * we will replace it with any locale specific alternative, | |
1709 | + * at the time of transfer to the ultimate destination. | |
1710 | + */ | |
1711 | + *p++ = '.'; | |
1712 | + | |
1713 | + /* If the most significant hexadecimal digit of the encoded | |
1714 | + * output value is greater than one, then the indicated value | |
1715 | + * will appear too large, by an additional binary exponent | |
1716 | + * corresponding to the number of higher order bit positions | |
1717 | + * which it occupies... | |
1718 | + */ | |
1719 | + while( value.__pformat_fpreg_mantissa > 1 ) | |
1720 | + { | |
1721 | + /* so reduce the exponent value to compensate... | |
1722 | + */ | |
1723 | + value.__pformat_fpreg_exponent--; | |
1724 | + value.__pformat_fpreg_mantissa >>= 1; | |
1725 | + } | |
1721 | 1726 | } |
1722 | - } | |
1723 | 1727 | |
1724 | - else if( stream->precision > 0 ) | |
1725 | - /* | |
1726 | - * we have not yet fulfilled the desired precision, | |
1727 | - * and we have not yet found the most significant digit, | |
1728 | - * so account for the current digit, within the field | |
1729 | - * width required to meet the specified precision. | |
1730 | - */ | |
1731 | - stream->precision--; | |
1728 | + else if( stream->precision > 0 ) | |
1729 | + /* | |
1730 | + * we have not yet fulfilled the desired precision, | |
1731 | + * and we have not yet found the most significant digit, | |
1732 | + * so account for the current digit, within the field | |
1733 | + * width required to meet the specified precision. | |
1734 | + */ | |
1735 | + stream->precision--; | |
1732 | 1736 | |
1733 | - if( (c > 0) || (p > buf) || (stream->precision >= 0) ) | |
1734 | - /* | |
1735 | - * Ignoring insignificant trailing zeros, (unless required to | |
1736 | - * satisfy specified precision), store the current encoded digit | |
1737 | - * into the pending output buffer, in LIFO order, and using the | |
1738 | - * appropriate case for digits in the `A'..`F' range. | |
1739 | - */ | |
1740 | - *p++ = c > 9 ? (c - 10 + 'A') | (stream->flags & PFORMAT_XCASE) : c + '0'; | |
1737 | + if( (c > 0) || (p > buf) || (stream->precision >= 0) ) | |
1738 | + /* | |
1739 | + * Ignoring insignificant trailing zeros, (unless required to | |
1740 | + * satisfy specified precision), store the current encoded digit | |
1741 | + * into the pending output buffer, in LIFO order, and using the | |
1742 | + * appropriate case for digits in the `A'..`F' range. | |
1743 | + */ | |
1744 | + *p++ = c > 9 ? (c - 10 + 'A') | (stream->flags & PFORMAT_XCASE) : c + '0'; | |
1741 | 1745 | |
1742 | - /* Shift out the current digit, (4-bit logical shift right), | |
1743 | - * to align the next more significant digit to be extracted, | |
1744 | - * and encoded in the next pass. | |
1745 | - */ | |
1746 | - value.__pformat_fpreg_mantissa >>= 4; | |
1746 | + /* Shift out the current digit, (4-bit logical shift right), | |
1747 | + * to align the next more significant digit to be extracted, | |
1748 | + * and encoded in the next pass. | |
1749 | + */ | |
1750 | + value.__pformat_fpreg_mantissa >>= 4; | |
1751 | + } | |
1747 | 1752 | } |
1748 | 1753 | |
1749 | 1754 | if( p == buf ) |