mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-02-06 15:35:29 +08:00
python 3.2 compatiblity (closes #56)
This commit is contained in:
parent
ba0732e7dc
commit
53b26549d0
@ -30,11 +30,11 @@ dict_result['key2'] = 'value2'
|
|||||||
instance.print_dict_2(dict_result)
|
instance.print_dict_2(dict_result)
|
||||||
|
|
||||||
set_result = instance.get_set()
|
set_result = instance.get_set()
|
||||||
set_result.add(u'key3')
|
set_result.add('key3')
|
||||||
instance.print_set(set_result)
|
instance.print_set(set_result)
|
||||||
|
|
||||||
set_result = instance.get_set2()
|
set_result = instance.get_set2()
|
||||||
set_result.add(u'key3')
|
set_result.add('key3')
|
||||||
instance.print_set_2(set_result)
|
instance.print_set_2(set_result)
|
||||||
|
|
||||||
list_result = instance.get_list()
|
list_result = instance.get_list()
|
||||||
|
|||||||
@ -23,20 +23,13 @@
|
|||||||
# define PYBIND11_EXPORT __attribute__ ((visibility("default")))
|
# define PYBIND11_EXPORT __attribute__ ((visibility("default")))
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# define PYBIND11_NOINLINE __declspec(noinline)
|
# define PYBIND11_NOINLINE __declspec(noinline)
|
||||||
#else
|
#else
|
||||||
# define PYBIND11_NOINLINE __attribute__ ((noinline))
|
# define PYBIND11_NOINLINE __attribute__ ((noinline))
|
||||||
#endif
|
#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
|
/// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# define HAVE_ROUND
|
# define HAVE_ROUND
|
||||||
@ -47,8 +40,10 @@
|
|||||||
# undef _DEBUG
|
# undef _DEBUG
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <frameobject.h>
|
#include <frameobject.h>
|
||||||
|
|
||||||
#ifdef isalnum
|
#ifdef isalnum
|
||||||
# undef isalnum
|
# undef isalnum
|
||||||
# undef isalpha
|
# undef isalpha
|
||||||
@ -58,6 +53,7 @@
|
|||||||
# undef tolower
|
# undef tolower
|
||||||
# undef toupper
|
# undef toupper
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# if defined(_DEBUG_MARKER)
|
# if defined(_DEBUG_MARKER)
|
||||||
# define _DEBUG
|
# define _DEBUG
|
||||||
@ -66,6 +62,13 @@
|
|||||||
# pragma warning(pop)
|
# pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3 /// Compatibility macros for various Python versions
|
#if PY_MAJOR_VERSION >= 3 /// Compatibility macros for various Python versions
|
||||||
#define PYBIND11_BYTES_CHECK PyBytes_Check
|
#define PYBIND11_BYTES_CHECK PyBytes_Check
|
||||||
#define PYBIND11_BYTES_FROM_STRING PyBytes_FromString
|
#define PYBIND11_BYTES_FROM_STRING PyBytes_FromString
|
||||||
|
|||||||
@ -248,13 +248,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
operator std::string() const {
|
operator std::string() const {
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
|
||||||
return PyUnicode_AsUTF8(m_ptr);
|
return PyUnicode_AsUTF8(m_ptr);
|
||||||
#else
|
#else
|
||||||
object temp(PyUnicode_AsUTF8String(m_ptr), false);
|
object temp(PyUnicode_AsUTF8String(m_ptr), false);
|
||||||
if (temp.ptr() == nullptr)
|
if (temp.ptr() == nullptr)
|
||||||
pybind11_fail("Unable to extract string contents!");
|
pybind11_fail("Unable to extract string contents!");
|
||||||
return PyString_AsString(temp.ptr());
|
return PYBIND11_BYTES_AS_STRING(temp.ptr());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user