Skip to content

Commit c63987a

Browse files
bugfixes
1 parent d130a2e commit c63987a

10 files changed

Lines changed: 63 additions & 49 deletions

src/tcommandlineinterface.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,14 @@
2323
{ \
2424
returnCode = STATICFUNCTION(); \
2525
commitTransactions(); \
26-
for (auto it = sqlDatabases.begin(); it != sqlDatabases.end(); ++it) { \
27-
it.value().database().close(); /* close SQL database */ \
28-
} \
29-
for (auto it = kvsDatabases.begin(); it != kvsDatabases.end(); ++it) { \
30-
it.value().close(); /* close KVS database */ \
31-
} \
3226
QEventLoop eventLoop; \
3327
while (eventLoop.processEvents()) { } \
3428
} \
3529
}; \
3630
TWebApplication app(argc, argv); \
3731
Tf::setupSystemLogger(new TStdErrSystemLogger); \
3832
Tf::setupQueryLogger(); \
39-
app.setMultiProcessingModule(TWebApplication::Thread); \
33+
app.setMultiProcessingModule(TWebApplication::MultiProcessingModule::Thread); \
4034
int idx = QCoreApplication::arguments().indexOf("-e"); \
4135
QString env = (idx > 0) ? QCoreApplication::arguments().value(idx + 1) : QString("product"); \
4236
app.setDatabaseEnvironment(env); \

src/tdatabasecontext.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ thread_local TDatabaseContext *databaseContextPtrTls = nullptr;
3333
TDatabaseContext::TDatabaseContext()
3434
{
3535
const int count = Tf::app()->sqlDatabaseSettingsCount();
36+
3637
if (sqlTransactions.size() < (size_t)count) {
3738
sqlTransactions.resize(count);
3839
}
@@ -133,11 +134,12 @@ void TDatabaseContext::release()
133134

134135
void TDatabaseContext::setTransactionEnabled(bool enable, int id)
135136
{
136-
if (id < 0) {
137+
if (id < 0 || id >= (int)sqlTransactions.size()) {
137138
Tf::error("Invalid database ID: {}", id);
138139
return;
139140
}
140-
return sqlTransactions[id].setEnabled(enable);
141+
142+
sqlTransactions[id].setEnabled(enable);
141143
}
142144

143145

src/test/buildtest/main.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,15 @@ void stack()
245245
{
246246
TStack<QString> stack;
247247
stack.push(QString());
248-
QString s;
249-
stack.pop(s);
250-
stack.top(s);
248+
auto s = stack.pop();
249+
stack.count();
251250
}
252251

253252
void queue()
254253
{
255254
TQueue<QString> queue;
256255
queue.enqueue(QString());
257-
QString s;
258-
queue.dequeue(s);
259-
queue.head(s);
256+
auto s = queue.dequeue();
260257
queue.count();
261258
}
262259

src/test/stack/main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class PopThread : public QThread
4747
protected:
4848
void run() {
4949
for (;;) {
50-
Box box;
51-
if (stackBox.pop(box)) {
50+
auto opbox = stackBox.pop();
51+
if (opbox) {
52+
auto box = opbox.value();
5253
Q_ASSERT(box.a + box.b == 1000);
5354
}
5455
//Tf::msleep(1);
@@ -67,7 +68,9 @@ class PushThread : public QThread
6768
void run() {
6869
for (;;) {
6970
Box box;
70-
if (stackBox.top(box)) {
71+
auto opbox = stackBox.pop();
72+
if (opbox) {
73+
box = opbox.value();
7174
Q_ASSERT(box.a + box.b == 1000);
7275
box.a++;
7376
box.b--;

src/tftest.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
TestObject obj; \
3535
returnCode = QTest::qExec(&obj, QCoreApplication::arguments()); \
3636
commitTransactions(); \
37-
for (QMap<int, TSqlTransaction>::iterator it = sqlDatabases.begin(); it != sqlDatabases.end(); ++it) { \
38-
it.value().database().close(); /* close SQL database */ \
39-
} \
40-
for (QMap<int, TKvsDatabase>::iterator it = kvsDatabases.begin(); it != kvsDatabases.end(); ++it) { \
41-
it.value().close(); /* close KVS database */ \
42-
} \
4337
QEventLoop eventLoop; \
4438
while (eventLoop.processEvents()) { \
4539
} \

src/tglobal.h

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ inline TDebug tTrace()
211211
template <typename... Args>
212212
inline void tFatal(const char *fmt, Args&&... args)
213213
{
214-
TDebug(Tf::FatalLevel).fatal(fmt, std::forward<Args>(args)...);
214+
if constexpr (sizeof...(Args) == 0) {
215+
TDebug(Tf::FatalLevel).fatal("%s", fmt);
216+
} else {
217+
TDebug(Tf::FatalLevel).fatal(fmt, std::forward<Args>(args)...);
218+
}
215219

216220
if (getAbortOnFatalFlag()) {
217221
#if defined(Q_OS_UNIX)
@@ -225,31 +229,51 @@ inline void tFatal(const char *fmt, Args&&... args)
225229
template <typename... Args>
226230
inline void tError(const char *fmt, Args&&... args)
227231
{
228-
TDebug(Tf::FatalLevel).error(fmt, std::forward<Args>(args)...);
232+
if constexpr (sizeof...(Args) == 0) {
233+
TDebug(Tf::FatalLevel).error("%s", fmt);
234+
} else {
235+
TDebug(Tf::FatalLevel).error(fmt, std::forward<Args>(args)...);
236+
}
229237
}
230238

231239
template <typename... Args>
232240
inline void tWarn(const char *fmt, Args&&... args)
233241
{
234-
TDebug(Tf::FatalLevel).warn(fmt, std::forward<Args>(args)...);
242+
if constexpr (sizeof...(Args) == 0) {
243+
TDebug(Tf::FatalLevel).warn("%s", fmt);
244+
} else {
245+
TDebug(Tf::FatalLevel).warn(fmt, std::forward<Args>(args)...);
246+
}
235247
}
236248

237249
template <typename... Args>
238250
inline void tInfo(const char *fmt, Args&&... args)
239251
{
240-
TDebug(Tf::FatalLevel).info(fmt, std::forward<Args>(args)...);
252+
if constexpr (sizeof...(Args) == 0) {
253+
TDebug(Tf::FatalLevel).info("%s", fmt);
254+
} else {
255+
TDebug(Tf::FatalLevel).info(fmt, std::forward<Args>(args)...);
256+
}
241257
}
242258

243259
template <typename... Args>
244260
inline void tDebug(const char *fmt, Args&&... args)
245261
{
246-
TDebug(Tf::FatalLevel).debug(fmt, std::forward<Args>(args)...);
262+
if constexpr (sizeof...(Args) == 0) {
263+
TDebug(Tf::FatalLevel).debug("%s", fmt);
264+
} else {
265+
TDebug(Tf::FatalLevel).debug(fmt, std::forward<Args>(args)...);
266+
}
247267
}
248268

249269
template <typename... Args>
250270
inline void tTrace(const char *fmt, Args&&... args)
251271
{
252-
TDebug(Tf::FatalLevel).trace(fmt, std::forward<Args>(args)...);
272+
if constexpr (sizeof...(Args) == 0) {
273+
TDebug(Tf::FatalLevel).trace("%s", fmt);
274+
} else {
275+
TDebug(Tf::FatalLevel).trace(fmt, std::forward<Args>(args)...);
276+
}
253277
}
254278

255279

src/tkvsdatabasepool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ TKvsDatabasePool::~TKvsDatabasePool()
7474
timer.stop();
7575

7676
for (int eng = 0; eng < (int)Tf::KvsEngine::Num; eng++) {
77-
if (!Tf::app()->isKvsAvailable((Tf::KvsEngine)eng)) {
77+
if (!Tf::app() || !Tf::app()->isKvsAvailable((Tf::KvsEngine)eng)) {
7878
continue;
7979
}
8080

src/tkvsdatabasepool.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class T_CORE_EXPORT TKvsDatabasePool : public QObject {
3636
TAtomic<uint> *lastCachedTime {nullptr};
3737
int maxConnects {0};
3838
QBasicTimer timer;
39-
// std::vector<TStack<KvsDbPtr>> availableDatabases;
40-
// std::vector<TStack<KvsDbPtr>> cachedDatabases;
4139
std::vector<TLockStack<KvsDbPtr>> availableDatabases;
4240
std::vector<TLockStack<KvsDbPtr>> cachedDatabases;
4341

src/tmultiplexingserver_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void TMultiplexingServer::instantiate(int listeningSocket)
4343
TMultiplexingServer *TMultiplexingServer::instance()
4444
{
4545
if (Q_UNLIKELY(!multiplexingServer)) {
46-
tFatal("Call TMultiplexingServer::instantiate() function first");
46+
Tf::fatal("Call TMultiplexingServer::instantiate() function first");
4747
}
4848
return multiplexingServer.get();
4949
}

src/tsqldatabasepool.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,25 @@ TSqlDatabasePool::~TSqlDatabasePool()
4444
{
4545
timer.stop();
4646

47-
for (int j = 0; j < Tf::app()->sqlDatabaseSettingsCount(); ++j) {
48-
auto &cache = cachedDatabases[j];
49-
QString name;
50-
while (!cache.empty()) {
51-
std::optional<SqlDbPtr> db = cache.pop();
52-
if (db) {
53-
name = (*db)->connectionName();
54-
closeDatabase(*(*db));
55-
TSqlDatabase::removeDatabase(name);
47+
if (Tf::app()) {
48+
for (int j = 0; j < Tf::app()->sqlDatabaseSettingsCount(); ++j) {
49+
auto &cache = cachedDatabases[j];
50+
QString name;
51+
while (!cache.empty()) {
52+
std::optional<SqlDbPtr> db = cache.pop();
53+
if (db) {
54+
name = (*db)->connectionName();
55+
closeDatabase(*(*db));
56+
TSqlDatabase::removeDatabase(name);
57+
}
5658
}
57-
}
5859

59-
auto &stack = availableDatabases[j];
60-
while (!stack.empty()) {
61-
std::optional<SqlDbPtr> db = stack.pop();
62-
if (db) {
63-
TSqlDatabase::removeDatabase((*db)->sqlDatabase().connectionName());
60+
auto &stack = availableDatabases[j];
61+
while (!stack.empty()) {
62+
std::optional<SqlDbPtr> db = stack.pop();
63+
if (db) {
64+
TSqlDatabase::removeDatabase((*db)->sqlDatabase().connectionName());
65+
}
6466
}
6567
}
6668
}

0 commit comments

Comments
 (0)