Pickle for C extension?
TL;DR Is it possible to use C code to implement the (un)pickling of an type written in a C extension, as it was written in _pickle.c? Long explaining: I'm trying to create a C extension for frozendict. For simplicity, first I wrote it in CPython, then I started to move it in a C extension. It seems to work, but I have to move the code I wrote in _pickle.c and pickle.py in the C extension. Is it possible, or I have to create a slower `__reduce_ex__` method that simply converts it to dict? This is, for example, the C code for pickling frozendict in _pickle.c: https://github.com/Marco-Sulla/cpython/blob/41a640a947c36007e56bbc28f362c261...
19.10.20 20:39, Marco Sulla пише:
TL;DR Is it possible to use C code to implement the (un)pickling of an type written in a C extension, as it was written in _pickle.c?
Long explaining: I'm trying to create a C extension for frozendict. For simplicity, first I wrote it in CPython, then I started to move it in a C extension. It seems to work, but I have to move the code I wrote in _pickle.c and pickle.py in the C extension. Is it possible, or I have to create a slower `__reduce_ex__` method that simply converts it to dict?
This is, for example, the C code for pickling frozendict in _pickle.c: https://github.com/Marco-Sulla/cpython/blob/41a640a947c36007e56bbc28f362c261...
For adding new opcode to the pickle format you need a new pickle version and a PEP. Implement __reduce_ex__, it is the way to support pickling of new types (as it was for sets, bytearrays, and many extension types).
Ah, okay. This is a problem for me, since I can't pass the 5th argument to __reduce__, since it's an immutable type.
participants (3)
-
Marco Sulla
-
Marco Sulla
-
Serhiy Storchaka