summaryrefslogtreecommitdiff
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
...
* bpo-9263: _PyXXX_CheckConsistency() use _PyObject_ASSERT() (GH-10108)Victor Stinner2018-10-263-52/+64
| | | | | | | | | | Use _PyObject_ASSERT() in: * _PyDict_CheckConsistency() * _PyType_CheckConsistency() * _PyUnicode_CheckConsistency() _PyObject_ASSERT() dumps the faulty object if the assertion fails to help debugging.
* bpo-9263: Use _PyObject_ASSERT() in typeobject.c (GH-10111)Victor Stinner2018-10-261-10/+13
| | | | Replace assert() with _PyObject_ASSERT() in Objects/typeobject.c to dump the faulty object on assertion failure to ease debugging.
* bpo-9263: Use _PyObject_ASSERT() in object.c (GH-10110)Victor Stinner2018-10-261-18/+22
| | | | Replace assert() with _PyObject_ASSERT() in Objects/object.c to dump the faulty object on assertion failure to ease debugging.
* bpo-35059: Convert PyObject_INIT() to function (GH-10077)Victor Stinner2018-10-266-9/+9
| | | | | * Convert PyObject_INIT() and PyObject_INIT_VAR() macros to static inline functions. * Fix usage of these functions: cast to PyObject* or PyVarObject*.
* bpo-9263: _Py_NegativeRefcount() use _PyObject_AssertFailed() (GH-10109)Victor Stinner2018-10-261-8/+5
| | | | _Py_NegativeRefcount() now uses _PyObject_AssertFailed() to dump the object to help debugging.
* bpo-9263: Dump Python object on GC assertion failure (GH-10062)Victor Stinner2018-10-251-0/+52
| | | | | | | | | | | | | | | | | | | | | | | Changes: * Add _PyObject_AssertFailed() function. * Add _PyObject_ASSERT() and _PyObject_ASSERT_WITH_MSG() macros. * gc_decref(): replace assert() with _PyObject_ASSERT_WITH_MSG() to dump the faulty object if the assertion fails. _PyObject_AssertFailed() calls: * _PyMem_DumpTraceback(): try to log the traceback where the object memory has been allocated if tracemalloc is enabled. * _PyObject_Dump(): log repr(obj). * Py_FatalError(): log the current Python traceback. _PyObject_AssertFailed() uses _PyObject_IsFreed() heuristic to check if the object memory has been freed by a debug hook on Python memory allocators. Initial patch written by David Malcolm. Co-Authored-By: David Malcolm <dmalcolm@redhat.com>
* bpo-35059: Add Py_STATIC_INLINE() macro (GH-10093)Victor Stinner2018-10-251-2/+2
| | | | | | | | | * Add Py_STATIC_INLINE() macro to declare a "static inline" function. If the compiler supports it, try to always inline the function even if no optimization level was specified. * Modify pydtrace.h to use Py_STATIC_INLINE() when WITH_DTRACE is not defined. * Add an unit test on Py_DECREF() to make sure that _Py_NegativeRefcount() reports the correct filename.
* bpo-35053: Enhance tracemalloc to trace free lists (GH-10063)Victor Stinner2018-10-252-0/+9
| | | | | | | | | | | | tracemalloc now tries to update the traceback when an object is reused from a "free list" (optimization for faster object creation, used by the builtin list type for example). Changes: * Add _PyTraceMalloc_NewReference() function which tries to update the Python traceback of a Python object. * _Py_NewReference() now calls _PyTraceMalloc_NewReference(). * Add an unit test.
* bpo-30863: Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(). ↵Serhiy Storchaka2018-10-231-123/+121
| | | | | | (GH-2599) They no longer cache the wchar_t* representation of string objects.
* bpo-9263: _PyObject_Dump() detects freed memory (GH-10061)Victor Stinner2018-10-232-23/+71
| | | | | | | | | _PyObject_Dump() now uses an heuristic to check if the object memory has been freed: log "<freed object>" in that case. The heuristic rely on the debug hooks on Python memory allocators which fills the memory with DEADBYTE (0xDB) when memory is deallocated. Use PYTHONMALLOC=debug to always enable these debug hooks.
* Fix issue 34551 - remove redundant store (#9009)Eric Lippert2018-10-221-1/+1
| | | The assignment of i/2 to nk is redundant because on this code path, nk is already the size of the dictionary, and i is already twice the size of the dictionary. I've replaced the store with an assertion that i/2 is nk.
* bpo-34984: Improve error messages for bytes and bytearray constructors. ↵Serhiy Storchaka2018-10-212-6/+23
| | | | (GH-9874)
* bpo-34973: Fix crash in bytes constructor. (GH-9841)Serhiy Storchaka2018-10-211-35/+69
| | | Constructing bytes from mutating list could cause a crash.
* bpo-34574: Prevent OrderedDict iterators from exhaustion during pickling. ↵Sergey Fedoseev2018-10-201-28/+9
| | | | (GH-9051)
* bpo-34573: Simplify __reduce__() of set and dict iterators. (GH-9050)Sergey Fedoseev2018-10-202-59/+7
| | | | Simplify the pickling of set and dictionary objects iterators by consuming the iterator into a list with PySequence_List.
* bpo-33712: OrderedDict only creates od_fast_nodes cache if needed (GH-7349)Serhiy Storchaka2018-10-201-50/+18
|
* bpo-33073: Rework int.as_integer_ratio() implementation (GH-9303)Serhiy Storchaka2018-10-191-6/+1
| | | | | * Simplify the C code. * Simplify tests and make them more strict and robust. * Add references in the documentation.
* bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). ↵Serhiy Storchaka2018-10-152-3/+5
| | | | | | | (GH-9852) bytes and bytearray constructors converted unexpected exceptions (e.g. MemoryError and KeyboardInterrupt) to TypeError.
* bpo-34940: Fix the error handling in _check_for_legacy_statements(). (GH-9764)Zackery Spytz2018-10-121-8/+18
|
* Micro-optimize list index range checks (GH-9784)Raymond Hettinger2018-10-101-5/+18
|
* Add missing closing quote and trailing period in str.isidentifier() ↵Emanuele Gaifas2018-10-082-4/+4
| | | | | docstring (GH-9756) This rectifies commit ffc5a14d00db984c8e72c7b67da8a493e17e2c14.
* bpo-33014: Clarify str.isidentifier docstring (GH-6088)Sanyam Khurana2018-10-082-6/+6
| | | | | | * bpo-33014: Clarify str.isidentifier docstring * bpo-33014: Add code example in isidentifier documentation
* bpo-34910: Ensure that PyObject_Print() always returns -1 on error. (GH-9733)Zackery Spytz2018-10-061-2/+3
|
* bpo-34899: Fix a possible assertion failure due to int_from_bytes_impl() ↵Zackery Spytz2018-10-061-1/+1
| | | | | | | (GH-9705) The _PyLong_FromByteArray() call in int_from_bytes_impl() was unchecked.
* bpo-34879: Fix a possible null pointer dereference in bytesobject.c (GH-9683)Zackery Spytz2018-10-031-1/+1
| | | | | formatfloat() was not checking if PyBytes_FromStringAndSize() failed, which could lead to a null pointer dereference in _PyBytes_FormatEx().
* bpo-30156: Remove property_descr_get() optimization (GH-9541)Victor Stinner2018-10-011-28/+5
| | | | | | | | | | | | | | | | property_descr_get() uses a "cached" tuple to optimize function calls. But this tuple can be discovered in debug mode with sys.getobjects(). Remove the optimization, it's not really worth it and it causes 3 different crashes last years. Microbenchmark: ./python -m perf timeit -v \ -s "from collections import namedtuple; P = namedtuple('P', 'x y'); p = P(1, 2)" \ --duplicate 1024 "p.x" Result: Mean +- std dev: [ref] 32.8 ns +- 0.8 ns -> [patch] 40.4 ns +- 1.3 ns: 1.23x slower (+23%)
* bpo-34320: Fix dict(o) didn't copy order of dict subclass (GH-8624)INADA Naoki2018-09-251-1/+3
| | | | | | | When dict subclass overrides order (`__iter__()`, `keys()`, and `items()`), `dict(o)` should use it instead of dict ordering. https://bugs.python.org/issue34320
* Fix compiler warning with a type cast (GH-9300)Raymond Hettinger2018-09-141-1/+1
|
* Fix-up parenthesis, organization, and NULL check (GH-9297)Raymond Hettinger2018-09-141-6/+11
|
* bpo-33073: Adding as_integer_ratio to ints. (GH-8750)Lisa Roach2018-09-132-1/+60
|
* closes bpo-34646: Remove PyAPI_* macros from declarations. (GH-9218)Benjamin Peterson2018-09-122-2/+2
|
* bpo-1621: Avoid signed integer overflow in set_table_resize(). (GH-9059)Sergey Fedoseev2018-09-111-8/+3
| | | | | | | | Address a C undefined behavior signed integer overflow issue in set object table resizing. Our -fwrapv compiler flag and practical reasons why sets are unlikely to get this large should mean this was never an issue but it was incorrect code that generates code analysis warnings. <!-- issue-number: [bpo-1621](https://www.bugs.python.org/issue1621) --> https://bugs.python.org/issue1621 <!-- /issue-number -->
* Revert "bpo-34595: Add %T format to PyUnicode_FromFormatV() (GH-9080)" (GH-9187)Victor Stinner2018-09-121-52/+53
| | | This reverts commit 886483e2b9bbabf60ab769683269b873381dd5ee.
* Fix misleading mentions of tp_size in comments (GH-9093)Peter Eisentraut2018-09-102-3/+3
| | | | Many type object initializations labeled a field "tp_size" in the comment, but the name of that field is tp_basicsize.
* bpo-34595: Add %T format to PyUnicode_FromFormatV() (GH-9080)Victor Stinner2018-09-071-53/+52
| | | | | | | | | * Add %T format to PyUnicode_FromFormatV(), and so to PyUnicode_FromFormat() and PyErr_Format(), to format an object type name: equivalent to "%s" with Py_TYPE(obj)->tp_name. * Replace Py_TYPE(obj)->tp_name with %T format in unicodeobject.c. * Add unit test on %T format. * Rename unicode_fromformat_write_cstr() to unicode_fromformat_write_utf8(), to make the intent more explicit.
* bpo-25750: fix refcounts in type_getattro() (GH-6118)jdemeyer2018-09-071-6/+11
| | | | When calling tp_descr_get(self, obj, type), make sure that we own a strong reference to "self".
* closes bpo-34599: Improve performance of _Py_bytes_capitalize(). (GH-9083)Sergey Fedoseev2018-09-061-17/+3
|
* bpo-34523: Support surrogatepass in locale codecs (GH-8995)Victor Stinner2018-08-292-73/+102
| | | | | | | | | | | | | | | | | | | | Add support for the "surrogatepass" error handler in PyUnicode_DecodeFSDefault() and PyUnicode_EncodeFSDefault() for the UTF-8 encoding. Changes: * _Py_DecodeUTF8Ex() and _Py_EncodeUTF8Ex() now support the surrogatepass error handler (_Py_ERROR_SURROGATEPASS). * _Py_DecodeLocaleEx() and _Py_EncodeLocaleEx() now use the _Py_error_handler enum instead of "int surrogateescape" to pass the error handler. These functions now return -3 if the error handler is unknown. * Add unit tests on _Py_DecodeLocaleEx() and _Py_EncodeLocaleEx() in test_codecs. * Rename get_error_handler() to _Py_GetErrorHandler() and expose it as a private function. * _freeze_importlib doesn't need config.filesystem_errors="strict" workaround anymore.
* bpo-34523: Add _PyCoreConfig.filesystem_encoding (GH-8963)Victor Stinner2018-08-291-24/+18
| | | | | | | | | | | | | | | | | | | | | | | _PyCoreConfig_Read() is now responsible to choose the filesystem encoding and error handler. Using Py_Main(), the encoding is now chosen even before calling Py_Initialize(). _PyCoreConfig.filesystem_encoding is now the reference, instead of Py_FileSystemDefaultEncoding, for the Python filesystem encoding. Changes: * Add filesystem_encoding and filesystem_errors to _PyCoreConfig * _PyCoreConfig_Read() now reads the locale encoding for the file system encoding. * PyUnicode_EncodeFSDefault() and PyUnicode_DecodeFSDefaultAndSize() now use the interpreter configuration rather than Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors global configuration variables. * Add _Py_SetFileSystemEncoding() and _Py_ClearFileSystemEncoding() private functions to only modify Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors in coreconfig.c. * _Py_CoerceLegacyLocale() now takes an int rather than _PyCoreConfig for the warning.
* closes bpo-34504: Remove the useless NULL check in PySequence_Check(). (GH-8935)Alexey Izbyshev2018-08-251-1/+1
| | | Reported by Svace static analyzer.
* closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before ↵Alexey Izbyshev2018-08-251-4/+9
| | | | | dereferencing it. (GH-8930) Reported by Svace static analyzer.
* closes bpo-34493: Objects/genobject.c: Add missing NULL check to ↵Alexey Izbyshev2018-08-251-0/+3
| | | | compute_cr_origin() (GH-8911)
* closes bpo-34468: Objects/rangeobject.c: Fix an always-false condition in ↵Alexey Izbyshev2018-08-231-4/+4
| | | | | | | | range_repr() (GH-8880) Also, propagate the error from PyNumber_AsSsize_t() because we don't care only about OverflowError which is not reported if the second argument is NULL. Reported by Svace static analyzer.
* closes bpo-34477: Objects/typeobject.c: Add missing NULL check to ↵Alexey Izbyshev2018-08-231-0/+3
| | | | | type_init() (GH-8876) Reported by Svace static analyzer.
* bpo-34436: Fix check that disables overallocation for the last fmt specifier ↵Alexey Izbyshev2018-08-231-3/+3
| | | | | (GH-8826) Reported by Svace static analyzer.
* bpo-34435: Add missing NULL check to unicode_encode_ucs1(). (GH-8823)Alexey Izbyshev2018-08-191-2/+3
| | | Reported by Svace static analyzer.
* bpo-22602: Raise an exception in the UTF-7 decoder for ill-formed sequences ↵Zackery Spytz2018-08-191-0/+5
| | | | | | | starting with "+". (GH-8741) The UTF-7 decoder now raises UnicodeDecodeError for ill-formed sequences starting with "+" (as specified in RFC 2152).
* bpo-34151: Improve performance of some list operations (GH-8332)Sergey Fedoseev2018-08-111-15/+36
|
* bpo-34301: Add _PyInterpreterState_Get() helper function (GH-8592)Victor Stinner2018-08-036-10/+10
| | | | sys_setcheckinterval() now uses a local variable to parse arguments, before writing into interp->check_interval.
* bpo-1617161: Make the hash and equality of methods not depending on the ↵Serhiy Storchaka2018-07-313-37/+20
| | | | | | | | | | | value of self. (GH-7848) * The hash of BuiltinMethodType instances no longer depends on the hash of __self__. It depends now on the hash of id(__self__). * The hash and equality of ModuleType and MethodWrapperType instances no longer depend on the hash and equality of __self__. They depend now on the hash and equality of id(__self__). * MethodWrapperType instances no longer support ordering.