summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Leroy <xavierleroy@users.noreply.github.com>2020-11-30 11:43:12 +0100
committerXavier Leroy <xavier.leroy@college-de-france.fr>2020-11-30 11:43:57 +0100
commit4143edddbe3ac3b7962ab3a2c725d8071075d077 (patch)
tree61ef30b3e0dcaa34cd7537f797dbcbe54de6a12e
parent9e1521c76d48694ce37806e0eaef9fb0521da11e (diff)
downloadocaml-4143edddbe3ac3b7962ab3a2c725d8071075d077.tar.gz
Make copy_value compatible with no-naked-pointers mode (#10054)
When copying a closure, properly distinguish the environment fields from the code pointers and closure info fields. Otherwise we end up calling `caml_darken` on code pointers. (cherry picked from commit 2b574d20a363dc736520b9e231e8556e491b8688)
-rw-r--r--runtime/weak.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/runtime/weak.c b/runtime/weak.c
index 9b51626146..29dc12c874 100644
--- a/runtime/weak.c
+++ b/runtime/weak.c
@@ -358,20 +358,28 @@ CAMLprim value caml_ephe_get_data (value ar)
return optionalize(caml_ephemeron_get_data(ar, &data), &data);
}
-
-Caml_inline void copy_value(value src, value dst)
-{
- if (Tag_val (src) < No_scan_tag){
- mlsize_t i;
- for (i = 0; i < Wosize_val (src); i++){
- value f = Field (src, i);
- if (caml_gc_phase == Phase_mark && Must_be_Marked_during_mark(f)){
- caml_darken (f, NULL);
- }
- caml_modify (&Field (dst, i), f);
+static void copy_value(value src, value dst)
+{
+ mlsize_t sz, i;
+ sz = Wosize_val(src);
+ if (Tag_val (src) >= No_scan_tag) {
+ /* Direct copy */
+ memcpy (Bp_val (dst), Bp_val (src), Bsize_wsize (sz));
+ return;
+ }
+ i = 0;
+ if (Tag_val (src) == Closure_tag) {
+ /* Direct copy of the code pointers and closure info fields */
+ i = Start_env_closinfo(Closinfo_val(src));
+ memcpy (Bp_val (dst), Bp_val (src), Bsize_wsize (i));
+ }
+ /* Field-by-field copy and darkening of the remaining fields */
+ for (/*nothing*/; i < sz; i++){
+ value f = Field (src, i);
+ if (caml_gc_phase == Phase_mark && Must_be_Marked_during_mark(f)){
+ caml_darken (f, NULL);
}
- }else{
- memmove (Bp_val (dst), Bp_val (src), Bosize_val (src));
+ caml_modify (&Field (dst, i), f);
}
}