Skip to content

Commit

Permalink
Fix lifetime issue for Entry objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Oct 13, 2019
1 parent d2b8ae1 commit 79f6a43
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
35 changes: 26 additions & 9 deletions src/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,32 @@ void Entry::copyToSubEntry(const std::unique_ptr<Entry> &current)
m_sublist.push_back(std::move(copy));
}

void Entry::moveFromSubEntry(const Entry *child,std::unique_ptr<Entry> &moveTo)
{
auto it = std::find_if(m_sublist.begin(),m_sublist.end(),
[child](const std::unique_ptr<Entry>&elem) { return elem.get()==child; });
if (it!=m_sublist.end())
{
moveTo = std::move(*it);
m_sublist.erase(it);
}
else
{
moveTo.reset();
}
}

void Entry::removeSubEntry(const Entry *e)
{
auto it = std::find_if(m_sublist.begin(),m_sublist.end(),
[e](const std::unique_ptr<Entry>&elem) { return elem.get()==e; });
if (it!=m_sublist.end())
{
m_sublist.erase(it);
}
}


void Entry::reset()
{
static bool entryCallGraph = Config_getBool(CALL_GRAPH);
Expand Down Expand Up @@ -335,14 +361,5 @@ void Entry::addSpecialListItem(const char *listName,int itemId)
sli->append(ili);
}

void Entry::removeSubEntry(Entry *e)
{
auto it = std::find_if(m_sublist.begin(),m_sublist.end(),
[e](const std::unique_ptr<Entry>&elem) { return elem.get()==e; });
if (it!=m_sublist.end())
{
m_sublist.erase(it);
}
}

//------------------------------------------------------------------
5 changes: 4 additions & 1 deletion src/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,17 @@ class Entry
void moveToSubEntryAndRefresh(Entry* &e);
void moveToSubEntryAndRefresh(std::unique_ptr<Entry> &e);

/*! take \a child of of to list of children and move it into \a moveTo */
void moveFromSubEntry(const Entry *child,std::unique_ptr<Entry> &moveTo);

/*! make a copy of \a e and add it as a child to this entry */
void copyToSubEntry (Entry* e);
void copyToSubEntry (const std::unique_ptr<Entry> &e);

/*! Removes entry \a e from the list of children.
* The entry will be deleted if found.
*/
void removeSubEntry(Entry *e);
void removeSubEntry(const Entry *e);

/*! Restore the state of this Entry to the default value it has
* at construction time.
Expand Down
4 changes: 2 additions & 2 deletions src/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -5305,9 +5305,9 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
else
{
current->endBodyLine=yyLineNr;

// take previous out of current_root and move it into current
current.swap(tempEntry); // remember current
current.reset(previous); // and temporarily switch to the previous entry
current_root->moveFromSubEntry(previous,current);
previous = 0;

docBlockContext = SkipCurlyEndDoc;
Expand Down

0 comments on commit 79f6a43

Please sign in to comment.