Skip to content

Commit 9204d37

Browse files
author
Anselm Kruis
committed
Stackless issue python#268: Add magic number to pickled code objects
Update the documentation.
1 parent c753054 commit 9204d37

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Doc/library/stackless/pickling.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,19 @@ types:
147147
C-types PyAsyncGenASend and PyAsyncGenAThrow (see :pep:`525`) as well as
148148
all kinds of :ref:`Dictionary view objects <dict-views>`.
149149

150+
Code
151+
====
152+
153+
|SLP| can pickle :data:`~types.CodeType` objects.
154+
155+
.. versionchanged:: 3.8
156+
The pickled representation of a code object contains the bytecode version number (:data:`~importlib.util.MAGIC_NUMBER`).
157+
If a program tries to unpickle a code object with a wrong bytecode version number, then |SLP|
158+
159+
* emits a ``RuntimeWarning('Unpickling code object with invalid magic number %ld')`` and
160+
* prepends the *co_code* attribute of the unpickled code object with an invalid |PY| bytecode instruction. This way any attempt
161+
to execute the code object raises :exc:`SystemError`.
162+
150163
Frames
151164
======
152165

@@ -156,6 +169,25 @@ generator. |SLP| does not register a "reduction" function for
156169
:data:`~types.FrameType`. This way |SLP| stays compatible with application
157170
code that registers its own "reduction" function for :data:`~types.FrameType`.
158171

172+
It is not possible to execute an unpickled frame, if the tasklet the original frame belonged to was
173+
not :attr:`~tasklet.restorable`. In this case the frame is marked as invalid and any attempt
174+
to execute it raises
175+
176+
.. versionchanged:: 3.8
177+
If a program tries to unpickle a frame using a code object whose first bytecode instruction is invalid, then |SLP|
178+
marks the frame as invalid. Any attempt to execute the frame raises :exc:`RuntimeError`.
179+
180+
181+
Functions
182+
=========
183+
184+
|SLP| can pickle functions including lambda-objects objects by value.
185+
186+
.. versionchanged:: 3.8
187+
If a program tries to unpickle a function using a code object whose first bytecode instruction is invalid, then |SLP|
188+
emits a ``RuntimeWarning('Unpickling function with invalid code object: %V')``. Any attempt
189+
to execute the function raises :exc:`SystemError`.
190+
159191
.. _slp_pickling_asyncgen:
160192

161193
Asynchronous Generators

0 commit comments

Comments
 (0)