[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master de59c02c685 01/11: Simplify etags.c by omitting a macro
From: |
Paul Eggert |
Subject: |
master de59c02c685 01/11: Simplify etags.c by omitting a macro |
Date: |
Tue, 30 Apr 2024 04:26:36 -0400 (EDT) |
branch: master
commit de59c02c685189413c7c5a136224d10152dc8a61
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>
Simplify etags.c by omitting a macro
* lib-src/etags.c (xnew): Remove. All uses removed.
xnew was confusing, as sometimes it was used with n=1,
sometimes with Type=char, and it’s easier just to use xmalloc
or xnmalloc.
---
lib-src/etags.c | 48 +++++++++++++++++++++++-------------------------
1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 032cfa8010b..c316b3c7649 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -243,12 +243,10 @@ endtoken (unsigned char c)
}
/*
- * xnew, xrnew -- allocate, reallocate storage
+ * xrnew -- reallocate storage
*
- * SYNOPSIS: Type *xnew (ptrdiff_t n, Type);
- * void xrnew (OldPointer, ptrdiff_t n, int multiplier);
+ * SYNOPSIS: void xrnew (OldPointer, ptrdiff_t n, int multiplier);
*/
-#define xnew(n, Type) ((Type *) xnmalloc (n, sizeof (Type)))
#define xrnew(op, n, m) ((op) = xnrealloc (op, n, (m) * sizeof *(op)))
typedef void Lang_function (FILE *);
@@ -1125,13 +1123,13 @@ main (int argc, char **argv)
progname = argv[0];
nincluded_files = 0;
- included_files = xnew (argc, char *);
+ included_files = xnmalloc (argc, sizeof *included_files);
current_arg = 0;
file_count = 0;
/* Allocate enough no matter what happens. Overkill, but each one
is small. */
- argbuffer = xnew (argc, argument);
+ argbuffer = xnmalloc (argc, sizeof *argbuffer);
/*
* Always find typedefs and structure tags.
@@ -1778,7 +1776,7 @@ process_file (FILE *fh, char *fn, language *lang)
infilename = fn;
/* Create a new input file description entry. */
- fdp = xnew (1, fdesc);
+ fdp = xmalloc (sizeof *fdp);
*fdp = emptyfdesc;
fdp->next = fdhead;
fdp->infname = savestr (fn);
@@ -2080,7 +2078,7 @@ pfnote (char *name, /* tag name, or NULL if
unnamed */
|| (!CTAGS && name && name[0] == '\0'))
return;
- np = xnew (1, node);
+ np = xmalloc (sizeof *np);
/* If ctags mode, change name "main" to M<thisfilename>. */
if (CTAGS && !cxref_style && streq (name, "main"))
@@ -2135,7 +2133,7 @@ push_node (node *np, stkentry **stack_top)
{
if (np)
{
- stkentry *new = xnew (1, stkentry);
+ stkentry *new = xmalloc (sizeof *new);
new->np = np;
new->next = *stack_top;
@@ -3425,8 +3423,8 @@ C_entries (int c_ext, /* extension of C */
{
cstack.size = (DEBUG) ? 1 : 4;
cstack.nl = 0;
- cstack.cname = xnew (cstack.size, char *);
- cstack.bracelev = xnew (cstack.size, ptrdiff_t);
+ cstack.cname = xnmalloc (cstack.size, sizeof *cstack.cname);
+ cstack.bracelev = xnmalloc (cstack.size, sizeof *cstack.bracelev);
}
tokoff = toklen = typdefbracelev = 0; /* keep compiler quiet */
@@ -5077,7 +5075,7 @@ Ruby_functions (FILE *inf)
if (writer)
{
size_t name_len = cp - np + 1;
- char *wr_name = xnew (name_len + 1, char);
+ char *wr_name = xmalloc (name_len + 1);
strcpy (mempcpy (wr_name, np, name_len - 1), "=");
pfnote (wr_name, true, lb.buffer, cp - lb.buffer + 1,
@@ -5854,7 +5852,7 @@ TEX_decode_env (const char *evarname, const char *defenv)
for (p = env; (p = strchr (p, ':')); )
if (*++p)
len++;
- TEX_toktab = xnew (len, linebuffer);
+ TEX_toktab = xnmalloc (len, sizeof *TEX_toktab);
/* Unpack environment string into token table. Be careful about */
/* zero-length strings (leading ':', "::" and trailing ':') */
@@ -7033,7 +7031,7 @@ add_regex (char *regexp_pattern, language *lang)
break;
}
- patbuf = xnew (1, struct re_pattern_buffer);
+ patbuf = xmalloc (sizeof *patbuf);
*patbuf = zeropattern;
if (ignore_case)
{
@@ -7064,7 +7062,7 @@ add_regex (char *regexp_pattern, language *lang)
}
rp = p_head;
- p_head = xnew (1, regexp);
+ p_head = xmalloc (sizeof *p_head);
p_head->pattern = savestr (regexp_pattern);
p_head->p_next = rp;
p_head->lang = lang;
@@ -7104,7 +7102,7 @@ substitute (char *in, char *out, struct re_registers
*regs)
/* Allocate space and do the substitutions. */
assert (size >= 0);
- result = xnew (size + 1, char);
+ result = xmalloc (size + 1);
for (t = result; *out != '\0'; out++)
if (*out == '\\' && c_isdigit (*++out))
@@ -7452,7 +7450,7 @@ readline (linebuffer *lbp, FILE *stream)
if (fdp == NULL) /* not found */
{
fdp = fdhead;
- fdhead = xnew (1, fdesc);
+ fdhead = xmalloc (sizeof *fdhead);
*fdhead = *curfdp; /* copy curr. file description */
fdhead->next = fdp;
fdhead->infname = savestr (curfdp->infname);
@@ -7552,7 +7550,7 @@ readline (linebuffer *lbp, FILE *stream)
/*
* Return a pointer to a space of size strlen(cp)+1 allocated
- * with xnew where the string CP has been copied.
+ * with xmalloc where the string CP has been copied.
*/
static char *
savestr (const char *cp)
@@ -7561,13 +7559,13 @@ savestr (const char *cp)
}
/*
- * Return a pointer to a space of size LEN+1 allocated with xnew
+ * Return a pointer to a space of size LEN+1 allocated with xmalloc
* with a copy of CP (containing LEN bytes) followed by a NUL byte.
*/
static char *
savenstr (const char *cp, ptrdiff_t len)
{
- char *dp = xnew (len + 1, char);
+ char *dp = xmalloc (len + 1);
dp[len] = '\0';
return memcpy (dp, cp, len);
}
@@ -7650,7 +7648,7 @@ static char *
concat (const char *s1, const char *s2, const char *s3)
{
ptrdiff_t len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
- char *result = xnew (len1 + len2 + len3 + 1, char);
+ char *result = xmalloc (len1 + len2 + len3 + 1);
strcpy (stpcpy (stpcpy (result, s1), s2), s3);
return result;
}
@@ -7662,7 +7660,7 @@ static char *
etags_getcwd (void)
{
ptrdiff_t bufsize = 200;
- char *path = xnew (bufsize, char);
+ char *path = xmalloc (bufsize);
while (getcwd (path, bufsize) == NULL)
{
@@ -7748,7 +7746,7 @@ escape_shell_arg_string (char *str)
p++;
}
- char *new_str = xnew (need_space + 1, char);
+ char *new_str = xmalloc (need_space + 1);
new_str[0] = '\'';
new_str[need_space-1] = '\'';
@@ -7841,7 +7839,7 @@ relative_filename (char *file, char *dir)
i = 0;
while ((dp = strchr (dp + 1, '/')) != NULL)
i += 1;
- res = xnew (3*i + strlen (fp + 1) + 1, char);
+ res = xmalloc (3*i + strlen (fp + 1) + 1);
char *z = res;
while (i-- > 0)
z = stpcpy (z, "../");
@@ -7996,7 +7994,7 @@ static void
linebuffer_init (linebuffer *lbp)
{
lbp->size = (DEBUG) ? 3 : 200;
- lbp->buffer = xnew (lbp->size, char);
+ lbp->buffer = xmalloc (lbp->size);
lbp->buffer[0] = '\0';
lbp->len = 0;
}
- master updated (d24981d27ce -> aad80e1934f), Paul Eggert, 2024/04/30
- master 7e2309c6fc6 02/11: etags: fix #line parsing (\\", long lines), Paul Eggert, 2024/04/30
- master de59c02c685 01/11: Simplify etags.c by omitting a macro,
Paul Eggert <=
- master ca4f0705be5 03/11: etags: work around GCC bug 114882, Paul Eggert, 2024/04/30
- master 62c2afe8410 05/11: Pacify GCC 14 -Wnull-dereference, Paul Eggert, 2024/04/30
- master 98d0fc989a0 04/11: Pacify GCC 14 -Walloc-size, Paul Eggert, 2024/04/30
- master c2b2a38f70f 07/11: Pacify GCC 14 -Wnull-dereference in tim_sort, Paul Eggert, 2024/04/30
- master aad80e1934f 11/11: Work around bad GCC diagnostic in select_window, Paul Eggert, 2024/04/30
- master 750dbccc124 08/11: Pacify GCC 14 -Wnull-dereference in intervals.c, Paul Eggert, 2024/04/30
- master c57a03c75e9 10/11: Pacify GCC 14 -Wanalyzer-out-of-bounds in hbfont.c, Paul Eggert, 2024/04/30
- master 59a11116e01 09/11: Pacify GCC 14 -Wstring-operflow in ftfont.c, Paul Eggert, 2024/04/30
- master 009a6ba71ea 06/11: Pacify GCC 14 -Wclobbered in eval.c, Paul Eggert, 2024/04/30