snowflake-connector-python 5.2.0__cp315-cp315-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snowflake/connector/__init__.py +148 -0
- snowflake/connector/_common/__init__.py +0 -0
- snowflake/connector/_common/extras.py +134 -0
- snowflake/connector/_common/telemetry.py +221 -0
- snowflake/connector/_common/wif_util.py +92 -0
- snowflake/connector/_core/sf_core_python.cp315-win_amd64.pyd +0 -0
- snowflake/connector/_core/sf_core_python.pyi +79 -0
- snowflake/connector/_internal/__init__.py +6 -0
- snowflake/connector/_internal/_private_key_helper.py +31 -0
- snowflake/connector/_internal/api_client/__init__.py +93 -0
- snowflake/connector/_internal/api_client/bridge.py +41 -0
- snowflake/connector/_internal/api_client/client_api.py +976 -0
- snowflake/connector/_internal/arrow.py +47 -0
- snowflake/connector/_internal/arrow_context.py +240 -0
- snowflake/connector/_internal/arrow_stream_async.py +266 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp311-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp312-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp313-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp314-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp314t-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp315-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.pyi +42 -0
- snowflake/connector/_internal/arrow_stream_utils.py +171 -0
- snowflake/connector/_internal/authenticator_type.py +53 -0
- snowflake/connector/_internal/backward_compatibility.py +245 -0
- snowflake/connector/_internal/binding_converters.py +741 -0
- snowflake/connector/_internal/config_utils.py +71 -0
- snowflake/connector/_internal/connection/__init__.py +39 -0
- snowflake/connector/_internal/connection/connection.py +616 -0
- snowflake/connector/_internal/connection/connection_types.py +13 -0
- snowflake/connector/_internal/connection/constants.py +25 -0
- snowflake/connector/_internal/connection/decorators.py +31 -0
- snowflake/connector/_internal/connection/freezable_proxy.py +104 -0
- snowflake/connector/_internal/connection/queries.py +10 -0
- snowflake/connector/_internal/connection_config_mixin.py +755 -0
- snowflake/connector/_internal/cursor/__init__.py +25 -0
- snowflake/connector/_internal/cursor/base.py +732 -0
- snowflake/connector/_internal/cursor/cursor_types.py +13 -0
- snowflake/connector/_internal/cursor/decorators.py +56 -0
- snowflake/connector/_internal/cursor/query_result.py +202 -0
- snowflake/connector/_internal/cursor/query_result_waiter.py +98 -0
- snowflake/connector/_internal/cursor/result_metadata.py +255 -0
- snowflake/connector/_internal/cursor/result_set_wrapper.py +66 -0
- snowflake/connector/_internal/decorators.py +539 -0
- snowflake/connector/_internal/error_kinds.py +111 -0
- snowflake/connector/_internal/errorcode.py +35 -0
- snowflake/connector/_internal/errorhandler.py +278 -0
- snowflake/connector/_internal/fips.py +28 -0
- snowflake/connector/_internal/logging/__init__.py +52 -0
- snowflake/connector/_internal/logging/config.py +134 -0
- snowflake/connector/_internal/logging/core_logger.py +218 -0
- snowflake/connector/_internal/logging/native_extension_logger.py +144 -0
- snowflake/connector/_internal/logout_config_mapping.py +187 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +57 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.cpp +943 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.hpp +63 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +18 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +118 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +116 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.cpp +323 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.hpp +133 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.cpp +275 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.hpp +168 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.cpp +439 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.hpp +30 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +48 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +76 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +90 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +63 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +62 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +41 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +65 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +54 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +79 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +117 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +54 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +34 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +33 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +18 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +39 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +326 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +138 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.cpp +13278 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.pyx +204 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +109 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +125 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1914 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +208 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +128 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +58 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +144 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +160 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +98 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +243 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +207 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +80 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +83 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +201 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +108 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +164 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +926 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +182 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc.c +3052 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3019 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3354 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +344 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +29305 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +381 -0
- snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.cpp +108 -0
- snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.hpp +47 -0
- snowflake/connector/_internal/nanoarrow_cpp/scripts/.clang-format +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/scripts/format.sh +8 -0
- snowflake/connector/_internal/protobuf_gen/__init__.py +0 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.py +408 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.pyi +4487 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_services.py +2088 -0
- snowflake/connector/_internal/protobuf_gen/proto_exception.py +17 -0
- snowflake/connector/_internal/result_batch.py +150 -0
- snowflake/connector/_internal/snowflake_restful.py +222 -0
- snowflake/connector/_internal/snowpark_backcompat_helpers.py +31 -0
- snowflake/connector/_internal/sqlstate.py +11 -0
- snowflake/connector/_internal/statement_utils.py +207 -0
- snowflake/connector/_internal/text_utils.py +112 -0
- snowflake/connector/_internal/type_codes.py +139 -0
- snowflake/connector/_internal/utils.py +65 -0
- snowflake/connector/_internal/write_pandas_operation.py +657 -0
- snowflake/connector/aio/README.md +168 -0
- snowflake/connector/aio/__init__.py +37 -0
- snowflake/connector/aio/connection/__init__.py +17 -0
- snowflake/connector/aio/connection/_connection.py +506 -0
- snowflake/connector/aio/cursor/__init__.py +35 -0
- snowflake/connector/aio/cursor/_base.py +1034 -0
- snowflake/connector/aio/cursor/_dict_cursor.py +78 -0
- snowflake/connector/aio/cursor/_result_set_wrapper.py +35 -0
- snowflake/connector/aio/cursor/_snowflake_cursor.py +72 -0
- snowflake/connector/aio/pandas_tools.py +279 -0
- snowflake/connector/aio/result_batch.py +165 -0
- snowflake/connector/auth/__init__.py +0 -0
- snowflake/connector/auth/workload_identity.py +5 -0
- snowflake/connector/compat.py +22 -0
- snowflake/connector/config_manager.py +392 -0
- snowflake/connector/connection/__init__.py +30 -0
- snowflake/connector/connection/_connection.py +641 -0
- snowflake/connector/connection_config.py +517 -0
- snowflake/connector/constants.py +52 -0
- snowflake/connector/cursor/__init__.py +37 -0
- snowflake/connector/cursor/_base.py +1169 -0
- snowflake/connector/cursor/_chunked_download_reader.py +75 -0
- snowflake/connector/cursor/_dict_cursor.py +78 -0
- snowflake/connector/cursor/_result_set_wrapper.py +35 -0
- snowflake/connector/cursor/_snowflake_cursor.py +72 -0
- snowflake/connector/description.py +7 -0
- snowflake/connector/errors.py +492 -0
- snowflake/connector/network.py +71 -0
- snowflake/connector/pandas_tools.py +191 -0
- snowflake/connector/py.typed +0 -0
- snowflake/connector/result_batch.py +216 -0
- snowflake/connector/telemetry.py +40 -0
- snowflake/connector/time_util.py +11 -0
- snowflake/connector/types.py +134 -0
- snowflake/connector/util_text.py +3 -0
- snowflake/connector/version.py +23 -0
- snowflake_connector_python-5.2.0.dist-info/DELVEWHEEL +2 -0
- snowflake_connector_python-5.2.0.dist-info/METADATA +190 -0
- snowflake_connector_python-5.2.0.dist-info/RECORD +204 -0
- snowflake_connector_python-5.2.0.dist-info/WHEEL +4 -0
- snowflake_connector_python.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#ifndef PALIGNED_ALLOC_H
|
|
2
|
+
|
|
3
|
+
#ifdef __cplusplus
|
|
4
|
+
extern "C" {
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* NOTE: MSVC in general has no aligned alloc function that is
|
|
9
|
+
* compatible with free and it is not trivial to implement a version
|
|
10
|
+
* which is. Therefore, to remain portable, end user code needs to
|
|
11
|
+
* use `aligned_free` which is not part of C11 but defined in this header.
|
|
12
|
+
*
|
|
13
|
+
* glibc only provides aligned_alloc when _ISOC11_SOURCE is defined, but
|
|
14
|
+
* MingW does not support aligned_alloc despite of this, it uses the
|
|
15
|
+
* the _aligned_malloc as MSVC.
|
|
16
|
+
*
|
|
17
|
+
* The same issue is present on some Unix systems not providing
|
|
18
|
+
* posix_memalign.
|
|
19
|
+
*
|
|
20
|
+
* Note that clang and gcc with -std=c11 or -std=c99 will not define
|
|
21
|
+
* _POSIX_C_SOURCE and thus posix_memalign cannot be detected but
|
|
22
|
+
* aligned_alloc is not necessarily available either. We assume
|
|
23
|
+
* that clang always has posix_memalign although it is not strictly
|
|
24
|
+
* correct. For gcc, use -std=gnu99 or -std=gnu11 or don't use -std in
|
|
25
|
+
* order to enable posix_memalign, or live with the fallback until using
|
|
26
|
+
* a system where glibc has a version that supports aligned_alloc.
|
|
27
|
+
*
|
|
28
|
+
* For C11 compliant compilers and compilers with posix_memalign,
|
|
29
|
+
* it is valid to use free instead of aligned_free with the above
|
|
30
|
+
* caveats.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
#include <stdlib.h>
|
|
34
|
+
|
|
35
|
+
/*
|
|
36
|
+
* Define this to see which version is used so the fallback is not
|
|
37
|
+
* enganged unnecessarily:
|
|
38
|
+
*
|
|
39
|
+
* #define PORTABLE_DEBUG_ALIGNED_ALLOC
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
#if 0
|
|
43
|
+
#define PORTABLE_DEBUG_ALIGNED_ALLOC
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
#if !defined(PORTABLE_C11_ALIGNED_ALLOC)
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* PORTABLE_C11_ALIGNED_ALLOC = 1
|
|
50
|
+
* indicates that the system has builtin aligned_alloc
|
|
51
|
+
* If it doesn't, the section after detection provides an implemention.
|
|
52
|
+
*/
|
|
53
|
+
#if defined(__MINGW32__)
|
|
54
|
+
/* MingW does not provide aligned_alloc despite defining _ISOC11_SOURCE */
|
|
55
|
+
#define PORTABLE_C11_ALIGNED_ALLOC 0
|
|
56
|
+
#elif defined(_ISOC11_SOURCE)
|
|
57
|
+
/* glibc aligned_alloc detection, but MingW is not truthful */
|
|
58
|
+
#define PORTABLE_C11_ALIGNED_ALLOC 1
|
|
59
|
+
#elif defined(__GLIBC__)
|
|
60
|
+
/* aligned_alloc is not available in glibc just because __STDC_VERSION__ >= 201112L. */
|
|
61
|
+
#define PORTABLE_C11_ALIGNED_ALLOC 0
|
|
62
|
+
#elif defined(__clang__)
|
|
63
|
+
#define PORTABLE_C11_ALIGNED_ALLOC 0
|
|
64
|
+
#elif defined(__IBMC__)
|
|
65
|
+
#define PORTABLE_C11_ALIGNED_ALLOC 0
|
|
66
|
+
#elif (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
|
|
67
|
+
#define PORTABLE_C11_ALIGNED_ALLOC 1
|
|
68
|
+
#else
|
|
69
|
+
#define PORTABLE_C11_ALIGNED_ALLOC 0
|
|
70
|
+
#endif
|
|
71
|
+
|
|
72
|
+
#endif /* PORTABLE_C11_ALIGNED_ALLOC */
|
|
73
|
+
|
|
74
|
+
/* https://linux.die.net/man/3/posix_memalign */
|
|
75
|
+
#if !defined(PORTABLE_POSIX_MEMALIGN) && defined(_GNU_SOURCE)
|
|
76
|
+
#define PORTABLE_POSIX_MEMALIGN 1
|
|
77
|
+
#endif
|
|
78
|
+
|
|
79
|
+
/* https://forum.kde.org/viewtopic.php?p=66274 */
|
|
80
|
+
#if !defined(PORTABLE_POSIX_MEMALIGN) && defined(_XOPEN_SOURCE)
|
|
81
|
+
#if _XOPEN_SOURCE >= 600
|
|
82
|
+
#define PORTABLE_POSIX_MEMALIGN 1
|
|
83
|
+
#endif
|
|
84
|
+
#endif
|
|
85
|
+
|
|
86
|
+
#if !defined(PORTABLE_POSIX_MEMALIGN) && defined(_POSIX_C_SOURCE)
|
|
87
|
+
#if _POSIX_C_SOURCE >= 200112L
|
|
88
|
+
#define PORTABLE_POSIX_MEMALIGN 1
|
|
89
|
+
#endif
|
|
90
|
+
#endif
|
|
91
|
+
|
|
92
|
+
#if !defined(PORTABLE_POSIX_MEMALIGN) && defined(__clang__)
|
|
93
|
+
#define PORTABLE_POSIX_MEMALIGN 1
|
|
94
|
+
#endif
|
|
95
|
+
|
|
96
|
+
#if !defined(PORTABLE_POSIX_MEMALIGN)
|
|
97
|
+
#define PORTABLE_POSIX_MEMALIGN 0
|
|
98
|
+
#endif
|
|
99
|
+
|
|
100
|
+
/* https://forum.kde.org/viewtopic.php?p=66274 */
|
|
101
|
+
#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
|
|
102
|
+
/* C11 or newer */
|
|
103
|
+
#include <stdalign.h>
|
|
104
|
+
#endif
|
|
105
|
+
|
|
106
|
+
/* C11 or newer */
|
|
107
|
+
#if !defined(aligned_alloc) && !defined(__aligned_alloc_is_defined)
|
|
108
|
+
|
|
109
|
+
#if PORTABLE_C11_ALIGNED_ALLOC
|
|
110
|
+
#ifdef PORTABLE_DEBUG_ALIGNED_ALLOC
|
|
111
|
+
#error "DEBUG: C11_ALIGNED_ALLOC configured"
|
|
112
|
+
#endif
|
|
113
|
+
#elif defined(_MSC_VER) || defined(__MINGW32__)
|
|
114
|
+
|
|
115
|
+
#ifdef PORTABLE_DEBUG_ALIGNED_ALLOC
|
|
116
|
+
#error "DEBUG: Windows _aligned_malloc configured"
|
|
117
|
+
#endif
|
|
118
|
+
|
|
119
|
+
/* Aligned _aligned_malloc is not compatible with free. */
|
|
120
|
+
#define aligned_alloc(alignment, size) _aligned_malloc(size, alignment)
|
|
121
|
+
#define aligned_free(p) _aligned_free(p)
|
|
122
|
+
#define __aligned_alloc_is_defined 1
|
|
123
|
+
#define __aligned_free_is_defined 1
|
|
124
|
+
|
|
125
|
+
#elif PORTABLE_POSIX_MEMALIGN
|
|
126
|
+
|
|
127
|
+
#if defined(__GNUC__)
|
|
128
|
+
#if !defined(__GNUCC__)
|
|
129
|
+
extern int posix_memalign(void**, size_t, size_t);
|
|
130
|
+
#elif __GNUCC__ < 5
|
|
131
|
+
extern int posix_memalign(void**, size_t, size_t);
|
|
132
|
+
#endif
|
|
133
|
+
#endif
|
|
134
|
+
|
|
135
|
+
static inline void* __portable_aligned_alloc(size_t alignment, size_t size) {
|
|
136
|
+
int err;
|
|
137
|
+
void* p = 0;
|
|
138
|
+
|
|
139
|
+
if (alignment < sizeof(void*)) {
|
|
140
|
+
alignment = sizeof(void*);
|
|
141
|
+
}
|
|
142
|
+
err = posix_memalign(&p, alignment, size);
|
|
143
|
+
if (err && p) {
|
|
144
|
+
free(p);
|
|
145
|
+
p = 0;
|
|
146
|
+
}
|
|
147
|
+
return p;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#ifdef PORTABLE_DEBUG_ALIGNED_ALLOC
|
|
151
|
+
#error "DEBUG: POSIX_MEMALIGN configured"
|
|
152
|
+
#endif
|
|
153
|
+
|
|
154
|
+
#define aligned_alloc(alignment, size) __portable_aligned_alloc(alignment, size)
|
|
155
|
+
#define aligned_free(p) free(p)
|
|
156
|
+
#define __aligned_alloc_is_defined 1
|
|
157
|
+
#define __aligned_free_is_defined 1
|
|
158
|
+
|
|
159
|
+
#else
|
|
160
|
+
|
|
161
|
+
static inline void* __portable_aligned_alloc(size_t alignment, size_t size) {
|
|
162
|
+
char* raw;
|
|
163
|
+
void* buf;
|
|
164
|
+
size_t total_size = (size + alignment - 1 + sizeof(void*));
|
|
165
|
+
|
|
166
|
+
if (alignment < sizeof(void*)) {
|
|
167
|
+
alignment = sizeof(void*);
|
|
168
|
+
}
|
|
169
|
+
raw = (char*)(size_t)malloc(total_size);
|
|
170
|
+
buf = raw + alignment - 1 + sizeof(void*);
|
|
171
|
+
buf = (void*)(((size_t)buf) & ~(alignment - 1));
|
|
172
|
+
((void**)buf)[-1] = raw;
|
|
173
|
+
return buf;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static inline void __portable_aligned_free(void* p) {
|
|
177
|
+
char* raw;
|
|
178
|
+
|
|
179
|
+
if (p) {
|
|
180
|
+
raw = (char*)((void**)p)[-1];
|
|
181
|
+
free(raw);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
#define aligned_alloc(alignment, size) __portable_aligned_alloc(alignment, size)
|
|
186
|
+
#define aligned_free(p) __portable_aligned_free(p)
|
|
187
|
+
#define __aligned_alloc_is_defined 1
|
|
188
|
+
#define __aligned_free_is_defined 1
|
|
189
|
+
|
|
190
|
+
#ifdef PORTABLE_DEBUG_ALIGNED_ALLOC
|
|
191
|
+
#error "DEBUG: aligned_alloc malloc fallback configured"
|
|
192
|
+
#endif
|
|
193
|
+
|
|
194
|
+
#endif
|
|
195
|
+
|
|
196
|
+
#endif /* aligned_alloc */
|
|
197
|
+
|
|
198
|
+
#if !defined(aligned_free) && !defined(__aligned_free_is_defined)
|
|
199
|
+
#define aligned_free(p) free(p)
|
|
200
|
+
#define __aligned_free_is_defined 1
|
|
201
|
+
#endif
|
|
202
|
+
|
|
203
|
+
#ifdef __cplusplus
|
|
204
|
+
}
|
|
205
|
+
#endif
|
|
206
|
+
|
|
207
|
+
#endif /* PALIGNED_ALLOC_H */
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* C23 introduces an attribute syntax `[[<attribute>]]`. Prior to that
|
|
4
|
+
* other non-standard syntaxes such as `__attribute__((<attribute>))`
|
|
5
|
+
* and `__declspec(<attribute>)` have been supported by some compiler
|
|
6
|
+
* versions.
|
|
7
|
+
*
|
|
8
|
+
* See also:
|
|
9
|
+
* https://en.cppreference.com/w/c/language/attributes
|
|
10
|
+
*
|
|
11
|
+
* There is no portable way to use C23 attributes in older C standards
|
|
12
|
+
* so in order to use these portably, some macro name needs to be
|
|
13
|
+
* defined for each attribute that either maps to the older supported
|
|
14
|
+
* syntax, or ignores the attribute as appropriate.
|
|
15
|
+
*
|
|
16
|
+
* The Linux kernel defines certain attributes as macros, such as
|
|
17
|
+
* `fallthrough`. When adding attributes it seems reasonable to follow
|
|
18
|
+
* the Linux conventions in lack of any official standard. However, it
|
|
19
|
+
* is not the intention that this file should mirror the Linux
|
|
20
|
+
* attributes 1 to 1.
|
|
21
|
+
*
|
|
22
|
+
* See also:
|
|
23
|
+
* https://github.com/torvalds/linux/blob/master/include/linux/compiler_attributes.h
|
|
24
|
+
*
|
|
25
|
+
* There is a risk that exposed attribute names may lead to name
|
|
26
|
+
* conflicts. A conflicting name can be undefined and if necessary used
|
|
27
|
+
* using `pattribute(<attribute>)`. All attributes can be hidden by
|
|
28
|
+
* defining `PORTABLE_EXPOSE_ATTRIBUTES=0` in which case
|
|
29
|
+
* `pattribute(<attribute>)` can still be used and then if a specific
|
|
30
|
+
* attribute name still needs to be exposed, it can be defined manually
|
|
31
|
+
* like `#define fallthrough pattribute(fallthrough)`.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
#ifndef PATTRIBUTES_H
|
|
35
|
+
#define PATTRIBUTES_H
|
|
36
|
+
|
|
37
|
+
#ifdef __cplusplus
|
|
38
|
+
extern "C" {
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#ifndef PORTABLE_EXPOSE_ATTRIBUTES
|
|
42
|
+
#define PORTABLE_EXPOSE_ATTRIBUTES 1
|
|
43
|
+
#endif
|
|
44
|
+
|
|
45
|
+
#ifdef __has_c_attribute
|
|
46
|
+
#define PORTABLE_HAS_C_ATTRIBUTE(x) __has_c_attribute(x)
|
|
47
|
+
#else
|
|
48
|
+
#define PORTABLE_HAS_C_ATTRIBUTE(x) 0
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
#ifdef __has_attribute
|
|
52
|
+
#define PORTABLE_HAS_ATTRIBUTE(x) __has_attribute(x)
|
|
53
|
+
#else
|
|
54
|
+
#define PORTABLE_HAS_ATTRIBUTE(x) 0
|
|
55
|
+
#endif
|
|
56
|
+
|
|
57
|
+
/* https://en.cppreference.com/w/c/language/attributes/fallthrough */
|
|
58
|
+
#if PORTABLE_HAS_C_ATTRIBUTE(__fallthrough__)
|
|
59
|
+
#define pattribute_fallthrough [[__fallthrough__]]
|
|
60
|
+
#elif PORTABLE_HAS_ATTRIBUTE(__fallthrough__)
|
|
61
|
+
#define pattribute_fallthrough __attribute__((__fallthrough__))
|
|
62
|
+
#else
|
|
63
|
+
#define pattribute_fallthrough ((void)0)
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
#define pattribute(x) pattribute_##x
|
|
67
|
+
|
|
68
|
+
#if PORTABLE_EXPOSE_ATTRIBUTES
|
|
69
|
+
|
|
70
|
+
#ifndef fallthrough
|
|
71
|
+
#define fallthrough pattribute(fallthrough)
|
|
72
|
+
#endif
|
|
73
|
+
|
|
74
|
+
#endif
|
|
75
|
+
|
|
76
|
+
#ifdef __cplusplus
|
|
77
|
+
}
|
|
78
|
+
#endif
|
|
79
|
+
|
|
80
|
+
#endif /* PATTRIBUTES_H */
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/* There is intentionally no include guard in this file. */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Usage: optionally disable any of these before including.
|
|
5
|
+
*
|
|
6
|
+
* #define PDIAGNOSTIC_IGNORE_UNUSED_FUNCTION
|
|
7
|
+
* #define PDIAGNOSTIC_IGNORE_UNUSED_VARIABLE
|
|
8
|
+
* #define PDIAGNOSTIC_IGNORE_UNUSED_PARAMETER
|
|
9
|
+
* #define PDIAGNOSTIC_IGNORE_UNUSED // all of the above
|
|
10
|
+
*
|
|
11
|
+
* #include "pdiagnostic.h"
|
|
12
|
+
*
|
|
13
|
+
* Alternatively use #include "pdiagnostic_push/pop.h"
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#ifdef _MSC_VER
|
|
17
|
+
#pragma warning(disable : 4668) /* preprocessor name not defined */
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
#if !defined(PDIAGNOSTIC_AWARE_MSVC) && defined(_MSC_VER)
|
|
21
|
+
#define PDIAGNOSTIC_AWARE_MSVC 1
|
|
22
|
+
#elif !defined(PDIAGNOSTIC_AWARE_MSVC)
|
|
23
|
+
#define PDIAGNOSTIC_AWARE_MSVC 0
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
#if !defined(PDIAGNOSTIC_AWARE_CLANG) && defined(__clang__)
|
|
27
|
+
#define PDIAGNOSTIC_AWARE_CLANG 1
|
|
28
|
+
#elif !defined(PDIAGNOSTIC_AWARE_CLANG)
|
|
29
|
+
#define PDIAGNOSTIC_AWARE_CLANG 0
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
#if !defined(PDIAGNOSTIC_AWARE_GCC) && defined(__GNUC__) && !defined(__clang__)
|
|
33
|
+
/* Can disable some warnings even if push is not available (gcc-4.2 vs gcc-4.7) */
|
|
34
|
+
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
|
|
35
|
+
#define PDIAGNOSTIC_AWARE_GCC 1
|
|
36
|
+
#endif
|
|
37
|
+
#endif
|
|
38
|
+
|
|
39
|
+
#if !defined(PDIAGNOSTIC_AWARE_GCC)
|
|
40
|
+
#define PDIAGNOSTIC_AWARE_GCC 0
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
#if defined(PDIAGNOSTIC_IGNORE_UNUSED_FUNCTION) || defined(PDIAGNOSTIC_IGNORE_UNUSED)
|
|
44
|
+
#if PDIAGNOSTIC_AWARE_CLANG
|
|
45
|
+
#pragma clang diagnostic ignored "-Wunused-function"
|
|
46
|
+
#elif PDIAGNOSTIC_AWARE_GCC
|
|
47
|
+
#pragma GCC diagnostic ignored "-Wunused-function"
|
|
48
|
+
#endif
|
|
49
|
+
#endif
|
|
50
|
+
#undef PDIAGNOSTIC_IGNORE_UNUSED_FUNCTION
|
|
51
|
+
|
|
52
|
+
#if defined(PDIAGNOSTIC_IGNORE_UNUSED_VARIABLE) || defined(PDIAGNOSTIC_IGNORE_UNUSED)
|
|
53
|
+
#if PDIAGNOSTIC_AWARE_MSVC
|
|
54
|
+
#pragma warning(disable : 4101) /* unused local variable */
|
|
55
|
+
#elif PDIAGNOSTIC_AWARE_CLANG
|
|
56
|
+
#pragma clang diagnostic ignored "-Wunused-variable"
|
|
57
|
+
#elif PDIAGNOSTIC_AWARE_GCC
|
|
58
|
+
#pragma GCC diagnostic ignored "-Wunused-variable"
|
|
59
|
+
#endif
|
|
60
|
+
#endif
|
|
61
|
+
#undef PDIAGNOSTIC_IGNORE_UNUSED_VARIABLE
|
|
62
|
+
|
|
63
|
+
#if defined(PDIAGNOSTIC_IGNORE_UNUSED_PARAMETER) || defined(PDIAGNOSTIC_IGNORE_UNUSED)
|
|
64
|
+
#if PDIAGNOSTIC_AWARE_CLANG
|
|
65
|
+
#pragma clang diagnostic ignored "-Wunused-parameter"
|
|
66
|
+
#elif PDIAGNOSTIC_AWARE_GCC
|
|
67
|
+
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
68
|
+
#endif
|
|
69
|
+
#endif
|
|
70
|
+
#undef PDIAGNOSTIC_IGNORE_UNUSED_PARAMETER
|
|
71
|
+
|
|
72
|
+
#undef PDIAGNOSTIC_IGNORE_UNUSED
|
|
73
|
+
|
|
74
|
+
#if defined(__cplusplus) && __cplusplus < 201103L
|
|
75
|
+
#if PDIAGNOSTIC_AWARE_CLANG
|
|
76
|
+
/* Needed for < C++11 clang C++ static_assert */
|
|
77
|
+
#pragma clang diagnostic ignored "-Wc11-extensions"
|
|
78
|
+
/* Needed for empty macro arguments. */
|
|
79
|
+
#pragma clang diagnostic ignored "-Wc99-extensions"
|
|
80
|
+
/* Needed for trailing commas. */
|
|
81
|
+
#pragma clang diagnostic ignored "-Wc++11-extensions"
|
|
82
|
+
#endif
|
|
83
|
+
#endif
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#if defined(PDIAGNOSTIC_PUSHED_MSVC)
|
|
2
|
+
#if PDIAGNOSTIC_PUSHED_MSVC
|
|
3
|
+
#pragma warning(pop)
|
|
4
|
+
#endif // PDIAGNOSTIC_PUSHED_MSVC
|
|
5
|
+
#undef PDIAGNOSTIC_PUSHED_MSVC
|
|
6
|
+
#endif // defined(PDIAGNOSTIC_PUSHED_MSVC)
|
|
7
|
+
|
|
8
|
+
#if defined(PDIAGNOSTIC_PUSHED_CLANG)
|
|
9
|
+
#if PDIAGNOSTIC_PUSHED_CLANG
|
|
10
|
+
#pragma clang diagnostic pop
|
|
11
|
+
#endif // PDIAGNOSTIC_PUSHED_CLANG
|
|
12
|
+
#undef PDIAGNOSTIC_PUSHED_CLANG
|
|
13
|
+
#endif // defined(PDIAGNOSTIC_PUSHED_CLANG)
|
|
14
|
+
|
|
15
|
+
#if defined(PDIAGNOSTIC_PUSHED_GCC)
|
|
16
|
+
#if PDIAGNOSTIC_PUSHED_GCC
|
|
17
|
+
#pragma GCC diagnostic pop
|
|
18
|
+
#endif // PDIAGNOSTIC_PUSHED_GCC
|
|
19
|
+
#undef PDIAGNOSTIC_PUSHED_GCC
|
|
20
|
+
#endif // defined(PDIAGNOSTIC_PUSHED_GCC)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* See also comment in "pdiagnostic.h"
|
|
3
|
+
*
|
|
4
|
+
* e.g.
|
|
5
|
+
* #define PDIAGNOSTIC_IGNORE_USED_FUNCTION
|
|
6
|
+
* #define PDIAGNOSTIC_IGNORE_USED_VARIABLE
|
|
7
|
+
* #include "pdiagnostic_push"
|
|
8
|
+
* ...
|
|
9
|
+
* #include "pdiagnostic_pop.h"
|
|
10
|
+
* <eof>
|
|
11
|
+
*
|
|
12
|
+
* or if push pop isn't desired:
|
|
13
|
+
* #define PDIAGNOSTIC_IGNORE_USED_FUNCTION
|
|
14
|
+
* #define PDIAGNOSTIC_IGNORE_USED_VARIABLE
|
|
15
|
+
* #include "pdiagnostic.h"
|
|
16
|
+
* ...
|
|
17
|
+
* <eof>
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* Some if these warnings cannot be ignored
|
|
21
|
+
* at the #pragma level, but might in the future.
|
|
22
|
+
* Use compiler switches like -Wno-unused-function
|
|
23
|
+
* to work around this.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#if defined(_MSC_VER)
|
|
27
|
+
#pragma warning(push)
|
|
28
|
+
#define PDIAGNOSTIC_PUSHED_MSVC 1
|
|
29
|
+
#else
|
|
30
|
+
#define PDIAGNOSTIC_PUSHED_MSVC 0
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
#if defined(__clang__)
|
|
34
|
+
#pragma clang diagnostic push
|
|
35
|
+
#define PDIAGNOSTIC_PUSHED_CLANG 1
|
|
36
|
+
#else
|
|
37
|
+
#define PDIAGNOSTIC_PUSHED_CLANG 0
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#if defined(__GNUC__) && !defined(__clang__)
|
|
41
|
+
#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
|
|
42
|
+
#pragma GCC diagnostic push
|
|
43
|
+
#define PDIAGNOSTIC_PUSHED_GCC 1
|
|
44
|
+
#else
|
|
45
|
+
#define PDIAGNOSTIC_PUSHED_GCC 0
|
|
46
|
+
#endif // GNUC >= 4.6
|
|
47
|
+
#else
|
|
48
|
+
#define PDIAGNOSTIC_PUSHED_GCC 0
|
|
49
|
+
#endif // defined(__GNUC__) && !defined(__clang__)
|
|
50
|
+
|
|
51
|
+
#include "pdiagnostic.h"
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
#ifndef PENDIAN_H
|
|
2
|
+
#define PENDIAN_H
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Defines platform optimized (as per linux <endian.h>
|
|
10
|
+
*
|
|
11
|
+
* le16toh, le32to, le64toh, be16toh, be32toh, be64toh
|
|
12
|
+
* htole16, htole32, htole64, htobe16, htobe32, htobe64
|
|
13
|
+
*
|
|
14
|
+
* Falls back to auto-detect endian conversion which is also fast
|
|
15
|
+
* if fast byteswap operation was detected.
|
|
16
|
+
*
|
|
17
|
+
* Also defines platform optimized:
|
|
18
|
+
*
|
|
19
|
+
* bswap16, bswap32, bswap64,
|
|
20
|
+
*
|
|
21
|
+
* with fall-back to shift-or implementation.
|
|
22
|
+
*
|
|
23
|
+
* For convenience also defines:
|
|
24
|
+
*
|
|
25
|
+
* le8to, be8toh, htole8, htobe8
|
|
26
|
+
* bswap8
|
|
27
|
+
*
|
|
28
|
+
* The convience functions makes is simpler to define conversion macros
|
|
29
|
+
* based on type size.
|
|
30
|
+
*
|
|
31
|
+
* NOTE: this implementation expects arguments with no side-effects and
|
|
32
|
+
* with appropriately sized unsigned arguments. These are expected to be
|
|
33
|
+
* used with typesafe wrappers.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
#ifndef UINT8_MAX
|
|
37
|
+
#include "pstdint.h"
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#if defined(__linux__)
|
|
41
|
+
#include <endian.h>
|
|
42
|
+
#elif defined(__OpenBSD__) || defined(__FreeBSD__)
|
|
43
|
+
#include <sys/endian.h>
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
#include "pendian_detect.h"
|
|
47
|
+
|
|
48
|
+
#if defined(_MSC_VER)
|
|
49
|
+
#if _MSC_VER >= 1300
|
|
50
|
+
#include <stdlib.h>
|
|
51
|
+
#define bswap16 _byteswap_ushort
|
|
52
|
+
#define bswap32 _byteswap_ulong
|
|
53
|
+
#define bswap64 _byteswap_uint64
|
|
54
|
+
#endif
|
|
55
|
+
#elif defined(__clang__)
|
|
56
|
+
#if __has_builtin(__builtin_bswap16)
|
|
57
|
+
#ifndef bswap16
|
|
58
|
+
#define bswap16 __builtin_bswap16
|
|
59
|
+
#endif
|
|
60
|
+
#endif
|
|
61
|
+
#if __has_builtin(__builtin_bswap32)
|
|
62
|
+
#ifndef bswap32
|
|
63
|
+
#define bswap32 __builtin_bswap32
|
|
64
|
+
#endif
|
|
65
|
+
#endif
|
|
66
|
+
#if __has_builtin(__builtin_bswap64)
|
|
67
|
+
#ifndef bswap64
|
|
68
|
+
#define bswap64 __builtin_bswap64
|
|
69
|
+
#endif
|
|
70
|
+
#endif
|
|
71
|
+
#elif defined(__OpenBSD__) || defined(__FreeBSD__)
|
|
72
|
+
#ifndef bswap16
|
|
73
|
+
#define bswap16 swap16
|
|
74
|
+
#endif
|
|
75
|
+
#ifndef bswap32
|
|
76
|
+
#define bswap32 swap32
|
|
77
|
+
#endif
|
|
78
|
+
#ifndef bswap64
|
|
79
|
+
#define bswap64 swap64
|
|
80
|
+
#endif
|
|
81
|
+
#elif defined(__GNUC__) /* Supported since at least GCC 4.4 */
|
|
82
|
+
#ifndef bswap32
|
|
83
|
+
#define bswap32 __builtin_bswap32
|
|
84
|
+
#endif
|
|
85
|
+
#ifndef bswap64
|
|
86
|
+
#define bswap64 __builtin_bswap64
|
|
87
|
+
#endif
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
#ifndef bswap16
|
|
91
|
+
#define bswap16(v) (((uint16_t)(v) << 8) | ((uint16_t)(v) >> 8))
|
|
92
|
+
#endif
|
|
93
|
+
|
|
94
|
+
#ifndef bswap32
|
|
95
|
+
#define bswap32(v) \
|
|
96
|
+
((((uint32_t)(v) << 24)) | (((uint32_t)(v) << 8) & UINT32_C(0x00FF0000)) | \
|
|
97
|
+
(((uint32_t)(v) >> 8) & UINT32_C(0x0000FF00)) | (((uint32_t)(v) >> 24)))
|
|
98
|
+
#endif
|
|
99
|
+
|
|
100
|
+
#ifndef bswap64
|
|
101
|
+
#define bswap64(v) \
|
|
102
|
+
((((uint64_t)(v) << 56)) | (((uint64_t)(v) << 40) & UINT64_C(0x00FF000000000000)) | \
|
|
103
|
+
(((uint64_t)(v) << 24) & UINT64_C(0x0000FF0000000000)) | \
|
|
104
|
+
(((uint64_t)(v) << 8) & UINT64_C(0x000000FF00000000)) | \
|
|
105
|
+
(((uint64_t)(v) >> 8) & UINT64_C(0x00000000FF000000)) | \
|
|
106
|
+
(((uint64_t)(v) >> 24) & UINT64_C(0x0000000000FF0000)) | \
|
|
107
|
+
(((uint64_t)(v) >> 40) & UINT64_C(0x000000000000FF00)) | (((uint64_t)(v) >> 56)))
|
|
108
|
+
#endif
|
|
109
|
+
|
|
110
|
+
#ifndef bswap8
|
|
111
|
+
#define bswap8(v) ((uint8_t)(v))
|
|
112
|
+
#endif
|
|
113
|
+
|
|
114
|
+
#if !defined(le16toh) && defined(letoh16)
|
|
115
|
+
#define le16toh letoh16
|
|
116
|
+
#define le32toh letoh32
|
|
117
|
+
#define le64toh letoh64
|
|
118
|
+
#endif
|
|
119
|
+
|
|
120
|
+
#if !defined(be16toh) && defined(betoh16)
|
|
121
|
+
#define be16toh betoh16
|
|
122
|
+
#define be32toh betoh32
|
|
123
|
+
#define be64toh betoh64
|
|
124
|
+
#endif
|
|
125
|
+
|
|
126
|
+
/* Assume it goes for all. */
|
|
127
|
+
#if !defined(le16toh)
|
|
128
|
+
|
|
129
|
+
#if defined(__LITTLE_ENDIAN__)
|
|
130
|
+
|
|
131
|
+
#define le16toh(v) (v)
|
|
132
|
+
#define le32toh(v) (v)
|
|
133
|
+
#define le64toh(v) (v)
|
|
134
|
+
|
|
135
|
+
#define htole16(v) (v)
|
|
136
|
+
#define htole32(v) (v)
|
|
137
|
+
#define htole64(v) (v)
|
|
138
|
+
|
|
139
|
+
#define be16toh(v) bswap16(v)
|
|
140
|
+
#define be32toh(v) bswap32(v)
|
|
141
|
+
#define be64toh(v) bswap64(v)
|
|
142
|
+
|
|
143
|
+
#define htobe16(v) bswap16(v)
|
|
144
|
+
#define htobe32(v) bswap32(v)
|
|
145
|
+
#define htobe64(v) bswap64(v)
|
|
146
|
+
|
|
147
|
+
#elif defined(__BIG_ENDIAN__)
|
|
148
|
+
|
|
149
|
+
#define le16toh(v) bswap16(v)
|
|
150
|
+
#define le32toh(v) bswap32(v)
|
|
151
|
+
#define le64toh(v) bswap64(v)
|
|
152
|
+
|
|
153
|
+
#define htole16(v) bswap16(v)
|
|
154
|
+
#define htole32(v) bswap32(v)
|
|
155
|
+
#define htole64(v) bswap64(v)
|
|
156
|
+
|
|
157
|
+
#define be16toh(v) (v)
|
|
158
|
+
#define be32toh(v) (v)
|
|
159
|
+
#define be64toh(v) (v)
|
|
160
|
+
|
|
161
|
+
#define htobe16(v) (v)
|
|
162
|
+
#define htobe32(v) (v)
|
|
163
|
+
#define htobe64(v) (v)
|
|
164
|
+
|
|
165
|
+
#else
|
|
166
|
+
|
|
167
|
+
static const int __pendian_test = 1;
|
|
168
|
+
|
|
169
|
+
#define le16toh(v) (*(char*)&__pendian_test ? (v) : bswap16(v))
|
|
170
|
+
#define le32toh(v) (*(char*)&__pendian_test ? (v) : bswap32(v))
|
|
171
|
+
#define le64toh(v) (*(char*)&__pendian_test ? (v) : bswap64(v))
|
|
172
|
+
|
|
173
|
+
#define htole16(v) (*(char*)&__pendian_test ? (v) : bswap16(v))
|
|
174
|
+
#define htole32(v) (*(char*)&__pendian_test ? (v) : bswap32(v))
|
|
175
|
+
#define htole64(v) (*(char*)&__pendian_test ? (v) : bswap64(v))
|
|
176
|
+
|
|
177
|
+
#define be16toh(v) (*(char*)&__pendian_test ? bswap16(v) : (v))
|
|
178
|
+
#define be32toh(v) (*(char*)&__pendian_test ? bswap32(v) : (v))
|
|
179
|
+
#define be64toh(v) (*(char*)&__pendian_test ? bswap64(v) : (v))
|
|
180
|
+
|
|
181
|
+
#define htobe16(v) (*(char*)&__pendian_test ? bswap16(v) : (v))
|
|
182
|
+
#define htobe32(v) (*(char*)&__pendian_test ? bswap32(v) : (v))
|
|
183
|
+
#define htobe64(v) (*(char*)&__pendian_test ? bswap64(v) : (v))
|
|
184
|
+
|
|
185
|
+
#endif
|
|
186
|
+
|
|
187
|
+
#endif /* le16toh */
|
|
188
|
+
|
|
189
|
+
/* Helpers not part of Linux <endian.h> */
|
|
190
|
+
#if !defined(le8toh)
|
|
191
|
+
#define le8toh(n) (n)
|
|
192
|
+
#define htole8(n) (n)
|
|
193
|
+
#define be8toh(n) (n)
|
|
194
|
+
#define htobe8(n) (n)
|
|
195
|
+
#endif
|
|
196
|
+
|
|
197
|
+
#ifdef __cplusplus
|
|
198
|
+
}
|
|
199
|
+
#endif
|
|
200
|
+
|
|
201
|
+
#endif /* PENDIAN_H */
|