@@ -244,9 +244,9 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
244244 ncol = length (VECTOR_ELT (l , first )); // ncol was increased as if fill=true, so reduce it back given fill=false (fill==false checked above)
245245 }
246246
247- int nprotect = 0 ;
248- SEXP ans = PROTECT (allocVector (VECSXP , idcol + ncol )); nprotect ++ ;
249- SEXP ansNames = PROTECT (allocVector (STRSXP , idcol + ncol )); nprotect ++ ;
247+ int nprotect = 2 ;
248+ SEXP ans = PROTECT (allocVector (VECSXP , idcol + ncol ));
249+ SEXP ansNames = PROTECT (allocVector (STRSXP , idcol + ncol ));
250250 setAttrib (ans , R_NamesSymbol , ansNames );
251251 if (idcol ) {
252252 SET_STRING_ELT (ansNames , 0 , STRING_ELT (idcolArg , 0 ));
@@ -534,22 +534,25 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
534534 if (w == -1 || !length (thisCol = VECTOR_ELT (li , w ))) { // !length for zeroCol warning above; #1871
535535 writeNA (target , ansloc , thisnrow , false); // writeNA is integer64 aware and writes INT64_MIN
536536 } else {
537- bool listprotect = false;
538- if ((TYPEOF (target )== VECSXP || TYPEOF (target )== EXPRSXP ) && TYPEOF (thisCol )!= TYPEOF (target )) {
539- // do an as.list() on the atomic column; #3528
540- thisCol = PROTECT (coerceVector (thisCol , TYPEOF (target ))); listprotect = true;
537+ bool listprotect = (TYPEOF (target )== VECSXP || TYPEOF (target )== EXPRSXP ) && TYPEOF (thisCol )!= TYPEOF (target );
538+ // do an as.list() on the atomic column; #3528
539+ if (listprotect ) {
540+ thisCol = PROTECT (coerceVector (thisCol , TYPEOF (target )));
541+ // else coerces if needed within memrecycle; with a no-alloc direct coerce from 1.12.4 (PR #3909)
542+ const char * ret = memrecycle (target , R_NilValue , ansloc , thisnrow , thisCol , 0 , -1 , idcol + j + 1 , foundName );
543+ UNPROTECT (1 ); // earlier unprotect rbindlist calls with lots of lists #4536
544+ if (ret ) warning (_ ("Column %d of item %d: %s" ), w + 1 , i + 1 , ret );
545+ } else {
546+ const char * ret = memrecycle (target , R_NilValue , ansloc , thisnrow , thisCol , 0 , -1 , idcol + j + 1 , foundName );
547+ if (ret ) warning (_ ("Column %d of item %d: %s" ), w + 1 , i + 1 , ret );
541548 }
542- // else coerces if needed within memrecycle; with a no-alloc direct coerce from 1.12.4 (PR #3909)
543- const char * ret = memrecycle (target , R_NilValue , ansloc , thisnrow , thisCol , 0 , -1 , idcol + j + 1 , foundName );
544- if (listprotect ) UNPROTECT (1 ); // earlier unprotect rbindlist calls with lots of lists #4536
545- if (ret ) warning (_ ("Column %d of item %d: %s" ), w + 1 , i + 1 , ret );
546549 // e.g. when precision is lost like assigning 3.4 to integer64; test 2007.2
547550 // TODO: but maxType should handle that and this should never warn
548551 }
549552 ansloc += thisnrow ;
550553 }
551554 }
552555 }
553- UNPROTECT (nprotect ); // ans, coercedForFactor, thisCol
556+ UNPROTECT (nprotect ); // ans, ansNames, coercedForFactor?
554557 return (ans );
555558}
0 commit comments