mattreecebentley / plf_colony

An unordered C++ data container providing fast iteration/insertion/erasure while maintaining pointer/iterator validity to non-erased elements regardless of insertions/erasures. Provides higher-performance than std:: library containers for high-modification scenarios with unordered data.
https://plflib.org/colony.htm
zlib License
398 stars 33 forks source link

Support for disabled exceptions #50

Closed sunnlok closed 1 year ago

sunnlok commented 1 year ago

Right now exceptions are a fixed part of plf_colony, but many projects have exceptions disabled, especially games. This obviously means that plf_colony will not compile. I was wondering if there was any interest in supporting users that have disabled exceptions via macros for/around try, catch and throw? The length_errors could also be handled via asserts in those cases as well.

Was this a deliberate choice or just never considered? If its deliberate, modifying the source to fit the use case is obviously a valid solution as well, just makes integrating new versions slightly more work.

mattreecebentley commented 1 year ago

My understanding is that if exceptions are disabled, then the code will compile, but the compiler will not include the code in the catch blocks, or throw statements. Otherwise games which don't use exceptions wouldn't work with anything that did, including STD:: stuff and OS stuff. Obviously the upshot of what this means is going to vary from compiler to compiler, as disabling exceptions is outside of the C++ standard behaviour, see here: https://stackoverflow.com/questions/943087/what-exactly-will-happen-if-i-disable-c-exceptions-in-a-project for MSVC and here: https://stackoverflow.com/questions/45935978/what-happens-when-code-that-throws-exceptions-is-linked-against-a-library-compil for GCC.

As long as the user doesn't do anything stupid (over-allocate memory, etc) in colony they won't encounter exceptions. If they do, there is no way of handling these with error codes instead as allocator_traits::construct doesn't have a return value, only exceptions, and it is required for allocator support, so malloc etc aren't appropriate.

If you've got a specific compiler/situation where colony is causing problems in this scenario (exceptions turned off) please tell me and I'll look into it.

[UPDATE: okay, compiled with -fno-exceptions under GCC shows me the problem, at least for GCC. Will look into it. GCC has the __EXCEPTIONS flag, possibly clang as well, I think MSVC compiles exceptions code fine when exceptions are disabled, but will have to check]

sunnlok commented 1 year ago

Thank you for the quick answer and sorry for not providing more info... Not sure why i forgot that. Yes the error only seems to appear under gcc/clang.

cannot use 'try'/'throw with exceptions disabled for clang and plf_colony.h:1090:17: error: exception handling disabled, use ���-fexceptions��� to enable catch (...) for gcc Msvc builds fine on all platforms.

Afaik the stl solves this internally via macros

mattreecebentley commented 1 year ago

Ah, that's interesting. Okay, will fix.

sunnlok commented 1 year ago

Aweseom! Thanks! Another unrelated issue: The constructor for colony_data under visual studio 2017 seems to confuse its argument size_type with the one from the allocator it inherits from for... some reason, causing a warning about accessing deprecated members of allocators. The allocator traits define seems to not affect it. Changing it to colony::size_type seemed to fix it.

mattreecebentley commented 1 year ago

Both fixed now, thanks-

AIIleG commented 11 months ago

Hi,

compiling with exceptions disabled didn't work for me:

"plf_colony.h", line 1460: error: support for exception handling is disabled

This happens with the github checkout from just a few minutes ago as well as the homepage download from 2 hours ago.

AIIleG commented 11 months ago

I had a look and it seems the problem was introduced in https://github.com/mattreecebentley/plf_colony/commit/0acfca7a737129a08d0ebd9a2a83da2866e14ff7

mattreecebentley commented 11 months ago

Fixed now, thanks :)