diff options
author | Rich Hickey <richhickey@gmail.com> | 2010-09-28 13:36:55 -0400 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2010-09-28 13:36:55 -0400 |
commit | cc8372f12074b4cccbdd9cde3cfacfae069c57d3 (patch) | |
tree | 4af7a31a63baeaaa505a8bc4a9c387595c34b6ce | |
parent | a79ef89804ea3ab0bf95c4d31189555b8e355abf (diff) |
don't coerce pre-boxed Integers and Floats to Longs/Doubles, fixes #439
-rw-r--r-- | src/clj/clojure/core.clj | 2 | ||||
-rw-r--r-- | src/clj/clojure/core_proxy.clj | 2 | ||||
-rw-r--r-- | src/jvm/clojure/lang/ArraySeq.java | 19 | ||||
-rw-r--r-- | src/jvm/clojure/lang/RT.java | 4 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Reflector.java | 14 |
5 files changed, 22 insertions, 19 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index eaab3aaf..bf81da4d 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -3305,7 +3305,7 @@ :inline-arities #{2} :added "1.0"} ([array idx] - (clojure.lang.Reflector/prepRet (. Array (get array idx)))) + (clojure.lang.Reflector/prepRet (.getComponentType (class array)) (. Array (get array idx)))) ([array idx & idxs] (apply aget (aget array idx) idxs))) diff --git a/src/clj/clojure/core_proxy.clj b/src/clj/clojure/core_proxy.clj index 9f2e057b..38f4ccca 100644 --- a/src/clj/clojure/core_proxy.clj +++ b/src/clj/clojure/core_proxy.clj @@ -376,7 +376,7 @@ (let [name (. pd (getName)) method (. pd (getReadMethod))] (if (and method (zero? (alength (. method (getParameterTypes))))) - (assoc m (keyword name) (fn [] (clojure.lang.Reflector/prepRet (. method (invoke x nil))))) + (assoc m (keyword name) (fn [] (clojure.lang.Reflector/prepRet (.getPropertyType pd) (. method (invoke x nil))))) m))) {} (seq (.. java.beans.Introspector diff --git a/src/jvm/clojure/lang/ArraySeq.java b/src/jvm/clojure/lang/ArraySeq.java index c54b91ba..08f1af70 100644 --- a/src/jvm/clojure/lang/ArraySeq.java +++ b/src/jvm/clojure/lang/ArraySeq.java @@ -18,6 +18,7 @@ public class ArraySeq extends ASeq implements IndexedSeq, IReduce{ public final Object array; final int i; final Object[] oa; +final Class ct; //ISeq _rest; static public ArraySeq create(){ @@ -53,6 +54,7 @@ static ISeq createFromObject(Object array){ ArraySeq(Object array, int i){ this.array = array; + this.ct = array.getClass().getComponentType(); this.i = i; this.oa = (Object[]) (array instanceof Object[] ? array : null); // this._rest = this; @@ -61,6 +63,7 @@ ArraySeq(Object array, int i){ ArraySeq(IPersistentMap meta, Object array, int i){ super(meta); this.array = array; + this.ct = array.getClass().getComponentType(); this.i = i; this.oa = (Object[]) (array instanceof Object[] ? array : null); } @@ -68,7 +71,7 @@ ArraySeq(IPersistentMap meta, Object array, int i){ public Object first(){ if(oa != null) return oa[i]; - return Reflector.prepRet(Array.get(array, i)); + return Reflector.prepRet(ct, Array.get(array, i)); } public ISeq next(){ @@ -108,9 +111,9 @@ public Object reduce(IFn f) throws Exception{ return ret; } - Object ret = Reflector.prepRet(Array.get(array, i)); + Object ret = Reflector.prepRet(ct, Array.get(array, i)); for(int x = i + 1; x < Array.getLength(array); x++) - ret = f.invoke(ret, Reflector.prepRet(Array.get(array, x))); + ret = f.invoke(ret, Reflector.prepRet(ct, Array.get(array, x))); return ret; } @@ -122,9 +125,9 @@ public Object reduce(IFn f, Object start) throws Exception{ ret = f.invoke(ret, oa[x]); return ret; } - Object ret = f.invoke(start, Reflector.prepRet(Array.get(array, i))); + Object ret = f.invoke(start, Reflector.prepRet(ct, Array.get(array, i))); for(int x = i + 1; x < Array.getLength(array); x++) - ret = f.invoke(ret, Reflector.prepRet(Array.get(array, x))); + ret = f.invoke(ret, Reflector.prepRet(ct, Array.get(array, x))); return ret; } @@ -135,7 +138,7 @@ public int indexOf(Object o) { } else { int n = Array.getLength(array); for (int j = i; j < n; j++) - if (Util.equals(o, Reflector.prepRet(Array.get(array, j)))) return j - i; + if (Util.equals(o, Reflector.prepRet(ct, Array.get(array, j)))) return j - i; } return -1; } @@ -152,10 +155,10 @@ public int lastIndexOf(Object o) { } else { if (o == null) { for (int j = Array.getLength(array) - 1 ; j >= i; j--) - if (Reflector.prepRet(Array.get(array, j)) == null) return j - i; + if (Reflector.prepRet(ct, Array.get(array, j)) == null) return j - i; } else { for (int j = Array.getLength(array) - 1 ; j >= i; j--) - if (o.equals(Reflector.prepRet(Array.get(array, j)))) return j - i; + if (o.equals(Reflector.prepRet(ct, Array.get(array, j)))) return j - i; } } return -1; diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java index b9faea84..a7c494cb 100644 --- a/src/jvm/clojure/lang/RT.java +++ b/src/jvm/clojure/lang/RT.java @@ -725,7 +725,7 @@ static Object nthFrom(Object coll, int n){ else if(coll instanceof CharSequence) return Character.valueOf(((CharSequence) coll).charAt(n)); else if(coll.getClass().isArray()) - return Reflector.prepRet(Array.get(coll, n)); + return Reflector.prepRet(coll.getClass().getComponentType(),Array.get(coll, n)); else if(coll instanceof RandomAccess) return ((List) coll).get(n); else if(coll instanceof Matcher) @@ -776,7 +776,7 @@ static Object nthFrom(Object coll, int n, Object notFound){ } else if(coll.getClass().isArray()) { if(n < Array.getLength(coll)) - return Reflector.prepRet(Array.get(coll, n)); + return Reflector.prepRet(coll.getClass().getComponentType(),Array.get(coll, n)); return notFound; } else if(coll instanceof RandomAccess) { diff --git a/src/jvm/clojure/lang/Reflector.java b/src/jvm/clojure/lang/Reflector.java index 312a0a14..bd5a4e80 100644 --- a/src/jvm/clojure/lang/Reflector.java +++ b/src/jvm/clojure/lang/Reflector.java @@ -87,7 +87,7 @@ static Object invokeMatchingMethod(String methodName, List methods, Object targe } try { - return prepRet(m.invoke(target, boxedArgs)); + return prepRet(m.getReturnType(), m.invoke(target, boxedArgs)); } catch(InvocationTargetException e) { @@ -213,7 +213,7 @@ public static Object getStaticField(Class c, String fieldName) throws Exception{ Field f = getField(c, fieldName, true); if(f != null) { - return prepRet(f.get(null)); + return prepRet(f.getType(), f.get(null)); } throw new IllegalArgumentException("No matching field found: " + fieldName + " for " + c); @@ -240,7 +240,7 @@ public static Object getInstanceField(Object target, String fieldName) throws Ex Field f = getField(c, fieldName, false); if(f != null) { - return prepRet(f.get(target)); + return prepRet(f.getType(), f.get(target)); } throw new IllegalArgumentException("No matching field found: " + fieldName + " for " + target.getClass()); @@ -273,7 +273,7 @@ public static Object invokeInstanceMember(Object target, String name) throws Exc Field f = getField(c, name, false); if(f != null) //field get { - return prepRet(f.get(target)); + return prepRet(f.getType(), f.get(target)); } return invokeInstanceMethod(target, name, RT.EMPTY_ARRAY); } @@ -446,9 +446,9 @@ static boolean isCongruent(Class[] params, Object[] args){ return ret; } -public static Object prepRet(Object x){ -// if(c == boolean.class) -// return ((Boolean) x).booleanValue() ? RT.T : null; +public static Object prepRet(Class c, Object x){ + if (!(c.isPrimitive() || c == Boolean.class)) + return x; if(x instanceof Boolean) return ((Boolean) x)?Boolean.TRUE:Boolean.FALSE; else if(x instanceof Integer) |