From noreply at rubyforge.org Mon Oct 1 18:00:05 2007 From: noreply at rubyforge.org (noreply at rubyforge.org) Date: Mon, 1 Oct 2007 18:00:05 -0400 (EDT) Subject: [Win32utils-devel] [ win32utils-Bugs-14360 ] Bad interaction between win32-file-stat and FileUtils Message-ID: <20071001220005.A55C05240ADA@rubyforge.org> Bugs item #14360, was opened at 2007-10-01 15:00 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=411&aid=14360&group_id=85 Category: win32-file-stat Group: Code Status: Open Resolution: None Priority: 3 Submitted By: Daniel Berger (djberg96) Assigned to: Nobody (None) Summary: Bad interaction between win32-file-stat and FileUtils Initial Comment: Ruby 1.8.6-25 (one-click) win32-file-stat 1.2.6 I already dealt with the lstat issue for the 'find' module, but I'm not sure how to fix this one off the top of my head. # stat-mv.rb require 'win32/file' require 'win32/file/stat' require 'fileutils' Dir.mkdir('foo') unless File.exists?('foo') FileUtils.touch('temp.txt') FileUtils.mv('temp.txt', 'foo') # END CODE C:\>ruby stat-mv.rb C:/ruby/lib/ruby/gems/1.8/gems/win32-file-stat-1.2.6/lib/win32/file/stat.rb:575:in `get_file_type': The system cannot fi nd the file specified. (ArgumentError) from C:/ruby/lib/ruby/gems/1.8/gems/win32-file-stat-1.2.6/lib/win32/file/stat.rb:53:in `initialize' from C:/ruby/lib/ruby/gems/1.8/gems/win32-file-0.5.4/lib/win32/file.rb:532:in `new' from C:/ruby/lib/ruby/gems/1.8/gems/win32-file-0.5.4/lib/win32/file.rb:532:in `stat' from C:/ruby/lib/ruby/1.8/fileutils.rb:1200:in `lstat' from C:/ruby/lib/ruby/1.8/fileutils.rb:1207:in `lstat!' from C:/ruby/lib/ruby/1.8/fileutils.rb:1125:in `exist?' from C:/ruby/lib/ruby/1.8/fileutils.rb:497:in `mv' from C:/ruby/lib/ruby/1.8/fileutils.rb:1395:in `fu_each_src_dest' from C:/ruby/lib/ruby/1.8/fileutils.rb:1409:in `fu_each_src_dest0' from C:/ruby/lib/ruby/1.8/fileutils.rb:1393:in `fu_each_src_dest' from C:/ruby/lib/ruby/1.8/fileutils.rb:494:in `mv' from stat-mv.rb:9 Suggestions? Dan (me) ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=411&aid=14360&group_id=85 From phasis at gmail.com Mon Oct 1 21:19:26 2007 From: phasis at gmail.com (Heesob Park) Date: Tue, 2 Oct 2007 10:19:26 +0900 Subject: [Win32utils-devel] [ win32utils-Bugs-14360 ] Bad interaction between win32-file-stat and FileUtils In-Reply-To: <20071001220005.A55C05240ADA@rubyforge.org> References: <20071001220005.A55C05240ADA@rubyforge.org> Message-ID: Hi, 2007/10/2, noreply at rubyforge.org : > > Bugs item #14360, was opened at 2007-10-01 15:00 > You can respond by visiting: > http://rubyforge.org/tracker/?func=detail&atid=411&aid=14360&group_id=85 > > Category: win32-file-stat > Group: Code > Status: Open > Resolution: None > Priority: 3 > Submitted By: Daniel Berger (djberg96) > Assigned to: Nobody (None) > Summary: Bad interaction between win32-file-stat and FileUtils > > Initial Comment: > Ruby 1.8.6-25 (one-click) > win32-file-stat 1.2.6 > > I already dealt with the lstat issue for the 'find' module, but I'm not > sure how to fix this one off the top of my head. > > # stat-mv.rb > require 'win32/file' > require 'win32/file/stat' > require 'fileutils' > > Dir.mkdir('foo') unless File.exists?('foo') > FileUtils.touch('temp.txt') > FileUtils.mv('temp.txt', 'foo') > # END CODE > > C:\>ruby stat-mv.rb > > C:/ruby/lib/ruby/gems/1.8/gems/win32-file-stat-1.2.6/lib/win32/file/stat.rb:575:in > `get_file_type': The system cannot fi > nd the file specified. (ArgumentError) > from C:/ruby/lib/ruby/gems/1.8/gems/win32-file-stat-1.2.6/lib/win32/file/stat.rb:53:in > `initialize' > from C:/ruby/lib/ruby/gems/1.8/gems/win32-file-0.5.4/lib/win32/file.rb:532:in > `new' > from C:/ruby/lib/ruby/gems/1.8/gems/win32-file-0.5.4/lib/win32/file.rb:532:in > `stat' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1200:in `lstat' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1207:in `lstat!' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1125:in `exist?' > from C:/ruby/lib/ruby/1.8/fileutils.rb:497:in `mv' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1395:in `fu_each_src_dest' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1409:in `fu_each_src_dest0' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1393:in `fu_each_src_dest' > from C:/ruby/lib/ruby/1.8/fileutils.rb:494:in `mv' > from stat-mv.rb:9 > > Suggestions? > > Dan (me) Modification of stat.rb at line #561 raise ArgumentError, get_last_error(error_num) to raise SystemCallError, get_last_error(error_num) would be a workaround for this case. Regards, Park Heesob -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20071002/36da3a45/attachment.html From djberg96 at gmail.com Mon Oct 1 23:36:57 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Mon, 01 Oct 2007 21:36:57 -0600 Subject: [Win32utils-devel] Giving folks access to Win2k In-Reply-To: References: <46FF22ED.7020804@gmail.com> <47005B70.4030402@gmail.com> Message-ID: <4701BCD9.8090101@gmail.com> Heesob Park wrote: > Hi, > > 2007/10/1, Daniel Berger >: > > Heesob Park wrote: > > Hi, > > > > > How about KpyM Telnet/SSH Server? > > > > http://www.kpym.com > > > > It is a free, open source telnet/ssh server for Windows. > > That seems to be working, thanks. > > I just realized that this might be a moot point without a static IP, > however. I've got DSL using DHCP. So, for the moment, I think I can only > login from my living room. > > Suggestions welcome. :) > > > Did you try DDNS(Dynamic DNS) service? > > www.dyndns.com > www.dnip.net > www.no-ip.com I used DynDNS - many thanks for the link! Got the virtual host setup and I can ping it. Cool. Now KpyM is complaining. I think I might need to remove it and reinstall it. I'll bet the DynDNS stuff confused it. Anyway, I'll work it out. Regards, Dan From djberg96 at gmail.com Tue Oct 2 00:28:02 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Mon, 01 Oct 2007 22:28:02 -0600 Subject: [Win32utils-devel] [ win32utils-Bugs-14360 ] Bad interaction between win32-file-stat and FileUtils In-Reply-To: References: <20071001220005.A55C05240ADA@rubyforge.org> Message-ID: <4701C8D2.8020009@gmail.com> Heesob Park wrote: > Hi, > > 2007/10/2, noreply at rubyforge.org > >: > > Bugs item #14360, was opened at 2007-10-01 15:00 > You can respond by visiting: > http://rubyforge.org/tracker/?func=detail&atid=411&aid=14360&group_id=85 > > > Category: win32-file-stat > Group: Code > Status: Open > Resolution: None > Priority: 3 > Submitted By: Daniel Berger (djberg96) > Assigned to: Nobody (None) > Summary: Bad interaction between win32-file-stat and FileUtils > > Initial Comment: > Ruby 1.8.6-25 (one-click) > win32-file-stat 1.2.6 > > I already dealt with the lstat issue for the 'find' module, but I'm > not sure how to fix this one off the top of my head. > > # stat-mv.rb > require 'win32/file' > require 'win32/file/stat' > require 'fileutils' > > Dir.mkdir('foo') unless File.exists?('foo') > FileUtils.touch('temp.txt') > FileUtils.mv('temp.txt', 'foo') > # END CODE > > C:\>ruby stat-mv.rb > > C:/ruby/lib/ruby/gems/1.8/gems/win32-file-stat-1.2.6/lib/win32/file/stat.rb:575:in > `get_file_type': The system cannot fi > nd the file specified. (ArgumentError) > from > C:/ruby/lib/ruby/gems/1.8/gems/win32-file-stat-1.2.6/lib/win32/file/stat.rb:53:in > `initialize' > from > C:/ruby/lib/ruby/gems/1.8/gems/win32-file-0.5.4/lib/win32/file.rb:532:in > `new' > from > C:/ruby/lib/ruby/gems/1.8/gems/win32-file-0.5.4/lib/win32/file.rb:532:in > `stat' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1200:in `lstat' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1207:in `lstat!' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1125:in `exist?' > from C:/ruby/lib/ruby/1.8/fileutils.rb:497:in `mv' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1395:in `fu_each_src_dest' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1409:in > `fu_each_src_dest0' > from C:/ruby/lib/ruby/1.8/fileutils.rb:1393:in `fu_each_src_dest' > from C:/ruby/lib/ruby/1.8/fileutils.rb:494:in `mv' > from stat-mv.rb:9 > > Suggestions? > > Dan (me) > > > Modification of stat.rb at line #561 > raise ArgumentError, get_last_error(error_num) > to > raise SystemCallError, get_last_error(error_num) > would be a workaround for this case. > > Regards, > > Park Heesob I guess that will have to do, until the next obscure stat error rears its ugly head that is. :) I'll get the change in tonight. Thanks, Dan From djberg96 at gmail.com Thu Oct 4 00:11:34 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Wed, 03 Oct 2007 22:11:34 -0600 Subject: [Win32utils-devel] Prototyping the Dir class Message-ID: <470467F6.1030502@gmail.com> Hi all, I've been prototyping a Windows-only Dir class for Ruby. Below is what I've got so far. The class methods were easy, except for Dir.glob. The code in dir.c is just nasty, and I can't help but think that it could be heavily refactored. I did come across this link: http://www.codeproject.com/file/fileglob.asp But I haven't investigated it yet. Anyone who wants to take a stab at a pure Ruby Dir.glob is welcome to try. I made one attempt to convert the pattern to Regexp objects, but it got pretty hairy, especially with '[a-z]' type ranges, i.e. match only one character instead of any one character. I'd be interested to see what techniques anyone else comes up with. The other issue is how to design Dir.new. I thought the smart thing to do would be to store the handle returned by FindFirstFile(), but then I realized that the handle returned by FindFirstFile() isn't compatible with the handle used for SetFilePointer(), which would make seek/tell difficult to implement. On the other hand, if we use CreateFile(), its handle is not compatible with FindFirstFile() or FindNextFile(), making read/each difficult to implement. I make two refactoring decisions for now - Dir.foreach has been skipped. The Dir.entries now takes an optional block. Dir.open has been skipped. The Dir.new method now takes an optional block. Anyway, suggestions welcome on the code below. BTW, you'll want to grab the latest windows-pr code from CVS for some of this code to work. Regards, Dan # dir.rb require 'windows/file' require 'windows/error' require 'windows/unicode' require 'windows/directory' require 'windows/process' require 'windows/handle' # Struct sizes (ANSI/Wide) # # WIN32_FIND_DATA: 320/592 # [0,4] => dwFileAttributes # [4,8] => ftCreationTime # [12,8] => ftLastAccessTime # [20,8] => ftLastWriteTime # [28,4] => nFileSizeHigh # [32,4] => nFileSizeLow # [36,4] => dwReserved0 # [40,4] => dwReserved1 # [44,260/520] => cFileName[MAX_PATH] # [304,14] => cAlternateFileName[14] class MyDir include Windows::Error include Windows::File include Windows::Unicode include Windows::Directory include Windows::Process include Windows::Handle extend Windows::Error extend Windows::File extend Windows::Unicode extend Windows::Directory extend Windows::Process extend Windows::Handle MAX_PATH = 260 def self.chdir(dir = nil, &block) if dir.nil? buf = 0.chr * 1024 # 32k is the official limit if GetEnvironmentVariable('USERPROFILE', buf, buf.size) == 0 if GetEnvironmentVariable('HOME', buf, buf.size) == 0 raise ArgumentError, 'USERPROFILE/HOME not set' end end dir = buf.unpack("Z*")[0] end if block_given? begin buf = 0.chr * MAX_PATH if GetCurrentDirectory(buf.length, buf) == 0 raise ArgumentError, get_last_error else # MSDN says the drive letter could be dropped, # and that GetFullPathName should be called just in case. current = buf.unpack("Z*")[0] buf2 = 0.chr * MAX_PATH if GetFullPathName(current, buf2.length, buf2, 0) == 0 raise ArgumentError, get_last_error end current = buf2.unpack("Z*")[0] end unless SetCurrentDirectory(dir) raise ArgumentError, get_last_error end block.call ensure SetCurrentDirectory(current) end else unless SetCurrentDirectory(dir) raise ArgumentError, get_last_error end end end def self.delete(dirname) unless RemoveDirectory(dirname) raise ArgumentError, get_last_error end end # Blend entries and foreach into one method def self.entries(dirname) dirname += "\\*" fdata = 0.chr * 320 # 580 if wide array = block_given? ? [] : nil hfind = FindFirstFile(dirname, fdata) if hfind == INVALID_HANDLE_VALUE raise ArgumentError, get_last_error end file = fdata[44, MAX_PATH].unpack("Z*")[0] if block_given? yield file else array << file end while FindNextFile(hfind, fdata) file = fdata[44, MAX_PATH].unpack("Z*")[0] if block_given? yield file else array << file end end error = GetLastError() FindClose(hfind) if error != ERROR_NO_MORE_FILES raise get_last_error(error) end array end def self.getwd buf = 0.chr * MAX_PATH if GetCurrentDirectory(buf.length, buf) == 0 raise ArgumentError, get_last_error end buf.unpack("Z*")[0] end # The 'permissions' could be a Security::Attributes object # of some sort. # def self.mkdir(dirname, permissions = nil) unless CreateDirectory(dirname, permissions) raise ArgumentError, get_last_error end end attr_reader :path # Blend new and open into one method def initialize(path) @path = path + "\\*" @path.tr!(File::SEPARATOR, File::ALT_SEPARATOR) @fdata = 0.chr * 320 # 580 if wide @handle = FindFirstFile(@path, @fdata) if @handle == INVALID_HANDLE_VALUE raise ArgumentError, get_last_error end if block_given? begin yield @handle ensure close end end @pos = 0 @handle end def close FindClose(@handle) end # Broken because the @handle isn't valid def pos SetFilePointer(@handle, 0, 0, FILE_CURRENT) end def read if @pos > 0 @fdata = 0.chr * 320 unless FindNextFile(@handle, @fdata) raise ArgumentError, get_last_error end end @pos += 1 @fdata[44, MAX_PATH].unpack("Z*")[0] end def each @fdata = 0.chr * 320 while FindNextFile(@handle, @fdata) yield @fdata[44, MAX_PATH].unpack("Z*")[0] end end def rewind unless SetFilePointerEx(@handle,0,nil,0) raise ArgumentError, get_last_error end end # class level aliases class << self alias open new alias foreach entries alias pwd getwd alias rmdir delete alias unlink delete end end if $0 == __FILE__ dir = MyDir.new(Dir.pwd) p dir.pos dir.read p dir.pos dir.close end From gthiesfeld at gmail.com Thu Oct 4 11:29:43 2007 From: gthiesfeld at gmail.com (Gordon Thiesfeld) Date: Thu, 4 Oct 2007 10:29:43 -0500 Subject: [Win32utils-devel] WinRuby? In-Reply-To: <71166b3b0709232050u35591fe9h6a746ac37343361@mail.gmail.com> References: <46F6861B.2090708@gmail.com> <554ac39c0709231110j4cc98507pdbc01f89a9870492@mail.gmail.com> <6037b70c0709231157tbe18788vfee8b01d3b3c261b@mail.gmail.com> <6037b70c0709231204w17f94f86j5dec1df536e87b83@mail.gmail.com> <554ac39c0709231430y579a3862o6b8c96c575cd523c@mail.gmail.com> <6037b70c0709231725k18ec869by9c6b875c501500da@mail.gmail.com> <71166b3b0709231943k5d72fa78mdabbf5f68ccbdb8e@mail.gmail.com> <6037b70c0709232042vcb8729cqe2dfccac3044a9f@mail.gmail.com> <71166b3b0709232050u35591fe9h6a746ac37343361@mail.gmail.com> Message-ID: I'd like to know everyone' s opinion of the Rubinius project. It currently doesn't support Windows, but the developers want to. I know there are a lot of great Windows developers here, so would the Rubinius project be a good place to start on a good Windows Ruby implementation? regards, Gordon Thiesfeld -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20071004/33b72fd5/attachment.html From djberg96 at gmail.com Sun Oct 7 18:05:00 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 07 Oct 2007 16:05:00 -0600 Subject: [Win32utils-devel] WinRuby? In-Reply-To: References: <46F6861B.2090708@gmail.com> <554ac39c0709231110j4cc98507pdbc01f89a9870492@mail.gmail.com> <6037b70c0709231157tbe18788vfee8b01d3b3c261b@mail.gmail.com> <6037b70c0709231204w17f94f86j5dec1df536e87b83@mail.gmail.com> <554ac39c0709231430y579a3862o6b8c96c575cd523c@mail.gmail.com> <6037b70c0709231725k18ec869by9c6b875c501500da@mail.gmail.com> <71166b3b0709231943k5d72fa78mdabbf5f68ccbdb8e@mail.gmail.com> <6037b70c0709232042vcb8729cqe2dfccac3044a9f@mail.gmail.com> <71166b3b0709232050u35591fe9h6a746ac37343361@mail.gmail.com> Message-ID: <4709580C.5040000@gmail.com> Gordon Thiesfeld wrote: > I'd like to know everyone' s opinion of the Rubinius project. It > currently doesn't support Windows, but the developers want to. I know > there are a lot of great Windows developers here, so would the Rubinius > project be a good place to start on a good Windows Ruby implementation? That remains to be seen, and we won't know until RubyConf 2007 at the earliest. My general impression of Rubinius so far is that any platform without the GNU toolchain is a second class citizen and Windows is a 3rd class citizen. Regards, Dan From luislavena at gmail.com Mon Oct 8 09:52:41 2007 From: luislavena at gmail.com (Luis Lavena) Date: Mon, 8 Oct 2007 10:52:41 -0300 Subject: [Win32utils-devel] WinRuby? In-Reply-To: References: <46F6861B.2090708@gmail.com> <554ac39c0709231110j4cc98507pdbc01f89a9870492@mail.gmail.com> <6037b70c0709231157tbe18788vfee8b01d3b3c261b@mail.gmail.com> <6037b70c0709231204w17f94f86j5dec1df536e87b83@mail.gmail.com> <554ac39c0709231430y579a3862o6b8c96c575cd523c@mail.gmail.com> <6037b70c0709231725k18ec869by9c6b875c501500da@mail.gmail.com> <71166b3b0709231943k5d72fa78mdabbf5f68ccbdb8e@mail.gmail.com> <6037b70c0709232042vcb8729cqe2dfccac3044a9f@mail.gmail.com> <71166b3b0709232050u35591fe9h6a746ac37343361@mail.gmail.com> Message-ID: <71166b3b0710080652r5d366ffdr799dedfc71261c86@mail.gmail.com> On 10/4/07, Gordon Thiesfeld wrote: > I'd like to know everyone' s opinion of the Rubinius project. It currently > doesn't support Windows, but the developers want to. I know there are a lot > of great Windows developers here, so would the Rubinius project be a good > place to start on a good Windows Ruby implementation? > Let me correct you on this one: supporting windows right now isn't important (not that they want to). Besides the GNU toolchain needed by Rubinius, you also need Git, which is a real pain to get working on Windows (outside cygwin, using mingw-git port). So not only you will have to spent time getting Rubinius working on Win32, but also all the toolchain correctly working... that's a huge problem. -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi From Daniel.Berger at qwest.com Mon Oct 8 10:23:17 2007 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Mon, 8 Oct 2007 09:23:17 -0500 Subject: [Win32utils-devel] Getting an actual system error Message-ID: <7524A45A1A5B264FA4809E2156496CFBE72E86@ITOMAE2KM01.AD.QINTRA.COM> Heya all, I don't think I've been paying attention. When a Windows API function fails, I could have been doing this: raise SystemCallError(GetLastError()) Instead of this: # Where 'Error' is nested under the current class. raise Error, get_last_error I'm not sure how big of a deal this is in practice, however, or if it's even preferred for our purposes. Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From gthiesfeld at gmail.com Mon Oct 8 10:40:11 2007 From: gthiesfeld at gmail.com (Gordon Thiesfeld) Date: Mon, 8 Oct 2007 09:40:11 -0500 Subject: [Win32utils-devel] WinRuby? In-Reply-To: <71166b3b0710080652r5d366ffdr799dedfc71261c86@mail.gmail.com> References: <46F6861B.2090708@gmail.com> <6037b70c0709231157tbe18788vfee8b01d3b3c261b@mail.gmail.com> <6037b70c0709231204w17f94f86j5dec1df536e87b83@mail.gmail.com> <554ac39c0709231430y579a3862o6b8c96c575cd523c@mail.gmail.com> <6037b70c0709231725k18ec869by9c6b875c501500da@mail.gmail.com> <71166b3b0709231943k5d72fa78mdabbf5f68ccbdb8e@mail.gmail.com> <6037b70c0709232042vcb8729cqe2dfccac3044a9f@mail.gmail.com> <71166b3b0709232050u35591fe9h6a746ac37343361@mail.gmail.com> <71166b3b0710080652r5d366ffdr799dedfc71261c86@mail.gmail.com> Message-ID: > Let me correct you on this one: supporting windows right now isn't > important (not that they want to). > > Besides the GNU toolchain needed by Rubinius, you also need Git, which > is a real pain to get working on Windows (outside cygwin, using > mingw-git port). > > So not only you will have to spent time getting Rubinius working on > Win32, but also all the toolchain correctly working... that's a huge > problem. Fair enough. I was basing my statements off of a post by Wilson Bilkovich*, where he says he wants to get it to compile on VC8 at some point. I'm not sure of the level of effort that would take, but I thought I'd ask here to get some opinions and see if there was any interest. * http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/228625 Thanks, Gordon From luislavena at gmail.com Mon Oct 8 10:53:54 2007 From: luislavena at gmail.com (Luis Lavena) Date: Mon, 8 Oct 2007 11:53:54 -0300 Subject: [Win32utils-devel] WinRuby? In-Reply-To: References: <46F6861B.2090708@gmail.com> <6037b70c0709231204w17f94f86j5dec1df536e87b83@mail.gmail.com> <554ac39c0709231430y579a3862o6b8c96c575cd523c@mail.gmail.com> <6037b70c0709231725k18ec869by9c6b875c501500da@mail.gmail.com> <71166b3b0709231943k5d72fa78mdabbf5f68ccbdb8e@mail.gmail.com> <6037b70c0709232042vcb8729cqe2dfccac3044a9f@mail.gmail.com> <71166b3b0709232050u35591fe9h6a746ac37343361@mail.gmail.com> <71166b3b0710080652r5d366ffdr799dedfc71261c86@mail.gmail.com> Message-ID: <71166b3b0710080753i5f0137e4lcd465f53bfb39569@mail.gmail.com> On 10/8/07, Gordon Thiesfeld wrote: > > Let me correct you on this one: supporting windows right now isn't > > important (not that they want to). > > > > Besides the GNU toolchain needed by Rubinius, you also need Git, which > > is a real pain to get working on Windows (outside cygwin, using > > mingw-git port). > > > > So not only you will have to spent time getting Rubinius working on > > Win32, but also all the toolchain correctly working... that's a huge > > problem. > > Fair enough. I was basing my statements off of a post by Wilson > Bilkovich*, where he says he wants to get it to compile on VC8 at some > point. I'm not sure of the level of effort that would take, but I > thought I'd ask here to get some opinions and see if there was any > interest. > > * http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/228625 > >From that post it seems they want to get rid of glib dependency (which is good). Guess that whey they reach that point, someone could step in and implement a configure-like batch file for VC8/VC9. Hopefully when the time comes, mingw-git will be integrated to git and will be more simple to get your copy of rubinius code on windows (I highly doubt about that, but miracles often happens)... -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi From phurley at gmail.com Mon Oct 8 12:32:04 2007 From: phurley at gmail.com (Patrick Hurley) Date: Mon, 8 Oct 2007 12:32:04 -0400 Subject: [Win32utils-devel] WinRuby? In-Reply-To: <71166b3b0710080753i5f0137e4lcd465f53bfb39569@mail.gmail.com> References: <46F6861B.2090708@gmail.com> <554ac39c0709231430y579a3862o6b8c96c575cd523c@mail.gmail.com> <6037b70c0709231725k18ec869by9c6b875c501500da@mail.gmail.com> <71166b3b0709231943k5d72fa78mdabbf5f68ccbdb8e@mail.gmail.com> <6037b70c0709232042vcb8729cqe2dfccac3044a9f@mail.gmail.com> <71166b3b0709232050u35591fe9h6a746ac37343361@mail.gmail.com> <71166b3b0710080652r5d366ffdr799dedfc71261c86@mail.gmail.com> <71166b3b0710080753i5f0137e4lcd465f53bfb39569@mail.gmail.com> Message-ID: <554ac39c0710080932l2377141ka7c96e87c0efbcc3@mail.gmail.com> On 10/8/07, Luis Lavena wrote: > On 10/8/07, Gordon Thiesfeld wrote: > > > Let me correct you on this one: supporting windows right now isn't > > > important (not that they want to). > > > > > > Besides the GNU toolchain needed by Rubinius, you also need Git, which > > > is a real pain to get working on Windows (outside cygwin, using > > > mingw-git port). > > > > > > So not only you will have to spent time getting Rubinius working on > > > Win32, but also all the toolchain correctly working... that's a huge > > > problem. > > > > Fair enough. I was basing my statements off of a post by Wilson > > Bilkovich*, where he says he wants to get it to compile on VC8 at some > > point. I'm not sure of the level of effort that would take, but I > > thought I'd ask here to get some opinions and see if there was any > > interest. > > > > * http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/228625 > > > > >From that post it seems they want to get rid of glib dependency (which is good). > > Guess that whey they reach that point, someone could step in and > implement a configure-like batch file for VC8/VC9. > > Hopefully when the time comes, mingw-git will be integrated to git and > will be more simple to get your copy of rubinius code on windows (I > highly doubt about that, but miracles often happens)... > > -- > Luis Lavena > Multimedia systems > - > Leaders are made, they are not born. They are made by hard effort, > which is the price which all of us must pay to achieve any goal that > is worthwhile. > Vince Lombardi > _______________________________________________ > win32utils-devel mailing list > win32utils-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/win32utils-devel > Missing git is not the end of the world. They provide an SVN mirror, you cannot commit from it, but that may be enough for porting to windows. I personally believe that Rubinius has the best internal design of any of the "future ruby" implementations -- time will tell if it pays off. Evan seems like a very reasonable guy and I would expect he would welcome porting support to Win32 -- but he is reasonably concentrating on the platforms on which he develops, and the tool chain used on those platforms. pth From luislavena at gmail.com Mon Oct 8 12:40:39 2007 From: luislavena at gmail.com (Luis Lavena) Date: Mon, 8 Oct 2007 13:40:39 -0300 Subject: [Win32utils-devel] WinRuby? In-Reply-To: <554ac39c0710080932l2377141ka7c96e87c0efbcc3@mail.gmail.com> References: <46F6861B.2090708@gmail.com> <6037b70c0709231725k18ec869by9c6b875c501500da@mail.gmail.com> <71166b3b0709231943k5d72fa78mdabbf5f68ccbdb8e@mail.gmail.com> <6037b70c0709232042vcb8729cqe2dfccac3044a9f@mail.gmail.com> <71166b3b0709232050u35591fe9h6a746ac37343361@mail.gmail.com> <71166b3b0710080652r5d366ffdr799dedfc71261c86@mail.gmail.com> <71166b3b0710080753i5f0137e4lcd465f53bfb39569@mail.gmail.com> <554ac39c0710080932l2377141ka7c96e87c0efbcc3@mail.gmail.com> Message-ID: <71166b3b0710080940l78cc5cb5g247b841225c931a5@mail.gmail.com> On 10/8/07, Patrick Hurley wrote: > Missing git is not the end of the world. They provide an SVN mirror, > you cannot commit from it, but that may be enough for porting to > windows. I know is not the end of the world. But providing patches using svn diff instead of git could be problematic (found the strip (-p1) option too complicated when working with different VCS). > I personally believe that Rubinius has the best internal > design of any of the "future ruby" implementations -- time will tell > if it pays off. Evan seems like a very reasonable guy and I would > expect he would welcome porting support to Win32 -- but he is > reasonably concentrating on the platforms on which he develops, and > the tool chain used on those platforms. > I agree on that Rubinius is just an amazing project, and is growing at huge rate. Tried it myself a few weeks back on linux and I must say I'm impressed. Also I understand that you must focus on the task (get it working in the platform he uses) than trying to debug it everywhere before. We should keep on eye on it and maybe provide specs to the language (I checked out the mspec and the spec folder to try it with MRI 1.8). For the time being, 1.8.x is 'production ready' on win32, could be enhanced and get better features. -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi From djberg96 at gmail.com Tue Oct 9 00:30:09 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Mon, 08 Oct 2007 22:30:09 -0600 Subject: [Win32utils-devel] RubyForge historical note Message-ID: <470B03D1.4000400@gmail.com> Hi all, The Win32Utils project is the first project in RubyForge history (that I know of) to reclaim a "Top Project Downloads" position. We were in 11th place, but dropped to 12th when Watir passed us several weeks ago. In the last day or so Win32Utils passed Watir, so we're back in 11th. How did it happen? I've been tracking daily downloads somewhat, and I'm fairly certain the downloads increased by about 25% after I created a home page for the project: http://win32utils.rubyforge.org/ It's nothing special, but it seems to have driven traffic up to our project rather dramatically. Let this be a lesson to any other project leaders who don't yet have a project home page. :) Regards, Dan From djberg96 at gmail.com Tue Oct 9 07:27:44 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Tue, 09 Oct 2007 05:27:44 -0600 Subject: [Win32utils-devel] Playing with ReadFileScatter() Message-ID: <470B65B0.80707@gmail.com> Hi all, Looking at the IO.readlines source in io.c, it looks to me like they grab 8k chunks, split on the input record separator, and buffer accordingly. Since it looks like ReadFileScatter() does some of that work automatically (in page file sized chunks), I thought I'd give it a try. Here's what I've got, but it doesn't work. I have an incorrect parameter in the call to ReadFileScatter(). So, I've either got the size wrong, bad alignment or I need to pass in a packed data structure of some sort. Any ideas? BTW, you'll want to grab the latest windows-pr from CVS in order to run this code. Thanks, Dan # WinIO.readlines require 'windows/handle' require 'windows/error' require 'windows/system_info' require 'windows/nio' require 'windows/file' class WinIO extend Windows::Error extend Windows::Handle extend Windows::NIO extend Windows::File extend Windows::MSVCRT::IO extend Windows::SystemInfo include Windows::File def self.readlines(file, sep = $INPUT_RECORD_SEPARATOR) handle = CreateFile( file, GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, nil ) if handle == INVALID_HANDLE_VALUE raise SystemCallError.new(GetLastError()) end sysbuf = 0.chr * 40 GetSystemInfo(sysbuf) page_size = sysbuf[8,4].unpack('L')[0] # dwPageSize file_size = File.size(file) # FILE_SEGMENT_ELEMENT fse_struct = (0.chr * page_size) + (0.chr * 8) # Buffer + Align. seg_array = (0.chr * (file_size / fse_struct.size)) + 0.chr olapped = 0.chr * 20 bool = ReadFileScatter(handle, seg_array, file_size, nil, olapped) raise SystemCallError.new(GetLastError()) end sleep 0.01 unless HasOverlappedIoCompleted(olapped) unless CloseHandle(handle) raise SystemCallError.new(GetLastError()) end seg_array.split(sep) end end From phasis at gmail.com Tue Oct 9 10:56:41 2007 From: phasis at gmail.com (Park Heesob) Date: Tue, 9 Oct 2007 23:56:41 +0900 Subject: [Win32utils-devel] Playing with ReadFileScatter() References: <470B65B0.80707@gmail.com> Message-ID: <000a01c80a84$9df180b0$9a7ba8c0@mycom> Hi, ----- Original Message ----- From: "Daniel Berger" To: "win32utils-devel" Sent: Tuesday, October 09, 2007 8:27 PM Subject: [Win32utils-devel] Playing with ReadFileScatter() > Hi all, > > Looking at the IO.readlines source in io.c, it looks to me like they > grab 8k chunks, split on the input record separator, and buffer accordingly. > > Since it looks like ReadFileScatter() does some of that work > automatically (in page file sized chunks), I thought I'd give it a try. > Here's what I've got, but it doesn't work. I have an incorrect parameter > in the call to ReadFileScatter(). So, I've either got the size wrong, > bad alignment or I need to pass in a packed data structure of some sort. > > Any ideas? BTW, you'll want to grab the latest windows-pr from CVS in > order to run this code. > > Thanks, > > Dan > Here is a complete working source using ReadFileScatter. Notice that VirtualAlloc shoud be redifined. Since ReadFileScatter requires page aligned memory buffer, I allocated buffer using VirtualAlloc. Regards, Park Heesob # WinIO.readlines require 'windows/handle' require 'windows/error' require 'windows/system_info' require 'windows/nio' require 'windows/file' require 'windows/synchronize' require 'windows/msvcrt/io' require 'windows/msvcrt/buffer' require 'windows/memory' class WinIO extend Windows::Error extend Windows::Handle extend Windows::NIO extend Windows::File extend Windows::Synchronize extend Windows::MSVCRT::IO extend Windows::MSVCRT::Buffer extend Windows::SystemInfo extend Windows::Memory include Windows::File include Windows::Memory PAGE_READWRITE = 4 ERROR_IO_PENDING = 997 MEM_RELEASE = 0x8000 def self.readlines(file, sep = $INPUT_RECORD_SEPARATOR) handle = CreateFile( file, GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, nil ) if handle == INVALID_HANDLE_VALUE raise SystemCallError.new(GetLastError()) end sysbuf = 0.chr * 40 GetSystemInfo(sysbuf) page_size = sysbuf[4,4].unpack('L')[0] # dwPageSize shoud be sysbuf[4,4] not sysbuf[8,4] file_size = File.size(file) page_num = (file_size*1.0 / page_size).ceil API.new('VirtualAlloc', 'LLLL', 'L') # redefined VirtualAlloc base_address = VirtualAlloc(nil, page_size * page_num, MEM_COMMIT, PAGE_READWRITE) buf_list = [] for i in 0...page_num buf_list.push(base_address+page_size*i) end seg_array = buf_list.pack('Q*') + 0.chr * 8 olapped = 0.chr * 20 unless ReadFileScatter(handle, seg_array, page_size * page_num, nil, olapped) error = GetLastError() if error != ERROR_IO_PENDING raise SystemCallError.new(error) end end sleep 0.01 unless HasOverlappedIoCompleted(olapped) unless CloseHandle(handle) raise SystemCallError.new(GetLastError()) end buffer = 0.chr * file_size memcpy(buffer, buf_list[0], file_size) VirtualFree(base_address,0,MEM_RELEASE) buffer.split(sep).map {|x| x+"\n"} end end a = IO.readlines('c:/work/java.txt') b = WinIO.readlines('c:/work/java.txt',"\r\n") p a==b From Daniel.Berger at qwest.com Tue Oct 9 12:09:26 2007 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Tue, 9 Oct 2007 11:09:26 -0500 Subject: [Win32utils-devel] Playing with ReadFileScatter() In-Reply-To: <000a01c80a84$9df180b0$9a7ba8c0@mycom> Message-ID: <7524A45A1A5B264FA4809E2156496CFBE72E90@ITOMAE2KM01.AD.QINTRA.COM> > -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Park Heesob > Sent: Tuesday, October 09, 2007 8:57 AM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Playing with ReadFileScatter() > Here is a complete working source using ReadFileScatter. > > Notice that VirtualAlloc shoud be redifined. Since > ReadFileScatter requires page > aligned memory buffer, I allocated buffer using VirtualAlloc. Thanks! That works. I was curious about performance, so I did some benchmarks. It seems to get dramatically worse as the file size gets larger. Is this to be expected? Here's a benchmark program I created. The 5 files end up at the following size (in bytes): 550 file1.txt 5,590 file2.txt 56,890 file3.txt 578,890 file4.txt 5,888,890 file5.txt A little profiling indicates that the worst of it is the buffer.split & map at the end. Here it is with split and map: user system total real IO.readlines file1 0.000000 0.000000 0.000000 ( 0.000000) IO.readlines file2 0.010000 0.000000 0.010000 ( 0.010000) IO.readlines file3 0.030000 0.000000 0.030000 ( 0.030000) IO.readlines file4 0.891000 0.020000 0.911000 ( 1.111000) IO.readlines file5 0.922000 0.020000 0.942000 ( 0.942000) WinIO.readlines file1 0.000000 0.010000 0.010000 ( 0.010000) WinIO.readlines file2 0.000000 0.000000 0.000000 ( 0.130000) WinIO.readlines file3 0.120000 0.030000 0.150000 ( 0.280000) WinIO.readlines file4 1.522000 0.040000 1.562000 ( 2.824000) WinIO.readlines file5 12.448000 0.431000 12.879000 ( 23.514000) Here it is if we remove the split and map. Much better, but still slow. user system total real IO.readlines file1 0.000000 0.000000 0.000000 ( 0.000000) IO.readlines file2 0.000000 0.010000 0.010000 ( 0.010000) IO.readlines file3 0.030000 0.010000 0.040000 ( 0.050000) IO.readlines file4 0.811000 0.040000 0.851000 ( 1.042000) IO.readlines file5 0.902000 0.020000 0.922000 ( 1.031000) WinIO.readlines file1 0.010000 0.000000 0.010000 ( 0.010000) WinIO.readlines file2 0.000000 0.010000 0.010000 ( 0.110000) WinIO.readlines file3 0.060000 0.010000 0.070000 ( 0.200000) WinIO.readlines file4 0.420000 0.030000 0.450000 ( 1.743000) WinIO.readlines file5 4.427000 0.140000 4.567000 ( 13.980000) # winio_bench.rb $:.unshift Dir.pwd require 'benchmark' require 'winio' fh1 = File.open("file1.txt", "w") fh2 = File.open("file2.txt", "w") fh3 = File.open("file3.txt", "w") fh4 = File.open("file4.txt", "w") fh5 = File.open("file5.txt", "w") s = "The quick brown fox jumped over the lazy dog's back " 10.times{ |n| fh1.puts s + n.to_s } fh1.close puts "File 1 created" 100.times{ |n| fh2.puts s + n.to_s } fh2.close puts "File 2 created" 1000.times{ |n| fh3.puts s + n.to_s } fh3.close puts "File 3 created" 10000.times{ |n| fh4.puts s + n.to_s } fh4.close puts "File 4 created" 100000.times{ |n| fh5.puts s + n.to_s } fh5.close puts "File 4 created" MAX = 10 Benchmark.bm(35) do |x| x.report("IO.readlines file1"){ MAX.times{ IO.readlines('file1.txt') } } x.report("IO.readlines file2"){ MAX.times{ IO.readlines('file2.txt') } } x.report("IO.readlines file3"){ MAX.times{ IO.readlines('file3.txt') } } x.report("IO.readlines file4"){ MAX.times{ IO.readlines('file4.txt') } } x.report("IO.readlines file5"){ MAX.times{ IO.readlines('file4.txt') } } x.report("WinIO.readlines file1"){ MAX.times{ WinIO.readlines('file1.txt') } } x.report("WinIO.readlines file2"){ MAX.times{ WinIO.readlines('file2.txt') } } x.report("WinIO.readlines file3"){ MAX.times{ WinIO.readlines('file3.txt') } } x.report("WinIO.readlines file4"){ MAX.times{ WinIO.readlines('file4.txt') } } x.report("WinIO.readlines file5"){ MAX.times{ WinIO.readlines('file5.txt') } } end Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From djberg96 at gmail.com Wed Oct 10 21:59:16 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Wed, 10 Oct 2007 19:59:16 -0600 Subject: [Win32utils-devel] Playing with ReadFileScatter() In-Reply-To: <000a01c80a84$9df180b0$9a7ba8c0@mycom> References: <470B65B0.80707@gmail.com> <000a01c80a84$9df180b0$9a7ba8c0@mycom> Message-ID: <470D8374.5060901@gmail.com> Hi, Just a quick followup. I noticed that VirtualAlloc() works on my Windows XP Pro and Win2k Pro boxes, but not on my XP Home laptop - it returns an empty string (NULL I presume, for failure). Are you all seeing the same thing? The docs don't specifically mention XP Pro as a requirement, but I wouldn't be entirely surprised. Also, I added ERROR_IO_PENDING and MEM_RELEASE to the appropriate files in windows-pr. I should probably move the PAGE_xxx constants over to the Windows::Memory module as well (they're currently in file-mapping.rb). Regards, Dan From phasis at gmail.com Thu Oct 11 00:37:19 2007 From: phasis at gmail.com (Heesob Park) Date: Thu, 11 Oct 2007 13:37:19 +0900 Subject: [Win32utils-devel] Playing with ReadFileScatter() In-Reply-To: <470D8374.5060901@gmail.com> References: <470B65B0.80707@gmail.com> <000a01c80a84$9df180b0$9a7ba8c0@mycom> <470D8374.5060901@gmail.com> Message-ID: Hi, 2007/10/11, Daniel Berger : > Hi, > > Just a quick followup. I noticed that VirtualAlloc() works on my Windows > XP Pro and Win2k Pro boxes, but not on my XP Home laptop - it returns an > empty string (NULL I presume, for failure). > > Are you all seeing the same thing? The docs don't specifically mention > XP Pro as a requirement, but I wouldn't be entirely surprised. In my XP Home Desktop, it works fine. The ReadFileScatter part of source code needs to modify like this: unless ReadFileScatter(handle, seg_array, page_size * page_num, nil, olapped) error = GetLastError() if error == ERROR_IO_PENDING while not HasOverlappedIoCompleted(olapped); end else raise SystemCallError.new(error) end end I noticed setting the benchmark iteration count MAX = 1 shows very different result with MAX = 10. I guess it is due to GC. Some tests show that in case of the large file(about 30MB) ,the ReadFileScatter reads faster than IO.readlines. > Also, I added ERROR_IO_PENDING and MEM_RELEASE to the appropriate files > in windows-pr. I should probably move the PAGE_xxx constants over to the > Windows::Memory module as well (they're currently in file-mapping.rb). > > Regards, > > Dan Regards, Park Heesob -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20071011/c6fe458e/attachment.html From Daniel.Berger at qwest.com Thu Oct 11 15:29:39 2007 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Thu, 11 Oct 2007 14:29:39 -0500 Subject: [Win32utils-devel] Playing with ReadFileScatter() In-Reply-To: Message-ID: <7524A45A1A5B264FA4809E2156496CFBE72EAB@ITOMAE2KM01.AD.QINTRA.COM> > -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of Heesob Park > Sent: Wednesday, October 10, 2007 10:37 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Playing with ReadFileScatter() Had to do some hand-editing of this reply - MS Outlook is being stupid today... > In my XP Home Desktop, it works fine. Odd. I wonder if I configured something that's causing it to fail. The system settings show that I should have 1.5gb of page file space. I'll play with it some more tonight. > The ReadFileScatter part of source code needs to modify like this: > > unless ReadFileScatter(handle, seg_array, page_size * page_num, nil, olapped) > error = GetLastError() > if error == ERROR_IO_PENDING > while not HasOverlappedIoCompleted(olapped); end > else > raise SystemCallError.new(error) > end > end Ok, made that change. I also moved the GetSystemInfo out of the method itself and made it a constant that gets set when the file gets loaded. > I noticed setting the benchmark iteration count MAX = 1 shows very different result with MAX = 10. > I guess it is due to GC. > > Some tests show that in case of the large file(about 30MB) ,the ReadFileScatter reads faster than IO.readlines. At work I get wildly different results of even a single iteration, even with a standard MRI IO.readlines call. The first time I call it, IO.readlines (not WinIO.readlines) takes about 9 seconds on a 30mb file. If I run it again in quick succession, it only takes 2 seconds! I'm guessing there's some caching going on. Similarly, when I run WinIO.readlines, the speed improves if I do successive iterations. Same for an equivalent Perl script. This makes benchmarking somewhat problematic. But, if I just look at the *first* run (waiting a few minutes between each run), our scatter method seems to be about 2 seconds faster than Ruby's builtin IO.readlines method. I'll play around with it some more tonight, though. Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From djberg96 at gmail.com Sun Oct 14 18:27:52 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 14 Oct 2007 16:27:52 -0600 Subject: [Win32utils-devel] GetTimeZoneInformation question Message-ID: <471297E8.5010108@gmail.com> Hi all, The following code snippet isn't working terribly well for me. I can get the Bias, StandardName and DaylightName, but everything else is goofed up. The alignment seems ok, but maybe I've missed something or maybe I have to do extra work to unpack the SYSTEMTIME structures. require 'windows/time' include Windows::Time buf = 0.chr * 172 # sizeof(TIME_ZONE_INFORMATION) GetTimeZoneInformation(buf) p buf[0,4].unpack('L')[0] # Bias p buf[4,64].tr("\0",'') # StandardName p buf[68,2].unpack('S')[0] # Year p buf[70,2].unpack('S')[0] # Month p buf[72,2].unpack('S')[0] # DOW p buf[74,2].unpack('S')[0] # Day p buf[76,2].unpack('S')[0] # Hour p buf[78,2].unpack('S')[0] # Minute p buf[80,2].unpack('S')[0] # Second p buf[82,2].unpack('S')[0] # Millisecond p buf[84,4].unpack('S')[0] # StandardBias p buf[88,64].tr("\0",'') # DaylightName p buf[152,2].unpack('S')[0] # Year p buf[154,2].unpack('S')[0] # Month p buf[156,2].unpack('S')[0] # DOW p buf[158,2].unpack('S')[0] # Day p buf[160,2].unpack('S')[0] # Hour p buf[162,2].unpack('S')[0] # Minute p buf[164,2].unpack('S')[0] # Second p buf[166,2].unpack('S')[0] # Millisecond p buf[168,4].unpack('L')[0] # DaylightBias Regards, Dan From phasis at gmail.com Sun Oct 14 21:01:34 2007 From: phasis at gmail.com (Heesob Park) Date: Mon, 15 Oct 2007 10:01:34 +0900 Subject: [Win32utils-devel] GetTimeZoneInformation question In-Reply-To: <471297E8.5010108@gmail.com> References: <471297E8.5010108@gmail.com> Message-ID: Hi, 2007/10/15, Daniel Berger : > > Hi all, > > The following code snippet isn't working terribly well for me. I can get > the Bias, StandardName and DaylightName, but everything else is goofed > up. The alignment seems ok, but maybe I've missed something or maybe I > have to do extra work to unpack the SYSTEMTIME structures. > > require 'windows/time' > include Windows::Time > > buf = 0.chr * 172 # sizeof(TIME_ZONE_INFORMATION) > GetTimeZoneInformation(buf) > > p buf[0,4].unpack('L')[0] # Bias > p buf[4,64].tr("\0",'') # StandardName > p buf[68,2].unpack('S')[0] # Year > p buf[70,2].unpack('S')[0] # Month > p buf[72,2].unpack('S')[0] # DOW > p buf[74,2].unpack('S')[0] # Day > p buf[76,2].unpack('S')[0] # Hour > p buf[78,2].unpack('S')[0] # Minute > p buf[80,2].unpack('S')[0] # Second > p buf[82,2].unpack('S')[0] # Millisecond > p buf[84,4].unpack('S')[0] # StandardBias > p buf[88,64].tr("\0",'') # DaylightName > p buf[152,2].unpack('S')[0] # Year > p buf[154,2].unpack('S')[0] # Month > p buf[156,2].unpack('S')[0] # DOW > p buf[158,2].unpack('S')[0] # Day > p buf[160,2].unpack('S')[0] # Hour > p buf[162,2].unpack('S')[0] # Minute > p buf[164,2].unpack('S')[0] # Second > p buf[166,2].unpack('S')[0] # Millisecond > p buf[168,4].unpack('L')[0] # DaylightBias > > Regards, > > Dan The SYSTEMTIME structure field StandarddDate and DaylightDate is not used with GetTimeZoneInformation API, but used with SetTimeZoneInformation. Refer to the sample vbnet code at http://vbnet.mvps.org/index.html?code/locale/gettimezoneinfo.htm Regards, Park Heesob -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20071015/46433d32/attachment.html From djberg96 at gmail.com Sun Oct 14 21:23:44 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 14 Oct 2007 19:23:44 -0600 Subject: [Win32utils-devel] GetTimeZoneInformation question In-Reply-To: References: <471297E8.5010108@gmail.com> Message-ID: <4712C120.8000608@gmail.com> Heesob Park wrote: > > Hi, > > 2007/10/15, Daniel Berger >: > > Hi all, > > The following code snippet isn't working terribly well for me. I can get > the Bias, StandardName and DaylightName, but everything else is goofed > up. The alignment seems ok, but maybe I've missed something or maybe I > have to do extra work to unpack the SYSTEMTIME structures. > > require 'windows/time' > include Windows::Time > > buf = 0.chr * 172 # sizeof(TIME_ZONE_INFORMATION) > GetTimeZoneInformation(buf) > > p buf[0,4].unpack('L')[0] # Bias > p buf[4,64].tr("\0",'') # StandardName > p buf[68,2].unpack('S')[0] # Year > p buf[70,2].unpack('S')[0] # Month > p buf[72,2].unpack('S')[0] # DOW > p buf[74,2].unpack('S')[0] # Day > p buf[76,2].unpack('S')[0] # Hour > p buf[78,2].unpack('S')[0] # Minute > p buf[80,2].unpack('S')[0] # Second > p buf[82,2].unpack('S')[0] # Millisecond > p buf[84,4].unpack('S')[0] # StandardBias > p buf[88,64].tr("\0",'') # DaylightName > p buf[152,2].unpack('S')[0] # Year > p buf[154,2].unpack('S')[0] # Month > p buf[156,2].unpack('S')[0] # DOW > p buf[158,2].unpack('S')[0] # Day > p buf[160,2].unpack('S')[0] # Hour > p buf[162,2].unpack('S')[0] # Minute > p buf[164,2].unpack('S')[0] # Second > p buf[166,2].unpack('S')[0] # Millisecond > p buf[168,4].unpack('L')[0] # DaylightBias > > Regards, > > Dan > > > The SYSTEMTIME structure field StandarddDate and DaylightDate is not > used with GetTimeZoneInformation API, but used with SetTimeZoneInformation. > > Refer to the sample vbnet code at > http://vbnet.mvps.org/index.html?code/locale/gettimezoneinfo.htm > > Regards, > > Park Heesob Oh, silly me. Disregard. Dan From djberg96 at gmail.com Sat Oct 20 23:06:48 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Sat, 20 Oct 2007 21:06:48 -0600 Subject: [Win32utils-devel] Getting an actual system error In-Reply-To: <7524A45A1A5B264FA4809E2156496CFBE72E86@ITOMAE2KM01.AD.QINTRA.COM> References: <7524A45A1A5B264FA4809E2156496CFBE72E86@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: <471AC248.1010909@gmail.com> Berger, Daniel wrote: > Heya all, > > I don't think I've been paying attention. When a Windows API function > fails, I could have been doing this: > > raise SystemCallError(GetLastError()) Whoops, that should have been SystemCallError.new(GetLastError()) > Instead of this: > > # Where 'Error' is nested under the current class. > raise Error, get_last_error > > I'm not sure how big of a deal this is in practice, however, or if it's > even preferred for our purposes. A bit more research indicates that the error messages don't always match up if you do this. For example, if you do: unless RemoveDirectory(bogus) raise SystemCallError.new(GetLastError()) # GetLastError returns 3 end The result is Errno::ESRCH (errno 3), whereas Ruby would raise Errno::ENOENT, which is errno 2. Looking at win32.c I now see why - they've got certain errors specifically mapped to certain codes. Take a look at the errmap struct. Regards, Dan From djberg96 at gmail.com Sun Oct 21 01:28:51 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Sat, 20 Oct 2007 23:28:51 -0600 Subject: [Win32utils-devel] Simulating RUBY_CRITICAL Message-ID: <471AE393.5040208@gmail.com> Hi all, I've added some critical section methods to the Windows::Synchronize module in the windows-pr library (in CVS). Looking at the RUBY_CRITICAL macro from rubysig.h, it basically looks like this (in pure Ruby): def RUBY_CRITICAL(&block) critical_section = [0].pack('L') InitializeCriticalSection(critical_section) EnterCriticalSection(critical_section) block.call LeaveCriticalSection(critical_section) end But, shouldn't we ensure that we leave the critical section once entered, like so? # This is what's currently in CVS def RUBY_CRITICAL(&block) critical_section = [0].pack('L') begin InitializeCriticalSection(critical_section) EnterCriticalSection(critical_section) block.call ensure LeaveCriticalSection(critical_section) end end Or, am I worrying over nothing? Regards, Dan From waynev at gmail.com Sun Oct 21 02:34:46 2007 From: waynev at gmail.com (Wayne Vucenic) Date: Sat, 20 Oct 2007 23:34:46 -0700 Subject: [Win32utils-devel] Simulating RUBY_CRITICAL In-Reply-To: <471AE393.5040208@gmail.com> References: <471AE393.5040208@gmail.com> Message-ID: <88c9ce410710202334y1e88c985ma56fb020c82abc67@mail.gmail.com> Hi Dan, I certainly like the idea of ensuring that we leave the critical section once entered. However, there are some possible complications. For example, MSDN says: "Windows 2000/NT: In low memory situations, EnterCriticalSection can raise an exception. Do not attempt to handle this exception; instead, either terminate the process or allow the exception to pass to the unhandled exception filter. To avoid an exception due to low memory, call the InitializeCriticalSectionAndSpinCount function to preallocate the event used by EnterCriticalSection instead of calling the InitializeCriticalSection function, which forces EnterCriticalSection to allocate the event. Preallocating the event is not necessary on Windows XP or later because EnterCriticalSection is guaranteed not to fail due to lack of resources." http://msdn2.microsoft.com/en-us/library/ms682608.aspx Then again, I don't think it's too likely that we'd be low enough on memory for EnterCriticalSection to fail. Best regards, Wayne On 10/20/07, Daniel Berger wrote: > Hi all, > > I've added some critical section methods to the Windows::Synchronize > module in the windows-pr library (in CVS). Looking at the RUBY_CRITICAL > macro from rubysig.h, it basically looks like this (in pure Ruby): > > def RUBY_CRITICAL(&block) > critical_section = [0].pack('L') > InitializeCriticalSection(critical_section) > EnterCriticalSection(critical_section) > block.call > LeaveCriticalSection(critical_section) > end > > But, shouldn't we ensure that we leave the critical section once > entered, like so? > > # This is what's currently in CVS > def RUBY_CRITICAL(&block) > critical_section = [0].pack('L') > begin > InitializeCriticalSection(critical_section) > EnterCriticalSection(critical_section) > block.call > ensure > LeaveCriticalSection(critical_section) > end > end > > Or, am I worrying over nothing? > > Regards, > > Dan > _______________________________________________ > win32utils-devel mailing list > win32utils-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/win32utils-devel > From djberg96 at gmail.com Sun Oct 21 03:09:34 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 21 Oct 2007 01:09:34 -0600 Subject: [Win32utils-devel] Simulating RUBY_CRITICAL In-Reply-To: <88c9ce410710202334y1e88c985ma56fb020c82abc67@mail.gmail.com> References: <471AE393.5040208@gmail.com> <88c9ce410710202334y1e88c985ma56fb020c82abc67@mail.gmail.com> Message-ID: <471AFB2E.8060605@gmail.com> Wayne Vucenic wrote: > Hi Dan, > > I certainly like the idea of ensuring that we leave the critical > section once entered. However, there are some possible complications. > For example, MSDN says: > > "Windows 2000/NT: In low memory situations, EnterCriticalSection can > raise an exception. Do not attempt to handle this exception; instead, > either terminate the process or allow the exception to pass to the > unhandled exception filter. To avoid an exception due to low memory, > call the InitializeCriticalSectionAndSpinCount function to preallocate > the event used by EnterCriticalSection instead of calling the > InitializeCriticalSection function, which forces EnterCriticalSection > to allocate the event. Preallocating the event is not necessary on > Windows XP or later because EnterCriticalSection is guaranteed not to > fail due to lack of resources." > http://msdn2.microsoft.com/en-us/library/ms682608.aspx > > Then again, I don't think it's too likely that we'd be low enough on > memory for EnterCriticalSection to fail. Hi Wayne, Yeah, I saw that. I guess I'm not especially worried about checking for low memory for two reasons. First, it seems we don't have to worry about it with XP and later, which covers the majority of Windows users at this point I think. Second, I'm pretty sure the interpreter would die anyway if there were a memory allocation issue. But, now that I look at this code, I'm somewhat confused as to why they felt compelled to wrap methods like Dir.mkdir in a RUBY_CRITICAL block in the first place. Are they trying to make it thread safe? The Ruby interpreter isn't thread safe to begin with. Are they trying to make create + chmod a single transaction? Seems overkill, and besides, the code in dir.c takes no such precaution for Unix. I'd really like to see the use cases for why this was used. Regards, Dan From djberg96 at gmail.com Sun Oct 21 10:42:22 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 21 Oct 2007 08:42:22 -0600 Subject: [Win32utils-devel] Taking a stab at a pure Ruby Dir.glob Message-ID: <471B654E.8000900@gmail.com> Hi all, Here's what I've come up with so far for a pure Ruby Dir.glob for MS Windows. It almost works. The problem right now is the [] notation, which I'm not translating properly into a regex. I haven't started on the '**' notation yet either, but I figure that's more of a control flow issue. Feel free to disagree with me and/or provide a solution. :) # mydir.rb - make sure you have the windows-pr library first. require 'windows/file' require 'windows/error' require 'windows/unicode' require 'windows/directory' require 'windows/process' require 'windows/handle' require 'windows/path' class MyDir extend Windows::Error extend Windows::File extend Windows::Unicode extend Windows::Directory extend Windows::Process extend Windows::Handle extend Windows::Path include Windows::Error include Windows::File include Windows::Handle def self.glob(pattern, flags = 0) raise TypeError unless flags.is_a?(Integer) dirname = File.dirname(pattern) + "\\*" pattern = File.basename(pattern) recursive = false regex = nil #puts "ORIG PATTERN: '#{pattern}'" # Convert backslashes to literal backslashes pattern.gsub!("\.", "\\.") # Convert 3 or more '*' characters to a single '*' pattern.gsub!(/\*{3,}/, '*') # Convert leading text to '/^xxx' format pattern.sub!(/^(\w)/, '^\1') # Convert all remaining literal '?' to a '.' (any single char). pattern.sub!(/^\?/, '^.') pattern.tr!('?', '.') # Convert all '*' to '.*?' to get the (nongreedy) intended result. pattern.gsub!("*", ".*?") # Convert {x, y} to (x|y) pattern.gsub!(/\{(.*?)\}/, '(\1)') pattern.gsub!(/\,\s*/, '|') # Convert {x, y} to (x|y) pattern.gsub!(/\{(.*?)\}/, '(\1)') pattern.gsub!(/\,\s*/, '|') dp = pattern.dup # This is an attempt to convert '[]' sets into # a regular expression. # TODO: Fix! dp.scan(/\[(.*?)\]/){ |array| array.each{ |match| start, finish = match.split('-') if finish chars = Range.new(start, finish).to_a else chars = start.split('') end pattern << '(' + chars.join('|') } pattern << ')' } pattern << '$' pattern.gsub!(/\[.*?\]/, '') puts "NEW PATTERN: '#{pattern}'" regex = Regexp.new(pattern) fdata = 0.chr * 320 # 580 if wide array = [] hfind = FindFirstFile(dirname, fdata) if hfind == INVALID_HANDLE_VALUE raise ArgumentError, get_last_error end file = fdata[44, MAX_PATH].unpack("Z*")[0] array << file if regex.match(file) while FindNextFile(hfind, fdata) file = fdata[44, MAX_PATH].unpack("Z*")[0] array << file if regex.match(file) end error = GetLastError() FindClose(hfind) if(error != ERROR_NO_MORE_FILES) raise get_last_error(error) end unless flags & File::FNM_DOTMATCH > 0 array.delete_if{ |file| file =~ /^\..*/ } end array end end Here's a test suite you can use to verify your results. Additions welcome: ######################################################################## # tc_glob.rb # # Test case for the MyDir.glob class method. ######################################################################## $:.unshift Dir.pwd require 'test/unit' require 'fileutils' require 'mydir' class TC_MyDir_Glob_Class < Test::Unit::TestCase # Helper method to get just the basename of the filename def base(files) files.map{ |f| File.basename(f) } end def setup @foo_files = %w/a.c a.cpp b.c b.h g.rb d/ @bar_files = %w/a.c a2.cpp a3.h a4.rb/ FileUtils.mkdir_p('foo/bar/baz') Dir.chdir('foo'){ @foo_files.each{ |f| FileUtils.touch(f) } } Dir.chdir('foo/bar'){ @bar_files.each{ |f| FileUtils.touch(f) } } end def test_glob_pattern assert_equal(%w/a.c a.cpp b.c b.h bar d g.rb/, base(MyDir.glob('foo/{*}'))) assert_equal(%w/g.rb/, base(MyDir.glob('foo/{*.rb}'))) assert_equal(%w/a.cpp g.rb/, base(MyDir.glob('foo/*.{rb,cpp}'))) assert_equal(%w/a.cpp g.rb/, base(MyDir.glob('foo/*.{rb,cp}*'))) assert_equal([], base(MyDir.glob('foo/*.{}'))) end def test_glob_char_list assert_equal(%w/d/, base(MyDir.glob('foo/[a-d]'))) assert_equal(%w/a.c a.cpp/, base(MyDir.glob('foo/[a]*'))) assert_equal(%w/a.c a.cpp b.c b.h bar d/, base(MyDir.glob('foo/[a-d]*'))) assert_equal(%w/d g.rb/, base(MyDir.glob('foo/[^a-b]*'))) if WINDOWS assert_equal(%w/a.c a.cpp b.c b.h bar d g.rb/, base(MyDir.glob('foo/[A-Z]*'))) else assert_equal([], base(MyDir.glob('foo/[A-Z]*'))) end end def test_glob_char_list_edge_cases assert_equal([], MyDir.glob('foo/[]')) assert_equal(['d'], base(MyDir.glob('foo/[^]'))) end def test_glob_question_mark assert_equal(%w/a.c/, base(MyDir.glob('foo/a.?'))) assert_equal(%w/a.cpp/, base(MyDir.glob('foo/a.c?p'))) assert_equal(%w/a.c b.c b.h bar/, base(MyDir.glob('foo/???'))) assert_equal(%w/a.c b.c b.h/, base(MyDir.glob('foo/?.?'))) end def test_glob_basic assert_respond_to(MyDir, :glob) assert_nothing_raised{ MyDir.glob("*") } end def test_glob_valid_metacharacters assert_nothing_raised{ MyDir.glob("**") } assert_nothing_raised{ MyDir.glob("foo.*") } assert_nothing_raised{ MyDir.glob("foo.?") } assert_nothing_raised{ MyDir.glob("*.[^r]*") } assert_nothing_raised{ MyDir.glob("*.[a-z][a-z]") } assert_nothing_raised{ MyDir.glob("*.{rb,h}") } assert_nothing_raised{ MyDir.glob("*.\t") } end def test_glob_star assert_equal(%w/a.c a.cpp b.c b.h bar d g.rb/, base(MyDir.glob('foo/*'))) assert_equal(%w/a.c a.cpp b.c b.h bar d g.rb/, base(MyDir.glob('foo/****'))) assert_equal(%w/a.c b.c/, base(MyDir.glob('foo/*.c'))) assert_equal(%w/a.c a.cpp/, base(MyDir.glob('foo/a*'))) assert_equal(%w/a.c a.cpp/, base(MyDir.glob('foo/a*c*'))) assert_equal(%w/a.cpp/, base(MyDir.glob('foo/a*p*'))) assert_equal([], MyDir.glob('x*')) end def test_glob_double_star assert_equal(%w/a.c a.cpp b.c b.h bar d g.rb/, base(MyDir.glob('foo/**'))) assert_equal(%w/a.c b.c a.c/, base(MyDir.glob('**/*.c'))) assert_equal(%w/a.c b.c a.c/, base(MyDir.glob('foo/**/*.c'))) assert_equal(%w/a.c a.cpp a.c a2.cpp a3.h a4.rb/, base(MyDir.glob('foo/**/a*'))) assert_equal([], MyDir.glob('**/x*')) end def test_glob_flags assert_nothing_raised{ MyDir.glob("*", File::FNM_DOTMATCH) } assert_nothing_raised{ MyDir.glob("*", File::FNM_NOESCAPE) } assert_nothing_raised{ MyDir.glob("*", File::FNM_PATHNAME) } assert_nothing_raised{ MyDir.glob("*", File::FNM_CASEFOLD) } end def test_glob_expected_errors assert_raises(TypeError){ MyDir.glob("*", "*") } end def teardown @foo_files = nil @bar_files = nil FileUtils.rm_rf('foo') end end Please feel free to take a stab at this. Good luck! Regards, Dan PS - I took a look at Python's fnmatch.py code. It's of no use - they don't support '**' or '{}' notation. From djberg96 at gmail.com Wed Oct 24 22:44:54 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Wed, 24 Oct 2007 20:44:54 -0600 Subject: [Win32utils-devel] Using strtok via win32/api Message-ID: <47200326.2000408@gmail.com> Hi all, I'm having a little trouble with strtok: require 'win32/api' include Win32 strtok = API.new('strtok', 'PP, 'P', 'msvcrt') string = "A string\tof ,,tokens\nand some more tokens"; seps = " ,\t\n"; puts "Tokens:" token = strtok.call(string, seps) while token puts token token = strtok.call(nil, seps) end This will work, except on the final call: C:\>ruby strtok.rb Tokens: A string of tokens and some more tokens C:/ruby/lib/ruby/site_ruby/1.8/windows/api.rb:342:in `call': NULL pointer given (ArgumentError) from C:/ruby/lib/ruby/site_ruby/1.8/windows/api.rb:342:in `call' from C:/ruby/lib/ruby/site_ruby/1.8/windows/msvcrt/string.rb:69:in `strtok' from strtok.rb:13 I can see why it's doing this, but I'd like to make it work without a begin/rescue, if possible, in order to keep it fast. Any ideas? Regards, Dan PS - Yes, I know strtok() is evil. Please humor me. From phasis at gmail.com Thu Oct 25 08:22:26 2007 From: phasis at gmail.com (Park Heesob) Date: Thu, 25 Oct 2007 21:22:26 +0900 Subject: [Win32utils-devel] Using strtok via win32/api References: <47200326.2000408@gmail.com> Message-ID: <003401c81701$b7315990$9a7ba8c0@mycom> Hi, ----- Original Message ----- From: "Daniel Berger" To: "win32utils-devel" Sent: Thursday, October 25, 2007 11:44 AM Subject: [Win32utils-devel] Using strtok via win32/api > Hi all, > > I'm having a little trouble with strtok: > > require 'win32/api' > include Win32 > > strtok = API.new('strtok', 'PP, 'P', 'msvcrt') > > string = "A string\tof ,,tokens\nand some more tokens"; > seps = " ,\t\n"; > > puts "Tokens:" > > token = strtok.call(string, seps) > > while token > puts token > token = strtok.call(nil, seps) > end > > This will work, except on the final call: > > C:\>ruby strtok.rb > Tokens: > A > string > of > tokens > and > some > more > tokens > C:/ruby/lib/ruby/site_ruby/1.8/windows/api.rb:342:in `call': NULL > pointer given (ArgumentError) > from C:/ruby/lib/ruby/site_ruby/1.8/windows/api.rb:342:in `call' > from > C:/ruby/lib/ruby/site_ruby/1.8/windows/msvcrt/string.rb:69:in `strtok' > from strtok.rb:13 > > I can see why it's doing this, but I'd like to make it work without a > begin/rescue, if possible, in order to keep it fast. Any ideas? > > Regards, > > Dan > I think it is a bug. The source code line #457 of api.c in win32-api module v_return = rb_str_new2((TCHAR*)return_value); shoule be v_return = (return_value==0) ? Qnil : rb_str_new2((TCHAR*)return_value); Regards, Park Heesob From djberg96 at gmail.com Thu Oct 25 08:39:59 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Thu, 25 Oct 2007 06:39:59 -0600 Subject: [Win32utils-devel] Using strtok via win32/api In-Reply-To: <003401c81701$b7315990$9a7ba8c0@mycom> References: <47200326.2000408@gmail.com> <003401c81701$b7315990$9a7ba8c0@mycom> Message-ID: <47208E9F.4000107@gmail.com> Park Heesob wrote: > Hi, > ----- Original Message ----- > From: "Daniel Berger" > To: "win32utils-devel" > Sent: Thursday, October 25, 2007 11:44 AM > Subject: [Win32utils-devel] Using strtok via win32/api > > >> Hi all, >> >> I'm having a little trouble with strtok: >> >> require 'win32/api' >> include Win32 >> >> strtok = API.new('strtok', 'PP, 'P', 'msvcrt') >> >> string = "A string\tof ,,tokens\nand some more tokens"; >> seps = " ,\t\n"; >> >> puts "Tokens:" >> >> token = strtok.call(string, seps) >> >> while token >> puts token >> token = strtok.call(nil, seps) >> end >> >> This will work, except on the final call: >> >> C:\>ruby strtok.rb >> Tokens: >> A >> string >> of >> tokens >> and >> some >> more >> tokens >> C:/ruby/lib/ruby/site_ruby/1.8/windows/api.rb:342:in `call': NULL >> pointer given (ArgumentError) >> from C:/ruby/lib/ruby/site_ruby/1.8/windows/api.rb:342:in `call' >> from >> C:/ruby/lib/ruby/site_ruby/1.8/windows/msvcrt/string.rb:69:in `strtok' >> from strtok.rb:13 >> >> I can see why it's doing this, but I'd like to make it work without a >> begin/rescue, if possible, in order to keep it fast. Any ideas? >> >> Regards, >> >> Dan >> > I think it is a bug. > > The source code line #457 of api.c in win32-api module > > v_return = rb_str_new2((TCHAR*)return_value); > > shoule be > > v_return = (return_value==0) ? Qnil : rb_str_new2((TCHAR*)return_value); Aha! I actually changed it to this: if(!return_value) v_return = Qnil; else v_return = rb_str_new2((TCHAR*)return_value); That should cover both 0 and NULL. :) Many thanks, Dan PS - Win32API suffers from the same bug (unless they patched it recently). From djberg96 at gmail.com Sat Oct 27 15:39:26 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Sat, 27 Oct 2007 13:39:26 -0600 Subject: [Win32utils-devel] Who wants to take a stab at IO.foreach? Message-ID: <472393EE.1050400@gmail.com> Hi all, Anyone want to help with a native IO.foreach? I'm missing some of the critical logic here. This currently just does a straight BYTE_MAX data read, instead of a line by line data read, and doesn't deal with lines split between multiple reads. I checked strtok into CVS (for windows-pr) if anyone wants to use that instead of String#split. It's in 'windows/msvcrt/string'. require 'windows/file' require 'windows/handle' require 'windows/error' class WinIO extend Windows::File extend Windows::Handle extend Windows::Error include Windows::File include Windows::Error MAX_READ = 20 # Small, for testing purposes def self.foreach(file, sep="\r\n") handle = CreateFile( file, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0 ) if handle == INVALID_HANDLE_VALUE raise Error, get_last_error end buffer = 0.chr * MAX_READ nbytes = [0].pack('L') offset = 0 olap = 0.chr * 20 # sizeof(OVERLAPPED) while bool = ReadFile(handle, buffer, buffer.size, nbytes, olap) error = GetLastError() if !bool && error == ERROR_INSUFFICIENT_BUFFER buffer = 0.chr * (buffer.size + buf_max) next end # TODO: Fix offset += MAX_READ yield buffer olap[8,4] = [offset].pack('L') # Bump the file pointer break if error == ERROR_HANDLE_EOF end unless CloseHandle(handle) raise RuntimeError, get_last_error end end end if $0 == __FILE__ WinIO.foreach('some_file.txt'){ |l| p l } end Regards, Dan From djberg96 at gmail.com Sun Oct 28 08:14:57 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 28 Oct 2007 06:14:57 -0600 Subject: [Win32utils-devel] Won't be at RubyConf Message-ID: <47247D41.2070607@gmail.com> Hi all Sorry folks, I won't be at RubyConf this year. I burned up the travel budget with a trip to Thailand, a makeup trip to Florida, and I'm headed to Florida again this Christmas. At least this gives me more time to work on Wuby. :) Regards, Dan From waynev at gmail.com Sun Oct 28 12:07:09 2007 From: waynev at gmail.com (Wayne Vucenic) Date: Sun, 28 Oct 2007 09:07:09 -0700 Subject: [Win32utils-devel] Won't be at RubyConf In-Reply-To: <47247D41.2070607@gmail.com> References: <47247D41.2070607@gmail.com> Message-ID: <88c9ce410710280907l173c0d4av816b933d8cffa899@mail.gmail.com> Hi Dan, I won't be making it to RubyConf either this year. I really, really wanted to go, but I'm just too busy at home and at work to take 4 days off. (Right now I'm getting ready to go in to work in just a minute (on Sunday)). At least the work is a non-Rails Ruby job (including Dhaka parsing, so thanks again for the tip on that) so it's a good thing to be busy with. See you next year for sure!!! Wayne On 10/28/07, Daniel Berger wrote: > Hi all > > Sorry folks, I won't be at RubyConf this year. I burned up the travel > budget with a trip to Thailand, a makeup trip to Florida, and I'm headed > to Florida again this Christmas. > > At least this gives me more time to work on Wuby. :) > > Regards, > > Dan > _______________________________________________ > win32utils-devel mailing list > win32utils-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/win32utils-devel > From djberg96 at gmail.com Wed Oct 31 21:15:18 2007 From: djberg96 at gmail.com (Daniel Berger) Date: Wed, 31 Oct 2007 19:15:18 -0600 Subject: [Win32utils-devel] Vista anyone? Message-ID: <472928A6.6070003@gmail.com> Anyone got a Vista box I can log into and test on? In exchange, I've got a Win2k box you can log into. Thanks, Dan