Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with Ruby 2.2.0 #229

Closed
dougo opened this issue Dec 25, 2014 · 40 comments
Closed

Incompatibility with Ruby 2.2.0 #229

dougo opened this issue Dec 25, 2014 · 40 comments

Comments

@dougo
Copy link

dougo commented Dec 25, 2014

I upgraded to Ruby 2.2.0, but now I get errors when I install the JSON gem:

bash-3.2$ gem install json
Fetching: json-1.8.1.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    /Users/dorleans/.rbenv/versions/2.2.0/bin/ruby -r ./siteconf20141225-66244-1qaxb2p.rb extconf.rb
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
    VALUE result = rb_str_new(FBUFFER_PAIR(fb));
                                              ^
/Users/dorleans/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/intern.h:793:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) __extension__ (    \
        ^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' [-Wint-conversion]
    VALUE result = rb_str_new(FBUFFER_PAIR(fb));
          ^        ~~~~~~~~~~
1 warning and 1 error generated.
make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/dorleans/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/json-1.8.1 for inspection.
Results logged to /Users/dorleans/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-13/2.2.0-static/json-1.8.1/gem_make.out
bash-3.2$ ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13]
bash-3.2$ gem --version
2.4.5

I don't see anything about rb_str_new in the Ruby 2.2.0 change log, so maybe I just have something wrong with my environment? Any tips would be appreciated.

@kgrz
Copy link

kgrz commented Dec 26, 2014

Not an expert in C and can't figure out why the macro expansion is not working properly. I was able to push a small fix by avoiding the use of FBUFFER_PAIR and using FBUFFER_PTR and FBUFFER_LEN as arguments to the rb_str_new function and get the extension to compile: kgrz@e49894d

@Mehonoshin
Copy link

Hi! I'm having the same issue

@DomT4
Copy link

DomT4 commented Dec 26, 2014

Yup, same thing here:

/usr/local/opt/ruby/bin/ruby -r ./siteconf20141226-34853-1i5xphz.rb extconf.rb
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
    VALUE result = rb_str_new(FBUFFER_PAIR(fb));
                                              ^
/usr/local/Cellar/ruby/2.2.0/include/ruby-2.2.0/ruby/intern.h:793:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) __extension__ (    \
        ^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' [-Wint-conversion]
    VALUE result = rb_str_new(FBUFFER_PAIR(fb));
          ^        ~~~~~~~~~~
1 warning and 1 error generated.
make: *** [generator.o] Error 1

make failed, exit code 2

@dougo
Copy link
Author

dougo commented Dec 26, 2014

It looks like this is the commit that changed rb_str_new from a function declaration to a macro:
ruby/ruby@abac848#diff-d25389b5dda13be5e80e89f60e1cc716R779
If I remove the macro from my local copy of the Ruby 2.2.0 include, then it compiles successfully.

@dougo
Copy link
Author

dougo commented Dec 26, 2014

Here is some discussion about how the C preprocessor deals with scanning function-like macro arguments: https://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html#Argument-Prescan
Although it says "Macro arguments are completely macro-expanded before they are substituted into a macro body", apparently the scan for commas happens before the argument is macro-expanded, which is where it raises the error. So aside from wrapping the macro in an actual C function (which would require declaring the two arguments, which would defeat the purpose of using the FBUFFER_PAIR macro), I think @kgrz's fix of not using FBUFFER_PAIR is the only way to do it.

@hsbt
Copy link
Collaborator

hsbt commented Dec 27, 2014

We(ruby-core) fixed our bundled json gems like forked. see diff https://github.com/zzak/json/compare/ruby-2.2

I think we should backport our patchs into this repository. Please wait until merge it and bump version 🙇

@hedgehog
Copy link

Any ETA on when a PR might be coming? e.g. days, weeks, undefined

@zzak
Copy link
Contributor

zzak commented Dec 28, 2014

I'm still trying to work out a patch to fix 1.8.7, since that is the only blocker I imagine it should be soon. Unless we just drop 1.8.7 support all-together.

@hedgehog
Copy link

I'm not that familiar with this gem's code base.... would it not be easier to add something to the backports gem (marcandre/backports) and have that 1.8.7 dependency rather than drop support?

@zzak
Copy link
Contributor

zzak commented Dec 28, 2014

The problem is the capi has changed, and this struct isnt available in 1.8.7: https://github.com/zzak/json/blob/ruby-2.2/ext/json/ext/generator/generator.c#L518

@hedgehog
Copy link

Ack. The backport may have to be a pure ruby implementation. Rather than pull the pin (either way) maybe a non-1.8.7 gem can be released as a workaround - this will also give time to assess the level of pain caused in the 1.8.7 community.

My 2c on 1.x.y:
I think we should be cautious about dropping 1.8.7 support for such an important gem, given that it is 1.x.y series currently supported.
1.x.y is only one major version away from where we are now, 2.m.n.
While ruby evolves quickly, it is doing so because it works really well which means people are starting to look at it for serious use cases, i.e production code that doesn't change rapidly, but where the hardware might - people buy time by leaving code (expensive to develop, good code that is) unchanged and upgrading the cheap parts of the system (hardware).

@san983
Copy link

san983 commented Dec 30, 2014

Same issue here

@hedgehog
Copy link

Given ruby 1.8.7 has had its EOL announced. I think the most pragmatic approach to take is to replace it with rbx 1.3 which I've just seen is continuing 1.8.7 compatibility - but fixing bugs.

See here: http://rubini.us/2014/12/08/rubinius-1-3/

@24X7
Copy link

24X7 commented Jan 4, 2015

When is a real fix available?

@anatol
Copy link

anatol commented Jan 5, 2015

I have the same issue. Browsing internet I found this file that looks interesting http://fossies.org/linux/misc/ruby-2.2.0.tar.gz/ruby-2.2.0/ext/json/fbuffer/fbuffer.h

They replaced the problematic line with

VALUE result = rb_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));

@anatol
Copy link

anatol commented Jan 6, 2015

Indeed, after applying following patch the tests pass on my Linux Arch with ruby 2.2.0 installed

diff --git a/ext/json/ext/fbuffer/fbuffer.h b/ext/json/ext/fbuffer/fbuffer.h
index af74187..9524fb1 100644
--- a/ext/json/ext/fbuffer/fbuffer.h
+++ b/ext/json/ext/fbuffer/fbuffer.h
@@ -172,7 +172,7 @@ static FBuffer *fbuffer_dup(FBuffer *fb)

 static VALUE fbuffer_to_s(FBuffer *fb)
 {
-    VALUE result = rb_str_new(FBUFFER_PAIR(fb));
+    VALUE result = rb_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
     fbuffer_free(fb);
     FORCE_UTF8(result);
     return result;

@DouglasAllen
Copy link

It's not that I need json-1.7.7.gem
But gem install devcenter requires it.
Let's get them updated for Ruby 2.2.0
Maybe Heroku can try bson and get things working faster yet or will this cost us? ;-)
mongodb requires it so json could perhaps gain some performance with it also IMHO.
Anyway now that I'm sidetracked and up on a spur I can leave this parked line and and go find ragel and G2. Thanks Mario Bro. https://aur.archlinux.org/packages/?O=0&C=10&SeB=nd&K=ruby-json+1.7.7&outdated=&SB=n&SO=a&PP=50&do_Search=Go

jrafanie added a commit to jrafanie/excon that referenced this issue Jan 27, 2015
Excon depends on json via the rdoc dependency.  We need to add an direct
dependency on json since the rdoc dependency for json (~> 1.4) doesn't enforce 1.8.2.

See: flori/json#229
jrafanie added a commit to jrafanie/excon that referenced this issue Jan 27, 2015
Excon depends on json via the rdoc dependency.  We need to add a direct
dependency on json since the rdoc dependency for json (~> 1.4) doesn't enforce 1.8.2.

See: flori/json#229
jrafanie added a commit to jrafanie/excon that referenced this issue Jan 27, 2015
Excon depends on json via the rdoc dependency.  We need to add a direct
dependency on json since the rdoc dependency for json (~> 1.4) doesn't enforce 1.8.2.

See: flori/json#229
jrafanie added a commit to jrafanie/excon that referenced this issue Jan 27, 2015
Excon depends on json via the rdoc dependency.  We need to add a direct
dependency on json since the rdoc dependency for json (~> 1.4) doesn't enforce 1.8.2.

See: flori/json#229
@MaxGabriel
Copy link

I think this can be closed with the 1.8.2 release. I just tested and was able to install json without any problems on 2.2.0, where previously that machine ran into the too few arguments error.

@flori
Copy link
Owner

flori commented Feb 3, 2015

Thank you I am closing this issue.

Nitrodist added a commit to Nitrodist/rails-erd that referenced this issue Sep 8, 2016
When installing the json gem with ruby 2.2.x, compilation fails. The
details of why it is failing are in this[0] github issue. Subsequent gem
releases (1.8.2+) have fixed the issue, so this commit bumps the gem to
the latest non-broken version so that people with ruby 2.2.x can install
and run the gh-pages for rails-erd locally.

[0] - flori/json#229
delcypher pushed a commit to klee/klee.github.io that referenced this issue Nov 17, 2016
when using Ruby 2.3.1 because of a compatability problem with the
JSON gem ( flori/json#229 ).

To do this I just removed the old gem lock file and generated a new
one.
delcypher pushed a commit to klee/klee.github.io that referenced this issue Nov 17, 2016
when using Ruby 2.3.1 because of a compatability problem with the
JSON gem ( flori/json#229 ).

To do this I just removed the old gem lock file and generated a new
one.
frankier added a commit to frankier/newrelic_platform_plugins that referenced this issue Dec 30, 2016
yasulab added a commit to yasslab/railsguides.jp that referenced this issue Jan 1, 2017
yasulab added a commit to yasslab/railsguides.jp that referenced this issue Jan 1, 2017
futurechimp pushed a commit to technicalpanda/plissken that referenced this issue Jan 13, 2017
twe4ked added a commit to freshshell/fresh that referenced this issue Jan 14, 2017
1.8.1 is incompatible with Ruby 2.2.0.

flori/json#229
@DomT4
Copy link

DomT4 commented Feb 25, 2017

#229 (comment) seems to be back with Ruby 2.4.0 on macOS Sierra 10.12.4, Bundler 1.14.5. If I switch back to using Ruby 2.0.0p648 (which is the system default on macOS 10.12.4) have no such issue. Maybe I'm barking up the wrong tree since nobody else seems to have added a new comment here, but 🤷‍♂️.

@umarsheikh
Copy link

#229 issue is back with ruby 2.4.

compiling generator.c
In file included from generator.c:1:0:
../fbuffer/fbuffer.h: In function ‘fbuffer_to_s’:
../fbuffer/fbuffer.h:175:47: error: macro "rb_str_new" requires 2 arguments, but only 1 given
../fbuffer/fbuffer.h:175:20: warning: initialization makes integer from pointer without a cast [enabled by default]
generator.c: In function ‘generate_json’:
generator.c:832:25: error: ‘rb_cFixnum’ undeclared (first use in this function)
generator.c:832:25: note: each undeclared identifier is reported only once for each function it appears in
generator.c:834:25: error: ‘rb_cBignum’ undeclared (first use in this function)
generator.c: At top level:

An error occurred while installing json (1.7.7), and Bundler cannot continue.

wayann added a commit to wayann/rethinkdb-example-sinatra-pastie that referenced this issue Mar 9, 2017
changed to branch v1.8 repo to avoid that annoying bug 
fbuffer.h > VALUE result = rb_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
flori/json#229 (comment)
hirose31 added a commit to hirose31/knife-solo that referenced this issue Apr 5, 2017
dcmoore added a commit to dcmoore/microservices that referenced this issue Apr 6, 2017
jwnx added a commit to jwnx/json that referenced this issue Jun 8, 2017
Adds support to ruby v2.2.2 by modifying rb_str_new macro parameters.

Issue: flori#229
@h0jeZvgoxFepBQ2C
Copy link

Have the same problem with ruby 2.3.4 on OSX Sierra.

@danman01
Copy link

Seems JSON version 1.8.3 does the trick http://fuzzyblog.io/blog/ruby/2016/10/11/what-to-do-when-bundle-install-fails-with-json-1-8-1.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests