Win32OLE again

I am having trouble trying to figure out what is wrong with the Win32ole
extension when running on 1.8.0. I have narrowed it down to the calling
of

ALLOC_N and freeing what is returned from there.

If I just call malloc and free that pointer, that works OK.

I looked at some other ruby extensions and they don’t call ALLOC_N.

I looked at the ruby source and it seems that ALLOC_N is just a call to
ruby_malloc which in turn calls malloc. So I should be able to free it
just fine.

Please anyone who has written C extensions or the author of Win32OLE,
let me know what is wrong with calling free on pointers allocated with
ALLOC_N.

Thanks in advance,

Steve Tuckner

Please anyone who has written C extensions or the author of Win32OLE,
let me know what is wrong with calling free on pointers allocated with
ALLOC_N.

Well there is nothing wrong with calling free with ALLOC_N because like
you've found ALLOC_N is just a call to malloc().

But if it exist an error in the C extensions (bad memory management
*elsewhere*) then the memory pool can be corrupted and this can explain
the crash.

Perhaps the error is in the extension Win32OLE (well, I don't know what
do this extension and I've not looked at the source)

Guy Decoux

Ok here are some bizarre results.

When I reduce my script to just a require and a new call, and I reduce the
extension to defining one real method, then I can make it fail depending on
how many other methods I define. In my Init_win32ole2 function, I define n
dummy methods. If I define 35 or below of them, it will get through the new
call. If I define 36 or above of them it will segfault. I found this by
discovering that if I commented out some of the method, class, etc,
definitions in the real Init_win32ole function, then it started to work.

My build environment is Visual C++ 6. The makefile was generated by the
extconf.rb that came with win32ole. I just modified it to use win32ole2
instead.

Does anyone have any ideas what is going wrong here or how I should proceed
further? I feel that I have reduced it down to the bare minimum so there
must be something simple that is not being done for 1.8. This test works in
1.6 with values as high as 1000.

Thanks,

Steve Tuckner

From: ts [mailto:decoux@moulon.inra.fr]
Sent: Wednesday, October 29, 2003 5:35 AM
To: ruby-talk ML
Cc: ruby-talk@ruby-lang.org
Subject: Re: Win32OLE again

Please anyone who has written C extensions or the author
of Win32OLE,
let me know what is wrong with calling free on pointers
allocated with
ALLOC_N.

Well there is nothing wrong with calling free with ALLOC_N
because like
you’ve found ALLOC_N is just a call to malloc().

But if it exist an error in the C extensions (bad memory management
elsewhere) then the memory pool can be corrupted and this
can explain
the crash.

Perhaps the error is in the extension Win32OLE (well, I
don’t know what
do this extension and I’ve not looked at the source)

Guy Decoux

=0A=
SHELL =3D /bin/sh=0A=
=0A=

Start of system configuration section. ####=0A=

=0A=
srcdir =3D .=0A=
topdir =3D $(rubylibdir)/$(arch)=0A=
hdrdir =3D $(rubylibdir)/$(arch)=0A=
VPATH =3D $(srcdir)=0A=
=0A=
DESTDIR =3D d:=0A=
prefix =3D $(DESTDIR)/a/ruby180=0A=
exec_prefix =3D $(prefix)=0A=
bindir =3D $(exec_prefix)/bin=0A=
sitelibdir =3D $(sitedir)/$(ruby_version)=0A=
datadir =3D $(prefix)/share=0A=
sitedir =3D $(prefix)/lib/ruby/site_ruby=0A=
sharedstatedir =3D $(DESTDIR)/etc=0A=
archdir =3D $(rubylibdir)/$(arch)=0A=
localstatedir =3D $(DESTDIR)/var=0A=
infodir =3D $(prefix)/info=0A=
oldincludedir =3D $(DESTDIR)/usr/include=0A=
libexecdir =3D $(exec_prefix)/libexec=0A=
compile_dir =3D =
$(DESTDIR)/pp/ruby/installer/ruby180/download/ruby/win32=0A=
sbindir =3D $(exec_prefix)/sbin=0A=
includedir =3D $(prefix)/include=0A=
sysconfdir =3D $(prefix)/etc=0A=
sitearchdir =3D $(sitelibdir)/$(sitearch)=0A=
mandir =3D $(prefix)/man=0A=
libdir =3D $(exec_prefix)/lib=0A=
rubylibdir =3D $(libdir)/ruby/$(ruby_version)=0A=
=0A=
CC =3D cl -nologo=0A=
LIBRUBY =3D $(RUBY_SO_NAME).lib=0A=
LIBRUBY_A =3D $(RUBY_SO_NAME)-static.lib=0A=
LIBRUBYARG_SHARED =3D $(LIBRUBY)=0A=
LIBRUBYARG_STATIC =3D $(LIBRUBY_A)=0A=
=0A=
CFLAGS =3D /W3 =0A=
CPPFLAGS =3D -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) -I. -I./… =
-I./…/missing=0A=
CXXFLAGS =3D $(CFLAGS) =0A=
DLDFLAGS =3D -link -incremental:no -pdb:none -dll $(LIBPATH) =
-def:$(DEFFILE) =0A=
LDSHARED =3D cl -nologo -LD=0A=
AR =3D lib -nologo=0A=
EXEEXT =3D .exe=0A=
=0A=
RUBY_INSTALL_NAME =3D ruby=0A=
RUBY_SO_NAME =3D msvcrt-ruby18=0A=
arch =3D i386-mswin32=0A=
sitearch =3D i386-msvcrt=0A=
ruby_version =3D 1.8=0A=
RUBY =3D ruby=0A=
RM =3D $(RUBY) -rftools -e “File::rm_f(*ARGV.map =
do>x>Dirend.flatten.uniq)”=0A=
MAKEDIRS =3D $(RUBY) -r ftools -e ‘File::makedirs(*ARGV)’=0A=
INSTALL_PROG =3D $(RUBY) -r ftools -e ‘File::install(ARGV[0], ARGV[1], =
0755, true)’=0A=
INSTALL_DATA =3D $(RUBY) -r ftools -e ‘File::install(ARGV[0], ARGV[1], =
0644, true)’=0A=
=0A=

End of system configuration section. ####=0A=

=0A=
=0A=
LIBPATH =3D -libpath:“$(libdir)”=0A=
DEFFILE =3D win32ole2.def=0A=
=0A=
CLEANFILES =3D =0A=
DISTCLEANFILES =3D =0A=
=0A=
target_prefix =3D =0A=
LOCAL_LIBS =3D =0A=
LIBS =3D $(LIBRUBYARG_SHARED) advapi32.lib user32.lib uuid.lib =
oleaut32.lib ole32.lib oldnames.lib user32.lib advapi32.lib =
wsock32.lib =0A=
OBJS =3D win32ole2.obj=0A=
TARGET =3D win32ole2=0A=
DLLIB =3D $(TARGET).so=0A=
=0A=
RUBYCOMMONDIR =3D $(sitedir)$(target_prefix)=0A=
RUBYLIBDIR =3D $(sitelibdir)$(target_prefix)=0A=
RUBYARCHDIR =3D $(sitearchdir)$(target_prefix)=0A=
=0A=
CLEANLIBS =3D “$(TARGET).{lib,exp,il?,tds,map}” $(DLLIB)=0A=
CLEANOBJS =3D ".{obj,lib,s[ol],pdb,bak}"=0A=
=0A=
all: $(DLLIB)=0A=
=0A=
clean:=0A=
@$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)=0A=
=0A=
distclean: clean=0A=
@$(RM) Makefile extconf.h conftest.
mkmf.log=0A=
@$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)=0A=
=0A=
realclean: distclean=0A=
install: $(RUBYARCHDIR)=0A=
install: $(RUBYARCHDIR)/$(DLLIB)=0A=
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB) $(RUBYARCHDIR)=0A=
@$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)=0A=
install: $(RUBYLIBDIR)=0A=
install: $(RUBYLIBDIR)/oleproperty.rb=0A=
$(RUBYLIBDIR)/oleproperty.rb: $(srcdir)/lib/oleproperty.rb =
$(RUBYLIBDIR)=0A=
@$(INSTALL_DATA) $(srcdir)/lib/oleproperty.rb $(RUBYLIBDIR)=0A=
$(RUBYARCHDIR):=0A=
@$(MAKEDIRS) $(RUBYARCHDIR)=0A=
$(RUBYLIBDIR):=0A=
@$(MAKEDIRS) $(RUBYLIBDIR)=0A=
=0A=
site-install: install=0A=
=0A=
.SUFFIXES: .c .cc .m .cxx .cpp .C .obj=0A=
=0A=
{$(srcdir)}.cc{}.obj:=0A=
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:=3D/)=0A=
=0A=
.cc.obj:=0A=
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:=3D/)=0A=
=0A=
{$(srcdir)}.cpp{}.obj:=0A=
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:=3D/)=0A=
=0A=
.cpp.obj:=0A=
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:=3D/)=0A=
=0A=
{$(srcdir)}.cxx{}.obj:=0A=
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:=3D/)=0A=
=0A=
.cxx.obj:=0A=
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:=3D/)=0A=
=0A=
{$(srcdir)}.C{}.obj:=0A=
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:=3D/)=0A=
=0A=
.C.obj:=0A=
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:=3D/)=0A=
=0A=
{$(srcdir)}.c{}.obj:=0A=
$(CC) $(CFLAGS) $(CPPFLAGS) -c -Tc$(<:=3D/)=0A=
=0A=
.c.obj:=0A=
$(CC) $(CFLAGS) $(CPPFLAGS) -c -Tc$(<:=3D/)=0A=
=0A=
$(DLLIB): $(OBJS)=0A=
@-$(RM) $@=0A=
@-$(RM) $(TARGET).lib=0A=
$(LDSHARED) -Fe$(@) $(OBJS) $(LIBS) $(LOCAL_LIBS) $(DLDFLAGS)=0A=
=0A=
###=0A=
win32ole2.obj : $(hdrdir)/ruby.h $(hdrdir)/config.h =
$(hdrdir)/defines.h=0A=

#include “ruby.h”
static VALUE
fev_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
char *pstr;
printf(“In WIN32OLE_EVENT.new\n”);

	pstr = ALLOC_N(char, 11);
	printf("pstr = %8.8lx\n", pstr);
  printf("In WIN32OLE_EVENT.new 1\n");
	free(pstr);
	printf("In WIN32OLE_EVENT.new 2\n");

}

static VALUE dummy_method(VALUE self)
{
}

VALUE cWIN32OLE_EVENT;
void
Init_win32ole2()
{
int i;
char s[100];

cWIN32OLE_EVENT = rb_define_class("WIN32OLE_EVENT", rb_cObject);
 for (i = 0; i < 35; i++) {
	 sprintf(s, "default%d", i);
	 rb_define_method(cWIN32OLE_EVENT, s, dummy_method, 0);
 }
rb_define_singleton_method(cWIN32OLE_EVENT, "new", fev_s_new, -1);

}

EXPORTS=0A=
Init_win32ole2=0A=

require “win32ole2”

ev = WIN32OLE_EVENT.new()

···

-----Original Message-----

Steve Tuckner wrote:

Does anyone have any ideas what is going wrong here or how I
should proceed further? I feel that I have reduced it down to
the bare minimum so there must be something simple that is
not being done for 1.8. This test works in
1.6 with values as high as 1000.

I haven’t had any problems with the value = 100035 for ruby -v

1.8.1 (2003-10-25) [i386-mswin32] (compiled with VC 7.1) and
1.8.0 (2003-9-18) [i386-mingw32]

So probably upgrading to cvs should help (maybe it is compiler
thing but I doubt it).

···

/Christoph

Please send off list mail to
‘my_mail@gmy.net’.gsub(/y/,‘x’)

Steve Tuckner wrote:

My build environment is Visual C++ 6. The makefile was
generated by the extconf.rb that came with win32ole. I just
modified it to use win32ole2 instead.

Hm, maybe that’s the problem - try the makefile generate by

ruby -rmkmf -e ‘create_makefile(“win32ole2”)’

instead

···

/Christoph

Please send off list mail to
‘my_mail@gmy.net’.gsub(/y/,‘x’)

You were right! Thank you Thank you Thank you :slight_smile: (I am smiling widely).

For some reason the extconf.rb that comes with win32ole generates the CFLAGS
with only /W3 as an option. When I run

ruby -rmkmf -e ‘create_makefile(“win32ole2”)’

The make file created contains the following options:

CFLAGS = -MD -Zi -O2b2xg- -G6

The one that makes difference is the -MD which enables the use of the
Multi-Threaded Library. It didn’t build because it didn’t include the
correct libraries that are in the makefile created by extconf.rb. So I just
added /MD to options of that makefile and viola it worked!

I don’t have a web site to put the version that works on there, but if you
email me, I will send you the version that works.

If you have Visual C++, then just get Win32Ole and add the options above to
the CFLAGS line of the makefile created by extconf.rb.

Thanks to all for your help!

Steve Tuckner

···

-----Original Message-----
From: Christoph [mailto:chr_mail@gmx.net]
Sent: Wednesday, October 29, 2003 11:38 AM
To: ruby-talk ML
Subject: Re: Win32OLE again

Steve Tuckner wrote:

My build environment is Visual C++ 6. The makefile was
generated by the extconf.rb that came with win32ole. I just
modified it to use win32ole2 instead.

Hm, maybe that’s the problem - try the makefile generate by

ruby -rmkmf -e ‘create_makefile(“win32ole2”)’

instead


/Christoph

Please send off list mail to
‘my_mail@gmy.net’.gsub(/y/,‘x’)

Steve Tuckner wrote:

You were right! Thank you Thank you Thank you :slight_smile: (I am
smiling widely).

It was just only wild guess, but I am happy that this worked out.

For some reason the extconf.rb that comes with win32ole
generates the CFLAGS with only /W3 as an option. When I run

That’s kind of odd isn’t it? The CFLAGS of my win32ole extension
makefile just look ``normal’’ - in particular they include the -MD
option. Maybe just regenerating the makefile by running

ruby path_your_win32ole_directory/extconf.rb

manually would have fixed the problem too? If the makefile
of other standard extension are missing the MD flag too you
probably should recompile all your standard extension? (just
erasing the ext directory of your compilation directory

  • make might do the trick)
···

/Christoph

Please send off list mail to
‘my_mail@gmy.net’.gsub(/y/,‘x’)

Note that the win32ole in the Prag Programmers distribution for 1.8.0 is
broken also.

···

-----Original Message-----
From: Christoph [mailto:chr_mail@gmx.net]
Sent: Wednesday, October 29, 2003 3:25 PM
To: ruby-talk ML
Subject: Re: Win32OLE again - solved

Steve Tuckner wrote:

You were right! Thank you Thank you Thank you :slight_smile: (I am
smiling widely).

It was just only wild guess, but I am happy that this worked out.

For some reason the extconf.rb that comes with win32ole
generates the CFLAGS with only /W3 as an option. When I run

That’s kind of odd isn’t it? The CFLAGS of my win32ole extension
makefile just look ``normal’’ - in particular they include the -MD
option. Maybe just regenerating the makefile by running

ruby path_your_win32ole_directory/extconf.rb

manually would have fixed the problem too? If the makefile
of other standard extension are missing the MD flag too you
probably should recompile all your standard extension? (just
erasing the ext directory of your compilation directory

  • make might do the trick)

/Christoph

Please send off list mail to
‘my_mail@gmy.net’.gsub(/y/,‘x’)