Skip to content

make finalize() a no-op for never-constructed module objects - #1518

Open
kevinushey wants to merge 2 commits into
masterfrom
bugfix/module-dummy-finalizer
Open

kevinushey wants to merge 2 commits into
masterfrom
bugfix/module-dummy-finalizer

Conversation

@kevinushey

@kevinushey kevinushey commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A module object created without arguments for a class lacking a default constructor holds the dummy pointer set up in .onLoad() (see cpp_object_dummy()), which is an environment rather than an external pointer. The generated finalize() method passed it to CppObject__finalize, which failed, and because the reference class registers finalize() as the object's finalizer the failure surfaced at garbage collection:

Error in gc() : Expecting an external pointer: [type=environment].

This makes CppObject__finalize a no-op when handed the dummy pointer, using the same identity check against rcpp_dummy_pointer that the CppMethod__invoke* entry points already use (via CHECK_DUMMY_OBJ), and adds a test. The test aborts with the error above on master.

The check is on identity rather than on TYPEOF(obj), so that a genuinely wrong .pointer still errors instead of being silently ignored.

Checklist

  • Code compiles correctly
  • R CMD check still passes all tests
  • Preferably, new tests were added which fail without the change
  • Document the changes by adding to the ChangeLog file

An object created without arguments for a class without a default
constructor holds the dummy pointer, which is an environment rather
than an external pointer. Its finalize() method passed it to
CppObject__finalize, which failed, and the failure surfaced as
"Expecting an external pointer: [type=environment]" during garbage
collection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant