1- /*===----- WrapperFunctionResult .h - blob-of-bytes container -----*- C -*-===*\
1+ /*===--------- WrapperFunction .h - Wrapper function utils ---- -----*- C -*-===*\
22|* *|
33|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
44|* Exceptions. *|
77|* *|
88|*===----------------------------------------------------------------------===*|
99|* *|
10- |* Defines orc_rt_WrapperFunctionResult and related APIs. *|
10+ |* Defines orc_rt_WrapperFunctionBuffer and related APIs. *|
1111|* *|
1212\*===----------------------------------------------------------------------===*/
1313
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
1616
1717#include "orc-rt-c/ExternC.h"
1818
@@ -25,154 +25,154 @@ ORC_RT_C_EXTERN_C_BEGIN
2525typedef union {
2626 char * ValuePtr ;
2727 char Value [sizeof (char * )];
28- } orc_rt_WrapperFunctionResultDataUnion ;
28+ } orc_rt_WrapperFunctionBufferDataUnion ;
2929
3030/**
31- * orc_rt_WrapperFunctionResult is a kind of C-SmallVector with an
31+ * orc_rt_WrapperFunctionBuffer is a kind of C-SmallVector with an
3232 * out-of-band error state.
3333 *
3434 * If Size == 0 and Data.ValuePtr is non-zero then the value is in the
3535 * 'out-of-band error' state, and Data.ValuePtr points at a malloc-allocated,
3636 * null-terminated string error message.
3737 *
38- * If Size <= sizeof(orc_rt_WrapperFunctionResultData ) then the value is in
38+ * If Size <= sizeof(orc_rt_WrapperFunctionBufferData ) then the value is in
3939 * the 'small' state and the content is held in the first Size bytes of
4040 * Data.Value.
4141 *
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
4343 * 'large' state and the content is held in the first Size bytes of the
4444 * memory pointed to by Data.ValuePtr. This memory must have been allocated by
4545 * malloc, and will be freed with free when this value is destroyed.
4646 */
4747typedef struct {
48- orc_rt_WrapperFunctionResultDataUnion Data ;
48+ orc_rt_WrapperFunctionBufferDataUnion Data ;
4949 size_t Size ;
50- } orc_rt_WrapperFunctionResult ;
50+ } orc_rt_WrapperFunctionBuffer ;
5151
5252/**
53- * Zero-initialize an orc_rt_WrapperFunctionResult .
53+ * Zero-initialize an orc_rt_WrapperFunctionBuffer .
5454 */
5555static 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 ;
5959}
6060
6161/**
62- * Create an orc_rt_WrapperFunctionResult with an uninitialized buffer of
62+ * Create an orc_rt_WrapperFunctionBuffer with an uninitialized buffer of
6363 * size Size. The buffer is returned via the DataPtr argument.
6464 */
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 ;
6969 // 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 ;
7474}
7575
7676/**
77- * Create an orc_rt_WrapperFunctionResult from the given data range.
77+ * Create an orc_rt_WrapperFunctionBuffer from the given data range.
7878 */
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 )) {
8484 char * Tmp = (char * )malloc (Size );
8585 memcpy (Tmp , Data , Size );
86- R .Data .ValuePtr = Tmp ;
86+ B .Data .ValuePtr = Tmp ;
8787 } else
88- memcpy (R .Data .Value , Data , Size );
89- return R ;
88+ memcpy (B .Data .Value , Data , Size );
89+ return B ;
9090}
9191
9292/**
93- * Create an orc_rt_WrapperFunctionResult by copying the given string,
93+ * Create an orc_rt_WrapperFunctionBuffer by copying the given string,
9494 * including the null-terminator.
9595 *
9696 * This function copies the input string. The client is responsible for freeing
9797 * the ErrMsg arg.
9898 */
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 ,
102102 strlen (Source ) + 1 );
103103}
104104
105105/**
106- * Create an orc_rt_WrapperFunctionResult representing an out-of-band
106+ * Create an orc_rt_WrapperFunctionBuffer representing an out-of-band
107107 * error.
108108 *
109109 * This function copies the input string. The client is responsible for freeing
110110 * the ErrMsg arg.
111111 */
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 ;
116116 char * Tmp = (char * )malloc (strlen (ErrMsg ) + 1 );
117117 strcpy (Tmp , ErrMsg );
118- R .Data .ValuePtr = Tmp ;
119- return R ;
118+ B .Data .ValuePtr = Tmp ;
119+ return B ;
120120}
121121
122122/**
123- * This should be called to destroy orc_rt_WrapperFunctionResult values
123+ * This should be called to destroy orc_rt_WrapperFunctionBuffer values
124124 * regardless of their state.
125125 */
126126static 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 );
130130}
131131
132132/**
133133 * Get a pointer to the data contained in the given
134- * orc_rt_WrapperFunctionResult .
134+ * orc_rt_WrapperFunctionBuffer .
135135 */
136136static 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 ) &&
139139 "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 ;
141141}
142142
143143/**
144- * Safely get the size of the given orc_rt_WrapperFunctionResult .
144+ * Safely get the size of the given orc_rt_WrapperFunctionBuffer .
145145 *
146146 * Asserts that we're not trying to access the size of an error value.
147147 */
148148static 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 ) &&
151151 "Cannot get size for out-of-band error value" );
152- return R -> Size ;
152+ return B -> Size ;
153153}
154154
155155/**
156156 * 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.
158158 */
159159static 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 ;
162162}
163163
164164/**
165165 * 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.
167167 *
168- * The orc_rt_WrapperFunctionResult retains ownership of the error
168+ * The orc_rt_WrapperFunctionBuffer retains ownership of the error
169169 * string, so it should be copied if the caller wishes to preserve it.
170170 */
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 ;
174174}
175175
176176ORC_RT_C_EXTERN_C_END
177177
178- #endif /* ORC_RT_WRAPPERFUNCTIONRESULT_H */
178+ #endif /* ORC_RT_WRAPPERFUNCTION_H */
0 commit comments