From: <pj...@us...> - 2009-10-04 21:25:59
|
Revision: 6837 http://jython.svn.sourceforge.net/jython/?rev=6837&view=rev Author: pjenvey Date: 2009-10-04 21:25:41 +0000 (Sun, 04 Oct 2009) Log Message: ----------- hack around PyReflectedFunction's assumption of how instancemethod calls into it so instancemethod's ThreadState pass through optimization can be enabled Modified Paths: -------------- trunk/jython/src/org/python/core/PyMethod.java trunk/jython/src/org/python/core/PyReflectedConstructor.java trunk/jython/src/org/python/core/PyReflectedFunction.java trunk/jython/src/org/python/core/ReflectedArgs.java Modified: trunk/jython/src/org/python/core/PyMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyMethod.java 2009-10-04 20:16:12 UTC (rev 6836) +++ trunk/jython/src/org/python/core/PyMethod.java 2009-10-04 21:25:41 UTC (rev 6837) @@ -94,7 +94,7 @@ return this; } } - /*// This has been disabled since JavaFunc expects to be called with self + boxed args + @Override public PyObject __call__() { return __call__(Py.getThreadState()); @@ -146,8 +146,7 @@ } @Override - public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, - PyObject arg2) { + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2) { PyObject self = checkSelf(arg0, null); if (self == null) { return im_func.__call__(state, arg0, arg1, arg2); @@ -162,17 +161,17 @@ } @Override - public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, - PyObject arg2, PyObject arg3) { + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2, + PyObject arg3) { PyObject self = checkSelf(arg0, null); if (self == null) { return im_func.__call__(state, arg0, arg1, arg2, arg3); } else { - return im_func.__call__(state, self, new PyObject[]{arg0, arg1, arg2, arg3}, Py.NoKeywords); + return im_func.__call__(state, self, new PyObject[]{arg0, arg1, arg2, arg3}, + Py.NoKeywords); } } - @Override public PyObject __call__(PyObject arg1, PyObject[] args, String[] keywords) { return __call__(Py.getThreadState(), arg1, args, keywords); @@ -180,15 +179,15 @@ @Override public PyObject __call__(ThreadState state, PyObject arg1, PyObject[] args, - String[] keywords) { + String[] keywords) { PyObject self = checkSelf(arg1, args); if (self == null) { return im_func.__call__(state, arg1, args, keywords); } else { - PyObject[] new_args = new PyObject[args.length+1]; - System.arraycopy(args, 0, new_args, 1, args.length); - new_args[0] = arg1; - return im_func.__call__(state, self, new_args, keywords); + PyObject[] newArgs = new PyObject[args.length + 1]; + System.arraycopy(args, 0, newArgs, 1, args.length); + newArgs[0] = arg1; + return im_func.__call__(state, self, newArgs, keywords); } } @@ -201,14 +200,19 @@ public PyObject __call__(ThreadState state, PyObject[] args) { return __call__(state, args, Py.NoKeywords); } - */ + @Override public PyObject __call__(PyObject[] args, String[] keywords) { - return instancemethod___call__(args, keywords); + return __call__(Py.getThreadState(), args, keywords); } @Override public PyObject __call__(ThreadState state, PyObject[] args, String[] keywords) { + return instancemethod___call__(state, args, keywords); + } + + @ExposedMethod(doc = BuiltinDocs.instancemethod___call___doc) + final PyObject instancemethod___call__(ThreadState state, PyObject[] args, String[] keywords) { PyObject self = checkSelf(null, args); if (self == null) { return im_func.__call__(state, args, keywords); @@ -216,11 +220,6 @@ return im_func.__call__(state, self, args, keywords); } } - - @ExposedMethod(doc = BuiltinDocs.instancemethod___call___doc) - final PyObject instancemethod___call__(PyObject[] args, String[] keywords) { - return __call__(Py.getThreadState(), args, keywords); - } private PyObject checkSelf(PyObject arg, PyObject[] args) { PyObject self = im_self; Modified: trunk/jython/src/org/python/core/PyReflectedConstructor.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedConstructor.java 2009-10-04 20:16:12 UTC (rev 6836) +++ trunk/jython/src/org/python/core/PyReflectedConstructor.java 2009-10-04 21:25:41 UTC (rev 6837) @@ -77,6 +77,7 @@ return obj; } + @Override public PyObject __call__(PyObject self, PyObject[] args, String[] keywords) { if (self == null) { throw Py.TypeError("invalid self argument to constructor"); @@ -144,6 +145,7 @@ return Py.None; } + @Override public PyObject __call__(PyObject[] args, String[] keywords) { if (args.length < 1) { throw Py.TypeError("constructor requires self argument"); @@ -180,6 +182,15 @@ obj.javaProxy = jself; } + @Override + public PyObject _doget(PyObject container, PyObject wherefound) { + if (container == null) { + return this; + } + return new PyMethod(this, container, wherefound); + } + + @Override public String toString() { // printArgs(); return "<java constructor " + __name__ + " " + Py.idstr(this) + ">"; Modified: trunk/jython/src/org/python/core/PyReflectedFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedFunction.java 2009-10-04 20:16:12 UTC (rev 6836) +++ trunk/jython/src/org/python/core/PyReflectedFunction.java 2009-10-04 21:25:41 UTC (rev 6837) @@ -17,6 +17,9 @@ public int nargs; + /** Whether __call__ should act as if this is called as a static method. */ + private boolean calledStatically; + protected PyReflectedFunction(String name) { __name__ = name; } @@ -35,17 +38,22 @@ } } + @Override public PyObject _doget(PyObject container) { return _doget(container, null); } + @Override public PyObject _doget(PyObject container, PyObject wherefound) { + // NOTE: this calledStatically business is pretty hacky if (container == null) { - return this; + return calledStatically ? this : copyWithCalledStatically(true); } - return new PyMethod(this, container, wherefound); + return new PyMethod(calledStatically ? copyWithCalledStatically(false) : this, + container, wherefound); } + @Override public PyObject getDoc() { return __doc__; } @@ -66,6 +74,12 @@ return func; } + private PyReflectedFunction copyWithCalledStatically(boolean calledStatically) { + PyReflectedFunction copy = copy(); + copy.calledStatically = calledStatically; + return copy; + } + public boolean handles(Method method) { return handles(makeArgs(method)); } @@ -143,6 +157,7 @@ nargs = nn; } + @Override public PyObject __call__(PyObject self, PyObject[] args, String[] keywords) { ReflectedCallData callData = new ReflectedCallData(); ReflectedArgs match = null; @@ -179,14 +194,17 @@ return Py.java2py(o); } + @Override public PyObject __call__(PyObject[] args, String[] keywords) { - PyObject self = null; - /* - PyObject[] new_args = new PyObject[args.length - 1]; - System.arraycopy(args, 1, new_args, 0, new_args.length); - self = args[0]; - args = new_args; - */ + PyObject self; + if (calledStatically) { + self = null; + } else { + PyObject[] unboundArgs = new PyObject[args.length - 1]; + System.arraycopy(args, 1, unboundArgs, 0, unboundArgs.length); + self = args[0]; + args = unboundArgs; + } return __call__(self, args, keywords); } @@ -317,8 +335,8 @@ } } + @Override public String toString() { - // printArgs(); return "<java function " + __name__ + " " + Py.idstr(this) + ">"; } } Modified: trunk/jython/src/org/python/core/ReflectedArgs.java =================================================================== --- trunk/jython/src/org/python/core/ReflectedArgs.java 2009-10-04 20:16:12 UTC (rev 6836) +++ trunk/jython/src/org/python/core/ReflectedArgs.java 2009-10-04 21:25:41 UTC (rev 6837) @@ -50,12 +50,6 @@ */ if (this.isStatic) { if (self != null) { - /* - PyObject[] newArgs = new PyObject[pyArgs.length+1]; - System.arraycopy(pyArgs, 0, newArgs, 1, pyArgs.length); - newArgs[0] = self; - pyArgs = newArgs; - //*/ self = null; } } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |