Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix an extra DECREF for pep 667 implementation
  • Loading branch information
gaogaotiantian committed May 5, 2024
commit 2bb4e2e18121d10f313a83c54658adb6ae82c9ec
16 changes: 16 additions & 0 deletions Lib/test/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,22 @@ def f():
c = 0
f()

def test_local_objects(self):
o = object()
k = '.'.join(['a', 'b', 'c'])
f_locals = sys._getframe().f_locals
f_locals['o'] = f_locals['k']
self.assertEqual(o, 'a.b.c')

def test_update_with_self(self):
# Make sure reference is not leaking here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was not a leak though -- it was a free-after-use (the opposite of a leak, really :-).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I was imaging a pool of reference and a hole that's leaking the reference without people knowing it so the pool is drained, but yeah leak is not a good word choice here. I just deleted it, the test itself makes sense without any comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, that's actually a nice image. :-) I will merge now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick review!

def f():
f_locals = sys._getframe().f_locals
f_locals.update(f_locals)
f_locals.update(f_locals)
f_locals.update(f_locals)
f()

def test_repr(self):
x = 1
# Introduce a reference cycle
Expand Down
1 change: 0 additions & 1 deletion Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value)
} else if (value != oldvalue) {
Py_XSETREF(fast[i], Py_NewRef(value));
}
Py_XDECREF(value);
return 0;
}
}
Expand Down