Skip to content

Commit 2005045

Browse files
author
luke
committed
Add R_duplicateAsResizable.
git-svn-id: https://svn.r-project.org/R/trunk@89042 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent f63fd15 commit 2005045

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/include/Rinternals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,7 @@ bool R_isResizable(SEXP x);
12371237
R_xlen_t R_maxLength(SEXP x);
12381238
void R_resizeVector(SEXP x, R_xlen_t newlen);
12391239
SEXP R_allocResizableVector(SEXPTYPE type, R_xlen_t len, R_xlen_t maxlen);
1240+
SEXP R_duplicateAsResizable(SEXP x);
12401241

12411242

12421243
/* Rest of this file

src/main/memory.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5045,6 +5045,20 @@ SEXP R_allocResizableVector(SEXPTYPE type, R_xlen_t len, R_xlen_t maxlen)
50455045
return val;
50465046
}
50475047

5048+
SEXP R_duplicateAsResizable(SEXP x)
5049+
{
5050+
if (ALTREP(x))
5051+
error(_("ALTREP objects cannot be made resizable"));
5052+
if (! isVector(x))
5053+
error(_("cannot make non-vector objects resizable"));
5054+
if (! GROWABLE_BIT_SET(x) && XTRUELENGTH(x) != 0)
5055+
error("XTRUELENGTH has been hijacked");
5056+
SEXP val = duplicate(x);
5057+
SET_TRUELENGTH(x, XLENGTH(x));
5058+
SET_GROWABLE_BIT(x);
5059+
return val;
5060+
}
5061+
50485062
static R_INLINE void clear_elements(SEXP x, R_xlen_t from, R_xlen_t to)
50495063
{
50505064
switch(TYPEOF(x)) {
@@ -5086,7 +5100,7 @@ void R_resizeVector(SEXP x, R_xlen_t newlen)
50865100
R_xlen_t len = XLENGTH(x);
50875101
if (newlen < len) // clear dropped elements to drop refcounts
50885102
clear_elements(x, newlen, len);
5089-
SETLENGTH(x, newlen);
5103+
SET_STDVEC_LENGTH(x, newlen);
50905104
if (len < newlen) // initialize new elements
50915105
clear_elements(x, len, newlen);
50925106
}

0 commit comments

Comments
 (0)