rb-gsl
                                
                                 rb-gsl copied to clipboard
                                
                                    rb-gsl copied to clipboard
                            
                            
                            
                        seems to require re-writing in places
I've tried to get this gem working for ruby 3.0; unfortunately, it seems that some major changes to ruby under the hood make this a rather complex problem.
A few things are simple to fix (e.g., moving "EXTERN" to "RUBY_EXTERN" in some declarations). But other issues seem to involve changes to the macros sitting inside the ruby code itself, e.g., "RB_OBJ_WRITE", which has a new definition in ruby 3.0.
linalg.c:154:5: error: cannot take the address of an rvalue of type 'VALUE' (aka 'unsigned long')
    RBGSL_SET_CLASS(omatrix, cgsl_matrix_LU);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/rb_gsl_common.h:302:5: note: expanded from macro 'RBGSL_SET_CLASS'
    RBGSL_SET_CLASS0(_obj_, cls); \
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/rb_gsl_common.h:296:56: note: expanded from macro 'RBGSL_SET_CLASS0'
#define RBGSL_SET_CLASS0(obj0, cls) RB_OBJ_WRITE(obj0, &(RBASIC_CLASS(obj0)), cls)
                                    ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/ruby-3.0.0/ruby/internal/rgengc.h:108:52: note: expanded from macro 'RB_OBJ_WRITE'
    RBIMPL_CAST(rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/ruby-3.0.0/ruby/internal/cast.h:33:29: note: expanded from macro 'RBIMPL_CAST'
# define RBIMPL_CAST(expr) (expr)
After a lot of fiddling, I think there's a solution.
- First, replace all "EXTERN" and "extern" with "RUBY_EXTERN" and "RUBY_EXTERN". You can do this using rpl.
- The remaining problem is the RBGSL_SET_CLASS macro. In the updated ruby 3.0, there's a new macro that sets the class directly. You'll want to edit the older definition of RBGSL_SET_CLASS as follows (I think):
#ifndef RBGSL_SET_CLASS
#define RBGSL_SET_CLASS(obj, cls) do { \
    VALUE _obj_ = (obj); \
    RBASIC_SET_CLASS(_obj_, cls); \
} while (0)
#endif
- then things actually do compile. You have to wrestle with gems for awhile, but it seems to install and run from irb3.0
If anyone's reading this and is interested in updating the gem to work with 3.0, let me know.
@simon-dedeo thanks for this investigation! I ended up downgrading to Ruby 2.7 to get GSL to work but I guess this is not a good solution. It'd be great to see a fork of this working for Ruby 3 (and modern Ruby 2 as well I guess).
Who will put the bell on the cat! Do you have the skills?
Simon DeDeo Carnegie Mellon University & the Santa Fe Institute http://santafe.edu/~simon
On Feb 22, 2021, at 6:44 PM, Paweł Świątkowski [email protected] wrote:
 @simon-dedeo thanks for this investigation! I ended up downgrading to Ruby 2.7 to get GSL to work but I guess this is not a good solution. It'd be great to see a fork of this working for Ruby 3 (and modern Ruby 2 as well I guess).
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
I forked the repo and I plan to update tests to check all modern Ruby versions. Then I can release it as a gem. Any ideas for the name? gsl-reborn? gsl-next?
Oh, wow, very cool. In terms of a name, gsl-reborn is great!
I think there probably needs to be a bunch more checks to be done on the GSL code. IIRC, my fixes seemed to break the “dup” method.
It would be lovely if we could keep this alive. It seems that a lot of scientific ruby projects are dying. The last update to statsample, e.g., was in 2017.
On 23 Feb 2021, at 3:42 PM, Paweł Świątkowski [email protected] wrote:
I forked the repo and I plan to update tests to check all modern Ruby versions. Then I can release it as a gem. Any ideas for the name? rb-gsl-reborn?
I'm no longer active on this project, but I would support adding new maintainers (i.e. folks who are actually using/developing rb-gsl). That might be better than forking/renaming.
@david-macmahon that's an option too. I'm no expert in GSL though, I only use it in Jekyll for similar posts :wink: But for sure I can do some maintenance chores, this is just Ruby after all.
How does that work? I agree that it would be nice to keep things on the same name. I use GSL quite a bit, but don't have the technical skills to do more than help out occasionally.
The most recent commit seems to be from almost 4 years ago so it seems unlikely to be current/compatible with modern Ruby and GSL implementations. Looking through the issues seems to confirm that. You two seem active, motivated, and competent so I'd vote for adding you both.
It looks like the "SciRuby" organization has a "gsl-admin" team that you would need to be added to. I am a member of that team, but I cannot add new members. I think you might have to lobby someone in the SciRuby "core" team to get added to the "gsl-admin" team.
It took some time to understand all the preprocessor magic and subtle changes in Ruby 3 C API, but I created a pull request that compiles against Ruby 3, passes tests and does not break backwards compatibility: https://github.com/SciRuby/rb-gsl/pull/66
I have no idea who to "lobby" in order to get this live.
Wow! Paweł, can you tell me how I can test this out on my system here? (I.e., how I can install this as a gem from your GitHub?) That will let me test things on my side as well and I can fiddle a bit.
Meanwhile, yes! I wonder if anyone with permissions sees this. I’ll also ask people on Twitter.
On Mar 1, 2021, at 5:36 PM, Paweł Świątkowski [email protected] wrote:
 It took some time to understand all the preprocessor magic and subtle changes in Ruby 3 C API, but I created a pull request that compiles against Ruby 3, passes tests and does not break backwards compatibility: #66
I have no idea who to "lobby" in order to get this live.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
@simon-dedeo just replace gem 'gsl' in your Gemfile with
gem 'gsl', git: 'https://github.com/katafrakt/rb-gsl.git', branch: 'ruby3-compatibility'
Thank you! It certainly installed; I'm giving it a workout now.
Just wanted to update this thread in 2023.
It seems the above PR got merged:
- https://github.com/SciRuby/rb-gsl/pull/66
But at least according to this issue, hasn't been released to rubygems yet:
- https://github.com/SciRuby/rb-gsl/issues/67
See also:
- https://github.com/SciRuby/rb-gsl/issues/68
- https://github.com/SciRuby/rb-gsl/issues/69
- https://github.com/SciRuby/rb-gsl/issues/41