Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | include_dir=../../include/openssl |
| 4 | |
| 5 | cat > "${include_dir}/stack_macros.h" << EOF |
| 6 | /* Copyright (c) 2014, Google Inc. |
| 7 | * |
| 8 | * Permission to use, copy, modify, and/or distribute this software for any |
| 9 | * purpose with or without fee is hereby granted, provided that the above |
| 10 | * copyright notice and this permission notice appear in all copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 13 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 15 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 17 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 18 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 19 | |
| 20 | #if !defined(IN_STACK_H) |
| 21 | #error "Don't include this file directly. Include stack.h." |
| 22 | #endif |
| 23 | |
| 24 | EOF |
| 25 | |
| 26 | output_stack () { |
| 27 | type=$1 |
| 28 | ptrtype=$2 |
| 29 | |
| 30 | cat >> "${include_dir}/stack_macros.h" << EOF |
| 31 | /* ${type} */ |
| 32 | #define sk_${type}_new(comp)\\ |
| 33 | ((STACK_OF(${type})*) sk_new(CHECKED_CAST(stack_cmp_func, int (*) (const ${ptrtype} *a, const ${ptrtype} *b), comp))) |
| 34 | |
| 35 | #define sk_${type}_new_null()\\ |
| 36 | ((STACK_OF(${type})*) sk_new_null()) |
| 37 | |
| 38 | #define sk_${type}_num(sk)\\ |
David Benjamin | d316cba | 2016-06-02 16:17:39 -0400 | [diff] [blame] | 39 | sk_num(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk)) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 40 | |
| 41 | #define sk_${type}_zero(sk)\\ |
| 42 | sk_zero(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk)); |
| 43 | |
| 44 | #define sk_${type}_value(sk, i)\\ |
David Benjamin | d316cba | 2016-06-02 16:17:39 -0400 | [diff] [blame] | 45 | ((${ptrtype}) sk_value(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk), (i))) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 46 | |
| 47 | #define sk_${type}_set(sk, i, p)\\ |
| 48 | ((${ptrtype}) sk_set(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), (i), CHECKED_CAST(void*, ${ptrtype}, p))) |
| 49 | |
| 50 | #define sk_${type}_free(sk)\\ |
| 51 | sk_free(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk)) |
| 52 | |
| 53 | #define sk_${type}_pop_free(sk, free_func)\\ |
| 54 | sk_pop_free(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void (*) (void*), void (*) (${ptrtype}), free_func)) |
| 55 | |
| 56 | #define sk_${type}_insert(sk, p, where)\\ |
| 57 | sk_insert(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void*, ${ptrtype}, p), (where)) |
| 58 | |
| 59 | #define sk_${type}_delete(sk, where)\\ |
| 60 | ((${ptrtype}) sk_delete(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), (where))) |
| 61 | |
| 62 | #define sk_${type}_delete_ptr(sk, p)\\ |
| 63 | ((${ptrtype}) sk_delete_ptr(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void*, ${ptrtype}, p))) |
| 64 | |
| 65 | #define sk_${type}_find(sk, out_index, p)\\ |
| 66 | sk_find(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), (out_index), CHECKED_CAST(void*, ${ptrtype}, p)) |
| 67 | |
| 68 | #define sk_${type}_shift(sk)\\ |
| 69 | ((${ptrtype}) sk_shift(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk))) |
| 70 | |
| 71 | #define sk_${type}_push(sk, p)\\ |
| 72 | sk_push(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void*, ${ptrtype}, p)) |
| 73 | |
| 74 | #define sk_${type}_pop(sk)\\ |
| 75 | ((${ptrtype}) sk_pop(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk))) |
| 76 | |
| 77 | #define sk_${type}_dup(sk)\\ |
David Benjamin | d316cba | 2016-06-02 16:17:39 -0400 | [diff] [blame] | 78 | ((STACK_OF(${type})*) sk_dup(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk))) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 79 | |
| 80 | #define sk_${type}_sort(sk)\\ |
| 81 | sk_sort(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk)) |
| 82 | |
| 83 | #define sk_${type}_is_sorted(sk)\\ |
David Benjamin | d316cba | 2016-06-02 16:17:39 -0400 | [diff] [blame] | 84 | sk_is_sorted(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk)) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 85 | |
| 86 | #define sk_${type}_set_cmp_func(sk, comp)\\ |
| 87 | ((int (*) (const ${type} **a, const ${type} **b)) sk_set_cmp_func(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(stack_cmp_func, int (*) (const ${type} **a, const ${type} **b), comp))) |
| 88 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 89 | #define sk_${type}_deep_copy(sk, copy_func, free_func)\\ |
| 90 | ((STACK_OF(${type})*) sk_deep_copy(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk), CHECKED_CAST(void* (*) (void*), ${ptrtype} (*) (${ptrtype}), copy_func), CHECKED_CAST(void (*) (void*), void (*) (${ptrtype}), free_func))) |
| 91 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 92 | EOF |
| 93 | } |
| 94 | |
| 95 | stack_types=$(cat "${include_dir}/stack.h" | grep '^ \* STACK_OF:' | sed -e 's/.*STACK_OF://' -e 's/ .*//') |
| 96 | const_stack_types=$(cat "${include_dir}/stack.h" | grep '^ \* CONST_STACK_OF:' | sed -e 's/.*CONST_STACK_OF://' -e 's/ .*//') |
| 97 | special_stack_types=$(cat "${include_dir}/stack.h" | grep '^ \* SPECIAL_STACK_OF:' | sed -e 's/.*SPECIAL_STACK_OF://' -e 's/ .*//') |
| 98 | |
| 99 | for type in $stack_types; do |
| 100 | echo Stack of ${type} |
| 101 | output_stack "${type}" "${type} *" |
| 102 | done |
| 103 | |
| 104 | for type in $const_stack_types; do |
| 105 | echo Stack of ${type} |
| 106 | output_stack "${type}" "const ${type} *" |
| 107 | done |
| 108 | |
| 109 | for type in $special_stack_types; do |
| 110 | echo Stack of ${type} |
| 111 | output_stack "${type}" "${type}" |
| 112 | done |
| 113 | |
| 114 | clang-format -i "${include_dir}/stack_macros.h" |