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
2c4932ed
Commit
2c4932ed
authored
Sep 09, 2022
by
Xiaofei Wang
Committed by
Copybara-Service
Sep 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Internal change
PiperOrigin-RevId: 473369330
parent
f735c948
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
7 deletions
+20
-7
pybind11_abseil/statusor_caster.h
+6
-6
pybind11_abseil/tests/status_example.cc
+10
-0
pybind11_abseil/tests/status_test.py
+4
-1
No files found.
pybind11_abseil/statusor_caster.h
View file @
2c4932ed
...
@@ -44,12 +44,12 @@ struct type_caster<absl::StatusOr<PayloadType>> {
...
@@ -44,12 +44,12 @@ struct type_caster<absl::StatusOr<PayloadType>> {
PYBIND11_TYPE_CASTER
(
absl
::
StatusOr
<
PayloadType
>
,
PayloadCaster
::
name
);
PYBIND11_TYPE_CASTER
(
absl
::
StatusOr
<
PayloadType
>
,
PayloadCaster
::
name
);
// We need this to support overriding virtual functions in Python. See the
bool
load
(
handle
src
,
bool
convert
)
{
// test cases for example.
PayloadCaster
base_caster
;
bool
load
(
handle
/*src*/
,
bool
/*convert*/
)
{
if
(
base_caster
.
load
(
src
,
convert
)
)
{
// This will not be called as long as we do not call C++ functions that
value
=
cast_op
<
PayloadType
>
(
std
::
move
(
base_caster
));
// redirect virtual calls back to Python.
return
true
;
// TODO(wangxf): Implement the load function.
}
return
false
;
return
false
;
}
}
...
...
pybind11_abseil/tests/status_example.cc
View file @
2c4932ed
...
@@ -93,6 +93,14 @@ class PyIntGetter : public IntGetter {
...
@@ -93,6 +93,14 @@ class PyIntGetter : public IntGetter {
}
}
};
};
absl
::
StatusOr
<
int
>
CallGetRedirectToPython
(
IntGetter
*
ptr
,
int
i
)
{
if
(
ptr
)
{
return
ptr
->
Get
(
i
);
}
return
absl
::
InvalidArgumentError
(
"Function parameter should not be nullptr."
);
}
PYBIND11_MODULE
(
status_example
,
m
)
{
PYBIND11_MODULE
(
status_example
,
m
)
{
auto
status_module
=
pybind11
::
google
::
ImportStatusModule
();
auto
status_module
=
pybind11
::
google
::
ImportStatusModule
();
m
.
attr
(
"StatusNotOk"
)
=
status_module
.
attr
(
"StatusNotOk"
);
m
.
attr
(
"StatusNotOk"
)
=
status_module
.
attr
(
"StatusNotOk"
);
...
@@ -153,6 +161,8 @@ PYBIND11_MODULE(status_example, m) {
...
@@ -153,6 +161,8 @@ PYBIND11_MODULE(status_example, m) {
class_
<
IntGetter
,
PyIntGetter
>
(
m
,
"IntGetter"
)
class_
<
IntGetter
,
PyIntGetter
>
(
m
,
"IntGetter"
)
.
def
(
init
())
.
def
(
init
())
.
def
(
"Get"
,
&
IntGetter
::
Get
);
.
def
(
"Get"
,
&
IntGetter
::
Get
);
m
.
def
(
"call_get_redirect_to_python"
,
&
CallGetRedirectToPython
,
arg
(
"ptr"
),
arg
(
"i"
));
// Needed to exercise raw_code() != code().
// Needed to exercise raw_code() != code().
m
.
def
(
"status_from_int_code"
,
[](
int
code
,
const
std
::
string
&
msg
)
{
m
.
def
(
"status_from_int_code"
,
[](
int
code
,
const
std
::
string
&
msg
)
{
...
...
pybind11_abseil/tests/status_test.py
View file @
2c4932ed
...
@@ -258,7 +258,10 @@ class StatusOrTest(absltest.TestCase):
...
@@ -258,7 +258,10 @@ class StatusOrTest(absltest.TestCase):
self
.
assertEqual
(
int_getter
.
Get
(
5
),
5
)
self
.
assertEqual
(
int_getter
.
Get
(
5
),
5
)
with
self
.
assertRaises
(
ValueError
):
with
self
.
assertRaises
(
ValueError
):
int_getter
.
Get
(
100
)
int_getter
.
Get
(
100
)
self
.
assertEqual
(
status_example
.
call_get_redirect_to_python
(
int_getter
,
5
),
5
)
with
self
.
assertRaises
(
ValueError
):
status_example
.
call_get_redirect_to_python
(
int_getter
,
100
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
absltest
.
main
()
absltest
.
main
()
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