Skip to content

Commit

Permalink
PROTECT() more to fix rchk issues
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbutuseless committed Apr 10, 2024
1 parent c073cb3 commit 850127e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: yyjsonr
Type: Package
Title: Fast 'JSON', 'NDJSON' and 'GeoJSON' Parser and Generator
Version: 0.1.19
Version: 0.1.20
Authors@R: c(
person("Mike", "Cheng", role = c("aut", "cre", 'cph'),
email = "[email protected]"),
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@


# yyjsonr 0.1.20 2024-04-10

* Fix outstanding `rchk` errors

# yyjsonr 0.1.19 2024-04-10

* Release to CRAN
* Prepare for CRAN

# yyjsonr 0.1.18.9007 2024-04-09

Expand Down
9 changes: 6 additions & 3 deletions src/R-yyjson-serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,13 @@ yyjson_mut_val *env_to_json_object(SEXP env_, yyjson_mut_doc *doc, serialize_opt

for (int i = 0; i < length(nms_); i++) {
const char *varname = CHAR(STRING_ELT(nms_, i));
SEXP elem_ = Rf_findVarInFrame(env_, installChar(mkChar(varname)));
SEXP elem_ = PROTECT(Rf_findVarInFrame(env_, installChar(mkChar(varname))));
if (elem_ != R_UnboundValue) {
yyjson_mut_val *key = yyjson_mut_strcpy(doc, varname);
yyjson_mut_val *val = serialize_core(elem_, doc, opt);
yyjson_mut_obj_add(obj, key, val);
}
UNPROTECT(1);
}

UNPROTECT(nprotect);
Expand Down Expand Up @@ -746,7 +747,7 @@ yyjson_mut_val *named_list_to_json_object(SEXP list_, yyjson_mut_doc *doc, seria

yyjson_mut_val *obj = yyjson_mut_obj(doc);

SEXP nms_ = getAttrib(list_, R_NamesSymbol);
SEXP nms_ = PROTECT(getAttrib(list_, R_NamesSymbol));

for (int i = 0; i < length(list_); i++) {
SEXP elem_ = VECTOR_ELT(list_, i);
Expand All @@ -764,6 +765,7 @@ yyjson_mut_val *named_list_to_json_object(SEXP list_, yyjson_mut_doc *doc, seria
yyjson_mut_obj_add(obj, key, val);
}

UNPROTECT(1);
return obj;
}

Expand Down Expand Up @@ -865,7 +867,7 @@ unsigned int *detect_data_frame_types(SEXP df_, serialize_options *opt) {
yyjson_mut_val *data_frame_row_to_json_object(SEXP df_, unsigned int *col_type, unsigned int row, int skip_col, yyjson_mut_doc *doc, serialize_options *opt) {

// get data.frame names
SEXP nms_ = getAttrib(df_, R_NamesSymbol);
SEXP nms_ = PROTECT(getAttrib(df_, R_NamesSymbol));
unsigned int ncols = (unsigned int)length(df_);

yyjson_mut_val *obj = yyjson_mut_obj(doc);
Expand Down Expand Up @@ -926,6 +928,7 @@ yyjson_mut_val *data_frame_row_to_json_object(SEXP df_, unsigned int *col_type,
}
}

UNPROTECT(1);
return obj;
}

Expand Down

0 comments on commit 850127e

Please sign in to comment.