Skip to content

Commit

Permalink
setListElement() now PROTECT()s the value being stored in the list fi…
Browse files Browse the repository at this point in the history
…rst thing, then unprotects it once it has been stored.
  • Loading branch information
krivit committed Nov 4, 2024
1 parent 09aaa99 commit f8c16ac
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions inst/include/ergm_Rutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ static inline SEXP getListElement(SEXP list, const char *str){
}

static inline SEXP setListElement(SEXP list, const char *str, SEXP value){
value = PROTECT(value);
SEXP names = getAttrib(list, R_NamesSymbol);

for (unsigned int i = 0; i < length(list); i++)
if(strcmp(CHAR(STRING_ELT(names, i)), str) == 0) {
SET_VECTOR_ELT(list, i, value);
UNPROTECT(1);
return value;
}
UNPROTECT(1);
error("List does not have element '%s' to set.", str);
return R_NilValue;
}
Expand Down

0 comments on commit f8c16ac

Please sign in to comment.