2 * *****************************************************************************
4 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2018-2020 Gavin D. Howard and contributors.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * *****************************************************************************
32 * The private header for the bc library.
36 #ifndef LIBBC_PRIVATE_H
37 #define LIBBC_PRIVATE_H
43 #define BC_FUNC_HEADER_LOCK(l) \
46 BC_SETJMP_LOCKED(l); \
47 vm.err = BCL_ERROR_NONE; \
51 #define BC_FUNC_FOOTER_UNLOCK(e) \
53 BC_SIG_ASSERT_LOCKED; \
61 #define BC_FUNC_HEADER(l) \
64 vm.err = BCL_ERROR_NONE; \
68 #define BC_FUNC_HEADER_INIT(l) \
70 BC_SETJMP_LOCKED(l); \
71 vm.err = BCL_ERROR_NONE; \
75 #define BC_FUNC_FOOTER_NO_ERR \
83 #define BC_FUNC_FOOTER(e) \
86 BC_FUNC_FOOTER_NO_ERR; \
89 #define BC_FUNC_RESETJMP(l) \
91 BC_SIG_ASSERT_LOCKED; \
93 BC_SETJMP_LOCKED(l); \
96 #define BC_MAYBE_SETUP(c, e, n, idx) \
98 if (BC_ERR((e) != BCL_ERROR_NONE)) { \
99 if ((n).num != NULL) bc_num_free(&(n)); \
100 idx.i = 0 - (size_t) (e); \
102 else idx = bcl_num_insert(c, &(n)); \
105 #define BC_CHECK_CTXT(c) \
108 if (BC_ERR(c == NULL)) { \
110 n_num.i = 0 - (size_t) BCL_ERROR_INVALID_CONTEXT; \
115 #define BC_CHECK_CTXT_ERR(c) \
118 if (BC_ERR(c == NULL)) { \
119 return BCL_ERROR_INVALID_CONTEXT; \
123 #define BC_CHECK_CTXT_ASSERT(c) \
129 #define BC_CHECK_NUM(c, n) \
131 if (BC_ERR((n).i >= (c)->nums.len)) { \
132 if ((n).i > 0 - (size_t) BCL_ERROR_NELEMS) return (n); \
135 n_num.i = 0 - (size_t) BCL_ERROR_INVALID_NUM; \
141 #define BC_CHECK_NUM_ERR(c, n) \
143 if (BC_ERR((n).i >= (c)->nums.len)) { \
144 if ((n).i > 0 - (size_t) BCL_ERROR_NELEMS) \
145 return (BclError) (0 - (n).i); \
146 else return BCL_ERROR_INVALID_NUM; \
150 #define BC_NUM(c, n) ((BcNum*) bc_vec_item(&(c)->nums, (n).i))
152 typedef size_t (*BcReqOp)(const BcNum*, const BcNum*, size_t);
154 typedef struct BclCtxt {
165 #endif // LIBBC_PRIVATE_H