[ORC-RT] Rename C-API functions to use __orc_rt_ prefix (instead of OrcRT).

This matches the C++ namespace name, and is consistent with other C linkage
functions (e.g. __orc_rt_jit_dispatch).
This commit is contained in:
Lang Hames 2021-05-31 15:37:00 -07:00
parent d791f0c219
commit 28c3e9c0d1
3 changed files with 86 additions and 84 deletions

View File

@ -50,18 +50,19 @@ ORC_RT_C_EXTERN_C_BEGIN
typedef union {
const char *ValuePtr;
char Value[sizeof(ValuePtr)];
} OrcRTCWrapperFunctionResultDataUnion;
} __orc_rt_CWrapperFunctionResultDataUnion;
/**
* OrcRTCWrapperFunctionResult is a kind of C-SmallVector with an out-of-band
* error state.
* __orc_rt_CWrapperFunctionResult is a kind of C-SmallVector with an
* out-of-band error state.
*
* If Size == 0 and Data.ValuePtr is non-zero then the value is in the
* 'out-of-band error' state, and Data.ValuePtr points at a malloc-allocated,
* null-terminated string error message.
*
* If Size <= sizeof(OrcRTCWrapperFunctionResultData) then the value is in the
* 'small' state and the content is held in the first Size bytes of Data.Value.
* If Size <= sizeof(__orc_rt_CWrapperFunctionResultData) then the value is in
* the 'small' state and the content is held in the first Size bytes of
* Data.Value.
*
* If Size > sizeof(OrtRTCWrapperFunctionResultData) then the value is in the
* 'large' state and the content is held in the first Size bytes of the
@ -69,29 +70,29 @@ typedef union {
* malloc, and will be freed with free when this value is destroyed.
*/
typedef struct {
OrcRTCWrapperFunctionResultDataUnion Data;
__orc_rt_CWrapperFunctionResultDataUnion Data;
size_t Size;
} OrcRTCWrapperFunctionResult;
} __orc_rt_CWrapperFunctionResult;
typedef struct OrcRTCSharedOpaqueJITProcessControl
*OrcRTSharedJITProcessControlRef;
typedef struct __orc_rt_CSharedOpaqueJITProcessControl
*__orc_rt_SharedJITProcessControlRef;
/**
* Zero-initialize an OrcRTCWrapperFunctionResult.
* Zero-initialize an __orc_rt_CWrapperFunctionResult.
*/
static inline void
OrcRTCWrapperFunctionResultInit(OrcRTCWrapperFunctionResult *R) {
__orc_rt_CWrapperFunctionResultInit(__orc_rt_CWrapperFunctionResult *R) {
R->Size = 0;
R->Data.ValuePtr = 0;
}
/**
* Create an OrcRTCWrapperFunctionResult with an uninitialized buffer of size
* Size. The buffer is returned via the DataPtr argument.
* Create an __orc_rt_CWrapperFunctionResult with an uninitialized buffer of
* size Size. The buffer is returned via the DataPtr argument.
*/
static inline char *
OrcRTCWrapperFunctionResultAllocate(OrcRTCWrapperFunctionResult *R,
size_t Size) {
__orc_rt_CWrapperFunctionResultAllocate(__orc_rt_CWrapperFunctionResult *R,
size_t Size) {
char *DataPtr;
R->Size = Size;
if (Size > sizeof(R->Data.Value)) {
@ -103,11 +104,11 @@ OrcRTCWrapperFunctionResultAllocate(OrcRTCWrapperFunctionResult *R,
}
/**
* Create an OrcRTWrapperFunctionResult from the given data range.
* Create an __orc_rt_WrapperFunctionResult from the given data range.
*/
static inline OrcRTCWrapperFunctionResult
OrcRTCreateCWrapperFunctionResultFromRange(const char *Data, size_t Size) {
OrcRTCWrapperFunctionResult R;
static inline __orc_rt_CWrapperFunctionResult
__orc_rt_CreateCWrapperFunctionResultFromRange(const char *Data, size_t Size) {
__orc_rt_CWrapperFunctionResult R;
R.Size = Size;
if (R.Size > sizeof(R.Data.Value)) {
char *Tmp = (char *)malloc(Size);
@ -119,27 +120,28 @@ OrcRTCreateCWrapperFunctionResultFromRange(const char *Data, size_t Size) {
}
/**
* Create an OrcRTCWrapperFunctionResult by copying the given string, including
* the null-terminator.
* Create an __orc_rt_CWrapperFunctionResult by copying the given string,
* including the null-terminator.
*
* This function copies the input string. The client is responsible for freeing
* the ErrMsg arg.
*/
static inline OrcRTCWrapperFunctionResult
OrcRTCreateCWrapperFunctionResultFromString(const char *Source) {
return OrcRTCreateCWrapperFunctionResultFromRange(Source, strlen(Source) + 1);
static inline __orc_rt_CWrapperFunctionResult
__orc_rt_CreateCWrapperFunctionResultFromString(const char *Source) {
return __orc_rt_CreateCWrapperFunctionResultFromRange(Source,
strlen(Source) + 1);
}
/**
* Create an OrcRTCWrapperFunctionResult representing an out-of-band
* Create an __orc_rt_CWrapperFunctionResult representing an out-of-band
* error.
*
* This function takes ownership of the string argument which must have been
* allocated with malloc.
*/
static inline OrcRTCWrapperFunctionResult
OrcRTCreateCWrapperFunctionResultFromOutOfBandError(const char *ErrMsg) {
OrcRTCWrapperFunctionResult R;
static inline __orc_rt_CWrapperFunctionResult
__orc_rt_CreateCWrapperFunctionResultFromOutOfBandError(const char *ErrMsg) {
__orc_rt_CWrapperFunctionResult R;
R.Size = 0;
char *Tmp = (char *)malloc(strlen(ErrMsg) + 1);
strcpy(Tmp, ErrMsg);
@ -148,11 +150,11 @@ OrcRTCreateCWrapperFunctionResultFromOutOfBandError(const char *ErrMsg) {
}
/**
* This should be called to destroy OrcRTCWrapperFunctionResult values
* This should be called to destroy __orc_rt_CWrapperFunctionResult values
* regardless of their state.
*/
static inline void
OrcRTDisposeCWrapperFunctionResult(OrcRTCWrapperFunctionResult *R) {
__orc_rt_DisposeCWrapperFunctionResult(__orc_rt_CWrapperFunctionResult *R) {
if (R->Size > sizeof(R->Data.Value) ||
(R->Size == 0 && R->Data.ValuePtr))
free((void *)R->Data.ValuePtr);
@ -160,22 +162,22 @@ OrcRTDisposeCWrapperFunctionResult(OrcRTCWrapperFunctionResult *R) {
/**
* Get a pointer to the data contained in the given
* OrcRTCWrapperFunctionResult.
* __orc_rt_CWrapperFunctionResult.
*/
static inline const char *
OrcRTCWrapperFunctionResultData(const OrcRTCWrapperFunctionResult *R) {
__orc_rt_CWrapperFunctionResultData(const __orc_rt_CWrapperFunctionResult *R) {
assert((R->Size != 0 || R->Data.ValuePtr == nullptr) &&
"Cannot get data for out-of-band error value");
return R->Size > sizeof(R->Data.Value) ? R->Data.ValuePtr : R->Data.Value;
}
/**
* Safely get the size of the given OrcRTCWrapperFunctionResult.
* Safely get the size of the given __orc_rt_CWrapperFunctionResult.
*
* Asserts that we're not trying to access the size of an error value.
*/
static inline size_t
OrcRTCWrapperFunctionResultSize(const OrcRTCWrapperFunctionResult *R) {
__orc_rt_CWrapperFunctionResultSize(const __orc_rt_CWrapperFunctionResult *R) {
assert((R->Size != 0 || R->Data.ValuePtr == nullptr) &&
"Cannot get size for out-of-band error value");
return R->Size;
@ -183,22 +185,22 @@ OrcRTCWrapperFunctionResultSize(const OrcRTCWrapperFunctionResult *R) {
/**
* Returns 1 if this value is equivalent to a value just initialized by
* OrcRTCWrapperFunctionResultInit, 0 otherwise.
* __orc_rt_CWrapperFunctionResultInit, 0 otherwise.
*/
static inline size_t
OrcRTCWrapperFunctionResultEmpty(const OrcRTCWrapperFunctionResult *R) {
__orc_rt_CWrapperFunctionResultEmpty(const __orc_rt_CWrapperFunctionResult *R) {
return R->Size == 0 && R->Data.ValuePtr == 0;
}
/**
* Returns a pointer to the out-of-band error string for this
* OrcRTCWrapperFunctionResult, or null if there is no error.
* __orc_rt_CWrapperFunctionResult, or null if there is no error.
*
* The OrcRTCWrapperFunctionResult retains ownership of the error
* The __orc_rt_CWrapperFunctionResult retains ownership of the error
* string, so it should be copied if the caller wishes to preserve it.
*/
static inline const char *OrcRTCWrapperFunctionResultGetOutOfBandError(
const OrcRTCWrapperFunctionResult *R) {
static inline const char *__orc_rt_CWrapperFunctionResultGetOutOfBandError(
const __orc_rt_CWrapperFunctionResult *R) {
return R->Size == 0 ? R->Data.ValuePtr : 0;
}

View File

@ -34,7 +34,7 @@ extern "C" __orc_rt_Opaque __orc_rt_jit_dispatch_ctx
/// This is declared for use by the runtime, but should be implemented in the
/// executor or provided by a definition added to the JIT before the runtime
/// is loaded.
extern "C" OrcRTCWrapperFunctionResult
extern "C" __orc_rt_CWrapperFunctionResult
__orc_rt_jit_dispatch(__orc_rt_Opaque *DispatchCtx, const void *FnTag,
const char *Data, size_t Size)
__attribute__((weak_import));

View File

@ -14,24 +14,24 @@
#include "gtest/gtest.h"
TEST(CAPITest, CWrapperFunctionResultInit) {
OrcRTCWrapperFunctionResult R;
OrcRTCWrapperFunctionResultInit(&R);
__orc_rt_CWrapperFunctionResult R;
__orc_rt_CWrapperFunctionResultInit(&R);
EXPECT_EQ(R.Size, 0U);
EXPECT_EQ(R.Data.ValuePtr, nullptr);
// Check that this value isn't treated as an out-of-band error.
EXPECT_EQ(OrcRTCWrapperFunctionResultGetOutOfBandError(&R), nullptr);
EXPECT_EQ(__orc_rt_CWrapperFunctionResultGetOutOfBandError(&R), nullptr);
// Check that we can dispose of the value.
OrcRTDisposeCWrapperFunctionResult(&R);
__orc_rt_DisposeCWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultAllocSmall) {
constexpr size_t SmallAllocSize = sizeof(const char *);
OrcRTCWrapperFunctionResult R;
char *DataPtr = OrcRTCWrapperFunctionResultAllocate(&R, SmallAllocSize);
__orc_rt_CWrapperFunctionResult R;
char *DataPtr = __orc_rt_CWrapperFunctionResultAllocate(&R, SmallAllocSize);
for (size_t I = 0; I != SmallAllocSize; ++I)
DataPtr[I] = 0x55 + I;
@ -44,24 +44,24 @@ TEST(CAPITest, CWrapperFunctionResultAllocSmall) {
<< "Unexpected value at index " << I;
// Check that this value isn't treated as an out-of-band error.
EXPECT_EQ(OrcRTCWrapperFunctionResultGetOutOfBandError(&R), nullptr);
EXPECT_EQ(__orc_rt_CWrapperFunctionResultGetOutOfBandError(&R), nullptr);
// Check that OrcRTCWrapperFunctionResult(Data|Result|Size) and
// OrcRTCWrapperFunctionResultGetOutOfBandError behave as expected.
EXPECT_EQ(OrcRTCWrapperFunctionResultData(&R), R.Data.Value);
EXPECT_EQ(OrcRTCWrapperFunctionResultSize(&R), SmallAllocSize);
EXPECT_FALSE(OrcRTCWrapperFunctionResultEmpty(&R));
EXPECT_EQ(OrcRTCWrapperFunctionResultGetOutOfBandError(&R), nullptr);
// Check that __orc_rt_CWrapperFunctionResult(Data|Result|Size) and
// __orc_rt_CWrapperFunctionResultGetOutOfBandError behave as expected.
EXPECT_EQ(__orc_rt_CWrapperFunctionResultData(&R), R.Data.Value);
EXPECT_EQ(__orc_rt_CWrapperFunctionResultSize(&R), SmallAllocSize);
EXPECT_FALSE(__orc_rt_CWrapperFunctionResultEmpty(&R));
EXPECT_EQ(__orc_rt_CWrapperFunctionResultGetOutOfBandError(&R), nullptr);
// Check that we can dispose of the value.
OrcRTDisposeCWrapperFunctionResult(&R);
__orc_rt_DisposeCWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultAllocLarge) {
constexpr size_t LargeAllocSize = sizeof(const char *) + 1;
OrcRTCWrapperFunctionResult R;
char *DataPtr = OrcRTCWrapperFunctionResultAllocate(&R, LargeAllocSize);
__orc_rt_CWrapperFunctionResult R;
char *DataPtr = __orc_rt_CWrapperFunctionResultAllocate(&R, LargeAllocSize);
for (size_t I = 0; I != LargeAllocSize; ++I)
DataPtr[I] = 0x55 + I;
@ -75,17 +75,17 @@ TEST(CAPITest, CWrapperFunctionResultAllocLarge) {
<< "Unexpected value at index " << I;
// Check that this value isn't treated as an out-of-band error.
EXPECT_EQ(OrcRTCWrapperFunctionResultGetOutOfBandError(&R), nullptr);
EXPECT_EQ(__orc_rt_CWrapperFunctionResultGetOutOfBandError(&R), nullptr);
// Check that OrcRTCWrapperFunctionResult(Data|Result|Size) and
// OrcRTCWrapperFunctionResultGetOutOfBandError behave as expected.
EXPECT_EQ(OrcRTCWrapperFunctionResultData(&R), R.Data.ValuePtr);
EXPECT_EQ(OrcRTCWrapperFunctionResultSize(&R), LargeAllocSize);
EXPECT_FALSE(OrcRTCWrapperFunctionResultEmpty(&R));
EXPECT_EQ(OrcRTCWrapperFunctionResultGetOutOfBandError(&R), nullptr);
// Check that __orc_rt_CWrapperFunctionResult(Data|Result|Size) and
// __orc_rt_CWrapperFunctionResultGetOutOfBandError behave as expected.
EXPECT_EQ(__orc_rt_CWrapperFunctionResultData(&R), R.Data.ValuePtr);
EXPECT_EQ(__orc_rt_CWrapperFunctionResultSize(&R), LargeAllocSize);
EXPECT_FALSE(__orc_rt_CWrapperFunctionResultEmpty(&R));
EXPECT_EQ(__orc_rt_CWrapperFunctionResultGetOutOfBandError(&R), nullptr);
// Check that we can dispose of the value.
OrcRTDisposeCWrapperFunctionResult(&R);
__orc_rt_DisposeCWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultFromRangeSmall) {
@ -95,8 +95,8 @@ TEST(CAPITest, CWrapperFunctionResultFromRangeSmall) {
for (size_t I = 0; I != SmallAllocSize; ++I)
Source[I] = 0x55 + I;
OrcRTCWrapperFunctionResult R =
OrcRTCreateCWrapperFunctionResultFromRange(Source, SmallAllocSize);
__orc_rt_CWrapperFunctionResult R =
__orc_rt_CreateCWrapperFunctionResultFromRange(Source, SmallAllocSize);
// Check that the inline storage in R.Data.Value contains the expected
// sequence.
@ -106,7 +106,7 @@ TEST(CAPITest, CWrapperFunctionResultFromRangeSmall) {
<< "Unexpected value at index " << I;
// Check that we can dispose of the value.
OrcRTDisposeCWrapperFunctionResult(&R);
__orc_rt_DisposeCWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultFromRangeLarge) {
@ -116,8 +116,8 @@ TEST(CAPITest, CWrapperFunctionResultFromRangeLarge) {
for (size_t I = 0; I != LargeAllocSize; ++I)
Source[I] = 0x55 + I;
OrcRTCWrapperFunctionResult R =
OrcRTCreateCWrapperFunctionResultFromRange(Source, LargeAllocSize);
__orc_rt_CWrapperFunctionResult R =
__orc_rt_CreateCWrapperFunctionResultFromRange(Source, LargeAllocSize);
// Check that the inline storage in R.Data.Value contains the expected
// sequence.
@ -127,7 +127,7 @@ TEST(CAPITest, CWrapperFunctionResultFromRangeLarge) {
<< "Unexpected value at index " << I;
// Check that we can dispose of the value.
OrcRTDisposeCWrapperFunctionResult(&R);
__orc_rt_DisposeCWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultFromStringSmall) {
@ -138,8 +138,8 @@ TEST(CAPITest, CWrapperFunctionResultFromStringSmall) {
Source[I] = 'a' + I;
Source[SmallAllocSize - 1] = '\0';
OrcRTCWrapperFunctionResult R =
OrcRTCreateCWrapperFunctionResultFromString(Source);
__orc_rt_CWrapperFunctionResult R =
__orc_rt_CreateCWrapperFunctionResultFromString(Source);
// Check that the inline storage in R.Data.Value contains the expected
// sequence.
@ -151,7 +151,7 @@ TEST(CAPITest, CWrapperFunctionResultFromStringSmall) {
<< "Unexpected value at index " << (SmallAllocSize - 1);
// Check that we can dispose of the value.
OrcRTDisposeCWrapperFunctionResult(&R);
__orc_rt_DisposeCWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultFromStringLarge) {
@ -162,8 +162,8 @@ TEST(CAPITest, CWrapperFunctionResultFromStringLarge) {
Source[I] = 'a' + I;
Source[LargeAllocSize - 1] = '\0';
OrcRTCWrapperFunctionResult R =
OrcRTCreateCWrapperFunctionResultFromString(Source);
__orc_rt_CWrapperFunctionResult R =
__orc_rt_CreateCWrapperFunctionResultFromString(Source);
// Check that the inline storage in R.Data.Value contains the expected
// sequence.
@ -175,26 +175,26 @@ TEST(CAPITest, CWrapperFunctionResultFromStringLarge) {
<< "Unexpected value at index " << (LargeAllocSize - 1);
// Check that we can dispose of the value.
OrcRTDisposeCWrapperFunctionResult(&R);
__orc_rt_DisposeCWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultFromOutOfBandError) {
constexpr const char *ErrMsg = "test error message";
OrcRTCWrapperFunctionResult R =
OrcRTCreateCWrapperFunctionResultFromOutOfBandError(ErrMsg);
__orc_rt_CWrapperFunctionResult R =
__orc_rt_CreateCWrapperFunctionResultFromOutOfBandError(ErrMsg);
#ifndef NDEBUG
EXPECT_DEATH({ OrcRTCWrapperFunctionResultData(&R); },
EXPECT_DEATH({ __orc_rt_CWrapperFunctionResultData(&R); },
"Cannot get data for out-of-band error value");
EXPECT_DEATH({ OrcRTCWrapperFunctionResultSize(&R); },
EXPECT_DEATH({ __orc_rt_CWrapperFunctionResultSize(&R); },
"Cannot get size for out-of-band error value");
#endif
EXPECT_FALSE(OrcRTCWrapperFunctionResultEmpty(&R));
const char *OOBErrMsg = OrcRTCWrapperFunctionResultGetOutOfBandError(&R);
EXPECT_FALSE(__orc_rt_CWrapperFunctionResultEmpty(&R));
const char *OOBErrMsg = __orc_rt_CWrapperFunctionResultGetOutOfBandError(&R);
EXPECT_NE(OOBErrMsg, nullptr);
EXPECT_NE(OOBErrMsg, ErrMsg);
EXPECT_TRUE(strcmp(OOBErrMsg, ErrMsg) == 0);
OrcRTDisposeCWrapperFunctionResult(&R);
__orc_rt_DisposeCWrapperFunctionResult(&R);
}