Giter VIP home page Giter VIP logo

awl's Introduction

Awl

AWL - A Working Library

AWL is a small cross-platform C++ library that includes:

  1. A simple binary serialization framework.
  2. Memory stream, buffered stream, hashing stream.
  3. A set that finds an element by both key and index with O(logN) time.
  4. A doubly linked list with static insert and erase methods.
  5. An observable with movable observers.
  6. A pool of reusable objects managed with std::shared_ptr.
  7. Bitset based on enum.
  8. A circular buffer with an interface similar to std::queue.
  9. Other simple classes like CompositeCompare, ReverseCompare, scope_guard, etc...
  10. A simple testing framework.

Theoretically, the master branch should compile with C++20 and work, at least it is periodically built with MSVC 19.37.32825, GCC 12.3.0, Android CLang 17.0.2 and Apple Clang 15.0.0.

There is also cpp17 branch that partially compiles with C++17.

Version compatibility is not guaranteed and there is no warranty of any kind.

Feel free to use it or fork it, report a bug by opening an issue.

To leave the author a message fill the form on his website.

Compiling on Windows with CMake and MSVC 2022:

cmake ..\..\Awl -G "Visual Studio 17 2022" -A x64
cmake --build . --target AwlTest --config Release

or

msbuild AwlTest.sln /p:Configuration=Release /p:Platform=x64

It also builds for x86 using the following command:

cmake ..\..\Awl -G "Visual Studio 17 2022" -A win32

but with couple warnings related to std::streamsize that are not fixed yet.

Compiling on Linux with CMake and GCC:

cmake ../../Awl/ -DCMAKE_BUILD_TYPE=Release
cmake --build . --parallel

or

cmake ../../Awl/ -DCMAKE_BUILD_TYPE=Debug
cmake --build . --parallel

Compiling on Ubuntu 22.04:

sudo apt install build-essential
sudo apt install cmake

mkdir repos
cd repos
git clone https://github.com/dmitriano/Awl
mkdir -p build/awl
cd build/awl
cmake ../../Awl/ -DCMAKE_BUILD_TYPE=Release
cmake --build . --parallel

Compiling with Ninja generator

cmake ../../repos/Awl/ -G Ninja
cmake --build . --parallel --target AwlTest --config RelWithDebInfo

Compiling a separate source file (by example of VtsTest.cpp):

cmake --build . --parallel --target CMakeFiles/AwlTest.dir/Tests/VtsTest.cpp.o

Using GCC sanitizer

To enable GCC sanitizer uncomment corresponding lines in CMake\AwlConfig.cmake.

Running the tests on Windows and Linux

Remove ./ prefix on Windows and do not forget quotes on Linux:

./AwlTest

of

./AwlTest --filter ".*_Test"

Running the benchmarks:

./AwlTest --filter ".*_Benchmark" --output all

Running the examples:

./AwlTest --filter ".*_Example" --output all

Do not run the commands below:

./AwlTest --filter ".*_Unstable"

or

./AwlTest --filter ".*"

they potentially can format your hard drive.

Running the tests on Android device

Built AWL for Android with -DAWL_STATIC_RUNTIME:BOOL=ON CMake option, upload the executable file to the device:

adb push AwlTest /data/local/tmp

and run it with the same options as on Linux:

adb shell
cd /data/local/tmp
chmod a+x AwlTest
./AwlTest

or with a single command:

adb shell "cd /data/local/tmp && chmod a+x AwlTest && ./AwlTest"

or

adb shell "cd /data/local/tmp && chmod a+x AwlTest && ./AwlTest --filter .*CompositeCompare.*"

awl's People

Contributors

dmitriano avatar

Stargazers

 avatar  avatar  avatar  avatar

Forkers

mediabuff

awl's Issues

GCC sanitizer reports incorrect downcast error in Awl/SingleList.h

GCC with -fsanitize=undefined reports the following:

Awl/SingleList.h:250:23: runtime error: downcast of address 0x000002a33fe0 which does not point to an object of type 'Observer'
0x000002a33fe0: note: object has invalid vptr
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^~~~~~~~~~~~~~~~~~~~~~~
invalid vptr

in function:

T * null() { return (T *)&Null; }

Replace std::size_t with std::streamsize in StdStream.h

Building AWL with QT for x86:

cmake.exe C:\dev\repos\Awl -G %MY_VS_GENERATOR% -DCMAKE_PREFIX_PATH=C:/dev/libs/QT5-msvc -A win32

StdStream.h(28,57): warning C4244: ‘initializing’: conversion from ‘std::streamsize’ to ‘size_t’, possible loss of data (compiling source file C:\dev\repos\Awl\Tests\HashStreamTest.cpp)

Probably make quick_list destructor exclude all the elements.

It is not clear enough how its move assignment operator should work

    quick_list& operator = (quick_list&& other) noexcept
    {
        if (this != &other)
        {
            //quick_list cannot free its resources, so it is supposed to be empty
            assert(empty());
            attach(other);
        }
        return *this;
    }

Alternatively, it probably excludes its null element.

Fix data race in Cancellation_InterruptibleSleep_Example

image

GCC reports "double lock of a mutex" because InterruptibleSleep is called on multiple threads:

    void InterruptibleSleep(std::chrono::nanoseconds time) const override
    {
        std::unique_lock lock(m_mutex);

        m_cv.wait_for(lock, time, [this]() -> bool
        {
            return isCancelled;
        });
    }

see
https://stackoverflow.com/a/68098941/2394762

template<typename _Rep, typename _Period>
void sleep_for(const std::chrono::duration<_Rep, _Period>& dur, const std::stop_token& stoken)
{
    std::condition_variable cv;
    std::mutex mutex_;
    std::unique_lock<std::mutex> ul_ {mutex_};
    std::stop_callback stop_wait {stoken, [&cv](){ cv.notify_one(); }};
    cv.wait_for(ul_, dur, [&stoken](){ return stoken.stop_requested(); });
}

https://en.cppreference.com/w/cpp/thread/stop_callback
https://en.cppreference.com/w/cpp/thread/stop_token

Array subscript -N is outside array bounds warning in GCC11

While compiling with GCC11 I get a lot of warnings like

/home/def/repos/Awl/Tests/ListTest.cpp:118:70: warning: array subscript 0 is outside array bounds of ‘{anonymous}::ListHolder<awl::quick_link> [1]’ [-Warray-bounds] 118 | for (typename ELEMENT_LIST::iterator i = list.begin(); i != list.end(); ++i)

GCC11 thinks that I dereference a pointer to an object that does not exist.

I published brunch gcc-warn that demonstrates a strange effect: commenting line 114 in ListTest.cpp affects the warning somehow.

And tried to publish a GCC bug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.