Skip to content

Commit

Permalink
Implement Cell.operator := ()
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed Nov 10, 2023
1 parent 79b9517 commit cada01a
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/deemon/objects/cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,41 @@ cell_fini(Cell *__restrict self) {
Dee_XDecref(self->c_item);
}

PRIVATE NONNULL((1)) int DCALL
cell_assign(Cell *__restrict self, Cell *__restrict other) {
DREF DeeObject *old_obj, *new_obj;
if (DeeObject_AssertType(other, &DeeCell_Type))
goto err;
DeeCell_LockRead(other);
new_obj = other->c_item;
Dee_XIncref(new_obj);
DeeCell_LockEndRead(other);
DeeCell_LockWrite(self);
old_obj = self->c_item;
self->c_item = new_obj;
DeeCell_LockEndWrite(self);
Dee_XDecref(old_obj);
return 0;
err:
return -1;
}

PRIVATE NONNULL((1)) int DCALL
cell_moveassign(Cell *__restrict self, Cell *__restrict other) {
DREF DeeObject *old_obj, *new_obj;
ASSERT_OBJECT_TYPE(other, &DeeCell_Type);
DeeCell_LockWrite(other);
new_obj = other->c_item;
other->c_item = NULL; /* Steal */
DeeCell_LockEndWrite(other);
DeeCell_LockWrite(self);
old_obj = self->c_item;
self->c_item = new_obj;
DeeCell_LockEndWrite(self);
Dee_XDecref(old_obj);
return 0;
}

PRIVATE NONNULL((1, 2)) void DCALL
cell_visit(Cell *__restrict self, dvisit_t proc, void *arg) {
DeeCell_LockRead(self);
Expand Down Expand Up @@ -578,8 +613,8 @@ PUBLIC DeeTypeObject DeeCell_Type = {
}
},
/* .tp_dtor = */ (void (DCALL *)(DeeObject *__restrict))&cell_fini,
/* .tp_assign = */ NULL,
/* .tp_move_assign = */ NULL,
/* .tp_assign = */ (int (DCALL *)(DeeObject *, DeeObject *))&cell_assign,
/* .tp_move_assign = */ (int (DCALL *)(DeeObject *, DeeObject *))&cell_moveassign,
/* .tp_deepload = */ (int (DCALL *)(DeeObject *__restrict))&cell_deepload
},
/* .tp_cast = */ {
Expand Down

0 comments on commit cada01a

Please sign in to comment.