mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00: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)
|
||||
|
||||
set_result = instance.get_set()
|
||||
set_result.add(u'key3')
|
||||
set_result.add('key3')
|
||||
instance.print_set(set_result)
|
||||
|
||||
set_result = instance.get_set2()
|
||||
set_result.add(u'key3')
|
||||
set_result.add('key3')
|
||||
instance.print_set_2(set_result)
|
||||
|
||||
list_result = instance.get_list()
|
||||
|
@ -10,25 +10,57 @@
|
||||
#pragma once
|
||||
|
||||
#if !defined(NAMESPACE_BEGIN)
|
||||
#define NAMESPACE_BEGIN(name) namespace name {
|
||||
# define NAMESPACE_BEGIN(name) namespace name {
|
||||
#endif
|
||||
#if !defined(NAMESPACE_END)
|
||||
#define NAMESPACE_END(name) }
|
||||
# define NAMESPACE_END(name) }
|
||||
#endif
|
||||
|
||||
#if !defined(PYBIND11_EXPORT)
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
#define PYBIND11_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define PYBIND11_EXPORT __attribute__ ((visibility("default")))
|
||||
#endif
|
||||
#endif
|
||||
#if defined(_MSC_VER)
|
||||
#define PYBIND11_NOINLINE __declspec(noinline)
|
||||
#else
|
||||
#define PYBIND11_NOINLINE __attribute__ ((noinline))
|
||||
# if defined(WIN32) || defined(_WIN32)
|
||||
# define PYBIND11_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define PYBIND11_EXPORT __attribute__ ((visibility("default")))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# define PYBIND11_NOINLINE __declspec(noinline)
|
||||
#else
|
||||
# define PYBIND11_NOINLINE __attribute__ ((noinline))
|
||||
#endif
|
||||
|
||||
/// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode
|
||||
#if defined(_MSC_VER)
|
||||
# define HAVE_ROUND
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4510 4610 4512 4005)
|
||||
# if _DEBUG
|
||||
# define _DEBUG_MARKER
|
||||
# undef _DEBUG
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <Python.h>
|
||||
#include <frameobject.h>
|
||||
|
||||
#ifdef isalnum
|
||||
# undef isalnum
|
||||
# undef isalpha
|
||||
# undef islower
|
||||
# undef isspace
|
||||
# undef isupper
|
||||
# undef tolower
|
||||
# undef toupper
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# if defined(_DEBUG_MARKER)
|
||||
# define _DEBUG
|
||||
# undef _DEBUG_MARKER
|
||||
#endif
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -37,35 +69,6 @@
|
||||
#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
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4510 4610 4512 4005)
|
||||
#if _DEBUG
|
||||
#define _DEBUG_MARKER
|
||||
#undef _DEBUG
|
||||
#endif
|
||||
#endif
|
||||
#include <Python.h>
|
||||
#include <frameobject.h>
|
||||
#ifdef isalnum
|
||||
#undef isalnum
|
||||
#undef isalpha
|
||||
#undef islower
|
||||
#undef isspace
|
||||
#undef isupper
|
||||
#undef tolower
|
||||
#undef toupper
|
||||
#endif
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_DEBUG_MARKER)
|
||||
#define _DEBUG
|
||||
#undef _DEBUG_MARKER
|
||||
#endif
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3 /// Compatibility macros for various Python versions
|
||||
#define PYBIND11_BYTES_CHECK PyBytes_Check
|
||||
#define PYBIND11_BYTES_FROM_STRING PyBytes_FromString
|
||||
|
@ -248,13 +248,13 @@ public:
|
||||
}
|
||||
|
||||
operator std::string() const {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
|
||||
return PyUnicode_AsUTF8(m_ptr);
|
||||
#else
|
||||
object temp(PyUnicode_AsUTF8String(m_ptr), false);
|
||||
if (temp.ptr() == nullptr)
|
||||
pybind11_fail("Unable to extract string contents!");
|
||||
return PyString_AsString(temp.ptr());
|
||||
return PYBIND11_BYTES_AS_STRING(temp.ptr());
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user