Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traverse bytecode objects #1

Open
lionel- opened this issue Dec 3, 2021 · 0 comments
Open

Traverse bytecode objects #1

lionel- opened this issue Dec 3, 2021 · 0 comments

Comments

@lionel-
Copy link
Member

lionel- commented Dec 3, 2021

Would have helped with r-lib/coro#36 where a leak occurred via a cached bytecode object where an environment was included in the constant pool.

f <- compiler::cmpfun(inject(function() {
  !!env(x = sample(1e7))
}))

cpp11::cpp_source(code = "
  #include <Rinternals.h>
  [[cpp11::register]]
  SEXP get_body(SEXP x) {
    return BODY(x);
  }"
)

bcode <- get_body(f)
rlang:::poke_type(bcode, "pairlist")

bcode
#> [[1]]
#> [1]      12       0 8430964       1       1       0 8423560       1
#>
#> .
#>
#> [[1]]
#> {
#>     <environment>
#> }
#>
#> [[2]]
#> <environment: 0x2e2708dc0>
#>
#> [[3]]
#> !!env(x = sample(1e7))
#>
#> [[4]]
#> [1] NA  1  1  1
#> attr(,"class")
#> [1] "expressionsIndex"
#>
#> [[5]]
#> [1] NA  2  2  2
#> attr(,"class")
#> [1] "srcrefsIndex"
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

No branches or pull requests

1 participant