Skip to content
Closed
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
2 changes: 0 additions & 2 deletions src/rinterface_extra.c
Original file line number Diff line number Diff line change
Expand Up @@ -3718,8 +3718,6 @@ int R_SEXP_to_igraph(SEXP graph, igraph_t *res) {
R_igraph_get_is(graph, &res->is);

/* attributes */
REAL(VECTOR_ELT(VECTOR_ELT(graph, igraph_t_idx_attr), 0))[0] = 1; /* R objects refcount */
REAL(VECTOR_ELT(VECTOR_ELT(graph, igraph_t_idx_attr), 0))[1] = 0; /* igraph_t objects */
res->attr=VECTOR_ELT(graph, igraph_t_idx_attr);

return 0;
Expand Down
80 changes: 80 additions & 0 deletions tests/testthat/test-attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,83 @@ test_that("setting NULL attributes works and doesn't change the input (#466)", {
expect_identical(set_edge_attr(g, "foo", value = NULL), g)
expect_identical(set_edge_attr(g, "foo", 1:3, value = NULL), g)
})

test_that("GRAPH attributes are destroyed when the graph is destroyed", {
finalized <- FALSE
finalizer <- function(e) {
finalized <<- TRUE
}

env <- new.env(parent = emptyenv())
reg.finalizer(env, finalizer)

g <- make_ring(1)
g$a <- list(env)
rm(env)
gc()
expect_false(finalized)

rm(g)
gc()
expect_true(finalized)
})

test_that("vertex attributes are destroyed when the graph is destroyed", {
finalized <- FALSE
finalizer <- function(e) {
finalized <<- TRUE
}

env <- new.env(parent = emptyenv())
reg.finalizer(env, finalizer)

g <- make_ring(1)
V(g)$a <- list(env)
rm(env)
gc()
expect_false(finalized)

g <- add_vertices(g, 1)
gc()
expect_false(finalized)

g <- delete_vertices(g, 2)
gc()
expect_false(finalized)

rm(g)
gc()
expect_true(finalized)
})

test_that("edge attributes are destroyed when the graph is destroyed", {
finalized <- FALSE
finalizer <- function(e) {
finalized <<- TRUE
}

env <- new.env(parent = emptyenv())
reg.finalizer(env, finalizer)

g <- make_ring(2)
E(g)$a <- list(env)
rm(env)
gc()
expect_false(finalized)

g <- add_vertices(g, 1)
gc()
expect_false(finalized)

g <- add_edges(g, c(2, 3))
gc()
expect_false(finalized)

g <- delete_edges(g, 2)
gc()
expect_false(finalized)

rm(g)
gc()
expect_true(finalized)
})