Awkward Array: include/awkward/common.h Source File

Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1// BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
2
3#ifndef AWKWARD_COMMON_H_
4#define AWKWARD_COMMON_H_
5
6#ifdef _MSC_VER
7 #define EXPORT_SYMBOL __declspec(dllexport)
8 #ifdef _WIN64
9 typedef signed __int64 ssize_t;
10 typedef unsigned __int64 size_t;
11 #else
12 typedef signed int ssize_t;
13 typedef unsigned int size_t;
14 #endif
15 typedef unsigned char uint8_t;
16 typedef signed char int8_t;
17 typedef unsigned short uint16_t;
18 typedef signed short int16_t;
19 typedef unsigned int uint32_t;
20 typedef signed int int32_t;
21 typedef unsigned __int64 uint64_t;
22 typedef signed __int64 int64_t;
23 #define ERROR Error
24#else
25 #define EXPORT_SYMBOL __attribute__((visibility("default")))
26 #include <cstddef>
27 #include <cstdint>
28 #define ERROR struct Error
29#endif
30
31#define QUOTE(x) #x
32
33#define FILENAME_FOR_EXCEPTIONS(filename, line) std::string("\n\n(https://github.com/scikit-hep/awkward-1.0/blob/" VERSION_INFO "/" filename "#L" #line ")")
34#define FILENAME_FOR_EXCEPTIONS_C(filename, line) ("\n\n(https://github.com/scikit-hep/awkward-1.0/blob/" VERSION_INFO "/" filename "#L" #line ")")
35#define FILENAME_FOR_EXCEPTIONS_CUDA(filename, line) ("\n\n(https://github.com/scikit-hep/awkward-1.0/blob/" QUOTE(VERSION_INFO) "/" filename "#L" #line ")")
36
37#ifdef __GNUC__
38// Silence a gcc warning: type attributes ignored after type is already defined
39 #define EXPORT_TEMPLATE_INST
40#else
41 #define EXPORT_TEMPLATE_INST EXPORT_SYMBOL
42#endif
43
44#ifndef LIBAWKWARD_EXPORT_SYMBOL
45 #define LIBAWKWARD_EXPORT_SYMBOL
46#endif
47
48#include <iostream>
49#include <algorithm>
50#include <map>
51#include <vector>
52#include <mutex>
53#include <memory>
54#include <cstring>
55
56extern "C" {
57 struct LIBAWKWARD_EXPORT_SYMBOL Error {
58 const char* str;
59 const char* filename;
60 int64_t identity;
61 int64_t attempt;
62 bool pass_through;
63 };
64
65 const int8_t kMaxInt8 = 127; // 2**7 - 1
66 const uint8_t kMaxUInt8 = 255; // 2**8 - 1
67 const int32_t kMaxInt32 = 2147483647; // 2**31 - 1
68 const uint32_t kMaxUInt32 = 4294967295; // 2**32 - 1
69 const int64_t kMaxInt64 = 9223372036854775806; // 2**63 - 2: see below
70 const int64_t kSliceNone = kMaxInt64 + 1; // for Slice::none()
71 const int64_t kMaxLevels = 48;
72
73 inline struct Error
74 success() {
75 struct Error out;
76 out.str = nullptr;
77 out.filename = nullptr;
78 out.identity = kSliceNone;
79 out.attempt = kSliceNone;
80 out.pass_through = false;
81 return out;
82 };
83
84 inline struct Error
85 failure(
86 const char* str,
87 int64_t identity,
88 int64_t attempt,
89 const char* filename) {
90 struct Error out;
91 out.str = str;
92 out.filename = filename;
93 out.identity = identity;
94 out.attempt = attempt;
95 out.pass_through = false;
96 return out;
97 };
98
99 inline struct Error
100 failure_pass_through(
101 const char* str,
102 int64_t identity,
103 int64_t attempt,
104 const char* filename) {
105 struct Error out;
106 out.str = str;
107 out.filename = filename;
108 out.identity = identity;
109 out.attempt = attempt;
110 out.pass_through = true;
111 return out;
112 };
113}
114
115#endif // AWKWARD_COMMON_H_
kMaxUInt32
const uint32_t kMaxUInt32
Definition: common.h:68
kMaxLevels
const int64_t kMaxLevels
Definition: common.h:71
kSliceNone
const int64_t kSliceNone
Definition: common.h:70
LIBAWKWARD_EXPORT_SYMBOL
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
kMaxInt64
const int64_t kMaxInt64
Definition: common.h:69
kMaxUInt8
const uint8_t kMaxUInt8
Definition: common.h:66
kMaxInt32
const int32_t kMaxInt32
Definition: common.h:67
failure_pass_through
struct Error failure_pass_through(const char *str, int64_t identity, int64_t attempt, const char *filename)
Definition: common.h:100
success
struct Error success()
Definition: common.h:74
failure
struct Error failure(const char *str, int64_t identity, int64_t attempt, const char *filename)
Definition: common.h:85
kMaxInt8
const int8_t kMaxInt8
Definition: common.h:65
identity
py::tuple identity(const T &self)
Creates a single identity as a Python tuple of integers and strings.
Error
Definition: common.h:57
Error::pass_through
bool pass_through
Definition: common.h:62
Error::attempt
int64_t attempt
Definition: common.h:61
Error::identity
int64_t identity
Definition: common.h:60
Error::filename
const char * filename
Definition: common.h:59
Error::str
const char * str
Definition: common.h:58