Commit 18fb3e32 by Wenzel Jakob

added a pybind11::none class

parent 9b880ba7
...@@ -212,7 +212,7 @@ private: ...@@ -212,7 +212,7 @@ private:
ssize_t pos = 0; ssize_t pos = 0;
}; };
inline bool iterable_check(PyObject *obj) { inline bool PyIterable_Check(PyObject *obj) {
PyObject *iter = PyObject_GetIter(obj); PyObject *iter = PyObject_GetIter(obj);
if (iter) { if (iter) {
Py_DECREF(iter); Py_DECREF(iter);
...@@ -222,8 +222,10 @@ inline bool iterable_check(PyObject *obj) { ...@@ -222,8 +222,10 @@ inline bool iterable_check(PyObject *obj) {
return false; return false;
} }
} }
NAMESPACE_END(detail)
inline bool PyNone_Check(PyObject *o) { return o == Py_None; }
NAMESPACE_END(detail)
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, CvtStmt) \ #define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, CvtStmt) \
Name(const handle &h, bool borrowed) : Parent(h, borrowed) { CvtStmt; } \ Name(const handle &h, bool borrowed) : Parent(h, borrowed) { CvtStmt; } \
...@@ -261,7 +263,7 @@ private: ...@@ -261,7 +263,7 @@ private:
class iterable : public object { class iterable : public object {
public: public:
PYBIND11_OBJECT_DEFAULT(iterable, object, detail::iterable_check) PYBIND11_OBJECT_DEFAULT(iterable, object, detail::PyIterable_Check)
}; };
inline detail::accessor handle::operator[](handle key) const { return detail::accessor(ptr(), key.ptr(), false); } inline detail::accessor handle::operator[](handle key) const { return detail::accessor(ptr(), key.ptr(), false); }
...@@ -319,6 +321,12 @@ public: ...@@ -319,6 +321,12 @@ public:
} }
}; };
class none : public object {
public:
PYBIND11_OBJECT(none, object, detail::PyNone_Check)
none() : object(Py_None, true) { }
};
class bool_ : public object { class bool_ : public object {
public: public:
PYBIND11_OBJECT_DEFAULT(bool_, object, PyBool_Check) PYBIND11_OBJECT_DEFAULT(bool_, object, PyBool_Check)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment