Skip to content

Commit

Permalink
Fix ref count, re issue #575
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Aug 23, 2024
1 parent e25737e commit f214031
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
10 changes: 4 additions & 6 deletions src/bif_bboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ static bool bif_bb_b_put_2(query *q)
if (DO_DUMP) DUMP_TERM2("bb_b_put", tmpbuf, p2, p2_ctx, 1);

char *key = strdup(tmpbuf);
check_heap_error(init_tmp_heap(q), free(key));
cell *tmp = deep_clone_to_tmp(q, p2, p2_ctx);
cell *tmp = deep_copy_to_heap(q, p2, p2_ctx, true);
cell *val = malloc(sizeof(cell)*tmp->nbr_cells);
check_heap_error(val);
dup_cells(val, tmp, tmp->nbr_cells);
Expand Down Expand Up @@ -123,8 +122,7 @@ static bool bif_bb_put_2(query *q)
// Note: we have to save a copy of attributes...

char *key2 = strdup(tmpbuf2);
check_heap_error(init_tmp_heap(q), free(key2));
cell *tmp = deep_copy_to_tmp(q, p2, p2_ctx, true);
cell *tmp = deep_copy_to_heap(q, p2, p2_ctx, true);
cell *val = malloc(sizeof(cell)*tmp->nbr_cells);
check_heap_error(val);
dup_cells(val, tmp, tmp->nbr_cells);
Expand Down Expand Up @@ -190,7 +188,7 @@ static bool bif_bb_get_2(query *q)

prolog_unlock(q->pl);

cell *tmp = shallow_copy_to_heap(q, (cell*)val, q->st.curr_frame, true);
cell *tmp = deep_copy_to_heap(q, (cell*)val, q->st.curr_frame, true);
check_heap_error(tmp);

if (DO_DUMP) DUMP_TERM2("bb_get", tmpbuf, tmp, q->st.curr_frame, 1);
Expand Down Expand Up @@ -248,7 +246,7 @@ static bool bif_bb_delete_2(query *q)
return false;
}

cell *tmp = shallow_copy_to_heap(q, (cell*)val, q->st.fp, true);
cell *tmp = deep_copy_to_heap(q, (cell*)val, q->st.fp, true);
check_heap_error(tmp, prolog_unlock(q->pl));

if (DO_DUMP) DUMP_TERM2("bb_delete", tmpbuf, tmp, q->st.curr_frame, 1);
Expand Down
24 changes: 0 additions & 24 deletions src/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,30 +548,6 @@ cell *deep_copy_to_heap_with_replacement(query *q, cell *p1, pl_idx p1_ctx, bool
return tmp2;
}

cell *shallow_copy_to_heap(query *q, cell *p1, pl_idx p1_ctx, bool copy_attrs)
{
q->noderef = true;
cell *tmp2 = deep_copy_to_heap(q, p1, p1_ctx, copy_attrs);
q->noderef = false;

if (!copy_attrs)
return tmp2;

cell *c = tmp2;

for (pl_idx i = 0; i < tmp2->nbr_cells; i++, c++) {
if (is_var(c) && c->tmp_attrs) {
const frame *f = GET_FRAME(c->var_ctx);
slot *e = GET_SLOT(f, c->var_nbr);
e->c.attrs = deep_clone_to_heap(q, c->tmp_attrs, q->st.curr_frame);
free(c->tmp_attrs);
c->tmp_attrs = NULL;
}
}

return tmp2;
}

cell *alloc_on_queuen(query *q, unsigned qnbr, const cell *c)
{
if (!q->queue[qnbr]) {
Expand Down
1 change: 0 additions & 1 deletion src/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ cell *deep_clone_to_heap(query *q, cell *p1, pl_idx p1_ctx);

cell *deep_copy_to_tmp(query *q, cell *p1, pl_idx p1_ctx, bool copy_attrs);
cell *deep_copy_to_heap(query *q, cell *p1, pl_idx p1_ctx, bool copy_attrs);
cell *shallow_copy_to_heap(query *q, cell *p1, pl_idx p1_ctx, bool copy_attrs);

cell *alloc_on_heap(query *q, unsigned nbr_cells);
cell *alloc_on_tmp(query *q, unsigned nbr_cells);
Expand Down

0 comments on commit f214031

Please sign in to comment.