From: <fwi...@us...> - 2008-12-23 18:53:41
|
Revision: 5793 http://jython.svn.sourceforge.net/jython/?rev=5793&view=rev Author: fwierzbicki Date: 2008-12-23 18:53:36 +0000 (Tue, 23 Dec 2008) Log Message: ----------- Added some __doc__ info for type. Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-12-23 18:06:19 UTC (rev 5792) +++ trunk/jython/src/org/python/core/PyType.java 2008-12-23 18:53:36 UTC (rev 5793) @@ -421,6 +421,7 @@ return base.getLayout(); } + //XXX: needs __doc__ @ExposedGet(name = "__base__") public PyObject getBase() { if (base == null) @@ -428,6 +429,7 @@ return base; } + //XXX: needs __doc__ @ExposedGet(name = "__bases__") public PyObject getBases() { return new PyTuple(bases); @@ -570,7 +572,7 @@ return new PyLong(tp_flags); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.type___subclasses___doc) public synchronized final PyObject type___subclasses__() { PyList result = new PyList(); cleanup_subclasses(); @@ -681,7 +683,7 @@ return Py.TypeError(msg.toString()); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.type_mro_doc) final PyList type_mro(PyObject o) { if (o == null) { return new PyList(compute_mro()); @@ -1029,7 +1031,7 @@ return addFromClass(c); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.type___getattribute___doc) final PyObject type___getattribute__(PyObject name) { String n = asName(name); PyObject ret = type___findattr_ex__(n); @@ -1081,7 +1083,7 @@ return true; } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.type___setattr___doc) final void type___setattr__(PyObject name, PyObject value) { type___setattr__(asName(name), value); } @@ -1127,7 +1129,7 @@ type___delattr__(name); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.type___delattr___doc) final void type___delattr__(PyObject name) { type___delattr__(asName(name)); } @@ -1175,7 +1177,7 @@ return type___call__(args, keywords); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.type___call___doc) final PyObject type___call__(PyObject[] args, String[] keywords) { PyObject new_ = lookup("__new__"); if (!instantiable || new_ == null) { @@ -1292,7 +1294,7 @@ return numSlots; } - @ExposedMethod(names = {"__repr__", "__str__"}) + @ExposedMethod(names = {"__repr__", "__str__"}, doc = BuiltinDocs.type___str___doc) public String type_toString() { String kind; if (!builtin) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-04-27 00:53:30
|
Revision: 6263 http://jython.svn.sourceforge.net/jython/?rev=6263&view=rev Author: cgroves Date: 2009-04-27 00:53:26 +0000 (Mon, 27 Apr 2009) Log Message: ----------- Add the proxy type for a python subclass of a python subclass of a java class before the proxy type for its superclass. This exposes any Java methods overriden in the most derived subclass. Fixes issue1297. Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-04-25 18:45:51 UTC (rev 6262) +++ trunk/jython/src/org/python/core/PyType.java 2009-04-27 00:53:26 UTC (rev 6263) @@ -267,7 +267,7 @@ } } } - + if (wantDict) { createDictSlot(); } @@ -596,6 +596,7 @@ // non-proxy types go straight into our lookup cleanedBases.add(base); } else { + if (!(base instanceof PyJavaType)) { // python subclasses of proxy types need to be added as a base so their // version of methods will show up @@ -875,10 +876,21 @@ PyObject candidate = toMerge[i].getCandidate(); for (MROMergeState mergee : toMerge) { - if(mergee.unmergedContains(candidate)) { + if (mergee.pastnextContains(candidate)) { continue scan; } } + if (!(this instanceof PyJavaType) && candidate instanceof PyJavaType + && candidate.javaProxy != null + && PyProxy.class.isAssignableFrom(((Class<?>)candidate.javaProxy)) + && candidate.javaProxy != javaProxy) { + // If this is a subclass of a Python class that subclasses a Java class, slip the + // proxy for this class in before the proxy class in the superclass' mro. + // This exposes the methods from the proxy generated for this class in addition to + // those generated for the superclass while allowing methods from the superclass to + // remain visible from the proxies. + mro.add(PyType.fromClass(((Class<?>)javaProxy))); + } mro.add(candidate); for (MROMergeState element : toMerge) { element.noteMerged(candidate); @@ -893,7 +905,6 @@ return mro.toArray(new PyObject[mro.size()]); } - /** * Must either throw an exception, or bring the merges in <code>toMerge</code> to completion by * finishing filling in <code>mro</code>. @@ -1616,7 +1627,7 @@ /** * Returns true if candidate is in the items past this state's next item to be merged. */ - public boolean unmergedContains(PyObject candidate) { + public boolean pastnextContains(PyObject candidate) { for (int i = next + 1; i < mro.length; i++) { if (mro[i] == candidate) { return true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-12 02:22:21
|
Revision: 6343 http://jython.svn.sourceforge.net/jython/?rev=6343&view=rev Author: pjenvey Date: 2009-05-12 01:35:11 +0000 (Tue, 12 May 2009) Log Message: ----------- this metatype check will never happen Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-05-11 21:04:36 UTC (rev 6342) +++ trunk/jython/src/org/python/core/PyType.java 2009-05-12 01:35:11 UTC (rev 6343) @@ -151,7 +151,7 @@ } PyType type; - if (new_.for_type == metatype || metatype == PyType.fromClass(Class.class)) { + if (new_.for_type == metatype) { // XXX: set metatype type = new PyType(); } else { @@ -437,7 +437,7 @@ type_prepended[0] = type; newobj = new_.__get__(null, type).__call__(type_prepended, keywords); } - /* special case type(x) */ + // special case type(x) if (type == TYPE && args.length == 1 && keywords.length == 0) { return newobj; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-08-03 06:30:29
|
Revision: 6627 http://jython.svn.sourceforge.net/jython/?rev=6627&view=rev Author: cgroves Date: 2009-08-03 06:30:19 +0000 (Mon, 03 Aug 2009) Log Message: ----------- Force static initialization on PyObject subclasses with Class.forName when looking for TypeBuilders. This gets rid of the need to access some static variable on exposed classes before handing them over to Python code. Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-08-02 23:52:18 UTC (rev 6626) +++ trunk/jython/src/org/python/core/PyType.java 2009-08-03 06:30:19 UTC (rev 6627) @@ -1126,7 +1126,40 @@ } private static TypeBuilder getBuilder(Class<?> c) { - return classToBuilder == null ? null : classToBuilder.get(c); + if (classToBuilder == null) { + // PyType itself has yet to be initialized. This should be a bootstrap type, so it'll + // go through the builder process in a second + return null; + } + if (c.isPrimitive() || !PyObject.class.isAssignableFrom(c)) { + // If this isn't a PyObject, don't bother forcing it to be initialized to load its + // builder + return null; + } + + // This is a PyObject, call forName to force static initialization on the class so if it has + // a builder, it'll be filled in + SecurityException exc = null; + try { + Class.forName(c.getName(), true, c.getClassLoader()); + } catch (ClassNotFoundException e) { + // Well, this is certainly surprising. + throw new RuntimeException("Got ClassNotFound calling Class.forName on an already " + + " found class.", e); + } catch (ExceptionInInitializerError e) { + throw Py.JavaError(e); + } catch (SecurityException e) { + exc = e; + } + TypeBuilder builder = classToBuilder.get(c); + if (builder == null && exc != null) { + Py.writeComment("type", + "Unable to initialize " + c.getName() + ", a PyObject subclass, due to a " + + "security exception, and no type builder could be found for it. If it's an " + + "exposed type, it may not work properly. Security exception: " + + exc.getMessage()); + } + return builder; } private static PyType createType(Class<?> c, Set<PyJavaType> needsInners) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-08-16 08:11:57
|
Revision: 6675 http://jython.svn.sourceforge.net/jython/?rev=6675&view=rev Author: cgroves Date: 2009-08-16 08:11:44 +0000 (Sun, 16 Aug 2009) Log Message: ----------- Have lookup call through to lookup_where rather than duplicating the lookup functionality Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-08-16 03:04:08 UTC (rev 6674) +++ trunk/jython/src/org/python/core/PyType.java 2009-08-16 08:11:44 UTC (rev 6675) @@ -90,6 +90,9 @@ /** Mapping of Java classes to their TypeBuilders. */ private static Map<Class<?>, TypeBuilder> classToBuilder; + /** Used by {@link #lookup} to call {@link #lookup_where} without allocating an array */ + private static final PyObject[] WHERE_PLACEHOLDER = new PyObject[1]; + protected PyType(PyType subtype) { super(subtype); } @@ -1043,20 +1046,7 @@ * @return found object or null */ public PyObject lookup(String name) { - PyObject[] mro = this.mro; - if (mro == null) { - return null; - } - for (PyObject element : mro) { - PyObject dict = element.fastGetDict(); - if (dict != null) { - PyObject obj = dict.__finditem__(name); - if (obj != null) { - return obj; - } - } - } - return null; + return lookup_where(name, WHERE_PLACEHOLDER); } public PyObject lookup_where(String name, PyObject[] where) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-08-17 00:17:42
|
Revision: 6685 http://jython.svn.sourceforge.net/jython/?rev=6685&view=rev Author: cgroves Date: 2009-08-17 00:17:36 +0000 (Mon, 17 Aug 2009) Log Message: ----------- WHERE_PLACEHOLDER could hold on to a reference to a type for a while, and it's causing static initialization problems. Screw using a static array and just pass in null if we don't want to know where the item was found. Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-08-16 23:39:05 UTC (rev 6684) +++ trunk/jython/src/org/python/core/PyType.java 2009-08-17 00:17:36 UTC (rev 6685) @@ -90,9 +90,6 @@ /** Mapping of Java classes to their TypeBuilders. */ private static Map<Class<?>, TypeBuilder> classToBuilder; - /** Used by {@link #lookup} to call {@link #lookup_where} without allocating an array */ - private static final PyObject[] WHERE_PLACEHOLDER = new PyObject[1]; - protected PyType(PyType subtype) { super(subtype); } @@ -1046,7 +1043,7 @@ * @return found object or null */ public PyObject lookup(String name) { - return lookup_where(name, WHERE_PLACEHOLDER); + return lookup_where(name, null); } public PyObject lookup_where(String name, PyObject[] where) { @@ -1059,7 +1056,9 @@ if (dict != null) { PyObject obj = dict.__finditem__(name); if (obj != null) { - where[0] = t; + if (where != null) { + where[0] = t; + } return obj; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-25 18:31:56
|
Revision: 6901 http://jython.svn.sourceforge.net/jython/?rev=6901&view=rev Author: pjenvey Date: 2009-10-25 18:31:36 +0000 (Sun, 25 Oct 2009) Log Message: ----------- simplify indexFor Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-10-25 02:34:06 UTC (rev 6900) +++ trunk/jython/src/org/python/core/PyType.java 2009-10-25 18:31:36 UTC (rev 6901) @@ -1827,8 +1827,7 @@ * Return the table index for type version/name. */ private static int indexFor(Object version, String name) { - long hash = version.hashCode() * name.hashCode(); - return (int)hash >>> (Integer.SIZE - SIZE_EXP); + return (version.hashCode() * name.hashCode()) >>> (Integer.SIZE - SIZE_EXP); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-04-09 01:37:45
|
Revision: 7004 http://jython.svn.sourceforge.net/jython/?rev=7004&view=rev Author: pjenvey Date: 2010-04-09 01:37:39 +0000 (Fri, 09 Apr 2010) Log Message: ----------- set needs_userdict on builtin types so their subclasses know not to need their own dict descriptor Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2010-04-09 01:32:44 UTC (rev 7003) +++ trunk/jython/src/org/python/core/PyType.java 2010-04-09 01:37:39 UTC (rev 7004) @@ -496,6 +496,7 @@ dict.__setitem__("__doc__", docObj); } setIsBaseType(builder.getIsBaseType()); + needs_userdict = dict.__finditem__("__dict__") != null; instantiable = dict.__finditem__("__new__") != null; fillHasSetAndDelete(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-11-17 20:44:52
|
Revision: 7172 http://jython.svn.sourceforge.net/jython/?rev=7172&view=rev Author: otmarhumbel Date: 2010-11-17 20:44:46 +0000 (Wed, 17 Nov 2010) Log Message: ----------- prevent null pointer exception Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2010-11-10 00:16:37 UTC (rev 7171) +++ trunk/jython/src/org/python/core/PyType.java 2010-11-17 20:44:46 UTC (rev 7172) @@ -1202,7 +1202,7 @@ } static boolean hasBuilder(Class<?> c) { - return classToBuilder.containsKey(c); + return classToBuilder != null && classToBuilder.containsKey(c); } private static TypeBuilder getBuilder(Class<?> c) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |