Sha256: 6a718e8edaca112abdc0bdfa7de67edefaa44c8d9e514b79672ab58ab3a9118a

Contents?: true

Size: 1.6 KB

Versions: 44

Compression:

Stored size: 1.6 KB

Contents

/*
 * 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 "compiler.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 */

Version data entries

44 entries across 44 versions & 3 rubygems

Version Path
wasmtime-30.0.2 ./ext/cargo-vendor/zstd-sys-2.0.14+zstd.1.5.7/zstd/lib/common/allocations.h
zstdlib-0.15.0-x86-mingw32 ext/zstdlib_c/zstd-1.5.7/lib/common/allocations.h
zstdlib-0.15.0-x86-linux ext/zstdlib_c/zstd-1.5.7/lib/common/allocations.h
zstdlib-0.15.0-x86_64-linux ext/zstdlib_c/zstd-1.5.7/lib/common/allocations.h
zstdlib-0.15.0-x86_64-darwin ext/zstdlib_c/zstd-1.5.7/lib/common/allocations.h
zstdlib-0.15.0-x64-mingw-ucrt ext/zstdlib_c/zstd-1.5.7/lib/common/allocations.h
zstdlib-0.15.0-x64-mingw32 ext/zstdlib_c/zstd-1.5.7/lib/common/allocations.h
zstdlib-0.15.0 ext/zstdlib_c/zstd-1.5.7/lib/common/allocations.h
zstdlib-0.15.0-arm64-darwin ext/zstdlib_c/zstd-1.5.7/lib/common/allocations.h
wasmtime-29.0.0 ./ext/cargo-vendor/zstd-sys-2.0.13+zstd.1.5.6/zstd/lib/common/allocations.h
wasmtime-28.0.0 ./ext/cargo-vendor/zstd-sys-2.0.13+zstd.1.5.6/zstd/lib/common/allocations.h
zstdlib-0.14.0-x86-mingw32 ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h
zstdlib-0.14.0-x86-linux ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h
zstdlib-0.14.0-x86_64-linux ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h
zstdlib-0.14.0-x86_64-darwin ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h
zstdlib-0.14.0-x64-mingw-ucrt ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h
zstdlib-0.14.0-x64-mingw32 ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h
zstdlib-0.14.0 ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h
zstdlib-0.14.0-arm64-darwin ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h
zstdlib-0.13.0-x86-mingw32 ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h