8000 rehash · jruby/ruby@3af58a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3af58a0

Browse files
author
matz
committed
rehash
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@276 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 334b2c9 commit 3af58a0

File tree

6 files changed

+54
-54
lines changed

6 files changed

+54
-54
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
Wed Jul 22 11:59:59 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
2+
3+
* st.c (rehash): still had a GC problem. fixed.
4+
15
Tue Jul 21 13:19:30 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
26

7+
* eval.c (gc_mark_threads): crashed on GC before thread allocation.
8+
39
* st.c (rehash): GC during rehash caused SEGV.
410

511
Tue Jul 21 01:25:10 1998 Yukihiro Matsumoto <matz@netlab.co.jp>

eval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5474,6 +5474,7 @@ gc_mark_threads()
54745474
{
54755475
thread_t th;
54765476

5477+
if (!curr_thread) return;
54775478
FOREACH_THREAD(th) {
54785479
thread_mark(th);
54795480
} END_FOREACH(th);

gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ rb_newobj()
255255
alloc_objects++;
256256
return obj;
257257
}
258-
if (dont_gc) add_heap();
258+
if (dont_gc || prohib 8000 it_interrupt) add_heap();
259259
else gc_gc();
260260

261261
goto retry;

io.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,8 +2598,6 @@ Init_IO()
25982598
rb_define_global_function("tell", f_tell, 0);
25992599
rb_define_global_function("seek", f_seek, 2);
26002600
rb_define_global_function("rewind", f_rewind, 0);
2601-
rb_define_global_function("pos", f_tell, 0);
2602-
rb_define_global_function("pos=", f_set_pos, 1);
26032601
rb_define_global_function("eof", f_eof, 0);
26042602
rb_define_global_function("eof?", f_eof, 0);
26052603
rb_define_global_function("getc", f_getc, 0);

sample/test.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,6 @@ def bar.test2
920920
check "marshal"
921921
$x = [1,2,3,[4,5,"foo"],{1=>"bar"},2.5,fact(30)]
922922
$y = Marshal.dump($x)
923-
p $x
924-
p Marshal.load($y)
925923
ok($x == Marshal.load($y))
926924

927925
check "pack"

st.c

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ void *xrealloc();
4242
static void rehash();
4343

4444
#define max(a,b) ((a) > (b) ? (a) : (b))
45-
#define nil(type) ((type*)0)
4645
#define alloc(type) (type*)xmalloc((unsigned)sizeof(type))
4746
#define Calloc(n,s) (char*)xcalloc((n),(s))
4847

@@ -100,18 +99,18 @@ st_free_table(table)
10099

101100
for(i = 0; i < table->num_bins ; i++) {
102101
ptr = table->bins[i];
103-
while (ptr != nil(st_table_entry)) {
102+
while (ptr != 0) {
104103
next = ptr->next;
105-
free((char*)ptr);
104+
free(ptr);
106105
ptr = next;
107106
}
108107
}
109-
free((char*)table->bins);
110-
free((char*)table);
108+
free(table->bins);
109+
free(table);
111110
}
112111

113112
#define PTR_NOT_EQUAL(table, ptr, key) \
114-
(ptr != nil(st_table_entry) && !EQUAL(table, key, (ptr)->key))
113+
(ptr != 0 && !EQUAL(table, key, (ptr)->key))
115114

116115
#define FIND_ENTRY(table, ptr, hash_val) \
117116
ptr = (table)->bins[hash_val];\
@@ -135,10 +134,10 @@ st_lookup(table, key, value)
135134

136135
FIND_ENTRY(table, ptr, hash_val);
137136

138-
if (ptr == nil(st_table_entry)) {
137+
if (ptr == 0) {
139138
return 0;
140139
} else {
141-
if (value != nil(char*)) *value = ptr->record;
140+
if (value != 0) *value = ptr->record;
142141
return 1;
143142
}
144143
}
@@ -173,7 +172,7 @@ st_insert(table, key, value)
173172

174173
FIND_ENTRY(table, ptr, hash_val);
175174

176-
if (ptr == nil(st_table_entry)) {
175+
if (ptr == 0) {
177176
ADD_DIRECT(table,key,value,hash_val,tbl);
178177
return 0;
179178
} else {
@@ -208,12 +207,12 @@ st_find_or_add(table, key, slot)
208207

209208
FIND_ENTRY(table, ptr, hash_val);
210209

211-
if (ptr == nil(st_table_entry)) {
210+
if (ptr == 0) {
212211
ADD_DIRECT(table, key, (char*)0, hash_val, tbl)
213-
if (slot != nil(char**)) *slot = &tbl->record;
212+
if (slot != 0) *slot = &tbl->record;
214213
return 0;
215214
} else {
216-
if (slot != nil(char**)) *slot = &ptr->record;
215+
if (slot != 0) *slot = &ptr->record;
217216
return 1;
218217
}
219218
}
@@ -222,7 +221,7 @@ static void
222221
rehash(table)
223222
register st_table *table;
224223
{
225-
register st_table_entry *ptr, *next, **old_bins = table->bins;
224+
register st_table_entry *ptr, *next, **new_bins;
226225
int i, old_num_bins = table->num_bins, new_num_bins, hash_val;
227226

228227
new_num_bins = 1.79*old_num_bins;
@@ -231,24 +230,22 @@ rehash(table)
231230
new_num_bins += 1;
232231
}
233232

234-
table->num_bins = 0;
235-
table->num_entries = 0;
236-
table->bins = (st_table_entry **)
233+
new_bins = (st_table_entry **)
237234
Calloc((unsigned)new_num_bins, sizeof(st_table_entry*));
238235

239236
for(i = 0; i < old_num_bins ; i++) {
240-
ptr = old_bins[i];
241-
while (ptr != nil(st_table_entry)) {
237+
ptr = table->bins[i];
238+
while (ptr != 0) {
242239
next = ptr->next;
243240
hash_val = do_hash2(ptr->key, table, new_num_bins);
244-
ptr->next = table->bins[hash_val];
245-
table->bins[hash_val] = ptr;
246-
table->num_entries++;
241+
ptr->next = new_bins[hash_val];
242+
new_bins[hash_val] = ptr;
247243
ptr = next;
248244
}
249245
}
246+
free(table->bins);
250247
table->num_bins = new_num_bins;
251-
free((char*)old_bins);
248+
table->bins = new_bins;
252249
}
253250

254251
st_table*
@@ -260,28 +257,28 @@ st_copy(old_table)
260257
int i, num_bins = old_table->num_bins;
261258

262259
new_table = alloc(st_table);
263-
if (new_table == nil(st_table)) {
264-
return nil(st_table);
260+
if (new_table == 0) {
261+
return 0;
265262
}
266263

267264
*new_table = *old_table;
268265
new_table->bins = (st_table_entry**)
269266
Calloc((unsigned)num_bins, sizeof(st_table_entry*));
270267

271-
if (new_table->bins == nil(st_table_entry*)) {
272-
free((char*)new_table);
273-
return nil(st_table);
268+
if (new_table->bins == 0) {
269+
free(new_table);
270+
return 0;
274271
}
275272

276273
for(i = 0; i < num_bins ; i++) {
277-
new_table->bins[i] = nil(st_table_entry);
274+
new_table->bins[i] = 0;
278275
ptr = old_table->bins[i];
279-
while (ptr != nil(st_table_entry)) {
276+
while (ptr != 0) {
280277
tbl = alloc(st_table_entry);
281-
if (tbl == nil(st_table_entry)) {
282-
free((char*)new_table->bins);
283-
free((char*)new_table);
284-
return nil(st_table);
278+
if (tbl == 0) {
279+
free(new_table->bins);
280+
free(new_table);
281+
return 0;
285282
}
286283
*tbl = *ptr;
287284
tbl->next = new_table->bins[i];
@@ -306,28 +303,28 @@ st_delete(table, key, value)
306303

307304
ptr = table->bins[hash_val];
308305

309-
if (ptr == nil(st_table_entry)) {
310-
if (value != nil(char*)) *value = nil(char);
306+
if (ptr == 0) {
307+
if (value != 0) *value = 0;
311308
return 0;
312309
}
313310

314311
if (EQUAL(table, *key, ptr->key)) {
315312
table->bins[hash_val] = ptr->next;
316313
table->num_entries--;
317-
if (value != nil(char*)) *value = ptr->record;
314+
if (value != 0) *value = ptr->record;
318315
*key = ptr->key;
319-
free((char*)ptr);
316+
free(ptr);
320317
return 1;
321318
}
322319

323-
for(; ptr->next != nil(st_table_entry); ptr = ptr->next) {
320+
for(; ptr->next != 0; ptr = ptr->next) {
324321
if (EQUAL(table, ptr->next->key, *key)) {
325322
tmp = ptr->next;
326323
ptr->next = ptr->next->next;
327324
table->num_entries--;
328-
if (value != nil(char*)) *value = tmp->record;
325+
if (value != 0) *value = tmp->record;
329326
*key = tmp->key;
330-
free((char*)tmp);
327+
free(tmp);
331328
return 1;
332329
}
333330
}
@@ -349,24 +346,24 @@ st_delete_safe(table, key, value, never)
349346

350347
ptr = table->bins[hash_val];
351348

352-
if (ptr == nil(st_table_entry)) {
353-
if (value != nil(char*)) *value = nil(char);
349+
if (ptr == 0) {
350+
if (value != 0) *value = 0;
354351
return 0;
355352
}
356353

357354
if (EQUAL(table, *key, ptr->key)) {
358355
table->num_entries--;
359356
*key = ptr->key;
360-
if (value != nil(char*)) *value = ptr->record;
357+
if (value != 0) *value = ptr->record;
361358
ptr->key = ptr->record = never;
362359
return 1;
363360
}
364361

365-
for(; ptr->next != nil(st_table_entry); ptr = ptr->next) {
362+
for(; ptr->next != 0; ptr = ptr->next) {
366363
if (EQUAL(table, ptr->next->key, *key)) {
367364
table->num_entries--;
368365
*key = ptr->key;
369-
if (value != nil(char*)) *value = ptr->record;
366+
if (value != 0) *value = ptr->record;
370367
ptr->key = ptr->record = never;
371368
return 1;
372369
}
@@ -386,8 +383,8 @@ st_foreach(table, func, arg)
386383
int i;
387384

388385
for(i = 0; i < table->num_bins; i++) {
389-
last = nil(st_table_entry);
390-
for(ptr = table->bins[i]; ptr != nil(st_table_entry);) {
386+
last = 0;
387+
for(ptr = table->bins[i]; ptr != 0;) {
391388
retval = (*func)(ptr->key, ptr->record, arg);
392389
switch (retval) {
393390
case ST_CONTINUE:
@@ -398,13 +395,13 @@ st_foreach(table, func, arg)
398395
return;
399396
case ST_DELETE:
400397
tmp = ptr;
401-
if (last == nil(st_table_entry)) {
398+
if (last == 0) {
402399
table->bins[i] = ptr->next;
403400
} else {
404401
last->next = ptr->next;
405402
}
406403
ptr = ptr->next;
407-
free((char*)tmp);
404+
free(tmp);
408405
table->num_entries--;
409406
}
410407
}

0 commit comments

Comments
 (0)
0