The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Things that make you go, "Huh"

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Things that make you go, "Huh" Posted: May 12, 2008 11:01 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Things that make you go, "Huh"
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
Not long ago, with the help of Park Heesob and teh intraweb, I came up with a program that would do a global search and replace. The goal was to replace all deprecated instances of "assert_raises" with "assert_raise". And, the code below works just dandy:
require 'win32/mmap'
require 'windows/msvcrt/buffer'
include Windows::MSVCRT::Buffer

Strlen = API.new('strlen', 'L', 'L', 'msvcrt')
Strstr = API.new('strstr', 'LP', 'L', 'msvcrt')

Dir["**/*.rb"].each{ |f|
   p f
   Win32::MMap.new(:file => f) do |addr|
      old_str = 'assert_raises'
      old_len = old_str.length
      new_str = 'assert_raise'
      new_len = new_str.length

      ptr1 = ptr2 = ptr3 = Strstr.call(addr,old_str)

      while ptr1 && ptr1 != 0
         ptr2 += new_len
         ptr3 += old_len
         memmove(ptr2, ptr3, 1 + Strlen.call(ptr3))
         memcpy(ptr1, new_str, new_len)
         ptr1 = ptr2 = ptr3 = Strstr.call(ptr2,old_str)
      end
   end
}

What totally threw me off is that, even after making the modifications, the mtime is the same! One of two things is happening. Either the modification is so fast (less than a second) that it doesn't update the mtime, or making changes via mmap won't update the mtime regardless.

Normally I wouldn't give a damn, except for one thing - it's confusing the bejesus out of Eclipse and its CVS integration. I've made a modification to the files locally (which I can see by manually inspecting them after the script has run), but it will NOT detect that the local file is different from the remote file, even if I explicitly check for it. I can only guess it's because the mtime is identical.

Weird, huh?

Read: Things that make you go, "Huh"

Topic: Metric_fu Now Measures Churn Previous Topic   Next Topic Topic: Resumen de JavaOne 2008 y Java University

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use