From: Jeff E. <JEm...@lg...> - 2003-03-26 03:57:44
|
Cool! You beat me to it. I was out today and couldn't get to it until after you had finished. -----Original Message----- From: Daniel Rall To: 'Finn Bock ' Cc: ''Mike GARCIA' '; Jeff Emanuel; ''jyt...@li...' ' Sent: 3/25/03 11:10 AM Subject: Re: [Jython-dev] [PATCH] Cross JDK support for java.lang.CharSequence > From: Finn Bock > Subject: Re: [Jython-dev] Question about Strings and java.util.regex > > [Jeff Emanuel] > > > PyString.java has this line (line 658 in the Jython 2.1 source) > > in the method __tojava__: > > > > if (c == String.class || c == Object.class || c == > Serializable.class) > > > > If you change it to this, it should work for you: > > > > if (c == String.class || c == CharSequence.class || > > c == Object.class || c == Serializable.class) > > > > I would suggest submitting a patch to the jython sourceforge site > > www.sf.net/projects/jython. > > This is also the change that I would expect to work (I haven't tested > it) but your change would tie jython to jdk1.4. That is clearly not > acceptable. > > So a patch would have to be more dynamic in nature, perhaps by loading > the CharSequence class within a try .. catch clause and only attempt to > load the class when the jdk version number is above 1.4. > > A patch that gets all this right so that it also works with jdk1.1 > applets will indeed be welcome. I didn't do anything rash like try to test this, but here's a first cut (against today's CVS): Index: org/python/core/PyString.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyString.java,v retrieving revision 2.60 diff -u -r2.60 PyString.java --- org/python/core/PyString.java 6 Nov 2002 08:15:21 -0000 2.60 +++ org/python/core/PyString.java 25 Mar 2003 17:06:02 -0000 @@ -236,6 +236,15 @@ */ public class PyString extends PySequence implements ClassDictInit { + private static Class charSequence = null; + static { + try { + charSequence = Class.forName("java.lang.CharSequence"); + } + catch (Throwable jdkLessThanOneDotFour) { + } + } + private String string; private transient int cached_hashcode=0; private transient boolean interned=false; @@ -661,7 +670,8 @@ public Object __tojava__(Class c) { //This is a hack to make almost all Java calls happy - if (c == String.class || c == Object.class || c == Serializable.class) + if (c == String.class || c == Object.class || c == Serializable.class + || (charSequence != null && charSequence.isAssignableFrom(c))) return string; if (c == Character.TYPE || c == Character.class) if (string.length() == 1) -- Daniel Rall <dl...@fi...> |