From bfebdb0a071fe4f657e9505331ea8cb210c9d9b9 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 12 Sep 2002 02:23:54 +0000 Subject: [PATCH] "const"-ipation fixes from Trevor Woerner --- assemble.c | 16 ++++++++-------- disasm.c | 2 +- listing.c | 4 ++-- nasm.h | 6 +++--- nasmlib.c | 28 ++++++++++++++++------------ nasmlib.h | 6 +++--- output/outaout.c | 6 +++--- output/outas86.c | 8 ++++---- output/outbin.c | 3 +-- output/outcoff.c | 6 +++--- output/outelf.c | 6 +++--- output/outieee.c | 4 ++-- output/outobj.c | 4 ++-- output/outrdf2.c | 6 +++--- preproc.c | 4 ++-- preproc.h | 2 +- 16 files changed, 57 insertions(+), 54 deletions(-) diff --git a/assemble.c b/assemble.c index 94a2af01..a3e1a9aa 100644 --- a/assemble.c +++ b/assemble.c @@ -89,8 +89,8 @@ static efunc errfunc; static struct ofmt *outfmt; static ListGen *list; -static long calcsize (long, long, int, insn *, char *); -static void gencode (long, long, int, insn *, char *, long); +static long calcsize (long, long, int, insn *, const char *); +static void gencode (long, long, int, insn *, const char *, long); static int regval (operand *o); static int matches (struct itemplate *, insn *); static ea * process_ea (operand *, ea *, int, int, int); @@ -101,7 +101,7 @@ static int chsize (operand *, int); * in order to pass a copy of the data off to the listing file * generator at the same time. */ -static void out (long offset, long segto, void *data, unsigned long type, +static void out (long offset, long segto, const void *data, unsigned long type, long segment, long wrt) { long lineno; @@ -152,7 +152,7 @@ static void out (long offset, long segto, void *data, unsigned long type, } static int jmp_match (long segment, long offset, int bits, - insn *ins, char *code) + insn *ins, const char *code) { long isize; unsigned char c = code[0]; @@ -349,7 +349,7 @@ long assemble (long segment, long offset, int bits, unsigned long cp, if (m == 100) /* matches! */ { - char *codes = temp->code; + const char *codes = temp->code; long insn_size = calcsize(segment, offset, bits, instruction, codes); itimes = instruction->times; @@ -527,7 +527,7 @@ long insn_size (long segment, long offset, int bits, unsigned long cp, if (m == 100) { /* we've matched an instruction. */ long isize; - char * codes = temp->code; + const char * codes = temp->code; int j; isize = calcsize(segment, offset, bits, instruction, codes); @@ -570,7 +570,7 @@ static int is_sbyte (insn *ins, int op, int size) } static long calcsize (long segment, long offset, int bits, - insn *ins, char *codes) + insn *ins, const char *codes) { long length = 0; unsigned char c; @@ -682,7 +682,7 @@ static long calcsize (long segment, long offset, int bits, } static void gencode (long segment, long offset, int bits, - insn *ins, char *codes, long insn_end) + insn *ins, const char *codes, long insn_end) { static char condval[] = { /* conditional opcodes */ 0x7, 0x3, 0x2, 0x6, 0x2, 0x4, 0xF, 0xD, 0xC, 0xE, 0x6, 0x2, diff --git a/disasm.c b/disasm.c index 24a2ab7b..811051e0 100644 --- a/disasm.c +++ b/disasm.c @@ -90,7 +90,7 @@ static int whichreg(long regflags, int regval) return 0; } -static char *whichcond(int condval) +static const char *whichcond(int condval) { static int conds[] = { C_O, C_NO, C_C, C_NC, C_Z, C_NZ, C_NA, C_A, diff --git a/listing.c b/listing.c index 5efc6dbd..d72450dd 100644 --- a/listing.c +++ b/listing.c @@ -120,7 +120,7 @@ static void list_out (long offset, char *str) strcat(listdata, str); } -static void list_output (long offset, void *data, unsigned long type) +static void list_output (long offset, const void *data, unsigned long type) { unsigned long typ, size; @@ -132,7 +132,7 @@ static void list_output (long offset, void *data, unsigned long type) if (typ == OUT_RAWDATA) { - unsigned char *p = data; + unsigned char const *p = data; char q[3]; while (size--) { diff --git a/nasm.h b/nasm.h index c767348e..4db1c292 100644 --- a/nasm.h +++ b/nasm.h @@ -147,7 +147,7 @@ typedef struct { * work with when doing things like uplevel(LIST_TIMES) or * uplevel(LIST_INCBIN). */ - void (*output) (long, void *, unsigned long); + void (*output) (long, const void *, unsigned long); /* * Called to send a text line to the listing generator. The @@ -565,7 +565,7 @@ struct ofmt { * and user-level equivalents for any format-specific * directives). */ - char **stdmac; + const char **stdmac; /* * This procedure is called at the start of an output session. @@ -594,7 +594,7 @@ struct ofmt { * The `type' argument specifies the type of output data, and * usually the size as well: its contents are described below. */ - void (*output) (long segto, void *data, unsigned long type, + void (*output) (long segto, const void *data, unsigned long type, long segment, long wrt); /* diff --git a/nasmlib.c b/nasmlib.c index 910c0eee..a2c7d4fe 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -473,9 +473,9 @@ void *saa_wstruct (struct SAA *s) return p; } -void saa_wbytes (struct SAA *s, void *data, long len) +void saa_wbytes (struct SAA *s, const void *data, long len) { - char *d = data; + const char *d = data; while (len > 0) { long l = s->end->length - s->end->posn; @@ -1008,7 +1008,7 @@ long reloc_wrt (expr *vect) /* * Binary search. */ -int bsi (char *string, char **array, int size) +int bsi (char *string, const char **array, int size) { int i = -1, j = size; /* always, i < index < j */ while (j-i >= 2) { @@ -1092,20 +1092,24 @@ char *nasm_strcat(char *one, char *two) return rslt; } -void null_debug_routine(void) -{ -} +void null_debug_init(struct ofmt *of, void *id, FILE *fp, efunc error ) {} +void null_debug_linenum(const char *filename, long linenumber, long segto) {} +void null_debug_deflabel(char *name, long segment, long offset, int is_global, char *special) {} +void null_debug_routine(const char *directive, const char *params) {} +void null_debug_typevalue(long type) {} +void null_debug_output(int type, void *param) {} +void null_debug_cleanup(void){} struct dfmt null_debug_form = { "Null debug format", "null", + null_debug_init, + null_debug_linenum, + null_debug_deflabel, null_debug_routine, - null_debug_routine, - null_debug_routine, - null_debug_routine, - null_debug_routine, - null_debug_routine, - null_debug_routine, + null_debug_typevalue, + null_debug_output, + null_debug_cleanup }; struct dfmt *null_debug_arr[2] = { &null_debug_form, NULL }; diff --git a/nasmlib.h b/nasmlib.h index 78f7dd0c..54964539 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -197,7 +197,7 @@ struct SAA { struct SAA *saa_init (long elem_len); /* 1 == byte */ void saa_free (struct SAA *); void *saa_wstruct (struct SAA *); /* return a structure of elem_len */ -void saa_wbytes (struct SAA *, void *, long); /* write arbitrary bytes */ +void saa_wbytes (struct SAA *, const void *, long); /* write arbitrary bytes */ void saa_rewind (struct SAA *); /* for reading from beginning */ void *saa_rstruct (struct SAA *); /* return NULL on EOA */ void *saa_rbytes (struct SAA *, long *); /* return 0 on EOA */ @@ -234,7 +234,7 @@ long reloc_wrt(expr *); * matching `string', or <0 if no match. `array' is taken to * contain `size' elements. */ -int bsi (char *string, char **array, int size); +int bsi (char *string, const char **array, int size); char *src_set_fname(char *newname); @@ -252,7 +252,7 @@ void nasm_quote(char **str); char *nasm_strcat(char *one, char *two); void nasmlib_cleanup(void); -void null_debug_routine(void); +void null_debug_routine(const char *directive, const char *params); extern struct dfmt null_debug_form; extern struct dfmt *null_debug_arr[2]; #endif diff --git a/output/outaout.c b/output/outaout.c index 4e61c8a4..24e2b581 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -103,7 +103,7 @@ static int is_pic; static void aout_write(void); static void aout_write_relocs(struct Reloc *); static void aout_write_syms(void); -static void aout_sect_write(struct Section *, unsigned char *, unsigned long); +static void aout_sect_write(struct Section *, const unsigned char *, unsigned long); static void aout_pad_sections(void); static void aout_fixup_relocs(struct Section *); @@ -546,7 +546,7 @@ static long aout_add_gotoff_reloc (struct Section *sect, long segment, return offset - asym->value; } -static void aout_out (long segto, void *data, unsigned long type, +static void aout_out (long segto, const void *data, unsigned long type, long segment, long wrt) { struct Section *s; @@ -854,7 +854,7 @@ static void aout_write_syms (void) } static void aout_sect_write (struct Section *sect, - unsigned char *data, unsigned long len) + const unsigned char *data, unsigned long len) { saa_wbytes (sect->data, data, len); sect->len += len; diff --git a/output/outas86.c b/output/outas86.c index 8c695675..3026ad9e 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -78,7 +78,7 @@ static efunc error; static void as86_write(void); static void as86_write_section (struct Section *, int); static int as86_add_string (char *name); -static void as86_sect_write(struct Section *, unsigned char *, unsigned long); +static void as86_sect_write(struct Section *, const unsigned char *, unsigned long); static void as86_init(FILE *fp, efunc errfunc, ldfunc ldef, evalfunc eval) { @@ -244,7 +244,7 @@ static void as86_add_piece (struct Section *sect, int type, long offset, p->number = raa_read (bsym, segment), p->type = 2; } -static void as86_out (long segto, void *data, unsigned long type, +static void as86_out (long segto, const void *data, unsigned long type, long segment, long wrt) { struct Section *s; @@ -524,7 +524,7 @@ static void as86_write_section (struct Section *sect, int index) } static void as86_sect_write (struct Section *sect, - unsigned char *data, unsigned long len) + const unsigned char *data, unsigned long len) { saa_wbytes (sect->data, data, len); sect->datalen += len; @@ -553,7 +553,7 @@ static void as86_filename (char *inname, char *outname, efunc error) standard_extension (inname, outname, ".o", error); } -static char *as86_stdmac[] = { +static const char *as86_stdmac[] = { "%define __SECT__ [section .text]", "%macro __NASM_CDecl__ 1", "%endmacro", diff --git a/output/outbin.c b/output/outbin.c index 424b4f44..d5b0df77 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -314,7 +314,7 @@ static void bin_cleanup (int debuginfo) } } -static void bin_out (long segto, void *data, unsigned long type, +static void bin_out (long segto, const void *data, unsigned long type, long segment, long wrt) { unsigned char *p, mydata[4]; @@ -381,7 +381,6 @@ static void bin_out (long segto, void *data, unsigned long type, } else if ((type & OUT_TYPMASK) == OUT_RAWDATA) { type &= OUT_SIZMASK; - p = data; if (s) { saa_wbytes (s->contents, data, type); s->length += type; diff --git a/output/outcoff.c b/output/outcoff.c index b20f02e7..856da58e 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -121,7 +121,7 @@ static struct SAA *strs; static unsigned long strslen; static void coff_gen_init(FILE *, efunc); -static void coff_sect_write (struct Section *, unsigned char *, +static void coff_sect_write (struct Section *, const unsigned char *, unsigned long); static void coff_write (void); static void coff_section_header (char *, long, long, long, long, int, long); @@ -420,7 +420,7 @@ static long coff_add_reloc (struct Section *sect, long segment, return 0; } -static void coff_out (long segto, void *data, unsigned long type, +static void coff_out (long segto, const void *data, unsigned long type, long segment, long wrt) { struct Section *s; @@ -529,7 +529,7 @@ static void coff_out (long segto, void *data, unsigned long type, } static void coff_sect_write (struct Section *sect, - unsigned char *data, unsigned long len) + const unsigned char *data, unsigned long len) { saa_wbytes (sect->data, data, len); sect->len += len; diff --git a/output/outelf.c b/output/outelf.c index 152e1d2e..f0065717 100644 --- a/output/outelf.c +++ b/output/outelf.c @@ -133,7 +133,7 @@ static int elf_nsect; static long elf_foffs; static void elf_write(void); -static void elf_sect_write(struct Section *, unsigned char *, unsigned long); +static void elf_sect_write(struct Section *, const unsigned char *, unsigned long); static void elf_section_header (int, int, int, void *, int, long, int, int, int, int); static void elf_write_sections (void); @@ -665,7 +665,7 @@ static long elf_add_gsym_reloc (struct Section *sect, return offset - sym->value; } -static void elf_out (long segto, void *data, unsigned long type, +static void elf_out (long segto, const void *data, unsigned long type, long segment, long wrt) { struct Section *s; @@ -1093,7 +1093,7 @@ static void elf_write_sections (void) } static void elf_sect_write (struct Section *sect, - unsigned char *data, unsigned long len) + const unsigned char *data, unsigned long len) { saa_wbytes (sect->data, data, len); sect->len += len; diff --git a/output/outieee.c b/output/outieee.c index 9784e797..3546ab05 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -367,10 +367,10 @@ static void ieee_deflabel (char *name, long segment, /* * Put data out */ -static void ieee_out (long segto, void *data, unsigned long type, +static void ieee_out (long segto, const void *data, unsigned long type, long segment, long wrt) { unsigned long size, realtype; - unsigned char *ucdata; + const unsigned char *ucdata; long ldata; struct ieeeSection *seg; diff --git a/output/outobj.c b/output/outobj.c index 65a1107f..0f8fa367 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -988,11 +988,11 @@ fprintf(stderr, " obj_deflabel: %s, seg=%ld, off=%ld, is_global=%d, %s\n", static void obj_write_fixup (ObjRecord *orp, int bytes, int segrel, long seg, long wrt, struct Segment *segto); -static void obj_out (long segto, void *data, unsigned long type, +static void obj_out (long segto, const void *data, unsigned long type, long segment, long wrt) { unsigned long size, realtype; - unsigned char *ucdata; + const unsigned char *ucdata; long ldata; struct Segment *seg; ObjRecord *orp; diff --git a/output/outrdf2.c b/output/outrdf2.c index e0988739..18d5e858 100644 --- a/output/outrdf2.c +++ b/output/outrdf2.c @@ -421,7 +421,7 @@ static void rdf2_deflabel(char *name, long segment, long offset, } } -static void membufwrite(int segment, void * data, int bytes) +static void membufwrite(int segment, const void * data, int bytes) { int i; char buf[4], * b; @@ -457,7 +457,7 @@ static int getsegmentlength(int segment) return segments[i].seglength; } -static void rdf2_out (long segto, void *data, unsigned long type, +static void rdf2_out (long segto, const void *data, unsigned long type, long segment, long wrt) { long bytes = type & OUT_SIZMASK; @@ -693,7 +693,7 @@ static void rdf2_filename (char *inname, char *outname, efunc error) { standard_extension(inname,outname,".rdf",error); } -static char *rdf2_stdmac[] = { +static const char *rdf2_stdmac[] = { "%define __SECT__ [section .text]", "%imacro library 1+.nolist", "[library %1]", diff --git a/preproc.c b/preproc.c index df0d946e..0770812e 100644 --- a/preproc.c +++ b/preproc.c @@ -402,7 +402,7 @@ static const char **stdmacpos; * The extra standard macros that come from the object format, if * any. */ -static char **extrastdmac = NULL; +static const char **extrastdmac = NULL; int any_extrastdmac; /* @@ -4438,7 +4438,7 @@ pp_pre_undefine(char *definition) } void -pp_extra_stdmac(char **macros) +pp_extra_stdmac(const char **macros) { extrastdmac = macros; } diff --git a/preproc.h b/preproc.h index e2756cc7..0b7df114 100644 --- a/preproc.h +++ b/preproc.h @@ -13,7 +13,7 @@ void pp_include_path (char *); void pp_pre_include (char *); void pp_pre_define (char *); void pp_pre_undefine (char *); -void pp_extra_stdmac (char **); +void pp_extra_stdmac (const char **); extern Preproc nasmpp;