Skip to content

Commit

Permalink
proper fix for #5753 to make zlib fully optional (#5770)
Browse files Browse the repository at this point in the history
  • Loading branch information
jangorecki authored Nov 27, 2023
1 parent a6fe882 commit 9ddbb4d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/fwrite.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
invisible()
}

nozlib = function() identical(.Call(Cdt_zlib_version), "zlib header files were not found when data.table was compiled")
haszlib = function() .Call(Cdt_has_zlib)

6 changes: 3 additions & 3 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) {
which.first = data.table:::which.first
which.last = data.table:::which.last
`-.IDate` = data.table:::`-.IDate`
nozlib = data.table:::nozlib
haszlib = data.table:::haszlib

# Also, for functions that are masked by other packages, we need to map the data.table one. Or else,
# the other package's function would be picked up. As above, we only need to do this because we desire
Expand Down Expand Up @@ -9881,7 +9881,7 @@ test(1658.39, fwrite(matrix(1:3, nrow=3, ncol=1), quote = TRUE), output = '"V1"\
test(1658.40, fwrite(matrix(1:4, nrow=2, ncol=2, dimnames = list(c("ra","rb"),c("ca","cb"))), quote = TRUE), output = '"ca","cb"\n.*1,3\n2,4', message = "x being coerced from class: matrix to data.table")

# fwrite compress
if (nozlib()) {
if (!haszlib()) {
test(1658.409, fwrite(data.table(a=1), file=tempfile(), compress="gzip"), error="header files were not found at the time data.table was compiled")
} else {
test(1658.41, fwrite(data.table(a=c(1:3), b=c(1:3)), compress="gzip"), output='a,b\n1,1\n2,2\n3,3') # compress ignored on console
Expand Down Expand Up @@ -9921,7 +9921,7 @@ test(1658.52, file.info(f1)$size, file.info(f2)$size)
unlink(c(f1, f2))

# compression error -5 due to only 3 bytes (bom) in first block; #3599
if (!nozlib()) {
if (haszlib()) {
DT = data.table(l=letters, n=1:26)
test(1658.53, fwrite(DT, file=f<-tempfile(fileext=".gz"), bom=TRUE, col.names=FALSE), NULL)
if (test_R.utils) test(1658.54, fread(f), setnames(DT,c("V1","V2")))
Expand Down
1 change: 1 addition & 0 deletions src/data.table.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ SEXP initLastUpdated(SEXP);
SEXP allNAR(SEXP);
SEXP test_dt_win_snprintf(void);
SEXP dt_zlib_version(void);
SEXP dt_has_zlib(void);
SEXP startsWithAny(SEXP, SEXP, SEXP);
SEXP convertDate(SEXP, SEXP);
SEXP fastmean(SEXP);
Expand Down
1 change: 1 addition & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ R_CallMethodDef callMethods[] = {
{"CcoerceAs", (DL_FUNC) &coerceAs, -1},
{"Ctest_dt_win_snprintf", (DL_FUNC)&test_dt_win_snprintf, -1},
{"Cdt_zlib_version", (DL_FUNC)&dt_zlib_version, -1},
{"Cdt_has_zlib", (DL_FUNC)&dt_has_zlib, -1},
{"Csubstitute_call_arg_namesR", (DL_FUNC) &substitute_call_arg_namesR, -1},
{"CstartsWithAny", (DL_FUNC)&startsWithAny, -1},
{"CconvertDate", (DL_FUNC)&convertDate, -1},
Expand Down
7 changes: 7 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ SEXP dt_zlib_version(void) {
#endif
return ScalarString(mkChar(out));
}
SEXP dt_has_zlib(void) {
#ifndef NOZLIB
return ScalarLogical(1);
#else
return ScalarLogical(0);
#endif
}

SEXP startsWithAny(const SEXP x, const SEXP y, SEXP start) {
// for is_url in fread.R added in #5097
Expand Down

0 comments on commit 9ddbb4d

Please sign in to comment.