diff --git a/CMakeLists.txt b/CMakeLists.txt index c9f7f878b..449970cf0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,9 +23,9 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) endif() string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE) -set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6) +set(Python_ADDITIONAL_VERSIONS 3.6 3.5 3.4 3.3 3.2) find_package(PythonLibs ${PYBIND11_PYTHON_VERSION} REQUIRED) -find_package(PythonInterp ${PYBIND11_PYTHON_VERSION} REQUIRED) +#find_package(PythonInterp ${PYBIND11_PYTHON_VERSION} REQUIRED) include(CheckCXXCompilerFlag) @@ -132,7 +132,7 @@ elseif (UNIX) # into Blender or Maya later on, this will cause segfaults when multiple # conflicting Python instances are active at the same time. - # Windows is not affected by this issue since it handles DLL imports + # Windows is not affected by this issue since it handles DLL imports # differently. The solution for Linux and Mac OS is simple: we just don't # link against the Python library. The resulting shared library will have # missing symbols, but that's perfectly fine -- they will be resolved at diff --git a/include/pybind11/common.h b/include/pybind11/common.h index bebcd0725..4b5a120d8 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -29,14 +29,6 @@ #define PYBIND11_NOINLINE __attribute__ ((noinline)) #endif - -#include -#include -#include -#include -#include -#include - /// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode #if defined(_MSC_VER) #define HAVE_ROUND @@ -66,6 +58,13 @@ #pragma warning(pop) #endif +#include +#include +#include +#include +#include +#include + #if PY_MAJOR_VERSION >= 3 #define PYBIND11_PLUGIN_IMPL(name) \ extern "C" PYBIND11_EXPORT PyObject *PyInit_##name() diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 4f7d58945..125718462 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -512,7 +512,7 @@ public: full_name = std::string(module_name) + "." + full_name; type->ht_name = name; -#if PY_MAJOR_VERSION >= 3 +#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3 type->ht_qualname = name; #endif type->ht_type.tp_name = strdup(full_name.c_str()); @@ -571,7 +571,7 @@ protected: throw std::runtime_error("Internal error in custom_type::metaclass()"); Py_INCREF(name); type->ht_name = name; -#if PY_MAJOR_VERSION >= 3 +#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3 type->ht_qualname = name; #endif type->ht_type.tp_name = strdup(name_.c_str()); @@ -974,4 +974,3 @@ NAMESPACE_END(pybind11) #elif defined(__GNUG__) and !defined(__clang__) #pragma GCC diagnostic pop #endif - diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index c0bb47b0b..3aca34586 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -264,17 +264,24 @@ public: PYBIND11_OBJECT_DEFAULT(str, object, PyUnicode_Check) str(const char *s) : object(PyUnicode_FromString(s), false) { } operator const char *() const { -#if PY_MAJOR_VERSION >= 3 +#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3 return PyUnicode_AsUTF8(m_ptr); +#else +#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 3 + m_temp = object(PyUnicode_AsUTF8String(m_ptr), false); + if (m_temp.ptr() == nullptr) + return nullptr; + return PyBytes_AsString(m_temp.ptr()); #else m_temp = object(PyUnicode_AsUTF8String(m_ptr), false); if (m_temp.ptr() == nullptr) return nullptr; return PyString_AsString(m_temp.ptr()); +#endif #endif } private: -#if PY_MAJOR_VERSION < 3 +#if !(PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3) mutable object m_temp; #endif };