Skip to content

Commit abd3cde

Browse files
committed
Struct Sequence with unnamed fields fix. Unnamed fields need to be after named ones and n_in_sequence needs to be limited to known fields. Fix in DebugContainers.c now works with PyObject_Print(), not yet in the Python module in src/cpy/StructSequence/cStructSequence.c.
1 parent 6fc1254 commit abd3cde

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/cpy/Containers/DebugContainers.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,17 +2662,17 @@ void dbg_PyStructSequence_with_unnamed_field(void) {
26622662
{"family_name", "Family name."},
26632663
/* Use NULL then replace with PyStructSequence_UnnamedField
26642664
* otherwise get an error "initializer element is not a compile-time constant" */
2665-
{NULL, "Documentation for an unnamed field."},
26662665
{"given_name", "Given name."},
2666+
{PyStructSequence_UnnamedField, "Documentation for an unnamed field."},
26672667
{NULL, NULL}
26682668
};
2669-
struct_sequence_with_unnamed_fields[1].name = PyStructSequence_UnnamedField;
2669+
// struct_sequence_with_unnamed_fields[2].name = PyStructSequence_UnnamedField;
26702670

26712671
PyStructSequence_Desc struct_sequence_with_unnamed_field_type_desc = {
26722672
"module.struct_sequence_simple_with_unnamed_field",
26732673
"Documentation.",
26742674
struct_sequence_with_unnamed_fields,
2675-
3,
2675+
2,
26762676
};
26772677

26782678
PyTypeObject *example_type = NULL;
@@ -2705,6 +2705,17 @@ void dbg_PyStructSequence_with_unnamed_field(void) {
27052705
ref_count = Py_REFCNT(set_item);
27062706
assert(ref_count == 1);
27072707

2708+
assert(!PyErr_Occurred());
2709+
fprintf(stdout, "Calling PyObject_Print(instance, stdout, 0);\n");
2710+
PyObject_Print(instance, stdout, 0);
2711+
fprintf(stdout, "\n");
2712+
assert(!PyErr_Occurred());
2713+
fprintf(stdout, "Calling PyObject_Print(instance, stdout, Py_PRINT_RAW);\n");
2714+
PyObject_Print(instance, stdout, Py_PRINT_RAW);
2715+
printf("\n");
2716+
assert(!PyErr_Occurred());
2717+
fprintf(stdout, "Calling PyObject_Print DONE\n");
2718+
27082719
/* Get items. */
27092720
get_item = PyStructSequence_GetItem(instance, 0);
27102721
assert(get_item != NULL);

0 commit comments

Comments
 (0)