Fix stack constification definitions.
[openssl.git] / include / openssl / safestack.h
1 /* automatically generated by util/mkstack.pl */
2 /* ====================================================================
3  * Copyright (c) 1999-2015 The OpenSSL Project.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in
14  *    the documentation and/or other materials provided with the
15  *    distribution.
16  *
17  * 3. All advertising materials mentioning features or use of this
18  *    software must display the following acknowledgment:
19  *    "This product includes software developed by the OpenSSL Project
20  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21  *
22  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23  *    endorse or promote products derived from this software without
24  *    prior written permission. For written permission, please contact
25  *    openssl-core@openssl.org.
26  *
27  * 5. Products derived from this software may not be called "OpenSSL"
28  *    nor may "OpenSSL" appear in their names without prior written
29  *    permission of the OpenSSL Project.
30  *
31  * 6. Redistributions of any form whatsoever must retain the following
32  *    acknowledgment:
33  *    "This product includes software developed by the OpenSSL Project
34  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35  *
36  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47  * OF THE POSSIBILITY OF SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This product includes cryptographic software written by Eric Young
51  * (eay@cryptsoft.com).  This product includes software written by Tim
52  * Hudson (tjh@cryptsoft.com).
53  *
54  */
55
56 #ifndef HEADER_SAFESTACK_H
57 # define HEADER_SAFESTACK_H
58
59 # include <openssl/stack.h>
60 # include <openssl/e_os2.h>
61
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65
66 # ifndef CHECKED_PTR_OF
67 #  define CHECKED_PTR_OF(type, p) ((void*) (1 ? p : (type*)0))
68 # endif
69
70 /*
71  * In C++ we get problems because an explicit cast is needed from (void *) we
72  * use CHECKED_STACK_OF to ensure the correct type is passed in the macros
73  * below.
74  */
75
76 # define CHECKED_STACK_OF(type, p) \
77     ((_STACK*) (1 ? p : (STACK_OF(type)*)0))
78
79 # define CHECKED_SK_COPY_FUNC(type, p) \
80     ((void *(*)(void *)) ((1 ? p : (type *(*)(const type *))0)))
81
82 # define CHECKED_SK_FREE_FUNC(type, p) \
83     ((void (*)(void *)) ((1 ? p : (void (*)(type *))0)))
84
85 # define CHECKED_SK_CMP_FUNC(type, p) \
86     ((int (*)(const void *, const void *)) \
87         ((1 ? p : (int (*)(const type * const *, const type * const *))0)))
88
89 # define STACK_OF(type) struct stack_st_##type
90
91 # define SKM_DEFINE_STACK_OF(t1, t2, t3) \
92     STACK_OF(t1); \
93     static ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \
94     { \
95         return sk_num((const _STACK *)sk); \
96     } \
97     static ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \
98     { \
99         return (t2 *)sk_value((const _STACK *)sk, idx); \
100     } \
101     static ossl_inline STACK_OF(t1) *sk_##t1##_new(int (*cmpf)(const t3 * const *a, const t3 * const *b)) \
102     { \
103         return (STACK_OF(t1) *)sk_new((int (*)(const void *a, const void *b))cmpf); \
104     } \
105     static ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \
106     { \
107         return (STACK_OF(t1) *)sk_new_null(); \
108     } \
109     static ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \
110     { \
111         sk_free((_STACK *)sk); \
112     } \
113     static ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \
114     { \
115         sk_zero((_STACK *)sk); \
116     } \
117     static ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \
118     { \
119         return (t2 *)sk_delete((_STACK *)sk, i); \
120     } \
121     static ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \
122     { \
123         return (t2 *)sk_delete_ptr((_STACK *)sk, (void *)ptr); \
124     } \
125     static ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \
126     { \
127         return sk_push((_STACK *)sk, (void *)ptr); \
128     } \
129     static ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \
130     { \
131         return sk_unshift((_STACK *)sk, (void *)ptr); \
132     } \
133     static ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
134     { \
135         return (t2 *)sk_pop((_STACK *)sk); \
136     } \
137     static ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \
138     { \
139         return (t2 *)sk_shift((_STACK *)sk); \
140     } \
141     static ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, void (*func)(t3 *a)) \
142     { \
143         sk_pop_free((_STACK *)sk, (void (*)(void *))func); \
144     } \
145     static ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \
146     { \
147         return sk_insert((_STACK *)sk, (void *)ptr, idx); \
148     } \
149     static ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \
150     { \
151         return (t2 *)sk_set((_STACK *)sk, idx, (void *)ptr); \
152     } \
153     static ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
154     { \
155         return sk_find((_STACK *)sk, (void *)ptr); \
156     } \
157     static ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \
158     { \
159         return sk_find_ex((_STACK *)sk, (void *)ptr); \
160     } \
161     static ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \
162     { \
163         sk_sort((_STACK *)sk); \
164     } \
165     static ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \
166     { \
167         return sk_is_sorted((const _STACK *)sk); \
168     } \
169     static ossl_inline STACK_OF(t1) * sk_##t1##_dup(STACK_OF(t1) *sk) \
170     { \
171         return (STACK_OF(t1) *)sk_dup((_STACK *)sk); \
172     } \
173     static ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(STACK_OF(t1) *sk, \
174                                                     t3 *(*copyfn)(const t3 *), \
175                                                     void (*freefn)(t3 *)) \
176     { \
177         return (STACK_OF(t1) *)sk_deep_copy((_STACK *)sk, \
178                                             (void * (*)(void *a))copyfn, \
179                                             (void (*)(void *a))freefn); \
180     } \
181     static ossl_inline int (*sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, int (*cmpf)(const t3 * const *a, const t3 * const *b)))(const t3 * const *, const t3 * const *) \
182     { \
183         return (int (*)(const t3 * const *,const t3 * const *))sk_set_cmp_func((_STACK *)sk, (int (*)(const void *a, const void *b))cmpf); \
184     }
185
186 # define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2)
187 # define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t)
188 # define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t)
189
190 /*-
191  * Strings are special: normally an lhash entry will point to a single
192  * (somewhat) mutable object. In the case of strings:
193  *
194  * a) Instead of a single char, there is an array of chars, NUL-terminated.
195  * b) The string may have be immutable.
196  *
197  * So, they need their own declarations. Especially important for
198  * type-checking tools, such as Deputy.
199  *
200  * In practice, however, it appears to be hard to have a const
201  * string. For now, I'm settling for dealing with the fact it is a
202  * string at all.
203  */
204 typedef char *OPENSSL_STRING;
205 typedef const char *OPENSSL_CSTRING;
206
207 /*-
208  * Confusingly, LHASH_OF(STRING) deals with char ** throughout, but
209  * STACK_OF(STRING) is really more like STACK_OF(char), only, as mentioned
210  * above, instead of a single char each entry is a NUL-terminated array of
211  * chars. So, we have to implement STRING specially for STACK_OF. This is
212  * dealt with in the autogenerated macros below.
213  */
214 DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
215
216 /*
217  * Similarly, we sometimes use a block of characters, NOT nul-terminated.
218  * These should also be distinguished from "normal" stacks.
219  */
220 typedef void *OPENSSL_BLOCK;
221 DEFINE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
222
223 # ifdef  __cplusplus
224 }
225 # endif
226 #endif