Add _PyFunction_GetXIData(). · python/cpython@4a195d8 · GitHub
Skip to content

Commit 4a195d8

Browse files
Add _PyFunction_GetXIData().
1 parent c81fa2b commit 4a195d8

5 files changed

Lines changed: 103 additions & 0 deletions

File tree

Include/internal/pycore_crossinterp.h

Lines changed: 7 additions & 0 deletions

Lib/test/test_crossinterp.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,40 @@ def test_other_objects(self):
758758
])
759759

760760

761+
class ShareableFuncTests(_GetXIDataTests):
762+
763+
MODE = 'func'
764+
765+
def test_stateless(self):
766+
self.assert_roundtrip_not_equal([
767+
*defs.STATELESS_FUNCTIONS,
768+
# Generators can be stateless too.
769+
*defs.FUNCTION_LIKE,
770+
])
771+
772+
def test_not_stateless(self):
773+
self.assert_not_shareable([
774+
*(f for f in defs.FUNCTIONS
775+
if f not in defs.STATELESS_FUNCTIONS),
776+
])
777+
778+
def test_other_objects(self):
779+
self.assert_not_shareable([
780+
None,
781+
True,
782+
False,
783+
Ellipsis,
784+
NotImplemented,
785+
9999,
786+
'spam',
787+
b'spam',
788+
(),
789+
[],
790+
{},
791+
object(),
792+
])
793+
794+
761795
class PureShareableScriptTests(_GetXIDataTests):
762796

763797
MODE = 'script-pure'

Modules/_testinternalcapi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,11 @@ get_crossinterp_data(PyObject *self, PyObject *args, PyObject *kwargs)
19891989
goto error;
19901990
}
19911991
}
1992+
else if (strcmp(mode, "func") == 0) {
1993+
if (_PyFunction_GetXIData(tstate, obj, xidata) != 0) {
1994+
goto error;
1995+
}
1996+
}
19921997
else if (strcmp(mode, "script") == 0) {
19931998
if (_PyCode_GetScriptXIData(tstate, obj, xidata) != 0) {
19941999
goto error;

Python/crossinterp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "pycore_initconfig.h" // _PyStatus_OK()
1111
#include "pycore_namespace.h" // _PyNamespace_New()
1212
#include "pycore_pythonrun.h" // _Py_SourceAsString()
13+
#include "pycore_setobject.h" // _PySet_NextEntry()
1314
#include "pycore_typeobject.h" // _PyStaticType_InitBuiltin()
1415

1516

Python/crossinterp_data_lookup.h

Lines changed: 56 additions & 0 deletions

0 commit comments

Comments
 (0)