Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
a7e62e1c
Commit
a7e62e1c
authored
Jun 19, 2016
by
Ivan Smirnov
Browse files
Add buffer_info::as_pybuffer() method
parent
3dd325b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
include/pybind11/common.h
include/pybind11/common.h
+25
-0
No files found.
include/pybind11/common.h
View file @
a7e62e1c
...
...
@@ -231,6 +231,31 @@ struct buffer_info {
~
buffer_info
()
{
if
(
view
)
{
PyBuffer_Release
(
view
);
delete
view
;
}
}
Py_buffer
&
as_pybuffer
()
const
{
static
Py_buffer
buf
{
};
// Py_buffer uses signed sizes, strides and shape!..
static
std
::
vector
<
Py_ssize_t
>
py_strides
{
};
static
std
::
vector
<
Py_ssize_t
>
py_shape
{
};
buf
.
buf
=
ptr
;
buf
.
itemsize
=
(
Py_ssize_t
)
itemsize
;
buf
.
format
=
const_cast
<
char
*>
(
format
.
c_str
());
buf
.
ndim
=
(
int
)
ndim
;
buf
.
len
=
(
Py_ssize_t
)
size
;
py_strides
.
clear
();
py_shape
.
clear
();
for
(
size_t
i
=
0
;
i
<
ndim
;
++
i
)
{
py_strides
.
push_back
((
Py_ssize_t
)
strides
[
i
]);
py_shape
.
push_back
((
Py_ssize_t
)
shape
[
i
]);
}
buf
.
strides
=
py_strides
.
data
();
buf
.
shape
=
py_shape
.
data
();
buf
.
suboffsets
=
nullptr
;
buf
.
readonly
=
false
;
buf
.
internal
=
nullptr
;
return
buf
;
}
private:
Py_buffer
*
view
=
nullptr
;
};
...
...
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