Skip to content

Commit

Permalink
Remove limit on number of sync points
Browse files Browse the repository at this point in the history
Make it possible for ndisasm to allocate more memory for sync points
as needed.
  • Loading branch information
H. Peter Anvin committed Sep 20, 2007
1 parent 87f252a commit 8d024e7
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#include <limits.h>
#include <inttypes.h>

#include "nasmlib.h"
#include "sync.h"

#define SYNC_MAX 4096 /* max # of sync points */
#define SYNC_MAX 4096 /* max # of sync points (initial) */

/*
* This lot manages the current set of sync points by means of a
Expand All @@ -24,38 +25,23 @@ static struct Sync {
uint32_t pos;
uint32_t length;
} *synx;
static int nsynx;
static int max_synx, nsynx;

void init_sync(void)
{
/*
* I'd like to allocate an array of size SYNC_MAX, then write
* `synx--' which would allow numbering the array from one
* instead of zero without wasting memory. Sadly I don't trust
* this to work in 16-bit Large model, so it's staying the way
* it is. Btw, we don't care about freeing this array, since it
* has to last for the duration of the program and will then be
* auto-freed on exit. And I'm lazy ;-)
*
* Speaking of 16-bit Large model, that's also the reason I'm
* not declaring this array statically - by doing it
* dynamically I avoid problems with the total size of DGROUP
* in Borland C.
*/
synx = malloc((SYNC_MAX + 1) * sizeof(*synx));
if (!synx) {
fprintf(stderr, "ndisasm: not enough memory for sync array\n");
exit(1);
}
max_synx = SYNC_MAX-1;
synx = nasm_malloc(SYNC_MAX * sizeof(*synx));
nsynx = 0;
}

void add_sync(uint32_t pos, uint32_t length)
{
int i;

if (nsynx == SYNC_MAX)
return; /* can't do anything - overflow */
if (nsynx >= max_synx) {
max_synx = (max_synx << 1)+1;
synx = nasm_realloc(synx, (max_synx+1) * sizeof(*synx));
}

nsynx++;
synx[nsynx].pos = pos;
Expand Down

0 comments on commit 8d024e7

Please sign in to comment.