Skip to content

Commit adc51ea

Browse files
not sure
1 parent 18ef60e commit adc51ea

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/assign.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ Moved out of ?setkey Details section in 1.12.2 (Mar 2019). Revisit this w.r.t. t
108108

109109
static int _selfrefok(SEXP x, Rboolean checkNames, Rboolean verbose) {
110110
SEXP v, p, tag, prot, names;
111-
int nprotect=0;
112-
v = PROTECT(getAttrib(x, SelfRefSymbol)); nprotect++;
111+
v = PROTECT(getAttrib(x, SelfRefSymbol));
113112
if (v==R_NilValue || TYPEOF(v)!=EXTPTRSXP) {
114113
// .internal.selfref missing is expected and normal for i) a pre v1.7.8 data.table loaded
115114
// from disk, and ii) every time a new data.table is over-allocated for the first time.
@@ -121,26 +120,26 @@ static int _selfrefok(SEXP x, Rboolean checkNames, Rboolean verbose) {
121120
p = R_ExternalPtrAddr(v);
122121
if (p==NULL) {
123122
if (verbose) Rprintf(_(".internal.selfref ptr is NULL. This is expected and normal for a data.table loaded from disk. Please remember to always setDT() immediately after loading to prevent unexpected behavior. If this table was not loaded from disk or you've already run setDT(), please report to data.table issue tracker.\n"));
124-
UNPROTECT(nprotect);
123+
UNPROTECT(1);
125124
return -1;
126125
}
127126
if (!isNull(p)) internal_error(__func__, ".internal.selfref ptr is neither NULL nor R_NilValue"); // # nocov
128127
tag = R_ExternalPtrTag(v);
129128
if (!(isNull(tag) || isString(tag))) internal_error(__func__, ".internal.selfref tag is neither NULL nor a character vector"); // # nocov
130-
names = PROTECT(getAttrib(x, R_NamesSymbol)); nprotect++;
129+
names = PROTECT(getAttrib(x, R_NamesSymbol));
131130
if (names!=tag && isString(names) && !ALTREP(names)) // !ALTREP for #4734
132131
SET_TRUELENGTH(names, LENGTH(names));
133132
// R copied this vector not data.table; it's not actually over-allocated. It looks over-allocated
134133
// because R copies the original vector's tl over despite allocating length.
135134
prot = R_ExternalPtrProtected(v);
136135
if (TYPEOF(prot) != EXTPTRSXP) { // Very rare. Was error(_(".internal.selfref prot is not itself an extptr")).
137-
UNPROTECT(nprotect);
136+
UNPROTECT(2);
138137
return 0; // # nocov ; see http://stackoverflow.com/questions/15342227/getting-a-random-internal-selfref-error-in-data-table-for-r
139138
}
140139
if (x!=R_ExternalPtrAddr(prot) && !ALTREP(x))
141140
SET_TRUELENGTH(x, LENGTH(x)); // R copied this vector not data.table, it's not actually over-allocated
142141
int ok = checkNames ? names==tag : x==R_ExternalPtrAddr(prot);
143-
UNPROTECT(nprotect);
142+
UNPROTECT(2);
144143
return ok;
145144
}
146145

0 commit comments

Comments
 (0)