Skip to content

Commit

Permalink
feat: Generate all bindings (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviator-app[bot] authored Apr 9, 2024
2 parents dce9ed6 + f87a91c commit e5ace75
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
11 changes: 11 additions & 0 deletions R/aaa-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ empty_impl <- function(n=0, directed=TRUE) {
res
}

add_edges_impl <- function(graph, edges) {
# Argument checks
ensure_igraph(graph)

on.exit( .Call(R_igraph_finalizer) )
# Function call
res <- .Call(R_igraph_add_edges, graph, edges)

res
}

copy_impl <- function(from) {
# Argument checks
ensure_igraph(from)
Expand Down
2 changes: 1 addition & 1 deletion R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ add_edges <- function(graph, edges, ..., attr = list()) {

edges.orig <- ecount(graph)
on.exit(.Call(R_igraph_finalizer))
graph <- .Call(R_igraph_add_edges, graph, as_igraph_vs(graph, edges) - 1)
graph <- .Call(R_igraph_add_edges_manual, graph, as_igraph_vs(graph, edges) - 1)
edges.new <- ecount(graph)

if (edges.new - edges.orig != 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern "C" SEXP _igraph_getsphere(SEXP spos, SEXP sradius, SEXP scolor, SEXP lig
extern "C" {
/* .Call calls */
extern SEXP R_igraph_add_edges(void *, void *);
extern SEXP R_igraph_add_edges_manual(void *, void *);
extern SEXP R_igraph_add_env(void *);
extern SEXP R_igraph_add_myid_to_env(void *);
extern SEXP R_igraph_add_version_to_env(void *);
Expand Down Expand Up @@ -481,6 +482,7 @@ extern SEXP promise_expr_(void *);

static const R_CallMethodDef CallEntries[] = {
{"R_igraph_add_edges", (DL_FUNC) &R_igraph_add_edges, 2},
{"R_igraph_add_edges_manual", (DL_FUNC) &R_igraph_add_edges_manual, 2},
{"R_igraph_add_env", (DL_FUNC) &R_igraph_add_env, 1},
{"R_igraph_add_myid_to_env", (DL_FUNC) &R_igraph_add_myid_to_env, 1},
{"R_igraph_add_version_to_env", (DL_FUNC) &R_igraph_add_version_to_env, 1},
Expand Down
27 changes: 27 additions & 0 deletions src/rinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ SEXP R_igraph_empty(SEXP n, SEXP directed) {
return(r_result);
}

/*-------------------------------------------/
/ igraph_add_edges /
/-------------------------------------------*/
SEXP R_igraph_add_edges(SEXP graph, SEXP edges) {
/* Declarations */
igraph_t c_graph;
igraph_vector_int_t c_edges;


SEXP r_result;
/* Convert input */
R_SEXP_to_igraph_copy(graph, &c_graph);
IGRAPH_FINALLY(igraph_destroy, &c_graph);
R_SEXP_to_vector_int_copy(edges, &c_edges);
/* Call igraph */
IGRAPH_R_CHECK(igraph_add_edges(&c_graph, &c_edges, 0));

/* Convert output */
PROTECT(graph=R_igraph_to_SEXP(&c_graph));
IGRAPH_I_DESTROY(&c_graph);
IGRAPH_FINALLY_CLEAN(1);
r_result = graph;

UNPROTECT(1);
return(r_result);
}

/*-------------------------------------------/
/ igraph_copy /
/-------------------------------------------*/
Expand Down
2 changes: 1 addition & 1 deletion src/rinterface_extra.c
Original file line number Diff line number Diff line change
Expand Up @@ -3787,7 +3787,7 @@ SEXP R_igraph_mybracket3_set(SEXP graph, SEXP pidx1, SEXP pidx2,
return newgraph;
}

SEXP R_igraph_add_edges(SEXP graph, SEXP edges) {
SEXP R_igraph_add_edges_manual(SEXP graph, SEXP edges) {

igraph_vector_int_t v; /* do NOT destroy! */
igraph_t g;
Expand Down
1 change: 0 additions & 1 deletion tools/stimulus/functions-R.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ igraph_empty_attrs:
IGNORE: RR, RC

igraph_add_edges:
IGNORE: RR, RC, RInit

igraph_add_vertices:
IGNORE: RR, RC, RInit
Expand Down

0 comments on commit e5ace75

Please sign in to comment.