| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-03-08 20:40:03 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-03-09 03:24:35 UTC |
| parent | d31d64eb9b3c00ac2cc7aad866aed69ce732a261 |
| Sources/c_borogove/iinclude/CrashHandler.h | +17 | -0 |
| Sources/c_borogove/iinclude/sys/db/Connection.h | +7 | -1 |
| Sources/c_borogove/src/CrashHandler.mm | +20 | -0 |
diff --git a/Sources/c_borogove/iinclude/CrashHandler.h b/Sources/c_borogove/iinclude/CrashHandler.h new file mode 100644 index 0000000..4b67ece --- /dev/null +++ b/Sources/c_borogove/iinclude/CrashHandler.h @@ -0,0 +1,17 @@ +#pragma once +#include <string> +#include <cstdio> + +namespace AppCore { + [[noreturn]] void TerminateWithMessage(const std::string& message); +} + +#define myassert(cond) \ + do { \ + if (!(cond)) { \ + char buffer[1024]; \ + snprintf(buffer, sizeof(buffer), "ASSERT FAILED: %s (%s:%d)", \ + #cond, __FILE__, __LINE__); \ + AppCore::TerminateWithMessage(buffer); \ + } \ + } while(0) diff --git a/Sources/c_borogove/iinclude/sys/db/Connection.h b/Sources/c_borogove/iinclude/sys/db/Connection.h index eb1d8c6..35cf126 100644 --- a/Sources/c_borogove/iinclude/sys/db/Connection.h +++ b/Sources/c_borogove/iinclude/sys/db/Connection.h @@ -6,6 +6,8 @@ #include <hxcpp.h> #endif +#include <CrashHandler.h> + HX_DECLARE_CLASS2(sys,db,Connection) HX_DECLARE_CLASS2(sys,db,ResultSet) @@ -20,7 +22,11 @@ class HXCPP_CLASS_ATTRIBUTES Connection_obj { ::Dynamic (::hx::Object :: *_hx_request)(::String s); static inline ::Dynamic request( ::Dynamic _hx_,::String s) { - return (_hx_.mPtr->*( ::hx::interface_cast< ::sys::db::Connection_obj *>(_hx_.mPtr->_hx_getInterface(0x6e7a3d49)))->_hx_request)(s); + myassert(_hx_.mPtr); + myassert(s); + auto interf = ::hx::interface_cast< ::sys::db::Connection_obj *>(_hx_.mPtr->_hx_getInterface(0x6e7a3d49)); + myassert(interf); + return (_hx_.mPtr->*(interf)->_hx_request)(s); } }; diff --git a/Sources/c_borogove/src/CrashHandler.mm b/Sources/c_borogove/src/CrashHandler.mm new file mode 100644 index 0000000..f5c5855 --- /dev/null +++ b/Sources/c_borogove/src/CrashHandler.mm @@ -0,0 +1,20 @@ +#include "CrashHandler.h" +#import <Foundation/Foundation.h> + +namespace AppCore { + + void TerminateWithMessage(const std::string& message) { + // Convert the C++ std::string to an Objective-C NSString + NSString *nsMessage = [NSString stringWithUTF8String:message.c_str()]; + + // Create an NSException. + // The 'name' categorizes it, and the 'reason' is what TestFlight will show. + NSException *exception = [NSException exceptionWithName:@"FatalCppError" + reason:nsMessage + userInfo:nil]; + + // Throw the exception to terminate the app + [exception raise]; + } + +}