Blender V4.3
makesdna.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
27#define DNA_DEPRECATED_ALLOW
28
29#include <algorithm>
30#include <cctype>
31#include <cstdio>
32#include <cstdlib>
33#include <cstring>
34
35#include "MEM_guardedalloc.h"
36
37#include "BLI_alloca.h"
38#include "BLI_ghash.h"
39#include "BLI_memarena.h"
40#include "BLI_string.h"
41#include "BLI_sys_types.h" /* for intptr_t support */
42#include "BLI_system.h" /* for 'BLI_system_backtrace' stub. */
43#include "BLI_utildefines.h"
44
45#include "DNA_sdna_types.h"
46#include "dna_utils.h"
47
48#define SDNA_MAX_FILENAME_LENGTH 255
49
50/* The include file below is automatically generated from the `SRC_DNA_INC`
51 * variable in 'source/blender/CMakeLists.txt'. */
52static const char *includefiles[] = {
53#include "dna_includes_as_strings.h"
54 /* Empty string to indicate end of include files. */
55 "",
56};
57
58/* -------------------------------------------------------------------- */
62static MemArena *mem_arena = nullptr;
63
64static int max_data_size = 500000, max_array_len = 50000;
65static int members_num = 0;
66static int types_num = 0;
67static int structs_num = 0;
69static char **members;
71static char **types;
73static short *types_size_native;
75static short *types_align_32;
77static short *types_align_64;
79static short *types_size_32;
81static short *types_size_64;
88static short **structs, *structdata;
89
91static struct {
96} g_version_data = {nullptr};
97
106static int debugSDNA = 0;
108
109#define DEBUG_PRINTF(debug_level, ...) \
110 { \
111 if (debugSDNA > debug_level) { \
112 printf(__VA_ARGS__); \
113 } \
114 } \
115 ((void)0)
116
117/* stub for BLI_abort() */
118#ifndef NDEBUG
120{
121 (void)fp;
122}
123#endif
124
127/* -------------------------------------------------------------------- */
137static int add_type(const char *type_name, int size);
138
144static int add_member(const char *member_name);
145
151static short *add_struct(int type_index);
152
157static int preprocess_include(char *maindata, const int maindata_len);
158
162static int convert_include(const char *filepath);
163
167static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char *base_directory);
168
172static void dna_write(FILE *file, const void *pntr, const int size);
173
177void print_struct_sizes();
178
181/* -------------------------------------------------------------------- */
187static bool match_identifier_with_len(const char *str,
188 const char *identifier,
189 const size_t identifier_len)
190{
191 if (strncmp(str, identifier, identifier_len) == 0) {
192 /* Check `str` isn't a prefix to a longer identifier. */
193 if (isdigit(str[identifier_len]) || isalpha(str[identifier_len]) ||
194 (str[identifier_len] == '_'))
195 {
196 return false;
197 }
198 return true;
199 }
200 return false;
201}
202
203static bool match_identifier(const char *str, const char *identifier)
204{
205 const size_t identifier_len = strlen(identifier);
206 return match_identifier_with_len(str, identifier, identifier_len);
207}
208
209static bool match_identifier_and_advance(char **str_ptr, const char *identifier)
210{
211 const size_t identifier_len = strlen(identifier);
212 if (match_identifier_with_len(*str_ptr, identifier, identifier_len)) {
213 (*str_ptr) += identifier_len;
214 return true;
215 }
216 return false;
217}
218
219static const char *version_struct_static_from_alias(const char *type_alias)
220{
221 const char *type_static = static_cast<const char *>(
222 BLI_ghash_lookup(g_version_data.type_map_static_from_alias, type_alias));
223 if (type_static != nullptr) {
224 return type_static;
225 }
226 return type_alias;
227}
228
229static const char *version_struct_alias_from_static(const char *type_static)
230{
231 const char *type_alias = static_cast<const char *>(
232 BLI_ghash_lookup(g_version_data.type_map_alias_from_static, type_static));
233 if (type_alias != nullptr) {
234 return type_alias;
235 }
236 return type_static;
237}
238
239static const char *version_member_static_from_alias(const int type_index,
240 const char *member_alias_full)
241{
242 const uint member_alias_full_len = strlen(member_alias_full);
243 char *member_alias = static_cast<char *>(alloca(member_alias_full_len + 1));
244 const int member_alias_len = DNA_member_id_strip_copy(member_alias, member_alias_full);
245 const char *str_pair[2] = {types[type_index], member_alias};
246 const char *member_static = static_cast<const char *>(
247 BLI_ghash_lookup(g_version_data.member_map_static_from_alias, str_pair));
248 if (member_static != nullptr) {
250 member_alias,
251 member_alias_len,
252 member_static,
253 strlen(member_static),
254 member_alias_full,
255 member_alias_full_len,
256 DNA_member_id_offset_start(member_alias_full));
257 }
258 return member_alias_full;
259}
260
265static bool is_name_legal(const char *name)
266{
267 const int name_size = strlen(name) + 1;
268 char *name_strip = static_cast<char *>(alloca(name_size));
269 DNA_member_id_strip_copy(name_strip, name);
270
271 const char prefix[] = {'p', 'a', 'd'};
272
273 if (name[0] == '_') {
274 if (strncmp(&name_strip[1], prefix, sizeof(prefix)) != 0) {
275 fprintf(
276 stderr, "Error: only '_pad' variables can start with an underscore, found '%s'\n", name);
277 return false;
278 }
279 }
280 else if (strncmp(name_strip, prefix, sizeof(prefix)) == 0) {
281 int i = sizeof(prefix);
282 if (name_strip[i] >= 'a' && name_strip[i] <= 'z') {
283 /* may be part of a word, allow that. */
284 return true;
285 }
286 bool has_only_digit_or_none = true;
287 for (; name_strip[i]; i++) {
288 const char c = name_strip[i];
289 if (!((c >= '0' && c <= '9') || c == '_')) {
290 has_only_digit_or_none = false;
291 break;
292 }
293 }
294 if (has_only_digit_or_none) {
295 /* found 'pad' or 'pad123'. */
296 fprintf(
297 stderr, "Error: padding variables must be formatted '_pad[number]', found '%s'\n", name);
298 return false;
299 }
300 }
301 return true;
302}
303
304static int add_type(const char *type_name, int size)
305{
306 /* first do validity check */
307 if (type_name[0] == 0) {
308 return -1;
309 }
310 if (strchr(type_name, '*')) {
311 /* NOTE: this is valid C syntax but we can't parse, complain!
312 * `struct SomeStruct* some_var;` <-- correct but we can't handle right now. */
313 return -1;
314 }
315
316 type_name = version_struct_static_from_alias(type_name);
317
318 /* search through type array */
319 for (int type_index = 0; type_index < types_num; type_index++) {
320 if (STREQ(type_name, types[type_index])) {
321 if (size) {
322 types_size_native[type_index] = size;
323 types_size_32[type_index] = size;
324 types_size_64[type_index] = size;
325 types_align_32[type_index] = size;
326 types_align_64[type_index] = size;
327 }
328 return type_index;
329 }
330 }
331
332 /* append new type */
333 const int type_name_len = strlen(type_name) + 1;
334 char *cp = static_cast<char *>(BLI_memarena_alloc(mem_arena, type_name_len));
335 memcpy(cp, type_name, type_name_len);
336 types[types_num] = cp;
342 if (types_num >= max_array_len) {
343 printf("too many types\n");
344 return types_num - 1;
345 }
346 types_num++;
347
348 return types_num - 1;
349}
350
357static int add_member(const char *member_name)
358{
359 char buf[255]; /* stupid limit, change it :) */
360 const char *name;
361
363
364 if (member_name[0] == 0 /* || (member_name[1] == 0) */) {
365 return -1;
366 }
367
368 if (member_name[0] == '(' && member_name[1] == '*') {
369 /* We handle function pointer and special array cases here, e.g.
370 * `void (*function)(...)` and `float (*array)[..]`. the array case
371 * name is still converted to (array *)() though because it is that
372 * way in old DNA too, and works correct with #DNA_struct_member_size. */
373 int isfuncptr = (strchr(member_name + 1, '(')) != nullptr;
374
375 DEBUG_PRINTF(3, "\t\t\t\t*** Function pointer or multidim array pointer found\n");
376 /* function-pointer: transform the type (sometimes). */
377 int i = 0;
378
379 while (member_name[i] != ')') {
380 buf[i] = member_name[i];
381 i++;
382 }
383
384 /* Another number we need is the extra slen offset. This extra
385 * offset is the overshoot after a space. If there is no
386 * space, no overshoot should be calculated. */
387 int j = i; /* j at first closing brace */
388
389 DEBUG_PRINTF(3, "first brace after offset %d\n", i);
390
391 j++; /* j beyond closing brace ? */
392 while ((member_name[j] != 0) && (member_name[j] != ')')) {
393 DEBUG_PRINTF(3, "seen %c (%d)\n", member_name[j], member_name[j]);
394 j++;
395 }
396 DEBUG_PRINTF(3,
397 "seen %c (%d)\n"
398 "special after offset%d\n",
399 member_name[j],
400 member_name[j],
401 j);
402
403 if (!isfuncptr) {
404 /* multidimensional array pointer case */
405 if (member_name[j] == 0) {
406 DEBUG_PRINTF(3, "offsetting for multi-dimensional array pointer\n");
407 }
408 else {
409 printf("Error during tokenizing multi-dimensional array pointer\n");
410 }
411 }
412 else if (member_name[j] == 0) {
413 DEBUG_PRINTF(3, "offsetting for space\n");
414 /* get additional offset */
415 int k = 0;
416 while (member_name[j] != ')') {
417 j++;
418 k++;
419 }
420 DEBUG_PRINTF(3, "extra offset %d\n", k);
422 }
423 else if (member_name[j] == ')') {
424 DEBUG_PRINTF(3, "offsetting for brace\n");
425 /* don't get extra offset */
426 }
427 else {
428 printf("Error during tokening function pointer argument list\n");
429 }
430
431 /*
432 * Put `)(void)` at the end? Maybe `)()`. Should check this with
433 * old `sdna`. Actually, sometimes `)()`, sometimes `)(void...)`
434 * Alas.. such is the nature of brain-damage :(
435 *
436 * Sorted it out: always do )(), except for `headdraw` and
437 * `windraw`, part of #ScrArea. This is important, because some
438 * linkers will treat different fp's differently when called
439 * !!! This has to do with interference in byte-alignment and
440 * the way arguments are pushed on the stack.
441 */
442 buf[i] = 0;
443 DEBUG_PRINTF(3, "Name before chomping: %s\n", buf);
444 if ((strncmp(buf, "(*headdraw", 10) == 0) || strncmp(buf, "(*windraw", 9) == 0) {
445 buf[i] = ')';
446 buf[i + 1] = '(';
447 buf[i + 2] = 'v';
448 buf[i + 3] = 'o';
449 buf[i + 4] = 'i';
450 buf[i + 5] = 'd';
451 buf[i + 6] = ')';
452 buf[i + 7] = 0;
453 }
454 else {
455 buf[i] = ')';
456 buf[i + 1] = '(';
457 buf[i + 2] = ')';
458 buf[i + 3] = 0;
459 }
460 /* Now proceed with buf. */
461 DEBUG_PRINTF(3, "\t\t\t\t\tProposing fp name %s\n", buf);
462 name = buf;
463 }
464 else {
465 /* normal field: old code */
466 name = member_name;
467 }
468
469 /* search name array */
470 for (int member_index = 0; member_index < members_num; member_index++) {
471 if (STREQ(name, members[member_index])) {
472 return member_index;
473 }
474 }
475
476 /* Sanity check the name. */
477 if (!is_name_legal(name)) {
478 return -1;
479 }
480
481 /* Append new name. */
482 const int name_len = strlen(name) + 1;
483 char *cp = static_cast<char *>(BLI_memarena_alloc(mem_arena, name_len));
484 memcpy(cp, name, name_len);
485 members[members_num] = cp;
486
487 if (members_num >= max_array_len) {
488 printf("too many names\n");
489 return members_num - 1;
490 }
491 members_num++;
492
493 return members_num - 1;
494}
495
496static short *add_struct(int type_index)
497{
498 if (structs_num == 0) {
499 structs[0] = structdata;
500 }
501 else {
502 short *sp = structs[structs_num - 1];
503 const int len = sp[1];
504 structs[structs_num] = sp + 2 * len + 2;
505 }
506
507 short *sp = structs[structs_num];
508 sp[0] = type_index;
509
510 if (structs_num >= max_array_len) {
511 printf("too many structs\n");
512 return sp;
513 }
514 structs_num++;
515
516 return sp;
517}
518
519/* Copied from `BLI_str_startswith` string.c
520 * to avoid complicating the compilation process of makesdna. */
521static bool str_startswith(const char *__restrict str, const char *__restrict start)
522{
523 for (; *str && *start; str++, start++) {
524 if (*str != *start) {
525 return false;
526 }
527 }
528
529 return (*start == '\0');
530}
531
537static bool match_preproc_prefix(const char *__restrict str, const char *__restrict start)
538{
539 if (*str != '#') {
540 return false;
541 }
542 str++;
543 while (*str == ' ') {
544 str++;
545 }
546 return str_startswith(str, start);
547}
548
552static char *match_preproc_strstr(char *__restrict str, const char *__restrict start)
553{
554 while ((str = strchr(str, '#'))) {
555 str++;
556 while (*str == ' ') {
557 str++;
558 }
559 if (str_startswith(str, start)) {
560 return str;
561 }
562 }
563 return nullptr;
564}
565
566static int preprocess_include(char *maindata, const int maindata_len)
567{
568 /* NOTE: len + 1, last character is a dummy to prevent
569 * comparisons using uninitialized memory */
570 char *temp = static_cast<char *>(MEM_mallocN(maindata_len + 1, "preprocess_include"));
571 temp[maindata_len] = ' ';
572
573 memcpy(temp, maindata, maindata_len);
574
575 /* remove all c++ comments */
576 /* replace all enters/tabs/etc with spaces */
577 char *cp = temp;
578 int a = maindata_len;
579 int comment = 0;
580 while (a--) {
581 if (cp[0] == '/' && cp[1] == '/') {
582 comment = 1;
583 }
584 else if (*cp == '\n') {
585 comment = 0;
586 }
587 if (comment || *cp < 32 || *cp > 128) {
588 *cp = 32;
589 }
590 cp++;
591 }
592
593 /* No need for leading '#' character. */
594 const char *cpp_block_start = "ifdef __cplusplus";
595 const char *cpp_block_end = "endif";
596
597 /* data from temp copy to maindata, remove comments and double spaces */
598 cp = temp;
599 char *md = maindata;
600 int newlen = 0;
601 comment = 0;
602 a = maindata_len;
603 bool skip_until_closing_brace = false;
604 while (a--) {
605
606 if (cp[0] == '/' && cp[1] == '*') {
607 comment = 1;
608 cp[0] = cp[1] = 32;
609 }
610 if (cp[0] == '*' && cp[1] == '/') {
611 comment = 0;
612 cp[0] = cp[1] = 32;
613 }
614
615 /* do not copy when: */
616 if (comment) {
617 /* pass */
618 }
619 else if (cp[0] == ' ' && cp[1] == ' ') {
620 /* pass */
621 }
622 else if (cp[-1] == '*' && cp[0] == ' ') {
623 /* pointers with a space */
624 } /* skip special keywords */
625 else if (match_identifier(cp, "DNA_DEPRECATED")) {
626 /* single values are skipped already, so decrement 1 less */
627 a -= 13;
628 cp += 13;
629 }
630 else if (match_identifier(cp, "DNA_DEFINE_CXX_METHODS")) {
631 /* single values are skipped already, so decrement 1 less */
632 a -= 21;
633 cp += 21;
634 skip_until_closing_brace = true;
635 }
636 else if (skip_until_closing_brace) {
637 if (cp[0] == ')') {
638 skip_until_closing_brace = false;
639 }
640 }
641 else if (match_preproc_prefix(cp, cpp_block_start)) {
642 char *end_ptr = match_preproc_strstr(cp, cpp_block_end);
643
644 if (end_ptr == nullptr) {
645 fprintf(stderr, "Error: '%s' block must end with '%s'\n", cpp_block_start, cpp_block_end);
646 }
647 else {
648 const int skip_offset = end_ptr - cp + strlen(cpp_block_end);
649 a -= skip_offset;
650 cp += skip_offset;
651 }
652 }
653 else {
654 md[0] = cp[0];
655 md++;
656 newlen++;
657 }
658 cp++;
659 }
660
661 MEM_freeN(temp);
662 return newlen;
663}
664
665static void *read_file_data(const char *filepath, int *r_len)
666{
667#ifdef WIN32
668 FILE *fp = fopen(filepath, "rb");
669#else
670 FILE *fp = fopen(filepath, "r");
671#endif
672 void *data;
673
674 if (!fp) {
675 *r_len = -1;
676 return nullptr;
677 }
678
679 fseek(fp, 0L, SEEK_END);
680 *r_len = ftell(fp);
681 fseek(fp, 0L, SEEK_SET);
682
683 if (*r_len == -1) {
684 fclose(fp);
685 return nullptr;
686 }
687
688 data = MEM_mallocN(*r_len, "read_file_data");
689 if (!data) {
690 *r_len = -1;
691 fclose(fp);
692 return nullptr;
693 }
694
695 if (fread(data, *r_len, 1, fp) != 1) {
696 *r_len = -1;
697 MEM_freeN(data);
698 fclose(fp);
699 return nullptr;
700 }
701
702 fclose(fp);
703 return data;
704}
705
706static int convert_include(const char *filepath)
707{
708 /* read include file, skip structs with a '#' before it.
709 * store all data in temporal arrays.
710 */
711
712 int maindata_len;
713 char *maindata = static_cast<char *>(read_file_data(filepath, &maindata_len));
714 char *md = maindata;
715 if (maindata_len == -1) {
716 fprintf(stderr, "Can't read file %s\n", filepath);
717 return 1;
718 }
719
720 maindata_len = preprocess_include(maindata, maindata_len);
721 char *mainend = maindata + maindata_len - 1;
722
723 /* we look for '{' and then back to 'struct' */
724 int count = 0;
725 bool skip_struct = false;
726 while (count < maindata_len) {
727
728 /* code for skipping a struct: two hashes on 2 lines. (preprocess added a space) */
729 if (md[0] == '#' && md[1] == ' ' && md[2] == '#') {
730 skip_struct = true;
731 }
732
733 if (md[0] == '{') {
734 md[0] = 0;
735 if (skip_struct) {
736 skip_struct = false;
737 }
738 else {
739 if (md[-1] == ' ') {
740 md[-1] = 0;
741 }
742 char *md1 = md - 2;
743 while (*md1 != 32) {
744 /* to beginning of word */
745 md1--;
746 }
747 md1++;
748
749 /* we've got a struct name when... */
750 if (match_identifier(md1 - 7, "struct")) {
751
752 const int struct_type_index = add_type(md1, 0);
753 if (struct_type_index == -1) {
754 fprintf(stderr, "File '%s' contains struct we can't parse \"%s\"\n", filepath, md1);
755 return 1;
756 }
757
758 short *structpoin = add_struct(struct_type_index);
759 short *sp = structpoin + 2;
760
761 DEBUG_PRINTF(1, "\t|\t|-- detected struct %s\n", types[struct_type_index]);
762
763 /* first lets make it all nice strings */
764 md1 = md + 1;
765 while (*md1 != '}') {
766 if (md1 > mainend) {
767 break;
768 }
769
770 if (ELEM(*md1, ',', ' ')) {
771 *md1 = 0;
772 }
773 md1++;
774 }
775
776 /* read types and names until first character that is not '}' */
777 md1 = md + 1;
778 while (*md1 != '}') {
779 if (md1 > mainend) {
780 break;
781 }
782
783 /* skip when it says 'struct' or 'unsigned' or 'const' */
784 if (*md1) {
785 const char *md1_prev = md1;
786 while (match_identifier_and_advance(&md1, "struct") ||
787 match_identifier_and_advance(&md1, "unsigned") ||
788 match_identifier_and_advance(&md1, "const"))
789 {
790 if (UNLIKELY(!ELEM(*md1, '\0', ' '))) {
791 /* This will happen with: `unsigned(*value)[3]` which isn't supported. */
792 fprintf(stderr,
793 "File '%s' contains non white space character "
794 "\"%c\" after identifier \"%s\"\n",
795 filepath,
796 *md1,
797 md1_prev);
798 return 1;
799 }
800 /* Skip ' ' or '\0'. */
801 md1++;
802 }
803
804 /* we've got a type! */
805 if (STR_ELEM(md1, "long", "ulong")) {
806 /* Forbid using long/ulong because those can be either 32 or 64 bit. */
807 fprintf(stderr,
808 "File '%s' contains use of \"%s\" in DNA struct which is not allowed\n",
809 filepath,
810 md1);
811 return -1;
812 }
813 const int member_type_index = add_type(md1, 0);
814 if (member_type_index == -1) {
815 fprintf(
816 stderr, "File '%s' contains struct we can't parse \"%s\"\n", filepath, md1);
817 return 1;
818 }
819
820 DEBUG_PRINTF(1, "\t|\t|\tfound type %s (", md1);
821
822 md1 += strlen(md1);
823
824 /* read until ';' */
825 while (*md1 != ';') {
826 if (md1 > mainend) {
827 break;
828 }
829
830 if (*md1) {
831 /* We've got a name. slen needs
832 * correction for function
833 * pointers! */
834 int slen = int(strlen(md1));
835 if (md1[slen - 1] == ';') {
836 md1[slen - 1] = 0;
837
838 const int name = add_member(
839 version_member_static_from_alias(struct_type_index, md1));
840 if (name == -1) {
841 fprintf(stderr,
842 "File '%s' contains struct with name that can't be added \"%s\"\n",
843 filepath,
844 md1);
845 return 1;
846 }
848 sp[0] = member_type_index;
849 sp[1] = name;
850
851 if (members[name] != nullptr) {
852 DEBUG_PRINTF(1, "%s |", members[name]);
853 }
854
855 structpoin[1]++;
856 sp += 2;
857
858 md1 += slen;
859 break;
860 }
861
862 const int name = add_member(
863 version_member_static_from_alias(struct_type_index, md1));
864 if (name == -1) {
865 fprintf(stderr,
866 "File '%s' contains struct with name that can't be added \"%s\"\n",
867 filepath,
868 md1);
869 return 1;
870 }
872
873 sp[0] = member_type_index;
874 sp[1] = name;
875 if (members[name] != nullptr) {
876 DEBUG_PRINTF(1, "%s ||", members[name]);
877 }
878
879 structpoin[1]++;
880 sp += 2;
881
882 md1 += slen;
883 }
884 md1++;
885 }
886
887 DEBUG_PRINTF(1, ")\n");
888 }
889 md1++;
890 }
891 }
892 }
893 }
894 count++;
895 md++;
896 }
897
898 MEM_freeN(maindata);
899
900 return 0;
901}
902
903static bool check_field_alignment(int firststruct,
904 int struct_type_index,
905 int type,
906 int len,
907 const char *name,
908 const char *detail)
909{
910 bool result = true;
911 if (type < firststruct && types_size_native[type] > 4 && (len % 8)) {
912 fprintf(stderr,
913 "Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n",
914 detail,
915 types[struct_type_index],
916 name,
917 len % 8);
918 result = false;
919 }
920 if (types_size_native[type] > 3 && (len % 4)) {
921 fprintf(stderr,
922 "Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n",
923 detail,
924 types[struct_type_index],
925 name,
926 len % 4);
927 result = false;
928 }
929 if (types_size_native[type] == 2 && (len % 2)) {
930 fprintf(stderr,
931 "Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n",
932 detail,
933 types[struct_type_index],
934 name,
935 len % 2);
936 result = false;
937 }
938 return result;
939}
940
941static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char *base_directory)
942{
943 bool dna_error = false;
944
945 /* Write test to verify sizes are accurate. */
946 fprintf(file_verify, "/* Verify struct sizes and member offsets are as expected by DNA. */\n");
947 fprintf(file_verify, "#include \"BLI_assert.h\"\n\n");
948 /* Needed so we can find offsets of deprecated structs. */
949 fprintf(file_verify, "#define DNA_DEPRECATED_ALLOW\n");
950 /* Workaround enum naming collision in static asserts
951 * (ideally this included a unique name/id per file). */
952 fprintf(file_verify, "#define assert_line_ assert_line_DNA_\n");
953 for (int i = 0; *(includefiles[i]) != '\0'; i++) {
954 fprintf(file_verify, "#include \"%s%s\"\n", base_directory, includefiles[i]);
955 }
956 fprintf(file_verify, "#undef assert_line_\n");
957 fprintf(file_verify, "\n");
958
959 /* Multiple iterations to handle nested structs. */
960 /* 'raw data' SDNA_RAW_DATA_STRUCT_INDEX fake struct should be ignored here. */
961 int unknown = structs_num - 1;
962 while (unknown) {
963 const int lastunknown = unknown;
964 unknown = 0;
965
966 /* check all structs... */
967 BLI_STATIC_ASSERT(SDNA_RAW_DATA_STRUCT_INDEX == 0, "'raw data' SDNA struct index should be 0")
968 for (int a = SDNA_RAW_DATA_STRUCT_INDEX + 1; a < structs_num; a++) {
969 const short *structpoin = structs[a];
970 const int struct_type_index = structpoin[0];
971 const char *struct_type_name = version_struct_alias_from_static(types[struct_type_index]);
972
973 /* when length is not known... */
974 if (types_size_native[struct_type_index] == 0) {
975
976 const short *sp = structpoin + 2;
977 int size_native = 0;
978 int size_32 = 0;
979 int size_64 = 0;
980 /* Sizes of the largest field in a struct. */
981 int max_align_32 = 0;
982 int max_align_64 = 0;
983
984 /* check all members in struct */
985 for (int b = 0; b < structpoin[1]; b++, sp += 2) {
986 int type = sp[0];
987 const char *cp = members[sp[1]];
988 int namelen = int(strlen(cp));
989
990 /* Write size verification to file. */
991 {
992 /* Normally 'alloca' would be used here, however we can't in a loop.
993 * Use an over-sized buffer instead. */
994 char name_static[1024];
995 BLI_assert(sizeof(name_static) > namelen);
996
997 DNA_member_id_strip_copy(name_static, cp);
998 const char *str_pair[2] = {types[struct_type_index], name_static};
999 const char *name_alias = static_cast<const char *>(
1000 BLI_ghash_lookup(g_version_data.member_map_alias_from_static, str_pair));
1001 fprintf(file_verify,
1002 "BLI_STATIC_ASSERT(offsetof(struct %s, %s) == %d, \"DNA member offset "
1003 "verify\");\n",
1004 struct_type_name,
1005 name_alias ? name_alias : name_static,
1006 size_native);
1007 }
1008
1009 /* is it a pointer or function pointer? */
1010 if (cp[0] == '*' || cp[1] == '*') {
1011 /* has the name an extra length? (array) */
1012 int mul = 1;
1013 if (cp[namelen - 1] == ']') {
1015 }
1016
1017 if (mul == 0) {
1018 fprintf(stderr,
1019 "Zero array size found or could not parse %s: '%.*s'\n",
1020 types[struct_type_index],
1021 namelen + 1,
1022 cp);
1023 dna_error = true;
1024 }
1025
1026 /* 4-8 aligned/ */
1027 if (sizeof(void *) == 4) {
1028 if (size_native % 4) {
1029 fprintf(stderr,
1030 "Align pointer error in struct (size_native 4): %s %s\n",
1031 types[struct_type_index],
1032 cp);
1033 dna_error = true;
1034 }
1035 }
1036 else {
1037 if (size_native % 8) {
1038 fprintf(stderr,
1039 "Align pointer error in struct (size_native 8): %s %s\n",
1040 types[struct_type_index],
1041 cp);
1042 dna_error = true;
1043 }
1044 }
1045
1046 if (size_64 % 8) {
1047 fprintf(stderr,
1048 "Align pointer error in struct (size_64 8): %s %s\n",
1049 types[struct_type_index],
1050 cp);
1051 dna_error = true;
1052 }
1053
1054 size_native += sizeof(void *) * mul;
1055 size_32 += 4 * mul;
1056 size_64 += 8 * mul;
1057 max_align_32 = std::max(max_align_32, 4);
1058 max_align_64 = std::max(max_align_64, 8);
1059 }
1060 else if (cp[0] == '[') {
1061 /* parsing can cause names "var" and "[3]"
1062 * to be found for "float var [3]" */
1063 fprintf(stderr,
1064 "Parse error in struct, invalid member name: %s %s\n",
1065 types[struct_type_index],
1066 cp);
1067 dna_error = true;
1068 }
1069 else if (types_size_native[type]) {
1070 /* has the name an extra length? (array) */
1071 int mul = 1;
1072 if (cp[namelen - 1] == ']') {
1074 }
1075
1076 if (mul == 0) {
1077 fprintf(stderr,
1078 "Zero array size found or could not parse %s: '%.*s'\n",
1079 types[struct_type_index],
1080 namelen + 1,
1081 cp);
1082 dna_error = true;
1083 }
1084
1085 /* struct alignment */
1086 if (type >= firststruct) {
1087 if (sizeof(void *) == 8 && (size_native % 8)) {
1088 fprintf(stderr,
1089 "Align struct error: %s::%s (starts at %d on the native platform; "
1090 "%d %% %zu = %d bytes)\n",
1091 types[struct_type_index],
1092 cp,
1093 size_native,
1094 size_native,
1095 sizeof(void *),
1096 size_native % 8);
1097 dna_error = true;
1098 }
1099 }
1100
1101 /* Check 2-4-8 aligned. */
1103 firststruct, struct_type_index, type, size_32, cp, "32 bit"))
1104 {
1105 dna_error = true;
1106 }
1108 firststruct, struct_type_index, type, size_64, cp, "64 bit"))
1109 {
1110 dna_error = true;
1111 }
1112
1113 size_native += mul * types_size_native[type];
1114 size_32 += mul * types_size_32[type];
1115 size_64 += mul * types_size_64[type];
1116 max_align_32 = std::max<int>(max_align_32, types_align_32[type]);
1117 max_align_64 = std::max<int>(max_align_64, types_align_64[type]);
1118 }
1119 else {
1120 size_native = 0;
1121 size_32 = 0;
1122 size_64 = 0;
1123 break;
1124 }
1125 }
1126
1127 if (size_native == 0) {
1128 unknown++;
1129 }
1130 else {
1131 types_size_native[struct_type_index] = size_native;
1132 types_size_32[struct_type_index] = size_32;
1133 types_size_64[struct_type_index] = size_64;
1134 types_align_32[struct_type_index] = max_align_32;
1135 types_align_64[struct_type_index] = max_align_64;
1136
1137 /* Sanity check 1: alignment should never be 0. */
1138 BLI_assert(max_align_32);
1139 BLI_assert(max_align_64);
1140
1141 /* Sanity check 2: alignment should always be equal or smaller than the maximum
1142 * size of a build in type which is 8 bytes (i.e. `int64_t` or double). */
1143 BLI_assert(max_align_32 <= 8);
1144 BLI_assert(max_align_64 <= 8);
1145
1146 if (size_32 % max_align_32) {
1147 /* There is an one odd case where only the 32 bit struct has alignment issues
1148 * and the 64 bit does not, that can only be fixed by adding a padding pointer
1149 * to the struct to resolve the problem. */
1150 if ((size_64 % max_align_64 == 0) && (size_32 % max_align_32 == 4)) {
1151 fprintf(stderr,
1152 "Sizeerror in 32 bit struct: %s (add padding pointer)\n",
1153 types[struct_type_index]);
1154 }
1155 else {
1156 fprintf(stderr,
1157 "Sizeerror in 32 bit struct: %s (add %d bytes)\n",
1158 types[struct_type_index],
1159 max_align_32 - (size_32 % max_align_32));
1160 }
1161 dna_error = true;
1162 }
1163
1164 if (size_64 % max_align_64) {
1165 fprintf(stderr,
1166 "Sizeerror in 64 bit struct: %s (add %d bytes)\n",
1167 types[struct_type_index],
1168 max_align_64 - (size_64 % max_align_64));
1169 dna_error = true;
1170 }
1171
1172 if (size_native % 4 && !ELEM(size_native, 1, 2)) {
1173 fprintf(stderr,
1174 "Sizeerror 4 in struct: %s (add %d bytes)\n",
1175 types[struct_type_index],
1176 size_native % 4);
1177 dna_error = true;
1178 }
1179
1180 /* Write size verification to file. */
1181 fprintf(file_verify,
1182 "BLI_STATIC_ASSERT(sizeof(struct %s) == %d, \"DNA struct size verify\");\n\n",
1183 struct_type_name,
1184 size_native);
1185 }
1186 }
1187 }
1188
1189 if (unknown == lastunknown) {
1190 break;
1191 }
1192 }
1193
1194 if (unknown) {
1195 fprintf(stderr, "ERROR: still %d structs unknown\n", unknown);
1196
1197 if (debugSDNA) {
1198 fprintf(stderr, "*** Known structs :\n");
1199
1200 for (int a = 0; a < structs_num; a++) {
1201 const short *structpoin = structs[a];
1202 const int structtype = structpoin[0];
1203
1204 /* length unknown */
1205 if (types_size_native[structtype] != 0) {
1206 fprintf(stderr, " %s\n", types[structtype]);
1207 }
1208 }
1209 }
1210
1211 fprintf(stderr, "*** Unknown structs :\n");
1212
1213 for (int a = 0; a < structs_num; a++) {
1214 const short *structpoin = structs[a];
1215 const int structtype = structpoin[0];
1216
1217 /* length unknown yet */
1218 if (types_size_native[structtype] == 0) {
1219 fprintf(stderr, " %s\n", types[structtype]);
1220 }
1221 }
1222
1223 dna_error = true;
1224 }
1225
1226 return dna_error;
1227}
1228
1229#define MAX_DNA_LINE_LENGTH 20
1230
1231static void dna_write(FILE *file, const void *pntr, const int size)
1232{
1233 static int linelength = 0;
1234 const char *data = (const char *)pntr;
1235
1236 for (int i = 0; i < size; i++) {
1237 fprintf(file, "%d, ", data[i]);
1238 linelength++;
1239 if (linelength >= MAX_DNA_LINE_LENGTH) {
1240 fprintf(file, "\n");
1241 linelength = 0;
1242 }
1243 }
1244}
1245
1247{
1248 int unknown = structs_num;
1249 printf("\n\n*** All detected structs:\n");
1250
1251 while (unknown) {
1252 unknown = 0;
1253
1254 /* check all structs... */
1255 for (int a = 0; a < structs_num; a++) {
1256 const short *structpoin = structs[a];
1257 const int structtype = structpoin[0];
1258 printf("\t%s\t:%d\n", types[structtype], types_size_native[structtype]);
1259 }
1260 }
1261
1262 printf("*** End of list\n");
1263}
1264
1265static int make_structDNA(const char *base_directory,
1266 FILE *file,
1267 FILE *file_offsets,
1268 FILE *file_verify)
1269{
1270 if (debugSDNA > 0) {
1271 fflush(stdout);
1272 printf("Running makesdna at debug level %d\n", debugSDNA);
1273 }
1274
1276
1277 /* the longest known struct is 50k, so we assume 100k is sufficient! */
1278 structdata = static_cast<short *>(MEM_callocN(max_data_size, "structdata"));
1279
1280 /* a maximum of 5000 variables, must be sufficient? */
1281 members = static_cast<char **>(MEM_callocN(sizeof(char *) * max_array_len, "names"));
1282 types = static_cast<char **>(MEM_callocN(sizeof(char *) * max_array_len, "types"));
1283 types_size_native = static_cast<short *>(
1284 MEM_callocN(sizeof(short) * max_array_len, "types_size_native"));
1285 types_size_32 = static_cast<short *>(
1286 MEM_callocN(sizeof(short) * max_array_len, "types_size_32"));
1287 types_size_64 = static_cast<short *>(
1288 MEM_callocN(sizeof(short) * max_array_len, "types_size_64"));
1289 types_align_32 = static_cast<short *>(
1290 MEM_callocN(sizeof(short) * max_array_len, "types_size_32"));
1291 types_align_64 = static_cast<short *>(
1292 MEM_callocN(sizeof(short) * max_array_len, "types_size_64"));
1293
1294 structs = static_cast<short **>(MEM_callocN(sizeof(short *) * max_array_len, "structs"));
1295
1296 /* Build versioning data */
1298 &g_version_data.type_map_alias_from_static,
1299 &g_version_data.member_map_alias_from_static);
1301 &g_version_data.type_map_static_from_alias,
1302 &g_version_data.member_map_static_from_alias);
1303
1311 add_type("char", 1); /* SDNA_TYPE_CHAR */
1312 add_type("uchar", 1); /* SDNA_TYPE_UCHAR */
1313 add_type("short", 2); /* SDNA_TYPE_SHORT */
1314 add_type("ushort", 2); /* SDNA_TYPE_USHORT */
1315 add_type("int", 4); /* SDNA_TYPE_INT */
1316
1317 /* NOTE: long isn't supported,
1318 * these are place-holders to maintain alignment with #eSDNA_Type. */
1319 add_type("long", 4); /* SDNA_TYPE_LONG */
1320 add_type("ulong", 4); /* SDNA_TYPE_ULONG */
1321
1322 add_type("float", 4); /* SDNA_TYPE_FLOAT */
1323 add_type("double", 8); /* SDNA_TYPE_DOUBLE */
1324 add_type("int64_t", 8); /* SDNA_TYPE_INT64 */
1325 add_type("uint64_t", 8); /* SDNA_TYPE_UINT64 */
1326 add_type("void", 0); /* SDNA_TYPE_VOID */
1327 add_type("int8_t", 1); /* SDNA_TYPE_INT8 */
1328
1329 /* Fake place-holder struct definition used to get an identifier for raw, untyped bytes buffers
1330 * in blend-files.
1331 *
1332 * It will be written into the blend-files SDNA, but it must never be used in the source code.
1333 * Trying to declare `struct raw_data` in DNA headers will cause a build error.
1334 *
1335 * NOTE: While not critical, since all blend-files before introduction of this 'raw_data'
1336 * type/struct have been using the `0` value for raw data #BHead.SDNAnr, it's best to reserve
1337 * that first struct index to this raw data explicitly. */
1338 const int raw_data_type_index = add_type("raw_data", 0); /* SDNA_TYPE_RAW_DATA */
1339 short *raw_data_struct_info = add_struct(raw_data_type_index);
1340 /* There are no members in this struct. */
1341 raw_data_struct_info[1] = 0;
1342 BLI_STATIC_ASSERT(SDNA_RAW_DATA_STRUCT_INDEX == 0, "'raw data' SDNA struct index should be 0")
1343 BLI_assert(raw_data_struct_info == structs[SDNA_RAW_DATA_STRUCT_INDEX]);
1344
1345 /* the defines above shouldn't be output in the padding file... */
1346 const int firststruct = types_num;
1347
1348 /* Add all include files defined in the global array.
1349 * Since the internal file+path name buffer has limited length,
1350 * I do a little test first...
1351 * Mind the breaking condition here! */
1352 DEBUG_PRINTF(0, "\tStart of header scan:\n");
1353 int header_count = 0;
1354 for (int i = 0; *(includefiles[i]) != '\0'; i++) {
1355 header_count++;
1356
1357 /* NOTE(nzc): `str` contains filenames.
1358 * Since we now include paths, I stretched it a bit. Hope this is enough :). */
1360 SNPRINTF(str, "%s%s", base_directory, includefiles[i]);
1361 DEBUG_PRINTF(0, "\t|-- Converting %s\n", str);
1362 if (convert_include(str)) {
1363 return 1;
1364 }
1365 }
1366 DEBUG_PRINTF(0, "\tFinished scanning %d headers.\n", header_count);
1367
1368 if (calculate_struct_sizes(firststruct, file_verify, base_directory)) {
1369 /* error */
1370 return 1;
1371 }
1372
1373 /* FOR DEBUG */
1374 if (debugSDNA > 1) {
1375 int a, b;
1376 // short *elem;
1377 short struct_members_num;
1378
1379 printf("names_len %d types_len %d structs_len %d\n", members_num, types_num, structs_num);
1380 for (a = 0; a < members_num; a++) {
1381 printf(" %s\n", members[a]);
1382 }
1383 printf("\n");
1384
1385 const short *sp = types_size_native;
1386 for (a = 0; a < types_num; a++, sp++) {
1387 printf(" %s %d\n", types[a], *sp);
1388 }
1389 printf("\n");
1390
1391 for (a = 0; a < structs_num; a++) {
1392 sp = structs[a];
1393 printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], types_size_native[sp[0]]);
1394 struct_members_num = sp[1];
1395 sp += 2;
1396 for (b = 0; b < struct_members_num; b++, sp += 2) {
1397 printf(" %s %s allign32:%d, allign64:%d\n",
1398 types[sp[0]],
1399 members[sp[1]],
1400 types_align_32[sp[0]],
1401 types_align_64[sp[0]]);
1402 }
1403 }
1404 }
1405
1406 /* file writing */
1407
1408 DEBUG_PRINTF(0, "Writing file ... ");
1409
1410 if (members_num == 0 || structs_num == 0) {
1411 /* pass */
1412 }
1413 else {
1414 const char nil_bytes[4] = {0};
1415
1416 dna_write(file, "SDNA", 4);
1417
1418 /* write names */
1419 dna_write(file, "NAME", 4);
1420 int len = members_num;
1421 dna_write(file, &len, 4);
1422 /* write array */
1423 len = 0;
1424 for (int member_index = 0; member_index < members_num; member_index++) {
1425 int member_len = strlen(members[member_index]) + 1;
1426 dna_write(file, members[member_index], member_len);
1427 len += member_len;
1428 }
1429 int len_align = (len + 3) & ~3;
1430 if (len != len_align) {
1431 dna_write(file, nil_bytes, len_align - len);
1432 }
1433
1434 /* write TYPES */
1435 dna_write(file, "TYPE", 4);
1436 len = types_num;
1437 dna_write(file, &len, 4);
1438 /* write array */
1439 len = 0;
1440 for (int type_index = 0; type_index < types_num; type_index++) {
1441 int type_len = strlen(types[type_index]) + 1;
1442 dna_write(file, types[type_index], type_len);
1443 len += type_len;
1444 }
1445 len_align = (len + 3) & ~3;
1446 if (len != len_align) {
1447 dna_write(file, nil_bytes, len_align - len);
1448 }
1449
1450 /* WRITE TYPELENGTHS */
1451 dna_write(file, "TLEN", 4);
1452
1453 len = 2 * types_num;
1454 if (types_num & 1) {
1455 len += 2;
1456 }
1458
1459 /* WRITE STRUCTS */
1460 dna_write(file, "STRC", 4);
1461 len = structs_num;
1462 dna_write(file, &len, 4);
1463
1464 /* calc datablock size */
1465 const short *sp = structs[structs_num - 1];
1466 sp += 2 + 2 * (sp[1]);
1467 len = intptr_t((char *)sp - (char *)structs[0]);
1468 len = (len + 3) & ~3;
1469
1470 dna_write(file, structs[0], len);
1471 }
1472
1473 /* write a simple enum with all structs offsets,
1474 * should only be accessed via SDNA_TYPE_FROM_STRUCT macro */
1475 {
1476 fprintf(file_offsets, "#pragma once\n");
1477 fprintf(file_offsets, "#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n");
1478 fprintf(file_offsets, "enum {\n");
1479 for (int i = 0; i < structs_num; i++) {
1480 const short *structpoin = structs[i];
1481 const int struct_type_index = structpoin[0];
1482 fprintf(file_offsets,
1483 "\t_SDNA_TYPE_%s = %d,\n",
1484 version_struct_alias_from_static(types[struct_type_index]),
1485 i);
1486 }
1487 fprintf(file_offsets, "\tSDNA_TYPE_MAX = %d,\n", structs_num);
1488 fprintf(file_offsets, "};\n\n");
1489 }
1490
1491 /* Check versioning errors which could cause duplicate names,
1492 * do last because names are stripped. */
1493 {
1494 GSet *members_unique = BLI_gset_str_new_ex(__func__, 512);
1495 for (int struct_index = 0; struct_index < structs_num; struct_index++) {
1496 const short *sp = structs[struct_index];
1497 const char *type = types[sp[0]];
1498 const int len = sp[1];
1499 sp += 2;
1500 for (int a = 0; a < len; a++, sp += 2) {
1501 char *member = members[sp[1]];
1502 DNA_member_id_strip(member);
1503 if (!BLI_gset_add(members_unique, member)) {
1504 fprintf(stderr,
1505 "Error: duplicate name found '%s.%s', "
1506 "likely cause is 'dna_rename_defs.h'\n",
1507 type,
1508 member);
1509 return 1;
1510 }
1511 }
1512 BLI_gset_clear(members_unique, nullptr);
1513 }
1514 BLI_gset_free(members_unique, nullptr);
1515 }
1516
1519 MEM_freeN(types);
1526
1528
1529 BLI_ghash_free(g_version_data.type_map_alias_from_static, nullptr, nullptr);
1530 BLI_ghash_free(g_version_data.type_map_static_from_alias, nullptr, nullptr);
1531 BLI_ghash_free(g_version_data.member_map_static_from_alias, MEM_freeN, nullptr);
1532 BLI_ghash_free(g_version_data.member_map_alias_from_static, MEM_freeN, nullptr);
1533
1534 DEBUG_PRINTF(0, "done.\n");
1535
1536 return 0;
1537}
1538
1541/* end make DNA. */
1542
1543/* -------------------------------------------------------------------- */
1547static void make_bad_file(const char *file, int line)
1548{
1549 FILE *fp = fopen(file, "w");
1550 fprintf(fp,
1551 "#error \"Error! can't make correct DNA.c file from %s:%d, check alignment.\"\n",
1552 __FILE__,
1553 line);
1554 fclose(fp);
1555}
1556
1557#ifndef BASE_HEADER
1558# define BASE_HEADER "../"
1559#endif
1560
1561int main(int argc, char **argv)
1562{
1563 int return_status = 0;
1564
1565 if (!ELEM(argc, 4, 5)) {
1566 printf("Usage: %s dna.c dna_struct_offsets.h [base directory]\n", argv[0]);
1567 return_status = 1;
1568 }
1569 else {
1570 FILE *file_dna = fopen(argv[1], "w");
1571 FILE *file_dna_offsets = fopen(argv[2], "w");
1572 FILE *file_dna_verify = fopen(argv[3], "w");
1573 if (!file_dna) {
1574 printf("Unable to open file: %s\n", argv[1]);
1575 return_status = 1;
1576 }
1577 else if (!file_dna_offsets) {
1578 printf("Unable to open file: %s\n", argv[2]);
1579 return_status = 1;
1580 }
1581 else if (!file_dna_verify) {
1582 printf("Unable to open file: %s\n", argv[3]);
1583 return_status = 1;
1584 }
1585 else {
1586 const char *base_directory;
1587
1588 if (argc == 5) {
1589 base_directory = argv[4];
1590 }
1591 else {
1592 base_directory = BASE_HEADER;
1593 }
1594
1595 /* NOTE: #init_structDNA() in dna_genfile.cc expects `sdna->data` is 4-bytes aligned.
1596 * `DNAstr[]` buffer written by `makesdna` is used for this data, so make `DNAstr` forcefully
1597 * 4-bytes aligned. */
1598#ifdef __GNUC__
1599# define FORCE_ALIGN_4 " __attribute__((aligned(4))) "
1600#else
1601# define FORCE_ALIGN_4 " "
1602#endif
1603 fprintf(file_dna, "extern const unsigned char DNAstr[];\n");
1604 fprintf(file_dna, "const unsigned char" FORCE_ALIGN_4 "DNAstr[] = {\n");
1605#undef FORCE_ALIGN_4
1606
1607 if (make_structDNA(base_directory, file_dna, file_dna_offsets, file_dna_verify)) {
1608 /* error */
1609 fclose(file_dna);
1610 file_dna = nullptr;
1611 make_bad_file(argv[1], __LINE__);
1612 return_status = 1;
1613 }
1614 else {
1615 fprintf(file_dna, "};\n");
1616 fprintf(file_dna, "extern const int DNAlen;\n");
1617 fprintf(file_dna, "const int DNAlen = sizeof(DNAstr);\n");
1618 }
1619 }
1620
1621 if (file_dna) {
1622 fclose(file_dna);
1623 }
1624 if (file_dna_offsets) {
1625 fclose(file_dna_offsets);
1626 }
1627 if (file_dna_verify) {
1628 fclose(file_dna_verify);
1629 }
1630 }
1631
1632 return return_status;
1633}
1634
1635/* handy but fails on struct bounds which makesdna doesn't care about
1636 * with quite the same strictness as GCC does */
1637#if 0
1638/* include files for automatic dependencies */
1639
1640/* extra safety check that we are aligned,
1641 * warnings here are easier to fix the makesdna's */
1642# ifdef __GNUC__
1643# pragma GCC diagnostic error "-Wpadded"
1644# endif
1645
1646#endif /* if 0 */
1647
1648/* The include file below is automatically generated from the `SRC_DNA_INC`
1649 * variable in 'source/blender/CMakeLists.txt'. */
1650#include "dna_includes_all.h"
1651
1652/* end of list */
1653
1656/* -------------------------------------------------------------------- */
1665{
1666#define DNA_STRUCT_RENAME(old, new) (void)sizeof(new);
1667#define DNA_STRUCT_RENAME_MEMBER(struct_name, old, new) (void)offsetof(struct_name, new);
1668#include "dna_rename_defs.h"
1669#undef DNA_STRUCT_RENAME
1670#undef DNA_STRUCT_RENAME_MEMBER
1671}
1672
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:87
#define BLI_assert(a)
Definition BLI_assert.h:50
struct GSet GSet
Definition BLI_ghash.h:341
void BLI_gset_clear(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition BLI_ghash.c:1029
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.c:731
GSet * BLI_gset_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.c:860
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition BLI_ghash.c:1034
bool BLI_gset_add(GSet *gs, void *key)
Definition BLI_ghash.c:966
void * BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1)
struct MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
#define BLI_MEMARENA_STD_BUFSIZE
#define STR_ELEM(...)
Definition BLI_string.h:653
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:597
unsigned int uint
#define UNUSED_FUNCTION(x)
#define UNLIKELY(x)
#define ELEM(...)
#define STREQ(a, b)
#define SDNA_RAW_DATA_STRUCT_INDEX
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
static void mul(btAlignedObjectArray< T > &items, const Q &value)
local_group_size(16, 16) .push_constant(Type b
#define printf
int DNA_member_array_num(const char *str)
Definition dna_utils.cc:29
void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_type_map, GHash **r_member_map)
Definition dna_utils.cc:193
uint DNA_member_id_offset_start(const char *member_full)
Definition dna_utils.cc:74
uint DNA_member_id_strip(char *member)
Definition dna_utils.cc:106
uint DNA_member_id_strip_copy(char *member_id_dst, const char *member_full_src)
Definition dna_utils.cc:96
char * DNA_member_id_rename(MemArena *mem_arena, const char *member_id_src, const int member_id_src_len, const char *member_id_dst, const int member_id_dst_len, const char *member_full_src, const int member_full_src_len, const uint member_full_src_offset_len)
Definition dna_utils.cc:134
@ DNA_RENAME_ALIAS_FROM_STATIC
Definition dna_utils.h:89
@ DNA_RENAME_STATIC_FROM_ALIAS
Definition dna_utils.h:88
int len
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
#define str(s)
int count
static int additional_slen_offset
Definition makesdna.cc:107
static bool match_identifier(const char *str, const char *identifier)
Definition makesdna.cc:203
#define MAX_DNA_LINE_LENGTH
Definition makesdna.cc:1229
static short * types_size_native
Definition makesdna.cc:73
static short * types_align_32
Definition makesdna.cc:75
static int preprocess_include(char *maindata, const int maindata_len)
Definition makesdna.cc:566
static short * types_size_32
Definition makesdna.cc:79
void print_struct_sizes()
Definition makesdna.cc:1246
#define BASE_HEADER
Definition makesdna.cc:1558
static int types_num
Definition makesdna.cc:66
static char * match_preproc_strstr(char *__restrict str, const char *__restrict start)
Definition makesdna.cc:552
static bool str_startswith(const char *__restrict str, const char *__restrict start)
Definition makesdna.cc:521
static short * structdata
Definition makesdna.cc:88
GHash * type_map_alias_from_static
Definition makesdna.cc:92
static int add_type(const char *type_name, int size)
Definition makesdna.cc:304
static int make_structDNA(const char *base_directory, FILE *file, FILE *file_offsets, FILE *file_verify)
Definition makesdna.cc:1265
static const char * version_member_static_from_alias(const int type_index, const char *member_alias_full)
Definition makesdna.cc:239
static short * types_size_64
Definition makesdna.cc:81
static bool match_identifier_and_advance(char **str_ptr, const char *identifier)
Definition makesdna.cc:209
static int add_member(const char *member_name)
Definition makesdna.cc:357
static void UNUSED_FUNCTION dna_rename_defs_ensure()
Definition makesdna.cc:1664
static void * read_file_data(const char *filepath, int *r_len)
Definition makesdna.cc:665
GHash * member_map_alias_from_static
Definition makesdna.cc:94
static struct @1325 g_version_data
static int max_data_size
Definition makesdna.cc:64
void BLI_system_backtrace(FILE *fp)
Definition makesdna.cc:119
static char ** types
Definition makesdna.cc:71
static void dna_write(FILE *file, const void *pntr, const int size)
Definition makesdna.cc:1231
static bool check_field_alignment(int firststruct, int struct_type_index, int type, int len, const char *name, const char *detail)
Definition makesdna.cc:903
#define DEBUG_PRINTF(debug_level,...)
Definition makesdna.cc:109
static short * add_struct(int type_index)
Definition makesdna.cc:496
static short ** structs
Definition makesdna.cc:88
static int debugSDNA
Definition makesdna.cc:106
static int convert_include(const char *filepath)
Definition makesdna.cc:706
GHash * type_map_static_from_alias
Definition makesdna.cc:93
static const char * version_struct_alias_from_static(const char *type_static)
Definition makesdna.cc:229
static short * types_align_64
Definition makesdna.cc:77
static bool match_identifier_with_len(const char *str, const char *identifier, const size_t identifier_len)
Definition makesdna.cc:187
#define SDNA_MAX_FILENAME_LENGTH
Definition makesdna.cc:48
static int members_num
Definition makesdna.cc:65
static int max_array_len
Definition makesdna.cc:64
static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char *base_directory)
Definition makesdna.cc:941
#define FORCE_ALIGN_4
static int structs_num
Definition makesdna.cc:67
static const char * version_struct_static_from_alias(const char *type_alias)
Definition makesdna.cc:219
GHash * member_map_static_from_alias
Definition makesdna.cc:95
static const char * includefiles[]
Definition makesdna.cc:52
static MemArena * mem_arena
Definition makesdna.cc:62
static char ** members
Definition makesdna.cc:69
static bool is_name_legal(const char *name)
Definition makesdna.cc:265
static bool match_preproc_prefix(const char *__restrict str, const char *__restrict start)
Definition makesdna.cc:537
static void make_bad_file(const char *file, int line)
Definition makesdna.cc:1547
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
#define L
int main()
_W64 int intptr_t
Definition stdint.h:118