Skip to content

Commit 3aa45b9

Browse files
Make it a helper
1 parent 1e2d4d7 commit 3aa45b9

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/assign.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ SEXP setdt_nrows(SEXP x)
239239
len_xi = INTEGER(dim_xi)[0];
240240
} else {
241241
// Be sure to do length() dispatch, #4800
242-
len_xi = INTEGER(PROTECT(eval(PROTECT(lang2(install("length"), xi)), R_GlobalEnv)))[0];
243-
UNPROTECT(2);
242+
len_xi = INTEGER(length_with_dispatch(xi))[0];
244243
}
245244
if (!base_length) {
246245
base_length = len_xi;

src/data.table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,6 @@ SEXP test_dt_win_snprintf(void);
350350
SEXP dt_zlib_version(void);
351351
SEXP dt_has_zlib(void);
352352
SEXP startsWithAny(SEXP, SEXP, SEXP);
353+
SEXP length_with_dispatch(SEXP);
353354
SEXP convertDate(SEXP, SEXP);
354355
SEXP fastmean(SEXP);
355-

src/utils.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ SEXP startsWithAny(const SEXP x, const SEXP y, SEXP start) {
449449
return ScalarLogical(false);
450450
}
451451

452+
SEXP length_with_dispatch(SEXP x) {
453+
SEXP l = PROTECT(eval(PROTECT(lang2(install("length"), x)), R_GlobalEnv));
454+
UNPROTECT(2);
455+
return l;
456+
}
457+
452458
void internal_error(const char *call_name, const char *format, ...) {
453459
char buff[1024];
454460
va_list args;

0 commit comments

Comments
 (0)