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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinite recursion in Pickler.persistent_id #89850
Comments
The following code, which seems reasonable: import io
import pickle
class Pickler(pickle.Pickler):
def persistent_id(self, obj):
return super().persistent_id(obj)
Pickler(io.BytesIO()).dump(42) crashes with: It works perfectly when inheriting from pickle._Pickler (the Python implementation). |
I think it's because in the C version persistent_id can be NULL (but it's still in dir()):
on the other hand:
|
(gdb) p _PyObject_Dump(self->pers_func)
object address : 0x7ffff74b90d0
object refcount : 3
object type : 0x555555a6f020
object type name: function
object repr : <function Pickler.persistent_id at 0x7ffff74b90d0>
$1 = void
(gdb) c
Continuing.
Breakpoint 1, Pickler_get_persid (self=0x7ffff75c13e0, _unused_ignored=0x0) at ./Modules/_pickle.c:5004
5004 if (self->pers_func == NULL) {
(gdb) p _PyObject_Dump(self->pers_func)
object address : 0x7ffff74b90d0
object refcount : 4
object type : 0x555555a6f020
object type name: function
object repr : <function Pickler.persistent_id at 0x7ffff74b90d0>
$2 = void
(gdb) c
Continuing.
Breakpoint 1, Pickler_get_persid (self=0x7ffff75c13e0, _unused_ignored=0x0) at ./Modules/_pickle.c:5004
5004 if (self->pers_func == NULL) {
(gdb) p _PyObject_Dump(self->pers_func)
object address : 0x7ffff74b90d0
object refcount : 5
object type : 0x555555a6f020
object type name: function
object repr : <function Pickler.persistent_id at 0x7ffff74b90d0>
$3 = void
(gdb) The refcount of Traceback (most recent call last):
File "/home/furkan/cpython/bug.py", line 8, in <module>
Pickler(io.BytesIO()).dump(42)
File "/home/furkan/cpython/bug.py", line 6, in persistent_id
return super().persistent_id(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Pickler.persistent_id() missing 1 required positional argument: 'obj' |
embe mannequin commentedNov 2, 2021
•
edited by bedevere-bot
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: