Coverage Report

Created: 2025-08-26 06:15

/src/zstd/lib/common/allocations.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under both the BSD-style license (found in the
6
 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
 * in the COPYING file in the root directory of this source tree).
8
 * You may select, at your option, one of the above-listed licenses.
9
 */
10
11
/* This file provides custom allocation primitives
12
 */
13
14
#define ZSTD_DEPS_NEED_MALLOC
15
#include "zstd_deps.h"   /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
16
17
#include "compiler.h" /* MEM_STATIC */
18
#define ZSTD_STATIC_LINKING_ONLY
19
#include "../zstd.h" /* ZSTD_customMem */
20
21
#ifndef ZSTD_ALLOCATIONS_H
22
#define ZSTD_ALLOCATIONS_H
23
24
/* custom memory allocation functions */
25
26
MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
27
1.29M
{
28
1.29M
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
1.29M
    return ZSTD_malloc(size);
31
1.29M
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customMalloc
Unexecuted instantiation: pool.c:ZSTD_customMalloc
zstd_compress.c:ZSTD_customMalloc
Line
Count
Source
27
778k
{
28
778k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
778k
    return ZSTD_malloc(size);
31
778k
}
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_double_fast.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_fast.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_lazy.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_ldm.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_opt.c:ZSTD_customMalloc
zstdmt_compress.c:ZSTD_customMalloc
Line
Count
Source
27
63.7k
{
28
63.7k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
63.7k
    return ZSTD_malloc(size);
31
63.7k
}
zstd_ddict.c:ZSTD_customMalloc
Line
Count
Source
27
143k
{
28
143k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
143k
    return ZSTD_malloc(size);
31
143k
}
zstd_decompress.c:ZSTD_customMalloc
Line
Count
Source
27
312k
{
28
312k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
312k
    return ZSTD_malloc(size);
31
312k
}
Unexecuted instantiation: fastcover.c:ZSTD_customMalloc
Unexecuted instantiation: zdict.c:ZSTD_customMalloc
32
33
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
34
204k
{
35
204k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset;
37
         * not as efficient as calloc, but next best guess for custom malloc */
38
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
39
0
        ZSTD_memset(ptr, 0, size);
40
0
        return ptr;
41
0
    }
42
204k
    return ZSTD_calloc(1, size);
43
204k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customCalloc
pool.c:ZSTD_customCalloc
Line
Count
Source
34
55.6k
{
35
55.6k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset;
37
         * not as efficient as calloc, but next best guess for custom malloc */
38
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
39
0
        ZSTD_memset(ptr, 0, size);
40
0
        return ptr;
41
0
    }
42
55.6k
    return ZSTD_calloc(1, size);
43
55.6k
}
Unexecuted instantiation: zstd_compress.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_double_fast.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_fast.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_lazy.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_ldm.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_opt.c:ZSTD_customCalloc
zstdmt_compress.c:ZSTD_customCalloc
Line
Count
Source
34
149k
{
35
149k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset;
37
         * not as efficient as calloc, but next best guess for custom malloc */
38
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
39
0
        ZSTD_memset(ptr, 0, size);
40
0
        return ptr;
41
0
    }
42
149k
    return ZSTD_calloc(1, size);
43
149k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_decompress.c:ZSTD_customCalloc
Unexecuted instantiation: fastcover.c:ZSTD_customCalloc
Unexecuted instantiation: zdict.c:ZSTD_customCalloc
44
45
MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
46
2.89M
{
47
2.89M
    if (ptr!=NULL) {
48
1.50M
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
1.50M
        else
51
1.50M
            ZSTD_free(ptr);
52
1.50M
    }
53
2.89M
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customFree
pool.c:ZSTD_customFree
Line
Count
Source
46
55.6k
{
47
55.6k
    if (ptr!=NULL) {
48
55.6k
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
55.6k
        else
51
55.6k
            ZSTD_free(ptr);
52
55.6k
    }
53
55.6k
}
zstd_compress.c:ZSTD_customFree
Line
Count
Source
46
1.71M
{
47
1.71M
    if (ptr!=NULL) {
48
778k
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
778k
        else
51
778k
            ZSTD_free(ptr);
52
778k
    }
53
1.71M
}
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_customFree
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_customFree
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_customFree
Unexecuted instantiation: zstd_double_fast.c:ZSTD_customFree
Unexecuted instantiation: zstd_fast.c:ZSTD_customFree
Unexecuted instantiation: zstd_lazy.c:ZSTD_customFree
Unexecuted instantiation: zstd_ldm.c:ZSTD_customFree
Unexecuted instantiation: zstd_opt.c:ZSTD_customFree
zstdmt_compress.c:ZSTD_customFree
Line
Count
Source
46
356k
{
47
356k
    if (ptr!=NULL) {
48
212k
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
212k
        else
51
212k
            ZSTD_free(ptr);
52
212k
    }
53
356k
}
zstd_ddict.c:ZSTD_customFree
Line
Count
Source
46
180k
{
47
180k
    if (ptr!=NULL) {
48
143k
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
143k
        else
51
143k
            ZSTD_free(ptr);
52
143k
    }
53
180k
}
zstd_decompress.c:ZSTD_customFree
Line
Count
Source
46
584k
{
47
584k
    if (ptr!=NULL) {
48
312k
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
312k
        else
51
312k
            ZSTD_free(ptr);
52
312k
    }
53
584k
}
Unexecuted instantiation: fastcover.c:ZSTD_customFree
Unexecuted instantiation: zdict.c:ZSTD_customFree
54
55
#endif /* ZSTD_ALLOCATIONS_H */