grouped debug functions into debug.h
There were 2 competing set of debug functions within zstd_internal.h and bitstream.h. They were mostly duplicate, and required care to avoid messing with each other. There is now a single implementation, shared by both. Significant change : The macro variable ZSTD_DEBUG does no longer exist, it has been replaced by DEBUGLEVEL, which required modifying several source files.
This commit is contained in:
parent
c986dbf241
commit
fa41bcc2c2
2
Makefile
2
Makefile
@ -64,7 +64,7 @@ zlibwrapper:
|
|||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
$(MAKE) -C $(PRGDIR) allVariants MOREFLAGS+="-g -DZSTD_DEBUG=1"
|
$(MAKE) -C $(PRGDIR) allVariants MOREFLAGS+="-g -DDEBUGLEVEL=1"
|
||||||
$(MAKE) -C $(TESTDIR) $@
|
$(MAKE) -C $(TESTDIR) $@
|
||||||
|
|
||||||
.PHONY: shortest
|
.PHONY: shortest
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
bitstream
|
bitstream
|
||||||
Part of FSE library
|
Part of FSE library
|
||||||
header file (to include)
|
Copyright (C) 2013-present, Yann Collet.
|
||||||
Copyright (C) 2013-2017, Yann Collet.
|
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
@ -49,45 +48,10 @@ extern "C" {
|
|||||||
* Dependencies
|
* Dependencies
|
||||||
******************************************/
|
******************************************/
|
||||||
#include "mem.h" /* unaligned access routines */
|
#include "mem.h" /* unaligned access routines */
|
||||||
|
#include "debug.h" /* assert(), DEBUGLOG(), RAWLOG() */
|
||||||
#include "error_private.h" /* error codes and messages */
|
#include "error_private.h" /* error codes and messages */
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
|
||||||
* Debug
|
|
||||||
***************************************/
|
|
||||||
#if defined(BIT_DEBUG) && (BIT_DEBUG>=1)
|
|
||||||
# include <assert.h>
|
|
||||||
#else
|
|
||||||
# ifndef assert
|
|
||||||
# define assert(condition) ((void)0)
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(BIT_DEBUG) && (BIT_DEBUG>=2)
|
|
||||||
# include <stdio.h>
|
|
||||||
extern int g_debuglog_enable;
|
|
||||||
/* recommended values for BIT_DEBUG display levels :
|
|
||||||
* 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 (*very* verbose) */
|
|
||||||
# define RAWLOG(l, ...) { \
|
|
||||||
if ((g_debuglog_enable) & (l<=BIT_DEBUG)) { \
|
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
|
||||||
} }
|
|
||||||
# define DEBUGLOG(l, ...) { \
|
|
||||||
if ((g_debuglog_enable) & (l<=BIT_DEBUG)) { \
|
|
||||||
fprintf(stderr, __FILE__ ": " __VA_ARGS__); \
|
|
||||||
fprintf(stderr, " \n"); \
|
|
||||||
} }
|
|
||||||
#else
|
|
||||||
# define RAWLOG(l, ...) {} /* disabled */
|
|
||||||
# define DEBUGLOG(l, ...) {} /* disabled */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*=========================================
|
/*=========================================
|
||||||
* Target specific
|
* Target specific
|
||||||
=========================================*/
|
=========================================*/
|
||||||
@ -107,8 +71,7 @@ extern int g_debuglog_enable;
|
|||||||
* A critical property of these streams is that they encode and decode in **reverse** direction.
|
* A critical property of these streams is that they encode and decode in **reverse** direction.
|
||||||
* So the first bit sequence you add will be the last to be read, like a LIFO stack.
|
* So the first bit sequence you add will be the last to be read, like a LIFO stack.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
size_t bitContainer;
|
size_t bitContainer;
|
||||||
unsigned bitPos;
|
unsigned bitPos;
|
||||||
char* startPtr;
|
char* startPtr;
|
||||||
@ -142,8 +105,7 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC);
|
|||||||
/*-********************************************
|
/*-********************************************
|
||||||
* bitStream decoding API (read backward)
|
* bitStream decoding API (read backward)
|
||||||
**********************************************/
|
**********************************************/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
size_t bitContainer;
|
size_t bitContainer;
|
||||||
unsigned bitsConsumed;
|
unsigned bitsConsumed;
|
||||||
const char* ptr;
|
const char* ptr;
|
||||||
@ -260,7 +222,8 @@ MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! BIT_addBitsFast() :
|
/*! BIT_addBitsFast() :
|
||||||
* works only if `value` is _clean_, meaning all high bits above nbBits are 0 */
|
* works only if `value` is _clean_,
|
||||||
|
* meaning all high bits above nbBits are 0 */
|
||||||
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC,
|
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC,
|
||||||
size_t value, unsigned nbBits)
|
size_t value, unsigned nbBits)
|
||||||
{
|
{
|
||||||
|
44
lib/common/debug.c
Normal file
44
lib/common/debug.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/* ******************************************************************
|
||||||
|
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
|
||||||
|
****************************************************************** */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This module only hosts one global variable
|
||||||
|
* which can be used to dynamically influence the verbosity of traces,
|
||||||
|
* such as DEBUGLOG and RAWLOG
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
int g_debuglevel = DEBUGLEVEL;
|
121
lib/common/debug.h
Normal file
121
lib/common/debug.h
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/* ******************************************************************
|
||||||
|
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().
|
||||||
|
*
|
||||||
|
* By default, DEBUGLEVEL==0, which means 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 */
|
||||||
|
#define DEBUG_STATIC_ASSERT(c) { enum { DEBUG_static_assert = 1/(int)(!!(c)) }; }
|
||||||
|
|
||||||
|
|
||||||
|
/* 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 functions disabled (except DEBUG_STATIC_ASSERT)
|
||||||
|
* 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_debug_level; /* 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_debug_level) { \
|
||||||
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
|
} }
|
||||||
|
# define DEBUGLOG(l, ...) { \
|
||||||
|
if (l<=g_debug_level) { \
|
||||||
|
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 */
|
@ -49,7 +49,7 @@
|
|||||||
* Error Management
|
* Error Management
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
#define FSE_isError ERR_isError
|
#define FSE_isError ERR_isError
|
||||||
#define FSE_STATIC_ASSERT(c) { enum { FSE_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
|
#define FSE_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */
|
||||||
|
|
||||||
/* check and forward error code */
|
/* check and forward error code */
|
||||||
#define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; }
|
#define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; }
|
||||||
|
@ -46,11 +46,6 @@ ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
|
|||||||
* provides error code string from enum */
|
* provides error code string from enum */
|
||||||
const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
|
const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
|
||||||
|
|
||||||
/*! g_debuglog_enable :
|
|
||||||
* turn on/off debug traces (global switch) */
|
|
||||||
#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG >= 2)
|
|
||||||
int g_debuglevel = ZSTD_DEBUG;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*=**************************************************************
|
/*=**************************************************************
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
***************************************/
|
***************************************/
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
#include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
|
||||||
#include "error_private.h"
|
#include "error_private.h"
|
||||||
#define ZSTD_STATIC_LINKING_ONLY
|
#define ZSTD_STATIC_LINKING_ONLY
|
||||||
#include "zstd.h"
|
#include "zstd.h"
|
||||||
@ -38,45 +39,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* ---- static assert (debug) --- */
|
||||||
/*-*************************************
|
#define ZSTD_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c)
|
||||||
* Debug
|
|
||||||
***************************************/
|
|
||||||
#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=1)
|
|
||||||
# include <assert.h>
|
|
||||||
#else
|
|
||||||
# ifndef assert
|
|
||||||
# define assert(condition) ((void)0)
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ZSTD_STATIC_ASSERT(c) { enum { ZSTD_static_assert = 1/(int)(!!(c)) }; }
|
|
||||||
|
|
||||||
#undef RAWLOG
|
|
||||||
#undef DEBUGLOG
|
|
||||||
#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=2)
|
|
||||||
# include <stdio.h>
|
|
||||||
extern int g_debuglevel;
|
|
||||||
/* recommended values for ZSTD_DEBUG display levels :
|
|
||||||
* 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 (*very* verbose) */
|
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
* Error Management
|
* Error Management
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
#define FSE_isError ERR_isError
|
#define FSE_isError ERR_isError
|
||||||
#define FSE_STATIC_ASSERT(c) { enum { FSE_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
|
#define FSE_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */
|
||||||
|
|
||||||
|
|
||||||
/* **************************************************************
|
/* **************************************************************
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
* Error Management
|
* Error Management
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
#define HUF_isError ERR_isError
|
#define HUF_isError ERR_isError
|
||||||
#define HUF_STATIC_ASSERT(c) { enum { HUF_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
|
#define HUF_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */
|
||||||
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
|
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
|
||||||
#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
|
#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ MEM_STATIC U32 ZSTD_MLcode(U32 mlBase)
|
|||||||
*/
|
*/
|
||||||
MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const void* literals, U32 offsetCode, size_t mlBase)
|
MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const void* literals, U32 offsetCode, size_t mlBase)
|
||||||
{
|
{
|
||||||
#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG >= 6)
|
#if defined(DEBUGLEVEL) && (DEBUGLEVEL >= 6)
|
||||||
static const BYTE* g_start = NULL;
|
static const BYTE* g_start = NULL;
|
||||||
if (g_start==NULL) g_start = (const BYTE*)literals; /* note : index only works for compression within a single segment */
|
if (g_start==NULL) g_start = (const BYTE*)literals; /* note : index only works for compression within a single segment */
|
||||||
{ U32 const pos = (U32)((const BYTE*)literals - g_start);
|
{ U32 const pos = (U32)((const BYTE*)literals - g_start);
|
||||||
|
@ -37,18 +37,17 @@
|
|||||||
#define ZSTD_RESIZE_SEQPOOL 0
|
#define ZSTD_RESIZE_SEQPOOL 0
|
||||||
|
|
||||||
/* ====== Debug ====== */
|
/* ====== Debug ====== */
|
||||||
#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=2)
|
#if defined(DEBUGLEVEL) && (DEBUGLEVEL>=2)
|
||||||
|
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <sys/times.h>
|
# include <sys/times.h>
|
||||||
# define DEBUGLOGRAW(l, ...) if (l<=ZSTD_DEBUG) { fprintf(stderr, __VA_ARGS__); }
|
|
||||||
|
|
||||||
# define DEBUG_PRINTHEX(l,p,n) { \
|
# define DEBUG_PRINTHEX(l,p,n) { \
|
||||||
unsigned debug_u; \
|
unsigned debug_u; \
|
||||||
for (debug_u=0; debug_u<(n); debug_u++) \
|
for (debug_u=0; debug_u<(n); debug_u++) \
|
||||||
DEBUGLOGRAW(l, "%02X ", ((const unsigned char*)(p))[debug_u]); \
|
RAWLOG(l, "%02X ", ((const unsigned char*)(p))[debug_u]); \
|
||||||
DEBUGLOGRAW(l, " \n"); \
|
RAWLOG(l, " \n"); \
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long long GetCurrentClockTimeMicroseconds(void)
|
static unsigned long long GetCurrentClockTimeMicroseconds(void)
|
||||||
@ -62,7 +61,7 @@ static unsigned long long GetCurrentClockTimeMicroseconds(void)
|
|||||||
|
|
||||||
#define MUTEX_WAIT_TIME_DLEVEL 6
|
#define MUTEX_WAIT_TIME_DLEVEL 6
|
||||||
#define ZSTD_PTHREAD_MUTEX_LOCK(mutex) { \
|
#define ZSTD_PTHREAD_MUTEX_LOCK(mutex) { \
|
||||||
if (ZSTD_DEBUG >= MUTEX_WAIT_TIME_DLEVEL) { \
|
if (DEBUGLEVEL >= MUTEX_WAIT_TIME_DLEVEL) { \
|
||||||
unsigned long long const beforeTime = GetCurrentClockTimeMicroseconds(); \
|
unsigned long long const beforeTime = GetCurrentClockTimeMicroseconds(); \
|
||||||
ZSTD_pthread_mutex_lock(mutex); \
|
ZSTD_pthread_mutex_lock(mutex); \
|
||||||
{ unsigned long long const afterTime = GetCurrentClockTimeMicroseconds(); \
|
{ unsigned long long const afterTime = GetCurrentClockTimeMicroseconds(); \
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
* Error Management
|
* Error Management
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
#define HUF_isError ERR_isError
|
#define HUF_isError ERR_isError
|
||||||
#define HUF_STATIC_ASSERT(c) { enum { HUF_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
|
#define HUF_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */
|
||||||
#define CHECK_F(f) { size_t const err_ = (f); if (HUF_isError(err_)) return err_; }
|
#define CHECK_F(f) { size_t const err_ = (f); if (HUF_isError(err_)) return err_; }
|
||||||
|
|
||||||
|
|
||||||
|
@ -1089,8 +1089,8 @@ size_t ZDICT_trainFromBuffer(void* dictBuffer, size_t dictBufferCapacity,
|
|||||||
params.steps = 4;
|
params.steps = 4;
|
||||||
/* Default to level 6 since no compression level information is available */
|
/* Default to level 6 since no compression level information is available */
|
||||||
params.zParams.compressionLevel = 6;
|
params.zParams.compressionLevel = 6;
|
||||||
#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=1)
|
#if defined(DEBUGLEVEL) && (DEBUGLEVEL>=1)
|
||||||
params.zParams.notificationLevel = ZSTD_DEBUG;
|
params.zParams.notificationLevel = DEBUGLEVEL;
|
||||||
#endif
|
#endif
|
||||||
return ZDICT_optimizeTrainFromBuffer_cover(dictBuffer, dictBufferCapacity,
|
return ZDICT_optimizeTrainFromBuffer_cover(dictBuffer, dictBufferCapacity,
|
||||||
samplesBuffer, samplesSizes, nbSamples,
|
samplesBuffer, samplesSizes, nbSamples,
|
||||||
|
@ -74,38 +74,9 @@ extern "C" {
|
|||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Debug
|
* Debug
|
||||||
***************************************/
|
***************************************/
|
||||||
#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=1)
|
#include "debug.h"
|
||||||
# include <assert.h>
|
#ifndef assert
|
||||||
#else
|
# define assert(condition) ((void)0)
|
||||||
# ifndef assert
|
|
||||||
# define assert(condition) ((void)0)
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ZSTD_STATIC_ASSERT(c) { enum { ZSTD_static_assert = 1/(int)(!!(c)) }; }
|
|
||||||
|
|
||||||
#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=2)
|
|
||||||
# include <stdio.h>
|
|
||||||
extern int g_debuglevel;
|
|
||||||
/* recommended values for ZSTD_DEBUG display levels :
|
|
||||||
* 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 (*very* verbose) */
|
|
||||||
# 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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ PYTHON ?= python3
|
|||||||
TESTARTEFACT := versionsTest
|
TESTARTEFACT := versionsTest
|
||||||
|
|
||||||
DEBUGLEVEL ?= 1
|
DEBUGLEVEL ?= 1
|
||||||
DEBUGFLAGS = -g -DZSTD_DEBUG=$(DEBUGLEVEL) -DBIT_DEBUG=$(DEBUGLEVEL)
|
DEBUGFLAGS = -g -DDEBUGLEVEL=$(DEBUGLEVEL)
|
||||||
CPPFLAGS += -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
|
CPPFLAGS += -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
|
||||||
-I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR)
|
-I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR)
|
||||||
CFLAGS ?= -O3
|
CFLAGS ?= -O3
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
* the data to zstd functions. Every fuzzer initializes the RNG exactly
|
* the data to zstd functions. Every fuzzer initializes the RNG exactly
|
||||||
* once before doing anything else, even if it is unused.
|
* once before doing anything else, even if it is unused.
|
||||||
* Default: 4.
|
* Default: 4.
|
||||||
* @param ZSTD_DEBUG:
|
* @param DEBUGLEVEL:
|
||||||
* This is a parameter for the zstd library. Defining `ZSTD_DEBUG=1`
|
* This is a parameter for the zstd library. Defining `DEBUGLEVEL=1`
|
||||||
* enables assert() statements in the zstd library. Higher levels enable
|
* enables assert() statements in the zstd library. Higher levels enable
|
||||||
* logging, so aren't recommended. Defining `ZSTD_DEBUG=1` is
|
* logging, so aren't recommended. Defining `DEBUGLEVEL=1` is
|
||||||
* recommended.
|
* recommended.
|
||||||
* @param MEM_FORCE_MEMORY_ACCESS:
|
* @param MEM_FORCE_MEMORY_ACCESS:
|
||||||
* This flag controls how the zstd library accesses unaligned memory.
|
* This flag controls how the zstd library accesses unaligned memory.
|
||||||
|
@ -251,7 +251,7 @@ def build_parser(args):
|
|||||||
dest='debug',
|
dest='debug',
|
||||||
type=int,
|
type=int,
|
||||||
default=1,
|
default=1,
|
||||||
help='Set ZSTD_DEBUG and BIT_DEBUG (default: 1)')
|
help='Set DEBUGLEVEL (default: 1)')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--force-memory-access',
|
'--force-memory-access',
|
||||||
dest='memory_access',
|
dest='memory_access',
|
||||||
@ -358,8 +358,7 @@ def build(args):
|
|||||||
common_flags = []
|
common_flags = []
|
||||||
|
|
||||||
cppflags += [
|
cppflags += [
|
||||||
'-DZSTD_DEBUG={}'.format(args.debug),
|
'-DDEBUGLEVEL={}'.format(args.debug),
|
||||||
'-DBIT_DEBUG={}'.format(args.debug),
|
|
||||||
'-DMEM_FORCE_MEMORY_ACCESS={}'.format(args.memory_access),
|
'-DMEM_FORCE_MEMORY_ACCESS={}'.format(args.memory_access),
|
||||||
'-DFUZZ_RNG_SEED_SIZE={}'.format(args.fuzz_rng_seed_size),
|
'-DFUZZ_RNG_SEED_SIZE={}'.format(args.fuzz_rng_seed_size),
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user