Bug #1388: cygwin-1.7, gcc4-4.3, and ruby-1.9. make btest #236 test_io.rb Segmentation fault
http://redmine.ruby-lang.org/issues/show/1388

Author: neomjp neomjp
Status: Open, Priority: Normal
ruby -v: ruby 1.9.2dev (2009-04-08 trunk 23198) [i386-cygwin]

Cygwin 1.7 is currently under beta testing. It is currently at cygwin-1.7.0-46. If nothing goes overly wrong, the official 1.7.1 is planned to be released in June.
http://sourceware.org/ml/cygwin-announce/2009-04/msg00025.html

Two issues blocking the release are:

1) Stabilization of gcc-4.3; It is currently at gcc4-4.3.2-2, and several to-do's remain. 
http://sourceware.org/ml/cygwin/2009-03/msg00378.html
http://sourceware.org/ml/cygwin/2009-03/msg00422.html
Hopefully it will get ready in gcc4-4.3.2-3.

2) Compilation of all packages using the stable gcc-4.3.

This bug report is about making ruby-1.9 ready for these new cygwin-1.7 and gcc-4.3. These are some of the patches required to make ruby trunk get compiled.

* eval_intern.h [CYGWIN]: Remove #ifdef __CYGWIN__ for _setjmp() and _longjmp(). Cygwin-1.7
    has its own definition in /usr/include/machine/setjmp.h . This is the minimally required
    patch to make the compilation go through to the end.

--- origsrc/ruby-1.9.2-r23198/eval_intern.h     2009-02-22 10:43:59.000000000 +0900
+++ src/ruby-1.9.2-r23198/eval_intern.h 2009-04-18 01:26:41.843750000 +0900
@@ -66,9 +66,6 @@ char *strrchr(const char *, const char);
 
 #define ruby_setjmp(env) RUBY_SETJMP(env)
 #define ruby_longjmp(env,val) RUBY_LONGJMP(env,val)
-#ifdef __CYGWIN__
-int _setjmp(), _longjmp();
-#endif
 
 #include <sys/types.h>
 #include <signal.h>

* ruby.c (push_include_cygwin): Use cygwin_conv_path instead of cygwin_conv_to_posix_path
    which is deprecated in cygwin-1.7.
* ruby.c (ruby_init_loadpath_safe): Use cygwin_conv_path instead of cygwin_conv_to_posix_path
    which is deprecated in cygwin-1.7.

--- origsrc/ruby-1.9.2-r23198/ruby.c    2009-03-17 10:29:17.000000000 +0900
+++ src/ruby-1.9.2-r23198/ruby.c        2009-04-18 01:26:41.859375000 +0900
@@ -257,7 +257,8 @@ push_include_cygwin(const char *path, VA
                p = strncpy(RSTRING_PTR(buf), p, len);
            }
        }
-       if (cygwin_conv_to_posix_path(p, rubylib) == 0)
+       if (cygwin_conv_path(CCP_WIN_W_TO_POSIX | CCP_RELATIVE, p, rubylib, 1)
+           == 0)
            p = rubylib;
        push_include(p, filter);
        if (!*s) break;
@@ -366,8 +367,10 @@ ruby_init_loadpath_safe(int safe_level)
 #elif defined __CYGWIN__
     {
        char rubylib[FILENAME_MAX];
-       cygwin_conv_to_posix_path(libpath, rubylib);
-       strncpy(libpath, rubylib, sizeof(libpath));
+       if (cygwin_conv_path(CCP_WIN_W_TO_POSIX | CCP_RELATIVE,
+                            libpath, rubylib, 1)
+           == 0)
+         strncpy(libpath, rubylib, sizeof(libpath));
     }
 #endif
     p = strrchr(libpath, '/');

* strftime.c [CYGWIN]: Cygwin <time.h> defines _timezone, _daylight, *_tzname[2], and tzname
    with dllimport attribute. But <cygwin/time.h> defines daylight and timezone without
    dllimport attribute.

--- origsrc/ruby-1.9.2-r23198/strftime.c        2009-03-17 10:29:17.000000000 +0
900
+++ src/ruby-1.9.2-r23198/strftime.c    2009-04-18 01:26:41.859375000 +0900
@@ -120,12 +120,16 @@ extern char *strchr();
 
 #define range(low, item, hi)   max(low, min(item, hi))
 
-#if defined __WIN32__ || defined _WIN32
+#if defined __CYGWIN__ || defined __WIN32__ || defined _WIN32
 #define DLL_IMPORT __declspec(dllimport)
 #endif
 #ifndef DLL_IMPORT
 #define DLL_IMPORT
 #endif
+#ifdef __CYGWIN__
+#define daylight _daylight
+#define timezone _timezone
+#endif
 #if !defined(OS2) && defined(HAVE_TZNAME)
 extern DLL_IMPORT char *tzname[2];
 #ifdef HAVE_DAYLIGHT

With the above three patches, ruby-1.9.2-r23198 can get compiled with only one warning:

** PTHREAD SUPPORT MODE WARNING:
**
**   Ruby is compiled with --enable-pthread, but your Tcl/Tk library
**   seems to be compiled without pthread support. Although you can
...

This is expected because cygwin tcltk-20080420-1 is compiled without pthread support. But when I try to compile like

CC=gcc-4 configure --program-suffix="-19" --disable-pthread
make

compilation fails.

make: *** No rule to make target `thread_.h', needed by `miniprelude.o'.  Stop.
*** ERROR: make failed

This is because THREAD_MODEL is empty in Makefile. Looking into configure.in, I can see that when 

if test "$rb_with_pthread" = "yes"; 

is false and

case "$target_os" in
when(cygwin*)

then THREAD_MODEL gets undefined. (when(mingw*) is true, THREAD_MODEL=win32.) If I compile like

CC=gcc-4 configure --program-suffix="-19" --disable-pthread
make THREAD_MODEL=w32

the compilation goes through to the end, and thread-win32.c seems to be used instead of thread-pthread.c. But the same warning persists.

** PTHREAD SUPPORT MODE WARNING:
**
**   Ruby is compiled with --enable-pthread, but your Tcl/Tk library
**   seems to be compiled without pthread support. Although you can
...

This is wrong because --disable-pthread is used. Looking into ext/tk/extconf.rb, I can see that this warning is emitted when

# check pthread mode
 if (macro_defined?('HAVE_NATIVETHREAD', '#include "ruby.h"'))
   # ruby -> enable
   unless tcl_enable_thread
     # ruby -> enable && tcl -> disable

But include/ruby/ruby.h has

#define HAVE_NATIVETHREAD

without any #ifdefs. So the pthread mode check in ext/tk/extconf.rb always evaluates to be true even when pthread support is disabled. This should be corrected. If these issues are corrected, then ruby-1.9 trunk can get compiled without warnings.

When I tried make run or make runruby, it failed.

* common.mk (TESTRUN_SCRIPT): Correct the path to test.rb

--- origsrc/ruby-1.9.2-r23198/common.mk    2009-04-10 11:32:15.000000000 +0900
+++ src/ruby-1.9.2-r23198/common.mk        2009-04-18 04:35:13.968750000 +0900
@@ -117,7 +117,7 @@
 TESTSDIR      = $(srcdir)/test
 TESTWORKDIR   = testwork
 
-TESTRUN_SCRIPT = $(srcdir)/test.rb
+TESTRUN_SCRIPT = $(srcdir)/sample/test.rb
 
 BOOTSTRAPRUBY = $(BASERUBY)
 
With this patch, the results of make run or runruby are

make run
not ok/test: 900 failed 1
Fnot ok system 9 -- .../ruby-1.9.2-r23198/sample/test.rb:1948:in `<main>'

make runruby
end of test(test: 900)

which is expected and good. miniruby.exe does not support euc-jp, shift_jis, windows-1251, cp932 in Encoding.name_list, so make run is expected to fail at that test. But the result of make btest is bad.

#236 test_io.rb: 
       at_exit { p :foo }
   
       megacontent = "abc" * 12345678
       #File.open("megasrc", "w") {|f| f << megacontent }
   
       Thread.new { sleep rand*0.2; Process.kill(:INT, $$) }
   
       r1, w1 = IO.pipe
       r2, w2 = IO.pipe
       t1 = Thread.new { w1 << megacontent; w1.close }
       t2 = Thread.new { r2.read }
       IO.copy_stream(r1, w2) rescue nil
       r2.close; w2.close
       r1.close; w1.close
       #=> killed by SIGABRT (signal 6)
| bootstraptest.tmp.rb:2: [BUG] Segmentation fault
| ruby 1.9.2dev (2009-04-15 trunk 23198) [i386-cygwin]
| 
| -- control frame ----------
| c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC  :p
| c:0003 p:0011 s:0006 b:0006 l:000aec d:000005 BLOCK  bootstraptest.tmp.rb:2
| c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
| c:0001 p:0000 s:0002 b:0002 l:000aec d:000aec TOP    <main>:19
| ---------------------------
| bootstraptest.tmp.rb:2:in `block in <main>'
| bootstraptest.tmp.rb:2:in `p'
|
| [NOTE]
| You may have encountered a bug in the Ruby interpreter or extension libraries.
| Bug reports are welcome.
| For details: http://www.ruby-lang.org/bugreport.html
| 
  
FAIL 1/890 tests failed
make: *** [btest] Error 1

make btest-ruby also emits several errors, but I will submit it as another issue because this report is already too long...


----------------------------------------
http://redmine.ruby-lang.org