Skip to content

Commit 8bc1323

Browse files
committed
Fix: always write structseq doc string if given
1 parent 4920b99 commit 8bc1323

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

graalpython/com.oracle.graal.python.cext/src/structseq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ count_members(PyStructSequence_Desc *desc, Py_ssize_t *n_unnamed_members) {
7676
return i;
7777
}
7878

79-
typedef int (*structseq_init_fun_t)(void *, void *, void *, void *, void *, int);
79+
typedef int (*structseq_init_fun_t)(void *, void *, void *, void *, int);
8080
UPCALL_TYPED_ID(PyStructSequence_InitType2, structseq_init_fun_t);
8181
int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc) {
8282
Py_ssize_t n_members, n_unnamed_members, n_named_members;
@@ -119,7 +119,6 @@ int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
119119
return _jls_PyStructSequence_InitType2(
120120
native_type_to_java(type),
121121
polyglot_from_string(desc->name, SRC_CS),
122-
polyglot_from_string(desc->doc, SRC_CS),
123122
/* TODO(fa): use polyglot_from_VoidPtr_array once this is visible */
124123
polyglot_from_PyObjectPtr_array((PyObjectPtr *) field_names, (uint64_t) n_members),
125124
polyglot_from_PyObjectPtr_array((PyObjectPtr *) field_docs, (uint64_t) n_members),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,17 +4032,17 @@ public void call(@SuppressWarnings("unused") PythonContext context) {
40324032
}
40334033

40344034
// directly called without landing function
4035-
@Builtin(name = "PyStructSequence_InitType2", minNumOfPositionalArgs = 6)
4035+
@Builtin(name = "PyStructSequence_InitType2", minNumOfPositionalArgs = 5)
40364036
@GenerateNodeFactory
40374037
abstract static class PyStructSequenceInitType2 extends NativeBuiltin {
40384038

40394039
@Specialization(limit = "1")
4040-
static int doGeneric(Object klass, String typeName, String typeDoc, Object fieldNamesObj, Object fieldDocsObj, int nInSequence,
4040+
static int doGeneric(Object klass, String typeName, Object fieldNamesObj, Object fieldDocsObj, int nInSequence,
40414041
@CachedLanguage PythonLanguage language,
40424042
@Cached AsPythonObjectNode asPythonObjectNode,
40434043
@CachedLibrary("fieldNamesObj") InteropLibrary lib,
40444044
@Cached(parameters = "true") WriteAttributeToObjectNode clearNewNode) {
4045-
return initializeStructType(asPythonObjectNode.execute(klass), typeName, typeDoc, fieldNamesObj, fieldDocsObj, nInSequence, language, lib, clearNewNode);
4045+
return initializeStructType(asPythonObjectNode.execute(klass), typeName, null, fieldNamesObj, fieldDocsObj, nInSequence, language, lib, clearNewNode);
40464046
}
40474047

40484048
static int initializeStructType(Object klass, String typeName, String typeDoc, Object fieldNamesObj, Object fieldDocsObj, int nInSequence,
@@ -4103,7 +4103,7 @@ Object doGeneric(VirtualFrame frame, String typeName, String typeDoc, Object fie
41034103
PTuple bases = factory().createTuple(new Object[]{PythonBuiltinClassType.PTuple});
41044104
PDict namespace = factory().createDict(new PKeyword[]{new PKeyword(SpecialAttributeNames.__DOC__, typeDoc)});
41054105
Object cls = callTypeNewNode.execute(typeBuiltin, typeName, bases, namespace);
4106-
PyStructSequenceInitType2.initializeStructType(cls, typeName, typeDoc, fieldNamesObj, fieldDocsObj, nInSequence, language, lib, clearNewNode);
4106+
PyStructSequenceInitType2.initializeStructType(cls, typeName, null, fieldNamesObj, fieldDocsObj, nInSequence, language, lib, clearNewNode);
41074107
return toNewRefNode.execute(cls);
41084108
} catch (PException e) {
41094109
transformToNative(frame, e);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ public static void initType(PythonLanguage language, Object klass, Descriptor de
219219

220220
WriteAttributeToObjectNode writeAttrNode = WriteAttributeToObjectNode.getUncached(true);
221221
/*
222-
* Only set __doc__ if not yet done. This is usually the case when initializing a native
223-
* class where 'tp_doc' is set in native code already.
222+
* Only set __doc__ if given. It may be 'null' e.g. in case of initializing a native class
223+
* where 'tp_doc' is set in native code already.
224224
*/
225-
if (ReadAttributeFromObjectNode.getUncachedForceType().execute(klass, __DOC__) == PNone.NO_VALUE) {
225+
if (desc.docString != null) {
226226
writeAttrNode.execute(klass, __DOC__, desc.docString);
227227
}
228228
writeAttrNode.execute(klass, N_SEQUENCE_FIELDS, desc.inSequence);

0 commit comments

Comments
 (0)