[ORC-RT] Rename 'orc_rt_*CWrapper*' types and functions to 'orc_rt_*Wrapper*'.

The orc_rt_ prefix implies C API anyway (the C++ API should use the orc_rc::
namespace), so the 'C' is redundant here.
This commit is contained in:
Lang Hames 2025-03-07 14:28:07 +11:00
parent f984b472c4
commit 2c8b2dc3f4
10 changed files with 156 additions and 154 deletions

View File

@ -48,46 +48,46 @@ ORC_RT_C_EXTERN_C_BEGIN
typedef union {
char *ValuePtr;
char Value[sizeof(char *)];
} orc_rt_CWrapperFunctionResultDataUnion;
} orc_rt_WrapperFunctionResultDataUnion;
/**
* orc_rt_CWrapperFunctionResult is a kind of C-SmallVector with an
* orc_rt_WrapperFunctionResult 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(orc_rt_CWrapperFunctionResultData) then the value is in
* If Size <= sizeof(orc_rt_WrapperFunctionResultData) 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
* If Size > sizeof(orc_rt_WrapperFunctionResultData) then the value is in the
* 'large' state and the content is held in the first Size bytes of the
* memory pointed to by Data.ValuePtr. This memory must have been allocated by
* malloc, and will be freed with free when this value is destroyed.
*/
typedef struct {
orc_rt_CWrapperFunctionResultDataUnion Data;
orc_rt_WrapperFunctionResultDataUnion Data;
size_t Size;
} orc_rt_CWrapperFunctionResult;
} orc_rt_WrapperFunctionResult;
/**
* Zero-initialize an orc_rt_CWrapperFunctionResult.
* Zero-initialize an orc_rt_WrapperFunctionResult.
*/
static inline void
orc_rt_CWrapperFunctionResultInit(orc_rt_CWrapperFunctionResult *R) {
orc_rt_WrapperFunctionResultInit(orc_rt_WrapperFunctionResult *R) {
R->Size = 0;
R->Data.ValuePtr = 0;
}
/**
* Create an orc_rt_CWrapperFunctionResult with an uninitialized buffer of
* Create an orc_rt_WrapperFunctionResult with an uninitialized buffer of
* size Size. The buffer is returned via the DataPtr argument.
*/
static inline orc_rt_CWrapperFunctionResult
orc_rt_CWrapperFunctionResultAllocate(size_t Size) {
orc_rt_CWrapperFunctionResult R;
static inline orc_rt_WrapperFunctionResult
orc_rt_WrapperFunctionResultAllocate(size_t Size) {
orc_rt_WrapperFunctionResult R;
R.Size = Size;
// If Size is 0 ValuePtr must be 0 or it is considered an out-of-band error.
R.Data.ValuePtr = 0;
@ -99,9 +99,9 @@ orc_rt_CWrapperFunctionResultAllocate(size_t Size) {
/**
* Create an orc_rt_WrapperFunctionResult from the given data range.
*/
static inline orc_rt_CWrapperFunctionResult
orc_rt_CreateCWrapperFunctionResultFromRange(const char *Data, size_t Size) {
orc_rt_CWrapperFunctionResult R;
static inline orc_rt_WrapperFunctionResult
orc_rt_CreateWrapperFunctionResultFromRange(const char *Data, size_t Size) {
orc_rt_WrapperFunctionResult R;
R.Size = Size;
if (R.Size > sizeof(R.Data.Value)) {
char *Tmp = (char *)malloc(Size);
@ -113,28 +113,28 @@ orc_rt_CreateCWrapperFunctionResultFromRange(const char *Data, size_t Size) {
}
/**
* Create an orc_rt_CWrapperFunctionResult by copying the given string,
* Create an orc_rt_WrapperFunctionResult 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 orc_rt_CWrapperFunctionResult
orc_rt_CreateCWrapperFunctionResultFromString(const char *Source) {
return orc_rt_CreateCWrapperFunctionResultFromRange(Source,
strlen(Source) + 1);
static inline orc_rt_WrapperFunctionResult
orc_rt_CreateWrapperFunctionResultFromString(const char *Source) {
return orc_rt_CreateWrapperFunctionResultFromRange(Source,
strlen(Source) + 1);
}
/**
* Create an orc_rt_CWrapperFunctionResult representing an out-of-band
* Create an orc_rt_WrapperFunctionResult representing an out-of-band
* error.
*
* This function copies the input string. The client is responsible for freeing
* the ErrMsg arg.
*/
static inline orc_rt_CWrapperFunctionResult
orc_rt_CreateCWrapperFunctionResultFromOutOfBandError(const char *ErrMsg) {
orc_rt_CWrapperFunctionResult R;
static inline orc_rt_WrapperFunctionResult
orc_rt_CreateWrapperFunctionResultFromOutOfBandError(const char *ErrMsg) {
orc_rt_WrapperFunctionResult R;
R.Size = 0;
char *Tmp = (char *)malloc(strlen(ErrMsg) + 1);
strcpy(Tmp, ErrMsg);
@ -143,11 +143,11 @@ orc_rt_CreateCWrapperFunctionResultFromOutOfBandError(const char *ErrMsg) {
}
/**
* This should be called to destroy orc_rt_CWrapperFunctionResult values
* This should be called to destroy orc_rt_WrapperFunctionResult values
* regardless of their state.
*/
static inline void
orc_rt_DisposeCWrapperFunctionResult(orc_rt_CWrapperFunctionResult *R) {
orc_rt_DisposeWrapperFunctionResult(orc_rt_WrapperFunctionResult *R) {
if (R->Size > sizeof(R->Data.Value) ||
(R->Size == 0 && R->Data.ValuePtr))
free(R->Data.ValuePtr);
@ -155,22 +155,22 @@ orc_rt_DisposeCWrapperFunctionResult(orc_rt_CWrapperFunctionResult *R) {
/**
* Get a pointer to the data contained in the given
* orc_rt_CWrapperFunctionResult.
* orc_rt_WrapperFunctionResult.
*/
static inline char *
orc_rt_CWrapperFunctionResultData(orc_rt_CWrapperFunctionResult *R) {
orc_rt_WrapperFunctionResultData(orc_rt_WrapperFunctionResult *R) {
assert((R->Size != 0 || R->Data.ValuePtr == NULL) &&
"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 orc_rt_CWrapperFunctionResult.
* Safely get the size of the given orc_rt_WrapperFunctionResult.
*
* Asserts that we're not trying to access the size of an error value.
*/
static inline size_t
orc_rt_CWrapperFunctionResultSize(const orc_rt_CWrapperFunctionResult *R) {
orc_rt_WrapperFunctionResultSize(const orc_rt_WrapperFunctionResult *R) {
assert((R->Size != 0 || R->Data.ValuePtr == NULL) &&
"Cannot get size for out-of-band error value");
return R->Size;
@ -178,22 +178,22 @@ orc_rt_CWrapperFunctionResultSize(const orc_rt_CWrapperFunctionResult *R) {
/**
* Returns 1 if this value is equivalent to a value just initialized by
* orc_rt_CWrapperFunctionResultInit, 0 otherwise.
* orc_rt_WrapperFunctionResultInit, 0 otherwise.
*/
static inline size_t
orc_rt_CWrapperFunctionResultEmpty(const orc_rt_CWrapperFunctionResult *R) {
orc_rt_WrapperFunctionResultEmpty(const orc_rt_WrapperFunctionResult *R) {
return R->Size == 0 && R->Data.ValuePtr == 0;
}
/**
* Returns a pointer to the out-of-band error string for this
* orc_rt_CWrapperFunctionResult, or null if there is no error.
* orc_rt_WrapperFunctionResult, or null if there is no error.
*
* The orc_rt_CWrapperFunctionResult retains ownership of the error
* The orc_rt_WrapperFunctionResult retains ownership of the error
* string, so it should be copied if the caller wishes to preserve it.
*/
static inline const char *orc_rt_CWrapperFunctionResultGetOutOfBandError(
const orc_rt_CWrapperFunctionResult *R) {
static inline const char *orc_rt_WrapperFunctionResultGetOutOfBandError(
const orc_rt_WrapperFunctionResult *R) {
return R->Size == 0 ? R->Data.ValuePtr : 0;
}

View File

@ -594,19 +594,19 @@ void *COFFPlatformRuntimeState::findJITDylibBaseByPC(uint64_t PC) {
return Range.Header;
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_coff_platform_bootstrap(char *ArgData, size_t ArgSize) {
COFFPlatformRuntimeState::initialize();
return WrapperFunctionResult().release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_coff_platform_shutdown(char *ArgData, size_t ArgSize) {
COFFPlatformRuntimeState::destroy();
return WrapperFunctionResult().release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_coff_register_jitdylib(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSString, SPSExecutorAddr)>::handle(
ArgData, ArgSize,
@ -617,7 +617,7 @@ __orc_rt_coff_register_jitdylib(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_coff_deregister_jitdylib(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSExecutorAddr)>::handle(
ArgData, ArgSize,
@ -628,7 +628,7 @@ __orc_rt_coff_deregister_jitdylib(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_coff_register_object_sections(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSExecutorAddr, SPSCOFFObjectSectionsMap,
bool)>::
@ -643,7 +643,7 @@ __orc_rt_coff_register_object_sections(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_coff_deregister_object_sections(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSExecutorAddr, SPSCOFFObjectSectionsMap)>::
handle(ArgData, ArgSize,

View File

@ -41,7 +41,7 @@ ORC_RT_IMPORT __orc_rt_Opaque __orc_rt_jit_dispatch_ctx ORC_RT_WEAK_IMPORT;
/// 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.
ORC_RT_IMPORT orc_rt_CWrapperFunctionResult
ORC_RT_IMPORT orc_rt_WrapperFunctionResult
__orc_rt_jit_dispatch(__orc_rt_Opaque *DispatchCtx, const void *FnTag,
const char *Data, size_t Size) ORC_RT_WEAK_IMPORT;

View File

@ -23,7 +23,7 @@ extern "C" void *__orc_rt_jit_dlopen(const char *path, int mode);
extern "C" int __orc_rt_jit_dlupdate(void *dso_handle);
extern "C" int __orc_rt_jit_dlclose(void *dso_handle);
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_jit_dlerror_wrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSString()>::handle(
ArgData, ArgSize,
@ -31,7 +31,7 @@ __orc_rt_jit_dlerror_wrapper(const char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_jit_dlopen_wrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSExecutorAddr(SPSString, int32_t)>::handle(
ArgData, ArgSize,
@ -43,7 +43,7 @@ __orc_rt_jit_dlopen_wrapper(const char *ArgData, size_t ArgSize) {
}
#ifndef _WIN32
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_jit_dlupdate_wrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<int32_t(SPSExecutorAddr)>::handle(
ArgData, ArgSize,
@ -54,7 +54,7 @@ __orc_rt_jit_dlupdate_wrapper(const char *ArgData, size_t ArgSize) {
}
#endif
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_jit_dlclose_wrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<int32_t(SPSExecutorAddr)>::handle(
ArgData, ArgSize,

View File

@ -656,7 +656,7 @@ void destroyELFNixTLVMgr(void *ELFNixTLVMgr) {
// JIT entry points
//------------------------------------------------------------------------------
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_elfnix_platform_bootstrap(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSExecutorAddr)>::handle(
ArgData, ArgSize,
@ -668,7 +668,7 @@ __orc_rt_elfnix_platform_bootstrap(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_elfnix_platform_shutdown(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError()>::handle(
ArgData, ArgSize,
@ -679,7 +679,7 @@ __orc_rt_elfnix_platform_shutdown(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_elfnix_register_jitdylib(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSString, SPSExecutorAddr)>::handle(
ArgData, ArgSize,
@ -690,7 +690,7 @@ __orc_rt_elfnix_register_jitdylib(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_elfnix_deregister_jitdylib(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSExecutorAddr)>::handle(
ArgData, ArgSize,
@ -701,7 +701,7 @@ __orc_rt_elfnix_deregister_jitdylib(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_elfnix_register_init_sections(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSExecutorAddr,
SPSSequence<SPSExecutorAddrRange>)>::
@ -714,7 +714,7 @@ __orc_rt_elfnix_register_init_sections(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_elfnix_deregister_init_sections(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSExecutorAddr,
SPSSequence<SPSExecutorAddrRange>)>::
@ -728,7 +728,7 @@ __orc_rt_elfnix_deregister_init_sections(char *ArgData, size_t ArgSize) {
}
/// Wrapper function for registering metadata on a per-object basis.
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_elfnix_register_object_sections(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSELFNixPerObjectSectionsToRegister)>::
handle(ArgData, ArgSize,
@ -740,7 +740,7 @@ __orc_rt_elfnix_register_object_sections(char *ArgData, size_t ArgSize) {
}
/// Wrapper for releasing per-object metadat.
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_elfnix_deregister_object_sections(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSELFNixPerObjectSectionsToRegister)>::
handle(ArgData, ArgSize,
@ -776,7 +776,7 @@ ORC_RT_INTERFACE ptrdiff_t ___orc_rt_elfnix_tlsdesc_resolver_impl(
return TLVPtr - ThreadPointer;
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_elfnix_create_pthread_key(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSExpected<uint64_t>(void)>::handle(
ArgData, ArgSize,

View File

@ -1349,7 +1349,7 @@ Error runWrapperFunctionCalls(std::vector<WrapperFunctionCall> WFCs) {
// JIT entry points
//------------------------------------------------------------------------------
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_macho_platform_bootstrap(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError()>::handle(
ArgData, ArgSize,
@ -1357,7 +1357,7 @@ __orc_rt_macho_platform_bootstrap(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_macho_platform_shutdown(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError()>::handle(
ArgData, ArgSize,
@ -1365,7 +1365,7 @@ __orc_rt_macho_platform_shutdown(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_macho_register_jitdylib(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSString, SPSExecutorAddr)>::handle(
ArgData, ArgSize,
@ -1376,7 +1376,7 @@ __orc_rt_macho_register_jitdylib(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_macho_deregister_jitdylib(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSExecutorAddr)>::handle(
ArgData, ArgSize,
@ -1387,7 +1387,7 @@ __orc_rt_macho_deregister_jitdylib(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_macho_register_object_platform_sections(char *ArgData,
size_t ArgSize) {
return WrapperFunction<SPSError(SPSExecutorAddr,
@ -1404,7 +1404,7 @@ __orc_rt_macho_register_object_platform_sections(char *ArgData,
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_macho_register_object_symbol_table(char *ArgData, size_t ArgSize) {
using SymtabContainer = std::vector<
std::tuple<ExecutorAddr, ExecutorAddr,
@ -1420,7 +1420,7 @@ __orc_rt_macho_register_object_symbol_table(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_macho_deregister_object_symbol_table(char *ArgData, size_t ArgSize) {
using SymtabContainer = std::vector<
std::tuple<ExecutorAddr, ExecutorAddr,
@ -1436,7 +1436,7 @@ __orc_rt_macho_deregister_object_symbol_table(char *ArgData, size_t ArgSize) {
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_macho_deregister_object_platform_sections(char *ArgData,
size_t ArgSize) {
return WrapperFunction<SPSError(SPSExecutorAddr,
@ -1453,7 +1453,7 @@ __orc_rt_macho_deregister_object_platform_sections(char *ArgData,
.release();
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_macho_run_wrapper_function_calls(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSError(SPSSequence<SPSWrapperFunctionCall>)>::handle(
ArgData, ArgSize, runWrapperFunctionCalls)
@ -1479,7 +1479,7 @@ ORC_RT_INTERFACE void *__orc_rt_macho_tlv_get_addr_impl(TLVDescriptor *D) {
reinterpret_cast<char *>(static_cast<uintptr_t>(D->DataAddress)));
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_macho_create_pthread_key(char *ArgData, size_t ArgSize) {
return WrapperFunction<SPSExpected<uint64_t>(void)>::handle(
ArgData, ArgSize,

View File

@ -22,7 +22,7 @@ extern "C" int64_t __orc_rt_run_program(const char *JITDylibName,
const char *EntrySymbolName, int argc,
char *argv[]);
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
ORC_RT_INTERFACE orc_rt_WrapperFunctionResult
__orc_rt_run_program_wrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<int64_t(SPSString, SPSString,
SPSSequence<SPSString>)>::

View File

@ -13,25 +13,25 @@
#include "orc_rt/c_api.h"
#include "gtest/gtest.h"
TEST(CAPITest, CWrapperFunctionResultInit) {
orc_rt_CWrapperFunctionResult R;
orc_rt_CWrapperFunctionResultInit(&R);
TEST(CAPITest, WrapperFunctionResultInit) {
orc_rt_WrapperFunctionResult R;
orc_rt_WrapperFunctionResultInit(&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(orc_rt_CWrapperFunctionResultGetOutOfBandError(&R), nullptr);
EXPECT_EQ(orc_rt_WrapperFunctionResultGetOutOfBandError(&R), nullptr);
// Check that we can dispose of the value.
orc_rt_DisposeCWrapperFunctionResult(&R);
orc_rt_DisposeWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultAllocSmall) {
TEST(CAPITest, WrapperFunctionResultAllocSmall) {
constexpr size_t SmallAllocSize = sizeof(const char *);
auto R = orc_rt_CWrapperFunctionResultAllocate(SmallAllocSize);
char *DataPtr = orc_rt_CWrapperFunctionResultData(&R);
auto R = orc_rt_WrapperFunctionResultAllocate(SmallAllocSize);
char *DataPtr = orc_rt_WrapperFunctionResultData(&R);
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(orc_rt_CWrapperFunctionResultGetOutOfBandError(&R), nullptr);
EXPECT_EQ(orc_rt_WrapperFunctionResultGetOutOfBandError(&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 orc_rt_WrapperFunctionResult(Data|Result|Size) and
// orc_rt_WrapperFunctionResultGetOutOfBandError behave as expected.
EXPECT_EQ(orc_rt_WrapperFunctionResultData(&R), R.Data.Value);
EXPECT_EQ(orc_rt_WrapperFunctionResultSize(&R), SmallAllocSize);
EXPECT_FALSE(orc_rt_WrapperFunctionResultEmpty(&R));
EXPECT_EQ(orc_rt_WrapperFunctionResultGetOutOfBandError(&R), nullptr);
// Check that we can dispose of the value.
orc_rt_DisposeCWrapperFunctionResult(&R);
orc_rt_DisposeWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultAllocLarge) {
TEST(CAPITest, WrapperFunctionResultAllocLarge) {
constexpr size_t LargeAllocSize = sizeof(const char *) + 1;
auto R = orc_rt_CWrapperFunctionResultAllocate(LargeAllocSize);
char *DataPtr = orc_rt_CWrapperFunctionResultData(&R);
auto R = orc_rt_WrapperFunctionResultAllocate(LargeAllocSize);
char *DataPtr = orc_rt_WrapperFunctionResultData(&R);
for (size_t I = 0; I != LargeAllocSize; ++I)
DataPtr[I] = 0x55 + I;
@ -75,28 +75,28 @@ TEST(CAPITest, CWrapperFunctionResultAllocLarge) {
<< "Unexpected value at index " << I;
// Check that this value isn't treated as an out-of-band error.
EXPECT_EQ(orc_rt_CWrapperFunctionResultGetOutOfBandError(&R), nullptr);
EXPECT_EQ(orc_rt_WrapperFunctionResultGetOutOfBandError(&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 orc_rt_WrapperFunctionResult(Data|Result|Size) and
// orc_rt_WrapperFunctionResultGetOutOfBandError behave as expected.
EXPECT_EQ(orc_rt_WrapperFunctionResultData(&R), R.Data.ValuePtr);
EXPECT_EQ(orc_rt_WrapperFunctionResultSize(&R), LargeAllocSize);
EXPECT_FALSE(orc_rt_WrapperFunctionResultEmpty(&R));
EXPECT_EQ(orc_rt_WrapperFunctionResultGetOutOfBandError(&R), nullptr);
// Check that we can dispose of the value.
orc_rt_DisposeCWrapperFunctionResult(&R);
orc_rt_DisposeWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultFromRangeSmall) {
TEST(CAPITest, WrapperFunctionResultFromRangeSmall) {
constexpr size_t SmallAllocSize = sizeof(const char *);
char Source[SmallAllocSize];
for (size_t I = 0; I != SmallAllocSize; ++I)
Source[I] = 0x55 + I;
orc_rt_CWrapperFunctionResult R =
orc_rt_CreateCWrapperFunctionResultFromRange(Source, SmallAllocSize);
orc_rt_WrapperFunctionResult R =
orc_rt_CreateWrapperFunctionResultFromRange(Source, SmallAllocSize);
// Check that the inline storage in R.Data.Value contains the expected
// sequence.
@ -106,18 +106,18 @@ TEST(CAPITest, CWrapperFunctionResultFromRangeSmall) {
<< "Unexpected value at index " << I;
// Check that we can dispose of the value.
orc_rt_DisposeCWrapperFunctionResult(&R);
orc_rt_DisposeWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultFromRangeLarge) {
TEST(CAPITest, WrapperFunctionResultFromRangeLarge) {
constexpr size_t LargeAllocSize = sizeof(const char *) + 1;
char Source[LargeAllocSize];
for (size_t I = 0; I != LargeAllocSize; ++I)
Source[I] = 0x55 + I;
orc_rt_CWrapperFunctionResult R =
orc_rt_CreateCWrapperFunctionResultFromRange(Source, LargeAllocSize);
orc_rt_WrapperFunctionResult R =
orc_rt_CreateWrapperFunctionResultFromRange(Source, LargeAllocSize);
// Check that the inline storage in R.Data.Value contains the expected
// sequence.
@ -127,10 +127,10 @@ TEST(CAPITest, CWrapperFunctionResultFromRangeLarge) {
<< "Unexpected value at index " << I;
// Check that we can dispose of the value.
orc_rt_DisposeCWrapperFunctionResult(&R);
orc_rt_DisposeWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultFromStringSmall) {
TEST(CAPITest, WrapperFunctionResultFromStringSmall) {
constexpr size_t SmallAllocSize = sizeof(const char *);
char Source[SmallAllocSize];
@ -138,8 +138,8 @@ TEST(CAPITest, CWrapperFunctionResultFromStringSmall) {
Source[I] = 'a' + I;
Source[SmallAllocSize - 1] = '\0';
orc_rt_CWrapperFunctionResult R =
orc_rt_CreateCWrapperFunctionResultFromString(Source);
orc_rt_WrapperFunctionResult R =
orc_rt_CreateWrapperFunctionResultFromString(Source);
// Check that the inline storage in R.Data.Value contains the expected
// sequence.
@ -151,10 +151,10 @@ TEST(CAPITest, CWrapperFunctionResultFromStringSmall) {
<< "Unexpected value at index " << (SmallAllocSize - 1);
// Check that we can dispose of the value.
orc_rt_DisposeCWrapperFunctionResult(&R);
orc_rt_DisposeWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultFromStringLarge) {
TEST(CAPITest, WrapperFunctionResultFromStringLarge) {
constexpr size_t LargeAllocSize = sizeof(const char *) + 1;
char Source[LargeAllocSize];
@ -162,8 +162,8 @@ TEST(CAPITest, CWrapperFunctionResultFromStringLarge) {
Source[I] = 'a' + I;
Source[LargeAllocSize - 1] = '\0';
orc_rt_CWrapperFunctionResult R =
orc_rt_CreateCWrapperFunctionResultFromString(Source);
orc_rt_WrapperFunctionResult R =
orc_rt_CreateWrapperFunctionResultFromString(Source);
// Check that the inline storage in R.Data.Value contains the expected
// sequence.
@ -175,26 +175,28 @@ TEST(CAPITest, CWrapperFunctionResultFromStringLarge) {
<< "Unexpected value at index " << (LargeAllocSize - 1);
// Check that we can dispose of the value.
orc_rt_DisposeCWrapperFunctionResult(&R);
orc_rt_DisposeWrapperFunctionResult(&R);
}
TEST(CAPITest, CWrapperFunctionResultFromOutOfBandError) {
TEST(CAPITest, WrapperFunctionResultFromOutOfBandError) {
constexpr const char *ErrMsg = "test error message";
orc_rt_CWrapperFunctionResult R =
orc_rt_CreateCWrapperFunctionResultFromOutOfBandError(ErrMsg);
orc_rt_WrapperFunctionResult R =
orc_rt_CreateWrapperFunctionResultFromOutOfBandError(ErrMsg);
#ifndef NDEBUG
EXPECT_DEATH({ orc_rt_CWrapperFunctionResultData(&R); },
"Cannot get data for out-of-band error value");
EXPECT_DEATH({ orc_rt_CWrapperFunctionResultSize(&R); },
"Cannot get size for out-of-band error value");
EXPECT_DEATH(
{ orc_rt_WrapperFunctionResultData(&R); },
"Cannot get data for out-of-band error value");
EXPECT_DEATH(
{ orc_rt_WrapperFunctionResultSize(&R); },
"Cannot get size for out-of-band error value");
#endif
EXPECT_FALSE(orc_rt_CWrapperFunctionResultEmpty(&R));
const char *OOBErrMsg = orc_rt_CWrapperFunctionResultGetOutOfBandError(&R);
EXPECT_FALSE(orc_rt_WrapperFunctionResultEmpty(&R));
const char *OOBErrMsg = orc_rt_WrapperFunctionResultGetOutOfBandError(&R);
EXPECT_NE(OOBErrMsg, nullptr);
EXPECT_NE(OOBErrMsg, ErrMsg);
EXPECT_TRUE(strcmp(OOBErrMsg, ErrMsg) == 0);
orc_rt_DisposeCWrapperFunctionResult(&R);
orc_rt_DisposeWrapperFunctionResult(&R);
}

View File

@ -29,8 +29,8 @@ TEST(WrapperFunctionUtilsTest, DefaultWrapperFunctionResult) {
}
TEST(WrapperFunctionUtilsTest, WrapperFunctionResultFromCStruct) {
orc_rt_CWrapperFunctionResult CR =
orc_rt_CreateCWrapperFunctionResultFromString(TestString);
orc_rt_WrapperFunctionResult CR =
orc_rt_CreateWrapperFunctionResultFromString(TestString);
WrapperFunctionResult R(CR);
EXPECT_EQ(R.size(), strlen(TestString) + 1);
EXPECT_TRUE(strcmp(R.data(), TestString) == 0);
@ -74,13 +74,13 @@ TEST(WrapperFunctionUtilsTest, WrapperFunctionCCallCreateEmpty) {
static void voidNoop() {}
static orc_rt_CWrapperFunctionResult voidNoopWrapper(const char *ArgData,
size_t ArgSize) {
static orc_rt_WrapperFunctionResult voidNoopWrapper(const char *ArgData,
size_t ArgSize) {
return WrapperFunction<void()>::handle(ArgData, ArgSize, voidNoop).release();
}
static orc_rt_CWrapperFunctionResult addWrapper(const char *ArgData,
size_t ArgSize) {
static orc_rt_WrapperFunctionResult addWrapper(const char *ArgData,
size_t ArgSize) {
return WrapperFunction<int32_t(int32_t, int32_t)>::handle(
ArgData, ArgSize,
[](int32_t X, int32_t Y) -> int32_t { return X + Y; })
@ -89,11 +89,11 @@ static orc_rt_CWrapperFunctionResult addWrapper(const char *ArgData,
extern "C" __orc_rt_Opaque __orc_rt_jit_dispatch_ctx{};
extern "C" orc_rt_CWrapperFunctionResult
extern "C" orc_rt_WrapperFunctionResult
__orc_rt_jit_dispatch(__orc_rt_Opaque *Ctx, const void *FnTag,
const char *ArgData, size_t ArgSize) {
using WrapperFunctionType =
orc_rt_CWrapperFunctionResult (*)(const char *, size_t);
orc_rt_WrapperFunctionResult (*)(const char *, size_t);
return reinterpret_cast<WrapperFunctionType>(const_cast<void *>(FnTag))(
ArgData, ArgSize);
@ -120,8 +120,8 @@ private:
int32_t X;
};
static orc_rt_CWrapperFunctionResult addMethodWrapper(const char *ArgData,
size_t ArgSize) {
static orc_rt_WrapperFunctionResult addMethodWrapper(const char *ArgData,
size_t ArgSize) {
return WrapperFunction<int32_t(SPSExecutorAddr, int32_t)>::handle(
ArgData, ArgSize, makeMethodWrapperHandler(&AddClass::addMethod))
.release();
@ -136,8 +136,8 @@ TEST(WrapperFunctionUtilsTest, WrapperFunctionMethodCallAndHandleRet) {
EXPECT_EQ(Result, (int32_t)3);
}
static orc_rt_CWrapperFunctionResult sumArrayWrapper(const char *ArgData,
size_t ArgSize) {
static orc_rt_WrapperFunctionResult sumArrayWrapper(const char *ArgData,
size_t ArgSize) {
return WrapperFunction<int8_t(SPSExecutorAddrRange)>::handle(
ArgData, ArgSize,
[](ExecutorAddrRange R) {

View File

@ -21,71 +21,71 @@
namespace orc_rt {
/// C++ wrapper function result: Same as CWrapperFunctionResult but
/// C++ wrapper function result: Same as orc_rt_WrapperFunctionResult but
/// auto-releases memory.
class WrapperFunctionResult {
public:
/// Create a default WrapperFunctionResult.
WrapperFunctionResult() { orc_rt_CWrapperFunctionResultInit(&R); }
WrapperFunctionResult() { orc_rt_WrapperFunctionResultInit(&R); }
/// Create a WrapperFunctionResult from a CWrapperFunctionResult. This
/// Create a WrapperFunctionResult from a WrapperFunctionResult. This
/// instance takes ownership of the result object and will automatically
/// call dispose on the result upon destruction.
WrapperFunctionResult(orc_rt_CWrapperFunctionResult R) : R(R) {}
WrapperFunctionResult(orc_rt_WrapperFunctionResult R) : R(R) {}
WrapperFunctionResult(const WrapperFunctionResult &) = delete;
WrapperFunctionResult &operator=(const WrapperFunctionResult &) = delete;
WrapperFunctionResult(WrapperFunctionResult &&Other) {
orc_rt_CWrapperFunctionResultInit(&R);
orc_rt_WrapperFunctionResultInit(&R);
std::swap(R, Other.R);
}
WrapperFunctionResult &operator=(WrapperFunctionResult &&Other) {
orc_rt_CWrapperFunctionResult Tmp;
orc_rt_CWrapperFunctionResultInit(&Tmp);
orc_rt_WrapperFunctionResult Tmp;
orc_rt_WrapperFunctionResultInit(&Tmp);
std::swap(Tmp, Other.R);
std::swap(R, Tmp);
return *this;
}
~WrapperFunctionResult() { orc_rt_DisposeCWrapperFunctionResult(&R); }
~WrapperFunctionResult() { orc_rt_DisposeWrapperFunctionResult(&R); }
/// Relinquish ownership of and return the
/// orc_rt_CWrapperFunctionResult.
orc_rt_CWrapperFunctionResult release() {
orc_rt_CWrapperFunctionResult Tmp;
orc_rt_CWrapperFunctionResultInit(&Tmp);
/// orc_rt_WrapperFunctionResult.
orc_rt_WrapperFunctionResult release() {
orc_rt_WrapperFunctionResult Tmp;
orc_rt_WrapperFunctionResultInit(&Tmp);
std::swap(R, Tmp);
return Tmp;
}
/// Get a pointer to the data contained in this instance.
char *data() { return orc_rt_CWrapperFunctionResultData(&R); }
char *data() { return orc_rt_WrapperFunctionResultData(&R); }
/// Returns the size of the data contained in this instance.
size_t size() const { return orc_rt_CWrapperFunctionResultSize(&R); }
size_t size() const { return orc_rt_WrapperFunctionResultSize(&R); }
/// Returns true if this value is equivalent to a default-constructed
/// WrapperFunctionResult.
bool empty() const { return orc_rt_CWrapperFunctionResultEmpty(&R); }
bool empty() const { return orc_rt_WrapperFunctionResultEmpty(&R); }
/// Create a WrapperFunctionResult with the given size and return a pointer
/// to the underlying memory.
static WrapperFunctionResult allocate(size_t Size) {
WrapperFunctionResult R;
R.R = orc_rt_CWrapperFunctionResultAllocate(Size);
R.R = orc_rt_WrapperFunctionResultAllocate(Size);
return R;
}
/// Copy from the given char range.
static WrapperFunctionResult copyFrom(const char *Source, size_t Size) {
return orc_rt_CreateCWrapperFunctionResultFromRange(Source, Size);
return orc_rt_CreateWrapperFunctionResultFromRange(Source, Size);
}
/// Copy from the given null-terminated string (includes the null-terminator).
static WrapperFunctionResult copyFrom(const char *Source) {
return orc_rt_CreateCWrapperFunctionResultFromString(Source);
return orc_rt_CreateWrapperFunctionResultFromString(Source);
}
/// Copy from the given std::string (includes the null terminator).
@ -95,7 +95,7 @@ public:
/// Create an out-of-band error by copying the given string.
static WrapperFunctionResult createOutOfBandError(const char *Msg) {
return orc_rt_CreateCWrapperFunctionResultFromOutOfBandError(Msg);
return orc_rt_CreateWrapperFunctionResultFromOutOfBandError(Msg);
}
/// Create an out-of-band error by copying the given string.
@ -116,11 +116,11 @@ public:
/// If this value is an out-of-band error then this returns the error message,
/// otherwise returns nullptr.
const char *getOutOfBandError() const {
return orc_rt_CWrapperFunctionResultGetOutOfBandError(&R);
return orc_rt_WrapperFunctionResultGetOutOfBandError(&R);
}
private:
orc_rt_CWrapperFunctionResult R;
orc_rt_WrapperFunctionResult R;
};
namespace detail {
@ -430,7 +430,7 @@ public:
/// Run call returning raw WrapperFunctionResult.
WrapperFunctionResult run() const {
using FnTy =
orc_rt_CWrapperFunctionResult(const char *ArgData, size_t ArgSize);
orc_rt_WrapperFunctionResult(const char *ArgData, size_t ArgSize);
return WrapperFunctionResult(
FnAddr.toPtr<FnTy *>()(ArgData.data(), ArgData.size()));
}