From 70514b3f2f32d57e58b04c01c83bc5f372559824 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 10 Jun 2010 21:31:59 -0700 Subject: [PATCH] tmpfile: Rename "struct tmpfile" to "struct temp_file". Mingw builds were failing because Gnulib was replacing "tmpfile" by "rpl_tmpfile", and this was visible only to some users of "struct tmpfile". The safest fix seems to be just renaming struct tmpfile, so that's what this commit does. Thanks to Harry Thijssen for reporting the problem. Bug #29965. --- src/data/case-tmpfile.c | 22 +++++------ src/libpspp/automake.mk | 4 +- src/libpspp/sparse-xarray.c | 53 +++++++++++++------------- src/libpspp/{tmpfile.c => temp-file.c} | 39 ++++++++++--------- src/libpspp/{tmpfile.h => temp-file.h} | 19 ++++----- tests/automake.mk | 2 +- 6 files changed, 71 insertions(+), 68 deletions(-) rename src/libpspp/{tmpfile.c => temp-file.c} (81%) rename src/libpspp/{tmpfile.h => temp-file.h} (63%) diff --git a/src/data/case-tmpfile.c b/src/data/case-tmpfile.c index 57447866..2b47d6dd 100644 --- a/src/data/case-tmpfile.c +++ b/src/data/case-tmpfile.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ #include #include -#include +#include #include "error.h" #include "xalloc.h" @@ -36,7 +36,7 @@ struct case_tmpfile struct caseproto *proto; /* Format of cases in the tmpfile. */ size_t case_size; /* Number of bytes per case. */ size_t *offsets; /* Offset to each value. */ - struct tmpfile *tmpfile; /* Temporary file. */ + struct temp_file *temp_file; /* Temporary file. */ }; /* Returns the number of bytes needed to store a value with the @@ -72,7 +72,7 @@ case_tmpfile_create (const struct caseproto *proto) ctf = xmalloc (sizeof *ctf); ctf->taint = taint_create (); - ctf->tmpfile = tmpfile_create (); + ctf->temp_file = temp_file_create (); ctf->proto = caseproto_ref (proto); ctf->case_size = 0; n_values = caseproto_get_n_widths (proto); @@ -97,7 +97,7 @@ case_tmpfile_destroy (struct case_tmpfile *ctf) if (ctf != NULL) { struct taint *taint = ctf->taint; - tmpfile_destroy (ctf->tmpfile); + temp_file_destroy (ctf->temp_file); caseproto_unref (ctf->proto); free (ctf->offsets); free (ctf); @@ -149,9 +149,9 @@ case_tmpfile_get_values (const struct case_tmpfile *ctf, { int width = caseproto_get_width (ctf->proto, i); if (width != -1 - && !tmpfile_read (ctf->tmpfile, case_offset + ctf->offsets[i], - width_to_n_bytes (width), - value_to_data (&values[i], width))) + && !temp_file_read (ctf->temp_file, case_offset + ctf->offsets[i], + width_to_n_bytes (width), + value_to_data (&values[i], width))) return false; } return true; @@ -194,9 +194,9 @@ case_tmpfile_put_values (struct case_tmpfile *ctf, { int width = caseproto_get_width (ctf->proto, i); if (width != -1 - && !tmpfile_write (ctf->tmpfile, case_offset + ctf->offsets[i], - width_to_n_bytes (width), - value_to_data (values++, width))) + && !temp_file_write (ctf->temp_file, case_offset + ctf->offsets[i], + width_to_n_bytes (width), + value_to_data (values++, width))) return false; } return true; diff --git a/src/libpspp/automake.mk b/src/libpspp/automake.mk index 35760f3e..e9a5e609 100644 --- a/src/libpspp/automake.mk +++ b/src/libpspp/automake.mk @@ -82,8 +82,8 @@ src_libpspp_libpspp_la_SOURCES = \ src/libpspp/str.h \ src/libpspp/taint.c \ src/libpspp/taint.h \ - src/libpspp/tmpfile.c \ - src/libpspp/tmpfile.h \ + src/libpspp/temp-file.c \ + src/libpspp/temp-file.h \ src/libpspp/tower.c \ src/libpspp/tower.h \ src/libpspp/version.h \ diff --git a/src/libpspp/sparse-xarray.c b/src/libpspp/sparse-xarray.c index 893fe390..7480f7c2 100644 --- a/src/libpspp/sparse-xarray.c +++ b/src/libpspp/sparse-xarray.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include "md4.h" #include "minmax.h" @@ -40,7 +40,7 @@ struct sparse_xarray uint8_t *default_row; /* Defaults for unwritten rows. */ unsigned long int max_memory_rows; /* Max rows before dumping to disk. */ struct sparse_array *memory; /* Backing, if stored in memory. */ - struct tmpfile *disk; /* Backing, if stored on disk. */ + struct temp_file *disk; /* Backing, if stored on disk. */ struct range_set *disk_rows; /* Allocated rows, if on disk. */ }; @@ -103,7 +103,7 @@ sparse_xarray_clone (const struct sparse_xarray *old) const struct range_set_node *node; void *tmp = xmalloc (old->n_bytes); - new->disk = tmpfile_create (); + new->disk = temp_file_create (); new->disk_rows = range_set_clone (old->disk_rows, NULL); for (node = range_set_first (old->disk_rows); node != NULL; node = range_set_next (old->disk_rows, node)) @@ -115,8 +115,8 @@ sparse_xarray_clone (const struct sparse_xarray *old) for (idx = start; idx < end; idx++) { off_t offset = (off_t) idx * old->n_bytes; - if (!tmpfile_read (old->disk, offset, old->n_bytes, tmp) - || !tmpfile_write (new->disk, offset, old->n_bytes, tmp)) + if (!temp_file_read (old->disk, offset, old->n_bytes, tmp) + || !temp_file_write (new->disk, offset, old->n_bytes, tmp)) { free (tmp); sparse_xarray_destroy (new); @@ -151,7 +151,7 @@ sparse_xarray_destroy (struct sparse_xarray *sx) free (*row); sparse_array_destroy (sx->memory); } - tmpfile_destroy (sx->disk); + temp_file_destroy (sx->disk); range_set_destroy (sx->disk_rows); free (sx); } @@ -192,16 +192,16 @@ dump_sparse_xarray_to_disk (struct sparse_xarray *sx) assert (sx->memory != NULL); assert (sx->disk == NULL); - sx->disk = tmpfile_create (); + sx->disk = temp_file_create (); sx->disk_rows = range_set_create (); for (row = sparse_array_first (sx->memory, &idx); row != NULL; row = sparse_array_next (sx->memory, idx, &idx)) { - if (!tmpfile_write (sx->disk, (off_t) idx * sx->n_bytes, sx->n_bytes, + if (!temp_file_write (sx->disk, (off_t) idx * sx->n_bytes, sx->n_bytes, *row)) { - tmpfile_destroy (sx->disk); + temp_file_destroy (sx->disk); sx->disk = NULL; range_set_destroy (sx->disk_rows); sx->disk_rows = NULL; @@ -246,8 +246,8 @@ sparse_xarray_read (const struct sparse_xarray *sx, unsigned long int row, else { if (range_set_contains (sx->disk_rows, row)) - return tmpfile_read (sx->disk, (off_t) row * sx->n_bytes + start, - n, data); + return temp_file_read (sx->disk, (off_t) row * sx->n_bytes + start, + n, data); } memcpy (data, sx->default_row + start, n); @@ -261,15 +261,15 @@ write_disk_row (struct sparse_xarray *sx, unsigned long int row, { off_t ofs = (off_t) row * sx->n_bytes; if (range_set_contains (sx->disk_rows, row)) - return tmpfile_write (sx->disk, ofs + start, n, data); + return temp_file_write (sx->disk, ofs + start, n, data); else { range_set_insert (sx->disk_rows, row, 1); - return (tmpfile_write (sx->disk, ofs, start, sx->default_row) - && tmpfile_write (sx->disk, ofs + start, n, data) - && tmpfile_write (sx->disk, ofs + start + n, - sx->n_bytes - start - n, - sx->default_row + start + n)); + return (temp_file_write (sx->disk, ofs, start, sx->default_row) + && temp_file_write (sx->disk, ofs + start, n, data) + && temp_file_write (sx->disk, ofs + start + n, + sx->n_bytes - start - n, + sx->default_row + start + n)); } } @@ -346,12 +346,12 @@ sparse_xarray_write_columns (struct sparse_xarray *sx, size_t start, for (row = start_row; row < end_row; row++) { off_t offset = (off_t) row * sx->n_bytes; - if (!tmpfile_write (sx->disk, offset + start, n, data)) + if (!temp_file_write (sx->disk, offset + start, n, data)) break; } } - if (tmpfile_error (sx->disk)) + if (temp_file_error (sx->disk)) return false; } return true; @@ -392,8 +392,8 @@ get_row (const struct sparse_xarray *sx, unsigned long int idx, uint8_t **p = sparse_array_get (sx->memory, idx); return *p; } - else if (tmpfile_read (sx->disk, (off_t) idx * sx->n_bytes, - sx->n_bytes, buffer)) + else if (temp_file_read (sx->disk, (off_t) idx * sx->n_bytes, + sx->n_bytes, buffer)) return buffer; else return NULL; @@ -456,10 +456,11 @@ sparse_xarray_copy (const struct sparse_xarray *sx, struct sparse_xarray *dx, for (row = start; row < end; row++) { off_t offset = (off_t) row * sx->n_bytes; - success = (tmpfile_read (sx->disk, offset, sx->n_bytes, tmp) + success = (temp_file_read (sx->disk, offset, sx->n_bytes, + tmp) && cb (tmp, tmp, aux) - && tmpfile_write (dx->disk, offset, - dx->n_bytes, tmp)); + && temp_file_write (dx->disk, offset, + dx->n_bytes, tmp)); if (!success) break; } @@ -596,7 +597,7 @@ sparse_xarray_model_checker_hash (const struct sparse_xarray *sx, for (idx = start; idx < end; idx++) { off_t offset = (off_t) idx * sx->n_bytes; - if (!tmpfile_read (sx->disk, offset, sx->n_bytes, tmp)) + if (!temp_file_read (sx->disk, offset, sx->n_bytes, tmp)) NOT_REACHED (); md4_process_bytes (&idx, sizeof idx, &ctx); md4_process_bytes (tmp, sx->n_bytes, &ctx); diff --git a/src/libpspp/tmpfile.c b/src/libpspp/temp-file.c similarity index 81% rename from src/libpspp/tmpfile.c rename to src/libpspp/temp-file.c index aff135d0..554a6d7d 100644 --- a/src/libpspp/tmpfile.c +++ b/src/libpspp/temp-file.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ #include -#include +#include #include #include @@ -34,7 +34,7 @@ #include "gettext.h" #define _(msgid) gettext (msgid) -struct tmpfile +struct temp_file { FILE *file; /* Underlying file. */ @@ -47,10 +47,10 @@ struct tmpfile /* Creates and returns a new temporary file. The temporary file will be automatically deleted when the process exits. */ -struct tmpfile * -tmpfile_create (void) +struct temp_file * +temp_file_create (void) { - struct tmpfile *tf = xmalloc (sizeof *tf); + struct temp_file *tf = xmalloc (sizeof *tf); tf->file = tmpfile (); if (tf->file == NULL) error (0, errno, _("failed to create temporary file")); @@ -62,12 +62,12 @@ tmpfile_create (void) TF always succeeded, false if an I/O error occurred at some point. */ bool -tmpfile_destroy (struct tmpfile *tf) +temp_file_destroy (struct temp_file *tf) { bool ok = true; if (tf != NULL) { - ok = !tmpfile_error (tf); + ok = !temp_file_error (tf); if (tf->file != NULL) fclose (tf->file); free (tf); @@ -80,11 +80,11 @@ tmpfile_destroy (struct tmpfile *tf) Returns true if the seek is successful and TF is not otherwise tainted, false otherwise. */ static bool -do_seek (const struct tmpfile *tf_, off_t offset) +do_seek (const struct temp_file *tf_, off_t offset) { - struct tmpfile *tf = CONST_CAST (struct tmpfile *, tf_); + struct temp_file *tf = CONST_CAST (struct temp_file *, tf_); - if (!tmpfile_error (tf)) + if (!temp_file_error (tf)) { if (tf->position == offset) return true; @@ -105,11 +105,11 @@ do_seek (const struct tmpfile *tf_, off_t offset) Returns true if successful, false upon an I/O error (in which case TF is marked tainted). */ static bool -do_read (const struct tmpfile *tf_, void *buffer, size_t bytes) +do_read (const struct temp_file *tf_, void *buffer, size_t bytes) { - struct tmpfile *tf = CONST_CAST (struct tmpfile *, tf_); + struct temp_file *tf = CONST_CAST (struct temp_file *, tf_); - assert (!tmpfile_error (tf)); + assert (!temp_file_error (tf)); if (bytes > 0 && fread (buffer, bytes, 1, tf->file) != 1) { if (ferror (tf->file)) @@ -129,9 +129,9 @@ do_read (const struct tmpfile *tf_, void *buffer, size_t bytes) Returns true if successful, false upon an I/O error (in which case TF is marked tainted). */ static bool -do_write (struct tmpfile *tf, const void *buffer, size_t bytes) +do_write (struct temp_file *tf, const void *buffer, size_t bytes) { - assert (!tmpfile_error (tf)); + assert (!temp_file_error (tf)); if (bytes > 0 && fwrite (buffer, bytes, 1, tf->file) != 1) { error (0, errno, _("writing to temporary file")); @@ -144,7 +144,7 @@ do_write (struct tmpfile *tf, const void *buffer, size_t bytes) /* Reads N bytes from TF at byte offset OFFSET into DATA. Returns true if successful, false on failure. */ bool -tmpfile_read (const struct tmpfile *tf, off_t offset, size_t n, void *data) +temp_file_read (const struct temp_file *tf, off_t offset, size_t n, void *data) { return do_seek (tf, offset) && do_read (tf, data, n); } @@ -152,7 +152,8 @@ tmpfile_read (const struct tmpfile *tf, off_t offset, size_t n, void *data) /* Writes the N bytes in DATA to TF at byte offset OFFSET. Returns true if successful, false on failure. */ bool -tmpfile_write (struct tmpfile *tf, off_t offset, size_t n, const void *data) +temp_file_write (struct temp_file *tf, off_t offset, size_t n, + const void *data) { return do_seek (tf, offset) && do_write (tf, data, n); } @@ -160,7 +161,7 @@ tmpfile_write (struct tmpfile *tf, off_t offset, size_t n, const void *data) /* Returns true if an error has occurred in I/O on TF, false if no error has been detected. */ bool -tmpfile_error (const struct tmpfile *tf) +temp_file_error (const struct temp_file *tf) { return tf->file == NULL || ferror (tf->file) || feof (tf->file); } diff --git a/src/libpspp/tmpfile.h b/src/libpspp/temp-file.h similarity index 63% rename from src/libpspp/tmpfile.h rename to src/libpspp/temp-file.h index e679a2fe..5965d544 100644 --- a/src/libpspp/tmpfile.h +++ b/src/libpspp/temp-file.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,16 +17,17 @@ /* A interface to allow a temporary file to be treated as an array of data. */ -#ifndef LIBPSPP_TMPFILE_H -#define LIBPSPP_TMPFILE_H 1 +#ifndef LIBPSPP_TEMP_FILE_H +#define LIBPSPP_TEMP_FILE_H 1 #include #include -struct tmpfile *tmpfile_create (void); -bool tmpfile_destroy (struct tmpfile *); -bool tmpfile_read (const struct tmpfile *, off_t offset, size_t n, void *); -bool tmpfile_write (struct tmpfile *, off_t offset, size_t n, const void *); -bool tmpfile_error (const struct tmpfile *); +struct temp_file *temp_file_create (void); +bool temp_file_destroy (struct temp_file *); +bool temp_file_read (const struct temp_file *, off_t offset, size_t n, void *); +bool temp_file_write (struct temp_file *, off_t offset, size_t n, + const void *); +bool temp_file_error (const struct temp_file *); -#endif /* libpspp/tmpfile.h */ +#endif /* libpspp/temp-file.h */ diff --git a/tests/automake.mk b/tests/automake.mk index 08a6dcad..699ce5d1 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -334,7 +334,7 @@ tests_libpspp_sparse_xarray_test_SOURCES = \ src/libpspp/sparse-xarray.c \ src/libpspp/str.c \ src/libpspp/pool.c \ - src/libpspp/tmpfile.c \ + src/libpspp/temp-file.c \ tests/libpspp/sparse-xarray-test.c tests_libpspp_sparse_xarray_test_LDADD = gl/libgl.la $(LIBINTL) tests_libpspp_sparse_xarray_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10 -- 2.30.2