Skip to content

Commit b30e0d3

Browse files
author
Pavel Marek
committed
Fix tests of memory leaks of CHARSXP native values
(cherry picked from commit 108c125)
1 parent ededbbf commit b30e0d3

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

com.oracle.truffle.r.test.native/packages/testrffi/testrffi/src/testrffi.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,13 +1191,17 @@ SEXP test_RfMatch(SEXP x, SEXP y) {
11911191
* Make sure this test runs with `gctorture()`.
11921192
*/
11931193
SEXP test_mkCharDoesNotCollect() {
1194-
// Not protected on purpose
1195-
SEXP char_sxp = mkChar("Hello-World");
1196-
// Allocate some other object. With gctorture, char_sxp can be collected.
1197-
SEXP string = PROTECT(allocVector(STRSXP, 1));
1198-
// If char_sxp is collected, the following statement should throw an error.
1199-
SET_STRING_ELT(string, 0, char_sxp);
1194+
SEXP string_one = PROTECT(allocVector(STRSXP, 1));
1195+
SEXP char_sxp = mkChar("XX_YY");
1196+
// Should be OK, char_sxp cannot be collected yet
1197+
SET_STRING_ELT(string_one, 0, char_sxp);
1198+
// char_sxp should be transitivelly referenced from GC root
12001199

1201-
UNPROTECT(1);
1202-
return string;
1200+
// char_sxp can be potentially collected here.
1201+
SEXP string_two = PROTECT(allocVector(STRSXP, 1));
1202+
// If char_sxp is collected, the following statement throws an error.
1203+
SET_STRING_ELT(string_two, 0, char_sxp);
1204+
1205+
UNPROTECT(2);
1206+
return list2(string_one, string_two);
12031207
}

com.oracle.truffle.r.test.native/packages/testrffi/testrffi/tests/rapiTests.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ assertEquals(rffi.test_RfMatch(c(), c("foo", "bar")), c(NA_integer_, NA_integer_
265265
# ----------------------------------------------------------------------------------------
266266
# Rf_mkChar should not be garbage collected
267267
gctorture(on = TRUE)
268-
assertEquals(rffi.test_mkCharDoesNotCollect(), "Hello-World")
268+
assertEquals(rffi.test_mkCharDoesNotCollect(), list("XX_YY", "XX_YY"))
269269
gctorture(on = FALSE)
270270

271271
# ----------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)