Bug #1511

"[BUG] Segmentation fault" with Win32API

Added by Br Hug over 2 years ago. Updated 10 months ago.

[ruby-core:23544]
Status:Closed Start date:05/25/2009
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:test
Target version:1.9.1
ruby -v:ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]

Description

I try to build ruby with Intel C++ compiler (w_cc_p_10.1.021), it works, mostly.

When I do nmake test, I got this:

D:/Temp/ruby-1.9.1-p129/win32/build/.ext/common/Win32API.rb:23: [BUG] Segmentation fault
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]

-- control frame ----------
c:0009 p:---- s:0031 b:0031 l:000030 d:000030 CFUNC  :call
c:0008 p:0039 s:0027 b:0027 l:000026 d:000026 METHOD D:/Temp/ruby-1.9.1-p129/win32/build/.ext/common/Win32API.rb:23
c:0007 p:0102 s:0021 b:0021 l:000020 d:000020 CLASS  D:/Temp/ruby-1.9.1-p129/lib/tmpdir.rb:20
c:0006 p:0021 s:0014 b:0014 l:000013 d:000013 TOP    D:/Temp/ruby-1.9.1-p129/lib/tmpdir.rb:9
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC  :require
c:0003 p:0025 s:0006 b:0006 l:001284 d:0013ac EVAL   ../../bootstraptest/runner.rb:10
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:001284 d:001284 TOP    <main>:371
---------------------------
-- Ruby level backtrace information-----------------------------------------
D:/Temp/ruby-1.9.1-p129/win32/build/.ext/common/Win32API.rb:23:in `call'
D:/Temp/ruby-1.9.1-p129/win32/build/.ext/common/Win32API.rb:23:in `call'
D:/Temp/ruby-1.9.1-p129/lib/tmpdir.rb:20:in `<class:Dir>'
D:/Temp/ruby-1.9.1-p129/lib/tmpdir.rb:9:in `<top (required)>'
../../bootstraptest/runner.rb:10:in `require'
../../bootstraptest/runner.rb:10:in `<main>'

History

Updated by Br Hug over 2 years ago

require 'win32api'

func = Win32API.new('Kernel32', 'GetModuleHandle', 'I', 'I')
# => [BUG] cfp consistency error - send

func = Win32API.new('Kernel32', 'GetModuleHandle', 'I', 'I', :stdcall)
# => OK

p func.call(0)

--------------

D:/Opt/ruby-1.9.1-p129-icl/lib/ruby/1.9.1/Win32API.rb:23: [BUG] cfp consistency error - send
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]

-- control frame ----------
c:0005 p:---- s:0018 b:0018 l:000017 d:000017 CFUNC  :call
c:0004 p:0039 s:0014 b:0014 l:000013 d:000013 METHOD D:/Opt/ruby-1.9.1-p129-icl/lib/ruby/1.9.1/Win32API.rb:23
c:0003 p:0052 s:0008 b:0007 l:000b24 d:001040 EVAL   tt.rb:4
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000b24 d:000b24 TOP    <main>:443
---------------------------
-- Ruby level backtrace information-----------------------------------------
D:/Opt/ruby-1.9.1-p129-icl/lib/ruby/1.9.1/Win32API.rb:23:in `call'
D:/Opt/ruby-1.9.1-p129-icl/lib/ruby/1.9.1/Win32API.rb:23:in `call'
tt.rb:4:in `<main>'

--------------

Maybe we should change

	def initialize(dllname, func, import, export = "0", *rest)

to

	def initialize(dllname, func, import, export = "0", call_type = :stdcall, *rest)

and

	@func = DL::CFunc.new(handle[func], TYPEMAP[export.tr("VPpNnLlIi", "0SSI")], func, *rest)

to

	@func = DL::CFunc.new(handle[func], TYPEMAP[export.tr("VPpNnLlIi", "0SSI")], func, call_type, *rest)

in Win32API.rb? Because most of Windows APIs use STDCALL convention.

I've no idea why i386-mswin32(VC) and i386-mingw32 worked with :cdcel...

Updated by Roger Pack over 2 years ago

Interesting. Does indeed work ok with mingw 1.9.1


>> func = Win32API.new('Kernel32', 'GetModuleHandle', 'I', 'I')
=> #<Win32API:0x159e100 @proto="I", @func=#<DL::CFunc:0x143e270 ptr=0x7c80b741 type=5 name='GetModuleHandle'>>

-=r

Updated by Br Hug over 2 years ago

Fixed already: http://redmine.ruby-lang.org/repositories/revision/1?rev=22889

sorry.

Updated by Yuki Sonoda over 2 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF