I am trying to connect ABCL up with some java code that uses multidimensional arrays of the form:
int[][] theArray = new int[4][4];
The problem is that when I call this code I get something like this in return:
#(#<jarray [I@2d983837 {6492BA43}> #<jarray [I@5d02b84a {5D9131FA}> #<jarray [I@67684413 {6E4D706E}> #<jarray [I@1e107e55 {4CD60DDE}>)
that is a lisp array that contains 4 java arrays. I can’t pass this off to a method like this:
static public int[][] arrayTest2(int[][] oldArray) { … }
I can work around this by creating a new java array myself (and populating it appropriately), but this is no fun. Is this the intended behavior?
thanks,
Cyrus
On Feb 6, 2014, at 2:52, Cyrus Harmon ch-lisp@bobobeach.com wrote:
I am trying to connect ABCL up with some java code that uses multidimensional arrays of the form:
int[][] theArray = new int[4][4];
The problem is that when I call this code I get something like this in return:
#(#<jarray [I@2d983837 {6492BA43}> #<jarray [I@5d02b84a {5D9131FA}> #<jarray [I@67684413 {6E4D706E}> #<jarray [I@1e107e55 {4CD60DDE}>)
that is a lisp array that contains 4 java arrays. I can’t pass this off to a method like this:
static public int[][] arrayTest2(int[][] oldArray) { … }
I can work around this by creating a new java array myself (and populating it appropriately), but this is no fun. Is this the intended behavior?
Regardless of whether this behavior was intended—for which I can find no evidence—it certainly seems wrong given that for the Java class:
public class Array { public static int[][] getMultiDimensional() { return new int[4][4]; }
public static int[][] returnRef(int[][] ref) { return ref; } }
Compiled with javac, (java:add-to-classpath “~/directory/“), then the following
CL-USER> (java:jnew-array "int" 4 4) #<jarray [[I@2e9e32cc {141906FD}> CL-USER> (jstatic "returnRef" "Array" *) #(#<jarray [I@4147aa25 {47F3849E}> #<jarray [I@4487c5f9 {2DD68195}> #<jarray [I@5dd574b5 {68E14733}> #<jarray [I@1e099b10 {8A346D8}>)
shows that we are clearly getting a different sort of Lisp object than we pass into the Java FFI for what should be a symmetric reflection.
Filed as [ticket-347][].
[ticket-347]: http://abcl.org/trac/ticket/347
On Feb 6, 2014, at 2:52, Cyrus Harmon ch-lisp@bobobeach.com wrote:
[…]
I can work around this by creating a new java array myself (and populating it appropriately), but this is no fun. Is this the intended behavior?
I’ve attached a [patch to ticket #347][1] that no longer converts multi-dimensional Java arrays to Lisp vectors of Java arrays, instead returning the primitive Java object.
I am not sure that I currently understand all the ramifications of changing this behavior, as there may be cases where this change makes things harder rather than easier, especially where people really want to be dealing with Lisp sequences rather than using a returned value for further Java calls. I don’t know specifically of any code or tests for which this change may be incompatible, as people tend to keep their “bridging to Java” ABCL code private.
Can you please test to see if this does what you want? And help me think through whether this is the right way forward for everyone? I suppose the alternative to changing the Lisp side value would be to “squash” a Lisp sequence of Java arrays down to the equivalent multi-dimensional Java array when calling into Java. Performing such a “squash” when calling into Java would have the virtue of preserving existing behavior.
[1]: http://abcl.org/trac/attachment/ticket/347/jarray-convert.diff
CL-USER> (#"getMultiDimensional" 'Array) #(#<jarray [I@2b8edf4d {30E64E92}> #<jarray [I@60306c52 {B17ACD4}> #<jarray [I@3f5397fc {91F41DF}> #<jarray [I@631d9c26 {2CF6B5A0}>) CL-USER> (#0"getMultiDimensional" 'Array) #<jarray [[I@4068f9fc {2BF4306D}>
or (jstatic-raw "getMultiDimensional" (find-java-class "Array")) #<jarray [[I@56810247 {2FBCAFAF}>
So try using #0"..." if you are using jss or jcall-raw if not.
-Alan
On Thu, Feb 6, 2014 at 9:47 AM, Mark Evenson evenson@panix.com wrote:
On Feb 6, 2014, at 2:52, Cyrus Harmon ch-lisp@bobobeach.com wrote:
I am trying to connect ABCL up with some java code that uses
multidimensional arrays of the form:
int[][] theArray = new int[4][4];
The problem is that when I call this code I get something like this in
return:
#(#<jarray [I@2d983837 {6492BA43}> #<jarray [I@5d02b84a{5D9131FA}> #<jarray [I@67684413{6E4D706E}> #<jarray [I@1e107e55{4CD60DDE}>)
that is a lisp array that contains 4 java arrays. I can’t pass this off
to a method like this:
static public int[][] arrayTest2(int[][] oldArray) { … }
I can work around this by creating a new java array myself (and
populating it appropriately), but this is no fun. Is this the intended behavior?
Regardless of whether this behavior was intended—for which I can find no evidence—it certainly seems wrong given that for the Java class:
public class Array { public static int[][] getMultiDimensional() { return new int[4][4]; }
public static int[][] returnRef(int[][] ref) { return ref; } }
Compiled with javac, (java:add-to-classpath “~/directory/“), then the following
CL-USER> (java:jnew-array "int" 4 4) #<jarray [[I@2e9e32cc {141906FD}> CL-USER> (jstatic "returnRef" "Array" *) #(#<jarray [I@4147aa25 {47F3849E}> #<jarray [I@4487c5f9 {2DD68195}> #<jarray [I@5dd574b5 {68E14733}> #<jarray [I@1e099b10 {8A346D8}>)
shows that we are clearly getting a different sort of Lisp object than we pass into the Java FFI for what should be a symmetric reflection.
Filed as [ticket-347][].
-- "A screaming comes across the sky. It has happened before but there is nothing to compare to it now."
On Feb 7, 2014, at 13:35, Alan Ruttenberg alanruttenberg@gmail.com wrote:
CL-USER> (#"getMultiDimensional" 'Array) #(#<jarray [I@2b8edf4d {30E64E92}> #<jarray [I@60306c52 {B17ACD4}> #<jarray [I@3f5397fc {91F41DF}> #<jarray [I@631d9c26 {2CF6B5A0}>) CL-USER> (#0"getMultiDimensional" 'Array) #<jarray [[I@4068f9fc {2BF4306D}>
or (jstatic-raw "getMultiDimensional" (find-java-class "Array")) #<jarray [[I@56810247 {2FBCAFAF}>
So try using #0"..." if you are using jss or jcall-raw if not.
@alan: Thanks! I feel dumb…
@cyrus: can you confirm that using the JAVA:*-RAW or JSS #0”*” methods will work for you?
Yup. That does the trick. Thanks Alan and sorry for the noise!
On Feb 7, 2014, at 4:58 AM, Mark Evenson evenson@panix.com wrote:
On Feb 7, 2014, at 13:35, Alan Ruttenberg alanruttenberg@gmail.com wrote:
CL-USER> (#"getMultiDimensional" 'Array) #(#<jarray [I@2b8edf4d {30E64E92}> #<jarray [I@60306c52 {B17ACD4}> #<jarray [I@3f5397fc {91F41DF}> #<jarray [I@631d9c26 {2CF6B5A0}>) CL-USER> (#0"getMultiDimensional" 'Array) #<jarray [[I@4068f9fc {2BF4306D}>
or (jstatic-raw "getMultiDimensional" (find-java-class "Array")) #<jarray [[I@56810247 {2FBCAFAF}>
So try using #0"..." if you are using jss or jcall-raw if not.
@alan: Thanks! I feel dumb…
@cyrus: can you confirm that using the JAVA:*-RAW or JSS #0”*” methods will work for you?
-- "A screaming comes across the sky. It has happened before but there is nothing to compare to it now."
armedbear-devel@common-lisp.net