* 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
This commit is contained in:
parent
8eba058079
commit
91b9d37a85
15
ChangeLog
15
ChangeLog
@ -1,3 +1,18 @@
|
|||||||
|
Mon Jan 6 23:36:29 2003 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Mon Jan 6 20:44:43 2003 Akinori MUSHA <knu@iDaemons.org>
|
Mon Jan 6 20:44:43 2003 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* intern.h (rb_check_array_type): Declare rb_check_array_type().
|
* intern.h (rb_check_array_type): Declare rb_check_array_type().
|
||||||
|
8
class.c
8
class.c
@ -54,7 +54,7 @@ clone_method(mid, body, tbl)
|
|||||||
NODE *body;
|
NODE *body;
|
||||||
st_table *tbl;
|
st_table *tbl;
|
||||||
{
|
{
|
||||||
st_insert(tbl, mid, NEW_METHOD(body->nd_body, body->nd_noex));
|
st_insert(tbl, mid, (st_data_t)NEW_METHOD(body->nd_body, body->nd_noex));
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,8 @@ rb_mod_clone(module)
|
|||||||
}
|
}
|
||||||
if (RCLASS(module)->m_tbl) {
|
if (RCLASS(module)->m_tbl) {
|
||||||
RCLASS(clone)->m_tbl = st_init_numtable();
|
RCLASS(clone)->m_tbl = st_init_numtable();
|
||||||
st_foreach(RCLASS(module)->m_tbl, clone_method, RCLASS(clone)->m_tbl);
|
st_foreach(RCLASS(module)->m_tbl, clone_method,
|
||||||
|
(st_data_t)RCLASS(clone)->m_tbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (VALUE)clone;
|
return (VALUE)clone;
|
||||||
@ -120,7 +121,8 @@ rb_singleton_class_clone(obj)
|
|||||||
clone->iv_tbl = st_copy(RCLASS(klass)->iv_tbl);
|
clone->iv_tbl = st_copy(RCLASS(klass)->iv_tbl);
|
||||||
}
|
}
|
||||||
clone->m_tbl = st_init_numtable();
|
clone->m_tbl = st_init_numtable();
|
||||||
st_foreach(RCLASS(klass)->m_tbl, clone_method, clone->m_tbl);
|
st_foreach(RCLASS(klass)->m_tbl, clone_method,
|
||||||
|
(st_data_t)clone->m_tbl);
|
||||||
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
|
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
|
||||||
FL_SET(clone, FL_SINGLETON);
|
FL_SET(clone, FL_SINGLETON);
|
||||||
return (VALUE)clone;
|
return (VALUE)clone;
|
||||||
|
17
eval.c
17
eval.c
@ -261,7 +261,7 @@ rb_add_method(klass, mid, node, noex)
|
|||||||
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
|
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
|
||||||
rb_clear_cache_by_id(mid);
|
rb_clear_cache_by_id(mid);
|
||||||
body = NEW_METHOD(node, noex);
|
body = NEW_METHOD(node, noex);
|
||||||
st_insert(RCLASS(klass)->m_tbl, mid, body);
|
st_insert(RCLASS(klass)->m_tbl, mid, (st_data_t)body);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -290,7 +290,7 @@ search_method(klass, id, origin)
|
|||||||
NODE *body;
|
NODE *body;
|
||||||
|
|
||||||
if (!klass) return 0;
|
if (!klass) return 0;
|
||||||
while (!st_lookup(RCLASS(klass)->m_tbl, id, &body)) {
|
while (!st_lookup(RCLASS(klass)->m_tbl, id, (st_data_t *)&body)) {
|
||||||
klass = RCLASS(klass)->super;
|
klass = RCLASS(klass)->super;
|
||||||
if (!klass) return 0;
|
if (!klass) return 0;
|
||||||
}
|
}
|
||||||
@ -363,7 +363,8 @@ remove_method(klass, mid)
|
|||||||
if (mid == __id__ || mid == __send__ || mid == init) {
|
if (mid == __id__ || mid == __send__ || mid == init) {
|
||||||
rb_warn("removing `%s' may cause serious problem", rb_id2name(mid));
|
rb_warn("removing `%s' may cause serious problem", rb_id2name(mid));
|
||||||
}
|
}
|
||||||
if (!st_delete(RCLASS(klass)->m_tbl, &mid, &body) || !body->nd_body) {
|
if (!st_delete(RCLASS(klass)->m_tbl, &mid, (st_data_t *)&body) ||
|
||||||
|
!body->nd_body) {
|
||||||
rb_name_error(mid, "method `%s' not defined in %s",
|
rb_name_error(mid, "method `%s' not defined in %s",
|
||||||
rb_id2name(mid), rb_class2name(klass));
|
rb_id2name(mid), rb_class2name(klass));
|
||||||
}
|
}
|
||||||
@ -1746,7 +1747,7 @@ rb_alias(klass, name, def)
|
|||||||
|
|
||||||
rb_clear_cache_by_id(name);
|
rb_clear_cache_by_id(name);
|
||||||
st_insert(RCLASS(klass)->m_tbl, name,
|
st_insert(RCLASS(klass)->m_tbl, name,
|
||||||
NEW_METHOD(NEW_FBODY(body, def, origin), orig->nd_noex));
|
(st_data_t)NEW_METHOD(NEW_FBODY(body, def, origin), orig->nd_noex));
|
||||||
if (singleton) {
|
if (singleton) {
|
||||||
rb_funcall(singleton, singleton_added, 1, ID2SYM(name));
|
rb_funcall(singleton, singleton_added, 1, ID2SYM(name));
|
||||||
}
|
}
|
||||||
@ -3249,7 +3250,7 @@ rb_eval(self, n)
|
|||||||
|
|
||||||
if (OBJ_FROZEN(recv)) rb_error_frozen("object");
|
if (OBJ_FROZEN(recv)) rb_error_frozen("object");
|
||||||
klass = rb_singleton_class(recv);
|
klass = rb_singleton_class(recv);
|
||||||
if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, &body)) {
|
if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, (st_data_t *)&body)) {
|
||||||
if (ruby_safe_level >= 4) {
|
if (ruby_safe_level >= 4) {
|
||||||
rb_raise(rb_eSecurityError, "redefining method prohibited");
|
rb_raise(rb_eSecurityError, "redefining method prohibited");
|
||||||
}
|
}
|
||||||
@ -5526,7 +5527,7 @@ rb_feature_p(feature, wait)
|
|||||||
if (ext && strcmp(ext, ".rb") == 0) {
|
if (ext && strcmp(ext, ".rb") == 0) {
|
||||||
rb_thread_t th;
|
rb_thread_t th;
|
||||||
|
|
||||||
while (st_lookup(loading_tbl, f, &th)) {
|
while (st_lookup(loading_tbl, (st_data_t)f, (st_data_t *)&th)) {
|
||||||
if (th == curr_thread) {
|
if (th == curr_thread) {
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
@ -5692,14 +5693,14 @@ rb_f_require(obj, fname)
|
|||||||
}
|
}
|
||||||
/* partial state */
|
/* partial state */
|
||||||
ftptr = ruby_strdup(RSTRING(feature)->ptr);
|
ftptr = ruby_strdup(RSTRING(feature)->ptr);
|
||||||
st_insert(loading_tbl, ftptr, curr_thread);
|
st_insert(loading_tbl, (st_data_t)ftptr, (st_data_t)curr_thread);
|
||||||
|
|
||||||
PUSH_TAG(PROT_NONE);
|
PUSH_TAG(PROT_NONE);
|
||||||
if ((state = EXEC_TAG()) == 0) {
|
if ((state = EXEC_TAG()) == 0) {
|
||||||
rb_load(fname, 0);
|
rb_load(fname, 0);
|
||||||
}
|
}
|
||||||
POP_TAG();
|
POP_TAG();
|
||||||
st_delete(loading_tbl, &ftptr, 0); /* loading done */
|
st_delete(loading_tbl, (st_data_t *)&ftptr, 0); /* loading done */
|
||||||
free(ftptr);
|
free(ftptr);
|
||||||
ruby_safe_level = safe;
|
ruby_safe_level = safe;
|
||||||
if (state) JUMP_TAG(state);
|
if (state) JUMP_TAG(state);
|
||||||
|
6
gc.c
6
gc.c
@ -428,12 +428,12 @@ rb_source_filename(f)
|
|||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
if (!st_lookup(source_filenames, f, &name)) {
|
if (!st_lookup(source_filenames, (st_data_t)f, (st_data_t *)&name)) {
|
||||||
long len = strlen(f) + 1;
|
long len = strlen(f) + 1;
|
||||||
char *ptr = name = ALLOC_N(char, len + 1);
|
char *ptr = name = ALLOC_N(char, len + 1);
|
||||||
*ptr++ = 0;
|
*ptr++ = 0;
|
||||||
MEMCPY(ptr, f, char, len);
|
MEMCPY(ptr, f, char, len);
|
||||||
st_add_direct(source_filenames, ptr, name);
|
st_add_direct(source_filenames, (st_data_t)ptr, (st_data_t)name);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
return name + 1;
|
return name + 1;
|
||||||
@ -448,7 +448,7 @@ mark_source_filename(f)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum st_retval
|
static int
|
||||||
sweep_source_filename(key, value)
|
sweep_source_filename(key, value)
|
||||||
char *key, *value;
|
char *key, *value;
|
||||||
{
|
{
|
||||||
|
12
hash.c
12
hash.c
@ -144,7 +144,7 @@ static VALUE
|
|||||||
rb_hash_foreach_call(arg)
|
rb_hash_foreach_call(arg)
|
||||||
struct rb_hash_foreach_arg *arg;
|
struct rb_hash_foreach_arg *arg;
|
||||||
{
|
{
|
||||||
st_foreach(RHASH(arg->hash)->tbl, rb_hash_foreach_iter, arg);
|
st_foreach(RHASH(arg->hash)->tbl, rb_hash_foreach_iter, (st_data_t)arg);
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ rb_hash_rehash(hash)
|
|||||||
|
|
||||||
rb_hash_modify(hash);
|
rb_hash_modify(hash);
|
||||||
tbl = st_init_table_with_size(&objhash, RHASH(hash)->tbl->num_entries);
|
tbl = st_init_table_with_size(&objhash, RHASH(hash)->tbl->num_entries);
|
||||||
st_foreach(RHASH(hash)->tbl, rb_hash_rehash_i, tbl);
|
st_foreach(RHASH(hash)->tbl, rb_hash_rehash_i, (st_data_t)tbl);
|
||||||
st_free_table(RHASH(hash)->tbl);
|
st_free_table(RHASH(hash)->tbl);
|
||||||
RHASH(hash)->tbl = tbl;
|
RHASH(hash)->tbl = tbl;
|
||||||
|
|
||||||
@ -377,7 +377,7 @@ rb_hash_index(hash, value)
|
|||||||
args[0] = value;
|
args[0] = value;
|
||||||
args[1] = Qnil;
|
args[1] = Qnil;
|
||||||
|
|
||||||
st_foreach(RHASH(hash)->tbl, index_i, args);
|
st_foreach(RHASH(hash)->tbl, index_i, (st_data_t)args);
|
||||||
|
|
||||||
return args[1];
|
return args[1];
|
||||||
}
|
}
|
||||||
@ -449,7 +449,7 @@ rb_hash_shift(hash)
|
|||||||
|
|
||||||
rb_hash_modify(hash);
|
rb_hash_modify(hash);
|
||||||
var.stop = 0;
|
var.stop = 0;
|
||||||
st_foreach(RHASH(hash)->tbl, shift_i, &var);
|
st_foreach(RHASH(hash)->tbl, shift_i, (st_data_t)&var);
|
||||||
|
|
||||||
if (var.stop) {
|
if (var.stop) {
|
||||||
return rb_assoc_new(var.key, var.val);
|
return rb_assoc_new(var.key, var.val);
|
||||||
@ -834,7 +834,7 @@ rb_hash_has_value(hash, val)
|
|||||||
|
|
||||||
data[0] = Qfalse;
|
data[0] = Qfalse;
|
||||||
data[1] = val;
|
data[1] = val;
|
||||||
st_foreach(RHASH(hash)->tbl, rb_hash_search_value, data);
|
st_foreach(RHASH(hash)->tbl, rb_hash_search_value, (st_data_t)data);
|
||||||
return data[0];
|
return data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,7 +878,7 @@ rb_hash_equal(hash1, hash2)
|
|||||||
|
|
||||||
data.tbl = RHASH(hash2)->tbl;
|
data.tbl = RHASH(hash2)->tbl;
|
||||||
data.result = Qtrue;
|
data.result = Qtrue;
|
||||||
st_foreach(RHASH(hash1)->tbl, equal_i, &data);
|
st_foreach(RHASH(hash1)->tbl, equal_i, (st_data_t)&data);
|
||||||
|
|
||||||
return data.result;
|
return data.result;
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ w_ivar(tbl, arg)
|
|||||||
{
|
{
|
||||||
if (tbl) {
|
if (tbl) {
|
||||||
w_long(tbl->num_entries, arg->arg);
|
w_long(tbl->num_entries, arg->arg);
|
||||||
st_foreach(tbl, obj_each, arg);
|
st_foreach(tbl, obj_each, (st_data_t)arg);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
w_long(0, arg->arg);
|
w_long(0, arg->arg);
|
||||||
@ -505,7 +505,7 @@ w_object(obj, arg, limit)
|
|||||||
w_byte(TYPE_HASH_DEF, arg);
|
w_byte(TYPE_HASH_DEF, arg);
|
||||||
}
|
}
|
||||||
w_long(RHASH(obj)->tbl->num_entries, arg);
|
w_long(RHASH(obj)->tbl->num_entries, arg);
|
||||||
st_foreach(RHASH(obj)->tbl, hash_each, &c_arg);
|
st_foreach(RHASH(obj)->tbl, hash_each, (st_data_t)&c_arg);
|
||||||
if (!NIL_P(RHASH(obj)->ifnone)) {
|
if (!NIL_P(RHASH(obj)->ifnone)) {
|
||||||
w_object(RHASH(obj)->ifnone, arg, limit);
|
w_object(RHASH(obj)->ifnone, arg, limit);
|
||||||
}
|
}
|
||||||
|
8
parse.y
8
parse.y
@ -5585,7 +5585,7 @@ rb_intern(name)
|
|||||||
ID id;
|
ID id;
|
||||||
int last;
|
int last;
|
||||||
|
|
||||||
if (st_lookup(sym_tbl, name, &id))
|
if (st_lookup(sym_tbl, (st_data_t)name, (st_data_t *)&id))
|
||||||
return id;
|
return id;
|
||||||
|
|
||||||
id = 0;
|
id = 0;
|
||||||
@ -5648,8 +5648,8 @@ rb_intern(name)
|
|||||||
id |= ++last_id << ID_SCOPE_SHIFT;
|
id |= ++last_id << ID_SCOPE_SHIFT;
|
||||||
id_regist:
|
id_regist:
|
||||||
name = strdup(name);
|
name = strdup(name);
|
||||||
st_add_direct(sym_tbl, name, id);
|
st_add_direct(sym_tbl, (st_data_t)name, id);
|
||||||
st_add_direct(sym_rev_tbl, id, name);
|
st_add_direct(sym_rev_tbl, id, (st_data_t)name);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5668,7 +5668,7 @@ rb_id2name(id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st_lookup(sym_rev_tbl, id, &name))
|
if (st_lookup(sym_rev_tbl, id, (st_data_t *)&name))
|
||||||
return name;
|
return name;
|
||||||
|
|
||||||
if (is_attrset_id(id)) {
|
if (is_attrset_id(id)) {
|
||||||
|
63
st.c
63
st.c
@ -5,6 +5,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "st.h"
|
#include "st.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -15,8 +16,8 @@ typedef struct st_table_entry st_table_entry;
|
|||||||
|
|
||||||
struct st_table_entry {
|
struct st_table_entry {
|
||||||
unsigned int hash;
|
unsigned int hash;
|
||||||
char *key;
|
st_data_t key;
|
||||||
char *record;
|
st_data_t record;
|
||||||
st_table_entry *next;
|
st_table_entry *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -32,18 +33,18 @@ struct st_table_entry {
|
|||||||
* allocated initially
|
* allocated initially
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int numcmp();
|
static int numcmp(long, long);
|
||||||
static int numhash();
|
static int numhash(long);
|
||||||
static struct st_hash_type type_numhash = {
|
static struct st_hash_type type_numhash = {
|
||||||
numcmp,
|
numcmp,
|
||||||
numhash,
|
numhash,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int strcmp();
|
/* extern int strcmp(const char *, const char *); */
|
||||||
static int strhash();
|
static int strhash(const char *);
|
||||||
static struct st_hash_type type_strhash = {
|
static struct st_hash_type type_strhash = {
|
||||||
strcmp,
|
(st_compare_func_t)strcmp,
|
||||||
strhash,
|
(st_hash_func_t)strhash,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef RUBY_PLATFORM
|
#ifdef RUBY_PLATFORM
|
||||||
@ -52,13 +53,13 @@ static struct st_hash_type type_strhash = {
|
|||||||
#define xrealloc ruby_xrealloc
|
#define xrealloc ruby_xrealloc
|
||||||
#define xfree ruby_xfree
|
#define xfree ruby_xfree
|
||||||
|
|
||||||
void *xmalloc();
|
void *xmalloc(long);
|
||||||
void *xcalloc();
|
void *xcalloc(long, long);
|
||||||
void *xrealloc();
|
void *xrealloc(void *, long);
|
||||||
void xfree();
|
void xfree(void *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void rehash();
|
static void rehash(st_table *);
|
||||||
|
|
||||||
#define alloc(type) (type*)xmalloc((unsigned)sizeof(type))
|
#define alloc(type) (type*)xmalloc((unsigned)sizeof(type))
|
||||||
#define Calloc(n,s) (char*)xcalloc((n),(s))
|
#define Calloc(n,s) (char*)xcalloc((n),(s))
|
||||||
@ -180,7 +181,7 @@ st_init_table(type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
st_table*
|
st_table*
|
||||||
st_init_numtable()
|
st_init_numtable(void)
|
||||||
{
|
{
|
||||||
return st_init_table(&type_numhash);
|
return st_init_table(&type_numhash);
|
||||||
}
|
}
|
||||||
@ -193,7 +194,7 @@ st_init_numtable_with_size(size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
st_table*
|
st_table*
|
||||||
st_init_strtable()
|
st_init_strtable(void)
|
||||||
{
|
{
|
||||||
return st_init_table(&type_strhash);
|
return st_init_table(&type_strhash);
|
||||||
}
|
}
|
||||||
@ -248,8 +249,8 @@ st_free_table(table)
|
|||||||
int
|
int
|
||||||
st_lookup(table, key, value)
|
st_lookup(table, key, value)
|
||||||
st_table *table;
|
st_table *table;
|
||||||
register char *key;
|
register st_data_t key;
|
||||||
char **value;
|
st_data_t *value;
|
||||||
{
|
{
|
||||||
unsigned int hash_val, bin_pos;
|
unsigned int hash_val, bin_pos;
|
||||||
register st_table_entry *ptr;
|
register st_table_entry *ptr;
|
||||||
@ -287,8 +288,8 @@ do {\
|
|||||||
int
|
int
|
||||||
st_insert(table, key, value)
|
st_insert(table, key, value)
|
||||||
register st_table *table;
|
register st_table *table;
|
||||||
register char *key;
|
register st_data_t key;
|
||||||
char *value;
|
st_data_t value;
|
||||||
{
|
{
|
||||||
unsigned int hash_val, bin_pos;
|
unsigned int hash_val, bin_pos;
|
||||||
register st_table_entry *ptr;
|
register st_table_entry *ptr;
|
||||||
@ -309,8 +310,8 @@ st_insert(table, key, value)
|
|||||||
void
|
void
|
||||||
st_add_direct(table, key, value)
|
st_add_direct(table, key, value)
|
||||||
st_table *table;
|
st_table *table;
|
||||||
char *key;
|
st_data_t key;
|
||||||
char *value;
|
st_data_t value;
|
||||||
{
|
{
|
||||||
unsigned int hash_val, bin_pos;
|
unsigned int hash_val, bin_pos;
|
||||||
|
|
||||||
@ -389,8 +390,8 @@ st_copy(old_table)
|
|||||||
int
|
int
|
||||||
st_delete(table, key, value)
|
st_delete(table, key, value)
|
||||||
register st_table *table;
|
register st_table *table;
|
||||||
register char **key;
|
register st_data_t *key;
|
||||||
char **value;
|
st_data_t *value;
|
||||||
{
|
{
|
||||||
unsigned int hash_val;
|
unsigned int hash_val;
|
||||||
st_table_entry *tmp;
|
st_table_entry *tmp;
|
||||||
@ -431,9 +432,9 @@ st_delete(table, key, value)
|
|||||||
int
|
int
|
||||||
st_delete_safe(table, key, value, never)
|
st_delete_safe(table, key, value, never)
|
||||||
register st_table *table;
|
register st_table *table;
|
||||||
register char **key;
|
register st_data_t *key;
|
||||||
char **value;
|
st_data_t *value;
|
||||||
char *never;
|
st_data_t never;
|
||||||
{
|
{
|
||||||
unsigned int hash_val;
|
unsigned int hash_val;
|
||||||
register st_table_entry *ptr;
|
register st_table_entry *ptr;
|
||||||
@ -461,7 +462,7 @@ st_delete_safe(table, key, value, never)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
delete_never(key, value, never)
|
delete_never(key, value, never)
|
||||||
char *key, *value, *never;
|
st_data_t key, value, never;
|
||||||
{
|
{
|
||||||
if (value == never) return ST_DELETE;
|
if (value == never) return ST_DELETE;
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
@ -470,7 +471,7 @@ delete_never(key, value, never)
|
|||||||
void
|
void
|
||||||
st_cleanup_safe(table, never)
|
st_cleanup_safe(table, never)
|
||||||
st_table *table;
|
st_table *table;
|
||||||
char *never;
|
st_data_t never;
|
||||||
{
|
{
|
||||||
int num_entries = table->num_entries;
|
int num_entries = table->num_entries;
|
||||||
|
|
||||||
@ -481,8 +482,8 @@ st_cleanup_safe(table, never)
|
|||||||
void
|
void
|
||||||
st_foreach(table, func, arg)
|
st_foreach(table, func, arg)
|
||||||
st_table *table;
|
st_table *table;
|
||||||
enum st_retval (*func)();
|
st_each_func_t func;
|
||||||
char *arg;
|
st_data_t arg;
|
||||||
{
|
{
|
||||||
st_table_entry *ptr, *last, *tmp;
|
st_table_entry *ptr, *last, *tmp;
|
||||||
enum st_retval retval;
|
enum st_retval retval;
|
||||||
@ -517,7 +518,7 @@ st_foreach(table, func, arg)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
strhash(string)
|
strhash(string)
|
||||||
register char *string;
|
register const char *string;
|
||||||
{
|
{
|
||||||
register int c;
|
register int c;
|
||||||
|
|
||||||
|
41
st.h
41
st.h
@ -6,11 +6,17 @@
|
|||||||
|
|
||||||
#define ST_INCLUDED
|
#define ST_INCLUDED
|
||||||
|
|
||||||
|
typedef long st_data_t;
|
||||||
|
|
||||||
|
typedef int (*st_compare_func_t)(st_data_t data1, st_data_t data2);
|
||||||
|
typedef int (*st_hash_func_t)(st_data_t data);
|
||||||
|
typedef int (*st_each_func_t)(st_data_t key, st_data_t value, st_data_t data);
|
||||||
|
|
||||||
typedef struct st_table st_table;
|
typedef struct st_table st_table;
|
||||||
|
|
||||||
struct st_hash_type {
|
struct st_hash_type {
|
||||||
int (*compare)();
|
st_compare_func_t compare;
|
||||||
int (*hash)();
|
st_hash_func_t hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct st_table {
|
struct st_table {
|
||||||
@ -20,23 +26,28 @@ struct st_table {
|
|||||||
struct st_table_entry **bins;
|
struct st_table_entry **bins;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define st_is_member(table,key) st_lookup(table,key,(char **)0)
|
#define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0)
|
||||||
|
|
||||||
enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE};
|
enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE};
|
||||||
|
|
||||||
st_table *st_init_table();
|
st_table *st_init_table(struct st_hash_type *);
|
||||||
st_table *st_init_table_with_size();
|
st_table *st_init_table_with_size(struct st_hash_type *, int);
|
||||||
st_table *st_init_numtable();
|
st_table *st_init_numtable(void);
|
||||||
st_table *st_init_numtable_with_size();
|
st_table *st_init_numtable_with_size(int);
|
||||||
st_table *st_init_strtable();
|
st_table *st_init_strtable(void);
|
||||||
st_table *st_init_strtable_with_size();
|
st_table *st_init_strtable_with_size(int);
|
||||||
int st_delete(), st_delete_safe();
|
int st_delete(st_table *, st_data_t *, st_data_t *);
|
||||||
int st_insert(), st_lookup();
|
int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t);
|
||||||
void st_foreach(), st_add_direct(), st_free_table(), st_cleanup_safe();
|
int st_insert(st_table *, st_data_t, st_data_t);
|
||||||
st_table *st_copy();
|
int st_lookup(st_table *, st_data_t, st_data_t *);
|
||||||
|
void st_foreach(st_table *, st_each_func_t, st_data_t);
|
||||||
|
void st_add_direct(st_table *, st_data_t, st_data_t);
|
||||||
|
void st_free_table(st_table *);
|
||||||
|
void st_cleanup_safe(st_table *, st_data_t);
|
||||||
|
st_table *st_copy(st_table *);
|
||||||
|
|
||||||
#define ST_NUMCMP ((int (*)()) 0)
|
#define ST_NUMCMP ((st_compare_func_t) 0)
|
||||||
#define ST_NUMHASH ((int (*)()) -2)
|
#define ST_NUMHASH ((st_hash_func_t) -2)
|
||||||
|
|
||||||
#define st_numcmp ST_NUMCMP
|
#define st_numcmp ST_NUMCMP
|
||||||
#define st_numhash ST_NUMHASH
|
#define st_numhash ST_NUMHASH
|
||||||
|
56
variable.c
56
variable.c
@ -94,7 +94,7 @@ fc_i(key, value, res)
|
|||||||
arg.klass = res->klass;
|
arg.klass = res->klass;
|
||||||
arg.track = value;
|
arg.track = value;
|
||||||
arg.prev = res;
|
arg.prev = res;
|
||||||
st_foreach(RCLASS(value)->iv_tbl, fc_i, &arg);
|
st_foreach(RCLASS(value)->iv_tbl, fc_i, (st_data_t)&arg);
|
||||||
if (arg.path) {
|
if (arg.path) {
|
||||||
res->path = arg.path;
|
res->path = arg.path;
|
||||||
return ST_STOP;
|
return ST_STOP;
|
||||||
@ -121,10 +121,10 @@ find_class_path(klass)
|
|||||||
arg.track = rb_cObject;
|
arg.track = rb_cObject;
|
||||||
arg.prev = 0;
|
arg.prev = 0;
|
||||||
if (RCLASS(rb_cObject)->iv_tbl) {
|
if (RCLASS(rb_cObject)->iv_tbl) {
|
||||||
st_foreach(RCLASS(rb_cObject)->iv_tbl, fc_i, &arg);
|
st_foreach(RCLASS(rb_cObject)->iv_tbl, fc_i, (st_data_t)&arg);
|
||||||
}
|
}
|
||||||
if (arg.path == 0) {
|
if (arg.path == 0) {
|
||||||
st_foreach(rb_class_tbl, fc_i, &arg);
|
st_foreach(rb_class_tbl, fc_i, (st_data_t)&arg);
|
||||||
}
|
}
|
||||||
if (arg.path) {
|
if (arg.path) {
|
||||||
if (!ROBJECT(klass)->iv_tbl) {
|
if (!ROBJECT(klass)->iv_tbl) {
|
||||||
@ -286,7 +286,7 @@ rb_autoload_id(id, filename)
|
|||||||
if (!autoload_tbl) {
|
if (!autoload_tbl) {
|
||||||
autoload_tbl = st_init_numtable();
|
autoload_tbl = st_init_numtable();
|
||||||
}
|
}
|
||||||
st_insert(autoload_tbl, id, strdup(filename));
|
st_insert(autoload_tbl, id, (st_data_t)strdup(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -351,7 +351,7 @@ rb_global_entry(id)
|
|||||||
{
|
{
|
||||||
struct global_entry *entry;
|
struct global_entry *entry;
|
||||||
|
|
||||||
if (!st_lookup(rb_global_tbl, id, &entry)) {
|
if (!st_lookup(rb_global_tbl, id, (st_data_t *)&entry)) {
|
||||||
struct global_variable *var;
|
struct global_variable *var;
|
||||||
entry = ALLOC(struct global_entry);
|
entry = ALLOC(struct global_entry);
|
||||||
var = ALLOC(struct global_variable);
|
var = ALLOC(struct global_variable);
|
||||||
@ -365,7 +365,7 @@ rb_global_entry(id)
|
|||||||
|
|
||||||
var->block_trace = 0;
|
var->block_trace = 0;
|
||||||
var->trace = 0;
|
var->trace = 0;
|
||||||
st_add_direct(rb_global_tbl, id, entry);
|
st_add_direct(rb_global_tbl, id, (st_data_t)entry);
|
||||||
}
|
}
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
@ -612,7 +612,7 @@ rb_f_untrace_var(argc, argv)
|
|||||||
|
|
||||||
rb_scan_args(argc, argv, "11", &var, &cmd);
|
rb_scan_args(argc, argv, "11", &var, &cmd);
|
||||||
id = rb_to_id(var);
|
id = rb_to_id(var);
|
||||||
if (!st_lookup(rb_global_tbl, id, &entry)) {
|
if (!st_lookup(rb_global_tbl, id, (st_data_t *)&entry)) {
|
||||||
rb_name_error(id, "undefined global variable %s", rb_id2name(id));
|
rb_name_error(id, "undefined global variable %s", rb_id2name(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -766,10 +766,10 @@ rb_alias_variable(name1, name2)
|
|||||||
rb_raise(rb_eSecurityError, "Insecure: can't alias global variable");
|
rb_raise(rb_eSecurityError, "Insecure: can't alias global variable");
|
||||||
|
|
||||||
entry2 = rb_global_entry(name2);
|
entry2 = rb_global_entry(name2);
|
||||||
if (!st_lookup(rb_global_tbl, name1, &entry1)) {
|
if (!st_lookup(rb_global_tbl, name1, (st_data_t *)&entry1)) {
|
||||||
entry1 = ALLOC(struct global_entry);
|
entry1 = ALLOC(struct global_entry);
|
||||||
entry1->id = name1;
|
entry1->id = name1;
|
||||||
st_add_direct(rb_global_tbl, name1, entry1);
|
st_add_direct(rb_global_tbl, name1, (st_data_t)entry1);
|
||||||
}
|
}
|
||||||
else if (entry1->var != entry2->var) {
|
else if (entry1->var != entry2->var) {
|
||||||
struct global_variable *var = entry1->var;
|
struct global_variable *var = entry1->var;
|
||||||
@ -804,7 +804,7 @@ rb_generic_ivar_table(obj)
|
|||||||
st_table *tbl;
|
st_table *tbl;
|
||||||
|
|
||||||
if (!generic_iv_tbl) return 0;
|
if (!generic_iv_tbl) return 0;
|
||||||
if (!st_lookup(generic_iv_tbl, obj, &tbl)) return 0;
|
if (!st_lookup(generic_iv_tbl, obj, (st_data_t *)&tbl)) return 0;
|
||||||
return tbl;
|
return tbl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -817,7 +817,7 @@ generic_ivar_get(obj, id)
|
|||||||
VALUE val;
|
VALUE val;
|
||||||
|
|
||||||
if (generic_iv_tbl) {
|
if (generic_iv_tbl) {
|
||||||
if (st_lookup(generic_iv_tbl, obj, &tbl)) {
|
if (st_lookup(generic_iv_tbl, obj, (st_data_t *)&tbl)) {
|
||||||
if (st_lookup(tbl, id, &val)) {
|
if (st_lookup(tbl, id, &val)) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -843,10 +843,10 @@ generic_ivar_set(obj, id, val)
|
|||||||
generic_iv_tbl = st_init_numtable();
|
generic_iv_tbl = st_init_numtable();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!st_lookup(generic_iv_tbl, obj, &tbl)) {
|
if (!st_lookup(generic_iv_tbl, obj, (st_data_t *)&tbl)) {
|
||||||
FL_SET(obj, FL_EXIVAR);
|
FL_SET(obj, FL_EXIVAR);
|
||||||
tbl = st_init_numtable();
|
tbl = st_init_numtable();
|
||||||
st_add_direct(generic_iv_tbl, obj, tbl);
|
st_add_direct(generic_iv_tbl, obj, (st_data_t)tbl);
|
||||||
st_add_direct(tbl, id, val);
|
st_add_direct(tbl, id, val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -862,7 +862,7 @@ generic_ivar_defined(obj, id)
|
|||||||
VALUE val;
|
VALUE val;
|
||||||
|
|
||||||
if (!generic_iv_tbl) return Qfalse;
|
if (!generic_iv_tbl) return Qfalse;
|
||||||
if (!st_lookup(generic_iv_tbl, obj, &tbl)) return Qfalse;
|
if (!st_lookup(generic_iv_tbl, obj, (st_data_t *)&tbl)) return Qfalse;
|
||||||
if (st_lookup(tbl, id, &val)) {
|
if (st_lookup(tbl, id, &val)) {
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
@ -879,10 +879,10 @@ generic_ivar_remove(obj, id, valp)
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (!generic_iv_tbl) return 0;
|
if (!generic_iv_tbl) return 0;
|
||||||
if (!st_lookup(generic_iv_tbl, obj, &tbl)) return 0;
|
if (!st_lookup(generic_iv_tbl, obj, (st_data_t *)&tbl)) return 0;
|
||||||
status = st_delete(tbl, &id, valp);
|
status = st_delete(tbl, &id, valp);
|
||||||
if (tbl->num_entries == 0) {
|
if (tbl->num_entries == 0) {
|
||||||
st_delete(generic_iv_tbl, &obj, &tbl);
|
st_delete(generic_iv_tbl, &obj, (st_data_t *)&tbl);
|
||||||
st_free_table(tbl);
|
st_free_table(tbl);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
@ -895,7 +895,7 @@ rb_mark_generic_ivar(obj)
|
|||||||
st_table *tbl;
|
st_table *tbl;
|
||||||
|
|
||||||
if (!generic_iv_tbl) return;
|
if (!generic_iv_tbl) return;
|
||||||
if (st_lookup(generic_iv_tbl, obj, &tbl)) {
|
if (st_lookup(generic_iv_tbl, obj, (st_data_t *)&tbl)) {
|
||||||
rb_mark_tbl(tbl);
|
rb_mark_tbl(tbl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -934,7 +934,7 @@ rb_free_generic_ivar(obj)
|
|||||||
{
|
{
|
||||||
st_table *tbl;
|
st_table *tbl;
|
||||||
|
|
||||||
if (st_delete(generic_iv_tbl, &obj, &tbl))
|
if (st_delete(generic_iv_tbl, &obj, (st_data_t *)&tbl))
|
||||||
st_free_table(tbl);
|
st_free_table(tbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -945,15 +945,15 @@ rb_copy_generic_ivar(clone, obj)
|
|||||||
st_table *tbl;
|
st_table *tbl;
|
||||||
|
|
||||||
if (!generic_iv_tbl) return;
|
if (!generic_iv_tbl) return;
|
||||||
if (st_lookup(generic_iv_tbl, obj, &tbl)) {
|
if (st_lookup(generic_iv_tbl, obj, (st_data_t *)&tbl)) {
|
||||||
st_table *old;
|
st_table *old;
|
||||||
|
|
||||||
if (st_lookup(generic_iv_tbl, clone, &old)) {
|
if (st_lookup(generic_iv_tbl, clone, (st_data_t *)&old)) {
|
||||||
st_free_table(old);
|
st_free_table(old);
|
||||||
st_insert(generic_iv_tbl, clone, st_copy(tbl));
|
st_insert(generic_iv_tbl, clone, (st_data_t)st_copy(tbl));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
st_add_direct(generic_iv_tbl, clone, st_copy(tbl));
|
st_add_direct(generic_iv_tbl, clone, (st_data_t)st_copy(tbl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1057,7 +1057,7 @@ rb_obj_instance_variables(obj)
|
|||||||
if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj)) {
|
if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj)) {
|
||||||
st_table *tbl;
|
st_table *tbl;
|
||||||
|
|
||||||
if (st_lookup(generic_iv_tbl, obj, &tbl)) {
|
if (st_lookup(generic_iv_tbl, obj, (st_data_t *)&tbl)) {
|
||||||
st_foreach(tbl, ivar_i, ary);
|
st_foreach(tbl, ivar_i, ary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1143,7 +1143,7 @@ rb_autoload_load(id)
|
|||||||
char *modname;
|
char *modname;
|
||||||
VALUE module;
|
VALUE module;
|
||||||
|
|
||||||
st_delete(autoload_tbl, &id, &modname);
|
st_delete(autoload_tbl, &id, (st_data_t *)&modname);
|
||||||
if (rb_provided(modname)) {
|
if (rb_provided(modname)) {
|
||||||
free(modname);
|
free(modname);
|
||||||
return;
|
return;
|
||||||
@ -1251,12 +1251,12 @@ rb_mod_const_at(mod, data)
|
|||||||
tbl = st_init_numtable();
|
tbl = st_init_numtable();
|
||||||
}
|
}
|
||||||
if (RCLASS(mod)->iv_tbl) {
|
if (RCLASS(mod)->iv_tbl) {
|
||||||
st_foreach(RCLASS(mod)->iv_tbl, sv_i, tbl);
|
st_foreach(RCLASS(mod)->iv_tbl, sv_i, (st_data_t)tbl);
|
||||||
}
|
}
|
||||||
if ((VALUE)mod == rb_cObject) {
|
if ((VALUE)mod == rb_cObject) {
|
||||||
st_foreach(rb_class_tbl, sv_i, tbl);
|
st_foreach(rb_class_tbl, sv_i, (st_data_t)tbl);
|
||||||
if (autoload_tbl) {
|
if (autoload_tbl) {
|
||||||
st_foreach(autoload_tbl, autoload_i, tbl);
|
st_foreach(autoload_tbl, autoload_i, (st_data_t)tbl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tbl;
|
return tbl;
|
||||||
@ -1410,7 +1410,7 @@ rb_const_assign(klass, id, val)
|
|||||||
if (autoload_tbl && st_lookup(autoload_tbl, id, 0)) {
|
if (autoload_tbl && st_lookup(autoload_tbl, id, 0)) {
|
||||||
char *modname;
|
char *modname;
|
||||||
|
|
||||||
st_delete(autoload_tbl, &id, &modname);
|
st_delete(autoload_tbl, (st_data_t *)&id, (st_data_t *)&modname);
|
||||||
free(modname);
|
free(modname);
|
||||||
st_insert(RCLASS(rb_cObject)->iv_tbl, id, val);
|
st_insert(RCLASS(rb_cObject)->iv_tbl, id, val);
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user