/src/c-blosc/internal-complibs/zstd-1.5.5/common/error_private.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 | | /* Note : this module is expected to remain private, do not expose it */ |
12 | | |
13 | | #ifndef ERROR_H_MODULE |
14 | | #define ERROR_H_MODULE |
15 | | |
16 | | #if defined (__cplusplus) |
17 | | extern "C" { |
18 | | #endif |
19 | | |
20 | | |
21 | | /* **************************************** |
22 | | * Dependencies |
23 | | ******************************************/ |
24 | | #include "../zstd_errors.h" /* enum list */ |
25 | | #include "compiler.h" |
26 | | #include "debug.h" |
27 | | #include "zstd_deps.h" /* size_t */ |
28 | | |
29 | | |
30 | | /* **************************************** |
31 | | * Compiler-specific |
32 | | ******************************************/ |
33 | | #if defined(__GNUC__) |
34 | | # define ERR_STATIC static __attribute__((unused)) |
35 | | #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) |
36 | | # define ERR_STATIC static inline |
37 | | #elif defined(_MSC_VER) |
38 | | # define ERR_STATIC static __inline |
39 | | #else |
40 | | # define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ |
41 | | #endif |
42 | | |
43 | | |
44 | | /*-**************************************** |
45 | | * Customization (error_public.h) |
46 | | ******************************************/ |
47 | | typedef ZSTD_ErrorCode ERR_enum; |
48 | 35.5M | #define PREFIX(name) ZSTD_error_##name |
49 | | |
50 | | |
51 | | /*-**************************************** |
52 | | * Error codes handling |
53 | | ******************************************/ |
54 | | #undef ERROR /* already defined on Visual Studio */ |
55 | 35.5M | #define ERROR(name) ZSTD_ERROR(name) |
56 | 35.5M | #define ZSTD_ERROR(name) ((size_t)-PREFIX(name)) |
57 | | |
58 | 35.2M | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } zstd_common.c:ERR_isError Line | Count | Source | 58 | 171k | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
zstd_compress.c:ERR_isError Line | Count | Source | 58 | 2.54M | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
zstd_compress_literals.c:ERR_isError Line | Count | Source | 58 | 35.0k | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
zstd_compress_sequences.c:ERR_isError Line | Count | Source | 58 | 737k | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
Unexecuted instantiation: zstd_compress_superblock.c:ERR_isError Unexecuted instantiation: zstd_double_fast.c:ERR_isError Unexecuted instantiation: zstd_fast.c:ERR_isError Unexecuted instantiation: zstd_lazy.c:ERR_isError Unexecuted instantiation: zstd_ldm.c:ERR_isError Unexecuted instantiation: zstd_opt.c:ERR_isError zstd_decompress.c:ERR_isError Line | Count | Source | 58 | 24.7M | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
zstd_decompress_block.c:ERR_isError Line | Count | Source | 58 | 4.50M | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
entropy_common.c:ERR_isError Line | Count | Source | 58 | 162k | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
Unexecuted instantiation: error_private.c:ERR_isError fse_decompress.c:ERR_isError Line | Count | Source | 58 | 482k | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
fse_compress.c:ERR_isError Line | Count | Source | 58 | 114k | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
Unexecuted instantiation: hist.c:ERR_isError huf_compress.c:ERR_isError Line | Count | Source | 58 | 1.27M | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
huf_decompress.c:ERR_isError Line | Count | Source | 58 | 512k | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
Unexecuted instantiation: zstd_ddict.c:ERR_isError |
59 | | |
60 | 81.8k | ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); } zstd_common.c:ERR_getErrorCode Line | Count | Source | 60 | 81.8k | ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); } |
Unexecuted instantiation: zstd_compress.c:ERR_getErrorCode Unexecuted instantiation: zstd_compress_literals.c:ERR_getErrorCode Unexecuted instantiation: zstd_compress_sequences.c:ERR_getErrorCode Unexecuted instantiation: zstd_compress_superblock.c:ERR_getErrorCode Unexecuted instantiation: zstd_double_fast.c:ERR_getErrorCode Unexecuted instantiation: zstd_fast.c:ERR_getErrorCode Unexecuted instantiation: zstd_lazy.c:ERR_getErrorCode Unexecuted instantiation: zstd_ldm.c:ERR_getErrorCode Unexecuted instantiation: zstd_opt.c:ERR_getErrorCode Unexecuted instantiation: zstd_decompress.c:ERR_getErrorCode Unexecuted instantiation: zstd_decompress_block.c:ERR_getErrorCode Unexecuted instantiation: entropy_common.c:ERR_getErrorCode Unexecuted instantiation: error_private.c:ERR_getErrorCode Unexecuted instantiation: fse_decompress.c:ERR_getErrorCode Unexecuted instantiation: fse_compress.c:ERR_getErrorCode Unexecuted instantiation: hist.c:ERR_getErrorCode Unexecuted instantiation: huf_compress.c:ERR_getErrorCode Unexecuted instantiation: huf_decompress.c:ERR_getErrorCode Unexecuted instantiation: zstd_ddict.c:ERR_getErrorCode |
61 | | |
62 | | /* check and forward error code */ |
63 | 1.42M | #define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e |
64 | 782k | #define CHECK_F(f) { CHECK_V_F(_var_err__, f); } |
65 | | |
66 | | |
67 | | /*-**************************************** |
68 | | * Error Strings |
69 | | ******************************************/ |
70 | | |
71 | | const char* ERR_getErrorString(ERR_enum code); /* error_private.c */ |
72 | | |
73 | | ERR_STATIC const char* ERR_getErrorName(size_t code) |
74 | 0 | { |
75 | 0 | return ERR_getErrorString(ERR_getErrorCode(code)); |
76 | 0 | } Unexecuted instantiation: zstd_common.c:ERR_getErrorName Unexecuted instantiation: zstd_compress.c:ERR_getErrorName Unexecuted instantiation: zstd_compress_literals.c:ERR_getErrorName Unexecuted instantiation: zstd_compress_sequences.c:ERR_getErrorName Unexecuted instantiation: zstd_compress_superblock.c:ERR_getErrorName Unexecuted instantiation: zstd_double_fast.c:ERR_getErrorName Unexecuted instantiation: zstd_fast.c:ERR_getErrorName Unexecuted instantiation: zstd_lazy.c:ERR_getErrorName Unexecuted instantiation: zstd_ldm.c:ERR_getErrorName Unexecuted instantiation: zstd_opt.c:ERR_getErrorName Unexecuted instantiation: zstd_decompress.c:ERR_getErrorName Unexecuted instantiation: zstd_decompress_block.c:ERR_getErrorName Unexecuted instantiation: entropy_common.c:ERR_getErrorName Unexecuted instantiation: error_private.c:ERR_getErrorName Unexecuted instantiation: fse_decompress.c:ERR_getErrorName Unexecuted instantiation: fse_compress.c:ERR_getErrorName Unexecuted instantiation: hist.c:ERR_getErrorName Unexecuted instantiation: huf_compress.c:ERR_getErrorName Unexecuted instantiation: huf_decompress.c:ERR_getErrorName Unexecuted instantiation: zstd_ddict.c:ERR_getErrorName |
77 | | |
78 | | /** |
79 | | * Ignore: this is an internal helper. |
80 | | * |
81 | | * This is a helper function to help force C99-correctness during compilation. |
82 | | * Under strict compilation modes, variadic macro arguments can't be empty. |
83 | | * However, variadic function arguments can be. Using a function therefore lets |
84 | | * us statically check that at least one (string) argument was passed, |
85 | | * independent of the compilation flags. |
86 | | */ |
87 | | static INLINE_KEYWORD UNUSED_ATTR |
88 | 0 | void _force_has_format_string(const char *format, ...) { |
89 | 0 | (void)format; |
90 | 0 | } Unexecuted instantiation: zstd_common.c:_force_has_format_string Unexecuted instantiation: zstd_compress.c:_force_has_format_string Unexecuted instantiation: zstd_compress_literals.c:_force_has_format_string Unexecuted instantiation: zstd_compress_sequences.c:_force_has_format_string Unexecuted instantiation: zstd_compress_superblock.c:_force_has_format_string Unexecuted instantiation: zstd_double_fast.c:_force_has_format_string Unexecuted instantiation: zstd_fast.c:_force_has_format_string Unexecuted instantiation: zstd_lazy.c:_force_has_format_string Unexecuted instantiation: zstd_ldm.c:_force_has_format_string Unexecuted instantiation: zstd_opt.c:_force_has_format_string Unexecuted instantiation: zstd_decompress.c:_force_has_format_string Unexecuted instantiation: zstd_decompress_block.c:_force_has_format_string Unexecuted instantiation: entropy_common.c:_force_has_format_string Unexecuted instantiation: error_private.c:_force_has_format_string Unexecuted instantiation: fse_decompress.c:_force_has_format_string Unexecuted instantiation: fse_compress.c:_force_has_format_string Unexecuted instantiation: hist.c:_force_has_format_string Unexecuted instantiation: huf_compress.c:_force_has_format_string Unexecuted instantiation: huf_decompress.c:_force_has_format_string Unexecuted instantiation: zstd_ddict.c:_force_has_format_string |
91 | | |
92 | | /** |
93 | | * Ignore: this is an internal helper. |
94 | | * |
95 | | * We want to force this function invocation to be syntactically correct, but |
96 | | * we don't want to force runtime evaluation of its arguments. |
97 | | */ |
98 | | #define _FORCE_HAS_FORMAT_STRING(...) \ |
99 | 57.5k | if (0) { \ |
100 | 0 | _force_has_format_string(__VA_ARGS__); \ |
101 | 0 | } |
102 | | |
103 | | #define ERR_QUOTE(str) #str |
104 | | |
105 | | /** |
106 | | * Return the specified error if the condition evaluates to true. |
107 | | * |
108 | | * In debug modes, prints additional information. |
109 | | * In order to do that (particularly, printing the conditional that failed), |
110 | | * this can't just wrap RETURN_ERROR(). |
111 | | */ |
112 | | #define RETURN_ERROR_IF(cond, err, ...) \ |
113 | 59.5M | if (cond) { \ |
114 | 12.5k | RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \ |
115 | 12.5k | __FILE__, __LINE__, ERR_QUOTE(cond), ERR_QUOTE(ERROR(err))); \ |
116 | 12.5k | _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \ |
117 | 12.5k | RAWLOG(3, ": " __VA_ARGS__); \ |
118 | 12.5k | RAWLOG(3, "\n"); \ |
119 | 12.5k | return ERROR(err); \ |
120 | 12.5k | } |
121 | | |
122 | | /** |
123 | | * Unconditionally return the specified error. |
124 | | * |
125 | | * In debug modes, prints additional information. |
126 | | */ |
127 | | #define RETURN_ERROR(err, ...) \ |
128 | 118 | do { \ |
129 | 118 | RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \ |
130 | 118 | __FILE__, __LINE__, ERR_QUOTE(ERROR(err))); \ |
131 | 118 | _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \ |
132 | 118 | RAWLOG(3, ": " __VA_ARGS__); \ |
133 | 118 | RAWLOG(3, "\n"); \ |
134 | 118 | return ERROR(err); \ |
135 | 118 | } while(0); |
136 | | |
137 | | /** |
138 | | * If the provided expression evaluates to an error code, returns that error code. |
139 | | * |
140 | | * In debug modes, prints additional information. |
141 | | */ |
142 | | #define FORWARD_IF_ERROR(err, ...) \ |
143 | 2.22M | do { \ |
144 | 2.22M | size_t const err_code = (err); \ |
145 | 2.22M | if (ERR_isError(err_code)) { \ |
146 | 44.8k | RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \ |
147 | 44.8k | __FILE__, __LINE__, ERR_QUOTE(err), ERR_getErrorName(err_code)); \ |
148 | 44.8k | _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \ |
149 | 44.8k | RAWLOG(3, ": " __VA_ARGS__); \ |
150 | 44.8k | RAWLOG(3, "\n"); \ |
151 | 44.8k | return err_code; \ |
152 | 44.8k | } \ |
153 | 2.22M | } while(0); |
154 | | |
155 | | #if defined (__cplusplus) |
156 | | } |
157 | | #endif |
158 | | |
159 | | #endif /* ERROR_H_MODULE */ |