Skip to content

Commit

Permalink
support for libdeflate
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@84880 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Aug 6, 2023
1 parent fafc33a commit 02b8eb0
Show file tree
Hide file tree
Showing 10 changed files with 445 additions and 90 deletions.
102 changes: 100 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,7 @@ with_recommended_packages
with_ICU
enable_byte_compiled_packages
with_static_cairo
with_libdeflate_compression
enable_static
enable_shared
with_pic
Expand Down Expand Up @@ -1926,6 +1927,9 @@ Optional Packages:
--with-ICU use ICU library (if available) [yes]
--with-static-cairo allow for the use of static cairo libraries [no, yes
on macOS]
--with-libdeflate-compression
use libdeflate (if available) to (de)compress
lazy-loaded R objects [no]
--with-pic[=PKGS] (libtool) try to use only PIC/non-PIC objects
[default=use both]
--with-aix-soname=aix|svr4|both
Expand Down Expand Up @@ -5055,6 +5059,21 @@ if test "x$use_static_cairo" = xdefault; then
esac
fi


# Check whether --with-libdeflate-compression was given.
if test ${with_libdeflate_compression+y}
then :
withval=$with_libdeflate_compression; use_libdeflate=${withval}
else $as_nop
use_libdeflate=no
fi

if test "x$use_libdeflate" = xyes; then

printf "%s\n" "#define USE_LIBDEFLATE 1" >>confdefs.h

fi

### ** Precious variables.


Expand Down Expand Up @@ -27111,7 +27130,7 @@ _ACEOF
# flags.
r_save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $r_verb"
(eval echo $as_me:27116: \"$ac_link\") >&5
(eval echo $as_me:27135: \"$ac_link\") >&5
r_c_v_output=`eval $ac_link 5>&1 2>&1 | grep -v 'Driving:'`
echo "$r_c_v_output" >&5
CFLAGS=$r_save_CFLAGS
Expand Down Expand Up @@ -27187,7 +27206,7 @@ _ACEOF
# flags.
r_save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $r_cv_prog_c_v"
(eval echo $as_me:27192: \"$ac_link\") >&5
(eval echo $as_me:27211: \"$ac_link\") >&5
r_c_v_output=`eval $ac_link 5>&1 2>&1 | grep -v 'Driving:'`
echo "$r_c_v_output" >&5
CFLAGS=$r_save_CFLAGS
Expand Down Expand Up @@ -51298,6 +51317,85 @@ else
fi


## libdeflate headers and libraries.

for ac_header in libdeflate.h
do :
ac_fn_c_check_header_compile "$LINENO" "libdeflate.h" "ac_cv_header_libdeflate_h" "$ac_includes_default"
if test "x$ac_cv_header_libdeflate_h" = xyes
then :
printf "%s\n" "#define HAVE_LIBDEFLATE_H 1" >>confdefs.h
have_libdeflate=yes
else $as_nop
have_libdeflate=no
fi

done
if test "${have_libdeflate}" = yes; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libdeflate_alloc_compressor in -ldeflate" >&5
printf %s "checking for libdeflate_alloc_compressor in -ldeflate... " >&6; }
if test ${ac_cv_lib_deflate_libdeflate_alloc_compressor+y}
then :
printf %s "(cached) " >&6
else $as_nop
ac_check_lib_save_LIBS=$LIBS
LIBS="-ldeflate $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
char libdeflate_alloc_compressor ();
#ifdef FC_DUMMY_MAIN
#ifndef FC_DUMMY_MAIN_EQ_F77
# ifdef __cplusplus
extern "C"
# endif
int FC_DUMMY_MAIN() { return 1; }
#endif
#endif
int
main (void)
{
return libdeflate_alloc_compressor ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
then :
ac_cv_lib_deflate_libdeflate_alloc_compressor=yes
else $as_nop
ac_cv_lib_deflate_libdeflate_alloc_compressor=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_deflate_libdeflate_alloc_compressor" >&5
printf "%s\n" "$ac_cv_lib_deflate_libdeflate_alloc_compressor" >&6; }
if test "x$ac_cv_lib_deflate_libdeflate_alloc_compressor" = xyes
then :
have_libdeflate=yes
else $as_nop
have_libdeflate=no
fi

fi
if test "x${r_cv_have_libdeflate}" = xno; then
have_libdeflate=no
fi
if test "x${have_libdeflate}" = xyes; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
LIBS="-ldeflate ${LIBS}"

printf "%s\n" "#define HAVE_LIBDEFLATE 1" >>confdefs.h

fi


## PCRE[12] headers and libraries.
have_pcre2=no
if test "x${use_pcre2}" = xyes; then
Expand Down
11 changes: 11 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,14 @@ if test "x$use_static_cairo" = xdefault; then
esac
fi

AC_ARG_WITH([libdeflate-compression],
[AS_HELP_STRING([--with-libdeflate-compression],[use libdeflate (if available) to (de)compress lazy-loaded R objects @<:@no@:>@])],
[use_libdeflate=${withval}],
[use_libdeflate=no])
if test "x$use_libdeflate" = xyes; then
AC_DEFINE(USE_LIBDEFLATE, 1, [Define to use libdefault rather than libz])
fi

### ** Precious variables.

AC_ARG_VAR([R_PRINTCMD],
Expand Down Expand Up @@ -2569,6 +2577,9 @@ R_BZLIB
## LZMA headers and libraries from xz-utils
R_LZMA

## libdeflate headers and libraries.
R_LIBDEFLATE

## PCRE[12] headers and libraries.
R_PCRE

Expand Down
43 changes: 30 additions & 13 deletions doc/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
\item The \code{confint()} and \code{profile} methods for
\code{"glm"} objects have gained a possibility to do profiling
based on the Rao Score statistic in addition to the default
Likelihood Ratio. This is controlled by a new \code{test=}
Likelihood Ratio. This is controlled by a new \code{test =}
argument.

\item The \code{"glm"} method for \code{anova()} computes test
Expand All @@ -42,7 +42,7 @@
\code{test} a false logical value.

\item In \code{setRepositories()} the repositories can be set
using their names via \code{name=} instead of index \code{ind=}.
using their names via \code{name =} instead of index \code{ind =}.

\item \code{methods()} and \code{.S3methods()} gain a
\code{all.names} option for the (rare) case where functions starting
Expand Down Expand Up @@ -73,24 +73,40 @@
\dQuote{binary} Windows installation \bold{if} a source \file{tests/}
folder is present.
\item \code{range(<DT_with_Inf>, finite=TRUE)} now work for objects
\item \code{range(<DT_with_Inf>, finite = TRUE)} now work for objects
of class \code{"Date"}, \code{"POSIXct"}, and \code{"POSIXlt"} with
infinite entries, analogously to \code{range.default()}, as proposed
by Davis Vaughan on R-devel. Other \code{range()}-methods can make
use of new \code{.rangeNum()}.
\item New \code{.internalGenerics} complementing \code{.S3PrimitiveGenerics},
for documentation and low-level book keeping.
\item New \code{.internalGenerics} complementing
\code{.S3PrimitiveGenerics}, for documentation and low-level book
keeping.
\item \code{grid()} now invisibly returns the x- and y- coordinates
at which the grid-lines were drawn.
\item \code{norm(., type)} now also works for complex matrices.
\item \code{kappa(., exact=TRUE, norm=*)} now works for all norms and
also for complex matrices. In symmetric / triangular cases, new argument
\code{uplo = "U" | "L"} allows to specify the upper or lower
triangular part.
\item \code{kappa(., exact = TRUE, norm = *)} now works for all
norms and also for complex matrices. In symmetric / triangular
cases, new argument \code{uplo = "U" | "L"} allows to specify the
upper or lower triangular part.
\item \code{memDecompress(type = "unknown")} recognizes compresion
in the defailt \sQuote{zlib} format as used by
\code{memCompress(type = "gzip")}.
\item (\strong{Experimental:}) \code{memCompress()} and
\code{memDecompress()} have a new type \code{"libdeflate"} which
use the \code{libdeflate} library
(\url{https://github.com/ebiggers/libdeflate}) if installed. This
uses the same type of compression as their default \code{type =
"gzip"} but is substantially faster on commpn plaftorms (it has
optimized code for \code{x86} and ARM CPUs, including their 64-bit
variants.)
This option may replace \code{type = "gzip"} before release.
}
}
Expand Down Expand Up @@ -221,14 +237,15 @@
arguments list (for multi-line \verb{\item} labels in the Rd source).
\item \code{kappa()} and \code{rcond()} work correctly in more cases;
\code{kappa(., norm="2")} now warns that it computes the 1-norm with
\code{kappa(., norm = "2")} now warns that it computes the 1-norm with
(default) \code{exact = FALSE}; prompted by Mikael Jagan's quite
comprehensive \PR{18543}.

\item Rd skeletons generated by \code{prompt()} or
\code{promptData()} now use a dummy title (so R CMD build works).
\code{tools::checkRdContents()} has been updated to detect
such template leftovers, including from \code{promptPackage()}.
\code{promptData()} now use a dummy title (so \command{R CMD
build} works). \code{tools::checkRdContents()} has been updated
to detect such template leftovers, including from
\code{promptPackage()}.
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions doc/manual/R-admin.texi
Original file line number Diff line number Diff line change
Expand Up @@ -3458,6 +3458,9 @@ uses @file{rpc/xdr.h} but that includes @file{netconfig.h} from the top
@file{tirpc} directory.} need to be on the C include path or under
@file{/usr/include/tirpc}.

Library @code{libdeflate} (@url{https://github.com/ebiggers/libdeflate})
is used by @code{memCompress()} and @code{memDecompress()} if available.

Use of the X11 clipboard selection requires the @code{Xmu} headers and
libraries. These are normally part of an X11 installation (e.g.@: the
Debian meta-package @samp{xorg-dev}), but some distributions have split
Expand Down Expand Up @@ -3487,12 +3490,12 @@ following packages and their development versions, and this may provide
a useful checklist for other systems:
@example
bzip2 cairo fontconfig freetype fribidi gcc gcc-gfortran gcc-c++ glib2
glibc harfbuzz libX11 libXext libXt libcurl libicu libjpeg libpng
libtiff libtirpc libxcrypt ncurses pango pkgconf-pkg-config pcre2
readline tcl tk xz zlib
glibc harfbuzz lapack libX11 libXext libXt libcurl libdeflate libicu
libjpeg libpng libtiff libtirpc libxcrypt ncurses pango
pkgconf-pkg-config pcre2 readline tcl tk xz zlib
@end example
@noindent
plus, preferably a TeX installation, Java and LAPACK >= 3.10.0.
plus, preferably a TeX installation and Java.

@menu
* Tcl/Tk::
Expand Down
21 changes: 21 additions & 0 deletions m4/R.m4
Original file line number Diff line number Diff line change
Expand Up @@ -3469,6 +3469,27 @@ else
fi
])# R_BZLIB

## R_LIBDEFLATE
## ------------
## Try finding libdeflate library and headers.
## We check that both are installed,
AC_DEFUN([R_LIBDEFLATE],
[
AC_CHECK_HEADERS(libdeflate.h, [have_libdeflate=yes], [have_libdeflate=no])
if test "${have_libdeflate}" = yes; then
AC_CHECK_LIB(deflate, libdeflate_alloc_compressor, [have_libdeflate=yes], [have_libdeflate=no])
fi
if test "x${r_cv_have_libdeflate}" = xno; then
have_libdeflate=no
fi
if test "x${have_libdeflate}" = xyes; then
AC_MSG_RESULT([yes])
LIBS="-ldeflate ${LIBS}"
AC_DEFINE(HAVE_LIBDEFLATE, 1,
[Define to 1 if you have libdeflate headers and library.])
fi
])# R_LIBDEFLATE

## R_TRE
## -------
## Try finding tre library and headers.
Expand Down
9 changes: 9 additions & 0 deletions src/gnuwin32/fixed/h/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,12 @@
/* Define if __libc_stack_end is visible. */
/* #undef HAVE_LIBC_STACK_END */

/* Define to 1 if you have libdeflate headers and library. */
/* #undef HAVE_LIBDEFLATE */

/* Define to 1 if you have the <libdeflate.h> header file. */
/* #undef HAVE_LIBDEFLATE_H */

/* Define to 1 if you have the `dl' library (-ldl). */
/* #undef HAVE_LIBDL */

Expand Down Expand Up @@ -1218,6 +1224,9 @@
/* Define to use internal time-zone code */
#define USE_INTERNAL_MKTIME 1

/* Define to use libdefault rather than libz */
/* #undef USE_LIBDEFLATE */

/* Define if the POSIX multithreading library can be used. (For intl) */
/* #undef USE_POSIX_THREADS */

Expand Down
9 changes: 9 additions & 0 deletions src/include/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@
/* Define if __libc_stack_end is visible. */
#undef HAVE_LIBC_STACK_END

/* Define to 1 if you have libdeflate headers and library. */
#undef HAVE_LIBDEFLATE

/* Define to 1 if you have the <libdeflate.h> header file. */
#undef HAVE_LIBDEFLATE_H

/* Define to 1 if you have the `dl' library (-ldl). */
#undef HAVE_LIBDL

Expand Down Expand Up @@ -1147,6 +1153,9 @@
/* Define to use internal time-zone code */
#undef USE_INTERNAL_MKTIME

/* Define to use libdefault rather than libz */
#undef USE_LIBDEFLATE

/* Define if the POSIX multithreading library can be used. (For intl) */
#undef USE_POSIX_THREADS

Expand Down
9 changes: 5 additions & 4 deletions src/library/base/R/connections.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,22 +323,23 @@ socketSelect <- function(socklist, write = FALSE, timeout = NULL) {
}

memCompress <-
function(from, type = c("gzip", "bzip2", "xz", "none"))
function(from, type = c("gzip", "bzip2", "xz", "libdeflate", "none"))
{
if(is.character(from))
from <- charToRaw(paste(from, collapse = "\n"))
else if(!is.raw(from)) stop("'from' must be raw or character")
type <- match(match.arg(type), c("none", "gzip", "bzip2", "xz"))
type <- match(match.arg(type), c("none", "gzip", "bzip2", "xz",
"libdeflate"))
.Internal(memCompress(from, type))
}

memDecompress <-
function(from,
type = c("unknown", "gzip", "bzip2", "xz", "none"),
type = c("unknown", "gzip", "bzip2", "xz", "libdeflate", "none"),
asChar = FALSE)
{
type <- match(match.arg(type),
c("none", "gzip", "bzip2", "xz", "unknown"))
c("none", "gzip", "bzip2", "xz", "unknown", "libdeflate"))
ans <- .Internal(memDecompress(from, type))
if(asChar) rawToChar(ans) else ans
}
Loading

0 comments on commit 02b8eb0

Please sign in to comment.