Added backwards compatibility for python3.2.

String handling when PY_MAJOR_VERSION>=3 relied on functions
  not present until 3.3.
This commit is contained in:
Eldritch Cheese 2015-12-30 13:38:20 -05:00
parent 3367cecc6b
commit 3c9e389ebe
4 changed files with 21 additions and 16 deletions

View File

@ -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

View File

@ -29,14 +29,6 @@
#define PYBIND11_NOINLINE __attribute__ ((noinline))
#endif
#include <vector>
#include <string>
#include <stdexcept>
#include <unordered_set>
#include <unordered_map>
#include <memory>
/// 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 <vector>
#include <string>
#include <stdexcept>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#if PY_MAJOR_VERSION >= 3
#define PYBIND11_PLUGIN_IMPL(name) \
extern "C" PYBIND11_EXPORT PyObject *PyInit_##name()

View File

@ -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

View File

@ -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
};