なかだです。

At Mon, 12 Sep 2005 00:56:36 +0900,
Tanaka Akira wrote in [ruby-dev:27019]:
> ただ、rb_thread_create についていえば引数は VALUE (*)(VALUE) で受けて
> VALUE (*)(VALUE, rb_thread_t) に cast してから rb_thread_start_0 にわ
> たせばいいことだと思います。

関数ポインタのキャストは基本的に避けたほうが無難じゃないでしょ
うか。rb_thread_tが必要なら、opaqueな型でtypedefしておくので充
分だと思います。

> > というわけで、放置するのは良くないような気がしてきました。typedef void* VALUE とすれば
> > 64bit 環境でも問題ない可能性はありますが、そのかわりコールバック側で VALUE * で受けたり、
> > struct のポインタで受けたりはできなくなるんじゃないでしょうか。
> 
> ここで述べられている理由はよくわかりませんが、個人的には VALUE は
> void* にするのが適切であろうと思っています。
> 
> それは、AS/400 なるシステムではポインタと同じサイズの整数型が存在しな
> いということを知ってしまったというのが理由です。

ということは関数ポインタをcastして呼び出すことは保証されないん
じゃないでしょうか。

とりあえずapply2files()のコールバックを修正してみました。


Index: file.c =================================================================== RCS file: /cvs/ruby/src/ruby/file.c,v retrieving revision 1.201 diff -U2 -p -r1.201 file.c --- file.c 12 Sep 2005 10:44:20 -0000 1.201 +++ file.c 12 Sep 2005 12:43:51 -0000 @@ -98,5 +98,5 @@ rb_get_path(VALUE obj) static long -apply2files(void (*func) (/* ??? */), VALUE vargs, void *arg) +apply2files(void (*func)(const char *, void *), VALUE vargs, void *arg) { long i; @@ -1276,7 +1276,5 @@ test_grpowned(VALUE obj, VALUE fname) #if defined(S_ISUID) || defined(S_ISGID) || defined(S_ISVTX) static VALUE -check3rdbyte(fname, mode) - VALUE fname; - int mode; +check3rdbyte(VALUE fname, int mode) { struct stat st; @@ -1359,5 +1357,5 @@ rb_file_s_size(VALUE klass, VALUE fname) static VALUE -rb_file_ftype(struct stat *st) +rb_file_ftype(const struct stat *st) { char *t; @@ -1562,7 +1560,7 @@ rb_file_ctime(VALUE obj) static void -chmod_internal(const char *path, int mode) +chmod_internal(const char *path, void *mode) { - if (chmod(path, mode) < 0) + if (chmod(path, (int)mode) < 0) rb_sys_fail(path); } @@ -1634,9 +1632,7 @@ rb_file_chmod(VALUE obj, VALUE vmode) #if defined(HAVE_LCHMOD) static void -lchmod_internal(path, mode) - const char *path; - int mode; +lchmod_internal(const char *path, void *mode) { - if (lchmod(path, mode) < 0) + if (lchmod(path, (int)mode) < 0) rb_sys_fail(path); } @@ -1653,7 +1649,5 @@ lchmod_internal(path, mode) static VALUE -rb_file_s_lchmod(argc, argv) - int argc; - VALUE *argv; +rb_file_s_lchmod(int argc, VALUE *argv) { VALUE vmode; @@ -1682,6 +1676,7 @@ struct chown_args { static void -chown_internal(const char *path, struct chown_args *args) +chown_internal(const char *path, void *arg) { + struct chown_args *args = arg; if (chown(path, args->owner, args->group) < 0) rb_sys_fail(path); @@ -1768,8 +1763,7 @@ rb_file_chown(VALUE obj, VALUE owner, VA #if defined(HAVE_LCHOWN) && !defined(__CHECKER__) static void -lchown_internal(path, args) - const char *path; - struct chown_args *args; +lchown_internal(const char *path, void *arg) { + struct chown_args *args = arg; if (lchown(path, args->owner, args->group) < 0) rb_sys_fail(path); @@ -1789,7 +1783,5 @@ lchown_internal(path, args) static VALUE -rb_file_s_lchown(argc, argv) - int argc; - VALUE *argv; +rb_file_s_lchown(int argc, VALUE *argv) { VALUE o, g, rest; @@ -1828,8 +1820,7 @@ struct timeval rb_time_timeval(VALUE tim static void -utime_internal(path, tvp) - char *path; - struct timeval tvp[]; +utime_internal(const char *path, void *arg) { + struct timeval *tvp = arg; if (utimes(path, tvp) < 0) rb_sys_fail(path); @@ -1846,7 +1837,5 @@ utime_internal(path, tvp) static VALUE -rb_file_s_utime(argc, argv) - int argc; - VALUE *argv; +rb_file_s_utime(int argc, VALUE *argv) { VALUE atime, mtime, rest; @@ -1873,6 +1862,7 @@ struct utimbuf { static void -utime_internal(const char *path, struct utimbuf *utp) +utime_internal(const char *path, void *arg) { + struct utimbuf *utp = arg; if (utime(path, utp) < 0) rb_sys_fail(path); @@ -2015,5 +2005,5 @@ rb_file_s_readlink(VALUE klass, VALUE pa static void -unlink_internal(const char *path) +unlink_internal(const char *path, void *arg) { if (unlink(path) < 0) @@ -3842,6 +3832,5 @@ is_absolute_path(const char *path) #ifndef DOSISH static int -path_check_1(path) - VALUE path; +path_check_1(VALUE path) { struct stat st; @@ -3883,8 +3872,8 @@ path_check_1(path) int -rb_path_check(char *path) +rb_path_check(const char *path) { #ifndef DOSISH - char *p0, *p, *pend; + const char *p0, *p, *pend; const char sep = PATH_SEP_CHAR; @@ -3911,6 +3900,5 @@ rb_path_check(char *path) #if defined(__MACOS__) || defined(riscos) static int -is_macos_native_path(path) - const char *path; +is_macos_native_path(const char *path) { if (strchr(path, ':')) return 1; @@ -3920,5 +3908,5 @@ is_macos_native_path(path) static int -file_load_ok(char *file) +file_load_ok(const char *file) { FILE *f; Index: intern.h =================================================================== RCS file: /cvs/ruby/src/ruby/intern.h,v retrieving revision 1.178 diff -U2 -p -r1.178 intern.h --- intern.h 30 Aug 2005 14:49:51 -0000 1.178 +++ intern.h 12 Sep 2005 12:20:27 -0000 @@ -324,5 +324,5 @@ VALUE rb_hash_aset _((VALUE, VALUE, VALU VALUE rb_hash_delete_if _((VALUE)); VALUE rb_hash_delete _((VALUE,VALUE)); -int rb_path_check _((char*)); +int rb_path_check _((const char*)); int rb_env_path_tainted _((void)); /* io.c */
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦