I finally got a clean compile and link for wxRuby. Now I''m down to deciphering runtime errors. Once again, I''m going to pick up on this tomorrow, but I thought I''d post my console output tonight to see if anyone has any thoughts before I tackle this tomorrow. I''m running the same app "minimal.rb" E:\Dev\RubyDev\wxruby\samples\minimal>ruby minimal.rb 18:24:27: Debug: E:\Dev\RubyDev\wxWindows-2.4.1/include\wx/datetime.h(1445): ass ert "t1.IsValid() && t2.IsValid()" failed: invalid wxDateTime minimal.rb:52:in `OnInit'': uninitialized constant RbApp::Point (NameError) from minimal.rb:59:in `initialize'' from minimal.rb:59:in `new'' from minimal.rb:59 E:\Dev\RubyDev\wxruby\samples\minimal> Curt
Curt Hibbs wrote:> I finally got a clean compile and link for wxRuby.Hooray!> E:\Dev\RubyDev\wxruby\samples\minimal>ruby minimal.rb > 18:24:27: Debug: E:\Dev\RubyDev\wxWindows-2.4.1/include\wx/datetime.h(1445): > ass > ert "t1.IsValid() && t2.IsValid()" failed: invalid wxDateTime > minimal.rb:52:in `OnInit'': uninitialized constant RbApp::Point (NameError) > from minimal.rb:59:in `initialize'' > from minimal.rb:59:in `new'' > from minimal.rb:59 > E:\Dev\RubyDev\wxruby\samples\minimal>Very strange. I would strongly recommend starting with nothing.rb instead of minimal.rb, because minimal.rb really isn''t "minimal" at all. The assert is firing because for some reason, it is comparing two wxDateTime objects to see if they are equal, but one (or both) is not a valid wxDateTime. The minimal app does nothing with dates. wxRuby initializes a constant for the current date, but that happens during init, which would have put the require statement in the stack trace. Fortunately, this only seems to be a warning, and not fatal. I don''t know why Point isn''t found. It apparently found App ok. You might try doing this right after the include Wx line, as an experiment: p = Point.new(0,0) Kevin
Kevin Smith wrote:> > Curt Hibbs wrote: > > I finally got a clean compile and link for wxRuby. > > Hooray! > > > E:\Dev\RubyDev\wxruby\samples\minimal>ruby minimal.rb > > 18:24:27: Debug: > E:\Dev\RubyDev\wxWindows-2.4.1/include\wx/datetime.h(1445): > > ass > > ert "t1.IsValid() && t2.IsValid()" failed: invalid wxDateTime > > minimal.rb:52:in `OnInit'': uninitialized constant RbApp::Point > (NameError) > > from minimal.rb:59:in `initialize'' > > from minimal.rb:59:in `new'' > > from minimal.rb:59 > > E:\Dev\RubyDev\wxruby\samples\minimal> > > Very strange. > > I would strongly recommend starting with nothing.rb instead of > minimal.rb, because minimal.rb really isn''t "minimal" at all. > > The assert is firing because for some reason, it is comparing two > wxDateTime objects to see if they are equal, but one (or both) is not a > valid wxDateTime. The minimal app does nothing with dates. wxRuby > initializes a constant for the current date, but that happens during > init, which would have put the require statement in the stack trace. > Fortunately, this only seems to be a warning, and not fatal. > > I don''t know why Point isn''t found. It apparently found App ok. You > might try doing this right after the include Wx line, as an experiment: > p = Point.new(0,0)Actually, I did run nothing.rb first. I got the same assert warnings on wxDateTime, but the window frame did some up. Looks like I need to build a debug version of Ruby -- as it stands MSVC won''t let me set breakpoints or trace execution and I''m pretty sure its because Ruby itself is not a debug version (even though my wxruby.so *is* a debug version). Curt
The reason I couldn''t set breakpoints wasn''t because I needed a debug version of Ruby, it was because I hadn''t set the linker option to create a debug library. I now know a little more about what is going on (but still no final answer)... First, I think the wxDateTime asserts are an annoying red herring that are occurring because I''m using a debug build of wxWindows (have you tried building and running a debug version of wxWindows/wxRuby?). The origin of this assert is line 834 in wxRuby''s const.cpp: rb_define_const(mWx,"DEFAULT_DATE_TIME", WxDateTime::init0(wxDefaultDateTime)); The problem here is that wxDefaultDateTime is an alias for wxInvalidDateTime, which is meant to represent a wxDateTime object with an invalid value. So, in date.cpp with this is called: VALUE WxDateTime::init0(const wxDateTime &dateTime) { VALUE self = Data_Wrap_Struct(rubyClass, 0, 0, 0); if(dateTime == wxDefaultDateTime) DATA_PTR(self) = (void*)&wxDefaultDateTime; else DATA_PTR(self) = new wxDateTime(dateTime.GetTicks()); return self; } the if statement compares the parameter dateTime with wxDefaultDateTime. They are, in fact equal, but the operator== code in wxWindows does an assert on whether the values of both operands are valid. Since neither one is valid, you get to assert errors (one for each operand). I have two questions here: 1) would it make sense to use a valid wxDateTime value for DEFAULT_DATE_TIME? and 2) do you get the same asserts if you run with a debug build? If I just ignore these asserts nothing.rb runs just fine (doing nothing, of course!). I did notice one thing that must be a benign error: the first few lines of WxApp::init (in app.cpp) are: VALUE WxApp::init(VALUE self) { wxAppWithCallbacks *pCppSelf = GetPtr(self); pCppSelf = new wxAppWithCallbacks(); DATA_PTR(self) = pCppSelf; The first line assigning a value to pCppSelf, then the next line simply overwrites it. I think the first line can be deleted. Anyway, I''ll now move from nothing.rb to minimal.rb. Curt
Kevin Smith
2003-Nov-06 10:15 UTC
[Wxruby-users] Inefficient .cpp code (was: nothing.rb and wxDateTime asserts)
Curt Hibbs wrote:> I did notice one thing that must be a benign error: the first few lines of > WxApp::init (in app.cpp) are: > > VALUE WxApp::init(VALUE self) > { > wxAppWithCallbacks *pCppSelf = GetPtr(self); > pCppSelf = new wxAppWithCallbacks(); > DATA_PTR(self) = pCppSelf; > > The first line assigning a value to pCppSelf, then the next line simply > overwrites it. I think the first line can be deleted.Yes, this is a potential code generation optimization in wxpp.rb. There are several others similar to this. So far, I have emphasized simplicity of the wxpp.rb implementation over efficiency of the .cpp output. Thanks, Kevin
Curt Hibbs wrote:> First, I think the wxDateTime asserts are an annoying red herring that are > occurring because I''m using a debug build of wxWindows (have you tried > building and running a debug version of wxWindows/wxRuby?).I just switched to using a debug version of wxGtk, and I am not getting those wxDateTime assert warnings. I haven''t yet looked back at the source code to see if that makes sense. Or maybe they removed the warning in 2.4.2? I no longer have 2.4.1 installed on my system (with Debian, it''s a bit of a pain to get the older version back), so I can''t easily compare the two. As an aside, I''m still fighting the segfaults with TextCtrl. No progress yet.> would it make sense to use a valid wxDateTime > value for DEFAULT_DATE_TIME?If the C++ version returns in invalid value for DEFAULT_DATE_TIME, then the wxRuby version should do that as well. There should be a way to change the == test in our code to avoid triggering the problem. Kevin