# HG changeset patch # User jwe # Date 1041309753 0 # Node ID 8a1ef8fe403611d3a60a26f97d9b792e53da49ee # Parent eef64f3f9a4c701eef406d82f76d9e9f77dc0753 [project @ 2002-12-31 04:42:32 by jwe] diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2002-12-30 John W. Eaton + + * configure.in (OCTAVE_LOCAL_BUFFER): New macro. + 2002-12-18 John W. Eaton * mkoctfile.in: Include $LIBOCTINTERP in the stand alone link command. diff --git a/configure.in b/configure.in --- a/configure.in +++ b/configure.in @@ -22,7 +22,7 @@ ### 02111-1307, USA. AC_INIT -AC_REVISION($Revision: 1.399 $) +AC_REVISION($Revision: 1.400 $) AC_PREREQ(2.52) AC_CONFIG_SRCDIR([src/octave.cc]) AC_CONFIG_HEADER(config.h) @@ -1348,6 +1348,15 @@ #if defined (sigsetjmp) && defined (HAVE_SIGLONGJMP) #define OCTAVE_HAVE_SIG_JUMP #endif + +#if defined (__GNUG__) +#define OCTAVE_LOCAL_BUFFER(T, buf, size) \ + T buf[size] +#else +#define OCTAVE_LOCAL_BUFFER(T, buf, size) \ + std::auto_ptr buf_auto_ptr (new T [size]); \ + T *buf = buf_auto_ptr.get () +#endif ]) ### Do the substitutions in all the Makefiles. diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 2002-12-30 John W. Eaton + * utils.cc (Ffile_in_path): Index args correctly. + + * utils.cc (Ffile_in_path): Call error, not print_usage, for + invalid option error. + (Ffile_in_loadpath): Likewise. + + * load-save.cc: Use OCTAVE_LOCAL_BUFFER instead of local automatic + arrays or using new/delete. + * lex.l (.): Try another approach to handling EOF here. * load-save.cc (read_mat_ascii_data): Use isalpha and isalnum, not diff --git a/src/load-save.cc b/src/load-save.cc --- a/src/load-save.cc +++ b/src/load-save.cc @@ -32,9 +32,10 @@ #include #include +#include #include #include -#include +#include #include #ifdef HAVE_HDF5 @@ -653,7 +654,8 @@ int len; if (extract_keyword (is, "length", len) && len >= 0) { - char tmp[len+1]; + OCTAVE_LOCAL_BUFFER (char, tmp, len+1); + if (len > 0 && ! is.read (X_CAST (char *, tmp), len)) { error ("load: failed to load string constant"); @@ -685,7 +687,8 @@ int len; if (extract_keyword (is, "length", len) && len >= 0) { - char *tmp = new char [len+1]; + OCTAVE_LOCAL_BUFFER (char, tmp, len+1); + if (len > 0 && ! is.read (X_CAST (char *, tmp), len)) { error ("load: failed to load string constant"); @@ -931,7 +934,7 @@ goto data_read_error; if (swap) swap_4_bytes (X_CAST (char *, &len)); - char s[len+1]; + OCTAVE_LOCAL_BUFFER (char, s, len+1); if (! is.read (X_CAST (char *, s), len)) goto data_read_error; s[len] = '\0'; @@ -977,7 +980,7 @@ goto data_read_error; if (swap) swap_4_bytes (X_CAST (char *, &len)); - char tmp[len+1]; + OCTAVE_LOCAL_BUFFER (char, tmp, len+1); if (! is.read (X_CAST (char *, tmp), len)) goto data_read_error; if (len > max_len) @@ -1311,9 +1314,8 @@ H5G_stat_t info; herr_t retval = 0; bool ident_valid = valid_identifier (name); - char *vname; - - vname = new char[strlen (name) + 1]; + + OCTAVE_LOCAL_BUFFER (char, vname, strlen (name) + 1); strcpy (vname, name); @@ -1372,8 +1374,8 @@ else if (rank > 0 && rank <= 2) { // real matrix - hsize_t *dims = new hsize_t[rank]; - hsize_t *maxdims = new hsize_t[rank]; + OCTAVE_LOCAL_BUFFER (hsize_t, dims, rank); + OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); H5Sget_simple_extent_dims (space_id, dims, maxdims); @@ -1381,10 +1383,6 @@ // octave uses column-major & HDF5 uses row-major nc = dims[0]; nr = rank > 1 ? dims[1] : 1; - - delete [] dims; - delete [] maxdims; - Matrix m (nr, nc); double *re = m.fortran_vec (); if (H5Dread (data_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, @@ -1395,13 +1393,13 @@ } else if (rank >= 3 && d->import) { - hsize_t *dims = new hsize_t[rank]; - hsize_t *maxdims = new hsize_t[rank]; + OCTAVE_LOCAL_BUFFER (hsize_t, dims, rank); + OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); H5Sget_simple_extent_dims (space_id, dims, maxdims); - hssize_t *start = new hssize_t[rank]; - hsize_t *count = new hsize_t[rank]; + OCTAVE_LOCAL_BUFFER (hssize_t, start, rank); + OCTAVE_LOCAL_BUFFER (hsize_t, count, rank); for (hsize_t i = 0; i < rank; ++i) { @@ -1414,11 +1412,6 @@ rank, dims, rank-1, start, count, H5T_NATIVE_DOUBLE, d->tc); - - delete [] count; - delete [] start; - delete [] dims; - delete [] maxdims; } else { @@ -1474,7 +1467,8 @@ // same physical length (I think), which is // slightly wasteful, but oh well. - char *s = new char [elements * slen]; + OCTAVE_LOCAL_BUFFER (char, s, elements * slen); + // create datatype for (null-terminated) string // to read into: hid_t st_id = H5Tcopy (H5T_C_S1); @@ -1493,8 +1487,6 @@ d->tc = octave_value (chm, true); } - delete [] s; - H5Tclose (st_id); } } @@ -1531,15 +1523,13 @@ else if (rank > 0 && rank <= 2) { // complex matrix - hsize_t *dims = new hsize_t[rank]; - hsize_t *maxdims = new hsize_t[rank]; + OCTAVE_LOCAL_BUFFER (hsize_t, dims, rank); + OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); H5Sget_simple_extent_dims (space_id, dims, maxdims); int nr, nc; // rows and columns // octave uses column-major & HDF5 uses row-major nc = dims[0]; nr = rank > 1 ? dims[1] : 1; - delete [] dims; - delete [] maxdims; ComplexMatrix m (nr, nc); Complex *reim = m.fortran_vec (); if (H5Dread (data_id, d->complex_type, H5S_ALL, @@ -1551,11 +1541,11 @@ } else if (rank >= 3 && d->import) { - hsize_t *dims = new hsize_t[rank]; - hsize_t *maxdims = new hsize_t[rank]; + OCTAVE_LOCAL_BUFFER (hsize_t, dims, rank); + OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); H5Sget_simple_extent_dims (space_id, dims, maxdims); - hssize_t *start = new hssize_t[rank]; - hsize_t *count = new hsize_t[rank]; + OCTAVE_LOCAL_BUFFER (hssize_t, start, rank); + OCTAVE_LOCAL_BUFFER (hsize_t, count, rank); for (hsize_t i = 0; i < rank; ++i) { start[i] = 0; @@ -1568,11 +1558,6 @@ start, count, d->complex_type, d->tc); - - delete [] count; - delete [] start; - delete [] dims; - delete [] maxdims; } else { @@ -1731,8 +1716,6 @@ strcpy (d->name, vname); } - delete [] vname; - return retval; } @@ -2358,7 +2341,7 @@ // supposed to include it, but apparently not all files do. Either // way, I think this should work. - char name[len+1]; + OCTAVE_LOCAL_BUFFER (char, name, len+1); if (! is.read (X_CAST (char *, name), len)) goto data_read_error; name[len] = '\0'; @@ -2623,7 +2606,7 @@ } pos = is.tellg (); - char name[len+1]; + OCTAVE_LOCAL_BUFFER (char, name, len+1); if (len) // structure field subelements have // zero-length array name subelements @@ -2665,7 +2648,6 @@ FOUR_BYTE_INT len; FOUR_BYTE_INT field_name_length; int i; - char *elname; // field name length subelement -- actually the maximum length // of a field name. The Matlab docs promise this will always @@ -2692,7 +2674,7 @@ goto data_read_error; } - elname = new char[len]; + OCTAVE_LOCAL_BUFFER (char, elname, len); if (! is.read (elname, len)) goto data_read_error; @@ -2705,7 +2687,6 @@ m[elname + i*field_name_length] = fieldtc; } - delete [] elname; tc = m; } break; @@ -3687,7 +3668,7 @@ if (data_id < 0) goto error_cleanup; - char *s = new char [nr * (nc + 1)]; + OCTAVE_LOCAL_BUFFER (char, s, nr * (nc + 1)); for (int i = 0; i < nr; ++i) { @@ -3697,11 +3678,8 @@ if (H5Dwrite (data_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void*) s) < 0) { - delete [] s; goto error_cleanup; } - - delete [] s; } else if (tc.is_range ()) { @@ -4014,11 +3992,10 @@ #define MAT5_DO_WRITE(TYPE, data, count, stream) \ do \ { \ - TYPE *ptr = new TYPE [count]; \ + OCTAVE_LOCAL_BUFFER (TYPE, ptr, count); \ for (int i = 0; i < count; i++) \ ptr[i] = X_CAST (TYPE, data[i]); \ stream.write (X_CAST (char *, ptr), count * sizeof (TYPE)); \ - delete [] ptr ; \ } \ while (0) @@ -4187,11 +4164,10 @@ int paddedlength = PAD (namelen); write_mat5_tag (os, miINT8, namelen); - char * paddedname = new char [paddedlength]; + OCTAVE_LOCAL_BUFFER (char, paddedname, paddedlength); memset (paddedname, 0, paddedlength); strncpy (paddedname, name.c_str (), namelen); os.write (paddedname, paddedlength); - delete [] paddedname; } // data element @@ -4202,7 +4178,7 @@ int len = nr*nc*2; int paddedlength = PAD (nr*nc*2); - TWO_BYTE_INT *buf = new TWO_BYTE_INT[nc*nr+3]; + OCTAVE_LOCAL_BUFFER (TWO_BYTE_INT, buf, nc*nr+3); write_mat5_tag (os, miUINT16, len); for (int i = 0; i < nr; i++) @@ -4217,8 +4193,6 @@ if (paddedlength > len) os.write ((char *)buf, paddedlength - len); - - delete [] buf; } else if (tc.is_real_scalar () || tc.is_real_matrix () || tc.is_range ()) { diff --git a/src/utils.cc b/src/utils.cc --- a/src/utils.cc +++ b/src/utils.cc @@ -314,7 +314,7 @@ if (! error_state && opt == "all") retval = Cell (make_absolute (Vload_path_dir_path.find_all_first_of (names))); else - print_usage ("file_in_loadpath: invalid option"); + error ("file_in_loadpath: invalid option"); } } else @@ -348,6 +348,7 @@ If the third optional argument @code{\"all\"} is supplied, return\n\ a cell array containing the list of all files that have the same\n\ name in the path. If no files are found, return an empty cell array.\n\ +@seealso{file_in_loadpath}\n\ @end deftypefn") { octave_value retval; @@ -360,7 +361,7 @@ if (! error_state) { - string_vector names = args(0).all_strings (); + string_vector names = args(1).all_strings (); if (! error_state && names.length () > 0) { @@ -375,12 +376,12 @@ } else if (nargin == 3) { - std::string opt = args(1).string_value (); + std::string opt = args(2).string_value (); if (! error_state && opt == "all") retval = Cell (make_absolute (search_path_for_all_files (path, names))); else - print_usage ("file_in_path: invalid option"); + error ("file_in_path: invalid option"); } } else diff --git a/test/octave.test/system/file_in_path-4.m b/test/octave.test/system/file_in_path-4.m --- a/test/octave.test/system/file_in_path-4.m +++ b/test/octave.test/system/file_in_path-4.m @@ -1,1 +1,1 @@ -file_in_path ("foo", "bar", "baz") +file_in_path ("foo", "bar", "baz", "ooka")