Convert usages of errx to h_platform_errx
This BSD call will have to be implemented on windows. Right now we have a stub that just exits the process.
This commit is contained in:
parent
c8726244ae
commit
0c35525e30
10 changed files with 63 additions and 12 deletions
|
|
@ -5,6 +5,7 @@ Import('env testruns')
|
||||||
dist_headers = [
|
dist_headers = [
|
||||||
"hammer.h",
|
"hammer.h",
|
||||||
"allocator.h",
|
"allocator.h",
|
||||||
|
"compiler_specifics.h",
|
||||||
"glue.h",
|
"glue.h",
|
||||||
"internal.h"
|
"internal.h"
|
||||||
]
|
]
|
||||||
|
|
@ -61,6 +62,7 @@ misc_hammer_parts = [
|
||||||
'desugar.c',
|
'desugar.c',
|
||||||
'glue.c',
|
'glue.c',
|
||||||
'hammer.c',
|
'hammer.c',
|
||||||
|
'platform_bsdlike.c',
|
||||||
'pprint.c',
|
'pprint.c',
|
||||||
'registry.c',
|
'registry.c',
|
||||||
'system_allocator.c']
|
'system_allocator.c']
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ HParseResult* grow(HParserCacheKey *k, HParseState *state, HRecursionHead *head)
|
||||||
h_hashtable_put(state->recursion_heads, &k->input_pos, head);
|
h_hashtable_put(state->recursion_heads, &k->input_pos, head);
|
||||||
HParserCacheValue *old_cached = h_hashtable_get(state->cache, k);
|
HParserCacheValue *old_cached = h_hashtable_get(state->cache, k);
|
||||||
if (!old_cached || PC_LEFT == old_cached->value_type)
|
if (!old_cached || PC_LEFT == old_cached->value_type)
|
||||||
errx(1, "impossible match");
|
h_platform_errx(1, "impossible match");
|
||||||
HParseResult *old_res = old_cached->right;
|
HParseResult *old_res = old_cached->right;
|
||||||
|
|
||||||
// rewind the input
|
// rewind the input
|
||||||
|
|
@ -148,7 +148,7 @@ HParseResult* grow(HParserCacheKey *k, HParseState *state, HRecursionHead *head)
|
||||||
state->input_stream = cached->input_stream;
|
state->input_stream = cached->input_stream;
|
||||||
return cached->right;
|
return cached->right;
|
||||||
} else {
|
} else {
|
||||||
errx(1, "impossible match");
|
h_platform_errx(1, "impossible match");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -173,7 +173,7 @@ HParseResult* lr_answer(HParserCacheKey *k, HParseState *state, HLeftRec *growab
|
||||||
return grow(k, state, growable->head);
|
return grow(k, state, growable->head);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errx(1, "lrAnswer with no head");
|
h_platform_errx(1, "lrAnswer with no head");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
16
src/compiler_specifics.h
Normal file
16
src/compiler_specifics.h
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef HAMMER_COMPILER_SPECIFICS__H
|
||||||
|
#define HAMMER_COMPILER_SPECIFICS__H
|
||||||
|
|
||||||
|
#if defined(__clang__) || defined(__GNUC__)
|
||||||
|
#define H_GCC_ATTRIBUTE(x) __attribute__(x)
|
||||||
|
#else
|
||||||
|
#define H_GCC_ATTRIBUTE(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define H_MSVC_DECLSPEC(x) __declspec(x)
|
||||||
|
#else
|
||||||
|
#define H_MSVC_DECLSPEC(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <err.h>
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,7 @@
|
||||||
#ifndef HAMMER_HAMMER__H
|
#ifndef HAMMER_HAMMER__H
|
||||||
#define HAMMER_HAMMER__H
|
#define HAMMER_HAMMER__H
|
||||||
|
|
||||||
#if defined(__clang__) || defined(__GNUC__)
|
#include "compiler_specifics.h"
|
||||||
#define H_GCC_ATTRIBUTE(x) __attribute__(x)
|
|
||||||
#else
|
|
||||||
#define H_GCC_ATTRIBUTE(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef HAMMER_INTERNAL__NO_STDARG_H
|
#ifndef HAMMER_INTERNAL__NO_STDARG_H
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@
|
||||||
#define HAMMER_INTERNAL__H
|
#define HAMMER_INTERNAL__H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <err.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "hammer.h"
|
#include "hammer.h"
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
/* "Internal" in this case means "we're not ready to commit
|
/* "Internal" in this case means "we're not ready to commit
|
||||||
* to a public API." Many structures and routines here will be
|
* to a public API." Many structures and routines here will be
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
#else
|
#else
|
||||||
#define assert_message(check, message) do { \
|
#define assert_message(check, message) do { \
|
||||||
if (!(check)) \
|
if (!(check)) \
|
||||||
errx(1, "Assertion failed (programmer error): %s", message); \
|
h_platform_errx(1, "Assertion failed (programmer error): %s", message); \
|
||||||
} while(0)
|
} while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ static HParseResult* parse_length_value(void *env, HParseState *state) {
|
||||||
if (!len)
|
if (!len)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (len->ast->token_type != TT_UINT)
|
if (len->ast->token_type != TT_UINT)
|
||||||
errx(1, "Length parser must return an unsigned integer");
|
h_platform_errx(1, "Length parser must return an unsigned integer");
|
||||||
// TODO: allocate this using public functions
|
// TODO: allocate this using public functions
|
||||||
HRepeat repeat = {
|
HRepeat repeat = {
|
||||||
.p = lv->value,
|
.p = lv->value,
|
||||||
|
|
|
||||||
18
src/platform.h
Normal file
18
src/platform.h
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef HAMMER_PLATFORM__H
|
||||||
|
#define HAMMER_PLATFORM__H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file interface between hammer and the operating system /
|
||||||
|
* underlying platform.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "compiler_specifics.h"
|
||||||
|
|
||||||
|
/* Error Reporting */
|
||||||
|
|
||||||
|
/* BSD errx function, seen in err.h */
|
||||||
|
H_MSVC_DECLSPEC(noreturn) \
|
||||||
|
void h_platform_errx(int err, const char* format, ...) \
|
||||||
|
H_GCC_ATTRIBUTE((noreturn, format (printf,2,3)));
|
||||||
|
|
||||||
|
#endif
|
||||||
10
src/platform_bsdlike.c
Normal file
10
src/platform_bsdlike.c
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
void h_platform_errx(int err, const char* format, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
verrx(err, format, ap);
|
||||||
|
}
|
||||||
10
src/platform_win32.c
Normal file
10
src/platform_win32.c
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include "windows.h"
|
||||||
|
|
||||||
|
void h_platform_errx(int err, const char* format, ...) {
|
||||||
|
// FIXME(windows) TODO(uucidl): to be implemented
|
||||||
|
ExitProcess(err);
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue