トップ «前の日記(2011-04-25) 最新 次の日記(2011-04-28)» 編集

日々の破片

著作一覧

2011-04-27

_ Rubyで困った(わかった)

バグなのか環境なのか判断がつかない。

とりあえず、もう少し追っかけてみよう。

現象:rb_requireでSEGVする。

#include <stdio.h>
#include "ruby.h"
int main(int argc, char* argv[])
{
    ruby_init();
    rb_require("socket");
    return 0;
}

コンパイル、実行する。

C:\Users\arton\Documents\ruby\test>cl -DNT -DWIN32 -I%INCDIR%/ruby-1
.9.1 -I%INCDIR%/ruby-1.9.1/i386-mswin32_100 test.c /MD -link /DEFAUL
TLIB:%LIBDIR%/msvcr100-ruby191.lib
Microsoft(R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.
 
test.c
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.
 
/out:test.exe
/DEFAULTLIB:/users/arton/lib/msvcr100-ruby191.lib
test.obj
 
C:\Users\arton\Documents\ruby\test>test
<main>: [BUG] Segmentation fault
ruby 1.9.3dev (2011-04-25) [i386-mswin32_100]
 
-- Control frame information -----------------------------------------------
c:0001 p:0000 s:0002 b:0002 l:002324 d:002324 TOP
 
-- C level backtrace information -------------------------------------------
C:\Windows\SysWOW64\ntdll.dll(NtWaitForSingleObject+0x15) [0x77B5F8C1]
C:\Windows\syswow64\kernel32.dll(WaitForSingleObjectEx+0x43) [0x770F1194]
C:\Windows\syswow64\kernel32.dll(WaitForSingleObject+0x12) [0x770F1148]
c:\users\arton\bin\msvcr100-ruby191.dll(rb_vm_bugreport+0x95) [0x6E094614] c:\us
ers\arton\documents\ruby\trunk\vm_dump.c:819
c:\users\arton\bin\msvcr100-ruby191.dll(report_bug+0xc7) [0x6E02B1F3] c:\users\a
rton\documents\ruby\trunk\error.c:256
c:\users\arton\bin\msvcr100-ruby191.dll(rb_bug+0x1c) [0x6E02B229] c:\users\arton
\documents\ruby\trunk\error.c:270
c:\users\arton\bin\msvcr100-ruby191.dll(sigsegv+0x3f) [0x6E0511D0] c:\users\arto
n\documents\ruby\trunk\signal.c:624
C:\Windows\system32\MSVCR100.dll(XcptFilter+0x13e) [0x6FFFB9DF]
 [0x00B811BB]
C:\Windows\syswow64\kernel32.dll(BaseThreadInitThunk+0x12) [0x770F33CA]
C:\Windows\SysWOW64\ntdll.dll(RtlInitializeExceptionChain+0x63) [0x77B79ED2]
 
-- Other runtime information -----------------------------------------------

rb_requireの中で2回JUMP_TAGを実行していて、2回目にはrb_thread_t*がNULLになっているように見えるのだが、確信が持てないというか、printfをいれてみるかな。

追記:わかった。ruby_process_optionではなく、ruby_optionsの呼び出しが必須なのだ。

#include <stdio.h>
#include "ruby.h"
static char* dummyargv[] = {"test", "-e", ";", NULL};
int run_node(void* arg)
{
    rb_require("socket");
    rb_eval_string("p 32");
    return 0;
}
int main(int argc, char* argv[])
{
    ruby_sysinit(&argc, &argv);
    {
	RUBY_INIT_STACK;
	ruby_init();
	return run_node(ruby_options(3, dummyargv));
    }
}

2003|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|

ジェズイットを見習え