Commit Graph

2538 Commits

Author SHA1 Message Date
Serhiy Storchaka a84f6c3dd3 Issue #25523: Merge a-to-an corrections from 3.4. 2015-11-02 14:39:05 +02:00
Serhiy Storchaka d65c9496da Issue #25523: Further a-to-an corrections. 2015-11-02 14:10:23 +02:00
Martin Panter e56a919100 Issue #25523: Merge a-to-an corrections from 3.5 2015-11-02 04:27:17 +00:00
Martin Panter 2eb819f7a8 Issue #25523: Merge "a" to "an" fixes from 3.4 into 3.5 2015-11-02 04:04:57 +00:00
Martin Panter 7462b64911 Issue #25523: Correct "a" article to "an" article
This changes the main documentation, doc strings, source code comments, and a
couple error messages in the test suite. In some cases the word was removed
or edited some other way to fix the grammar.
2015-11-02 03:37:02 +00:00
Victor Stinner c5c3ba4bec Add _PyBytesWriter_Resize() function
This function gives a control to the buffer size without using min_size.
2015-10-14 13:56:47 +02:00
Victor Stinner 2ec8063cc9 Modify _PyBytes_DecodeEscapeRecode() to use _PyBytesAPI
* Don't overallocate by 400% when recode is needed: only overallocate on demand
  using _PyBytesWriter.
* Use _PyLong_DigitValue to convert hexadecimal digit to int
* Create _PyBytes_DecodeEscapeRecode() subfunction
2015-10-14 13:32:13 +02:00
Victor Stinner 2bf8993db9 Optimize bytes.fromhex() and bytearray.fromhex()
Issue #25401: Optimize bytes.fromhex() and bytearray.fromhex(): they are now
between 2x and 3.5x faster. Changes:

* Use a fast-path working on a char* string for ASCII string
* Use a slow-path for non-ASCII string
* Replace slow hex_digit_to_int() function with a O(1) lookup in
  _PyLong_DigitValue precomputed table
* Use _PyBytesWriter API to handle the buffer
* Add unit tests to check the error position in error messages
2015-10-14 11:25:33 +02:00
Victor Stinner 772b2b09f2 Optimize bytearray % args
Issue #25399: Don't create temporary bytes objects: modify _PyBytes_Format() to
create work directly on bytearray objects.

* Rename _PyBytes_Format() to _PyBytes_FormatEx() just in case if something
  outside CPython uses it
* _PyBytes_FormatEx() now uses (char*, Py_ssize_t) for the input string, so
  bytearray_format() doesn't need tot create a temporary input bytes object
* Add use_bytearray parameter to _PyBytes_FormatEx() which is passed to
  _PyBytesWriter, to create a bytearray buffer instead of a bytes buffer

Most formatting operations are now between 2.5 and 5 times faster.
2015-10-14 09:56:53 +02:00
Victor Stinner 661aaccf9d Add use_bytearray attribute to _PyBytesWriter
Issue #25399: Add a new use_bytearray attribute to _PyBytesWriter to use a
bytearray buffer, instead of using a bytes object.
2015-10-14 09:41:48 +02:00
Victor Stinner f7d2471260 Merge 3.5 (sys.setrecursionlimit) 2015-10-13 00:16:07 +02:00
Victor Stinner 50856d5ae7 sys.setrecursionlimit() now raises RecursionError
Issue #25274: sys.setrecursionlimit() now raises a RecursionError if the new
recursion limit is too low depending at the current recursion depth. Modify
also the "lower-water mark" formula to make it monotonic. This mark is used to
decide when the overflowed flag of the thread state is reset.
2015-10-13 00:11:21 +02:00
Victor Stinner c29e29bed1 Relax _PyBytesWriter API
Don't require _PyBytesWriter pointer to be a "char *". Same change for
_PyBytesWriter_WriteBytes() parameter.

For example, binascii uses "unsigned char*".
2015-10-12 13:12:54 +02:00
Victor Stinner be75b8cf23 Issue #25349: Optimize bytes % int
Optimize bytes.__mod__(args) for integere formats: %d (%i, %u), %o, %x and %X.
_PyBytesWriter is now used to format directly the integer into the writer
buffer, instead of using a temporary bytes object.

Formatting is between 30% and 50% faster on a microbenchmark.
2015-10-09 22:43:24 +02:00
Victor Stinner ce179bf6ba Add _PyBytesWriter_WriteBytes() to factorize the code 2015-10-09 12:57:22 +02:00
Victor Stinner 53926a1ce2 _PyBytesWriter: rename size attribute to min_size 2015-10-09 12:37:03 +02:00
Victor Stinner b3653a3458 Issue #25318: cleanup code _PyBytesWriter
Rename "stack buffer" to "small buffer".

Add also an assertion in _PyBytesWriter_GetPos().
2015-10-09 03:38:24 +02:00
Victor Stinner 0016507c16 Issue #25318: Move _PyBytesWriter to bytesobject.c
Declare also the private API in bytesobject.h.
2015-10-09 01:53:21 +02:00
Victor Stinner fdfbf78114 Issue #25318: Add _PyBytesWriter API
Add a new private API to optimize Unicode encoders. It uses a small buffer
allocated on the stack and supports overallocation.

Use _PyBytesWriter API for UCS1 (ASCII and Latin1) and UTF-8 encoders. Enable
overallocation for the UTF-8 encoder with error handlers.

unicode_encode_ucs1(): initialize collend to collstart+1 to not check the
current character twice, we already know that it is not ASCII.
2015-10-09 00:33:49 +02:00
Serhiy Storchaka 5dbe245ef2 Issue #24483: C implementation of functools.lru_cache() now calculates key's
hash only once.
2015-10-02 12:47:59 +03:00
Serhiy Storchaka b9d98d532c Issue #24483: C implementation of functools.lru_cache() now calculates key's
hash only once.
2015-10-02 12:47:11 +03:00
Victor Stinner ca9381ea01 Issue #24870: Add _PyUnicodeWriter_PrepareKind() macro
Add a macro which ensures that the writer has at least the requested kind.
2015-09-22 00:58:32 +02:00
Eric V. Smith 235a6f0984 Issue #24965: Implement PEP 498 "Literal String Interpolation". Documentation is still needed, I'll open an issue for that. 2015-09-19 14:51:32 -04:00
Victor Stinner 258f17c96d Merge 3.5 2015-09-18 15:08:14 +02:00
Victor Stinner 6df29ada02 Issue #25150: Hide the private _Py_atomic_xxx symbols from the public
Python.h header to fix a compilation error with OpenMP. PyThreadState_GET()
becomes an alias to PyThreadState_Get() to avoid ABI incompatibilies.

It is important that the _PyThreadState_Current variable is always accessed
with the same implementation of pyatomic.h. Use the PyThreadState_Get()
function so extension modules will all reuse the same implementation.
2015-09-18 15:06:34 +02:00
Victor Stinner 9a8b177e60 Issue #25155: Add _PyTime_AsTimevalTime_t() function
On Windows, the tv_sec field of the timeval structure has the type C long,
whereas it has the type C time_t on all other platforms. A C long has a size of
32 bits (signed inter, 1 bit for the sign, 31 bits for the value) which is not
enough to store an Epoch timestamp after the year 2038.

Add the _PyTime_AsTimevalTime_t() function written for datetime.datetime.now():
convert a _PyTime_t timestamp to a (secs, us) tuple where secs type is time_t.
It allows to support dates after the year 2038 on Windows.

Enhance also _PyTime_AsTimeval_impl() to detect overflow on the number of
seconds when rounding the number of microseconds.
2015-09-18 13:36:17 +02:00
Victor Stinner 1e2b6882fc Issue #25155: Add _PyTime_AsTimevalTime_t() function
On Windows, the tv_sec field of the timeval structure has the type C long,
whereas it has the type C time_t on all other platforms. A C long has a size of
32 bits (signed inter, 1 bit for the sign, 31 bits for the value) which is not
enough to store an Epoch timestamp after the year 2038.

Add the _PyTime_AsTimevalTime_t() function written for datetime.datetime.now():
convert a _PyTime_t timestamp to a (secs, us) tuple where secs type is time_t.
It allows to support dates after the year 2038 on Windows.

Enhance also _PyTime_AsTimeval_impl() to detect overflow on the number of
seconds when rounding the number of microseconds.
2015-09-18 13:23:02 +02:00
Larry Hastings 9c51f89cd6 Merge release engineering work from Python 3.5.0. 2015-09-13 15:43:21 +01:00
Larry Hastings 82c0c69011 Post-release updates for Python 3.5.0. 2015-09-13 15:36:07 +01:00
Larry Hastings f92f6c8e56 Version bump for Python 3.5.0 final. 2015-09-12 17:28:39 +01:00
Victor Stinner ce6aa749b4 Make _PyTime_RoundHalfEven() private again 2015-09-09 22:28:09 +02:00
Larry Hastings ded28e3863 Merge Python 3.5.0rc4 back to hg.python.org. 2015-09-09 06:52:38 -07:00
Larry Hastings 03728fac15 Post-release update for Python 3.5.0rc4. 2015-09-09 06:45:19 -07:00
Larry Hastings 1043f95b9b Version bump for Python 3.5.0rc4. 2015-09-08 23:58:10 -07:00
Victor Stinner 7667f58151 Issue #23517: fromtimestamp() and utcfromtimestamp() methods of
datetime.datetime now round microseconds to nearest with ties going to nearest
even integer (ROUND_HALF_EVEN), as round(float), instead of rounding towards
-Infinity (ROUND_FLOOR).

pytime API: replace _PyTime_ROUND_HALF_UP with _PyTime_ROUND_HALF_EVEN. Fix
also _PyTime_Divide() for negative numbers.

_PyTime_AsTimeval_impl() now reuses _PyTime_Divide() instead of reimplementing
rounding modes.
2015-09-09 01:02:23 +02:00
Larry Hastings c8c47f55e6 Merge heads. 2015-09-07 05:16:38 -07:00
Larry Hastings 442c560bd8 Version bump for Python 3.5.0rc3. 2015-09-07 05:12:05 -07:00
Victor Stinner 2ec558739e Issue #23517: datetime.timedelta constructor now rounds microseconds to nearest
with ties going away from zero (ROUND_HALF_UP), as Python 2 and Python older
than 3.3, instead of rounding to nearest with ties going to nearest even
integer (ROUND_HALF_EVEN).
2015-09-02 19:16:07 +02:00
Victor Stinner 744742320f Issue #23517: Add "half up" rounding mode to the _PyTime API 2015-09-02 01:43:56 +02:00
Yury Selivanov 7f344a89ef Merge 3.5 2015-08-26 13:04:06 -04:00
Yury Selivanov beaa5094a2 docs: Better comment for tp_as_async slot 2015-08-26 13:03:57 -04:00
Larry Hastings a51812ae98 Post-release updates for Python 3.5.0rc2. 2015-08-25 13:30:58 -07:00
Larry Hastings e6c6f69ac9 Version bump for Python 3.5.0rc2. 2015-08-24 20:31:53 -07:00
R David Murray 803502c56b #21167: Fix definition of NAN when ICC used without -fp-model strict.
Patch from Chris Hogan of Intel, reviewed by Mark Dickinson.
2015-08-15 18:33:45 -04:00
R David Murray 587748e271 Merge: #21167: Fix definition of NAN when ICC used without -fp-model strict. 2015-08-13 10:07:54 -04:00
R David Murray c77088d055 Merge: #21167: Fix definition of NAN when ICC used without -fp-model strict. 2015-08-13 10:04:21 -04:00
R David Murray edbc28ce81 #21167: Fix definition of NAN when ICC used without -fp-model strict.
Patch from Chris Hogan of Intel, reviewed by Mark Dickinson.
2015-08-13 09:58:07 -04:00
Larry Hastings 2ab6ddb19d Post-release bump for Python 3.5.0rc1. 2015-08-10 18:03:52 -07:00
Larry Hastings 71ea65feed Release bump for Python 3.5.0rc1. 2015-08-09 03:41:04 -07:00
Raymond Hettinger 9344bd828c Clarify comments on setentry invariants. 2015-08-01 15:21:41 -07:00
Larry Hastings 3d1dc904f4 Post-release updates for Python 3.5.0b4. 2015-07-26 07:55:08 -07:00
Larry Hastings 164df4e51a Version bump for Python 3.5.0b4. 2015-07-25 14:22:13 -07:00
Larry Hastings b34db6ad9b Post-release fixes for Python 3.5.0b3. 2015-07-05 10:26:00 -07:00
Larry Hastings 9626971c74 Version bump for Python 3.5.0b3 release. 2015-07-04 19:13:02 -07:00
Raymond Hettinger ac2ef65c32 Make the unicode equality test an external function rather than in-lining it.
The real benefit of the unicode specialized function comes from
bypassing the overhead of PyObject_RichCompareBool() and not
from being in-lined (especially since there was almost no shared
data between the caller and callee).  Also, the in-lining was
having a negative effect on code generation for the callee.
2015-07-04 16:04:44 -07:00
Yury Selivanov bb215e2300 Merge 3.5 (Issue #19235) 2015-07-03 01:10:11 -04:00
Yury Selivanov f488fb422a Issue #19235: Add new RecursionError exception. Patch by Georg Brandl. 2015-07-03 01:04:23 -04:00
Yury Selivanov 6edc2f7549 Issue #24400: Merge 3.5 2015-06-22 12:31:24 -04:00
Yury Selivanov 5376ba9630 Issue #24400: Introduce a distinct type for 'async def' coroutines.
Summary of changes:

1. Coroutines now have a distinct, separate from generators
   type at the C level: PyGen_Type, and a new typedef PyCoroObject.
   PyCoroObject shares the initial segment of struct layout with
   PyGenObject, making it possible to reuse existing generators
   machinery.  The new type is exposed as 'types.CoroutineType'.

   As a consequence of having a new type, CO_GENERATOR flag is
   no longer applied to coroutines.

2. Having a separate type for coroutines made it possible to add
   an __await__ method to the type.  Although it is not used by the
   interpreter (see details on that below), it makes coroutines
   naturally (without using __instancecheck__) conform to
   collections.abc.Coroutine and collections.abc.Awaitable ABCs.

   [The __instancecheck__ is still used for generator-based
   coroutines, as we don't want to add __await__ for generators.]

3. Add new opcode: GET_YIELD_FROM_ITER.  The opcode is needed to
   allow passing native coroutines to the YIELD_FROM opcode.

   Before this change, 'yield from o' expression was compiled to:

      (o)
      GET_ITER
      LOAD_CONST
      YIELD_FROM

   Now, we use GET_YIELD_FROM_ITER instead of GET_ITER.

   The reason for adding a new opcode is that GET_ITER is used
   in some contexts (such as 'for .. in' loops) where passing
   a coroutine object is invalid.

4. Add two new introspection functions to the inspec module:
   getcoroutinestate(c) and getcoroutinelocals(c).

5. inspect.iscoroutine(o) is updated to test if 'o' is a native
   coroutine object.  Before this commit it used abc.Coroutine,
   and it was requested to update inspect.isgenerator(o) to use
   abc.Generator; it was decided, however, that inspect functions
   should really be tailored for checking for native types.

6. sys.set_coroutine_wrapper(w) API is updated to work with only
   native coroutines.  Since types.coroutine decorator supports
   any type of callables now, it would be confusing that it does
   not work for all types of coroutines.

7. Exceptions logic in generators C implementation was updated
   to raise clearer messages for coroutines:

   Before: TypeError("generator raised StopIteration")
   After: TypeError("coroutine raised StopIteration")
2015-06-22 12:19:30 -04:00
Serhiy Storchaka dcbff7d4e1 Added the const qualifier for char* argument of Py_EnterRecursiveCall(). 2015-06-21 16:27:36 +03:00
Serhiy Storchaka 289dd19124 Added the const qualifier for char* argument of Py_EnterRecursiveCall(). 2015-06-21 16:27:09 +03:00
Serhiy Storchaka 5fa22fc088 Added the const qualifier for char* argument of Py_EnterRecursiveCall(). 2015-06-21 16:26:28 +03:00
Serhiy Storchaka 86621ae19b Issue #24436: Added const qualifiers for char* arguments of _PyTraceback_Add.
Patch by Michael Ensslin.
2015-06-21 16:00:58 +03:00
Serhiy Storchaka ccfdf0923a Issue #24436: Added const qualifiers for char* arguments of _PyTraceback_Add.
Patch by Michael Ensslin.
2015-06-21 16:00:33 +03:00
Serhiy Storchaka 73c95f1949 Issue #24436: Added const qualifiers for char* arguments of _PyTraceback_Add.
Patch by Michael Ensslin.
2015-06-21 15:59:46 +03:00
Yury Selivanov a641def110 Issue 24342: No need to use PyAPI_FUNC for _PyEval_ApplyCoroutineWrapper
(Merge 3.5)
2015-06-02 22:30:51 -04:00
Yury Selivanov eb698fe68c Issue 24342: No need to use PyAPI_FUNC for _PyEval_ApplyCoroutineWrapper 2015-06-02 22:30:31 -04:00
Yury Selivanov 47d5e15e50 Issue 24365: Merge 3.5 2015-06-02 19:07:17 -04:00
Yury Selivanov ca82910221 Issue 24365: Conditionalize PEP 489 additions to the stable ABI
Patch by Petr Viktorin.
2015-06-02 19:06:47 -04:00
Yury Selivanov 082332ce37 Issue 24342: Let wrapper set by sys.set_coroutine_wrapper fail gracefully
(Merge 3.5)
2015-06-02 18:45:11 -04:00
Yury Selivanov aab3c4a211 Issue 24342: Let wrapper set by sys.set_coroutine_wrapper fail gracefully 2015-06-02 18:43:51 -04:00
Eric Snow c976b73002 Merge from 3.5. 2015-06-01 23:06:20 -06:00
Eric Snow a762af74b2 Issue #24347: Set KeyError if PyDict_GetItemWithError returns NULL. 2015-06-01 22:59:08 -06:00
Yury Selivanov 1b12c554e5 Issue 24017: Make PyEval_(Set|Get)CoroutineWrapper private 2015-06-01 12:15:47 -04:00
Yury Selivanov d8cf382ee7 Issue 24017: Make PyEval_(Set|Get)CoroutineWrapper private 2015-06-01 12:15:23 -04:00
Benjamin Peterson cae0658f09 merge 3.5 (#24345) 2015-06-01 10:14:35 -05:00
Benjamin Peterson 0969a9f8ab add Py_tp_finalize slot (closes #24345)
Patch from Petr Viktorin.
2015-06-01 10:12:48 -05:00
Larry Hastings 61eb146b22 Post-release updates for Python 3.5.0b2. 2015-05-31 21:42:35 -07:00
Larry Hastings d200e0c072 Version bump for Python 3.5.0b2. 2015-05-30 17:00:48 -07:00
Eric Snow 1edcb2242b Merge from 3.5. 2015-05-30 12:06:26 -06:00
Eric Snow d0a06455a5 Issue #16991: Drop Py_ODict_GetItemId. 2015-05-30 12:06:03 -06:00
Eric Snow 6e15fdfdec Merge from 3.5. 2015-05-30 09:34:28 -06:00
Eric Snow 8c7ed012b8 Issue #16991: Use PyObject_TypeCheck instead of PyObject_IsInstance. 2015-05-30 09:29:53 -06:00
Yury Selivanov 7aa5341164 Reverting my previous commit.
Something went horribly wrong when I was doing `hg rebase`.
2015-05-30 10:57:56 -04:00
Eric Snow 47db71756d Issue #16991: Add a C implementation of collections.OrderedDict. 2015-05-29 22:21:39 -06:00
Benjamin Peterson 0938d98bcc merge 3.5 2015-05-28 14:40:15 -05:00
Benjamin Peterson 264be6f48f remove STORE_MAP, since it's unused 2015-05-28 14:40:08 -05:00
Yury Selivanov ac0bffb962 Issue 24017: Drop getawaitablefunc and friends in favor of unaryfunc. 2015-05-28 11:22:41 -04:00
Yury Selivanov 6ef059097c Issue 24017: Drop getawaitablefunc and friends in favor of unaryfunc. 2015-05-28 11:21:31 -04:00
Serhiy Storchaka e998aad7b3 Issue #24288: Generated opcode.h no longer contains trailing spaces and tabs. 2015-05-27 21:31:50 +03:00
Serhiy Storchaka 3028c955fa Issue #24288: Generated opcode.h no longer contains trailing spaces and tabs. 2015-05-27 21:31:33 +03:00
Larry Hastings d0c2a20b24 Version bump for trunk to 3.6.0a0. Welcome to the future! 2015-05-25 16:49:01 -07:00
Larry Hastings f46aa8e2d1 Post-release fixes for 3.5.0b1. 2015-05-24 16:40:45 -07:00
Larry Hastings 205acde55e Version bump for 3.5.0b1. 2015-05-23 17:43:05 -07:00
Steve Dower 11d7b1423f Issue #24268: Adds PyModuleDef_Init and PyModuleDef_Type to python3.def (stable ABI) 2015-05-23 14:44:37 -07:00
Nick Coghlan d5cacbb1d9 PEP 489: Multi-phase extension module initialization
Known limitations of the current implementation:

- documentation changes are incomplete
- there's a reference leak I haven't tracked down yet

The leak is most visible by running:

  ./python -m test -R3:3 test_importlib

However, you can also see it by running:

  ./python -X showrefcount

Importing the array or _testmultiphase modules, and
then deleting them from both sys.modules and the local
namespace shows significant increases in the total
number of active references each cycle. By contrast,
with _testcapi (which continues to use single-phase
initialisation) the global refcounts stabilise after
a couple of cycles.
2015-05-23 22:24:10 +10:00
Raymond Hettinger 5cbd8331ff Issue #24221: Small optimizations for heapq.
Replaces the PyList_GET_ITEM and PyList_SET_ITEM macros with normal array
accesses.  Replace the siftup unpredicatable branch with arithmetic.
Replace the rc == -1 tests with rc < 0.  Gives nicer looking assembly
with both Clang and GCC-4.9.  Also gives a small performance both for both.
2015-05-22 00:41:57 -07:00
Serhiy Storchaka 48e47aaa28 Issue #22486: Added the math.gcd() function. The fractions.gcd() function now is
deprecated.  Based on patch by Mark Dickinson.
2015-05-13 00:19:51 +03:00
Yury Selivanov f487a005d6 Fix warnings for PyEval_GetCoroutineWrapper 2015-05-11 23:19:34 -04:00
Yury Selivanov 7544508f02 PEP 0492 -- Coroutines with async and await syntax. Issue #24017. 2015-05-11 22:57:16 -04:00