Skip to content

Commit c3e8f0c

Browse files
committed
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.
1 parent 23c7b3b commit c3e8f0c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/data.table.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@
8787
# endif
8888
#endif
8989

90+
// TODO(R>=4.6.0): remove the SVN revision check
91+
#if R_VERSION < R_Version(4, 6, 0) || R_SVN_REVISION < 89077
92+
static inline SEXP R_allocResizableVector_(SEXPTYPE type, R_xlen_t maxlen) {
93+
SEXP ret = allocVector(type, maxlen);
94+
SET_TRUELENGTH(ret, maxlen);
95+
SET_GROWABLE_BIT(ret);
96+
return ret;
97+
}
98+
# define R_allocResizableVector(type, maxlen) R_allocResizableVector_(type, maxlen)
99+
static inline SEXP R_duplicateAsResizable_(SEXP x) {
100+
SEXP ret = duplicate(x);
101+
SET_TRUELENGTH(ret, xlength(ret));
102+
SET_GROWABLE_BIT(ret);
103+
return ret;
104+
}
105+
# define R_duplicateAsResizable(x) R_duplicateAsResizable_(x)
106+
# define R_resizeVector(x, newlen) SETLENGTH(x, newlen)
107+
#endif
108+
90109
// init.c
91110
extern SEXP char_integer64;
92111
extern SEXP char_ITime;

0 commit comments

Comments
 (0)