Daniel Berger
2007-Nov-03 13:37 UTC
[Win32utils-devel] Service.services bug (pure Ruby version)
Hi all, I''ve hit a curious bug in the Service.services method. This is in the pure Ruby version in CVS. Check it out and run this snippet: Service.services{ |s| p s.service_name p s.display_name } That will segfault after about 14 entries for me. It appears to be a problem with memcpy on line 658, but I couldn''t tell you why. The interesting thing is that the more I use ''puts'', the less likely this error is to occur. To show you what I mean, try this snippet: Service.services{ |s| puts s.service_name p s.display_name } That gets further, but will still segfault. Now try this: Service.services{ |s| puts s.service_name puts s.display_name } That one gets me through all services without segfaulting. I know I''ve seen various reports over the years of a ''puts'' that made bugs mysteriously disappear, so I''m wondering if I''ve hit upon something. Can anyone tell me what''s going on? Thanks, Dan
Heesob Park
2007-Nov-03 16:37 UTC
[Win32utils-devel] Service.services bug (pure Ruby version)
Hi, 2007/11/3, Daniel Berger <djberg96 at gmail.com>:> > Hi all, > > I''ve hit a curious bug in the Service.services method. This is in the > pure Ruby version in CVS. Check it out and run this snippet: > > Service.services{ |s| > p s.service_name > p s.display_name > } > > That will segfault after about 14 entries for me. It appears to be a > problem with memcpy on line 658, but I couldn''t tell you why. > > The interesting thing is that the more I use ''puts'', the less likely > this error is to occur. To show you what I mean, try this snippet: > > Service.services{ |s| > puts s.service_name > p s.display_name > } > > That gets further, but will still segfault. Now try this: > > Service.services{ |s| > puts s.service_name > puts s.display_name > } > > That one gets me through all services without segfaulting. > > I know I''ve seen various reports over the years of a ''puts'' that made > bugs mysteriously disappear, so I''m wondering if I''ve hit upon > something. Can anyone tell me what''s going on? > > Thanks, > > DanThe segfaulting is due to the memcpy in service.rb dep_buf = 0.chr * 260 memcpy(dep_buf, config_buf[24,4].unpack(''L'').first, dep_buf.size) dependencies = dep_buf.split("\000\000").first.split(0.chr) Here is an agly but working code: dep_buf = "" psz_depend = config_buf[24,4].unpack(''L'').first while psz_depend!=0 char_buf = 0.chr memcpy(char_buf, psz_depend, 1) psz_depend += 1 dep_buf += char_buf break if dep_buf[-2,2]=="\0\0" end dependencies = [] if dep_buf != "\0\0" dependencies = dep_buf.split("\000\000").first.split(0.chr) end Regards, Park Heesob -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20071104/58155fa9/attachment.html
Daniel Berger
2007-Nov-04 01:12 UTC
[Win32utils-devel] Service.services bug (pure Ruby version)
Heesob Park wrote: <snip>> The segfaulting is due to the memcpy in service.rb > > dep_buf = 0.chr * 260 > memcpy(dep_buf, config_buf[24,4].unpack(''L'').first, > dep_buf.size) > dependencies = dep_buf.split("\000\000").first.split(0.chr) > > Here is an agly but working code: > > dep_buf = "" > psz_depend = config_buf[24,4].unpack(''L'').first > while psz_depend!=0 > char_buf = 0.chr > memcpy(char_buf, psz_depend, 1) > psz_depend += 1 > dep_buf += char_buf > break if dep_buf[-2,2]=="\0\0" > end > dependencies = [] > if dep_buf != "\0\0" > dependencies = dep_buf.split("\000\000").first.split(0.chr) > end > > Regards, > > Park HeesobExcellent, that works, thanks! It does seem like there ought to be a more efficient way, but we can worry about that later. Thanks, Dan