summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-07-22 03:00:45 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-07-22 03:00:45 +0000
commit3af58a0a57aaea69a6cd622ef14c76e57a06fe84 (patch)
treed153b733c23a10c9666f680263bd3b48e29debb3
parent334b2c9f855ca8e4a36d34c6e600f5203ec017a5 (diff)
rehash
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@276 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--eval.c1
-rw-r--r--gc.c2
-rw-r--r--io.c2
-rw-r--r--sample/test.rb2
-rw-r--r--st.c95
6 files changed, 54 insertions, 54 deletions
diff --git a/ChangeLog b/ChangeLog
index e30ce0c03a..a523e664cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
+Wed Jul 22 11:59:59 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * st.c (rehash): still had a GC problem. fixed.
+
Tue Jul 21 13:19:30 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+ * eval.c (gc_mark_threads): crashed on GC before thread allocation.
+
* st.c (rehash): GC during rehash caused SEGV.
Tue Jul 21 01:25:10 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
diff --git a/eval.c b/eval.c
index 7c8264598a..c17c91bfa2 100644
--- a/eval.c
+++ b/eval.c
@@ -5474,6 +5474,7 @@ gc_mark_threads()
{
thread_t th;
+ if (!curr_thread) return;
FOREACH_THREAD(th) {
thread_mark(th);
} END_FOREACH(th);
diff --git a/gc.c b/gc.c
index 934b00ec80..2d6e5aeee6 100644
--- a/gc.c
+++ b/gc.c
@@ -255,7 +255,7 @@ rb_newobj()
alloc_objects++;
return obj;
}
- if (dont_gc) add_heap();
+ if (dont_gc || prohibit_interrupt) add_heap();
else gc_gc();
goto retry;
diff --git a/io.c b/io.c
index 16e539f2fb..a2be5a70ff 100644
--- a/io.c
+++ b/io.c
@@ -2598,8 +2598,6 @@ Init_IO()
rb_define_global_function("tell", f_tell, 0);
rb_define_global_function("seek", f_seek, 2);
rb_define_global_function("rewind", f_rewind, 0);
- rb_define_global_function("pos", f_tell, 0);
- rb_define_global_function("pos=", f_set_pos, 1);
rb_define_global_function("eof", f_eof, 0);
rb_define_global_function("eof?", f_eof, 0);
rb_define_global_function("getc", f_getc, 0);
diff --git a/sample/test.rb b/sample/test.rb
index 9bf6433b83..0adcb22307 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -920,8 +920,6 @@ end
check "marshal"
$x = [1,2,3,[4,5,"foo"],{1=>"bar"},2.5,fact(30)]
$y = Marshal.dump($x)
-p $x
-p Marshal.load($y)
ok($x == Marshal.load($y))
check "pack"
diff --git a/st.c b/st.c
index eefa8497d9..ada4fa1489 100644
--- a/st.c
+++ b/st.c
@@ -42,7 +42,6 @@ void *xrealloc();
static void rehash();
#define max(a,b) ((a) > (b) ? (a) : (b))
-#define nil(type) ((type*)0)
#define alloc(type) (type*)xmalloc((unsigned)sizeof(type))
#define Calloc(n,s) (char*)xcalloc((n),(s))
@@ -100,18 +99,18 @@ st_free_table(table)
for(i = 0; i < table->num_bins ; i++) {
ptr = table->bins[i];
- while (ptr != nil(st_table_entry)) {
+ while (ptr != 0) {
next = ptr->next;
- free((char*)ptr);
+ free(ptr);
ptr = next;
}
}
- free((char*)table->bins);
- free((char*)table);
+ free(table->bins);
+ free(table);
}
#define PTR_NOT_EQUAL(table, ptr, key) \
-(ptr != nil(st_table_entry) && !EQUAL(table, key, (ptr)->key))
+(ptr != 0 && !EQUAL(table, key, (ptr)->key))
#define FIND_ENTRY(table, ptr, hash_val) \
ptr = (table)->bins[hash_val];\
@@ -135,10 +134,10 @@ st_lookup(table, key, value)
FIND_ENTRY(table, ptr, hash_val);
- if (ptr == nil(st_table_entry)) {
+ if (ptr == 0) {
return 0;
} else {
- if (value != nil(char*)) *value = ptr->record;
+ if (value != 0) *value = ptr->record;
return 1;
}
}
@@ -173,7 +172,7 @@ st_insert(table, key, value)
FIND_ENTRY(table, ptr, hash_val);
- if (ptr == nil(st_table_entry)) {
+ if (ptr == 0) {
ADD_DIRECT(table,key,value,hash_val,tbl);
return 0;
} else {
@@ -208,12 +207,12 @@ st_find_or_add(table, key, slot)
FIND_ENTRY(table, ptr, hash_val);
- if (ptr == nil(st_table_entry)) {
+ if (ptr == 0) {
ADD_DIRECT(table, key, (char*)0, hash_val, tbl)
- if (slot != nil(char**)) *slot = &tbl->record;
+ if (slot != 0) *slot = &tbl->record;
return 0;
} else {
- if (slot != nil(char**)) *slot = &ptr->record;
+ if (slot != 0) *slot = &ptr->record;
return 1;
}
}
@@ -222,7 +221,7 @@ static void
rehash(table)
register st_table *table;
{
- register st_table_entry *ptr, *next, **old_bins = table->bins;
+ register st_table_entry *ptr, *next, **new_bins;
int i, old_num_bins = table->num_bins, new_num_bins, hash_val;
new_num_bins = 1.79*old_num_bins;
@@ -231,24 +230,22 @@ rehash(table)
new_num_bins += 1;
}
- table->num_bins = 0;
- table->num_entries = 0;
- table->bins = (st_table_entry **)
+ new_bins = (st_table_entry **)
Calloc((unsigned)new_num_bins, sizeof(st_table_entry*));
for(i = 0; i < old_num_bins ; i++) {
- ptr = old_bins[i];
- while (ptr != nil(st_table_entry)) {
+ ptr = table->bins[i];
+ while (ptr != 0) {
next = ptr->next;
hash_val = do_hash2(ptr->key, table, new_num_bins);
- ptr->next = table->bins[hash_val];
- table->bins[hash_val] = ptr;
- table->num_entries++;
+ ptr->next = new_bins[hash_val];
+ new_bins[hash_val] = ptr;
ptr = next;
}
}
+ free(table->bins);
table->num_bins = new_num_bins;
- free((char*)old_bins);
+ table->bins = new_bins;
}
st_table*
@@ -260,28 +257,28 @@ st_copy(old_table)
int i, num_bins = old_table->num_bins;
new_table = alloc(st_table);
- if (new_table == nil(st_table)) {
- return nil(st_table);
+ if (new_table == 0) {
+ return 0;
}
*new_table = *old_table;
new_table->bins = (st_table_entry**)
Calloc((unsigned)num_bins, sizeof(st_table_entry*));
- if (new_table->bins == nil(st_table_entry*)) {
- free((char*)new_table);
- return nil(st_table);
+ if (new_table->bins == 0) {
+ free(new_table);
+ return 0;
}
for(i = 0; i < num_bins ; i++) {
- new_table->bins[i] = nil(st_table_entry);
+ new_table->bins[i] = 0;
ptr = old_table->bins[i];
- while (ptr != nil(st_table_entry)) {
+ while (ptr != 0) {
tbl = alloc(st_table_entry);
- if (tbl == nil(st_table_entry)) {
- free((char*)new_table->bins);
- free((char*)new_table);
- return nil(st_table);
+ if (tbl == 0) {
+ free(new_table->bins);
+ free(new_table);
+ return 0;
}
*tbl = *ptr;
tbl->next = new_table->bins[i];
@@ -306,28 +303,28 @@ st_delete(table, key, value)
ptr = table->bins[hash_val];
- if (ptr == nil(st_table_entry)) {
- if (value != nil(char*)) *value = nil(char);
+ if (ptr == 0) {
+ if (value != 0) *value = 0;
return 0;
}
if (EQUAL(table, *key, ptr->key)) {
table->bins[hash_val] = ptr->next;
table->num_entries--;
- if (value != nil(char*)) *value = ptr->record;
+ if (value != 0) *value = ptr->record;
*key = ptr->key;
- free((char*)ptr);
+ free(ptr);
return 1;
}
- for(; ptr->next != nil(st_table_entry); ptr = ptr->next) {
+ for(; ptr->next != 0; ptr = ptr->next) {
if (EQUAL(table, ptr->next->key, *key)) {
tmp = ptr->next;
ptr->next = ptr->next->next;
table->num_entries--;
- if (value != nil(char*)) *value = tmp->record;
+ if (value != 0) *value = tmp->record;
*key = tmp->key;
- free((char*)tmp);
+ free(tmp);
return 1;
}
}
@@ -349,24 +346,24 @@ st_delete_safe(table, key, value, never)
ptr = table->bins[hash_val];
- if (ptr == nil(st_table_entry)) {
- if (value != nil(char*)) *value = nil(char);
+ if (ptr == 0) {
+ if (value != 0) *value = 0;
return 0;
}
if (EQUAL(table, *key, ptr->key)) {
table->num_entries--;
*key = ptr->key;
- if (value != nil(char*)) *value = ptr->record;
+ if (value != 0) *value = ptr->record;
ptr->key = ptr->record = never;
return 1;
}
- for(; ptr->next != nil(st_table_entry); ptr = ptr->next) {
+ for(; ptr->next != 0; ptr = ptr->next) {
if (EQUAL(table, ptr->next->key, *key)) {
table->num_entries--;
*key = ptr->key;
- if (value != nil(char*)) *value = ptr->record;
+ if (value != 0) *value = ptr->record;
ptr->key = ptr->record = never;
return 1;
}
@@ -386,8 +383,8 @@ st_foreach(table, func, arg)
int i;
for(i = 0; i < table->num_bins; i++) {
- last = nil(st_table_entry);
- for(ptr = table->bins[i]; ptr != nil(st_table_entry);) {
+ last = 0;
+ for(ptr = table->bins[i]; ptr != 0;) {
retval = (*func)(ptr->key, ptr->record, arg);
switch (retval) {
case ST_CONTINUE:
@@ -398,13 +395,13 @@ st_foreach(table, func, arg)
return;
case ST_DELETE:
tmp = ptr;
- if (last == nil(st_table_entry)) {
+ if (last == 0) {
table->bins[i] = ptr->next;
} else {
last->next = ptr->next;
}
ptr = ptr->next;
- free((char*)tmp);
+ free(tmp);
table->num_entries--;
}
}