• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * C extensions module to test importing multiple modules from one compiled
3  * file (issue16421). This file defines 3 modules (_testimportmodule,
4  * foo, bar), only the first one is called the same as the compiled file.
5  */
6 
7 #include "pyconfig.h"   // Py_GIL_DISABLED
8 #ifndef Py_GIL_DISABLED
9 #  define Py_LIMITED_API 0x030d0000
10 #endif
11 
12 #include <Python.h>
13 
14 static PyModuleDef_Slot shared_slots[] = {
15     {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
16     {Py_mod_gil, Py_MOD_GIL_NOT_USED},
17     {0, NULL},
18 };
19 
20 static struct PyModuleDef _testimportmultiple = {
21     PyModuleDef_HEAD_INIT,
22     "_testimportmultiple",
23     "_testimportmultiple doc",
24     0,
25     NULL,
26     shared_slots,
27     NULL,
28     NULL,
29     NULL
30 };
31 
PyInit__testimportmultiple(void)32 PyMODINIT_FUNC PyInit__testimportmultiple(void)
33 {
34     return PyModuleDef_Init(&_testimportmultiple);
35 }
36 
37 static struct PyModuleDef _foomodule = {
38     PyModuleDef_HEAD_INIT,
39     "_testimportmultiple_foo",
40     "_testimportmultiple_foo doc",
41     0,
42     NULL,
43     shared_slots,
44     NULL,
45     NULL,
46     NULL
47 };
48 
PyInit__testimportmultiple_foo(void)49 PyMODINIT_FUNC PyInit__testimportmultiple_foo(void)
50 {
51     return PyModuleDef_Init(&_foomodule);
52 }
53 
54 static struct PyModuleDef _barmodule = {
55     PyModuleDef_HEAD_INIT,
56     "_testimportmultiple_bar",
57     "_testimportmultiple_bar doc",
58     0,
59     NULL,
60     shared_slots,
61     NULL,
62     NULL,
63     NULL
64 };
65 
PyInit__testimportmultiple_bar(void)66 PyMODINIT_FUNC PyInit__testimportmultiple_bar(void){
67     return PyModuleDef_Init(&_barmodule);
68 }
69