Skip to content

Commit 5b8691c

Browse files
committed
Rip out stale code and jythonc support from proxy code
1 parent bcd5bb6 commit 5b8691c

20 files changed

Lines changed: 130 additions & 568 deletions

Lib/test/test_java_integration.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,6 @@ def f(evt, called=called):
9292
m.fireComponentHidden(ComponentEvent(Container(), 0))
9393
self.assertEquals(2, len(called))
9494

95-
class MethodVisibilityTest(unittest.TestCase):
96-
def test_in_dict(self):
97-
from java.awt import Container, MenuContainer, Component
98-
for c in Container, MenuContainer, Component:
99-
self.failUnless('remove' in c.__dict__,
100-
'remove expected in %s __dict__' % c)
101-
102-
def test_parent_cant_call_subclass(self):
103-
'''
104-
Makes sure that Base doesn't pick up the getVal method from Sub that
105-
takes an int
106-
'''
107-
from org.python.tests import Base, Sub
108-
b = Base()
109-
s = Sub()
110-
self.assertRaises(TypeError, b.getVal, 8)
111-
112-
def test_dir_on_java_class(self):
113-
'''Checks that basic fields and methods are in the dir of a regular Java class'''
114-
from org.python.core import Py
115-
self.failUnless('None' in dir(Py))
116-
self.failUnless('newString' in dir(Py))
117-
11895
class ExtendJavaTest(unittest.TestCase):
11996
def test_override_tostring(self):
12097
from java.lang import Object, String
@@ -190,7 +167,7 @@ class FooVector(Vector):
190167
ht = Hashtable()
191168
fv = FooVector()
192169
ht.put("a", fv)
193-
fv = ht.get("a")
170+
self.failUnless(fv is ht.get("a"))
194171

195172
class ReservedNamesTest(unittest.TestCase):
196173
"Access to java names which are al reserved words"
@@ -276,7 +253,6 @@ def test_main():
276253
test_support.run_unittest(AbstractOnSyspathTest,
277254
InstantiationTest,
278255
BeanTest,
279-
MethodVisibilityTest,
280256
ExtendJavaTest,
281257
SysIntegrationTest,
282258
AutoSuperTest,

Lib/test/test_java_visibility.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
from test import test_support
3-
from org.python.tests import Invisible, SubVisible, Visible
3+
from org.python.tests import Invisible, SubVisible, Visible, VisibleOverride
44
from org.python.tests import VisibilityResults as Results
55

66
class VisibilityTest(unittest.TestCase):
@@ -32,6 +32,9 @@ def test_visible(self):
3232
self.assertEquals(Results.EXTRA_ARG_PUBLIC_STATIC_METHOD,
3333
v.visibleStatic(0, 'a'))
3434

35+
# Ensure that the visibleInstance method from SubVisible that takes a double doesn't
36+
# leak through to the parent
37+
self.assertRaises(TypeError, v.visibleInstance, 0.0, 'b')
3538
# TODO - no way to access a field with the same name as a method
3639
#self.assertEquals(Results.PUBLIC_METHOD_FIELD, v.visibleInstance)
3740
#self.assertEquals(Results.PUBLIC_STATIC_METHOD_FIELD, Visible.visibleStatic)
@@ -49,6 +52,12 @@ def test_java_subclass(self):
4952
# return the subclass value here.
5053
self.assertEquals(Results.SUBCLASS_OVERRIDE, Visible.visibleInstance(s, 3))
5154

55+
def test_in_dict(self):
56+
for c in Visible, SubVisible, VisibleOverride:
57+
self.failUnless('visibleInstance' in c.__dict__,
58+
'visibleInstance expected in %s __dict__' % c)
59+
60+
5261

5362
def test_main():
5463
test_support.run_unittest(VisibilityTest)
Lines changed: 16 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,40 @@
11
// Copyright (c) Corporation for National Research Initiatives
2-
32
package org.python.compiler;
43

54
import java.lang.reflect.Method;
65
import java.lang.reflect.Modifier;
76

87
import org.python.core.PyObject;
98

10-
public class JavaMaker extends ProxyMaker implements ClassConstants
11-
{
9+
public class JavaMaker extends ProxyMaker implements ClassConstants {
10+
1211
public String pythonClass, pythonModule;
13-
public String[] properties;
14-
public String[] packages;
15-
PyObject methods;
16-
public boolean frozen, main;
1712

18-
public JavaMaker(Class<?> superclass, Class<?>[] interfaces,
19-
String pythonClass, String pythonModule, String myClass,
20-
PyObject methods)
21-
{
22-
this(superclass, interfaces, pythonClass, pythonModule, myClass,
23-
null, null, methods, false, false);
24-
}
13+
PyObject methods;
2514

26-
public JavaMaker(Class<?> superclass, Class<?>[] interfaces,
27-
String pythonClass, String pythonModule, String myClass,
28-
String[] packages, String[] properties,
29-
PyObject methods,
30-
boolean frozen, boolean main)
31-
{
15+
public JavaMaker(Class<?> superclass,
16+
Class<?>[] interfaces,
17+
String pythonClass,
18+
String pythonModule,
19+
String myClass,
20+
PyObject methods) {
3221
super(myClass, superclass, interfaces);
33-
// System.out.println("props: "+properties+", "+properties.length);
3422
this.pythonClass = pythonClass;
3523
this.pythonModule = pythonModule;
36-
this.packages = packages;
37-
this.properties = properties;
38-
this.frozen = frozen;
39-
this.main = main;
4024
this.methods = methods;
4125
}
4226

43-
private void makeStrings(Code code, String[] list) throws Exception {
44-
if (list != null) {
45-
int n = list.length;
46-
code.iconst(n);
47-
code.anewarray(code.pool.Class("java/lang/String"));
48-
int strings = code.getLocal("[java/lang/String");
49-
code.astore(strings);
50-
for(int i=0; i<n; i++) {
51-
code.aload(strings);
52-
code.iconst(i);
53-
code.ldc(list[i]);
54-
code.aastore();
55-
}
56-
code.aload(strings);
57-
code.freeLocal(strings);
58-
} else {
59-
code.aconst_null();
60-
}
61-
}
62-
63-
public void addConstructor(String name, Class<?>[] parameters, Class<?> ret,
64-
String sig, int access)
65-
throws Exception
66-
{
27+
public void addConstructor(String name,
28+
Class<?>[] parameters,
29+
Class<?> ret,
30+
String sig,
31+
int access) throws Exception {
6732
/* Need a fancy constructor for the Java side of things */
6833
Code code = classfile.addMethod("<init>", sig, access);
6934
callSuper(code, "<init>", name, parameters, null, sig);
7035
code.aload(0);
7136
getArgs(code, parameters);
72-
37+
7338
int initProxy = code.pool.Methodref(classfile.name,
7439
"__initProxy__",
7540
"([Ljava/lang/Object;)V");
@@ -80,34 +45,20 @@ public void addConstructor(String name, Class<?>[] parameters, Class<?> ret,
8045
public void addProxy() throws Exception {
8146
if (methods != null)
8247
super.addProxy();
83-
8448
// _initProxy method
8549
Code code = classfile.addMethod("__initProxy__", "([Ljava/lang/Object;)V", Modifier.PUBLIC);
86-
8750
code.aload(0);
8851
code.ldc(pythonModule);
8952
code.ldc(pythonClass);
90-
9153
code.aload(1);
92-
93-
makeStrings(code, packages);
94-
makeStrings(code, properties);
95-
96-
code.iconst(frozen ? 1 : 0);
97-
9854
int initProxy = code.pool.Methodref("org/python/core/Py", "initProxy", "(" + $pyProxy
99-
+ $str + $str + $objArr + $strArr + $strArr + "Z)V");
55+
+ $str + $str + $objArr + ")V");
10056
code.invokestatic(initProxy);
10157
code.return_();
10258

103-
if (main)
104-
addMain();
10559
}
10660

10761
public void addMethod(Method method, int access) throws Exception {
108-
//System.out.println("add: "+method.getName()+", "+
109-
// methods.containsKey(method.getName()));
110-
// Check to see if it's an abstract method
11162
if (Modifier.isAbstract(access)) {
11263
// Maybe throw an exception here???
11364
super.addMethod(method, access);
@@ -117,24 +68,4 @@ public void addMethod(Method method, int access) throws Exception {
11768
addSuperMethod(method, access);
11869
}
11970
}
120-
121-
public void addMain() throws Exception {
122-
Code code = classfile.addMethod("main", "(" + $str + ")V", ClassFile.PUBLIC
123-
| ClassFile.STATIC);
124-
125-
// Load the class of the Python module to run
126-
int forname = code.pool.Methodref("java/lang/Class", "forName", "(" + $str + ")" + $clss);
127-
code.ldc(pythonModule);
128-
code.invokestatic(forname);
129-
130-
// Load in any command line arguments
131-
code.aload(0);
132-
makeStrings(code, packages);
133-
makeStrings(code, properties);
134-
code.iconst(frozen ? 1 : 0);
135-
int runMain = code.pool.Methodref("org/python/core/Py", "runMain", "(" + $clss + $strArr
136-
+ $strArr + $strArr + "Z)V");
137-
code.invokestatic(runMain);
138-
code.return_();
139-
}
14071
}

src/org/python/compiler/ProxyMaker.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import org.python.core.Py;
1717

18-
public class ProxyMaker implements ClassConstants
18+
public class ProxyMaker implements ClassConstants
1919
{
2020
public static final int tBoolean=0;
2121
public static final int tByte=1;
@@ -33,15 +33,15 @@ public class ProxyMaker implements ClassConstants
3333

3434
public static Map<Class<?>, Integer> fillTypes() {
3535
Map<Class<?>, Integer> types = new HashMap<Class<?>, Integer>();
36-
types.put(Boolean.TYPE, new Integer(tBoolean));
37-
types.put(Byte.TYPE, new Integer(tByte));
38-
types.put(Short.TYPE, new Integer(tShort));
39-
types.put(Integer.TYPE, new Integer(tInteger));
40-
types.put(Long.TYPE, new Integer(tLong));
41-
types.put(Float.TYPE, new Integer(tFloat));
42-
types.put(Double.TYPE, new Integer(tDouble));
43-
types.put(Character.TYPE, new Integer(tCharacter));
44-
types.put(Void.TYPE, new Integer(tVoid));
36+
types.put(Boolean.TYPE, tBoolean);
37+
types.put(Byte.TYPE, tByte);
38+
types.put(Short.TYPE, tShort);
39+
types.put(Integer.TYPE, tInteger);
40+
types.put(Long.TYPE, tLong);
41+
types.put(Float.TYPE, tFloat);
42+
types.put(Double.TYPE, tDouble);
43+
types.put(Character.TYPE, tCharacter);
44+
types.put(Void.TYPE, tVoid);
4545
return types;
4646
}
4747

@@ -60,7 +60,6 @@ public static int getType(Class<?> c) {
6060
public String myClass;
6161
public boolean isAdapter=false;
6262

63-
// Ctor used by makeProxy and AdapterMaker.
6463
public ProxyMaker(String classname, Class<?> superclass) {
6564
this.myClass = "org.python.proxies."+classname;
6665
if (superclass.isInterface()) {
@@ -72,7 +71,6 @@ public ProxyMaker(String classname, Class<?> superclass) {
7271
}
7372
}
7473

75-
// Ctor used by javamaker.
7674
public ProxyMaker(String myClass, Class<?> superclass, Class<?>[] interfaces) {
7775
this.myClass = myClass;
7876
if (superclass == null)
@@ -389,9 +387,8 @@ public void callMethod(Code code,
389387
code.ldc(ret.getName());
390388
code.invokestatic(forname);
391389

392-
int tojava = code.pool.Methodref(
393-
"org/python/core/Py", "tojava",
394-
"(" + $pyObj + $clss + ")" + $obj);
390+
int tojava = code.pool.Methodref("org/python/core/Py", "tojava", "(" + $pyObj
391+
+ $clss + ")" + $obj);
395392
code.invokestatic(tojava);
396393
// I guess I need this checkcast to keep the verifier happy
397394
code.checkcast(code.pool.Class(mapClass(ret)));

src/org/python/core/MakeProxies.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ public static synchronized Class<?> makeProxy(Class<?> superclass,
5959
} else {
6060
pythonModuleName = (String) mn.__tojava__(String.class);
6161
}
62-
JavaMaker jm = new JavaMaker(superclass, interfaces, className,
63-
pythonModuleName, fullProxyName, dict);
62+
JavaMaker jm = new JavaMaker(superclass,
63+
interfaces,
64+
className,
65+
pythonModuleName,
66+
fullProxyName,
67+
dict);
6468
try {
6569
jm.build();
6670
ByteArrayOutputStream bytes = new ByteArrayOutputStream();

src/org/python/core/NewCompilerResources.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ public static PyObject makeClass(String name, PyObject[] bases,
4343
if (metaclass == null) {
4444
if (bases.length != 0) {
4545
PyObject base = bases[0];
46-
47-
if (base instanceof PyMetaClass) {
48-
// jython-only, experimental PyMetaClass hook
49-
// xxx keep?
50-
try {
51-
java.lang.reflect.Constructor ctor = base.getClass().getConstructor(
52-
pyClassCtrSignature);
53-
return (PyObject) ctor.newInstance(new Object[] { name,
54-
new PyTuple(bases), dict, proxyClass });
55-
} catch (Exception e) {
56-
throw Py.TypeError("meta-class fails to supply proper "
57-
+ "ctr: " + base.getType().fastGetName());
58-
}
59-
}
6046
metaclass = base.__findattr__("__class__");
6147
if (metaclass == null) {
6248
metaclass = base.getType();

src/org/python/core/Options.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Options {
1818

1919
/**
2020
* When true, python exception raised in overriden methods will be shown on
21-
* stderr. This option is remarkable usefull when python is used for
21+
* stderr. This option is remarkably useful when python is used for
2222
* implementing CORBA server. Some CORBA servers will turn python exception
2323
* (say a NameError) into an anonymous user exception without any
2424
* stacktrace. Setting this option will show the stacktrace.
@@ -53,7 +53,7 @@ public class Options {
5353
public static boolean deprecatedKeywordMangling = false;
5454

5555
/**
56-
* A directory where the dynamicly generated classes are written. Nothing is
56+
* A directory where the dynamically generated classes are written. Nothing is
5757
* ever read from here, it is only for debugging purposes.
5858
*/
5959
public static String proxyDebugDirectory = null;

0 commit comments

Comments
 (0)