Skip to content

Commit 9437eb6

Browse files
msmolensjcfr
authored andcommitted
Explicitly initialize global storage containers
This commit changes initialization of the global storage containers to be explicit instead of happening during static initialization. This makes the containers properly initialized if PythonQt is initialized and cleaned up more than once. The motivation for this change is to support testing cleanup and finalization.
1 parent 290a5fb commit 9437eb6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/PythonQt.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,10 @@ PythonQtPrivate::PythonQtPrivate()
13331333
_hadError = false;
13341334
_systemExitExceptionHandlerEnabled = false;
13351335
_debugAPI = new PythonQtDebugAPI(this);
1336+
1337+
PythonQtConv::global_valueStorage.init();
1338+
PythonQtConv::global_ptrStorage.init();
1339+
PythonQtConv::global_variantStorage.init();
13361340
}
13371341

13381342
void PythonQtPrivate::setupSharedLibrarySuffixes()

src/PythonQtMisc.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,25 @@ template <typename T, int chunkEntries> class PythonQtValueStorage
7676
PythonQtValueStorage() {
7777
_chunkIdx = 0;
7878
_chunkOffset = 0;
79+
_currentChunk = NULL;
80+
};
81+
82+
//! initialize memory
83+
void init() {
84+
assert(_currentChunk == NULL);
85+
assert(_chunks.isEmpty());
86+
_chunkIdx = 0;
87+
_chunkOffset = 0;
7988
_currentChunk = new T[chunkEntries];
8089
_chunks.append(_currentChunk);
81-
};
90+
}
8291

8392
//! clear all memory
8493
void clear() {
94+
_chunkIdx = 0;
95+
_chunkOffset = 0;
96+
_currentChunk = NULL;
97+
8598
T* chunk;
8699
Q_FOREACH(chunk, _chunks) {
87100
delete[]chunk;

0 commit comments

Comments
 (0)