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
f5f75c65
Commit
f5f75c65
authored
Jul 18, 2016
by
Ivan Smirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make struct packing in example20 MSVC-compliant
parent
b37985ee
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
example/example20.cpp
+12
-4
No files found.
example/example20.cpp
View file @
f5f75c65
...
@@ -13,6 +13,12 @@
...
@@ -13,6 +13,12 @@
#include <cstdint>
#include <cstdint>
#include <iostream>
#include <iostream>
#ifdef __GNUC__
#define PYBIND11_PACKED(cls) cls __attribute__((__packed__))
#else
#define PYBIND11_PACKED(cls) __pragma(pack(push, 1)) cls __pragma(pack(pop))
#endif
namespace
py
=
pybind11
;
namespace
py
=
pybind11
;
struct
SimpleStruct
{
struct
SimpleStruct
{
...
@@ -25,20 +31,20 @@ std::ostream& operator<<(std::ostream& os, const SimpleStruct& v) {
...
@@ -25,20 +31,20 @@ std::ostream& operator<<(std::ostream& os, const SimpleStruct& v) {
return
os
<<
"s:"
<<
v
.
x
<<
","
<<
v
.
y
<<
","
<<
v
.
z
;
return
os
<<
"s:"
<<
v
.
x
<<
","
<<
v
.
y
<<
","
<<
v
.
z
;
}
}
struct
PackedStruct
{
PYBIND11_PACKED
(
struct
PackedStruct
{
bool
x
;
bool
x
;
uint32_t
y
;
uint32_t
y
;
float
z
;
float
z
;
}
__attribute__
((
packed
)
);
});
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
PackedStruct
&
v
)
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
PackedStruct
&
v
)
{
return
os
<<
"p:"
<<
v
.
x
<<
","
<<
v
.
y
<<
","
<<
v
.
z
;
return
os
<<
"p:"
<<
v
.
x
<<
","
<<
v
.
y
<<
","
<<
v
.
z
;
}
}
struct
NestedStruct
{
PYBIND11_PACKED
(
struct
NestedStruct
{
SimpleStruct
a
;
SimpleStruct
a
;
PackedStruct
b
;
PackedStruct
b
;
}
__attribute__
((
packed
)
);
});
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
NestedStruct
&
v
)
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
NestedStruct
&
v
)
{
return
os
<<
"n:a="
<<
v
.
a
<<
";b="
<<
v
.
b
;
return
os
<<
"n:a="
<<
v
.
a
<<
";b="
<<
v
.
b
;
...
@@ -148,3 +154,5 @@ void init_ex20(py::module &m) {
...
@@ -148,3 +154,5 @@ void init_ex20(py::module &m) {
m
.
def
(
"print_dtypes"
,
&
print_dtypes
);
m
.
def
(
"print_dtypes"
,
&
print_dtypes
);
m
.
def
(
"get_format_unbound"
,
&
get_format_unbound
);
m
.
def
(
"get_format_unbound"
,
&
get_format_unbound
);
}
}
#undef PYBIND11_PACKED
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