Fix alignment of Transaction allocation:

new of a char array might not have the correct alignment to hold a Transaction.
Allocate a Transaction itself directly, instead of in-place constructing it in
the character array.

Each Transaction in the pool is thus constructed through `new Transaction(S)`
and destructed through `delete T`, which is nicely symmetrical. The use of
`::operator new` and `::operator delete` isn't actually necessary.

While I'm at it, improve the assert message's wording.
This commit is contained in:
Axel Naumann 2021-03-30 16:58:29 +02:00 committed by jenkins
parent 0a3384a342
commit db8d306106

View File

@ -48,10 +48,9 @@ namespace cling {
Transaction* takeTransaction(clang::Sema& S) {
Transaction *T;
if (kDebugMode || m_Transactions.empty()) {
T = (Transaction*) ::operator new(sizeof(Transaction));
new(T) Transaction(S);
} else
if (kDebugMode || m_Transactions.empty())
T = new Transaction(S);
else
T = new (m_Transactions.pop_back_val()) Transaction(S);
return T;
@ -63,7 +62,7 @@ namespace cling {
if (reuse) {
assert((T->getState() == Transaction::kCompleted ||
T->getState() == Transaction::kRolledBack)
&& "Transaction must completed!");
&& "Transaction must be completed!");
// Force reuse to off when not in Debug mode
if (kDebugMode)
reuse = false;
@ -73,15 +72,14 @@ namespace cling {
if (T->getParent())
T->getParent()->removeNestedTransaction(T);
T->~Transaction();
// don't overflow the pool
if (reuse && (m_Transactions.size() < kPoolSize)) {
T->m_State = Transaction::kNumStates;
T->~Transaction();
m_Transactions.push_back(T);
}
else
::operator delete(T);
delete T;
}
};