Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107144428
D10407.id27471.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
18 KB
Referenced Files
None
Subscribers
None
D10407.id27471.diff
View Options
Index: contrib/zstd/lib/Makefile
===================================================================
--- contrib/zstd/lib/Makefile
+++ contrib/zstd/lib/Makefile
@@ -43,6 +43,10 @@
ZSTD_OBJ := $(patsubst %.c,%.o,$(ZSTD_FILES))
+ifeq ($(ZSTD_HEAPMODE), 1)
+CFLAGS += -DZSTD_HEAPMODE=1
+endif
+
# OS X linker doesn't support -soname, and use different extension
# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
ifeq ($(shell uname), Darwin)
Index: contrib/zstd/lib/common/error_private.h
===================================================================
--- contrib/zstd/lib/common/error_private.h
+++ contrib/zstd/lib/common/error_private.h
@@ -20,7 +20,11 @@
/* ****************************************
* Dependencies
******************************************/
+#ifdef _KERNEL
+#include <sys/types.h> /* size_t */
+#else
#include <stddef.h> /* size_t */
+#endif
#include "zstd_errors.h" /* enum list */
Index: contrib/zstd/lib/common/fse.h
===================================================================
--- contrib/zstd/lib/common/fse.h
+++ contrib/zstd/lib/common/fse.h
@@ -42,7 +42,11 @@
/*-*****************************************
* Dependencies
******************************************/
+#ifdef _KERNEL
+#include <sys/param.h> /* size_t, ptrdiff_t */
+#else
#include <stddef.h> /* size_t, ptrdiff_t */
+#endif
/*-*****************************************
Index: contrib/zstd/lib/common/fse_decompress.c
===================================================================
--- contrib/zstd/lib/common/fse_decompress.c
+++ contrib/zstd/lib/common/fse_decompress.c
@@ -57,12 +57,20 @@
/* **************************************************************
* Includes
****************************************************************/
+#ifdef _KERNEL
+#include <sys/systm.h> /* memset */
+#else
#include <stdlib.h> /* malloc, free, qsort */
#include <string.h> /* memcpy, memset */
+#endif
#include "bitstream.h"
#define FSE_STATIC_LINKING_ONLY
#include "fse.h"
+#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE==1)
+#include "zstd_internal.h" /* defaultCustomMem */
+static ZSTD_customMem customMalloc = { ZSTD_defaultAllocFunction, ZSTD_defaultFreeFunction, NULL };
+#endif
/* **************************************************************
* Error Management
@@ -71,7 +79,7 @@
#define FSE_STATIC_ASSERT(c) { enum { FSE_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
/* check and forward error code */
-#define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; }
+#define CHECK_FSE_F(f) { size_t const e = f; if (FSE_isError(e)) return e; }
/* **************************************************************
@@ -98,6 +106,18 @@
/* Function templates */
+#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE==1)
+FSE_DTable* FSE_createDTable (unsigned tableLog)
+{
+ if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
+ return (FSE_DTable*)ZSTD_malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32), customMalloc );
+}
+
+void FSE_freeDTable (FSE_DTable* dt)
+{
+ ZSTD_free(dt, customMalloc);
+}
+#else
FSE_DTable* FSE_createDTable (unsigned tableLog)
{
if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
@@ -108,6 +128,7 @@
{
free(dt);
}
+#endif
size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
{
@@ -231,7 +252,7 @@
FSE_DState_t state2;
/* Init */
- CHECK_F(BIT_initDStream(&bitD, cSrc, cSrcSize));
+ CHECK_FSE_F(BIT_initDStream(&bitD, cSrc, cSrcSize));
FSE_initDState(&state1, &bitD, dt);
FSE_initDState(&state2, &bitD, dt);
@@ -309,7 +330,7 @@
ip += NCountLength;
cSrcSize -= NCountLength;
- CHECK_F( FSE_buildDTable (workSpace, counting, maxSymbolValue, tableLog) );
+ CHECK_FSE_F( FSE_buildDTable (workSpace, counting, maxSymbolValue, tableLog) );
return FSE_decompress_usingDTable (dst, dstCapacity, ip, cSrcSize, workSpace); /* always return, even if it is an error code */
}
Index: contrib/zstd/lib/common/huf.h
===================================================================
--- contrib/zstd/lib/common/huf.h
+++ contrib/zstd/lib/common/huf.h
@@ -40,7 +40,11 @@
/* *** Dependencies *** */
+#ifdef _KERNEL
+#include <sys/types.h> /* size_t */
+#else
#include <stddef.h> /* size_t */
+#endif
/* *** simple functions *** */
Index: contrib/zstd/lib/common/mem.h
===================================================================
--- contrib/zstd/lib/common/mem.h
+++ contrib/zstd/lib/common/mem.h
@@ -17,8 +17,13 @@
/*-****************************************
* Dependencies
******************************************/
+#ifdef _KERNEL
+#include <sys/types.h> /* size_t */
+#include <sys/systm.h> /* memcpy */
+#else
#include <stddef.h> /* size_t, ptrdiff_t */
#include <string.h> /* memcpy */
+#endif
/*-****************************************
@@ -47,7 +52,9 @@
* Basic Types
*****************************************************************/
#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
+#ifndef _KERNEL
# include <stdint.h>
+#endif
typedef uint8_t BYTE;
typedef uint16_t U16;
typedef int16_t S16;
Index: contrib/zstd/lib/common/pool.h
===================================================================
--- contrib/zstd/lib/common/pool.h
+++ contrib/zstd/lib/common/pool.h
@@ -14,7 +14,11 @@
#endif
+#ifdef _KERNEL
+#include <sys/types.h>
+#else
#include <stddef.h> /* size_t */
+#endif
typedef struct POOL_ctx_s POOL_ctx;
Index: contrib/zstd/lib/common/pool.c
===================================================================
--- contrib/zstd/lib/common/pool.c
+++ contrib/zstd/lib/common/pool.c
@@ -9,8 +9,13 @@
/* ====== Dependencies ======= */
+#ifdef _KERNEL
+#include <sys/types.h>
+#include <sys/systm.h>
+#else
#include <stddef.h> /* size_t */
#include <stdlib.h> /* malloc, calloc, free */
+#endif
#include "pool.h"
/* ====== Compiler specifics ====== */
Index: contrib/zstd/lib/common/xxhash.h
===================================================================
--- contrib/zstd/lib/common/xxhash.h
+++ contrib/zstd/lib/common/xxhash.h
@@ -75,7 +75,11 @@
/* ****************************
* Definitions
******************************/
+#ifdef _KERNEL
+#include <sys/types.h> /* size_t */
+#else
#include <stddef.h> /* size_t */
+#endif
typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
Index: contrib/zstd/lib/common/xxhash.c
===================================================================
--- contrib/zstd/lib/common/xxhash.c
+++ contrib/zstd/lib/common/xxhash.c
@@ -97,11 +97,23 @@
***************************************/
/* Modify the local functions below should you wish to use some other memory routines */
/* for malloc(), free() */
+#ifdef _KERNEL
+#include <sys/types.h>
+extern void *zstd_alloc(void *opaque, size_t size);
+extern void zstd_free(void *opaque, void *ptr);
+static void* XXH_malloc(size_t s) { return zstd_alloc("xxh", s); }
+static void XXH_free (void* p) { zstd_free("xxh", p); }
+#else
#include <stdlib.h>
static void* XXH_malloc(size_t s) { return malloc(s); }
static void XXH_free (void* p) { free(p); }
+#endif
/* for memcpy() */
+#ifdef _KERNEL
+#include <sys/systm.h>
+#else
#include <string.h>
+#endif
static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
#ifndef XXH_STATIC_LINKING_ONLY
@@ -135,7 +147,9 @@
#ifndef MEM_MODULE
# define MEM_MODULE
# if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
+#ifndef _KERNEL
# include <stdint.h>
+#endif
typedef uint8_t BYTE;
typedef uint16_t U16;
typedef uint32_t U32;
Index: contrib/zstd/lib/common/zstd_common.c
===================================================================
--- contrib/zstd/lib/common/zstd_common.c
+++ contrib/zstd/lib/common/zstd_common.c
@@ -12,7 +12,9 @@
/*-*************************************
* Dependencies
***************************************/
+#ifndef _KERNEL
#include <stdlib.h> /* malloc */
+#endif
#include "error_private.h"
#define ZSTD_STATIC_LINKING_ONLY
#include "zstd.h" /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
@@ -50,15 +52,23 @@
/* default uses stdlib */
void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
{
+#ifdef _KERNEL
+ void* address = zstd_alloc(opaque, size);
+#else
void* address = malloc(size);
(void)opaque;
+#endif
return address;
}
void ZSTD_defaultFreeFunction(void* opaque, void* address)
{
+#ifdef _KERNEL
+ zstd_free(opaque, address);
+#else
(void)opaque;
free(address);
+#endif
}
void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
Index: contrib/zstd/lib/common/zstd_errors.h
===================================================================
--- contrib/zstd/lib/common/zstd_errors.h
+++ contrib/zstd/lib/common/zstd_errors.h
@@ -15,7 +15,11 @@
#endif
/*===== dependency =====*/
+#ifdef _KERNEL
+#include <sys/types.h> /* size_t */
+#else
#include <stddef.h> /* size_t */
+#endif
/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
Index: contrib/zstd/lib/common/zstd_internal.h
===================================================================
--- contrib/zstd/lib/common/zstd_internal.h
+++ contrib/zstd/lib/common/zstd_internal.h
@@ -58,8 +58,10 @@
/*-*************************************
* shared macros
***************************************/
+#ifndef MIN
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define MAX(a,b) ((a)>(b) ? (a) : (b))
+#endif
#define CHECK_F(f) { size_t const errcod = f; if (ERR_isError(errcod)) return errcod; } /* check and Forward error code */
#define CHECK_E(f, e) { size_t const errcod = f; if (ERR_isError(errcod)) return ERROR(e); } /* check and send Error code */
Index: contrib/zstd/lib/compress/fse_compress.c
===================================================================
--- contrib/zstd/lib/compress/fse_compress.c
+++ contrib/zstd/lib/compress/fse_compress.c
@@ -56,13 +56,21 @@
/* **************************************************************
* Includes
****************************************************************/
+#ifdef _KERNEL
+#include <sys/systm.h> /* memcpy, memset */
+#else
#include <stdlib.h> /* malloc, free, qsort */
#include <string.h> /* memcpy, memset */
#include <stdio.h> /* printf (debug) */
+#endif
#include "bitstream.h"
#define FSE_STATIC_LINKING_ONLY
#include "fse.h"
+#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE==1)
+#include "zstd_internal.h" /* defaultCustomMem */
+static ZSTD_customMem customMalloc = { ZSTD_defaultAllocFunction, ZSTD_defaultFreeFunction, NULL };
+#endif
/* **************************************************************
* Error Management
@@ -468,10 +476,18 @@
size_t size;
if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
size = FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32);
+#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE==1)
+ return (FSE_CTable*)ZSTD_malloc(size, customMalloc);
+#else
return (FSE_CTable*)malloc(size);
+#endif
}
+#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE==1)
+void FSE_freeCTable (FSE_CTable* ct) { ZSTD_free(ct, customMalloc); }
+#else
void FSE_freeCTable (FSE_CTable* ct) { free(ct); }
+#endif
/* provides the minimum logSize to safely represent a distribution */
static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
@@ -782,7 +798,7 @@
size_t FSE_compressBound(size_t size) { return FSE_COMPRESSBOUND(size); }
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return f
-#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
+#define CHECK_FSE_F(f) { CHECK_V_F(_var_err__, f); }
/* FSE_compress_wksp() :
* Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
@@ -815,7 +831,7 @@
}
tableLog = FSE_optimalTableLog(tableLog, srcSize, maxSymbolValue);
- CHECK_F( FSE_normalizeCount(norm, tableLog, count, srcSize, maxSymbolValue) );
+ CHECK_FSE_F( FSE_normalizeCount(norm, tableLog, count, srcSize, maxSymbolValue) );
/* Write table description header */
{ CHECK_V_F(nc_err, FSE_writeNCount(op, oend-op, norm, maxSymbolValue, tableLog) );
@@ -823,7 +839,7 @@
}
/* Compress */
- CHECK_F( FSE_buildCTable_wksp(CTable, norm, maxSymbolValue, tableLog, scratchBuffer, scratchBufferSize) );
+ CHECK_FSE_F( FSE_buildCTable_wksp(CTable, norm, maxSymbolValue, tableLog, scratchBuffer, scratchBufferSize) );
{ CHECK_V_F(cSize, FSE_compress_usingCTable(op, oend - op, src, srcSize, CTable) );
if (cSize == 0) return 0; /* not enough space for compressed data */
op += cSize;
Index: contrib/zstd/lib/compress/huf_compress.c
===================================================================
--- contrib/zstd/lib/compress/huf_compress.c
+++ contrib/zstd/lib/compress/huf_compress.c
@@ -43,21 +43,29 @@
/* **************************************************************
* Includes
****************************************************************/
+#ifdef _KERNEL
+#include <sys/systm.h> /* memcpy, memset */
+#else
#include <string.h> /* memcpy, memset */
#include <stdio.h> /* printf (debug) */
+#endif
#include "bitstream.h"
#define FSE_STATIC_LINKING_ONLY /* FSE_optimalTableLog_internal */
#include "fse.h" /* header compression */
#define HUF_STATIC_LINKING_ONLY
#include "huf.h"
+#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE==1)
+#include "zstd_internal.h" /* defaultCustomMem */
+static ZSTD_customMem customMalloc = { ZSTD_defaultAllocFunction, ZSTD_defaultFreeFunction, NULL };
+#endif
/* **************************************************************
* Error Management
****************************************************************/
#define HUF_STATIC_ASSERT(c) { enum { HUF_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return f
-#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
+#define CHECK_HUF_F(f) { CHECK_V_F(_var_err__, f); }
/* **************************************************************
@@ -103,7 +111,7 @@
}
tableLog = FSE_optimalTableLog(tableLog, wtSize, maxSymbolValue);
- CHECK_F( FSE_normalizeCount(norm, tableLog, count, wtSize, maxSymbolValue) );
+ CHECK_HUF_F( FSE_normalizeCount(norm, tableLog, count, wtSize, maxSymbolValue) );
/* Write table description header */
{ CHECK_V_F(hSize, FSE_writeNCount(op, oend-op, norm, maxSymbolValue, tableLog) );
@@ -111,7 +119,7 @@
}
/* Compress */
- CHECK_F( FSE_buildCTable_wksp(CTable, norm, maxSymbolValue, tableLog, scratchBuffer, sizeof(scratchBuffer)) );
+ CHECK_HUF_F( FSE_buildCTable_wksp(CTable, norm, maxSymbolValue, tableLog, scratchBuffer, sizeof(scratchBuffer)) );
{ CHECK_V_F(cSize, FSE_compress_usingCTable(op, oend - op, weightTable, wtSize, CTable) );
if (cSize == 0) return 0; /* not enough space for compressed data */
op += cSize;
Index: contrib/zstd/lib/compress/zstd_compress.c
===================================================================
--- contrib/zstd/lib/compress/zstd_compress.c
+++ contrib/zstd/lib/compress/zstd_compress.c
@@ -11,7 +11,11 @@
/*-*************************************
* Dependencies
***************************************/
+#ifdef _KERNEL
+#include <sys/systm.h> /* memcpy, memset */
+#else
#include <string.h> /* memset */
+#endif
#include "mem.h"
#define FSE_STATIC_LINKING_ONLY /* FSE_encodeSymbol */
#include "fse.h"
Index: contrib/zstd/lib/decompress/huf_decompress.c
===================================================================
--- contrib/zstd/lib/decompress/huf_decompress.c
+++ contrib/zstd/lib/decompress/huf_decompress.c
@@ -54,12 +54,20 @@
/* **************************************************************
* Dependencies
****************************************************************/
+#ifdef _KERNEL
+#include <sys/systm.h> /* memcpy, memset */
+#else
#include <string.h> /* memcpy, memset */
+#endif
#include "bitstream.h" /* BIT_* */
#include "fse.h" /* header compression */
#define HUF_STATIC_LINKING_ONLY
#include "huf.h"
+#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE==1)
+#include "zstd_internal.h" /* defaultCustomMem */
+static ZSTD_customMem customMalloc = { ZSTD_defaultAllocFunction, ZSTD_defaultFreeFunction, NULL };
+#endif
/* **************************************************************
* Error Management
Index: contrib/zstd/lib/decompress/zstd_decompress.c
===================================================================
--- contrib/zstd/lib/decompress/zstd_decompress.c
+++ contrib/zstd/lib/decompress/zstd_decompress.c
@@ -41,7 +41,11 @@
/*-*******************************************************
* Dependencies
*********************************************************/
+#ifdef _KERNEL
+#include <sys/systm.h> /* memcpy, memset */
+#else
#include <string.h> /* memcpy, memmove, memset */
+#endif
#include "mem.h" /* low level memory routines */
#define FSE_STATIC_LINKING_ONLY
#include "fse.h"
Index: contrib/zstd/lib/zstd.h
===================================================================
--- contrib/zstd/lib/zstd.h
+++ contrib/zstd/lib/zstd.h
@@ -15,7 +15,13 @@
#define ZSTD_H_235446
/* ====== Dependency ======*/
+#ifdef _KERNEL
+#include <sys/param.h> /* size_t */
+extern void *zstd_alloc(void *opaque, size_t size);
+extern void zstd_free(void *opaque, void *ptr);
+#else
#include <stddef.h> /* size_t */
+#endif
/* ===== ZSTDLIB_API : control library symbols visibility ===== */
Index: contrib/zstd/programs/Makefile
===================================================================
--- contrib/zstd/programs/Makefile
+++ contrib/zstd/programs/Makefile
@@ -55,6 +55,10 @@
ZSTDLIB_FILES := $(wildcard $(ZSTD_FILES)) $(wildcard $(ZSTDLEGACY_FILES)) $(wildcard $(ZDICT_FILES))
ZSTDLIB_OBJ := $(patsubst %.c,%.o,$(ZSTDLIB_FILES))
+ifeq ($(ZSTD_HEAPMODE), 1)
+CFLAGS += -DZSTD_HEAPMODE=1
+endif
+
# Define *.exe as extension for Windows systems
ifneq (,$(filter Windows%,$(OS)))
EXT =.exe
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 11, 7:34 PM (12 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15757157
Default Alt Text
D10407.id27471.diff (18 KB)
Attached To
Mode
D10407: Modify zstd so it can be built into the kernel as well
Attached
Detach File
Event Timeline
Log In to Comment