[Q] ruby 1.8.6 p287 and p383 crashing in WIN32OLE_EVENT.message_loop

C

Chuck Remes

Sorry for the long subject. I wanted to make sure folks interested in
WIN32OLE stuff saw it.

Anyway, I am doing some application automation on Windows using the
WIN32OLE classes. In this particular case, I have registered event
handlers for a bunch of possible events that may be generated by
another Windows application. I have tested about a dozen of these
handlers and all is well. However, I added one more and now when I
trigger the event that calls it, ruby crashes.

If I am using ruby 1.8.6 patch level 287, it generates a segfault and
writes the usual message:

It also gives me a line number in my code. This line corresponds to
this code:

WIN32OLE_EVENT.message_loop

I took the error message at face value and decided this was a ruby bug
so I upgraded to patch level 383. (For this installation I used the
one-click installer available from rubyinstaller.org, preview 2).

It still crashes but now it doesn't give me any code line or write any
message at all.

I'm not well versed in Windows programming so I don't really know how
to debug this. Here is what I have tried:

1. I've narrowed the "cause" down to the line of code that generates
the event that the handler will get on the next call to
WIN32OLE_EVENT.message_loop. If I comment it out, the program
continues to run. With it in, the program crashes.

The line in question is calling a method on a WIN32OLE COM object that
was previously retrieved via WIN32OLE.new. The method called generates
a callback event after it finishes processing. This same COM object is
also used for making other method calls that are all succeeding just
fine.

2. I thought that perhaps I had a bug in my event handler code. I
commented it out. The crash still occurs.

This leads me to believe that the event being received is causing the
crash. I have *no idea* how to get deeper on this without getting the
ruby C source and mucking about inside the #message_loop code.

Anyone have any ideas on how I can solve this? If you need more
information, let me know. At this point this crash is a showstopper
for me because I *need* to be able to process the event that is
causing the crash.

cr
 
D

Daniel Berger

Sorry for the long subject. I wanted to make sure folks interested in =A0
WIN32OLE stuff saw it.

Anyway, I am doing some application automation on Windows using the =A0
WIN32OLE classes. In this particular case, I have registered event =A0
handlers for a bunch of possible events that may be generated by =A0
another Windows application. I have tested about a dozen of these =A0
handlers and all is well. However, I added one more and now when I =A0
trigger the event that calls it, ruby crashes.

If I am using ruby 1.8.6 patch level 287, it generates a segfault and =A0
writes the usual message:


It also gives me a line number in my code. This line corresponds to =A0
this code:

WIN32OLE_EVENT.message_loop

I took the error message at face value and decided this was a ruby bug = =A0
so I upgraded to patch level 383. (For this installation I used the =A0
one-click installer available from rubyinstaller.org, preview 2).

It still crashes but now it doesn't give me any code line or write any = =A0
message at all.

I'm not well versed in Windows programming so I don't really know how =A0
to debug this. Here is what I have tried:

1. I've narrowed the "cause" down to the line of code that generates =A0
the event that the handler will get on the next call to =A0
WIN32OLE_EVENT.message_loop. If I comment it out, the program =A0
continues to run. With it in, the program crashes.

The line in question is calling a method on a WIN32OLE COM object that = =A0
was previously retrieved via WIN32OLE.new. The method called generates = =A0
a callback event after it finishes processing. This same COM object is = =A0
also used for making other method calls that are all succeeding just =A0
fine.

2. I thought that perhaps I had a bug in my event handler code. I =A0
commented it out. The crash still occurs.

This leads me to believe that the event being received is causing the =A0
crash. I have *no idea* how to get deeper on this without getting the =A0
ruby C source and mucking about inside the #message_loop code.

Anyone have any ideas on how I can solve this? If you need more =A0
information, let me know. At this point this crash is a showstopper =A0
for me because I *need* to be able to process the event that is =A0
causing the crash.

I know we discussed this a bit offline, but I'm curious if you see the
same behavior with pr-win32ole. You can checkout the code at:

svn checkout http://pure.rubyforge.org/svn/pr-win32ole

I'm curious if it exhibits the same behavior. If it does, we can
probably figure out what's wrong with the C code, too. With pr-
win32ole, you can at least use the debugger. :)

Regards,

Dan

PS - No folks, pr-win32ole has not been officially released yet.
 
C

Chuck Remes

I know we discussed this a bit offline, but I'm curious if you see the
same behavior with pr-win32ole. You can checkout the code at:

svn checkout http://pure.rubyforge.org/svn/pr-win32ole

I'm curious if it exhibits the same behavior. If it does, we can
probably figure out what's wrong with the C code, too. With pr-
win32ole, you can at least use the debugger. :)

It can't seem to load a few of its dependencies like "windows/com".

1. The gem doesn't have a dependency on the windows-api gem.

2. The windows-api gem, after installation, doesn't have a lot of the
files that pr-win32ole wants to load.

#2 leads me to believe that you have a super-secret version of the
windows-api gem containing all this cool new stuff but it hasn't been
released yet.

Where can I find this super-secret code? Alternately, email me the gem
at the above address. :)

cr
 
D

Daniel Berger

It can't seem to load a few of its dependencies like "windows/com".

1. The gem doesn't have a dependency on the windows-api gem.

2. The windows-api gem, after installation, doesn't have a lot of the =A0
files that pr-win32ole wants to load.

There is no gem for pr-win32ole. All you should need to do is:

gem install windows-pr

That should install win32-api and windows-api automatically. It should
then "just work" as long as RUBYOPT is set. If it doesn't, please give
me a specific error you're getting.

Regards,

Dan
 
C

Chuck Remes

There is no gem for pr-win32ole. All you should need to do is:

gem install windows-pr

That should install win32-api and windows-api automatically. It should
then "just work" as long as RUBYOPT is set. If it doesn't, please give
me a specific error you're getting.

Well, I ran 'gem build pr-winole32.gemspec' so it was easy to install.

I now have everything up and going. When I run my program, it crashes
on a call to WIN32OLE_EVENT.message_loop.

starting...
C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:
701:in `[]=': index 8 out of string (IndexError)
from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
win32ole.rb:701:in `ole_val2variant'
from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
win32ole.rb:4481
from (eval):3:in `call'
from (eval):3:in `DispatchMessage'
from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
win32ole.rb:5034:in `ole_msg_loop'
from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
win32ole.rb:5039:in `message_loop'
from //.host/Shared Folders/My Documents/NetBeansProjects/
ChuckKit/lib/main.rb:165

If that trace looks crappy, view it here: http://pastie.org/603650

I need to point out that it is crashing way earlier than the stock
WIN32OLE stuff. This test program works just fine using MRI's WIN32
classes. I figured once I had everything up and going I could trigger
that event which was causing my other code to bomb out.

cr
 
C

Chuck Remes

There is no gem for pr-win32ole. All you should need to do is:

gem install windows-pr

That should install win32-api and windows-api automatically. It
should
then "just work" as long as RUBYOPT is set. If it doesn't, please
give
me a specific error you're getting.

Well, I ran 'gem build pr-winole32.gemspec' so it was easy to install.

I now have everything up and going. When I run my program, it
crashes on a call to WIN32OLE_EVENT.message_loop.

starting...
C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:
701:in `[]=': index 8 out of string (IndexError)
from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
win32ole.rb:701:in `ole_val2variant'
from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
win32ole.rb:4481
from (eval):3:in `call'
from (eval):3:in `DispatchMessage'
from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
win32ole.rb:5034:in `ole_msg_loop'
from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
win32ole.rb:5039:in `message_loop'
from //.host/Shared Folders/My Documents/NetBeansProjects/
ChuckKit/lib/main.rb:165

If that trace looks crappy, view it here: http://pastie.org/603650

Okay, dug into the pr-win32ole code and this is what I found.

Line 701 was trying to access index 8 of a string with only 4
characters. Backing up the stack I looked at where it was passed in
from and see that the +pvarResult+ variable passed into the lambda had
the value "\n\000". The lambda in question is on line 4400.

I don't know this code well enough to say where that came from
originally, but that explains the IndexError anyway. It looks like the
code that operates on those strings assumes they are 16 characters
long. That assumption blew it up.

cr
 
M

Masaki Suketa

Hello,

Okay, dug into the pr-win32ole code and this is what I found.

Line 701 was trying to access index 8 of a string with only 4
characters. Backing up the stack I looked at where it was passed in from
and see that the +pvarResult+ variable passed into the lambda had the
value "\n\000". The lambda in question is on line 4400.

I don't know this code well enough to say where that came from
originally, but that explains the IndexError anyway. It looks like the
code that operates on those strings assumes they are 16 characters long.
That assumption blew it up.

How about commenting the 3 lines from line 4480 to line 4482?
Does it work?

ary2ptr_dispparams(outargv, pdispparams)
end

# if pvarResult
# WIN32OLE.ole_val2variant(result,pvarResult)
# end
S_OK
})

Regards,
Masaki Suketa
 
C

Chuck Remes

Hello,



How about commenting the 3 lines from line 4480 to line 4482?
Does it work?

ary2ptr_dispparams(outargv, pdispparams)
end

# if pvarResult
# WIN32OLE.ole_val2variant(result,pvarResult)
# end
S_OK
})

Commenting out those lines fixes (hides?) the problem described above.
It now runs the program successfully.

However, this pure ruby version of the library still crashes when I
run the code described in my original post. It crashes without writing
any error message to the Output window in NetBeans. I *assume* it is
crashing somewhere in #message_loop but I don't know that for sure.

Is there any easy way to instrument the win32ole code so I can
pinpoint the crash location?

cr
 
M

Masaki Suketa

Hello,

Commenting out those lines fixes (hides?) the problem described above.
It now runs the program successfully.

However, this pure ruby version of the library still crashes when I run
the code described in my original post. It crashes without writing any
error message to the Output window in NetBeans. I *assume* it is
crashing somewhere in #message_loop but I don't know that for sure.

Is there any easy way to instrument the win32ole code so I can pinpoint
the crash location?

I would like to know more detail about the event when the code
crashes.

Anyway, I am doing some application automation on Windows using the
WIN32OLE classes. In this particular case, I have registered event
handlers for a bunch of possible events that may be generated by another
Windows application. I have tested about a dozen of these handlers and
all is well. However, I added one more and now when I trigger the event
that calls it, ruby crashes.

Does the event expect the return value from event handler?
If so, what kind of the return value the event expect?
For example, the NavigateComplete2 of InternetExplorer is as following,
and does not expect the return value(VOID).

VOID NavigateComplete2(pDisp[in], URL[in])

Or could you show me the IDL of the event?

Regards,
Masaki Suketa
 
D

Daniel Berger

On Sep 2, 2009, at 4:43 PM, Daniel Berger wrote:
Well, I ran 'gem build pr-winole32.gemspec' so it was easy to install.
I now have everything up and going. When I run my program, it =A0
crashes on a call toWIN32OLE_EVENT.message_loop.
starting...
C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:
701:in `[]=3D': index 8 out of string (IndexError)
=A0 =A0 =A0 =A0from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/li= b/pr/
win32ole.rb:701:in `ole_val2variant'
=A0 =A0 =A0 =A0from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/li= b/pr/
win32ole.rb:4481
=A0 =A0 =A0 =A0from (eval):3:in `call'
=A0 =A0 =A0 =A0from (eval):3:in `DispatchMessage'
=A0 =A0 =A0 =A0from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/li= b/pr/
win32ole.rb:5034:in `ole_msg_loop'
=A0 =A0 =A0 =A0from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/li= b/pr/
win32ole.rb:5039:in `message_loop'
=A0 =A0 =A0 =A0from //.host/Shared Folders/My Documents/NetBeansProject= s/
ChuckKit/lib/main.rb:165
If that trace looks crappy, view it here: =A0http://pastie.org/603650

Okay, dug into the pr-win32ole code and this is what I found.

Line 701 was trying to access index 8 of a string with only 4 =A0
characters. Backing up the stack I looked at where it was passed in =A0
from and see that the +pvarResult+ variable passed into the lambda had = =A0
the value "\n\000". =A0The lambda in question is on line 4400.

I don't know this code well enough to say where that came from =A0
originally, but that explains the IndexError anyway. It looks like the = =A0
code that operates on those strings assumes they are 16 characters =A0
long. That assumption blew it up.

It's been fixed in SVN. I'm curious if your code works with the
updated version.

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top