Skip to content

Commit

Permalink
Add missing darkening when setting data\n\n Fixes ocaml#9391
Browse files Browse the repository at this point in the history
  • Loading branch information
bobot committed Apr 5, 2020
1 parent 52dc5d7 commit edf92f6
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion runtime/weak.c
Expand Up @@ -91,6 +91,23 @@ Caml_inline int Must_be_Marked_during_mark(value x)
}
#endif

/* True if ar could be in the set (1) (Cf. major_gc.c) */
static int already_marked (value ar)
{
value old_data;
CAMLassert (caml_gc_phase == Phase_mark);

old_data = Field (ar, CAML_EPHE_DATA_OFFSET);
return ( old_data == caml_ephe_none ||
(Is_block(old_data) &&
#if defined (NATIVE_CODE) && defined (NO_NAKED_POINTERS)
!Is_young (old_data) &&
#else
Is_in_heap(old_data) &&
#endif
Is_white_val(old_data)) );
}

/* [len] is a number of words (fields) */
CAMLexport value caml_ephemeron_create (mlsize_t len)
{
Expand Down Expand Up @@ -254,6 +271,7 @@ CAMLexport void caml_ephemeron_set_data (value ar, value el)
{
CAMLassert_valid_ephemeron(ar);

if (caml_gc_phase == Phase_mark && already_marked(ar)) caml_darken (el, NULL);
if (caml_gc_phase == Phase_clean){
/* During this phase since we don't know which ephemerons have been
cleaned we always need to check it. */
Expand Down Expand Up @@ -565,14 +583,22 @@ CAMLprim value caml_weak_blit (value ars, value ofs,

CAMLexport void caml_ephemeron_blit_data (value ars, value ard)
{
value data;
CAMLassert_valid_ephemeron(ars);
CAMLassert_valid_ephemeron(ard);

if(caml_gc_phase == Phase_clean) {
caml_ephe_clean(ars);
caml_ephe_clean(ard);
};
do_set (ard, CAML_EPHE_DATA_OFFSET, Field (ars, CAML_EPHE_DATA_OFFSET));

data = Field (ars, CAML_EPHE_DATA_OFFSET);
if (caml_gc_phase == Phase_mark &&
data != caml_ephe_none &&
already_marked(ard))
caml_darken (data, NULL);

do_set (ard, CAML_EPHE_DATA_OFFSET, data);
}

CAMLprim value caml_ephe_blit_data (value ars, value ard)
Expand Down

0 comments on commit edf92f6

Please sign in to comment.