From: ljsebald <ljs...@us...> - 2023-12-04 12:38:00
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 4ea251487dfe5dcbe2fa47cbd434fea4d209703d (commit) via 5b76dda7c21805b6e4b2f030ceb8f9c57133ef35 (commit) from 8d98948f2b6dfc9aedd8a1edd6fb209f300403ff (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 4ea251487dfe5dcbe2fa47cbd434fea4d209703d Merge: 8d98948 5b76dda Author: Lawrence Sebald <ljs...@us...> Date: Mon Dec 4 07:37:37 2023 -0500 Merge pull request #405 from KallistiOS/out_of_memory_update Updated out_of_memory KOS example commit 5b76dda7c21805b6e4b2f030ceb8f9c57133ef35 Author: Falco Girgis <gyr...@gm...> Date: Mon Dec 4 00:35:43 2023 -0600 Updated out_of_memory KOS example - Using standard return values - Printing success/error properly now at the end - Added copyright information + description ----------------------------------------------------------------------- Summary of changes: .../dreamcast/cpp/out_of_memory/out_of_memory.cc | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/examples/dreamcast/cpp/out_of_memory/out_of_memory.cc b/examples/dreamcast/cpp/out_of_memory/out_of_memory.cc index 14974dd..f0e9593 100644 --- a/examples/dreamcast/cpp/out_of_memory/out_of_memory.cc +++ b/examples/dreamcast/cpp/out_of_memory/out_of_memory.cc @@ -1,3 +1,16 @@ +/* KallistiOS ##version## + + out_of_memory.cc + Copyright (C) 2023 Falco Girgis + +*/ + +/* + This is a simple example of how to gracefully handle running + out of memory in C++ with both a static handler and exceptions. + The same applies for C, except that malloc() will return NULL. +*/ + #include <vector> #include <iostream> #include <cstdint> @@ -7,7 +20,11 @@ KOS_INIT_FLAGS(INIT_MALLOCSTATS); -void new_handler_cb() { +static unsigned new_handler_counter = 0; + +static void new_handler_cb() { + ++new_handler_counter; + std::cout << "new_handler callback invoked!" << std::endl; malloc_stats(); @@ -60,7 +77,15 @@ int main(int argc, char **argv) { } } - std::cout << "All done. Thank you for the RAM!" << std::endl; + const bool success = failed_once && (new_handler_counter == 1); + + if(success) { + std::cout << "\n\nTEST SUCCESS! Thank you for the RAM!\n\n" << std::endl; + return EXIT_SUCCESS; + } + else { + std::cerr << "\n\nTEST FAILURE!\n\n"; + return EXIT_FAILURE; + } - return !failed_once; } hooks/post-receive -- A pseudo Operating System for the Dreamcast. |