Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions math/vecops/inc/ROOT/RVec.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ void R__CLING_PTRCHECK(off) SmallVectorTemplateBase<T, TriviallyCopyable>::grow(
// Always grow, even from zero.
size_t NewCapacity = size_t(NextPowerOf2(this->capacity() + 2));
NewCapacity = std::min(std::max(NewCapacity, MinSize), this->SizeTypeMax());
T *NewElts = static_cast<T *>(malloc(NewCapacity * sizeof(T)));
T *NewElts = static_cast<T *>(::operator new(NewCapacity * sizeof(T), std::nothrow));
R__ASSERT(NewElts != nullptr);

// Move the elements over.
Expand All @@ -410,7 +410,7 @@ void R__CLING_PTRCHECK(off) SmallVectorTemplateBase<T, TriviallyCopyable>::grow(

// If this wasn't grown from the inline copy, deallocate the old space.
if (!this->isSmall())
free(this->begin());
::operator delete(this->begin());
}

this->fBeginX = NewElts;
Expand Down Expand Up @@ -560,7 +560,7 @@ public:
// Subclass has already destructed this vector's elements.
// If this wasn't grown from the inline copy, deallocate the old space.
if (!this->isSmall() && this->Owns())
free(this->begin());
::operator delete(this->begin());
}

// also give up adopted memory if applicable
Expand Down Expand Up @@ -1037,7 +1037,7 @@ RVecImpl<T> &RVecImpl<T>::operator=(RVecImpl<T> &&RHS) noexcept(kIsNoExcept)
if (this->Owns()) {
this->destroy_range(this->begin(), this->end());
if (!this->isSmall())
free(this->begin());
::operator delete(this->begin());
}
this->fBeginX = RHS.fBeginX;
this->fSize = RHS.fSize;
Expand Down
19 changes: 8 additions & 11 deletions math/vecops/src/RVec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,14 @@ void ROOT::Internal::VecOps::SmallVectorBase::grow_pod(void *FirstEl, size_t Min
size_t NewCapacity = 2 * capacity() + 1; // Always grow.
NewCapacity = std::min(std::max(NewCapacity, MinSize), SizeTypeMax());

void *NewElts;
if (fBeginX == FirstEl || !this->Owns()) {
NewElts = malloc(NewCapacity * TSize);
R__ASSERT(NewElts != nullptr);

// Copy the elements over. No need to run dtors on PODs.
memcpy(NewElts, this->fBeginX, size() * TSize);
} else {
// If this wasn't grown from the inline copy, grow the allocated space.
NewElts = realloc(this->fBeginX, NewCapacity * TSize);
R__ASSERT(NewElts != nullptr);
void *NewElts = ::operator new(NewCapacity * TSize, std::nothrow);
R__ASSERT(NewElts != nullptr);
// Copy the elements over. No need to run dtors on PODs.
memcpy(NewElts, this->fBeginX, size() * TSize);

if (fBeginX != FirstEl && this->Owns()) {
// If this wasn't grown from the inline copy, delete the previously allocated space.
::operator delete(this->fBeginX);
}

this->fBeginX = NewElts;
Expand Down
10 changes: 4 additions & 6 deletions tree/ntuple/src/RFieldSequenceContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
#include <ROOT/RFieldVisitor.hxx>
#include <ROOT/RFieldUtils.hxx>

#include <cstdlib> // for malloc, free
#include <limits>
#include <memory>
#include <new> // hardware_destructive_interference_size
#include <new> // hardware_destructive_interference_size, operator new

namespace {

Expand Down Expand Up @@ -199,7 +198,7 @@ ROOT::RRVecField::RRVecField(std::string_view fieldName, std::unique_ptr<RFieldB
fNWritten(0)
{
if (itemField->GetAlignment() > sizeof(std::max_align_t)) {
// RVec uses malloc() and free()
// RVec uses operator new without alignment info
throw RException(R__FAIL("RVec does not support over-aligned types"));
}

Expand Down Expand Up @@ -314,9 +313,8 @@ unsigned char *ROOT::RRVecField::ResizeRVec(void *rvec, std::size_t nItems, std:
}

Internal::DestroyRVecWithChecks(itemField->GetAlignment(), beginPtr, capacityPtr);
// We trust that malloc returns a buffer with large enough alignment.
// This might not be the case if T in RVec<T> is over-aligned.
*beginPtr = static_cast<unsigned char *>(malloc(newCapacity * itemSize));
// We checked that the item type is not over-aligned
*beginPtr = static_cast<unsigned char *>(::operator new(newCapacity * itemSize, std::nothrow));
R__ASSERT(*beginPtr != nullptr);
*capacityPtr = static_cast<std::int32_t>(newCapacity);

Expand Down
2 changes: 1 addition & 1 deletion tree/ntuple/src/RFieldUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -894,5 +894,5 @@ void ROOT::Internal::DestroyRVecWithChecks(std::size_t alignOfT, unsigned char *

const bool owns = (*capacityPtr != -1);
if (!isSmall && owns)
free(*beginPtr);
::operator delete(*beginPtr);
}
Loading