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
de1bca86
Commit
de1bca86
authored
Mar 26, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added feature to pass void* pointers by popular demand
parent
12cf5438
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
2 deletions
+29
-2
example/example14.cpp
+4
-1
example/example14.py
+4
-0
example/example14.ref
+1
-0
include/pybind11/cast.h
+20
-1
No files found.
example/example14.cpp
View file @
de1bca86
/*
/*
example/example14.cpp -- opaque types
example/example14.cpp -- opaque types
, passing void pointers
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
@@ -26,4 +26,7 @@ void init_ex14(py::module &m) {
...
@@ -26,4 +26,7 @@ void init_ex14(py::module &m) {
for
(
auto
entry
:
l
)
for
(
auto
entry
:
l
)
std
::
cout
<<
" "
<<
entry
<<
std
::
endl
;
std
::
cout
<<
" "
<<
entry
<<
std
::
endl
;
});
});
m
.
def
(
"return_void_ptr"
,
[]()
{
return
(
void
*
)
1234
;
});
m
.
def
(
"print_void_ptr"
,
[](
void
*
ptr
)
{
std
::
cout
<<
"Got void ptr : "
<<
(
uint64_t
)
ptr
<<
std
::
endl
;
});
}
}
example/example14.py
View file @
de1bca86
...
@@ -12,3 +12,7 @@ print_opaque_list(l)
...
@@ -12,3 +12,7 @@ print_opaque_list(l)
print
(
"Back element is
%
s"
%
l
.
back
())
print
(
"Back element is
%
s"
%
l
.
back
())
l
.
pop_back
()
l
.
pop_back
()
print_opaque_list
(
l
)
print_opaque_list
(
l
)
from
example
import
return_void_ptr
,
print_void_ptr
print_void_ptr
(
return_void_ptr
())
example/example14.ref
View file @
de1bca86
...
@@ -4,3 +4,4 @@ Opaque list:
...
@@ -4,3 +4,4 @@ Opaque list:
Back element is Element 2
Back element is Element 2
Opaque list:
Opaque list:
Element 1
Element 1
Got void ptr : 1234
include/pybind11/cast.h
View file @
de1bca86
...
@@ -323,7 +323,26 @@ public:
...
@@ -323,7 +323,26 @@ public:
PYBIND11_TYPE_CASTER
(
void_type
,
_
(
"NoneType"
));
PYBIND11_TYPE_CASTER
(
void_type
,
_
(
"NoneType"
));
};
};
template
<>
class
type_caster
<
void
>
:
public
type_caster
<
void_type
>
{
};
template
<>
class
type_caster
<
void
>
:
public
type_caster
<
void_type
>
{
public
:
using
type_caster
<
void_type
>::
cast
;
bool
load
(
handle
h
,
bool
)
{
capsule
c
(
h
,
true
);
if
(
!
c
.
check
())
return
false
;
value
=
(
void
*
)
c
;
return
true
;
}
static
handle
cast
(
void
*
ptr
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
return
capsule
(
ptr
).
inc_ref
();
}
operator
void
*
()
{
return
value
;
}
private
:
void
*
value
;
};
template
<>
class
type_caster
<
std
::
nullptr_t
>
:
public
type_caster
<
void_type
>
{
};
template
<>
class
type_caster
<
std
::
nullptr_t
>
:
public
type_caster
<
void_type
>
{
};
template
<>
class
type_caster
<
bool
>
{
template
<>
class
type_caster
<
bool
>
{
...
...
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