[ruby-dev:31241] Re: trunk: バグを指摘している警告(cygwin)
From:
Nobuyoshi Nakada <nobu@...>
Date:
2007-07-17 08:05:53 UTC
List:
ruby-dev #31241
なかだです。
At Mon, 16 Jul 2007 21:23:01 +0900,
pegacorn wrote in [ruby-dev:31239]:
> 今度は、cygwin 環境で -Wall を付けてコンパイルしてみました。
>
> gcc -g -O2 -Wall -I. -I.ext/include/i386-cygwin -I./include -I. -DRUBY_EXPORT -c dln.c
> dln.c: In function `conv_to_posix_path':
> dln.c:1615: warning: implicit declaration of function `cygwin32_conv_to_posix_path'
> gcc -g -O2 -Wall -I. -I.ext/include/i386-cygwin -I./include -I. -DRUBY_EXPORT -c ruby.c
> ruby.c: In function `ruby_push_include':
> ruby.c:190: warning: implicit declaration of function `conv_to_posix_path'
conv_to_posix_path()は元はdln.cでも使っていたのですが、今は
ruby.cでしか使っていません。ruby.cにそのまま移動してもいいかも
しれませんが、最後のチェックはなんだか意味不明だし、
rubylib_mangle関係もそろそろ消していいと思います。
わたなべさんは、POSIX pathへの変換自体をやめにしたいそうですが。
> gcc -g -O2 -Wall -I. -I.ext/include/i386-cygwin -I./include -I. -DRUBY_EXPORT -c ./missing/strftime.c
> ./missing/strftime.c: In function `strftime':
> ./missing/strftime.c:448: warning: int format, long int arg (arg 3)
> ./missing/strftime.c:448: warning: int format, long int arg (arg 4)
これは逆に値のほうをキャストしてもいいような。
> compiling socket
> gcc -I. -I../../.ext/include/i386-cygwin -I../.././include -I../.././ext/socket -DRUBY_EXTCONF_H=\"extconf.h\" -I. -g -O2 -Wall -c getnameinfo.c
> getnameinfo.c: In function `inet_ntop':
> getnameinfo.c:126: warning: implicit declaration of function `snprintf'
stdio.hくらいは常にインクルードしていいんじゃないでしょうか。
> compiling tk
> gcc -I. -I../../.ext/include/i386-cygwin -I../.././include -I../.././ext/tk -DRUBY_EXTCONF_H=\"extconf.h\" -D_WIN32 -DWITH_TCL_ENABLE_THREAD=0 -g -O2 -Wall -c tcltklib.c
> tcltklib.c: In function `eventloop_sleep':
> tcltklib.c:1262: warning: implicit declaration of function `is_ruby_native_thread'
これは永井さんがなにかいってませんでしたっけ。
Index: dln.c
===================================================================
--- dln.c (revision 12804)
+++ dln.c (working copy)
@@ -1601,30 +1601,4 @@ dln_find_file(const char *fname, const c
}
-#if defined(__CYGWIN32__)
-const char *
-conv_to_posix_path(char *win32, char *posix, int len)
-{
- char *first = win32;
- char *p = win32;
- char *dst = posix;
-
- posix[0] = '\0';
- for (p = win32; *p; p++)
- if (*p == ';') {
- *p = 0;
- cygwin32_conv_to_posix_path(first, posix);
- posix += strlen(posix);
- *posix++ = ':';
- first = p + 1;
- *p = ';';
- }
- if (len < strlen(first))
- fprintf(stderr, "PATH length too long: %s\n", first);
- else
- cygwin32_conv_to_posix_path(first, posix);
- return dst;
-}
-#endif
-
static char fbuf[MAXPATHLEN];
Index: ruby.c
===================================================================
--- ruby.c (revision 12804)
+++ ruby.c (working copy)
@@ -15,4 +15,5 @@
#ifdef __CYGWIN__
#include <windows.h>
+#include <sys/cygwin.h>
#endif
#ifdef _WIN32_WCE
@@ -117,103 +118,84 @@ extern VALUE rb_load_path;
#define STATIC_FILE_LENGTH 255
-#if defined _WIN32 || defined __CYGWIN__ || defined __DJGPP__
-static char *
-rubylib_mangle(const char *s, unsigned int l)
+#ifndef CharNext /* defined as CharNext[AW] on Windows. */
+#define CharNext(p) ((p) + mblen(p, RUBY_MBCHAR_MAXSIZE))
+#endif
+
+#if defined(__CYGWIN32__)
+const char *
+conv_to_posix_path(char *win32, char *posix, int len)
{
- static char *newp, *oldp;
- static int newl, oldl, notfound;
- static char newsub[STATIC_FILE_LENGTH + 1];
-
- if (!newp && !notfound) {
- newp = getenv("RUBYLIB_PREFIX");
- if (newp) {
- char *s;
-
- oldp = newp;
- while (*newp && !ISSPACE(*newp) && *newp != ';') {
- newp++;
- oldl++; /* Skip digits. */
- }
- while (*newp && (ISSPACE(*newp) || *newp == ';')) {
- newp++; /* Skip whitespace. */
- }
- newl = strlen(newp);
- if (newl == 0 || oldl == 0 || newl > STATIC_FILE_LENGTH) {
- rb_fatal("malformed RUBYLIB_PREFIX");
- }
- strcpy(newsub, newp);
- s = newsub;
- while (*s) {
- if (*s == '\\')
- *s = '/';
- s++;
- }
- }
- else {
- notfound = 1;
+ char *first = win32;
+ char *p = win32;
+ char *dst = posix;
+
+ posix[0] = '\0';
+ for (p = win32; *p; p++)
+ if (*p == ';') {
+ *p = 0;
+ cygwin32_conv_to_posix_path(first, posix);
+ posix += strlen(posix);
+ *posix++ = ':';
+ first = p + 1;
+ *p = ';';
}
- }
- if (l == 0) {
- l = strlen(s);
- }
- if (!newp || l < oldl || strncasecmp(oldp, s, oldl) != 0) {
- static char ret[STATIC_FILE_LENGTH + 1];
- strncpy(ret, s, l);
- ret[l] = 0;
- return ret;
- }
- if (l + newl - oldl > STATIC_FILE_LENGTH || newl > STATIC_FILE_LENGTH) {
- rb_fatal("malformed RUBYLIB_PREFIX");
- }
- strcpy(newsub + newl, s + oldl);
- newsub[l + newl - oldl] = 0;
- return newsub;
+ if (len < strlen(first))
+ fprintf(stderr, "PATH length too long: %s\n", first);
+ else
+ cygwin32_conv_to_posix_path(first, posix);
+ return dst;
}
-
-#define rubylib_mangled_path(s, l) rb_str_new2(rubylib_mangle((s), (l)))
-#define rubylib_mangled_path2(s) rb_str_new2(rubylib_mangle((s), 0))
-#else
-#define rubylib_mangled_path(s, l) rb_str_new((s), (l))
-#define rubylib_mangled_path2(s) rb_str_new2(s)
#endif
-void
-ruby_push_include(const char *path, VALUE (*filter) (VALUE))
+static void
+push_include(const char *path, VALUE (*filter) (VALUE))
{
const char sep = PATH_SEP_CHAR;
+ const char *p, *s;
- if (path == 0)
- return;
-#if defined(__CYGWIN__)
- {
- char rubylib[FILENAME_MAX];
- conv_to_posix_path(path, rubylib, FILENAME_MAX);
- path = rubylib;
+ p = path;
+ while (*p) {
+ while (*p == sep)
+ p++;
+ if (!*p) break;
+ for (s = p; *s && *s != sep; s = CharNext(s));
+ rb_ary_push(rb_load_path, (*filter)(rb_str_new(p, s - p)));
+ if (!*s) break;
+ p = s + 1;
}
-#endif
- if (strchr(path, sep)) {
- const char *p, *s;
- VALUE ary = rb_ary_new();
-
- p = path;
- while (*p) {
- while (*p == sep)
- p++;
- if ((s = strchr(p, sep)) != 0) {
- rb_ary_push(ary,
- (*filter) (rubylib_mangled_path
- (p, (int)(s - p))));
- p = s + 1;
- }
- else {
- rb_ary_push(ary, (*filter) (rubylib_mangled_path2(p)));
- break;
- }
+}
+
+void
+ruby_push_include(const char *path, VALUE (*filter) (VALUE))
+{
+#if defined __CYGWIN32__
+ const char sep = ';';
+ const char *p, *s;
+ char rubylib[FILENAME_MAX], *buf;
+ int len;
+
+ p = path;
+ while (*p) {
+ while (*p == sep)
+ p++;
+ if (!*p) break;
+ for (s = p; *s && *s != sep; s = CharNext(s));
+ if (*s) {
+ buf = ALLOC_N(char, (len = s - p));
+ MEMCPY(buf, p, char, len);
+ cygwin32_conv_to_posix_path(buf, rubylib);
+ free(buf);
+ push_include(rubylib, filter);
+ p = s + 1;
+ }
+ else {
+ cygwin32_conv_to_posix_path(p, rubylib);
+ push_include(rubylib, filter);
+ break;
}
- rb_ary_concat(rb_load_path, ary);
- }
- else {
- rb_ary_push(rb_load_path, (*filter) (rubylib_mangled_path2(path)));
}
+#else
+ push_include(path, filter);
+#endif
}
@@ -259,9 +241,5 @@ translate_char(char *p, int from, int to
if ((unsigned char)*p == from)
*p = to;
-#ifdef CharNext /* defined as CharNext[AW] on Windows. */
p = CharNext(p);
-#else
- p += mblen(p, RUBY_MBCHAR_MAXSIZE);
-#endif
}
}
@@ -301,6 +279,12 @@ ruby_init_loadpath(void)
libpath[sizeof(libpath) - 1] = '\0';
-#if defined DOSISH || defined __CYGWIN__
+#if defined DOSISH
translate_char(libpath, '\\', '/');
+#elif defined __CYGWIN__
+ {
+ char rubylib[FILENAME_MAX];
+ cygwin_conv_to_posix_path(libpath, rubylib);
+ strncpy(libpath, rubylib, sizeof(libpath));
+ }
#endif
p = strrchr(libpath, '/');
@@ -323,4 +307,5 @@ ruby_init_loadpath(void)
#define RUBY_RELATIVE(path) (path)
#endif
+#define incpush(path) rb_ary_push(rb_load_path, rb_str_new2(path))
if (rb_safe_level() == 0) {
@@ -329,22 +314,31 @@ ruby_init_loadpath(void)
#ifdef RUBY_SEARCH_PATH
- ruby_incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
+ incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
#endif
- ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));
+ incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));
#ifdef RUBY_SITE_THIN_ARCHLIB
- ruby_incpush(RUBY_RELATIVE(RUBY_SITE_THIN_ARCHLIB));
+ incpush(RUBY_RELATIVE(RUBY_SITE_THIN_ARCHLIB));
+#endif
+ incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB));
+ incpush(RUBY_RELATIVE(RUBY_SITE_LIB));
+
+#ifdef RUBY_VENDOR_LIB
+ incpush(RUBY_RELATIVE(RUBY_VENDOR_LIB2));
+#ifdef RUBY_VENDOR_THIN_ARCHLIB
+ incpush(RUBY_RELATIVE(RUBY_VENDOR_THIN_ARCHLIB));
+#endif
+ incpush(RUBY_RELATIVE(RUBY_VENDOR_ARCHLIB));
+ incpush(RUBY_RELATIVE(RUBY_VENDOR_LIB));
#endif
- ruby_incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB));
- ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB));
- ruby_incpush(RUBY_RELATIVE(RUBY_LIB));
+ incpush(RUBY_RELATIVE(RUBY_LIB));
#ifdef RUBY_THIN_ARCHLIB
- ruby_incpush(RUBY_RELATIVE(RUBY_THIN_ARCHLIB));
+ incpush(RUBY_RELATIVE(RUBY_THIN_ARCHLIB));
#endif
- ruby_incpush(RUBY_RELATIVE(RUBY_ARCHLIB));
+ incpush(RUBY_RELATIVE(RUBY_ARCHLIB));
if (rb_safe_level() == 0) {
- ruby_incpush(".");
+ incpush(".");
}
}
Index: missing/strftime.c
===================================================================
--- missing/strftime.c (revision 12804)
+++ missing/strftime.c (working copy)
@@ -446,5 +446,5 @@ strftime(char *s, size_t maxsize, const
tbuf[0] = '+';
}
- sprintf(tbuf+1, "%02d%02d", off/60, off%60);
+ sprintf(tbuf+1, "%02d%02d", (int)off/60, (int)off%60);
break;
#endif /* MAILHEADER_EXT */
Index: ext/socket/getnameinfo.c
===================================================================
--- ext/socket/getnameinfo.c (revision 12804)
+++ ext/socket/getnameinfo.c (working copy)
@@ -36,4 +36,5 @@
#include "ruby/config.h"
+#include <stdio.h>
#include <sys/types.h>
#ifndef _WIN32
@@ -52,7 +53,4 @@
#include <netdb.h>
#if defined(HAVE_RESOLV_H)
-#ifdef _SX
-#include <stdio.h>
-#endif
#include <resolv.h>
#endif
@@ -60,5 +58,4 @@
#ifdef _WIN32
#include <winsock2.h>
-#include <stdio.h>
#define snprintf _snprintf
#endif
--
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
中田 伸悦