mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[RemoteMirrors] Support passing NULL for the FreeBytesFunction.
This commit is contained in:
@@ -79,10 +79,13 @@ public:
|
|||||||
void *FreeContext;
|
void *FreeContext;
|
||||||
auto Ptr = Impl.readBytes(Impl.reader_context, address.getAddressData(), size,
|
auto Ptr = Impl.readBytes(Impl.reader_context, address.getAddressData(), size,
|
||||||
&FreeContext);
|
&FreeContext);
|
||||||
auto ReaderContext = Impl.reader_context;
|
|
||||||
auto Free = Impl.free;
|
auto Free = Impl.free;
|
||||||
auto freeLambda = [=]{ Free(ReaderContext, Ptr, FreeContext); };
|
if (Free == nullptr)
|
||||||
|
return std::make_tuple(Ptr, []{});
|
||||||
|
|
||||||
|
auto ReaderContext = Impl.reader_context;
|
||||||
|
auto freeLambda = [=]{ Free(ReaderContext, Ptr, FreeContext); };
|
||||||
return std::make_tuple(Ptr, freeLambda);
|
return std::make_tuple(Ptr, freeLambda);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ typedef struct MemoryReaderImpl {
|
|||||||
/// Get the size in bytes of the target's size type.
|
/// Get the size in bytes of the target's size type.
|
||||||
SizeSizeFunction getSizeSize;
|
SizeSizeFunction getSizeSize;
|
||||||
|
|
||||||
/// Free memory returned from readBytes.
|
/// Free memory returned from readBytes. May be NULL if memory never needs to be freed.
|
||||||
FreeBytesFunction free;
|
FreeBytesFunction free;
|
||||||
|
|
||||||
// FIXME: -Wdocumentation complains about \param and \returns on function pointers.
|
// FIXME: -Wdocumentation complains about \param and \returns on function pointers.
|
||||||
|
|||||||
@@ -260,7 +260,8 @@ static int swift_reflection_interop_readBytesAdapter(void *reader_context,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
memcpy(dest, ptr, size);
|
memcpy(dest, ptr, size);
|
||||||
Context->FreeBytes(Context->ReaderContext, ptr, FreeContext);
|
if (Context->FreeBytes != NULL)
|
||||||
|
Context->FreeBytes(Context->ReaderContext, ptr, FreeContext);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,12 +374,14 @@ swift_reflection_interop_addImageLegacy(
|
|||||||
MachHeader *Header = (MachHeader *)Buf;
|
MachHeader *Header = (MachHeader *)Buf;
|
||||||
|
|
||||||
if (Header->magic != MH_MAGIC && Header->magic != MH_MAGIC_64) {
|
if (Header->magic != MH_MAGIC && Header->magic != MH_MAGIC_64) {
|
||||||
ContextRef->FreeBytes(ContextRef->ReaderContext, Buf, FreeContext);
|
if (ContextRef->FreeBytes != NULL)
|
||||||
|
ContextRef->FreeBytes(ContextRef->ReaderContext, Buf, FreeContext);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Length = Header->sizeofcmds;
|
uint32_t Length = Header->sizeofcmds;
|
||||||
ContextRef->FreeBytes(ContextRef->ReaderContext, Buf, FreeContext);
|
if (ContextRef->FreeBytes != NULL)
|
||||||
|
ContextRef->FreeBytes(ContextRef->ReaderContext, Buf, FreeContext);
|
||||||
|
|
||||||
Buf = ContextRef->ReadBytes(ContextRef->ReaderContext,
|
Buf = ContextRef->ReadBytes(ContextRef->ReaderContext,
|
||||||
imageStart,
|
imageStart,
|
||||||
|
|||||||
Reference in New Issue
Block a user