diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2023-05-22 14:32:14 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-05-22 14:32:14 +0200 |
| commit | 6100b4bd33ab27d78f0f5087c770e42b25100eb9 (patch) | |
| tree | 343157a10df7e3778e1e69725f88325c9b2b7340 /thirdparty/zstd/common/allocations.h | |
| parent | 65fa775ff645e9ba1cb7fdc9cd8cb439bbbaae1a (diff) | |
| download | redot-engine-6100b4bd33ab27d78f0f5087c770e42b25100eb9.tar.gz | |
zstd: Update to upstream version 1.5.5
Release notes:
- https://github.com/facebook/zstd/releases/tag/v1.5.3
- https://github.com/facebook/zstd/releases/tag/v1.5.4
- https://github.com/facebook/zstd/releases/tag/v1.5.5
Diffstat (limited to 'thirdparty/zstd/common/allocations.h')
| -rw-r--r-- | thirdparty/zstd/common/allocations.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/thirdparty/zstd/common/allocations.h b/thirdparty/zstd/common/allocations.h new file mode 100644 index 0000000000..a3153c4bac --- /dev/null +++ b/thirdparty/zstd/common/allocations.h @@ -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 */ |
