-
-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tino Reichardt <[email protected]>
- Loading branch information
Showing
31 changed files
with
942 additions
and
627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under both the BSD-style license (found in the | ||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found | ||
* in the COPYING file in the root directory of this source tree). | ||
* You may select, at your option, one of the above-listed licenses. | ||
*/ | ||
|
||
/* This file provides custom allocation primitives | ||
*/ | ||
|
||
#define ZSTD_DEPS_NEED_MALLOC | ||
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */ | ||
|
||
#include "mem.h" /* MEM_STATIC */ | ||
#define ZSTD_STATIC_LINKING_ONLY | ||
#include "zstd.h" /* ZSTD_customMem */ | ||
|
||
#ifndef ZSTD_ALLOCATIONS_H | ||
#define ZSTD_ALLOCATIONS_H | ||
|
||
/* custom memory allocation functions */ | ||
|
||
MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem) | ||
{ | ||
if (customMem.customAlloc) | ||
return customMem.customAlloc(customMem.opaque, size); | ||
return ZSTD_malloc(size); | ||
} | ||
|
||
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem) | ||
{ | ||
if (customMem.customAlloc) { | ||
/* calloc implemented as malloc+memset; | ||
* not as efficient as calloc, but next best guess for custom malloc */ | ||
void* const ptr = customMem.customAlloc(customMem.opaque, size); | ||
ZSTD_memset(ptr, 0, size); | ||
return ptr; | ||
} | ||
return ZSTD_calloc(1, size); | ||
} | ||
|
||
MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem) | ||
{ | ||
if (ptr!=NULL) { | ||
if (customMem.customFree) | ||
customMem.customFree(customMem.opaque, ptr); | ||
else | ||
ZSTD_free(ptr); | ||
} | ||
} | ||
|
||
#endif /* ZSTD_ALLOCATIONS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.