summaryrefslogtreecommitdiff
path: root/saa.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-07-18 21:07:17 -0400
committerH. Peter Anvin <hpa@zytor.com>2009-07-18 18:43:12 -0700
commit9bd1506d5999d7c41a4cf6de2f43b97939bb260e (patch)
treed3dad5bda2b167af7dfe29cad7cb532406ddb1c4 /saa.c
parent159178f2aa516718fcb420a281c17adc8b330492 (diff)
downloadnasm-9bd1506d5999d7c41a4cf6de2f43b97939bb260e.tar.gz
nasm-9bd1506d5999d7c41a4cf6de2f43b97939bb260e.tar.bz2
nasm-9bd1506d5999d7c41a4cf6de2f43b97939bb260e.zip
Remove function pointers in output, simplify error handling
Remove a bunch of function pointers in the output stage; they are never changed and don't add any value. Also make "ofile" a global variable and let the backend use it directly. All we ever did with these variables were stashing it in locals and using them as-is anyway for no benefit. Also change the global error function, nasm_error() into a true function which invokes a function pointer internally. That lets us use direct calls to it. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'saa.c')
-rw-r--r--saa.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/saa.c b/saa.c
index ed70755..157aba3 100644
--- a/saa.c
+++ b/saa.c
@@ -99,15 +99,10 @@ void *saa_wstruct(struct SAA *s)
{
void *p;
- if (s->wpos % s->elem_len)
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
- "misaligned wpos in saa_wstruct");
+ nasm_assert((s->wpos % s->elem_len) == 0);
if (s->wpos + s->elem_len > s->blk_len) {
- if (s->wpos != s->blk_len)
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
- "unfilled block in saa_wstruct");
-
+ nasm_assert(s->wpos == s->blk_len);
if (s->wptr + s->elem_len > s->length)
saa_extend(s);
s->wblk++;
@@ -167,9 +162,7 @@ void *saa_rstruct(struct SAA *s)
if (s->rptr + s->elem_len > s->datalen)
return NULL;
- if (s->rpos % s->elem_len)
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
- "misaligned rpos in saa_rstruct");
+ nasm_assert((s->rpos % s->elem_len) == 0);
if (s->rpos + s->elem_len > s->blk_len) {
s->rblk++;
@@ -217,11 +210,7 @@ void saa_rnbytes(struct SAA *s, void *data, size_t len)
{
char *d = data;
- if (s->rptr + len > s->datalen) {
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
- "overrun in saa_rnbytes");
- return;
- }
+ nasm_assert(s->rptr + len <= s->datalen);
while (len) {
size_t l;
@@ -241,10 +230,7 @@ void saa_fread(struct SAA *s, size_t posn, void *data, size_t len)
{
size_t ix;
- if (posn + len > s->datalen) {
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE, "overrun in saa_fread");
- return;
- }
+ nasm_assert(posn + len <= s->datalen);
if (likely(s->blk_len == SAA_BLKLEN)) {
ix = posn >> SAA_BLKSHIFT;
@@ -264,11 +250,8 @@ void saa_fwrite(struct SAA *s, size_t posn, const void *data, size_t len)
{
size_t ix;
- if (posn > s->datalen) {
- /* Seek beyond the end of the existing array not supported */
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE, "overrun in saa_fwrite");
- return;
- }
+ /* Seek beyond the end of the existing array not supported */
+ nasm_assert(posn <= s->datalen);
if (likely(s->blk_len == SAA_BLKLEN)) {
ix = posn >> SAA_BLKSHIFT;