Commit Graph

4502 Commits

Author SHA1 Message Date
Serhiy Storchaka bf28d2dcad Issue #18818: The "encodingname" part of PYTHONIOENCODING is now optional. 2013-09-13 11:46:24 +03:00
Antoine Pitrou 7b4769937f Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
This prevents unpredictable aborts in Py_EndInterpreter() when some non-daemon threads are still running.
2013-09-07 23:38:37 +02:00
Victor Stinner b034eee711 Close #18954: Fix some typo in fileutils.c comments
Patch written by Vajrasky Kok.
2013-09-07 10:36:04 +02:00
Meador Inge 3c56145638 Issue #16826: Revert fix while Windows issues are being worked out. 2013-09-03 19:54:40 -05:00
Meador Inge c9e1dcdd53 Issue #16826: Revert fix while Windows issues are being worked out. 2013-09-03 19:43:49 -05:00
Meador Inge 9ab358ad7c Issue #16826: Don't check for PYTHONCASEOK when using -E.
This commit fixes a regression that sneaked into Python 3.3 where importlib
was not respecting -E when checking for the PYTHONCASEOK environment variable.
2013-09-03 16:53:22 -05:00
Meador Inge d151da9ef7 Issue #16826: Don't check for PYTHONCASEOK when using -E.
This commit fixes a regression that sneaked into Python 3.3 where importlib
was not respecting -E when checking for the PYTHONCASEOK environment variable.
2013-09-03 16:37:26 -05:00
Raymond Hettinger 69492dab07 Factor-out the common code for setting a KeyError. 2013-09-02 15:59:26 -07:00
Antoine Pitrou 4879a963d4 Issue #18756: os.urandom() now uses a lazily-opened persistent file descriptor, so as to avoid using many file descriptors when run in parallel from multiple threads. 2013-08-31 00:26:02 +02:00
Victor Stinner 55a1220bdb pythonrun.c: use MAXPATHLEN instead of PATH_MAX
PATH_MAX is not available on "MIPS IRIX 6.5.30 [SB] 3.x" buildbot
2013-08-28 01:47:46 +02:00
Victor Stinner daf455554b Issue #18571: Implementation of the PEP 446: file descriptors and file handles
are now created non-inheritable; add functions os.get/set_inheritable(),
os.get/set_handle_inheritable() and socket.socket.get/set_inheritable().
2013-08-28 00:53:59 +02:00
Serhiy Storchaka 46e1ce214b Issue #18783: Removed existing mentions of Python long type in docstrings,
error messages and comments.
2013-08-27 20:17:03 +03:00
Serhiy Storchaka 9594942716 Issue #18783: Removed existing mentions of Python long type in docstrings,
error messages and comments.
2013-08-27 19:40:23 +03:00
Victor Stinner 14e461d5b9 Close #11619: The parser and the import machinery do not encode Unicode
filenames anymore on Windows.
2013-08-26 22:28:21 +02:00
Victor Stinner c82bfd871f Issue #18664, #18408: Rewrite PyErr_WriteUnraisable() to handle errors
* Catch PyFile_WriteString() and PyFile_WriteObject() errors
 * Clear the current exception on _PyObject_GetAttrId() failure
 * Use PyUnicode_CompareWithASCIIString() and PyFile_WriteObject() instead of
   _PyUnicode_AsString() and strcmp() to avoid Unicode encoding error. stderr
   has a more tolerant error handler than utf-8/strict.
2013-08-26 14:04:10 +02:00
Ezio Melotti 0e1e04301b #18839: merge with 3.3. 2013-08-26 14:01:29 +03:00
Ezio Melotti 4af4d273bd #18839: document that sys.exit() will not accept a non-integer numeric value as exit status. 2013-08-26 14:00:39 +03:00
Antoine Pitrou 7eaf3f7080 Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error). 2013-08-25 19:48:18 +02:00
Benjamin Peterson 3a7dffa4ce remove support for compiling on systems without getcwd()
Do we need a fallback implementation of getcwd() from 1991 that claims to
support "really old Unix systems"? I don't think so.
2013-08-23 21:01:48 -05:00
Victor Stinner cba2e3c2e9 remove unused declaration 2013-08-22 02:23:13 +02:00
Christian Heimes 01a513b5d3 Remove last bit of GNU pth thread
PEP 11:
  Name: Systems using --with-pth (GNU pth threads)
  Unsupported in: Python 3.2
  Code removed in: Python 3.3
2013-08-17 00:17:58 +02:00
Antoine Pitrou 95b21460ee Issue #18756: Improve error reporting in os.urandom() when the failure is due to something else than /dev/urandom not existing. 2013-08-16 20:49:32 +02:00
Antoine Pitrou ec34ab5010 Issue #18756: Improve error reporting in os.urandom() when the failure is due to something else than /dev/urandom not existing. 2013-08-16 20:44:38 +02:00
Antoine Pitrou 9ed5f27266 Issue #18722: Remove uses of the "register" keyword in C code. 2013-08-13 20:18:52 +02:00
Antoine Pitrou 40322e6ad5 Issue #10241: Clear extension module dict copies at interpreter shutdown.
Patch by Neil Schemenauer, minimally modified.

(re-apply after fix for tkinter-related crash)
2013-08-11 00:30:09 +02:00
Christian Heimes ad73a9cf97 Issue #16400: Add command line option for isolated mode.
-I

    Run Python in isolated mode. This also implies -E and -s. In isolated mode
    sys.path contains neither the script’s directory nor the user’s
    site-packages directory. All PYTHON* environment variables are ignored,
    too. Further restrictions may be imposed to prevent the user from
    injecting malicious code.
2013-08-10 16:36:18 +02:00
Antoine Pitrou 79ba3882ad Improve verbose reporting of shutdown phase by using the "public" module name 2013-08-06 22:50:15 +02:00
Antoine Pitrou 58720d6145 Issue #17934: Add a clear() method to frame objects, to help clean up expensive details (local variables) and break reference cycles. 2013-08-05 23:26:40 +02:00
Antoine Pitrou 95db2e7b8a Backout 62658d9d8926 (issue #10241): it causes a crash at shutdown when deallocating a Tkapp object. 2013-08-02 20:39:46 +02:00
Antoine Pitrou 84f31a5676 Issue #10241: Clear extension module dict copies at interpreter shutdown.
Patch by Neil Schemenauer, minimally modified.
2013-08-01 22:07:06 +02:00
Antoine Pitrou dcedaf6e53 Issue #18214: Improve finalization of Python modules to avoid setting their globals to None, in most cases. 2013-07-31 23:14:08 +02:00
Antoine Pitrou 32d483c39b Fix style 2013-07-30 21:01:23 +02:00
Victor Stinner c588feeea9 Issue #15893: Improve error handling in main() and Py_FrozenMain()
* handle _PyMem_RawStrdup() failure
* Py_FrozenMain() releases memory on error
* Py_FrozenMain() duplicates the old locale, as done in main()
2013-07-27 02:39:09 +02:00
Victor Stinner 739cf4e3e6 Py_FrozenMain() now uses _Py_char2wchar() to decode command line arguments, as
done in main()
2013-07-27 02:24:52 +02:00
Victor Stinner b5245bec93 Issue #18203: Replace PyMem_Malloc() with PyMem_RawMalloc() at Python initialization 2013-07-27 01:13:34 +02:00
Victor Stinner 597696c70c (Merge 3.3) Issue #15893: frozenmain.c now handles PyMem_Malloc() failure 2013-07-27 01:05:49 +02:00
Victor Stinner 36577e4e8c Issue #15893: frozenmain.c now handles PyMem_Malloc() failure 2013-07-27 01:04:56 +02:00
Christian Heimes b7f1b38dea Issue #18552: Check return value of PyArena_AddPyObject() in obj2ast_object(). 2013-07-27 00:33:35 +02:00
Christian Heimes 70c94e7896 Issue #18552: Check return value of PyArena_AddPyObject() in obj2ast_object(). 2013-07-27 00:33:13 +02:00
Victor Stinner b318990cac (Merge 3.3) Parser/asdl_c.py: use Py_CLEAR() 2013-07-27 00:04:42 +02:00
Victor Stinner 1acc129d48 Parser/asdl_c.py: use Py_CLEAR() 2013-07-27 00:03:47 +02:00
Victor Stinner ee4b59c0f8 (Merge 3.3) According to the PEP 7, C code must "use 4-space indents"
Replace 8 spaces with 4.
2013-07-27 00:01:35 +02:00
Victor Stinner ce72e1ce6c According to the PEP 7, C code must "use 4-space indents"
Replace 8 spaces with 4.
2013-07-27 00:00:36 +02:00
Christian Heimes 4ebf6d7c3c Issue #18560: Fix potential NULL pointer dereference in sum() 2013-07-26 22:50:01 +02:00
Christian Heimes 704e2d374f Issue #18560: Fix potential NULL pointer dereference in sum() 2013-07-26 22:49:26 +02:00
Christian Heimes 6f08d30afe Fix potential NULL pointer dereferencing in ast module
CID 719690
2013-07-24 21:02:50 +02:00
Christian Heimes 72f562f719 Fix potential NULL pointer dereferencing in ast module
CID 719690
2013-07-24 21:02:17 +02:00
Benjamin Peterson 26421ab302 merge 3.3 2013-07-22 22:08:17 -07:00
Benjamin Peterson 7d28b6b379 return NULL here 2013-07-22 22:08:09 -07:00
Victor Stinner ba30883f60 Issue #18520: Fix initstdio(), handle PySys_SetObject() failure 2013-07-22 23:55:19 +02:00
Victor Stinner 62ce62a3a1 Issue #18520: initsite() is a little bit more verbose when import site fails 2013-07-22 22:53:28 +02:00
Victor Stinner 580496005d Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors 2013-07-22 22:40:00 +02:00
Victor Stinner f54a574478 Issue #18520: PyErr_NoMemory() now fails with a fatal error if it is called
before PyExc_MemoryError has been initialized by _PyExc_Init()
2013-07-22 22:28:37 +02:00
Victor Stinner 1c8f059019 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
PyStructSequence_InitType() except that it has a return value (0 on success,
-1 on error).

 * PyStructSequence_InitType2() now raises MemoryError on memory allocation failure
 * Fix also some calls to PyDict_SetItemString(): handle error
2013-07-22 22:24:54 +02:00
Christian Heimes de0e63bd9c Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
prefix and exec_prefix if the operation system does not obey MAXPATHLEN.
2013-07-22 12:54:21 +02:00
Christian Heimes 60a6067709 Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
prefix and exec_prefix if the operation system does not obey MAXPATHLEN.
2013-07-22 12:53:32 +02:00
Benjamin Peterson c3e10c237b merge 3.3 2013-07-21 13:29:42 -07:00
Benjamin Peterson 0f9b7d32c7 fix spacing 2013-07-21 13:29:37 -07:00
Benjamin Peterson 33113a3504 merge 3.3 2013-07-21 13:26:27 -07:00
Benjamin Peterson 04b01dc8f7 let's not return NULL from functions that should return ints 2013-07-21 13:26:13 -07:00
Victor Stinner d786ad55ef Issue #18520: Fix initsigs(), handle PyOS_InitInterrupts() error
PyOS_InitInterrupts() can raise error when importing the signal module
2013-07-21 13:25:51 +02:00
Christian Heimes 02e8b53e6d Check return value of lseek() in _Py_DisplaySourceLine().
Also use portable SEEK_SET instead of 0.
CID 1040639
2013-07-21 02:12:44 +02:00
Christian Heimes 1f34729f42 Check return value of lseek() in _Py_DisplaySourceLine().
Also use portable SEEK_SET instead of 0.
CID 1040639
2013-07-21 02:12:35 +02:00
Christian Heimes 8282d749a6 Check return value of PyObject_AsFileDescriptor() in _Py_DisplaySourceLine() for error
CID 486768
2013-07-21 01:53:18 +02:00
Christian Heimes 8c077bc03e Check return value of PyObject_AsFileDescriptor() in _Py_DisplaySourceLine() for error
CID 486768
2013-07-21 01:53:10 +02:00
Christian Heimes 7bc80fcf4e Check return value of fstat() in _PyImport_GetDynLoadFunc()
CID 486250
2013-07-20 22:18:19 +02:00
Christian Heimes 27c4c3ec79 Check return value of fstat() in _PyImport_GetDynLoadFunc()
CID 486250
2013-07-20 22:17:55 +02:00
Christian Heimes 74ba26a40c Add missing check of PyDict_SetItem()'s return value in _PyImport_FindExtensionObject()
CID 486649
2013-07-20 14:52:18 +02:00
Christian Heimes 09ca794afe Add missing check of PyDict_SetItem()'s return value in _PyImport_FindExtensionObject()
CID 486649
2013-07-20 14:51:53 +02:00
Christian Heimes 895bdfb16e Add missing check of PyDict_SetItem()'s return value in PyEval_EvalCodeEx()
CID 486647
2013-07-20 14:48:21 +02:00
Christian Heimes 0bd447f847 Add missing check of PyDict_SetItem()'s return value in PyEval_EvalCodeEx()
CID 486647
2013-07-20 14:48:10 +02:00
Victor Stinner ace47d7efd Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
with an assertion error if they are called with an exception set
(PyErr_Occurred()).

If these functions are called with an exception set, the exception may be
cleared and so the caller looses its exception.

Add also assertions to PyEval_CallObjectWithKeywords() and call_function() to
check if the function succeed with no exception set, or the function failed
with an exception set.
2013-07-18 01:41:08 +02:00
Victor Stinner 479054bca7 Issue #18408: Fix PyErr_SetImportError(), handle PyDict_SetItemString() failure 2013-07-17 21:54:25 +02:00
Victor Stinner 8e54b1c448 Issue #18408: Fix _PyImport_LoadDynamicModule(), handle PyUnicode_FromFormat() failure 2013-07-17 21:53:23 +02:00
Victor Stinner 0fae8f9083 Issue #18408: Fix ast_for_atom(), PyErr_Fetch(&type, &value, &tback) can set value to NULL 2013-07-17 21:51:42 +02:00
Victor Stinner 26f91999b4 Close #18469: Replace PyDict_GetItemString() with _PyDict_GetItemId() in structseq.c
_PyDict_GetItemId() is more efficient: it only builds the Unicode string once.
Identifiers (dictionary keys) are now created at Python initialization, and if
the creation failed, Python does exit with a fatal error.

Before, PyDict_GetItemString() failure was not handled: structseq_new() could
call PyObject_GC_NewVar() with a negative size, and structseq_dealloc() could
also crash.
2013-07-17 01:22:45 +02:00
Victor Stinner 43d8195a70 Issue #18408: Handle PyArena_AddPyObject() failure in ast.c
PyList_Append() (called by PyArena_AddPyObject()) can fail because of a
MemoryError for example.
2013-07-17 00:57:58 +02:00
Victor Stinner 74a7fa6663 Issue #18408: Fix PyErr_NormalizeException(), handle PyObject_IsSubclass() failure
PyObject_IsSubclass() can fail and raise a new exception!
2013-07-17 00:44:53 +02:00
Victor Stinner bdf630c4a7 Issue #18408: Fix Python-ast.c: handle init_types() failure (ex: MemoryError) 2013-07-17 00:17:15 +02:00
Victor Stinner 1e53bbaced Issue #18408: handle PySys_GetObject() failure, raise a RuntimeError 2013-07-16 22:26:05 +02:00
Victor Stinner 78e2c985ac Issue #18408: Fix show_warning(), clear also the exception raised by
_Py_DisplaySourceLine()

For example, _PyGC_DumpShutdownStats() calls PyErr_WarnExplicitFormat() while
the import machinery does not work anymore, _Py_DisplaySourceLine() fails when
trying to import the io module.
2013-07-16 01:54:37 +02:00
Victor Stinner f243ee4055 Issue #18408: add more assertions on PyErr_Occurred() in ceval.c to detect bugs
earlier
2013-07-16 01:02:12 +02:00
Victor Stinner ceceaa00ba Issue #18408: Fix _Py_DisplaySourceLine()
Report _Py_FindSourceFile() error, so the error is cleared;
and clear io.open(filename) exception on failure.
2013-07-16 00:32:14 +02:00
Victor Stinner 7eab0d000c Issue #18408: Fix PyEval_EvalFrameEx() for MemoryError
Don't pass a NULL traceback to PyException_SetTraceback(): pass Py_None.
Passing NULL would raise a new exception.
2013-07-15 21:16:27 +02:00
Brett Cannon a79e4fb38d Issue #18342: Use the repr of a module name for ``from ... import
...`` when an ImportError occurs.

Other cases had already been switched over to using the repr.

Thanks to Tomasz Maćkowiak for the patch.
2013-07-12 11:22:26 -04:00
Brett Cannon f0cb69274c Issue #18415: Normalize what type of quotes are used with string
constants in importlib._bootstrap. Along the way clean up from string
interpolation to use the repr explicitly.

Initial patch by Madison May.
2013-07-12 11:04:23 -04:00
Victor Stinner fb3a630001 Issue #18408: errors.c: in debug mode, calling PyErr_BadInternalCall() now
fails with an assertion error
2013-07-12 00:37:30 +02:00
Victor Stinner 365b693adc Issue #18408: ceval.c: in debug mode, convert the PyErr_Occurred() check on
exception (when getting NULL) to an assertion to detect bugs earlier
2013-07-12 00:11:58 +02:00
Victor Stinner cc35159ed8 Issue #18408: normalizestring() now raises MemoryError on memory allocation failure 2013-07-12 00:02:55 +02:00
Victor Stinner 6b64a6803e Issue #18408: Fix compiler_import() to handle PyUnicode_Substring() failure properly 2013-07-11 22:50:45 +02:00
Victor Stinner 9a4fb66966 Issue #18408: ste_new() initialize all attributes before handling error
If an attribute is not initialized, the destructor can crash
2013-07-11 22:49:00 +02:00
Serhiy Storchaka f9e6672ae8 Issue #17872: Fix a segfault in marshal.load() when input stream returns
more bytes than requested.
2013-07-11 22:28:18 +03:00
Serhiy Storchaka 3641a74e1c Issue #17872: Fix a segfault in marshal.load() when input stream returns
more bytes than requested.
2013-07-11 22:20:47 +03:00
Serhiy Storchaka a155d40ed5 Fix reference leaks introduced by the patch for issue #5308. 2013-07-11 19:19:47 +03:00
Serhiy Storchaka dfde2151ed Fix reference leaks introduced by the patch for issue #5308. 2013-07-11 19:14:26 +03:00
Christian Heimes 6cee994674 Issue #18426: improve exception message. Courtesy of Amaury 2013-07-11 13:02:37 +02:00
Christian Heimes 7ce57d67c9 Issue #18426: improve exception message. Courtesy of Amaury 2013-07-11 13:02:30 +02:00
Christian Heimes 5ec44649df Issue #18426: Fix NULL pointer dereference in C extension import when
PyModule_GetDef() returns an error.
2013-07-11 11:23:34 +02:00
Christian Heimes 848ee099f5 Issue #18426: Fix NULL pointer dereference in C extension import when
PyModule_GetDef() returns an error.
2013-07-11 11:22:21 +02:00
R David Murray acb362e29f Merge: #18424: PEP8ify the tense of the sum docstring. 2013-07-10 16:22:59 -04:00
R David Murray 87ead1138d #18424: PEP8ify the tense of the sum docstring. 2013-07-10 16:22:14 -04:00
Victor Stinner aaa8ed8b84 Issue #18408: Fix call_exc_trace(): if the traceback is NULL, use None when
building the tuple (type, value, traceback) passed to the callback.

PyTuple_Pack() does crash if an argument is NULL.
2013-07-10 13:57:55 +02:00
Victor Stinner e0af3a802a Issue #18408: Fix PyCode_Optimize(): raise a MemoryError on memory allocation
failure.
2013-07-09 00:32:04 +02:00
Victor Stinner 0ff0f54dd4 Issue #18408: Fix call_function() of ceval.c to handle PyTuple_New() failure
(in load_args()), ex: MemoryError.
2013-07-08 22:27:42 +02:00
Victor Stinner 3a8b79d4d2 Issue #18408: Fix marshal reader for Unicode strings: handle
PyUnicode_DecodeUTF8() failure (ex: MemoryError).
2013-07-08 22:23:32 +02:00
Victor Stinner 49fc8ece81 Issue #18203: Add _PyMem_RawStrdup() and _PyMem_Strdup()
Replace strdup() with _PyMem_RawStrdup() or _PyMem_Strdup(), depending if the
GIL is held or not.
2013-07-07 23:30:24 +02:00
Victor Stinner c6632e7eb4 Issue #18203: Replace malloc() with PyMem_Malloc() to allocate arena objects 2013-07-07 17:18:53 +02:00
Victor Stinner 80aa565fb4 Issue #18203: Replace malloc() with PyMem_RawMalloc() to allocate thread locks 2013-07-07 17:17:59 +02:00
Victor Stinner 65bf9cf26f Issue #18203: Fix decode_ascii_surrogateescape(), use PyMem_RawMalloc() as _Py_char2wchar() 2013-07-07 16:35:54 +02:00
Victor Stinner 1a7425f67a Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
* Replace malloc() with PyMem_RawMalloc()
* Replace PyMem_Malloc() with PyMem_RawMalloc() where the GIL is not held.
* _Py_char2wchar() now returns a buffer allocated by PyMem_RawMalloc(), instead
  of PyMem_Malloc()
2013-07-07 16:25:15 +02:00
Victor Stinner 51fa458d0a Issue #18203: Fix Py_Finalize(): destroy the GIL after the last call to
PyMem_Malloc() or PyObject_Malloc().

For example, PyCFunction_Fini() calls PyObject_GC_Del() which calls
PyObject_FREE().
2013-07-07 15:50:49 +02:00
Brett Cannon 7e5d55705c merge for issue #18351. 2013-07-06 18:04:41 -04:00
Brett Cannon a53cca3fea Issue #18351: Fix various issues with
importlib._bootstrap._get_sourcefile().

Thanks to its only use by the C API, it was never properly tested
until now.

Thanks to Neal Norwitz for discovering the bug and Madison May for the patch.
2013-07-06 17:56:43 -04:00
Brett Cannon 0075110ab2 Issue #18364: Stop using the ImportError._not_found hack.
The private attribute was leaking out of importlib and led to at least
one person noticing it. Switch to another hack which won't leak
outside of importlib and is nearly as robust.
2013-07-06 14:48:18 -04:00
Brett Cannon 679ecb565b Issue #15767: back out 8a0ed9f63c6e, finishing the removal of
ModuleNotFoundError.
2013-07-04 17:51:50 -04:00
Brett Cannon 82da8886cc Issue #15767: Revert 3a50025f1900 for ModuleNotFoundError 2013-07-04 17:48:16 -04:00
Christian Heimes 1d5b933504 Issue #18328: Reorder ops in PyThreadState_Delete*() functions. Now the
tstate is first removed from TLS and then deallocated.
CID 1019639 (#1 of 1): Use after free (USE_AFTER_FREE)
 use_after_free: Using freed pointer tstate.
2013-07-01 23:43:09 +02:00
Christian Heimes b9dbc7d6e1 Issue #18328: Reorder ops in PyThreadState_Delete*() functions. Now the
tstate is first removed from TLS and then deallocated.
CID 1019639 (#1 of 1): Use after free (USE_AFTER_FREE)
 use_after_free: Using freed pointer tstate.
2013-07-01 23:42:28 +02:00
Raymond Hettinger 4d6018fe45 Issue 18111: Add a default argument to min() and max() 2013-06-24 22:43:02 -07:00
Victor Stinner 14b9b11098 If MS_WIN64 is defined, MS_WINDOWS is also defined: #ifdef can be simplified. 2013-06-25 00:37:25 +02:00
Victor Stinner 7b2513589f Issue #9566: pystrtod.c: Fix a compiler warnings on Windows x64 2013-06-24 23:37:40 +02:00
Victor Stinner 76d38502e4 Issue #9566: Fix a compiler warning on Windows x64 2013-06-24 23:34:15 +02:00
Christian Heimes 582cfbbf74 import.c does neither need mode_t nor _mkdir() anymore 2013-06-23 15:53:09 +02:00
Victor Stinner 2ab07f01a4 (Merge 3.3) Issue #18137: Detect integer overflow on precision in
float.__format__() and complex.__format__().
2013-06-23 14:55:43 +02:00
Victor Stinner 2f084ecfe7 Issue #18137: Detect integer overflow on precision in float.__format__() and
complex.__format__().
2013-06-23 14:54:30 +02:00
Victor Stinner f1913ca37f marshal: optimize parsing of empty Unicode strings
Don't create a temporary buffer of zeroy byte nor call r_string() if the length
is zero, create directly the empty string.
2013-06-21 19:08:06 +02:00
Andrew Kuchling c61b913078 #13226: update references from ctypes/DLFCN modules to os module 2013-06-21 10:58:41 -04:00
Antoine Pitrou 1a1a06ee36 Issue #18256: Compilation fix for recent AIX releases. Patch by David Edelsohn. 2013-06-18 22:19:11 +02:00
Antoine Pitrou 9a00e0a41c Issue #18256: Compilation fix for recent AIX releases. Patch by David Edelsohn. 2013-06-18 22:17:48 +02:00
Brett Cannon 1d75382e81 Fix a misnaming of a method and an argument 2013-06-16 19:06:55 -04:00
Brett Cannon f24fecd4ac Issue #18076: Introduce imoportlib.util.decode_source().
The helper function makes it easier to implement
imoprtlib.abc.InspectLoader.get_source() by making that function
require just the raw bytes for source code and handling all other
details.
2013-06-16 18:37:53 -04:00
Brett Cannon f4375ef4d4 importlib.abc.SourceLoader.get_source() was re-raising SyntaxError and
UnicodeDecodeError as ImportError. That was over-reaching the point of
raising ImportError in get_source() (which is to signal the source
code was not found when it should have). Conflating the two exceptions
with ImportError could lead to masking errors with the source which
should be known outside of whether there was an error simply getting
the source to begin with.
2013-06-16 18:05:54 -04:00
Brett Cannon 01b0475b08 Issue #18115: Abstract out managing the cleanup of modules to use in
loaders where C code provides the loaded module.
2013-06-16 17:23:06 -04:00
Brett Cannon 13d8ff9c5b Issues #18058, 18057: Make importlib._bootstrap.NamespaceLoader
conform the the InspectLoader ABC. Perk of this is that runpy/-m can
now work with namespace packages.
2013-06-16 14:56:58 -04:00
Brett Cannon a3c96154d2 Issue #17907: touch up the code for imp.new_module(). 2013-06-14 22:26:30 -04:00
Brett Cannon 05a647deed Issue #18192: Introduce importlib.util.MAGIC_NUMBER and document the
deprecation of imp.get_magic().
2013-06-14 19:02:34 -04:00
Brett Cannon 8f5ac5106e Issue #15767: Touch up ModuleNotFoundError usage by import.
Forgot to raise ModuleNotFoundError when None is found in sys.modules.
This led to introducing the C function PyErr_SetImportErrorSubclass()
to make setting ModuleNotFoundError easier.

Also updated the reference docs to mention ModuleNotFoundError
appropriately. Updated the docs for ModuleNotFoundError to mention the
None in sys.modules case.

Lastly, it was noticed that PyErr_SetImportError() was not setting an
exception when returning None in one case. That issue is now fixed.
2013-06-12 23:29:18 -04:00
Brett Cannon b1611e2772 Issue #15767: Introduce ModuleNotFoundError, a subclass of
ImportError.

The exception is raised by import when a module could not be found.
Technically this is defined as no viable loader could be found for the
specified module. This includes ``from ... import`` statements so that
the module usage is consistent for all situations where import
couldn't find what was requested.

This should allow for the common idiom of::

  try:
    import something
  except ImportError:
    pass

to be updated to using ModuleNotFoundError and not accidentally mask
ImportError messages that should propagate (e.g. issues with a
loader).

This work was driven by the fact that the ``from ... import``
statement needed to be able to tell the difference between an
ImportError that simply couldn't find a module (and thus silence the
exception so that ceval can raise it) and an ImportError that
represented an actual problem.
2013-06-12 16:59:46 -04:00
Richard Oudkerk cac17b4d78 Merge. 2013-06-10 15:45:30 +01:00
Richard Oudkerk 409f90237c Issue #18180: Fix ref leak in _PyImport_GetDynLoadWindows(). 2013-06-10 15:38:54 +01:00
Brett Cannon 4e694d6fa9 tweak exception message (again) 2013-06-05 18:37:50 -04:00
Victor Stinner 9550ef30e3 Issue #9566: Fix compilater warnings on Windows 64-bit 2013-06-05 01:18:13 +02:00
Victor Stinner 56785eab33 Issue #9566: Fix compiler warning on Windows 64-bit 2013-06-05 00:46:29 +02:00
Brett Cannon af38f5a503 Tweak at the suggestion of Ezio Melotti for exception messages when
EOF is hit while trying to read the header of a bytecode file.
2013-06-04 17:34:49 -04:00
Victor Stinner da2cbb4fc8 Issue #15893: Remove dead code 2013-07-27 02:41:03 +02:00
Benjamin Peterson e2135c6158 move definition to top of block 2013-05-16 19:38:22 -05:00
Brett Cannon 3e0651b5fa Issue #18065: For frozen packages set __path__ to [].
Previously __path__ was set to [__name__], but that could lead to bad
results if someone managed to circumvent the frozen importer and
somehow ended up with a finder that thought __name__ was a legit
directory/location.
2013-05-31 23:18:39 -04:00
Brett Cannon 0dbb4c7f13 Issues #18088, 18089: Introduce
importlib.abc.Loader.init_module_attrs() and implement
importlib.abc.InspectLoader.load_module().

The importlib.abc.Loader.init_module_attrs() method sets the various
attributes on the module being loaded. It is done unconditionally to
support reloading. Typically people used
importlib.util.module_for_loader, but since that's a decorator there
was no way to override it's actions, so init_module_attrs() came into
existence to allow for overriding. This is also why module_for_loader
is now pending deprecation (having its other use replaced by
importlib.util.module_to_load).

All of this allowed for importlib.abc.InspectLoader.load_module() to
be implemented. At this point you can now implement a loader with
nothing more than get_code() (which only requires get_source();
package support requires is_package()). Thanks to init_module_attrs()
the implementation of load_module() is basically a context manager
containing 2 methods calls, a call to exec(), and a return statement.
2013-05-31 18:56:47 -04:00
Brett Cannon 357c9fb055 Rename importlib.util.ModuleManager to module_to_load so that the name
explains better what the context manager is providing.
2013-05-30 17:31:47 -04:00
Brett Cannon 3dc48d6f69 Issue #18070: importlib.util.module_for_loader() now sets __loader__
and __package__ unconditionally in order to do the right thing for
reloading.
2013-05-28 18:35:54 -04:00
Brett Cannon f5fe13099e Update importlib.h 2013-05-28 17:50:04 -04:00
Brett Cannon a3687f0d68 Introduce importlib.util.ModuleManager which is a context manager to
handle providing (and cleaning up if needed) the module to be loaded.

A future commit will use the context manager in
Lib/importlib/_bootstrap.py and thus why the code is placed there
instead of in Lib/importlib/util.py.
2013-05-28 17:29:34 -04:00
Charles-Francois Natali 74ca886788 Issue #17917: Use PyModule_AddIntMacro() instead of PyModule_AddIntConstant()
when applicable.
2013-05-20 19:13:19 +02:00
Antoine Pitrou fef34e3186 Issue #17937: Try harder to collect cyclic garbage at shutdown. 2013-05-19 01:11:58 +02:00
Richard Oudkerk 25296ce5de Use PY_FORMAT_SIZE_T because Visual Studio does not understand %zd format. 2013-05-18 17:35:19 +01:00
Victor Stinner 84bb1cf994 Fix compilater warnings on Windows 64-bit 2013-05-17 00:12:04 +02:00
Victor Stinner 9ce59bbe43 Fix a compilater warning on Windows 64-bit 2013-05-17 00:04:56 +02:00
Victor Stinner d3dfd0e433 Fix a compilater warning on Windows 64-bit
idx variable is used for a tuple indexn so use Py_ssize_t (not int).
2013-05-16 23:48:01 +02:00
Victor Stinner 0b1bc56bb6 fix compilation on Windows 2013-05-16 22:17:17 +02:00
Benjamin Peterson e8e14591eb rather than passing locals to the class body, just execute the class body in the proper environment 2013-05-16 14:37:25 -05:00
Benjamin Peterson 1e93b06007 complain about "global __class__" in a class body (closes #17983) 2013-05-15 16:17:25 -05:00
Benjamin Peterson 312595ce3a hide the __class__ closure from the class body (#12370) 2013-05-15 15:26:42 -05:00
Benjamin Peterson e1b4cbc422 when arguments are cells clear the locals slot (backport of #17927) 2013-05-14 22:31:26 -05:00
Benjamin Peterson 159ae41da6 when an argument is a cell, set the local copy to NULL (see #17927) 2013-05-12 18:16:06 -05:00
Guido van Rossum 6832c81d5d #17927: Keep frame from referencing cell-ified arguments. 2013-05-10 08:47:42 -07:00
Charles-Francois Natali f28dfdd07b Issue #17912: Use a doubly linked-list for thread states. 2013-05-08 21:09:52 +02:00
Antoine Pitrou 070cb3c9be Issue #1545463: At shutdown, defer finalization of codec modules so that stderr remains usable.
(should fix Windows buildbot failures on test_gc)
2013-05-08 13:23:25 +02:00
Victor Stinner 22c103b3cc Fix a compiler warning: use unsigned int type instead of enum PyUnicode_Kind to
compare two Unicode kinds
2013-05-07 23:50:03 +02:00
Victor Stinner 313f10c722 Fix a compiler warning: in and out are unused in _Py_char2wchar() if
HAVE_MBRTOWC is not defined
2013-05-07 23:48:56 +02:00
Antoine Pitrou 5f454a07a0 Issue #1545463: Global variables caught in reference cycles are now garbage-collected at shutdown. 2013-05-06 21:15:57 +02:00
Antoine Pitrou 8408cea0cd Issue #17094: Clear stale thread states after fork().
Note that this is a potentially disruptive change since it may
release some system resources which would otherwise remain
perpetually alive (e.g. database connections kept in thread-local
storage).
2013-05-05 23:47:09 +02:00
Antoine Pitrou 4adb566ad7 Fix crash caused by 8c1385205a35
(thanks Arfrever for reporting).
2013-05-05 08:14:53 +02:00
Antoine Pitrou fd417cc54b Fix crash caused by 8c1385205a35
(thanks Arfrever for reporting).
2013-05-05 08:12:42 +02:00
Brett Cannon 13853a67cf #17115: I hate you MS for not supporting C99. 2013-05-04 17:37:09 -04:00
Antoine Pitrou df6931dbbc Issue #17408: Avoid using an obsolete instance of the copyreg module when the interpreter is shutdown and then started again. 2013-05-04 20:46:19 +02:00
Antoine Pitrou 957a23b088 Issue #17408: Avoid using an obsolete instance of the copyreg module when the interpreter is shutdown and then started again. 2013-05-04 20:45:02 +02:00
Brett Cannon 4c14b5de1c #17115,17116: Have modules initialize the __package__ and __loader__
attributes to None.

The long-term goal is for people to be able to rely on these
attributes existing and checking for None to see if they have been
set. Since import itself sets these attributes when a loader does not
the only instances when the attributes are None are from someone
overloading __import__() and not using a loader or someone creating a
module from scratch.

This patch also unifies module initialization. Before you could have
different attributes with default values depending on how the module
object was created. Now the only way to not get the same default set
of attributes is to circumvent initialization by calling
ModuleType.__new__() directly.
2013-05-04 13:56:58 -04:00
Alexandre Vassalotti 865eaa1b53 Closes #17892: Fix the name of _PyObject_CallMethodObjIdArgs 2013-05-02 10:44:04 -07:00
Benjamin Peterson 3b0431dc60 check local class namespace before reaching for cells (closes #17853) 2013-04-30 09:41:40 -04:00
Benjamin Peterson 0bb83f812f merge 3.3 (#17863) 2013-04-29 10:23:31 -04:00
Benjamin Peterson fe1b22af0a ignore errors when trying to fetch sys.stdin.encoding (closes #17863) 2013-04-29 10:23:08 -04:00
Benjamin Peterson 5c089314ef merge 3.3 2013-04-29 09:08:33 -04:00
Benjamin Peterson 7d110042c5 raise an ImportError (rather than fatal) when __import__ is not found in __builtins__ (closes #17867) 2013-04-29 09:08:14 -04:00
Antoine Pitrou 208ac5cf65 Issue #17832: fix a compilation warning about a function prototype.
Also, make the private function static.
2013-04-24 20:17:53 +02:00
R David Murray f097f175dd Merge #17413: make sure settrace funcs get passed exception instances for 'value'.
Patch by Ingrid Cheung and Brendan McLoughlin.
2013-04-19 12:57:54 -04:00
R David Murray 3583761bcd #17413: make sure settrace funcs get passed exception instances for 'value'.
Patch by Ingrid Cheung and Brendan McLoughlin.
2013-04-19 12:56:57 -04:00
Ezio Melotti 03a0c27569 Merge indentation fix from 3.3. 2013-04-19 07:10:45 +03:00
Ezio Melotti 1b6424fc4b Fix indentation. 2013-04-19 07:10:09 +03:00
Brett Cannon edfd6ae79c Issue #17244: Don't mask exceptions raised during the creation of
bytecode files in py_compile.

Thanks to Arfrever Frehtes Taifersar Arahesis for the bug report.
2013-04-14 12:48:15 -04:00
Benjamin Peterson 214a7d2674 properly lookup the __round__ special method (closes #17722) 2013-04-13 17:19:01 -04:00
Antoine Pitrou e9bbe8b87b Issue #15480: Remove the deprecated and unused TYPE_INT64 code from marshal.
Initial patch by Daniel Riti.
2013-04-13 22:41:09 +02:00
Brett Cannon 100883f0cb Issue #17093,17566,17567: Methods from classes in importlib.abc now raise/return
the default exception/value when called instead of raising/returning
NotimplementedError/NotImplemented (except where appropriate).
This should allow for the ABCs to act as the bottom/end of the MRO with expected
default results.

As part of this work, also make importlib.abc.Loader.module_repr()
optional instead of an abstractmethod.
2013-04-09 16:59:39 -04:00
Serhiy Storchaka ee57f159af Revert a premature patch for issue #14010 (changeset 846bd418aee5). 2013-04-06 22:55:12 +03:00
Serhiy Storchaka 278d03bd66 Revert a premature patch for issue #14010 (changeset aaaf36026511). 2013-04-06 22:52:34 +03:00
Antoine Pitrou 7d8c29a022 Issue #17645: convert an assert() into a proper exception in _Py_Mangle(). 2013-04-06 21:21:46 +02:00
Antoine Pitrou 55bff89190 Issue #17645: convert an assert() into a proper exception in _Py_Mangle(). 2013-04-06 21:21:04 +02:00
Serhiy Storchaka aac81e2780 Issue #14010: Fix a crash when iterating or deleting deeply nested filters
(builting and in itertools module, i.e. map(), itertools.chain(), etc).
2013-04-06 21:20:30 +03:00
Serhiy Storchaka e8f706eda7 Issue #14010: Fix a crash when iterating or deleting deeply nested filters
(builting and in itertools module, i.e. map(), itertools.chain(), etc).
2013-04-06 21:14:43 +03:00
Richard Oudkerk eea1f5c2e4 Merge 2013-04-03 13:49:36 +01:00
Richard Oudkerk 614c578dec Issue #17619: Make input() check for Ctrl-C correctly on Windows. 2013-04-03 13:44:50 +01:00
Victor Stinner eb4b5ac8af Close #16757: Avoid calling the expensive _PyUnicode_FindMaxChar() function
when possible
2013-04-03 02:02:33 +02:00
Brett Cannon daf4daa295 merge 2013-04-01 13:25:40 -04:00
Brett Cannon f8ffec0617 Issue #17357: Add missing verbosity messages when running under
-v/-vv that were lost in the transition to importlib.
2013-04-01 13:10:51 -04:00
Benjamin Peterson d0924b3d38 update importlib.h 2013-03-27 17:53:17 -04:00
Ezio Melotti 1f8898a591 #17323: The "[X refs, Y blocks]" printed by debug builds has been disabled by default. It can be re-enabled with the `-X showrefcount` option. 2013-03-26 01:59:56 +02:00
Gregory P. Smith d6f1d1647b Fixes issue4653 - Correctly specify the buffer size to FormatMessageW and
correctly check for errors on two CreateFileMapping calls.
2013-03-23 16:06:06 -07:00
Gregory P. Smith b803c6c4b8 Fixes issue4653 - Correctly specify the buffer size to FormatMessageW and
correctly check for errors on two CreateFileMapping calls.
2013-03-23 16:05:36 -07:00
Kristján Valur Jónsson 684cd0e643 Issue #17522: Add the PyGILState_Check() API. 2013-03-23 03:36:16 -07:00
Benjamin Peterson 440282ba8a copy 2.7 magic numbers for historical interest 2013-03-21 23:04:45 -05:00
Kristján Valur Jónsson 6168362509 Issue #16475 : Correctly handle the EOF when reading marshal streams. 2013-03-20 14:26:33 -07:00
Kristján Valur Jónsson e178187bf6 Issue #16475: Simplify the interface to r_ref_allocate and improve comments. 2013-03-20 11:43:57 -07:00
Benjamin Peterson eddb0a7884 fix compiler warning 2013-03-20 00:40:07 -05:00
Benjamin Peterson 605a774a98 Backed out changeset 521232b05b97 2013-03-20 00:39:41 -05:00
Benjamin Peterson c6dc12484b fix compiler warning 2013-03-19 23:20:59 -05:00
Kristján Valur Jónsson dc32d18d11 Issue #15038 : Fixing the condition broadcast and docs. 2013-03-19 20:18:37 -07:00
Kristján Valur Jónsson 32ecccaf63 Issue #15038 : Fixing the condition broadcast and docs. 2013-03-19 20:18:37 -07:00
Kristján Valur Jónsson d7009c6913 Issue #16475: Support object instancing, recursion and interned strings
in marshal
2013-03-19 18:02:10 -07:00
Benjamin Peterson 3a61943b7b bump Python-ast.c 2013-03-18 23:40:53 -07:00
Benjamin Peterson b72406b8fa refactor to fix refleaks 2013-03-18 23:24:41 -07:00
Benjamin Peterson 6fba3dbce0 sprinkle const 2013-03-18 23:13:31 -07:00
Benjamin Peterson aad1d87339 move declaration to top of block 2013-03-18 10:59:41 -07:00
Benjamin Peterson cda75be02a unify some ast.argument's attrs; change Attribute column offset (closes #16795)
Patch from Sven Brauch.
2013-03-18 10:48:58 -07:00
Benjamin Peterson aa14dc3b4e C89 compliance 2013-03-16 15:38:28 -07:00
Benjamin Peterson 2d6acd2ac2 reject non-docs strings between future imports (closes #17434) 2013-03-16 09:15:47 -07:00
Benjamin Peterson 7701e6ef93 make some freezing related stuff const 2013-03-13 14:06:39 -05:00
Brett Cannon 4802becb16 Issue #17117: Have both import itself and importlib.util.set_loader()
set __loader__ on a module when set to None.

Thanks to Gökcen Eraslan for the fix.
2013-03-13 10:41:36 -07:00
Ezio Melotti 04a29554c1 #17032: The "global" in the "NameError: global name 'x' is not defined" error message has been removed. Patch by Ram Rachum. 2013-03-03 15:12:44 +02:00
Brett Cannon c190389834 Issue #17220: two fixes for changeset 2528e4aea338.
First, because the mtime can exceed 4 bytes, make sure to mask it down to 4
bytes before getting its little-endian representation for writing out to a .pyc
file.

Two, cap an rsplit() call to 1 split, else can lead to too many values being
returned for unpacking.
2013-02-25 17:10:11 -05:00
Serhiy Storchaka 39e47f94ec Issue #17220: Little cleanup of _bootstrap.py. 2013-02-25 15:40:33 +02:00
Ezio Melotti 92bd4ef640 Merge importlib.h rebuild from 3.3 after the changes introduced in 65eaac000147. 2013-02-20 22:15:47 +02:00
Ezio Melotti 795c10b3b6 Rebuild importlib.h after the changes introduced in 0f65bf6063ca. 2013-02-20 21:42:46 +02:00
Antoine Pitrou 7056cb2867 Issue #17170: speed up PyArg_ParseTuple[AndKeywords] a bit. 2013-02-17 01:04:57 +01:00
Ezio Melotti 178e6fef9e #17178: merge with 3.3. 2013-02-15 23:38:23 +02:00
Ezio Melotti 293ab9728a #17178: merge with 3.2. 2013-02-15 23:38:05 +02:00
Ezio Melotti b19ed57d8d #17178: update any()/all() docstrings to document their behavior with empty iterables. Patch by Ankur Ankan. 2013-02-15 23:35:14 +02:00
Serhiy Storchaka 0c15b5d897 Issue #5308: Raise ValueError when marshalling too large object (a sequence
with size >= 2**31), instead of producing illegal marshal data.
2013-02-13 12:12:11 +02:00
Serhiy Storchaka 5a1f152d19 Issue #5308: Raise ValueError when marshalling too large object (a sequence
with size >= 2**31), instead of producing illegal marshal data.
2013-02-13 12:11:03 +02:00
Serhiy Storchaka 7e0191170e Issue #5308: Raise ValueError when marshalling too large object (a sequence
with size >= 2**31), instead of producing illegal marshal data.
2013-02-13 12:08:15 +02:00
Serhiy Storchaka b8cbba5877 Issue #12983: Bytes literals with invalid \x escape now raise a SyntaxError
and a full traceback including line number.
2013-02-10 17:43:25 +02:00
Serhiy Storchaka 801d955f04 Issue #12983: Bytes literals with invalid \x escape now raise a SyntaxError
and a full traceback including line number.
2013-02-10 17:42:01 +02:00
Serhiy Storchaka 5e61f14c6d Issue #12983: Bytes literals with invalid \x escape now raise a SyntaxError
and a full traceback including line number.
2013-02-10 17:36:00 +02:00
Benjamin Peterson 419d9a83d5 evaluate lambda keyword-only defaults after positional defaults (#16967 again) 2013-02-10 09:48:22 -05:00
Benjamin Peterson 1ef876cd28 evaluate positional defaults before keyword-only defaults (closes #16967) 2013-02-10 09:29:59 -05:00
Antoine Pitrou 8ad5b07ccb Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.) in the interpreter.
I've left a couple of them in: zlib (third-party lib), getaddrinfo.c
(doesn't include Python.h, and probably obsolete), _sre.c (legitimate
use for the re.LOCALE flag), mpdecimal (needs to build without Python.h).
2013-02-09 23:16:51 +01:00
Antoine Pitrou c73c561181 Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.) in the interpreter.
I've left a couple of them in: zlib (third-party lib), getaddrinfo.c
(doesn't include Python.h, and probably obsolete), _sre.c (legitimate
use for the re.LOCALE flag), mpdecimal (needs to build without Python.h).
2013-02-09 23:14:42 +01:00
Antoine Pitrou 4de7457009 Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.) in the interpreter.
I've left a couple of them in: zlib (third-party lib), getaddrinfo.c
(doesn't include Python.h, and probably obsolete), _sre.c (legitimate
use for the re.LOCALE flag).
2013-02-09 23:11:27 +01:00
Brett Cannon 85ae3566d1 Merge w/ 3.3 more fixes thanks to issue #17098 2013-02-01 16:36:29 -05:00
Brett Cannon da9cf0eef8 Issue #17098: Be more stringent of setting __loader__ on early imported
modules. Also made test more rigorous.
2013-02-01 15:31:49 -05:00
Brett Cannon 0ecd30b4af Issue #17098: Make sure every module has __loader__ defined.
Thanks to Thomas Heller for the bug report.
2013-02-01 14:04:12 -05:00
Brett Cannon f3220d6af7 Tweak an exception message 2013-01-27 13:04:56 -05:00