Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
ad696349
Commit
ad696349
authored
May 03, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor cleanups
parent
aadc2f3d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
17 deletions
+20
-17
include/pybind11/cast.h
+6
-9
include/pybind11/common.h
+12
-6
include/pybind11/pybind11.h
+1
-1
include/pybind11/pytypes.h
+1
-1
No files found.
include/pybind11/cast.h
View file @
ad696349
...
@@ -225,9 +225,6 @@ using cast_op_type = typename std::conditional<std::is_pointer<typename std::rem
...
@@ -225,9 +225,6 @@ using cast_op_type = typename std::conditional<std::is_pointer<typename std::rem
typename
std
::
add_pointer
<
typename
intrinsic_type
<
T
>::
type
>::
type
,
typename
std
::
add_pointer
<
typename
intrinsic_type
<
T
>::
type
>::
type
,
typename
std
::
add_lvalue_reference
<
typename
intrinsic_type
<
T
>::
type
>::
type
>::
type
;
typename
std
::
add_lvalue_reference
<
typename
intrinsic_type
<
T
>::
type
>::
type
>::
type
;
/// Thrown then trying to cast a null pointer into a reference argument
class
invalid_reference_cast
:
public
std
::
exception
{
};
/// Generic type caster for objects stored on the heap
/// Generic type caster for objects stored on the heap
template
<
typename
type
>
class
type_caster_base
:
public
type_caster_generic
{
template
<
typename
type
>
class
type_caster_base
:
public
type_caster_generic
{
public
:
public
:
...
@@ -256,7 +253,7 @@ public:
...
@@ -256,7 +253,7 @@ public:
template
<
typename
T
>
using
cast_op_type
=
pybind11
::
detail
::
cast_op_type
<
T
>
;
template
<
typename
T
>
using
cast_op_type
=
pybind11
::
detail
::
cast_op_type
<
T
>
;
operator
type
*
()
{
return
(
type
*
)
value
;
}
operator
type
*
()
{
return
(
type
*
)
value
;
}
operator
type
&
()
{
if
(
!
value
)
throw
invalid_reference_cast
();
return
*
((
type
*
)
value
);
}
operator
type
&
()
{
if
(
!
value
)
throw
cast_error
();
return
*
((
type
*
)
value
);
}
protected
:
protected
:
typedef
void
*
(
*
Constructor
)(
const
void
*
stream
);
typedef
void
*
(
*
Constructor
)(
const
void
*
stream
);
...
@@ -763,7 +760,7 @@ public:
...
@@ -763,7 +760,7 @@ public:
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
detail
)
template
<
typename
T
>
inline
T
cast
(
handle
handle
)
{
template
<
typename
T
>
T
cast
(
handle
handle
)
{
typedef
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
T
>::
type
>
type_caster
;
typedef
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
T
>::
type
>
type_caster
;
type_caster
conv
;
type_caster
conv
;
if
(
!
conv
.
load
(
handle
,
true
))
if
(
!
conv
.
load
(
handle
,
true
))
...
@@ -771,7 +768,7 @@ template <typename T> inline T cast(handle handle) {
...
@@ -771,7 +768,7 @@ template <typename T> inline T cast(handle handle) {
return
conv
.
operator
typename
type_caster
::
template
cast_op_type
<
T
>
();
return
conv
.
operator
typename
type_caster
::
template
cast_op_type
<
T
>
();
}
}
template
<
typename
T
>
inline
object
cast
(
const
T
&
value
,
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
handle
parent
=
handle
())
{
template
<
typename
T
>
object
cast
(
const
T
&
value
,
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
handle
parent
=
handle
())
{
if
(
policy
==
return_value_policy
::
automatic
)
if
(
policy
==
return_value_policy
::
automatic
)
policy
=
std
::
is_pointer
<
T
>::
value
?
return_value_policy
::
take_ownership
:
return_value_policy
::
copy
;
policy
=
std
::
is_pointer
<
T
>::
value
?
return_value_policy
::
take_ownership
:
return_value_policy
::
copy
;
else
if
(
policy
==
return_value_policy
::
automatic_reference
)
else
if
(
policy
==
return_value_policy
::
automatic_reference
)
...
@@ -779,11 +776,11 @@ template <typename T> inline object cast(const T &value, return_value_policy pol
...
@@ -779,11 +776,11 @@ template <typename T> inline object cast(const T &value, return_value_policy pol
return
object
(
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
T
>::
type
>::
cast
(
value
,
policy
,
parent
),
false
);
return
object
(
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
T
>::
type
>::
cast
(
value
,
policy
,
parent
),
false
);
}
}
template
<
typename
T
>
inline
T
handle
::
cast
()
const
{
return
pybind11
::
cast
<
T
>
(
*
this
);
}
template
<
typename
T
>
T
handle
::
cast
()
const
{
return
pybind11
::
cast
<
T
>
(
*
this
);
}
template
<>
inline
void
handle
::
cast
()
const
{
return
;
}
template
<>
inline
void
handle
::
cast
()
const
{
return
;
}
template
<
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
template
<
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
typename
...
Args
>
inline
tuple
make_tuple
(
Args
&&
...
args_
)
{
typename
...
Args
>
tuple
make_tuple
(
Args
&&
...
args_
)
{
const
size_t
size
=
sizeof
...(
Args
);
const
size_t
size
=
sizeof
...(
Args
);
std
::
array
<
object
,
size
>
args
{
std
::
array
<
object
,
size
>
args
{
{
object
(
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
Args
>::
type
>::
cast
(
{
object
(
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
Args
>::
type
>::
cast
(
...
@@ -799,7 +796,7 @@ template <return_value_policy policy = return_value_policy::automatic_reference,
...
@@ -799,7 +796,7 @@ template <return_value_policy policy = return_value_policy::automatic_reference,
return
result
;
return
result
;
}
}
template
<
typename
...
Args
>
inline
object
handle
::
call
(
Args
&&
...
args
)
const
{
template
<
typename
...
Args
>
object
handle
::
call
(
Args
&&
...
args
)
const
{
tuple
args_tuple
=
pybind11
::
make_tuple
(
std
::
forward
<
Args
>
(
args
)...);
tuple
args_tuple
=
pybind11
::
make_tuple
(
std
::
forward
<
Args
>
(
args
)...);
object
result
(
PyObject_CallObject
(
m_ptr
,
args_tuple
.
ptr
()),
false
);
object
result
(
PyObject_CallObject
(
m_ptr
,
args_tuple
.
ptr
()),
false
);
if
(
!
result
)
if
(
!
result
)
...
...
include/pybind11/common.h
View file @
ad696349
...
@@ -280,7 +280,7 @@ template<size_t N, size_t ...S> struct make_index_sequence : make_index_sequence
...
@@ -280,7 +280,7 @@ template<size_t N, size_t ...S> struct make_index_sequence : make_index_sequence
template
<
size_t
...
S
>
struct
make_index_sequence
<
0
,
S
...
>
{
typedef
index_sequence
<
S
...
>
type
;
};
template
<
size_t
...
S
>
struct
make_index_sequence
<
0
,
S
...
>
{
typedef
index_sequence
<
S
...
>
type
;
};
/// Strip the class from a method type
/// Strip the class from a method type
template
<
typename
T
>
struct
remove_class
{};
template
<
typename
T
>
struct
remove_class
{
};
template
<
typename
C
,
typename
R
,
typename
...
A
>
struct
remove_class
<
R
(
C
::*
)(
A
...)
>
{
typedef
R
type
(
A
...);
};
template
<
typename
C
,
typename
R
,
typename
...
A
>
struct
remove_class
<
R
(
C
::*
)(
A
...)
>
{
typedef
R
type
(
A
...);
};
template
<
typename
C
,
typename
R
,
typename
...
A
>
struct
remove_class
<
R
(
C
::*
)(
A
...)
const
>
{
typedef
R
type
(
A
...);
};
template
<
typename
C
,
typename
R
,
typename
...
A
>
struct
remove_class
<
R
(
C
::*
)(
A
...)
const
>
{
typedef
R
type
(
A
...);
};
...
@@ -305,12 +305,18 @@ to_string(T value) { return std::to_string((int) value); }
...
@@ -305,12 +305,18 @@ to_string(T value) { return std::to_string((int) value); }
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
detail
)
#define PYBIND11_RUNTIME_EXCEPTION(name) \
class name : public std::runtime_error { public: \
name(const std::string &w) : std::runtime_error(w) { }; \
name(const char *s) : std::runtime_error(s) { }; \
name() : std::runtime_error("") { } \
};
// C++ bindings of core Python exceptions
// C++ bindings of core Python exceptions
struct
stop_iteration
:
public
std
::
runtime_error
{
public
:
stop_iteration
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
class
error_already_set
:
public
std
::
runtime_error
{
public
:
error_already_set
()
:
std
::
runtime_error
(
detail
::
error_string
())
{}
};
struct
index_error
:
public
std
::
runtime_error
{
public
:
index_error
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
PYBIND11_RUNTIME_EXCEPTION
(
stop_iteration
)
struct
error_already_set
:
public
std
::
runtime_error
{
public
:
error_already_set
()
:
std
::
runtime_error
(
detail
::
error_string
())
{}
};
PYBIND11_RUNTIME_EXCEPTION
(
index_error
)
/// Thrown when pybind11::cast or handle::call fail due to a type casting error
PYBIND11_RUNTIME_EXCEPTION
(
cast_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
)
{}
};
[[
noreturn
]]
PYBIND11_NOINLINE
inline
void
pybind11_fail
(
const
char
*
reason
)
{
throw
std
::
runtime_error
(
reason
);
}
[[
noreturn
]]
PYBIND11_NOINLINE
inline
void
pybind11_fail
(
const
char
*
reason
)
{
throw
std
::
runtime_error
(
reason
);
}
[[
noreturn
]]
PYBIND11_NOINLINE
inline
void
pybind11_fail
(
const
std
::
string
&
reason
)
{
throw
std
::
runtime_error
(
reason
);
}
[[
noreturn
]]
PYBIND11_NOINLINE
inline
void
pybind11_fail
(
const
std
::
string
&
reason
)
{
throw
std
::
runtime_error
(
reason
);
}
...
...
include/pybind11/pybind11.h
View file @
ad696349
...
@@ -413,7 +413,7 @@ protected:
...
@@ -413,7 +413,7 @@ protected:
try
{
try
{
if
(
kwargs_consumed
==
nkwargs
)
if
(
kwargs_consumed
==
nkwargs
)
result
=
it
->
impl
(
it
,
args_
,
parent
);
result
=
it
->
impl
(
it
,
args_
,
parent
);
}
catch
(
detail
::
invalid_reference_cast
&
)
{
}
catch
(
cast_error
&
)
{
result
=
PYBIND11_TRY_NEXT_OVERLOAD
;
result
=
PYBIND11_TRY_NEXT_OVERLOAD
;
}
}
...
...
include/pybind11/pytypes.h
View file @
ad696349
...
@@ -126,7 +126,7 @@ public:
...
@@ -126,7 +126,7 @@ public:
return
result
;
return
result
;
}
}
template
<
typename
T
>
inline
T
cast
()
const
{
return
operator
object
().
cast
<
T
>
();
}
template
<
typename
T
>
T
cast
()
const
{
return
operator
object
().
cast
<
T
>
();
}
operator
bool
()
const
{
operator
bool
()
const
{
if
(
attr
)
{
if
(
attr
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment