diff --git a/.travis.yml b/.travis.yml index 17c56ec59..03b1dc583 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ matrix: compiler: gcc-4.8 script: - pyvenv-3.5 venv - - cmake -DPYBIND_PYTHON_VERSION=3.5 -DPYTHON_INCLUDE_DIR:PATH=/usr/include/python3.5m -DPYTHON_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython3.5m.so -DPYTHON_EXECUTABLE:FILEPATH=`pwd`/venv/bin/python3.5 -DCMAKE_CXX_COMPILER=g++-4.8 + - cmake -DPYBIND11_PYTHON_VERSION=3.5 -DPYTHON_INCLUDE_DIR:PATH=/usr/include/python3.5m -DPYTHON_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython3.5m.so -DPYTHON_EXECUTABLE:FILEPATH=`pwd`/venv/bin/python3.5 -DCMAKE_CXX_COMPILER=g++-4.8 - make -j 2 - source venv/bin/activate - pip install numpy @@ -24,6 +24,6 @@ matrix: - os: osx compiler: clang script: - - cmake -DPYBIND_PYTHON_VERSION=2.7 + - cmake -DPYBIND11_PYTHON_VERSION=2.7 - make -j 2 - CTEST_OUTPUT_ON_FAILURE=TRUE make test diff --git a/CMakeLists.txt b/CMakeLists.txt index 09edbae5a..92aa018b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 2.8) project(pybind11) # Add a CMake parameter for choosing a desired Python version -set(PYBIND_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling the example application") +set(PYBIND11_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling the example application") # Set a default build configuration if none is specified. 'MinSizeRel' produces the smallest binaries if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) @@ -22,8 +22,8 @@ endif() string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE) set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6) -find_package(PythonLibs ${PYBIND_PYTHON_VERSION} REQUIRED) -find_package(PythonInterp ${PYBIND_PYTHON_VERSION} REQUIRED) +find_package(PythonLibs ${PYBIND11_PYTHON_VERSION} REQUIRED) +find_package(PythonInterp ${PYBIND11_PYTHON_VERSION} REQUIRED) if (UNIX) # Enable C++11 mode diff --git a/docs/advanced.rst b/docs/advanced.rst index 70561d760..4caacf9c0 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -45,7 +45,7 @@ to Python. #include - PYBIND_PLUGIN(example) { + PYBIND11_PLUGIN(example) { py::module m("example", "pybind11 example plugin"); py::class_(m, "Vector2") @@ -127,7 +127,7 @@ trivial to generate binding code for both of these functions. #include - PYBIND_PLUGIN(example) { + PYBIND11_PLUGIN(example) { py::module m("example", "pybind11 example plugin"); m.def("func_arg", &func_arg); @@ -199,7 +199,7 @@ Normally, the binding code for these classes would look as follows: .. code-block:: cpp - PYBIND_PLUGIN(example) { + PYBIND11_PLUGIN(example) { py::module m("example", "pybind11 example plugin"); py::class_ animal(m, "Animal"); @@ -230,7 +230,7 @@ helper class that is defined as follows: /* Trampoline (need one for each virtual function) */ std::string go(int n_times) { - PYBIND_OVERLOAD_PURE( + PYBIND11_OVERLOAD_PURE( std::string, /* Return type */ Animal, /* Parent class */ go, /* Name of function */ @@ -239,15 +239,15 @@ helper class that is defined as follows: } }; -The macro :func:`PYBIND_OVERLOAD_PURE` should be used for pure virtual -functions, and :func:`PYBIND_OVERLOAD` should be used for functions which have +The macro :func:`PYBIND11_OVERLOAD_PURE` should be used for pure virtual +functions, and :func:`PYBIND11_OVERLOAD` should be used for functions which have a default implementation. The binding code also needs a few minor adaptations (highlighted): .. code-block:: cpp :emphasize-lines: 4,6,7 - PYBIND_PLUGIN(example) { + PYBIND11_PLUGIN(example) { py::module m("example", "pybind11 example plugin"); py::class_ animal(m, "Animal"); @@ -375,7 +375,7 @@ See below for an example that uses the Internal internal; }; - PYBIND_PLUGIN(example) { + PYBIND11_PLUGIN(example) { py::module m("example", "pybind11 example plugin"); py::class_(m, "Example") @@ -441,7 +441,7 @@ be declared at the top level before any binding code: .. code-block:: cpp - PYBIND_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); .. seealso:: diff --git a/docs/basics.rst b/docs/basics.rst index 3d281d64e..c4db8f753 100644 --- a/docs/basics.rst +++ b/docs/basics.rst @@ -87,7 +87,7 @@ a file named :file:`example.cpp` with the following contents: namespace py = pybind11; - PYBIND_PLUGIN(example) { + PYBIND11_PLUGIN(example) { py::module m("example", "pybind11 example plugin"); m.def("add", &add, "A function which adds two numbers"); @@ -95,7 +95,7 @@ a file named :file:`example.cpp` with the following contents: return m.ptr(); } -The :func:`PYBIND_PLUGIN` macro creates a function that will be called when an +The :func:`PYBIND11_PLUGIN` macro creates a function that will be called when an ``import`` statement is issued from within Python. The next line creates a module named ``example`` (with the supplied docstring). The method :func:`module::def` generates binding code that exposes the diff --git a/docs/classes.rst b/docs/classes.rst index a7c75d838..db4dc427f 100644 --- a/docs/classes.rst +++ b/docs/classes.rst @@ -27,7 +27,7 @@ The binding code for ``Pet`` looks as follows: namespace py = pybind11; - PYBIND_PLUGIN(example) { + PYBIND11_PLUGIN(example) { py::module m("example", "pybind11 example plugin"); py::class_(m, "Pet") diff --git a/docs/reference.rst b/docs/reference.rst index 3a70822ac..16d2a8d14 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -12,7 +12,7 @@ Reference Macros ====== -.. function:: PYBIND_PLUGIN(const char *name) +.. function:: PYBIND11_PLUGIN(const char *name) This macro creates the entry point that will be invoked when the Python interpreter imports a plugin library. Please create a @@ -21,7 +21,7 @@ Macros .. code-block:: cpp - PYBIND_PLUGIN(example) { + PYBIND11_PLUGIN(example) { pybind11::module m("example", "pybind11 example plugin"); /// Set up bindings here return m.ptr(); diff --git a/example/example.cpp b/example/example.cpp index e7a3ffc51..0b97359b0 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -22,7 +22,7 @@ void init_ex10(py::module &); void init_ex11(py::module &); void init_ex12(py::module &); -PYBIND_PLUGIN(example) { +PYBIND11_PLUGIN(example) { py::module m("example", "pybind example plugin"); init_ex1(m); diff --git a/example/example12.cpp b/example/example12.cpp index d0e8699d5..57a0765c4 100644 --- a/example/example12.cpp +++ b/example/example12.cpp @@ -39,7 +39,7 @@ public: virtual int run(int value) { /* Generate wrapping code that enables native function overloading */ - PYBIND_OVERLOAD( + PYBIND11_OVERLOAD( int, /* Return type */ Example12, /* Parent class */ run, /* Name of function */ @@ -48,7 +48,7 @@ public: } virtual void pure_virtual() { - PYBIND_OVERLOAD_PURE( + PYBIND11_OVERLOAD_PURE( void, /* Return type */ Example12, /* Parent class */ pure_virtual /* Name of function */ diff --git a/example/example8.cpp b/example/example8.cpp index d8a43e382..cb9491658 100644 --- a/example/example8.cpp +++ b/example/example8.cpp @@ -32,7 +32,7 @@ private: }; /// Make pybind aware of the ref-counted wrapper type -PYBIND_DECLARE_HOLDER_TYPE(T, ref); +PYBIND11_DECLARE_HOLDER_TYPE(T, ref); Object *make_object_1() { return new MyObject(1); } ref make_object_2() { return new MyObject(2); } diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 84af4469f..a813252c7 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -25,9 +25,9 @@ NAMESPACE_BEGIN(detail) #endif #if PY_MAJOR_VERSION >= 3 -#define PYBIND_AS_STRING PyBytes_AsString +#define PYBIND11_AS_STRING PyBytes_AsString #else -#define PYBIND_AS_STRING PyString_AsString +#define PYBIND11_AS_STRING PyString_AsString #endif /** Linked list descriptor type for function signatures (produces smaller binaries @@ -214,7 +214,7 @@ protected: object temp; }; -#define PYBIND_TYPE_CASTER(type, py_name) \ +#define PYBIND11_TYPE_CASTER(type, py_name) \ protected: \ type value; \ public: \ @@ -225,7 +225,7 @@ protected: operator type*() { return &value; } \ operator type&() { return value; } \ -#define PYBIND_TYPE_CASTER_NUMBER(type, py_type, from_type, to_pytype) \ +#define PYBIND11_TYPE_CASTER_NUMBER(type, py_type, from_type, to_pytype) \ template <> class type_caster { \ public: \ bool load(PyObject *src, bool) { \ @@ -244,7 +244,7 @@ protected: static PyObject *cast(type src, return_value_policy /* policy */, PyObject * /* parent */) { \ return to_pytype((py_type) src); \ } \ - PYBIND_TYPE_CASTER(type, #type); \ + PYBIND11_TYPE_CASTER(type, #type); \ }; #if PY_MAJOR_VERSION >= 3 @@ -266,27 +266,27 @@ inline unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong_Fixed(PyObject *o) { } #endif -PYBIND_TYPE_CASTER_NUMBER(int8_t, long, PyLong_AsLong, PyLong_FromLong) -PYBIND_TYPE_CASTER_NUMBER(uint8_t, unsigned long, PyLong_AsUnsignedLong, PyLong_FromUnsignedLong) -PYBIND_TYPE_CASTER_NUMBER(int16_t, long, PyLong_AsLong, PyLong_FromLong) -PYBIND_TYPE_CASTER_NUMBER(uint16_t, unsigned long, PyLong_AsUnsignedLong, PyLong_FromUnsignedLong) -PYBIND_TYPE_CASTER_NUMBER(int32_t, long, PyLong_AsLong, PyLong_FromLong) -PYBIND_TYPE_CASTER_NUMBER(uint32_t, unsigned long, PyLong_AsUnsignedLong, PyLong_FromUnsignedLong) -PYBIND_TYPE_CASTER_NUMBER(int64_t, PY_LONG_LONG, PyLong_AsLongLong_Fixed, PyLong_FromLongLong) -PYBIND_TYPE_CASTER_NUMBER(uint64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong_Fixed, PyLong_FromUnsignedLongLong) +PYBIND11_TYPE_CASTER_NUMBER(int8_t, long, PyLong_AsLong, PyLong_FromLong) +PYBIND11_TYPE_CASTER_NUMBER(uint8_t, unsigned long, PyLong_AsUnsignedLong, PyLong_FromUnsignedLong) +PYBIND11_TYPE_CASTER_NUMBER(int16_t, long, PyLong_AsLong, PyLong_FromLong) +PYBIND11_TYPE_CASTER_NUMBER(uint16_t, unsigned long, PyLong_AsUnsignedLong, PyLong_FromUnsignedLong) +PYBIND11_TYPE_CASTER_NUMBER(int32_t, long, PyLong_AsLong, PyLong_FromLong) +PYBIND11_TYPE_CASTER_NUMBER(uint32_t, unsigned long, PyLong_AsUnsignedLong, PyLong_FromUnsignedLong) +PYBIND11_TYPE_CASTER_NUMBER(int64_t, PY_LONG_LONG, PyLong_AsLongLong_Fixed, PyLong_FromLongLong) +PYBIND11_TYPE_CASTER_NUMBER(uint64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong_Fixed, PyLong_FromUnsignedLongLong) #if defined(__APPLE__) // size_t/ssize_t are separate types on Mac OS X #if PY_MAJOR_VERSION >= 3 -PYBIND_TYPE_CASTER_NUMBER(ssize_t, Py_ssize_t, PyLong_AsSsize_t, PyLong_FromSsize_t) -PYBIND_TYPE_CASTER_NUMBER(size_t, size_t, PyLong_AsSize_t, PyLong_FromSize_t) +PYBIND11_TYPE_CASTER_NUMBER(ssize_t, Py_ssize_t, PyLong_AsSsize_t, PyLong_FromSsize_t) +PYBIND11_TYPE_CASTER_NUMBER(size_t, size_t, PyLong_AsSize_t, PyLong_FromSize_t) #else -PYBIND_TYPE_CASTER_NUMBER(ssize_t, PY_LONG_LONG, PyLong_AsLongLong_Fixed, PyLong_FromLongLong) -PYBIND_TYPE_CASTER_NUMBER(size_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong_Fixed, PyLong_FromUnsignedLongLong) +PYBIND11_TYPE_CASTER_NUMBER(ssize_t, PY_LONG_LONG, PyLong_AsLongLong_Fixed, PyLong_FromLongLong) +PYBIND11_TYPE_CASTER_NUMBER(size_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong_Fixed, PyLong_FromUnsignedLongLong) #endif #endif -PYBIND_TYPE_CASTER_NUMBER(float, double, PyFloat_AsDouble, PyFloat_FromDouble) -PYBIND_TYPE_CASTER_NUMBER(double, double, PyFloat_AsDouble, PyFloat_FromDouble) +PYBIND11_TYPE_CASTER_NUMBER(float, double, PyFloat_AsDouble, PyFloat_FromDouble) +PYBIND11_TYPE_CASTER_NUMBER(double, double, PyFloat_AsDouble, PyFloat_FromDouble) template <> class type_caster { public: @@ -295,7 +295,7 @@ public: Py_INCREF(Py_None); return Py_None; } - PYBIND_TYPE_CASTER(void_type, "None"); + PYBIND11_TYPE_CASTER(void_type, "None"); }; template <> class type_caster : public type_caster { @@ -313,7 +313,7 @@ public: Py_INCREF(result); return result; } - PYBIND_TYPE_CASTER(bool, "bool"); + PYBIND11_TYPE_CASTER(bool, "bool"); }; template <> class type_caster { @@ -325,7 +325,7 @@ public: object temp(PyUnicode_AsUTF8String(src), false); const char *ptr = nullptr; if (temp) - ptr = PYBIND_AS_STRING(temp.ptr()); + ptr = PYBIND11_AS_STRING(temp.ptr()); if (!ptr) { PyErr_Clear(); return false; } value = ptr; return true; @@ -333,7 +333,7 @@ public: static PyObject *cast(const std::string &src, return_value_policy /* policy */, PyObject * /* parent */) { return PyUnicode_FromString(src.c_str()); } - PYBIND_TYPE_CASTER(std::string, "str"); + PYBIND11_TYPE_CASTER(std::string, "str"); }; template <> class type_caster { @@ -345,7 +345,7 @@ public: object temp(PyUnicode_AsUTF8String(src), false); const char *ptr = nullptr; if (temp) - ptr = PYBIND_AS_STRING(temp.ptr()); + ptr = PYBIND11_AS_STRING(temp.ptr()); if (!ptr) { PyErr_Clear(); return false; } value = ptr; return true; @@ -527,7 +527,7 @@ protected: holder_type holder; }; -#define PYBIND_DECLARE_HOLDER_TYPE(type, holder_type) \ +#define PYBIND11_DECLARE_HOLDER_TYPE(type, holder_type) \ namespace pybind11 { namespace detail { \ template class type_caster \ : public type_caster_holder { }; \ @@ -543,24 +543,24 @@ public: src.inc_ref(); return (PyObject *) src.ptr(); } - PYBIND_TYPE_CASTER(handle, "handle"); + PYBIND11_TYPE_CASTER(handle, "handle"); }; -#define PYBIND_TYPE_CASTER_PYTYPE(name) \ +#define PYBIND11_TYPE_CASTER_PYTYPE(name) \ template <> class type_caster { \ public: \ bool load(PyObject *src, bool) { value = name(src, true); return true; } \ static PyObject *cast(const name &src, return_value_policy /* policy */, PyObject * /* parent */) { \ src.inc_ref(); return (PyObject *) src.ptr(); \ } \ - PYBIND_TYPE_CASTER(name, #name); \ + PYBIND11_TYPE_CASTER(name, #name); \ }; -PYBIND_TYPE_CASTER_PYTYPE(object) PYBIND_TYPE_CASTER_PYTYPE(buffer) -PYBIND_TYPE_CASTER_PYTYPE(capsule) PYBIND_TYPE_CASTER_PYTYPE(dict) -PYBIND_TYPE_CASTER_PYTYPE(float_) PYBIND_TYPE_CASTER_PYTYPE(int_) -PYBIND_TYPE_CASTER_PYTYPE(list) PYBIND_TYPE_CASTER_PYTYPE(slice) -PYBIND_TYPE_CASTER_PYTYPE(tuple) PYBIND_TYPE_CASTER_PYTYPE(function) +PYBIND11_TYPE_CASTER_PYTYPE(object) PYBIND11_TYPE_CASTER_PYTYPE(buffer) +PYBIND11_TYPE_CASTER_PYTYPE(capsule) PYBIND11_TYPE_CASTER_PYTYPE(dict) +PYBIND11_TYPE_CASTER_PYTYPE(float_) PYBIND11_TYPE_CASTER_PYTYPE(int_) +PYBIND11_TYPE_CASTER_PYTYPE(list) PYBIND11_TYPE_CASTER_PYTYPE(slice) +PYBIND11_TYPE_CASTER_PYTYPE(tuple) PYBIND11_TYPE_CASTER_PYTYPE(function) NAMESPACE_END(detail) diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 95807f75e..bfa8c4a44 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -16,11 +16,11 @@ #define NAMESPACE_END(name) } #endif -#if !defined(PYBIND_EXPORT) +#if !defined(PYBIND11_EXPORT) #if defined(WIN32) || defined(_WIN32) -#define PYBIND_EXPORT __declspec(dllexport) +#define PYBIND11_EXPORT __declspec(dllexport) #else -#define PYBIND_EXPORT __attribute__ ((visibility("default"))) +#define PYBIND11_EXPORT __attribute__ ((visibility("default"))) #endif #endif @@ -61,11 +61,11 @@ #endif #if PY_MAJOR_VERSION >= 3 -#define PYBIND_PLUGIN(name) \ - extern "C" PYBIND_EXPORT PyObject *PyInit_##name() +#define PYBIND11_PLUGIN(name) \ + extern "C" PYBIND11_EXPORT PyObject *PyInit_##name() #else -#define PYBIND_PLUGIN(name) \ - extern "C" PYBIND_EXPORT PyObject *init##name() +#define PYBIND11_PLUGIN(name) \ + extern "C" PYBIND11_EXPORT PyObject *init##name() #endif NAMESPACE_BEGIN(pybind11) @@ -93,10 +93,10 @@ enum class return_value_policy : int { /// Format strings for basic number types template struct format_descriptor { }; -#define PYBIND_DECL_FMT(t, n) template<> struct format_descriptor { static std::string value() { return n; }; }; -PYBIND_DECL_FMT(int8_t, "b"); PYBIND_DECL_FMT(uint8_t, "B"); PYBIND_DECL_FMT(int16_t, "h"); PYBIND_DECL_FMT(uint16_t, "H"); -PYBIND_DECL_FMT(int32_t, "i"); PYBIND_DECL_FMT(uint32_t, "I"); PYBIND_DECL_FMT(int64_t, "q"); PYBIND_DECL_FMT(uint64_t, "Q"); -PYBIND_DECL_FMT(float, "f"); PYBIND_DECL_FMT(double, "d"); PYBIND_DECL_FMT(bool, "?"); +#define PYBIND11_DECL_FMT(t, n) template<> struct format_descriptor { static std::string value() { return n; }; }; +PYBIND11_DECL_FMT(int8_t, "b"); PYBIND11_DECL_FMT(uint8_t, "B"); PYBIND11_DECL_FMT(int16_t, "h"); PYBIND11_DECL_FMT(uint16_t, "H"); +PYBIND11_DECL_FMT(int32_t, "i"); PYBIND11_DECL_FMT(uint32_t, "I"); PYBIND11_DECL_FMT(int64_t, "q"); PYBIND11_DECL_FMT(uint64_t, "Q"); +PYBIND11_DECL_FMT(float, "f"); PYBIND11_DECL_FMT(double, "d"); PYBIND11_DECL_FMT(bool, "?"); /// Information record describing a Python buffer object struct buffer_info { diff --git a/include/pybind11/complex.h b/include/pybind11/complex.h index 512b788fe..ce3276c05 100644 --- a/include/pybind11/complex.h +++ b/include/pybind11/complex.h @@ -14,8 +14,8 @@ NAMESPACE_BEGIN(pybind11) -PYBIND_DECL_FMT(std::complex, "Zf"); -PYBIND_DECL_FMT(std::complex, "Zd"); +PYBIND11_DECL_FMT(std::complex, "Zf"); +PYBIND11_DECL_FMT(std::complex, "Zd"); NAMESPACE_BEGIN(detail) template class type_caster> { @@ -34,7 +34,7 @@ public: return PyComplex_FromDoubles((double) src.real(), (double) src.imag()); } - PYBIND_TYPE_CASTER(std::complex, "complex"); + PYBIND11_TYPE_CASTER(std::complex, "complex"); }; NAMESPACE_END(detail) NAMESPACE_END(pybind11) diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h index c2cd1e612..10b21aee6 100644 --- a/include/pybind11/functional.h +++ b/include/pybind11/functional.h @@ -39,7 +39,7 @@ public: } - PYBIND_TYPE_CASTER(type, detail::descr("function<") + + PYBIND11_TYPE_CASTER(type, detail::descr("function<") + type_caster>::name() + detail::descr(" -> ") + type_caster::type>::name() + detail::descr(">")); diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 8a117866f..dfbdc4988 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -76,7 +76,7 @@ public: PyObject *(*PyArray_FromAny) (PyObject *, PyObject *, int, int, int, PyObject *); }; - PYBIND_OBJECT_DEFAULT(array, buffer, lookup_api().PyArray_Check) + PYBIND11_OBJECT_DEFAULT(array, buffer, lookup_api().PyArray_Check) template array(size_t size, const Type *ptr) { API& api = lookup_api(); @@ -126,7 +126,7 @@ protected: template class array_t : public array { public: - PYBIND_OBJECT_CVT(array_t, array, is_non_null, m_ptr = ensure(m_ptr)); + PYBIND11_OBJECT_CVT(array_t, array, is_non_null, m_ptr = ensure(m_ptr)); array_t() : array() { } static bool is_non_null(PyObject *ptr) { return ptr != nullptr; } PyObject *ensure(PyObject *ptr) { @@ -150,15 +150,15 @@ DECL_FMT(std::complex, NPY_CDOUBLE); NAMESPACE_BEGIN(detail) -PYBIND_TYPE_CASTER_PYTYPE(array) -PYBIND_TYPE_CASTER_PYTYPE(array_t) PYBIND_TYPE_CASTER_PYTYPE(array_t) -PYBIND_TYPE_CASTER_PYTYPE(array_t) PYBIND_TYPE_CASTER_PYTYPE(array_t) -PYBIND_TYPE_CASTER_PYTYPE(array_t) PYBIND_TYPE_CASTER_PYTYPE(array_t) -PYBIND_TYPE_CASTER_PYTYPE(array_t) PYBIND_TYPE_CASTER_PYTYPE(array_t) -PYBIND_TYPE_CASTER_PYTYPE(array_t) PYBIND_TYPE_CASTER_PYTYPE(array_t) -PYBIND_TYPE_CASTER_PYTYPE(array_t>) -PYBIND_TYPE_CASTER_PYTYPE(array_t>) -PYBIND_TYPE_CASTER_PYTYPE(array_t) +PYBIND11_TYPE_CASTER_PYTYPE(array) +PYBIND11_TYPE_CASTER_PYTYPE(array_t) PYBIND11_TYPE_CASTER_PYTYPE(array_t) +PYBIND11_TYPE_CASTER_PYTYPE(array_t) PYBIND11_TYPE_CASTER_PYTYPE(array_t) +PYBIND11_TYPE_CASTER_PYTYPE(array_t) PYBIND11_TYPE_CASTER_PYTYPE(array_t) +PYBIND11_TYPE_CASTER_PYTYPE(array_t) PYBIND11_TYPE_CASTER_PYTYPE(array_t) +PYBIND11_TYPE_CASTER_PYTYPE(array_t) PYBIND11_TYPE_CASTER_PYTYPE(array_t) +PYBIND11_TYPE_CASTER_PYTYPE(array_t>) +PYBIND11_TYPE_CASTER_PYTYPE(array_t>) +PYBIND11_TYPE_CASTER_PYTYPE(array_t) template struct vectorize_helper { diff --git a/include/pybind11/operators.h b/include/pybind11/operators.h index de90b34ea..d2caa88f4 100644 --- a/include/pybind11/operators.h +++ b/include/pybind11/operators.h @@ -59,7 +59,7 @@ template struct op_ { } }; -#define PYBIND_BINARY_OPERATOR(id, rid, op, expr) \ +#define PYBIND11_BINARY_OPERATOR(id, rid, op, expr) \ template struct op_impl { \ static char const* name() { return "__" #id "__"; } \ static auto execute(const L &l, const R &r) -> decltype(expr) { return (expr); } \ @@ -80,7 +80,7 @@ template op_ op(const T &, const self_t & return op_(); \ }; -#define PYBIND_INPLACE_OPERATOR(id, op, expr) \ +#define PYBIND11_INPLACE_OPERATOR(id, op, expr) \ template struct op_impl { \ static char const* name() { return "__" #id "__"; } \ static auto execute(L &l, const R &r) -> decltype(expr) { return expr; } \ @@ -90,7 +90,7 @@ template op_ op(const self_t &, const T & return op_(); \ }; -#define PYBIND_UNARY_OPERATOR(id, op, expr) \ +#define PYBIND11_UNARY_OPERATOR(id, op, expr) \ template struct op_impl { \ static char const* name() { return "__" #id "__"; } \ static auto execute(const L &l) -> decltype(expr) { return expr; } \ @@ -100,48 +100,48 @@ inline op_ op(const self_t &) { return op_(); \ }; -PYBIND_BINARY_OPERATOR(sub, rsub, operator-, l - r) -PYBIND_BINARY_OPERATOR(add, radd, operator+, l + r) -PYBIND_BINARY_OPERATOR(mul, rmul, operator*, l * r) +PYBIND11_BINARY_OPERATOR(sub, rsub, operator-, l - r) +PYBIND11_BINARY_OPERATOR(add, radd, operator+, l + r) +PYBIND11_BINARY_OPERATOR(mul, rmul, operator*, l * r) #if PY_MAJOR_VERSION >= 3 -PYBIND_BINARY_OPERATOR(truediv, rtruediv, operator/, l / r) +PYBIND11_BINARY_OPERATOR(truediv, rtruediv, operator/, l / r) #else -PYBIND_BINARY_OPERATOR(div, rdiv, operator/, l / r) +PYBIND11_BINARY_OPERATOR(div, rdiv, operator/, l / r) #endif -PYBIND_BINARY_OPERATOR(mod, rmod, operator%, l % r) -PYBIND_BINARY_OPERATOR(lshift, rlshift, operator<<, l << r) -PYBIND_BINARY_OPERATOR(rshift, rrshift, operator>>, l >> r) -PYBIND_BINARY_OPERATOR(and, rand, operator&, l & r) -PYBIND_BINARY_OPERATOR(xor, rxor, operator^, l ^ r) -PYBIND_BINARY_OPERATOR(eq, eq, operator==, l == r) -PYBIND_BINARY_OPERATOR(ne, ne, operator!=, l != r) -PYBIND_BINARY_OPERATOR(or, ror, operator|, l | r) -PYBIND_BINARY_OPERATOR(gt, lt, operator>, l > r) -PYBIND_BINARY_OPERATOR(ge, le, operator>=, l >= r) -PYBIND_BINARY_OPERATOR(lt, gt, operator<, l < r) -PYBIND_BINARY_OPERATOR(le, ge, operator<=, l <= r) -//PYBIND_BINARY_OPERATOR(pow, rpow, pow, std::pow(l, r)) -PYBIND_INPLACE_OPERATOR(iadd, operator+=, l += r) -PYBIND_INPLACE_OPERATOR(isub, operator-=, l -= r) -PYBIND_INPLACE_OPERATOR(imul, operator*=, l *= r) -PYBIND_INPLACE_OPERATOR(idiv, operator/=, l /= r) -PYBIND_INPLACE_OPERATOR(imod, operator%=, l %= r) -PYBIND_INPLACE_OPERATOR(ilshift, operator<<=, l <<= r) -PYBIND_INPLACE_OPERATOR(irshift, operator>>=, l >>= r) -PYBIND_INPLACE_OPERATOR(iand, operator&=, l &= r) -PYBIND_INPLACE_OPERATOR(ixor, operator^=, l ^= r) -PYBIND_INPLACE_OPERATOR(ior, operator|=, l |= r) -PYBIND_UNARY_OPERATOR(neg, operator-, -l) -PYBIND_UNARY_OPERATOR(pos, operator+, +l) -PYBIND_UNARY_OPERATOR(abs, abs, std::abs(l)) -PYBIND_UNARY_OPERATOR(invert, operator~, ~l) -PYBIND_UNARY_OPERATOR(bool, operator!, !!l) -PYBIND_UNARY_OPERATOR(int, int_, (int) l) -PYBIND_UNARY_OPERATOR(float, float_, (double) l) +PYBIND11_BINARY_OPERATOR(mod, rmod, operator%, l % r) +PYBIND11_BINARY_OPERATOR(lshift, rlshift, operator<<, l << r) +PYBIND11_BINARY_OPERATOR(rshift, rrshift, operator>>, l >> r) +PYBIND11_BINARY_OPERATOR(and, rand, operator&, l & r) +PYBIND11_BINARY_OPERATOR(xor, rxor, operator^, l ^ r) +PYBIND11_BINARY_OPERATOR(eq, eq, operator==, l == r) +PYBIND11_BINARY_OPERATOR(ne, ne, operator!=, l != r) +PYBIND11_BINARY_OPERATOR(or, ror, operator|, l | r) +PYBIND11_BINARY_OPERATOR(gt, lt, operator>, l > r) +PYBIND11_BINARY_OPERATOR(ge, le, operator>=, l >= r) +PYBIND11_BINARY_OPERATOR(lt, gt, operator<, l < r) +PYBIND11_BINARY_OPERATOR(le, ge, operator<=, l <= r) +//PYBIND11_BINARY_OPERATOR(pow, rpow, pow, std::pow(l, r)) +PYBIND11_INPLACE_OPERATOR(iadd, operator+=, l += r) +PYBIND11_INPLACE_OPERATOR(isub, operator-=, l -= r) +PYBIND11_INPLACE_OPERATOR(imul, operator*=, l *= r) +PYBIND11_INPLACE_OPERATOR(idiv, operator/=, l /= r) +PYBIND11_INPLACE_OPERATOR(imod, operator%=, l %= r) +PYBIND11_INPLACE_OPERATOR(ilshift, operator<<=, l <<= r) +PYBIND11_INPLACE_OPERATOR(irshift, operator>>=, l >>= r) +PYBIND11_INPLACE_OPERATOR(iand, operator&=, l &= r) +PYBIND11_INPLACE_OPERATOR(ixor, operator^=, l ^= r) +PYBIND11_INPLACE_OPERATOR(ior, operator|=, l |= r) +PYBIND11_UNARY_OPERATOR(neg, operator-, -l) +PYBIND11_UNARY_OPERATOR(pos, operator+, +l) +PYBIND11_UNARY_OPERATOR(abs, abs, std::abs(l)) +PYBIND11_UNARY_OPERATOR(invert, operator~, ~l) +PYBIND11_UNARY_OPERATOR(bool, operator!, !!l) +PYBIND11_UNARY_OPERATOR(int, int_, (int) l) +PYBIND11_UNARY_OPERATOR(float, float_, (double) l) -#undef PYBIND_BINARY_OPERATOR -#undef PYBIND_INPLACE_OPERATOR -#undef PYBIND_UNARY_OPERATOR +#undef PYBIND11_BINARY_OPERATOR +#undef PYBIND11_INPLACE_OPERATOR +#undef PYBIND11_UNARY_OPERATOR NAMESPACE_END(detail) using detail::self; diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 6c7fef0c9..47e99b9c8 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -429,7 +429,7 @@ private: class module : public object { public: - PYBIND_OBJECT_DEFAULT(module, object, PyModule_Check) + PYBIND11_OBJECT_DEFAULT(module, object, PyModule_Check) module(const char *name, const char *doc = nullptr) { #if PY_MAJOR_VERSION >= 3 @@ -476,7 +476,7 @@ NAMESPACE_BEGIN(detail) /// Basic support for creating new Python heap types class custom_type : public object { public: - PYBIND_OBJECT_DEFAULT(custom_type, object, PyType_Check) + PYBIND11_OBJECT_DEFAULT(custom_type, object, PyType_Check) custom_type(object &scope, const char *name_, const std::type_info *tinfo, size_t type_size, size_t instance_size, @@ -667,7 +667,7 @@ template > class cla public: typedef detail::instance instance_type; - PYBIND_OBJECT(class_, detail::custom_type, PyType_Check) + PYBIND11_OBJECT(class_, detail::custom_type, PyType_Check) class_(object &scope, const char *name, const char *doc = nullptr) : detail::custom_type(scope, name, &typeid(type), sizeof(type), @@ -925,18 +925,18 @@ inline function get_overload(const void *this_ptr, const char *name) { return overload; } -#define PYBIND_OVERLOAD_INT(ret_type, class_name, name, ...) { \ +#define PYBIND11_OVERLOAD_INT(ret_type, class_name, name, ...) { \ pybind11::gil_scoped_acquire gil; \ pybind11::function overload = pybind11::get_overload(this, #name); \ if (overload) \ return overload.call(__VA_ARGS__).cast(); } -#define PYBIND_OVERLOAD(ret_type, class_name, name, ...) \ - PYBIND_OVERLOAD_INT(ret_type, class_name, name, __VA_ARGS__) \ +#define PYBIND11_OVERLOAD(ret_type, class_name, name, ...) \ + PYBIND11_OVERLOAD_INT(ret_type, class_name, name, __VA_ARGS__) \ return class_name::name(__VA_ARGS__) -#define PYBIND_OVERLOAD_PURE(ret_type, class_name, name, ...) \ - PYBIND_OVERLOAD_INT(ret_type, class_name, name, __VA_ARGS__) \ +#define PYBIND11_OVERLOAD_PURE(ret_type, class_name, name, ...) \ + PYBIND11_OVERLOAD_INT(ret_type, class_name, name, __VA_ARGS__) \ throw std::runtime_error("Tried to call pure virtual function \"" #name "\""); NAMESPACE_END(pybind11) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 76956d487..f8b98c3b6 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -195,7 +195,7 @@ inline detail::accessor handle::operator[](const char *key) { return detail::acc inline detail::accessor handle::attr(handle key) { return detail::accessor(ptr(), key.ptr(), true); } inline detail::accessor handle::attr(const char *key) { return detail::accessor(ptr(), key, true); } -#define PYBIND_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 object& o): Parent(o) { CvtStmt; } \ Name(object&& o): Parent(std::move(o)) { CvtStmt; } \ @@ -203,16 +203,16 @@ inline detail::accessor handle::attr(const char *key) { return detail::accessor( Name& operator=(object& o) { return static_cast(object::operator=(o)); CvtStmt; } \ bool check() const { return m_ptr != nullptr && (bool) CheckFun(m_ptr); } -#define PYBIND_OBJECT(Name, Parent, CheckFun) \ - PYBIND_OBJECT_CVT(Name, Parent, CheckFun, ) +#define PYBIND11_OBJECT(Name, Parent, CheckFun) \ + PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ) -#define PYBIND_OBJECT_DEFAULT(Name, Parent, CheckFun) \ - PYBIND_OBJECT(Name, Parent, CheckFun) \ +#define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun) \ + PYBIND11_OBJECT(Name, Parent, CheckFun) \ Name() : Parent() { } class str : public object { public: - PYBIND_OBJECT_DEFAULT(str, object, PyUnicode_Check) + 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 @@ -241,13 +241,13 @@ inline pybind11::str handle::str() const { class bool_ : public object { public: - PYBIND_OBJECT_DEFAULT(bool_, object, PyBool_Check) + PYBIND11_OBJECT_DEFAULT(bool_, object, PyBool_Check) operator bool() const { return m_ptr && PyLong_AsLong(m_ptr) != 0; } }; class int_ : public object { public: - PYBIND_OBJECT_DEFAULT(int_, object, PyLong_Check) + PYBIND11_OBJECT_DEFAULT(int_, object, PyLong_Check) int_(int value) : object(PyLong_FromLong((long) value), false) { } int_(size_t value) : object(PyLong_FromSize_t(value), false) { } #if !defined(WIN32) || defined(_WIN64) @@ -258,7 +258,7 @@ public: class float_ : public object { public: - PYBIND_OBJECT_DEFAULT(float_, object, PyFloat_Check) + PYBIND11_OBJECT_DEFAULT(float_, object, PyFloat_Check) float_(float value) : object(PyFloat_FromDouble((double) value), false) { } float_(double value) : object(PyFloat_FromDouble((double) value), false) { } operator float() const { return (float) PyFloat_AsDouble(m_ptr); } @@ -267,7 +267,7 @@ public: class slice : public object { public: - PYBIND_OBJECT_DEFAULT(slice, object, PySlice_Check) + PYBIND11_OBJECT_DEFAULT(slice, object, PySlice_Check) slice(ssize_t start_, ssize_t stop_, ssize_t step_) { int_ start(start_), stop(stop_), step(step_); m_ptr = PySlice_New(start.ptr(), stop.ptr(), step.ptr()); @@ -285,7 +285,7 @@ public: class capsule : public object { public: - PYBIND_OBJECT_DEFAULT(capsule, object, PyCapsule_CheckExact) + PYBIND11_OBJECT_DEFAULT(capsule, object, PyCapsule_CheckExact) capsule(PyObject *obj, bool borrowed) : object(obj, borrowed) { } capsule(void *value, void (*destruct)(PyObject *) = nullptr) : object(PyCapsule_New(value, nullptr, destruct), false) { } template operator T *() const { @@ -297,7 +297,7 @@ public: class tuple : public object { public: - PYBIND_OBJECT_DEFAULT(tuple, object, PyTuple_Check) + PYBIND11_OBJECT_DEFAULT(tuple, object, PyTuple_Check) tuple(size_t size) : object(PyTuple_New((Py_ssize_t) size), false) { } size_t size() const { return (size_t) PyTuple_Size(m_ptr); } detail::tuple_accessor operator[](size_t index) { return detail::tuple_accessor(ptr(), index); } @@ -305,7 +305,7 @@ public: class dict : public object { public: - PYBIND_OBJECT(dict, object, PyDict_Check) + PYBIND11_OBJECT(dict, object, PyDict_Check) dict() : object(PyDict_New(), false) { } size_t size() const { return (size_t) PyDict_Size(m_ptr); } detail::dict_iterator begin() { return (++detail::dict_iterator(ptr(), 0)); } @@ -314,7 +314,7 @@ public: class list : public object { public: - PYBIND_OBJECT(list, object, PyList_Check) + PYBIND11_OBJECT(list, object, PyList_Check) list(size_t size = 0) : object(PyList_New((ssize_t) size), false) { } size_t size() const { return (size_t) PyList_Size(m_ptr); } detail::list_iterator begin() { return detail::list_iterator(ptr(), 0); } @@ -325,7 +325,7 @@ public: class function : public object { public: - PYBIND_OBJECT_DEFAULT(function, object, PyFunction_Check) + PYBIND11_OBJECT_DEFAULT(function, object, PyFunction_Check) bool is_cpp_function() { PyObject *ptr = m_ptr; @@ -343,7 +343,7 @@ public: class buffer : public object { public: - PYBIND_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer) + PYBIND11_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer) buffer_info request(bool writable = false) { int flags = PyBUF_STRIDES | PyBUF_FORMAT; diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index e4e819a2a..fc4637b46 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -54,7 +54,7 @@ public: } return list; } - PYBIND_TYPE_CASTER(type, detail::descr("list<") + value_conv::name() + detail::descr(">")); + PYBIND11_TYPE_CASTER(type, detail::descr("list<") + value_conv::name() + detail::descr(">")); }; template struct type_caster> { @@ -97,7 +97,7 @@ public: return dict; } - PYBIND_TYPE_CASTER(type, detail::descr("dict<") + key_conv::name() + detail::descr(", ") + value_conv::name() + detail::descr(">")); + PYBIND11_TYPE_CASTER(type, detail::descr("dict<") + key_conv::name() + detail::descr(", ") + value_conv::name() + detail::descr(">")); }; NAMESPACE_END(detail)