1
1
2
2
/* Testing module for single-phase initialization of extension modules
3
3
4
- This file contains 5 distinct modules, meaning each as its own name
4
+ This file contains 8 distinct modules, meaning each as its own name
5
5
and its own init function (PyInit_...). The default import system will
6
6
only find the one matching the filename: _testsinglephase. To load the
7
7
others you must do so manually. For example:
@@ -14,7 +14,7 @@ spec = importlib.util.spec_from_file_location(name, filename, loader=loader)
14
14
mod = importlib._bootstrap._load(spec)
15
15
```
16
16
17
- Here are the 5 modules:
17
+ Here are the 8 modules:
18
18
19
19
* _testsinglephase
20
20
* def: _testsinglephase_basic,
@@ -136,6 +136,32 @@ Here are the 5 modules:
136
136
5. increment <global>.initialized_count
137
137
* functions: see common functions below
138
138
* import system: same as _testsinglephase_basic_copy
139
+ * _testsinglephase_check_cache_first
140
+ * def: _testsinglepahse_check_cache_first
141
+ * m_name: "_testsinglephase_check_cache_first"
142
+ * m_size: -1
143
+ * state: none
144
+ * init function:
145
+ * tries PyState_FindModule() first
146
+ * otherwise creates empty module
147
+ * functions: none
148
+ * import system: same as _testsinglephase
149
+ * _testsinglephase_with_reinit_check_cache_first
150
+ * def: _testsinglepahse_with_reinit_check_cache_first
151
+ * m_name: "_testsinglephase_with_reinit_check_cache_first"
152
+ * m_size: 0
153
+ * state: none
154
+ * init function: same as _testsinglephase_check_cache_first
155
+ * functions: none
156
+ * import system: same as _testsinglephase_with_reinit
157
+ * _testsinglephase_with_state_check_cache_first
158
+ * def: _testsinglepahse_with_state_check_cache_first
159
+ * m_name: "_testsinglephase_with_state_check_cache_first"
160
+ * m_size: 42
161
+ * state: none
162
+ * init function: same as _testsinglephase_check_cache_first
163
+ * functions: none
164
+ * import system: same as _testsinglephase_with_state
139
165
140
166
Module state:
141
167
@@ -650,3 +676,64 @@ PyInit__testsinglephase_with_state(void)
650
676
finally :
651
677
return module ;
652
678
}
679
+
680
+
681
+ /****************************************************/
682
+ /* the _testsinglephase_*_check_cache_first modules */
683
+ /****************************************************/
684
+
685
+ static struct PyModuleDef _testsinglephase_check_cache_first = {
686
+ PyModuleDef_HEAD_INIT ,
687
+ .m_name = "_testsinglephase_check_cache_first" ,
688
+ .m_doc = PyDoc_STR ("Test module _testsinglephase_check_cache_first" ),
689
+ .m_size = -1 , // no module state
690
+ };
691
+
692
+ PyMODINIT_FUNC
693
+ PyInit__testsinglephase_check_cache_first (void )
694
+ {
695
+ assert (_testsinglephase_check_cache_first .m_base .m_index == 0 );
696
+ PyObject * mod = PyState_FindModule (& _testsinglephase_check_cache_first );
697
+ if (mod != NULL ) {
698
+ return Py_NewRef (mod );
699
+ }
700
+ return PyModule_Create (& _testsinglephase_check_cache_first );
701
+ }
702
+
703
+
704
+ static struct PyModuleDef _testsinglephase_with_reinit_check_cache_first = {
705
+ PyModuleDef_HEAD_INIT ,
706
+ .m_name = "_testsinglephase_with_reinit_check_cache_first" ,
707
+ .m_doc = PyDoc_STR ("Test module _testsinglephase_with_reinit_check_cache_first" ),
708
+ .m_size = 0 , // no module state
709
+ };
710
+
711
+ PyMODINIT_FUNC
712
+ PyInit__testsinglephase_with_reinit_check_cache_first (void )
713
+ {
714
+ assert (_testsinglephase_with_reinit_check_cache_first .m_base .m_index == 0 );
715
+ PyObject * mod = PyState_FindModule (& _testsinglephase_with_reinit_check_cache_first );
716
+ if (mod != NULL ) {
717
+ return Py_NewRef (mod );
718
+ }
719
+ return PyModule_Create (& _testsinglephase_with_reinit_check_cache_first );
720
+ }
721
+
722
+
723
+ static struct PyModuleDef _testsinglephase_with_state_check_cache_first = {
724
+ PyModuleDef_HEAD_INIT ,
725
+ .m_name = "_testsinglephase_with_state_check_cache_first" ,
726
+ .m_doc = PyDoc_STR ("Test module _testsinglephase_with_state_check_cache_first" ),
727
+ .m_size = 42 , // not used
728
+ };
729
+
730
+ PyMODINIT_FUNC
731
+ PyInit__testsinglephase_with_state_check_cache_first (void )
732
+ {
733
+ assert (_testsinglephase_with_state_check_cache_first .m_base .m_index == 0 );
734
+ PyObject * mod = PyState_FindModule (& _testsinglephase_with_state_check_cache_first );
735
+ if (mod != NULL ) {
736
+ return Py_NewRef (mod );
737
+ }
738
+ return PyModule_Create (& _testsinglephase_with_state_check_cache_first );
739
+ }
0 commit comments