diff options
author | H. Peter Anvin <hpa@zytor.com> | 2009-07-01 22:02:54 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2009-07-01 22:02:54 -0700 |
commit | 807bed5ffd11a3b2cd8f8ccd8824c43ac5f5aa69 (patch) | |
tree | 660dabaffba8f02249f5232f5cde651341222566 | |
parent | 396e6dcc4b446f2b17cc5a03b8e43b1a298b9895 (diff) | |
download | nasm-807bed5ffd11a3b2cd8f8ccd8824c43ac5f5aa69.tar.gz nasm-807bed5ffd11a3b2cd8f8ccd8824c43ac5f5aa69.tar.bz2 nasm-807bed5ffd11a3b2cd8f8ccd8824c43ac5f5aa69.zip |
nasmlib: add nasm_assert(); use const char * for filenames
Add new nasm_assert() function, and add "const" to the declarations
which take filenames, as well as to the nasm_strdup/strndup functions.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | nasmlib.c | 21 | ||||
-rw-r--r-- | nasmlib.h | 21 |
2 files changed, 28 insertions, 14 deletions
@@ -95,7 +95,7 @@ void nasm_set_malloc_error(efunc error) } #ifdef LOGALLOC -void *nasm_malloc_log(char *file, int line, size_t size) +void *nasm_malloc_log(const char *file, int line, size_t size) #else void *nasm_malloc(size_t size) #endif @@ -112,7 +112,7 @@ void *nasm_malloc(size_t size) } #ifdef LOGALLOC -void *nasm_zalloc_log(char *file, int line, size_t size) +void *nasm_zalloc_log(const char *file, int line, size_t size) #else void *nasm_zalloc(size_t size) #endif @@ -129,7 +129,7 @@ void *nasm_zalloc(size_t size) } #ifdef LOGALLOC -void *nasm_realloc_log(char *file, int line, void *q, size_t size) +void *nasm_realloc_log(const char *file, int line, void *q, size_t size) #else void *nasm_realloc(void *q, size_t size) #endif @@ -149,7 +149,7 @@ void *nasm_realloc(void *q, size_t size) } #ifdef LOGALLOC -void nasm_free_log(char *file, int line, void *q) +void nasm_free_log(const char *file, int line, void *q) #else void nasm_free(void *q) #endif @@ -163,7 +163,7 @@ void nasm_free(void *q) } #ifdef LOGALLOC -char *nasm_strdup_log(char *file, int line, const char *s) +char *nasm_strdup_log(const char *file, int line, const char *s) #else char *nasm_strdup(const char *s) #endif @@ -184,9 +184,9 @@ char *nasm_strdup(const char *s) } #ifdef LOGALLOC -char *nasm_strndup_log(char *file, int line, char *s, size_t len) +char *nasm_strndup_log(const char *file, int line, const char *s, size_t len) #else -char *nasm_strndup(char *s, size_t len) +char *nasm_strndup(const char *s, size_t len) #endif { char *p; @@ -205,6 +205,13 @@ char *nasm_strndup(char *s, size_t len) return p; } +noreturn nasm_assert_failed(const char *file, int line, const char *msg) +{ + nasm_malloc_error(ERR_FATAL, "assertion %s failed at %s:%d", + msg, file, line); + exit(1); +} + #ifndef nasm_stricmp int nasm_stricmp(const char *s1, const char *s2) { @@ -152,14 +152,14 @@ void *nasm_zalloc(size_t); void *nasm_realloc(void *, size_t); void nasm_free(void *); char *nasm_strdup(const char *); -char *nasm_strndup(char *, size_t); +char *nasm_strndup(const char *, size_t); #else -void *nasm_malloc_log(char *, int, size_t); -void *nasm_zalloc_log(char *, int, size_t); -void *nasm_realloc_log(char *, int, void *, size_t); -void nasm_free_log(char *, int, void *); -char *nasm_strdup_log(char *, int, const char *); -char *nasm_strndup_log(char *, int, char *, size_t); +void *nasm_malloc_log(const char *, int, size_t); +void *nasm_zalloc_log(const char *, int, size_t); +void *nasm_realloc_log(const char *, int, void *, size_t); +void nasm_free_log(const char *, int, void *); +char *nasm_strdup_log(const char *, int, const char *); +char *nasm_strndup_log(const char *, int, const char *, size_t); #define nasm_malloc(x) nasm_malloc_log(__FILE__,__LINE__,x) #define nasm_zalloc(x) nasm_zalloc_log(__FILE__,__LINE__,x) #define nasm_realloc(x,y) nasm_realloc_log(__FILE__,__LINE__,x,y) @@ -169,6 +169,13 @@ char *nasm_strndup_log(char *, int, char *, size_t); #endif /* + * NASM assert failure + */ +noreturn nasm_assert_failed(const char *, int, const char *); +#define nasm_assert(x) \ + do { if (!(x)) nasm_assert_failed(__FILE__,__LINE__,#x); } while (0) + +/* * ANSI doesn't guarantee the presence of `stricmp' or * `strcasecmp'. */ |