diff --git a/CMakeLists.txt b/CMakeLists.txt index 16c3dc6e6..82c0785ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.8) -project(pybind) +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") @@ -55,13 +55,13 @@ include_directories(include) # Create the binding library add_library(example SHARED - include/pybind/cast.h - include/pybind/common.h - include/pybind/operators.h - include/pybind/pybind.h - include/pybind/pytypes.h - include/pybind/typeid.h - include/pybind/numpy.h + include/pybind11/cast.h + include/pybind11/common.h + include/pybind11/operators.h + include/pybind11/pybind11.h + include/pybind11/pytypes.h + include/pybind11/typeid.h + include/pybind11/numpy.h example/example.cpp example/example1.cpp example/example2.cpp diff --git a/docs/advanced.rst b/docs/advanced.rst index 962869514..577bc04c8 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -8,9 +8,9 @@ present: .. code-block:: cpp - #include + #include - namespace py = pybind; + namespace py = pybind11 Operator overloading ==================== @@ -43,10 +43,10 @@ to Python. .. code-block:: cpp - #include + #include PYBIND_PLUGIN(example) { - py::module m("example", "pybind example plugin"); + py::module m("example", "pybind11 example plugin"); py::class_(m, "Vector2") .def(py::init()) @@ -79,7 +79,7 @@ C++ side, or to perform other types of customization. .. note:: To use the more convenient ``py::self`` notation, the additional - header file :file:`pybind/operators.h` must be included. + header file :file:`pybind11/operators.h` must be included. .. seealso:: @@ -120,15 +120,15 @@ its return value upon execution. }; } -After including the extra header file :file:`pybind/functional.h`, it is almost +After including the extra header file :file:`pybind11/functional.h`, it is almost trivial to generate binding code for both of these functions. .. code-block:: cpp - #include + #include PYBIND_PLUGIN(example) { - py::module m("example", "pybind example plugin"); + py::module m("example", "pybind11 example plugin"); m.def("func_arg", &func_arg); m.def("func_ret", &func_ret); @@ -200,7 +200,7 @@ Normally, the binding code for these classes would look as follows: .. code-block:: cpp PYBIND_PLUGIN(example) { - py::module m("example", "pybind example plugin"); + py::module m("example", "pybind11 example plugin"); py::class_ animal(m, "Animal"); animal @@ -248,7 +248,7 @@ a default implementation. The binding code also needs a few minor adaptations :emphasize-lines: 4,6,7 PYBIND_PLUGIN(example) { - py::module m("example", "pybind example plugin"); + py::module m("example", "pybind11 example plugin"); py::class_ animal(m, "Animal"); animal @@ -295,11 +295,11 @@ a virtual method call. Passing STL data structures =========================== -When including the additional header file :file:`pybind/stl.h`, conversions +When including the additional header file :file:`pybind11/stl.h`, conversions between ``std::vector<>`` and ``std::map<>`` and the Python ``list`` and ``dict`` data structures are automatically enabled. The types ``std::pair<>`` and ``std::tuple<>`` are already supported out of the box with just the core -:file:`pybind/pybind.h` header. +:file:`pybind11/pybind11.h` header. .. note:: @@ -376,7 +376,7 @@ See below for an example that uses the }; PYBIND_PLUGIN(example) { - py::module m("example", "pybind example plugin"); + py::module m("example", "pybind11 example plugin"); py::class_(m, "Example") .def(py::init<>()) @@ -620,7 +620,7 @@ dense array of doubles in C-style ordering. When it is invoked with a different type (e.g. an integer), the binding code will attempt to cast the input into a NumPy array of the requested type. -Note that this feature requires the ``pybind/numpy.h`` header to be included. +Note that this feature requires the ``pybind11/numpy.h`` header to be included. Vectorizing functions ===================== @@ -633,7 +633,7 @@ N-D arrays) in addition to its normal arguments: double my_func(int x, float y, double z); -After including the ``pybind/numpy.h`` header, this is extremely simple: +After including the ``pybind11/numpy.h`` header, this is extremely simple: .. code-block:: cpp diff --git a/docs/basics.rst b/docs/basics.rst index a4e727190..b55d402d6 100644 --- a/docs/basics.rst +++ b/docs/basics.rst @@ -37,7 +37,7 @@ Windows On Windows, use the `CMake GUI`_ to create a Visual Studio project. Note that only the 2015 release and newer versions are supported since pybind11 relies on various C++11 language features that break older versions of Visual Studio. -After running CMake, open the created :file:`pybind.sln` file and perform a +After running CMake, open the created :file:`pybind11.sln` file and perform a release build, which will will produce a file named :file:`Release\\example.pyd`. Copy this file to the :file:`example` directory and run :file:`example\\run_test.py` using the targeted Python version. @@ -79,16 +79,16 @@ a file named :file:`example.cpp` with the following contents: .. code-block:: cpp - #include + #include int add(int i, int j) { return i + j; } - namespace py = pybind; + namespace py = pybind11 PYBIND_PLUGIN(example) { - py::module m("example", "pybind example plugin"); + py::module m("example", "pybind11 example plugin"); m.def("add", &add, "A function which adds two numbers"); @@ -117,7 +117,7 @@ example can be compiled using the following command .. code-block:: bash - $ c++ -O3 -shared -std=c++11 -I /include `python-config --cflags --libs` example.cpp -o example.so + $ c++ -O3 -shared -std=c++11 -I /include `python-config --cflags --libs` example.cpp -o example.so In general, it is advisable to include several additional build parameters that can considerably reduce the size of the created binary. Refer to section @@ -222,41 +222,41 @@ The following basic data types are supported out of the box (some may require an additional extension header to be included). To pass other data structures as arguments and return values, refer to the section on binding :ref:`classes`. -+------------------------+--------------------------+---------------------+ -| Data type | Description | Header file | -+========================+==========================+=====================+ -| int8_t, uint8_t | 8-bit integers | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| int16_t, uint16_t | 16-bit integers | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| int32_t, uint32_t | 32-bit integers | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| int64_t, uint64_t | 64-bit integers | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| ssize_t, size_t | Platform-dependent size | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| float, double | Floating point types | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| bool | Two-state Boolean type | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| char | Character literal | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| const char * | UTF-8 string literal | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| std::string | STL dynamic UTF-8 string | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| std::pair | Pair of two custom types | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| std::tuple<....> | Arbitrary tuple of types | pybind/pybind.h | -+------------------------+--------------------------+---------------------+ -| std::complex | Complex numbers | pybind/complex.h | -+------------------------+--------------------------+---------------------+ -| std::vector | STL dynamic array | pybind/stl.h | -+------------------------+--------------------------+---------------------+ -| std::map | STL dynamic maps | pybind/stl.h | -+------------------------+--------------------------+---------------------+ -| std::function<...> | STL polymorphic function | pybind/functional.h | -+------------------------+--------------------------+---------------------+ ++------------------------+--------------------------+-----------------------+ +| Data type | Description | Header file | ++========================+==========================+=======================+ +| int8_t, uint8_t | 8-bit integers | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| int16_t, uint16_t | 16-bit integers | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| int32_t, uint32_t | 32-bit integers | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| int64_t, uint64_t | 64-bit integers | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| ssize_t, size_t | Platform-dependent size | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| float, double | Floating point types | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| bool | Two-state Boolean type | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| char | Character literal | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| const char * | UTF-8 string literal | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| std::string | STL dynamic UTF-8 string | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| std::pair | Pair of two custom types | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| std::tuple<....> | Arbitrary tuple of types | pybind11/pybind11.h | ++------------------------+--------------------------+-----------------------+ +| std::complex | Complex numbers | pybind11/complex.h | ++------------------------+--------------------------+-----------------------+ +| std::vector | STL dynamic array | pybind11/stl.h | ++------------------------+--------------------------+-----------------------+ +| std::map | STL dynamic maps | pybind11/stl.h | ++------------------------+--------------------------+-----------------------+ +| std::function<...> | STL polymorphic function | pybind11/functional.h | ++------------------------+--------------------------+-----------------------+ .. [#f1] In practice, implementation and binding code will generally be located diff --git a/docs/classes.rst b/docs/classes.rst index 9f3b56cb6..5ef042ccf 100644 --- a/docs/classes.rst +++ b/docs/classes.rst @@ -23,12 +23,12 @@ The binding code for ``Pet`` looks as follows: .. code-block:: cpp - #include + #include - namespace py = pybind; + namespace py = pybind11 PYBIND_PLUGIN(example) { - py::module m("example", "pybind example plugin"); + py::module m("example", "pybind11 example plugin"); py::class_(m, "Pet") .def(py::init()) diff --git a/docs/reference.rst b/docs/reference.rst index 5fade60a1..3a70822ac 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -4,7 +4,7 @@ Please be advised that the reference documentation discussing pybind11 internals is currently incomplete. Please refer to the previous sections - and the pybind header files for the nitty gritty details. + and the pybind11 header files for the nitty gritty details. Reference ######### @@ -22,7 +22,7 @@ Macros .. code-block:: cpp PYBIND_PLUGIN(example) { - pybind::module m("example", "pybind example plugin"); + pybind11::module m("example", "pybind11 example plugin"); /// Set up bindings here return m.ptr(); } @@ -188,9 +188,9 @@ Convenience classes for specific Python types .. code-block:: cpp - pybind::module m("example", "pybind example plugin"); - pybind::module m2 = m.def_submodule("sub", "A submodule of 'example'"); - pybind::module m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'"); + pybind11::module m("example", "pybind11 example plugin"); + pybind11::module m2 = m.def_submodule("sub", "A submodule of 'example'"); + pybind11::module m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'"); .. cpp:function:: template module& module::def(const char *name, Func && f, Extra && ... extra) diff --git a/example/example.h b/example/example.h index 67434bb11..ab8fff796 100644 --- a/example/example.h +++ b/example/example.h @@ -1,7 +1,7 @@ -#include +#include #include using std::cout; using std::endl; -namespace py = pybind; +namespace py = pybind11; diff --git a/example/example10.cpp b/example/example10.cpp index 80f789028..1a377e569 100644 --- a/example/example10.cpp +++ b/example/example10.cpp @@ -9,7 +9,7 @@ */ #include "example.h" -#include +#include double my_func(int x, float y, double z) { std::cout << "my_func(x:int=" << x << ", y:float=" << y << ", z:float=" << z << ")" << std::endl; diff --git a/example/example12.cpp b/example/example12.cpp index 274edf832..d0e8699d5 100644 --- a/example/example12.cpp +++ b/example/example12.cpp @@ -8,7 +8,7 @@ */ #include "example.h" -#include +#include /* This is an example class that we'll want to be able to extend from Python */ class Example12 { diff --git a/example/example2.cpp b/example/example2.cpp index 580fbc3d5..f7972e03e 100644 --- a/example/example2.cpp +++ b/example/example2.cpp @@ -9,7 +9,7 @@ */ #include "example.h" -#include +#include class Example2 { public: diff --git a/example/example3.cpp b/example/example3.cpp index 80bdf0e43..3b3a6253e 100644 --- a/example/example3.cpp +++ b/example/example3.cpp @@ -8,7 +8,7 @@ */ #include "example.h" -#include +#include class Vector2 { public: diff --git a/example/example5.cpp b/example/example5.cpp index 34c7abe1c..cabd84795 100644 --- a/example/example5.cpp +++ b/example/example5.cpp @@ -9,7 +9,7 @@ */ #include "example.h" -#include +#include class Pet { diff --git a/example/example6.cpp b/example/example6.cpp index 880f86558..416c1d010 100644 --- a/example/example6.cpp +++ b/example/example6.cpp @@ -9,8 +9,8 @@ */ #include "example.h" -#include -#include +#include +#include class Sequence { public: diff --git a/example/example8.cpp b/example/example8.cpp index 475f72a6c..d8a43e382 100644 --- a/example/example8.cpp +++ b/example/example8.cpp @@ -32,10 +32,7 @@ private: }; /// Make pybind aware of the ref-counted wrapper type -namespace pybind { namespace detail { -template class type_caster> - : public type_caster_holder> { }; -}} +PYBIND_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/pybind/cast.h b/include/pybind11/cast.h similarity index 97% rename from include/pybind/cast.h rename to include/pybind11/cast.h index d949da8e4..84af4469f 100644 --- a/include/pybind/cast.h +++ b/include/pybind11/cast.h @@ -1,5 +1,5 @@ /* - pybind/cast.h: Partial template specializations to cast between + pybind11/cast.h: Partial template specializations to cast between C++ and Python types Copyright (c) 2015 Wenzel Jakob @@ -10,12 +10,12 @@ #pragma once -#include -#include +#include "pytypes.h" +#include "typeid.h" #include #include -NAMESPACE_BEGIN(pybind) +NAMESPACE_BEGIN(pybind11) NAMESPACE_BEGIN(detail) #if defined(_MSC_VER) @@ -527,6 +527,12 @@ protected: holder_type holder; }; +#define PYBIND_DECLARE_HOLDER_TYPE(type, holder_type) \ + namespace pybind11 { namespace detail { \ + template class type_caster \ + : public type_caster_holder { }; \ + }} + template <> class type_caster { public: bool load(PyObject *src) { @@ -571,7 +577,7 @@ template inline object cast(const T &value, return_value_policy pol return object(detail::type_caster::type>::cast(value, policy, parent), false); } -template inline T handle::cast() { return pybind::cast(m_ptr); } +template inline T handle::cast() { return pybind11::cast(m_ptr); } template <> inline void handle::cast() { return; } template inline object handle::call(Args&&... args_) { @@ -601,4 +607,4 @@ template inline object handle::call(Args&&... args_) { return object(result, false); } -NAMESPACE_END(pybind) +NAMESPACE_END(pybind11) diff --git a/include/pybind/common.h b/include/pybind11/common.h similarity index 97% rename from include/pybind/common.h rename to include/pybind11/common.h index 427bce705..95807f75e 100644 --- a/include/pybind/common.h +++ b/include/pybind11/common.h @@ -1,5 +1,5 @@ /* - pybind/common.h -- Basic macros + pybind11/common.h -- Basic macros Copyright (c) 2015 Wenzel Jakob @@ -68,7 +68,7 @@ extern "C" PYBIND_EXPORT PyObject *init##name() #endif -NAMESPACE_BEGIN(pybind) +NAMESPACE_BEGIN(pybind11) typedef Py_ssize_t ssize_t; @@ -192,7 +192,7 @@ NAMESPACE_END(detail) struct stop_iteration : public std::runtime_error { public: stop_iteration(const std::string &w="") : std::runtime_error(w) {} }; struct index_error : public std::runtime_error { public: index_error(const std::string &w="") : std::runtime_error(w) {} }; struct error_already_set : public std::runtime_error { public: error_already_set() : std::runtime_error(detail::error_string()) {} }; -/// Thrown when pybind::cast or handle::call fail due to a type casting error +/// Thrown when pybind11::cast or handle::call fail due to a type casting error struct cast_error : public std::runtime_error { public: cast_error(const std::string &w = "") : std::runtime_error(w) {} }; -NAMESPACE_END(pybind) +NAMESPACE_END(pybind11) diff --git a/include/pybind/complex.h b/include/pybind11/complex.h similarity index 89% rename from include/pybind/complex.h rename to include/pybind11/complex.h index 9d690b14f..512b788fe 100644 --- a/include/pybind/complex.h +++ b/include/pybind11/complex.h @@ -1,5 +1,5 @@ /* - pybind/complex.h: Complex number support + pybind11/complex.h: Complex number support Copyright (c) 2015 Wenzel Jakob @@ -9,10 +9,10 @@ #pragma once -#include +#include "pybind11.h" #include -NAMESPACE_BEGIN(pybind) +NAMESPACE_BEGIN(pybind11) PYBIND_DECL_FMT(std::complex, "Zf"); PYBIND_DECL_FMT(std::complex, "Zd"); @@ -37,4 +37,4 @@ public: PYBIND_TYPE_CASTER(std::complex, "complex"); }; NAMESPACE_END(detail) -NAMESPACE_END(pybind) +NAMESPACE_END(pybind11) diff --git a/include/pybind/functional.h b/include/pybind11/functional.h similarity index 86% rename from include/pybind/functional.h rename to include/pybind11/functional.h index 7c3c9a006..c2cd1e612 100644 --- a/include/pybind/functional.h +++ b/include/pybind11/functional.h @@ -1,5 +1,5 @@ /* - pybind/functional.h: std::function<> support + pybind11/functional.h: std::function<> support Copyright (c) 2015 Wenzel Jakob @@ -9,10 +9,10 @@ #pragma once -#include +#include "pybind11.h" #include -NAMESPACE_BEGIN(pybind) +NAMESPACE_BEGIN(pybind11) NAMESPACE_BEGIN(detail) template struct type_caster> { @@ -24,7 +24,7 @@ public: return false; object src(src_, true); value = [src](Args... args) -> Return { - object retval(pybind::handle(src).call(std::move(args)...)); + object retval(pybind11::handle(src).call(std::move(args)...)); /* Visual studio 2015 parser issue: need parentheses around this expression */ return (retval.template cast()); }; @@ -46,4 +46,4 @@ public: }; NAMESPACE_END(detail) -NAMESPACE_END(pybind) +NAMESPACE_END(pybind11) diff --git a/include/pybind/numpy.h b/include/pybind11/numpy.h similarity index 97% rename from include/pybind/numpy.h rename to include/pybind11/numpy.h index 93a3c6bee..8a117866f 100644 --- a/include/pybind/numpy.h +++ b/include/pybind11/numpy.h @@ -1,5 +1,5 @@ /* - pybind/numpy.h: Basic NumPy support, auto-vectorization support + pybind11/numpy.h: Basic NumPy support, auto-vectorization support Copyright (c) 2015 Wenzel Jakob @@ -9,15 +9,15 @@ #pragma once -#include -#include +#include "pybind11.h" +#include "complex.h" #if defined(_MSC_VER) #pragma warning(push) #pragma warning(disable: 4127) // warning C4127: Conditional expression is constant #endif -NAMESPACE_BEGIN(pybind) +NAMESPACE_BEGIN(pybind11) template struct npy_format_descriptor { }; @@ -196,7 +196,7 @@ struct vectorize_helper { /* Check if the parameters are actually compatible */ for (size_t i=0; i auto vectorize(func &&f) -> decltype( &std::remove_reference::type::operator())>::type *) nullptr); } -NAMESPACE_END(pybind) +NAMESPACE_END(pybind11) #if defined(_MSC_VER) #pragma warning(pop) diff --git a/include/pybind/operators.h b/include/pybind11/operators.h similarity index 96% rename from include/pybind/operators.h rename to include/pybind11/operators.h index 1e08fdac4..de90b34ea 100644 --- a/include/pybind/operators.h +++ b/include/pybind11/operators.h @@ -1,5 +1,5 @@ /* - pybind/operator.h: Metatemplates for operator overloading + pybind11/operator.h: Metatemplates for operator overloading Copyright (c) 2015 Wenzel Jakob @@ -9,10 +9,10 @@ #pragma once -#include +#include "pybind11.h" #include -NAMESPACE_BEGIN(pybind) +NAMESPACE_BEGIN(pybind11) NAMESPACE_BEGIN(detail) /// Enumeration with all supported operator types @@ -45,13 +45,13 @@ template struct op_impl { } /// Operator implementation generator template struct op_ { - template void execute(pybind::class_ &class_, Extra&&... extra) const { + template void execute(pybind11::class_ &class_, Extra&&... extra) const { typedef typename std::conditional::value, Base, L>::type L_type; typedef typename std::conditional::value, Base, R>::type R_type; typedef op_impl op; class_.def(op::name(), &op::execute, std::forward(extra)...); } - template void execute_cast(pybind::class_ &class_, Extra&&... extra) const { + template void execute_cast(pybind11::class_ &class_, Extra&&... extra) const { typedef typename std::conditional::value, Base, L>::type L_type; typedef typename std::conditional::value, Base, R>::type R_type; typedef op_impl op; @@ -146,4 +146,4 @@ NAMESPACE_END(detail) using detail::self; -NAMESPACE_END(pybind) +NAMESPACE_END(pybind11) diff --git a/include/pybind/pybind.h b/include/pybind11/pybind11.h similarity index 94% rename from include/pybind/pybind.h rename to include/pybind11/pybind11.h index 86fc60991..6c7fef0c9 100644 --- a/include/pybind/pybind.h +++ b/include/pybind11/pybind11.h @@ -1,5 +1,5 @@ /* - pybind/pybind.h: Main header file of the C++11 python binding generator library + pybind11/pybind11.h: Main header file of the C++11 python binding generator library Copyright (c) 2015 Wenzel Jakob @@ -23,9 +23,9 @@ #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif -#include +#include "cast.h" -NAMESPACE_BEGIN(pybind) +NAMESPACE_BEGIN(pybind11) template struct arg_t; @@ -113,31 +113,31 @@ private: } static void process_extra(const char *doc, function_entry *entry, const char **, const char **) { entry->doc = doc; } - static void process_extra(const pybind::doc &d, function_entry *entry, const char **, const char **) { entry->doc = d.value; } - static void process_extra(const pybind::name &n, function_entry *entry, const char **, const char **) { entry->name = n.value; } - static void process_extra(const pybind::arg &a, function_entry *entry, const char **kw, const char **) { + static void process_extra(const pybind11::doc &d, function_entry *entry, const char **, const char **) { entry->doc = d.value; } + static void process_extra(const pybind11::name &n, function_entry *entry, const char **, const char **) { entry->name = n.value; } + static void process_extra(const pybind11::arg &a, function_entry *entry, const char **kw, const char **) { if (entry->is_method && entry->keywords == 0) kw[entry->keywords++] = "self"; kw[entry->keywords++] = a.name; } template - static void process_extra(const pybind::arg_t &a, function_entry *entry, const char **kw, const char **def) { + static void process_extra(const pybind11::arg_t &a, function_entry *entry, const char **kw, const char **def) { if (entry->is_method && entry->keywords == 0) kw[entry->keywords++] = "self"; kw[entry->keywords] = a.name; def[entry->keywords++] = strdup(detail::to_string(a.value).c_str()); } - static void process_extra(const pybind::is_method &m, function_entry *entry, const char **, const char **) { + static void process_extra(const pybind11::is_method &m, function_entry *entry, const char **, const char **) { entry->is_method = true; entry->class_ = m.class_; } - static void process_extra(const pybind::return_value_policy p, function_entry *entry, const char **, const char **) { entry->policy = p; } - static void process_extra(pybind::sibling s, function_entry *entry, const char **, const char **) { entry->sibling = s.value; } + static void process_extra(const pybind11::return_value_policy p, function_entry *entry, const char **, const char **) { entry->policy = p; } + static void process_extra(pybind11::sibling s, function_entry *entry, const char **, const char **) { entry->sibling = s.value; } template static void process_extra(T, int &, PyObject *, PyObject *) { } - static void process_extra(const pybind::arg &a, int &index, PyObject *args, PyObject *kwargs) { + static void process_extra(const pybind11::arg &a, int &index, PyObject *args, PyObject *kwargs) { if (kwargs) { if (PyTuple_GET_ITEM(args, index) != nullptr) { index++; @@ -152,7 +152,7 @@ private: index++; } template - static void process_extra(const pybind::arg_t &a, int &index, PyObject *args, PyObject *kwargs) { + static void process_extra(const pybind11::arg_t &a, int &index, PyObject *args, PyObject *kwargs) { if (PyTuple_GET_ITEM(args, index) != nullptr) { index++; return; @@ -327,7 +327,7 @@ private: PyObject *inst = PyTuple_GetItem(args, 0); const detail::type_info *type_info = capsule(PyObject_GetAttrString((PyObject *) Py_TYPE(inst), - const_cast("__pybind__")), false); + const_cast("__pybind11__")), false); type_info->init_holder(inst); } return result; @@ -360,7 +360,7 @@ private: throw std::runtime_error( "cpp_function(): function \"" + std::string(m_entry->name) + "\" takes " + std::to_string(args) + " arguments, but " + std::to_string(m_entry->keywords) + - " pybind::arg entries were specified!"); + " pybind11::arg entries were specified!"); m_entry->is_constructor = !strcmp(m_entry->name, "__init__"); m_entry->signature = descr.str(); @@ -462,7 +462,7 @@ public: + std::string(".") + std::string(name); module result(PyImport_AddModule(full_name.c_str()), true); if (doc) - result.attr("__doc__") = pybind::str(doc); + result.attr("__doc__") = pybind11::str(doc); attr(name) = result; return result; } @@ -493,7 +493,7 @@ public: Py_INCREF(name); std::string full_name(name_); - pybind::str scope_name = (object) scope.attr("__name__"), + pybind11::str scope_name = (object) scope.attr("__name__"), module_name = (object) scope.attr("__module__"); if (scope_name.check()) @@ -538,7 +538,7 @@ public: type_info.type = (PyTypeObject *) m_ptr; type_info.type_size = type_size; type_info.init_holder = init_holder; - attr("__pybind__") = capsule(&type_info); + attr("__pybind11__") = capsule(&type_info); scope.attr(name) = *this; } @@ -584,7 +584,7 @@ protected: static PyObject *new_instance(PyTypeObject *type, PyObject *, PyObject *) { const detail::type_info *type_info = capsule( - PyObject_GetAttrString((PyObject *) type, const_cast("__pybind__")), false); + PyObject_GetAttrString((PyObject *) type, const_cast("__pybind11__")), false); instance *self = (instance *) PyType_GenericAlloc(type, 0); self->value = ::operator new(type_info->type_size); self->owned = true; @@ -619,13 +619,13 @@ protected: #endif type->as_buffer.bf_getbuffer = getbuffer; type->as_buffer.bf_releasebuffer = releasebuffer; - auto info = ((detail::type_info *) capsule(attr("__pybind__"))); + auto info = ((detail::type_info *) capsule(attr("__pybind11__"))); info->get_buffer = get_buffer; info->get_buffer_data = get_buffer_data; } static int getbuffer(PyObject *obj, Py_buffer *view, int flags) { - auto const &typeinfo = ((detail::type_info *) capsule(handle(obj).attr("__pybind__"))); + auto const &typeinfo = ((detail::type_info *) capsule(handle(obj).attr("__pybind11__"))); if (view == nullptr || obj == nullptr || !typeinfo || !typeinfo->get_buffer) { PyErr_SetString(PyExc_BufferError, "Internal error"); @@ -776,7 +776,7 @@ public: } class_ &def_property(const char *name, const cpp_function &fget, const cpp_function &fset, const char *doc = nullptr) { - object doc_obj = doc ? pybind::str(doc) : (object) const_cast(fget).attr("__doc__"); + object doc_obj = doc ? pybind11::str(doc) : (object) const_cast(fget).attr("__doc__"); object property( PyObject_CallFunction((PyObject *)&PyProperty_Type, const_cast("OOOO"), fget.ptr() ? fget.ptr() : Py_None, @@ -786,7 +786,7 @@ public: } class_ &def_property_static(const char *name, const cpp_function &fget, const cpp_function &fset, const char *doc = nullptr) { - object doc_obj = doc ? pybind::str(doc) : (object) const_cast(fget).attr("__doc__"); + object doc_obj = doc ? pybind11::str(doc) : (object) const_cast(fget).attr("__doc__"); object property( PyObject_CallFunction((PyObject *)&PyProperty_Type, const_cast("OOOs"), fget.ptr() ? fget.ptr() : Py_None, @@ -796,7 +796,7 @@ public: } template class_ alias() { - auto &instances = pybind::detail::get_internals().registered_types; + auto &instances = pybind11::detail::get_internals().registered_types; instances[&typeid(target)] = instances[&typeid(type)]; return *this; } @@ -846,7 +846,7 @@ public: /// Add an enumeration entry enum_& value(char const* name, Type value) { - this->attr(name) = pybind::cast(value, return_value_policy::copy); + this->attr(name) = pybind11::cast(value, return_value_policy::copy); (*m_entries)[(int) value] = name; return *this; } @@ -857,7 +857,7 @@ private: NAMESPACE_BEGIN(detail) template struct init { - template void execute(pybind::class_ &class_, Extra&&... extra) const { + template void execute(pybind11::class_ &class_, Extra&&... extra) const { /// Function which calls a specific C++ in-place constructor class_.def("__init__", [](Base *instance, Args... args) { new (instance) Base(args...); }, std::forward(extra)...); } @@ -919,15 +919,15 @@ inline function get_overload(const void *this_ptr, const char *name) { return function(); } PyFrameObject *frame = PyThreadState_Get()->frame; - pybind::str caller = pybind::handle(frame->f_code->co_name).str(); + pybind11::str caller = pybind11::handle(frame->f_code->co_name).str(); if (strcmp((const char *) caller, name) == 0) return function(); return overload; } #define PYBIND_OVERLOAD_INT(ret_type, class_name, name, ...) { \ - pybind::gil_scoped_acquire gil; \ - pybind::function overload = pybind::get_overload(this, #name); \ + pybind11::gil_scoped_acquire gil; \ + pybind11::function overload = pybind11::get_overload(this, #name); \ if (overload) \ return overload.call(__VA_ARGS__).cast(); } @@ -939,7 +939,7 @@ inline function get_overload(const void *this_ptr, const char *name) { PYBIND_OVERLOAD_INT(ret_type, class_name, name, __VA_ARGS__) \ throw std::runtime_error("Tried to call pure virtual function \"" #name "\""); -NAMESPACE_END(pybind) +NAMESPACE_END(pybind11) #if defined(_MSC_VER) #pragma warning(pop) diff --git a/include/pybind/pytypes.h b/include/pybind11/pytypes.h similarity index 97% rename from include/pybind/pytypes.h rename to include/pybind11/pytypes.h index 4f70bbd23..76956d487 100644 --- a/include/pybind/pytypes.h +++ b/include/pybind11/pytypes.h @@ -1,5 +1,5 @@ /* - pybind/typeid.h: Convenience wrapper classes for basic Python types + pybind11/typeid.h: Convenience wrapper classes for basic Python types Copyright (c) 2015 Wenzel Jakob @@ -9,10 +9,10 @@ #pragma once -#include +#include "common.h" #include -NAMESPACE_BEGIN(pybind) +NAMESPACE_BEGIN(pybind11) /* A few forward declarations */ class object; @@ -37,7 +37,7 @@ public: inline detail::accessor operator[](const char *key); inline detail::accessor attr(handle key); inline detail::accessor attr(const char *key); - inline pybind::str str() const; + inline pybind11::str str() const; template T cast(); template object call(Args&&... args_); operator bool() const { return m_ptr != nullptr; } @@ -230,13 +230,13 @@ private: #endif }; -inline pybind::str handle::str() const { +inline pybind11::str handle::str() const { PyObject *str = PyObject_Str(m_ptr); #if PY_MAJOR_VERSION < 3 PyObject *unicode = PyUnicode_FromEncodedObject(str, "utf-8", nullptr); Py_XDECREF(str); str = unicode; #endif - return pybind::str(str, false); + return pybind11::str(str, false); } class bool_ : public object { @@ -370,12 +370,12 @@ inline internals &get_internals() { if (internals_ptr) return *internals_ptr; handle builtins(PyEval_GetBuiltins()); - capsule caps(builtins["__pybind__"]); + capsule caps(builtins["__pybind11__"]); if (caps.check()) { internals_ptr = caps; } else { internals_ptr = new internals(); - builtins["__pybind__"] = capsule(internals_ptr); + builtins["__pybind11__"] = capsule(internals_ptr); } return *internals_ptr; } @@ -413,4 +413,4 @@ inline handle get_type_handle(const std::type_info &tp) { } NAMESPACE_END(detail) -NAMESPACE_END(pybind) +NAMESPACE_END(pybind11) diff --git a/include/pybind/stl.h b/include/pybind11/stl.h similarity index 96% rename from include/pybind/stl.h rename to include/pybind11/stl.h index bf1d8980f..e4e819a2a 100644 --- a/include/pybind/stl.h +++ b/include/pybind11/stl.h @@ -1,5 +1,5 @@ /* - pybind/complex.h: Complex number support + pybind11/complex.h: Complex number support Copyright (c) 2015 Wenzel Jakob @@ -9,7 +9,7 @@ #pragma once -#include +#include "pybind11.h" #include #include @@ -19,7 +19,7 @@ #pragma warning(disable: 4127) // warning C4127: Conditional expression is constant #endif -NAMESPACE_BEGIN(pybind) +NAMESPACE_BEGIN(pybind11) NAMESPACE_BEGIN(detail) template struct type_caster> { @@ -104,7 +104,7 @@ NAMESPACE_END(detail) inline std::ostream &operator<<(std::ostream &os, const object &obj) { os << (const char *) obj.str(); return os; } -NAMESPACE_END(pybind) +NAMESPACE_END(pybind11) #if defined(_MSC_VER) #pragma warning(pop) diff --git a/include/pybind/typeid.h b/include/pybind11/typeid.h similarity index 87% rename from include/pybind/typeid.h rename to include/pybind11/typeid.h index 73ee8ec39..551895fcc 100644 --- a/include/pybind/typeid.h +++ b/include/pybind11/typeid.h @@ -1,5 +1,5 @@ /* - pybind/typeid.h: Compiler-independent access to type identifiers + pybind11/typeid.h: Compiler-independent access to type identifiers Copyright (c) 2015 Wenzel Jakob @@ -9,14 +9,13 @@ #pragma once -#include #include #include #if defined(__GNUG__) #include #endif -NAMESPACE_BEGIN(pybind) +NAMESPACE_BEGIN(pybind11) NAMESPACE_BEGIN(detail) /// Erase all occurrences of a substring inline void erase_all(std::string &string, const std::string &search) { @@ -39,7 +38,7 @@ inline void clean_type_id(std::string &name) { detail::erase_all(name, "struct "); detail::erase_all(name, "enum "); #endif - detail::erase_all(name, "pybind::"); + detail::erase_all(name, "pybind11::"); } NAMESPACE_END(detail) @@ -50,4 +49,4 @@ template static std::string type_id() { return name; } -NAMESPACE_END(pybind) +NAMESPACE_END(pybind11)