Skip to content

Commit 3e451b3

Browse files
committed
always force run weak finalizers before freeing sys
1 parent d72c0e4 commit 3e451b3

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

R/init.R

-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,5 @@ NULL
2525
}
2626

2727
.onUnload = function(libname, pkgname) {
28-
# force run weak finalizers before freeing sys
29-
invisible(gc())
3028
udunits_exit()
3129
}

src/udunits.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ typedef XPtr<ut_unit, PreserveStorage, ut_free, true> XPtrUT;
3030
static ut_system *sys = NULL;
3131
static ut_encoding enc = UT_UTF8;
3232

33+
// [[Rcpp::export]]
34+
void udunits_exit() {
35+
R_gc();
36+
ut_free_system(sys);
37+
sys = NULL;
38+
}
39+
3340
// [[Rcpp::export]]
3441
void udunits_init(CharacterVector path) {
3542
ut_set_error_message_handler(ut_ignore);
36-
ut_free_system(sys);
43+
udunits_exit();
3744
for (int i = 0; i < path.size(); i++) {
3845
if ((sys = ut_read_xml(path[i])) != NULL)
3946
break;
@@ -45,12 +52,6 @@ void udunits_init(CharacterVector path) {
4552
stop("no database found!"); // #nocov
4653
}
4754

48-
// [[Rcpp::export]]
49-
void udunits_exit() { // #nocov start
50-
ut_free_system(sys);
51-
sys = NULL;
52-
} // #nocov end
53-
5455
// wrap a ut_unit pointer in an XPtr
5556
SEXP ut_wrap(ut_unit *u) {
5657
XPtrUT p(u);

0 commit comments

Comments
 (0)