[llvm] Revert "Revert "[llvm-mt] Use XmlDeleter to free xmlFreeDoc"" (PR #128579)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 24 13:30:29 PST 2025
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/128579
>From be07ac819f1ac6040f2b196c56d5b570cf5d5af2 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at gmail.com>
Date: Mon, 24 Feb 2025 13:07:48 -0800
Subject: [PATCH 1/2] Revert "Revert "[llvm-mt] Use XmlDeleter to free
xmlFreeDoc" (#128578)"
This reverts commit e063365a9732551b2d7b6c2b0d81e79d224a61e8.
---
.../WindowsManifest/WindowsManifestMerger.cpp | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp b/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
index a85dcd2ae2859..cdd63686d4711 100644
--- a/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
+++ b/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
@@ -32,7 +32,6 @@ void WindowsManifestError::log(raw_ostream &OS) const { OS << Msg; }
class WindowsManifestMerger::WindowsManifestMergerImpl {
public:
- ~WindowsManifestMergerImpl();
Error merge(MemoryBufferRef Manifest);
std::unique_ptr<MemoryBuffer> getMergedManifest();
@@ -45,7 +44,7 @@ class WindowsManifestMerger::WindowsManifestMergerImpl {
void operator()(xmlDoc *Ptr) { xmlFreeDoc(Ptr); }
};
xmlDocPtr CombinedDoc = nullptr;
- std::vector<xmlDocPtr> MergedDocs;
+ std::vector<std::unique_ptr<xmlDoc, XmlDeleter>> MergedDocs;
bool Merged = false;
int BufferSize = 0;
std::unique_ptr<xmlChar, XmlDeleter> Buffer;
@@ -611,11 +610,6 @@ static void checkAndStripPrefixes(xmlNodePtr Node,
}
}
-WindowsManifestMerger::WindowsManifestMergerImpl::~WindowsManifestMergerImpl() {
- for (auto &Doc : MergedDocs)
- xmlFreeDoc(Doc);
-}
-
Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
MemoryBufferRef Manifest) {
if (Merged)
@@ -626,17 +620,17 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
"attempted to merge empty manifest");
xmlSetGenericErrorFunc((void *)this,
WindowsManifestMergerImpl::errorCallback);
- xmlDocPtr ManifestXML = xmlReadMemory(
+ std::unique_ptr<xmlDoc, XmlDeleter> ManifestXML(xmlReadMemory(
Manifest.getBufferStart(), Manifest.getBufferSize(), "manifest.xml",
- nullptr, XML_PARSE_NOBLANKS | XML_PARSE_NODICT);
+ nullptr, XML_PARSE_NOBLANKS | XML_PARSE_NODICT));
xmlSetGenericErrorFunc(nullptr, nullptr);
if (auto E = getParseError())
return E;
- xmlNodePtr AdditionalRoot = xmlDocGetRootElement(ManifestXML);
+ xmlNodePtr AdditionalRoot = xmlDocGetRootElement(ManifestXML.get());
stripComments(AdditionalRoot);
setAttributeNamespaces(AdditionalRoot);
if (CombinedDoc == nullptr) {
- CombinedDoc = ManifestXML;
+ CombinedDoc = ManifestXML.get();
} else {
xmlNodePtr CombinedRoot = xmlDocGetRootElement(CombinedDoc);
if (!xmlStringsEqual(CombinedRoot->name, AdditionalRoot->name) ||
@@ -648,7 +642,7 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
return E;
}
}
- MergedDocs.push_back(ManifestXML);
+ MergedDocs.push_back(std::move(ManifestXML));
return Error::success();
}
>From d6ba1f8e6f2d47965b25dde662a6651096bcb665 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Mon, 24 Feb 2025 13:09:06 -0800
Subject: [PATCH 2/2] Remove ~WindowsManifestMergerImpl from
!LLVM_ENABLE_LIBXML2 branch
---
llvm/lib/WindowsManifest/WindowsManifestMerger.cpp | 3 ---
1 file changed, 3 deletions(-)
diff --git a/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp b/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
index cdd63686d4711..7017bde146c90 100644
--- a/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
+++ b/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
@@ -676,9 +676,6 @@ bool windows_manifest::isAvailable() { return true; }
#else
-WindowsManifestMerger::WindowsManifestMergerImpl::~WindowsManifestMergerImpl() {
-}
-
Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
MemoryBufferRef Manifest) {
return make_error<WindowsManifestError>("no libxml2");
More information about the llvm-commits
mailing list