fixed errors for Linux clang/gcc

This commit is contained in:
silverqx
2021-11-12 12:27:03 +01:00
parent 272d27043c
commit b39b4dcf48
20 changed files with 72 additions and 35 deletions

View File

@@ -44,6 +44,7 @@ function(tiny_sources out_headers out_sources)
macros/export.hpp
macros/export_common.hpp
macros/systemheader.hpp
macros/threadlocal.hpp
mysqlconnection.hpp
ormtypes.hpp
postgresconnection.hpp

View File

@@ -41,6 +41,7 @@ HEADERS += \
$$PWD/orm/macros/export.hpp \
$$PWD/orm/macros/export_common.hpp \
$$PWD/orm/macros/systemheader.hpp \
$$PWD/orm/macros/threadlocal.hpp \
$$PWD/orm/mysqlconnection.hpp \
$$PWD/orm/ormtypes.hpp \
$$PWD/orm/postgresconnection.hpp \

View File

@@ -8,6 +8,7 @@ TINY_SYSTEM_HEADER
#include <QVariantHash>
#include "orm/macros/commonnamespace.hpp"
#include "orm/macros/threadlocal.hpp"
TINYORM_BEGIN_COMMON_NAMESPACE
@@ -29,16 +30,16 @@ namespace Orm::Support
/*! Default Database Connection Name, used as default value in method declarations
only. */
thread_local
T_THREAD_LOCAL
inline static QString defaultConnectionName = QStringLiteral("tinyorm_default");
// CUR better naming silverqx
/*! Currently set Default Database Connection Name in a current thread. */
thread_local
T_THREAD_LOCAL
inline static QString defaultConnection;
/*! Default namespace prefix for MySQL savepoints in a current thread. */
thread_local
T_THREAD_LOCAL
inline static
QString defaultSavepointNamespace = QStringLiteral("tinyorm_savepoint");
@@ -53,7 +54,7 @@ namespace Orm::Support
private:
/*! Database connection configurations. */
thread_local
T_THREAD_LOCAL
inline static ConfigurationsType m_configurations;
};

View File

@@ -0,0 +1,16 @@
#pragma once
#ifndef ORM_MACROS_THREADLOCAL_HPP
#define ORM_MACROS_THREADLOCAL_HPP
#include "orm/macros/systemheader.hpp"
TINY_SYSTEM_HEADER
#if !defined(__clang__)
# define T_THREAD_LOCAL thread_local
#endif
#if !defined(T_THREAD_LOCAL)
# define T_THREAD_LOCAL
#endif
#endif // ORM_MACROS_THREADLOCAL_HPP

View File

@@ -9,6 +9,7 @@ TINY_SYSTEM_HEADER
#include "orm/databaseconnection.hpp"
#include "orm/macros/commonnamespace.hpp"
#include "orm/macros/threadlocal.hpp"
TINYORM_BEGIN_COMMON_NAMESPACE
@@ -39,7 +40,7 @@ namespace Orm::Support
private:
/*! Database connections for the current thread. */
thread_local
T_THREAD_LOCAL
inline static ConnectionsType m_connections;
};

View File

@@ -6,6 +6,7 @@
TINY_SYSTEM_HEADER
#include "orm/concepts.hpp"
#include "orm/macros/threadlocal.hpp"
#include "orm/ormtypes.hpp"
#include "orm/utils/type.hpp"
@@ -80,16 +81,16 @@ namespace Concerns
fillableFromArray(QVector<AttributeItem> &&attributes) const;
/*! The attributes that are mass assignable. */
thread_local
T_THREAD_LOCAL
inline static QStringList u_fillable;
/*! The attributes that aren't mass assignable. */
thread_local
T_THREAD_LOCAL
inline static QStringList u_guarded {ASTERISK}; // NOLINT(cppcoreguidelines-interfaces-global-init)
/*! Indicates if all mass assignment is enabled. */
thread_local
T_THREAD_LOCAL
inline static bool m_unguarded = false;
/*! The actual columns that exist on the database and can be guarded. */
thread_local
T_THREAD_LOCAL
inline static QHash<QString, QStringList> m_guardableColumns;
private:

View File

@@ -246,7 +246,7 @@ namespace Concerns
constexpr static RelationStoreType initStoreType();
/*! Served store type, this class can handle two store types. */
thread_local
T_THREAD_LOCAL
constexpr static RelationStoreType STORE_TYPE = initStoreType();
private:

View File

@@ -50,13 +50,13 @@ namespace Private
// BUG clang and thread_local, gcc on MinGW doesn't work too silverqx
/*! Data member for nested stores. */
template<typename Related>
thread_local
T_THREAD_LOCAL
inline static
std::stack<std::shared_ptr<NestedStore<Related>>> STORE;
/*! Stored Related type is used to avoid a cryptic message when a bad type-id
was passed to the has() nested method. */
thread_local
T_THREAD_LOCAL
inline static
std::stack<std::type_index> STORE_TYPEID;

View File

@@ -46,7 +46,7 @@ namespace Relations {
{
/*! The connection to use in the Model, this data member is picked up
in the Model::getConnectionName(). */
thread_local
T_THREAD_LOCAL
inline static QString connection;
};
#endif
@@ -131,6 +131,7 @@ namespace Relations {
// CUR study how to use acquire/release memory order for m_queryLogId atomic silverqx
// CUR u_guarded in Pivot/BasePivot and TLS silverqx
// CUR rename m_db to m_dm in tinyplay silverqx
// CUR move T_LIKELY to likely.hpp from macros.hpp silverqx
/*! Base model class. */
template<typename Derived, AllRelationsConcept ...AllRelations>
class Model :
@@ -705,7 +706,7 @@ namespace Relations {
/* HasAttributes */
/*! The model's default values for attributes. */
thread_local
T_THREAD_LOCAL
inline static QVector<AttributeItem> u_attributes;
/*! The model's attributes (insert order). */
QVector<AttributeItem> m_attributes;
@@ -727,10 +728,10 @@ namespace Relations {
// TODO add support for 'U' like in PHP to support unix timestamp, I will have to manually check if u_dateFormat contains 'U' and use QDateTime::fromSecsSinceEpoch() silverqx
/*! The storage format of the model's date columns. */
thread_local
T_THREAD_LOCAL
inline static QString u_dateFormat;
/*! The attributes that should be mutated to dates. @deprecated */
thread_local
T_THREAD_LOCAL
inline static QStringList u_dates;
/* HasRelationships */
@@ -2439,7 +2440,7 @@ namespace Relations {
const QStringList &
Model<Derived, AllRelations...>::getDates() const
{
thread_local
T_THREAD_LOCAL
static const QStringList &dates = getDatesInternal();
return dates;

View File

@@ -84,7 +84,7 @@ namespace Orm::Tiny::Relations
/*! Indicates if the ID is auto-incrementing. */
bool u_incrementing = false;
/*! The attributes that aren't mass assignable. */
thread_local
T_THREAD_LOCAL
inline static QStringList u_guarded;
/* AsPivot */

View File

@@ -104,7 +104,7 @@ namespace Orm::Tiny::Relations
/*! The name of the relationship. */
QString m_relationName;
/*! The count of self joins. */
thread_local
T_THREAD_LOCAL
inline static int selfJoinCount = 0;
};

View File

@@ -5,6 +5,7 @@
#include "orm/macros/systemheader.hpp"
TINY_SYSTEM_HEADER
#include "orm/macros/threadlocal.hpp"
// FEATURE orm types, only AttributeItem used silverqx
#include "orm/ormtypes.hpp"
@@ -127,7 +128,7 @@ namespace Concerns {
inline Relation<Model, Related> &
SupportsDefaultModels<Model, Related>::relation()
{
thread_local
T_THREAD_LOCAL
static auto &cached = dynamic_cast<Relation<Model, Related> &>(*this);
return cached;

View File

@@ -115,7 +115,7 @@ namespace Orm::Tiny::Relations
/*! The local key of the parent model. */
QString m_localKey;
/*! The count of self joins. */
thread_local
T_THREAD_LOCAL
inline static int selfJoinCount = 0;
};

View File

@@ -13,6 +13,7 @@ TINY_SYSTEM_HEADER
#include <range/v3/action/unique.hpp>
#include "orm/exceptions/runtimeerror.hpp"
#include "orm/macros/threadlocal.hpp"
#include "orm/tiny/relations/relationproxies.hpp"
TINYORM_BEGIN_COMMON_NAMESPACE
@@ -175,7 +176,7 @@ namespace Relations
/*! The TinyORM TinyBuilder instance. */
std::unique_ptr<Builder<Related>> m_query;
/*! Indicates if the relation is adding constraints. */
thread_local
T_THREAD_LOCAL
inline static bool constraints = true;
};

View File

@@ -5,6 +5,8 @@
#include "orm/macros/systemheader.hpp"
TINY_SYSTEM_HEADER
#include <QtGlobal>
#include "orm/macros/commonnamespace.hpp"
#include "orm/macros/export.hpp"
@@ -26,10 +28,12 @@ namespace Orm::Utils
/*! Set thread name for debugger, -1 for a current thread. */
static void nameThreadForDebugging(
const QString &threadName, quint64 threadId = -1);
const QString &threadName,
quint64 threadId = static_cast<quint64>(-1));
/*! Set thread name for debugger, -1 for a current thread. */
static void nameThreadForDebugging(
const char *threadName, quint64 threadId = -1);
const char *threadName,
quint64 threadId = static_cast<quint64>(-1));
};
} // namespace Orm::Utils

View File

@@ -1,5 +1,6 @@
#include "orm/query/grammars/mysqlgrammar.hpp"
#include "orm/macros/threadlocal.hpp"
#include "orm/query/querybuilder.hpp"
TINYORM_BEGIN_COMMON_NAMESPACE
@@ -106,7 +107,7 @@ MySqlGrammar::getCompileMap() const
};
// Pointers to a where member methods by whereType, yes yes c++ 😂
thread_local
T_THREAD_LOCAL
static const QMap<SelectComponentType, SelectComponentValue> cached {
{SelectComponentType::AGGREGATE, {bind(&MySqlGrammar::compileAggregate),
[this]
@@ -161,7 +162,7 @@ MySqlGrammar::getWhereMethod(const WhereType whereType) const
// Pointers to a where member methods by whereType, yes yes c++ 😂
// An order has to be the same as in enum struct WhereType
// FUTURE QHash would has faster lookup, I should choose QHash, fix also another Grammars silverx
thread_local
T_THREAD_LOCAL
static const QVector<std::function<QString(const WhereConditionItem &)>> cached {
bind(&MySqlGrammar::whereBasic),
bind(&MySqlGrammar::whereNested),
@@ -175,7 +176,7 @@ MySqlGrammar::getWhereMethod(const WhereType whereType) const
bind(&MySqlGrammar::whereNotExists),
};
thread_local
T_THREAD_LOCAL
static const auto size = cached.size();
// Check if whereType is in the range, just for sure 😏

View File

@@ -1,5 +1,6 @@
#include "orm/query/grammars/postgresgrammar.hpp"
#include "orm/macros/threadlocal.hpp"
#include "orm/query/querybuilder.hpp"
TINYORM_BEGIN_COMMON_NAMESPACE
@@ -112,7 +113,7 @@ PostgresGrammar::getCompileMap() const
};
// Pointers to a where member methods by whereType, yes yes c++ 😂
thread_local
T_THREAD_LOCAL
static const QMap<SelectComponentType, SelectComponentValue> cached {
{SelectComponentType::AGGREGATE, {bind(&PostgresGrammar::compileAggregate),
[this]
@@ -166,7 +167,7 @@ PostgresGrammar::getWhereMethod(const WhereType whereType) const
// Pointers to a where member methods by whereType, yes yes c++ 😂
// An order has to be the same as in enum struct WhereType
// FUTURE QHash would has faster lookup, I should choose QHash, fix also another Grammars silverx
thread_local
T_THREAD_LOCAL
static const QVector<std::function<QString(const WhereConditionItem &)>> cached {
bind(&PostgresGrammar::whereBasic),
bind(&PostgresGrammar::whereNested),
@@ -180,7 +181,7 @@ PostgresGrammar::getWhereMethod(const WhereType whereType) const
bind(&PostgresGrammar::whereNotExists),
};
thread_local
T_THREAD_LOCAL
static const auto size = cached.size();
// Check if whereType is in the range, just for sure 😏

View File

@@ -1,5 +1,6 @@
#include "orm/query/grammars/sqlitegrammar.hpp"
#include "orm/macros/threadlocal.hpp"
#include "orm/query/querybuilder.hpp"
TINYORM_BEGIN_COMMON_NAMESPACE
@@ -89,7 +90,7 @@ SQLiteGrammar::getCompileMap() const
};
// Pointers to a where member methods by whereType, yes yes c++ 😂
thread_local
T_THREAD_LOCAL
static const QMap<SelectComponentType, SelectComponentValue> cached {
{SelectComponentType::AGGREGATE, {bind(&SQLiteGrammar::compileAggregate),
[this]
@@ -142,7 +143,7 @@ SQLiteGrammar::getWhereMethod(const WhereType whereType) const
// Pointers to a where member methods by whereType, yes yes c++ 😂
// An order has to be the same as in enum struct WhereType
thread_local
T_THREAD_LOCAL
static const QVector<std::function<QString(const WhereConditionItem &)>> cached {
bind(&SQLiteGrammar::whereBasic),
bind(&SQLiteGrammar::whereNested),
@@ -156,7 +157,7 @@ SQLiteGrammar::getWhereMethod(const WhereType whereType) const
bind(&SQLiteGrammar::whereNotExists),
};
thread_local
T_THREAD_LOCAL
static const auto size = cached.size();
// Check if whereType is in the range, just for sure 😏

View File

@@ -1,10 +1,16 @@
#include "orm/utils/thread.hpp"
#include <QString>
#if !defined(__clang__) && \
!defined(TINYORM_NO_DEBUG) && defined(_MSC_VER) && !defined(Q_OS_WINRT)
#include <qt_windows.h>
#endif
#if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE)
#include <sys/prctl.h>
#endif
// CUR test on gcc/clang and add needed includes silverqx
TINYORM_BEGIN_COMMON_NAMESPACE
@@ -55,7 +61,7 @@ namespace
void setCurrentThreadName(const char *name)
{
# if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE)
prctl(PR_SET_NAME, (unsigned long) name, 0, 0, 0);
prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(name), 0, 0, 0);
# elif defined(Q_OS_MAC)
pthread_setname_np(name);
# elif defined(Q_OS_QNX)

View File

@@ -33,7 +33,7 @@ private slots:
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
private:
/*! The Database Manager used in this test case. */
std::unique_ptr<DatabaseManager> m_dm;
std::unique_ptr<DatabaseManager> m_dm {};
};
void tst_DatabaseManager::initTestCase()