Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11_abseil
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_abseil
Commits
dc0479f3
Commit
dc0479f3
authored
Jan 19, 2021
by
Ken Oslund
Committed by
Copybara-Service
Jan 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Internal change
PiperOrigin-RevId: 352628261
parent
c192cb07
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
+13
-8
pybind11_abseil/status_casters.h
+2
-2
pybind11_abseil/status_utils.h
+11
-6
No files found.
pybind11_abseil/status_casters.h
View file @
dc0479f3
...
@@ -106,8 +106,8 @@ struct type_caster<absl::Status> : public type_caster_base<absl::Status> {
...
@@ -106,8 +106,8 @@ struct type_caster<absl::Status> : public type_caster_base<absl::Status> {
private
:
private
:
template
<
typename
CType
>
template
<
typename
CType
>
static
handle
cast_impl
(
CType
src
,
return_value_policy
policy
,
handle
parent
,
static
handle
cast_impl
(
CType
&&
src
,
return_value_policy
policy
,
bool
throw_exception
)
{
handle
parent
,
bool
throw_exception
)
{
google
::
CheckStatusModuleImported
();
google
::
CheckStatusModuleImported
();
if
(
!
throw_exception
)
{
if
(
!
throw_exception
)
{
// Use the built-in/standard pybind11 caster.
// Use the built-in/standard pybind11 caster.
...
...
pybind11_abseil/status_utils.h
View file @
dc0479f3
...
@@ -16,7 +16,8 @@ namespace pybind11 {
...
@@ -16,7 +16,8 @@ namespace pybind11 {
namespace
google
{
namespace
google
{
// Wrapper type to signal to the type_caster that a non-ok status should not
// Wrapper type to signal to the type_caster that a non-ok status should not
// be converted into an object rather than a thrown exception.
// be converted into an object rather than a thrown exception. StatusType can
// encapsulate references, e.g. `NoThrowStatus<absl::Status&>`.
template
<
typename
StatusType
>
template
<
typename
StatusType
>
struct
NoThrowStatus
{
struct
NoThrowStatus
{
NoThrowStatus
(
StatusType
status_in
)
NoThrowStatus
(
StatusType
status_in
)
...
@@ -24,7 +25,11 @@ struct NoThrowStatus {
...
@@ -24,7 +25,11 @@ struct NoThrowStatus {
StatusType
status
;
StatusType
status
;
};
};
// Convert a absl::Status(Or) into a NoThrowStatus.
// Convert a absl::Status(Or) into a NoThrowStatus. To use this with references,
// explicitly specify the template parameter rather deducing it, e.g.:
// `return DoNotThrowStatus<const absl::Status&>(my_status);`
// When returning a status by value (by far the most common case), deducing the
// template parameter is fine, e.g.: `return DoNotThrowStatus(my_status);`
template
<
typename
StatusType
>
template
<
typename
StatusType
>
NoThrowStatus
<
StatusType
>
DoNotThrowStatus
(
StatusType
status
)
{
NoThrowStatus
<
StatusType
>
DoNotThrowStatus
(
StatusType
status
)
{
return
NoThrowStatus
<
StatusType
>
(
std
::
forward
<
StatusType
>
(
status
));
return
NoThrowStatus
<
StatusType
>
(
std
::
forward
<
StatusType
>
(
status
));
...
@@ -34,7 +39,7 @@ NoThrowStatus<StatusType> DoNotThrowStatus(StatusType status) {
...
@@ -34,7 +39,7 @@ NoThrowStatus<StatusType> DoNotThrowStatus(StatusType status) {
template
<
typename
StatusType
,
typename
...
Args
>
template
<
typename
StatusType
,
typename
...
Args
>
std
::
function
<
NoThrowStatus
<
StatusType
>
(
Args
...)
>
DoNotThrowStatus
(
std
::
function
<
NoThrowStatus
<
StatusType
>
(
Args
...)
>
DoNotThrowStatus
(
std
::
function
<
StatusType
(
Args
...)
>
f
)
{
std
::
function
<
StatusType
(
Args
...)
>
f
)
{
return
[
f
=
std
::
move
(
f
)](
Args
...
args
)
{
return
[
f
=
std
::
move
(
f
)](
Args
&&
...
args
)
{
return
NoThrowStatus
<
StatusType
>
(
return
NoThrowStatus
<
StatusType
>
(
std
::
forward
<
StatusType
>
(
f
(
std
::
forward
<
Args
>
(
args
)...)));
std
::
forward
<
StatusType
>
(
f
(
std
::
forward
<
Args
>
(
args
)...)));
};
};
...
@@ -42,7 +47,7 @@ std::function<NoThrowStatus<StatusType>(Args...)> DoNotThrowStatus(
...
@@ -42,7 +47,7 @@ std::function<NoThrowStatus<StatusType>(Args...)> DoNotThrowStatus(
template
<
typename
StatusType
,
typename
...
Args
>
template
<
typename
StatusType
,
typename
...
Args
>
std
::
function
<
NoThrowStatus
<
StatusType
>
(
Args
...)
>
DoNotThrowStatus
(
std
::
function
<
NoThrowStatus
<
StatusType
>
(
Args
...)
>
DoNotThrowStatus
(
StatusType
(
*
f
)(
Args
...))
{
StatusType
(
*
f
)(
Args
...))
{
return
[
f
](
Args
...
args
)
{
return
[
f
](
Args
&&
...
args
)
{
return
NoThrowStatus
<
StatusType
>
(
return
NoThrowStatus
<
StatusType
>
(
std
::
forward
<
StatusType
>
(
f
(
std
::
forward
<
Args
>
(
args
)...)));
std
::
forward
<
StatusType
>
(
f
(
std
::
forward
<
Args
>
(
args
)...)));
};
};
...
@@ -50,7 +55,7 @@ std::function<NoThrowStatus<StatusType>(Args...)> DoNotThrowStatus(
...
@@ -50,7 +55,7 @@ std::function<NoThrowStatus<StatusType>(Args...)> DoNotThrowStatus(
template
<
typename
StatusType
,
typename
Class
,
typename
...
Args
>
template
<
typename
StatusType
,
typename
Class
,
typename
...
Args
>
std
::
function
<
NoThrowStatus
<
StatusType
>
(
Class
*
,
Args
...)
>
DoNotThrowStatus
(
std
::
function
<
NoThrowStatus
<
StatusType
>
(
Class
*
,
Args
...)
>
DoNotThrowStatus
(
StatusType
(
Class
::*
f
)(
Args
...))
{
StatusType
(
Class
::*
f
)(
Args
...))
{
return
[
f
](
Class
*
c
,
Args
...
args
)
{
return
[
f
](
Class
*
c
,
Args
&&
...
args
)
{
return
NoThrowStatus
<
StatusType
>
(
return
NoThrowStatus
<
StatusType
>
(
std
::
forward
<
StatusType
>
((
c
->*
f
)(
std
::
forward
<
Args
>
(
args
)...)));
std
::
forward
<
StatusType
>
((
c
->*
f
)(
std
::
forward
<
Args
>
(
args
)...)));
};
};
...
@@ -58,7 +63,7 @@ std::function<NoThrowStatus<StatusType>(Class*, Args...)> DoNotThrowStatus(
...
@@ -58,7 +63,7 @@ std::function<NoThrowStatus<StatusType>(Class*, Args...)> DoNotThrowStatus(
template
<
typename
StatusType
,
typename
Class
,
typename
...
Args
>
template
<
typename
StatusType
,
typename
Class
,
typename
...
Args
>
std
::
function
<
NoThrowStatus
<
StatusType
>
(
const
Class
*
,
Args
...)
>
std
::
function
<
NoThrowStatus
<
StatusType
>
(
const
Class
*
,
Args
...)
>
DoNotThrowStatus
(
StatusType
(
Class
::*
f
)(
Args
...)
const
)
{
DoNotThrowStatus
(
StatusType
(
Class
::*
f
)(
Args
...)
const
)
{
return
[
f
](
const
Class
*
c
,
Args
...
args
)
{
return
[
f
](
const
Class
*
c
,
Args
&&
...
args
)
{
return
NoThrowStatus
<
StatusType
>
(
return
NoThrowStatus
<
StatusType
>
(
std
::
forward
<
StatusType
>
((
c
->*
f
)(
std
::
forward
<
Args
>
(
args
)...)));
std
::
forward
<
StatusType
>
((
c
->*
f
)(
std
::
forward
<
Args
>
(
args
)...)));
};
};
...
...
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