Skip to content

Traverse bytecode objects #1

@lionel-

Description

@lionel-

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions