Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
c3d8b8cf
Commit
c3d8b8cf
authored
Oct 09, 2016
by
Wenzel Jakob
Committed by
GitHub
Oct 09, 2016
Browse files
Merge pull request #435 from wjakob/master
extra python version sanity check at import time
parents
f6661015
4c00fd9e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
10 deletions
+22
-10
include/pybind11/common.h
include/pybind11/common.h
+22
-10
No files found.
include/pybind11/common.h
View file @
c3d8b8cf
...
@@ -144,16 +144,28 @@ extern "C" {
...
@@ -144,16 +144,28 @@ extern "C" {
#define PYBIND11_INTERNALS_ID "__pybind11_" \
#define PYBIND11_INTERNALS_ID "__pybind11_" \
PYBIND11_TOSTRING(PYBIND11_VERSION_MAJOR) "_" PYBIND11_TOSTRING(PYBIND11_VERSION_MINOR) "__"
PYBIND11_TOSTRING(PYBIND11_VERSION_MAJOR) "_" PYBIND11_TOSTRING(PYBIND11_VERSION_MINOR) "__"
#define PYBIND11_PLUGIN(name) \
#define PYBIND11_PLUGIN(name) \
static PyObject *pybind11_init(); \
static PyObject *pybind11_init(); \
PYBIND11_PLUGIN_IMPL(name) { \
PYBIND11_PLUGIN_IMPL(name) { \
try { \
int major, minor; \
return pybind11_init(); \
if (sscanf(Py_GetVersion(), "%i.%i", &major, &minor) != 2) { \
} catch (const std::exception &e) { \
PyErr_SetString(PyExc_ImportError, "Can't parse Python version."); \
PyErr_SetString(PyExc_ImportError, e.what()); \
return nullptr; \
return nullptr; \
} else if (major != PY_MAJOR_VERSION || minor != PY_MINOR_VERSION) { \
} \
PyErr_Format(PyExc_ImportError, \
} \
"Python version mismatch: module was compiled for " \
"version %i.%i, while the interpreter is running " \
"version %i.%i.", PY_MAJOR_VERSION, PY_MINOR_VERSION, \
major, minor); \
return nullptr; \
} \
try { \
return pybind11_init(); \
} catch (const std::exception &e) { \
PyErr_SetString(PyExc_ImportError, e.what()); \
return nullptr; \
} \
} \
PyObject *pybind11_init()
PyObject *pybind11_init()
NAMESPACE_BEGIN
(
pybind11
)
NAMESPACE_BEGIN
(
pybind11
)
...
...
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