From a650af271357a4c72bd5ecdfafa8d56a4c1571aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 30 Nov 2024 19:39:53 +0100 Subject: [PATCH] Protection tweaks --- src/rinterface_extra.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index 698aa9856b..bd4cb07684 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -253,7 +253,6 @@ SEXP R_igraph_get_attr_mode(SEXP graph, SEXP pwhich) { igraph_error_t R_SEXP_to_attr_comb(SEXP input, igraph_attribute_combination_t *comb) { igraph_integer_t n = Rf_xlength(input); - SEXP names = GET_NAMES(input); IGRAPH_CHECK(igraph_attribute_combination_init(comb)); IGRAPH_FINALLY(igraph_attribute_combination_destroy, comb); @@ -265,7 +264,7 @@ igraph_error_t R_SEXP_to_attr_comb(SEXP input, igraph_attribute_combination_t *c /* Name */ if (!Rf_isNull(names)) { - name = CHAR(STRING_ELT(names, i)); + name = CHAR(STRING_ELT(GET_NAMES(input), i)); } if (Rf_isNull(names) || strlen(name) == 0) { name = NULL; @@ -288,7 +287,7 @@ igraph_error_t R_SEXP_to_attr_comb(SEXP input, igraph_attribute_combination_t *c static SEXP R_igraph_attribute_preserve_list; -void R_igraph_attribute_add_to_preserve_list(SEXP attr) { +SEXP R_igraph_attribute_add_to_preserve_list(SEXP attr) { if (!R_igraph_attribute_preserve_list) { // We don't care about freeing this, typically this is just a single node R_igraph_attribute_preserve_list = Rf_cons(R_NilValue, R_NilValue); @@ -298,6 +297,7 @@ void R_igraph_attribute_add_to_preserve_list(SEXP attr) { // Create a new node, add it to the head of the list. SEXP node = Rf_cons(attr, CDR(R_igraph_attribute_preserve_list)); SETCDR(R_igraph_attribute_preserve_list, node); + return attr; } void R_igraph_attribute_clean_preserve_list(void) { @@ -319,9 +319,10 @@ igraph_error_t R_igraph_attribute_init(igraph_t *graph, igraph_vector_ptr_t *att int px = 0; result=PROTECT(NEW_LIST(4)); - // The "preserve list" Will be cleared with the next invocation of an igraph function. + // The "preserve list" will be cleared with the next invocation of an igraph function. // Adding to that list ensures that the attributes aren't GC-ed prematurely. - R_igraph_attribute_add_to_preserve_list(result); + result = R_igraph_attribute_add_to_preserve_list(result); + UNPROTECT(1); /* Add dummy vector for compatibility with CRAN versions */ SEXP dummy = NEW_NUMERIC(3); @@ -337,7 +338,6 @@ igraph_error_t R_igraph_attribute_init(igraph_t *graph, igraph_vector_ptr_t *att SET_VECTOR_ELT(result, i, attr); /* gal, val, eal */ UNPROTECT(1); } - UNPROTECT(1); graph->attr=result; /* Add graph attributes */