| 1 | #cxx . . $ `<file>/mojoshader_common.c`/define __MOJOSHADER_INTERNAL__cxx . . $ `mojoshader_common.c:1:9`! 1 |
| 2 | #include "mojoshader_internal.h"cxx . . $ `<file>/mojoshader_internal.h`/ |
| 3 | #ifndef MOJOSHADER_USE_SDL_STDLIB |
| 4 | #include <math.h> |
| 5 | #endif /* MOJOSHADER_USE_SDL_STDLIB */ |
| 6 | |
| 7 | // Convenience functions for allocators... |
| 8 | #if !MOJOSHADER_FORCE_ALLOCATOR |
| 9 | static char zeromalloccxx . . $ zeromalloc. = 0; |
| 10 | void * MOJOSHADERCALLcxx . . $ `mojoshader.h:42:9`! MOJOSHADER_internal_malloccxx . . $ MOJOSHADER_internal_malloc(d0e8a54466770ee5).(int bytes, void *d) |
| 11 | { |
| 12 | return (bytes == 0) ? &zeromalloccxx . . $ zeromalloc. : malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(bytes); |
| 13 | } // MOJOSHADER_internal_malloc |
| 14 | void MOJOSHADERCALLcxx . . $ `mojoshader.h:42:9`! MOJOSHADER_internal_freecxx . . $ MOJOSHADER_internal_free(6c58c5e2437d25a2).(void *ptr, void *d) |
| 15 | { |
| 16 | if ((ptr != &zeromalloccxx . . $ zeromalloc.) && (ptr != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) |
| 17 | freecxx . . $ free(5d22bdacc48458e8).(ptr); |
| 18 | } // MOJOSHADER_internal_free |
| 19 | #endif |
| 20 | |
| 21 | MOJOSHADER_errorcxx . . $ MOJOSHADER_error# MOJOSHADER_out_of_mem_errorcxx . . $ MOJOSHADER_out_of_mem_error. = { |
| 22 | "Out of memory", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, MOJOSHADER_POSITION_NONEcxx . . $ `mojoshader.h:377:9`! |
| 23 | }; |
| 24 | |
| 25 | MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData# MOJOSHADER_out_of_mem_datacxx . . $ MOJOSHADER_out_of_mem_data. = { |
| 26 | 1, &MOJOSHADER_out_of_mem_errorcxx . . $ MOJOSHADER_out_of_mem_error., 0, 0, 0, 0, |
| 27 | MOJOSHADER_TYPE_UNKNOWNcxx . . $ MOJOSHADER_TYPE_UNKNOWN., 0, 0, 0, 0, 0, 0, 0, |
| 28 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 29 | }; |
| 30 | |
| 31 | |
| 32 | typedef struct HashItemcxx . . $ HashItem# |
| 33 | { |
| 34 | const void *keycxx . . $ HashItem#key.; |
| 35 | const void *valuecxx . . $ HashItem#value.; |
| 36 | struct HashItemcxx . . $ HashItem# *nextcxx . . $ HashItem#next.; |
| 37 | } HashItemcxx . . $ HashItem#; |
| 38 | |
| 39 | struct HashTablecxx . . $ HashTable# |
| 40 | { |
| 41 | HashItemcxx . . $ HashItem# **tablecxx . . $ HashTable#table.; |
| 42 | uint32cxx . . $ uint32# table_lencxx . . $ HashTable#table_len.; |
| 43 | int stackablecxx . . $ HashTable#stackable.; |
| 44 | void *datacxx . . $ HashTable#data.; |
| 45 | HashTable_HashFncxx . . $ HashTable_HashFn# hashcxx . . $ HashTable#hash.; |
| 46 | HashTable_KeyMatchFncxx . . $ HashTable_KeyMatchFn# keymatchcxx . . $ HashTable#keymatch.; |
| 47 | HashTable_NukeFncxx . . $ HashTable_NukeFn# nukecxx . . $ HashTable#nuke.; |
| 48 | MOJOSHADER_malloccxx . . $ MOJOSHADER_malloc# mcxx . . $ HashTable#m.; |
| 49 | MOJOSHADER_freecxx . . $ MOJOSHADER_free# fcxx . . $ HashTable#f.; |
| 50 | void *dcxx . . $ HashTable#d.; |
| 51 | }; |
| 52 | |
| 53 | static inline uint32cxx . . $ uint32# calc_hashcxx . . $ calc_hash(548a926837147d65).(const HashTablecxx . . $ HashTable# *table, const void *key) |
| 54 | { |
| 55 | return table->hashcxx . . $ HashTable#hash.(key, table->datacxx . . $ HashTable#data.) & (table->table_lencxx . . $ HashTable#table_len.-1); |
| 56 | } // calc_hash |
| 57 | |
| 58 | int hash_findcxx . . $ hash_find(7ef6c75da24368fe).(const HashTablecxx . . $ HashTable# *table, const void *key, const void **_value) |
| 59 | { |
| 60 | HashItemcxx . . $ HashItem# *i; |
| 61 | void *data = table->datacxx . . $ HashTable#data.; |
| 62 | const uint32cxx . . $ uint32# hash = calc_hashcxx . . $ calc_hash(548a926837147d65).(table, key); |
| 63 | HashItemcxx . . $ HashItem# *prev = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 64 | for (i = table->tablecxx . . $ HashTable#table.[hash]; i != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; i = i->nextcxx . . $ HashItem#next.) |
| 65 | { |
| 66 | if (table->keymatchcxx . . $ HashTable#keymatch.(key, i->keycxx . . $ HashItem#key., data)) |
| 67 | { |
| 68 | if (_value != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 69 | *_value = i->valuecxx . . $ HashItem#value.; |
| 70 | |
| 71 | // Matched! Move to the front of list for faster lookup next time. |
| 72 | // (stackable tables have to remain in the same order, though!) |
| 73 | if ((!table->stackablecxx . . $ HashTable#stackable.) && (prev != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) |
| 74 | { |
| 75 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(prev->next == i); |
| 76 | prev->nextcxx . . $ HashItem#next. = i->nextcxx . . $ HashItem#next.; |
| 77 | i->nextcxx . . $ HashItem#next. = table->tablecxx . . $ HashTable#table.[hash]; |
| 78 | table->tablecxx . . $ HashTable#table.[hash] = i; |
| 79 | } // if |
| 80 | |
| 81 | return 1; |
| 82 | } // if |
| 83 | |
| 84 | prev = i; |
| 85 | } // for |
| 86 | |
| 87 | return 0; |
| 88 | } // hash_find |
| 89 | |
| 90 | int hash_itercxx . . $ hash_iter(7424f801a1aef07a).(const HashTablecxx . . $ HashTable# *table, const void *key, |
| 91 | const void **_value, void **iter) |
| 92 | { |
| 93 | HashItemcxx . . $ HashItem# *item = (HashItemcxx . . $ HashItem# *) *iter; |
| 94 | if (item == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 95 | item = table->tablecxx . . $ HashTable#table.[calc_hashcxx . . $ calc_hash(548a926837147d65).(table, key)]; |
| 96 | else |
| 97 | item = item->nextcxx . . $ HashItem#next.; |
| 98 | |
| 99 | while (item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 100 | { |
| 101 | if (table->keymatchcxx . . $ HashTable#keymatch.(key, item->keycxx . . $ HashItem#key., table->datacxx . . $ HashTable#data.)) |
| 102 | { |
| 103 | *_value = item->valuecxx . . $ HashItem#value.; |
| 104 | *iter = item; |
| 105 | return 1; |
| 106 | } // if |
| 107 | item = item->nextcxx . . $ HashItem#next.; |
| 108 | } // while |
| 109 | |
| 110 | // no more matches. |
| 111 | *_value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 112 | *iter = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 113 | return 0; |
| 114 | } // hash_iter |
| 115 | |
| 116 | int hash_iter_keyscxx . . $ hash_iter_keys(c68c721387e4f0a2).(const HashTablecxx . . $ HashTable# *table, const void **_key, void **iter) |
| 117 | { |
| 118 | HashItemcxx . . $ HashItem# *item = (HashItemcxx . . $ HashItem# *) *iter; |
| 119 | uint32cxx . . $ uint32# idx = 0; |
| 120 | |
| 121 | if (item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 122 | { |
| 123 | const HashItemcxx . . $ HashItem# *orig = item; |
| 124 | item = item->nextcxx . . $ HashItem#next.; |
| 125 | if (item == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 126 | idx = calc_hashcxx . . $ calc_hash(548a926837147d65).(table, orig->keycxx . . $ HashItem#key.) + 1; |
| 127 | } // if |
| 128 | |
| 129 | while (!item && (idx < table->table_lencxx . . $ HashTable#table_len.)) |
| 130 | item = table->tablecxx . . $ HashTable#table.[idx++]; // skip empty buckets... |
| 131 | |
| 132 | if (item == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) // no more matches? |
| 133 | { |
| 134 | *_key = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 135 | *iter = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 136 | return 0; |
| 137 | } // if |
| 138 | |
| 139 | *_key = item->keycxx . . $ HashItem#key.; |
| 140 | *iter = item; |
| 141 | return 1; |
| 142 | } // hash_iter_keys |
| 143 | |
| 144 | int hash_insertcxx . . $ hash_insert(1d30a91d107a3de).(HashTablecxx . . $ HashTable# *table, const void *key, const void *value) |
| 145 | { |
| 146 | HashItemcxx . . $ HashItem# *item = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 147 | const uint32cxx . . $ uint32# hash = calc_hashcxx . . $ calc_hash(548a926837147d65).(table, key); |
| 148 | if ( (!table->stackablecxx . . $ HashTable#stackable.) && (hash_findcxx . . $ hash_find(7ef6c75da24368fe).(table, key, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) ) |
| 149 | return 0; |
| 150 | |
| 151 | // !!! FIXME: grow and rehash table if it gets too saturated. |
| 152 | item = (HashItemcxx . . $ HashItem# *) table->mcxx . . $ HashTable#m.(sizeof (HashItemcxx . . $ HashItem#), table->dcxx . . $ HashTable#d.); |
| 153 | if (item == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 154 | return -1; |
| 155 | |
| 156 | item->keycxx . . $ HashItem#key. = key; |
| 157 | item->valuecxx . . $ HashItem#value. = value; |
| 158 | item->nextcxx . . $ HashItem#next. = table->tablecxx . . $ HashTable#table.[hash]; |
| 159 | table->tablecxx . . $ HashTable#table.[hash] = item; |
| 160 | |
| 161 | return 1; |
| 162 | } // hash_insert |
| 163 | |
| 164 | HashTablecxx . . $ HashTable# *hash_createcxx . . $ hash_create(8335872bcb6e2f75).(void *data, const HashTable_HashFncxx . . $ HashTable_HashFn# hashfn, |
| 165 | const HashTable_KeyMatchFncxx . . $ HashTable_KeyMatchFn# keymatchfn, |
| 166 | const HashTable_NukeFncxx . . $ HashTable_NukeFn# nukefn, |
| 167 | const int stackable, |
| 168 | MOJOSHADER_malloccxx . . $ MOJOSHADER_malloc# m, MOJOSHADER_freecxx . . $ MOJOSHADER_free# f, void *d) |
| 169 | { |
| 170 | const uint32cxx . . $ uint32# initial_table_size = 256; |
| 171 | const uint32cxx . . $ uint32# alloc_len = sizeof (HashItemcxx . . $ HashItem# *) * initial_table_size; |
| 172 | HashTablecxx . . $ HashTable# *table = (HashTablecxx . . $ HashTable# *) m(sizeof (HashTablecxx . . $ HashTable#), d); |
| 173 | if (table == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 174 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 175 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(table, '\0', sizeof (HashTablecxx . . $ HashTable#)); |
| 176 | |
| 177 | table->tablecxx . . $ HashTable#table. = (HashItemcxx . . $ HashItem# **) m(alloc_len, d); |
| 178 | if (table->tablecxx . . $ HashTable#table. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 179 | { |
| 180 | f(table, d); |
| 181 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 182 | } // if |
| 183 | |
| 184 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(table->tablecxx . . $ HashTable#table., '\0', alloc_len); |
| 185 | table->table_lencxx . . $ HashTable#table_len. = initial_table_size; |
| 186 | table->stackablecxx . . $ HashTable#stackable. = stackable; |
| 187 | table->datacxx . . $ HashTable#data. = data; |
| 188 | table->hashcxx . . $ HashTable#hash. = hashfn; |
| 189 | table->keymatchcxx . . $ HashTable#keymatch. = keymatchfn; |
| 190 | table->nukecxx . . $ HashTable#nuke. = nukefn; |
| 191 | table->mcxx . . $ HashTable#m. = m; |
| 192 | table->fcxx . . $ HashTable#f. = f; |
| 193 | table->dcxx . . $ HashTable#d. = d; |
| 194 | return table; |
| 195 | } // hash_create |
| 196 | |
| 197 | void hash_destroycxx . . $ hash_destroy(801354b631669f34).(HashTablecxx . . $ HashTable# *table, const void *ctx) |
| 198 | { |
| 199 | uint32cxx . . $ uint32# i; |
| 200 | void *data = table->datacxx . . $ HashTable#data.; |
| 201 | MOJOSHADER_freecxx . . $ MOJOSHADER_free# f = table->fcxx . . $ HashTable#f.; |
| 202 | void *d = table->dcxx . . $ HashTable#d.; |
| 203 | for (i = 0; i < table->table_lencxx . . $ HashTable#table_len.; i++) |
| 204 | { |
| 205 | HashItemcxx . . $ HashItem# *item = table->tablecxx . . $ HashTable#table.[i]; |
| 206 | while (item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 207 | { |
| 208 | HashItemcxx . . $ HashItem# *next = item->nextcxx . . $ HashItem#next.; |
| 209 | table->nukecxx . . $ HashTable#nuke.(ctx, item->keycxx . . $ HashItem#key., item->valuecxx . . $ HashItem#value., data); |
| 210 | f(item, d); |
| 211 | item = next; |
| 212 | } // while |
| 213 | } // for |
| 214 | |
| 215 | f(table->tablecxx . . $ HashTable#table., d); |
| 216 | f(table, d); |
| 217 | } // hash_destroy |
| 218 | |
| 219 | int hash_removecxx . . $ hash_remove(1d30a91d107a3de).(HashTablecxx . . $ HashTable# *table, const void *key, const void *ctx) |
| 220 | { |
| 221 | HashItemcxx . . $ HashItem# *item = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 222 | HashItemcxx . . $ HashItem# *prev = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 223 | void *data = table->datacxx . . $ HashTable#data.; |
| 224 | const uint32cxx . . $ uint32# hash = calc_hashcxx . . $ calc_hash(548a926837147d65).(table, key); |
| 225 | for (item = table->tablecxx . . $ HashTable#table.[hash]; item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; item = item->nextcxx . . $ HashItem#next.) |
| 226 | { |
| 227 | if (table->keymatchcxx . . $ HashTable#keymatch.(key, item->keycxx . . $ HashItem#key., data)) |
| 228 | { |
| 229 | if (prev != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 230 | prev->nextcxx . . $ HashItem#next. = item->nextcxx . . $ HashItem#next.; |
| 231 | else |
| 232 | table->tablecxx . . $ HashTable#table.[hash] = item->nextcxx . . $ HashItem#next.; |
| 233 | |
| 234 | table->nukecxx . . $ HashTable#nuke.(ctx, item->keycxx . . $ HashItem#key., item->valuecxx . . $ HashItem#value., data); |
| 235 | table->fcxx . . $ HashTable#f.(item, table->dcxx . . $ HashTable#d.); |
| 236 | return 1; |
| 237 | } // if |
| 238 | |
| 239 | prev = item; |
| 240 | } // for |
| 241 | |
| 242 | return 0; |
| 243 | } // hash_remove |
| 244 | |
| 245 | |
| 246 | // this is djb's xor hashing function. |
| 247 | static inline uint32cxx . . $ uint32# hash_string_djbxorcxx . . $ hash_string_djbxor(b323a3098472c9f4).(const char *str, size_t len) |
| 248 | { |
| 249 | register uint32cxx . . $ uint32# hash = 5381; |
| 250 | while (len--) |
| 251 | hash = ((hash << 5) + hash) ^ *(str++); |
| 252 | return hash; |
| 253 | } // hash_string_djbxor |
| 254 | |
| 255 | static inline uint32cxx . . $ uint32# hash_stringcxx . . $ hash_string(b323a3098472c9f4).(const char *str, size_t len) |
| 256 | { |
| 257 | return hash_string_djbxorcxx . . $ hash_string_djbxor(b323a3098472c9f4).(str, len); |
| 258 | } // hash_string |
| 259 | |
| 260 | uint32cxx . . $ uint32# hash_hash_stringcxx . . $ hash_hash_string(3be275e70c14adf4).(const void *sym, void *data) |
| 261 | { |
| 262 | (void) data; |
| 263 | return hash_stringcxx . . $ hash_string(b323a3098472c9f4).((const char*) sym, strlencxx . . $ strlen(751346f8406fd082).((const char *) sym)); |
| 264 | } // hash_hash_string |
| 265 | |
| 266 | int hash_keymatch_stringcxx . . $ hash_keymatch_string(b8f62d2ccbc12f7d).(const void *a, const void *b, void *data) |
| 267 | { |
| 268 | (void) data; |
| 269 | return (strcmpcxx . . $ strcmp(5ae29d726ae57f88).((const char *) a, (const char *) b) == 0); |
| 270 | } // hash_keymatch_string |
| 271 | |
| 272 | |
| 273 | // string -> string map... |
| 274 | |
| 275 | static void stringmap_nuke_noopcxx . . $ stringmap_nuke_noop(12471b72f5b802e8).(const void *ctx, const void *key, const void *val, void *d) {} |
| 276 | |
| 277 | static void stringmap_nukecxx . . $ stringmap_nuke(12471b72f5b802e8).(const void *ctx, const void *key, const void *val, void *d) |
| 278 | { |
| 279 | StringMapcxx . . $ StringMap# *smap = (StringMapcxx . . $ StringMap# *) d; |
| 280 | smap->fcxx . . $ HashTable#f.((void *) key, smap->dcxx . . $ HashTable#d.); |
| 281 | smap->fcxx . . $ HashTable#f.((void *) val, smap->dcxx . . $ HashTable#d.); |
| 282 | } // stringmap_nuke |
| 283 | |
| 284 | StringMapcxx . . $ StringMap# *stringmap_createcxx . . $ stringmap_create(b90973fc0f11569c).(const int copy, MOJOSHADER_malloccxx . . $ MOJOSHADER_malloc# m, |
| 285 | MOJOSHADER_freecxx . . $ MOJOSHADER_free# f, void *d) |
| 286 | { |
| 287 | HashTable_NukeFncxx . . $ HashTable_NukeFn# nuke = copy ? stringmap_nukecxx . . $ stringmap_nuke(12471b72f5b802e8). : stringmap_nuke_noopcxx . . $ stringmap_nuke_noop(12471b72f5b802e8).; |
| 288 | StringMapcxx . . $ StringMap# *smap; |
| 289 | smap = hash_createcxx . . $ hash_create(8335872bcb6e2f75).(0,hash_hash_stringcxx . . $ hash_hash_string(3be275e70c14adf4).,hash_keymatch_stringcxx . . $ hash_keymatch_string(b8f62d2ccbc12f7d).,nuke,0,m,f,d); |
| 290 | if (smap != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 291 | smap->datacxx . . $ HashTable#data. = smap; |
| 292 | return smap; |
| 293 | } // stringmap_create |
| 294 | |
| 295 | void stringmap_destroycxx . . $ stringmap_destroy(84d7d441182d6029).(StringMapcxx . . $ StringMap# *smap) |
| 296 | { |
| 297 | hash_destroycxx . . $ hash_destroy(801354b631669f34).(smap, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 298 | } // stringmap_destroy |
| 299 | |
| 300 | int stringmap_insertcxx . . $ stringmap_insert(3a82e30735b2152a).(StringMapcxx . . $ StringMap# *smap, const char *key, const char *value) |
| 301 | { |
| 302 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(key != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 303 | if (smap->nukecxx . . $ HashTable#nuke. == stringmap_nuke_noopcxx . . $ stringmap_nuke_noop(12471b72f5b802e8).) // no copy? |
| 304 | return hash_insertcxx . . $ hash_insert(1d30a91d107a3de).(smap, key, value); |
| 305 | |
| 306 | int rc = -1; |
| 307 | char *k = (char *) smap->mcxx . . $ HashTable#m.(strlencxx . . $ strlen(751346f8406fd082).(key) + 1, smap->dcxx . . $ HashTable#d.); |
| 308 | char *v = (char *) (value ? smap->mcxx . . $ HashTable#m.(strlencxx . . $ strlen(751346f8406fd082).(value) + 1, smap->dcxx . . $ HashTable#d.) : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 309 | int failed = ( (!k) || ((!v) && (value)) ); |
| 310 | |
| 311 | if (!failed) |
| 312 | { |
| 313 | strcpycxx . . $ strcpy(b7b3a83273496486).(k, key); |
| 314 | if (value != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 315 | strcpycxx . . $ strcpy(b7b3a83273496486).(v, value); |
| 316 | failed = ((rc = hash_insertcxx . . $ hash_insert(1d30a91d107a3de).(smap, k, v)) <= 0); |
| 317 | } // if |
| 318 | |
| 319 | if (failed) |
| 320 | { |
| 321 | smap->fcxx . . $ HashTable#f.(k, smap->dcxx . . $ HashTable#d.); |
| 322 | smap->fcxx . . $ HashTable#f.(v, smap->dcxx . . $ HashTable#d.); |
| 323 | } // if |
| 324 | |
| 325 | return rc; |
| 326 | } // stringmap_insert |
| 327 | |
| 328 | int stringmap_removecxx . . $ stringmap_remove(c54b7143281a1e38).(StringMapcxx . . $ StringMap# *smap, const char *key) |
| 329 | { |
| 330 | return hash_removecxx . . $ hash_remove(1d30a91d107a3de).(smap, key, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 331 | } // stringmap_remove |
| 332 | |
| 333 | int stringmap_findcxx . . $ stringmap_find(798cea8404476ec7).(const StringMapcxx . . $ StringMap# *smap, const char *key, const char **_value) |
| 334 | { |
| 335 | const void *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 336 | const int retval = hash_findcxx . . $ hash_find(7ef6c75da24368fe).(smap, key, &value); |
| 337 | *_value = (const char *) value; |
| 338 | return retval; |
| 339 | } // stringmap_find |
| 340 | |
| 341 | |
| 342 | // The string cache... !!! FIXME: use StringMap internally for this. |
| 343 | |
| 344 | typedef struct StringBucketcxx . . $ StringBucket# |
| 345 | { |
| 346 | char *stringcxx . . $ StringBucket#string.; |
| 347 | struct StringBucketcxx . . $ StringBucket# *nextcxx . . $ StringBucket#next.; |
| 348 | } StringBucketcxx . . $ StringBucket#; |
| 349 | |
| 350 | struct StringCachecxx . . $ StringCache# |
| 351 | { |
| 352 | StringBucketcxx . . $ StringBucket# **hashtablecxx . . $ StringCache#hashtable.; |
| 353 | uint32cxx . . $ uint32# table_sizecxx . . $ StringCache#table_size.; |
| 354 | MOJOSHADER_malloccxx . . $ MOJOSHADER_malloc# mcxx . . $ StringCache#m.; |
| 355 | MOJOSHADER_freecxx . . $ MOJOSHADER_free# fcxx . . $ StringCache#f.; |
| 356 | void *dcxx . . $ StringCache#d.; |
| 357 | }; |
| 358 | |
| 359 | |
| 360 | const char *stringcachecxx . . $ stringcache(9a0b32e58267707a).(StringCachecxx . . $ StringCache# *cache, const char *str) |
| 361 | { |
| 362 | return stringcache_lencxx . . $ stringcache_len(a48eb3d5dcd20ad4).(cache, str, strlencxx . . $ strlen(751346f8406fd082).(str)); |
| 363 | } // stringcache |
| 364 | |
| 365 | static const char *stringcache_len_internalcxx . . $ stringcache_len_internal(d4a11bece8530d8d).(StringCachecxx . . $ StringCache# *cache, |
| 366 | const char *str, |
| 367 | const unsigned int len, |
| 368 | const int addmissing) |
| 369 | { |
| 370 | const uint8cxx . . $ uint8# hash = hash_stringcxx . . $ hash_string(b323a3098472c9f4).(str, len) & (cache->table_sizecxx . . $ StringCache#table_size.-1); |
| 371 | StringBucketcxx . . $ StringBucket# *bucket = cache->hashtablecxx . . $ StringCache#hashtable.[hash]; |
| 372 | StringBucketcxx . . $ StringBucket# *prev = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 373 | while (bucket) |
| 374 | { |
| 375 | const char *bstr = bucket->stringcxx . . $ StringBucket#string.; |
| 376 | if ((strncmpcxx . . $ strncmp(fd278af2f295fa2e).(bstr, str, len) == 0) && (bstr[len] == 0)) |
| 377 | { |
| 378 | // Matched! Move this to the front of the list. |
| 379 | if (prev != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 380 | { |
| 381 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(prev->next == bucket); |
| 382 | prev->nextcxx . . $ StringBucket#next. = bucket->nextcxx . . $ StringBucket#next.; |
| 383 | bucket->nextcxx . . $ StringBucket#next. = cache->hashtablecxx . . $ StringCache#hashtable.[hash]; |
| 384 | cache->hashtablecxx . . $ StringCache#hashtable.[hash] = bucket; |
| 385 | } // if |
| 386 | return bstr; // already cached |
| 387 | } // if |
| 388 | prev = bucket; |
| 389 | bucket = bucket->nextcxx . . $ StringBucket#next.; |
| 390 | } // while |
| 391 | |
| 392 | // no match! |
| 393 | if (!addmissing) |
| 394 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 395 | |
| 396 | // add to the table. |
| 397 | bucket = (StringBucketcxx . . $ StringBucket# *) cache->mcxx . . $ StringCache#m.(sizeof (StringBucketcxx . . $ StringBucket#) + len + 1, cache->dcxx . . $ StringCache#d.); |
| 398 | if (bucket == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 399 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 400 | bucket->stringcxx . . $ StringBucket#string. = (char *)(bucket + 1); |
| 401 | memcpycxx . . $ memcpy(cc817cb175f282d).(bucket->stringcxx . . $ StringBucket#string., str, len); |
| 402 | bucket->stringcxx . . $ StringBucket#string.[len] = '\0'; |
| 403 | bucket->nextcxx . . $ StringBucket#next. = cache->hashtablecxx . . $ StringCache#hashtable.[hash]; |
| 404 | cache->hashtablecxx . . $ StringCache#hashtable.[hash] = bucket; |
| 405 | return bucket->stringcxx . . $ StringBucket#string.; |
| 406 | } // stringcache_len_internal |
| 407 | |
| 408 | const char *stringcache_lencxx . . $ stringcache_len(a48eb3d5dcd20ad4).(StringCachecxx . . $ StringCache# *cache, const char *str, |
| 409 | const unsigned int len) |
| 410 | { |
| 411 | return stringcache_len_internalcxx . . $ stringcache_len_internal(d4a11bece8530d8d).(cache, str, len, 1); |
| 412 | } // stringcache_len |
| 413 | |
| 414 | int stringcache_iscachedcxx . . $ stringcache_iscached(4e54f2a32da2e893).(StringCachecxx . . $ StringCache# *cache, const char *str) |
| 415 | { |
| 416 | return (stringcache_len_internalcxx . . $ stringcache_len_internal(d4a11bece8530d8d).(cache, str, strlencxx . . $ strlen(751346f8406fd082).(str), 0) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 417 | } // stringcache_iscached |
| 418 | |
| 419 | const char *stringcache_fmtcxx . . $ stringcache_fmt(ddf619c92e98f8e4).(StringCachecxx . . $ StringCache# *cache, const char *fmt, ...) |
| 420 | { |
| 421 | char buf[128]; // use the stack if reasonable. |
| 422 | char *ptr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 423 | int len = 0; // number of chars, NOT counting null-terminator! |
| 424 | va_listcxx . . $ va_list# ap; |
| 425 | |
| 426 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(ap, fmt); |
| 427 | len = vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(buf, sizeof (buf), fmt, ap); |
| 428 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(ap); |
| 429 | |
| 430 | if (len > sizeof (buf)) |
| 431 | { |
| 432 | ptr = (char *) cache->mcxx . . $ StringCache#m.(len, cache->dcxx . . $ StringCache#d.); |
| 433 | if (ptr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 434 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 435 | |
| 436 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(ap, fmt); |
| 437 | vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(ptr, len, fmt, ap); |
| 438 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(ap); |
| 439 | } // if |
| 440 | |
| 441 | const char *retval = stringcache_lencxx . . $ stringcache_len(a48eb3d5dcd20ad4).(cache, ptr ? ptr : buf, len); |
| 442 | if (ptr != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 443 | cache->fcxx . . $ StringCache#f.(ptr, cache->dcxx . . $ StringCache#d.); |
| 444 | |
| 445 | return retval; |
| 446 | } // stringcache_fmt |
| 447 | |
| 448 | StringCachecxx . . $ StringCache# *stringcache_createcxx . . $ stringcache_create(b4617f7a2c1625cb).(MOJOSHADER_malloccxx . . $ MOJOSHADER_malloc# m, MOJOSHADER_freecxx . . $ MOJOSHADER_free# f, void *d) |
| 449 | { |
| 450 | const uint32cxx . . $ uint32# initial_table_size = 256; |
| 451 | const size_t tablelen = sizeof (StringBucketcxx . . $ StringBucket# *) * initial_table_size; |
| 452 | StringCachecxx . . $ StringCache# *cache = (StringCachecxx . . $ StringCache# *) m(sizeof (StringCachecxx . . $ StringCache#), d); |
| 453 | if (!cache) |
| 454 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 455 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(cache, '\0', sizeof (StringCachecxx . . $ StringCache#)); |
| 456 | |
| 457 | cache->hashtablecxx . . $ StringCache#hashtable. = (StringBucketcxx . . $ StringBucket# **) m(tablelen, d); |
| 458 | if (!cache->hashtablecxx . . $ StringCache#hashtable.) |
| 459 | { |
| 460 | f(cache, d); |
| 461 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 462 | } // if |
| 463 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(cache->hashtablecxx . . $ StringCache#hashtable., '\0', tablelen); |
| 464 | |
| 465 | cache->table_sizecxx . . $ StringCache#table_size. = initial_table_size; |
| 466 | cache->mcxx . . $ StringCache#m. = m; |
| 467 | cache->fcxx . . $ StringCache#f. = f; |
| 468 | cache->dcxx . . $ StringCache#d. = d; |
| 469 | return cache; |
| 470 | } // stringcache_create |
| 471 | |
| 472 | void stringcache_destroycxx . . $ stringcache_destroy(a32b2fea73ec6fd5).(StringCachecxx . . $ StringCache# *cache) |
| 473 | { |
| 474 | if (cache == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 475 | return; |
| 476 | |
| 477 | MOJOSHADER_freecxx . . $ MOJOSHADER_free# f = cache->fcxx . . $ StringCache#f.; |
| 478 | void *d = cache->dcxx . . $ StringCache#d.; |
| 479 | size_t i; |
| 480 | |
| 481 | for (i = 0; i < cache->table_sizecxx . . $ StringCache#table_size.; i++) |
| 482 | { |
| 483 | StringBucketcxx . . $ StringBucket# *bucket = cache->hashtablecxx . . $ StringCache#hashtable.[i]; |
| 484 | cache->hashtablecxx . . $ StringCache#hashtable.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 485 | while (bucket) |
| 486 | { |
| 487 | StringBucketcxx . . $ StringBucket# *next = bucket->nextcxx . . $ StringBucket#next.; |
| 488 | f(bucket, d); |
| 489 | bucket = next; |
| 490 | } // while |
| 491 | } // for |
| 492 | |
| 493 | f(cache->hashtablecxx . . $ StringCache#hashtable., d); |
| 494 | f(cache, d); |
| 495 | } // stringcache_destroy |
| 496 | |
| 497 | |
| 498 | // We chain errors as a linked list with a head/tail for easy appending. |
| 499 | // These get flattened before passing to the application. |
| 500 | typedef struct ErrorItemcxx . . $ ErrorItem# |
| 501 | { |
| 502 | MOJOSHADER_errorcxx . . $ MOJOSHADER_error# errorcxx . . $ ErrorItem#error.; |
| 503 | struct ErrorItemcxx . . $ ErrorItem# *nextcxx . . $ ErrorItem#next.; |
| 504 | } ErrorItemcxx . . $ ErrorItem#; |
| 505 | |
| 506 | struct ErrorListcxx . . $ ErrorList# |
| 507 | { |
| 508 | ErrorItemcxx . . $ ErrorItem# headcxx . . $ ErrorList#head.; |
| 509 | ErrorItemcxx . . $ ErrorItem# *tailcxx . . $ ErrorList#tail.; |
| 510 | int countcxx . . $ ErrorList#count.; |
| 511 | MOJOSHADER_malloccxx . . $ MOJOSHADER_malloc# mcxx . . $ ErrorList#m.; |
| 512 | MOJOSHADER_freecxx . . $ MOJOSHADER_free# fcxx . . $ ErrorList#f.; |
| 513 | void *dcxx . . $ ErrorList#d.; |
| 514 | }; |
| 515 | |
| 516 | ErrorListcxx . . $ ErrorList# *errorlist_createcxx . . $ errorlist_create(509ec232261ad79b).(MOJOSHADER_malloccxx . . $ MOJOSHADER_malloc# m, MOJOSHADER_freecxx . . $ MOJOSHADER_free# f, void *d) |
| 517 | { |
| 518 | ErrorListcxx . . $ ErrorList# *retval = (ErrorListcxx . . $ ErrorList# *) m(sizeof (ErrorListcxx . . $ ErrorList#), d); |
| 519 | if (retval != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 520 | { |
| 521 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(retval, '\0', sizeof (ErrorListcxx . . $ ErrorList#)); |
| 522 | retval->tailcxx . . $ ErrorList#tail. = &retval->headcxx . . $ ErrorList#head.; |
| 523 | retval->mcxx . . $ ErrorList#m. = m; |
| 524 | retval->fcxx . . $ ErrorList#f. = f; |
| 525 | retval->dcxx . . $ ErrorList#d. = d; |
| 526 | } // if |
| 527 | |
| 528 | return retval; |
| 529 | } // errorlist_create |
| 530 | |
| 531 | |
| 532 | int errorlist_addcxx . . $ errorlist_add(347f4457d4600809).(ErrorListcxx . . $ ErrorList# *list, const char *fname, |
| 533 | const int errpos, const char *str) |
| 534 | { |
| 535 | return errorlist_add_fmtcxx . . $ errorlist_add_fmt(e7685dbd98c501da).(list, fname, errpos, "%s", str); |
| 536 | } // errorlist_add |
| 537 | |
| 538 | |
| 539 | int errorlist_add_fmtcxx . . $ errorlist_add_fmt(e7685dbd98c501da).(ErrorListcxx . . $ ErrorList# *list, const char *fname, |
| 540 | const int errpos, const char *fmt, ...) |
| 541 | { |
| 542 | va_listcxx . . $ va_list# ap; |
| 543 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(ap, fmt); |
| 544 | const int retval = errorlist_add_vacxx . . $ errorlist_add_va(97218a3e36e3d3b0).(list, fname, errpos, fmt, ap); |
| 545 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(ap); |
| 546 | return retval; |
| 547 | } // errorlist_add_fmt |
| 548 | |
| 549 | |
| 550 | int errorlist_add_vacxx . . $ errorlist_add_va(97218a3e36e3d3b0).(ErrorListcxx . . $ ErrorList# *list, const char *_fname, |
| 551 | const int errpos, const char *fmt, va_listcxx . . $ va_list# va) |
| 552 | { |
| 553 | ErrorItemcxx . . $ ErrorItem# *error = (ErrorItemcxx . . $ ErrorItem# *) list->mcxx . . $ ErrorList#m.(sizeof (ErrorItemcxx . . $ ErrorItem#), list->dcxx . . $ ErrorList#d.); |
| 554 | if (error == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 555 | return 0; |
| 556 | |
| 557 | char *fname = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 558 | if (_fname != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 559 | { |
| 560 | fname = (char *) list->mcxx . . $ ErrorList#m.(strlencxx . . $ strlen(751346f8406fd082).(_fname) + 1, list->dcxx . . $ ErrorList#d.); |
| 561 | if (fname == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 562 | { |
| 563 | list->fcxx . . $ ErrorList#f.(error, list->dcxx . . $ ErrorList#d.); |
| 564 | return 0; |
| 565 | } // if |
| 566 | strcpycxx . . $ strcpy(b7b3a83273496486).(fname, _fname); |
| 567 | } // if |
| 568 | |
| 569 | char scratch[128]; |
| 570 | va_listcxx . . $ va_list# ap; |
| 571 | va_copycxx . . $ `<external>/8105065126723003039/stdarg.h:56:9`!(ap, va); |
| 572 | int len = vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(scratch, sizeof (scratch), fmt, ap); |
| 573 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(ap); |
| 574 | |
| 575 | // on some versions of the windows C runtime, vsnprintf() returns -1 |
| 576 | // if the buffer overflows instead of the length the string would have |
| 577 | // been as expected. |
| 578 | // In this case we make another copy of va and fetch the length only |
| 579 | // with another call to _vscprintf |
| 580 | |
| 581 | #if defined(_WIN32) && !defined(MOJOSHADER_USE_SDL_STDLIB) |
| 582 | if (len == -1) |
| 583 | { |
| 584 | va_copy(ap, va); |
| 585 | len = _vscprintf(fmt, ap); |
| 586 | va_end(ap); |
| 587 | } |
| 588 | #endif |
| 589 | |
| 590 | char *failstr = (char *) list->mcxx . . $ ErrorList#m.(len + 1, list->dcxx . . $ ErrorList#d.); |
| 591 | if (failstr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 592 | { |
| 593 | list->fcxx . . $ ErrorList#f.(error, list->dcxx . . $ ErrorList#d.); |
| 594 | list->fcxx . . $ ErrorList#f.(fname, list->dcxx . . $ ErrorList#d.); |
| 595 | return 0; |
| 596 | } // if |
| 597 | |
| 598 | // If we overflowed our scratch buffer, that's okay. We were going to |
| 599 | // allocate anyhow...the scratch buffer just lets us avoid a second |
| 600 | // run of vsnprintf(). |
| 601 | if (len < sizeof (scratch)) |
| 602 | strcpycxx . . $ strcpy(b7b3a83273496486).(failstr, scratch); // copy it over. |
| 603 | else |
| 604 | { |
| 605 | va_copycxx . . $ `<external>/8105065126723003039/stdarg.h:56:9`!(ap, va); |
| 606 | vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(failstr, len + 1, fmt, ap); // rebuild it. |
| 607 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(ap); |
| 608 | } // else |
| 609 | |
| 610 | error->errorcxx . . $ ErrorItem#error..errorcxx . . $ MOJOSHADER_error#error. = failstr; |
| 611 | error->errorcxx . . $ ErrorItem#error..filenamecxx . . $ MOJOSHADER_error#filename. = fname; |
| 612 | error->errorcxx . . $ ErrorItem#error..error_positioncxx . . $ MOJOSHADER_error#error_position. = errpos; |
| 613 | error->nextcxx . . $ ErrorItem#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 614 | |
| 615 | list->tailcxx . . $ ErrorList#tail.->nextcxx . . $ ErrorItem#next. = error; |
| 616 | list->tailcxx . . $ ErrorList#tail. = error; |
| 617 | |
| 618 | list->countcxx . . $ ErrorList#count.++; |
| 619 | return 1; |
| 620 | } // errorlist_add_va |
| 621 | |
| 622 | |
| 623 | int errorlist_countcxx . . $ errorlist_count(11e96bbabc88ab8f).(ErrorListcxx . . $ ErrorList# *list) |
| 624 | { |
| 625 | return list->countcxx . . $ ErrorList#count.; |
| 626 | } // errorlist_count |
| 627 | |
| 628 | |
| 629 | MOJOSHADER_errorcxx . . $ MOJOSHADER_error# *errorlist_flattencxx . . $ errorlist_flatten(33ed08000618f0ec).(ErrorListcxx . . $ ErrorList# *list) |
| 630 | { |
| 631 | if (list->countcxx . . $ ErrorList#count. == 0) |
| 632 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 633 | |
| 634 | int total = 0; |
| 635 | MOJOSHADER_errorcxx . . $ MOJOSHADER_error# *retval = (MOJOSHADER_errorcxx . . $ MOJOSHADER_error# *) |
| 636 | list->mcxx . . $ ErrorList#m.(sizeof (MOJOSHADER_errorcxx . . $ MOJOSHADER_error#) * list->countcxx . . $ ErrorList#count., list->dcxx . . $ ErrorList#d.); |
| 637 | if (retval == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 638 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 639 | |
| 640 | ErrorItemcxx . . $ ErrorItem# *item = list->headcxx . . $ ErrorList#head..nextcxx . . $ ErrorItem#next.; |
| 641 | while (item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 642 | { |
| 643 | ErrorItemcxx . . $ ErrorItem# *next = item->nextcxx . . $ ErrorItem#next.; |
| 644 | // reuse the string allocations |
| 645 | memcpycxx . . $ memcpy(cc817cb175f282d).(&retval[total], &item->errorcxx . . $ ErrorItem#error., sizeof (MOJOSHADER_errorcxx . . $ MOJOSHADER_error#)); |
| 646 | list->fcxx . . $ ErrorList#f.(item, list->dcxx . . $ ErrorList#d.); |
| 647 | item = next; |
| 648 | total++; |
| 649 | } // while |
| 650 | |
| 651 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(total == list->count); |
| 652 | list->countcxx . . $ ErrorList#count. = 0; |
| 653 | list->headcxx . . $ ErrorList#head..nextcxx . . $ ErrorItem#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 654 | list->tailcxx . . $ ErrorList#tail. = &list->headcxx . . $ ErrorList#head.; |
| 655 | return retval; |
| 656 | } // errorlist_flatten |
| 657 | |
| 658 | |
| 659 | void errorlist_destroycxx . . $ errorlist_destroy(a656397e2b0a5308).(ErrorListcxx . . $ ErrorList# *list) |
| 660 | { |
| 661 | if (list == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 662 | return; |
| 663 | |
| 664 | MOJOSHADER_freecxx . . $ MOJOSHADER_free# f = list->fcxx . . $ ErrorList#f.; |
| 665 | void *d = list->dcxx . . $ ErrorList#d.; |
| 666 | ErrorItemcxx . . $ ErrorItem# *item = list->headcxx . . $ ErrorList#head..nextcxx . . $ ErrorItem#next.; |
| 667 | while (item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 668 | { |
| 669 | ErrorItemcxx . . $ ErrorItem# *next = item->nextcxx . . $ ErrorItem#next.; |
| 670 | f((void *) item->errorcxx . . $ ErrorItem#error..errorcxx . . $ MOJOSHADER_error#error., d); |
| 671 | f((void *) item->errorcxx . . $ ErrorItem#error..filenamecxx . . $ MOJOSHADER_error#filename., d); |
| 672 | f(item, d); |
| 673 | item = next; |
| 674 | } // while |
| 675 | f(list, d); |
| 676 | } // errorlist_destroy |
| 677 | |
| 678 | |
| 679 | Buffercxx . . $ Buffer# *buffer_createcxx . . $ buffer_create(76a014b9fd4a8dd).(size_t blksz, MOJOSHADER_malloccxx . . $ MOJOSHADER_malloc# m, |
| 680 | MOJOSHADER_freecxx . . $ MOJOSHADER_free# f, void *d) |
| 681 | { |
| 682 | Buffercxx . . $ Buffer# *buffer = (Buffercxx . . $ Buffer# *) m(sizeof (Buffercxx . . $ Buffer#), d); |
| 683 | if (buffer != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 684 | { |
| 685 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(buffer, '\0', sizeof (Buffercxx . . $ Buffer#)); |
| 686 | buffer->block_sizecxx . . $ Buffer#block_size. = blksz; |
| 687 | buffer->mcxx . . $ Buffer#m. = m; |
| 688 | buffer->fcxx . . $ Buffer#f. = f; |
| 689 | buffer->dcxx . . $ Buffer#d. = d; |
| 690 | } // if |
| 691 | return buffer; |
| 692 | } // buffer_create |
| 693 | |
| 694 | char *buffer_reservecxx . . $ buffer_reserve(52966bd6b1ee8fbe).(Buffercxx . . $ Buffer# *buffer, const size_t len) |
| 695 | { |
| 696 | // note that we make the blocks bigger than blocksize when we have enough |
| 697 | // data to overfill a fresh block, to reduce allocations. |
| 698 | const size_t blocksize = buffer->block_sizecxx . . $ Buffer#block_size.; |
| 699 | |
| 700 | if (len == 0) |
| 701 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 702 | |
| 703 | if (buffer->tailcxx . . $ Buffer#tail. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 704 | { |
| 705 | const size_t tailbytes = buffer->tailcxx . . $ Buffer#tail.->bytescxx . . $ BufferBlock#bytes.; |
| 706 | const size_t avail = (tailbytes >= blocksize) ? 0 : blocksize - tailbytes; |
| 707 | if (len <= avail) |
| 708 | { |
| 709 | buffer->tailcxx . . $ Buffer#tail.->bytescxx . . $ BufferBlock#bytes. += len; |
| 710 | buffer->total_bytescxx . . $ Buffer#total_bytes. += len; |
| 711 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(buffer->tail->bytes <= blocksize); |
| 712 | return (char *) buffer->tailcxx . . $ Buffer#tail.->datacxx . . $ BufferBlock#data. + tailbytes; |
| 713 | } // if |
| 714 | } // if |
| 715 | |
| 716 | // need to allocate a new block (even if a previous block wasn't filled, |
| 717 | // so this buffer is contiguous). |
| 718 | const size_t bytecount = len > blocksize ? len : blocksize; |
| 719 | const size_t malloc_len = sizeof (BufferBlockcxx . . $ BufferBlock#) + bytecount; |
| 720 | BufferBlockcxx . . $ BufferBlock# *item = (BufferBlockcxx . . $ BufferBlock# *) buffer->mcxx . . $ Buffer#m.(malloc_len, buffer->dcxx . . $ Buffer#d.); |
| 721 | if (item == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 722 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 723 | |
| 724 | item->datacxx . . $ BufferBlock#data. = ((uint8cxx . . $ uint8# *) item) + sizeof (BufferBlockcxx . . $ BufferBlock#); |
| 725 | item->bytescxx . . $ BufferBlock#bytes. = len; |
| 726 | item->nextcxx . . $ BufferBlock#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 727 | if (buffer->tailcxx . . $ Buffer#tail. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 728 | buffer->tailcxx . . $ Buffer#tail.->nextcxx . . $ BufferBlock#next. = item; |
| 729 | else |
| 730 | buffer->headcxx . . $ Buffer#head. = item; |
| 731 | buffer->tailcxx . . $ Buffer#tail. = item; |
| 732 | |
| 733 | buffer->total_bytescxx . . $ Buffer#total_bytes. += len; |
| 734 | |
| 735 | return (char *) item->datacxx . . $ BufferBlock#data.; |
| 736 | } // buffer_reserve |
| 737 | |
| 738 | int buffer_appendcxx . . $ buffer_append(e4e8268775a9929a).(Buffercxx . . $ Buffer# *buffer, const void *_data, size_t len) |
| 739 | { |
| 740 | const uint8cxx . . $ uint8# *data = (const uint8cxx . . $ uint8# *) _data; |
| 741 | |
| 742 | // note that we make the blocks bigger than blocksize when we have enough |
| 743 | // data to overfill a fresh block, to reduce allocations. |
| 744 | const size_t blocksize = buffer->block_sizecxx . . $ Buffer#block_size.; |
| 745 | |
| 746 | if (len == 0) |
| 747 | return 1; |
| 748 | |
| 749 | if (buffer->tailcxx . . $ Buffer#tail. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 750 | { |
| 751 | const size_t tailbytes = buffer->tailcxx . . $ Buffer#tail.->bytescxx . . $ BufferBlock#bytes.; |
| 752 | const size_t avail = (tailbytes >= blocksize) ? 0 : blocksize - tailbytes; |
| 753 | const size_t cpy = (avail > len) ? len : avail; |
| 754 | if (cpy > 0) |
| 755 | { |
| 756 | memcpycxx . . $ memcpy(cc817cb175f282d).(buffer->tailcxx . . $ Buffer#tail.->datacxx . . $ BufferBlock#data. + tailbytes, data, cpy); |
| 757 | len -= cpy; |
| 758 | data += cpy; |
| 759 | buffer->tailcxx . . $ Buffer#tail.->bytescxx . . $ BufferBlock#bytes. += cpy; |
| 760 | buffer->total_bytescxx . . $ Buffer#total_bytes. += cpy; |
| 761 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(buffer->tail->bytes <= blocksize); |
| 762 | } // if |
| 763 | } // if |
| 764 | |
| 765 | if (len > 0) |
| 766 | { |
| 767 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((!buffer->tail) || (buffer->tail->bytes >= blocksize)); |
| 768 | const size_t bytecount = len > blocksize ? len : blocksize; |
| 769 | const size_t malloc_len = sizeof (BufferBlockcxx . . $ BufferBlock#) + bytecount; |
| 770 | BufferBlockcxx . . $ BufferBlock# *item = (BufferBlockcxx . . $ BufferBlock# *) buffer->mcxx . . $ Buffer#m.(malloc_len, buffer->dcxx . . $ Buffer#d.); |
| 771 | if (item == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 772 | return 0; |
| 773 | |
| 774 | item->datacxx . . $ BufferBlock#data. = ((uint8cxx . . $ uint8# *) item) + sizeof (BufferBlockcxx . . $ BufferBlock#); |
| 775 | item->bytescxx . . $ BufferBlock#bytes. = len; |
| 776 | item->nextcxx . . $ BufferBlock#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 777 | if (buffer->tailcxx . . $ Buffer#tail. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 778 | buffer->tailcxx . . $ Buffer#tail.->nextcxx . . $ BufferBlock#next. = item; |
| 779 | else |
| 780 | buffer->headcxx . . $ Buffer#head. = item; |
| 781 | buffer->tailcxx . . $ Buffer#tail. = item; |
| 782 | |
| 783 | memcpycxx . . $ memcpy(cc817cb175f282d).(item->datacxx . . $ BufferBlock#data., data, len); |
| 784 | buffer->total_bytescxx . . $ Buffer#total_bytes. += len; |
| 785 | } // if |
| 786 | |
| 787 | return 1; |
| 788 | } // buffer_append |
| 789 | |
| 790 | int buffer_append_fmtcxx . . $ buffer_append_fmt(32cad238001a2625).(Buffercxx . . $ Buffer# *buffer, const char *fmt, ...) |
| 791 | { |
| 792 | va_listcxx . . $ va_list# ap; |
| 793 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(ap, fmt); |
| 794 | const int retval = buffer_append_vacxx . . $ buffer_append_va(70652df479affa1f).(buffer, fmt, ap); |
| 795 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(ap); |
| 796 | return retval; |
| 797 | } // buffer_append_fmt |
| 798 | |
| 799 | int buffer_append_vacxx . . $ buffer_append_va(70652df479affa1f).(Buffercxx . . $ Buffer# *buffer, const char *fmt, va_listcxx . . $ va_list# va) |
| 800 | { |
| 801 | char scratch[256]; |
| 802 | |
| 803 | va_listcxx . . $ va_list# ap; |
| 804 | va_copycxx . . $ `<external>/8105065126723003039/stdarg.h:56:9`!(ap, va); |
| 805 | const int len = vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(scratch, sizeof (scratch), fmt, ap); |
| 806 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(ap); |
| 807 | |
| 808 | // If we overflowed our scratch buffer, heap allocate and try again. |
| 809 | |
| 810 | if (len == 0) |
| 811 | return 1; // nothing to do. |
| 812 | else if (len < sizeof (scratch)) |
| 813 | return buffer_appendcxx . . $ buffer_append(e4e8268775a9929a).(buffer, scratch, len); |
| 814 | |
| 815 | char *buf = (char *) buffer->mcxx . . $ Buffer#m.(len + 1, buffer->dcxx . . $ Buffer#d.); |
| 816 | if (buf == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 817 | return 0; |
| 818 | va_copycxx . . $ `<external>/8105065126723003039/stdarg.h:56:9`!(ap, va); |
| 819 | vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(buf, len + 1, fmt, ap); // rebuild it. |
| 820 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(ap); |
| 821 | const int retval = buffer_appendcxx . . $ buffer_append(e4e8268775a9929a).(buffer, buf, len); |
| 822 | buffer->fcxx . . $ Buffer#f.(buf, buffer->dcxx . . $ Buffer#d.); |
| 823 | return retval; |
| 824 | } // buffer_append_va |
| 825 | |
| 826 | size_t buffer_sizecxx . . $ buffer_size(ecc380cc53efe3bc).(Buffercxx . . $ Buffer# *buffer) |
| 827 | { |
| 828 | return buffer->total_bytescxx . . $ Buffer#total_bytes.; |
| 829 | } // buffer_size |
| 830 | |
| 831 | void buffer_emptycxx . . $ buffer_empty(bc6579b1763bded2).(Buffercxx . . $ Buffer# *buffer) |
| 832 | { |
| 833 | BufferBlockcxx . . $ BufferBlock# *item = buffer->headcxx . . $ Buffer#head.; |
| 834 | while (item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 835 | { |
| 836 | BufferBlockcxx . . $ BufferBlock# *next = item->nextcxx . . $ BufferBlock#next.; |
| 837 | buffer->fcxx . . $ Buffer#f.(item, buffer->dcxx . . $ Buffer#d.); |
| 838 | item = next; |
| 839 | } // while |
| 840 | buffer->headcxx . . $ Buffer#head. = buffer->tailcxx . . $ Buffer#tail. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 841 | buffer->total_bytescxx . . $ Buffer#total_bytes. = 0; |
| 842 | } // buffer_empty |
| 843 | |
| 844 | char *buffer_flattencxx . . $ buffer_flatten(4b7117bbdee3d5c9).(Buffercxx . . $ Buffer# *buffer) |
| 845 | { |
| 846 | char *retval = (char *) buffer->mcxx . . $ Buffer#m.(buffer->total_bytescxx . . $ Buffer#total_bytes. + 1, buffer->dcxx . . $ Buffer#d.); |
| 847 | if (retval == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 848 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 849 | BufferBlockcxx . . $ BufferBlock# *item = buffer->headcxx . . $ Buffer#head.; |
| 850 | char *ptr = retval; |
| 851 | while (item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 852 | { |
| 853 | BufferBlockcxx . . $ BufferBlock# *next = item->nextcxx . . $ BufferBlock#next.; |
| 854 | memcpycxx . . $ memcpy(cc817cb175f282d).(ptr, item->datacxx . . $ BufferBlock#data., item->bytescxx . . $ BufferBlock#bytes.); |
| 855 | ptr += item->bytescxx . . $ BufferBlock#bytes.; |
| 856 | buffer->fcxx . . $ Buffer#f.(item, buffer->dcxx . . $ Buffer#d.); |
| 857 | item = next; |
| 858 | } // while |
| 859 | *ptr = '\0'; |
| 860 | |
| 861 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(ptr == (retval + buffer->total_bytes)); |
| 862 | |
| 863 | buffer->headcxx . . $ Buffer#head. = buffer->tailcxx . . $ Buffer#tail. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 864 | buffer->total_bytescxx . . $ Buffer#total_bytes. = 0; |
| 865 | |
| 866 | return retval; |
| 867 | } // buffer_flatten |
| 868 | |
| 869 | char *buffer_mergecxx . . $ buffer_merge(ec59a92c7b10b67c).(Buffercxx . . $ Buffer# **buffers, const size_t n, size_t *_len) |
| 870 | { |
| 871 | Buffercxx . . $ Buffer# *first = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 872 | size_t len = 0; |
| 873 | size_t i; |
| 874 | for (i = 0; i < n; i++) |
| 875 | { |
| 876 | Buffercxx . . $ Buffer# *buffer = buffers[i]; |
| 877 | if (buffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 878 | continue; |
| 879 | if (first == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 880 | first = buffer; |
| 881 | len += buffer->total_bytescxx . . $ Buffer#total_bytes.; |
| 882 | } // for |
| 883 | |
| 884 | char *retval = (char *) (first ? first->mcxx . . $ Buffer#m.(len + 1, first->dcxx . . $ Buffer#d.) : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 885 | if (retval == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 886 | { |
| 887 | *_len = 0; |
| 888 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 889 | } // if |
| 890 | |
| 891 | *_len = len; |
| 892 | char *ptr = retval; |
| 893 | for (i = 0; i < n; i++) |
| 894 | { |
| 895 | Buffercxx . . $ Buffer# *buffer = buffers[i]; |
| 896 | if (buffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 897 | continue; |
| 898 | BufferBlockcxx . . $ BufferBlock# *item = buffer->headcxx . . $ Buffer#head.; |
| 899 | while (item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 900 | { |
| 901 | BufferBlockcxx . . $ BufferBlock# *next = item->nextcxx . . $ BufferBlock#next.; |
| 902 | memcpycxx . . $ memcpy(cc817cb175f282d).(ptr, item->datacxx . . $ BufferBlock#data., item->bytescxx . . $ BufferBlock#bytes.); |
| 903 | ptr += item->bytescxx . . $ BufferBlock#bytes.; |
| 904 | buffer->fcxx . . $ Buffer#f.(item, buffer->dcxx . . $ Buffer#d.); |
| 905 | item = next; |
| 906 | } // while |
| 907 | |
| 908 | buffer->headcxx . . $ Buffer#head. = buffer->tailcxx . . $ Buffer#tail. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 909 | buffer->total_bytescxx . . $ Buffer#total_bytes. = 0; |
| 910 | } // for |
| 911 | *ptr = '\0'; |
| 912 | |
| 913 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(ptr == (retval + len)); |
| 914 | |
| 915 | return retval; |
| 916 | } // buffer_merge |
| 917 | |
| 918 | void buffer_destroycxx . . $ buffer_destroy(bc6579b1763bded2).(Buffercxx . . $ Buffer# *buffer) |
| 919 | { |
| 920 | if (buffer != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 921 | { |
| 922 | MOJOSHADER_freecxx . . $ MOJOSHADER_free# f = buffer->fcxx . . $ Buffer#f.; |
| 923 | void *d = buffer->dcxx . . $ Buffer#d.; |
| 924 | buffer_emptycxx . . $ buffer_empty(bc6579b1763bded2).(buffer); |
| 925 | f(buffer, d); |
| 926 | } // if |
| 927 | } // buffer_destroy |
| 928 | |
| 929 | void buffer_patchcxx . . $ buffer_patch(b50c5e09500c0639).(Buffercxx . . $ Buffer# *buffer, const size_t start, |
| 930 | const void *_data, const size_t len) |
| 931 | { |
| 932 | if (len == 0) |
| 933 | return; // Nothing to do. |
| 934 | |
| 935 | if ((start + len) > buffer->total_bytescxx . . $ Buffer#total_bytes.) |
| 936 | return; // definitely can't patch. |
| 937 | |
| 938 | // Find the start point somewhere in the center of a buffer. |
| 939 | BufferBlockcxx . . $ BufferBlock# *item = buffer->headcxx . . $ Buffer#head.; |
| 940 | size_t pos = 0; |
| 941 | if (start > 0) |
| 942 | { |
| 943 | while (1) |
| 944 | { |
| 945 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 946 | if ((pos + item->bytescxx . . $ BufferBlock#bytes.) > start) // start is in this block. |
| 947 | break; |
| 948 | |
| 949 | pos += item->bytescxx . . $ BufferBlock#bytes.; |
| 950 | item = item->nextcxx . . $ BufferBlock#next.; |
| 951 | } // while |
| 952 | } // if |
| 953 | |
| 954 | const uint8cxx . . $ uint8# *data = (const uint8cxx . . $ uint8# *) _data; |
| 955 | size_t write_pos = start - pos; |
| 956 | size_t write_remain = len; |
| 957 | size_t written = 0; |
| 958 | while (write_remain) |
| 959 | { |
| 960 | size_t write_end = write_pos + write_remain; |
| 961 | if (write_end > item->bytescxx . . $ BufferBlock#bytes.) |
| 962 | write_end = item->bytescxx . . $ BufferBlock#bytes.; |
| 963 | |
| 964 | size_t to_write = write_end - write_pos; |
| 965 | memcpycxx . . $ memcpy(cc817cb175f282d).(item->datacxx . . $ BufferBlock#data. + write_pos, data + written, to_write); |
| 966 | write_remain -= to_write; |
| 967 | written += to_write; |
| 968 | write_pos = 0; |
| 969 | item = item->nextcxx . . $ BufferBlock#next.; |
| 970 | } // while |
| 971 | } // buffer_patch |
| 972 | |
| 973 | // Based on SDL_string.c's SDL_PrintFloat function |
| 974 | size_t MOJOSHADER_printFloatcxx . . $ MOJOSHADER_printFloat(d760c2ad178ccd37).(char *text, size_t maxlen, float arg) |
| 975 | { |
| 976 | size_t len; |
| 977 | size_t left = maxlen; |
| 978 | char *textstart = text; |
| 979 | |
| 980 | int precision = 9; |
| 981 | |
| 982 | if (isnancxx . . $ `<external>/11263917310783833665/math.h:980:11`!(arg)) |
| 983 | { |
| 984 | if (left > 3) |
| 985 | { |
| 986 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(text, left, "NaN"); |
| 987 | left -= 3; |
| 988 | } // if |
| 989 | text += 3; |
| 990 | } // if |
| 991 | else if (isinfcxx . . $ `<external>/11263917310783833665/math.h:999:11`!(arg)) |
| 992 | { |
| 993 | if (left > 3) |
| 994 | { |
| 995 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(text, left, "inf"); |
| 996 | left -= 3; |
| 997 | } // if |
| 998 | text += 3; |
| 999 | } // else if |
| 1000 | else if (arg) |
| 1001 | { |
| 1002 | /* This isn't especially accurate, but hey, it's easy. :) */ |
| 1003 | unsigned long value; |
| 1004 | |
| 1005 | if (arg < 0) |
| 1006 | { |
| 1007 | if (left > 1) |
| 1008 | { |
| 1009 | *text = '-'; |
| 1010 | --left; |
| 1011 | } // if |
| 1012 | ++text; |
| 1013 | arg = -arg; |
| 1014 | } // if |
| 1015 | value = (unsigned long) arg; |
| 1016 | len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(text, left, "%lu", value); |
| 1017 | text += len; |
| 1018 | if (len >= left) |
| 1019 | left = (left < 1) ? left : 1; |
| 1020 | else |
| 1021 | left -= len; |
| 1022 | arg -= value; |
| 1023 | |
| 1024 | int mult = 10; |
| 1025 | if (left > 1) |
| 1026 | { |
| 1027 | *text = '.'; |
| 1028 | --left; |
| 1029 | } // if |
| 1030 | ++text; |
| 1031 | while (precision-- > 0) |
| 1032 | { |
| 1033 | value = (unsigned long) (arg * mult); |
| 1034 | len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(text, left, "%lu", value); |
| 1035 | text += len; |
| 1036 | if (len >= left) |
| 1037 | left = (left < 1) ? left : 1; |
| 1038 | else |
| 1039 | left -= len; |
| 1040 | arg -= (double) value / mult; |
| 1041 | if (arg < 0) arg = -arg; // Sometimes that bit gets flipped... |
| 1042 | mult *= 10; |
| 1043 | } // while |
| 1044 | } // if |
| 1045 | else |
| 1046 | { |
| 1047 | if (left > 3) |
| 1048 | { |
| 1049 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(text, left, "0.0"); |
| 1050 | left -= 3; |
| 1051 | } // if |
| 1052 | text += 3; |
| 1053 | } // else |
| 1054 | |
| 1055 | return (text - textstart); |
| 1056 | } // MOJOSHADER_printFloat |
| 1057 | |
| 1058 | #if SUPPORT_PROFILE_SPIRVcxx . . $ `mojoshader_internal.h:210:9`! |
| 1059 | #include "spirv/spirv.h"cxx . . $ `<file>/spirv/spirv.h`/ |
| 1060 | #include "spirv/GLSL.std.450.h"cxx . . $ `<file>/spirv/GLSL.std.450.h`/ |
| 1061 | void MOJOSHADER_spirv_link_attributescxx . . $ MOJOSHADER_spirv_link_attributes(8985aed79211bd0).(const MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData# *vertex, |
| 1062 | const MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData# *pixel, |
| 1063 | int is_glspirv) |
| 1064 | { |
| 1065 | int i; |
| 1066 | uint32cxx . . $ uint32# attr_loc = 0; |
| 1067 | uint32cxx . . $ uint32# vOffset, pOffset; |
| 1068 | int vDataLen = vertex->output_lencxx . . $ MOJOSHADER_parseData#output_len. - sizeof(SpirvPatchTablecxx . . $ SpirvPatchTable#); |
| 1069 | int pDataLen = pixel->output_lencxx . . $ MOJOSHADER_parseData#output_len. - sizeof(SpirvPatchTablecxx . . $ SpirvPatchTable#); |
| 1070 | SpirvPatchTablecxx . . $ SpirvPatchTable# *vTable = (SpirvPatchTablecxx . . $ SpirvPatchTable# *) &vertex->outputcxx . . $ MOJOSHADER_parseData#output.[vDataLen]; |
| 1071 | SpirvPatchTablecxx . . $ SpirvPatchTable# *pTable = (SpirvPatchTablecxx . . $ SpirvPatchTable# *) &pixel->outputcxx . . $ MOJOSHADER_parseData#output.[pDataLen]; |
| 1072 | const uint32cxx . . $ uint32# texcoord0Loc = pTable->attrib_offsetscxx . . $ SpirvPatchTable#attrib_offsets.[MOJOSHADER_USAGE_TEXCOORDcxx . . $ MOJOSHADER_USAGE_TEXCOORD.][0]; |
| 1073 | |
| 1074 | if (is_glspirv) |
| 1075 | { |
| 1076 | // We need locations for color outputs first! |
| 1077 | for (i = 0; i < pixel->output_countcxx . . $ MOJOSHADER_parseData#output_count.; i++) |
| 1078 | { |
| 1079 | const MOJOSHADER_attributecxx . . $ MOJOSHADER_attribute#* pAttr = &pixel->outputscxx . . $ MOJOSHADER_parseData#outputs.[i]; |
| 1080 | if (pAttr->usagecxx . . $ MOJOSHADER_attribute#usage. != MOJOSHADER_USAGE_COLORcxx . . $ MOJOSHADER_USAGE_COLOR.) |
| 1081 | { |
| 1082 | // This should be FragDepth, which is builtin |
| 1083 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(pAttr->usage == MOJOSHADER_USAGE_DEPTH); |
| 1084 | continue; |
| 1085 | } // if |
| 1086 | |
| 1087 | // Set the loc for the output declaration... |
| 1088 | pOffset = pTable->output_offsetscxx . . $ SpirvPatchTable#output_offsets.[pAttr->indexcxx . . $ MOJOSHADER_attribute#index.]; |
| 1089 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(pOffset > 0); |
| 1090 | ((uint32cxx . . $ uint32#*)pixel->outputcxx . . $ MOJOSHADER_parseData#output.)[pOffset] = attr_loc; |
| 1091 | |
| 1092 | // Set the same value for the vertex output/pixel input... |
| 1093 | pOffset = pTable->attrib_offsetscxx . . $ SpirvPatchTable#attrib_offsets.[pAttr->usagecxx . . $ MOJOSHADER_attribute#usage.][pAttr->indexcxx . . $ MOJOSHADER_attribute#index.]; |
| 1094 | if (pOffset) |
| 1095 | ((uint32cxx . . $ uint32#*)pixel->outputcxx . . $ MOJOSHADER_parseData#output.)[pOffset] = attr_loc; |
| 1096 | vOffset = vTable->attrib_offsetscxx . . $ SpirvPatchTable#attrib_offsets.[pAttr->usagecxx . . $ MOJOSHADER_attribute#usage.][pAttr->indexcxx . . $ MOJOSHADER_attribute#index.]; |
| 1097 | if (vOffset) |
| 1098 | ((uint32cxx . . $ uint32#*)vertex->outputcxx . . $ MOJOSHADER_parseData#output.)[vOffset] = attr_loc; |
| 1099 | |
| 1100 | // ... increment location index, finally. |
| 1101 | attr_loc++; |
| 1102 | } // for |
| 1103 | } |
| 1104 | |
| 1105 | // Okay, now we can start linking pixel/vertex attributes |
| 1106 | for (i = 0; i < pixel->attribute_countcxx . . $ MOJOSHADER_parseData#attribute_count.; i++) |
| 1107 | { |
| 1108 | const MOJOSHADER_attributecxx . . $ MOJOSHADER_attribute# *pAttr = &pixel->attributescxx . . $ MOJOSHADER_parseData#attributes.[i]; |
| 1109 | if (pAttr->usagecxx . . $ MOJOSHADER_attribute#usage. == MOJOSHADER_USAGE_UNKNOWNcxx . . $ MOJOSHADER_USAGE_UNKNOWN.) |
| 1110 | continue; // Probably something like VPOS, ignore! |
| 1111 | if (pAttr->usagecxx . . $ MOJOSHADER_attribute#usage. == MOJOSHADER_USAGE_DEPTHcxx . . $ MOJOSHADER_USAGE_DEPTH.) |
| 1112 | continue; // This should be FragDepth, which is builtin |
| 1113 | if (is_glspirv && pAttr->usagecxx . . $ MOJOSHADER_attribute#usage. == MOJOSHADER_USAGE_COLORcxx . . $ MOJOSHADER_USAGE_COLOR. && pTable->output_offsetscxx . . $ SpirvPatchTable#output_offsets.[pAttr->indexcxx . . $ MOJOSHADER_attribute#index.]) |
| 1114 | continue; |
| 1115 | |
| 1116 | // The input may not exist in the output list! |
| 1117 | pOffset = pTable->attrib_offsetscxx . . $ SpirvPatchTable#attrib_offsets.[pAttr->usagecxx . . $ MOJOSHADER_attribute#usage.][pAttr->indexcxx . . $ MOJOSHADER_attribute#index.]; |
| 1118 | vOffset = vTable->attrib_offsetscxx . . $ SpirvPatchTable#attrib_offsets.[pAttr->usagecxx . . $ MOJOSHADER_attribute#usage.][pAttr->indexcxx . . $ MOJOSHADER_attribute#index.]; |
| 1119 | ((uint32cxx . . $ uint32# *) pixel->outputcxx . . $ MOJOSHADER_parseData#output.)[pOffset] = attr_loc; |
| 1120 | if (vOffset) |
| 1121 | ((uint32cxx . . $ uint32# *) vertex->outputcxx . . $ MOJOSHADER_parseData#output.)[vOffset] = attr_loc; |
| 1122 | attr_loc++; |
| 1123 | } // for |
| 1124 | |
| 1125 | // There may be outputs not present in the input list! |
| 1126 | for (i = 0; i < vertex->output_countcxx . . $ MOJOSHADER_parseData#output_count.; i++) |
| 1127 | { |
| 1128 | const MOJOSHADER_attributecxx . . $ MOJOSHADER_attribute# *vAttr = &vertex->outputscxx . . $ MOJOSHADER_parseData#outputs.[i]; |
| 1129 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(vAttr->usage != MOJOSHADER_USAGE_UNKNOWN); |
| 1130 | if (vAttr->usagecxx . . $ MOJOSHADER_attribute#usage. == MOJOSHADER_USAGE_POSITIONcxx . . $ MOJOSHADER_USAGE_POSITION. && vAttr->indexcxx . . $ MOJOSHADER_attribute#index. == 0) |
| 1131 | continue; |
| 1132 | if (vAttr->usagecxx . . $ MOJOSHADER_attribute#usage. == MOJOSHADER_USAGE_POINTSIZEcxx . . $ MOJOSHADER_USAGE_POINTSIZE. && vAttr->indexcxx . . $ MOJOSHADER_attribute#index. == 0) |
| 1133 | continue; |
| 1134 | if (is_glspirv && vAttr->usagecxx . . $ MOJOSHADER_attribute#usage. == MOJOSHADER_USAGE_COLORcxx . . $ MOJOSHADER_USAGE_COLOR. && pTable->output_offsetscxx . . $ SpirvPatchTable#output_offsets.[vAttr->indexcxx . . $ MOJOSHADER_attribute#index.]) |
| 1135 | continue; |
| 1136 | |
| 1137 | if (!pTable->attrib_offsetscxx . . $ SpirvPatchTable#attrib_offsets.[vAttr->usagecxx . . $ MOJOSHADER_attribute#usage.][vAttr->indexcxx . . $ MOJOSHADER_attribute#index.]) |
| 1138 | { |
| 1139 | vOffset = vTable->attrib_offsetscxx . . $ SpirvPatchTable#attrib_offsets.[vAttr->usagecxx . . $ MOJOSHADER_attribute#usage.][vAttr->indexcxx . . $ MOJOSHADER_attribute#index.]; |
| 1140 | ((uint32cxx . . $ uint32# *) vertex->outputcxx . . $ MOJOSHADER_parseData#output.)[vOffset] = attr_loc++; |
| 1141 | } // if |
| 1142 | } // for |
| 1143 | |
| 1144 | // gl_PointCoord support |
| 1145 | if (texcoord0Loc) |
| 1146 | { |
| 1147 | if (vTable->attrib_offsetscxx . . $ SpirvPatchTable#attrib_offsets.[MOJOSHADER_USAGE_POINTSIZEcxx . . $ MOJOSHADER_USAGE_POINTSIZE.][0] > 0) |
| 1148 | { |
| 1149 | ((uint32cxx . . $ uint32# *) pixel->outputcxx . . $ MOJOSHADER_parseData#output.)[pTable->pointcoord_var_offsetcxx . . $ SpirvPatchTable#pointcoord_var_offset. + 1] = pTable->tid_pvec2icxx . . $ SpirvPatchTable#tid_pvec2i.; |
| 1150 | ((uint32cxx . . $ uint32# *) pixel->outputcxx . . $ MOJOSHADER_parseData#output.)[pTable->pointcoord_load_offsetcxx . . $ SpirvPatchTable#pointcoord_load_offset. + 1] = pTable->tid_vec2cxx . . $ SpirvPatchTable#tid_vec2.; |
| 1151 | ((uint32cxx . . $ uint32# *) pixel->outputcxx . . $ MOJOSHADER_parseData#output.)[texcoord0Loc - 1] = SpvDecorationBuiltIncxx . . $ SpvDecorationBuiltIn.; |
| 1152 | ((uint32cxx . . $ uint32# *) pixel->outputcxx . . $ MOJOSHADER_parseData#output.)[texcoord0Loc] = SpvBuiltInPointCoordcxx . . $ SpvBuiltInPointCoord.; |
| 1153 | } // if |
| 1154 | else |
| 1155 | { |
| 1156 | ((uint32cxx . . $ uint32# *) pixel->outputcxx . . $ MOJOSHADER_parseData#output.)[pTable->pointcoord_var_offsetcxx . . $ SpirvPatchTable#pointcoord_var_offset. + 1] = pTable->tid_pvec4icxx . . $ SpirvPatchTable#tid_pvec4i.; |
| 1157 | ((uint32cxx . . $ uint32# *) pixel->outputcxx . . $ MOJOSHADER_parseData#output.)[pTable->pointcoord_load_offsetcxx . . $ SpirvPatchTable#pointcoord_load_offset. + 1] = pTable->tid_vec4cxx . . $ SpirvPatchTable#tid_vec4.; |
| 1158 | ((uint32cxx . . $ uint32# *) pixel->outputcxx . . $ MOJOSHADER_parseData#output.)[texcoord0Loc - 1] = SpvDecorationLocationcxx . . $ SpvDecorationLocation.; |
| 1159 | // texcoord0Loc should already have attr_loc from the above work! |
| 1160 | } // else |
| 1161 | } // if |
| 1162 | } // MOJOSHADER_spirv_link_attributes |
| 1163 | #endif |
| 1164 | |
| 1165 | // end of mojoshader_common.c ... |
| 1166 |