Use public R C APIs for R 4.6 compatibility#2
Conversation
Replace legacy/non-API R internals that are no longer available under R 4.6 headers. Allocate language objects directly with Rf_allocLang(), avoid Rf_findVarInFrame(), and rebuild transformed closures with R_mkClosure() while preserving the original environment and attributes. This fixes installation failures such as: imputesrcref.so: undefined symbol: SET_BODY The srcref coordinate output was compared against the previous implementation under R 4.5.2 and matched after normalizing srcfile timestamps.
There was a problem hiding this comment.
Pull request overview
This PR updates the package’s C code to avoid relying on R internals that are no longer available with R 4.6 headers, replacing them with public R APIs to restore build/install compatibility.
Changes:
- Rebuild transformed functions using
R_mkClosure()(preserving the original closure environment) and reapply attributes viaattributes(). - Replace legacy
allocList(...); SET_TYPEOF(..., LANGSXP)patterns withRf_allocLang()for language object allocation. - Replace
Rf_findVarInFrame()usage withR_tryEvalSilent()when probing base bindings forSPECIALSXP.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/transform.c | Uses public APIs (Rf_allocLang, R_mkClosure, attributes()) to construct transformed closures without internal setters. |
| src/srcref_sites.c | Allocates language objects with Rf_allocLang() for R 4.6 header compatibility. |
| src/source_impute.c | Allocates the sys.source call with Rf_allocLang() instead of mutating a list into a LANGSXP. |
| src/blacklist.c | Avoids Rf_findVarInFrame() by evaluating symbols in R_BaseEnv via R_tryEvalSilent(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Are there performance implications for this? Time to impute is included in our results for comparison against |
|
I have not benchmarked yet but I expect there would be a performance impact as it now copies instead of mutating place for the closures. I don't think the No need to merge this now, but anyway, some of the functions used in the package are not public anymore in R 4.6 so the package will break. |
# Conflicts: # src/transform.c
R from 4.6 hides symbols that used to be public
Replace legacy/non-API R internals that are no longer available under R 4.6 headers. Allocate language objects directly with Rf_allocLang(), avoid Rf_findVarInFrame(), and rebuild transformed closures with R_mkClosure() while preserving the original environment and attributes.
This fixes installation failures such as:
imputesrcref.so: undefined symbol: SET_BODY
The srcref coordinate output was compared against the previous implementation under R 4.5.2 and matched after normalizing srcfile timestamps.