Update of /cvsroot/jython/jython/org/python/core
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20407/org/python/core
Modified Files:
ByteSwapper.java BytecodeLoader.java BytecodeLoader1.java
BytecodeLoader2.java
Log Message:
reformat
Index: ByteSwapper.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/core/ByteSwapper.java,v
retrieving revision 2.1
retrieving revision 2.2
diff -C2 -d -r2.1 -r2.2
*** ByteSwapper.java 3 Jun 2005 04:19:26 -0000 2.1
--- ByteSwapper.java 30 Sep 2005 19:48:45 -0000 2.2
***************
*** 14,18 ****
* limitations under the License.
*/
!
package org.python.core;
--- 14,18 ----
* limitations under the License.
*/
!
package org.python.core;
***************
*** 21,25 ****
/**
* Simple class that provides the capability to swap or reverse the byte order
! * of all elements of an <code>Array</code>. Used to convert from one endian
* type to another. The class swaps the following types:
* <ul>
--- 21,25 ----
/**
* Simple class that provides the capability to swap or reverse the byte order
! * of all elements of an <code>Array</code>. Used to convert from one endian
* type to another. The class swaps the following types:
* <ul>
***************
*** 29,196 ****
* <li>float</li>
* <li>double</li>
! * </ul><p />
! * Note this functionality is provided in the base types since 1.5.
! *
* @author Andrew Howard
*/
public class ByteSwapper {
-
- /**
- * Reverses the byte order of all elements in the supplied array,
- * converting between little and big endian byte order.
- *
- * @param array the input array for type sensitive byte swapping.
- */
- public static void swap(Object array) {
- Class arrayType = array.getClass().getComponentType();
! if (arrayType.isPrimitive()) {
! if (arrayType == Boolean.TYPE)
! return;
! else if (arrayType == Byte.TYPE)
! return;
! else if (arrayType == Character.TYPE)
! return;
! else if (arrayType == Short.TYPE)
! swapShortArray(array);
! else if (arrayType == Integer.TYPE)
! swapIntegerArray(array);
! else if (arrayType == Long.TYPE)
! swapLongArray(array);
! else if (arrayType == Float.TYPE)
! swapFloatArray(array);
! else if (arrayType == Double.TYPE)
! swapDoubleArray(array);
! }
!
! }
!
! /**
! * Byte order reverses an <code>Array</code> of <code>doubles</code>
! *
! * @param array input array
! */
! private static void swapDoubleArray(Object array) {
! int len = Array.getLength(array);
! double dtmp;
! long tmp;
! long b1, b2, b3, b4, b5, b6, b7, b8;
!
! for(int i = 0; i < len; i++) {
! dtmp = Array.getDouble(array, i);
! tmp = Double.doubleToLongBits(dtmp);
!
! b1 = (tmp >> 0) & 0xff;
! b2 = (tmp >> 8) & 0xff;
! b3 = (tmp >> 16) & 0xff;
! b4 = (tmp >> 24) & 0xff;
! b5 = (tmp >> 32) & 0xff;
! b6 = (tmp >> 40) & 0xff;
! b7 = (tmp >> 48) & 0xff;
! b8 = (tmp >> 56) & 0xff;
! tmp = (long)(b1<<56 | b2<<48 | b3<<40 | b4<<32 |
! b5<<24 | b6<<16 | b7<<8 |
b8<<0);
!
! dtmp = Double.longBitsToDouble(tmp);
! Array.setDouble(array, i, dtmp);
! }
! }
! /**
! * Byte order reverses an <code>Array</code> of <code>floats</code>
! *
! * @param array input array
! */
! private static void swapFloatArray(Object array) {
! int len = Array.getLength(array);
! float ftmp;
! int tmp;
! int b1, b2, b3, b4;
!
! for(int i = 0; i < len; i++) {
! ftmp = Array.getFloat(array, i);
! tmp = Float.floatToIntBits(ftmp);
!
! b1 = (tmp >> 0) & 0xff;
! b2 = (tmp >> 8) & 0xff;
! b3 = (tmp >> 16) & 0xff;
! b4 = (tmp >> 24) & 0xff;
! tmp = (int)(b1<<24 | b2<<16 | b3<<8 | b4<<0);
!
! ftmp = Float.intBitsToFloat(tmp);
! Array.setFloat(array, i, ftmp);
! }
! }
! /**
! * Byte order reverses an <code>Array</code> of <code>ints</code>
! *
! * @param array input array
! */
! private static void swapIntegerArray(Object array) {
! int len = Array.getLength(array);
! int tmp;
! int b1, b2, b3, b4;
!
! for(int i = 0; i < len; i++) {
! tmp = Array.getInt(array, i);
!
! b1 = (tmp >> 0) & 0xff;
! b2 = (tmp >> 8) & 0xff;
! b3 = (tmp >> 16) & 0xff;
! b4 = (tmp >> 24) & 0xff;
! tmp = (int)(b1<<24 | b2<<16 | b3<<8 | b4<<0);
!
! Array.setInt(array, i, tmp);
! }
! }
! /**
! * Byte order reverses an <code>Array</code> of <code>longs</code>
! *
! * @param array input array
! */
! private static void swapLongArray(Object array) {
! int len = Array.getLength(array);
! long tmp;
! long b1, b2, b3, b4, b5, b6, b7, b8;
!
! for(int i = 0; i < len; i++) {
! tmp = Array.getLong(array, i);
!
! b1 = (tmp >> 0) & 0xff;
! b2 = (tmp >> 8) & 0xff;
! b3 = (tmp >> 16) & 0xff;
! b4 = (tmp >> 24) & 0xff;
! b5 = (tmp >> 32) & 0xff;
! b6 = (tmp >> 40) & 0xff;
! b7 = (tmp >> 48) & 0xff;
! b8 = (tmp >> 56) & 0xff;
! tmp = (long)(b1<<56 | b2<<48 | b3<<40 | b4<<32 |
! b5<<24 | b6<<16 | b7<<8 |
b8<<0);
!
! Array.setLong(array, i, tmp);
! }
! }
! /**
! * Byte order reverses an <code>Array</code> of <code>shorts</code>
! *
! * @param array input array
! */
! private static void swapShortArray(Object array) {
! int len = Array.getLength(array);
! short tmp;
! int b1, b2;
!
! for(int i = 0; i < len; i++) {
! tmp = Array.getShort(array, i);
!
! b1 = (tmp >> 0) & 0xff;
! b2 = (tmp >> 8) & 0xff;
! tmp = (short)(b1<<8 | b2<<0);
!
! Array.setShort(array, i, tmp);
! }
! }
}
--- 29,198 ----
* <li>float</li>
* <li>double</li>
! * </ul>
! * <p />
! * Note this functionality is provided in the base types since 1.5.
! *
* @author Andrew Howard
*/
public class ByteSwapper {
! /**
! * Reverses the byte order of all elements in the supplied array,
converting
! * between little and big endian byte order.
! *
! * @param array the input array for type sensitive byte swapping.
! */
! public static void swap(Object array) {
! Class arrayType = array.getClass().getComponentType();
! if (arrayType.isPrimitive()) {
! if (arrayType == Boolean.TYPE) {
! return;
! } else if (arrayType == Byte.TYPE) {
! return;
! } else if (arrayType == Character.TYPE) {
! return;
! } else if (arrayType == Short.TYPE) {
! swapShortArray(array);
! } else if (arrayType == Integer.TYPE) {
! swapIntegerArray(array);
! } else if (arrayType == Long.TYPE) {
! swapLongArray(array);
! } else if (arrayType == Float.TYPE) {
! swapFloatArray(array);
! } else if (arrayType == Double.TYPE) {
! swapDoubleArray(array);
! }
! }
! }
! /**
! * Byte order reverses an <code>Array</code> of <code>doubles</code>
! *
! * @param array input array
! */
! private static void swapDoubleArray(Object array) {
! int len = Array.getLength(array);
! double dtmp;
! long tmp;
! long b1, b2, b3, b4, b5, b6, b7, b8;
! for (int i = 0; i < len; i++) {
! dtmp = Array.getDouble(array, i);
! tmp = Double.doubleToLongBits(dtmp);
!
! b1 = (tmp >> 0) & 0xff;
! b2 = (tmp >> 8) & 0xff;
! b3 = (tmp >> 16) & 0xff;
! b4 = (tmp >> 24) & 0xff;
! b5 = (tmp >> 32) & 0xff;
! b6 = (tmp >> 40) & 0xff;
! b7 = (tmp >> 48) & 0xff;
! b8 = (tmp >> 56) & 0xff;
! tmp = b1 << 56 | b2 << 48 | b3 << 40 | b4 << 32 | b5 << 24
! | b6 << 16 | b7 << 8 | b8 << 0;
!
! dtmp = Double.longBitsToDouble(tmp);
! Array.setDouble(array, i, dtmp);
! }
! }
!
! /**
! * Byte order reverses an <code>Array</code> of <code>floats</code>
! *
! * @param array input array
! */
! private static void swapFloatArray(Object array) {
! int len = Array.getLength(array);
! float ftmp;
! int tmp;
! int b1, b2, b3, b4;
!
! for (int i = 0; i < len; i++) {
! ftmp = Array.getFloat(array, i);
! tmp = Float.floatToIntBits(ftmp);
!
! b1 = (tmp >> 0) & 0xff;
! b2 = (tmp >> 8) & 0xff;
! b3 = (tmp >> 16) & 0xff;
! b4 = (tmp >> 24) & 0xff;
! tmp = b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0;
!
! ftmp = Float.intBitsToFloat(tmp);
! Array.setFloat(array, i, ftmp);
! }
! }
!
! /**
! * Byte order reverses an <code>Array</code> of <code>ints</code>
! *
! * @param array input array
! */
! private static void swapIntegerArray(Object array) {
! int len = Array.getLength(array);
! int tmp;
! int b1, b2, b3, b4;
!
! for (int i = 0; i < len; i++) {
! tmp = Array.getInt(array, i);
!
! b1 = (tmp >> 0) & 0xff;
! b2 = (tmp >> 8) & 0xff;
! b3 = (tmp >> 16) & 0xff;
! b4 = (tmp >> 24) & 0xff;
! tmp = b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0;
!
! Array.setInt(array, i, tmp);
! }
! }
!
! /**
! * Byte order reverses an <code>Array</code> of <code>longs</code>
! *
! * @param array input array
! */
! private static void swapLongArray(Object array) {
! int len = Array.getLength(array);
! long tmp;
! long b1, b2, b3, b4, b5, b6, b7, b8;
!
! for (int i = 0; i < len; i++) {
! tmp = Array.getLong(array, i);
!
! b1 = (tmp >> 0) & 0xff;
! b2 = (tmp >> 8) & 0xff;
! b3 = (tmp >> 16) & 0xff;
! b4 = (tmp >> 24) & 0xff;
! b5 = (tmp >> 32) & 0xff;
! b6 = (tmp >> 40) & 0xff;
! b7 = (tmp >> 48) & 0xff;
! b8 = (tmp >> 56) & 0xff;
! tmp = b1 << 56 | b2 << 48 | b3 << 40 | b4 << 32 | b5 << 24
! | b6 << 16 | b7 << 8 | b8 << 0;
!
! Array.setLong(array, i, tmp);
! }
! }
!
! /**
! * Byte order reverses an <code>Array</code> of <code>shorts</code>
! *
! * @param array input array
! */
! private static void swapShortArray(Object array) {
! int len = Array.getLength(array);
! short tmp;
! int b1, b2;
!
! for (int i = 0; i < len; i++) {
! tmp = Array.getShort(array, i);
!
! b1 = (tmp >> 0) & 0xff;
! b2 = (tmp >> 8) & 0xff;
! tmp = (short) (b1 << 8 | b2 << 0);
!
! Array.setShort(array, i, tmp);
! }
! }
}
Index: BytecodeLoader.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/core/BytecodeLoader.java,v
retrieving revision 2.15
retrieving revision 2.16
diff -C2 -d -r2.15 -r2.16
*** BytecodeLoader.java 28 Oct 2001 17:13:42 -0000 2.15
--- BytecodeLoader.java 30 Sep 2005 19:48:45 -0000 2.16
***************
*** 2,13 ****
package org.python.core;
! import java.io.*;
! import java.util.StringTokenizer;
! import java.util.Hashtable;
import java.util.Vector;
/**
! * Utility class for loading of compiled python modules and
! * java classes defined in python modules.
*/
public class BytecodeLoader {
--- 2,11 ----
package org.python.core;
!
import java.util.Vector;
/**
! * Utility class for loading of compiled python modules and java classes
defined
! * in python modules.
*/
public class BytecodeLoader {
***************
*** 19,30 ****
}
-
static Class findParentClass(Vector parents, String name)
! throws ClassNotFoundException
! {
for (int i = 0; i < parents.size(); i++) {
try {
! return ((ClassLoader)parents.elementAt(i)).loadClass(name);
! } catch(ClassNotFoundException e) { }
}
// couldn't find the .class file on sys.path
--- 17,27 ----
}
static Class findParentClass(Vector parents, String name)
! throws ClassNotFoundException {
for (int i = 0; i < parents.size(); i++) {
try {
! return ((ClassLoader) parents.elementAt(i)).loadClass(name);
! } catch (ClassNotFoundException e) {
! }
}
// couldn't find the .class file on sys.path
***************
*** 33,37 ****
static void compileClass(Class c) {
! // This method has caused much trouble. Using it breaks jdk1.2rc1
// Not using it can make SUN's jdk1.1.6 JIT slightly unhappy.
// Don't use by default, but allow python.options.compileClass to
--- 30,34 ----
static void compileClass(Class c) {
! // This method has caused much trouble. Using it breaks jdk1.2rc1
// Not using it can make SUN's jdk1.1.6 JIT slightly unhappy.
// Don't use by default, but allow python.options.compileClass to
***************
*** 43,47 ****
}
-
private static Class loaderClass = null;
--- 40,43 ----
***************
*** 52,57 ****
if (version.compareTo("1.2") >= 0) {
try {
! loaderClass =
! Class.forName("org.python.core.BytecodeLoader2");
} catch (Throwable e) {
loaderClass = BytecodeLoader1.class;
--- 48,53 ----
if (version.compareTo("1.2") >= 0) {
try {
! loaderClass = Class
! .forName("org.python.core.BytecodeLoader2");
} catch (Throwable e) {
loaderClass = BytecodeLoader1.class;
***************
*** 70,81 ****
/**
* Turn the java byte code in data into a java class.
! * @param name the name of the class
! * @param referents a list of superclass and interfaces that
! * the new class will reference.
! * @param data the java byte code.
*/
! public static Class makeClass(String name, Vector referents,
! byte[] data)
! {
Loader loader = makeLoader();
--- 66,76 ----
/**
* Turn the java byte code in data into a java class.
! *
! * @param name the name of the class
! * @param referents a list of superclass and interfaces that the new class
! * will reference.
! * @param data the java byte code.
*/
! public static Class makeClass(String name, Vector referents, byte[] data)
{
Loader loader = makeLoader();
***************
*** 83,91 ****
for (int i = 0; i < referents.size(); i++) {
try {
! Class cls = (Class)referents.elementAt(i);
ClassLoader cur = cls.getClassLoader();
! if (cur != null)
! loader.addParent(cur);
! } catch(SecurityException e) { }
}
}
--- 78,88 ----
for (int i = 0; i < referents.size(); i++) {
try {
! Class cls = (Class) referents.elementAt(i);
ClassLoader cur = cls.getClassLoader();
! if (cur != null) {
! loader.addParent(cur);
! }
! } catch (SecurityException e) {
! }
}
}
***************
*** 94,108 ****
/**
! * Turn the java byte code for a compiled python module into a
! * java class.
! * @param name the name of the class
! * @param data the java byte code.
*/
public static PyCode makeCode(String name, byte[] data) {
try {
Class c = makeClass(name, null, data);
! return ((PyRunnable)c.newInstance()).getMain();
! }
! catch (Exception e) {
throw Py.JavaError(e);
}
--- 91,104 ----
/**
! * Turn the java byte code for a compiled python module into a java class.
! *
! * @param name the name of the class
! * @param data the java byte code.
*/
public static PyCode makeCode(String name, byte[] data) {
try {
Class c = makeClass(name, null, data);
! return ((PyRunnable) c.newInstance()).getMain();
! } catch (Exception e) {
throw Py.JavaError(e);
}
Index: BytecodeLoader1.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/core/BytecodeLoader1.java,v
retrieving revision 2.4
retrieving revision 2.5
diff -C2 -d -r2.4 -r2.5
*** BytecodeLoader1.java 28 Oct 2001 17:13:42 -0000 2.4
--- BytecodeLoader1.java 30 Sep 2005 19:48:45 -0000 2.5
***************
*** 2,10 ****
package org.python.core;
! import java.io.*;
! import java.util.*;
/**
* A java1 classloader for loading compiled python modules.
*/
class BytecodeLoader1 extends ClassLoader implements Loader {
--- 2,12 ----
package org.python.core;
!
! import java.util.Vector;
/**
* A java1 classloader for loading compiled python modules.
+ *
+ * @deprecated java1 no longer supported.
*/
class BytecodeLoader1 extends ClassLoader implements Loader {
***************
*** 12,34 ****
public BytecodeLoader1() {
! parents = BytecodeLoader.init();
}
public void addParent(ClassLoader referent) {
! if (!parents.contains(referent))
! parents.addElement(referent);
}
// override from abstract base class
protected Class loadClass(String name, boolean resolve)
! throws ClassNotFoundException
! {
Class c = findLoadedClass(name);
! if (c != null)
return c;
! return BytecodeLoader.findParentClass(parents, name);
}
-
public Class loadClassFromBytes(String name, byte[] data) {
Class c = defineClass(name, data, 0, data.length);
--- 14,36 ----
public BytecodeLoader1() {
! this.parents = BytecodeLoader.init();
}
public void addParent(ClassLoader referent) {
! if (!this.parents.contains(referent)) {
! this.parents.addElement(referent);
! }
}
// override from abstract base class
protected Class loadClass(String name, boolean resolve)
! throws ClassNotFoundException {
Class c = findLoadedClass(name);
! if (c != null) {
return c;
! }
! return BytecodeLoader.findParentClass(this.parents, name);
}
public Class loadClassFromBytes(String name, byte[] data) {
Class c = defineClass(name, data, 0, data.length);
Index: BytecodeLoader2.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/core/BytecodeLoader2.java,v
retrieving revision 2.4
retrieving revision 2.5
diff -C2 -d -r2.4 -r2.5
*** BytecodeLoader2.java 28 Oct 2001 17:13:42 -0000 2.4
--- BytecodeLoader2.java 30 Sep 2005 19:48:45 -0000 2.5
***************
*** 2,8 ****
package org.python.core;
! import java.io.*;
! import java.util.*;
! import java.security.*;
/**
--- 2,8 ----
package org.python.core;
!
! import java.security.SecureClassLoader;
! import java.util.Vector;
/**
***************
*** 13,38 ****
public BytecodeLoader2() {
! parents = BytecodeLoader.init();
}
public void addParent(ClassLoader referent) {
! if (!parents.contains(referent))
! parents.addElement(referent);
}
// override from abstract base class
protected Class loadClass(String name, boolean resolve)
! throws ClassNotFoundException
! {
Class c = findLoadedClass(name);
! if (c != null)
return c;
! return BytecodeLoader.findParentClass(parents, name);
}
-
public Class loadClassFromBytes(String name, byte[] data) {
! Class c = defineClass(name, data, 0, data.length,
! this.getClass().getProtectionDomain());
resolveClass(c);
BytecodeLoader.compileClass(c);
--- 13,38 ----
public BytecodeLoader2() {
! this.parents = BytecodeLoader.init();
}
public void addParent(ClassLoader referent) {
! if (!this.parents.contains(referent)) {
! this.parents.addElement(referent);
! }
}
// override from abstract base class
protected Class loadClass(String name, boolean resolve)
! throws ClassNotFoundException {
Class c = findLoadedClass(name);
! if (c != null) {
return c;
! }
! return BytecodeLoader.findParentClass(this.parents, name);
}
public Class loadClassFromBytes(String name, byte[] data) {
! Class c = defineClass(name, data, 0, data.length, this.getClass()
! .getProtectionDomain());
resolveClass(c);
BytecodeLoader.compileClass(c);
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more.
http://solutions.newsforge.com/ibmarch.tmpl