Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
098f9aef
Commit
098f9aef
authored
Jul 18, 2016
by
Ivan Smirnov
Browse files
Replace 4096B format buffer with std::string
parent
f5f75c65
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
include/pybind11/numpy.h
include/pybind11/numpy.h
+3
-3
No files found.
include/pybind11/numpy.h
View file @
098f9aef
...
@@ -291,7 +291,7 @@ struct npy_format_descriptor<T, typename std::enable_if<is_pod_struct<T>::value>
...
@@ -291,7 +291,7 @@ struct npy_format_descriptor<T, typename std::enable_if<is_pod_struct<T>::value>
static
const
char
*
format
()
{
static
const
char
*
format
()
{
if
(
!
dtype_
())
if
(
!
dtype_
())
pybind11_fail
(
"NumPy: unsupported buffer format!"
);
pybind11_fail
(
"NumPy: unsupported buffer format!"
);
return
format_
();
return
format_
()
.
c_str
()
;
}
}
static
void
register_dtype
(
std
::
initializer_list
<
field_descriptor
>
fields
)
{
static
void
register_dtype
(
std
::
initializer_list
<
field_descriptor
>
fields
)
{
...
@@ -337,7 +337,7 @@ struct npy_format_descriptor<T, typename std::enable_if<is_pod_struct<T>::value>
...
@@ -337,7 +337,7 @@ struct npy_format_descriptor<T, typename std::enable_if<is_pod_struct<T>::value>
if
(
sizeof
(
T
)
>
offset
)
if
(
sizeof
(
T
)
>
offset
)
oss
<<
(
sizeof
(
T
)
-
offset
)
<<
'x'
;
oss
<<
(
sizeof
(
T
)
-
offset
)
<<
'x'
;
oss
<<
'}'
;
oss
<<
'}'
;
std
::
strncpy
(
format_
()
,
oss
.
str
()
.
c_str
(),
4096
)
;
format_
()
=
oss
.
str
();
// Sanity check: verify that NumPy properly parses our buffer format string
// Sanity check: verify that NumPy properly parses our buffer format string
auto
arr
=
array
(
buffer_info
(
nullptr
,
sizeof
(
T
),
format
(),
1
,
{
0
},
{
sizeof
(
T
)
}));
auto
arr
=
array
(
buffer_info
(
nullptr
,
sizeof
(
T
),
format
(),
1
,
{
0
},
{
sizeof
(
T
)
}));
...
@@ -348,7 +348,7 @@ struct npy_format_descriptor<T, typename std::enable_if<is_pod_struct<T>::value>
...
@@ -348,7 +348,7 @@ struct npy_format_descriptor<T, typename std::enable_if<is_pod_struct<T>::value>
private:
private:
static
inline
PyObject
*&
dtype_
()
{
static
PyObject
*
ptr
=
nullptr
;
return
ptr
;
}
static
inline
PyObject
*&
dtype_
()
{
static
PyObject
*
ptr
=
nullptr
;
return
ptr
;
}
static
inline
char
*
format_
()
{
static
char
s
[
4096
]
;
return
s
;
}
static
inline
std
::
string
&
format_
()
{
static
std
::
string
s
;
return
s
;
}
};
};
// Extract name, offset and format descriptor for a struct field
// Extract name, offset and format descriptor for a struct field
...
...
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