Fix and check array types for JSS:JMAP/J2LIST

(Olof-Joachim Frahm)

From <https://github.com/armedbear/abcl/pull/60>.

Merges <https://github.com/armedbear/abcl/pull/60/commits/852463daac38615e30b6c4f1db0aeb4e32e7e2b8>.
parent 0d79f184
......@@ -142,8 +142,11 @@ arguments, key and value."
((jcall isinstance (load-time-value (ignore-errors (jclass "java.util.Dictionary"))) thing)
(iterator-run (#"elements" thing)))
(t
(let ((array (ignore-errors (#"toArray" thing))))
(if array
(let ((jarray (ignore-errors
(or (and (jclass-array-p (jclass-of thing))
thing)
(#"toArray" thing)))))
(if jarray
(loop :for i :from 0 :below (jarray-length jarray)
:do (funcall function (jarray-ref jarray i)))
(error "yet another iteration type - fix it: ~a" (jclass-name (jobject-class thing)))))))))
......@@ -192,9 +195,13 @@ iterators or a Java array."
((jcall isinstance (load-time-value (ignore-errors (jclass "java.util.Dictionary"))) thing)
(iterator-collect (#"elements" thing)))
(t
(let ((array (ignore-errors (#"toArray" thing))))
(if array
(coerce array 'list)
(let ((jarray (ignore-errors
(or (and (jclass-array-p (jclass-of thing))
thing)
(#"toArray" thing)))))
(if jarray
(loop :for i :from 0 :below (jarray-length jarray)
:collect (jarray-ref jarray i))
(error "yet another iteration type - fix it: ~a" (jclass-name (jobject-class thing))))))))))
(defun to-hashset (list)
......
......@@ -7,7 +7,24 @@
"Checking whether JSS:TO-HASHSET produces a Java object…")
(prove:ok (jss:jmap 'constantly
(java:jnew-array "java.lang.Integer" 10))
"Checking JSS:MAP on Java array of java.lang.Integer…"))
"Checking JSS:JMAP on Java array of java.lang.Integer…")
(prove:ok (jss:j2list (java:jnew-array "java.lang.Integer" 10))
"Checking JSS:J2LIST on Java array of java.langInteger…")
(prove:is (let (list)
(jss:jmap (lambda (x) (push x list))
(let ((jarray (java:jnew-array "int" 3)))
(jarray-set jarray 1 1)
(jarray-set jarray 2 2)
jarray))
(nreverse list))
'(0 1 2)
"Checking JSS:JMAP on Java array of int…")
(prove:is (jss:j2list (let ((jarray (java:jnew-array "int" 3)))
(jarray-set jarray 1 1)
(jarray-set jarray 2 2)
jarray))
'(0 1 2)
"Checking JSS:J2LIST on Java array of int…"))
(prove:finalize)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment