Skip to content

Commit c72aa76

Browse files
committed
Fix problem with inconsistent operator inheritance
1 parent a32b60a commit c72aa76

File tree

6 files changed

+218
-161
lines changed

6 files changed

+218
-161
lines changed

include/deemon/class.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ struct Dee_class_descriptor_object {
418418
#define CLASS_TP_FSUPERKWDS Dee_TP_FHEAP /* FLAG: When set, the superargs operator actually returns a tuple `(args, kwds)' which
419419
* should then be used to invoke the super-constructor as `super(args..., **kwds)'
420420
* Otherwise, `args' is returned, and the super-constructor is called as `super(args...)' */
421+
#define CLASS_TP_FNOBUILTIN Dee_TP_FVARIABLE/* FLAG: Don't auto-define builtin operators */
421422
#endif /* DEE_SOURCE */
422423
uint16_t cd_flags; /* [const] Additional flags to set for the resulting type (set of `TP_F*').
423424
* NOTE: The `TP_FINHERITCTOR' flag has special meaning here,

include/deemon/operator-hints.h

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -468,60 +468,6 @@ DFUNDEF WUNUSED NONNULL((1)) Dee_funptr_t
468468

469469

470470
#if defined(CONFIG_BUILDING_DEEMON) || defined(__DEEMON__)
471-
struct Dee_tno_assign {
472-
enum Dee_tno_id tnoa_id; /* Operator slot ID to write to */
473-
Dee_funptr_t tnoa_cb; /* [1..1] Function pointer to write to `tnoa_id' */
474-
};
475-
476-
/* The max # of operator slots that might ever need to be assigned at once.
477-
* iow: this is the length of the longest non-looping dependency chain that
478-
* can be formed using `default__*__with__*' callbacks below.
479-
* Example:
480-
* - default__hasitem__with__bounditem
481-
* - default__bounditem__with__getitem
482-
* - default__getitem__with__getitem_index
483-
* Note that the following doesn't count because is can be shortened:
484-
* - default__hasitem_index__with__hasitem
485-
* - default__hasitem__with__bounditem
486-
* - default__bounditem__with__getitem
487-
* - default__getitem__with__getitem_index
488-
* Shorter version is:
489-
* - default__hasitem_index__with__bounditem_index
490-
* - default__bounditem_index__with__getitem_index */
491-
/*[[[deemon (print_TNO_ASSIGN_MAXLEN from "...src.deemon.method-hints.method-hints")();]]]*/
492-
/* { Dee_TNO_hasitem_string_len_hash, &default__hasitem_string_len_hash__with__bounditem_string_len_hash }
493-
* { Dee_TNO_bounditem_string_len_hash, &default__bounditem_string_len_hash__with__bounditem_string_hash }
494-
* { Dee_TNO_bounditem_string_hash, &default__bounditem_string_hash__with__getitem_string_hash }
495-
* { Dee_TNO_getitem_string_hash, &default__getitem_string_hash__with__trygetitem_string_hash }
496-
* { Dee_TNO_trygetitem_string_hash, &default__trygetitem_string_hash__with__trygetitem }
497-
* { Dee_TNO_trygetitem, &default__trygetitem__with__getitem }
498-
* { Dee_TNO_getitem, &default__getitem__with__getitem_index }
499-
* { Dee_TNO_getitem_index, &default__getitem_index__with__size__and__getitem_index_fast }
500-
* { Dee_TNO_size, &default__size__with__sizeob } */
501-
#define Dee_TNO_ASSIGN_MAXLEN 9
502-
/*[[[end]]]*/
503-
504-
505-
/* Looking at related operators that actually *are* present,
506-
* and assuming that `id' isn't implemented, return the most
507-
* applicable default implementation for the operator.
508-
*
509-
* e.g. Given a type that defines `tp_iter' and `id=Dee_TNO_foreach',
510-
* this function would return `&default__foreach__with__iter'
511-
*
512-
* When no related operators are present (or `id' doesn't
513-
* have *any* related operators), return `NULL' instead.
514-
*
515-
* NOTE: This function does *!!NOT!!* return method hint pointers
516-
* @param actions: Actions that need to be performed (multiple assignments
517-
* might be necessary in case of a transitive dependency)
518-
* Stored actions must be performed in *REVERSE* order
519-
* The first (last-written) action is always for `id'
520-
* @return: The number of actions written to `actions' */
521-
INTDEF WUNUSED NONNULL((1)) size_t
522-
(DCALL DeeType_SelectMissingNativeOperator)(DeeTypeObject const *__restrict self, enum Dee_tno_id id,
523-
struct Dee_tno_assign actions[Dee_TNO_ASSIGN_MAXLEN]);
524-
525471
/* Return an actual, user-defined operator "id"
526472
* (*NOT* allowing stuff like `default__size__with__sizeob'
527473
* or `default__seq_operator_size__with__seq_operator_sizeob')
@@ -537,21 +483,6 @@ INTDEF WUNUSED NONNULL((1)) Dee_funptr_t
537483
INTDEF WUNUSED NONNULL((1)) Dee_funptr_t
538484
(DCALL DeeType_GetNativeOperatorWithoutHints)(DeeTypeObject *__restrict self, enum Dee_tno_id id);
539485

540-
/* Ignoring method hints that might have been able to implement "id" along
541-
* the way, and assuming that `DeeType_GetNativeOperatorWithoutHints(from, id)'
542-
* returned `impl', make sure that `impl' can be (and is) inherited by `into'.
543-
*
544-
* This function is allowed to assume that "impl" really is what should be
545-
* inherited for the specified "id" (if it is not correct, everything breaks)
546-
*
547-
* @return: Indicative of a successful inherit (inherit may fail when "impl"
548-
* is `default__*__with__*', and dependencies could not be written
549-
* due to OOM, though in this case, no error is thrown) */
550-
INTDEF WUNUSED NONNULL((1, 2, 4)) bool
551-
(DCALL DeeType_InheritNativeOperatorWithoutHints)(DeeTypeObject *__restrict from,
552-
DeeTypeObject *__restrict into,
553-
enum Dee_tno_id id, Dee_funptr_t impl);
554-
555486
/* Same as `DeeType_GetNativeOperatorWithoutHints', but also load operators
556487
* from method hints (though don't inherit them from base-types, yet). */
557488
INTDEF WUNUSED NONNULL((1)) Dee_funptr_t

src/deemon/objects/cell.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ PRIVATE WUNUSED NONNULL((1, 2)) int DCALL
355355
cell_trycompare_eq(DeeCellObject *self, DeeCellObject *other) {
356356
uintptr_t lhs_id, rhs_id;
357357
if unlikely(!DeeCell_Check(other))
358-
return 1;
358+
return -1;
359359
lhs_id = DeeObject_Id(DeeCell_GetItemPointer(self));
360360
rhs_id = DeeObject_Id(DeeCell_GetItemPointer(other));
361361
return lhs_id == rhs_id ? 0 : 1;

src/deemon/objects/class.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5901,7 +5901,13 @@ DeeClass_New(DeeObject *bases, DeeObject *descriptor,
59015901
if ((!result->tp_cast.tp_repr && !result->tp_cast.tp_printrepr) && (desc->cd_flags & CLASS_TP_FAUTOINIT))
59025902
result->tp_cast.tp_printrepr = &instance_builtin_auto_printrepr;
59035903
#endif /* CLASS_TP_FAUTOINIT */
5904-
if (!result->tp_cmp)
5904+
if (!result->tp_cmp && !(desc->cd_flags & CLASS_TP_FNOBUILTIN)
5905+
#if 1 /* TODO: Get rid of this once the compiler is able to produce "CLASS_TP_FNOBUILTIN"
5906+
* right now, this is here for the "class MyCell: Cell" test (asserting that cross-
5907+
* dependent operators are inherited as sets) */
5908+
&& desc->cd_imemb_size > 0
5909+
#endif
5910+
)
59055911
result->tp_cmp = &instance_builtin_cmp;
59065912

59075913
/* Make sure to disallow MOVE-ANY when the builtin move-assign operator is used. */

0 commit comments

Comments
 (0)