From 7a887989fb1da56ebd264ee3338c1472c7e40a51 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 12 Oct 2007 04:54:46 +0000 Subject: [PATCH] malloca-instead-of-local_alloc.patch from patch #6230. * alloc.h (local_alloc): Removed. Changed all users to use xmalloca instead. (local_free): Removed. Changed all users to use freea instead. * Smake: Drop alloca, alloca-opt modules as we don't use them anymore. --- ChangeLog | 5 +++++ Smake | 2 -- src/data/file-name.c | 8 +++++--- src/language/command.c | 6 ++++-- src/language/data-io/list.q | 8 +++++--- src/language/stats/crosstabs.q | 28 ++++++++++++++-------------- src/libpspp/ChangeLog | 6 ++++++ src/libpspp/alloc.h | 12 ------------ 8 files changed, 39 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index e35d2382..e18976e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-10-11 Ben Pfaff + + * Smake: Drop alloca, alloca-opt modules as we don't use them + anymore. + 2007-10-10 Ben Pfaff * acinclude.m4: Improve formatting. diff --git a/Smake b/Smake index 1709a192..edb247e8 100644 --- a/Smake +++ b/Smake @@ -5,8 +5,6 @@ GNULIB = ../gnulib GNULIB_TOOL = $(GNULIB)/gnulib-tool GNULIB_MODULES = \ - alloca \ - alloca-opt \ assert \ byteswap \ c-ctype \ diff --git a/src/data/file-name.c b/src/data/file-name.c index f8ad11d0..82279f77 100644 --- a/src/data/file-name.c +++ b/src/data/file-name.c @@ -28,14 +28,16 @@ #include "intprops.h" #include "minmax.h" #include "dirname.h" +#include "xmalloca.h" -#include #include #include #include #include #include +#include "xalloc.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -279,13 +281,13 @@ fn_open (const char *fn, const char *mode) if (get_safer_mode ()) return safety_violation (fn); - s = local_alloc (strlen (fn)); + s = xmalloca (strlen (fn)); memcpy (s, fn, strlen (fn) - 1); s[strlen (fn) - 1] = 0; f = popen (s, mode[0] == 'r' ? "r" : "w"); - local_free (s); + freea (s); return f; } diff --git a/src/language/command.c b/src/language/command.c index 1688a10e..62538c64 100644 --- a/src/language/command.c +++ b/src/language/command.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -49,6 +48,9 @@ #include #endif +#include "xalloc.h" +#include "xmalloca.h" + #include "gettext.h" #define _(msgid) gettext (msgid) #define N_(msgid) msgid @@ -777,7 +779,7 @@ shell (void) { const char *cp = strrchr (shell_fn, '/'); cp = cp ? &cp[1] : shell_fn; - shell_process = local_alloc (strlen (cp) + 8); + shell_process = xmalloca (strlen (cp) + 8); strcpy (shell_process, "-"); strcat (shell_process, cp); if (strcmp (cp, "sh")) diff --git a/src/language/data-io/list.q b/src/language/data-io/list.q index 135dcc4c..0227c72b 100644 --- a/src/language/data-io/list.q +++ b/src/language/data-io/list.q @@ -21,6 +21,8 @@ #include "intprops.h" #include "size_max.h" +#include "xmalloca.h" + #include #include #include @@ -462,8 +464,8 @@ write_fallback_headers (struct outp_driver *d) int line_number = 0; const char *Line = _("Line"); - char *leader = local_alloc (strlen (Line) - + INT_STRLEN_BOUND (line_number) + 1 + 1); + char *leader = xmalloca (strlen (Line) + + INT_STRLEN_BOUND (line_number) + 1 + 1); while (index < cmd.n_variables) { @@ -517,7 +519,7 @@ write_fallback_headers (struct outp_driver *d) d->cp_x = 0; d->cp_y += d->font_height; - local_free (leader); + freea (leader); } /* There are three possible layouts for the LIST procedure: diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index 86a561e8..5277e545 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -46,13 +46,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -60,6 +58,8 @@ #include #include "minmax.h" +#include "xalloc.h" +#include "xmalloca.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -551,7 +551,7 @@ precalc (struct casereader *input, const struct dataset *ds) sorted_tab = xnrealloc (sorted_tab, n_sorted_tab + count, sizeof *sorted_tab); - v = local_alloc (sizeof *v * x->nvar); + v = xmalloca (sizeof *v * x->nvar); for (j = 2; j < x->nvar; j++) v[j] = get_var_range (x->vars[j])->min; for (j = 0; j < count; j++) @@ -585,7 +585,7 @@ precalc (struct casereader *input, const struct dataset *ds) break; } } - local_free (v); + freea (v); } sorted_tab = xnrealloc (sorted_tab, @@ -615,7 +615,7 @@ calc_general (struct ccase *c, const struct dataset *ds) struct crosstab *x = xtab[t]; const size_t entry_size = (sizeof (struct table_entry) + sizeof (union value) * (x->nvar - 1)); - struct table_entry *te = local_alloc (entry_size); + struct table_entry *te = xmalloca (entry_size); /* Construct table entry for the current record and table. */ te->table = t; @@ -664,7 +664,7 @@ calc_general (struct ccase *c, const struct dataset *ds) } next_crosstab: - local_free (te); + freea (te); } } @@ -924,7 +924,7 @@ insert_summary (struct tab_table *t, int tab_index, double valid) /* Crosstabulation name. */ { - char *buf = local_alloc (128 * x->nvar); + char *buf = xmalloca (128 * x->nvar); char *cp = buf; int i; @@ -937,7 +937,7 @@ insert_summary (struct tab_table *t, int tab_index, double valid) } tab_text (t, 0, 0, TAB_LEFT, buf); - local_free (buf); + freea (buf); } /* Counts and percentages. */ @@ -1064,7 +1064,7 @@ output_pivot_table (struct table_entry **pb, struct table_entry **pe, /* Title. */ { - char *title = local_alloc (x->nvar * 64 + 128); + char *title = xmalloca (x->nvar * 64 + 128); char *cp = title; int i; @@ -1130,7 +1130,7 @@ output_pivot_table (struct table_entry **pb, struct table_entry **pe, strcpy (cp, "]."); tab_title (table, "%s", title); - local_free (title); + freea (title); } tab_offset (table, 0, 2); @@ -2734,8 +2734,8 @@ calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC], /* Spearman correlation, Pearson's r. */ if (cmd.a_statistics[CRS_ST_CORR]) { - double *R = local_alloc (sizeof *R * n_rows); - double *C = local_alloc (sizeof *C * n_cols); + double *R = xmalloca (sizeof *R * n_rows); + double *C = xmalloca (sizeof *C * n_cols); { double y, t, c = 0., s = 0.; @@ -2774,8 +2774,8 @@ calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC], calc_r (R, C, &v[6], &t[6], &ase[6]); t[6] = v[6] / t[6]; - local_free (R); - local_free (C); + freea (R); + freea (C); calc_r ((double *) rows, (double *) cols, &v[7], &t[7], &ase[7]); t[7] = v[7] / t[7]; diff --git a/src/libpspp/ChangeLog b/src/libpspp/ChangeLog index 76e4e7e0..bd5398ee 100644 --- a/src/libpspp/ChangeLog +++ b/src/libpspp/ChangeLog @@ -1,3 +1,9 @@ +2007-10-11 Ben Pfaff + + * alloc.h (local_alloc): Removed. Changed all users to use + xmalloca instead. + (local_free): Removed. Changed all users to use freea instead. + 2007-10-11 Ben Pfaff * float-format.c (float_get_lowest): New function. diff --git a/src/libpspp/alloc.h b/src/libpspp/alloc.h index a83db782..b1a2a655 100644 --- a/src/libpspp/alloc.h +++ b/src/libpspp/alloc.h @@ -24,16 +24,4 @@ void *nmalloc (size_t n, size_t s); -/* alloca() wrapper functions. */ -#if defined HAVE_ALLOCA || defined C_ALLOCA -#ifdef HAVE_ALLOCA_H -#include -#endif -#define local_alloc(X) alloca (X) -#define local_free(P) ((void) 0) -#else -#define local_alloc(X) xmalloc (X) -#define local_free(P) free (P) -#endif - #endif /* alloc.h */ -- 2.30.2