Skip to content

Commit ad55272

Browse files
committed
Explicitly r_clone() when we zap srcref
1 parent b92a2a6 commit ad55272

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/internal/attr.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,19 @@ r_obj* fn_zap_srcref(r_obj* x) {
213213

214214
r_obj* out = KEEP(r_new_function(formals, body, env));
215215

216-
// Copy over attributes, but zap any `srcref` attribute.
217-
// `r_attrib_poke()` will clone the attribute pairlist as required
218-
// to avoid mutating the attributes of `x`.
219-
r_poke_attrib(out, r_attrib(x));
220-
r_attrib_poke(out, r_syms.srcref, r_null);
216+
// Copy over attributes, but zap any `srcref` attribute
217+
if (r_attrib_get(x, r_syms.srcref) == r_null) {
218+
// Nothing to zap
219+
r_obj* attrib = r_attrib(x);
220+
r_poke_attrib(out, attrib);
221+
} else {
222+
// Clone so we can zap `srcref`
223+
r_obj* attrib = r_attrib(x);
224+
attrib = KEEP(r_clone(attrib));
225+
r_poke_attrib(out, attrib);
226+
FREE(1);
227+
r_attrib_poke(out, r_syms.srcref, r_null);
228+
}
221229

222230
FREE(2);
223231
return out;

0 commit comments

Comments
 (0)