MagLev / maglev

GemStone Maglev Ruby Repository
http://maglev.github.io
518 stars 41 forks source link

atomic gem build failure #349

Open mmmries opened 10 years ago

mmmries commented 10 years ago

On the latest head (3d9829defb00ffcd750aecae8e38454da377d785) the atomic gem fails to build with the error below. A lot of gems depend on on atomic including Virtus which is what I was trying to install.

Installing atomic (1.1.16) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/michael/code/maglev/bin/maglev-ruby extconf.rb
checking for libkern/OSAtomic.h... yes
creating Makefile

make
gcc  -I. -I. -I/Users/michael/code/maglev/lib/ruby/1.9/include -I. -DHAVE_LIBKERN_OSATOMIC_H -DHAVE_GCC_CAS  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE      -fPIC -DTARGET_RT_MAC_CFM=0 -fno-omit-frame-pointer -fno-strict-aliasing -fexceptions     -arch x86_64  -c atomic_reference.c
atomic_reference.c:35:5: warning: implicit declaration of function 'DATA_PTR' is invalid in C99 [-Wimplicit-function-declaration]
    DATA_PTR(self) = (void *) value;
    ^
atomic_reference.c:35:20: error: expression is not assignable
    DATA_PTR(self) = (void *) value;
    ~~~~~~~~~~~~~~ ^
atomic_reference.c:44:20: error: expression is not assignable
    DATA_PTR(self) = (void *) new_value;
    ~~~~~~~~~~~~~~ ^
atomic_reference.c:51:20: error: expression is not assignable
    DATA_PTR(self) = (void *) new_value;
    ~~~~~~~~~~~~~~ ^
atomic_reference.c:57:59: error: cannot take the address of an rvalue of type 'int'
    if (OSAtomicCompareAndSwap64(expect_value, new_value, &DATA_PTR(self))) {
                                                          ^~~~~~~~~~~~~~~
1 warning and 4 errors generated.
make: *** [atomic_reference.o] Error 1

Gem files will remain installed in /Users/michael/code/maglev/gems/gems/atomic-1.1.16 for inspection.
Results logged to /Users/michael/code/maglev/gems/gems/atomic-1.1.16/ext/gem_make.out
An error occured while installing atomic (1.1.16), and Bundler cannot continue.
Make sure that `gem install atomic -v '1.1.16'` succeeds before bundling.
a RubySystemExit occurred (error 2752)
topaz 1> exit
timfel commented 10 years ago

We don't support DATAPTR. Instead, the rb* API needs to be used. See also https://github.com/MagLev/maglev/blob/master/docs/Maglev_c_extensions.md

timfel commented 10 years ago

That being said, maybe there's a better way to implement this in MagLev, using the atomic support in GenStone.

timfel commented 10 years ago

Sorry for not doing anything on this. I just took a look at the atomic gem's code, and it looks like it should be straightforward to modify.

The first three lines that assign to DATA_PTR(self) need to be replaced with rb_rdata_store(self, (void*)value). The last line should work when you replace &DATA_PTR(self) with &rb_rdata_fetch(self).

If you have time to try this and it works, the updated code should work just as well on the other implementations, so a PR to the atomic gem would be perfect. You can alternatively publish the atomic gem under the name atomic-maglev- (we have code in our Rubygems that looks for such "override packages" and installs them instead of the vanilla versions)