Skip to content

Commit f613027

Browse files
committed
Various doc- and style-improvements.
1 parent e8511bf commit f613027

File tree

9 files changed

+483
-87
lines changed

9 files changed

+483
-87
lines changed

src/org/python/core/PyBytecode.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ public PyObject __findattr_ex__(String name) {
164164

165165
enum Why {
166166

167-
NOT, /* No error */
167+
NOT, /* No error */
168168
EXCEPTION, /* Exception occurred */
169-
RERAISE, /* Exception re-raised by 'finally' */
170-
RETURN, /* 'return' statement */
171-
BREAK, /* 'break' statement */
172-
CONTINUE, /* 'continue' statement */
173-
YIELD /* 'yield' operator */
169+
RERAISE, /* Exception re-raised by 'finally' */
170+
RETURN, /* 'return' statement */
171+
BREAK, /* 'break' statement */
172+
CONTINUE, /* 'continue' statement */
173+
YIELD /* 'yield' operator */
174174

175175
};
176176

@@ -1054,7 +1054,8 @@ protected PyObject interpret(PyFrame f, ThreadState ts) {
10541054
break;
10551055

10561056
case Opcode.WITH_CLEANUP: {
1057-
/* TOP is the context.__exit__ bound method.
1057+
/*
1058+
TOP is the context.__exit__ bound method.
10581059
Below that are 1-3 values indicating how/why
10591060
we entered the finally clause:
10601061
- SECOND = None

src/org/python/core/PyObject.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,22 @@
2020

2121
/**
2222
* All objects known to the Jython runtime system are represented by an instance
23-
* of the class <code>PyObject</code> or one of its subclasses.
23+
* of the class {@code PyObject} or one of its subclasses.
2424
*/
2525
@ExposedType(name = "object", doc = BuiltinDocs.object_doc)
2626
public class PyObject implements Serializable {
2727

2828
public static final PyType TYPE = PyType.fromClass(PyObject.class);
2929

3030
/**
31-
* This should have been suited at org.python.modules.gc, but that would cause
32-
* a dependency cycle in the init-phases of gc.class and PyObject.class.
33-
* Now this boolean mirrors the presence of the MONITOR_GLOBAL-flag of
34-
* Jython's gc module.
31+
* This should have been suited at {@link org.python.modules.gc},
32+
* but that would cause a dependency cycle in the init-phases of
33+
* {@code gc.class} and {@code PyObject.class}. Now this boolean
34+
* mirrors the presence of the
35+
* {@link org.python.modules.gc#MONITOR_GLOBAL}-flag in Jython's
36+
* gc module.<br>
37+
* <br>
38+
* <b>Do not change manually.</b>
3539
*/
3640
public static boolean gcMonitorGlobal = false;
3741

@@ -45,12 +49,15 @@ public class PyObject implements Serializable {
4549
* objects can be accessed by the methods and keys in
4650
* {@link org.python.core.JyAttribute}.
4751
* A notable attribute is the javaProxy (accessible via
48-
* {@code JyAttribute.getAttr(this, JAVA_PROXY_ATTR)}),
52+
* {@code JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR)}),
4953
* an underlying Java instance that this object is wrapping or is a
5054
* subclass of. Anything attempting to use the proxy should go through
5155
* {@link #getJavaProxy()} which ensures that it's initialized.
56+
*
57+
* @see org.python.core.JyAttribute
58+
* @see org.python.core.JyAttribute#JAVA_PROXY_ATTR
59+
* @see #getJavaProxy()
5260
*/
53-
//protected Object javaProxy;
5461
protected Object attributes;
5562

5663
/** Primitives classes their wrapper classes. */
@@ -1708,7 +1715,6 @@ public final PyObject _gt(PyObject o) {
17081715
public PyObject _is(PyObject o) {
17091716
// Access javaProxy directly here as is is for object identity, and at best getJavaProxy
17101717
// will initialize a new object with a different identity
1711-
//return this == o || (javaProxy != null && javaProxy == o.javaProxy) ? Py.True : Py.False;
17121718
return this == o || (JyAttribute.hasAttr(this, JyAttribute.JAVA_PROXY_ATTR) &&
17131719
JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR) ==
17141720
JyAttribute.getAttr(o, JyAttribute.JAVA_PROXY_ATTR)) ? Py.True : Py.False;
@@ -1723,7 +1729,6 @@ public PyObject _is(PyObject o) {
17231729
public PyObject _isnot(PyObject o) {
17241730
// Access javaProxy directly here as is is for object identity, and at best getJavaProxy
17251731
// will initialize a new object with a different identity
1726-
//return this != o && (javaProxy == null || javaProxy != o.javaProxy) ? Py.True : Py.False;
17271732
return this != o && (!JyAttribute.hasAttr(this, JyAttribute.JAVA_PROXY_ATTR) ||
17281733
JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR) !=
17291734
JyAttribute.getAttr(o, JyAttribute.JAVA_PROXY_ATTR)) ? Py.True : Py.False;

src/org/python/core/Traverseproc.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
* tracefunc in {@link org.python.core.PyFrame}).
2121
* PyObjects that don't own references to other PyObjects under any condition
2222
* and neither inherit such references from a superclass are strictly recommended
23-
* to be annotated {@code {@literal @}Untraversable}
24-
* (see {@link org.python.core.Untraversable} for details).
23+
* to be annotated {@link org.python.core.Untraversable}.
2524
* </p>
2625
* <p>
2726
* Jython's traverse mechanism serves debugging purposes to ease finding memory
@@ -42,14 +41,16 @@
4241
* Note that the slots-array and - if existent - the user-dict of fooDerived classes
4342
* is traversed by {@link org.python.core.TraverseProcDerived}.
4443
* The gc module takes care of exploiting both traverse methods in its static traverse
45-
* method. So for manual traversion one should always use {@code gc.traverse} rather
44+
* method. So for manual traversion one should always use
45+
* {@link org.python.modules.gc#traverse(PyObject, Visitproc, Object)} rather
4646
* than directly calling methods in this interface.
4747
* </p>
4848
* <p>
49-
* Also note that {@code objtype} is not subject to {@code Traverseproc}s
50-
* by default. In CPython only objects with heap-types traverse their
51-
* ob_type field. In Jython, {@code fooDerived}-classes are the
52-
* equivalents of heapTypes. For such classes, objtype is actually
49+
* Also note that {@link org.python.core.PyObject#objtype} is not subject to
50+
* {@code Traverseproc}s by default. In CPython only objects with heap-types
51+
* traverse their {@code ob_type}-field. In Jython, {@code fooDerived}-classes
52+
* are the equivalents of heapTypes. For such classes
53+
* {@link org.python.core.PyObject#objtype} is actually
5354
* traversed (along with the user dict).
5455
* </p>
5556
* <p>
@@ -439,6 +440,9 @@
439440
* UAdd - no refs, extends PythonTree<br>
440441
* USub - no refs, extends PythonTree<br>
441442
* </p>
443+
* @see org.python.core.Untraversable
444+
* @see org.python.core.Visitproc
445+
* @see org.python.modules.gc#traverse(PyObject, Visitproc, Object)
442446
*/
443447
public interface Traverseproc {
444448

src/org/python/core/TraverseprocDerived.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* {@code fooDerived}-classes. This way we avoid that the traverse
77
* method of a traversable {@link org.python.core.PyObject} is
88
* overwritten by the derived version.
9-
* The {@link org.python.modules.gc}-module takes care of
9+
* {@link org.python.modules.gc#traverse(PyObject, Visitproc, Object)} takes care of
1010
* exploiting both traverse methods.
1111
*/
1212
public interface TraverseprocDerived {

src/org/python/core/finalization/FinalizeTrigger.java

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,15 @@
1212
public class FinalizeTrigger {
1313
/**
1414
* This flag tells the finalize trigger to call
15-
* gc.notifyFinalize after it called the finalizer.
15+
* {@link gc#notifyFinalize(PyObject)} after it called the finalizer.
1616
*/
1717
public static final byte NOTIFY_GC_FLAG = (1<<0);
18-
19-
/**
20-
* This flag tells the finalize trigger to refrain from actually
21-
* running the PyObject's {@code __del__} method (or variants for
22-
* derived or builtins).
23-
* It can be used to have finalize triggers for debugging and
24-
* monitoring purposes. The actual purpose is for Jython gc's
25-
* {@code DONT_FINALIZE_CYCLIC_GARBAGE} flag that tells the gc to emulate
26-
* CPython's <3.4 policy never to finalize cyclic garbage.
27-
*/
28-
//public static final byte INHIBIT_FINALIZER_FLAG = (1<<1);
29-
30-
/**
31-
* Tells the finalizer to add the finalized PyObject to the gc's
32-
* garbage list. This allows gc to mimic CPython's way to deal
33-
* with cyclic finalizable objects prior 3.4
34-
* (c.f. CPython's gc's DEBUG_SAVEALL flag).
35-
*/
36-
//public static final byte ADD_TO_GARBAGE_LIST_FLAG = (1<<2);
3718

3819
/**
39-
* Similar to {@code INHIBIT_FINALIZER_FLAG}, but indicates that the
40-
* underlying PyObject was never intended to be finalized, while
41-
* {@code INHIBIT_FINALIZER_FLAG} indicates that there actually *is* a
42-
* finalizer that is just not processed due to special
43-
* circumstances (i.e. inactive {@code DONT_FINALIZE_CYCLIC_GARBAGE} flag).
20+
* Indicates that the underlying PyObject was never intended to be finalized.
21+
* It is actually not finalizable and the trigger only exists to notify
22+
* {@link org.python.modules.gc} that the underlying object was finalized.
23+
* This is needed for some advanced gc-functionality.
4424
*/
4525
public static final byte NOT_FINALIZABLE_FLAG = (1<<3);
4626

@@ -186,7 +166,7 @@ public void performFinalization() {
186166
}
187167
}
188168
if ((gc.getJythonGCFlags() & gc.VERBOSE_FINALIZE) != 0) {
189-
Py.writeDebug("gc", "finalization of "+toFinalize);
169+
gc.writeDebug("gc", "finalization of "+toFinalize);
190170
}
191171
if (saveGarbage == 1 || (saveGarbage == 0 &&
192172
(gc.get_debug() & gc.DEBUG_SAVEALL) != 0 && isCyclic())) {
@@ -199,13 +179,13 @@ public void performFinalization() {
199179
}
200180
gc.garbage.add(toFinalize);
201181
if ((gc.getJythonGCFlags() & gc.VERBOSE_FINALIZE) != 0) {
202-
Py.writeDebug("gc", toFinalize+" added to garbage.");
182+
gc.writeDebug("gc", toFinalize+" added to garbage.");
203183
}
204184
}
205185
}
206186
if ((flags & NOTIFY_GC_FLAG) != 0) {
207187
if ((gc.getJythonGCFlags() & gc.VERBOSE_FINALIZE) != 0) {
208-
Py.writeDebug("gc", "notify finalization of "+toFinalize);
188+
gc.writeDebug("gc", "notify finalization of "+toFinalize);
209189
}
210190
gc.notifyFinalize(toFinalize);
211191
flags &= ~NOTIFY_GC_FLAG;
@@ -217,7 +197,7 @@ protected void finalize() throws Throwable {
217197
gc.notifyPreFinalization();
218198
if (gc.delayedFinalizationEnabled() && toFinalize != null) {
219199
if ((gc.getJythonGCFlags() & gc.VERBOSE_FINALIZE) != 0) {
220-
Py.writeDebug("gc", "delayed finalization for "+toFinalize);
200+
gc.writeDebug("gc", "delayed finalization for "+toFinalize);
221201
}
222202
gc.registerForDelayedFinalization(toFinalize);
223203
} else {

src/org/python/modules/_weakref/AbstractReference.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected PyObject get() {
8484
return null;
8585
}
8686
if ((gc.getJythonGCFlags() & gc.VERBOSE_WEAKREF) != 0) {
87-
Py.writeDebug("gc", "pending in get of abstract ref "+this+": "+
87+
gc.writeDebug("gc", "pending in get of abstract ref "+this+": "+
8888
Thread.currentThread().getId());
8989
}
9090
JyAttribute.setAttr(this, JyAttribute.WEAKREF_PENDING_GET_ATTR, Thread.currentThread());
@@ -96,14 +96,14 @@ protected PyObject get() {
9696
}
9797
JyAttribute.delAttr(this, JyAttribute.WEAKREF_PENDING_GET_ATTR);
9898
if ((gc.getJythonGCFlags() & gc.VERBOSE_WEAKREF) != 0) {
99-
Py.writeDebug("gc", "pending of "+this+" resolved: "+
99+
gc.writeDebug("gc", "pending of "+this+" resolved: "+
100100
Thread.currentThread().getId());
101101
if (gref.cleared) {
102-
Py.writeDebug("gc", "reference was cleared.");
102+
gc.writeDebug("gc", "reference was cleared.");
103103
} else if (result != null){
104-
Py.writeDebug("gc", "reference was restored.");
104+
gc.writeDebug("gc", "reference was restored.");
105105
} else {
106-
Py.writeDebug("gc", "something went very wrong.");
106+
gc.writeDebug("gc", "something went very wrong.");
107107
}
108108
}
109109
return result;

src/org/python/modules/_weakref/GlobalRef.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
public class GlobalRef extends WeakReference<PyObject> {
2121

2222
/**
23-
* This reference's hashCode: the System.identityHashCode of the referent. Only used
24-
* internally.
23+
* This reference's hashCode: The {@code System.identityHashCode} of the referent.
24+
* Only used internally.
2525
*/
2626
private int hashCode;
2727

@@ -31,16 +31,19 @@ public class GlobalRef extends WeakReference<PyObject> {
3131
*/
3232
private int pythonHashCode;
3333

34-
/** Whether pythonHashCode was already determined. */
34+
/** Whether {@link #pythonHashCode} was already determined. */
3535
private boolean havePythonHashCode;
3636

3737
/**
38-
* This boolean is set true when the callback is processed. If the reference is
39-
* cleared it might potentially be restored until this boolean is set true.
40-
* If weak reference restoring is activated (c.f.
41-
* {@code gc.PRESERVE_WEAKREFS_ON_RESURRECTION}), {@code AbstractReference.get}
38+
* This boolean is set {@code true} when the callback is processed.
39+
* If the reference is cleared it might potentially be restored until
40+
* this boolean is set true. If weak reference restoring is activated (c.f.
41+
* {@link gc#PRESERVE_WEAKREFS_ON_RESURRECTION}), {@link AbstractReference#get()}
4242
* would block until a consistent state is reached (i.e. referent is
4343
* non-{@code null} or {@code cleared == true}).
44+
*
45+
* @see gc#PRESERVE_WEAKREFS_ON_RESURRECTION
46+
* @see AbstractReference#get()
4447
*/
4548
protected boolean cleared = false;
4649

@@ -108,7 +111,10 @@ synchronized void call() {
108111
}
109112

110113
/**
111-
* Call all callbacks that were enqueued via delayedCallback method.
114+
* Call all callbacks that were enqueued via
115+
* {@link #delayedCallback(GlobalRef)} method.
116+
*
117+
* @see #delayedCallback(GlobalRef)
112118
*/
113119
public static void processDelayedCallbacks() {
114120
if (delayedCallbacks != null) {
@@ -124,9 +130,11 @@ public static void processDelayedCallbacks() {
124130
/**
125131
* Stores the callback for later processing. This is needed if
126132
* weak reference restoration (c.f.
127-
* {@code gc.PRESERVE_WEAKREFS_ON_RESURRECTION})
133+
* {@link gc#PRESERVE_WEAKREFS_ON_RESURRECTION})
128134
* is active. In this case the callback is delayed until it was
129135
* determined whether a resurrection restored the reference.
136+
*
137+
* @see gc#PRESERVE_WEAKREFS_ON_RESURRECTION
130138
*/
131139
private static void delayedCallback(GlobalRef cl) {
132140
if (delayedCallbacks == null) {
@@ -196,6 +204,9 @@ public static GlobalRef newInstance(PyObject object) {
196204
* If the given {@link org.python.core.PyObject} is not the former
197205
* referent of this weak reference, an
198206
* {@link java.lang.IllegalArgumentException} is thrown.
207+
*
208+
* @throws java.lang.IllegalArgumentException if {@code formerReferent} is not
209+
* the actual former referent.
199210
*/
200211
public void restore(PyObject formerReferent) {
201212
if (JyAttribute.getAttr(formerReferent, JyAttribute.WEAK_REF_ATTR) != this) {
@@ -265,8 +276,8 @@ public static int getCount(PyObject object) {
265276
* Return a list of references to the specified
266277
* {@link org.python.core.PyObject}.
267278
*
268-
* @param object a PyObject
269-
* @return a PyList of references. may be empty
279+
* @param object a {@link org.python.core.PyObject}
280+
* @return a {@link org.python.core.PyList} of references. May be empty.
270281
*/
271282
public static PyList getRefs(PyObject object) {
272283
GlobalRef ref = objects.get(new GlobalRef(object));

src/org/python/modules/_weakref/ReferenceType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ final void weakref___init__(PyObject[] args, String[] keywords) {
6868
* to passthru).
6969
*
7070
* @param funcName the name of the caller
71-
* @param args PyObject array of args
72-
* @param keywords String array of keywords
73-
* @return an ArgParser instance
71+
* @param args {@link or.python.core.PyObject} array of args
72+
* @param keywords {@code String}-array of keywords
73+
* @return an {@link or.python.core.ArgParser} instance
7474
*/
7575
private static ArgParser parseInitArgs(String funcName, PyObject[] args, String[] keywords) {
7676
if (keywords.length > 0) {

0 commit comments

Comments
 (0)