Fix typos, fix some warnings, added more compile options, moved to forgejo CI
Some checks failed
Main LMDBAL workflow / Test LMDBAL with qt5 (push) Has been cancelled
Main LMDBAL workflow / Test LMDBAL with qt6 (push) Has been cancelled
Main LMDBAL workflow / Release documentation (push) Has been cancelled

This commit is contained in:
Blue 2025-05-02 18:19:06 +03:00
parent 3ae1fd15c0
commit 1585b8e4f5
Signed by: blue
GPG key ID: 9B203B252A63EE38
15 changed files with 204 additions and 120 deletions

View file

@ -1,4 +1,4 @@
name: Main LMDBAL workfow name: Main LMDBAL workflow
run-name: ${{ gitea.actor }} is running LMDBAL main workflow run-name: ${{ gitea.actor }} is running LMDBAL main workflow
on: on:
push: push:
@ -8,13 +8,13 @@ on:
jobs: jobs:
test-qt5: test-qt5:
name: Test LMDBAL with qt5 name: Test LMDBAL with qt5
uses: ./.gitea/workflows/test.yml uses: ./.forgejo/workflows/test.yml
with: with:
flags: -D QT_VERSION_MAJOR=5 -D LMDBAL_NAME=LMDBAL-QT5 flags: -D QT_VERSION_MAJOR=5 -D LMDBAL_NAME=LMDBAL-QT5
test-qt6: test-qt6:
name: Test LMDBAL with qt6 name: Test LMDBAL with qt6
uses: ./.gitea/workflows/test.yml uses: ./.forgejo/workflows/test.yml
with: with:
flags: -D QT_VERSION_MAJOR=6 -D LMDBAL_NAME=LMDBAL-QT6 flags: -D QT_VERSION_MAJOR=6 -D LMDBAL_NAME=LMDBAL-QT6
@ -31,7 +31,7 @@ jobs:
- name: Configure - name: Configure
working-directory: ./build working-directory: ./build
run: cmake .. BUILD_DOC_HTML=True -D BUILD_DOC_XML=True -D BUILD_DOC_MAN=True -D BUILD_DOXYGEN_AWESOME=True run: cmake .. LMDBAL_BUILD_DOC_HTML=True -D LMDBAL_BUILD_DOC_XML=True -D LMDBAL_BUILD_DOC_MAN=True -D LMDBAL_BUILD_DOXYGEN_AWESOME=True
- name: Build - name: Build
working-directory: ./build working-directory: ./build

View file

@ -7,7 +7,7 @@ on:
jobs: jobs:
qt5: qt5:
name: Release qt5 build to AUR name: Release qt5 build to AUR
uses: ./.gitea/workflows/aur.yml uses: ./.forgejo/workflows/aur.yml
with: with:
package-name: lmdbal-qt5 package-name: lmdbal-qt5
description: LMDB Abstraction Layer, qt5 version description: LMDB Abstraction Layer, qt5 version
@ -20,7 +20,7 @@ jobs:
qt6: qt6:
name: Release qt6 build to AUR name: Release qt6 build to AUR
uses: ./.gitea/workflows/aur.yml uses: ./.forgejo/workflows/aur.yml
with: with:
package-name: lmdbal-qt6 package-name: lmdbal-qt6
description: LMDB Abstraction Layer, qt6 version description: LMDB Abstraction Layer, qt6 version

View file

@ -14,7 +14,7 @@ on:
jobs: jobs:
test: test:
name: Building and rinning unit tests name: Building and running unit tests
runs-on: archlinux runs-on: archlinux
steps: steps:
- name: Check out repository code - name: Check out repository code
@ -25,7 +25,7 @@ jobs:
- name: Configure - name: Configure
working-directory: ./build working-directory: ./build
run: cmake .. -D BUILD_TESTS=True -D QT_VERSION_MAJOR= ${{ inputs.flags }} run: cmake .. -D LMDBAL_STRICT=True -D LMDBAL_BUILD_TESTS=True -D QT_VERSION_MAJOR= ${{ inputs.flags }}
- name: Build - name: Build
working-directory: ./build working-directory: ./build

View file

@ -11,12 +11,16 @@ cmake_policy(SET CMP0079 NEW)
set(LMDBAL_NAME ${PROJECT_NAME} CACHE STRING "Override for library name and install path") set(LMDBAL_NAME ${PROJECT_NAME} CACHE STRING "Override for library name and install path")
option(BUILD_STATIC "Builds library as static library" OFF) option(LMDBAL_BUILD_STATIC "Builds library as static library" OFF)
option(BUILD_TESTS "Builds tests" OFF) option(LMDBAL_BUILD_TESTS "Builds tests" OFF)
option(BUILD_DOC_MAN "Builds man page documentation" OFF) option(LMDBAL_BUILD_DOC_MAN "Builds man page documentation" OFF)
option(BUILD_DOC_HTML "Builds html documentation" OFF) option(LMDBAL_BUILD_DOC_HTML "Builds html documentation" OFF)
option(BUILD_DOC_XML "Builds xml documentation" OFF) option(LMDBAL_BUILD_DOC_XML "Builds xml documentation" OFF)
option(BUILD_DOXYGEN_AWESOME "Builds documentation alternative style" OFF) option(LMDBAL_BUILD_DOXYGEN_AWESOME "Builds documentation alternative style" OFF)
option(LMDBAL_STRICT "Builds with extra compiler warnings" OFF)
option(LMDBAL_ASAN "Enables Address Sanitizer" OFF)
option(LMDBAL_UBSAN "Enables Undefined Behavior Sanitizer" OFF)
option(LMDBAL_TSAN "Enables Thread Sanitizer" OFF)
include(GNUInstallDirs) include(GNUInstallDirs)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
@ -40,22 +44,62 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
endif () endif ()
if (BUILD_STATIC) if (LMDBAL_BUILD_STATIC)
add_library(${LMDBAL_NAME} STATIC) add_library(${LMDBAL_NAME} STATIC)
else () else ()
add_library(${LMDBAL_NAME} SHARED) add_library(${LMDBAL_NAME} SHARED)
endif() endif()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
list(APPEND COMPILE_OPTIONS -O3) if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND COMPILE_OPTIONS -g)
list(APPEND COMPILE_OPTIONS -Wall) list(APPEND COMPILE_OPTIONS -Wall)
list(APPEND COMPILE_OPTIONS -Wextra) list(APPEND COMPILE_OPTIONS -Wextra)
list(APPEND COMPILE_OPTIONS -Wpedantic)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
list(APPEND COMPILE_OPTIONS -O3)
list(APPEND COMPILE_OPTIONS -DNDEBUG)
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND COMPILE_OPTIONS -O0)
list(APPEND COMPILE_OPTIONS -g3)
list(APPEND COMPILE_OPTIONS -ggdb)
endif ()
if (LMDBAL_STRICT)
list(APPEND COMPILE_OPTIONS -Wall)
list(APPEND COMPILE_OPTIONS -Werror)
list(APPEND COMPILE_OPTIONS -Wconversion)
list(APPEND COMPILE_OPTIONS -Wnon-virtual-dtor)
list(APPEND COMPILE_OPTIONS -Wold-style-cast)
list(APPEND COMPILE_OPTIONS -Wcast-align)
list(APPEND COMPILE_OPTIONS -Wunused)
list(APPEND COMPILE_OPTIONS -Woverloaded-virtual)
list(APPEND COMPILE_OPTIONS -Wsign-conversion)
list(APPEND COMPILE_OPTIONS -Wnull-dereference)
endif ()
if(JAY_ENABLE_ASAN)
list(APPEND COMPILE_OPTIONS -fsanitize=address)
list(APPEND COMPILE_OPTIONS -fno-omit-frame-pointer)
list(APPEND LINK_OPTIONS -fsanitize=address)
add_link_options()
endif()
if(JAY_ENABLE_UBSAN)
list(APPEND COMPILE_OPTIONS -fsanitize=undefined)
list(APPEND LINK_OPTIONS -fsanitize=undefined)
endif()
if(JAY_ENABLE_TSAN)
list(APPEND COMPILE_OPTIONS -fsanitize=thread)
list(APPEND LINK_OPTIONS -fsanitize=thread)
endif()
endif () endif ()
message("Compilation options: " ${COMPILE_OPTIONS}) message("Compilation options: " ${COMPILE_OPTIONS})
message("Linking options: " ${LINK_OPTIONS})
target_compile_options(${LMDBAL_NAME} PRIVATE ${COMPILE_OPTIONS}) target_compile_options(${LMDBAL_NAME} PRIVATE ${COMPILE_OPTIONS})
target_link_options(${LMDBAL_NAME} PRIVATE ${LINK_OPTIONS})
set_property(TARGET ${LMDBAL_NAME} PROPERTY VERSION ${version}) set_property(TARGET ${LMDBAL_NAME} PROPERTY VERSION ${version})
set_property(TARGET ${LMDBAL_NAME} PROPERTY SOVERSION 1) set_property(TARGET ${LMDBAL_NAME} PROPERTY SOVERSION 1)
@ -73,7 +117,7 @@ if (UNIX)
endif () endif ()
add_subdirectory(src) add_subdirectory(src)
if (BUILD_DOC_MAN OR BUILD_DOC_HTML OR BUILD_DOC_XML) if (LMDBAL_BUILD_DOC_MAN OR LMDBAL_BUILD_DOC_HTML OR LMDBAL_BUILD_DOC_XML)
find_package(Doxygen) find_package(Doxygen)
if (DOXYGEN_FOUND) if (DOXYGEN_FOUND)
add_subdirectory(doc) add_subdirectory(doc)
@ -82,7 +126,7 @@ if (BUILD_DOC_MAN OR BUILD_DOC_HTML OR BUILD_DOC_XML)
endif () endif ()
endif () endif ()
if (BUILD_TESTS) if (LMDBAL_BUILD_TESTS)
add_subdirectory(test) add_subdirectory(test)
endif () endif ()

View file

@ -19,7 +19,8 @@
#### As a system library #### As a system library
If you're using LMDBAL as a system library you probably have no control over it's build options. The easiest way to include the project is to add following If you're using LMDBAL as a system library, you probably have no control over its build options.
The easiest way to include the project is to add the following
``` ```
find_package(lmdbal) find_package(lmdbal)
@ -29,14 +30,14 @@ if (LMDBAL_FOUND)
endif() endif()
``` ```
#### As an embeded subproject #### As an embedded subproject
If you're using LMDBAL as a embeded library you might want to control it's build options, for example you can run If you're using LMDBAL as a embedded library, you might want to control its build options, for example, you can run
``` ```
set(BUILD_STATIC ON) set(LMDBAL_BUILD_STATIC ON)
``` ```
before including the library in your project. This will set the library to be build in a static mode. ... before including the library in your project. This will set the library to be build in a static mode.
Then you want to run something like this Then you want to run something like this
``` ```
@ -67,9 +68,11 @@ $ cmake --build .
$ cmake --install . --prefix install $ cmake --install . --prefix install
``` ```
This way will create you a `lmdbal/build` directory with temporary files, and `lmdbal/build/install` with all the export files for installation to the system. This way will create you a `lmdbal/build` directory with temporary files, and `lmdbal/build/install`
with all the export files for installation to the system.
After `cmake ..` you can specify keys to alter the building process. In this context building keys are transfered like so After `cmake ..` you can specify keys to alter the building process.
In this context building keys are transferred like so
``` ```
cmake .. -D KEY1=VALUE1 -D KEY2=VALUE2 ... cmake .. -D KEY1=VALUE1 -D KEY2=VALUE2 ...
@ -80,22 +83,26 @@ cmake .. -D KEY1=VALUE1 -D KEY2=VALUE2 ...
Here is the list of keys you can pass to configuration phase of `cmake ..`: Here is the list of keys you can pass to configuration phase of `cmake ..`:
- `CMAKE_BUILD_TYPE` - `Debug` just builds showing all warnings, `Release` builds with no warnings and applies optimizations (default is `Debug`); - `CMAKE_BUILD_TYPE` - `Debug` just builds showing all warnings, `Release` builds with no warnings and applies optimizations (default is `Debug`);
- `BUILD_STATIC` - `True` builds project as a static library, `False` builds as dynamic (default is `False`); - `LMDBAL_BUILD_STATIC` - `True` builds project as a static library, `False` builds as dynamic (default is `False`);
- `BUILD_TESTS` - `True` build unit tests, `False` does not (default is `False`); - `LMDBAL_BUILD_TESTS` - `True` build unit tests, `False` does not (default is `False`);
- `BUILD_DOC` - `True` build doxygen documentation, `False` does not (default is `False`); - `BUILD_DOC` - `True` build doxygen documentation, `False` does not (default is `False`);
- `BUILD_DOXYGEN_AWESOME` - `True` build doxygen awesome theme if `BUILD_DOC` is also `True` (default is `False`); - `LMDBAL_BUILD_DOXYGEN_AWESOME` - `True` build doxygen awesome theme if `BUILD_DOC` is also `True` (default is `False`);
- `QT_VERSION_MAJOR` - `5` links against Qt5, `6` links agains Qt6, there is no default, so, if you didn't specify it the project will chose automatically; - `QT_VERSION_MAJOR` - `5` links against Qt5, `6` links against Qt6, there is no default, so, if you didn't specify it, the project will choose automatically;
- `LMDBAL_NAME` - `LMDBAL` builds main target with this name, also install path witll be this name lowercase, usefull if you want to build `LMDBAL-QT6` not to conflict with `LMDBAL-QT5`; - `LMDBAL_NAME` - `LMDBAL` builds the main target with this name, also the installation path will be this name lowercase, useful if you want to build `LMDBAL-QT6` not to conflict with `LMDBAL-QT5`;
- `LMDBAL_STRICT` - `True` builds with extra warnings and considers them errors (default is `False`);
- `LMDBAL_ASAN` - `True` builds with address sanitizer (default is `False`);
- `LMDBAL_TSAN` - `True` builds with thread sanitizer (default is `False`);
- `LMDBAL_UBSAN` - `True` builds with undefined behavior sanitizer (default is `False`);
#### Running tests #### Running tests
If you built the library with `-D BUILD_TESTS=True`, then there will be `lmdbal/build/tests/runUnitTests` executable file. You can simply run it as If you built the library with `-D LMDBAL_BUILD_TESTS=True`, then there will be `lmdbal/build/tests/runUnitTests` executable file. You can run it as
``` ```
./runUnitTests ./runUnitTests
``` ```
if you're in the same directory with it ... if you're in the same directory with it
## License ## License

View file

@ -1,14 +1,14 @@
if (BUILD_DOC_HTML) if (LMDBAL_BUILD_DOC_HTML)
set(DOXYGEN_GENERATE_HTML YES) set(DOXYGEN_GENERATE_HTML YES)
endif() endif()
if (BUILD_DOC_MAN) if (LMDBAL_BUILD_DOC_MAN)
set(DOXYGEN_GENERATE_MAN YES) set(DOXYGEN_GENERATE_MAN YES)
endif() endif()
if (BUILD_DOC_XML) if (LMDBAL_BUILD_DOC_XML)
set(DOXYGEN_GENERATE_XML YES) set(DOXYGEN_GENERATE_XML YES)
endif() endif()
if (BUILD_DOXYGEN_AWESOME) if (LMDBAL_BUILD_DOXYGEN_AWESOME)
include(ExternalProject) include(ExternalProject)
ExternalProject_Add(doxygen-awesome-css ExternalProject_Add(doxygen-awesome-css
GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css.git GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css.git
@ -42,25 +42,25 @@ doxygen_add_docs(
ALL ALL
COMMENT "Generate man and html pages" COMMENT "Generate man and html pages"
) )
if (BUILD_DOC_MAN) if (LMDBAL_BUILD_DOC_MAN)
install(DIRECTORY install(DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/man ${CMAKE_CURRENT_BINARY_DIR}/man
TYPE DOC TYPE DOC
) )
endif() endif()
if (BUILD_DOC_HTML) if (LMDBAL_BUILD_DOC_HTML)
install(DIRECTORY install(DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/html ${CMAKE_CURRENT_BINARY_DIR}/html
TYPE DOC TYPE DOC
) )
endif() endif()
if (BUILD_DOC_XML) if (LMDBAL_BUILD_DOC_XML)
install(DIRECTORY install(DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/xml ${CMAKE_CURRENT_BINARY_DIR}/xml
TYPE DOC TYPE DOC
) )
endif() endif()
if (BUILD_DOXYGEN_AWESOME) if (LMDBAL_BUILD_DOXYGEN_AWESOME)
add_dependencies(documentation doxygen-awesome-css) add_dependencies(documentation doxygen-awesome-css)
endif() endif()

View file

@ -28,13 +28,13 @@
* \brief Database abstraction * \brief Database abstraction
* *
* This is a basic class that represents the database as a collection of storages. * This is a basic class that represents the database as a collection of storages.
* Storages is something key-value database has instead of tables in classic SQL databases. * Storages are something that key-value databases have instead of tables in classic SQL databases.
*/ */
/** /**
* \brief Creates the database * \brief Creates the database
* *
* \param[in] _name - name of the database, it is going to affect folder name that is created to store data * \param[in] _name - name of the database, it is going to affect the folder name that is created to store data
* \param[in] _mapSize - LMDB map size (MiB), multiplied by 1024^2 and passed to <a class="el" href="http://www.lmdb.tech/doc/group__mdb.html#gaa2506ec8dab3d969b0e609cd82e619e5">mdb_env_set_mapsize</a> during the call of LMDBAL::Base::open() * \param[in] _mapSize - LMDB map size (MiB), multiplied by 1024^2 and passed to <a class="el" href="http://www.lmdb.tech/doc/group__mdb.html#gaa2506ec8dab3d969b0e609cd82e619e5">mdb_env_set_mapsize</a> during the call of LMDBAL::Base::open()
*/ */
LMDBAL::Base::Base(const QString& _name, uint16_t _mapSize): LMDBAL::Base::Base(const QString& _name, uint16_t _mapSize):
@ -60,13 +60,13 @@ LMDBAL::Base::~Base() {
* \brief Closes the database * \brief Closes the database
* *
* Closes all lmdb handles, aborts all public transactions. * Closes all lmdb handles, aborts all public transactions.
* This function will do nothing on closed database * This function will do nothing on a closed database
* *
* \exception LMDBAL::Unknown - thrown if something went wrong aborting transactions * \exception LMDBAL::Unknown - thrown if something went wrong aborting transactions
*/ */
void LMDBAL::Base::close() { void LMDBAL::Base::close() {
if (opened) { if (opened) {
for (const std::pair<LMDBAL::TransactionID, LMDBAL::Transaction*> pair : transactions) { for (const std::pair<TransactionID, Transaction*> pair : transactions) {
abortTransaction(pair.first, emptyName); abortTransaction(pair.first, emptyName);
pair.second->reset(); pair.second->reset();
} }
@ -84,8 +84,8 @@ void LMDBAL::Base::close() {
* \brief Opens the database * \brief Opens the database
* *
* Almost every LMDBAL::Base require it to be opened, this function does it. * Almost every LMDBAL::Base require it to be opened, this function does it.
* It laso creates the directory for the database if it was an initial launch. * It also creates the directory for the database if it was an initial launch.
* This function will do nothing on opened database * This function will do nothing on an opened database
* *
* \exception LMDBAL::Unknown - thrown if something went wrong opening storages and caches * \exception LMDBAL::Unknown - thrown if something went wrong opening storages and caches
*/ */
@ -94,15 +94,14 @@ void LMDBAL::Base::open() {
mdb_env_create(&environment); mdb_env_create(&environment);
QString path = createDirectory(); QString path = createDirectory();
mdb_env_set_maxdbs(environment, storages.size()); mdb_env_set_maxdbs(environment, static_cast<MDB_dbi>(storages.size()));
mdb_env_set_mapsize(environment, size * 1024UL * 1024UL); mdb_env_set_mapsize(environment, size * 1024UL * 1024UL);
mdb_env_open(environment, path.toStdString().c_str(), 0, 0664); mdb_env_open(environment, path.toStdString().c_str(), 0, 0664);
TransactionID txn = beginPrivateTransaction(emptyName); TransactionID txn = beginPrivateTransaction(emptyName);
for (const std::pair<const std::string, StorageCommon*>& pair : storages) { for (const std::pair<const std::string, StorageCommon*>& pair : storages) {
StorageCommon* storage = pair.second; StorageCommon* storage = pair.second;
int rc = storage->open(txn); if (const int rc = storage->open(txn))
if (rc)
throw Unknown(name, mdb_strerror(rc)); throw Unknown(name, mdb_strerror(rc));
} }
commitPrivateTransaction(txn, emptyName); commitPrivateTransaction(txn, emptyName);
@ -113,9 +112,9 @@ void LMDBAL::Base::open() {
/** /**
* \brief Removes database directory * \brief Removes database directory
* *
* \returns true if removal was successfull of if no directory was created where it's expected to be, false otherwise * \returns true if removal was successful of if no directory was created where it's expected to be, false otherwise
* *
* \exception LMDBAL::Opened - thrown if this function was called on opened database * \exception LMDBAL::Opened - thrown if this function was called on an opened database
*/ */
bool LMDBAL::Base::removeDirectory() { bool LMDBAL::Base::removeDirectory() {
if (opened) if (opened)
@ -141,7 +140,7 @@ bool LMDBAL::Base::removeDirectory() {
* *
* \returns the path of the created directory * \returns the path of the created directory
* *
* \exception LMDBAL::Opened - thrown if called on opened database * \exception LMDBAL::Opened - thrown if called on an opened database
* \exception LMDBAL::Directory - if the database couldn't create the folder * \exception LMDBAL::Directory - if the database couldn't create the folder
*/ */
QString LMDBAL::Base::createDirectory() { QString LMDBAL::Base::createDirectory() {

View file

@ -48,7 +48,7 @@ template <class K, class V>
class Cache; class Cache;
typedef MDB_txn* TransactionID; /**<\brief I'm going to use transaction pointers as transaction IDs*/ typedef MDB_txn* TransactionID; /**<\brief I'm going to use transaction pointers as transaction IDs*/
typedef uint32_t SizeType; /**<\brief All LMDBAL sizes are uint32_t*/ typedef uint32_t SizeType; /**<\brief All LMDBAL sizes are uint32*/
class Base { class Base {
friend class StorageCommon; friend class StorageCommon;
@ -135,8 +135,8 @@ LMDBAL::Storage<K, V>* LMDBAL::Base::addStorage(const std::string& storageName,
if (opened) if (opened)
throw Opened(name, "add storage " + storageName); throw Opened(name, "add storage " + storageName);
Storage<K, V>* storage = new Storage<K, V>(this, storageName, duplicates); auto storage = new Storage<K, V>(this, storageName, duplicates);
std::pair<Storages::const_iterator, bool> pair = storages.insert(std::make_pair(storageName, (StorageCommon *)storage)); std::pair<Storages::const_iterator, bool> pair = storages.emplace(storageName, static_cast<StorageCommon *>(storage));
if (!pair.second) if (!pair.second)
throw StorageDuplicate(name, storageName); throw StorageDuplicate(name, storageName);
@ -163,8 +163,8 @@ LMDBAL::Cache<K, V> * LMDBAL::Base::addCache(const std::string& storageName) {
if (opened) if (opened)
throw Opened(name, "add cache " + storageName); throw Opened(name, "add cache " + storageName);
Cache<K, V>* cache = new Cache<K, V>(this, storageName, false); auto cache = new Cache<K, V>(this, storageName, false);
std::pair<Storages::const_iterator, bool> pair = storages.insert(std::make_pair(storageName, (StorageCommon *)cache)); std::pair<Storages::const_iterator, bool> pair = storages.emplace(storageName, static_cast<StorageCommon *>(cache));
if (!pair.second) if (!pair.second)
throw StorageDuplicate(name, storageName); throw StorageDuplicate(name, storageName);

View file

@ -114,7 +114,7 @@ T LMDBAL::Serializer<T>::deserialize(const MDB_val& value) {
template<class T> template<class T>
void LMDBAL::Serializer<T>::deserialize(const MDB_val& value, T& result) { void LMDBAL::Serializer<T>::deserialize(const MDB_val& value, T& result) {
clear(); clear();
bytes.setRawData((char*)value.mv_data, value.mv_size); bytes.setRawData(static_cast<char *>(value.mv_data), value.mv_size);
stream >> result; stream >> result;
} }
@ -154,7 +154,7 @@ MDB_val LMDBAL::Serializer<T>::getData() {
MDB_val val; MDB_val val;
val.mv_size = buffer.pos(); val.mv_size = buffer.pos();
val.mv_data = (char*)bytes.data(); val.mv_data = bytes.data();
return val; return val;
} }

View file

@ -34,7 +34,17 @@ public:
return value; return value;
}; };
void deserialize(const MDB_val& data, QByteArray& result) { void deserialize(const MDB_val& data, QByteArray& result) {
result.setRawData((char*)data.mv_data, data.mv_size); #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (data.mv_size > static_cast<size_t>(std::numeric_limits<qsizetype>::max()))
throw std::runtime_error("Data size exceeds QByteArray capacity");
result.setRawData(static_cast<char *>(data.mv_data), static_cast<qsizetype>(data.mv_size));
#else
if (data.mv_size > static_cast<size_t>(std::numeric_limits<uint>::max()))
throw std::runtime_error("Data size exceeds QByteArray capacity");
result.setRawData(static_cast<char *>(data.mv_data), static_cast<uint>(data.mv_size));
#endif
} }
MDB_val setData(const QByteArray& data) { MDB_val setData(const QByteArray& data) {
value = data; value = data;
@ -43,7 +53,7 @@ public:
MDB_val getData() { MDB_val getData() {
MDB_val result; MDB_val result;
result.mv_data = value.data(); result.mv_data = value.data();
result.mv_size = value.size(); result.mv_size = static_cast<size_t>(value.size());
return result; return result;
}; };
void clear() { void clear() {

View file

@ -31,11 +31,33 @@ public:
~Serializer() {}; ~Serializer() {};
QString deserialize(const MDB_val& data) { QString deserialize(const MDB_val& data) {
value = QByteArray((char*)data.mv_data, data.mv_size); #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (data.mv_size > static_cast<size_t>(std::numeric_limits<qsizetype>::max()))
throw std::runtime_error("Data size exceeds QByteArray capacity");
value = QByteArray(static_cast<char *>(data.mv_data), static_cast<qsizetype>(data.mv_size));
#else
if (data.mv_size > static_cast<size_t>(std::numeric_limits<int>::max()))
throw std::runtime_error("Data size exceeds QByteArray capacity");
value = QByteArray(static_cast<char *>(data.mv_data), static_cast<int>(data.mv_size));
#endif
return QString::fromUtf8(value); return QString::fromUtf8(value);
}; };
void deserialize(const MDB_val& data, QString& result) { void deserialize(const MDB_val& data, QString& result) {
value = QByteArray((char*)data.mv_data, data.mv_size); #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (data.mv_size > static_cast<size_t>(std::numeric_limits<qsizetype>::max()))
throw std::runtime_error("Data size exceeds QByteArray capacity");
value = QByteArray(static_cast<char *>(data.mv_data), static_cast<qsizetype>(data.mv_size));
#else
if (data.mv_size > static_cast<size_t>(std::numeric_limits<int>::max()))
throw std::runtime_error("Data size exceeds QByteArray capacity");
value = QByteArray(static_cast<char *>(data.mv_data), static_cast<int>(data.mv_size));
#endif
result = QString::fromUtf8(value); result = QString::fromUtf8(value);
} }
MDB_val setData(const QString& data) { MDB_val setData(const QString& data) {
@ -45,7 +67,7 @@ public:
MDB_val getData() { MDB_val getData() {
MDB_val result; MDB_val result;
result.mv_data = value.data(); result.mv_data = value.data();
result.mv_size = value.size(); result.mv_size = static_cast<size_t>(value.size());
return result; return result;
}; };
void clear() {}; //not possible; void clear() {}; //not possible;

View file

@ -34,7 +34,7 @@ public:
return value; return value;
}; };
void deserialize(const MDB_val& data, std::string& result) { void deserialize(const MDB_val& data, std::string& result) {
result.assign((char*)data.mv_data, data.mv_size); result.assign(static_cast<char *>(data.mv_data), data.mv_size);
} }
MDB_val setData(const std::string& data) { MDB_val setData(const std::string& data) {
value = data; value = data;
@ -42,7 +42,7 @@ public:
}; };
MDB_val getData() { MDB_val getData() {
MDB_val result; MDB_val result;
result.mv_data = (char*)value.c_str(); result.mv_data = const_cast<char *>(value.c_str());
result.mv_size = value.size(); result.mv_size = value.size();
return result; return result;
}; };

View file

@ -23,13 +23,13 @@
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
/** /**
* \class LMDBAL::iStorage * \class LMDBAL::StorageCommon
* *
* \brief Storage interface * \brief Storage interface
* *
* This is a interface-like class, it's designed to be an inner database interface to * This is an interface-like class, it's designed to be an inner database interface to
* be used as a polymorphic entity, and provide protected interaction with the database * be used as a polymorphic entity and provide protected interaction with the database
* from the heirs code * from the heir code
*/ */
/** /**
@ -49,7 +49,7 @@ LMDBAL::StorageCommon::StorageCommon(Base* parent, const std::string& name, bool
/** /**
* \brief Destroys a storage interface * \brief Destroys a storage interface
*/ */
LMDBAL::StorageCommon::~StorageCommon () {} LMDBAL::StorageCommon::~StorageCommon () = default;
/** /**
* \brief A private virtual function to close each storage in the database * \brief A private virtual function to close each storage in the database
@ -103,7 +103,7 @@ void LMDBAL::StorageCommon::drop() {
* *
* Just performs content drop * Just performs content drop
* *
* \param[in] transaction - transaction ID, must be writable transaction! * \param[in] transaction - transaction ID; must be writable transaction!
* \returns MDB_SUCCESS if everything went fine, MDB_<error> code otherwise * \returns MDB_SUCCESS if everything went fine, MDB_<error> code otherwise
*/ */
int LMDBAL::StorageCommon::drop(TransactionID transaction) { int LMDBAL::StorageCommon::drop(TransactionID transaction) {
@ -115,7 +115,7 @@ int LMDBAL::StorageCommon::drop(TransactionID transaction) {
* *
* Just performs content drop * Just performs content drop
* *
* \param[in] txn - transaction ID, must be writable transaction! * \param[in] txn - transaction ID; must be writable transaction!
* \returns MDB_SUCCESS if everything went fine, MDB_<error> code otherwise * \returns MDB_SUCCESS if everything went fine, MDB_<error> code otherwise
* *
* \exception LMDBAL::TransactionTerminated thrown if the transaction was not active * \exception LMDBAL::TransactionTerminated thrown if the transaction was not active
@ -126,7 +126,7 @@ int LMDBAL::StorageCommon::drop(const WriteTransaction& txn) {
} }
/** /**
* \brief Helper function, thows exception if the database is not opened * \brief Helper function; throws an exception if the database is not opened
* *
* \param[in] methodName - name of the method this function is called from, just for display in std::exception::what() message * \param[in] methodName - name of the method this function is called from, just for display in std::exception::what() message
* *
@ -140,7 +140,7 @@ void LMDBAL::StorageCommon::ensureOpened(const std::string& methodName) const {
/** /**
* \brief Storage size * \brief Storage size
* *
* \returns amount of records in the storage * \returns number of records in the storage
* *
* \exception LMDBAL::Closed thrown if the database was closed * \exception LMDBAL::Closed thrown if the database was closed
* \exception LMDBAL::Unknown thrown if something unexpected happened * \exception LMDBAL::Unknown thrown if something unexpected happened
@ -162,7 +162,7 @@ LMDBAL::SizeType LMDBAL::StorageCommon::count() const {
} }
/** /**
* \brief Retrieves public transaction object for a cursor handle * \brief Retrieves a public transaction object for a cursor handle
* *
* Cursor must be still opened by a public transaction * Cursor must be still opened by a public transaction
* *
@ -222,25 +222,27 @@ void LMDBAL::StorageCommon::closeCursorTransaction (MDB_cursor* cursor, bool clo
/** /**
* \brief Storage size (private transaction variant) * \brief Storage size (private transaction variant)
* *
* \param[in] txn - transaction ID, can be read-only transaction * \param[in] txn - transaction ID; can be read-only transaction
* \returns amount of records in the storage * \returns number of records in the storage
* *
* \exception LMDBAL::Unknown thrown if something unexpected happened * \exception LMDBAL::Unknown thrown if something unexpected happened
*/ */
LMDBAL::SizeType LMDBAL::StorageCommon::count(TransactionID txn) const { LMDBAL::SizeType LMDBAL::StorageCommon::count(TransactionID txn) const {
MDB_stat stat; MDB_stat stat;
int rc = mdb_stat(txn, dbi, &stat); if (const int rc = mdb_stat(txn, dbi, &stat); rc != MDB_SUCCESS)
if (rc != MDB_SUCCESS)
throw Unknown(db->name, mdb_strerror(rc), name); throw Unknown(db->name, mdb_strerror(rc), name);
return stat.ms_entries; if (stat.ms_entries > std::numeric_limits<SizeType>::max())
throw Unknown(db->name, "Storage size exceeds it's limits", name);
return static_cast<SizeType>(stat.ms_entries);
} }
/** /**
* \brief Storage size (public transaction variant) * \brief Storage size (public transaction variant)
* *
* \param[in] txn - transaction, can be read-only transaction * \param[in] txn - transaction; can be read-only transaction
* \returns amount of records in the storage * \returns number of records in the storage
* *
* \exception LMDBAL::Closed thrown if the database was closed * \exception LMDBAL::Closed thrown if the database was closed
* \exception LMDBAL::Unknown thrown if something unexpected happened * \exception LMDBAL::Unknown thrown if something unexpected happened

View file

@ -19,7 +19,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <stdint.h> #include <cstdint>
#include <lmdb.h> #include <lmdb.h>