Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-142589: Fix PyUnstable_Object_IsUniqueReferencedTemporary#142593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletionsLib/test/test_capi/test_object.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -251,6 +251,13 @@ def func(x):

func(object())

# Test that a newly created object in C is not considered
# a uniquely referenced temporary, because it's not on the stack.
# gh-142586: do the test in a loop over a list to test for handling
# tagged ints on the stack.
foriin [0,1,2]:
self.assertFalse(_testcapi.pyobject_is_unique_temporary_new_object())

defpyobject_dump(self,obj,release_gil=False):
pyobject_dump=_testcapi.pyobject_dump

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Fix :c:func:`PyUnstable_Object_IsUniqueReferencedTemporary()` handling of
tagged ints on the interpreter stack.
10 changes: 10 additions & 0 deletionsModules/_testcapi/object.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,6 +138,15 @@ pyobject_is_unique_temporary(PyObject *self, PyObject *obj)
return PyLong_FromLong(result);
}

static PyObject *
pyobject_is_unique_temporary_new_object(PyObject *self, PyObject *unused)
{
PyObject *obj = PyList_New(0);
int result = PyUnstable_Object_IsUniqueReferencedTemporary(obj);
Py_DECREF(obj);
return PyLong_FromLong(result);
}

static int MyObject_dealloc_called = 0;

static void
Expand DownExpand Up@@ -517,6 +526,7 @@ static PyMethodDef test_methods[] = {
{"pyobject_clear_weakrefs_no_callbacks", pyobject_clear_weakrefs_no_callbacks, METH_O},
{"pyobject_enable_deferred_refcount", pyobject_enable_deferred_refcount, METH_O},
{"pyobject_is_unique_temporary", pyobject_is_unique_temporary, METH_O},
{"pyobject_is_unique_temporary_new_object", pyobject_is_unique_temporary_new_object, METH_NOARGS},
{"test_py_try_inc_ref", test_py_try_inc_ref, METH_NOARGS},
{"test_xincref_doesnt_leak",test_xincref_doesnt_leak, METH_NOARGS},
{"test_incref_doesnt_leak", test_incref_doesnt_leak, METH_NOARGS},
Expand Down
8 changes: 6 additions & 2 deletionsObjects/object.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2759,8 +2759,12 @@ PyUnstable_Object_IsUniqueReferencedTemporary(PyObject *op)
_PyStackRef*stackpointer=frame->stackpointer;
while (stackpointer>base) {
stackpointer--;
if (op==PyStackRef_AsPyObjectBorrow(*stackpointer)) {
returnPyStackRef_IsHeapSafe(*stackpointer);
_PyStackRefref=*stackpointer;
if (PyStackRef_IsTaggedInt(ref)) {
continue;
}
if (op==PyStackRef_AsPyObjectBorrow(ref)) {
returnPyStackRef_IsHeapSafe(ref);
}
}
return0;
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp