Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2026-10-22 Kevin Ushey <kevinushey@gmail.com>

* src/module.cpp (CppObject__finalize): Make finalize() a no-op for a
module object that was never constructed (created without arguments for a
class without a default constructor); it used to fail on the dummy
pointer, and the failure surfaced as an error message at garbage
collection
* inst/tinytest/test_module.R: Add test

2026-10-22 Michael Sumner <mdsumner@gmail.com>

* R/00_classes.R: Define C++Field, C++OverloadedMethods and C++Constructor
Expand Down
7 changes: 7 additions & 0 deletions inst/tinytest/test_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,10 @@ gctorture(TRUE)
res <- gadget$value()
gctorture(FALSE)
expect_identical( res, c(1, 2, 3) )

# test.Module.finalize.dummy <- function(){
## an object created without arguments for a class lacking a default
## constructor holds the dummy pointer; finalizing it must be a no-op
## rather than an error (which used to surface at garbage collection)
r <- new( ModuleRandomizer )
expect_identical( r$finalize(), NULL )
7 changes: 7 additions & 0 deletions src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ RCPP_FUN_4(SEXP, CppField__set, XP_Class cl, SEXP field_xp, SEXP obj, SEXP value
cl->setProperty(field_xp, obj, value);
return R_NilValue;
}

extern SEXP rcpp_dummy_pointer;

RCPP_FUN_2(SEXP, CppObject__finalize, XP_Class cl, SEXP obj) {
// an object created without arguments for a class lacking a default
// constructor holds the dummy pointer: there is nothing to finalize
if (obj == rcpp_dummy_pointer)
return R_NilValue;
cl->run_finalizer(obj);
return R_NilValue;
}
Expand Down
Loading