Skip to content

Commit f933f9d

Browse files
author
matz
committed
* gc.c (id2ref): must not assign pointers to long int. use
LONG_LONG instead if SIZEOF_LONG < SIZEOF_VOIDP. [ruby-talk:149645] * ruby.h: use LONG_LONG to simplify the change. [ruby-talk:149645] * eval.c (rb_f_throw): replace all '0x%lx' by '%p'. [ruby-talk:149553] * missing/vsnprintf.c (BSD_vfprintf): '%p' need to handle 64bit size pointer. [ruby-talk:149553] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent d68e049 commit f933f9d

File tree

8 files changed

+62
-28
lines changed

8 files changed

+62
-28
lines changed

ChangeLog

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
Wed Jul 27 10:43:14 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* gc.c (id2ref): must not assign pointers to long int. use
4+
LONG_LONG instead if SIZEOF_LONG < SIZEOF_VOIDP.
5+
[ruby-talk:149645]
6+
7+
* ruby.h: use LONG_LONG to simplify the change.
8+
[ruby-talk:149645]
9+
110
Wed Jul 27 10:59:02 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
211

312
* dir.c (dir_each): rewinddir(3) before iteration.
413
[ruby-talk:149628]
514

15+
Wed Jul 27 02:34:58 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
16+
17+
* eval.c (rb_f_throw): replace all '0x%lx' by '%p'.
18+
[ruby-talk:149553]
19+
20+
* missing/vsnprintf.c (BSD_vfprintf): '%p' need to handle 64bit
21+
size pointer. [ruby-talk:149553]
22+
623
Tue Jul 26 18:11:33 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
724

825
* ruby.h: support LLP64 model. [ruby-talk:149524]

eval.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5848,7 +5848,7 @@ rb_call(klass, recv, mid, argc, argv, scope)
58485848
struct cache_entry *ent;
58495849

58505850
if (!klass) {
5851-
rb_raise(rb_eNotImpError, "method `%s' called on terminated object (0x%lx)",
5851+
rb_raise(rb_eNotImpError, "method `%s' called on terminated object (%p)",
58525852
rb_id2name(mid), recv);
58535853
}
58545854
/* is it in the method cache? */
@@ -8502,7 +8502,7 @@ proc_to_s(self)
85028502
struct BLOCK *data;
85038503
NODE *node;
85048504
char *cname = rb_obj_classname(self);
8505-
const int w = (SIZEOF_LONG * CHAR_BIT) / 4;
8505+
const int w = (sizeof(VALUE) * CHAR_BIT) / 4;
85068506
long len = strlen(cname)+6+w; /* 6:tags 16:addr */
85078507
VALUE str;
85088508

@@ -8511,13 +8511,13 @@ proc_to_s(self)
85118511
len += strlen(node->nd_file) + 2 + (SIZEOF_LONG*CHAR_BIT-NODE_LSHIFT)/3;
85128512
str = rb_str_new(0, len);
85138513
snprintf(RSTRING(str)->ptr, len+1,
8514-
"#<%s:0x%.*lx@%s:%d>", cname, w, (VALUE)data->body,
8514+
"#<%s:%p@%s:%d>", cname, (VALUE)data->body,
85158515
node->nd_file, nd_line(node));
85168516
}
85178517
else {
85188518
str = rb_str_new(0, len);
85198519
snprintf(RSTRING(str)->ptr, len+1,
8520-
"#<%s:0x%.*lx>", cname, w, (VALUE)data->body);
8520+
"#<%s:%p>", cname, (VALUE)data->body);
85218521
}
85228522
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
85238523
if (OBJ_TAINTED(self)) OBJ_TAINT(str);
@@ -10229,7 +10229,7 @@ rb_thread_deadlock()
1022910229
char msg[21+SIZEOF_LONG*2];
1023010230
VALUE e;
1023110231

10232-
sprintf(msg, "Thread(0x%lx): deadlock", curr_thread->thread);
10232+
sprintf(msg, "Thread(%p): deadlock", curr_thread->thread);
1023310233
e = rb_exc_new2(rb_eFatal, msg);
1023410234
if (curr_thread == main_thread) {
1023510235
rb_exc_raise(e);
@@ -10509,13 +10509,13 @@ rb_thread_schedule()
1050910509
TRAP_END;
1051010510
}
1051110511
FOREACH_THREAD_FROM(curr, th) {
10512-
warn_printf("deadlock 0x%lx: %s:",
10512+
warn_printf("deadlock %p: %s:",
1051310513
th->thread, thread_status_name(th->status));
1051410514
if (th->wait_for & WAIT_FD) warn_printf("F(%d)", th->fd);
1051510515
if (th->wait_for & WAIT_SELECT) warn_printf("S");
1051610516
if (th->wait_for & WAIT_TIME) warn_printf("T(%f)", th->delay);
1051710517
if (th->wait_for & WAIT_JOIN)
10518-
warn_printf("J(0x%lx)", th->join ? th->join->thread : 0);
10518+
warn_printf("J(%p)", th->join ? th->join->thread : 0);
1051910519
if (th->wait_for & WAIT_PID) warn_printf("P");
1052010520
if (!th->wait_for) warn_printf("-");
1052110521
warn_printf(" %s - %s:%d\n",
@@ -10752,10 +10752,10 @@ rb_thread_join(th, limit)
1075210752
if (rb_thread_critical) rb_thread_deadlock();
1075310753
if (!rb_thread_dead(th)) {
1075410754
if (th == curr_thread)
10755-
rb_raise(rb_eThreadError, "thread 0x%lx tried to join itself",
10755+
rb_raise(rb_eThreadError, "thread %p tried to join itself",
1075610756
th->thread);
1075710757
if ((th->wait_for & WAIT_JOIN) && th->join == curr_thread)
10758-
rb_raise(rb_eThreadError, "Thread#join: deadlock 0x%lx - mutual join(0x%lx)",
10758+
rb_raise(rb_eThreadError, "Thread#join: deadlock %p - mutual join(%p)",
1075910759
curr_thread->thread, th->thread);
1076010760
if (curr_thread->status == THREAD_TO_KILL)
1076110761
last_status = THREAD_TO_KILL;
@@ -12269,7 +12269,7 @@ rb_thread_inspect(thread)
1226912269
size_t len = strlen(cname)+7+16+9+1;
1227012270

1227112271
str = rb_str_new(0, len); /* 7:tags 16:addr 9:status 1:nul */
12272-
snprintf(RSTRING(str)->ptr, len, "#<%s:0x%lx %s>", cname, thread, status);
12272+
snprintf(RSTRING(str)->ptr, len, "#<%s:%p %s>", cname, thread, status);
1227312273
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
1227412274
OBJ_INFECT(str, thread);
1227512275

@@ -12803,7 +12803,7 @@ rb_f_throw(argc, argv)
1280312803
break;
1280412804
}
1280512805
if (tt->tag == PROT_THREAD) {
12806-
rb_raise(rb_eThreadError, "uncaught throw `%s' in thread 0x%lx",
12806+
rb_raise(rb_eThreadError, "uncaught throw `%s' in thread %p",
1280712807
rb_id2name(SYM2ID(tag)),
1280812808
curr_thread);
1280912809
}

gc.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ gc_mark_children(ptr, lev)
990990
break;
991991

992992
default:
993-
rb_bug("rb_gc_mark(): unknown data type 0x%lx(0x%lx) %s",
993+
rb_bug("rb_gc_mark(): unknown data type %p(%p) %s",
994994
obj->as.basic.flags & T_MASK, obj,
995995
is_pointer_to_heap(obj) ? "corrupted object" : "non object");
996996
}
@@ -1256,7 +1256,7 @@ obj_free(obj)
12561256
break;
12571257

12581258
default:
1259-
rb_bug("gc_sweep(): unknown data type 0x%lx(%ld)", obj,
1259+
rb_bug("gc_sweep(): unknown data type %p(%ld)", obj,
12601260
RANY(obj)->as.basic.flags & T_MASK);
12611261
}
12621262
}
@@ -1883,10 +1883,18 @@ static VALUE
18831883
id2ref(obj, id)
18841884
VALUE obj, id;
18851885
{
1886-
unsigned long ptr, p0;
1886+
#if SIZEOF_LONG == SIZEOF_VOIDP
1887+
#define NUM2PTR(x) NUM2ULONG(x)
1888+
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
1889+
#define NUM2PTR(x) NUM2ULL(x)
1890+
#endif
1891+
VALUE ptr;
1892+
void *p0;
18871893

18881894
rb_secure(4);
1889-
p0 = ptr = NUM2ULONG(id);
1895+
ptr = NUM2PTR(id);
1896+
p0 = (void *)ptr;
1897+
18901898
if (ptr == Qtrue) return Qtrue;
18911899
if (ptr == Qfalse) return Qfalse;
18921900
if (ptr == Qnil) return Qnil;
@@ -1897,10 +1905,10 @@ id2ref(obj, id)
18971905

18981906
ptr = id ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */
18991907
if (!is_pointer_to_heap((void *)ptr)|| BUILTIN_TYPE(ptr) >= T_BLKTAG) {
1900-
rb_raise(rb_eRangeError, "0x%lx is not id value", p0);
1908+
rb_raise(rb_eRangeError, "%p is not id value", p0);
19011909
}
19021910
if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0) {
1903-
rb_raise(rb_eRangeError, "0x%lx is recycled object", p0);
1911+
rb_raise(rb_eRangeError, "%p is recycled object", p0);
19041912
}
19051913
return (VALUE)ptr;
19061914
}

missing/vsnprintf.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,19 @@ fp_begin: _double = va_arg(ap, double);
781781
* defined manner.''
782782
* -- ANSI X3J11
783783
*/
784+
#ifdef _HAVE_LLP64_
785+
uqval = (u_long)va_arg(ap, void *);
786+
flags = (flags) | QUADINT | HEXPREFIX;
787+
#else
784788
ulval = (u_long)va_arg(ap, void *);
785-
base = 16;
786-
xdigs = "0123456789abcdef";
787789
#ifdef _HAVE_SANE_QUAD_
788790
flags = (flags & ~QUADINT) | HEXPREFIX;
789791
#else /* _HAVE_SANE_QUAD_ */
790792
flags = (flags) | HEXPREFIX;
791793
#endif /* _HAVE_SANE_QUAD_ */
794+
#endif
795+
base = 16;
796+
xdigs = "0123456789abcdef";
792797
ch = 'x';
793798
goto nosign;
794799
case 's':

object.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ rb_any_to_s(obj)
359359

360360
len = strlen(cname)+6+16;
361361
str = rb_str_new(0, len); /* 6:tags 16:addr */
362-
snprintf(RSTRING(str)->ptr, len+1, "#<%s:0x%lx>", cname, obj);
362+
snprintf(RSTRING(str)->ptr, len+1, "#<%s:%p>", cname, obj);
363363
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
364364
if (OBJ_TAINTED(obj)) OBJ_TAINT(str);
365365

@@ -442,13 +442,13 @@ rb_obj_inspect(obj)
442442
if (rb_inspecting_p(obj)) {
443443
len = strlen(c)+10+16+1;
444444
str = rb_str_new(0, len); /* 10:tags 16:addr 1:nul */
445-
snprintf(RSTRING(str)->ptr, len, "#<%s:0x%lx ...>", c, obj);
445+
snprintf(RSTRING(str)->ptr, len, "#<%s:%p ...>", c, obj);
446446
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
447447
return str;
448448
}
449449
len = strlen(c)+6+16+1;
450450
str = rb_str_new(0, len); /* 6:tags 16:addr 1:nul */
451-
snprintf(RSTRING(str)->ptr, len, "-<%s:0x%lx", c, obj);
451+
snprintf(RSTRING(str)->ptr, len, "-<%s:%p", c, obj);
452452
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
453453
return rb_protect_inspect(inspect_obj, obj, str);
454454
}

ruby.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,8 @@ extern "C" {
7474
typedef unsigned long VALUE;
7575
typedef unsigned long ID;
7676
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
77-
typedef unsigned long long VALUE;
78-
typedef unsigned long long ID;
79-
#elif SIZEOF___INT64 == SIZEOF_VOIDP
80-
typedef unsigned __int64 VALUE;
81-
typedef unsigned __int64 ID;
77+
typedef unsigned LONG_LONG VALUE;
78+
typedef unsigned LONG_LONG ID;
8279
#else
8380
# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
8481
#endif

sprintf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,3 +809,10 @@ fmt_setup(buf, c, flags, width, prec)
809809
*buf++ = c;
810810
*buf = '\0';
811811
}
812+
#if SIZEOF_LONG < SIZEOF_VOIDP
813+
# if SIZEOF_LONG_LONG == SIZEOF_VOIDP
814+
# define _HAVE_SANE_QUAD_
815+
# define _HAVE_LLP64_
816+
# define u_quad_t unsigned LONG_LONG
817+
# endif
818+
#endif

variable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ rb_class_path(klass)
208208
}
209209
len = 2 + strlen(s) + 3 + 2 * SIZEOF_LONG + 1;
210210
path = rb_str_new(0, len);
211-
snprintf(RSTRING(path)->ptr, len+1, "#<%s:0x%lx>", s, klass);
211+
snprintf(RSTRING(path)->ptr, len+1, "#<%s:%p>", s, klass);
212212
RSTRING(path)->len = strlen(RSTRING(path)->ptr);
213213
rb_ivar_set(klass, tmp_classpath, path);
214214

0 commit comments

Comments
 (0)