SciRuby / nmatrix

Dense and sparse linear algebra library for Ruby via SciRuby
Other
469 stars 133 forks source link

API Bug with Ruby 2.3 #538

Open gtamba opened 8 years ago

gtamba commented 8 years ago

I was having this issue when I tried testing my gem on Ruby 2.3 and greater. The gem adds the nmatrix.h header to the native include path so that NMatrix objects can be created directly from C code. There is no problem with running NMatrix outside on a terminal or ruby scripts, it's just a macro clash that occurs when SpiceRub is building

In file included from ../../../../ext/spice_rub/spice_ephemerides.h:5:0,
                 from ../../../../ext/spice_rub/spice_ephemerides.c:1:
/home/gaurav/.rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/nmatrix-0.2.1/nmatrix.h:72:1: error: redefinition of ‘rb_array_const_ptr’
 rb_array_const_ptr(VALUE a)
 ^
In file included from /home/gaurav/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby.h:33:0,
                 from ../../../../ext/spice_rub/spice_ephemerides.h:1,
                 from ../../../../ext/spice_rub/spice_ephemerides.c:1:
/home/gaurav/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/ruby.h:2018:1: note: previous definition of ‘rb_array_const_ptr’ was here
 rb_array_const_ptr(VALUE a)
 ^
make: *** [spice_ephemerides.o] Error 1
rake aborted!

This is the code from extconf.rb that locates the nmatrix header :-

nmatrix_path =  Gem::Specification.find_all_by_name("nmatrix")

nmatrix_header_dir = nmatrix_path.compact[0].require_path

HEADER_DIRS = [File.expand_path(File.join(File.dirname(__FILE__), "cspice/include")), nmatrix_header_dir]
translunar commented 8 years ago

Believe this is a duplicate of #522.

translunar commented 8 years ago

@gau27 Can you do the following, please?

rake clobber
rake compile

And look at the output, see if it finds rb_array_const_ptr() (and let me know).

Then look in the nmatrix_config.h file that gets generated (mine is in tmp/x86_64-darwin15/nmatrix/2.3.1) and paste it here?

gtamba commented 8 years ago

@mohawkjohn I'm unable to replicate the issue as in #522 , build works fine for just the NMatrix source. Only when I try to compile SpiceRub is this error showing up

gtamba commented 8 years ago

Can confirm that this problem arises when trying to compile SpiceRub with NMatrix built from source as well as from Rubygems for Rubies 2.3.0, 2.3.1. As Prasun said, removing the following lines from nmatrix.h seems to solve the issue without breaking any tests of NMatrix or SpiceRub. I have no idea how this will impact previous versions though.

#ifndef HAVE_RB_ARRAY_CONST_PTR
static inline const VALUE *
rb_array_const_ptr(VALUE a)
{
  return FIX_CONST_VALUE_PTR((RBASIC(a)->flags & RARRAY_EMBED_FLAG) ?
    RARRAY(a)->as.ary : RARRAY(a)->as.heap.ptr);
}
#endif
translunar commented 6 years ago

Bumping this since there's a proposed solution here, and it's relatively easy to test.