mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 12:46:51 +00:00
[ORC-RT] Add non-const WrapperFunctionResult data access, simplify allocate.
WrapperFunctionResult no longer supports wrapping constant data, so this patch provides direct non-const access to the wrapped data. Since wrapped data can now be written, the WrapperFunctionResult::allocate method can be simplified to return a WrapperFunctionResult. This is essentially the same change (and with the same motivation) as LLVM commit 8b117830b1b, but applied to the ORC runtime's WrapperFunctionResult code.
This commit is contained in:
parent
280a0b735f
commit
8614cb9f99
@ -91,15 +91,13 @@ __orc_rt_CWrapperFunctionResultInit(__orc_rt_CWrapperFunctionResult *R) {
|
||||
* Create an __orc_rt_CWrapperFunctionResult with an uninitialized buffer of
|
||||
* size Size. The buffer is returned via the DataPtr argument.
|
||||
*/
|
||||
static inline char *
|
||||
__orc_rt_CWrapperFunctionResultAllocate(__orc_rt_CWrapperFunctionResult *R,
|
||||
size_t Size) {
|
||||
R->Size = Size;
|
||||
if (Size <= sizeof(R->Data.Value))
|
||||
return R->Data.Value;
|
||||
|
||||
R->Data.ValuePtr = (char *)malloc(Size);
|
||||
return R->Data.ValuePtr;
|
||||
static inline __orc_rt_CWrapperFunctionResult
|
||||
__orc_rt_CWrapperFunctionResultAllocate(size_t Size) {
|
||||
__orc_rt_CWrapperFunctionResult R;
|
||||
R.Size = Size;
|
||||
if (Size > sizeof(R.Data.Value))
|
||||
R.Data.ValuePtr = (char *)malloc(Size);
|
||||
return R;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,8 +161,8 @@ __orc_rt_DisposeCWrapperFunctionResult(__orc_rt_CWrapperFunctionResult *R) {
|
||||
* Get a pointer to the data contained in the given
|
||||
* __orc_rt_CWrapperFunctionResult.
|
||||
*/
|
||||
static inline const char *
|
||||
__orc_rt_CWrapperFunctionResultData(const __orc_rt_CWrapperFunctionResult *R) {
|
||||
static inline char *
|
||||
__orc_rt_CWrapperFunctionResultData(__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;
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
}
|
||||
|
||||
/// Get a pointer to the data contained in this instance.
|
||||
const char *data() const { return __orc_rt_CWrapperFunctionResultData(&R); }
|
||||
char *data() { return __orc_rt_CWrapperFunctionResultData(&R); }
|
||||
|
||||
/// Returns the size of the data contained in this instance.
|
||||
size_t size() const { return __orc_rt_CWrapperFunctionResultSize(&R); }
|
||||
@ -72,10 +72,10 @@ public:
|
||||
|
||||
/// Create a WrapperFunctionResult with the given size and return a pointer
|
||||
/// to the underlying memory.
|
||||
static char *allocate(WrapperFunctionResult &R, size_t Size) {
|
||||
__orc_rt_DisposeCWrapperFunctionResult(&R.R);
|
||||
__orc_rt_CWrapperFunctionResultInit(&R.R);
|
||||
return __orc_rt_CWrapperFunctionResultAllocate(&R.R, Size);
|
||||
static WrapperFunctionResult allocate(size_t Size) {
|
||||
WrapperFunctionResult R;
|
||||
R.R = __orc_rt_CWrapperFunctionResultAllocate(Size);
|
||||
return R;
|
||||
}
|
||||
|
||||
/// Copy from the given char range.
|
||||
@ -118,10 +118,8 @@ namespace detail {
|
||||
template <typename SPSArgListT, typename... ArgTs>
|
||||
Expected<WrapperFunctionResult>
|
||||
serializeViaSPSToWrapperFunctionResult(const ArgTs &...Args) {
|
||||
WrapperFunctionResult Result;
|
||||
char *DataPtr =
|
||||
WrapperFunctionResult::allocate(Result, SPSArgListT::size(Args...));
|
||||
SPSOutputBuffer OB(DataPtr, Result.size());
|
||||
auto Result = WrapperFunctionResult::allocate(SPSArgListT::size(Args...));
|
||||
SPSOutputBuffer OB(Result.data(), Result.size());
|
||||
if (!SPSArgListT::serialize(OB, Args...))
|
||||
return make_error<StringError>(
|
||||
"Error serializing arguments to blob in call");
|
||||
|
Loading…
x
Reference in New Issue
Block a user