assert.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. /**
  3. * @brief Solana assert and panic utilities
  4. */
  5. #include <sol/types.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /**
  10. * Panics
  11. *
  12. * Prints the line number where the panic occurred and then causes
  13. * the SBF VM to immediately halt execution. No accounts' data are updated
  14. */
  15. /* DO NOT MODIFY THIS GENERATED FILE. INSTEAD CHANGE platform-tools-sdk/sbf/c/inc/sol/inc/assert.inc AND RUN `cargo run --bin gen-headers` */
  16. #ifndef SOL_SBFV2
  17. void sol_panic_(const char *, uint64_t, uint64_t, uint64_t);
  18. #else
  19. typedef void(*sol_panic__pointer_type)(const char *, uint64_t, uint64_t, uint64_t);
  20. static void sol_panic_(const char * arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4) {
  21. sol_panic__pointer_type sol_panic__pointer = (sol_panic__pointer_type) 1751159739;
  22. sol_panic__pointer(arg1, arg2, arg3, arg4);
  23. }
  24. #endif
  25. #define sol_panic() sol_panic_(__FILE__, sizeof(__FILE__), __LINE__, 0)
  26. /**
  27. * Asserts
  28. */
  29. #define sol_assert(expr) \
  30. if (!(expr)) { \
  31. sol_panic(); \
  32. }
  33. #ifdef SOL_TEST
  34. /**
  35. * Stub functions when building tests
  36. */
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. void sol_panic_(const char *file, uint64_t len, uint64_t line, uint64_t column) {
  40. printf("Panic in %s at %d:%d\n", file, line, column);
  41. abort();
  42. }
  43. #endif
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. /**@}*/