Commit Graph

61 Commits

Author SHA1 Message Date
Sergey B Kirpichev cd11ff12ac
gh-119613: Use C99+ functions instead of Py_IS_NAN/INFINITY/FINITE (#119619) 2024-05-29 09:51:19 +02:00
Victor Stinner b298b395e8
gh-108765: Cleanup #include in Python/*.c files (#108977)
Mention one symbol imported by each #include.
2023-09-06 15:56:08 +02:00
Sebastian Berg 7a3b03509e
gh-104263: Rely on Py_NAN and introduce Py_INFINITY (GH-104202)
This PR removes `_Py_dg_stdnan` and `_Py_dg_infinity` in favour of
using the standard `NAN` and `INFINITY` macros provided by C99.
This change has the side-effect of fixing a bug on MIPS where the
hard-coded value used by `_Py_dg_stdnan` gave a signalling NaN
rather than a quiet NaN.
---------

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2023-05-10 17:44:52 +01:00
John Belmonte b0b836b20c
bpo-45995: add "z" format specifer to coerce negative 0 to zero (GH-30049)
Add "z" format specifier to coerce negative 0 to zero.

See https://github.com/python/cpython/issues/90153 (originally https://bugs.python.org/issue45995) for discussion.
This covers `str.format()` and f-strings.  Old-style string interpolation is not supported.

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2022-04-11 15:34:18 +01:00
Victor Stinner 1b2611eb02
bpo-46656: Remove Py_NO_NAN macro (GH-31160)
Building Python now requires support for floating point Not-a-Number
(NaN): remove the Py_NO_NAN macro.
2022-02-25 01:32:57 +01:00
Victor Stinner 9bbdde2180
bpo-45412: Add _PY_SHORT_FLOAT_REPR macro (GH-31171)
Remove the HAVE_PY_SET_53BIT_PRECISION macro (moved to the internal
C API).

* Move HAVE_PY_SET_53BIT_PRECISION macro to pycore_pymath.h.
* Replace PY_NO_SHORT_FLOAT_REPR macro with _PY_SHORT_FLOAT_REPR
  macro which is always defined. gcc -Wundef emits a warning when
  using _PY_SHORT_FLOAT_REPR but the macro is not defined, if
  pycore_pymath.h include was forgotten.
2022-02-23 18:16:23 +01:00
Victor Stinner 7103356455
bpo-45412: Move _Py_SET_53BIT_PRECISION_START to pycore_pymath.h (GH-28882)
Move the following macros , to pycore_pymath.h (internal C API):

* _Py_SET_53BIT_PRECISION_HEADER
* _Py_SET_53BIT_PRECISION_START
* _Py_SET_53BIT_PRECISION_END

PEP 7: add braces to if and "do { ... } while (0)" in these macros.

Move also _Py_get_387controlword() and _Py_set_387controlword()
definitions to pycore_pymath.h. These functions are no longer
exported.

pystrtod.c now includes pycore_pymath.h.
2021-10-11 23:09:40 +02:00
Victor Stinner 00d7abd7ef
bpo-42519: Replace PyMem_MALLOC() with PyMem_Malloc() (GH-23586)
No longer use deprecated aliases to functions:

* Replace PyMem_MALLOC() with PyMem_Malloc()
* Replace PyMem_REALLOC() with PyMem_Realloc()
* Replace PyMem_FREE() with PyMem_Free()
* Replace PyMem_Del() with PyMem_Free()
* Replace PyMem_DEL() with PyMem_Free()

Modify also the PyMem_DEL() macro to use directly PyMem_Free().
2020-12-01 09:56:42 +01:00
Victor Stinner e9e7d284c4
bpo-35081: Move dtoa.h header to the internal C API (GH-18489)
Move the dtoa.h header file to the internal C API as pycore_dtoa.h:
it only contains private functions (prefixed by "_Py").

The math and cmath modules must now be compiled with the
Py_BUILD_CORE macro defined.
2020-02-12 22:54:42 +01:00
Victor Stinner be143ec996
bpo-38835: Don't use PyFPE_START_PROTECT and PyFPE_END_PROTECT (GH-17231)
The PyFPE_START_PROTECT() and PyFPE_END_PROTECT() macros are empty:
they have been doing nothing for the last year  (since commit
735ae8d139), so stop using them.
2019-11-20 02:51:30 +01:00
Pedro Lacerda 4fa7504ee3 bpo-27268: Fix incorrect error message on float('') (GH-2745) 2019-05-17 18:32:44 -04:00
Zackery Spytz 4c49da0cb7 bpo-35436: Add missing PyErr_NoMemory() calls and other minor bug fixes. (GH-11015)
Set MemoryError when appropriate, add missing failure checks,
and fix some potential leaks.
2018-12-07 12:11:30 +02:00
Benjamin Peterson e502451781
closes bpo-34646: Remove PyAPI_* macros from declarations. (GH-9218) 2018-09-12 12:06:42 -07:00
INADA Naoki 16dfca4d82
bpo-34087: Fix buffer overflow in int(s) and similar functions (GH-8274)
`_PyUnicode_TransformDecimalAndSpaceToASCII()` missed trailing NUL char.
It caused buffer overflow in `_Py_string_to_number_with_underscores()`.

This bug is introduced in 9b6c60cb.
2018-07-14 12:06:43 +09:00
Siddhesh Poyarekar 9fb8415759 Drop confusing commented out code in pystrtod.c (GH-6072) 2018-03-11 17:45:10 +08:00
Siddhesh Poyarekar efd2bac156 Fix strncpy warning with gcc 8 (#5840)
The length in strncpy is one char too short and as a result it leads
to a build warning with gcc 8.  Comment out the strncpy since the
interpreter aborts immediately after anyway.
2018-03-06 18:34:35 +08:00
Serhiy Storchaka e2f92de6a9
Add the const qualifier to "char *" variables that refer to literal strings. (#4370) 2017-11-11 13:06:26 +02:00
Barry Warsaw b2e5794870 bpo-31338 (#3374)
* Add Py_UNREACHABLE() as an alias to abort().
* Use Py_UNREACHABLE() instead of assert(0)
* Convert more unreachable code to use Py_UNREACHABLE()
* Document Py_UNREACHABLE() and a few other macros.
2017-09-14 18:13:16 -07:00
Brett Cannon a721abac29 Issue #26331: Implement the parsing part of PEP 515.
Thanks to Georg Brandl for the patch.
2016-09-09 14:57:09 -07:00
Serhiy Storchaka 2d06e84455 Issue #25923: Added the const qualifier to static constant arrays. 2015-12-25 19:53:18 +02:00
Serhiy Storchaka 56a6d855e2 Removed duplicated words in in comments and docs. 2014-12-01 18:28:43 +02:00
Georg Brandl 6083a4bc1c Re #18521: remove assignments of variables that are immediately reassigned. 2013-10-14 06:51:46 +02:00
Victor Stinner 7b2513589f Issue #9566: pystrtod.c: Fix a compiler warnings on Windows x64 2013-06-24 23:37:40 +02:00
Mark Dickinson e383e82e04 Issue #14521: Make result of float('nan') and float('-nan') more consistent across platforms. Further, don't rely on Py_HUGE_VAL for float('inf'). 2012-04-29 15:31:56 +01:00
Brett Cannon b94767ff44 Issue #8914: fix various warnings from the Clang static analyzer v254. 2011-02-22 20:15:44 +00:00
Antoine Pitrou f95a1b3c53 Recorded merge of revisions 81029 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines

  Untabify C files. Will watch buildbots.
........
2010-05-09 15:52:27 +00:00
Eric Smith 68af50ba39 Issue #5988: Delete deprecated functions PyOS_ascii_formatd, PyOS_ascii_strtod, and PyOS_ascii_atof. 2010-02-22 14:58:30 +00:00
Mark Dickinson f41d29a8eb Merged revisions 77691,77698,77713-77714 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77691 | mark.dickinson | 2010-01-22 16:18:09 +0000 (Fri, 22 Jan 2010) | 1 line

  Correct typo in comment.
........
  r77698 | mark.dickinson | 2010-01-22 17:04:07 +0000 (Fri, 22 Jan 2010) | 3 lines

  Issue #7743:  Fix a potential incorrect rounding bug in dtoa.c (2nd bug
  in issue 7743).
........
  r77713 | mark.dickinson | 2010-01-23 20:48:56 +0000 (Sat, 23 Jan 2010) | 3 lines

  Issue #7743:  Add checks for zero inputs to the lshift and mult functions;
  this fixes the first bug described in issue #7743.
........
  r77714 | mark.dickinson | 2010-01-23 21:25:53 +0000 (Sat, 23 Jan 2010) | 1 line

  dtoa.c fix from upstream that fixes incorrectly rounded results for certain subnormals that are also halfway cases.
........
2010-01-24 10:16:29 +00:00
Mark Dickinson 3b38df24df Move some comments to more appropriate places 2009-10-26 14:36:29 +00:00
Mark Dickinson bd16edd305 Refactor to remove duplicated nan/inf parsing code in
pystrtod.c, floatobject.c and dtoa.c.
2009-05-20 22:05:25 +00:00
Eric Smith 63376228a3 Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson. 2009-05-05 14:04:18 +00:00
Mark Dickinson 129ab1d809 Merged revisions 72257 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r72257 | mark.dickinson | 2009-05-03 23:33:34 +0100 (Sun, 03 May 2009) | 2 lines

  Don't use PyOS_strnicmp for NaN and Inf detection: it's locale-aware.
........
2009-05-03 22:36:01 +00:00
Mark Dickinson 725bfd8489 Issue #5914: Add new C-API function PyOS_string_to_double, to complement
PyOS_double_to_string, and deprecate PyOS_ascii_strtod and PyOS_ascii_atof.
2009-05-03 20:33:40 +00:00
Mark Dickinson f489caf5da Issue #5859: Remove use of fixed-length buffers for float formatting
in unicodeobject.c and the fallback version of PyOS_double_to_string.
As a result, operations like '%.120e' % 12.34 no longer raise an
exception.
2009-05-01 11:42:00 +00:00
Mark Dickinson d3ca557150 Issue #5864: Fix problem with empty code formatting for floats,
where a bogus trailing zero could be added.
2009-04-29 18:47:07 +00:00
Eric Smith 6dc46f5eaa Merged revisions 72040 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r72040 | eric.smith | 2009-04-27 15:04:37 -0400 (Mon, 27 Apr 2009) | 1 line

  Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
........
2009-04-27 20:39:49 +00:00
Eric Smith cc32a11976 Issue #5835: Deprecate PyOS_ascii_formatd. 2009-04-26 21:35:14 +00:00
Mark Dickinson ce95e5646b Merged revisions 71976 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r71976 | mark.dickinson | 2009-04-26 20:54:55 +0100 (Sun, 26 Apr 2009) | 2 lines

  Fix typo in function name
........
2009-04-26 20:02:24 +00:00
Mark Dickinson 6d65df1e8a Internal plumbing changes for float parsing:
- check for nans and infs within PyOS_ascii_strtod
 - simplify parsing in PyFloat_FromString, and handle out-of-memory
   errors properly
2009-04-26 15:30:47 +00:00
Mark Dickinson ad476dab09 Issue #5816: Simplify code for parsing and printing of complex numbers.
nans and infs are no longer given special treatment; as a result,
repr(complex(z)) recovers z for any complex number z.
2009-04-23 19:14:16 +00:00
Mark Dickinson 3370cce4dd Issue 5780: Fix test_float failures for legacy style float repr. 2009-04-17 22:40:53 +00:00
Eric Smith 193125ad19 Simplify PyOS_double_to_string. 2009-04-16 22:08:31 +00:00
Eric Smith 0923d1d8d7 The other half of Issue #1580: use short float repr where possible.
Addresses the float -> string conversion, using David Gay's code which
was added in Mark Dickinson's checkin r71663.

Also addresses these, which are intertwined with the short repr
changes:

- Issue #5772: format(1e100, '<') produces '1e+100', not '1.0e+100'
- Issue #5515: 'n' formatting with commas no longer works poorly
    with leading zeros.
- PEP 378 Format Specifier for Thousands Separator: implemented
    for floats.
2009-04-16 20:16:10 +00:00
Eric Smith a3b1ac8dca Added ',' thousands grouping to int.__format__. See PEP 378.
This is incomplete, but I want to get some version into the next alpha. I am still working on:
Documentation.
More tests.
Implement for floats.

In addition, there's an existing bug with 'n' formatting that carries forward to thousands grouping (issue 5515).
2009-04-03 14:45:06 +00:00
Eric Smith 2ad79e82c8 Merged revisions 65125 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r65125 | eric.smith | 2008-07-18 20:24:05 -0400 (Fri, 18 Jul 2008) | 1 line

  Fix issue 3411: default float format spec fails on negative numbers.
........
2008-07-19 00:33:23 +00:00
Eric Smith 6d7e7a730e Merged revisions 64491 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r64491 | eric.smith | 2008-06-23 20:42:10 -0400 (Mon, 23 Jun 2008) | 1 line

  Modified interface to _Py_[String|Unicode]InsertThousandsGrouping, in anticipation of fixing issue 3140.
........
2008-06-24 01:06:47 +00:00
Christian Heimes 72b710a596 Renamed PyString to PyBytes 2008-05-26 13:28:38 +00:00
Eric Smith 5807c415c5 Merged revisions 63078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

When forward porting this, I added _PyUnicode_InsertThousandsGrouping.

........
  r63078 | eric.smith | 2008-05-11 15:52:48 -0400 (Sun, 11 May 2008) | 14 lines

  Addresses issue 2802: 'n' formatting for integers.

  Adds 'n' as a format specifier for integers, to mirror the same
  specifier which is already available for floats.  'n' is the same as
  'd', but inserts the current locale-specific thousands grouping.

  I added this as a stringlib function, but it's only used by str type,
  not unicode.  This is because of an implementation detail in
  unicode.format(), which does its own str->unicode conversion.  But the
  unicode version will be needed in 3.0, and it may be needed by other
  code eventually in 2.6 (maybe decimal?), so I left it as a stringlib
  implementation.  As long as the unicode version isn't instantiated,
  there's no overhead for this.
........
2008-05-11 21:00:57 +00:00
Eric Smith b2c7af8221 Merged revisions 62586 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r62586 | eric.smith | 2008-04-29 21:09:30 -0400 (Tue, 29 Apr 2008) | 5 lines

  Issue 2526, float.__format__ 'n' specifier does not support thousands grouping.

  Implemented grouping, with tests.
  Cleaned up PyOS_ascii_formatd by breaking reformatting into smaller functions.
........
2008-04-30 02:12:09 +00:00
Christian Heimes b186d0084c Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r61431 | vinay.sajip | 2008-03-16 22:35:58 +0100 (So, 16 Mär 2008) | 1 line

  Clarified documentation on use of shutdown().
........
  r61433 | mark.summerfield | 2008-03-17 09:28:15 +0100 (Mo, 17 Mär 2008) | 5 lines

  Added a footnote to each pointing out that for XML output if an encoding
  string is given it should conform to the appropriate XML standards---for
  example, "UTF-8" is okay, but "UTF8" is not.
........
  r61434 | eric.smith | 2008-03-17 12:01:01 +0100 (Mo, 17 Mär 2008) | 7 lines

  Issue 2264: empty float presentation type needs to have at least one digit past the decimal point.

  Added "Z" format_char to PyOS_ascii_formatd to support empty float presentation type.
  Renamed buf_size in PyOS_ascii_formatd to more accurately reflect it's meaning.
  Modified format.__float__ to use the new "Z" format as the default.
  Added test cases.
........
  r61435 | eric.smith | 2008-03-17 13:14:29 +0100 (Mo, 17 Mär 2008) | 2 lines

  Reformated lines > 79 chars.
  Deleted unused macro ISXDIGIT.
........
  r61436 | jeffrey.yasskin | 2008-03-17 15:40:53 +0100 (Mo, 17 Mär 2008) | 13 lines

  Allow Gnu gcc's to build python on OSX by removing -Wno-long-double,
  -no-cpp-precomp, and -mno-fused-madd from configure.
   * r22183 added -no-cpp-precomp, which
     http://gcc.gnu.org/ml/gcc/2005-12/msg00368.html claims hasn't been
     needed since gcc-3.1.
   * r25607 added -Wno-long-double to avoid a warning in
     Include/objimpl.h (issue 525481). The long double is still there,
     but OSX 10.4's gcc no longer warns about it.
   * r33666 fixed issue 775892 on OSX 10.3 by adding -mno-fused-madd,
     which changed the sign of some float 0s. Tim Peters said it wasn't
     a real issue anyway, and it no longer causes test failures.
  Fixes issue #1779871.
........
  r61439 | martin.v.loewis | 2008-03-17 17:31:57 +0100 (Mo, 17 Mär 2008) | 2 lines

  Add Trent Nelson.
........
  r61444 | travis.oliphant | 2008-03-17 18:36:12 +0100 (Mo, 17 Mär 2008) | 1 line

  Add necessary headers to back-port new buffer protocol to Python 2.6
........
  r61449 | gregory.p.smith | 2008-03-17 19:48:05 +0100 (Mo, 17 Mär 2008) | 8 lines

  Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
  regardless of the native sizeof(long) used in the integer object.

  This somewhat odd behavior of returning a signed is maintained in 2.x for
  compatibility reasons of always returning an integer rather than a long object.

  Fixes Issue1202 for Python 2.6
........
  r61450 | neal.norwitz | 2008-03-17 20:02:45 +0100 (Mo, 17 Mär 2008) | 3 lines

  Use a buffer large enough to ensure we don't overrun, even if the value
  is outside the range we expect.
........
  r61453 | steven.bethard | 2008-03-17 20:33:11 +0100 (Mo, 17 Mär 2008) | 1 line

  Document unicode.isnumeric() and unicode.isdecimal() (issue2326)
........
  r61458 | neal.norwitz | 2008-03-17 21:22:43 +0100 (Mo, 17 Mär 2008) | 5 lines

  Issue 2321: reduce memory usage (increase the memory that is returned
  to the system) by using pymalloc for the data of unicode objects.

  Will backport.
........
  r61465 | martin.v.loewis | 2008-03-17 22:55:30 +0100 (Mo, 17 Mär 2008) | 2 lines

  Add David Wolever.
........
  r61468 | gregory.p.smith | 2008-03-18 01:20:01 +0100 (Di, 18 Mär 2008) | 3 lines

  Fix the IOError message text when opening a file with an invalid filename.
  Error reported by Ilan Schnell.
........
  r61471 | brett.cannon | 2008-03-18 02:00:07 +0100 (Di, 18 Mär 2008) | 2 lines

  Convert test_strftime, test_getargs, and test_pep247 to use unittest.
........
  r61472 | jeffrey.yasskin | 2008-03-18 02:09:59 +0100 (Di, 18 Mär 2008) | 2 lines

  Fix build on platforms that don't have intptr_t. Patch by Joseph Armbruster.
........
  r61473 | brett.cannon | 2008-03-18 02:50:25 +0100 (Di, 18 Mär 2008) | 2 lines

  Convert test_dummy_threading and test_dbm to unittest.
........
  r61474 | brett.cannon | 2008-03-18 02:58:56 +0100 (Di, 18 Mär 2008) | 2 lines

  Move test_extcall to doctest.
........
  r61480 | brett.cannon | 2008-03-18 04:46:22 +0100 (Di, 18 Mär 2008) | 2 lines

  test_errno was a no-op test; now it actually tests things and uses unittest.
........
  r61483 | brett.cannon | 2008-03-18 05:09:00 +0100 (Di, 18 Mär 2008) | 3 lines

  Remove our implementation of memmove() and strerror(); both are in the C89
  standard library.
........
  r61484 | brett.cannon | 2008-03-18 05:16:06 +0100 (Di, 18 Mär 2008) | 2 lines

  The output directory for tests that compare against stdout is now gone!
........
  r61488 | jeffrey.yasskin | 2008-03-18 05:29:35 +0100 (Di, 18 Mär 2008) | 2 lines

  Block the "socket.ssl() is deprecated" warning from test_socket_ssl.
........
  r61495 | jeffrey.yasskin | 2008-03-18 05:56:06 +0100 (Di, 18 Mär 2008) | 4 lines

  Speed test_thread up from 51.328s to 0.081s by reducing its sleep times. We
  still sleep at all to make it likely that all threads are active at the same
  time.
........
  r61496 | jeffrey.yasskin | 2008-03-18 06:12:41 +0100 (Di, 18 Mär 2008) | 4 lines

  Speed up test_dict by about 10x by only checking selected dict literal sizes,
  instead of every integer from 0 to 400. Exhaustive testing wastes time without
  providing enough more assurance that the code is correct.
........
  r61498 | neal.norwitz | 2008-03-18 06:20:29 +0100 (Di, 18 Mär 2008) | 1 line

  Try increasing the timeout to reduce the flakiness of this test.
........
  r61503 | brett.cannon | 2008-03-18 06:43:04 +0100 (Di, 18 Mär 2008) | 2 lines

  Improve the error message for a test that failed on the S-390 Debian buildbot.
........
  r61504 | jeffrey.yasskin | 2008-03-18 06:45:40 +0100 (Di, 18 Mär 2008) | 3 lines

  Add a -S/--slow flag to regrtest to have it print the 10 slowest tests with
  their times.
........
  r61507 | neal.norwitz | 2008-03-18 07:03:46 +0100 (Di, 18 Mär 2008) | 1 line

  Add some info to the failure messages
........
  r61509 | trent.nelson | 2008-03-18 08:02:12 +0100 (Di, 18 Mär 2008) | 1 line

  Issue 2286: bump up the stack size of the 64-bit debug python_d.exe to 2100000.  The default value of 200000 causes a stack overflow at 1965 iterations of r_object() in marshal.c, 35 iterations before the 2000 limit enforced by MAX_MARSHAL_STACK_DEPTH.
........
  r61510 | trent.nelson | 2008-03-18 08:32:47 +0100 (Di, 18 Mär 2008) | 5 lines

  The behaviour of winsound.Beep() seems to differ between different versions of Windows when there's either:
      a) no sound card entirely
      b) legacy beep driver has been disabled
      c) the legacy beep driver has been uninstalled
  Sometimes RuntimeErrors are raised, sometimes they're not.  If _have_soundcard() returns False, don't expect winsound.Beep() to raise a RuntimeError, as this clearly isn't the case, as demonstrated by the various Win32 XP buildbots.
........
  r61515 | martin.v.loewis | 2008-03-18 13:20:15 +0100 (Di, 18 Mär 2008) | 2 lines

  norwitz-amd64 (gentoo) has EREMOTEIO.
........
  r61516 | martin.v.loewis | 2008-03-18 13:45:37 +0100 (Di, 18 Mär 2008) | 2 lines

  Add more Linux error codes.
........
  r61517 | martin.v.loewis | 2008-03-18 14:05:03 +0100 (Di, 18 Mär 2008) | 2 lines

  Add WSA errors.
........
  r61518 | martin.v.loewis | 2008-03-18 14:16:05 +0100 (Di, 18 Mär 2008) | 2 lines

  Note that the stderr output of the test is intentional.
........
2008-03-18 15:15:01 +00:00