rubinius / rubinius

The Rubinius Language Platform
https://rubinius.com
Mozilla Public License 2.0
3.07k stars 612 forks source link

File.readsymlink return a string with only spaces #256

Closed jlawler closed 14 years ago

jlawler commented 14 years ago
jlawler@papyrus:~/git/rubinius (master)$ bin/rbx -v
rubinius 1.0.0-rc4 (1.8.7 56897205 2010-03-31 JI) [i686-pc-linux-gnu]
jlawler@papyrus:~/git/rubinius (master)$ bin/mspec  core/file/readlink_spec.rb
rubinius 1.0.0-rc4 (1.8.7 56897205 2010-03-31 JI) [i686-pc-linux-gnu]
F.

1)
File.readlink return the name of the file referenced by the given link FAILED
Expected "                                                            "
to equal "/home/jlawler/git/rubinius/rubyspec_temp/1-file_readlink.txt"

                   main.__script__ {} at spec/ruby/core/file/readlink_spec.rb:22
         Kernel(Object)#instance_eval at kernel/common/eval.rb:158
            Enumerable(Array)#all? {} at kernel/common/enumerable.rb:267
                           Array#each at kernel/bootstrap/array.rb:156
               Enumerable(Array)#all? at kernel/common/enumerable.rb:267
                           Array#each at kernel/bootstrap/array.rb:156
                      main.__script__ at spec/ruby/core/file/readlink_spec.rb:3
   Rubinius::CompiledMethod#as_script at kernel/common/compiled_method.rb:242
          Requirer::Utils.single_load at kernel/delta/requirer.rb:289
         Requirer::Utils.unified_load at kernel/delta/requirer.rb:98
                          Kernel.load at kernel/common/kernel.rb:694
         Kernel(Object)#instance_eval at kernel/common/eval.rb:158
                           Array#each at kernel/bootstrap/array.rb:156
   Rubinius::CompiledMethod#as_script at kernel/common/compiled_method.rb:242
          Requirer::Utils.single_load at kernel/delta/requirer.rb:289
  Requirer::Utils.load_from_extension at kernel/delta/requirer.rb:374
              Rubinius::Loader#script at kernel/loader.rb:417
                Rubinius::Loader#main at kernel/loader.rb:529
                    Object#__script__ at kernel/loader.rb:534

Finished in 0.004115 seconds

1 file, 2 examples, 2 expectations, 1 failure, 0 errors

Given the fact that File.readlink directly maps to POSIX.readlink, I would guess this is a problem with ffi. I am unable to follow it any further than I have without digging into ffi code.

evanphx commented 14 years ago

Fix File.readlink. Closed by 9e5b900b98c6db280289239c4b97e1ae7ed91319.

FFI used to be able to manipuate a String objects insides, thats how this method expected to work. We removed that functionality at some time in the past because it's too hard to make work properly (and it's not compatible with ruby-ffi).

The proper way is to use an explicit MemoryPointer and read the data back out of it, as is done here.