Commit Graph

4858 Commits

Author SHA1 Message Date
Victor Stinner 861f067201 Merge 3.4 (os.urandom) 2015-10-01 10:00:23 +02:00
Victor Stinner 78cc2e8968 Issue #25003: os.urandom() doesn't use getentropy() on Solaris because
getentropy() is blocking, whereas os.urandom() should not block. getentropy()
is supported since Solaris 11.3.
2015-10-01 09:59:32 +02:00
Victor Stinner bae2d6203f Issue #25003: On Solaris 11.3 or newer, os.urandom() now uses the getrandom()
function instead of the getentropy() function. The getentropy() function is
blocking to generate very good quality entropy, os.urandom() doesn't need such
high-quality entropy.
2015-10-01 09:47:30 +02:00
Benjamin Peterson 58b53953f8 make opening brace of container literals and comprehensions correspond to the line number and col offset of the AST node (closes #25131) 2015-09-25 22:44:43 -07:00
Victor Stinner ec26f83f2e Issue #25155: Fix _PyTime_Divide() rounding
_PyTime_Divide() rounding was wrong: copy code from Python default which has
now much better unit tests.
2015-09-18 14:21:14 +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 cd6e69439c Issue #25160: Fix import_init() comments and messages
import_init() imports the "_imp" module, not the "imp" module.
2015-09-18 09:11:57 +02:00
Benjamin Peterson b685515039 compute stack effect of BUILD_MAP correctly (closes #25060) 2015-09-10 21:02:39 -07:00
Steve Dower f35bd306ff Merge from 3.5.0 branch. 2015-09-06 22:27:42 -07:00
Larry Hastings 714e49371b Issue #24305: Prevent import subsystem stack frames from being counted
by the warnings.warn(stacklevel=) parameter.
2015-09-06 00:39:37 -07:00
Victor Stinner 874dbe895d Merge 3.4 (create_stdio) 2015-09-04 17:29:57 +02:00
Victor Stinner 6fb5bae252 Fix race condition in create_stdio()
Issue #24891: Fix a race condition at Python startup if the file descriptor
of stdin (0), stdout (1) or stderr (2) is closed while Python is creating
sys.stdin, sys.stdout and sys.stderr objects. These attributes are now set
to None if the creation of the object failed, instead of raising an OSError
exception. Initial patch written by Marco Paolini.
2015-09-04 17:27:49 +02:00
Victor Stinner 38b8ae0f5b Issue #24993: Handle import error in namereplace error handler
Handle PyCapsule_Import() failure (exception) in PyCodec_NameReplaceErrors():
return immedialty NULL.
2015-09-03 16:19:40 +02:00
Victor Stinner 5ad5821d09 oops, rename pymonotonic_new() to pymonotonic()
I was not supposed to commit the function with the name pymonotonic_new(). I
forgot to rename it.
2015-09-03 00:14:58 +02:00
Victor Stinner c3c616c3d1 Issue #24707: Remove assertion in monotonic clock
Don't check anymore at runtime that the monotonic clock doesn't go backward.
Yes, it happens. It occurs sometimes each month on a Debian buildbot slave
running in a VM.

The problem is that Python cannot do anything useful if a monotonic clock goes
backward. It was decided in the PEP 418 to not fix the system, but only expose
the clock provided by the OS.
2015-09-03 00:13:46 +02:00
Yury Selivanov b3d531348c Issue #24975: Fix AST compilation for PEP 448 syntax. 2015-09-01 16:10:49 -04:00
Larry Hastings 01b1ff6970 Rebuilt Clinic generated code. 2015-08-24 20:23:27 -07:00
Larry Hastings 1df0b35e3d Issue #24769: Interpreter now starts properly when dynamic loading
is disabled.  Patch by Petr Viktorin.
2015-08-24 19:53:56 -07:00
Brett Cannon 3008bc0f4a Issue #24492: make sure that ``from ... import ...` raises an
ImportError if __name__ is not defined on a package.

Thanks to Armin Rigo for the bug report and diagnosing the cause.
2015-08-11 18:01:31 -07:00
Berker Peksag 0bd5fb0112 Issue #24728: Fix building without threads.
Patch by Louis Dassy.
2015-07-27 16:46:11 +03:00
Yury Selivanov 14acf5f41d Issue #24791: Fix grammar regression for call syntax: 'g(*a or b)'. 2015-08-05 17:54:10 -04:00
Victor Stinner 61d5aab9b9 py_getrandom(): getrandom() *can* return EINTR
See the latest version of getrandom() manual page:
http://man7.org/linux/man-pages/man2/getrandom.2.html#NOTES

    The behavior when a call to getrandom() that is blocked while reading from
    /dev/urandom is interrupted by a signal handler depends on the
    initialization state of the entropy buffer and on the request size, buflen.
    If the entropy is not yet initialized, then the call will fail with the
    EINTR error.  If the entropy pool has been initialized and the request size
    is large (buflen > 256), the call either succeeds, returning a partially
    filled buffer, or fails with the error EINTR.  If the entropy pool has been
    initialized and the request size is small (buflen <= 256), then getrandom()
    will not fail with EINTR.  Instead, it will return all of the bytes that
    have been requested.

Note: py_getrandom() calls getrandom() with flags=0.
2015-07-30 10:13:52 +02:00
Stefan Krah c0cbed1554 Fix refleak. 2015-07-27 12:56:49 +02:00
Yury Selivanov f315c1c016 Issue #24687: Plug refleak on SyntaxError in function parameters annotations. 2015-07-23 09:10:44 +03:00
Yury Selivanov b7666a3093 Issue #24619: More tests; fix nits in compiler.c 2015-07-22 14:48:57 +03:00
Benjamin Peterson d5d77aac60 set items in dict displays from left to right (closes #24569) 2015-07-05 10:37:25 -05:00
Yury Selivanov f488fb422a Issue #19235: Add new RecursionError exception. Patch by Georg Brandl. 2015-07-03 01:04:23 -04:00
Yury Selivanov 9dec03571f Issue #24528: Improve error message for awaits in comprehensions 2015-06-30 12:49:04 -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 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 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
Serhiy Storchaka 553e156921 Fixed indentation of Python examples in C comments. 2015-06-11 00:07:47 +03:00
Serhiy Storchaka d741a88049 Fixed indentation of Python examples in C comments. 2015-06-11 00:06:39 +03:00
Yury Selivanov 94c2263005 Issue 24374: Plug refleak in set_coroutine_wrapper 2015-06-04 10:16: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 72ea27c89b Issue 24366: Merge 3.4 2015-06-02 18:54:31 -04:00
Yury Selivanov e12685757f Issue 24366: Merge 3.3 2015-06-02 18:54:09 -04:00
Yury Selivanov 614bfcc953 Issue 24366: Indent code (thanks to li4ick for reporting). 2015-06-02 18:53:46 -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
Yury Selivanov d8cf382ee7 Issue 24017: Make PyEval_(Set|Get)CoroutineWrapper private 2015-06-01 12:15:23 -04:00
Serhiy Storchaka ac5569b1fa Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.
2015-05-30 17:48:19 +03:00
Serhiy Storchaka fa494fd883 Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.
2015-05-30 17:45:22 +03:00
Serhiy Storchaka 8b2e8b6cce Specify default values of semantic booleans in Argument Clinic generated signatures as booleans. 2015-05-30 11:30:39 +03:00
Serhiy Storchaka 7e810a6e3d Use converter names instead of format units in Argument Clinic descriptions
in builtin and _crypt modules.
2015-05-30 11:09:35 +03:00
Benjamin Peterson e20056c8f7 fix importing one char extension modules (closes #24328) 2015-05-29 17:10:30 -05:00
Benjamin Peterson 264be6f48f remove STORE_MAP, since it's unused 2015-05-28 14:40:08 -05:00
Benjamin Peterson ee85339cc6 in dict displays, evaluate the key before the value (closes #11205)
Patch partially by Steve Dougherty.
2015-05-28 14:30:26 -05:00
Yury Selivanov 6ef059097c Issue 24017: Drop getawaitablefunc and friends in favor of unaryfunc. 2015-05-28 11:21:31 -04:00
Nick Coghlan 55871f04bf Issue #24285: fix importing extensions from packages 2015-05-26 21:48:17 +10:00
Steve Dower adc2fb8a6a Issue #24268: Fix import naming when loading extension modules. Patch by Petr Viktorin. 2015-05-23 14:13:41 -07:00
Steve Dower 7689154f58 Issue #24268: Fixes generation of init import name on Windows. 2015-05-23 08:59:25 -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
Serhiy Storchaka c0937f79ec Issue #24102: Fixed exception type checking in standard error handlers. 2015-05-18 16:10:40 +03:00
Serhiy Storchaka ca7fecb038 Issue #24102: Fixed exception type checking in standard error handlers. 2015-05-18 16:08:52 +03:00
Benjamin Peterson de12b79cd6 allow test node after ** in calls (closes #24176) 2015-05-16 09:44:45 -04:00
Eric Snow 183a941bc1 Issue #24192: Fix namespace package imports. 2015-05-15 21:54:59 -06:00
Nick Coghlan baaadbf70d Issue 24017: fix for "async with" refcounting
* adds missing INCREF in WITH_CLEANUP_START
* adds missing DECREF in WITH_CLEANUP_FINISH
* adds several new tests Yury created while investigating this
2015-05-13 15:54:02 +10:00
Benjamin Peterson baa2e562ce use our normal bracing style 2015-05-12 11:32:41 -04:00
Yury Selivanov 1dde177f82 Issue #24017: Plug ref leak. 2015-05-12 11:30:14 -04: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
Yury Selivanov 8170e8c0d1 PEP 479: Change StopIteration handling inside generators.
Closes issue #22906.
2015-05-09 11:44:30 -04:00
Benjamin Peterson 95283fb589 Merge 3.4 2015-05-07 18:42:16 -04:00
Benjamin Peterson 9e77f72fb2 shorten capsule name macro; it doesn't need to be so long 2015-05-07 18:41:47 -04:00
Benjamin Peterson 025e9ebd0a PEP 448: additional unpacking generalizations (closes #2292)
Patch by Neil Girdhar.
2015-05-05 20:16:41 -04:00
Benjamin Peterson 63a6a6fd41 merge 3.4 (#24096) 2015-05-03 11:29:58 -04:00
Benjamin Peterson 8c59816b70 merge 3.3 (#24096) 2015-05-03 11:28:46 -04:00
Benjamin Peterson deff2b76ec be more robust against the filters list changing under us (closes #24096) 2015-05-03 11:23:37 -04:00
Eric Snow 32439d6eb6 Issue #23911: Move path-based bootstrap code to a separate frozen module. 2015-05-02 19:15:18 -06:00
Benjamin Peterson 1dfd247c1b remove the concept of an unoptimized function scope from the compiler, since it can't happen anymore 2015-04-27 21:44:22 -04:00
Gregory P. Smith f789465eed Silence a gcc "may be used uninitialized" compiler warning. Not true.
Initializing retval prevents the naive warning.
2015-04-25 23:51:39 -07:00
Gregory P. Smith 5d0ccd2f91 Add missing PyAPI_FUNC macro's to the public functions as other .c files do
in hopes that this fixes the windows extension module link error for modules
trying to call _Py_strhex functions.  issue9951.
2015-04-26 04:59:52 +00:00
Gregory P. Smith e3f6393b52 Add the files missing from c9f1630cf2b1 for issue9951.
hg status should be my friend more often...
2015-04-26 00:41:00 +00:00
Benjamin Peterson 51f58059f6 merge 3.4 (#24049) 2015-04-24 12:02:53 -04:00
Benjamin Peterson 9bdd61338d remove dead *-import checking code (closes #24049) 2015-04-24 12:02:29 -04:00
Serhiy Storchaka 247789cee9 Issue #24007: Argument Clinic now writes the format of PyArg_Parse*() at the
same line as function name.
2015-04-24 00:40:51 +03:00
Christian Heimes 1a084a882b Issue #23998: PyImport_ReInitLock() now checks for lock allocation error 2015-04-19 21:15:02 +02:00
Christian Heimes e0ac2beb4f Issue #23998: PyImport_ReInitLock() now checks for lock allocation error 2015-04-19 21:12:14 +02:00
Christian Heimes 418fd74f87 Issue #23998: PyImport_ReInitLock() now checks for lock allocation error 2015-04-19 21:08:42 +02:00
Serhiy Storchaka db46fea8b6 Fixed error message for the "u#" format code. 2015-04-19 21:13:00 +03:00
Serhiy Storchaka d6e53dab86 Fixed error message for the "u#" format code. 2015-04-19 21:11:30 +03:00
Christian Heimes e8e4283cec Remove redundant check for tb != NULL to shut up Coverity . It has been set to Py_None a couple of lines earlier.
CID 1291697 (#1 of 1): Dereference before null check (REVERSE_INULL)
check_after_deref: Null-checking tb suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
2015-04-16 17:25:45 +02:00
R David Murray 4171bbe687 #23949: Improve tuple unpacking error messages.
Patch by Arnon Yaari.
2015-04-15 17:08:45 -04:00
Larry Hastings 89964c48d1 Issue #23944: Argument Clinic now wraps long impl prototypes at column 78. 2015-04-14 18:07:59 -04:00
Brett Cannon f299abdafa Issue #23731: Implement PEP 488.
The concept of .pyo files no longer exists. Now .pyc files have an
optional `opt-` tag which specifies if any extra optimizations beyond
the peepholer were applied.
2015-04-13 14:21:02 -04:00
Steve Dower 8fc8980c96 Issue #23524: Replace _PyVerify_fd function with calls to _set_thread_local_invalid_parameter_handler. 2015-04-12 00:26:27 -04:00
Benjamin Peterson 55c14355ac fix building without threads (closes #23877) 2015-04-06 09:59:23 -04:00
Serhiy Storchaka 92e8af67a8 Issue #23492: Argument Clinic now generates argument parsing code with
PyArg_Parse instead of PyArg_ParseTuple if possible.
2015-04-04 00:12:11 +03:00
Serhiy Storchaka 1009bf18b3 Issue #23501: Argumen Clinic now generates code into separate files by default. 2015-04-03 23:53:51 +03:00
Victor Stinner 13019fdef3 Issue #22117: Add a new _PyTime_FromSeconds() function
Fix also _Py_InitializeEx_Private(): initialize time before initializing
import, import_init() uses the _PyTime API (for thread locks).
2015-04-03 13:10:54 +02:00
Serhiy Storchaka 1399a01b90 Issue #22977: Fixed formatting Windows error messages on Wine.
Patch by Martin Panter.
2015-04-02 09:50:06 +03:00
Serhiy Storchaka f41f8f9974 Issue #22977: Fixed formatting Windows error messages on Wine.
Patch by Martin Panter.
2015-04-02 09:47:27 +03:00
Victor Stinner 97f86b82b7 Issue #23836: Use _Py_write_noraise() to retry on EINTR in _Py_DumpTraceback()
and _Py_DumpTracebackThreads(). Document also these functions to explain that
the caller is responsible to call PyErr_CheckSignals().
2015-04-01 18:38:01 +02:00
Victor Stinner 6f4fae8a95 Issue #23836: Document functions releasing the GIL in fileutils.c 2015-04-01 18:34:32 +02:00
Victor Stinner 82c3e4599d Issue #23836: Add _Py_write_noraise() function
Helper to write() which retries write() if it is interrupted by a signal (fails
with EINTR).
2015-04-01 18:34:45 +02:00
Victor Stinner 62d1c70eff Issue #22117, issue #23485: Fix _PyTime_AsMilliseconds() and
_PyTime_AsMicroseconds() rounding.

Add also unit tests.
2015-04-01 17:47:07 +02:00
Victor Stinner fa09beb150 Issue #23485: Add _PyTime_FromMillisecondsObject() function 2015-03-30 21:36:10 +02:00
Victor Stinner 81c6df5c0f (Merge 3.4) Issue #22585: os.urandom() now releases the GIL when the
getentropy() is used (OpenBSD 5.6+).
2015-03-30 11:19:07 +02:00