From a95511600fd0d23997c6291c6df63343b0a9b59b Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 23 Dec 2015 03:45:44 +0200 Subject: [PATCH] Fixed the destruction of comments another way because this one crashes the OS X build. See https://github.com/mono/CppSharp/issues/599. Signed-off-by: Dimitar Dobrev --- src/CppParser/AST.cpp | 55 +++++++++++++++++++++++++++++++++++++++---- src/CppParser/AST.h | 1 - 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/CppParser/AST.cpp b/src/CppParser/AST.cpp index c4b1b2f589..1a2a7c1791 100644 --- a/src/CppParser/AST.cpp +++ b/src/CppParser/AST.cpp @@ -809,8 +809,6 @@ TranslationUnit* ASTContext::FindOrCreateModule(std::string File) // Comments Comment::Comment(CommentKind kind) : Kind(kind) {} -Comment::~Comment() {} - DEF_STRING(RawComment, Text) DEF_STRING(RawComment, BriefText) @@ -827,7 +825,33 @@ FullComment::FullComment() : Comment(CommentKind::FullComment) {} FullComment::~FullComment() { for (auto& block : Blocks) - delete block; + { + // HACK: see https://github.com/mono/CppSharp/issues/599 + switch (block->Kind) + { + case CommentKind::BlockCommandComment: + delete static_cast(block); + break; + case CommentKind::ParamCommandComment: + delete static_cast(block); + break; + case CommentKind::TParamCommandComment: + delete static_cast(block); + break; + case CommentKind::VerbatimBlockComment: + delete static_cast(block); + break; + case CommentKind::VerbatimLineComment: + delete static_cast(block); + break; + case CommentKind::ParagraphComment: + delete static_cast(block); + break; + default: + delete block; + break; + } + } } DEF_VECTOR(FullComment, BlockContentComment*, Blocks) @@ -871,7 +895,30 @@ ParagraphComment::ParagraphComment() : BlockContentComment(CommentKind::Paragrap ParagraphComment::~ParagraphComment() { for (auto& content : Content) - delete content; + { + // HACK: see https://github.com/mono/CppSharp/issues/599 + switch (content->Kind) + { + case CommentKind::InlineCommandComment: + delete static_cast(content); + break; + case CommentKind::HTMLTagComment: + delete static_cast(content); + break; + case CommentKind::HTMLStartTagComment: + delete static_cast(content); + break; + case CommentKind::HTMLEndTagComment: + delete static_cast(content); + break; + case CommentKind::TextComment: + delete static_cast(content); + break; + default: + delete content; + break; + } + } } DEF_VECTOR(ParagraphComment, InlineContentComment*, Content) diff --git a/src/CppParser/AST.h b/src/CppParser/AST.h index b6dccd088a..5a87e0d7af 100644 --- a/src/CppParser/AST.h +++ b/src/CppParser/AST.h @@ -932,7 +932,6 @@ class CS_API CS_ABSTRACT Comment { public: Comment(CommentKind kind); - virtual ~Comment(); CommentKind Kind; };