summaryrefslogtreecommitdiffstats
path: root/Objects/weakrefobject.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-99537: Use Py_SETREF() function in C code (#99657)Victor Stinner2022-11-221-4/+2
| | | | | | | | | | | | | | | Fix potential race condition in code patterns: * Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);" * Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);" * Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);" Other changes: * Replace "old = var; var = new; Py_DECREF(var)" with "Py_SETREF(var, new);" * Replace "old = var; var = new; Py_XDECREF(var)" with "Py_XSETREF(var, new);" * And remove the "old" variable.
* gh-99300: Use Py_NewRef() in Objects/ directory (#99354)Victor Stinner2022-11-101-8/+4
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Objects/ directory.
* gh-94673: Add Per-Interpreter tp_weaklist for Static Builtin Types (#95302)Eric Snow2022-07-291-0/+19
| | | | | | | | | | | | | | | * Store tp_weaklist on the interpreter state for static builtin types. * Factor out _PyStaticType_GET_WEAKREFS_LISTPTR(). * Add _PyStaticType_ClearWeakRefs(). * Add a comment about how _PyStaticType_ClearWeakRefs() loops. * Document the change. * Update Doc/whatsnew/3.12.rst * Fix a typo.
* gh-95324: Emit a warning if an object doesn't call PyObject_GC_UnTrack ↵Pablo Galindo Salgado2022-07-271-0/+1
| | | | during deallocation in debug mode (#95325)
* gh-79512: Fixed names and __module__ value of weakref classes (GH-93719)Serhiy Storchaka2022-06-141-3/+3
| | | | | Classes ReferenceType, ProxyType and CallableProxyType have now correct atrtributes __module__, __name__ and __qualname__. It makes them (types, not instances) pickleable.
* bpo-46541: Discover the global strings. (gh-31346)Eric Snow2022-02-151-2/+2
| | | | | | | Instead of manually enumerating the global strings in generate_global_objects.py, we extrapolate the list from usage of _Py_ID() and _Py_STR() in the source files. This is partly inspired by gh-31261. https://bugs.python.org/issue46541
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | global objects. (gh-30928) We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
* bpo-40170: PyType_SUPPORTS_WEAKREFS() becomes a regular function (GH-30938)Victor Stinner2022-01-271-4/+4
| | | | | | | | Convert the PyType_SUPPORTS_WEAKREFS() macro to a regular function. It no longer access the PyTypeObject.tp_weaklistoffset member directly. Add _PyType_SUPPORTS_WEAKREFS() static inline functions, used internally by Python for best performance.
* bpo-46481: Implement vectorcall for weakref.ref.__call__ method. (GH-30820)Dong-hee Na2022-01-231-50/+30
|
* Clean up initialization __class_getitem__ with Py_GenericAlias. (GH-28450)Serhiy Storchaka2021-09-191-1/+1
| | | | | The cast to PyCFunction is redundant. Overuse of redundant casts can hide actual bugs.
* bpo-44720: Don't crash when calling weakref.proxy(not_an_iterator).__next__ ↵Dennis Sweeney2021-07-241-0/+6
| | | | (GH-27316)
* bpo-44523: Remove the pass-through for hash() in weakref proxy objects ↵Pablo Galindo2021-06-291-16/+2
| | | | (GH-26950)
* bpo-40523: Add pass-throughs for hash() and reversed() to weakref.proxy ↵Pablo Galindo2020-05-051-1/+18
| | | | objects (GH-19946)
* bpo-40268: Remove unused structmember.h includes (GH-19530)Victor Stinner2020-04-151-2/+2
| | | | | | If only offsetof() is needed: include stddef.h instead. When structmember.h is used, add a comment explaining that PyMemberDef is used.
* bpo-39481: Make weakref and WeakSet generic (GH-19497)Ethan Smith2020-04-141-1/+7
|
* bpo-40170: PyObject_GET_WEAKREFS_LISTPTR() becomes a function (GH-19377)Victor Stinner2020-04-061-1/+2
| | | | | | | | Convert the PyObject_GET_WEAKREFS_LISTPTR() macro to a function to hide implementation details: the macro accessed directly to the PyTypeObject.tp_weaklistoffset member. Add _PyObject_GET_WEAKREFS_LISTPTR() static inline function to the internal C API.
* bpo-39245: Switch to public API for Vectorcall (GH-18460)Petr Viktorin2020-02-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The bulk of this patch was generated automatically with: for name in \ PyObject_Vectorcall \ Py_TPFLAGS_HAVE_VECTORCALL \ PyObject_VectorcallMethod \ PyVectorcall_Function \ PyObject_CallOneArg \ PyObject_CallMethodNoArgs \ PyObject_CallMethodOneArg \ ; do echo $name git grep -lwz _$name | xargs -0 sed -i "s/\b_$name\b/$name/g" done old=_PyObject_FastCallDict new=PyObject_VectorcallDict git grep -lwz $old | xargs -0 sed -i "s/\b$old\b/$new/g" and then cleaned up: - Revert changes to in docs & news - Revert changes to backcompat defines in headers - Nudge misaligned comments
* bpo-39573: Add Py_SET_TYPE() function (GH-18394)Victor Stinner2020-02-071-4/+6
| | | Add Py_SET_TYPE() function to set the type of an object.
* bpo-39573: Use Py_REFCNT() macro (GH-18388)Victor Stinner2020-02-061-4/+5
| | | | Replace direct acccess to PyObject.ob_refcnt with usage of the Py_REFCNT() macro.
* bpo-38395: Fix ownership in weakref.proxy methods (GH-16632)Pablo Galindo2019-10-081-31/+88
| | | | | | | | | | | | | The implementation of weakref.proxy's methods call back into the Python API using a borrowed references of the weakly referenced object (acquired via PyWeakref_GET_OBJECT). This API call may delete the last reference to the object (either directly or via GC), leaving a dangling pointer, which can be subsequently dereferenced. To fix this, claim a temporary ownership of the referenced object when calling the appropriate method. Some functions because at the moment they do not need to access the borrowed referent, but to protect against future changes to these functions, ownership need to be fixed in all potentially affected methods.
* bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630)Serhiy Storchaka2019-09-011-3/+3
| | | Only AttributeError should be silenced.
* bpo-37337: Add _PyObject_CallMethodNoArgs() (GH-14267)Jeroen Demeyer2019-07-081-1/+1
|
* bpo-37483: add _PyObject_CallOneArg() function (#14558)Jeroen Demeyer2019-07-041-1/+1
|
* bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async ↵Jeroen Demeyer2019-05-311-6/+6
| | | | | | | | | (GH-13464) Automatically replace tp_print -> tp_vectorcall_offset tp_compare -> tp_as_async tp_reserved -> tp_as_async
* bpo-36669: add matmul support to weakref.proxy (GH-12932)Mark Dickinson2019-04-261-0/+4
|
* bpo-35059: Cleanup usage of Python macros (GH-10648)Victor Stinner2018-11-221-1/+2
| | | | | | | | | | | | | Don't pass complex expressions but regular variables to Python macros. * _datetimemodule.c: split single large "if" into two "if" in date_new(), time_new() and datetime_new(). * _pickle.c, load_extension(): flatten complex "if" expression into more regular C code. * _ssl.c: addbool() now uses a temporary bool_obj to only evaluate the value once. * weakrefobject.c: replace "Py_INCREF(result = proxy);" with "result = proxy; Py_INCREF(result);"
* bpo-33012: Fix invalid function cast warnings with gcc 8 for METH_NOARGS. ↵Siddhesh Poyarekar2018-04-291-2/+2
| | | | | | | | | (GH-6030) METH_NOARGS functions need only a single argument but they are cast into a PyCFunction, which takes two arguments. This triggers an invalid function cast warning in gcc8 due to the argument mismatch. Fix this by adding a dummy unused argument.
* bpo-30592: Fixed error messages for some builtins. (#1996)Serhiy Storchaka2017-06-081-1/+1
| | | | | Error messages when pass keyword arguments to some builtins that don't support keyword arguments contained double parenthesis: "()()". The regression was introduced by bpo-30534.
* bpo-29347: Fix possibly dereferencing undefined pointers when creating ↵Xiang Zhang2017-02-201-0/+2
| | | | weakref objects (#128)
* bpo-29548: Fix some inefficient call API usage (GH-97)INADA Naoki2017-02-161-1/+1
|
* Backed out changeset b9c9691c72c5Victor Stinner2016-12-041-1/+1
| | | | | | Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like _PyObject_CallArg1() uses more stack memory than PyObject_CallFunctionObjArgs().
* Replace PyObject_CallFunctionObjArgs() with fastcallVictor Stinner2016-12-011-1/+1
| | | | | | | | | | | | | | * PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func) * PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg) PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires extra work to "parse" C arguments to build a C array of PyObject*. _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack. This change is part of the fastcall project. The change on listsort() is related to the issue #23507.
* Avoid calling functions with an empty string as format stringVictor Stinner2016-09-061-1/+1
| | | | Directly pass NULL rather than an empty string.
* Issue #17765: weakref.ref() no longer silently ignores keyword arguments.Serhiy Storchaka2016-05-071-1/+3
|\ | | | | | | Patch by Georg Brandl.
| * Issue #17765: weakref.ref() no longer silently ignores keyword arguments.Serhiy Storchaka2016-05-071-1/+3
| | | | | | | | Patch by Georg Brandl.
* | Issue #25923: Added more const qualifiers to signatures of static and ↵Serhiy Storchaka2015-12-251-1/+1
|/ | | | private functions.
* Issue #23783: Fixed memory leak in PyObject_ClearWeakRefs() in case ofSerhiy Storchaka2015-03-301-7/+4
| | | | MemoryError.
* Issue #17643: Add __callback__ attribute to weakref.ref.Mark Dickinson2013-04-131-1/+6
|
* Issue #16602: When a weakref's target was part of a long deallocation chain, ↵Antoine Pitrou2012-12-081-3/+2
|\ | | | | | | | | | | the object could remain reachable through its weakref even though its refcount had dropped to zero. Thanks to Eugene Toder for diagnosing and reporting the issue.
| * Issue #16602: When a weakref's target was part of a long deallocation chain, ↵Antoine Pitrou2012-12-081-3/+2
| | | | | | | | | | | | the object could remain reachable through its weakref even though its refcount had dropped to zero. Thanks to Eugene Toder for diagnosing and reporting the issue.
* | Issue #16453: Fix equality testing of dead weakref objects.Antoine Pitrou2012-11-111-3/+7
|\ \ | |/ | | | | Also add tests for ordering and hashing.
| * Issue #16453: Fix equality testing of dead weakref objects.Antoine Pitrou2012-11-111-3/+7
| | | | | | | | Also add tests for ordering and hashing.
* | Rename _Py_identifier to _Py_IDENTIFIER.Martin v. Löwis2011-10-141-2/+2
| |
* | Use identifier API for PyObject_GetAttrString.Martin v. Löwis2011-10-101-1/+2
| |
* | Add API for static strings, primarily good for identifiers.Martin v. Löwis2011-10-091-2/+3
| | | | | | | | Thanks to Konrad Schöbel and Jasper Schulz for helping with the mass-editing.
* | Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.Brian Curtin2011-08-111-2/+1
| | | | | | | | The macro was introduced in #12724.
* | Issue #10833: Remove the buffer allocated on the stack, it isn't used anymoreVictor Stinner2011-03-211-1/+0
| |
* | Issue #10833: Use PyUnicode_FromFormat() and PyErr_Format() instead ofVictor Stinner2011-03-211-31/+27
| | | | | | | | PyOS_snprintf().
* | Issue #8914: fix various warnings from the Clang static analyzer v254.Brett Cannon2011-02-221-7/+14
|/
* Issue #10359: Remove ";" after function definition, invalid in ISO CVictor Stinner2010-11-091-1/+1
|