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

R: cannot call igraph function in callbacks #571

Closed
gaborcsardi opened this issue Jan 24, 2014 · 7 comments
Closed

R: cannot call igraph function in callbacks #571

gaborcsardi opened this issue Jan 24, 2014 · 7 comments
Assignees
Milestone

Comments

@gaborcsardi
Copy link
Contributor

BEcause it frees all memory allocated by igraph.

@ghost ghost assigned gaborcsardi Jan 24, 2014
@gaborcsardi
Copy link
Contributor Author

I guess there is not much we can do at this point, but 1) document that this is not allowed and 2) check the finally stack at the beginning of each call from R, and if it is not empty, then quit with an error.

@gaborcsardi
Copy link
Contributor Author

Since we don't have a hook that is called each time an R->C call happens, maybe a possible solution is to redefine .Call within the package. Unfortunately this will have some overhead, both the .Call redefinition and the check for the FINALLY stack being empty.

@gaborcsardi
Copy link
Contributor Author

Redefining .Call is quite some overhead, actually:

> time_that("Redefining .Call does not have much overhead #1", replications=10,
+           init = { library(igraph) ; g <- graph.ring(100) },
+           { for (i in 1:20000) {
+             base::.Call("R_igraph_vcount", g, PACKAGE = "igraph")
+           }  })
replications    user.self     sys.self      elapsed   user.child    sys.child 
     10.0000       0.1515       0.0004       0.1518       0.0000       0.0000 
> 
> time_that("Redefining .Call does not have much overhead #1", replications=10,
+           init = { library(igraph) ; g <- graph.ring(100) },
+           { for (i in 1:20000) {
+             igraph:::.Call("R_igraph_vcount", g, PACKAGE = "igraph")
+           }  })
replications    user.self     sys.self      elapsed   user.child    sys.child 
     10.0000       0.2692       0.0003       0.2693       0.0000       0.0000 

And this is even without the extra .Call to check the FINALLY stack. And this is with the proper check:

> time_that("Redefining .Call does not have much overhead #1", replications=10,
+           init = { library(igraph) ; g <- graph.ring(100) },
+           { for (i in 1:20000) {
+             igraph:::.Call("R_igraph_vcount", g, PACKAGE = "igraph")
+           }  })
replications    user.self     sys.self      elapsed   user.child    sys.child 
     10.0000       0.4127       0.0011       0.4137       0.0000       0.0000 

@gaborcsardi
Copy link
Contributor Author

OK, redefined .Call for now, until there will be a better solution.

@ludwikbukowski
Copy link

ludwikbukowski commented Feb 8, 2018

is it fixed? I got segmentation faults in simple scripts:

library('igraph')
g <- make_tree(10)
#g<- set_vertex_attr(g, "xx", value = 10:19)
f.in <- function(graph, data, extra) {
print(graph)
FALSE
}
tmp <- bfs(g, root=1, "out",callback=f.in)

Remove if not related to this issue

@ntamas
Copy link
Member

ntamas commented Feb 8, 2018

Most likely it is fixed; the latest R interface of igraph is version 1.1.2, released 2017-07-21, which is several years later than the date of the above commit. Please file a separate bug report for your issue in https://github.com/igraph/rigraph/issues

@ludwikbukowski
Copy link

Thank you for the response.
I just did it here: igraph/rigraph#253

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

3 participants