}
/* Look for dynamic module. First build full module name from keyword. */
- name = xmalloc(5+strlen(keyword)+1);
+ name = yasm_xmalloc(5+strlen(keyword)+1);
strcpy(name, "yasm-");
strcat(name, keyword);
handle = lt_dlopenext(name);
if (!handle) {
- xfree(name);
+ yasm_xfree(name);
return NULL;
}
- m = xmalloc(sizeof(module));
+ m = yasm_xmalloc(sizeof(module));
m->keyword = name;
strcpy(m->keyword, keyword);
m->handle = handle;
while (!SLIST_EMPTY(&modules)) {
m = SLIST_FIRST(&modules);
SLIST_REMOVE_HEAD(&modules, link);
- xfree(m->keyword);
+ yasm_xfree(m->keyword);
lt_dlclose(m->handle);
- xfree(m);
+ yasm_xfree(m);
}
}
lt_dlmalloc = malloc;
lt_dlfree = free;
#else
- lt_dlmalloc = xmalloc;
- lt_dlfree = xfree;
+ lt_dlmalloc = yasm_xmalloc;
+ lt_dlfree = yasm_xfree;
#endif
/* Initialize preloaded symbol lookup table. */
in = fopen(in_filename, "rt");
if (!in) {
print_error(_("could not open file `%s'"), in_filename);
- xfree(in_filename);
+ yasm_xfree(in_filename);
if (obj_filename)
- xfree(obj_filename);
+ yasm_xfree(obj_filename);
return EXIT_FAILURE;
}
} else {
/* If no files were specified or filename was "-", read stdin */
in = stdin;
if (!in_filename)
- in_filename = xstrdup("-");
+ in_filename = yasm__xstrdup("-");
}
/* Initialize line manager */
/* handle preproc-only case here */
if (preproc_only) {
- char *preproc_buf = xmalloc(PREPROC_BUF_SIZE);
+ char *preproc_buf = yasm_xmalloc(PREPROC_BUF_SIZE);
size_t got;
/* Default output to stdout if not specified */
/* Open output (object) file */
obj = open_obj("wt");
if (!obj) {
- xfree(preproc_buf);
+ yasm_xfree(preproc_buf);
return EXIT_FAILURE;
}
}
print_yasm_error, print_yasm_warning);
if (obj != stdout)
remove(obj_filename);
- xfree(preproc_buf);
+ yasm_xfree(preproc_buf);
cleanup(NULL);
return EXIT_FAILURE;
}
- xfree(preproc_buf);
+ yasm_xfree(preproc_buf);
cleanup(NULL);
return EXIT_SUCCESS;
}
if (!obj_filename) {
if (in == stdin)
/* Default to yasm.out if no obj filename specified */
- obj_filename = xstrdup("yasm.out");
+ obj_filename = yasm__xstrdup("yasm.out");
else
/* replace (or add) extension */
obj_filename = replace_extension(in_filename,
if (DO_FREE) {
if (in_filename)
- xfree(in_filename);
+ yasm_xfree(in_filename);
if (obj_filename)
- xfree(obj_filename);
+ yasm_xfree(obj_filename);
}
}
if (in_filename) {
print_error(
_("warning: can open only one input file, only the last file will be processed"));
- xfree(in_filename);
+ yasm_xfree(in_filename);
}
- in_filename = xstrdup(param);
+ in_filename = yasm__xstrdup(param);
return 0;
}
if (obj_filename) {
print_error(
_("warning: can output to only one object file, last specified used"));
- xfree(obj_filename);
+ yasm_xfree(obj_filename);
}
assert(param != NULL);
- obj_filename = xstrdup(param);
+ obj_filename = yasm__xstrdup(param);
return 0;
}
char *out, *outext;
/* allocate enough space for full existing name + extension */
- out = xmalloc(strlen(orig)+(ext ? (strlen(ext)+2) : 1));
+ out = yasm_xmalloc(strlen(orig)+(ext ? (strlen(ext)+2) : 1));
strcpy(out, orig);
outext = strrchr(out, '.');
if (outext) {
yasm_insn_operand *
yasm_operand_new_reg(unsigned long reg)
{
- yasm_insn_operand *retval = xmalloc(sizeof(yasm_insn_operand));
+ yasm_insn_operand *retval = yasm_xmalloc(sizeof(yasm_insn_operand));
retval->type = YASM_INSN__OPERAND_REG;
retval->data.reg = reg;
yasm_insn_operand *
yasm_operand_new_segreg(unsigned long segreg)
{
- yasm_insn_operand *retval = xmalloc(sizeof(yasm_insn_operand));
+ yasm_insn_operand *retval = yasm_xmalloc(sizeof(yasm_insn_operand));
retval->type = YASM_INSN__OPERAND_SEGREG;
retval->data.reg = segreg;
yasm_insn_operand *
yasm_operand_new_mem(/*@only@*/ yasm_effaddr *ea)
{
- yasm_insn_operand *retval = xmalloc(sizeof(yasm_insn_operand));
+ yasm_insn_operand *retval = yasm_xmalloc(sizeof(yasm_insn_operand));
retval->type = YASM_INSN__OPERAND_MEMORY;
retval->data.ea = ea;
retval = yasm_operand_new_reg(*reg);
yasm_expr_delete(val);
} else {
- retval = xmalloc(sizeof(yasm_insn_operand));
+ retval = yasm_xmalloc(sizeof(yasm_insn_operand));
retval->type = YASM_INSN__OPERAND_IMM;
retval->data.val = val;
retval->targetmod = 0;
default:
break;
}
- xfree(cur);
+ yasm_xfree(cur);
cur = next;
}
STAILQ_INIT(headp);
FACTOR = LOGBITS - 3; /* ld(BITS / 8) = ld(BITS) - ld(8) = ld(BITS) - 3 */
MSB = (LSB << MODMASK);
- BITMASKTAB = (wordptr) xmalloc((size_t) (BITS << FACTOR));
+ BITMASKTAB = (wordptr) yasm_xmalloc((size_t) (BITS << FACTOR));
if (BITMASKTAB == NULL) return(ErrCode_Null);
void BitVector_Shutdown(void)
{
- if (BITMASKTAB) xfree(BITMASKTAB);
+ if (BITMASKTAB) yasm_xfree(BITMASKTAB);
}
N_word BitVector_Size(N_int bits) /* bit vector size (# of words) */
void BitVector_Dispose(charptr string) /* free string */
{
- if (string != NULL) xfree((voidptr) string);
+ if (string != NULL) yasm_xfree((voidptr) string);
}
void BitVector_Destroy(wordptr addr) /* free bitvec */
if (addr != NULL)
{
addr -= BIT_VECTOR_HIDDEN_WORDS;
- xfree((voidptr) addr);
+ yasm_xfree((voidptr) addr);
}
}
size = BitVector_Size(bits);
mask = BitVector_Mask(bits);
bytes = (size + BIT_VECTOR_HIDDEN_WORDS) << FACTOR;
- addr = (wordptr) xmalloc((size_t) bytes);
+ addr = (wordptr) yasm_xmalloc((size_t) bytes);
if (addr != NULL)
{
*addr++ = bits;
else
{
bytes = (newsize + BIT_VECTOR_HIDDEN_WORDS) << FACTOR;
- newaddr = (wordptr) xmalloc((size_t) bytes);
+ newaddr = (wordptr) yasm_xmalloc((size_t) bytes);
if (newaddr != NULL)
{
*newaddr++ = bits;
length = bits >> 2;
if (bits AND 0x0003) length++;
- string = (charptr) xmalloc((size_t) (length+1));
+ string = (charptr) yasm_xmalloc((size_t) (length+1));
if (string == NULL) return(NULL);
string += length;
*string = (N_char) '\0';
charptr string;
length = bits_(addr);
- string = (charptr) xmalloc((size_t) (length+1));
+ string = (charptr) yasm_xmalloc((size_t) (length+1));
if (string == NULL) return(NULL);
string += length;
*string = (N_char) '\0';
length = (N_word) (bits / 3.3); /* digits = bits * ln(2) / ln(10) */
length += 2; /* compensate for truncating & provide space for minus sign */
- result = (charptr) xmalloc((size_t) (length+1)); /* remember the '\0'! */
+ result = (charptr) yasm_xmalloc((size_t) (length+1)); /* remember the '\0'! */
if (result == NULL) return(NULL);
string = result;
sign = BitVector_Sign(addr);
}
}
else length = 1;
- string = (charptr) xmalloc((size_t) length);
+ string = (charptr) yasm_xmalloc((size_t) length);
if (string == NULL) return(NULL);
start = 0;
comma = FALSE;
/* provide translation for independence of endian-ness: */
*length = size << FACTOR;
- buffer = (charptr) xmalloc((size_t) ((*length)+1));
+ buffer = (charptr) yasm_xmalloc((size_t) ((*length)+1));
if (buffer == NULL) return(NULL);
target = buffer;
if (size > 0)
yasm_immval *
yasm_imm_new_expr(yasm_expr *expr_ptr)
{
- yasm_immval *im = xmalloc(sizeof(yasm_immval));
+ yasm_immval *im = yasm_xmalloc(sizeof(yasm_immval));
im->val = expr_ptr;
im->len = 0;
if (cur_arch->ea_data_delete)
cur_arch->ea_data_delete(ea);
yasm_expr_delete(ea->disp);
- xfree(ea);
+ yasm_xfree(ea);
}
/*@=nullstate@*/
yasm_bytecode *
yasm_bc_new_common(yasm_bytecode_type type, size_t size, unsigned long lindex)
{
- yasm_bytecode *bc = xmalloc(size);
+ yasm_bytecode *bc = yasm_xmalloc(size);
bc->type = type;
break;
case YASM_BC__INCBIN:
incbin = (bytecode_incbin *)bc;
- xfree(incbin->filename);
+ yasm_xfree(incbin->filename);
yasm_expr_delete(incbin->start);
yasm_expr_delete(incbin->maxlen);
break;
/*@=branchstate@*/
yasm_expr_delete(bc->multiple);
- xfree(bc);
+ yasm_xfree(bc);
}
void
*gap = 0;
if (*bufsize < datasize) {
- mybuf = xmalloc(sizeof(bc->len));
+ mybuf = yasm_xmalloc(sizeof(bc->len));
origbuf = mybuf;
destbuf = mybuf;
} else {
STAILQ_INSERT_TAIL(headp, bc, link);
return bc;
} else {
- xfree(bc);
+ yasm_xfree(bc);
}
}
return (yasm_bytecode *)NULL;
yasm_dataval *
yasm_dv_new_expr(yasm_expr *expn)
{
- yasm_dataval *retval = xmalloc(sizeof(yasm_dataval));
+ yasm_dataval *retval = yasm_xmalloc(sizeof(yasm_dataval));
retval->type = DV_EXPR;
retval->data.expn = expn;
yasm_dataval *
yasm_dv_new_string(char *str_val)
{
- yasm_dataval *retval = xmalloc(sizeof(yasm_dataval));
+ yasm_dataval *retval = yasm_xmalloc(sizeof(yasm_dataval));
retval->type = DV_STRING;
retval->data.str_val = str_val;
yasm_expr_delete(cur->data.expn);
break;
case DV_STRING:
- xfree(cur->data.str_val);
+ yasm_xfree(cur->data.str_val);
break;
default:
break;
}
- xfree(cur);
+ yasm_xfree(cur);
cur = next;
}
STAILQ_INIT(headp);
we = SLIST_FIRST(&errwarns);
SLIST_REMOVE_HEAD(&errwarns, link);
- xfree(we);
+ yasm_xfree(we);
}
}
we = ins_we;
} else {
/* add a new error */
- we = xmalloc(sizeof(errwarn_data));
+ we = yasm_xmalloc(sizeof(errwarn_data));
we->type = WE_UNKNOWN;
we->line = lindex;
unsigned long lindex)
{
yasm_expr *ptr, *sube;
- ptr = xmalloc(sizeof(yasm_expr));
+ ptr = yasm_xmalloc(sizeof(yasm_expr));
ptr->op = op;
ptr->numterms = 0;
ptr->terms[1].type = YASM_EXPR_NONE;
if (left) {
ptr->terms[0] = *left; /* structure copy */
- xfree(left);
+ yasm_xfree(left);
ptr->numterms++;
/* Search downward until we find something *other* than an
sube = ptr->terms[0].data.expn;
ptr->terms[0] = sube->terms[0]; /* structure copy */
/*@-usereleased@*/
- xfree(sube);
+ yasm_xfree(sube);
/*@=usereleased@*/
}
} else {
if (right) {
ptr->terms[1] = *right; /* structure copy */
- xfree(right);
+ yasm_xfree(right);
ptr->numterms++;
/* Search downward until we find something *other* than an
sube = ptr->terms[1].data.expn;
ptr->terms[1] = sube->terms[0]; /* structure copy */
/*@-usereleased@*/
- xfree(sube);
+ yasm_xfree(sube);
/*@=usereleased@*/
}
}
yasm_expr__item *
yasm_expr_sym(yasm_symrec *s)
{
- yasm_expr__item *e = xmalloc(sizeof(yasm_expr__item));
+ yasm_expr__item *e = yasm_xmalloc(sizeof(yasm_expr__item));
e->type = YASM_EXPR_SYM;
e->data.sym = s;
return e;
yasm_expr__item *
yasm_expr_expr(yasm_expr *x)
{
- yasm_expr__item *e = xmalloc(sizeof(yasm_expr__item));
+ yasm_expr__item *e = yasm_xmalloc(sizeof(yasm_expr__item));
e->type = YASM_EXPR_EXPR;
e->data.expn = x;
return e;
yasm_expr__item *
yasm_expr_int(yasm_intnum *i)
{
- yasm_expr__item *e = xmalloc(sizeof(yasm_expr__item));
+ yasm_expr__item *e = yasm_xmalloc(sizeof(yasm_expr__item));
e->type = YASM_EXPR_INT;
e->data.intn = i;
return e;
yasm_expr__item *
yasm_expr_float(yasm_floatnum *f)
{
- yasm_expr__item *e = xmalloc(sizeof(yasm_expr__item));
+ yasm_expr__item *e = yasm_xmalloc(sizeof(yasm_expr__item));
e->type = YASM_EXPR_FLOAT;
e->data.flt = f;
return e;
yasm_expr__item *
yasm_expr_reg(unsigned long reg)
{
- yasm_expr__item *e = xmalloc(sizeof(yasm_expr__item));
+ yasm_expr__item *e = yasm_xmalloc(sizeof(yasm_expr__item));
e->type = YASM_EXPR_REG;
e->data.reg = reg;
return e;
}
if (e->numterms != numterms) {
e->numterms = numterms;
- e = xrealloc(e, sizeof(yasm_expr)+((numterms<2) ? 0 :
- sizeof(yasm_expr__item)*(numterms-2)));
+ e = yasm_xrealloc(e, sizeof(yasm_expr)+((numterms<2) ? 0 :
+ sizeof(yasm_expr__item)*(numterms-2)));
if (numterms == 1)
e->op = YASM_EXPR_IDENT;
}
static void
expr_xform_neg_item(yasm_expr *e, yasm_expr__item *ei)
{
- yasm_expr *sube = xmalloc(sizeof(yasm_expr));
+ yasm_expr *sube = yasm_xmalloc(sizeof(yasm_expr));
/* Build -1*ei subexpression */
sube->op = YASM_EXPR_MUL;
/* Everything else. MUL will be combined when it's leveled.
* Make a new expr (to replace e) with -1*e.
*/
- ne = xmalloc(sizeof(yasm_expr));
+ ne = yasm_xmalloc(sizeof(yasm_expr));
ne->op = YASM_EXPR_MUL;
ne->line = e->line;
ne->numterms = 2;
*/
while (e->op == YASM_EXPR_IDENT && e->terms[0].type == YASM_EXPR_EXPR) {
yasm_expr *sube = e->terms[0].data.expn;
- xfree(e);
+ yasm_xfree(e);
e = sube;
}
level_numterms = e->numterms;
e->terms[i].data.expn->op == YASM_EXPR_IDENT) {
yasm_expr *sube = e->terms[i].data.expn;
e->terms[i] = sube->terms[0];
- xfree(sube);
+ yasm_xfree(sube);
}
if (e->terms[i].type == YASM_EXPR_EXPR &&
level_numterms <= fold_numterms) {
/* Downsize e if necessary */
if (fold_numterms < e->numterms && e->numterms > 2)
- e = xrealloc(e, sizeof(yasm_expr)+((fold_numterms<2) ? 0 :
- sizeof(yasm_expr__item)*(fold_numterms-2)));
+ e = yasm_xrealloc(e, sizeof(yasm_expr)+((fold_numterms<2) ? 0 :
+ sizeof(yasm_expr__item)*(fold_numterms-2)));
/* Update numterms */
e->numterms = fold_numterms;
return e;
}
/* Alloc more (or conceivably less, but not usually) space for e */
- e = xrealloc(e, sizeof(yasm_expr)+((level_numterms<2) ? 0 :
- sizeof(yasm_expr__item)*(level_numterms-2)));
+ e = yasm_xrealloc(e, sizeof(yasm_expr)+((level_numterms<2) ? 0 :
+ sizeof(yasm_expr__item)*(level_numterms-2)));
/* Copy up ExprItem's. Iterate from right to left to keep the same
* ordering as was present originally.
/* delete subexpression, but *don't delete nodes* (as we've just
* copied them!)
*/
- xfree(sube);
+ yasm_xfree(sube);
} else if (o != i) {
/* copy operand if it changed places */
if (o == first_int_term)
yasm_expr *n;
int i;
- n = xmalloc(sizeof(yasm_expr) +
- sizeof(yasm_expr__item)*(e->numterms<2?0:e->numterms-2));
+ n = yasm_xmalloc(sizeof(yasm_expr) +
+ sizeof(yasm_expr__item)*(e->numterms<2?0:e->numterms-2));
n->op = e->op;
n->line = e->line;
break; /* none of the other types needs to be deleted */
}
}
- xfree(e); /* free ourselves */
+ yasm_xfree(e); /* free ourselves */
return 0; /* don't stop recursion */
}
int i;
/* Allocate space for two POT tables */
- POT_TableN = xmalloc(14*sizeof(POT_Entry));
- POT_TableP = xmalloc(15*sizeof(POT_Entry)); /* note 1 extra for -1 */
+ POT_TableN = yasm_xmalloc(14*sizeof(POT_Entry));
+ POT_TableP = yasm_xmalloc(15*sizeof(POT_Entry)); /* note 1 extra for -1 */
/* Initialize entry[0..12] */
for (i=12; i>=0; i--) {
}
BitVector_Destroy(POT_TableP[14].f.mantissa);
- xfree(POT_TableN);
- xfree(POT_TableP);
+ yasm_xfree(POT_TableN);
+ yasm_xfree(POT_TableP);
}
/*@=globstate@*/
int decimal_pt;
boolean carry;
- flt = xmalloc(sizeof(yasm_floatnum));
+ flt = yasm_xmalloc(sizeof(yasm_floatnum));
flt->mantissa = BitVector_Create(MANT_BITS, TRUE);
yasm_floatnum *
yasm_floatnum_copy(const yasm_floatnum *flt)
{
- yasm_floatnum *f = xmalloc(sizeof(yasm_floatnum));
+ yasm_floatnum *f = yasm_xmalloc(sizeof(yasm_floatnum));
f->mantissa = BitVector_Clone(flt->mantissa);
f->exponent = flt->exponent;
yasm_floatnum_delete(yasm_floatnum *flt)
{
BitVector_Destroy(flt->mantissa);
- xfree(flt);
+ yasm_xfree(flt);
}
void
memcpy(ptr, buf, byte_size*sizeof(unsigned char));
/* free allocated resources */
- xfree(buf);
+ yasm_xfree(buf);
BitVector_Destroy(output);
str = BitVector_to_Hex(flt->mantissa);
fprintf(f, "%c %s *2^%04x\n", flt->sign?'-':'+', (char *)str,
flt->exponent);
- xfree(str);
+ yasm_xfree(str);
/* 32-bit (single precision) format */
fprintf(f, "32-bit: %d: ", yasm_floatnum_get_sized(flt, out, 4));
HAMT_new(/*@exits@*/ void (*error_func) (const char *file, unsigned int line,
const char *message))
{
- /*@out@*/ HAMT *hamt = xmalloc(sizeof(HAMT));
+ /*@out@*/ HAMT *hamt = yasm_xmalloc(sizeof(HAMT));
int i;
SLIST_INIT(&hamt->entries);
- hamt->root = xmalloc(32*sizeof(HAMTNode));
+ hamt->root = yasm_xmalloc(32*sizeof(HAMTNode));
for (i=0; i<32; i++) {
hamt->root[i].BitMapKey = 0;
for (i=0; i<Size; i++)
HAMT_delete_trie(&(GetSubTrie(node))[i]);
- xfree(GetSubTrie(node));
+ yasm_xfree(GetSubTrie(node));
}
}
entry = SLIST_FIRST(&hamt->entries);
SLIST_REMOVE_HEAD(&hamt->entries, next);
deletefunc(entry->data);
- xfree(entry);
+ yasm_xfree(entry);
}
/* delete trie */
for (i=0; i<32; i++)
HAMT_delete_trie(&hamt->root[i]);
- xfree(hamt->root);
- xfree(hamt);
+ yasm_xfree(hamt->root);
+ yasm_xfree(hamt);
}
int
if (!node->BaseValue) {
node->BitMapKey = key;
- entry = xmalloc(sizeof(HAMTEntry));
+ entry = yasm_xmalloc(sizeof(HAMTEntry));
entry->str = str;
entry->data = data;
SLIST_INSERT_HEAD(&hamt->entries, entry, next);
/* Still equal, build one-node subtrie and continue
* downward.
*/
- newnodes = xmalloc(sizeof(HAMTNode));
+ newnodes = yasm_xmalloc(sizeof(HAMTNode));
newnodes[0] = *node; /* structure copy */
node->BitMapKey = 1<<keypart;
SetSubTrie(hamt, node, newnodes);
level++;
} else {
/* partitioned: allocate two-node subtrie */
- newnodes = xmalloc(2*sizeof(HAMTNode));
+ newnodes = yasm_xmalloc(2*sizeof(HAMTNode));
- entry = xmalloc(sizeof(HAMTEntry));
+ entry = yasm_xmalloc(sizeof(HAMTEntry));
entry->str = str;
entry->data = data;
SLIST_INSERT_HEAD(&hamt->entries, entry, next);
/* Count total number of bits in bitmap to determine new size */
BitCount(Size, node->BitMapKey);
Size &= 0x1F; /* Clamp to <32 */
- newnodes = xmalloc(Size*sizeof(HAMTNode));
+ newnodes = yasm_xmalloc(Size*sizeof(HAMTNode));
/* Count bits below to find where to insert new node at */
BitCount(Map, node->BitMapKey & ~((~0UL)<<keypart));
memcpy(&newnodes[Map+1], &(GetSubTrie(node))[Map],
(Size-Map-1)*sizeof(HAMTNode));
/* Delete old subtrie */
- xfree(GetSubTrie(node));
+ yasm_xfree(GetSubTrie(node));
/* Set up new node */
newnodes[Map].BitMapKey = key;
- entry = xmalloc(sizeof(HAMTEntry));
+ entry = yasm_xmalloc(sizeof(HAMTEntry));
entry->str = str;
entry->data = data;
SLIST_INSERT_HEAD(&hamt->entries, entry, next);
yasm_intnum *
yasm_intnum_new_dec(char *str, unsigned long lindex)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
intn->origsize = 0; /* no reliable way to figure this out */
yasm_intnum *
yasm_intnum_new_bin(char *str, unsigned long lindex)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
intn->origsize = (unsigned char)strlen(str);
yasm_intnum *
yasm_intnum_new_oct(char *str, unsigned long lindex)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
intn->origsize = strlen(str)*3;
yasm_intnum *
yasm_intnum_new_hex(char *str, unsigned long lindex)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
intn->origsize = strlen(str)*4;
yasm_intnum *
yasm_intnum_new_charconst_nasm(const char *str, unsigned long lindex)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
size_t len = strlen(str);
if (len > 4)
yasm_intnum *
yasm_intnum_new_uint(unsigned long i)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
intn->val.ul = i;
intn->type = INTNUM_UL;
yasm_intnum *
yasm_intnum_copy(const yasm_intnum *intn)
{
- yasm_intnum *n = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *n = yasm_xmalloc(sizeof(yasm_intnum));
switch (intn->type) {
case INTNUM_UL:
{
if (intn->type == INTNUM_BV)
BitVector_Destroy(intn->val.bv);
- xfree(intn);
+ yasm_xfree(intn);
}
/*@-nullderef -nullpass -branchstate@*/
if (len < (unsigned int)size)
yasm_internal_error(N_("Invalid size specified (too large)"));
memcpy(ptr, buf, size);
- xfree(buf);
+ yasm_xfree(buf);
break;
}
}
case INTNUM_BV:
s = BitVector_to_Hex(intn->val.bv);
fprintf(f, "0x%s/%u", (char *)s, (unsigned int)intn->origsize);
- xfree(s);
+ yasm_xfree(s);
break;
}
}
static void
filename_delete_one(/*@only@*/ void *d)
{
- xfree(d);
+ yasm_xfree(d);
}
static void
/* Create a new mapping in the map */
if (line_index_map->size >= line_index_map->allocated) {
/* allocate another size bins when full for 2x space */
- line_index_map->vector = xrealloc(line_index_map->vector,
- 2*line_index_map->allocated*sizeof(line_index_mapping));
+ line_index_map->vector =
+ yasm_xrealloc(line_index_map->vector, 2*line_index_map->allocated
+ *sizeof(line_index_mapping));
line_index_map->allocated *= 2;
}
mapping = &line_index_map->vector[line_index_map->size];
/* Fill it */
/* Copy the filename (via shared storage) */
- copy = xstrdup(filename);
+ copy = yasm__xstrdup(filename);
/*@-aliasunique@*/
mapping->filename = HAMT_insert(filename_table, copy, copy, &replace,
filename_delete_one);
line_index = 1;
/* initialize mapping vector */
- line_index_map = xmalloc(sizeof(line_index_mapping_head));
- line_index_map->vector = xmalloc(8*sizeof(line_index_mapping));
+ line_index_map = yasm_xmalloc(sizeof(line_index_mapping_head));
+ line_index_map->vector = yasm_xmalloc(8*sizeof(line_index_mapping));
line_index_map->size = 0;
line_index_map->allocated = 8;
/* initialize associated data arrays */
line_index_assoc_data_array =
- xmalloc(MAX_LINE_INDEX_ASSOC_DATA_ARRAY *
- sizeof(line_index_assoc_data_raw_head));
+ yasm_xmalloc(MAX_LINE_INDEX_ASSOC_DATA_ARRAY *
+ sizeof(line_index_assoc_data_raw_head));
for (i=0; i<MAX_LINE_INDEX_ASSOC_DATA_ARRAY; i++) {
line_index_assoc_data_array[i].vector = NULL;
line_index_assoc_data_array[i].size = 0;
if (adrh->vector[j])
adrh->delete_func(adrh->vector[j]);
}
- xfree(adrh->vector);
+ yasm_xfree(adrh->vector);
}
}
- xfree(line_index_assoc_data_array);
+ yasm_xfree(line_index_assoc_data_array);
line_index_assoc_data_array = NULL;
}
if (line_index_map) {
- xfree(line_index_map->vector);
- xfree(line_index_map);
+ yasm_xfree(line_index_map->vector);
+ yasm_xfree(line_index_map);
line_index_map = NULL;
}
int i;
adrh->size = 4;
- adrh->vector = xmalloc(adrh->size*sizeof(void *));
+ adrh->vector = yasm_xmalloc(adrh->size*sizeof(void *));
adrh->delete_func = delete_func;
for (i=0; i<adrh->size; i++)
adrh->vector[i] = NULL;
int i;
/* allocate another size bins when full for 2x space */
- adrh->vector = xrealloc(adrh->vector, 2*adrh->size*sizeof(void *));
+ adrh->vector = yasm_xrealloc(adrh->vector,
+ 2*adrh->size*sizeof(void *));
for(i=adrh->size; i<adrh->size*2; i++)
adrh->vector[i] = NULL;
adrh->size *= 2;
STAILQ_INIT(headp);
/* Add an initial "default" section */
- yasm_vp_new(vp, xstrdup(of->default_section_name), NULL);
+ yasm_vp_new(vp, yasm__xstrdup(of->default_section_name), NULL);
yasm_vps_initialize(&vps);
yasm_vps_append(&vps, vp);
s = of->sections_switch(headp, &vps, NULL, 0);
/* No: we have to allocate and create a new one. */
/* Okay, the name is valid; now allocate and initialize */
- s = xcalloc(1, sizeof(yasm_section));
+ s = yasm_xcalloc(1, sizeof(yasm_section));
STAILQ_INSERT_TAIL(headp, s, link);
s->type = SECTION_GENERAL;
- s->data.general.name = xstrdup(name);
+ s->data.general.name = yasm__xstrdup(name);
s->data.general.of = NULL;
s->data.general.of_data = NULL;
s->start = yasm_expr_new_ident(yasm_expr_int(yasm_intnum_new_uint(start)),
{
yasm_section *s;
- s = xcalloc(1, sizeof(yasm_section));
+ s = yasm_xcalloc(1, sizeof(yasm_section));
STAILQ_INSERT_TAIL(headp, s, link);
s->type = SECTION_ABSOLUTE;
return;
if (sect->type == SECTION_GENERAL) {
- xfree(sect->data.general.name);
+ yasm_xfree(sect->data.general.name);
if (sect->data.general.of_data && sect->data.general.of) {
yasm_objfmt *of = sect->data.general.of;
if (of->section_data_delete)
}
yasm_expr_delete(sect->start);
yasm_bcs_delete(§->bc);
- xfree(sect);
+ yasm_xfree(sect);
}
void
yasm_symrec_initialize(void)
{
sym_table = HAMT_new(yasm_internal_error_);
- non_table_syms = xmalloc(sizeof(nontablesymhead));
+ non_table_syms = yasm_xmalloc(sizeof(nontablesymhead));
SLIST_INIT(non_table_syms);
}
symrec_delete_one(/*@only@*/ void *d)
{
yasm_symrec *sym = d;
- xfree(sym->name);
+ yasm_xfree(sym->name);
if (sym->type == SYM_EQU)
yasm_expr_delete(sym->value.expn);
if (sym->of_data && sym->of) {
yasm_internal_error(
N_("don't know how to delete objfmt-specific data"));
}
- xfree(sym);
+ yasm_xfree(sym);
}
static /*@partial@*/ yasm_symrec *
symrec_new_common(/*@keep@*/ char *name)
{
- yasm_symrec *rec = xmalloc(sizeof(yasm_symrec));
+ yasm_symrec *rec = yasm_xmalloc(sizeof(yasm_symrec));
rec->name = name;
rec->type = SYM_UNKNOWN;
rec->line = 0;
static /*@partial@*/ /*@dependent@*/ yasm_symrec *
symrec_get_or_new_not_in_table(/*@only@*/ char *name)
{
- non_table_symrec *sym = xmalloc(sizeof(non_table_symrec));
+ non_table_symrec *sym = yasm_xmalloc(sizeof(non_table_symrec));
sym->rec = symrec_new_common(name);
sym->rec->status = SYM_NOTINTABLE;
static /*@partial@*/ /*@dependent@*/ yasm_symrec *
symrec_get_or_new(const char *name, int in_table)
{
- char *symname = xstrdup(name);
+ char *symname = yasm__xstrdup(name);
if (in_table)
return symrec_get_or_new_in_table(symname);
non_table_symrec *sym = SLIST_FIRST(non_table_syms);
SLIST_REMOVE_HEAD(non_table_syms, link);
symrec_delete_one(sym->rec);
- xfree(sym);
+ yasm_xfree(sym);
}
- xfree(non_table_syms);
+ yasm_xfree(non_table_syms);
}
typedef struct symrec_print_data {
# endif
#endif
+#ifdef WITH_DMALLOC
+# include <dmalloc.h>
+
+#define yasm__xstrdup(str) xstrdup(str)
+#define yasm_xmalloc(size) xmalloc(size)
+#define yasm_xcalloc(count, size) xcalloc(count, size)
+#define yasm_xrealloc(ptr, size) xrealloc(ptr, size)
+#define yasm_xfree(ptr) xfree(ptr)
+
+#else
/* strdup() implementation with error checking (using xmalloc). */
-/*@only@*/ char *xstrdup(const char *str);
+/*@only@*/ char *yasm__xstrdup(const char *str);
-/* Error-checking memory allocation routines in xmalloc.c. */
-/*@only@*/ /*@out@*/ void *xmalloc(size_t size);
-/*@only@*/ void *xcalloc(size_t nelem, size_t elsize);
-/*@only@*/ void *xrealloc(/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/
- void *oldmem, size_t size) /*@modifies oldmem@*/;
-void xfree(/*@only@*/ /*@out@*/ /*@null@*/ void *p) /*@modifies p@*/;
+/* Error-checking memory allocation routines. Default implementations in
+ * xmalloc.c.
+ */
+extern /*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size);
+extern /*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize);
+extern /*@only@*/ void * (*yasm_xrealloc)
+ (/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size)
+ /*@modifies oldmem@*/;
+extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p)
+ /*@modifies p@*/;
-#ifdef WITH_DMALLOC
-# include <dmalloc.h>
#endif
-/*@only@*/ char *xstrndup(const char *str, size_t len);
+/*@only@*/ char *yasm__xstrndup(const char *str, size_t len);
/* Bit-counting: used primarily by HAMT but also in a few other places. */
#define SK5 0x55555555
while (cur) {
next = STAILQ_NEXT(cur, link);
if (cur->val)
- xfree(cur->val);
+ yasm_xfree(cur->val);
if (cur->param)
yasm_expr_delete(cur->param);
- xfree(cur);
+ yasm_xfree(cur);
cur = next;
}
STAILQ_INIT(headp);
void yasm_vp_new(/*@out@*/ yasm_valparam *r, /*@keep@*/ const char *v,
/*@keep@*/ yasm_expr *p);
-#define yasm_vp_new(r, v, p) do { \
- r = xmalloc(sizeof(yasm_valparam)); \
- r->val = v; \
- r->param = p; \
+#define yasm_vp_new(r, v, p) do { \
+ r = yasm_xmalloc(sizeof(yasm_valparam)); \
+ r->val = v; \
+ r->param = p; \
} while(0)
/* void yasm_vps_initialize(//@out@// yasm_valparamhead *headp); */
#ifndef WITH_DMALLOC
-void *
-xmalloc(size_t size)
+static /*@only@*/ /*@out@*/ void *def_xmalloc(size_t size);
+static /*@only@*/ void *def_xcalloc(size_t nelem, size_t elsize);
+static /*@only@*/ void *def_xrealloc
+ (/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size)
+ /*@modifies oldmem@*/;
+static void def_xfree(/*@only@*/ /*@out@*/ /*@null@*/ void *p)
+ /*@modifies p@*/;
+
+/* storage for global function pointers */
+/*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size) = def_xmalloc;
+/*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize) = def_xcalloc;
+/*@only@*/ void * (*yasm_xrealloc)
+ (/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size)
+ /*@modifies oldmem@*/ = def_xrealloc;
+void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p)
+ /*@modifies p@*/ = def_xfree;
+
+
+static void *
+def_xmalloc(size_t size)
{
void *newmem;
return newmem;
}
-void *
-xcalloc(size_t nelem, size_t elsize)
+static void *
+def_xcalloc(size_t nelem, size_t elsize)
{
void *newmem;
return newmem;
}
-void *
-xrealloc(void *oldmem, size_t size)
+static void *
+def_xrealloc(void *oldmem, size_t size)
{
void *newmem;
return newmem;
}
-void
-xfree(void *p)
+static void
+def_xfree(void *p)
{
if (!p)
return;
#ifndef WITH_DMALLOC
char *
-xstrdup(const char *str)
+yasm__xstrdup(const char *str)
{
size_t len;
char *copy;
len = strlen(str) + 1;
- copy = xmalloc(len);
+ copy = yasm_xmalloc(len);
memcpy(copy, str, len);
return (copy);
}
#endif
char *
-xstrndup(const char *str, size_t len)
+yasm__xstrndup(const char *str, size_t len)
{
char *copy;
- copy = xmalloc(len+1);
+ copy = yasm_xmalloc(len+1);
memcpy(copy, str, len);
copy[len] = '\0';
return (copy);
if (yasm_x86__set_rex_from_reg(rex, &rm, reg, bits, X86_REX_B))
return NULL;
- x86_ea = xmalloc(sizeof(x86_effaddr));
+ x86_ea = yasm_xmalloc(sizeof(x86_effaddr));
x86_ea->ea.disp = (yasm_expr *)NULL;
x86_ea->ea.len = 0;
{
x86_effaddr *x86_ea;
- x86_ea = xmalloc(sizeof(x86_effaddr));
+ x86_ea = yasm_xmalloc(sizeof(x86_effaddr));
x86_ea->ea.disp = e;
x86_ea->ea.len = 0;
{
x86_effaddr *x86_ea;
- x86_ea = xmalloc(sizeof(x86_effaddr));
+ x86_ea = yasm_xmalloc(sizeof(x86_effaddr));
x86_ea->ea.disp = imm;
x86_ea->ea.len = im_len;
yasm_ea_delete((yasm_effaddr *)insn->ea);
if (insn->imm) {
yasm_expr_delete(insn->imm->val);
- xfree(insn->imm);
+ yasm_xfree(insn->imm);
}
break;
case X86_BC_JMPREL:
insn->opcode[0] = insn->opcode[1];
/* Delete imm, as it's not needed. */
yasm_expr_delete(imm->val);
- xfree(imm);
+ yasm_xfree(imm);
insn->imm = (yasm_immval *)NULL;
}
} else
yasm__error(lindex,
N_("invalid combination of opcode and operands"));
if (d.ea)
- xfree(d.ea);
+ yasm_xfree(d.ea);
return NULL;
}
} else
/* Don't bother doing anything else if size ended up being 0. */
if (size == 0) {
if (bigbuf)
- xfree(bigbuf);
+ yasm_xfree(bigbuf);
return 0;
}
/* If bigbuf was allocated, free it */
if (bigbuf)
- xfree(bigbuf);
+ yasm_xfree(bigbuf);
return 0;
}
bin_objfmt_output_info info;
info.f = f;
- info.buf = xmalloc(REGULAR_OUTBUF_SIZE);
+ info.buf = yasm_xmalloc(REGULAR_OUTBUF_SIZE);
text = yasm_sections_find_general(sections, ".text");
data = yasm_sections_find_general(sections, ".data");
/* If .bss is present, check it for non-reserve bytecodes */
- xfree(info.buf);
+ yasm_xfree(info.buf);
}
static void
if (isnew) {
if (have_alignval) {
- unsigned long *data = xmalloc(sizeof(unsigned long));
+ unsigned long *data = yasm_xmalloc(sizeof(unsigned long));
*data = alignval;
yasm_section_set_of_data(retval, &yasm_bin_LTX_objfmt, data);
}
static void
bin_objfmt_section_data_delete(/*@only@*/ void *d)
{
- xfree(d);
+ yasm_xfree(d);
}
static void
sym_data_prev = yasm_symrec_get_of_data(entry->sym);
assert(sym_data_prev != NULL);
- sym_data = xmalloc(sizeof(coff_symrec_data));
+ sym_data = yasm_xmalloc(sizeof(coff_symrec_data));
sym_data->index = sym_data_prev->index + entry->numaux + 1;
sym_data->sclass = sclass;
sym_data->size = size;
yasm_symrec_set_of_data(sym, &yasm_coff_LTX_objfmt, sym_data);
- entry = xmalloc(sizeof(coff_symtab_entry) +
- (numaux-1)*sizeof(coff_symtab_auxent));
+ entry = yasm_xmalloc(sizeof(coff_symtab_entry) +
+ (numaux-1)*sizeof(coff_symtab_auxent));
entry->sym = sym;
entry->numaux = numaux;
entry->auxtype = auxtype;
coff_objfmt_parse_scnum = 1; /* section numbering starts at 1 */
STAILQ_INIT(&coff_symtab);
- data = xmalloc(sizeof(coff_symrec_data));
+ data = yasm_xmalloc(sizeof(coff_symrec_data));
data->index = 0;
data->sclass = COFF_SCL_FILE;
data->size = NULL;
filesym = yasm_symrec_define_label(".file", NULL, NULL, 0, 0);
yasm_symrec_set_of_data(filesym, &yasm_coff_LTX_objfmt, data);
- entry = xmalloc(sizeof(coff_symtab_entry));
+ entry = yasm_xmalloc(sizeof(coff_symtab_entry));
entry->sym = filesym;
entry->numaux = 1;
entry->auxtype = COFF_SYMTAB_AUX_FILE;
- entry->aux[0].fname = xstrdup(in_filename);
+ entry->aux[0].fname = yasm__xstrdup(in_filename);
STAILQ_INSERT_TAIL(&coff_symtab, entry, link);
}
return 1;
}
- reloc = xmalloc(sizeof(coff_reloc));
+ reloc = yasm_xmalloc(sizeof(coff_reloc));
reloc->addr = bc->offset + offset;
if (COFF_SET_VMA)
reloc->addr += info->addr;
/* Don't bother doing anything else if size ended up being 0. */
if (size == 0) {
if (bigbuf)
- xfree(bigbuf);
+ yasm_xfree(bigbuf);
return 0;
}
/* If bigbuf was allocated, free it */
if (bigbuf)
- xfree(bigbuf);
+ yasm_xfree(bigbuf);
return 0;
}
coff_symtab_entry *entry;
info.f = f;
- info.buf = xmalloc(REGULAR_OUTBUF_SIZE);
+ info.buf = yasm_xmalloc(REGULAR_OUTBUF_SIZE);
/* Allocate space for headers by seeking forward */
if (fseek(f, 20+40*(coff_objfmt_parse_scnum-1), SEEK_SET) < 0) {
yasm_sections_traverse(sections, &info, coff_objfmt_output_secthead);
- xfree(info.buf);
+ yasm_xfree(info.buf);
}
static void
while (entry1 != NULL) {
entry2 = STAILQ_NEXT(entry1, link);
if (entry1->numaux == 1 && entry1->auxtype == COFF_SYMTAB_AUX_FILE)
- xfree(entry1->aux[0].fname);
- xfree(entry1);
+ yasm_xfree(entry1->aux[0].fname);
+ yasm_xfree(entry1);
entry1 = entry2;
}
}
coff_section_data *data;
yasm_symrec *sym;
- data = xmalloc(sizeof(coff_section_data));
+ data = yasm_xmalloc(sizeof(coff_section_data));
data->scnum = coff_objfmt_parse_scnum++;
data->flags = flags;
data->addr = 0;
r1 = STAILQ_FIRST(&csd->relocs);
while (r1 != NULL) {
r2 = STAILQ_NEXT(r1, link);
- xfree(r1);
+ yasm_xfree(r1);
r1 = r2;
}
- xfree(data);
+ yasm_xfree(data);
}
static void
coff_symrec_data *csymd = (coff_symrec_data *)data;
if (csymd->size)
yasm_expr_delete(csymd->size);
- xfree(data);
+ yasm_xfree(data);
}
static void
dbg_objfmt_section_data_delete(/*@only@*/ void *data)
{
fprintf(dbg_objfmt_file, "section_data_delete(%p)\n", data);
- xfree(data);
+ yasm_xfree(data);
}
static void
dbg_objfmt_bc_objfmt_data_delete(unsigned int type, /*@only@*/ void *data)
{
fprintf(dbg_objfmt_file, "symrec_data_delete(%u, %p)\n", type, data);
- xfree(data);
+ yasm_xfree(data);
}
static void
yasm_intnum_get_uint($4));
yasm_intnum_delete($2);
yasm_intnum_delete($4);
- xfree($5);
+ yasm_xfree($5);
$$ = (yasm_bytecode *)NULL;
}
| '[' { nasm_parser_set_directive_state(); } directive ']' '\n' {
| label TIMES expr exp { $$ = $4; yasm_bc_set_multiple($$, $3); }
| label_id_equ EQU expr {
yasm_symrec_define_equ($1, $3, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
$$ = (yasm_bytecode *)NULL;
}
;
label: label_id {
yasm_symrec_define_label($1, nasm_parser_cur_section,
nasm_parser_prev_bc, 1, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
}
| label_id ':' {
yasm_symrec_define_label($1, nasm_parser_cur_section,
nasm_parser_prev_bc, 1, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
}
;
label_id: ID {
$$ = $1;
if (nasm_parser_locallabel_base)
- xfree(nasm_parser_locallabel_base);
+ yasm_xfree(nasm_parser_locallabel_base);
nasm_parser_locallabel_base_len = strlen($1);
nasm_parser_locallabel_base =
- xmalloc(nasm_parser_locallabel_base_len+1);
+ yasm_xmalloc(nasm_parser_locallabel_base_len+1);
strcpy(nasm_parser_locallabel_base, $1);
}
| SPECIAL_ID
/* directives */
directive: DIRECTIVE_NAME directive_val {
- xfree($1);
+ yasm_xfree($1);
}
| DIRECTIVE_NAME error {
yasm__error(cur_lindex, N_("invalid arguments to [%s]"), $1);
- xfree($1);
+ yasm_xfree($1);
}
;
*/
const /*@null@*/ yasm_symrec *vp_symrec;
if ((vp_symrec = yasm_expr_get_symrec(&$1, 0))) {
- yasm_vp_new($$, xstrdup(yasm_symrec_get_name(vp_symrec)), NULL);
+ yasm_vp_new($$, yasm__xstrdup(yasm_symrec_get_name(vp_symrec)),
+ NULL);
yasm_expr_delete($1);
} else {
yasm_expr__traverse_leaves_in($1, NULL, fix_directive_symrec);
| ID {
$$ = p_expr_new_ident(yasm_expr_sym(
yasm_symrec_define_label($1, NULL, NULL, 0, cur_lindex)));
- xfree($1);
+ yasm_xfree($1);
}
| direxpr '|' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_OR, $3); }
| direxpr '^' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_XOR, $3); }
| STRING {
$$ = p_expr_new_ident(yasm_expr_int(
yasm_intnum_new_charconst_nasm($1, cur_lindex)));
- xfree($1);
+ yasm_xfree($1);
}
| explabel { $$ = p_expr_new_ident(yasm_expr_sym($1)); }
/*| expr '||' expr { $$ = p_expr_new_tree($1, YASM_EXPR_LOR, $3); }*/
explabel: ID {
$$ = yasm_symrec_use($1, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
}
| SPECIAL_ID {
$$ = yasm_symrec_use($1, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
}
| LOCAL_ID {
$$ = yasm_symrec_use($1, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
}
| '$' {
/* "$" references the current assembly position */
/* Free locallabel base if necessary */
if (nasm_parser_locallabel_base)
- xfree(nasm_parser_locallabel_base);
+ yasm_xfree(nasm_parser_locallabel_base);
return &nasm_parser_sections;
}
if (!s.bot)
first = 1;
if((s.top - s.lim) < BSIZE){
- char *buf = xmalloc((s.lim - s.bot) + BSIZE);
+ char *buf = yasm_xmalloc((s.lim - s.bot) + BSIZE);
memcpy(buf, s.tok, s.lim - s.tok);
s.tok = buf;
s.ptr = &buf[s.ptr - s.bot];
s.lim = &buf[s.lim - s.bot];
s.top = &s.lim[BSIZE];
if (s.bot)
- xfree(s.bot);
+ yasm_xfree(s.bot);
s.bot = buf;
}
if((cnt = nasm_parser_input(s.lim, BSIZE)) == 0){
static void
delete_line(/*@only@*/ void *data)
{
- xfree(data);
+ yasm_xfree(data);
}
static YYCTYPE *
/* save previous line using assoc_data */
nasm_parser_linemgr->add_assoc_data(YASM_LINEMGR_STD_TYPE_SOURCE,
- xstrdup(cur_line), delete_line);
+ yasm__xstrdup(cur_line), delete_line);
/* save next line into cur_line */
if ((YYLIMIT - YYCURSOR) < 80)
YYFILL(80);
nasm_parser_cleanup(void)
{
if (s.bot)
- xfree(s.bot);
+ yasm_xfree(s.bot);
}
/* starting size of string buffer */
/* special non-local ..@label and labels like ..start */
".." [a-zA-Z0-9_$#@~.?]+ {
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(SPECIAL_ID);
}
"." [a-zA-Z0-9_$#@~?][a-zA-Z0-9_$#@~.?]* {
/* override local labels in directive state */
if (state == DIRECTIVE2) {
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(ID);
} else if (!nasm_parser_locallabel_base) {
yasm__warning(YASM_WARN_GENERAL, cur_lindex,
N_("no non-local label before `%s'"), s.tok[0]);
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
} else {
len = TOKLEN + nasm_parser_locallabel_base_len;
- yylval.str_val = xmalloc(len + 1);
+ yylval.str_val = yasm_xmalloc(len + 1);
strcpy(yylval.str_val, nasm_parser_locallabel_base);
strncat(yylval.str_val, s.tok, TOKLEN);
yylval.str_val[len] = '\0';
/* forced identifier */
"$" [a-zA-Z_?][a-zA-Z0-9_$#@~.?]* {
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(ID);
}
switch (check_id_ret) {
case YASM_ARCH_CHECK_ID_NONE:
/* Just an identifier, return as such. */
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(ID);
case YASM_ARCH_CHECK_ID_INSN:
RETURN(INSN);
default:
yasm__warning(YASM_WARN_GENERAL, cur_lindex,
N_("Arch feature not supported, treating as identifier"));
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(ID);
}
}
(any \ [\r\n])+ {
state = LINECHG;
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(FILENAME);
}
*/
iletter+ {
state = DIRECTIVE2;
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(DIRECTIVE_NAME);
}
/* string/character constant values */
stringconst:
- strbuf = xmalloc(STRBUF_ALLOC_SIZE);
+ strbuf = yasm_xmalloc(STRBUF_ALLOC_SIZE);
strbuf_size = STRBUF_ALLOC_SIZE;
count = 0;
strbuf[count++] = s.tok[0];
if (count >= strbuf_size) {
- strbuf = xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE);
+ strbuf = yasm_xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE);
strbuf_size += STRBUF_ALLOC_SIZE;
}
tot += n;
if (n == lineleft) {
- xfree(line);
+ yasm_xfree(line);
line = NULL;
} else {
lineleft -= n;
* passed a NULL pointer; nasm_free will do nothing if it is passed
* a NULL pointer.
*/
-#define nasm_malloc xmalloc
-#define nasm_realloc xrealloc
-#define nasm_free(p) if (p) xfree(p)
-#define nasm_strdup xstrdup
-#define nasm_strndup xstrndup
+#define nasm_malloc yasm_xmalloc
+#define nasm_realloc yasm_xrealloc
+#define nasm_free(p) yasm_xfree(p)
+#define nasm_strdup yasm__xstrdup
+#define nasm_strndup yasm__xstrndup
#define nasm_stricmp yasm__strcasecmp
#define nasm_strnicmp yasm__strncasecmp
YAPP_Macro *
yapp_macro_insert (char *name, int argc, int fillargs)
{
- YAPP_Macro *ym = xmalloc(sizeof(YAPP_Macro));
+ YAPP_Macro *ym = yasm_xmalloc(sizeof(YAPP_Macro));
ym->type = YAPP_MACRO;
ym->args = argc;
ym->fillargs = fillargs;
else if (argc >= 0)
{
/* insert placeholder for paramlisted defines */
- ym = xmalloc(sizeof(YAPP_Macro));
+ ym = yasm_xmalloc(sizeof(YAPP_Macro));
ym->type = YAPP_DEFINE;
ym->args = argc;
ym->fillargs = fillargs;
}
/* now for the real one */
- ym = xmalloc(sizeof(YAPP_Macro));
+ ym = yasm_xmalloc(sizeof(YAPP_Macro));
ym->type = YAPP_DEFINE;
ym->args = argc;
ym->fillargs = fillargs;
ym->expanding = 0;
if (argc>=0) {
- mungename = xmalloc(strlen(name)+8);
+ mungename = yasm_xmalloc(strlen(name)+8);
sprintf(mungename, "%s(%d)", name, argc);
}
{
while (!SLIST_EMPTY(&ym->macro_head)) {
source *s = SLIST_FIRST(&ym->macro_head);
- xfree(s);
+ yasm_xfree(s);
SLIST_REMOVE_HEAD(&ym->macro_head, next);
}
- xfree(ym);
+ yasm_xfree(ym);
}
static YAPP_Macro *
{
is_interactive = f ? (isatty(fileno(f)) > 0) : 0;
yapp_preproc_linemgr = lm;
- yapp_preproc_current_file = xstrdup(in_filename);
+ yapp_preproc_current_file = yasm__xstrdup(in_filename);
yapp_preproc_line_number = 1;
yapp_lex_initialize(f);
SLIST_INIT(&output_head);
SLIST_INIT(&source_head);
SLIST_INIT(¯o_head);
SLIST_INIT(¶m_head);
- out = xmalloc(sizeof(output));
+ out = yasm_xmalloc(sizeof(output));
out->out = current_output = YAPP_OUTPUT;
SLIST_INSERT_HEAD(&output_head, out, next);
static void
push_if(int val)
{
- out = xmalloc(sizeof(output));
+ out = yasm_xmalloc(sizeof(output));
out->out = current_output;
SLIST_INSERT_HEAD(&output_head, out, next);
out = SLIST_FIRST(&output_head);
current_output = out->out;
SLIST_REMOVE_HEAD(&output_head, next);
- xfree(out);
+ yasm_xfree(out);
if (current_output != YAPP_OUTPUT) set_inhibit();
}
if ((*to_tail) && (*to_tail)->token.type == LINE
&& (token == '\n' || token == LINE))
{
- xfree ((*to_tail)->token.str);
- (*to_tail)->token.str = xmalloc(23+strlen(yapp_preproc_current_file));
+ yasm_xfree ((*to_tail)->token.str);
+ (*to_tail)->token.str = yasm_xmalloc(23+strlen(yapp_preproc_current_file));
sprintf((*to_tail)->token.str, "%%line %d+1 %s\n", yapp_preproc_line_number, yapp_preproc_current_file);
}
else {
- src = xmalloc(sizeof(source));
+ src = yasm_xmalloc(sizeof(source));
src->token.type = token;
switch (token)
{
case INTNUM:
- src->token.str = xstrdup(yapp_preproc_lval.int_str_val.str);
+ src->token.str = yasm__xstrdup(yapp_preproc_lval.int_str_val.str);
src->token.val.int_val = yapp_preproc_lval.int_str_val.val;
break;
case FLTNUM:
- src->token.str = xstrdup(yapp_preproc_lval.double_str_val.str);
+ src->token.str = yasm__xstrdup(yapp_preproc_lval.double_str_val.str);
src->token.val.double_val = yapp_preproc_lval.double_str_val.val;
break;
case STRING:
case WHITESPACE:
- src->token.str = xstrdup(yapp_preproc_lval.str_val);
+ src->token.str = yasm__xstrdup(yapp_preproc_lval.str_val);
break;
case IDENT:
- src->token.str = xstrdup(yapp_preproc_lval.str_val);
+ src->token.str = yasm__xstrdup(yapp_preproc_lval.str_val);
break;
case '+': case '-': case '*': case '/': case '%': case ',': case '\n':
case '[': case ']': case '(': case ')':
- src->token.str = xmalloc(2);
+ src->token.str = yasm_xmalloc(2);
src->token.str[0] = (char)token;
src->token.str[1] = '\0';
break;
case LINE:
/* TODO: consider removing any trailing newline or LINE tokens */
- src->token.str = xmalloc(23+strlen(yapp_preproc_current_file));
+ src->token.str = yasm_xmalloc(23+strlen(yapp_preproc_current_file));
sprintf(src->token.str, "%%line %d+1 %s\n", yapp_preproc_line_number, yapp_preproc_current_file);
break;
default:
- xfree(src);
+ yasm_xfree(src);
return;
}
append_processed_token(src, to_head, to_tail);
void
copy_token(YAPP_Token *tok, struct source_head *to_head, source **to_tail)
{
- src = xmalloc(sizeof(source));
+ src = yasm_xmalloc(sizeof(source));
src->token.type = tok->type;
- src->token.str = xstrdup(tok->str);
+ src->token.str = yasm__xstrdup(tok->str);
append_processed_token(src, to_head, to_tail);
}
}
/* Now we have the argument count; let's see if it exists */
- mungename = xmalloc(strlen(name)+8);
+ mungename = yasm_xmalloc(strlen(name)+8);
sprintf(mungename, "%s(%d)", name, argc);
ym = yapp_macro_get(mungename);
if (!ym)
{
ydebug(("YAPP: -Didn't find macro %s\n", mungename));
replay_saved_tokens(name, &replay_head, to_head, to_tail);
- xfree(mungename);
+ yasm_xfree(mungename);
return;
}
ydebug(("YAPP: +Found macro %s\n", mungename));
while (replay->token.type != '(') {
ydebug(("YAPP: Ignoring replay token '%c' \"%s\"\n", replay->token.type, replay->token.str));
SLIST_REMOVE_HEAD(&replay_head, next);
- xfree(replay->token.str);
- xfree(replay);
+ yasm_xfree(replay->token.str);
+ yasm_xfree(replay);
replay = SLIST_FIRST(&replay_head);
}
ydebug(("YAPP: Ignoring replay token '%c' \"%s\"\n", replay->token.type, replay->token.str));
/* free the open paren */
SLIST_REMOVE_HEAD(&replay_head, next);
- xfree(replay->token.str);
- xfree(replay);
+ yasm_xfree(replay->token.str);
+ yasm_xfree(replay);
param = SLIST_FIRST(&ym->param_head);
|| replay->token.type == ')'))
{
int zero=0;
- struct source_head *argmacro = xmalloc(sizeof(struct source_head));
+ struct source_head *argmacro = yasm_xmalloc(sizeof(struct source_head));
memcpy(argmacro, &arg_head, sizeof(struct source_head));
SLIST_INIT(&arg_head);
arg_tail = SLIST_FIRST(&arg_head);
/* don't save the comma */
- xfree(replay->token.str);
- xfree(replay);
+ yasm_xfree(replay->token.str);
+ yasm_xfree(replay);
HAMT_insert(param_table,
param->token.str,
if (replay) SLIST_REMOVE_HEAD(&replay_head, next);
}
if (replay) {
- xfree(replay->token.str);
- xfree(replay);
+ yasm_xfree(replay->token.str);
+ yasm_xfree(replay);
}
else if (param) {
yasm_internal_error(N_("Got to end of arglist before end of replay!"));
ydebug(("YAPP: define: "));
token = yapp_get_ident("define");
ydebug((" \"%s\"\n", yapp_preproc_lval.str_val));
- s = xstrdup(yapp_preproc_lval.str_val);
+ s = yasm__xstrdup(yapp_preproc_lval.str_val);
/* three cases: newline or stuff or left paren */
token = yapp_preproc_lex();
saved_length -= strlen(src->token.str);
SLIST_REMOVE_HEAD(&source_head, next);
- xfree(src->token.str);
- xfree(src);
+ yasm_xfree(src->token.str);
+ yasm_xfree(src);
}
}
#define yylval yapp_preproc_lval
+#define malloc yasm_xmalloc
+#define realloc yasm_xrealloc
+
/* starting size of string buffer */
#define STRBUF_ALLOC_SIZE 128
int inch, count;
char endch = yytext[0];
- strbuf = xmalloc(STRBUF_ALLOC_SIZE);
+ strbuf = yasm_xmalloc(STRBUF_ALLOC_SIZE);
strbuf_size = STRBUF_ALLOC_SIZE;
inch = input();
while(inch != EOF && inch != endch && inch != '\n') {
strbuf[count++] = inch;
if(count >= strbuf_size) {
- strbuf = xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE);
+ strbuf = yasm_xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE);
strbuf_size += STRBUF_ALLOC_SIZE;
}
inch = input();
\.\.[a-z0-9_$#@~.?]+ |
\.[a-z0-9_$#@~?][a-z0-9_$#@~.?]* |
[a-z_?][a-z0-9_$#@~.?]* {
- yylval.str_val = xstrdup(yytext);
+ yylval.str_val = yasm__xstrdup(yytext);
return IDENT;
}
<incl>[^ \t\n"]* { /* have the filename */
include *inc;
FILE *incfile;
- inc = xmalloc(sizeof(include));
+ inc = yasm_xmalloc(sizeof(include));
inc->include_state = YY_CURRENT_BUFFER;
/* FIXME: handle includes that aren't relative */
if(!incfile) {
yasm__error(cur_lindex, _("include file `%s': %s"),
yytext, strerror(errno));
- xfree(inc);
+ yasm_xfree(inc);
}
else {
yyin = incfile;
SLIST_INSERT_HEAD(&includes_head, inc, next);
yapp_preproc_line_number = 1;
- yapp_preproc_current_file = xstrdup(yytext);
+ yapp_preproc_current_file = yasm__xstrdup(yytext);
BEGIN(INITIAL);
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
}
inc = SLIST_FIRST(&includes_head);
yy_delete_buffer (YY_CURRENT_BUFFER);
yy_switch_to_buffer (inc->include_state);
- xfree(yapp_preproc_current_file);
+ yasm_xfree(yapp_preproc_current_file);
yapp_preproc_current_file = inc->filename;
yapp_preproc_line_number = inc->line_number + 1;
SLIST_REMOVE_HEAD(&includes_head, next);
- xfree(inc);
+ yasm_xfree(inc);
BEGIN(incl);
return INCLUDE;
}
<line>{WS}+["] ; /* eat space before file */
<line>[^ \t\n"]* { /* have the filename */
- xfree(yapp_preproc_current_file);
- yapp_preproc_current_file = xstrdup(yytext);
+ yasm_xfree(yapp_preproc_current_file);
+ yapp_preproc_current_file = yasm__xstrdup(yytext);
}
<line>["]{WS}*\n {
BEGIN(INITIAL);
yasm_insn_operand *
yasm_operand_new_reg(unsigned long reg)
{
- yasm_insn_operand *retval = xmalloc(sizeof(yasm_insn_operand));
+ yasm_insn_operand *retval = yasm_xmalloc(sizeof(yasm_insn_operand));
retval->type = YASM_INSN__OPERAND_REG;
retval->data.reg = reg;
yasm_insn_operand *
yasm_operand_new_segreg(unsigned long segreg)
{
- yasm_insn_operand *retval = xmalloc(sizeof(yasm_insn_operand));
+ yasm_insn_operand *retval = yasm_xmalloc(sizeof(yasm_insn_operand));
retval->type = YASM_INSN__OPERAND_SEGREG;
retval->data.reg = segreg;
yasm_insn_operand *
yasm_operand_new_mem(/*@only@*/ yasm_effaddr *ea)
{
- yasm_insn_operand *retval = xmalloc(sizeof(yasm_insn_operand));
+ yasm_insn_operand *retval = yasm_xmalloc(sizeof(yasm_insn_operand));
retval->type = YASM_INSN__OPERAND_MEMORY;
retval->data.ea = ea;
retval = yasm_operand_new_reg(*reg);
yasm_expr_delete(val);
} else {
- retval = xmalloc(sizeof(yasm_insn_operand));
+ retval = yasm_xmalloc(sizeof(yasm_insn_operand));
retval->type = YASM_INSN__OPERAND_IMM;
retval->data.val = val;
retval->targetmod = 0;
default:
break;
}
- xfree(cur);
+ yasm_xfree(cur);
cur = next;
}
STAILQ_INIT(headp);
if (yasm_x86__set_rex_from_reg(rex, &rm, reg, bits, X86_REX_B))
return NULL;
- x86_ea = xmalloc(sizeof(x86_effaddr));
+ x86_ea = yasm_xmalloc(sizeof(x86_effaddr));
x86_ea->ea.disp = (yasm_expr *)NULL;
x86_ea->ea.len = 0;
{
x86_effaddr *x86_ea;
- x86_ea = xmalloc(sizeof(x86_effaddr));
+ x86_ea = yasm_xmalloc(sizeof(x86_effaddr));
x86_ea->ea.disp = e;
x86_ea->ea.len = 0;
{
x86_effaddr *x86_ea;
- x86_ea = xmalloc(sizeof(x86_effaddr));
+ x86_ea = yasm_xmalloc(sizeof(x86_effaddr));
x86_ea->ea.disp = imm;
x86_ea->ea.len = im_len;
yasm_ea_delete((yasm_effaddr *)insn->ea);
if (insn->imm) {
yasm_expr_delete(insn->imm->val);
- xfree(insn->imm);
+ yasm_xfree(insn->imm);
}
break;
case X86_BC_JMPREL:
insn->opcode[0] = insn->opcode[1];
/* Delete imm, as it's not needed. */
yasm_expr_delete(imm->val);
- xfree(imm);
+ yasm_xfree(imm);
insn->imm = (yasm_immval *)NULL;
}
} else
yasm__error(lindex,
N_("invalid combination of opcode and operands"));
if (d.ea)
- xfree(d.ea);
+ yasm_xfree(d.ea);
return NULL;
}
} else
FACTOR = LOGBITS - 3; /* ld(BITS / 8) = ld(BITS) - ld(8) = ld(BITS) - 3 */
MSB = (LSB << MODMASK);
- BITMASKTAB = (wordptr) xmalloc((size_t) (BITS << FACTOR));
+ BITMASKTAB = (wordptr) yasm_xmalloc((size_t) (BITS << FACTOR));
if (BITMASKTAB == NULL) return(ErrCode_Null);
void BitVector_Shutdown(void)
{
- if (BITMASKTAB) xfree(BITMASKTAB);
+ if (BITMASKTAB) yasm_xfree(BITMASKTAB);
}
N_word BitVector_Size(N_int bits) /* bit vector size (# of words) */
void BitVector_Dispose(charptr string) /* free string */
{
- if (string != NULL) xfree((voidptr) string);
+ if (string != NULL) yasm_xfree((voidptr) string);
}
void BitVector_Destroy(wordptr addr) /* free bitvec */
if (addr != NULL)
{
addr -= BIT_VECTOR_HIDDEN_WORDS;
- xfree((voidptr) addr);
+ yasm_xfree((voidptr) addr);
}
}
size = BitVector_Size(bits);
mask = BitVector_Mask(bits);
bytes = (size + BIT_VECTOR_HIDDEN_WORDS) << FACTOR;
- addr = (wordptr) xmalloc((size_t) bytes);
+ addr = (wordptr) yasm_xmalloc((size_t) bytes);
if (addr != NULL)
{
*addr++ = bits;
else
{
bytes = (newsize + BIT_VECTOR_HIDDEN_WORDS) << FACTOR;
- newaddr = (wordptr) xmalloc((size_t) bytes);
+ newaddr = (wordptr) yasm_xmalloc((size_t) bytes);
if (newaddr != NULL)
{
*newaddr++ = bits;
length = bits >> 2;
if (bits AND 0x0003) length++;
- string = (charptr) xmalloc((size_t) (length+1));
+ string = (charptr) yasm_xmalloc((size_t) (length+1));
if (string == NULL) return(NULL);
string += length;
*string = (N_char) '\0';
charptr string;
length = bits_(addr);
- string = (charptr) xmalloc((size_t) (length+1));
+ string = (charptr) yasm_xmalloc((size_t) (length+1));
if (string == NULL) return(NULL);
string += length;
*string = (N_char) '\0';
length = (N_word) (bits / 3.3); /* digits = bits * ln(2) / ln(10) */
length += 2; /* compensate for truncating & provide space for minus sign */
- result = (charptr) xmalloc((size_t) (length+1)); /* remember the '\0'! */
+ result = (charptr) yasm_xmalloc((size_t) (length+1)); /* remember the '\0'! */
if (result == NULL) return(NULL);
string = result;
sign = BitVector_Sign(addr);
}
}
else length = 1;
- string = (charptr) xmalloc((size_t) length);
+ string = (charptr) yasm_xmalloc((size_t) length);
if (string == NULL) return(NULL);
start = 0;
comma = FALSE;
/* provide translation for independence of endian-ness: */
*length = size << FACTOR;
- buffer = (charptr) xmalloc((size_t) ((*length)+1));
+ buffer = (charptr) yasm_xmalloc((size_t) ((*length)+1));
if (buffer == NULL) return(NULL);
target = buffer;
if (size > 0)
yasm_immval *
yasm_imm_new_expr(yasm_expr *expr_ptr)
{
- yasm_immval *im = xmalloc(sizeof(yasm_immval));
+ yasm_immval *im = yasm_xmalloc(sizeof(yasm_immval));
im->val = expr_ptr;
im->len = 0;
if (cur_arch->ea_data_delete)
cur_arch->ea_data_delete(ea);
yasm_expr_delete(ea->disp);
- xfree(ea);
+ yasm_xfree(ea);
}
/*@=nullstate@*/
yasm_bytecode *
yasm_bc_new_common(yasm_bytecode_type type, size_t size, unsigned long lindex)
{
- yasm_bytecode *bc = xmalloc(size);
+ yasm_bytecode *bc = yasm_xmalloc(size);
bc->type = type;
break;
case YASM_BC__INCBIN:
incbin = (bytecode_incbin *)bc;
- xfree(incbin->filename);
+ yasm_xfree(incbin->filename);
yasm_expr_delete(incbin->start);
yasm_expr_delete(incbin->maxlen);
break;
/*@=branchstate@*/
yasm_expr_delete(bc->multiple);
- xfree(bc);
+ yasm_xfree(bc);
}
void
*gap = 0;
if (*bufsize < datasize) {
- mybuf = xmalloc(sizeof(bc->len));
+ mybuf = yasm_xmalloc(sizeof(bc->len));
origbuf = mybuf;
destbuf = mybuf;
} else {
STAILQ_INSERT_TAIL(headp, bc, link);
return bc;
} else {
- xfree(bc);
+ yasm_xfree(bc);
}
}
return (yasm_bytecode *)NULL;
yasm_dataval *
yasm_dv_new_expr(yasm_expr *expn)
{
- yasm_dataval *retval = xmalloc(sizeof(yasm_dataval));
+ yasm_dataval *retval = yasm_xmalloc(sizeof(yasm_dataval));
retval->type = DV_EXPR;
retval->data.expn = expn;
yasm_dataval *
yasm_dv_new_string(char *str_val)
{
- yasm_dataval *retval = xmalloc(sizeof(yasm_dataval));
+ yasm_dataval *retval = yasm_xmalloc(sizeof(yasm_dataval));
retval->type = DV_STRING;
retval->data.str_val = str_val;
yasm_expr_delete(cur->data.expn);
break;
case DV_STRING:
- xfree(cur->data.str_val);
+ yasm_xfree(cur->data.str_val);
break;
default:
break;
}
- xfree(cur);
+ yasm_xfree(cur);
cur = next;
}
STAILQ_INIT(headp);
we = SLIST_FIRST(&errwarns);
SLIST_REMOVE_HEAD(&errwarns, link);
- xfree(we);
+ yasm_xfree(we);
}
}
we = ins_we;
} else {
/* add a new error */
- we = xmalloc(sizeof(errwarn_data));
+ we = yasm_xmalloc(sizeof(errwarn_data));
we->type = WE_UNKNOWN;
we->line = lindex;
unsigned long lindex)
{
yasm_expr *ptr, *sube;
- ptr = xmalloc(sizeof(yasm_expr));
+ ptr = yasm_xmalloc(sizeof(yasm_expr));
ptr->op = op;
ptr->numterms = 0;
ptr->terms[1].type = YASM_EXPR_NONE;
if (left) {
ptr->terms[0] = *left; /* structure copy */
- xfree(left);
+ yasm_xfree(left);
ptr->numterms++;
/* Search downward until we find something *other* than an
sube = ptr->terms[0].data.expn;
ptr->terms[0] = sube->terms[0]; /* structure copy */
/*@-usereleased@*/
- xfree(sube);
+ yasm_xfree(sube);
/*@=usereleased@*/
}
} else {
if (right) {
ptr->terms[1] = *right; /* structure copy */
- xfree(right);
+ yasm_xfree(right);
ptr->numterms++;
/* Search downward until we find something *other* than an
sube = ptr->terms[1].data.expn;
ptr->terms[1] = sube->terms[0]; /* structure copy */
/*@-usereleased@*/
- xfree(sube);
+ yasm_xfree(sube);
/*@=usereleased@*/
}
}
yasm_expr__item *
yasm_expr_sym(yasm_symrec *s)
{
- yasm_expr__item *e = xmalloc(sizeof(yasm_expr__item));
+ yasm_expr__item *e = yasm_xmalloc(sizeof(yasm_expr__item));
e->type = YASM_EXPR_SYM;
e->data.sym = s;
return e;
yasm_expr__item *
yasm_expr_expr(yasm_expr *x)
{
- yasm_expr__item *e = xmalloc(sizeof(yasm_expr__item));
+ yasm_expr__item *e = yasm_xmalloc(sizeof(yasm_expr__item));
e->type = YASM_EXPR_EXPR;
e->data.expn = x;
return e;
yasm_expr__item *
yasm_expr_int(yasm_intnum *i)
{
- yasm_expr__item *e = xmalloc(sizeof(yasm_expr__item));
+ yasm_expr__item *e = yasm_xmalloc(sizeof(yasm_expr__item));
e->type = YASM_EXPR_INT;
e->data.intn = i;
return e;
yasm_expr__item *
yasm_expr_float(yasm_floatnum *f)
{
- yasm_expr__item *e = xmalloc(sizeof(yasm_expr__item));
+ yasm_expr__item *e = yasm_xmalloc(sizeof(yasm_expr__item));
e->type = YASM_EXPR_FLOAT;
e->data.flt = f;
return e;
yasm_expr__item *
yasm_expr_reg(unsigned long reg)
{
- yasm_expr__item *e = xmalloc(sizeof(yasm_expr__item));
+ yasm_expr__item *e = yasm_xmalloc(sizeof(yasm_expr__item));
e->type = YASM_EXPR_REG;
e->data.reg = reg;
return e;
}
if (e->numterms != numterms) {
e->numterms = numterms;
- e = xrealloc(e, sizeof(yasm_expr)+((numterms<2) ? 0 :
- sizeof(yasm_expr__item)*(numterms-2)));
+ e = yasm_xrealloc(e, sizeof(yasm_expr)+((numterms<2) ? 0 :
+ sizeof(yasm_expr__item)*(numterms-2)));
if (numterms == 1)
e->op = YASM_EXPR_IDENT;
}
static void
expr_xform_neg_item(yasm_expr *e, yasm_expr__item *ei)
{
- yasm_expr *sube = xmalloc(sizeof(yasm_expr));
+ yasm_expr *sube = yasm_xmalloc(sizeof(yasm_expr));
/* Build -1*ei subexpression */
sube->op = YASM_EXPR_MUL;
/* Everything else. MUL will be combined when it's leveled.
* Make a new expr (to replace e) with -1*e.
*/
- ne = xmalloc(sizeof(yasm_expr));
+ ne = yasm_xmalloc(sizeof(yasm_expr));
ne->op = YASM_EXPR_MUL;
ne->line = e->line;
ne->numterms = 2;
*/
while (e->op == YASM_EXPR_IDENT && e->terms[0].type == YASM_EXPR_EXPR) {
yasm_expr *sube = e->terms[0].data.expn;
- xfree(e);
+ yasm_xfree(e);
e = sube;
}
level_numterms = e->numterms;
e->terms[i].data.expn->op == YASM_EXPR_IDENT) {
yasm_expr *sube = e->terms[i].data.expn;
e->terms[i] = sube->terms[0];
- xfree(sube);
+ yasm_xfree(sube);
}
if (e->terms[i].type == YASM_EXPR_EXPR &&
level_numterms <= fold_numterms) {
/* Downsize e if necessary */
if (fold_numterms < e->numterms && e->numterms > 2)
- e = xrealloc(e, sizeof(yasm_expr)+((fold_numterms<2) ? 0 :
- sizeof(yasm_expr__item)*(fold_numterms-2)));
+ e = yasm_xrealloc(e, sizeof(yasm_expr)+((fold_numterms<2) ? 0 :
+ sizeof(yasm_expr__item)*(fold_numterms-2)));
/* Update numterms */
e->numterms = fold_numterms;
return e;
}
/* Alloc more (or conceivably less, but not usually) space for e */
- e = xrealloc(e, sizeof(yasm_expr)+((level_numterms<2) ? 0 :
- sizeof(yasm_expr__item)*(level_numterms-2)));
+ e = yasm_xrealloc(e, sizeof(yasm_expr)+((level_numterms<2) ? 0 :
+ sizeof(yasm_expr__item)*(level_numterms-2)));
/* Copy up ExprItem's. Iterate from right to left to keep the same
* ordering as was present originally.
/* delete subexpression, but *don't delete nodes* (as we've just
* copied them!)
*/
- xfree(sube);
+ yasm_xfree(sube);
} else if (o != i) {
/* copy operand if it changed places */
if (o == first_int_term)
yasm_expr *n;
int i;
- n = xmalloc(sizeof(yasm_expr) +
- sizeof(yasm_expr__item)*(e->numterms<2?0:e->numterms-2));
+ n = yasm_xmalloc(sizeof(yasm_expr) +
+ sizeof(yasm_expr__item)*(e->numterms<2?0:e->numterms-2));
n->op = e->op;
n->line = e->line;
break; /* none of the other types needs to be deleted */
}
}
- xfree(e); /* free ourselves */
+ yasm_xfree(e); /* free ourselves */
return 0; /* don't stop recursion */
}
int i;
/* Allocate space for two POT tables */
- POT_TableN = xmalloc(14*sizeof(POT_Entry));
- POT_TableP = xmalloc(15*sizeof(POT_Entry)); /* note 1 extra for -1 */
+ POT_TableN = yasm_xmalloc(14*sizeof(POT_Entry));
+ POT_TableP = yasm_xmalloc(15*sizeof(POT_Entry)); /* note 1 extra for -1 */
/* Initialize entry[0..12] */
for (i=12; i>=0; i--) {
}
BitVector_Destroy(POT_TableP[14].f.mantissa);
- xfree(POT_TableN);
- xfree(POT_TableP);
+ yasm_xfree(POT_TableN);
+ yasm_xfree(POT_TableP);
}
/*@=globstate@*/
int decimal_pt;
boolean carry;
- flt = xmalloc(sizeof(yasm_floatnum));
+ flt = yasm_xmalloc(sizeof(yasm_floatnum));
flt->mantissa = BitVector_Create(MANT_BITS, TRUE);
yasm_floatnum *
yasm_floatnum_copy(const yasm_floatnum *flt)
{
- yasm_floatnum *f = xmalloc(sizeof(yasm_floatnum));
+ yasm_floatnum *f = yasm_xmalloc(sizeof(yasm_floatnum));
f->mantissa = BitVector_Clone(flt->mantissa);
f->exponent = flt->exponent;
yasm_floatnum_delete(yasm_floatnum *flt)
{
BitVector_Destroy(flt->mantissa);
- xfree(flt);
+ yasm_xfree(flt);
}
void
memcpy(ptr, buf, byte_size*sizeof(unsigned char));
/* free allocated resources */
- xfree(buf);
+ yasm_xfree(buf);
BitVector_Destroy(output);
str = BitVector_to_Hex(flt->mantissa);
fprintf(f, "%c %s *2^%04x\n", flt->sign?'-':'+', (char *)str,
flt->exponent);
- xfree(str);
+ yasm_xfree(str);
/* 32-bit (single precision) format */
fprintf(f, "32-bit: %d: ", yasm_floatnum_get_sized(flt, out, 4));
HAMT_new(/*@exits@*/ void (*error_func) (const char *file, unsigned int line,
const char *message))
{
- /*@out@*/ HAMT *hamt = xmalloc(sizeof(HAMT));
+ /*@out@*/ HAMT *hamt = yasm_xmalloc(sizeof(HAMT));
int i;
SLIST_INIT(&hamt->entries);
- hamt->root = xmalloc(32*sizeof(HAMTNode));
+ hamt->root = yasm_xmalloc(32*sizeof(HAMTNode));
for (i=0; i<32; i++) {
hamt->root[i].BitMapKey = 0;
for (i=0; i<Size; i++)
HAMT_delete_trie(&(GetSubTrie(node))[i]);
- xfree(GetSubTrie(node));
+ yasm_xfree(GetSubTrie(node));
}
}
entry = SLIST_FIRST(&hamt->entries);
SLIST_REMOVE_HEAD(&hamt->entries, next);
deletefunc(entry->data);
- xfree(entry);
+ yasm_xfree(entry);
}
/* delete trie */
for (i=0; i<32; i++)
HAMT_delete_trie(&hamt->root[i]);
- xfree(hamt->root);
- xfree(hamt);
+ yasm_xfree(hamt->root);
+ yasm_xfree(hamt);
}
int
if (!node->BaseValue) {
node->BitMapKey = key;
- entry = xmalloc(sizeof(HAMTEntry));
+ entry = yasm_xmalloc(sizeof(HAMTEntry));
entry->str = str;
entry->data = data;
SLIST_INSERT_HEAD(&hamt->entries, entry, next);
/* Still equal, build one-node subtrie and continue
* downward.
*/
- newnodes = xmalloc(sizeof(HAMTNode));
+ newnodes = yasm_xmalloc(sizeof(HAMTNode));
newnodes[0] = *node; /* structure copy */
node->BitMapKey = 1<<keypart;
SetSubTrie(hamt, node, newnodes);
level++;
} else {
/* partitioned: allocate two-node subtrie */
- newnodes = xmalloc(2*sizeof(HAMTNode));
+ newnodes = yasm_xmalloc(2*sizeof(HAMTNode));
- entry = xmalloc(sizeof(HAMTEntry));
+ entry = yasm_xmalloc(sizeof(HAMTEntry));
entry->str = str;
entry->data = data;
SLIST_INSERT_HEAD(&hamt->entries, entry, next);
/* Count total number of bits in bitmap to determine new size */
BitCount(Size, node->BitMapKey);
Size &= 0x1F; /* Clamp to <32 */
- newnodes = xmalloc(Size*sizeof(HAMTNode));
+ newnodes = yasm_xmalloc(Size*sizeof(HAMTNode));
/* Count bits below to find where to insert new node at */
BitCount(Map, node->BitMapKey & ~((~0UL)<<keypart));
memcpy(&newnodes[Map+1], &(GetSubTrie(node))[Map],
(Size-Map-1)*sizeof(HAMTNode));
/* Delete old subtrie */
- xfree(GetSubTrie(node));
+ yasm_xfree(GetSubTrie(node));
/* Set up new node */
newnodes[Map].BitMapKey = key;
- entry = xmalloc(sizeof(HAMTEntry));
+ entry = yasm_xmalloc(sizeof(HAMTEntry));
entry->str = str;
entry->data = data;
SLIST_INSERT_HEAD(&hamt->entries, entry, next);
yasm_intnum *
yasm_intnum_new_dec(char *str, unsigned long lindex)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
intn->origsize = 0; /* no reliable way to figure this out */
yasm_intnum *
yasm_intnum_new_bin(char *str, unsigned long lindex)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
intn->origsize = (unsigned char)strlen(str);
yasm_intnum *
yasm_intnum_new_oct(char *str, unsigned long lindex)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
intn->origsize = strlen(str)*3;
yasm_intnum *
yasm_intnum_new_hex(char *str, unsigned long lindex)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
intn->origsize = strlen(str)*4;
yasm_intnum *
yasm_intnum_new_charconst_nasm(const char *str, unsigned long lindex)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
size_t len = strlen(str);
if (len > 4)
yasm_intnum *
yasm_intnum_new_uint(unsigned long i)
{
- yasm_intnum *intn = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
intn->val.ul = i;
intn->type = INTNUM_UL;
yasm_intnum *
yasm_intnum_copy(const yasm_intnum *intn)
{
- yasm_intnum *n = xmalloc(sizeof(yasm_intnum));
+ yasm_intnum *n = yasm_xmalloc(sizeof(yasm_intnum));
switch (intn->type) {
case INTNUM_UL:
{
if (intn->type == INTNUM_BV)
BitVector_Destroy(intn->val.bv);
- xfree(intn);
+ yasm_xfree(intn);
}
/*@-nullderef -nullpass -branchstate@*/
if (len < (unsigned int)size)
yasm_internal_error(N_("Invalid size specified (too large)"));
memcpy(ptr, buf, size);
- xfree(buf);
+ yasm_xfree(buf);
break;
}
}
case INTNUM_BV:
s = BitVector_to_Hex(intn->val.bv);
fprintf(f, "0x%s/%u", (char *)s, (unsigned int)intn->origsize);
- xfree(s);
+ yasm_xfree(s);
break;
}
}
static void
filename_delete_one(/*@only@*/ void *d)
{
- xfree(d);
+ yasm_xfree(d);
}
static void
/* Create a new mapping in the map */
if (line_index_map->size >= line_index_map->allocated) {
/* allocate another size bins when full for 2x space */
- line_index_map->vector = xrealloc(line_index_map->vector,
- 2*line_index_map->allocated*sizeof(line_index_mapping));
+ line_index_map->vector =
+ yasm_xrealloc(line_index_map->vector, 2*line_index_map->allocated
+ *sizeof(line_index_mapping));
line_index_map->allocated *= 2;
}
mapping = &line_index_map->vector[line_index_map->size];
/* Fill it */
/* Copy the filename (via shared storage) */
- copy = xstrdup(filename);
+ copy = yasm__xstrdup(filename);
/*@-aliasunique@*/
mapping->filename = HAMT_insert(filename_table, copy, copy, &replace,
filename_delete_one);
line_index = 1;
/* initialize mapping vector */
- line_index_map = xmalloc(sizeof(line_index_mapping_head));
- line_index_map->vector = xmalloc(8*sizeof(line_index_mapping));
+ line_index_map = yasm_xmalloc(sizeof(line_index_mapping_head));
+ line_index_map->vector = yasm_xmalloc(8*sizeof(line_index_mapping));
line_index_map->size = 0;
line_index_map->allocated = 8;
/* initialize associated data arrays */
line_index_assoc_data_array =
- xmalloc(MAX_LINE_INDEX_ASSOC_DATA_ARRAY *
- sizeof(line_index_assoc_data_raw_head));
+ yasm_xmalloc(MAX_LINE_INDEX_ASSOC_DATA_ARRAY *
+ sizeof(line_index_assoc_data_raw_head));
for (i=0; i<MAX_LINE_INDEX_ASSOC_DATA_ARRAY; i++) {
line_index_assoc_data_array[i].vector = NULL;
line_index_assoc_data_array[i].size = 0;
if (adrh->vector[j])
adrh->delete_func(adrh->vector[j]);
}
- xfree(adrh->vector);
+ yasm_xfree(adrh->vector);
}
}
- xfree(line_index_assoc_data_array);
+ yasm_xfree(line_index_assoc_data_array);
line_index_assoc_data_array = NULL;
}
if (line_index_map) {
- xfree(line_index_map->vector);
- xfree(line_index_map);
+ yasm_xfree(line_index_map->vector);
+ yasm_xfree(line_index_map);
line_index_map = NULL;
}
int i;
adrh->size = 4;
- adrh->vector = xmalloc(adrh->size*sizeof(void *));
+ adrh->vector = yasm_xmalloc(adrh->size*sizeof(void *));
adrh->delete_func = delete_func;
for (i=0; i<adrh->size; i++)
adrh->vector[i] = NULL;
int i;
/* allocate another size bins when full for 2x space */
- adrh->vector = xrealloc(adrh->vector, 2*adrh->size*sizeof(void *));
+ adrh->vector = yasm_xrealloc(adrh->vector,
+ 2*adrh->size*sizeof(void *));
for(i=adrh->size; i<adrh->size*2; i++)
adrh->vector[i] = NULL;
adrh->size *= 2;
lt_dlmalloc = malloc;
lt_dlfree = free;
#else
- lt_dlmalloc = xmalloc;
- lt_dlfree = xfree;
+ lt_dlmalloc = yasm_xmalloc;
+ lt_dlfree = yasm_xfree;
#endif
/* Initialize preloaded symbol lookup table. */
in = fopen(in_filename, "rt");
if (!in) {
print_error(_("could not open file `%s'"), in_filename);
- xfree(in_filename);
+ yasm_xfree(in_filename);
if (obj_filename)
- xfree(obj_filename);
+ yasm_xfree(obj_filename);
return EXIT_FAILURE;
}
} else {
/* If no files were specified or filename was "-", read stdin */
in = stdin;
if (!in_filename)
- in_filename = xstrdup("-");
+ in_filename = yasm__xstrdup("-");
}
/* Initialize line manager */
/* handle preproc-only case here */
if (preproc_only) {
- char *preproc_buf = xmalloc(PREPROC_BUF_SIZE);
+ char *preproc_buf = yasm_xmalloc(PREPROC_BUF_SIZE);
size_t got;
/* Default output to stdout if not specified */
/* Open output (object) file */
obj = open_obj("wt");
if (!obj) {
- xfree(preproc_buf);
+ yasm_xfree(preproc_buf);
return EXIT_FAILURE;
}
}
print_yasm_error, print_yasm_warning);
if (obj != stdout)
remove(obj_filename);
- xfree(preproc_buf);
+ yasm_xfree(preproc_buf);
cleanup(NULL);
return EXIT_FAILURE;
}
- xfree(preproc_buf);
+ yasm_xfree(preproc_buf);
cleanup(NULL);
return EXIT_SUCCESS;
}
if (!obj_filename) {
if (in == stdin)
/* Default to yasm.out if no obj filename specified */
- obj_filename = xstrdup("yasm.out");
+ obj_filename = yasm__xstrdup("yasm.out");
else
/* replace (or add) extension */
obj_filename = replace_extension(in_filename,
if (DO_FREE) {
if (in_filename)
- xfree(in_filename);
+ yasm_xfree(in_filename);
if (obj_filename)
- xfree(obj_filename);
+ yasm_xfree(obj_filename);
}
}
if (in_filename) {
print_error(
_("warning: can open only one input file, only the last file will be processed"));
- xfree(in_filename);
+ yasm_xfree(in_filename);
}
- in_filename = xstrdup(param);
+ in_filename = yasm__xstrdup(param);
return 0;
}
if (obj_filename) {
print_error(
_("warning: can output to only one object file, last specified used"));
- xfree(obj_filename);
+ yasm_xfree(obj_filename);
}
assert(param != NULL);
- obj_filename = xstrdup(param);
+ obj_filename = yasm__xstrdup(param);
return 0;
}
char *out, *outext;
/* allocate enough space for full existing name + extension */
- out = xmalloc(strlen(orig)+(ext ? (strlen(ext)+2) : 1));
+ out = yasm_xmalloc(strlen(orig)+(ext ? (strlen(ext)+2) : 1));
strcpy(out, orig);
outext = strrchr(out, '.');
if (outext) {
}
/* Look for dynamic module. First build full module name from keyword. */
- name = xmalloc(5+strlen(keyword)+1);
+ name = yasm_xmalloc(5+strlen(keyword)+1);
strcpy(name, "yasm-");
strcat(name, keyword);
handle = lt_dlopenext(name);
if (!handle) {
- xfree(name);
+ yasm_xfree(name);
return NULL;
}
- m = xmalloc(sizeof(module));
+ m = yasm_xmalloc(sizeof(module));
m->keyword = name;
strcpy(m->keyword, keyword);
m->handle = handle;
while (!SLIST_EMPTY(&modules)) {
m = SLIST_FIRST(&modules);
SLIST_REMOVE_HEAD(&modules, link);
- xfree(m->keyword);
+ yasm_xfree(m->keyword);
lt_dlclose(m->handle);
- xfree(m);
+ yasm_xfree(m);
}
}
/* Don't bother doing anything else if size ended up being 0. */
if (size == 0) {
if (bigbuf)
- xfree(bigbuf);
+ yasm_xfree(bigbuf);
return 0;
}
/* If bigbuf was allocated, free it */
if (bigbuf)
- xfree(bigbuf);
+ yasm_xfree(bigbuf);
return 0;
}
bin_objfmt_output_info info;
info.f = f;
- info.buf = xmalloc(REGULAR_OUTBUF_SIZE);
+ info.buf = yasm_xmalloc(REGULAR_OUTBUF_SIZE);
text = yasm_sections_find_general(sections, ".text");
data = yasm_sections_find_general(sections, ".data");
/* If .bss is present, check it for non-reserve bytecodes */
- xfree(info.buf);
+ yasm_xfree(info.buf);
}
static void
if (isnew) {
if (have_alignval) {
- unsigned long *data = xmalloc(sizeof(unsigned long));
+ unsigned long *data = yasm_xmalloc(sizeof(unsigned long));
*data = alignval;
yasm_section_set_of_data(retval, &yasm_bin_LTX_objfmt, data);
}
static void
bin_objfmt_section_data_delete(/*@only@*/ void *d)
{
- xfree(d);
+ yasm_xfree(d);
}
static void
sym_data_prev = yasm_symrec_get_of_data(entry->sym);
assert(sym_data_prev != NULL);
- sym_data = xmalloc(sizeof(coff_symrec_data));
+ sym_data = yasm_xmalloc(sizeof(coff_symrec_data));
sym_data->index = sym_data_prev->index + entry->numaux + 1;
sym_data->sclass = sclass;
sym_data->size = size;
yasm_symrec_set_of_data(sym, &yasm_coff_LTX_objfmt, sym_data);
- entry = xmalloc(sizeof(coff_symtab_entry) +
- (numaux-1)*sizeof(coff_symtab_auxent));
+ entry = yasm_xmalloc(sizeof(coff_symtab_entry) +
+ (numaux-1)*sizeof(coff_symtab_auxent));
entry->sym = sym;
entry->numaux = numaux;
entry->auxtype = auxtype;
coff_objfmt_parse_scnum = 1; /* section numbering starts at 1 */
STAILQ_INIT(&coff_symtab);
- data = xmalloc(sizeof(coff_symrec_data));
+ data = yasm_xmalloc(sizeof(coff_symrec_data));
data->index = 0;
data->sclass = COFF_SCL_FILE;
data->size = NULL;
filesym = yasm_symrec_define_label(".file", NULL, NULL, 0, 0);
yasm_symrec_set_of_data(filesym, &yasm_coff_LTX_objfmt, data);
- entry = xmalloc(sizeof(coff_symtab_entry));
+ entry = yasm_xmalloc(sizeof(coff_symtab_entry));
entry->sym = filesym;
entry->numaux = 1;
entry->auxtype = COFF_SYMTAB_AUX_FILE;
- entry->aux[0].fname = xstrdup(in_filename);
+ entry->aux[0].fname = yasm__xstrdup(in_filename);
STAILQ_INSERT_TAIL(&coff_symtab, entry, link);
}
return 1;
}
- reloc = xmalloc(sizeof(coff_reloc));
+ reloc = yasm_xmalloc(sizeof(coff_reloc));
reloc->addr = bc->offset + offset;
if (COFF_SET_VMA)
reloc->addr += info->addr;
/* Don't bother doing anything else if size ended up being 0. */
if (size == 0) {
if (bigbuf)
- xfree(bigbuf);
+ yasm_xfree(bigbuf);
return 0;
}
/* If bigbuf was allocated, free it */
if (bigbuf)
- xfree(bigbuf);
+ yasm_xfree(bigbuf);
return 0;
}
coff_symtab_entry *entry;
info.f = f;
- info.buf = xmalloc(REGULAR_OUTBUF_SIZE);
+ info.buf = yasm_xmalloc(REGULAR_OUTBUF_SIZE);
/* Allocate space for headers by seeking forward */
if (fseek(f, 20+40*(coff_objfmt_parse_scnum-1), SEEK_SET) < 0) {
yasm_sections_traverse(sections, &info, coff_objfmt_output_secthead);
- xfree(info.buf);
+ yasm_xfree(info.buf);
}
static void
while (entry1 != NULL) {
entry2 = STAILQ_NEXT(entry1, link);
if (entry1->numaux == 1 && entry1->auxtype == COFF_SYMTAB_AUX_FILE)
- xfree(entry1->aux[0].fname);
- xfree(entry1);
+ yasm_xfree(entry1->aux[0].fname);
+ yasm_xfree(entry1);
entry1 = entry2;
}
}
coff_section_data *data;
yasm_symrec *sym;
- data = xmalloc(sizeof(coff_section_data));
+ data = yasm_xmalloc(sizeof(coff_section_data));
data->scnum = coff_objfmt_parse_scnum++;
data->flags = flags;
data->addr = 0;
r1 = STAILQ_FIRST(&csd->relocs);
while (r1 != NULL) {
r2 = STAILQ_NEXT(r1, link);
- xfree(r1);
+ yasm_xfree(r1);
r1 = r2;
}
- xfree(data);
+ yasm_xfree(data);
}
static void
coff_symrec_data *csymd = (coff_symrec_data *)data;
if (csymd->size)
yasm_expr_delete(csymd->size);
- xfree(data);
+ yasm_xfree(data);
}
static void
dbg_objfmt_section_data_delete(/*@only@*/ void *data)
{
fprintf(dbg_objfmt_file, "section_data_delete(%p)\n", data);
- xfree(data);
+ yasm_xfree(data);
}
static void
dbg_objfmt_bc_objfmt_data_delete(unsigned int type, /*@only@*/ void *data)
{
fprintf(dbg_objfmt_file, "symrec_data_delete(%u, %p)\n", type, data);
- xfree(data);
+ yasm_xfree(data);
}
static void
yasm_intnum_get_uint($4));
yasm_intnum_delete($2);
yasm_intnum_delete($4);
- xfree($5);
+ yasm_xfree($5);
$$ = (yasm_bytecode *)NULL;
}
| '[' { nasm_parser_set_directive_state(); } directive ']' '\n' {
| label TIMES expr exp { $$ = $4; yasm_bc_set_multiple($$, $3); }
| label_id_equ EQU expr {
yasm_symrec_define_equ($1, $3, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
$$ = (yasm_bytecode *)NULL;
}
;
label: label_id {
yasm_symrec_define_label($1, nasm_parser_cur_section,
nasm_parser_prev_bc, 1, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
}
| label_id ':' {
yasm_symrec_define_label($1, nasm_parser_cur_section,
nasm_parser_prev_bc, 1, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
}
;
label_id: ID {
$$ = $1;
if (nasm_parser_locallabel_base)
- xfree(nasm_parser_locallabel_base);
+ yasm_xfree(nasm_parser_locallabel_base);
nasm_parser_locallabel_base_len = strlen($1);
nasm_parser_locallabel_base =
- xmalloc(nasm_parser_locallabel_base_len+1);
+ yasm_xmalloc(nasm_parser_locallabel_base_len+1);
strcpy(nasm_parser_locallabel_base, $1);
}
| SPECIAL_ID
/* directives */
directive: DIRECTIVE_NAME directive_val {
- xfree($1);
+ yasm_xfree($1);
}
| DIRECTIVE_NAME error {
yasm__error(cur_lindex, N_("invalid arguments to [%s]"), $1);
- xfree($1);
+ yasm_xfree($1);
}
;
*/
const /*@null@*/ yasm_symrec *vp_symrec;
if ((vp_symrec = yasm_expr_get_symrec(&$1, 0))) {
- yasm_vp_new($$, xstrdup(yasm_symrec_get_name(vp_symrec)), NULL);
+ yasm_vp_new($$, yasm__xstrdup(yasm_symrec_get_name(vp_symrec)),
+ NULL);
yasm_expr_delete($1);
} else {
yasm_expr__traverse_leaves_in($1, NULL, fix_directive_symrec);
| ID {
$$ = p_expr_new_ident(yasm_expr_sym(
yasm_symrec_define_label($1, NULL, NULL, 0, cur_lindex)));
- xfree($1);
+ yasm_xfree($1);
}
| direxpr '|' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_OR, $3); }
| direxpr '^' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_XOR, $3); }
| STRING {
$$ = p_expr_new_ident(yasm_expr_int(
yasm_intnum_new_charconst_nasm($1, cur_lindex)));
- xfree($1);
+ yasm_xfree($1);
}
| explabel { $$ = p_expr_new_ident(yasm_expr_sym($1)); }
/*| expr '||' expr { $$ = p_expr_new_tree($1, YASM_EXPR_LOR, $3); }*/
explabel: ID {
$$ = yasm_symrec_use($1, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
}
| SPECIAL_ID {
$$ = yasm_symrec_use($1, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
}
| LOCAL_ID {
$$ = yasm_symrec_use($1, cur_lindex);
- xfree($1);
+ yasm_xfree($1);
}
| '$' {
/* "$" references the current assembly position */
/* Free locallabel base if necessary */
if (nasm_parser_locallabel_base)
- xfree(nasm_parser_locallabel_base);
+ yasm_xfree(nasm_parser_locallabel_base);
return &nasm_parser_sections;
}
if (!s.bot)
first = 1;
if((s.top - s.lim) < BSIZE){
- char *buf = xmalloc((s.lim - s.bot) + BSIZE);
+ char *buf = yasm_xmalloc((s.lim - s.bot) + BSIZE);
memcpy(buf, s.tok, s.lim - s.tok);
s.tok = buf;
s.ptr = &buf[s.ptr - s.bot];
s.lim = &buf[s.lim - s.bot];
s.top = &s.lim[BSIZE];
if (s.bot)
- xfree(s.bot);
+ yasm_xfree(s.bot);
s.bot = buf;
}
if((cnt = nasm_parser_input(s.lim, BSIZE)) == 0){
static void
delete_line(/*@only@*/ void *data)
{
- xfree(data);
+ yasm_xfree(data);
}
static YYCTYPE *
/* save previous line using assoc_data */
nasm_parser_linemgr->add_assoc_data(YASM_LINEMGR_STD_TYPE_SOURCE,
- xstrdup(cur_line), delete_line);
+ yasm__xstrdup(cur_line), delete_line);
/* save next line into cur_line */
if ((YYLIMIT - YYCURSOR) < 80)
YYFILL(80);
nasm_parser_cleanup(void)
{
if (s.bot)
- xfree(s.bot);
+ yasm_xfree(s.bot);
}
/* starting size of string buffer */
/* special non-local ..@label and labels like ..start */
".." [a-zA-Z0-9_$#@~.?]+ {
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(SPECIAL_ID);
}
"." [a-zA-Z0-9_$#@~?][a-zA-Z0-9_$#@~.?]* {
/* override local labels in directive state */
if (state == DIRECTIVE2) {
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(ID);
} else if (!nasm_parser_locallabel_base) {
yasm__warning(YASM_WARN_GENERAL, cur_lindex,
N_("no non-local label before `%s'"), s.tok[0]);
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
} else {
len = TOKLEN + nasm_parser_locallabel_base_len;
- yylval.str_val = xmalloc(len + 1);
+ yylval.str_val = yasm_xmalloc(len + 1);
strcpy(yylval.str_val, nasm_parser_locallabel_base);
strncat(yylval.str_val, s.tok, TOKLEN);
yylval.str_val[len] = '\0';
/* forced identifier */
"$" [a-zA-Z_?][a-zA-Z0-9_$#@~.?]* {
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(ID);
}
switch (check_id_ret) {
case YASM_ARCH_CHECK_ID_NONE:
/* Just an identifier, return as such. */
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(ID);
case YASM_ARCH_CHECK_ID_INSN:
RETURN(INSN);
default:
yasm__warning(YASM_WARN_GENERAL, cur_lindex,
N_("Arch feature not supported, treating as identifier"));
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(ID);
}
}
(any \ [\r\n])+ {
state = LINECHG;
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(FILENAME);
}
*/
iletter+ {
state = DIRECTIVE2;
- yylval.str_val = xstrndup(s.tok, TOKLEN);
+ yylval.str_val = yasm__xstrndup(s.tok, TOKLEN);
RETURN(DIRECTIVE_NAME);
}
/* string/character constant values */
stringconst:
- strbuf = xmalloc(STRBUF_ALLOC_SIZE);
+ strbuf = yasm_xmalloc(STRBUF_ALLOC_SIZE);
strbuf_size = STRBUF_ALLOC_SIZE;
count = 0;
strbuf[count++] = s.tok[0];
if (count >= strbuf_size) {
- strbuf = xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE);
+ strbuf = yasm_xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE);
strbuf_size += STRBUF_ALLOC_SIZE;
}
tot += n;
if (n == lineleft) {
- xfree(line);
+ yasm_xfree(line);
line = NULL;
} else {
lineleft -= n;
* passed a NULL pointer; nasm_free will do nothing if it is passed
* a NULL pointer.
*/
-#define nasm_malloc xmalloc
-#define nasm_realloc xrealloc
-#define nasm_free(p) if (p) xfree(p)
-#define nasm_strdup xstrdup
-#define nasm_strndup xstrndup
+#define nasm_malloc yasm_xmalloc
+#define nasm_realloc yasm_xrealloc
+#define nasm_free(p) yasm_xfree(p)
+#define nasm_strdup yasm__xstrdup
+#define nasm_strndup yasm__xstrndup
#define nasm_stricmp yasm__strcasecmp
#define nasm_strnicmp yasm__strncasecmp
YAPP_Macro *
yapp_macro_insert (char *name, int argc, int fillargs)
{
- YAPP_Macro *ym = xmalloc(sizeof(YAPP_Macro));
+ YAPP_Macro *ym = yasm_xmalloc(sizeof(YAPP_Macro));
ym->type = YAPP_MACRO;
ym->args = argc;
ym->fillargs = fillargs;
else if (argc >= 0)
{
/* insert placeholder for paramlisted defines */
- ym = xmalloc(sizeof(YAPP_Macro));
+ ym = yasm_xmalloc(sizeof(YAPP_Macro));
ym->type = YAPP_DEFINE;
ym->args = argc;
ym->fillargs = fillargs;
}
/* now for the real one */
- ym = xmalloc(sizeof(YAPP_Macro));
+ ym = yasm_xmalloc(sizeof(YAPP_Macro));
ym->type = YAPP_DEFINE;
ym->args = argc;
ym->fillargs = fillargs;
ym->expanding = 0;
if (argc>=0) {
- mungename = xmalloc(strlen(name)+8);
+ mungename = yasm_xmalloc(strlen(name)+8);
sprintf(mungename, "%s(%d)", name, argc);
}
{
while (!SLIST_EMPTY(&ym->macro_head)) {
source *s = SLIST_FIRST(&ym->macro_head);
- xfree(s);
+ yasm_xfree(s);
SLIST_REMOVE_HEAD(&ym->macro_head, next);
}
- xfree(ym);
+ yasm_xfree(ym);
}
static YAPP_Macro *
{
is_interactive = f ? (isatty(fileno(f)) > 0) : 0;
yapp_preproc_linemgr = lm;
- yapp_preproc_current_file = xstrdup(in_filename);
+ yapp_preproc_current_file = yasm__xstrdup(in_filename);
yapp_preproc_line_number = 1;
yapp_lex_initialize(f);
SLIST_INIT(&output_head);
SLIST_INIT(&source_head);
SLIST_INIT(¯o_head);
SLIST_INIT(¶m_head);
- out = xmalloc(sizeof(output));
+ out = yasm_xmalloc(sizeof(output));
out->out = current_output = YAPP_OUTPUT;
SLIST_INSERT_HEAD(&output_head, out, next);
static void
push_if(int val)
{
- out = xmalloc(sizeof(output));
+ out = yasm_xmalloc(sizeof(output));
out->out = current_output;
SLIST_INSERT_HEAD(&output_head, out, next);
out = SLIST_FIRST(&output_head);
current_output = out->out;
SLIST_REMOVE_HEAD(&output_head, next);
- xfree(out);
+ yasm_xfree(out);
if (current_output != YAPP_OUTPUT) set_inhibit();
}
if ((*to_tail) && (*to_tail)->token.type == LINE
&& (token == '\n' || token == LINE))
{
- xfree ((*to_tail)->token.str);
- (*to_tail)->token.str = xmalloc(23+strlen(yapp_preproc_current_file));
+ yasm_xfree ((*to_tail)->token.str);
+ (*to_tail)->token.str = yasm_xmalloc(23+strlen(yapp_preproc_current_file));
sprintf((*to_tail)->token.str, "%%line %d+1 %s\n", yapp_preproc_line_number, yapp_preproc_current_file);
}
else {
- src = xmalloc(sizeof(source));
+ src = yasm_xmalloc(sizeof(source));
src->token.type = token;
switch (token)
{
case INTNUM:
- src->token.str = xstrdup(yapp_preproc_lval.int_str_val.str);
+ src->token.str = yasm__xstrdup(yapp_preproc_lval.int_str_val.str);
src->token.val.int_val = yapp_preproc_lval.int_str_val.val;
break;
case FLTNUM:
- src->token.str = xstrdup(yapp_preproc_lval.double_str_val.str);
+ src->token.str = yasm__xstrdup(yapp_preproc_lval.double_str_val.str);
src->token.val.double_val = yapp_preproc_lval.double_str_val.val;
break;
case STRING:
case WHITESPACE:
- src->token.str = xstrdup(yapp_preproc_lval.str_val);
+ src->token.str = yasm__xstrdup(yapp_preproc_lval.str_val);
break;
case IDENT:
- src->token.str = xstrdup(yapp_preproc_lval.str_val);
+ src->token.str = yasm__xstrdup(yapp_preproc_lval.str_val);
break;
case '+': case '-': case '*': case '/': case '%': case ',': case '\n':
case '[': case ']': case '(': case ')':
- src->token.str = xmalloc(2);
+ src->token.str = yasm_xmalloc(2);
src->token.str[0] = (char)token;
src->token.str[1] = '\0';
break;
case LINE:
/* TODO: consider removing any trailing newline or LINE tokens */
- src->token.str = xmalloc(23+strlen(yapp_preproc_current_file));
+ src->token.str = yasm_xmalloc(23+strlen(yapp_preproc_current_file));
sprintf(src->token.str, "%%line %d+1 %s\n", yapp_preproc_line_number, yapp_preproc_current_file);
break;
default:
- xfree(src);
+ yasm_xfree(src);
return;
}
append_processed_token(src, to_head, to_tail);
void
copy_token(YAPP_Token *tok, struct source_head *to_head, source **to_tail)
{
- src = xmalloc(sizeof(source));
+ src = yasm_xmalloc(sizeof(source));
src->token.type = tok->type;
- src->token.str = xstrdup(tok->str);
+ src->token.str = yasm__xstrdup(tok->str);
append_processed_token(src, to_head, to_tail);
}
}
/* Now we have the argument count; let's see if it exists */
- mungename = xmalloc(strlen(name)+8);
+ mungename = yasm_xmalloc(strlen(name)+8);
sprintf(mungename, "%s(%d)", name, argc);
ym = yapp_macro_get(mungename);
if (!ym)
{
ydebug(("YAPP: -Didn't find macro %s\n", mungename));
replay_saved_tokens(name, &replay_head, to_head, to_tail);
- xfree(mungename);
+ yasm_xfree(mungename);
return;
}
ydebug(("YAPP: +Found macro %s\n", mungename));
while (replay->token.type != '(') {
ydebug(("YAPP: Ignoring replay token '%c' \"%s\"\n", replay->token.type, replay->token.str));
SLIST_REMOVE_HEAD(&replay_head, next);
- xfree(replay->token.str);
- xfree(replay);
+ yasm_xfree(replay->token.str);
+ yasm_xfree(replay);
replay = SLIST_FIRST(&replay_head);
}
ydebug(("YAPP: Ignoring replay token '%c' \"%s\"\n", replay->token.type, replay->token.str));
/* free the open paren */
SLIST_REMOVE_HEAD(&replay_head, next);
- xfree(replay->token.str);
- xfree(replay);
+ yasm_xfree(replay->token.str);
+ yasm_xfree(replay);
param = SLIST_FIRST(&ym->param_head);
|| replay->token.type == ')'))
{
int zero=0;
- struct source_head *argmacro = xmalloc(sizeof(struct source_head));
+ struct source_head *argmacro = yasm_xmalloc(sizeof(struct source_head));
memcpy(argmacro, &arg_head, sizeof(struct source_head));
SLIST_INIT(&arg_head);
arg_tail = SLIST_FIRST(&arg_head);
/* don't save the comma */
- xfree(replay->token.str);
- xfree(replay);
+ yasm_xfree(replay->token.str);
+ yasm_xfree(replay);
HAMT_insert(param_table,
param->token.str,
if (replay) SLIST_REMOVE_HEAD(&replay_head, next);
}
if (replay) {
- xfree(replay->token.str);
- xfree(replay);
+ yasm_xfree(replay->token.str);
+ yasm_xfree(replay);
}
else if (param) {
yasm_internal_error(N_("Got to end of arglist before end of replay!"));
ydebug(("YAPP: define: "));
token = yapp_get_ident("define");
ydebug((" \"%s\"\n", yapp_preproc_lval.str_val));
- s = xstrdup(yapp_preproc_lval.str_val);
+ s = yasm__xstrdup(yapp_preproc_lval.str_val);
/* three cases: newline or stuff or left paren */
token = yapp_preproc_lex();
saved_length -= strlen(src->token.str);
SLIST_REMOVE_HEAD(&source_head, next);
- xfree(src->token.str);
- xfree(src);
+ yasm_xfree(src->token.str);
+ yasm_xfree(src);
}
}
#define yylval yapp_preproc_lval
+#define malloc yasm_xmalloc
+#define realloc yasm_xrealloc
+
/* starting size of string buffer */
#define STRBUF_ALLOC_SIZE 128
int inch, count;
char endch = yytext[0];
- strbuf = xmalloc(STRBUF_ALLOC_SIZE);
+ strbuf = yasm_xmalloc(STRBUF_ALLOC_SIZE);
strbuf_size = STRBUF_ALLOC_SIZE;
inch = input();
while(inch != EOF && inch != endch && inch != '\n') {
strbuf[count++] = inch;
if(count >= strbuf_size) {
- strbuf = xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE);
+ strbuf = yasm_xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE);
strbuf_size += STRBUF_ALLOC_SIZE;
}
inch = input();
\.\.[a-z0-9_$#@~.?]+ |
\.[a-z0-9_$#@~?][a-z0-9_$#@~.?]* |
[a-z_?][a-z0-9_$#@~.?]* {
- yylval.str_val = xstrdup(yytext);
+ yylval.str_val = yasm__xstrdup(yytext);
return IDENT;
}
<incl>[^ \t\n"]* { /* have the filename */
include *inc;
FILE *incfile;
- inc = xmalloc(sizeof(include));
+ inc = yasm_xmalloc(sizeof(include));
inc->include_state = YY_CURRENT_BUFFER;
/* FIXME: handle includes that aren't relative */
if(!incfile) {
yasm__error(cur_lindex, _("include file `%s': %s"),
yytext, strerror(errno));
- xfree(inc);
+ yasm_xfree(inc);
}
else {
yyin = incfile;
SLIST_INSERT_HEAD(&includes_head, inc, next);
yapp_preproc_line_number = 1;
- yapp_preproc_current_file = xstrdup(yytext);
+ yapp_preproc_current_file = yasm__xstrdup(yytext);
BEGIN(INITIAL);
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
}
inc = SLIST_FIRST(&includes_head);
yy_delete_buffer (YY_CURRENT_BUFFER);
yy_switch_to_buffer (inc->include_state);
- xfree(yapp_preproc_current_file);
+ yasm_xfree(yapp_preproc_current_file);
yapp_preproc_current_file = inc->filename;
yapp_preproc_line_number = inc->line_number + 1;
SLIST_REMOVE_HEAD(&includes_head, next);
- xfree(inc);
+ yasm_xfree(inc);
BEGIN(incl);
return INCLUDE;
}
<line>{WS}+["] ; /* eat space before file */
<line>[^ \t\n"]* { /* have the filename */
- xfree(yapp_preproc_current_file);
- yapp_preproc_current_file = xstrdup(yytext);
+ yasm_xfree(yapp_preproc_current_file);
+ yapp_preproc_current_file = yasm__xstrdup(yytext);
}
<line>["]{WS}*\n {
BEGIN(INITIAL);
STAILQ_INIT(headp);
/* Add an initial "default" section */
- yasm_vp_new(vp, xstrdup(of->default_section_name), NULL);
+ yasm_vp_new(vp, yasm__xstrdup(of->default_section_name), NULL);
yasm_vps_initialize(&vps);
yasm_vps_append(&vps, vp);
s = of->sections_switch(headp, &vps, NULL, 0);
/* No: we have to allocate and create a new one. */
/* Okay, the name is valid; now allocate and initialize */
- s = xcalloc(1, sizeof(yasm_section));
+ s = yasm_xcalloc(1, sizeof(yasm_section));
STAILQ_INSERT_TAIL(headp, s, link);
s->type = SECTION_GENERAL;
- s->data.general.name = xstrdup(name);
+ s->data.general.name = yasm__xstrdup(name);
s->data.general.of = NULL;
s->data.general.of_data = NULL;
s->start = yasm_expr_new_ident(yasm_expr_int(yasm_intnum_new_uint(start)),
{
yasm_section *s;
- s = xcalloc(1, sizeof(yasm_section));
+ s = yasm_xcalloc(1, sizeof(yasm_section));
STAILQ_INSERT_TAIL(headp, s, link);
s->type = SECTION_ABSOLUTE;
return;
if (sect->type == SECTION_GENERAL) {
- xfree(sect->data.general.name);
+ yasm_xfree(sect->data.general.name);
if (sect->data.general.of_data && sect->data.general.of) {
yasm_objfmt *of = sect->data.general.of;
if (of->section_data_delete)
}
yasm_expr_delete(sect->start);
yasm_bcs_delete(§->bc);
- xfree(sect);
+ yasm_xfree(sect);
}
void
yasm_symrec_initialize(void)
{
sym_table = HAMT_new(yasm_internal_error_);
- non_table_syms = xmalloc(sizeof(nontablesymhead));
+ non_table_syms = yasm_xmalloc(sizeof(nontablesymhead));
SLIST_INIT(non_table_syms);
}
symrec_delete_one(/*@only@*/ void *d)
{
yasm_symrec *sym = d;
- xfree(sym->name);
+ yasm_xfree(sym->name);
if (sym->type == SYM_EQU)
yasm_expr_delete(sym->value.expn);
if (sym->of_data && sym->of) {
yasm_internal_error(
N_("don't know how to delete objfmt-specific data"));
}
- xfree(sym);
+ yasm_xfree(sym);
}
static /*@partial@*/ yasm_symrec *
symrec_new_common(/*@keep@*/ char *name)
{
- yasm_symrec *rec = xmalloc(sizeof(yasm_symrec));
+ yasm_symrec *rec = yasm_xmalloc(sizeof(yasm_symrec));
rec->name = name;
rec->type = SYM_UNKNOWN;
rec->line = 0;
static /*@partial@*/ /*@dependent@*/ yasm_symrec *
symrec_get_or_new_not_in_table(/*@only@*/ char *name)
{
- non_table_symrec *sym = xmalloc(sizeof(non_table_symrec));
+ non_table_symrec *sym = yasm_xmalloc(sizeof(non_table_symrec));
sym->rec = symrec_new_common(name);
sym->rec->status = SYM_NOTINTABLE;
static /*@partial@*/ /*@dependent@*/ yasm_symrec *
symrec_get_or_new(const char *name, int in_table)
{
- char *symname = xstrdup(name);
+ char *symname = yasm__xstrdup(name);
if (in_table)
return symrec_get_or_new_in_table(symname);
non_table_symrec *sym = SLIST_FIRST(non_table_syms);
SLIST_REMOVE_HEAD(non_table_syms, link);
symrec_delete_one(sym->rec);
- xfree(sym);
+ yasm_xfree(sym);
}
- xfree(non_table_syms);
+ yasm_xfree(non_table_syms);
}
typedef struct symrec_print_data {
# endif
#endif
+#ifdef WITH_DMALLOC
+# include <dmalloc.h>
+
+#define yasm__xstrdup(str) xstrdup(str)
+#define yasm_xmalloc(size) xmalloc(size)
+#define yasm_xcalloc(count, size) xcalloc(count, size)
+#define yasm_xrealloc(ptr, size) xrealloc(ptr, size)
+#define yasm_xfree(ptr) xfree(ptr)
+
+#else
/* strdup() implementation with error checking (using xmalloc). */
-/*@only@*/ char *xstrdup(const char *str);
+/*@only@*/ char *yasm__xstrdup(const char *str);
-/* Error-checking memory allocation routines in xmalloc.c. */
-/*@only@*/ /*@out@*/ void *xmalloc(size_t size);
-/*@only@*/ void *xcalloc(size_t nelem, size_t elsize);
-/*@only@*/ void *xrealloc(/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/
- void *oldmem, size_t size) /*@modifies oldmem@*/;
-void xfree(/*@only@*/ /*@out@*/ /*@null@*/ void *p) /*@modifies p@*/;
+/* Error-checking memory allocation routines. Default implementations in
+ * xmalloc.c.
+ */
+extern /*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size);
+extern /*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize);
+extern /*@only@*/ void * (*yasm_xrealloc)
+ (/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size)
+ /*@modifies oldmem@*/;
+extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p)
+ /*@modifies p@*/;
-#ifdef WITH_DMALLOC
-# include <dmalloc.h>
#endif
-/*@only@*/ char *xstrndup(const char *str, size_t len);
+/*@only@*/ char *yasm__xstrndup(const char *str, size_t len);
/* Bit-counting: used primarily by HAMT but also in a few other places. */
#define SK5 0x55555555
while (cur) {
next = STAILQ_NEXT(cur, link);
if (cur->val)
- xfree(cur->val);
+ yasm_xfree(cur->val);
if (cur->param)
yasm_expr_delete(cur->param);
- xfree(cur);
+ yasm_xfree(cur);
cur = next;
}
STAILQ_INIT(headp);
void yasm_vp_new(/*@out@*/ yasm_valparam *r, /*@keep@*/ const char *v,
/*@keep@*/ yasm_expr *p);
-#define yasm_vp_new(r, v, p) do { \
- r = xmalloc(sizeof(yasm_valparam)); \
- r->val = v; \
- r->param = p; \
+#define yasm_vp_new(r, v, p) do { \
+ r = yasm_xmalloc(sizeof(yasm_valparam)); \
+ r->val = v; \
+ r->param = p; \
} while(0)
/* void yasm_vps_initialize(//@out@// yasm_valparamhead *headp); */
#ifndef WITH_DMALLOC
-void *
-xmalloc(size_t size)
+static /*@only@*/ /*@out@*/ void *def_xmalloc(size_t size);
+static /*@only@*/ void *def_xcalloc(size_t nelem, size_t elsize);
+static /*@only@*/ void *def_xrealloc
+ (/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size)
+ /*@modifies oldmem@*/;
+static void def_xfree(/*@only@*/ /*@out@*/ /*@null@*/ void *p)
+ /*@modifies p@*/;
+
+/* storage for global function pointers */
+/*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size) = def_xmalloc;
+/*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize) = def_xcalloc;
+/*@only@*/ void * (*yasm_xrealloc)
+ (/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size)
+ /*@modifies oldmem@*/ = def_xrealloc;
+void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p)
+ /*@modifies p@*/ = def_xfree;
+
+
+static void *
+def_xmalloc(size_t size)
{
void *newmem;
return newmem;
}
-void *
-xcalloc(size_t nelem, size_t elsize)
+static void *
+def_xcalloc(size_t nelem, size_t elsize)
{
void *newmem;
return newmem;
}
-void *
-xrealloc(void *oldmem, size_t size)
+static void *
+def_xrealloc(void *oldmem, size_t size)
{
void *newmem;
return newmem;
}
-void
-xfree(void *p)
+static void
+def_xfree(void *p)
{
if (!p)
return;
#ifndef WITH_DMALLOC
char *
-xstrdup(const char *str)
+yasm__xstrdup(const char *str)
{
size_t len;
char *copy;
len = strlen(str) + 1;
- copy = xmalloc(len);
+ copy = yasm_xmalloc(len);
memcpy(copy, str, len);
return (copy);
}
#endif
char *
-xstrndup(const char *str, size_t len)
+yasm__xstrndup(const char *str, size_t len)
{
char *copy;
- copy = xmalloc(len+1);
+ copy = yasm_xmalloc(len+1);
memcpy(copy, str, len);
copy[len] = '\0';
return (copy);
# endif
#endif
+#ifdef WITH_DMALLOC
+# include <dmalloc.h>
+
+#define yasm__xstrdup(str) xstrdup(str)
+#define yasm_xmalloc(size) xmalloc(size)
+#define yasm_xcalloc(count, size) xcalloc(count, size)
+#define yasm_xrealloc(ptr, size) xrealloc(ptr, size)
+#define yasm_xfree(ptr) xfree(ptr)
+
+#else
/* strdup() implementation with error checking (using xmalloc). */
-/*@only@*/ char *xstrdup(const char *str);
+/*@only@*/ char *yasm__xstrdup(const char *str);
-/* Error-checking memory allocation routines in xmalloc.c. */
-/*@only@*/ /*@out@*/ void *xmalloc(size_t size);
-/*@only@*/ void *xcalloc(size_t nelem, size_t elsize);
-/*@only@*/ void *xrealloc(/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/
- void *oldmem, size_t size) /*@modifies oldmem@*/;
-void xfree(/*@only@*/ /*@out@*/ /*@null@*/ void *p) /*@modifies p@*/;
+/* Error-checking memory allocation routines. Default implementations in
+ * xmalloc.c.
+ */
+extern /*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size);
+extern /*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize);
+extern /*@only@*/ void * (*yasm_xrealloc)
+ (/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size)
+ /*@modifies oldmem@*/;
+extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p)
+ /*@modifies p@*/;
-#ifdef WITH_DMALLOC
-# include <dmalloc.h>
#endif
-/*@only@*/ char *xstrndup(const char *str, size_t len);
+/*@only@*/ char *yasm__xstrndup(const char *str, size_t len);
/* Bit-counting: used primarily by HAMT but also in a few other places. */
#define SK5 0x55555555