[graalvm-users] Inconsistent interop behavior

Chris Seaton chris.seaton at oracle.com
Thu Jun 14 16:41:44 PDT 2018


I think the problem is that TruffleRuby does not convert Java strings to Ruby strings at the point of a return from a call to Polyglot.eval.

https://github.com/oracle/truffleruby/blob/5d7724a08b283d9e8823a355b7325ba98f6057d8/doc/contributor/interop.md#string-conversion

I think this is a bug - it’s not an ‘interop message' so we hadn’t thought to do that. We should also possibly try to make all Java strings appear to be frozen Ruby strings instead of doing any conversion.

You can do this in the mean time and we will fix in the next release.

module R
  def self.eval(string)
    Truffle::Interop.from_java_string(Polyglot.eval("R", string))
  end
end

> On 14 Jun 2018, at 23:17, Rodrigo Botafogo <rodrigo.a.botafogo at gmail.com> wrote:
> 
> Hello,
> 
> I have the following R script 
> 
> ===
> var = "Hello"
> var
> var[1]
> 
> var = c("Hello")
> var
> var[1]
> ===
> 
> Running it in Graal with R I get:
> 
> ===
> > var = "Hello"
> > var
> [1] "Hello"
> > var[1]
> [1] "Hello"
> > 
> > var = c("Hello")
> > var
> [1] "Hello"
> > var[1]
> [1] "Hello"
> > 
> ===
> 
> Which is the same as running standard R.
> 
> Now in Ruby:
> 
> ===
>       var = R.eval("'Hello'")
>       p var[0]
> 
> Failure/Error: p var[0]
>      
>      NoMethodError:
>        undefined method `[]' for #<Truffle::Interop::Foreign:0x42628b2>:Truffle::Interop::Foreign
> ===
> 
> Now...
> 
> ===
>       var = R.c("Hello")
>       p var
>       p var[0]
> 
> "Hello"
> "H"
> ===
> 
> I expected R.eval("'Hello'") to be identical to R.c("Hello").
> 
> 
> 
> -- 
> Rodrigo Botafogo
> Integrando TI ao seu negócio
> 21-3010-4802/11-3010-1802
> _______________________________________________
> GraalVM-Users mailing list
> GraalVM-Users at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/graalvm-users




More information about the GraalVM-Users mailing list