Commit Graph

4681 Commits

Author SHA1 Message Date
Victor Stinner 5b3b1006bb Issue #18520: Fix _PyDict_GetItemId(), suppress _PyUnicode_FromId() error
As PyDict_GetItem(), _PyDict_GetItemId() suppresses all errors that may occur,
for historical reasons.
2013-07-22 23:50:57 +02:00
Victor Stinner 34f96b8dd3 Issue #18520: Fix PyFunction_NewWithQualName() error handling 2013-07-22 23:04:55 +02:00
Victor Stinner 4d1f5d6eee Reindent PyFunction_NewWithQualName() 2013-07-22 23:02:05 +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 6895947570 Propagate error when PyByteArray_Resize() fails in bytearray_translate()
CID 715334
2013-07-21 02:04:44 +02:00
Christian Heimes c731bbe665 Propagate error when PyByteArray_Resize() fails in bytearray_translate()
CID 715334
2013-07-21 02:04:35 +02:00
Christian Heimes b578735dff Check return value of PyType_Ready(&EncodingMapType)
CID 486654
2013-07-20 14:57:28 +02:00
Christian Heimes 26532f7519 Check return value of PyType_Ready(&EncodingMapType)
CID 486654
2013-07-20 14:57:16 +02:00
Christian Heimes de4d183955 Issue #18327: Fix argument order in call to compatible_for_assignment(oldto, newto, attr).
The fix only affects the error message of __class__ assignment. CID 983564
2013-07-20 14:19:46 +02:00
Victor Stinner 2c40f640d9 Issue #18408: Fix list_ass_slice(), handle list_resize() failure
I tested the patch manually by injecting a fault using gdb: list items are
correctly restored on failure.
2013-07-19 23:06:21 +02:00
Victor Stinner 8e47832737 Issue #18408: PyObject_Str(), PyObject_Repr() and type_call() now fail with an
assertion error if they are called with an exception set (PyErr_Occurred()).

As PyEval_EvalFrameEx(), they may clear the current exception and so the caller
looses its exception.
2013-07-18 01:49:30 +02:00
Victor Stinner f97dfd7b59 Issue #18408: Fix dict_repr(), don't call PyObject_Repr() with an exception set
PyObject_Repr() can removes the current exception. For example, module_repr()
calls PyErr_Clear() if calling loader.module_repr(mod) failed.
2013-07-18 01:00:45 +02:00
Victor Stinner 08a80b11ad longobject.c: add an assertion to ensure that MEDIUM_VALUE() is only called on
small integers (0 or 1 digit)
2013-07-17 22:33:42 +02:00
Victor Stinner 8aed6f1c7d Issue #18408: Rewrite NEGATE() macro in longobject.c to handle PyLong_FromLong() failure 2013-07-17 22:31:17 +02:00
Victor Stinner 5967bf4928 Issue #18408: Fix PyType_Ready(), handle _PyDict_SetItemId() failure 2013-07-17 22:01:37 +02:00
Victor Stinner e901d1fbdf Issue #18408: Fix Py_ReprEnter(), handle PyList_Append() failure 2013-07-17 21:58:41 +02:00
Victor Stinner 095d99ffff Issue #18408: Fix listpop(), handle list_ass_slice() failure 2013-07-17 21:58:01 +02:00
Victor Stinner 9a146eeadb Issue #18408: Fix structseq_reduce(), handle PyDict_SetItemString() failure 2013-07-17 13:41:39 +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 3997cfdb7f Cleanup type_call() to ease debug
It was easy to miss the call to type->tp_init because it was done in a long
conditional expression. Split the long expression in multiple lines to make the
debug step by step easier.
2013-07-16 22:51:21 +02:00
Victor Stinner 1b63493ed1 Issue #18408: Py_ReprLeave() now saves/restores the current exception,
and ignores exceptions raised during the call
2013-07-16 22:24:44 +02:00
Victor Stinner ac2a4fe8a2 Issue #18408: dict_new() now fails on new_keys_object() error
Pass the MemoryError exception to the caller, instead of using empty keys.
2013-07-16 22:19:00 +02:00
Victor Stinner a9f61a5a23 Cleanup dictobject.c 2013-07-16 22:17:26 +02:00
Victor Stinner fdcbab9602 Issue #18408: Fix PyDict_GetItemString(), suppress PyUnicode_FromString() error
As PyDict_GetItem(), PyDict_GetItemString() suppresses all errors that may
occur for historical reasons.
2013-07-16 22:16:05 +02:00
Victor Stinner 32fd6eab1e Issue #18408: Fix list.extend(), handle list_resize() failure 2013-07-16 21:45:58 +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 53510cda59 Issue #18408: type_new() and PyType_FromSpecWithBases() now raise MemoryError
on memory allocation failure
2013-07-15 19:34:20 +02:00
Victor Stinner e699e5a218 Issue #18408: Don't check unicode consistency in _PyUnicode_HAS_UTF8_MEMORY()
and _PyUnicode_HAS_WSTR_MEMORY() macros

These macros are called in unicode_dealloc(), whereas the unicode object can be
"inconsistent" if the creation of the object failed.

For example, when unicode_subtype_new() fails on a memory allocation,
_PyUnicode_CheckConsistency() fails with an assertion error because data is
NULL.
2013-07-15 18:22:47 +02:00
Victor Stinner 3de5869864 Issue #18408: PyObject_Call() now fails with an assertion error in debug mode
if the function called failed whereas no exception was raised, to detect bugs
earlier.
2013-07-15 17:50:07 +02:00
Victor Stinner a41f085144 Issue #18408: pmerge() help of mro_implementation() now raises MemoryError on
memory allocation failure

Replace also PyMem_Free() with PyMem_FREE() to be consistent with the rest of
the function.
2013-07-12 00:42:14 +02:00
Victor Stinner 9035ad932b Issue #18408: In debug mode, PyCFunction_Call() now checks if an exception was
raised if the result is NULL to help to find bugs in C mode (get the error
earlier than the SystemError in ceval.c).
2013-07-11 23:44:46 +02:00
Victor Stinner 2e8474ddde Issue #18408: slot_tp_str() must not fallback on slot_tp_repr() on error
type->tp_str must not point to slot_tp_str() if type has no __str__ attribute,
so there is no reason for slot_tp_str() to fallback on slot_tp_str() on lookup
error. Moreover, calling PyErr_Clear() may hide a real bug like MemoryError.

If __str__ attribute is removed, slots must be updated (which is done by
type_setattro()).
2013-07-11 22:46:11 +02:00
Victor Stinner 54e4ca76c9 typeobject.c: remove trailing spaces 2013-07-11 22:42:25 +02:00
Victor Stinner c4266360fc Issue #18408: Fix _PyMem_DebugRealloc()
Don't mark old extra memory dead before calling realloc(). realloc() can fail
and realloc() must not touch the original buffer on failure.

So mark old extra memory dead only on success if the new buffer did not move
(has the same address).
2013-07-09 00:44:43 +02:00
Victor Stinner 9e6b4d715c Issue #18408: _PyUnicodeWriter_Finish() now clears its buffer attribute in all
cases, so _PyUnicodeWriter_Dealloc() can be called after finish.
2013-07-09 00:37:24 +02:00
Victor Stinner 15a0bd3965 Issue #18408: Fix _PyUnicodeWriter_Finish(): clear writer->buffer,
so _PyUnicodeWriter_Dealloc() can be called on the writer after finish.
2013-07-08 22:29:55 +02:00
Victor Stinner 9812af8e72 Issue #18408: Fix PyType_Ready() and type.__bases__ setter to handle
PyWeakref_NewRef() failure (ex: MemoryError).
2013-07-08 22:25:48 +02:00
Victor Stinner b27cd3e5ad Issue #18408: Fix list.pop() to handle list_resize() failure (MemoryError). 2013-07-08 22:20:44 +02:00
Victor Stinner c9b7f51ec2 Issue #18408: Fix PyDict_New() to handle correctly new_keys_object() failure
(MemoryError).
2013-07-08 22:19:20 +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 6f8eeee7b9 Issue #18203: Fix _Py_DecodeUTF8_surrogateescape(), use PyMem_RawMalloc() as _Py_char2wchar() 2013-07-07 22:57:45 +02:00
Victor Stinner 0e2d3cf2cb Issue #18203: Replace malloc() with PyMem_Malloc() in _PySequence_BytesToCharpArray() 2013-07-07 17:22:41 +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 725e668ac8 Issue #3329: Fix _PyObject_ArenaVirtualFree()
According to VirtualFree() documentation, the size must be zero if the "free
type" is MEM_RELEASE.
2013-07-07 03:06:16 +02:00
Victor Stinner 0507bf56f0 Issue #3329: Implement the PEP 445
Add new enum:

* PyMemAllocatorDomain

Add new structures:

* PyMemAllocator
* PyObjectArenaAllocator

Add new functions:

* PyMem_RawMalloc(), PyMem_RawRealloc(), PyMem_RawFree()
* PyMem_GetAllocator(), PyMem_SetAllocator()
* PyObject_GetArenaAllocator(), PyObject_SetArenaAllocator()
* PyMem_SetupDebugHooks()

Changes:

* PyMem_Malloc()/PyObject_Realloc() now always call malloc()/realloc(), instead
  of calling PyObject_Malloc()/PyObject_Realloc() in debug mode.
* PyObject_Malloc()/PyObject_Realloc() now falls back to
  PyMem_Malloc()/PyMem_Realloc() for allocations larger than 512 bytes.
* Redesign debug checks on memory block allocators as hooks, instead of using C
  macros
2013-07-07 02:05:46 +02:00
Brett Cannon 679ecb565b Issue #15767: back out 8a0ed9f63c6e, finishing the removal of
ModuleNotFoundError.
2013-07-04 17:51:50 -04:00
Christian Heimes d47802eef7 Fix ref leak in error case of unicode find, count, formatlong
CID 983315: Resource leak (RESOURCE_LEAK)
CID 983316: Resource leak (RESOURCE_LEAK)
CID 983317: Resource leak (RESOURCE_LEAK)
2013-06-29 21:33:36 +02:00
Christian Heimes d47a0456b1 Fix ref leak in error case of unicode index
CID 983319 (#1 of 2): Resource leak (RESOURCE_LEAK)
leaked_storage: Variable substring going out of scope leaks the storage it points to.
2013-06-29 21:21:37 +02:00
Christian Heimes ea71a525c3 Fix ref leak in error case of unicode rindex and rfind
CID 983320: Resource leak (RESOURCE_LEAK)
CID 983321: Resource leak (RESOURCE_LEAK)
leaked_storage: Variable substring going out of scope leaks the storage it points to.
2013-06-29 21:17:34 +02:00
Christian Heimes 305e49e17e Fix memory leak in endswith
CID 1040368 (#1 of 1): Resource leak (RESOURCE_LEAK)
leaked_storage: Variable substring going out of scope leaks the storage it points to.
2013-06-29 20:41:06 +02:00