Skip to content

Commit 8f65e18

Browse files
committed
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 3b4050b commit 8f65e18

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/PythonQt.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,10 @@ PythonQtPrivate::PythonQtPrivate()
12941294
_hadError = false;
12951295
_systemExitExceptionHandlerEnabled = false;
12961296
_debugAPI = new PythonQtDebugAPI(this);
1297+
1298+
PythonQtConv::global_valueStorage.init();
1299+
PythonQtConv::global_ptrStorage.init();
1300+
PythonQtConv::global_variantStorage.init();
12971301
}
12981302

12991303
void PythonQtPrivate::setupSharedLibrarySuffixes()

src/PythonQtMisc.h

+14-1
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)