Go to file
David Anderson 7a3e4054c7 Enable exception handling in C++ code.
It turns out this was already enabled on MSVC (due to /EHsc), but let's
enable it on other platforms as well.

Exception handling comes with a huge caveat: SourceMod and SourcePawn
are not exception safe. Not only do they predate usable STL (C++11),
they often predate C++03, and sometimes even C++ itself. There are many
places we do not use RAII, or where we accumulate state in a way that
cannot be interrupted.

By enabling exceptions, we are NOT inviting general try/catch. We are
still assuming that a `throw` anywhere within SourceMod will ultimately
result in a crash.

However, as we enable more and more STL, we are losing the ability to
gracefully handle constructor failures and malloc failures. So try-catch
is now enabled. It should only be used in the narrowest of
circumstances:

 - When an exception can be thrown by a library call, and
 - There is no way "a priori" to tell if an exception will be thrown
(for example, std::bad_alloc or std::system_error), and
 - Handling the exception is meaningful.

Generally malloc failures should not be considered meaningful. Once
memory is exhausted, the program will crash or be OOM-killed, so there's
no point in handling the failure. However, cases where the allocation
amount is variable may be meaningful to handle. A simple example would
be CDataPack, where if a plugin leaks entries, it's better to handle
this gracefully given that vector growth is geometric. Another example
might be reads of a massive file or network request into a buffer.

These cases should be rare, given that memory pressure is usually
fatal to srcds anyway. But if you've decided to handle an exception,
the try-catch block should be as narrow as possible. For example,
the following is erroneous:

    ke::Maybe<SomeGiganticThing> object;
    try {
        object.init();
    } catch (const std::bad_alloc&) {
    }

`ke::Maybe` is not threadsafe, and this can leak. Basically, do as
little as possible in try blocks, and use them sparingly, because
they're very difficult to audit.

We are also not inviting use of `throw`, as auditing it is even more
complex than try/catch. It is better to abort(), or use boolean
returns and two-stage object initialization.
2020-05-19 12:21:57 -07:00
.github Create FUNDING.yml 2019-05-27 17:15:04 +01:00
bridge/include Rename ke::Lambda to ke::Function. 2020-05-17 12:33:52 -07:00
configs Allow setting multiple chat trigger characters (PR #449, bug 4341, bug 5668) 2016-10-04 16:34:42 +01:00
core Update AMTL; replace AutoPtr/UniquePtr with STL. 2020-05-18 18:19:16 -07:00
editor Added AMXX Pawn geshi generation script. 2010-08-23 13:53:44 -04:00
extensions Replace all uses of AMTL threads with STL threads. 2020-05-16 22:35:56 -07:00
gamedata Fix GetDataDescMap not work on Day Of Infamy (#1263) 2020-05-07 12:20:29 +01:00
licenses Fix quote mismatch (#1092) 2019-09-30 22:43:18 -07:00
loader Revert "Remove arch loops from build scripts. (#889)" 2018-10-04 17:59:40 +00:00
plugins Add an array operations to CDataPack (#1219) 2020-05-08 15:23:48 -07:00
public Update AMTL; replace AutoPtr/UniquePtr with STL. 2020-05-18 18:19:16 -07:00
sourcepawn@2075605089 Update AMTL; replace AutoPtr/UniquePtr with STL. 2020-05-18 18:19:16 -07:00
tools Improve Travis coverage. 2020-05-13 19:09:20 -07:00
translations Standardize some spacing in translation phrases (#1254) 2020-05-08 14:55:05 -07:00
versionlib 64-bit support for CSGO on Linux and macOS (#705) 2017-12-20 01:56:23 -06:00
.arcconfig Add a .arcconfig file so that arc works 2013-10-15 22:57:59 +01:00
.gitattributes NPOTB: Correct GitHub's Linguist inaccuracies (#1096) 2019-10-07 19:14:09 +01:00
.gitignore Update to the latest SourcePawn revision. 2015-08-18 09:51:24 -07:00
.gitmodules Use upstream SourcePawn as a submodule. 2015-03-15 16:38:38 -07:00
.travis.yml Improve Travis coverage. 2020-05-13 19:09:20 -07:00
AMBuildScript Enable exception handling in C++ code. 2020-05-19 12:21:57 -07:00
changelog.txt Triggering a build. 2011-04-13 19:05:41 -05:00
configure.py Add an option to build against no SDKs (#1201) 2020-03-04 21:52:07 +00:00
product.version Bump version to 1.11. 2019-10-18 21:07:36 -07:00
pushbuild.txt Trigger build for hl2sdk-csgo update. 2019-03-28 20:00:20 -04:00
README.md Incorperate Licensing Into Project Tree (#961) 2019-04-12 12:10:13 -07:00

SourceMod

General

Development

Contact

  • Connect with us on GameSurge IRC in #sourcemod
  • Alternatively feel free to join our Discord server

License

SourceMod is licensed under the GNU General Public License version 3. Special exceptions are outlined in the LICENSE.txt file inside of the licenses folder.