|
89 | 89 |
|
90 | 90 | // TODO(R>=4.6.0): remove the SVN revision check |
91 | 91 | #if R_VERSION < R_Version(4, 6, 0) || R_SVN_REVISION < 89077 |
| 92 | +# define BACKPORT_RESIZABLE_API |
92 | 93 | # define R_allocResizableVector(type, maxlen) R_allocResizableVector_(type, maxlen) |
93 | 94 | # define R_duplicateAsResizable(x) R_duplicateAsResizable_(x) |
94 | | -# define R_resizeVector(x, newlen) SETLENGTH(x, newlen) |
95 | 95 | # define R_maxLength(x) R_maxLength_(x) |
96 | 96 | static inline R_xlen_t R_maxLength_(SEXP x) { |
97 | 97 | return IS_GROWABLE(x) ? TRUELENGTH(x) : XLENGTH(x); |
98 | 98 | } |
99 | 99 | # define R_isResizable(x) R_isResizable_(x) |
100 | 100 | static inline bool R_isResizable_(SEXP x) { |
101 | | - // IS_GROWABLE also checks for XLENGTH < TRUELENGTH |
102 | | - return (LEVELS(x) & 0x20) && TRUELENGTH(x); |
| 101 | + // IS_GROWABLE checks for XLENGTH < TRUELENGTH instead |
| 102 | + return (LEVELS(x) & 0x20) && XLENGTH(x) <= TRUELENGTH(x); |
103 | 103 | } |
| 104 | +# define R_resizeVector(x, newlen) R_resizeVector_(x, newlen) |
104 | 105 | #endif |
105 | 106 |
|
106 | 107 | // init.c |
@@ -338,8 +339,11 @@ bool perhapsDataTable(SEXP x); |
338 | 339 | SEXP perhapsDataTableR(SEXP x); |
339 | 340 | SEXP frev(SEXP x, SEXP copyArg); |
340 | 341 | NORET void internal_error(const char *call_name, const char *format, ...); |
| 342 | +#ifdef BACKPORT_RESIZABLE_API |
341 | 343 | SEXP R_allocResizableVector_(SEXPTYPE type, R_xlen_t maxlen); |
342 | 344 | SEXP R_duplicateAsResizable_(SEXP x); |
| 345 | +void R_resizeVector_(SEXP x, R_xlen_t newlen); |
| 346 | +#endif |
343 | 347 |
|
344 | 348 | // types.c |
345 | 349 | char *end(char *start); |
|
0 commit comments