File tree 2 files changed +75
-0
lines changed
2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -2203,6 +2203,22 @@ def test_module_state_shared_in_global(self):
2203
2203
subinterp_attr_id = os .read (r , 100 )
2204
2204
self .assertEqual (main_attr_id , subinterp_attr_id )
2205
2205
2206
+ @unittest .skipIf (_testmultiphase is None , "test requires _testmultiphase module" )
2207
+ def test_datetime_capi_client (self ):
2208
+ script = textwrap .dedent ("""
2209
+ import importlib.machinery
2210
+ import importlib.util
2211
+ fullname = '_test_datetime_capi_client'
2212
+ origin = importlib.util.find_spec('_testmultiphase').origin
2213
+ loader = importlib.machinery.ExtensionFileLoader(fullname, origin)
2214
+ spec = importlib.util.spec_from_loader(fullname, loader)
2215
+ module = importlib.util.module_from_spec(spec)
2216
+ spec.loader.exec_module(module)
2217
+ """ )
2218
+ exec (script ) # run main interp first
2219
+ ret = support .run_in_subinterp (script )
2220
+ self .assertEqual (ret , 0 )
2221
+
2206
2222
2207
2223
@requires_subinterpreters
2208
2224
class InterpreterConfigTests (unittest .TestCase ):
Original file line number Diff line number Diff line change @@ -952,3 +952,62 @@ PyInit__test_shared_gil_only(void)
952
952
{
953
953
return PyModuleDef_Init (& shared_gil_only_def );
954
954
}
955
+
956
+
957
+ #include "datetime.h"
958
+
959
+ static int
960
+ datetime_capi_client_exec (PyObject * m )
961
+ {
962
+ int ismain = PyInterpreterState_Get () == PyInterpreterState_Main ();
963
+ if (ismain ) {
964
+ _pydatetimeapi_main = NULL ;
965
+ }
966
+
967
+ PyDateTime_IMPORT ;
968
+ if (Py
10000
DateTimeAPI == NULL ) {
969
+ return -1 ;
970
+ }
971
+ if (PyDateTimeAPI != PyCapsule_Import (PyDateTime_CAPSULE_NAME , 0 )) {
972
+ return -1 ;
973
+ }
974
+ if (ismain ) {
975
+ if (PyDateTimeAPI != _pydatetimeapi_main ) {
976
+ return -1 ;
977
+ }
978
+ }
979
+ else {
980
+ if (PyDateTimeAPI == _pydatetimeapi_main ) {
981
+ PyObject * module = PyImport_ImportModule ("_datetime" );
982
+ if (module == NULL ) {
983
+ return -1 ;
984
+ }
985
+ PyModuleDef * def = PyModule_GetDef (module );
986
+ Py_DECREF (module );
987
+ if (def ) {
988
+ // multi-phase init
989
+ return -1 ;
990
+ }
991
+ else {
992
+ // legacy init (shared module)
993
+ return 0 ;
994
+ }
995
+ }
996
+ }
997
+ return 0 ;
998
+ }
999
+
1000
+ static PyModuleDef_Slot datetime_capi_client_slots [] = {
1001
+ {Py_mod_exec , datetime_capi_client_exec },
1002
+ {Py_mod_multiple_interpreters , Py_MOD_PER_INTERPRETER_GIL_SUPPORTED },
1003
+ {0 , NULL },
1004
+ };
1005
+
1006
+ static PyModuleDef datetime_capi_client_def = TEST_MODULE_DEF (
1007
+ "_testmultiphase_datetime_capi_client" , datetime_capi_client_slots , NULL );
1008
+
1009
+ PyMODINIT_FUNC
1010
+ PyInit__test_datetime_capi_client (void )
1011
+ {
1012
+ return PyModuleDef_Init (& datetime_capi_client_def );
1013
+ }
You can’t perform that action at this time.
0 commit comments