mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 13:15:12 +00:00
last breaking change: be consistent about the project name
This commit is contained in:
parent
607654f7ec
commit
8f4eb00690
@ -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
|
||||
|
@ -8,9 +8,9 @@ present:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include <pybind/pybind.h>
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
namespace py = pybind;
|
||||
namespace py = pybind11
|
||||
|
||||
Operator overloading
|
||||
====================
|
||||
@ -43,10 +43,10 @@ to Python.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include <pybind/operators.h>
|
||||
#include <pybind11/operators.h>
|
||||
|
||||
PYBIND_PLUGIN(example) {
|
||||
py::module m("example", "pybind example plugin");
|
||||
py::module m("example", "pybind11 example plugin");
|
||||
|
||||
py::class_<Vector2>(m, "Vector2")
|
||||
.def(py::init<float, float>())
|
||||
@ -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 <pybind/functional.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
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> 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_<PyAnimal> 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_<Example>(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
|
||||
|
||||
|
@ -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 <pybind/pybind.h>
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
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 <path-to-pybind>/include `python-config --cflags --libs` example.cpp -o example.so
|
||||
$ c++ -O3 -shared -std=c++11 -I <path-to-pybind11>/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<T1, T2> | Pair of two custom types | pybind/pybind.h |
|
||||
+------------------------+--------------------------+---------------------+
|
||||
| std::tuple<....> | Arbitrary tuple of types | pybind/pybind.h |
|
||||
+------------------------+--------------------------+---------------------+
|
||||
| std::complex<T> | Complex numbers | pybind/complex.h |
|
||||
+------------------------+--------------------------+---------------------+
|
||||
| std::vector<T> | STL dynamic array | pybind/stl.h |
|
||||
+------------------------+--------------------------+---------------------+
|
||||
| std::map<T1, T2> | STL dynamic maps | pybind/stl.h |
|
||||
+------------------------+--------------------------+---------------------+
|
||||
| std::function<...> | STL polymorphic function | pybind/functional.h |
|
||||
+------------------------+--------------------------+---------------------+
|
||||
+========================+==========================+=======================+
|
||||
| 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<T1, T2> | Pair of two custom types | pybind11/pybind11.h |
|
||||
+------------------------+--------------------------+-----------------------+
|
||||
| std::tuple<....> | Arbitrary tuple of types | pybind11/pybind11.h |
|
||||
+------------------------+--------------------------+-----------------------+
|
||||
| std::complex<T> | Complex numbers | pybind11/complex.h |
|
||||
+------------------------+--------------------------+-----------------------+
|
||||
| std::vector<T> | STL dynamic array | pybind11/stl.h |
|
||||
+------------------------+--------------------------+-----------------------+
|
||||
| std::map<T1, T2> | 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
|
||||
|
@ -23,12 +23,12 @@ The binding code for ``Pet`` looks as follows:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include <pybind/pybind.h>
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
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_<Pet>(m, "Pet")
|
||||
.def(py::init<const std::string &>())
|
||||
|
@ -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 <typename Func, typename ... Extra> module& module::def(const char *name, Func && f, Extra && ... extra)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <pybind/pybind.h>
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <iostream>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
namespace py = pybind;
|
||||
namespace py = pybind11;
|
||||
|
@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
#include "example.h"
|
||||
#include <pybind/numpy.h>
|
||||
#include <pybind11/numpy.h>
|
||||
|
||||
double my_func(int x, float y, double z) {
|
||||
std::cout << "my_func(x:int=" << x << ", y:float=" << y << ", z:float=" << z << ")" << std::endl;
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "example.h"
|
||||
#include <pybind/functional.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
/* This is an example class that we'll want to be able to extend from Python */
|
||||
class Example12 {
|
||||
|
@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
#include "example.h"
|
||||
#include <pybind/stl.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
class Example2 {
|
||||
public:
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "example.h"
|
||||
#include <pybind/operators.h>
|
||||
#include <pybind11/operators.h>
|
||||
|
||||
class Vector2 {
|
||||
public:
|
||||
|
@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
#include "example.h"
|
||||
#include <pybind/functional.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
|
||||
class Pet {
|
||||
|
@ -9,8 +9,8 @@
|
||||
*/
|
||||
|
||||
#include "example.h"
|
||||
#include <pybind/operators.h>
|
||||
#include <pybind/stl.h>
|
||||
#include <pybind11/operators.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
class Sequence {
|
||||
public:
|
||||
|
@ -32,10 +32,7 @@ private:
|
||||
};
|
||||
|
||||
/// Make pybind aware of the ref-counted wrapper type
|
||||
namespace pybind { namespace detail {
|
||||
template <typename T> class type_caster<ref<T>>
|
||||
: public type_caster_holder<T, ref<T>> { };
|
||||
}}
|
||||
PYBIND_DECLARE_HOLDER_TYPE(T, ref<T>);
|
||||
|
||||
Object *make_object_1() { return new MyObject(1); }
|
||||
ref<Object> make_object_2() { return new MyObject(2); }
|
||||
|
@ -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 <wenzel@inf.ethz.ch>
|
||||
@ -10,12 +10,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind/pytypes.h>
|
||||
#include <pybind/typeid.h>
|
||||
#include "pytypes.h"
|
||||
#include "typeid.h"
|
||||
#include <array>
|
||||
#include <limits>
|
||||
|
||||
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 <typename type> class type_caster<holder_type> \
|
||||
: public type_caster_holder<type, holder_type> { }; \
|
||||
}}
|
||||
|
||||
template <> class type_caster<handle> {
|
||||
public:
|
||||
bool load(PyObject *src) {
|
||||
@ -571,7 +577,7 @@ template <typename T> inline object cast(const T &value, return_value_policy pol
|
||||
return object(detail::type_caster<typename detail::decay<T>::type>::cast(value, policy, parent), false);
|
||||
}
|
||||
|
||||
template <typename T> inline T handle::cast() { return pybind::cast<T>(m_ptr); }
|
||||
template <typename T> inline T handle::cast() { return pybind11::cast<T>(m_ptr); }
|
||||
template <> inline void handle::cast() { return; }
|
||||
|
||||
template <typename... Args> inline object handle::call(Args&&... args_) {
|
||||
@ -601,4 +607,4 @@ template <typename... Args> inline object handle::call(Args&&... args_) {
|
||||
return object(result, false);
|
||||
}
|
||||
|
||||
NAMESPACE_END(pybind)
|
||||
NAMESPACE_END(pybind11)
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
pybind/common.h -- Basic macros
|
||||
pybind11/common.h -- Basic macros
|
||||
|
||||
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
|
||||
|
||||
@ -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)
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
pybind/complex.h: Complex number support
|
||||
pybind11/complex.h: Complex number support
|
||||
|
||||
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
|
||||
|
||||
@ -9,10 +9,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind/pybind.h>
|
||||
#include "pybind11.h"
|
||||
#include <complex>
|
||||
|
||||
NAMESPACE_BEGIN(pybind)
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
|
||||
PYBIND_DECL_FMT(std::complex<float>, "Zf");
|
||||
PYBIND_DECL_FMT(std::complex<double>, "Zd");
|
||||
@ -37,4 +37,4 @@ public:
|
||||
PYBIND_TYPE_CASTER(std::complex<T>, "complex");
|
||||
};
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind)
|
||||
NAMESPACE_END(pybind11)
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
pybind/functional.h: std::function<> support
|
||||
pybind11/functional.h: std::function<> support
|
||||
|
||||
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
|
||||
|
||||
@ -9,10 +9,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind/pybind.h>
|
||||
#include "pybind11.h"
|
||||
#include <functional>
|
||||
|
||||
NAMESPACE_BEGIN(pybind)
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
template <typename Return, typename... Args> struct type_caster<std::function<Return(Args...)>> {
|
||||
@ -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<Return>());
|
||||
};
|
||||
@ -46,4 +46,4 @@ public:
|
||||
};
|
||||
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind)
|
||||
NAMESPACE_END(pybind11)
|
@ -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 <wenzel@inf.ethz.ch>
|
||||
|
||||
@ -9,15 +9,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind/pybind.h>
|
||||
#include <pybind/complex.h>
|
||||
#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 <typename type> struct npy_format_descriptor { };
|
||||
|
||||
@ -196,7 +196,7 @@ struct vectorize_helper {
|
||||
/* Check if the parameters are actually compatible */
|
||||
for (size_t i=0; i<N; ++i) {
|
||||
if (buffers[i].count != 1 && (buffers[i].ndim != ndim || buffers[i].shape != shape))
|
||||
throw std::runtime_error("pybind::vectorize: incompatible size/dimension of inputs!");
|
||||
throw std::runtime_error("pybind11::vectorize: incompatible size/dimension of inputs!");
|
||||
}
|
||||
|
||||
/* Call the function */
|
||||
@ -234,7 +234,7 @@ template <typename func> auto vectorize(func &&f) -> decltype(
|
||||
&std::remove_reference<func>::type::operator())>::type *) nullptr);
|
||||
}
|
||||
|
||||
NAMESPACE_END(pybind)
|
||||
NAMESPACE_END(pybind11)
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
pybind/operator.h: Metatemplates for operator overloading
|
||||
pybind11/operator.h: Metatemplates for operator overloading
|
||||
|
||||
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
|
||||
|
||||
@ -9,10 +9,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind/pybind.h>
|
||||
#include "pybind11.h"
|
||||
#include <type_traits>
|
||||
|
||||
NAMESPACE_BEGIN(pybind)
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
/// Enumeration with all supported operator types
|
||||
@ -45,13 +45,13 @@ template <op_id, op_type, typename B, typename L, typename R> struct op_impl { }
|
||||
|
||||
/// Operator implementation generator
|
||||
template <op_id id, op_type ot, typename L, typename R> struct op_ {
|
||||
template <typename Base, typename Holder, typename... Extra> void execute(pybind::class_<Base, Holder> &class_, Extra&&... extra) const {
|
||||
template <typename Base, typename Holder, typename... Extra> void execute(pybind11::class_<Base, Holder> &class_, Extra&&... extra) const {
|
||||
typedef typename std::conditional<std::is_same<L, self_t>::value, Base, L>::type L_type;
|
||||
typedef typename std::conditional<std::is_same<R, self_t>::value, Base, R>::type R_type;
|
||||
typedef op_impl<id, ot, Base, L_type, R_type> op;
|
||||
class_.def(op::name(), &op::execute, std::forward<Extra>(extra)...);
|
||||
}
|
||||
template <typename Base, typename Holder, typename... Extra> void execute_cast(pybind::class_<Base, Holder> &class_, Extra&&... extra) const {
|
||||
template <typename Base, typename Holder, typename... Extra> void execute_cast(pybind11::class_<Base, Holder> &class_, Extra&&... extra) const {
|
||||
typedef typename std::conditional<std::is_same<L, self_t>::value, Base, L>::type L_type;
|
||||
typedef typename std::conditional<std::is_same<R, self_t>::value, Base, R>::type R_type;
|
||||
typedef op_impl<id, ot, Base, L_type, R_type> op;
|
||||
@ -146,4 +146,4 @@ NAMESPACE_END(detail)
|
||||
|
||||
using detail::self;
|
||||
|
||||
NAMESPACE_END(pybind)
|
||||
NAMESPACE_END(pybind11)
|
@ -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 <wenzel@inf.ethz.ch>
|
||||
|
||||
@ -23,9 +23,9 @@
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
|
||||
#include <pybind/cast.h>
|
||||
#include "cast.h"
|
||||
|
||||
NAMESPACE_BEGIN(pybind)
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
|
||||
template <typename T> 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 <typename T>
|
||||
static void process_extra(const pybind::arg_t<T> &a, function_entry *entry, const char **kw, const char **def) {
|
||||
static void process_extra(const pybind11::arg_t<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 <typename T> 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 <typename T>
|
||||
static void process_extra(const pybind::arg_t<T> &a, int &index, PyObject *args, PyObject *kwargs) {
|
||||
static void process_extra(const pybind11::arg_t<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<char *>("__pybind__")), false);
|
||||
const_cast<char *>("__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<char*>("__pybind__")), false);
|
||||
PyObject_GetAttrString((PyObject *) type, const_cast<char*>("__pybind11__")), false);
|
||||
instance<void> *self = (instance<void> *) 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<cpp_function&>(fget).attr("__doc__");
|
||||
object doc_obj = doc ? pybind11::str(doc) : (object) const_cast<cpp_function&>(fget).attr("__doc__");
|
||||
object property(
|
||||
PyObject_CallFunction((PyObject *)&PyProperty_Type,
|
||||
const_cast<char *>("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<cpp_function&>(fget).attr("__doc__");
|
||||
object doc_obj = doc ? pybind11::str(doc) : (object) const_cast<cpp_function&>(fget).attr("__doc__");
|
||||
object property(
|
||||
PyObject_CallFunction((PyObject *)&PyProperty_Type,
|
||||
const_cast<char *>("OOOs"), fget.ptr() ? fget.ptr() : Py_None,
|
||||
@ -796,7 +796,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename target> 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 <typename... Args> struct init {
|
||||
template <typename Base, typename Holder, typename... Extra> void execute(pybind::class_<Base, Holder> &class_, Extra&&... extra) const {
|
||||
template <typename Base, typename Holder, typename... Extra> void execute(pybind11::class_<Base, Holder> &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>(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<ret_type>(); }
|
||||
|
||||
@ -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)
|
@ -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 <wenzel@inf.ethz.ch>
|
||||
|
||||
@ -9,10 +9,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind/common.h>
|
||||
#include "common.h"
|
||||
#include <utility>
|
||||
|
||||
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 <typename T> T cast();
|
||||
template <typename ... Args> 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)
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
pybind/complex.h: Complex number support
|
||||
pybind11/complex.h: Complex number support
|
||||
|
||||
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind/pybind.h>
|
||||
#include "pybind11.h"
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
|
||||
@ -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 <typename Value> struct type_caster<std::vector<Value>> {
|
||||
@ -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)
|
@ -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 <wenzel@inf.ethz.ch>
|
||||
|
||||
@ -9,14 +9,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind/typeid.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#if defined(__GNUG__)
|
||||
#include <cxxabi.h>
|
||||
#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 <typename T> static std::string type_id() {
|
||||
return name;
|
||||
}
|
||||
|
||||
NAMESPACE_END(pybind)
|
||||
NAMESPACE_END(pybind11)
|
Loading…
Reference in New Issue
Block a user