Added ntassert() mechanism for Windows based port use.
This commit is contained in:
@@ -246,4 +246,14 @@ extern int FDECL(set_win32_option, (const char *, const char *));
|
||||
extern int FDECL(alternative_palette, (char *));
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define ntassert(expression) ((void)0)
|
||||
#else
|
||||
extern void FDECL(ntassert_failed, (const char * exp, const char * file,
|
||||
int line));
|
||||
|
||||
#define ntassert(expression) (void)((!!(expression)) || \
|
||||
(ntassert_failed(#expression, __FILE__, __LINE__), 0))
|
||||
#endif
|
||||
|
||||
#endif /* NTCONF_H */
|
||||
|
||||
@@ -322,6 +322,10 @@ static void check_buffer_size(int width, int height)
|
||||
|
||||
static cell_t * buffer_get_cell(console_buffer_t * buffer, int x, int y)
|
||||
{
|
||||
ntassert(x >= 0 && x < buffer_width);
|
||||
ntassert(y >= 0 && ((y < buffer_height) ||
|
||||
(y == buffer_height && x == 0)));
|
||||
|
||||
return buffer->cells + (buffer_width * y) + x;
|
||||
}
|
||||
|
||||
@@ -363,6 +367,9 @@ static void back_buffer_flip()
|
||||
static void buffer_fill_to_end(console_buffer_t * buffer, cell_t * src,
|
||||
int x, int y)
|
||||
{
|
||||
ntassert(x >= 0 && x < buffer_width);
|
||||
ntassert(y >= 0 && y < buffer_height);
|
||||
|
||||
cell_t * dst = buffer_get_cell(buffer, x, y);
|
||||
cell_t * sentinel = buffer_get_cell(buffer, 0, buffer_height);
|
||||
while (dst != sentinel)
|
||||
@@ -374,6 +381,9 @@ static void buffer_fill_to_end(console_buffer_t * buffer, cell_t * src,
|
||||
|
||||
static void back_buffer_write(cell_t * cell, int x, int y)
|
||||
{
|
||||
ntassert(x >= 0 && x < buffer_width);
|
||||
ntassert(y >= 0 && y < buffer_height);
|
||||
|
||||
cell_t * dst = buffer_get_cell(&back_buffer, x, y);
|
||||
*dst = *cell;
|
||||
|
||||
@@ -383,6 +393,9 @@ static void back_buffer_write(cell_t * cell, int x, int y)
|
||||
|
||||
static void back_buffer_clear_to_end_of_line(int x, int y)
|
||||
{
|
||||
ntassert(x >= 0 && x < buffer_width);
|
||||
ntassert(y >= 0 && y < buffer_height);
|
||||
|
||||
cell_t * cell;
|
||||
cell_t *sentinel;
|
||||
|
||||
@@ -834,6 +847,9 @@ int in_ch;
|
||||
void
|
||||
cl_end()
|
||||
{
|
||||
ntassert(ttyDisplay->curx >= 0 && ttyDisplay->curx < buffer_width);
|
||||
ntassert(ttyDisplay->cury >= 0 && ttyDisplay->cury < buffer_height);
|
||||
|
||||
console.cursor.X = ttyDisplay->curx;
|
||||
console.cursor.Y = ttyDisplay->cury;
|
||||
|
||||
|
||||
@@ -461,6 +461,21 @@ char *buf;
|
||||
}
|
||||
#endif /* RUNTIME_PORT_ID */
|
||||
|
||||
/* ntassert_failed is called when an ntassert's condition is false */
|
||||
void ntassert_failed(const char * exp, const char * file, int line)
|
||||
{
|
||||
char message[128];
|
||||
_snprintf(message, sizeof(message),
|
||||
"NHASSERT(%s) in '%s' at line %d\n", exp, file, line);
|
||||
|
||||
if (IsDebuggerPresent()) {
|
||||
OutputDebugStringA(message);
|
||||
DebugBreak();
|
||||
}
|
||||
|
||||
error(message);
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
/*winnt.c*/
|
||||
|
||||
Reference in New Issue
Block a user