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

oj: error: use of undeclared identifier 'rb_eEncodingError' #1437

Closed
deepj opened this issue Oct 28, 2018 · 17 comments
Closed

oj: error: use of undeclared identifier 'rb_eEncodingError' #1437

deepj opened this issue Oct 28, 2018 · 17 comments
Assignees
Milestone

Comments

@deepj
Copy link

deepj commented Oct 28, 2018

Hello,
I'm trying one of my project on truffle ruby 1.0.0-rc8, and it uses oj gem. I'm getting this error

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

    current directory: ~/.gem/truffleruby/2.4.4/gems/oj-3.6.13/ext/oj
~/.rubies/truffleruby-1.0.0-rc8/bin/truffleruby -r ./siteconf20181028-97127-10xa5ts.rb extconf.rb
>>>>> Creating Makefile for truffleruby version 2.4.4 on x86_64-darwin <<<<<
creating Makefile

current directory: ~/.gem/truffleruby/2.4.4/gems/oj-3.6.13/ext/oj
make "DESTDIR=" clean

current directory: ~/.gem/truffleruby/2.4.4/gems/oj-3.6.13/ext/oj
make "DESTDIR="
compiling cache8.c
compiling circarray.c
compiling code.c
compiling compat.c
compiling custom.c
custom.c:423:15: error: use of undeclared identifier 'rb_eEncodingError'
            rb_raise(rb_eEncodingError, "Invalid type for raw JSON.\n");
                     ^
1 error generated.
make: *** [custom.bc] Error 1

make failed, exit code 2

Gem files will remain installed in ~/.gem/truffleruby/2.4.4/gems/oj-3.6.13 for inspection.
Results logged to ~/.gem/truffleruby/2.4.4/extensions/x86_64-darwin/2.4.0/oj-3.6.13/gem_make.out
@deepj
Copy link
Author

deepj commented Oct 28, 2018

Noticed now, there is #1400

Anyway, I couldn't find this particular error has been reported.

@eregon
Copy link
Member

eregon commented Nov 4, 2018

Thank you for the report.

I'll define rb_eEncodingError, but oj has code that relies on specific Ruby implementations names, so it won't quite work yet:
https://github.com/ohler55/oj/blob/a3cf48212d087ddbdb953565a795d02e7db5f8e3/ext/oj/extconf.rb#L31

Additionally, the oj code seems to have a bug, oj.c has a fallback defining rb_eEncodingError but custom.c does not, leading to the error you reported. That fallback should likely be defined in oj.h.

@deepj
Copy link
Author

deepj commented Nov 4, 2018

@eregon reported ohler55/oj#513

@eregon
Copy link
Member

eregon commented Nov 4, 2018

I added rb_eEncodingError in 8d4d80c.

Now, installing oj fails with:

$ gem install oj
Building native extensions.  This could take a while...
ERROR:  Error installing oj:
	ERROR: Failed to build gem native extension.

    current directory: truffleruby/lib/ruby/gems/2.4.0/gems/oj-3.7.0/ext/oj
truffleruby/bin/truffleruby -r ./siteconf20181104-22422-17fl85z.rb extconf.rb
>>>>> Creating Makefile for truffleruby version 2.4.4 on x86_64-linux <<<<<
creating Makefile

current directory: truffleruby/lib/ruby/gems/2.4.0/gems/oj-3.7.0/ext/oj
make "DESTDIR=" clean

current directory: truffleruby/lib/ruby/gems/2.4.0/gems/oj-3.7.0/ext/oj
make "DESTDIR="
compiling cache8.c
compiling circarray.c
compiling code.c
compiling compat.c
compiling custom.c
compiling dump.c
dump.c:324:16: warning: variable 'cnt' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    } else if (0xFC == (0xFE & b)) {
               ^~~~~~~~~~~~~~~~~~
dump.c:330:16: note: uninitialized use occurs here
    for (; 0 < cnt; cnt--, str++) {
               ^~~
dump.c:324:12: note: remove the 'if' if its condition is always true
    } else if (0xFC == (0xFE & b)) {
           ^~~~~~~~~~~~~~~~~~~~~~~~
dump.c:314:13: note: initialize the variable 'cnt' to silence this warning
    int         cnt;
                   ^
                    = 0
1 warning generated.
compiling dump_compat.c
compiling dump_leaf.c
compiling dump_object.c
compiling dump_strict.c
dump_strict.c:18:9: warning: 'rb_eEncodingError' macro redefined [-Wmacro-redefined]
#define rb_eEncodingError       rb_eException
        ^
truffleruby/lib/cext/include/truffleruby/constants.h:83:9: note: previous definition is here
#define rb_eEncodingError rb_tr_get_EncodingError()
        ^
1 warning generated.
compiling err.c
compiling fast.c
compiling hash.c
compiling hash_test.c
compiling mimic_json.c
compiling object.c
compiling odd.c
compiling oj.c
oj.c:23:9: warning: 'rb_eEncodingError' macro redefined [-Wmacro-redefined]
#define rb_eEncodingError       rb_eException
        ^
truffleruby/lib/cext/include/truffleruby/constants.h:83:9: note: previous definition is here
#define rb_eEncodingError rb_tr_get_EncodingError()
        ^
1 warning generated.
compiling parse.c
compiling rails.c
rails.c:1027:5: error: statement requires expression of integer type ('VALUE' (aka 'void *') invalid)
    switch (state) {
    ^       ~~~~~
rails.c:1028:10: error: expression is not an integer constant expression
    case Qtrue:
         ^~~~~
truffleruby/lib/cext/include/ruby/ruby.h:431:15: note: expanded from macro 'Qtrue'
#define Qtrue ((VALUE)(&rb_tr_true))
              ^~~~~~~~~~~~~~~~~~~~~~
rails.c:1029:10: error: expression is not an integer constant expression
    case Qfalse:
         ^~~~~~
truffleruby/lib/cext/include/ruby/ruby.h:430:16: note: expanded from macro 'Qfalse'
#define Qfalse ((VALUE)(&rb_tr_false))
               ^~~~~~~~~~~~~~~~~~~~~~~
rails.c:1031:10: error: expression is not an integer constant expression
    case Qnil:
         ^~~~
truffleruby/lib/cext/include/ruby/ruby.h:432:14: note: expanded from macro 'Qnil'
#define Qnil ((VALUE)(&rb_tr_nil))
             ^~~~~~~~~~~~~~~~~~~~~
4 errors generated.
make: *** [Makefile:212: rails.bc] Error 1

make failed, exit code 2

The warning: 'rb_eEncodingError' macro redefined is a problem in oj I mentioned above.

The switch error is a problem in our current C extension support, which we might fix later.

@ohler55
Copy link

ohler55 commented Nov 8, 2018

Did the latest changes n the branch work for you?

@eregon
Copy link
Member

eregon commented Nov 9, 2018

They do, thank you. (also mentioned in ohler55/oj#513 (comment))

@deepj
Copy link
Author

deepj commented Dec 5, 2018

I guess this can be closed since oj is possible to compile "successfully". On the other hand, require 'oj' fails anyway...

@ohler55
Copy link

ohler55 commented Dec 5, 2018

How does it fail?

@deepj
Copy link
Author

deepj commented Dec 5, 2018

@ohler55

$ ruby -v
truffleruby 1.0.0-rc10, like ruby 2.4.4, GraalVM CE Native [x86_64-darwin]
$ gem list | grep oj
oj (3.7.4)
$ irb
irb(main):001:0> require 'oj'
RuntimeError: Cannot convert LLVMTypedForeignObject+0x0 to LLVMNativePointer (IllegalStateException)
	from java.lang.Throwable.<init>(Throwable.java:287)
	from java.lang.Exception.<init>(Exception.java:84)
	from java.lang.RuntimeException.<init>(RuntimeException.java:80)
	from java.lang.IllegalStateException.<init>(IllegalStateException.java:75)
	from com.oracle.truffle.llvm.runtime.nodes.api.LLVMToNativeNode$LLVMObjectToNativeNode.transitionToNative(LLVMToNativeNode.java:117)
	from com.oracle.truffle.llvm.runtime.nodes.api.LLVMToNativeNodeGen$LLVMObjectToNativeNodeGen.executeAndSpecialize(LLVMToNativeNodeGen.java:301)
	from com.oracle.truffle.llvm.runtime.nodes.api.LLVMToNativeNodeGen$LLVMObjectToNativeNodeGen.executeWithTarget(LLVMToNativeNodeGen.java:201)
	from com.oracle.truffle.llvm.runtime.nodes.api.LLVMToNativeNode.doOther(LLVMToNativeNode.java:78)
	from com.oracle.truffle.llvm.runtime.nodes.api.LLVMToNativeNodeGen.executeAndSpecialize(LLVMToNativeNodeGen.java:129)
	from com.oracle.truffle.llvm.runtime.nodes.api.LLVMToNativeNodeGen.executeWithTarget(LLVMToNativeNodeGen.java:50)
Caused by:
Message not supported: TO_NATIVE (UnsupportedMessageException)
	from java.lang.Throwable.<init>(Throwable.java:265)
	from java.lang.Exception.<init>(Exception.java:66)
	from com.oracle.truffle.api.interop.InteropException.<init>(InteropException.java:52)
	from com.oracle.truffle.api.interop.UnsupportedMessageException.<init>(UnsupportedMessageException.java:57)
	from com.oracle.truffle.api.interop.UnsupportedMessageException.raise(UnsupportedMessageException.java:84)
	from com.oracle.truffle.api.interop.InteropAccessNode.createMessageTarget(InteropAccessNode.java:261)
	from com.oracle.truffle.api.interop.InteropAccessNodeGen.executeAndSpecialize(InteropAccessNodeGen.java:72)
	from com.oracle.truffle.api.interop.InteropAccessNodeGen.executeImpl(InteropAccessNodeGen.java:45)
	from com.oracle.truffle.api.interop.InteropAccessNode.execute(InteropAccessNode.java:69)
	from com.oracle.truffle.api.interop.ForeignAccess.sendToNative(ForeignAccess.java:432)
Translated to internal error
	from ~/.rubies/truffleruby-1.0.0-rc10/lib/mri/rubygems/core_ext/kernel_require.rb:55:in `gem_original_require'
	from ~/.rubies/truffleruby-1.0.0-rc10/lib/mri/rubygems/core_ext/kernel_require.rb:55:in `require'
	from ~/.gem/truffleruby/2.4.4/gems/oj-3.7.4/lib/oj.rb:21:in `<top (required)>'
	from ~/.rubies/truffleruby-1.0.0-rc10/lib/mri/rubygems/core_ext/kernel_require.rb:133:in `gem_original_require'
	from ~/.rubies/truffleruby-1.0.0-rc10/lib/mri/rubygems/core_ext/kernel_require.rb:133:in `require'
	from (irb):1
	from ~/.rubies/truffleruby-1.0.0-rc10/bin/irb:29:in `<main>'

@ohler55
Copy link

ohler55 commented Dec 5, 2018

I see. That gets down into the internals of Truffle. I can imagine that getting C extensions to work as expected is going to be a painful process. If there is anything I can do let me know.

@deepj
Copy link
Author

deepj commented Jan 27, 2019

@eregon I guess this has been fixed. Anyway, there is another issue with oj, see #1437 (comment) but this might be resolved by changes with native extensions in RC12

@ohler55
Copy link

ohler55 commented Jan 27, 2019

Good to know progress is being made. I appreciate the updates.

@deepj
Copy link
Author

deepj commented Feb 4, 2019

OK. With RC12 there is a new issue

irb(main):001:0> require 'oj'
ERROR: pthread_mutex_init is unsupported!
truffleruby: org.graalvm.polyglot.PolyglotException: com.oracle.truffle.llvm.runtime.LLVMExitException
Original Internal Error:
com.oracle.truffle.llvm.runtime.LLVMExitException

@eregon ^^

@ohler55
Copy link

ohler55 commented Feb 4, 2019

Is there an equivalent in the OS you are using?

@eregon
Copy link
Member

eregon commented Feb 4, 2019

@ohler55 I'm pretty sure it's a Sulong bug (our way to run C extensions), not a missing OS feature.

@deepj Would you mind opening a new issue to avoid mixing different bugs? This particular issue might also be present with other C extensions, so it seems even more important to have its own bug.

@deepj
Copy link
Author

deepj commented Feb 4, 2019

@eregon of course. I wanted to make it anyway. But closing this I’m leaving on you

@eregon
Copy link
Member

eregon commented Feb 4, 2019

@deepj Thanks!
Let's close this as the original issue (use of undeclared identifier 'rb_eEncodingError') is solved, as well as the conversion to native pointer.

@eregon eregon closed this as completed Feb 4, 2019
@eregon eregon added this to the 1.0.0-rc12 milestone Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants