summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <bonzini@gnu.org>2012-03-16 09:10:57 +0100
committerPaolo Bonzini <bonzini@gnu.org>2012-03-16 10:08:39 +0100
commit2ce25280383ed1ec537e7b9033b20293f139b412 (patch)
tree53844c11e96c7f3c47167be04986bb3120b88e30
parent24b6cccd075d3f485aa4089db21f4df2f2a533b9 (diff)
downloadsed-2ce25280383ed1ec537e7b9033b20293f139b412.tar.gz
rip out old macros
2012-03-16 Paolo Bonzini <bonzini@gnu.org> * basicdefs.h (CAST, VCAST, VOID, MEMCPY, MEMMOVE): Rip out. * sed/compile.c: Adjust. * sed/execute.c: Adjust. * sed/regexp.c: Adjust. * sed/utils.c: Adjust. * sed/utils.h: Adjust.
-rw-r--r--ChangeLog9
-rw-r--r--basicdefs.h43
-rw-r--r--sed/compile.c22
-rw-r--r--sed/execute.c40
-rw-r--r--sed/regexp.c4
-rw-r--r--sed/utils.c22
-rw-r--r--sed/utils.h14
7 files changed, 65 insertions, 89 deletions
diff --git a/ChangeLog b/ChangeLog
index 6079991..e47dcdc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2012-03-16 Paolo Bonzini <bonzini@gnu.org>
+ * basicdefs.h (CAST, VCAST, VOID, MEMCPY, MEMMOVE): Rip out.
+ * sed/compile.c: Adjust.
+ * sed/execute.c: Adjust.
+ * sed/regexp.c: Adjust.
+ * sed/utils.c: Adjust.
+ * sed/utils.h: Adjust.
+
+2012-03-16 Paolo Bonzini <bonzini@gnu.org>
+
* sed/execute.c: Unconditionally compile for MBCS.
* sed/mbcs.c: Unconditionally compile for MBCS.
* sed/sed.h: Unconditionally compile for MBCS.
diff --git a/basicdefs.h b/basicdefs.h
index 71b95fa..1b7af78 100644
--- a/basicdefs.h
+++ b/basicdefs.h
@@ -31,23 +31,6 @@
/* type countT is used to keep track of line numbers, etc. */
typedef unsigned long countT;
-/* Oftentimes casts are used as an ugly hack to silence warnings
- * from the compiler. However, sometimes those warnings really
- * do point to something worth avoiding. I define this
- * dummy marker to make searching for them with a text editor
- * much easier, in case I want to verify that they are all
- * legitimate. It is defined in the way it is so that it is
- * easy to disable all casts so that the compiler (or lint)
- * can tell me potentially interesting things about what would
- * happen to the code without the explicit casts.
- */
-#ifdef LOUD_LINT
-# define CAST(x)
-#else
-# define CAST(x) (x)
-#endif
-
-
/* Can the compiler grok function prototypes? */
#if (defined __STDC__ && __STDC__-0) || defined __GNUC__ || defined __SUNPRO_C || __PROTOTYPES
# define P_(s) s
@@ -55,27 +38,11 @@ typedef unsigned long countT;
# define P_(s) ()
#endif
-/* (VOID *) is the generic pointer type; some ancient compilers
- don't know about (void *), and typically use (char *) instead.
- VCAST() is used to cast to and from (VOID *)s --- but if the
- compiler *does* support (void *) make this a no-op, so that
- the compiler can detect if we omitted an essential function
- declaration somewhere.
- */
-#ifndef VOID
-# define VOID void
-# define VCAST(t)
-#else
-# define VCAST(t) (t)
-#endif
-
-/* some basic definitions to avoid undue promulgating of VCAST ugliness */
-#define MALLOC(n,t) (VCAST(t *)ck_malloc((n)*sizeof(t)))
-#define REALLOC(x,n,t) (VCAST(t *)ck_realloc(VCAST(VOID *)(x),(n)*sizeof(t)))
-#define MEMDUP(x,n,t) (VCAST(t *)ck_memdup(VCAST(VOID *)(x),(n)*sizeof(t)))
-#define FREE(x) (ck_free(VCAST(VOID *)x))
-#define MEMCPY(d,s,l) (memcpy(VCAST(VOID *)(d),VCAST(const VOID *)(s),l))
-#define MEMMOVE(d,s,l) (memmove(VCAST(VOID *)(d),VCAST(const VOID *)(s),l))
+/* some basic definitions to avoid undue promulgating of ugliness */
+#define MALLOC(n,t) ((t *)ck_malloc((n)*sizeof(t)))
+#define REALLOC(x,n,t) ((t *)ck_realloc((void *)(x),(n)*sizeof(t)))
+#define MEMDUP(x,n,t) ((t *)ck_memdup((void *)(x),(n)*sizeof(t)))
+#define FREE(x) (ck_free((void *)x))
#define OB_MALLOC(o,n,t) ((t *)(void *)obstack_alloc(o,(n)*sizeof(t)))
#define obstack_chunk_alloc ck_malloc
diff --git a/sed/compile.c b/sed/compile.c
index cf3b32b..40b67ca 100644
--- a/sed/compile.c
+++ b/sed/compile.c
@@ -190,12 +190,12 @@ bad_prog(why)
{
if (cur_input.name)
fprintf(stderr, _("%s: file %s line %lu: %s\n"),
- myname, cur_input.name, CAST(unsigned long)cur_input.line, why);
+ myname, cur_input.name, (unsigned long)cur_input.line, why);
else
fprintf(stderr, _("%s: -e expression #%lu, char %lu: %s\n"),
myname,
- CAST(unsigned long)cur_input.string_expr_count,
- CAST(unsigned long)(prog.cur-prog.base),
+ (unsigned long)cur_input.string_expr_count,
+ (unsigned long)(prog.cur-prog.base),
why);
exit(EXIT_FAILURE);
}
@@ -239,7 +239,7 @@ savchar(ch)
{
if (prog.cur <= prog.base || *--prog.cur != ch)
panic("Called savchar() with unexpected pushback (%x)",
- CAST(unsigned char)ch);
+ (unsigned char)ch);
}
else
ungetc(ch, prog.file);
@@ -707,7 +707,7 @@ setup_label(list, idx, name, err_info)
ret->v_index = idx;
ret->name = name;
if (err_info)
- MEMCPY(&ret->err_info, err_info, sizeof (ret->err_info));
+ memcpy(&ret->err_info, err_info, sizeof (ret->err_info));
ret->next = list;
return ret;
}
@@ -778,7 +778,7 @@ setup_replacement(sub, text, length)
{
/* Preceding the backslash may be some literal text: */
tail = tail->next =
- new_replacement(base, CAST(size_t)(p - base), repl_type);
+ new_replacement(base, (size_t)(p - base), repl_type);
repl_type = save_type;
@@ -840,7 +840,7 @@ setup_replacement(sub, text, length)
{
/* Preceding the ampersand may be some literal text: */
tail = tail->next =
- new_replacement(base, CAST(size_t)(p - base), repl_type);
+ new_replacement(base, (size_t)(p - base), repl_type);
repl_type = save_type;
tail->subst_id = 0;
@@ -850,7 +850,7 @@ setup_replacement(sub, text, length)
/* There may be some trailing literal text: */
if (base < text_end)
tail = tail->next =
- new_replacement(base, CAST(size_t)(text_end - base), repl_type);
+ new_replacement(base, (size_t)(text_end - base), repl_type);
tail->next = NULL;
sub->replacement = root.next;
@@ -1354,7 +1354,7 @@ compile_program(vector)
{
unsigned char *translate =
OB_MALLOC(&obs, YMAP_LENGTH, unsigned char);
- unsigned char *ustring = CAST(unsigned char *)src_buf;
+ unsigned char *ustring = (unsigned char *)src_buf;
if (len != dest_len)
bad_prog(_(Y_CMD_LEN));
@@ -1563,7 +1563,7 @@ compile_string(cur_program, str, len)
struct vector *ret;
prog.file = NULL;
- prog.base = CAST(unsigned char *)str;
+ prog.base = (unsigned char *)str;
prog.cur = prog.base;
prog.end = prog.cur + len;
@@ -1627,7 +1627,7 @@ check_final_program(program)
if (blocks)
{
/* update info for error reporting: */
- MEMCPY(&cur_input, &blocks->err_info, sizeof (cur_input));
+ memcpy(&cur_input, &blocks->err_info, sizeof (cur_input));
bad_prog(_(EXCESS_OPEN_BRACE));
}
diff --git a/sed/execute.c b/sed/execute.c
index 6e96ee5..6e61c4c 100644
--- a/sed/execute.c
+++ b/sed/execute.c
@@ -145,7 +145,7 @@ resize_line(lb, len)
* remove it. */
if (inactive > lb->alloc * 2)
{
- MEMMOVE(lb->text, lb->active, lb->length);
+ memmove(lb->text, lb->active, lb->length);
lb->alloc += lb->active - lb->text;
lb->active = lb->text;
inactive = 0;
@@ -176,7 +176,7 @@ str_append(to, string, length)
if (to->alloc < new_length)
resize_line(to, new_length);
- MEMCPY(to->active + to->length, string, length);
+ memcpy(to->active + to->length, string, length);
to->length = new_length;
if (mb_cur_max > 1 && !is_utf8)
@@ -221,7 +221,7 @@ str_append_modified(to, string, length, type)
if (to->alloc - to->length < length * mb_cur_max)
resize_line(to, to->length + length * mb_cur_max);
- MEMCPY (&from_stat, &to->mbstate, sizeof(mbstate_t));
+ memcpy (&from_stat, &to->mbstate, sizeof(mbstate_t));
while (length)
{
wchar_t wc;
@@ -346,10 +346,10 @@ line_copy(from, to, state)
to->active = to->text;
to->length = from->length;
to->chomped = from->chomped;
- MEMCPY(to->active, from->active, from->length);
+ memcpy(to->active, from->active, from->length);
if (state)
- MEMCPY(&to->mbstate, &from->mbstate, sizeof (from->mbstate));
+ memcpy(&to->mbstate, &from->mbstate, sizeof (from->mbstate));
}
/* Append the contents of the line `from' to the line `to'.
@@ -366,7 +366,7 @@ line_append(from, to, state)
to->chomped = from->chomped;
if (state)
- MEMCPY (&to->mbstate, &from->mbstate, sizeof (from->mbstate));
+ memcpy (&to->mbstate, &from->mbstate, sizeof (from->mbstate));
}
/* Exchange two "struct line" buffers.
@@ -382,15 +382,15 @@ line_exchange(a, b, state)
if (state)
{
- MEMCPY(&t, a, sizeof (struct line));
- MEMCPY( a, b, sizeof (struct line));
- MEMCPY( b, &t, sizeof (struct line));
+ memcpy(&t, a, sizeof (struct line));
+ memcpy( a, b, sizeof (struct line));
+ memcpy( b, &t, sizeof (struct line));
}
else
{
- MEMCPY(&t, a, SIZEOF_LINE);
- MEMCPY( a, b, SIZEOF_LINE);
- MEMCPY( b, &t, SIZEOF_LINE);
+ memcpy(&t, a, SIZEOF_LINE);
+ memcpy( a, b, SIZEOF_LINE);
+ memcpy( b, &t, SIZEOF_LINE);
}
}
@@ -565,7 +565,7 @@ get_backup_file_name(name)
(asterisk = strchr(old_asterisk, '*'));
old_asterisk = asterisk + 1)
{
- MEMCPY (p, old_asterisk, asterisk - old_asterisk);
+ memcpy (p, old_asterisk, asterisk - old_asterisk);
p += asterisk - old_asterisk;
strcpy (p, name);
p += name_length;
@@ -954,7 +954,7 @@ static void
do_list(line_len)
int line_len;
{
- unsigned char *p = CAST(unsigned char *)line.active;
+ unsigned char *p = (unsigned char *)line.active;
countT len = line.length;
countT width = 0;
char obuf[180]; /* just in case we encounter a 512-bit char (;-) */
@@ -1050,7 +1050,7 @@ append_replacement (buf, p, regs, repl_mod)
else if (regs->end[i] != regs->start[i])
str_append_modified(buf, line.active + regs->start[i],
- CAST(size_t)(regs->end[i] - regs->start[i]),
+ (size_t)(regs->end[i] - regs->start[i]),
curr_type);
}
}
@@ -1255,15 +1255,15 @@ shrink_program(vec, cur_cmd)
for (p=v; p < cur_cmd; ++p)
if (p->cmd != '#')
- MEMCPY(v++, p, sizeof *v);
+ memcpy(v++, p, sizeof *v);
cmd_cnt = v - vec->v;
for (; p < last_cmd; ++p)
if (p->cmd != '#')
- MEMCPY(v++, p, sizeof *v);
+ memcpy(v++, p, sizeof *v);
vec->v_length = v - vec->v;
- return (0 < vec->v_length) ? (vec->v + cmd_cnt) : CAST(struct sed_cmd *)0;
+ return (0 < vec->v_length) ? (vec->v + cmd_cnt) : (struct sed_cmd *)0;
}
#endif /*EXPERIMENTAL_DASH_N_OPTIMIZATION*/
@@ -1623,7 +1623,7 @@ execute_program(vec, input)
else
{
unsigned char *p, *e;
- p = CAST(unsigned char *)line.active;
+ p = (unsigned char *)line.active;
for (e=p+line.length; p<e; ++p)
*p = cur_cmd->x.translate[*p];
}
@@ -1637,7 +1637,7 @@ execute_program(vec, input)
case '=':
output_missing_newline(&output_file);
fprintf(output_file.fp, "%lu\n",
- CAST(unsigned long)input->line_number);
+ (unsigned long)input->line_number);
flush_output(output_file.fp);
break;
diff --git a/sed/regexp.c b/sed/regexp.c
index 74cee00..6477f7f 100644
--- a/sed/regexp.c
+++ b/sed/regexp.c
@@ -233,8 +233,8 @@ match_regex(regex, buf, buflen, buf_start_offset, regarray, regsize)
regex_last = regex;
#ifdef REG_PERL
- regmatch[0].rm_so = CAST(int)buf_start_offset;
- regmatch[0].rm_eo = CAST(int)buflen;
+ regmatch[0].rm_so = (int)buf_start_offset;
+ regmatch[0].rm_eo = (int)buflen;
ret = regexec (&regex->pattern, buf, regsize, regmatch, REG_STARTEND);
if (regsize)
diff --git a/sed/utils.c b/sed/utils.c
index 3db737b..8fc9b35 100644
--- a/sed/utils.c
+++ b/sed/utils.c
@@ -219,7 +219,7 @@ ck_mkstemp (p_filename, tmpdir, base, mode)
/* Panic on failing fwrite */
void
ck_fwrite(ptr, size, nmemb, stream)
- const VOID *ptr;
+ const void *ptr;
size_t size;
size_t nmemb;
FILE *stream;
@@ -234,7 +234,7 @@ ck_fwrite(ptr, size, nmemb, stream)
/* Panic on failing fread */
size_t
ck_fread(ptr, size, nmemb, stream)
- VOID *ptr;
+ void *ptr;
size_t size;
size_t nmemb;
FILE *stream;
@@ -441,23 +441,23 @@ ck_rename (from, to, unlink_if_fail)
/* Panic on failing malloc */
-VOID *
+void *
ck_malloc(size)
size_t size;
{
- VOID *ret = calloc(1, size ? size : 1);
+ void *ret = calloc(1, size ? size : 1);
if (!ret)
panic("couldn't allocate memory");
return ret;
}
/* Panic on failing realloc */
-VOID *
+void *
ck_realloc(ptr, size)
- VOID *ptr;
+ void *ptr;
size_t size;
{
- VOID *ret;
+ void *ret;
if (size == 0)
{
@@ -482,19 +482,19 @@ ck_strdup(str)
}
/* Return a malloc()'d copy of a block of memory */
-VOID *
+void *
ck_memdup(buf, len)
- const VOID *buf;
+ const void *buf;
size_t len;
{
- VOID *ret = ck_malloc(len);
+ void *ret = ck_malloc(len);
return memcpy(ret, buf, len);
}
/* Release a malloc'd block of memory */
void
ck_free(ptr)
- VOID *ptr;
+ void *ptr;
{
if (ptr)
free(ptr);
diff --git a/sed/utils.h b/sed/utils.h
index 9132e3d..34b1d7e 100644
--- a/sed/utils.h
+++ b/sed/utils.h
@@ -24,8 +24,8 @@ void panic P_((const char *str, ...));
FILE *ck_fopen P_((const char *name, const char *mode, int fail));
FILE *ck_fdopen P_((int fd, const char *name, const char *mode, int fail));
-void ck_fwrite P_((const VOID *ptr, size_t size, size_t nmemb, FILE *stream));
-size_t ck_fread P_((VOID *ptr, size_t size, size_t nmemb, FILE *stream));
+void ck_fwrite P_((const void *ptr, size_t size, size_t nmemb, FILE *stream));
+size_t ck_fread P_((void *ptr, size_t size, size_t nmemb, FILE *stream));
void ck_fflush P_((FILE *stream));
void ck_fclose P_((FILE *stream));
const char *follow_symlink P_((const char *path));
@@ -34,12 +34,12 @@ FILE * ck_mkstemp P_((char **p_filename, const char *tmpdir, const char *base,
const char *mode));
void ck_rename P_((const char *from, const char *to, const char *unlink_if_fail));
-VOID *ck_malloc P_((size_t size));
-VOID *xmalloc P_((size_t size));
-VOID *ck_realloc P_((VOID *ptr, size_t size));
+void *ck_malloc P_((size_t size));
+void *xmalloc P_((size_t size));
+void *ck_realloc P_((void *ptr, size_t size));
char *ck_strdup P_((const char *str));
-VOID *ck_memdup P_((const VOID *buf, size_t len));
-void ck_free P_((VOID *ptr));
+void *ck_memdup P_((const void *buf, size_t len));
+void ck_free P_((void *ptr));
struct buffer *init_buffer P_((void));
char *get_buffer P_((struct buffer *b));