1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 21:19:24 +00:00

Portability fixes.

This commit is contained in:
Bruno Haible
2003-03-03 14:28:09 +00:00
parent ea37cea17b
commit 9fa3ac42b3
8 changed files with 34 additions and 16 deletions

View File

@@ -1,3 +1,19 @@
2002-12-04 Bruno Haible <bruno@clisp.org>
Portability fixes.
* src/positions.h (Positions::LASTCHAR, Positions::MAX_KEY_POS,
PositionIterator::EOS): Define as compile-time constants using enum.
* src/bool-array.cc (Bool_Array::~Bool_Array): Remove const qualifier
of pointer to be deleted.
* src/input.cc (Input::~Input): Likewise.
* src/keyword.cc (KeywordExt::delete_selchars): Likewise.
* src/main.cc (main): Likewise.
* src/hash-table.cc (Hash_Table::~Hash_Table): Limit scope of 'for'
variables.
* src/search.cc (Search::prepare_asso_values): Use a static_cast to
convert from time_t to long. This is possible because ISO C 99 says
time_t is a numeric type.
2002-11-20 Bruno Haible <bruno@clisp.org> 2002-11-20 Bruno Haible <bruno@clisp.org>
* src/search.cc (Search::find_asso_values): Avoid gcc warnings about * src/search.cc (Search::find_asso_values): Avoid gcc warnings about

View File

@@ -35,7 +35,7 @@ Bool_Array::~Bool_Array ()
fprintf (stderr, "\ndumping boolean array information\n" fprintf (stderr, "\ndumping boolean array information\n"
"size = %d\niteration number = %d\nend of array dump\n", "size = %d\niteration number = %d\nend of array dump\n",
_size, _iteration_number); _size, _iteration_number);
delete[] _storage_array; delete[] const_cast<unsigned int *>(_storage_array);
} }
#ifndef __OPTIMIZE__ #ifndef __OPTIMIZE__

View File

@@ -90,10 +90,12 @@ Hash_Table::~Hash_Table ()
int field_width; int field_width;
field_width = 0; field_width = 0;
for (int i = _size - 1; i >= 0; i--) {
if (_table[i]) for (int i = _size - 1; i >= 0; i--)
if (field_width < _table[i]->_selchars_length) if (_table[i])
field_width = _table[i]->_selchars_length; if (field_width < _table[i]->_selchars_length)
field_width = _table[i]->_selchars_length;
}
fprintf (stderr, fprintf (stderr,
"\ndumping the hash table\n" "\ndumping the hash table\n"

View File

@@ -915,8 +915,8 @@ Input::read_input ()
Input::~Input () Input::~Input ()
{ {
/* Free allocated memory. */ /* Free allocated memory. */
delete[] _return_type; delete[] const_cast<char*>(_return_type);
delete[] _struct_tag; delete[] const_cast<char*>(_struct_tag);
delete[] _struct_decl; delete[] const_cast<char*>(_struct_decl);
delete[] _input; delete[] _input;
} }

View File

@@ -130,7 +130,7 @@ KeywordExt::init_selchars_multiset (bool use_all_chars, const Positions& positio
void void
KeywordExt::delete_selchars () KeywordExt::delete_selchars ()
{ {
delete[] _selchars; delete[] const_cast<unsigned int *>(_selchars);
} }

View File

@@ -134,12 +134,12 @@ main (int argc, char *argv[])
do do
{ {
KeywordExt *next_keyword = keyword->_duplicate_link; KeywordExt *next_keyword = keyword->_duplicate_link;
delete[] keyword->_selchars; delete[] const_cast<unsigned int *>(keyword->_selchars);
if (keyword->_rest != empty_string) if (keyword->_rest != empty_string)
delete[] keyword->_rest; delete[] const_cast<char*>(keyword->_rest);
if (!(keyword->_allchars >= inputter._input if (!(keyword->_allchars >= inputter._input
&& keyword->_allchars < inputter._input_end)) && keyword->_allchars < inputter._input_end))
delete[] keyword->_allchars; delete[] const_cast<char*>(keyword->_allchars);
delete keyword; delete keyword;
keyword = next_keyword; keyword = next_keyword;
} }

View File

@@ -33,11 +33,11 @@ class Positions
friend class PositionIterator; friend class PositionIterator;
public: public:
/* Denotes the last char of a keyword, depending on the keyword's length. */ /* Denotes the last char of a keyword, depending on the keyword's length. */
static const int LASTCHAR = 0; enum { LASTCHAR = 0 };
/* Maximum key position specifiable by the user. /* Maximum key position specifiable by the user.
Note that this must fit into the element type of _positions[], below. */ Note that this must fit into the element type of _positions[], below. */
static const int MAX_KEY_POS = 255; enum { MAX_KEY_POS = 255 };
/* Constructors. */ /* Constructors. */
Positions (); Positions ();
@@ -89,7 +89,7 @@ public:
PositionIterator (Positions const& positions); PositionIterator (Positions const& positions);
/* End of iteration marker. */ /* End of iteration marker. */
static const int EOS = -1; enum { EOS = -1 };
/* Retrieves the next position, or EOS past the end. */ /* Retrieves the next position, or EOS past the end. */
int next (); int next ();

View File

@@ -778,7 +778,7 @@ Search::prepare_asso_values ()
if (option[RANDOM] || option.get_jump () == 0) if (option[RANDOM] || option.get_jump () == 0)
/* We will use rand(), so initialize the random number generator. */ /* We will use rand(), so initialize the random number generator. */
srand (reinterpret_cast<long>(time (0))); srand (static_cast<long>(time (0)));
_initial_asso_value = (option[RANDOM] ? -1 : option.get_initial_asso_value ()); _initial_asso_value = (option[RANDOM] ? -1 : option.get_initial_asso_value ());
_jump = option.get_jump (); _jump = option.get_jump ();