1
- /*===----- WrapperFunctionResult .h - blob-of-bytes container -----*- C -*-===*\
1
+ /*===--------- WrapperFunction .h - Wrapper function utils ---- -----*- C -*-===*\
2
2
|* *|
3
3
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4
4
|* Exceptions. *|
7
7
|* *|
8
8
|*===----------------------------------------------------------------------===*|
9
9
|* *|
10
- |* Defines orc_rt_WrapperFunctionResult and related APIs. *|
10
+ |* Defines orc_rt_WrapperFunctionBuffer and related APIs. *|
11
11
|* *|
12
12
\*===----------------------------------------------------------------------===*/
13
13
14
- #ifndef ORC_RT_C_WRAPPERFUNCTIONRESULT_H
15
- #define ORC_RT_C_WRAPPERFUNCTIONRESULT_H
14
+ #ifndef ORC_RT_C_WRAPPERFUNCTION_H
15
+ #define ORC_RT_C_WRAPPERFUNCTION_H
16
16
17
17
#include "orc-rt-c/ExternC.h"
18
18
@@ -25,154 +25,154 @@ ORC_RT_C_EXTERN_C_BEGIN
25
25
typedef union {
26
26
char * ValuePtr ;
27
27
char Value [sizeof (char * )];
28
- } orc_rt_WrapperFunctionResultDataUnion ;
28
+ } orc_rt_WrapperFunctionBufferDataUnion ;
29
29
30
30
/**
31
- * orc_rt_WrapperFunctionResult is a kind of C-SmallVector with an
31
+ * orc_rt_WrapperFunctionBuffer is a kind of C-SmallVector with an
32
32
* out-of-band error state.
33
33
*
34
34
* If Size == 0 and Data.ValuePtr is non-zero then the value is in the
35
35
* 'out-of-band error' state, and Data.ValuePtr points at a malloc-allocated,
36
36
* null-terminated string error message.
37
37
*
38
- * If Size <= sizeof(orc_rt_WrapperFunctionResultData ) then the value is in
38
+ * If Size <= sizeof(orc_rt_WrapperFunctionBufferData ) then the value is in
39
39
* the 'small' state and the content is held in the first Size bytes of
40
40
* Data.Value.
41
41
*
42
- * If Size > sizeof(orc_rt_WrapperFunctionResultData ) then the value is in the
42
+ * If Size > sizeof(orc_rt_WrapperFunctionBufferData ) then the value is in the
43
43
* 'large' state and the content is held in the first Size bytes of the
44
44
* memory pointed to by Data.ValuePtr. This memory must have been allocated by
45
45
* malloc, and will be freed with free when this value is destroyed.
46
46
*/
47
47
typedef struct {
48
- orc_rt_WrapperFunctionResultDataUnion Data ;
48
+ orc_rt_WrapperFunctionBufferDataUnion Data ;
49
49
size_t Size ;
50
- } orc_rt_WrapperFunctionResult ;
50
+ } orc_rt_WrapperFunctionBuffer ;
51
51
52
52
/**
53
- * Zero-initialize an orc_rt_WrapperFunctionResult .
53
+ * Zero-initialize an orc_rt_WrapperFunctionBuffer .
54
54
*/
55
55
static inline void
56
- orc_rt_WrapperFunctionResultInit ( orc_rt_WrapperFunctionResult * R ) {
57
- R -> Size = 0 ;
58
- R -> Data .ValuePtr = 0 ;
56
+ orc_rt_WrapperFunctionBufferInit ( orc_rt_WrapperFunctionBuffer * B ) {
57
+ B -> Size = 0 ;
58
+ B -> Data .ValuePtr = 0 ;
59
59
}
60
60
61
61
/**
62
- * Create an orc_rt_WrapperFunctionResult with an uninitialized buffer of
62
+ * Create an orc_rt_WrapperFunctionBuffer with an uninitialized buffer of
63
63
* size Size. The buffer is returned via the DataPtr argument.
64
64
*/
65
- static inline orc_rt_WrapperFunctionResult
66
- orc_rt_WrapperFunctionResultAllocate (size_t Size ) {
67
- orc_rt_WrapperFunctionResult R ;
68
- R .Size = Size ;
65
+ static inline orc_rt_WrapperFunctionBuffer
66
+ orc_rt_WrapperFunctionBufferAllocate (size_t Size ) {
67
+ orc_rt_WrapperFunctionBuffer B ;
68
+ B .Size = Size ;
69
69
// If Size is 0 ValuePtr must be 0 or it is considered an out-of-band error.
70
- R .Data .ValuePtr = 0 ;
71
- if (Size > sizeof (R .Data .Value ))
72
- R .Data .ValuePtr = (char * )malloc (Size );
73
- return R ;
70
+ B .Data .ValuePtr = 0 ;
71
+ if (Size > sizeof (B .Data .Value ))
72
+ B .Data .ValuePtr = (char * )malloc (Size );
73
+ return B ;
74
74
}
75
75
76
76
/**
77
- * Create an orc_rt_WrapperFunctionResult from the given data range.
77
+ * Create an orc_rt_WrapperFunctionBuffer from the given data range.
78
78
*/
79
- static inline orc_rt_WrapperFunctionResult
80
- orc_rt_CreateWrapperFunctionResultFromRange (const char * Data , size_t Size ) {
81
- orc_rt_WrapperFunctionResult R ;
82
- R .Size = Size ;
83
- if (R .Size > sizeof (R .Data .Value )) {
79
+ static inline orc_rt_WrapperFunctionBuffer
80
+ orc_rt_CreateWrapperFunctionBufferFromRange (const char * Data , size_t Size ) {
81
+ orc_rt_WrapperFunctionBuffer B ;
82
+ B .Size = Size ;
83
+ if (B .Size > sizeof (B .Data .Value )) {
84
84
char * Tmp = (char * )malloc (Size );
85
85
memcpy (Tmp , Data , Size );
86
- R .Data .ValuePtr = Tmp ;
86
+ B .Data .ValuePtr = Tmp ;
87
87
} else
88
- memcpy (R .Data .Value , Data , Size );
89
- return R ;
88
+ memcpy (B .Data .Value , Data , Size );
89
+ return B ;
90
90
}
91
91
92
92
/**
93
- * Create an orc_rt_WrapperFunctionResult by copying the given string,
93
+ * Create an orc_rt_WrapperFunctionBuffer by copying the given string,
94
94
* including the null-terminator.
95
95
*
96
96
* This function copies the input string. The client is responsible for freeing
97
97
* the ErrMsg arg.
98
98
*/
99
- static inline orc_rt_WrapperFunctionResult
100
- orc_rt_CreateWrapperFunctionResultFromString (const char * Source ) {
101
- return orc_rt_CreateWrapperFunctionResultFromRange (Source ,
99
+ static inline orc_rt_WrapperFunctionBuffer
100
+ orc_rt_CreateWrapperFunctionBufferFromString (const char * Source ) {
101
+ return orc_rt_CreateWrapperFunctionBufferFromRange (Source ,
102
102
strlen (Source ) + 1 );
103
103
}
104
104
105
105
/**
106
- * Create an orc_rt_WrapperFunctionResult representing an out-of-band
106
+ * Create an orc_rt_WrapperFunctionBuffer representing an out-of-band
107
107
* error.
108
108
*
109
109
* This function copies the input string. The client is responsible for freeing
110
110
* the ErrMsg arg.
111
111
*/
112
- static inline orc_rt_WrapperFunctionResult
113
- orc_rt_CreateWrapperFunctionResultFromOutOfBandError (const char * ErrMsg ) {
114
- orc_rt_WrapperFunctionResult R ;
115
- R .Size = 0 ;
112
+ static inline orc_rt_WrapperFunctionBuffer
113
+ orc_rt_CreateWrapperFunctionBufferFromOutOfBandError (const char * ErrMsg ) {
114
+ orc_rt_WrapperFunctionBuffer B ;
115
+ B .Size = 0 ;
116
116
char * Tmp = (char * )malloc (strlen (ErrMsg ) + 1 );
117
117
strcpy (Tmp , ErrMsg );
118
- R .Data .ValuePtr = Tmp ;
119
- return R ;
118
+ B .Data .ValuePtr = Tmp ;
119
+ return B ;
120
120
}
121
121
122
122
/**
123
- * This should be called to destroy orc_rt_WrapperFunctionResult values
123
+ * This should be called to destroy orc_rt_WrapperFunctionBuffer values
124
124
* regardless of their state.
125
125
*/
126
126
static inline void
127
- orc_rt_DisposeWrapperFunctionResult ( orc_rt_WrapperFunctionResult * R ) {
128
- if (R -> Size > sizeof (R -> Data .Value ) || (R -> Size == 0 && R -> Data .ValuePtr ))
129
- free (R -> Data .ValuePtr );
127
+ orc_rt_WrapperFunctionBufferDispose ( orc_rt_WrapperFunctionBuffer * B ) {
128
+ if (B -> Size > sizeof (B -> Data .Value ) || (B -> Size == 0 && B -> Data .ValuePtr ))
129
+ free (B -> Data .ValuePtr );
130
130
}
131
131
132
132
/**
133
133
* Get a pointer to the data contained in the given
134
- * orc_rt_WrapperFunctionResult .
134
+ * orc_rt_WrapperFunctionBuffer .
135
135
*/
136
136
static inline char *
137
- orc_rt_WrapperFunctionResultData ( orc_rt_WrapperFunctionResult * R ) {
138
- assert ((R -> Size != 0 || R -> Data .ValuePtr == NULL ) &&
137
+ orc_rt_WrapperFunctionBufferData ( orc_rt_WrapperFunctionBuffer * B ) {
138
+ assert ((B -> Size != 0 || B -> Data .ValuePtr == NULL ) &&
139
139
"Cannot get data for out-of-band error value" );
140
- return R -> Size > sizeof (R -> Data .Value ) ? R -> Data .ValuePtr : R -> Data .Value ;
140
+ return B -> Size > sizeof (B -> Data .Value ) ? B -> Data .ValuePtr : B -> Data .Value ;
141
141
}
142
142
143
143
/**
144
- * Safely get the size of the given orc_rt_WrapperFunctionResult .
144
+ * Safely get the size of the given orc_rt_WrapperFunctionBuffer .
145
145
*
146
146
* Asserts that we're not trying to access the size of an error value.
147
147
*/
148
148
static inline size_t
149
- orc_rt_WrapperFunctionResultSize (const orc_rt_WrapperFunctionResult * R ) {
150
- assert ((R -> Size != 0 || R -> Data .ValuePtr == NULL ) &&
149
+ orc_rt_WrapperFunctionBufferSize (const orc_rt_WrapperFunctionBuffer * B ) {
150
+ assert ((B -> Size != 0 || B -> Data .ValuePtr == NULL ) &&
151
151
"Cannot get size for out-of-band error value" );
152
- return R -> Size ;
152
+ return B -> Size ;
153
153
}
154
154
155
155
/**
156
156
* Returns 1 if this value is equivalent to a value just initialized by
157
- * orc_rt_WrapperFunctionResultInit , 0 otherwise.
157
+ * orc_rt_WrapperFunctionBufferInit , 0 otherwise.
158
158
*/
159
159
static inline size_t
160
- orc_rt_WrapperFunctionResultEmpty (const orc_rt_WrapperFunctionResult * R ) {
161
- return R -> Size == 0 && R -> Data .ValuePtr == 0 ;
160
+ orc_rt_WrapperFunctionBufferEmpty (const orc_rt_WrapperFunctionBuffer * B ) {
161
+ return B -> Size == 0 && B -> Data .ValuePtr == 0 ;
162
162
}
163
163
164
164
/**
165
165
* Returns a pointer to the out-of-band error string for this
166
- * orc_rt_WrapperFunctionResult , or null if there is no error.
166
+ * orc_rt_WrapperFunctionBuffer , or null if there is no error.
167
167
*
168
- * The orc_rt_WrapperFunctionResult retains ownership of the error
168
+ * The orc_rt_WrapperFunctionBuffer retains ownership of the error
169
169
* string, so it should be copied if the caller wishes to preserve it.
170
170
*/
171
- static inline const char * orc_rt_WrapperFunctionResultGetOutOfBandError (
172
- const orc_rt_WrapperFunctionResult * R ) {
173
- return R -> Size == 0 ? R -> Data .ValuePtr : 0 ;
171
+ static inline const char * orc_rt_WrapperFunctionBufferGetOutOfBandError (
172
+ const orc_rt_WrapperFunctionBuffer * B ) {
173
+ return B -> Size == 0 ? B -> Data .ValuePtr : 0 ;
174
174
}
175
175
176
176
ORC_RT_C_EXTERN_C_END
177
177
178
- #endif /* ORC_RT_WRAPPERFUNCTIONRESULT_H */
178
+ #endif /* ORC_RT_WRAPPERFUNCTION_H */
0 commit comments