Skip to content

Commit

Permalink
Fix Set.operator repr not filtering duplicate items
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed Dec 8, 2024
1 parent f508f95 commit 1172c0f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/deemon/objects/seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ foreach_seq_printrepr_cb(void *arg, DeeObject *elem) {
return result;
}


INTERN WUNUSED NONNULL((1, 2)) Dee_ssize_t DCALL
default_seq_printrepr(DeeObject *__restrict self, Dee_formatprinter_t printer, void *arg) {
PRIVATE WUNUSED NONNULL((1, 2, 4)) Dee_ssize_t DCALL
default_seq_printrepr_impl(DeeObject *__restrict self,
Dee_formatprinter_t printer, void *arg,
Dee_mh_seq_operator_foreach_t seq_foreach) {
#define DO(err, expr) \
do { \
if unlikely((temp = (expr)) < 0) \
Expand All @@ -256,7 +257,7 @@ default_seq_printrepr(DeeObject *__restrict self, Dee_formatprinter_t printer, v
data.fsprd_printer = printer;
data.fsprd_arg = arg;
data.fsprd_first = true;
DO(err, DeeObject_Foreach(self, &foreach_seq_printrepr_cb, &data));
DO(err, (*seq_foreach)(self, &foreach_seq_printrepr_cb, &data));
DO(err, data.fsprd_first ? DeeFormat_PRINT(printer, arg, "}")
: DeeFormat_PRINT(printer, arg, " }"));
done:
Expand All @@ -266,6 +267,16 @@ default_seq_printrepr(DeeObject *__restrict self, Dee_formatprinter_t printer, v
#undef DO
}

INTERN WUNUSED NONNULL((1, 2)) Dee_ssize_t DCALL
default_seq_printrepr(DeeObject *__restrict self, Dee_formatprinter_t printer, void *arg) {
return default_seq_printrepr_impl(self, printer, arg, DeeType_RequireSeqOperatorForeach(Dee_TYPE(self)));
}

INTERN WUNUSED NONNULL((1, 2)) Dee_ssize_t DCALL
default_set_printrepr(DeeObject *__restrict self, Dee_formatprinter_t printer, void *arg) {
return default_seq_printrepr_impl(self, printer, arg, DeeType_RequireSetOperatorForeach(Dee_TYPE(self)));
}


PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL
seq_mul(DeeObject *self, DeeObject *countob) {
Expand Down
12 changes: 9 additions & 3 deletions src/deemon/objects/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,14 @@ PRIVATE struct type_getset tpconst set_class_getsets[] = {
};


INTDEF WUNUSED NONNULL((1, 2)) Dee_ssize_t DCALL
default_set_printrepr(DeeObject *__restrict self, Dee_formatprinter_t printer, void *arg);

INTDEF int DCALL none_i1(void *UNUSED(a));
INTDEF int DCALL none_i2(void *UNUSED(a), void *UNUSED(b));

PRIVATE struct type_operator const set_operators[] = {
// TYPE_OPERATOR_FLAGS(OPERATOR_0007_REPR, METHOD_FCONSTCALL | METHOD_FCONSTCALL_IF_THISELEM_CONSTREPR), /* TODO: And THISELEM CONST_HASH+CONST_COMPARE_EQ */
TYPE_OPERATOR_FLAGS(OPERATOR_000D_INV, METHOD_FCONSTCALL),
TYPE_OPERATOR_FLAGS(OPERATOR_0010_ADD, METHOD_FCONSTCALL),
TYPE_OPERATOR_FLAGS(OPERATOR_0011_SUB, METHOD_FCONSTCALL),
Expand Down Expand Up @@ -447,9 +451,11 @@ PUBLIC DeeTypeObject DeeSet_Type = {
/* .tp_move_assign = */ NULL
},
/* .tp_cast = */ {
/* .tp_str = */ NULL,
/* .tp_repr = */ NULL, /* TODO: "{ 10, 20, 30 } as Set" */
/* .tp_bool = */ &DeeSet_OperatorBool
/* .tp_str = */ NULL,
/* .tp_repr = */ NULL,
/* .tp_bool = */ &DeeSet_OperatorBool,
/* .tp_print = */ NULL,
/* .tp_printrepr = */ &default_set_printrepr,
},
/* .tp_call = */ NULL,
/* .tp_visit = */ NULL,
Expand Down

0 comments on commit 1172c0f

Please sign in to comment.