You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Migrate most uses of SETLENGTH to the resizable API (#7451)
* Use the experimental resizable vectors API
Thanks to Luke Tierney for introducing the API and helping with the migration.
* Backport the resizable API
Make sure to set the GROWABLE_BIT on the resizable vectors to avoid
problems when they are duplicated or garbage-collected.
* test 2291.1: misleading TRUELENGTH now impossible
Now that data.table objects have the GROWABLE_BIT set, R will reset TRUELENGTH
when duplicating them, causing our code to take a different branch.
* Drop the finalizer
Now that (1) we depend on R >= 3.4 and (2) data.table objects have the
GROWABLE_BIT set, there is no need to adjust allocated memory counts by
hand.
* frollapply(adaptive=TRUE): resizable temporaries
Since adaptive application of rolling functions requires us to resize
the argument to match the window size, make sure to allocate it as such.
* Drop remaining uses of TRUELENGTH from assign.c
- Don't SET_TRUELENGTH by hand. All of our resizable vectors now have
the GROWABLE_BIT set, so when they are duplicated, TRUELENGTH is reset
to 0.
- Use a combination of R_isResizable and R_maxLength to replace other
uses of TRUELENGTH.
* Drop test for TRUELENGTH from init.c
* Better backport of R_isResizable()
* Placate rchk
* copyAsGrowable: don't crash on 0-len argument
* Move the resizable allocation functions to utils.c
* duplicateAsResizable: refuse ALTREP objects
* maxLength: return xlength if non-resizable
That's what the function does in R-devel.
* adjust to previous code
* Safety checks in R_resizeVector() backport
* fix comment
* Mark internal errors as # nocov
---------
Co-authored-by: Jan Gorecki <[email protected]>
Co-authored-by: Benjamin Schwendinger <[email protected]>
tight=function(i, dest, src, n) {stopf("internal error: has.growable should be TRUE, implement support for n==0"); FUN(src[(i-n[i]+1L):i], ...)} # nocov
tight=function(i, dest, src, n) {stopf("internal error: has.growable should be TRUE, implement support for n==0"); FUN(src[(i-n[i]+1L):i, , drop=FALSE], ...)} # nocov
328
-
} else {
329
-
tight=function(i, dest, src, n) {stopf("internal error: has.growable should be TRUE, implement support for n==0"); FUN(lapply(src, `[`, (i-n[i]+1L):i), ...)} # nocov
// modify DT by reference. Other than if new columns are being added and the allocVec() fails with
510
445
// out-of-memory. In that case the user will receive hard halt and know to rerun.
511
446
if (length(newcolnames)) {
512
-
oldtncol=TRUELENGTH(dt); // TO DO: oldtncol can be just called tl now, as we won't realloc here any more.
447
+
if (!R_isResizable(dt)) error(_("This data.table has either been loaded from disk (e.g. using readRDS()/load()) or constructed manually (e.g. using structure()). Please run setDT() or setalloccol() on it first (to pre-allocate space for new columns) before assigning by reference to it.")); // #2996
448
+
oldtncol=R_maxLength(dt); // TO DO: oldtncol can be just called tl now, as we won't realloc here any more.
513
449
514
450
if (oldtncol<oldncol) {
515
-
if (oldtncol==0) error(_("This data.table has either been loaded from disk (e.g. using readRDS()/load()) or constructed manually (e.g. using structure()). Please run setDT() or setalloccol() on it first (to pre-allocate space for new columns) before assigning by reference to it.")); // #2996
if (oldtncol>oldncol+10000L) warning(_("truelength (%d) is greater than 10,000 items over-allocated (length = %d). See ?truelength. If you didn't set the datatable.alloccol option very large, please report to data.table issue tracker including the result of sessionInfo()."),oldtncol, oldncol);
error(_("It appears that at some earlier point, names of this data.table have been reassigned. Please ensure to use setnames() rather than names<- or colnames<-. Otherwise, please report to data.table issue tracker.")); // # nocov
523
458
// Can growVector at this point easily enough, but it shouldn't happen in first place so leave it as
524
459
// strong error message for now.
525
-
elseif (TRUELENGTH(names) !=oldtncol)
460
+
elseif (R_maxLength(names) !=oldtncol)
526
461
// Use (long long) to cast R_xlen_t to a fixed type to robustly avoid -Wformat compiler warnings, see #5768, PRId64 didn't work
527
-
internal_error(__func__, "selfrefnames is ok but tl names [%lld] != tl [%d]", (long long)TRUELENGTH(names), oldtncol); // # nocov
462
+
internal_error(__func__, "selfrefnames is ok but maxLength(names) [%lld] != maxLength(dt) [%d]", (long long)R_maxLength(names), oldtncol); // # nocov
528
463
if (!selfrefok(dt, verbose)) // #6410 setDT(dt) and subsequent attr<- can lead to invalid selfref
529
464
error(_("It appears that at some earlier point, attributes of this data.table have been reassigned. Please use setattr(DT, name, value) rather than attr(DT, name) <- value. If that doesn't apply to you, please report your case to the data.table issue tracker."));
0 commit comments