summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-06 15:55:43 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-06 15:55:43 +0000
commit91b9d37a853d4b8629c2719328ba6473d8766959 (patch)
treeedede8c398b29110d806b1ecce1bcafa3dffb275 /st.c
parent8eba0580798736ee144793e24afdb31d4ddb1cb5 (diff)
* st.h, st.c: Introduce new conventional typedef's, st_data_t,
st_compare_func_t, st_hash_func_t and st_each_func_t. * st.h, st.c: Do explicit function declarations and do not rely on implicit declarations. On such platforms as IA64, int argument values are NOT automatically promoted to long (64bit) values, so explicit declarations are mandatory for those functions that take long values or pointers. This fixes miniruby's coredump on FreeBSD/IA64. * class.c, eval.c, gc.c, hash.c, marshal.c, parse.y, variable.c: Add proper casts to avoid warnings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c63
1 files changed, 32 insertions, 31 deletions
diff --git a/st.c b/st.c
index 85391cac80..d9e8be4970 100644
--- a/st.c
+++ b/st.c
@@ -5,6 +5,7 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "st.h"
#ifdef _WIN32
@@ -15,8 +16,8 @@ typedef struct st_table_entry st_table_entry;
struct st_table_entry {
unsigned int hash;
- char *key;
- char *record;
+ st_data_t key;
+ st_data_t record;
st_table_entry *next;
};
@@ -32,18 +33,18 @@ struct st_table_entry {
* allocated initially
*
*/
-static int numcmp();
-static int numhash();
+static int numcmp(long, long);
+static int numhash(long);
static struct st_hash_type type_numhash = {
numcmp,
numhash,
};
-extern int strcmp();
-static int strhash();
+/* extern int strcmp(const char *, const char *); */
+static int strhash(const char *);
static struct st_hash_type type_strhash = {
- strcmp,
- strhash,
+ (st_compare_func_t)strcmp,
+ (st_hash_func_t)strhash,
};
#ifdef RUBY_PLATFORM
@@ -52,13 +53,13 @@ static struct st_hash_type type_strhash = {
#define xrealloc ruby_xrealloc
#define xfree ruby_xfree
-void *xmalloc();
-void *xcalloc();
-void *xrealloc();
-void xfree();
+void *xmalloc(long);
+void *xcalloc(long, long);
+void *xrealloc(void *, long);
+void xfree(void *);
#endif
-static void rehash();
+static void rehash(st_table *);
#define alloc(type) (type*)xmalloc((unsigned)sizeof(type))
#define Calloc(n,s) (char*)xcalloc((n),(s))
@@ -180,7 +181,7 @@ st_init_table(type)
}
st_table*
-st_init_numtable()
+st_init_numtable(void)
{
return st_init_table(&type_numhash);
}
@@ -193,7 +194,7 @@ st_init_numtable_with_size(size)
}
st_table*
-st_init_strtable()
+st_init_strtable(void)
{
return st_init_table(&type_strhash);
}
@@ -248,8 +249,8 @@ st_free_table(table)
int
st_lookup(table, key, value)
st_table *table;
- register char *key;
- char **value;
+ register st_data_t key;
+ st_data_t *value;
{
unsigned int hash_val, bin_pos;
register st_table_entry *ptr;
@@ -287,8 +288,8 @@ do {\
int
st_insert(table, key, value)
register st_table *table;
- register char *key;
- char *value;
+ register st_data_t key;
+ st_data_t value;
{
unsigned int hash_val, bin_pos;
register st_table_entry *ptr;
@@ -309,8 +310,8 @@ st_insert(table, key, value)
void
st_add_direct(table, key, value)
st_table *table;
- char *key;
- char *value;
+ st_data_t key;
+ st_data_t value;
{
unsigned int hash_val, bin_pos;
@@ -389,8 +390,8 @@ st_copy(old_table)
int
st_delete(table, key, value)
register st_table *table;
- register char **key;
- char **value;
+ register st_data_t *key;
+ st_data_t *value;
{
unsigned int hash_val;
st_table_entry *tmp;
@@ -431,9 +432,9 @@ st_delete(table, key, value)
int
st_delete_safe(table, key, value, never)
register st_table *table;
- register char **key;
- char **value;
- char *never;
+ register st_data_t *key;
+ st_data_t *value;
+ st_data_t never;
{
unsigned int hash_val;
register st_table_entry *ptr;
@@ -461,7 +462,7 @@ st_delete_safe(table, key, value, never)
static int
delete_never(key, value, never)
- char *key, *value, *never;
+ st_data_t key, value, never;
{
if (value == never) return ST_DELETE;
return ST_CONTINUE;
@@ -470,7 +471,7 @@ delete_never(key, value, never)
void
st_cleanup_safe(table, never)
st_table *table;
- char *never;
+ st_data_t never;
{
int num_entries = table->num_entries;
@@ -481,8 +482,8 @@ st_cleanup_safe(table, never)
void
st_foreach(table, func, arg)
st_table *table;
- enum st_retval (*func)();
- char *arg;
+ st_each_func_t func;
+ st_data_t arg;
{
st_table_entry *ptr, *last, *tmp;
enum st_retval retval;
@@ -517,7 +518,7 @@ st_foreach(table, func, arg)
static int
strhash(string)
- register char *string;
+ register const char *string;
{
register int c;