Skip to content

Commit

Permalink
xbox: Replace assert() with system-specific version
Browse files Browse the repository at this point in the history
  • Loading branch information
thrimbor committed Oct 1, 2019
1 parent ae5c0a3 commit 18e3b16
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 121 deletions.
71 changes: 0 additions & 71 deletions functions/_PDCLIB/assert.c

This file was deleted.

50 changes: 0 additions & 50 deletions include/assert.h

This file was deleted.

19 changes: 19 additions & 0 deletions platform/xbox/functions/assert/assert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <assert.h>
#include <debug.h>
#include <stdlib.h>
#include "xboxkrnl/xboxkrnl.h"

void _xbox_assert(char const * const expression, char const * const file_name, char const * const function_name, unsigned long line)
{
#ifdef DEBUG_CONSOLE
char buffer[512];
snprintf(buffer, 512, "In function '%s': ", function_name);
RtlAssert((PVOID)expression, (PVOID)file_name, line, buffer);
#else
debugPrint("\nAssertion failed: '%s' in function '%s', file '%s', line %u\n", expression, function_name, file_name, line);
__asm__ ("cli\n"
".l:\n"
"hlt\n"
"jmp .l\n");
#endif
}
39 changes: 39 additions & 0 deletions platform/xbox/include/assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Diagnostics <assert.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/

#include "pdclib/_PDCLIB_aux.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifndef _PDCLIB_ASSERT_H
#define _PDCLIB_ASSERT_H
void _xbox_assert(char const * const expression, char const * const file_name, char const * const function_name, unsigned long line);
#endif

/* If NDEBUG is set, assert() is a null operation. */
#undef assert

#ifdef NDEBUG
#define assert(ignore) ((void)0)
#else
#define assert(expression) \
do { \
if(!(expression)) { \
_xbox_assert(_PDCLIB_symbol2string(expression), \
__FILE__, \
__func__, \
__LINE__); \
} \
} while(0)
#endif

#define static_assert _Static_assert

#ifdef __cplusplus
}
#endif

0 comments on commit 18e3b16

Please sign in to comment.