Changes as per review and reverted the change in Collections.h and Collections.cpp to avoid memory growth, but ignore the warnings -Wmaybe-uninitialized
(cherry picked from commit 61729a319ab0015aae716d8baa04bfd0e8c5deb0) Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/4ecccfcb Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/4ecccfcb Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/4ecccfcb Branch: refs/heads/master Commit: 4ecccfcb0bd640d13e923cdf873380fde6daa974 Parents: cd3f230 Author: selvaganesang <[email protected]> Authored: Fri Oct 13 00:15:12 2017 +0000 Committer: selvaganesang <[email protected]> Committed: Fri Oct 13 00:15:12 2017 +0000 ---------------------------------------------------------------------- core/sql/clitest/blobtest.cpp | 2 +- core/sql/common/Collections.cpp | 25 ++++++++++++++++++++++--- core/sql/common/Collections.h | 14 ++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4ecccfcb/core/sql/clitest/blobtest.cpp ---------------------------------------------------------------------- diff --git a/core/sql/clitest/blobtest.cpp b/core/sql/clitest/blobtest.cpp index 0175f3b..85ac4be 100644 --- a/core/sql/clitest/blobtest.cpp +++ b/core/sql/clitest/blobtest.cpp @@ -152,7 +152,7 @@ Int32 extractLobToFileInChunks(CliGlobals *cliglob, char * lobHandle, char *fil } } lobExtractLen = 0; - sprintf(query,"extract lobtobuffer(lob '%s', LOCATION %lu, SIZE %ld) ", lobHandle, (unsigned long)lobDataBuf, (unsigned long)inputOutputAddr); + sprintf(query,"extract lobtobuffer(lob '%s', LOCATION %lu, SIZE %lu) ", lobHandle, (unsigned long)lobDataBuf, (unsigned long)inputOutputAddr); retcode = cliInterface.executeImmediatePrepare(query); cliInterface.clearExecFetchClose(NULL,NULL,statusBuf, &statusBufLen); http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4ecccfcb/core/sql/common/Collections.cpp ---------------------------------------------------------------------- diff --git a/core/sql/common/Collections.cpp b/core/sql/common/Collections.cpp index efef0c7..beb0014 100644 --- a/core/sql/common/Collections.cpp +++ b/core/sql/common/Collections.cpp @@ -157,11 +157,14 @@ CollIndex NACollection<T>::resize(CollIndex newSize) #ifdef __GNUC__ # if __GNUC__ * 100 + __GNUC_MINOR__ >= 404 // push_options added in 4.4 -# pragma GCC push_options +#pragma GCC push_options // GCC prior to 4.4 did not complain about this // need to ignore uninitialized for this statement: // T temp; # pragma GCC diagnostic ignored "-Wuninitialized" +# if __GNUC__ * 100 + __GNUC_MINOR__ >= 408 +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +# endif # endif #endif template <class T> void NACollection<T>::allocate(CollIndex initLen) @@ -185,8 +188,24 @@ template <class T> void NACollection<T>::allocate(CollIndex initLen) } else { - arr_ = new(heap_) T[maxLength_]; - usages_ = new(heap_) CollIndex[maxLength_]; + // The method for dynamic allocation should match the one in + // deallocate. When the compiler supports the feature to overload + // new[] and delete[], the following two lines should be used + // instead. + //arr_ = new(heap_) T[maxLength_]; + //usages_ = new(heap_) CollIndex[maxLength_]; + + arr_ = (T *)heap_->allocateMemory(sizeof(T) * ((size_t) maxLength_)); + usages_ = (CollIndex *) heap_->allocateMemory( + sizeof(CollIndex) * ((size_t) maxLength_)); + + // To finish up, we copy uninitialized objects of type T into + // the newly-alloc'd space, so vtbl-pointers get set properly. + // (This is not always necessary, but it's a good idea in + // general!) + T temp; + for ( CollIndex i = 0 ; i < maxLength_ ; i++ ) + memcpy ((void*)&arr_[i], (void*)&temp, sizeof(T)) ; } } else http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4ecccfcb/core/sql/common/Collections.h ---------------------------------------------------------------------- diff --git a/core/sql/common/Collections.h b/core/sql/common/Collections.h index c8f6f1b..a53e3d4 100644 --- a/core/sql/common/Collections.h +++ b/core/sql/common/Collections.h @@ -442,10 +442,16 @@ public: } else { - if (!arr_) - NADELETE(arr_, T, heap_); - if (!usages_) - delete [] usages_; + // user-specified delete operator + // Note : this won't call the destructor of each arr_ element. + // after the compiler supports delete[] operator to be supprted, + // it should be changed to + //if (arr_) delete [] arr_; + //if (usages_) delete [] usages_; + + if (arr_ != NULL) heap_->deallocateMemory(arr_); + if (usages_ != NULL) heap_->deallocateMemory(usages_); + } arr_ = NULL; usages_ = NULL;
