[ORC] Add non-const WrapperFunctionResult::data method, simplify allocate.

WrapperFunctionResult no longer supports wrapping constant data, so this patch
adds a non-const data method. Since data can now be written through the data
method, the allocate method can be simplified to return a WrapperFunctionResult.
This commit is contained in:
Lang Hames
2021-08-24 15:13:54 +10:00
parent 07e85823aa
commit 8b117830b1
3 changed files with 20 additions and 23 deletions

View File

@@ -89,6 +89,13 @@ public:
} }
/// Get a pointer to the data contained in this instance. /// Get a pointer to the data contained in this instance.
char *data() {
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;
}
/// Get a const pointer to the data contained in this instance.
const char *data() const { const char *data() const {
assert((R.Size != 0 || R.Data.ValuePtr == nullptr) && assert((R.Size != 0 || R.Data.ValuePtr == nullptr) &&
"Cannot get data for out-of-band error value"); "Cannot get data for out-of-band error value");
@@ -108,24 +115,19 @@ public:
/// Create a WrapperFunctionResult with the given size and return a pointer /// Create a WrapperFunctionResult with the given size and return a pointer
/// to the underlying memory. /// to the underlying memory.
static char *allocate(WrapperFunctionResult &WFR, size_t Size) { static WrapperFunctionResult allocate(size_t Size) {
// Reset. // Reset.
WFR = WrapperFunctionResult(); WrapperFunctionResult WFR;
WFR.R.Size = Size; WFR.R.Size = Size;
char *DataPtr; if (WFR.R.Size > sizeof(WFR.R.Data.Value))
if (WFR.R.Size > sizeof(WFR.R.Data.Value)) { WFR.R.Data.ValuePtr = (char *)malloc(WFR.R.Size);
DataPtr = (char *)malloc(WFR.R.Size); return WFR;
WFR.R.Data.ValuePtr = DataPtr;
} else
DataPtr = WFR.R.Data.Value;
return DataPtr;
} }
/// Copy from the given char range. /// Copy from the given char range.
static WrapperFunctionResult copyFrom(const char *Source, size_t Size) { static WrapperFunctionResult copyFrom(const char *Source, size_t Size) {
WrapperFunctionResult WFR; auto WFR = allocate(Size);
char *DataPtr = allocate(WFR, Size); memcpy(WFR.data(), Source, Size);
memcpy(DataPtr, Source, Size);
return WFR; return WFR;
} }
@@ -174,10 +176,8 @@ namespace detail {
template <typename SPSArgListT, typename... ArgTs> template <typename SPSArgListT, typename... ArgTs>
WrapperFunctionResult WrapperFunctionResult
serializeViaSPSToWrapperFunctionResult(const ArgTs &...Args) { serializeViaSPSToWrapperFunctionResult(const ArgTs &...Args) {
WrapperFunctionResult Result; auto Result = WrapperFunctionResult::allocate(SPSArgListT::size(Args...));
char *DataPtr = SPSOutputBuffer OB(Result.data(), Result.size());
WrapperFunctionResult::allocate(Result, SPSArgListT::size(Args...));
SPSOutputBuffer OB(DataPtr, Result.size());
if (!SPSArgListT::serialize(OB, Args...)) if (!SPSArgListT::serialize(OB, Args...))
return WrapperFunctionResult::createOutOfBandError( return WrapperFunctionResult::createOutOfBandError(
"Error serializing arguments to blob in call"); "Error serializing arguments to blob in call");

View File

@@ -125,10 +125,9 @@ public:
if (auto Err = deserializeSeq(C, Size)) if (auto Err = deserializeSeq(C, Size))
return Err; return Err;
WrapperFunctionResult Tmp; auto Tmp = WrapperFunctionResult::allocate(Size);
char *Data = WrapperFunctionResult::allocate(Tmp, Size);
if (auto Err = C.readBytes(Data, Size)) if (auto Err = C.readBytes(Tmp.data(), Tmp.size()))
return Err; return Err;
E = std::move(Tmp); E = std::move(Tmp);

View File

@@ -97,10 +97,8 @@ TEST(ExecutionSessionWrapperFunctionCalls, RegisterAsyncHandlerAndRun) {
using ArgSerialization = SPSArgList<int32_t, int32_t>; using ArgSerialization = SPSArgList<int32_t, int32_t>;
size_t ArgBufferSize = ArgSerialization::size(1, 2); size_t ArgBufferSize = ArgSerialization::size(1, 2);
WrapperFunctionResult ArgBuffer; auto ArgBuffer = WrapperFunctionResult::allocate(ArgBufferSize);
char *ArgBufferData = SPSOutputBuffer OB(ArgBuffer.data(), ArgBuffer.size());
WrapperFunctionResult::allocate(ArgBuffer, ArgBufferSize);
SPSOutputBuffer OB(ArgBufferData, ArgBufferSize);
EXPECT_TRUE(ArgSerialization::serialize(OB, 1, 2)); EXPECT_TRUE(ArgSerialization::serialize(OB, 1, 2));
ES.runJITDispatchHandler( ES.runJITDispatchHandler(