Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
7e27c7cd
Commit
7e27c7cd
authored
Aug 25, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement safe-guard to prevent loading Cython modules into multiple subinterpreters.
parent
7562f7c2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+27
-0
No files found.
Cython/Utility/ModuleSetupCode.c
View file @
7e27c7cd
...
@@ -906,6 +906,31 @@ PyEval_InitThreads();
...
@@ -906,6 +906,31 @@ PyEval_InitThreads();
//@substitute: naming
//@substitute: naming
//#if CYTHON_PEP489_MULTI_PHASE_INIT
//#if CYTHON_PEP489_MULTI_PHASE_INIT
static
CYTHON_SMALL_CODE
int
__Pyx_check_single_interpreter
(
void
)
{
#if PY_VERSION_HEX >= 0x030700A1
static
PY_INT64_T
main_interpreter_id
=
-
1
;
PY_INT64_T
current_id
=
PyInterpreterState_GetID
(
PyThreadState_Get
()
->
interp
);
if
(
main_interpreter_id
==
-
1
)
{
main_interpreter_id
=
current_id
;
return
(
unlikely
(
current_id
==
-
1
))
?
-
1
:
0
;
}
else
if
(
unlikely
(
main_interpreter_id
!=
current_id
))
#else
static
PyInterpreterState
*
main_interpreter
=
NULL
;
PyInterpreterState
*
current_interpreter
=
PyThreadState_Get
()
->
interp
;
if
(
!
main_interpreter
)
{
main_interpreter
=
current_interpreter
;
}
else
if
(
unlikely
(
main_interpreter
!=
current_interpreter
))
#endif
{
PyErr_SetString
(
PyExc_RuntimeError
,
"Interpreter change detected - this module does not support subinterpreters."
);
return
-
1
;
}
return
0
;
}
static
CYTHON_SMALL_CODE
int
__Pyx_copy_spec_to_module
(
PyObject
*
spec
,
PyObject
*
moddict
,
const
char
*
from_name
,
const
char
*
to_name
)
{
static
CYTHON_SMALL_CODE
int
__Pyx_copy_spec_to_module
(
PyObject
*
spec
,
PyObject
*
moddict
,
const
char
*
from_name
,
const
char
*
to_name
)
{
PyObject
*
value
=
PyObject_GetAttrString
(
spec
,
from_name
);
PyObject
*
value
=
PyObject_GetAttrString
(
spec
,
from_name
);
int
result
=
0
;
int
result
=
0
;
...
@@ -924,6 +949,8 @@ static CYTHON_SMALL_CODE PyObject* ${pymodule_create_func_cname}(PyObject *spec,
...
@@ -924,6 +949,8 @@ static CYTHON_SMALL_CODE PyObject* ${pymodule_create_func_cname}(PyObject *spec,
PyObject
*
module
=
NULL
,
*
moddict
,
*
modname
;
PyObject
*
module
=
NULL
,
*
moddict
,
*
modname
;
// For now, we only have exactly one module instance.
// For now, we only have exactly one module instance.
if
(
__Pyx_check_single_interpreter
())
return
NULL
;
if
(
$
{
module_cname
})
if
(
$
{
module_cname
})
return
__Pyx_NewRef
(
$
{
module_cname
});
return
__Pyx_NewRef
(
$
{
module_cname
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment