From 7b98b3a4f58f6dc5a8e9cbc188b627966d5e652d Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 12 Feb 2004 08:19:49 +0000 Subject: [PATCH] Clean up pref.h.orig and deal with the consequences. --- ChangeLog | 11 ++++ pref.h.orig | 125 ++++---------------------------------------- src/ChangeLog | 42 +++++++++++++++ src/aggregate.c | 6 +-- src/algorithm.c | 2 +- src/alloc.h | 12 ++++- src/ascii.c | 26 +++++----- src/autorecode.c | 4 +- src/command.c | 4 +- src/correlations.q | 4 +- src/crosstabs.q | 8 +-- src/data-in.c | 2 +- src/data-list.c | 2 +- src/descript.q | 2 +- src/devind.c | 4 +- src/dictionary.c | 2 +- src/do-if.c | 2 +- src/error.h | 6 +-- src/expr-evl.c | 77 +++++---------------------- src/expr-opt.c | 8 +-- src/expr-prs.c | 22 ++++---- src/exprP.h | 5 +- src/file-handle.q | 4 +- src/filename.c | 26 +++++----- src/frequencies.q | 18 +++---- src/get.c | 4 +- src/getline.c | 4 +- src/glob.c | 4 +- src/glob.h | 2 +- src/groff-font.c | 8 +-- src/hash.c | 2 +- src/html.c | 4 +- src/inpt-pgm.c | 4 +- src/loop.c | 2 +- src/main.c | 2 +- src/matrix-data.c | 2 +- src/modify-vars.c | 2 +- src/pfm-read.c | 2 +- src/pool.c | 127 +++++++++++++++++++++++++++++++-------------- src/pool.h | 1 + src/postscript.c | 54 +++++++++---------- src/print.c | 25 ++------- src/q2c.c | 16 ++---- src/sample.c | 2 +- src/set.q | 34 ++++++------ src/sfm-read.c | 2 +- src/sfmP.h | 2 +- src/sort.c | 8 ++- src/str.h | 2 +- src/t-test.q | 22 ++++---- src/tab.c | 2 +- src/tab.h | 6 +-- src/value-labels.c | 8 +-- src/vars-atr.c | 4 +- 54 files changed, 357 insertions(+), 424 deletions(-) diff --git a/ChangeLog b/ChangeLog index f7daa2e225..6616c85ab7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Wed Feb 11 23:54:15 2004 Ben Pfaff + + * pref.h.orig: Don't meddle with __WIN32__, __MSDOS, __DJGPP__, + __CYGWIN32__, __unix__, or unix anymore, and deal with some of the + consequences. Declare ATTRIBUTE instead of meddling withe + __attribute__. Declare UNUSED instead of unused. Add macros + NO_RETURN, PRINTF_FORMAT, SCANF_FORMAT. Reformat gettext, N_, _ + macros. Move alloca()-related stuff to src/alloc.h and simplify. + Get rid of PAGED_STACK entirely. Remove mkdir macro definition. + Get rid of obsolete "procedure-specific options". + 2004-01-23 gettextize * Makefile.am (SUBDIRS): Remove intl. diff --git a/pref.h.orig b/pref.h.orig index bb4022836a..434d9aacbf 100644 --- a/pref.h.orig +++ b/pref.h.orig @@ -25,37 +25,6 @@ /* Compilers. */ -/* Fix Windows lossage. */ -#ifdef __WIN32__ -#undef __WIN32__ -#define __WIN32__ 1 -#undef __MSDOS__ -#define __MSDOS__ 1 -#endif - -/* Fix DJGPP lossage. */ -#if __DJGPP__ -#undef unix -#undef __unix__ -#endif - -/* Fix Cygnus Windows lossage. */ -#if defined (__CYGWIN32__) -#define unix 1 -#endif - -/* Ensure that unix and __unix__ are equivalent. */ -#if defined (unix) || defined (__unix__) || defined (__unix) -#undef unix -#define unix 1 - -#undef __unix__ -#define __unix__ 1 - -#undef __unix -#define __unix 1 -#endif - /* Make sure to use the proper keywords. */ #if __GNUC__ > 1 && !defined (inline) #define inline __inline__ @@ -65,18 +34,15 @@ printf-like arguments, never return, etc. Conditionalize these declarations on whether gcc is in use. */ #if __GNUC__ > 1 -#define __attribute__(X) __attribute__ (X) +#define ATTRIBUTE(X) __attribute__ (X) #else -#define __attribute__(X) +#define ATTRIBUTE(X) #endif -/* GNU C allows unused variables and parameters to be declared as - such. */ -#if __GNUC__ >= 2 -#define unused __attribute__ ((__unused__)) -#else -#define unused -#endif +#define UNUSED ATTRIBUTE ((unused)) +#define NO_RETURN ATTRIBUTE ((noreturn)) +#define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (printf, FMT, FIRST))) +#define SCANF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (scanf, FMT, FIRST))) /* CPUs. */ @@ -123,77 +89,27 @@ which causes gcc not to do its checking on printf() format types. */ #undef gettext -#define gettext(STRING) \ - STRING +#define gettext(STRING) STRING #endif -#define _(STRING) \ - gettext(STRING) - -#define N_(STRING) \ - STRING - -/* Even C emulation of alloca counts as an alloca implementation. */ -#if C_ALLOCA -#define HAVE_ALLOCA 1 -#endif - -/* Define PAGED_STACK if alloca() is supported and the stack can - expand arbitrarily. (Under some broken OSes like DOS and - Windows the stack is small and fixed in size.) This will prevent - big alloca() requests (like 1MB). */ -#if HAVE_ALLOCA && unix -#define PAGED_STACK 1 -#endif - -/* Saves on #if's. */ -#if HAVE_ALLOCA && !__CHECKER__ -#define local_alloc(X) \ - alloca(X) - -#define local_free(P) \ - do \ - { \ - } \ - while (0) -#elif !__CHECKER__ -#define local_alloc(X) \ - xmalloc (X) - -#define local_free(P) \ - free (P) -#else /* __CHECKER__ */ -/* Why define these this way? Because if you do it this way then if - you try to free a block returned by local_alloc() with the free() - function, you get an error message. */ -#define local_alloc(X) \ - ((void *) (((char *) (xmalloc (X+16))) + 16)) - -#define local_free(P) \ - free (((char *) P) - 16) -#endif /* __CHECKER__ */ +#define _(STRING) gettext(STRING) +#define N_(STRING) STRING /* Filesystems. */ /* Directory separator character for this OS, if applicable. */ -#if !__MSDOS__ +#ifndef __MSDOS__ #define DIR_SEPARATOR '/' #elif #define DIR_SEPARATOR '\\' #endif /* Path delimiter character. */ -#if !__MSDOS__ +#ifndef __MSDOS__ #define PATH_DELIMITER ':' #else #define PATH_DELIMITER ';' #endif - -/* MSDOS mkdir() takes only one argument. */ -#if __MSDOS__ && !__DJGPP__ -#define mkdir(path, mode) \ - mkdir (path) -#endif /* Options. */ @@ -217,22 +133,3 @@ /* Define to exclude the PostScript and Encapsulated PostScript driver. */ /* #define NO_POSTSCRIPT 1 */ - -/* Procedure-specific options. */ - -/* CROSSTABS: Maximum number of tables to process in one pass. */ -#define MAX_CROSSTAB_TABLES 32 - -/* FREQUENCIES: Define to allow bars greater than 1/2" wide. */ -/* #define ALLOW_HUGE_BARS 1 */ - -/* FREQUENCIES: Minimum, maximum number of bars in a histogram. The - number is based on the number of unique values of the variable, - unless overridden. */ -#define MIN_HIST_BARS 3 -#define MAX_HIST_BARS 20 - -/* FREQUENCIES: Density of polyline used to approximate the normal - curve. The value is the number of samples taken per chart. Higher - values give smoother curves. */ -#define POLYLINE_DENSITY (MAX_HIST_BARS*4) diff --git a/src/ChangeLog b/src/ChangeLog index 477d1dd5cb..4f6deaecc6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,45 @@ +Wed Feb 11 23:56:51 2004 Ben Pfaff + + Miscellaneous cleanups. + + * Change unused to UNUSED in many source files to reflect modified + pref.h. Change use of __WIN32__, __MSDOS, __DJGPP__, + __CYGWIN32__, __unix__, and unix not to assume that they're + defined to a nonzero value. Change use of __attribute__ to use + NO_RETURN or PRINTF_FORMAT instead. + + * alloc.h: Move definitions for local_alloc(), local_free() here + from ../pref.h.orig and simplify. + + * expr-evl.c: Instead of working differently based on PAGED_STACK, + use a pool allocator unconditionally. + (CHECK_STRING_SPACE) Removed. + (ALLOC_STRING_SPACE) Removed. + (expr_evaluate) Use e->pool instead of CHECK_STRING_SPACE and + ALLOC_STRING_SPACE. + + * expr-opt.c: (dump_expression) Allocate string pool. + + * expr-prs.c: (expr_free) Free string pool. + + * pool.c: (pool_destroy) This pool must be removed from its + parent's list of gizmos, not from its own. Use free_all_gizmos(). + (pool_clear) New function. + (free_all_gizmos) New function. + (pool_alloc) Use space in empty block after this one if any. + (pool_release) Only empty out blocks, don't actually free() them. + + * print.c: Get rid of PAGED_STACK special case by always + dynamically allocating line buffers. + (struct print_trns) Always include the `line' member. + (internal_cmd_print) Always initialize the `line' member. + (alloc_line) Always allocate memory for `line'. + (print_trns_proc) Always initialize buf from `line' member. + (print_trns_free) Always free `line' memory. + + * sort.c: (allocate_file_handles) Special-case MS-DOS for mkdir() + call. + Wed Feb 11 20:33:18 2004 Ben Pfaff * flip.c: Fixed crash from FLIP when a numeric variable is diff --git a/src/aggregate.c b/src/aggregate.c index 34ac3e843a..1c885b1be5 100644 --- a/src/aggregate.c +++ b/src/aggregate.c @@ -1195,7 +1195,7 @@ initialize_aggregate_info (void) /* Aggregate each case as it comes through. Cases which aren't needed are dropped. */ static int -agr_00x_trns_proc (struct trns_header *h unused, struct ccase *c) +agr_00x_trns_proc (struct trns_header *h UNUSED, struct ccase *c) { int code = aggregate_single_case (c, compaction_case); debug_printf (("%d ", code)); @@ -1252,7 +1252,7 @@ write_case_to_sfm (void) /* Aggregate the current case and output it if we passed a breakpoint. */ static int -agr_10x_trns_proc (struct trns_header *h unused, struct ccase *c) +agr_10x_trns_proc (struct trns_header *h UNUSED, struct ccase *c) { int code = aggregate_single_case (c, buf_1xx); @@ -1264,7 +1264,7 @@ agr_10x_trns_proc (struct trns_header *h unused, struct ccase *c) /* Close the system file now that we're done with it. */ static void -agr_10x_trns_free (struct trns_header *h unused) +agr_10x_trns_free (struct trns_header *h UNUSED) { fh_close_handle (outfile); } diff --git a/src/algorithm.c b/src/algorithm.c index 8a569749e6..0982aeb77a 100644 --- a/src/algorithm.c +++ b/src/algorithm.c @@ -223,7 +223,7 @@ partition (void *array, size_t count, size_t size, /* A algo_random_func that uses random.h. */ unsigned -algo_default_random (unsigned max, void *aux unused) +algo_default_random (unsigned max, void *aux UNUSED) { return rng_get_unsigned (pspp_rng ()) % max; } diff --git a/src/alloc.h b/src/alloc.h index 50e7ab1f10..b1b34d0fec 100644 --- a/src/alloc.h +++ b/src/alloc.h @@ -22,10 +22,20 @@ #include -/* Functions. */ +/* malloc() wrapper functions. */ void *xmalloc (size_t size); void *xcalloc (size_t size); void *xrealloc (void *ptr, size_t size); char *xstrdup (const char *s); + +/* alloca() wrapper functions. */ +#if defined (HAVE_ALLOCA) || defined (C_ALLOCA) +#include +#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 */ diff --git a/src/ascii.c b/src/ascii.c index 60bd1837ce..b9222b83a2 100644 --- a/src/ascii.c +++ b/src/ascii.c @@ -185,21 +185,21 @@ static int postopen (struct file_ext *); static int preclose (struct file_ext *); static int -ascii_open_global (struct outp_class *this unused) +ascii_open_global (struct outp_class *this UNUSED) { ascii_pool = pool_create (); return 1; } static int -ascii_close_global (struct outp_class *this unused) +ascii_close_global (struct outp_class *this UNUSED) { pool_destroy (ascii_pool); return 1; } static int * -ascii_font_sizes (struct outp_class *this unused, int *n_valid_sizes) +ascii_font_sizes (struct outp_class *this UNUSED, int *n_valid_sizes) { static int valid_sizes[] = {12, 12, 0, 0}; @@ -735,7 +735,7 @@ expand_line (struct ascii_driver_ext *x, int i, int l) static void ascii_line_horz (struct outp_driver *this, const struct rect *r, - const struct color *c unused, int style) + const struct color *c UNUSED, int style) { struct ascii_driver_ext *ext = this->ext; int x1 = r->x1 / this->horiz; @@ -769,7 +769,7 @@ ascii_line_horz (struct outp_driver *this, const struct rect *r, static void ascii_line_vert (struct outp_driver *this, const struct rect *r, - const struct color *c unused, int style) + const struct color *c UNUSED, int style) { struct ascii_driver_ext *ext = this->ext; int x1 = r->x1 / this->horiz; @@ -804,7 +804,7 @@ ascii_line_vert (struct outp_driver *this, const struct rect *r, static void ascii_line_intersection (struct outp_driver *this, const struct rect *r, - const struct color *c unused, + const struct color *c UNUSED, const struct outp_styles *style) { struct ascii_driver_ext *ext = this->ext; @@ -835,25 +835,25 @@ ascii_line_intersection (struct outp_driver *this, const struct rect *r, /* FIXME: Later we could set this up so that for certain devices it performs shading? */ static void -ascii_box (struct outp_driver *this unused, const struct rect *r unused, - const struct color *bord unused, const struct color *fill unused) +ascii_box (struct outp_driver *this UNUSED, const struct rect *r UNUSED, + const struct color *bord UNUSED, const struct color *fill UNUSED) { assert (this->driver_open && this->page_open); } /* Polylines not supported. */ static void -ascii_polyline_begin (struct outp_driver *this unused, const struct color *c unused) +ascii_polyline_begin (struct outp_driver *this UNUSED, const struct color *c UNUSED) { assert (this->driver_open && this->page_open); } static void -ascii_polyline_point (struct outp_driver *this unused, int x unused, int y unused) +ascii_polyline_point (struct outp_driver *this UNUSED, int x UNUSED, int y UNUSED) { assert (this->driver_open && this->page_open); } static void -ascii_polyline_end (struct outp_driver *this unused) +ascii_polyline_end (struct outp_driver *this UNUSED) { assert (this->driver_open && this->page_open); } @@ -888,7 +888,7 @@ ascii_text_set_font_by_position (struct outp_driver *this, int pos) } static void -ascii_text_set_font_by_family (struct outp_driver *this unused, const char *s unused) +ascii_text_set_font_by_family (struct outp_driver *this UNUSED, const char *s UNUSED) { assert (this->driver_open && this->page_open); } @@ -916,7 +916,7 @@ ascii_text_get_font_name (struct outp_driver *this) } static const char * -ascii_text_get_font_family (struct outp_driver *this unused) +ascii_text_get_font_family (struct outp_driver *this UNUSED) { assert (this->driver_open && this->page_open); return ""; diff --git a/src/autorecode.c b/src/autorecode.c index 488361dd17..c487255ffe 100644 --- a/src/autorecode.c +++ b/src/autorecode.c @@ -292,7 +292,7 @@ hash_alpha_value (const void *a_, void *v_) } static int -compare_numeric_value (const void *a_, const void *b_, void *foo unused) +compare_numeric_value (const void *a_, const void *b_, void *foo UNUSED) { const union value *a = a_; const union value *b = b_; @@ -301,7 +301,7 @@ compare_numeric_value (const void *a_, const void *b_, void *foo unused) } static unsigned -hash_numeric_value (const void *a_, void *foo unused) +hash_numeric_value (const void *a_, void *foo UNUSED) { const union value *a = a_; diff --git a/src/command.c b/src/command.c index f86ef55c2b..f4c76c33b3 100644 --- a/src/command.c +++ b/src/command.c @@ -601,7 +601,7 @@ cmd_erase (void) return CMD_SUCCESS; } -#if unix +#ifdef unix /* Spawn a shell process. */ static int shell (void) @@ -713,7 +713,7 @@ cmd_host (void) lex_match_id ("HOST"); -#if unix +#ifdef unix /* Figure out whether to invoke an interactive shell or to execute a single shell command. */ if (lex_look_ahead () == '.') diff --git a/src/correlations.q b/src/correlations.q index c7aed0ddc4..5b4fc2b38b 100644 --- a/src/correlations.q +++ b/src/correlations.q @@ -83,7 +83,7 @@ internal_cmd_correlations (void) } static int -cor_custom_variables (struct cmd_correlations *cmd unused) +cor_custom_variables (struct cmd_correlations *cmd UNUSED) { struct variable **v1, **v2; int nv1, nv2; @@ -130,7 +130,7 @@ cor_custom_variables (struct cmd_correlations *cmd unused) } static int -cor_custom_matrix (struct cmd_correlations *cmd unused) +cor_custom_matrix (struct cmd_correlations *cmd UNUSED) { if (!lex_force_match ('(')) return 0; diff --git a/src/crosstabs.q b/src/crosstabs.q index bf9adc3de0..7502259a4a 100644 --- a/src/crosstabs.q +++ b/src/crosstabs.q @@ -284,7 +284,7 @@ internal_cmd_crosstabs (void) /* Parses the TABLES subcommand. */ static int -crs_custom_tables (struct cmd_crosstabs *cmd unused) +crs_custom_tables (struct cmd_crosstabs *cmd UNUSED) { struct var_set *var_set; int n_by; @@ -383,7 +383,7 @@ crs_custom_tables (struct cmd_crosstabs *cmd unused) /* Parses the VARIABLES subcommand. */ static int -crs_custom_variables (struct cmd_crosstabs *cmd unused) +crs_custom_variables (struct cmd_crosstabs *cmd UNUSED) { if (nxtab) { @@ -736,7 +736,7 @@ print_table_entries (struct table_entry **tab) /* Compare the table_entry's at A and B and return a strcmp()-type result. */ static int -compare_table_entry (const void *a_, const void *b_, void *foo unused) +compare_table_entry (const void *a_, const void *b_, void *foo UNUSED) { const struct table_entry *a = a_; const struct table_entry *b = b_; @@ -775,7 +775,7 @@ compare_table_entry (const void *a_, const void *b_, void *foo unused) /* Calculate a hash value from table_entry PA. */ static unsigned -hash_table_entry (const void *pa, void *foo unused) +hash_table_entry (const void *pa, void *foo UNUSED) { const struct table_entry *a = pa; unsigned long hash = a->table; diff --git a/src/data-in.c b/src/data-in.c index aac47680ff..586e74f373 100644 --- a/src/data-in.c +++ b/src/data-in.c @@ -42,7 +42,7 @@ /* Specialized error routine. */ static void dls_error (const struct data_in *, const char *format, ...) - __attribute__ ((format (printf, 2, 3))); + PRINTF_FORMAT (2, 3); static void dls_error (const struct data_in *i, const char *format, ...) diff --git a/src/data-list.c b/src/data-list.c index b5d72f4ed3..1a6b9af89f 100644 --- a/src/data-list.c +++ b/src/data-list.c @@ -1199,7 +1199,7 @@ destroy_dls (struct trns_header *pgm) /* Note that since this is exclusively an input program, C is guaranteed to be temp_case. */ static int -read_one_case (struct trns_header *t, struct ccase *c unused) +read_one_case (struct trns_header *t, struct ccase *c UNUSED) { dlsp = (struct data_list_pgm *) t; return do_reading (1); diff --git a/src/descript.q b/src/descript.q index 69134aef52..6ccec2a44a 100644 --- a/src/descript.q +++ b/src/descript.q @@ -312,7 +312,7 @@ cmd_descriptives (void) /* Parses the VARIABLES subcommand. */ static int -dsc_custom_variables (struct cmd_descriptives *cmd unused) +dsc_custom_variables (struct cmd_descriptives *cmd UNUSED) { if (!lex_match_id ("VARIABLES") && (token != T_ID || dict_lookup_var (default_dict, tokid) == NULL) diff --git a/src/devind.c b/src/devind.c index 8432ea8e4d..4a8da54aab 100644 --- a/src/devind.c +++ b/src/devind.c @@ -116,13 +116,13 @@ struct devind_driver_ext }; static int -devind_open_global (struct outp_class *this unused) +devind_open_global (struct outp_class *this UNUSED) { return 1; } static int -devind_close_global (struct outp_class *this unused) +devind_close_global (struct outp_class *this UNUSED) { return 1; } diff --git a/src/dictionary.c b/src/dictionary.c index dba6bb142a..e03c429eab 100644 --- a/src/dictionary.c +++ b/src/dictionary.c @@ -331,7 +331,7 @@ dict_contains_var (const struct dictionary *d, const struct variable *v) } static int -compare_variable_dblptrs (const void *a_, const void *b_, void *aux unused) +compare_variable_dblptrs (const void *a_, const void *b_, void *aux UNUSED) { struct variable *const *a = a_; struct variable *const *b = b_; diff --git a/src/do-if.c b/src/do-if.c index 247684ec29..b0014484f0 100644 --- a/src/do-if.c +++ b/src/do-if.c @@ -276,7 +276,7 @@ parse_do_if (void) /* Executes a goto transformation. */ static int -goto_trns_proc (struct trns_header * t, struct ccase * c unused) +goto_trns_proc (struct trns_header * t, struct ccase * c UNUSED) { return ((struct goto_trns *) t)->dest; } diff --git a/src/error.h b/src/error.h index 6eb77a14b1..60bcbe85df 100644 --- a/src/error.h +++ b/src/error.h @@ -70,9 +70,9 @@ extern int err_verbosity; /* Functions. */ void msg (int class, const char *format, ...) - __attribute__ ((format (printf, 2, 3))); + PRINTF_FORMAT (2, 3); void tmsg (int class, const char *title, const char *format, ...) - __attribute__ ((format (printf, 3, 4))); + PRINTF_FORMAT (3, 4); void err_failure (void); void err_cond_fail (void); @@ -84,7 +84,7 @@ void err_location (struct file_locator *); /* Obscure functions. */ void err_break (void); void err_check_count (void); -void err_hcf (int exit_code) __attribute__ ((noreturn)); +void err_hcf (int exit_code) NO_RETURN; void err_vmsg (const struct error *); #endif /* error.h */ diff --git a/src/expr-evl.c b/src/expr-evl.c index 100571c644..0699e86b0b 100644 --- a/src/expr-evl.c +++ b/src/expr-evl.c @@ -42,6 +42,7 @@ #include "error.h" #include "julcal/julcal.h" #include "magic.h" +#include "pool.h" #include "random.h" #include "stats.h" #include "str.h" @@ -57,54 +58,20 @@ efficient if I hand-coded it in assembly for a dozen processors, but I'm not going to do that either. */ -/* These macros are defined differently depending on the way that - the stack is managed. (i.e., I have to adapt the code to inferior - environments.) - - void CHECK_STRING_SPACE(int x): Assure that at least X+1 bytes of - space are available in the string evaluation stack. - - unsigned char *ALLOC_STRING_SPACE(int x): Return a pointer to X+1 - bytes of space. CHECK_STRING_SPACE must have previously been - called with an argument of at least X. */ - -#if PAGED_STACK -#define CHECK_STRING_SPACE(X) /* nothing to do! */ -#define ALLOC_STRING_SPACE(X) \ - alloca((X) + 1) -#else /* !PAGED_STACK */ -#define CHECK_STRING_SPACE(X) \ - do \ - { \ - if (str_stk + X >= str_end) \ - { \ - e->str_size += 1024; \ - e->str_stk = xrealloc (e->str_stk, e->str_size); \ - str_end = e->str_stk + e->str_size - 1; \ - } \ - } \ - while (0) - -#define ALLOC_STRING_SPACE(X) \ - (str_stk += X + 1, str_stk - X - 1) -#endif /* !PAGED_STACK */ - double expr_evaluate (struct expression *e, struct ccase *c, union value *v) { unsigned char *op = e->op; double *dbl = e->num; unsigned char *str = e->str; -#if !PAGED_STACK - unsigned char *str_stk = e->str_stk; - unsigned char *str_end = e->str_stk + e->str_size - 1; -#endif struct variable **vars = e->var; int i, j; /* Stack pointer. */ union value *sp = e->stack; + pool_clear (e->pool); + for (;;) { switch (*op++) @@ -813,8 +780,7 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v) int n_args = *op++; unsigned char *dest; - CHECK_STRING_SPACE (255); - dest = ALLOC_STRING_SPACE (255); + dest = pool_alloc (e->pool, 256); dest[0] = 0; sp -= n_args - 1; @@ -936,8 +902,7 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v) { unsigned char *dest; - CHECK_STRING_SPACE (len); - dest = ALLOC_STRING_SPACE (len); + dest = pool_alloc (e->pool, len + 1); dest[0] = len; memset (&dest[1], ' ', len - sp->c[0]); memcpy (&dest[len - sp->c[0] + 1], &sp->c[1], sp->c[0]); @@ -956,8 +921,7 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v) { unsigned char *dest; - CHECK_STRING_SPACE (len); - dest = ALLOC_STRING_SPACE (len); + dest = pool_alloc (e->pool, len + 1); dest[0] = len; memset (&dest[1], sp[2].c[1], len - sp->c[0]); memcpy (&dest[len - sp->c[0] + 1], &sp->c[1], sp->c[0]); @@ -976,8 +940,7 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v) { unsigned char *dest; - CHECK_STRING_SPACE (len); - dest = ALLOC_STRING_SPACE (len); + dest = pool_alloc (e->pool, len + 1); dest[0] = len; memcpy (&dest[1], &sp->c[1], sp->c[0]); memset (&dest[sp->c[0] + 1], ' ', len - sp->c[0]); @@ -996,8 +959,7 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v) { unsigned char *dest; - CHECK_STRING_SPACE (len); - dest = ALLOC_STRING_SPACE (len); + dest = pool_alloc (e->pool, len + 1); dest[0] = len; memcpy (&dest[1], &sp->c[1], sp->c[0]); memset (&dest[sp->c[0] + 1], sp[2].c[1], len - sp->c[0]); @@ -1096,8 +1058,7 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v) f.w = *op++; f.d = *op++; - CHECK_STRING_SPACE (f.w); - dest = ALLOC_STRING_SPACE (f.w); + dest = pool_alloc (e->pool, f.w + 1); dest[0] = f.w; data_out (&dest[1], &f, sp); @@ -1235,15 +1196,13 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v) msg (SE, _("%g is not a valid index value for vector %s. " "The result will be set to the empty string."), sp[0].f, vect->name); - CHECK_STRING_SPACE (0); - sp->c = ALLOC_STRING_SPACE (0); + sp->c = pool_alloc (e->pool, 1); sp->c[0] = 0; break; } v = vect->var[rindx - 1]; - CHECK_STRING_SPACE (v->width); - sp->c = ALLOC_STRING_SPACE (v->width); + sp->c = pool_alloc (e->pool, v->width + 1); sp->c[0] = v->width; memcpy (&sp->c[1], c->data[v->fv].s, v->width); } @@ -1256,8 +1215,7 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v) break; case OP_STR_CON: sp++; - CHECK_STRING_SPACE (*str); - sp->c = ALLOC_STRING_SPACE (*str); + sp->c = pool_alloc (e->pool, *str + 1); memcpy (sp->c, str, *str + 1); str += *str + 1; break; @@ -1273,8 +1231,7 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v) int width = (*vars)->width; sp++; - CHECK_STRING_SPACE (width); - sp->c = ALLOC_STRING_SPACE (width); + sp->c = pool_alloc (e->pool, width + 1); sp->c[0] = width; memcpy (&sp->c[1], &c->data[(*vars)->fv], width); vars++; @@ -1302,8 +1259,7 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v) int width = (*vars)->width; sp++; - CHECK_STRING_SPACE (width); - sp->c = ALLOC_STRING_SPACE (width); + sp->c = pool_alloc (e->pool, width + 1); sp->c[0] = width; if (c == NULL) @@ -1361,12 +1317,7 @@ finished: { assert (v); -#if PAGED_STACK - memcpy (e->str_stack, sp->c, sp->c[0] + 1); - v->c = e->str_stack; -#else v->c = sp->c; -#endif return 0.0; } diff --git a/src/expr-opt.c b/src/expr-opt.c index 9d1537733f..e021858e96 100644 --- a/src/expr-opt.c +++ b/src/expr-opt.c @@ -31,6 +31,7 @@ #include "error.h" #include "julcal/julcal.h" #include "misc.h" +#include "pool.h" #include "stats.h" #include "str.h" #include "var.h" @@ -1027,12 +1028,7 @@ dump_expression (union any_node * n, struct expression * expr) e->stack = xmalloc (max_height * sizeof *e->stack); -#if PAGED_STACK - e->str_stack = e->type == EX_STRING ? xmalloc (256) : NULL; -#else - e->str_stack = xmalloc (256); - e->str_size = 256; -#endif + e->pool = pool_create (); } static void diff --git a/src/expr-prs.c b/src/expr-prs.c index 046e360f1d..d8e2085365 100644 --- a/src/expr-prs.c +++ b/src/expr-prs.c @@ -81,7 +81,7 @@ expr_free (struct expression *e) free (e->num); free (e->str); free (e->stack); - free (e->str_stack); + pool_destroy (e->pool); free (e); } @@ -690,7 +690,7 @@ static int func_count; static int get_num_args (struct function *, int, union any_node **); static int -unary_func (struct function * f, int x unused, union any_node ** n) +unary_func (struct function * f, int x UNUSED, union any_node ** n) { double divisor; struct nonterm_node *c; @@ -738,7 +738,7 @@ multiply: } static int -binary_func (struct function * f, int x unused, union any_node ** n) +binary_func (struct function * f, int x UNUSED, union any_node ** n) { if (!get_num_args (f, 2, n)) return EX_ERROR; @@ -746,7 +746,7 @@ binary_func (struct function * f, int x unused, union any_node ** n) } static int -ternary_func (struct function * f, int x unused, union any_node ** n) +ternary_func (struct function * f, int x UNUSED, union any_node ** n) { if (!get_num_args (f, 3, n)) return EX_ERROR; @@ -754,7 +754,7 @@ ternary_func (struct function * f, int x unused, union any_node ** n) } static int -MISSING_func (struct function * f, int x unused, union any_node ** n) +MISSING_func (struct function * f, int x UNUSED, union any_node ** n) { if (token == T_ID && dict_lookup_var (default_dict, tokid) != NULL @@ -772,7 +772,7 @@ MISSING_func (struct function * f, int x unused, union any_node ** n) } static int -SYSMIS_func (struct function * f unused, int x unused, union any_node ** n) +SYSMIS_func (struct function * f UNUSED, int x UNUSED, union any_node ** n) { int t; @@ -818,7 +818,7 @@ SYSMIS_func (struct function * f unused, int x unused, union any_node ** n) } static int -VALUE_func (struct function *f unused, int x unused, union any_node **n) +VALUE_func (struct function *f UNUSED, int x UNUSED, union any_node **n) { struct variable *v = parse_variable (); @@ -839,7 +839,7 @@ VALUE_func (struct function *f unused, int x unused, union any_node **n) } static int -LAG_func (struct function *f unused, int x unused, union any_node **n) +LAG_func (struct function *f UNUSED, int x UNUSED, union any_node **n) { struct variable *v = parse_variable (); int nlag = 1; @@ -1040,7 +1040,7 @@ fail: } static int -CONCAT_func (struct function * f unused, int x unused, union any_node ** n) +CONCAT_func (struct function * f UNUSED, int x UNUSED, union any_node ** n) { int m = 0; @@ -1088,7 +1088,7 @@ fail: arg; and `f', format spec (this must be the last arg). If the optional args are included, the type becomes f->t+1. */ static int -generic_str_func (struct function *f, int x unused, union any_node ** n) +generic_str_func (struct function *f, int x UNUSED, union any_node ** n) { int max_args = 0; int type; @@ -1626,7 +1626,7 @@ static struct function func_tab[] = /* An algo_compare_func that compares functions A and B based on their names. */ static int -compare_functions (const void *a_, const void *b_, void *aux unused) +compare_functions (const void *a_, const void *b_, void *aux UNUSED) { const struct function *a = a_; const struct function *b = b_; diff --git a/src/exprP.h b/src/exprP.h index 873f0ce779..596638005f 100644 --- a/src/exprP.h +++ b/src/exprP.h @@ -281,10 +281,7 @@ struct expression double *num; /* Numeric operands. */ unsigned char *str; /* String operands. */ union value *stack; /* Evaluation stack. */ - unsigned char *str_stack; /* String evaluation stack. */ -#if !PAGED_STACK - size_t str_size; /* Size of string eval stack. */ -#endif + struct pool *pool; /* Pool for evaluation temporaries. */ }; struct nonterm_node *optimize_expression (struct nonterm_node *); diff --git a/src/file-handle.q b/src/file-handle.q index c70945ee38..c4878bbb92 100644 --- a/src/file-handle.q +++ b/src/file-handle.q @@ -286,7 +286,7 @@ fh_close_handle (struct file_handle *h) /* Hashes the name of file handle H. */ static unsigned -hash_file_handle (const void *handle_, void *param unused) +hash_file_handle (const void *handle_, void *param UNUSED) { const struct file_handle *handle = handle_; @@ -295,7 +295,7 @@ hash_file_handle (const void *handle_, void *param unused) /* Compares names of file handles A and B. */ static int -cmp_file_handle (const void *a_, const void *b_, void *foo unused) +cmp_file_handle (const void *a_, const void *b_, void *foo UNUSED) { const struct file_handle *a = a_; const struct file_handle *b = b_; diff --git a/src/filename.c b/src/filename.c index 4d90e6d5aa..c9f0b62ecc 100644 --- a/src/filename.c +++ b/src/filename.c @@ -33,7 +33,7 @@ /* PORTME: Everything in this file is system dependent. */ -#if unix +#ifdef unix #include #if HAVE_UNISTD_H #include @@ -41,7 +41,7 @@ #include "stat.h" #endif -#if __WIN32__ +#ifdef __WIN32__ #define NOGDI #define NOUSER #define NONLS @@ -129,7 +129,7 @@ fn_interp_vars (const char *input, const char *(*getenv) (const char *)) } } -#if unix +#ifdef unix /* Expands csh tilde notation from the path INPUT into a malloc()'d returned string. */ char * @@ -201,7 +201,7 @@ fn_tilde_expand (char *input) If PREPEND is non-NULL, then it is prepended to each filename; i.e., it looks like PREPEND/PATH_COMPONENT/NAME. This is not done with absolute directories in the path. */ -#if unix || __MSDOS__ || __WIN32__ +#if defined (unix) || defined (__MSDOS__) || defined (__WIN32__) char * fn_search_path (const char *basename, const char *path, const char *prepend) { @@ -317,7 +317,7 @@ fn_prepend_dir (const char *file, const char *dir) existing file. Returns a malloc()'d copy of the canonical name. This function must always succeed; if it needs to bail out then it should return xstrdup(FN1). */ -#if unix +#ifdef unix char * fn_normalize (const char *filename) { @@ -427,7 +427,7 @@ fn_normalize (const char *filename) } } } -#elif __WIN32__ +#elif defined (__WIN32__) char * fn_normalize (const char *fn1) { @@ -551,13 +551,13 @@ fn_get_cwd (void) int fn_absolute_p (const char *name) { -#if unix +#ifdef unix if (name[0] == '/' || !strncmp (name, "./", 2) || !strncmp (name, "../", 3) || name[0] == '~') return 1; -#elif __MSDOS__ +#elif defined (__MSDOS__) if (name[0] == '\\' || !strncmp (name, ".\\", 2) || !strncmp (name, "..\\", 3) @@ -575,7 +575,7 @@ fn_special_p (const char *filename) { if (!strcmp (filename, "-") || !strcmp (filename, "stdin") || !strcmp (filename, "stdout") || !strcmp (filename, "stderr") -#if unix +#ifdef unix || filename[0] == '|' || (*filename && filename[strlen (filename) - 1] == '|') #endif @@ -589,7 +589,7 @@ fn_special_p (const char *filename) int fn_exists_p (const char *name) { -#if unix +#ifdef unix struct stat temp; return stat (name, &temp) == 0; @@ -602,7 +602,7 @@ fn_exists_p (const char *name) #endif } -#if unix +#ifdef unix /* Stolen from libc.info but heavily modified, this is a wrapper around readlink() that allows for arbitrary filename length. */ char * @@ -692,7 +692,7 @@ fn_open (const char *fn, const char *mode) else if (mode[0] == 'w' && !strcmp (fn, "stderr")) return stderr; -#if unix +#ifdef unix if (fn[0] == '|') { if (set_safer) @@ -738,7 +738,7 @@ fn_close (const char *fn, FILE *f) { if (!strcmp (fn, "-")) return 0; -#if unix +#ifdef unix else if (fn[0] == '|' || (*fn && fn[strlen (fn) - 1] == '|')) { pclose (f); diff --git a/src/frequencies.q b/src/frequencies.q index 3f5224d679..d1a75f72e3 100644 --- a/src/frequencies.q +++ b/src/frequencies.q @@ -585,7 +585,7 @@ cleanup_freq_tab (struct variable *v) /* Parses the VARIABLES subcommand, adding to {n_variables,v_variables}. */ static int -frq_custom_variables (struct cmd_frequencies *cmd unused) +frq_custom_variables (struct cmd_frequencies *cmd UNUSED) { int mode; int min, max; @@ -671,7 +671,7 @@ frq_custom_variables (struct cmd_frequencies *cmd unused) /* Parses the GROUPED subcommand, setting the frq.{n_grouped,grouped} fields of specified variables. */ static int -frq_custom_grouped (struct cmd_frequencies *cmd unused) +frq_custom_grouped (struct cmd_frequencies *cmd UNUSED) { lex_match ('='); if ((token == T_ID && dict_lookup_var (default_dict, tokid) != NULL) @@ -779,7 +779,7 @@ add_percentile (double x) /* Parses the PERCENTILES subcommand, adding user-specified percentiles to the list. */ static int -frq_custom_percentiles (struct cmd_frequencies *cmd unused) +frq_custom_percentiles (struct cmd_frequencies *cmd UNUSED) { lex_match ('='); if (token != T_NUM) @@ -808,7 +808,7 @@ frq_custom_percentiles (struct cmd_frequencies *cmd unused) /* Parses the NTILES subcommand, adding the percentiles that correspond to the specified evenly-distributed ntiles. */ static int -frq_custom_ntiles (struct cmd_frequencies *cmd unused) +frq_custom_ntiles (struct cmd_frequencies *cmd UNUSED) { int i; @@ -825,7 +825,7 @@ frq_custom_ntiles (struct cmd_frequencies *cmd unused) /* Hash of numeric values. */ static unsigned -hash_value_numeric (const void *value_, void *foo unused) +hash_value_numeric (const void *value_, void *foo UNUSED) { const struct freq *value = value_; return hsh_hash_double (value->v.f); @@ -843,7 +843,7 @@ hash_value_alpha (const void *value_, void *v_) /* Ascending numeric compare of values. */ static int -compare_value_numeric_a (const void *a_, const void *b_, void *foo unused) +compare_value_numeric_a (const void *a_, const void *b_, void *foo UNUSED) { const struct freq *a = a_; const struct freq *b = b_; @@ -869,7 +869,7 @@ compare_value_alpha_a (const void *a_, const void *b_, void *v_) /* Descending numeric compare of values. */ static int -compare_value_numeric_d (const void *a, const void *b, void *foo unused) +compare_value_numeric_d (const void *a, const void *b, void *foo UNUSED) { return -compare_value_numeric_a (a, b, foo); } @@ -884,7 +884,7 @@ compare_value_alpha_d (const void *a, const void *b, void *v) /* Ascending numeric compare of frequency; secondary key on ascending numeric value. */ static int -compare_freq_numeric_a (const void *a_, const void *b_, void *foo unused) +compare_freq_numeric_a (const void *a_, const void *b_, void *foo UNUSED) { const struct freq *a = a_; const struct freq *b = b_; @@ -922,7 +922,7 @@ compare_freq_alpha_a (const void *a_, const void *b_, void *v_) /* Descending numeric compare of frequency; secondary key on ascending numeric value. */ static int -compare_freq_numeric_d (const void *a_, const void *b_, void *foo unused) +compare_freq_numeric_d (const void *a_, const void *b_, void *foo UNUSED) { const struct freq *a = a_; const struct freq *b = b_; diff --git a/src/get.c b/src/get.c index ba95ade48a..72c49833de 100644 --- a/src/get.c +++ b/src/get.c @@ -224,7 +224,7 @@ save_write_case_func (struct ccase * c) } static int -save_trns_proc (struct trns_header * t unused, struct ccase * c) +save_trns_proc (struct trns_header * t UNUSED, struct ccase * c) { flt64 *p = trns->case_buf; int i; @@ -1046,7 +1046,7 @@ mtf_compare_BY_values (struct mtf_file *a, struct mtf_file *b) /* Perform one iteration of steps 3...7 above. */ static int -mtf_processing (struct ccase *c unused) +mtf_processing (struct ccase *c UNUSED) { /* List of files with minimum BY values. */ struct mtf_file *min_head, *min_tail; diff --git a/src/getline.c b/src/getline.c index 114e2c33db..89370b1332 100644 --- a/src/getline.c +++ b/src/getline.c @@ -79,7 +79,7 @@ getl_initialize (void) void getl_uninitialize (void) { -#if HAVE_LIBHISTORY && unix +#if HAVE_LIBHISTORY && defined (unix) if (history_file) write_history (history_file); #endif @@ -424,7 +424,7 @@ read_console (void) #if HAVE_LIBHISTORY if (!history_file) { -#if unix +#ifdef unix history_file = tilde_expand (HISTORY_FILE); #endif using_history (); diff --git a/src/glob.c b/src/glob.c index 5832a10b5f..db3bda94ac 100644 --- a/src/glob.c +++ b/src/glob.c @@ -62,7 +62,7 @@ extern void stifle_history (); #if __DJGPP__ #include -#elif __WIN32__ && __BORLANDC__ +#elif defined (__WIN32__) && defined (__BORLANDC__) #undef gettext #include #define gettext(STRING) \ @@ -130,7 +130,7 @@ static char term_buffer[16384]; #endif void -init_glob (int argc unused, char **argv) +init_glob (int argc UNUSED, char **argv) { /* FIXME: Allow i18n of other locale items (besides LC_MESSAGES). */ #if ENABLE_NLS diff --git a/src/glob.h b/src/glob.h index 0b15f34ab7..254b3cdd77 100644 --- a/src/glob.h +++ b/src/glob.h @@ -20,6 +20,6 @@ #if !INCLUDED_GLOB_H #define INCLUDED_GLOB_H 1 -void init_glob (int argc unused, char **argv); +void init_glob (int argc UNUSED, char **argv); #endif /* glob.h */ diff --git a/src/groff-font.c b/src/groff-font.c index b1c7f763aa..e4df2cff7c 100644 --- a/src/groff-font.c +++ b/src/groff-font.c @@ -38,7 +38,7 @@ int font_number_to_index (int); int space_index; static int font_msg (int, const char *,...) - __attribute__ ((format (printf, 2, 3))); + PRINTF_FORMAT (2, 3); static void scan_badchars (char *, int); static void dup_char_metric (struct font_desc * font, int dest, int src); static void add_char_metric (struct font_desc * font, struct char_metrics *metrics, @@ -100,7 +100,7 @@ groff_read_font (const char *fn) /* Current location in file, used for error reporting. */ struct file_locator where; -#if unix +#ifdef unix fn = fn_tilde_expand (fn); #endif @@ -355,7 +355,7 @@ groff_read_font (const char *fn) goto file_lossage; } free (line); -#if unix +#ifdef unix free ((char *) fn); #endif @@ -381,7 +381,7 @@ lose: if (f != NULL) fclose (f); pool_destroy (font_pool); -#if unix +#ifdef unix free ((char *) fn); #endif err_pop_file_locator (&where); diff --git a/src/hash.c b/src/hash.c index 38dd7ee276..9961612ccf 100644 --- a/src/hash.c +++ b/src/hash.c @@ -229,7 +229,7 @@ hsh_rehash (struct hsh_table *h, size_t new_size) /* A "algo_predicate_func" that returns nonzero if DATA points to a non-null void. */ static int -not_null (const void *data_, void *aux unused) +not_null (const void *data_, void *aux UNUSED) { void *const *data = data_; diff --git a/src/html.c b/src/html.c index 53add68cd5..6f56b47e97 100644 --- a/src/html.c +++ b/src/html.c @@ -46,13 +46,13 @@ static int postopen (struct file_ext *); static int preclose (struct file_ext *); static int -html_open_global (struct outp_class *this unused) +html_open_global (struct outp_class *this UNUSED) { return 1; } static int -html_close_global (struct outp_class *this unused) +html_close_global (struct outp_class *this UNUSED) { return 1; } diff --git a/src/inpt-pgm.c b/src/inpt-pgm.c index 6fba390d29..7ef6904bbe 100644 --- a/src/inpt-pgm.c +++ b/src/inpt-pgm.c @@ -276,7 +276,7 @@ cmd_end_case (void) } int -end_case_trns_proc (struct trns_header *t unused, struct ccase * c unused) +end_case_trns_proc (struct trns_header *t UNUSED, struct ccase * c UNUSED) { #if DEBUGGING printf ("END CASE\n"); @@ -419,7 +419,7 @@ cmd_end_file (void) } static int -end_file_trns_proc (struct trns_header * t unused, struct ccase * c unused) +end_file_trns_proc (struct trns_header * t UNUSED, struct ccase * c UNUSED) { #if DEBUGGING printf ("END FILE\n"); diff --git a/src/loop.c b/src/loop.c index c8715bcad1..5d9266b0e4 100644 --- a/src/loop.c +++ b/src/loop.c @@ -538,7 +538,7 @@ cmd_break (void) } static int -break_trns_proc (struct trns_header * trns, struct ccase * c unused) +break_trns_proc (struct trns_header * trns, struct ccase * c UNUSED) { return ((struct break_trns *) trns)->loop_term; } diff --git a/src/main.c b/src/main.c index e0cd4f3e4f..04e886787b 100644 --- a/src/main.c +++ b/src/main.c @@ -33,7 +33,7 @@ #include "debug-print.h" -static void parse_script (void) __attribute__ ((noreturn)); +static void parse_script (void) NO_RETURN; static void handle_error (int code); static int execute_command (void); diff --git a/src/matrix-data.c b/src/matrix-data.c index 892e716f20..4af8908349 100644 --- a/src/matrix-data.c +++ b/src/matrix-data.c @@ -1628,7 +1628,7 @@ wr_read_splits (void) /* Compares doubles A and B, treating SYSMIS as greatest. */ static int -compare_doubles (const void *a_, const void *b_, void *aux unused) +compare_doubles (const void *a_, const void *b_, void *aux UNUSED) { const double *a = a_; const double *b = b_; diff --git a/src/modify-vars.c b/src/modify-vars.c index ed28ee4c67..bce6ea1bb3 100644 --- a/src/modify-vars.c +++ b/src/modify-vars.c @@ -360,7 +360,7 @@ struct var_renaming var_renaming structures A and B. */ static int compare_var_renaming_by_new_name (const void *a_, const void *b_, - void *foo unused) + void *foo UNUSED) { const struct var_renaming *a = a_; const struct var_renaming *b = b_; diff --git a/src/pfm-read.c b/src/pfm-read.c index 0a13086281..b587fbcafa 100644 --- a/src/pfm-read.c +++ b/src/pfm-read.c @@ -62,7 +62,7 @@ static struct fh_ext_class pfm_r_class; static int corrupt_msg (struct file_handle *h, const char *format,...) - __attribute__ ((format (printf, 2, 3))); + PRINTF_FORMAT (2, 3); /* Displays a corruption error. */ static int diff --git a/src/pool.c b/src/pool.c index c30b2f7bc3..336671e2bc 100644 --- a/src/pool.c +++ b/src/pool.c @@ -140,6 +140,7 @@ static long serial = 0; /* Prototypes. */ static void add_gizmo (struct pool *, struct pool_gizmo *); static void free_gizmo (struct pool_gizmo *); +static void free_all_gizmos (struct pool *pool); static void delete_gizmo (struct pool *, struct pool_gizmo *); #if !PSPP @@ -180,20 +181,14 @@ pool_destroy (struct pool *pool) if (pool == NULL) return; + /* Remove this pool from its parent's list of gizmos. */ if (pool->parent) - delete_gizmo (pool, + delete_gizmo (pool->parent, (void *) (((char *) pool) + POOL_SIZE + POOL_BLOCK_SIZE)); - { - struct pool_gizmo *cur, *next; + free_all_gizmos (pool); - for (cur = pool->gizmos; cur; cur = next) - { - next = cur->next; - free_gizmo (cur); - } - } - + /* Free all the memory. */ { struct pool_block *cur, *next; @@ -205,6 +200,30 @@ pool_destroy (struct pool *pool) } } } + +/* Release all the memory and gizmos in POOL. + Blocks are not given back with free() but kept for later + allocations. To give back memory, use a subpool instead. */ +void +pool_clear (struct pool *pool) +{ + free_all_gizmos (pool); + + /* Zero out block sizes. */ + { + struct pool_block *cur; + + cur = pool->blocks; + do + { + cur->ofs = POOL_BLOCK_SIZE; + if ((char *) cur + POOL_BLOCK_SIZE == (char *) pool) + cur->ofs += POOL_SIZE; + cur = cur->next; + } + while (cur != pool->blocks); + } +} /* Suballocation routines. */ @@ -215,9 +234,10 @@ pool_alloc (struct pool *pool, size_t amt) { assert (pool != NULL); -#if !DISCRETE_BLOCKS +#ifndef DISCRETE_BLOCKS if (amt <= MAX_SUBALLOC) { + /* If there is space in this block, take it. */ struct pool_block *b = pool->blocks; b->ofs = ROUND_UP (b->ofs, ALIGN_SIZE); if (b->ofs + amt <= BLOCK_SIZE) @@ -227,18 +247,34 @@ pool_alloc (struct pool *pool, size_t amt) return p; } - b = xmalloc (BLOCK_SIZE); - b->next = pool->blocks; - b->prev = pool->blocks->prev; - b->ofs = POOL_BLOCK_SIZE + amt; - - pool->blocks->prev->next = b; - pool->blocks = pool->blocks->prev = b; - - return ((char *) b) + POOL_BLOCK_SIZE; + /* No space in this block, so we must make other + arrangements. */ + if (b->next->ofs == 0) + { + /* The next block is empty. Use it. */ + b = b->next; + b->ofs = POOL_BLOCK_SIZE; + if ((char *) b + POOL_BLOCK_SIZE == (char *) pool) + b->ofs += POOL_SIZE; + } + else + { + /* Create a new block at the start of the list. */ + b = xmalloc (BLOCK_SIZE); + b->next = pool->blocks; + b->prev = pool->blocks->prev; + b->ofs = POOL_BLOCK_SIZE; + pool->blocks->prev->next = b; + pool->blocks->prev = b; + } + pool->blocks = b; + + /* Allocate space from B. */ + b->ofs += amt; + return ((char *) b) + b->ofs - amt; } else -#endif /* !DISCRETE_BLOCKS */ +#endif return pool_malloc (pool, amt); } @@ -257,19 +293,19 @@ pool_strndup (struct pool *pool, const char *string, size_t length) size = length + 1; /* Note that strings need not be aligned on any boundary. */ +#ifndef DISCRETE_BLOCKS { -#if !DISCRETE_BLOCKS struct pool_block *const b = pool->blocks; if (b->ofs + size <= BLOCK_SIZE) { - copy = ((char *) b) + b->ofs; - b->ofs += size; + copy = ((char *) b) + b->ofs; + b->ofs += size; } - else -#endif - copy = pool_alloc (pool, size); } +#else + copy = pool_alloc (pool, size); +#endif memcpy (copy, string, length); copy[length] = '\0'; @@ -495,7 +531,10 @@ pool_mark (struct pool *pool, struct pool_mark *mark) mark->serial = serial; } -/* Restores to POOL the state recorded in MARK. */ +/* Restores to POOL the state recorded in MARK. + Emptied blocks are not given back with free() but kept for + later allocations. To get that behavior, use a subpool + instead. */ void pool_release (struct pool *pool, const struct pool_mark *mark) { @@ -520,21 +559,16 @@ pool_release (struct pool *pool, const struct pool_mark *mark) } { - struct pool_block *cur, *next, *last; + struct pool_block *cur; - last = pool->blocks->prev; - for (cur = pool->blocks; cur != mark->block; cur = next) + for (cur = pool->blocks; cur != mark->block; cur = cur->next) { - next = cur->next; - assert (next != cur); - - free (cur); + cur->ofs = POOL_BLOCK_SIZE; + if ((char *) cur + POOL_BLOCK_SIZE == (char *) pool) + cur->ofs += POOL_SIZE; } - - cur->prev = last; - last->next = pool->blocks = cur; - - cur->ofs = mark->ofs; + pool->blocks = mark->block; + pool->blocks->ofs = mark->ofs; } } @@ -595,6 +629,19 @@ free_gizmo (struct pool_gizmo *gizmo) assert (0); } } + +/* Free all the gizmos in POOL. */ +static void +free_all_gizmos (struct pool *pool) +{ + struct pool_gizmo *cur, *next; + + for (cur = pool->gizmos; cur; cur = next) + { + next = cur->next; + free_gizmo (cur); + } +} /* Memory allocation. */ diff --git a/src/pool.h b/src/pool.h index a751c96cb7..dd7080a15b 100644 --- a/src/pool.h +++ b/src/pool.h @@ -36,6 +36,7 @@ struct pool_mark /* General routines. */ struct pool *pool_create (void); void pool_destroy (struct pool *); +void pool_clear (struct pool *); /* Suballocation routines. */ void *pool_alloc (struct pool *, size_t); diff --git a/src/postscript.c b/src/postscript.c index be8abb5a60..8a11935aa6 100644 --- a/src/postscript.c +++ b/src/postscript.c @@ -287,7 +287,7 @@ static char *quote_ps_string (char *dest, const char *string); /* Driver initialization. */ static int -ps_open_global (struct outp_class *this unused) +ps_open_global (struct outp_class *this UNUSED) { init_fonts (); groff_init (); @@ -295,13 +295,13 @@ ps_open_global (struct outp_class *this unused) } static int -ps_close_global (struct outp_class *this unused) +ps_close_global (struct outp_class *this UNUSED) { return 1; } static int * -ps_font_sizes (struct outp_class *this unused, int *n_valid_sizes) +ps_font_sizes (struct outp_class *this UNUSED, int *n_valid_sizes) { /* Allow fonts up to 1" in height. */ static int valid_sizes[] = @@ -494,14 +494,14 @@ ps_close_driver (struct outp_driver *this) /* font_entry comparison function for hash tables. */ static int -compare_font_entry (const void *a, const void *b, void *foobar unused) +compare_font_entry (const void *a, const void *b, void *foobar UNUSED) { return strcmp (((struct font_entry *) a)->dit, ((struct font_entry *) b)->dit); } /* font_entry hash function for hash tables. */ static unsigned -hash_font_entry (const void *fe_, void *foobar unused) +hash_font_entry (const void *fe_, void *foobar UNUSED) { const struct font_entry *fe = fe_; return hsh_hash_string (fe->dit); @@ -509,7 +509,7 @@ hash_font_entry (const void *fe_, void *foobar unused) /* font_entry destructor function for hash tables. */ static void -free_font_entry (void *pa, void *foo unused) +free_font_entry (void *pa, void *foo UNUSED) { struct font_entry *a = pa; free (a->dit); @@ -856,7 +856,7 @@ find_ps_file (struct outp_driver *this, const char *name) /* Hash table comparison function for ps_encoding's. */ static int -compare_ps_encoding (const void *pa, const void *pb, void *foo unused) +compare_ps_encoding (const void *pa, const void *pb, void *foo UNUSED) { const struct ps_encoding *a = pa; const struct ps_encoding *b = pb; @@ -866,7 +866,7 @@ compare_ps_encoding (const void *pa, const void *pb, void *foo unused) /* Hash table hash function for ps_encoding's. */ static unsigned -hash_ps_encoding (const void *pa, void *foo unused) +hash_ps_encoding (const void *pa, void *foo UNUSED) { const struct ps_encoding *a = pa; @@ -875,7 +875,7 @@ hash_ps_encoding (const void *pa, void *foo unused) /* Hash table free function for ps_encoding's. */ static void -free_ps_encoding (void *pa, void *foo unused) +free_ps_encoding (void *pa, void *foo UNUSED) { struct ps_encoding *a = pa; @@ -1726,7 +1726,7 @@ int_2_compare (const void *a_, const void *b_) /* Hash table comparison function for cached lines. */ static int -compare_line (const void *a_, const void *b_, void *foo unused) +compare_line (const void *a_, const void *b_, void *foo UNUSED) { const struct line_form *a = a_; const struct line_form *b = b_; @@ -1736,7 +1736,7 @@ compare_line (const void *a_, const void *b_, void *foo unused) /* Hash table hash function for cached lines. */ static unsigned -hash_line (const void *pa, void *foo unused) +hash_line (const void *pa, void *foo UNUSED) { const struct line_form *a = pa; @@ -1745,7 +1745,7 @@ hash_line (const void *pa, void *foo unused) /* Hash table free function for cached lines. */ static void -free_line (void *pa, void *foo unused) +free_line (void *pa, void *foo UNUSED) { free (pa); } @@ -1898,7 +1898,7 @@ line (struct outp_driver *this, int type, int ind, int dep1, int dep2) static void ps_line_horz (struct outp_driver *this, const struct rect *r, - const struct color *c unused, int style) + const struct color *c UNUSED, int style) { /* Must match output.h:OUTP_L_*. */ static const int types[OUTP_L_COUNT] = @@ -1915,7 +1915,7 @@ ps_line_horz (struct outp_driver *this, const struct rect *r, static void ps_line_vert (struct outp_driver *this, const struct rect *r, - const struct color *c unused, int style) + const struct color *c UNUSED, int style) { /* Must match output.h:OUTP_L_*. */ static const int types[OUTP_L_COUNT] = @@ -1937,7 +1937,7 @@ ps_line_vert (struct outp_driver *this, const struct rect *r, static void ps_line_intersection (struct outp_driver *this, const struct rect *r, - const struct color *c unused, + const struct color *c UNUSED, const struct outp_styles *style) { struct ps_driver_ext *ext = this->ext; @@ -2018,25 +2018,25 @@ ps_line_intersection (struct outp_driver *this, const struct rect *r, } static void -ps_box (struct outp_driver *this unused, const struct rect *r unused, - const struct color *bord unused, const struct color *fill unused) +ps_box (struct outp_driver *this UNUSED, const struct rect *r UNUSED, + const struct color *bord UNUSED, const struct color *fill UNUSED) { assert (this->driver_open && this->page_open); } static void -ps_polyline_begin (struct outp_driver *this unused, - const struct color *c unused) +ps_polyline_begin (struct outp_driver *this UNUSED, + const struct color *c UNUSED) { assert (this->driver_open && this->page_open); } static void -ps_polyline_point (struct outp_driver *this unused, int x unused, int y unused) +ps_polyline_point (struct outp_driver *this UNUSED, int x UNUSED, int y UNUSED) { assert (this->driver_open && this->page_open); } static void -ps_polyline_end (struct outp_driver *this unused) +ps_polyline_end (struct outp_driver *this UNUSED) { assert (this->driver_open && this->page_open); } @@ -2270,7 +2270,7 @@ struct output_char /* Hash table comparison function for ps_combo structs. */ static int -compare_ps_combo (const void *pa, const void *pb, void *foo unused) +compare_ps_combo (const void *pa, const void *pb, void *foo UNUSED) { const struct ps_font_combo *a = pa; const struct ps_font_combo *b = pb; @@ -2280,7 +2280,7 @@ compare_ps_combo (const void *pa, const void *pb, void *foo unused) /* Hash table hash function for ps_combo structs. */ static unsigned -hash_ps_combo (const void *pa, void *foo unused) +hash_ps_combo (const void *pa, void *foo UNUSED) { const struct ps_font_combo *a = pa; unsigned name_hash = hsh_hash_string (a->font->font->internal_name); @@ -2289,7 +2289,7 @@ hash_ps_combo (const void *pa, void *foo unused) /* Hash table free function for ps_combo structs. */ static void -free_ps_combo (void *a, void *foo unused) +free_ps_combo (void *a, void *foo UNUSED) { free (a); } @@ -2388,7 +2388,7 @@ switch_font (struct outp_driver *this, const struct output_char *cp) static void write_text (struct outp_driver *this, const struct output_char *cp, const struct output_char *end, - struct outp_text *t, int width unused, int width_left) + struct outp_text *t, int width UNUSED, int width_left) { struct ps_driver_ext *ext = this->ext; int ofs; @@ -2787,7 +2787,7 @@ static struct hsh_table *ps_fonts; /* Hash table comparison function for filename2font structs. */ static int -compare_filename2font (const void *a, const void *b, void *param unused) +compare_filename2font (const void *a, const void *b, void *param UNUSED) { return strcmp (((struct filename2font *) a)->filename, ((struct filename2font *) b)->filename); @@ -2795,7 +2795,7 @@ compare_filename2font (const void *a, const void *b, void *param unused) /* Hash table hash function for filename2font structs. */ static unsigned -hash_filename2font (const void *f2f_, void *param unused) +hash_filename2font (const void *f2f_, void *param UNUSED) { const struct filename2font *f2f = f2f_; return hsh_hash_string (f2f->filename); diff --git a/src/print.c b/src/print.c index e1f7f6eff6..7d5b73b8cc 100644 --- a/src/print.c +++ b/src/print.c @@ -80,9 +80,7 @@ struct print_trns int options; /* PRT_* bitmapped field. */ struct prt_out_spec *spec; /* Output specifications. */ int max_width; /* Maximum line width including null. */ -#if !PAGED_STACK char *line; /* Buffer for sticking lines in. */ -#endif }; /* PRT_PRINT or PRT_WRITE. */ @@ -152,9 +150,7 @@ internal_cmd_print (int f) prt.handle = NULL; prt.options = f; prt.spec = NULL; -#if !PAGED_STACK prt.line = NULL; -#endif next = NULL; nrec = 0; @@ -853,15 +849,14 @@ dump_table (void) } /* PORTME: The number of characters in a line terminator. */ -#if __MSDOS__ +#ifdef __MSDOS__ #define LINE_END_WIDTH 2 /* \r\n */ #else #define LINE_END_WIDTH 1 /* \n */ #endif /* Calculates the maximum possible line width and allocates a buffer - big enough to contain it, if necessary (otherwise sets max_width). - (The action taken depends on compiler & OS as detected by pref.h.) */ + big enough to contain it */ static void alloc_line (void) { @@ -898,9 +893,7 @@ alloc_line (void) w = pot_w; } prt.max_width = w + LINE_END_WIDTH + 1; -#if !PAGED_STACK prt.line = xmalloc (prt.max_width); -#endif } /* Transformation. */ @@ -916,15 +909,7 @@ print_trns_proc (struct trns_header * trns, struct ccase * c) struct prt_out_spec *i; /* Line buffer. */ -#if PAGED_STACK -#if __GNUC__ && !__STRICT_ANSI__ - char buf[t->max_width]; -#else /* !__GNUC__ */ - char *buf = alloca (t->max_width); -#endif /* !__GNUC__ */ -#else /* !PAGED_STACK */ char *buf = t->line; -#endif /* !PAGED_STACK */ /* Length of the line in buf. */ int len = 0; @@ -952,7 +937,7 @@ print_trns_proc (struct trns_header * trns, struct ccase * c) || t->handle->mode != FH_MD_BINARY) { /* PORTME: Line ends. */ -#if __MSDOS__ +#ifdef __MSDOS__ buf[len++] = '\r'; #endif buf[len++] = '\n'; @@ -1022,9 +1007,7 @@ print_trns_free (struct trns_header * t) n = i->next; free (i); } -#if !PAGED_STACK free (((struct print_trns *) t)->line); -#endif } /* PRINT SPACE. */ @@ -1130,7 +1113,7 @@ print_space_trns_proc (struct trns_header * trns, struct ccase * c) char buf[LINE_END_WIDTH]; /* PORTME: Line ends. */ -#if __MSDOS__ +#ifdef __MSDOS__ buf[0] = '\r'; buf[1] = '\n'; #else diff --git a/src/q2c.c b/src/q2c.c index a1bc26ba8e..c85ea9b37d 100644 --- a/src/q2c.c +++ b/src/q2c.c @@ -99,9 +99,7 @@ finish_up (void) fprintf (stderr, "%s: %s: remove: %s\n", pgmname, ofn, strerror (errno)); } -#if __GNUC__ >= 2 -void hcf (void) __attribute__ ((noreturn)); -#endif +void hcf (void) NO_RETURN; /* Terminate unsuccessfully. */ void @@ -111,10 +109,8 @@ hcf (void) exit (EXIT_FAILURE); } -#if __GNUC__ >= 2 -int fail (const char *, ...) __attribute__ ((format (printf, 1, 2))); -int error (const char *, ...) __attribute__ ((format (printf, 1, 2))); -#endif +int fail (const char *, ...) PRINTF_FORMAT (1, 2); +int error (const char *, ...) PRINTF_FORMAT (1, 2); /* Output an error message and terminate unsuccessfully. */ int @@ -859,9 +855,7 @@ parse_subcommands (void) /* Size of the indent from the left margin. */ int indent; -#if __GNUC__ >= 2 -void dump (int, const char *, ...) __attribute__ ((format (printf, 2, 3))); -#endif +void dump (int, const char *, ...) PRINTF_FORMAT (2, 3); /* Write line FORMAT to the output file, formatted as with printf, indented `indent' characters from the left margin. If INDENTION is @@ -1734,7 +1728,7 @@ dump_free (void) dump (0, "static void"); dump (0, "free_%s (struct cmd_%s *p%s)", make_identifier (cmdname), - make_identifier (cmdname), used ? "" : " unused"); + make_identifier (cmdname), used ? "" : " UNUSED"); dump (1, "{"); for (sbc = subcommands; sbc; sbc = sbc->next) diff --git a/src/sample.c b/src/sample.c index b721f2db9c..8a5406d142 100644 --- a/src/sample.c +++ b/src/sample.c @@ -119,7 +119,7 @@ cmd_sample (void) } int -sample_trns_proc (struct trns_header * trns, struct ccase *c unused) +sample_trns_proc (struct trns_header * trns, struct ccase *c UNUSED) { struct sample_trns *t = (struct sample_trns *) trns; double U; diff --git a/src/set.q b/src/set.q index c34a6a8aff..5d9f149072 100644 --- a/src/set.q +++ b/src/set.q @@ -486,7 +486,7 @@ set_routing (int q, int *setting) } static int -stc_custom_pager (struct cmd_set *cmd unused) +stc_custom_pager (struct cmd_set *cmd UNUSED) { lex_match ('='); #if !USE_INTERNAL_PAGER @@ -519,7 +519,7 @@ stc_custom_pager (struct cmd_set *cmd unused) SYSMIS or a numeric value; PC+: Syntax is '.', which is equivalent to SYSMIS, or a numeric value. */ static int -stc_custom_blanks (struct cmd_set *cmd unused) +stc_custom_blanks (struct cmd_set *cmd UNUSED) { lex_match ('='); if ((token == T_ID && lex_id_match ("SYSMIS", tokid)) @@ -539,7 +539,7 @@ stc_custom_blanks (struct cmd_set *cmd unused) } static int -stc_custom_length (struct cmd_set *cmd unused) +stc_custom_length (struct cmd_set *cmd UNUSED) { int page_length; @@ -564,7 +564,7 @@ stc_custom_length (struct cmd_set *cmd unused) } static int -stc_custom_results (struct cmd_set *cmd unused) +stc_custom_results (struct cmd_set *cmd UNUSED) { struct tuple { @@ -605,7 +605,7 @@ stc_custom_results (struct cmd_set *cmd unused) } static int -stc_custom_seed (struct cmd_set *cmd unused) +stc_custom_seed (struct cmd_set *cmd UNUSED) { lex_match ('='); if (lex_match_id ("RANDOM")) @@ -622,7 +622,7 @@ stc_custom_seed (struct cmd_set *cmd unused) } static int -stc_custom_width (struct cmd_set *cmd unused) +stc_custom_width (struct cmd_set *cmd UNUSED) { int page_width; @@ -651,7 +651,7 @@ stc_custom_width (struct cmd_set *cmd unused) /* Parses FORMAT subcommand, which consists of a numeric format specifier. */ static int -stc_custom_format (struct cmd_set *cmd unused) +stc_custom_format (struct cmd_set *cmd UNUSED) { struct fmt_spec fmt; @@ -671,7 +671,7 @@ stc_custom_format (struct cmd_set *cmd unused) } static int -stc_custom_journal (struct cmd_set *cmd unused) +stc_custom_journal (struct cmd_set *cmd UNUSED) { lex_match ('='); if (lex_match_id ("ON")) @@ -689,7 +689,7 @@ stc_custom_journal (struct cmd_set *cmd unused) /* Parses COLOR subcommand. PC+: either ON or OFF or two or three comma-delimited numbers inside parentheses. */ static int -stc_custom_color (struct cmd_set *cmd unused) +stc_custom_color (struct cmd_set *cmd UNUSED) { msg (MW, _("%s is obsolete."),"COLOR"); @@ -740,7 +740,7 @@ stc_custom_color (struct cmd_set *cmd unused) } static int -stc_custom_listing (struct cmd_set *cmd unused) +stc_custom_listing (struct cmd_set *cmd UNUSED) { lex_match ('='); if (lex_match_id ("ON") || lex_match_id ("YES")) @@ -756,21 +756,21 @@ stc_custom_listing (struct cmd_set *cmd unused) } static int -stc_custom_disk (struct cmd_set *cmd unused) +stc_custom_disk (struct cmd_set *cmd UNUSED) { stc_custom_listing (cmd); return 0; } static int -stc_custom_log (struct cmd_set *cmd unused) +stc_custom_log (struct cmd_set *cmd UNUSED) { stc_custom_journal (cmd); return 0; } static int -stc_custom_rcolor (struct cmd_set *cmd unused) +stc_custom_rcolor (struct cmd_set *cmd UNUSED) { msg (SW, _("%s is obsolete."),"RCOLOR"); @@ -819,7 +819,7 @@ stc_custom_rcolor (struct cmd_set *cmd unused) } static int -stc_custom_viewlength (struct cmd_set *cmd unused) +stc_custom_viewlength (struct cmd_set *cmd UNUSED) { if (lex_match_id ("MINIMUM")) set_viewlength = 25; @@ -831,7 +831,7 @@ stc_custom_viewlength (struct cmd_set *cmd unused) { if (!lex_force_int ()) return 0; -#if __MSDOS__ +#ifdef __MSDOS__ if (lex_integer () >= (43 + 25) / 2) set_viewlength = 43; else @@ -842,14 +842,14 @@ stc_custom_viewlength (struct cmd_set *cmd unused) lex_get (); } -#if __MSDOS__ +#ifdef __MSDOS__ msg (SW, _("%s is not yet implemented."),"VIEWLENGTH"); #endif /* dos */ return 1; } static int -stc_custom_workdev (struct cmd_set *cmd unused) +stc_custom_workdev (struct cmd_set *cmd UNUSED) { char c[2]; diff --git a/src/sfm-read.c b/src/sfm-read.c index bbf5762c11..c38aa1c2d1 100644 --- a/src/sfm-read.c +++ b/src/sfm-read.c @@ -126,7 +126,7 @@ bswap_flt64 (flt64 *x) static void corrupt_msg (int class, const char *format,...) - __attribute__ ((format (printf, 2, 3))); + PRINTF_FORMAT (2, 3); /* Displays a corrupt sysfile error. */ static void diff --git a/src/sfmP.h b/src/sfmP.h index d03ba042b7..fd47a070e7 100644 --- a/src/sfmP.h +++ b/src/sfmP.h @@ -21,7 +21,7 @@ structures. */ /* This attribute might avoid some problems. On the other hand... */ -#define P __attribute__((packed)) +#define P ATTRIBUTE ((packed)) #if __BORLANDC__ #pragma option -a- /* Turn off alignment. */ diff --git a/src/sort.c b/src/sort.c index d68ee45b2a..de3ff977aa 100644 --- a/src/sort.c +++ b/src/sort.c @@ -429,10 +429,10 @@ allocate_file_handles (void) if (dir == NULL) dir = P_tmpdir; #endif -#if __unix__ +#ifdef unix if (dir == NULL) dir = "/tmp"; -#elif __MSDOS__ +#elif defined (__MSDOS__) if (dir == NULL) dir = getenv ("TEMP"); if (dir == NULL) @@ -446,7 +446,11 @@ allocate_file_handles (void) buf = xmalloc (strlen (dir) + 1 + 4 + 8 + 4 + 1 + INT_DIGITS + 1); cp = spprintf (buf, "%s%c%04lX%04lXpspp", dir, DIR_SEPARATOR, ((long) time (0)) & 0xffff, ((long) getpid ()) & 0xffff); +#ifndef __MSDOS__ if (-1 == mkdir (buf, S_IRWXU)) +#else + if (-1 == mkdir (buf)) +#endif { free (buf); msg (SE, _("%s: Cannot create temporary directory: %s."), diff --git a/src/str.h b/src/str.h index dedcc10daa..719b503b8e 100644 --- a/src/str.h +++ b/src/str.h @@ -181,7 +181,7 @@ void ds_putchar (struct string *, int ch); void ds_concat (struct string *, const char *); void ds_concat_buffer (struct string *, const char *buf, size_t len); void ds_printf (struct string *, const char *, ...) - __attribute__ ((format (printf, 2, 3))); + PRINTF_FORMAT (2, 3); #if __GNUC__ > 1 extern inline void diff --git a/src/t-test.q b/src/t-test.q index c19a932798..1e3150fa57 100644 --- a/src/t-test.q +++ b/src/t-test.q @@ -167,8 +167,8 @@ static int paired_calc (struct ccase *); static void paired_precalc (void); static void paired_postcalc (void); -static int compare_var_name (const void *a_, const void *b_, void *v_ unused); -static unsigned hash_var_name (const void *a_, void *v_ unused); +static int compare_var_name (const void *a_, const void *b_, void *v_ UNUSED); +static unsigned hash_var_name (const void *a_, void *v_ UNUSED); int @@ -295,7 +295,7 @@ cmd_t_test(void) } static int -tts_custom_groups (struct cmd_t_test *cmd unused) +tts_custom_groups (struct cmd_t_test *cmd UNUSED) { lex_match('='); @@ -360,7 +360,7 @@ tts_custom_groups (struct cmd_t_test *cmd unused) static int -tts_custom_pairs (struct cmd_t_test *cmd unused) +tts_custom_pairs (struct cmd_t_test *cmd UNUSED) { struct variable **vars; int n_vars; @@ -676,7 +676,7 @@ void ssbox_paired_populate(struct ssbox *ssb, /* Initialize the paired values ssbox */ void -ssbox_paired_init(struct ssbox *this, struct cmd_t_test *cmd unused) +ssbox_paired_init(struct ssbox *this, struct cmd_t_test *cmd UNUSED) { int hsize=6; @@ -697,7 +697,7 @@ ssbox_paired_init(struct ssbox *this, struct cmd_t_test *cmd unused) /* Populate the ssbox for paired values */ void -ssbox_paired_populate(struct ssbox *ssb,struct cmd_t_test *cmd unused) +ssbox_paired_populate(struct ssbox *ssb,struct cmd_t_test *cmd UNUSED) { int i; @@ -818,7 +818,7 @@ trbox_finalize(struct trbox *trb) /* Initialize the independent samples trbox */ void trbox_independent_samples_init(struct trbox *self, - struct cmd_t_test *cmd unused) + struct cmd_t_test *cmd UNUSED) { const int hsize=11; const int vsize=cmd->n_variables*2+3; @@ -877,7 +877,7 @@ trbox_independent_samples_populate(struct trbox *self, /* Initialize the paired samples trbox */ void trbox_paired_init(struct trbox *self, - struct cmd_t_test *cmd unused) + struct cmd_t_test *cmd UNUSED) { const int hsize=10; @@ -912,7 +912,7 @@ trbox_paired_init(struct trbox *self, /* Populate the paired samples trbox */ void trbox_paired_populate(struct trbox *trb, - struct cmd_t_test *cmd unused) + struct cmd_t_test *cmd UNUSED) { int i; @@ -1316,7 +1316,7 @@ one_sample_postcalc (void) static int -compare_var_name (const void *a_, const void *b_, void *v_ unused) +compare_var_name (const void *a_, const void *b_, void *v_ UNUSED) { const struct variable *a = a_; const struct variable *b = b_; @@ -1325,7 +1325,7 @@ compare_var_name (const void *a_, const void *b_, void *v_ unused) } static unsigned -hash_var_name (const void *a_, void *v_ unused) +hash_var_name (const void *a_, void *v_ UNUSED) { const struct variable *a = a_; diff --git a/src/tab.c b/src/tab.c index e017418d29..862028a8c5 100644 --- a/src/tab.c +++ b/src/tab.c @@ -1263,7 +1263,7 @@ struct som_table_class tab_table_class = FIXME: Doesn't use r1? Huh? */ static int -render_strip (int x, int y, int r, int c1, int c2, int r1 unused, int r2) +render_strip (int x, int y, int r, int c1, int c2, int r1 UNUSED, int r2) { int x_origin = x; diff --git a/src/tab.h b/src/tab.h index 37e045c961..7062c79c3f 100644 --- a/src/tab.h +++ b/src/tab.h @@ -169,10 +169,10 @@ void tab_float (struct tab_table *, int c, int r, unsigned char opt, double v, int w, int d); void tab_text (struct tab_table *, int c, int r, unsigned opt, const char *, ...) - __attribute__ ((format (printf, 5, 6))); + PRINTF_FORMAT (5, 6); void tab_joint_text (struct tab_table *, int x1, int y1, int x2, int y2, unsigned opt, const char *, ...) - __attribute__ ((format (printf, 7, 8))); + PRINTF_FORMAT (7, 8); /* Cell low-level access. */ #define tab_alloc(TABLE, AMT) pool_alloc ((TABLE)->container, (AMT)) @@ -189,7 +189,7 @@ void tab_next_row (struct tab_table *); /* Simple output. */ void tab_output_text (int options, const char *string, ...) - __attribute__ ((format (printf, 2, 3))); + PRINTF_FORMAT (2, 3); #endif /* tab_h */ diff --git a/src/value-labels.c b/src/value-labels.c index e061e452e5..9c7640866c 100644 --- a/src/value-labels.c +++ b/src/value-labels.c @@ -384,7 +384,7 @@ hash_int_val_lab (const void *vl_, void *vls_) /* Free a value label. */ void -free_int_val_lab (void *vl_, void *vls_ unused) +free_int_val_lab (void *vl_, void *vls_ UNUSED) { struct int_val_lab *vl = vl_; @@ -462,7 +462,7 @@ atom_to_string (const struct atom *atom) /* A hsh_compare_func that compares A and B. */ static int -compare_atoms (const void *a_, const void *b_, void *aux unused) +compare_atoms (const void *a_, const void *b_, void *aux UNUSED) { const struct atom *a = a_; const struct atom *b = b_; @@ -472,7 +472,7 @@ compare_atoms (const void *a_, const void *b_, void *aux unused) /* A hsh_hash_func that hashes ATOM. */ static unsigned -hash_atom (const void *atom_, void *aux unused) +hash_atom (const void *atom_, void *aux UNUSED) { const struct atom *atom = atom_; @@ -481,7 +481,7 @@ hash_atom (const void *atom_, void *aux unused) /* A hsh_free_func that destroys ATOM. */ static void -free_atom (void *atom_, void *aux unused) +free_atom (void *atom_, void *aux UNUSED) { struct atom *atom = atom_; diff --git a/src/vars-atr.c b/src/vars-atr.c index d1bbd61080..41e4a70197 100644 --- a/src/vars-atr.c +++ b/src/vars-atr.c @@ -174,7 +174,7 @@ is_user_missing (const union value *val, const struct variable *v) /* A hsh_compare_func that orders variables A and B by their names. */ int -compare_variables (const void *a_, const void *b_, void *foo unused) +compare_variables (const void *a_, const void *b_, void *foo UNUSED) { const struct variable *a = a_; const struct variable *b = b_; @@ -184,7 +184,7 @@ compare_variables (const void *a_, const void *b_, void *foo unused) /* A hsh_hash_func that hashes variable V based on its name. */ unsigned -hash_variable (const void *v_, void *foo unused) +hash_variable (const void *v_, void *foo UNUSED) { const struct variable *v = v_; -- 2.30.2