An emulator, assembler, and disassembler for the Sega Game Gear
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
1.5 KiB

  1. /* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. Released under the terms of the MIT License. See LICENSE for details. */
  3. #pragma once
  4. #include <stddef.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include "logging.h"
  8. #define OUT_OF_MEMORY() FATAL("couldn't allocate enough memory")
  9. #define OOM_GUARD_(type, call) \
  10. type ptr = call; \
  11. if (!ptr) \
  12. OUT_OF_MEMORY() \
  13. return ptr;
  14. #define OOM_GUARD_FUNC_1_(ret_type, func, arg_type) \
  15. static inline ret_type cr_##func(arg_type arg1) { \
  16. OOM_GUARD_(ret_type, func(arg1)) \
  17. }
  18. #define OOM_GUARD_FUNC_2_(ret_type, func, arg1_type, arg2_type) \
  19. static inline ret_type cr_##func(arg1_type arg1, arg2_type arg2) { \
  20. OOM_GUARD_(ret_type, func(arg1, arg2)) \
  21. }
  22. /* Functions */
  23. OOM_GUARD_FUNC_1_(void*, malloc, size_t) // cr_malloc
  24. OOM_GUARD_FUNC_2_(void*, calloc, size_t, size_t) // cr_calloc
  25. OOM_GUARD_FUNC_2_(void*, realloc, void*, size_t) // cr_realloc
  26. OOM_GUARD_FUNC_1_(char*, strdup, const char*) // cr_strdup
  27. OOM_GUARD_FUNC_2_(char*, strndup, const char*, size_t) // cr_strndup
  28. #undef OOM_GUARD_FUNC2_
  29. #undef OOM_GUARD_FUNC1_
  30. #undef OOM_GUARD_