d0b38cbc3b
- Import zstd-1.3.6 from upstream - Add zstd's module.c file - Add the zstd module to Makefile.core.def Import zstd-1.3.6 from upstream [1]. Only the files need for decompression are imported. I used the latest zstd release, which includes patches [2] to build cleanly in GRUB. I included the script used to import zstd-1.3.6 below at the bottom of the commit message. Upstream zstd commit hash: 4fa456d7f12f8b27bd3b2f5dfd4f46898cb31c24 Upstream zstd commit name: Merge pull request #1354 from facebook/dev Zstd requires some posix headers, which it gets from posix_wrap. This can be checked by inspecting the .Po files generated by automake, which contain the header dependencies. After building run the command `cat grub-core/lib/zstd/.deps-core/*.Po` to see the dependencies [3]. The only OS dependencies are: - stddef.h, which is already a dependency in posix_wrap, and used for size_t by lzo and xz. - stdarg.h, which comes from the grub/misc.h header, and we don't use in zstd. All the types like uint64_t are typedefed to grub_uint64_t under the hood. The only exception is size_t, which comes from stddef.h. This is already the case for lzo and xz. I don't think there are any cross-compilation concerns, because cross-compilers provide their own system headers (and it would already be broken). [1] https://github.com/facebook/zstd/releases/tag/v1.3.6 [2] https://github.com/facebook/zstd/pull/1344 [3] https://gist.github.com/terrelln/7a16b92f5a1b3aecf980f944b4a966c4 ``` curl -L -O https://github.com/facebook/zstd/releases/download/v1.3.6/zstd-1.3.6.tar.gz curl -L -O https://github.com/facebook/zstd/releases/download/v1.3.6/zstd-1.3.6.tar.gz.sha256 sha256sum --check zstd-1.3.6.tar.gz.sha256 tar xzf zstd-1.3.6.tar.gz SRC_LIB="zstd-1.3.6/lib" DST_LIB="grub-core/lib/zstd" rm -rf $DST_LIB mkdir -p $DST_LIB cp $SRC_LIB/zstd.h $DST_LIB/ cp $SRC_LIB/common/*.[hc] $DST_LIB/ cp $SRC_LIB/decompress/*.[hc] $DST_LIB/ rm $DST_LIB/{pool.[hc],threading.[hc]} rm -rf zstd-1.3.6* echo SUCCESS! ``` Signed-off-by: Nick Terrell <terrelln@fb.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
123 lines
4.6 KiB
C
123 lines
4.6 KiB
C
/* ******************************************************************
|
|
debug
|
|
Part of FSE library
|
|
Copyright (C) 2013-present, Yann Collet.
|
|
|
|
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions are
|
|
met:
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
* Redistributions in binary form must reproduce the above
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
in the documentation and/or other materials provided with the
|
|
distribution.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
You can contact the author at :
|
|
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
****************************************************************** */
|
|
|
|
|
|
/*
|
|
* The purpose of this header is to enable debug functions.
|
|
* They regroup assert(), DEBUGLOG() and RAWLOG() for run-time,
|
|
* and DEBUG_STATIC_ASSERT() for compile-time.
|
|
*
|
|
* By default, DEBUGLEVEL==0, which means run-time debug is disabled.
|
|
*
|
|
* Level 1 enables assert() only.
|
|
* Starting level 2, traces can be generated and pushed to stderr.
|
|
* The higher the level, the more verbose the traces.
|
|
*
|
|
* It's possible to dynamically adjust level using variable g_debug_level,
|
|
* which is only declared if DEBUGLEVEL>=2,
|
|
* and is a global variable, not multi-thread protected (use with care)
|
|
*/
|
|
|
|
#ifndef DEBUG_H_12987983217
|
|
#define DEBUG_H_12987983217
|
|
|
|
#if defined (__cplusplus)
|
|
extern "C" {
|
|
#endif
|
|
|
|
|
|
/* static assert is triggered at compile time, leaving no runtime artefact,
|
|
* but can only work with compile-time constants.
|
|
* This variant can only be used inside a function. */
|
|
#define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
|
|
|
|
|
|
/* DEBUGLEVEL is expected to be defined externally,
|
|
* typically through compiler command line.
|
|
* Value must be a number. */
|
|
#ifndef DEBUGLEVEL
|
|
# define DEBUGLEVEL 0
|
|
#endif
|
|
|
|
/* recommended values for DEBUGLEVEL :
|
|
* 0 : no debug, all run-time functions disabled
|
|
* 1 : no display, enables assert() only
|
|
* 2 : reserved, for currently active debug path
|
|
* 3 : events once per object lifetime (CCtx, CDict, etc.)
|
|
* 4 : events once per frame
|
|
* 5 : events once per block
|
|
* 6 : events once per sequence (verbose)
|
|
* 7+: events at every position (*very* verbose)
|
|
*
|
|
* It's generally inconvenient to output traces > 5.
|
|
* In which case, it's possible to selectively enable higher verbosity levels
|
|
* by modifying g_debug_level.
|
|
*/
|
|
|
|
#if (DEBUGLEVEL>=1)
|
|
# include <assert.h>
|
|
#else
|
|
# ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
|
|
# define assert(condition) ((void)0) /* disable assert (default) */
|
|
# endif
|
|
#endif
|
|
|
|
#if (DEBUGLEVEL>=2)
|
|
# include <stdio.h>
|
|
extern int g_debuglevel; /* here, this variable is only declared,
|
|
it actually lives in debug.c,
|
|
and is shared by the whole process.
|
|
It's typically used to enable very verbose levels
|
|
on selective conditions (such as position in src) */
|
|
|
|
# define RAWLOG(l, ...) { \
|
|
if (l<=g_debuglevel) { \
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
} }
|
|
# define DEBUGLOG(l, ...) { \
|
|
if (l<=g_debuglevel) { \
|
|
fprintf(stderr, __FILE__ ": " __VA_ARGS__); \
|
|
fprintf(stderr, " \n"); \
|
|
} }
|
|
#else
|
|
# define RAWLOG(l, ...) {} /* disabled */
|
|
# define DEBUGLOG(l, ...) {} /* disabled */
|
|
#endif
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
}
|
|
#endif
|
|
|
|
#endif /* DEBUG_H_12987983217 */
|