Skip to content

Commit c07422d

Browse files
committed
Add ByteOrder.cpp
1 parent 0d8f934 commit c07422d

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

Jamfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ local sourceFiles =
199199
PrintJob.cpp
200200

201201
#SupportKit
202+
ByteOrder.cpp
202203
StopWatch.cpp
203204
Beep.cpp
204205
Locker.cpp

bindings/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
from .Input import *
9292
from .PrintJob import *
9393

94+
from .ByteOrder import *
9495
from .StopWatch import *
9596
from .Beep import *
9697
from .Architecture import *

bindings/support/ByteOrder.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,33 @@
66
#include <support/ByteOrder.h>
77

88
namespace py = pybind11;
9+
/*
10+
uint64 sw_int64(uint64 arg){
11+
#if __GNUC__ >= 4
12+
return __builtin_bswap64(arg);
13+
#else
14+
return __swap_int64(arg);
15+
}*/
916

17+
#if __GNUC__ >= 4
18+
uint64 swap_int64(uint64 arg) {
19+
return __builtin_bswap64(arg);
20+
}
21+
uint32 swap_int32(uint32 arg) {
22+
return __builtin_bswap32(arg);
23+
}
24+
uint16 swap_int16(uint16 arg) {
25+
return __builtin_bswap16(arg);
26+
}
27+
#else
28+
extern uint64 __swap_int64(uint64 arg);
29+
extern uint32 __swap_int32(uint32 arg);
30+
extern uint16 __swap_int16(uint16 arg);
31+
#endif
1032

11-
void define_ByteOrder(py::module_& m)
33+
34+
35+
PYBIND11_MODULE(ByteOrder, m)
1236
{
1337
py::enum_<swap_action>(m, "swap_action", "")
1438
.value("B_SWAP_HOST_TO_LENDIAN", swap_action::B_SWAP_HOST_TO_LENDIAN, "")
@@ -25,11 +49,18 @@ m.def("is_type_swapped", &is_type_swapped, "", py::arg("type"));
2549
m.def("__swap_double", &__swap_double, "", py::arg("arg"));
2650

2751
m.def("__swap_float", &__swap_float, "", py::arg("arg"));
28-
52+
/*
2953
m.def("__swap_int64", &__swap_int64, "", py::arg("arg"));
30-
3154
m.def("__swap_int32", &__swap_int32, "", py::arg("arg"));
32-
3355
m.def("__swap_int16", &__swap_int16, "", py::arg("arg"));
34-
56+
*/
57+
#if __GNUC__ >= 4
58+
m.def("__swap_int64", &swap_int64, "Swap bytes of a 64-bit integer");
59+
m.def("__swap_int32", &swap_int32, "Swap bytes of a 32-bit integer");
60+
m.def("__swap_int16", &swap_int16, "Swap bytes of a 16-bit integer");
61+
#else
62+
m.def("__swap_int64", &__swap_int64, "", py::arg("arg"));
63+
m.def("__swap_int32", &__swap_int32, "", py::arg("arg"));
64+
m.def("__swap_int16", &__swap_int16, "", py::arg("arg"));
65+
#endif
3566
}

0 commit comments

Comments
 (0)