summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2023-02-11 14:48:17 +0100
committerAndre Weissflog <floooh@gmail.com>2023-02-11 14:48:17 +0100
commitfe9032490603a999ce4e87b9aa4a7312b45267e7 (patch)
tree928d2d75307aab8886fbfa6041d299eba2387f48
parent7ad6e379597dadc76314a521bd064139f0d70cb3 (diff)
sokol_app.h: use _SAPP_PANIC() for failed allocations
-rw-r--r--sokol_app.h82
1 files changed, 42 insertions, 40 deletions
diff --git a/sokol_app.h b/sokol_app.h
index dc288db2..880ef902 100644
--- a/sokol_app.h
+++ b/sokol_app.h
@@ -2799,46 +2799,6 @@ typedef struct {
} _sapp_t;
static _sapp_t _sapp;
-// ███ ███ ███████ ███ ███ ██████ ██████ ██ ██
-// ████ ████ ██ ████ ████ ██ ██ ██ ██ ██ ██
-// ██ ████ ██ █████ ██ ████ ██ ██ ██ ██████ ████
-// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-// ██ ██ ███████ ██ ██ ██████ ██ ██ ██
-//
-// >>memory
-_SOKOL_PRIVATE void _sapp_clear(void* ptr, size_t size) {
- SOKOL_ASSERT(ptr && (size > 0));
- memset(ptr, 0, size);
-}
-
-_SOKOL_PRIVATE void* _sapp_malloc(size_t size) {
- SOKOL_ASSERT(size > 0);
- void* ptr;
- if (_sapp.desc.allocator.alloc) {
- ptr = _sapp.desc.allocator.alloc(size, _sapp.desc.allocator.user_data);
- }
- else {
- ptr = malloc(size);
- }
- SOKOL_ASSERT(ptr);
- return ptr;
-}
-
-_SOKOL_PRIVATE void* _sapp_malloc_clear(size_t size) {
- void* ptr = _sapp_malloc(size);
- _sapp_clear(ptr, size);
- return ptr;
-}
-
-_SOKOL_PRIVATE void _sapp_free(void* ptr) {
- if (_sapp.desc.allocator.free) {
- _sapp.desc.allocator.free(ptr, _sapp.desc.allocator.user_data);
- }
- else {
- free(ptr);
- }
-}
-
// ██ ██████ ██████ ██████ ██ ███ ██ ██████
// ██ ██ ██ ██ ██ ██ ████ ██ ██
// ██ ██ ██ ██ ███ ██ ███ ██ ██ ██ ██ ██ ███
@@ -2878,6 +2838,48 @@ static void _sapp_log(sapp_log_item log_item, uint32_t log_level, const char* ms
}
}
+// ███ ███ ███████ ███ ███ ██████ ██████ ██ ██
+// ████ ████ ██ ████ ████ ██ ██ ██ ██ ██ ██
+// ██ ████ ██ █████ ██ ████ ██ ██ ██ ██████ ████
+// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
+// ██ ██ ███████ ██ ██ ██████ ██ ██ ██
+//
+// >>memory
+_SOKOL_PRIVATE void _sapp_clear(void* ptr, size_t size) {
+ SOKOL_ASSERT(ptr && (size > 0));
+ memset(ptr, 0, size);
+}
+
+_SOKOL_PRIVATE void* _sapp_malloc(size_t size) {
+ SOKOL_ASSERT(size > 0);
+ void* ptr;
+ if (_sapp.desc.allocator.alloc) {
+ ptr = _sapp.desc.allocator.alloc(size, _sapp.desc.allocator.user_data);
+ }
+ else {
+ ptr = malloc(size);
+ }
+ if (0 == ptr) {
+ _SAPP_PANIC(MALLOC_FAILED);
+ }
+ return ptr;
+}
+
+_SOKOL_PRIVATE void* _sapp_malloc_clear(size_t size) {
+ void* ptr = _sapp_malloc(size);
+ _sapp_clear(ptr, size);
+ return ptr;
+}
+
+_SOKOL_PRIVATE void _sapp_free(void* ptr) {
+ if (_sapp.desc.allocator.free) {
+ _sapp.desc.allocator.free(ptr, _sapp.desc.allocator.user_data);
+ }
+ else {
+ free(ptr);
+ }
+}
+
// ██ ██ ███████ ██ ██████ ███████ ██████ ███████
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
// ███████ █████ ██ ██████ █████ ██████ ███████