Commit Graph

167 Commits

Author SHA1 Message Date
Serhiy Storchaka 9b6c60cbce
bpo-31979: Simplify transforming decimals to ASCII (#4336)
in int(), float() and complex() parsers.

This also speeds up parsing non-ASCII numbers by around 20%.
2017-11-13 21:23:48 +02: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
Serhiy Storchaka bae6881b42 Update Argument Clinic generated code for bpo-29878. (#1001) 2017-04-05 12:00:42 +03:00
Serhiy Storchaka ba85d69a3e bpo-29878: Add global instances of int for 0 and 1. (#852) 2017-03-30 09:09:41 +03:00
Serhiy Storchaka 671079ef60 bpo-29894: Deprecate returning an instance of complex subclass from __complex__. (#798)
In a future versions of Python this can be an error.
2017-03-24 21:28:43 +02:00
Serhiy Storchaka 18b250f844 bpo-29793: Convert some builtin types constructors to Argument Clinic. (#615) 2017-03-19 08:51:07 +02:00
Mark Dickinson 112ec38c15 bpo-29602: fix signed zero handling in complex constructor. (#203)
* Fix incorrect handling of signed zeros for complex-related classes.

* Add Misc/NEWS entry.
2017-02-20 20:28:15 +00:00
Victor Stinner f17c3de263 Use _PyObject_CallNoArg()
Replace:
    PyObject_CallFunctionObjArgs(callable, NULL)
with:
    _PyObject_CallNoArg(callable)
2016-12-06 18:46:19 +01:00
Victor Stinner de4ae3d486 Backed out changeset b9c9691c72c5
Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like
_PyObject_CallArg1() uses more stack memory than
PyObject_CallFunctionObjArgs().
2016-12-04 22:59:09 +01:00
Victor Stinner 27580c1fb5 Replace PyObject_CallFunctionObjArgs() with fastcall
* PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func)
* PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg)

PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires
extra work to "parse" C arguments to build a C array of PyObject*.

_PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate
memory on the C stack.

This change is part of the fastcall project. The change on listsort() is
related to the issue #23507.
2016-12-01 14:43:22 +01:00
Mark Dickinson 6997946ec4 Issue #28203: Merge from 3.5 2016-09-24 15:28:34 +01:00
Mark Dickinson 613f8e513c Issue #28203: Fix incorrect type in error message from complex(1.0, {2:3}). Patch by Soumya Sharma. 2016-09-24 15:26:36 +01: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
Martin Panter 61d6e4ae9d Issue #24802: Merge null termination fixes from 3.4 into 3.5 2015-11-07 02:56:11 +00:00
Martin Panter eeb896c411 Issue #24802: Copy bytes-like objects to null-terminated buffers if necessary
This avoids possible buffer overreads when int(), float(), compile(), exec()
and eval() are passed bytes-like objects. Similar code is removed from the
complex() constructor, where it was not reachable.

Patch by John Leitch, Serhiy Storchaka and Martin Panter.
2015-11-07 02:32:21 +00:00
Serhiy Storchaka 3dd3e26680 Issue #22896: Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer()
and PyObject_AsWriteBuffer().
2015-02-03 01:25:42 +02:00
Serhiy Storchaka 4fdb68491e Issue #22896: Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer()
and PyObject_AsWriteBuffer().
2015-02-03 01:21:08 +02:00
Antoine Pitrou 759920c5cb Issue #22604: Fix assertion error in debug mode when dividing a complex number by (nan+0j). 2014-10-10 23:51:04 +02:00
Antoine Pitrou 9086f9260f Issue #22604: Fix assertion error in debug mode when dividing a complex number by (nan+0j). 2014-10-10 23:49:32 +02:00
Antoine Pitrou 1eee8e5207 Issue #21803: remove macro indirections in complexobject.h 2014-07-07 18:49:30 -04:00
Christian Heimes d3afe781b1 Silence expression result unused warnings with clang.
The PyObject_INIT() macros returns obj:

../cpython/Objects/methodobject.c:32:23: warning: expression result unused [-Wunused-value]
        PyObject_INIT(op, &PyCFunction_Type);
                      ^~
../cpython/Include/objimpl.h:139:69: note: expanded from macro 'PyObject_INIT'
    ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
                                                                    ^
1 warning generated.
2013-12-04 09:27:47 +01:00
Ezio Melotti a5b9599538 #17080: improve error message of float/complex when the wrong type is passed. 2013-11-07 19:18:34 +02:00
Ezio Melotti c1ae254717 #19068: merge with 3.3. 2013-10-06 00:39:44 +03:00
Ezio Melotti 488d244e1a #19068: use imperative mood in complex object docstrings. Patch by Marco Buttu. 2013-10-06 00:39:18 +03:00
Antoine Pitrou 9ed5f27266 Issue #18722: Remove uses of the "register" keyword in C code. 2013-08-13 20:18:52 +02:00
Victor Stinner 8f674ccd64 Close #17694: Add minimum length to _PyUnicodeWriter
* Add also min_char attribute to _PyUnicodeWriter structure (currently unused)
 * _PyUnicodeWriter_Init() has no more argument (except the writer itself):
   min_length and overallocate must be set explicitly
 * In error handlers, only enable overallocation if the replacement string
   is longer than 1 character
 * CJK decoders don't use overallocation anymore
 * Set min_length, instead of preallocating memory using
   _PyUnicodeWriter_Prepare(), in many decoders
 * _PyUnicode_DecodeUnicodeInternal() checks for integer overflow
2013-04-17 23:02:17 +02:00
Mark Dickinson d20fb82195 Issue #16290: __complex__ must now always return an instance of complex. 2012-11-14 17:08:31 +00:00
Victor Stinner d3f0882dfb Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
* Formatting string, int, float and complex use the _PyUnicodeWriter API. It
   avoids a temporary buffer in most cases.
 * Add _PyUnicodeWriter_WriteStr() to restore the PyAccu optimization: just
   keep a reference to the string if the output is only composed of one string
 * Disable overallocation when formatting the last argument of str%args and
   str.format(args)
 * Overallocation allocates at least 100 characters: add min_length attribute
   to the _PyUnicodeWriter structure
 * Add new private functions: _PyUnicode_FastCopyCharacters(),
   _PyUnicode_FastFill() and _PyUnicode_FromASCII()

The speed up is around 20% in average.
2012-05-29 12:57:52 +02:00
Benjamin Peterson ce79852077 use the static identifier api for looking up special methods
I had to move the static identifier code from unicodeobject.h to object.h in
order for this to work.
2012-01-22 11:24:29 -05:00
Martin v. Löwis d63a3b8beb Implement PEP 393. 2011-09-28 07:41:54 +02:00
Brian Curtin dfc80e3d97 Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.
The macro was introduced in #12724.
2011-08-10 20:28:54 -05:00
Victor Stinner 6ced7c4333 Issue #10833: Use PyErr_Format() and PyUnicode_FromFormat() instead of
PyOS_snprintf() to avoid temporary buffer allocated on the stack and a
conversion from bytes to Unicode.
2011-03-21 18:15:42 +01:00
Eric Smith 70099a1555 Removed static function complex_format, moved it into complex_repr. Modified tests to check both str and repr, which are the same for complex. 2010-12-04 13:27:34 +00:00
Alexander Belopolsky 942af5a9a4 Issue #10557: Fixed error messages from float() and other numeric
types.  Added a new API function, PyUnicode_TransformDecimalToASCII(),
which transforms non-ASCII decimal digits in a Unicode string to their
ASCII equivalents.
2010-12-04 03:38:46 +00:00
Victor Stinner f961377e99 #6780: fix complex() constructor TypeError message 2010-12-03 16:51:33 +00:00
Benjamin Peterson 8035bc5c04 follow up to #9778: define and use an unsigned hash type 2010-10-23 16:20:50 +00:00
Benjamin Peterson 8f67d0893f make hashes always the size of pointers; introduce Py_hash_t #9778 2010-10-17 20:54:53 +00:00
Mark Dickinson 388122d43b Issue #9337: Make float.__str__ identical to float.__repr__.
(And similarly for complex numbers.)
2010-08-04 20:56:28 +00:00
Mark Dickinson dc787d2055 Issue #8188: Introduce a new scheme for computing hashes of numbers
(instances of int, float, complex, decimal.Decimal and
fractions.Fraction) that makes it easy to maintain the invariant that
hash(x) == hash(y) whenever x and y have equal value.
2010-05-23 13:33:13 +00:00
Mark Dickinson cc6a982de8 Issue #8748: Fix two issues with comparisons between complex and integer
objects.  (1) The comparison could incorrectly return True in some cases
(2**53+1 == complex(2**53) == 2**53), breaking transivity of equality.
(2) The comparison raised an OverflowError for large integers, leading
to unpredictable exceptions when combining integers and complex objects
in sets or dicts.

Patch by Meador Inge.
2010-05-21 14:55:26 +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
Mark Dickinson f673f0c40c Issue #7845: Make 1j.__le__(2j) return NotImplemented rather than raising TypeError. 2010-03-13 09:48:39 +00:00
Ezio Melotti 50363262b2 Merged revisions 78319 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78319 | ezio.melotti | 2010-02-22 18:30:58 +0200 (Mon, 22 Feb 2010) | 1 line

  #7482: clarify error message in case of division by zero of float and complex numbers.
........
2010-02-22 16:34:50 +00:00
Benjamin Peterson aea4428fdc Merged revisions 77292-77293 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77292 | benjamin.peterson | 2010-01-03 18:43:01 -0600 (Sun, 03 Jan 2010) | 1 line

  do correct lookup of the __complex__ method
........
  r77293 | benjamin.peterson | 2010-01-03 19:00:47 -0600 (Sun, 03 Jan 2010) | 1 line

  factor out __complex__ lookup code to fix another case
........
2010-01-04 01:10:28 +00:00
Mark Dickinson a4962cb694 Merged revisions 76561 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r76561 | mark.dickinson | 2009-11-28 12:30:36 +0000 (Sat, 28 Nov 2009) | 5 lines

  Include ieeefp.h (when available) in pyport.h instead of individually in
  Objects/floatobject.c and Objects/complexobject.c.  This should silence
  compiler warnings about implicit declaration of the 'finite' function
  on Solaris.
........
2009-11-28 12:35:42 +00:00
Mark Dickinson 1daebdf82c Make sure memory is freed on error in complex_subtype_from_string. 2009-10-26 22:05:06 +00:00
Mark Dickinson f972488213 Remove length limitation on string arguments to complex() 2009-10-26 21:51:18 +00:00
Skip Montanaro ba1e0f46ab Issue 7147 - remove ability to attempt to build Python without complex number support (was broken anyway) 2009-10-18 14:25:35 +00:00
Mark Dickinson 6b1e43b7bc Issue #5829: complex('1e500') shouldn't raise OverflowError 2009-05-20 18:41:04 +00:00
Mark Dickinson 578cc749ab Merged revisions 72718 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r72718 | mark.dickinson | 2009-05-17 11:38:30 +0100 (Sun, 17 May 2009) | 4 lines

  Issue #6044: remove confusing wording from complex -> integer and
  complex -> float conversion error messages.
........
2009-05-17 10:40:10 +00:00