Skip to content
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

gh-117398: Add datetime C-API type check test for subinterpreters #119604

Merged
merged 40 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0db4a81
Update _testmultiphase.c
neonene May 27, 2024
593f05a
Update test_misc.py
neonene May 27, 2024
d85c8bc
ingore import error on subinterp with GIL disabled
neonene May 27, 2024
9b667d7
revert
neonene May 28, 2024
6a67b45
Update Modules/_testcapi/datetime.c
neonene May 28, 2024
f21ef4a
revert
neonene May 29, 2024
ac9ad4b
add test for subinterpreters
neonene May 29, 2024
e4f6cc1
Merge branch 'main' into capi_type_check
neonene May 29, 2024
f0654f5
restore _testmultiphase check for WASI?
neonene May 29, 2024
17cb0c1
use test_datetime_capi() instead of PyDateTime_IMPORT
neonene May 29, 2024
fdfe135
remove redundant PyDateTimeAPI check
neonene May 29, 2024
c7d9de4
add Py_MOD_GIL_NOT_USED
neonene May 29, 2024
b89801c
ignore dlopen error on WASI
neonene May 30, 2024
cb5d65b
Merge branch 'main' into capi_type_check
neonene May 30, 2024
dc9c5e3
edit comment
neonene May 30, 2024
76695c7
Merge branch 'main' into capi_type_check
neonene May 30, 2024
6d57d33
rely on support module to run subinterps
neonene May 30, 2024
4a04542
nit
neonene May 30, 2024
ba08b04
add blank lines
neonene May 31, 2024
8c26d7e
simplify WASI check
neonene Jun 1, 2024
0360151
use _interpreters.new_config()
neonene Jun 1, 2024
b2c1e70
do not run_in_subinterp()
neonene Jun 2, 2024
23909a8
use @requires_subinterpreters instead of builtin _testcapi check
neonene Jun 2, 2024
daac381
do not use function to create module
neonene Jun 2, 2024
bf4d78a
do not copy config dict
neonene Jun 2, 2024
8c53a58
Merge branch 'main' into capi_type_check
neonene Jun 4, 2024
b3460b4
add test for all OSes
neonene Jun 4, 2024
aab36c3
_datetime does now multi-phase init
neonene Jun 4, 2024
378b1fd
remove test for all OSes
neonene Jun 4, 2024
df4c43e
remove duplicate test for main interpreter
neonene Jun 4, 2024
5ce05a4
reuse existing PyMethodDef
neonene Jun 4, 2024
ba41ef1
use expected config of InterpreterConfigTests instead
neonene Jun 4, 2024
272f25f
move static type assertions to test_datetime_capi()
neonene Jun 5, 2024
0d82c3c
Merge branch 'main' into capi_type_check
neonene Jun 5, 2024
17615ef
WASI support (only on legacy subinterp)
neonene Jun 5, 2024
9c46fe0
use _interpreters.new_config()
neonene Jun 13, 2024
0c40fc8
move test to datetimetester.py
neonene Jun 13, 2024
55beee7
Merge branch 'main' into capi_type_check
neonene Jun 13, 2024
b861bd3
rename test case
neonene Jun 13, 2024
a1421dd
simplify conditions in support.run_in_subinterp_with_config()
neonene Jun 13, 2024
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
18 changes: 18 additions & 0 deletions Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,24 @@ def test_module_state_shared_in_global(self):
subinterp_attr_id = os.read(r, 100)
self.assertEqual(main_attr_id, subinterp_attr_id)

@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
ericsnowcurrently marked this conversation as resolved.
Show resolved Hide resolved
def test_datetime_capi_type_check(self):
neonene marked this conversation as resolved.
Show resolved Hide resolved
script = textwrap.dedent("""
import importlib.machinery
import importlib.util
fullname = '_test_datetime_capi_client'
origin = importlib.util.find_spec('_testmultiphase').origin
loader = importlib.machinery.ExtensionFileLoader(fullname, origin)
spec = importlib.util.spec_from_loader(fullname, loader)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
import datetime
module.pydate_check(datetime.date.today())
""")
exec(script)
ret = support.run_in_subinterp(script)
self.assertEqual(ret, 0)


@requires_subinterpreters
class InterpreterConfigTests(unittest.TestCase):
Expand Down
40 changes: 40 additions & 0 deletions Modules/_testmultiphase.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,43 @@ PyInit__test_shared_gil_only(void)
{
return PyModuleDef_Init(&shared_gil_only_def);
}


#include "datetime.h"

static PyObject *
datetime_capi_pydate_check(PyObject *self, PyObject *op)
{
PyDateTime_IMPORT;
#ifdef Py_GIL_DISABLED
if (!PyDateTimeAPI && PyInterpreterState_Get() != PyInterpreterState_Main()) {
// Subinterpreter cannot import lagacy _datetime module and capsule.
PyErr_WriteUnraisable(NULL);
Py_RETURN_NONE;
}
#endif
if (PyDate_Check(op)) {
Py_RETURN_NONE;
}
PyErr_SetString(PyExc_TypeError, "object is not instance of capi type");
return NULL;
}

static PyMethodDef datetime_capi_client_methods[] = {
{"pydate_check", datetime_capi_pydate_check, METH_O, NULL},
{0},
};

static PyModuleDef_Slot datetime_capi_client_slots[] = {
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL},
};

static PyModuleDef datetime_capi_client_def = TEST_MODULE_DEF(
"_testmultiphase_datetime_capi_client", datetime_capi_client_slots, datetime_capi_client_methods);

PyMODINIT_FUNC
PyInit__test_datetime_capi_client(void)
{
return PyModuleDef_Init(&datetime_capi_client_def);
}
neonene marked this conversation as resolved.
Show resolved Hide resolved
Loading