From: <pj...@us...> - 2009-04-10 05:01:35
|
Revision: 6204 http://jython.svn.sourceforge.net/jython/?rev=6204&view=rev Author: pjenvey Date: 2009-04-10 05:01:22 +0000 (Fri, 10 Apr 2009) Log Message: ----------- fix a new GlobalRef being tracked (reaped) for every getweakrefcount/getweakrefs query Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java trunk/jython/src/org/python/modules/_weakref/GlobalRef.java trunk/jython/src/org/python/modules/_weakref/WeakrefModule.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-04-10 04:27:38 UTC (rev 6203) +++ trunk/jython/src/org/python/core/PyType.java 2009-04-10 05:01:22 UTC (rev 6204) @@ -18,7 +18,7 @@ import org.python.expose.ExposedSet; import org.python.expose.ExposedType; import org.python.expose.TypeBuilder; -import org.python.modules._weakref.GlobalRef; +import org.python.modules._weakref.WeakrefModule; import org.python.util.Generic; /** @@ -325,7 +325,7 @@ @Override public Object invokeGet(PyObject obj) { - PyList weakrefs = GlobalRef.newInstance(obj).refs(); + PyList weakrefs = WeakrefModule.getweakrefs(obj); switch (weakrefs.size()) { case 0: return Py.None; Modified: trunk/jython/src/org/python/modules/_weakref/GlobalRef.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/GlobalRef.java 2009-04-10 04:27:38 UTC (rev 6203) +++ trunk/jython/src/org/python/modules/_weakref/GlobalRef.java 2009-04-10 05:01:22 UTC (rev 6204) @@ -110,6 +110,12 @@ return new PyList(list); } + /** + * Create a new tracked GlobalRef. + * + * @param object a PyObject to reference + * @return a new tracked GlobalRef + */ public static GlobalRef newInstance(PyObject object) { GlobalRef ref = objects.get(new GlobalRef(object)); if (ref == null) { @@ -120,6 +126,28 @@ } /** + * Return the number of references to the specified PyObject. + * + * @param object a PyObject + * @return an int reference count + */ + public static int getCount(PyObject object) { + GlobalRef ref = objects.get(new GlobalRef(object)); + return ref == null ? 0 : ref.count(); + } + + /** + * Return a list of references to the specified PyObject. + * + * @param object a PyObject + * @return a PyList of references. may be empty + */ + public static PyList getRefs(PyObject object) { + GlobalRef ref = objects.get(new GlobalRef(object)); + return ref == null ? new PyList() : ref.refs(); + } + + /** * Allow GlobalRef's to be used as hashtable keys. */ public boolean equals(Object o) { Modified: trunk/jython/src/org/python/modules/_weakref/WeakrefModule.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/WeakrefModule.java 2009-04-10 04:27:38 UTC (rev 6203) +++ trunk/jython/src/org/python/modules/_weakref/WeakrefModule.java 2009-04-10 05:01:22 UTC (rev 6204) @@ -55,20 +55,12 @@ } } - public static int getweakrefcount(PyObject o) { - GlobalRef ref = GlobalRef.newInstance(o); - if (ref == null) { - return 0; - } - return ref.count(); + public static int getweakrefcount(PyObject object) { + return GlobalRef.getCount(object); } - public static PyList getweakrefs(PyObject o) { - GlobalRef ref = GlobalRef.newInstance(o); - if (ref == null) { - return new PyList(); - } - return ref.refs(); + public static PyList getweakrefs(PyObject object) { + return GlobalRef.getRefs(object); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |