# GDiff

**URL:** <https://www.ruby-forum.com/t/gdiff/95045>\
**Category:** Ruby\
**Created:** [May 19, 2006, 11:39pm UTC](https://www.ruby-forum.com/t/gdiff/95045 "2006-05-19T23:39:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leslieviljoen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3d9bf3/32.png) [@leslieviljoen](https://www.ruby-forum.com/u/leslieviljoen)\
**Post date:** [May 19, 2006, 11:39pm UTC](https://www.ruby-forum.com/t/gdiff/95045/1 "2006-05-19T23:39:31Z")

</div>

I recently ported Brian Schroeder’s great GDiff  
([http://ruby.brian-schroeder.de/gdiff/](http://ruby.brian-schroeder.de/gdiff/)) program to Windows with just  
one small problem: it doesn’t work. The required extension (Zed S.'s  
suffix array) needed some minor changes to compile with silly MS VC++  
6 and then everything _seemed_ to be working except the GDiff files  
produced when running the program look invalid.

The gpatch command and the tests with gdiff have never worked but that  
was ok for me because gdiff worked under Linux and I wrote a gpatch in  
C. Now I really need gdiff to run on Windows (my gpatch runs on an ARM  
inside a device).

Now for the Windows port:  
I did some basic tests with the suffix array and it looks functional.  
I don’t have comprehensive tests.

Running the gdiff test suite gives this on both platforms:

Loaded suite tc\_gdiff  
Started  
E…E.  
Finished in 13.757589 seconds.

1. Error:  
test\_big(TC\_GDiff):  
NoMethodError: undefined method `operations' for #<Diff::GDiff:0x402ba89c> /usr/local/lib/site_ruby/1.8/gdiff.rb:244:in `to\_s’  
tc\_gdiff.rb:27:in `test\_big’

2. Error:  
test\_pack\_unpack(TC\_GDiff):  
NoMethodError: undefined method `operations' for #<Diff::GDiff:0x402b8074> /usr/local/lib/site_ruby/1.8/gdiff.rb:244:in `to\_s’  
tc\_gdiff.rb:36:in `test_pack_unpack' tc_gdiff.rb:32:in `each’  
tc\_gdiff.rb:32:in `test\_pack\_unpack’

7 tests, 26 assertions, 0 failures, 2 errors

My next thought was to require breakpoint in lib/gdiff.rb on both  
platforms and have them stop at some crucial places so I could inspect  
the state. But when I put “breakpoint” on a line, suddenly this error  
occurred:

lesliev@redebo:~/svnroot/bootpatcher/test$ ./gdiff\_t one.bin two.bin

> patch.bin  
> /usr/local/lib/site\_ruby/1.8/gdiff\_t.rb:246:in `to_s': undefined method `operations’ for #Diff::GDiff:0x4041c87c (NoMethodError)  
> from /usr/lib/ruby/1.8/irb.rb:270:in `prompt' from /usr/lib/ruby/1.8/irb.rb:265:in `gsub!’  
> from /usr/lib/ruby/1.8/irb.rb:265:in `prompt' from /usr/lib/ruby/1.8/irb.rb:114:in `eval\_input’  
> from /usr/lib/ruby/1.8/irb.rb:103:in `call' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:200:in `prompt’  
> from /usr/lib/ruby/1.8/irb/ruby-lex.rb:214:in `initialize_input' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:221:in `each\_top\_level\_statement’  
> … 10 levels…  
> from /usr/local/lib/site\_ruby/1.8/breakpoint.rb:537:in  
> `breakpoint' from /usr/local/lib/site_ruby/1.8/gdiff_t.rb:193:in `initialize’  
> from ./gdiff\_t:25:in `diff’  
> from ./gdiff\_t:25

- very similar to the tests.

So much for platform Independence! I have tried to contact Brian  
without success and now I’m running out of time.

Any suggestions?

Les

---

<div class="post-metadata">

**Author:** ![leslieviljoen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3d9bf3/32.png) [@leslieviljoen](https://www.ruby-forum.com/u/leslieviljoen)\
**Post date:** [May 20, 2006, 1:58pm UTC](https://www.ruby-forum.com/t/gdiff/95045/2 "2006-05-20T13:58:26Z")

</div>

On 5/19/06, Leslie V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So much for platform Independence! I have tried to contact Brian  
> without success and now I’m running out of time.
> 
> Any suggestions?

Gonzalo sent me a ported suffix array and the tests and it all works  
very well - although Gdiff still produces broken files. I am going to  
go through it and try to debug it.

Is there some difference between how Ruby handles binary files on  
Windows and on Linux? Could it be ios.binmode? I am going to give it a  
try…

---

<div class="post-metadata">

**Author:** ![leslieviljoen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3d9bf3/32.png) [@leslieviljoen](https://www.ruby-forum.com/u/leslieviljoen)\
**Post date:** [May 20, 2006, 2:10pm UTC](https://www.ruby-forum.com/t/gdiff/95045/3 "2006-05-20T14:10:58Z")

</div>

On 5/20/06, Leslie V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there some difference between how Ruby handles binary files on  
> Windows and on Linux? Could it be ios.binmode? I am going to give it a  
> try…

Working better now… the patch files are very similar…

---

<div class="post-metadata">

**Author:** ![leslieviljoen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3d9bf3/32.png) [@leslieviljoen](https://www.ruby-forum.com/u/leslieviljoen)\
**Post date:** [May 20, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/gdiff/95045/4 "2006-05-20T14:20:14Z")

</div>

On 5/20/06, Leslie V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > go through it and try to debug it.
> > 
> > Is there some difference between how Ruby handles binary files on  
> > Windows and on Linux? Could it be ios.binmode? I am going to give it a  
> > try…
> 
> Working better now… the patch files are very similar…

Problem solved! I had to set binmode on all three files in question:

require “gdiff”

source = File.new(ARGV[0])  
source.binmode

target = File.new(ARGV[1])  
target.binmode

$stdout.binmode

puts Diff::GDiff.diff(source.read, target.read).pack

///////\

Sorry for the running soap-opera-like updates, but it sure was  
exciting wasn’t it!?  
If anyone needs GDiff/GPatch to run on Windows they can send me an email  
and I’ll give them the full run-down.

Les
