Blender  V2.93
makesdna.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
44 #define DNA_DEPRECATED_ALLOW
45 
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49 
50 #include "MEM_guardedalloc.h"
51 
52 #include "BLI_alloca.h"
53 #include "BLI_ghash.h"
54 #include "BLI_memarena.h"
55 #include "BLI_sys_types.h" /* for intptr_t support */
56 #include "BLI_system.h" /* for 'BLI_system_backtrace' stub. */
57 #include "BLI_utildefines.h"
58 
59 #include "dna_utils.h"
60 
61 #define SDNA_MAX_FILENAME_LENGTH 255
62 
63 /* Included the path relative from /source/blender/ here, so we can move */
64 /* headers around with more freedom. */
65 static const char *includefiles[] = {
66  /* if you add files here, please add them at the end
67  * of makesdna.c (this file) as well */
68  "DNA_listBase.h",
69  "DNA_vec_types.h",
70  "DNA_ID.h",
71  "DNA_ipo_types.h",
72  "DNA_key_types.h",
73  "DNA_text_types.h",
74  "DNA_packedFile_types.h",
75  "DNA_gpu_types.h",
76  "DNA_camera_types.h",
77  "DNA_image_types.h",
78  "DNA_texture_types.h",
79  "DNA_light_types.h",
80  "DNA_material_types.h",
81  "DNA_vfont_types.h",
82  "DNA_meta_types.h",
83  "DNA_curve_types.h",
84  "DNA_mesh_types.h",
85  "DNA_meshdata_types.h",
86  "DNA_modifier_types.h",
87  "DNA_lineart_types.h",
88  "DNA_lattice_types.h",
89  "DNA_object_types.h",
90  "DNA_object_force_types.h",
91  "DNA_object_fluidsim_types.h",
92  "DNA_world_types.h",
93  "DNA_scene_types.h",
94  "DNA_view3d_types.h",
95  "DNA_view2d_types.h",
96  "DNA_space_types.h",
97  "DNA_userdef_types.h",
98  "DNA_screen_types.h",
99  "DNA_sdna_types.h",
100  "DNA_fileglobal_types.h",
101  "DNA_sequence_types.h",
102  "DNA_session_uuid_types.h",
103  "DNA_effect_types.h",
104  "DNA_outliner_types.h",
105  "DNA_sound_types.h",
106  "DNA_collection_types.h",
107  "DNA_armature_types.h",
108  "DNA_action_types.h",
109  "DNA_constraint_types.h",
110  "DNA_nla_types.h",
111  "DNA_node_types.h",
112  "DNA_color_types.h",
113  "DNA_brush_types.h",
114  "DNA_customdata_types.h",
115  "DNA_particle_types.h",
116  "DNA_cloth_types.h",
117  "DNA_gpencil_types.h",
118  "DNA_gpencil_modifier_types.h",
119  "DNA_shader_fx_types.h",
120  "DNA_windowmanager_types.h",
121  "DNA_anim_types.h",
122  "DNA_boid_types.h",
123  "DNA_fluid_types.h",
124  "DNA_speaker_types.h",
125  "DNA_movieclip_types.h",
126  "DNA_tracking_types.h",
127  "DNA_dynamicpaint_types.h",
128  "DNA_mask_types.h",
129  "DNA_rigidbody_types.h",
130  "DNA_freestyle_types.h",
131  "DNA_linestyle_types.h",
132  "DNA_cachefile_types.h",
133  "DNA_layer_types.h",
134  "DNA_workspace_types.h",
135  "DNA_lightprobe_types.h",
136  "DNA_curveprofile_types.h",
137  "DNA_xr_types.h",
138  "DNA_hair_types.h",
139  "DNA_pointcloud_types.h",
140  "DNA_volume_types.h",
141  "DNA_simulation_types.h",
142  "DNA_pointcache_types.h",
143  "DNA_asset_types.h",
144 
145  /* see comment above before editing! */
146 
147  /* empty string to indicate end of includefiles */
148  "",
149 };
150 
151 /* -------------------------------------------------------------------- */
156 
157 static int max_data_size = 500000, max_array_len = 50000;
158 static int names_len = 0;
159 static int types_len = 0;
160 static int structs_len = 0;
162 static char **names;
164 static char **types;
166 static short *types_size_native;
168 static short *types_align_32;
170 static short *types_align_64;
172 static short *types_size_32;
174 static short *types_size_64;
181 static short **structs, *structdata;
182 
184 static struct {
190 
199 static int debugSDNA = 0;
201 
202 #define DEBUG_PRINTF(debug_level, ...) \
203  { \
204  if (debugSDNA > debug_level) { \
205  printf(__VA_ARGS__); \
206  } \
207  } \
208  ((void)0)
209 
210 /* stub for BLI_abort() */
211 #ifndef NDEBUG
212 void BLI_system_backtrace(FILE *fp)
213 {
214  (void)fp;
215 }
216 #endif
217 
220 /* -------------------------------------------------------------------- */
230 static int add_type(const char *str, int size);
231 
237 static int add_name(const char *str);
238 
243 static short *add_struct(int namecode);
244 
249 static int preprocess_include(char *maindata, const int maindata_len);
250 
254 static int convert_include(const char *filename);
255 
259 static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char *base_directory);
260 
264 static void dna_write(FILE *file, const void *pntr, const int size);
265 
269 void print_struct_sizes(void);
270 
273 /* -------------------------------------------------------------------- */
279 static const char *version_struct_static_from_alias(const char *str)
280 {
281  const char *str_test = BLI_ghash_lookup(g_version_data.struct_map_static_from_alias, str);
282  if (str_test != NULL) {
283  return str_test;
284  }
285  return str;
286 }
287 
288 static const char *version_struct_alias_from_static(const char *str)
289 {
290  const char *str_test = BLI_ghash_lookup(g_version_data.struct_map_alias_from_static, str);
291  if (str_test != NULL) {
292  return str_test;
293  }
294  return str;
295 }
296 
297 static const char *version_elem_static_from_alias(const int strct, const char *elem_alias_full)
298 {
299  const uint elem_alias_full_len = strlen(elem_alias_full);
300  char *elem_alias = alloca(elem_alias_full_len + 1);
301  const int elem_alias_len = DNA_elem_id_strip_copy(elem_alias, elem_alias_full);
302  const char *str_pair[2] = {types[strct], elem_alias};
303  const char *elem_static = BLI_ghash_lookup(g_version_data.elem_map_static_from_alias, str_pair);
304  if (elem_static != NULL) {
306  elem_alias,
307  elem_alias_len,
308  elem_static,
309  strlen(elem_static),
310  elem_alias_full,
311  elem_alias_full_len,
312  DNA_elem_id_offset_start(elem_alias_full));
313  }
314  return elem_alias_full;
315 }
316 
321 static bool is_name_legal(const char *name)
322 {
323  const int name_size = strlen(name) + 1;
324  char *name_strip = alloca(name_size);
325  DNA_elem_id_strip_copy(name_strip, name);
326 
327  const char prefix[] = {'p', 'a', 'd'};
328 
329  if (name[0] == '_') {
330  if (strncmp(&name_strip[1], prefix, sizeof(prefix)) != 0) {
331  fprintf(
332  stderr, "Error: only '_pad' variables can start with an underscore, found '%s'\n", name);
333  return false;
334  }
335  }
336  else if (strncmp(name_strip, prefix, sizeof(prefix)) == 0) {
337  int i = sizeof(prefix);
338  if (name_strip[i] >= 'a' && name_strip[i] <= 'z') {
339  /* may be part of a word, allow that. */
340  return true;
341  }
342  bool has_only_digit_or_none = true;
343  for (; name_strip[i]; i++) {
344  const char c = name_strip[i];
345  if (!((c >= '0' && c <= '9') || c == '_')) {
346  has_only_digit_or_none = false;
347  break;
348  }
349  }
350  if (has_only_digit_or_none) {
351  /* found 'pad' or 'pad123'. */
352  fprintf(
353  stderr, "Error: padding variables must be formatted '_pad[number]', found '%s'\n", name);
354  return false;
355  }
356  }
357  return true;
358 }
359 
360 static int add_type(const char *str, int size)
361 {
362  /* first do validity check */
363  if (str[0] == 0) {
364  return -1;
365  }
366  if (strchr(str, '*')) {
367  /* note: this is valid C syntax but we can't parse, complain!
368  * `struct SomeStruct* some_var;` <-- correct but we cant handle right now. */
369  return -1;
370  }
371 
373 
374  /* search through type array */
375  for (int index = 0; index < types_len; index++) {
376  if (STREQ(str, types[index])) {
377  if (size) {
378  types_size_native[index] = size;
379  types_size_32[index] = size;
380  types_size_64[index] = size;
381  types_align_32[index] = size;
382  types_align_64[index] = size;
383  }
384  return index;
385  }
386  }
387 
388  /* append new type */
389  const int str_size = strlen(str) + 1;
390  char *cp = BLI_memarena_alloc(mem_arena, str_size);
391  memcpy(cp, str, str_size);
392  types[types_len] = cp;
398  if (types_len >= max_array_len) {
399  printf("too many types\n");
400  return types_len - 1;
401  }
402  types_len++;
403 
404  return types_len - 1;
405 }
406 
413 static int add_name(const char *str)
414 {
415  char buf[255]; /* stupid limit, change it :) */
416  const char *name;
417 
419 
420  if (str[0] == 0 /* || (str[1] == 0) */) {
421  return -1;
422  }
423 
424  if (str[0] == '(' && str[1] == '*') {
425  /* We handle function pointer and special array cases here, e.g.
426  * `void (*function)(...)` and `float (*array)[..]`. the array case
427  * name is still converted to (array *)() though because it is that
428  * way in old DNA too, and works correct with #DNA_elem_size_nr. */
429  int isfuncptr = (strchr(str + 1, '(')) != NULL;
430 
431  DEBUG_PRINTF(3, "\t\t\t\t*** Function pointer or multidim array pointer found\n");
432  /* functionpointer: transform the type (sometimes) */
433  int i = 0;
434 
435  while (str[i] != ')') {
436  buf[i] = str[i];
437  i++;
438  }
439 
440  /* Another number we need is the extra slen offset. This extra
441  * offset is the overshoot after a space. If there is no
442  * space, no overshoot should be calculated. */
443  int j = i; /* j at first closing brace */
444 
445  DEBUG_PRINTF(3, "first brace after offset %d\n", i);
446 
447  j++; /* j beyond closing brace ? */
448  while ((str[j] != 0) && (str[j] != ')')) {
449  DEBUG_PRINTF(3, "seen %c (%d)\n", str[j], str[j]);
450  j++;
451  }
452  DEBUG_PRINTF(3,
453  "seen %c (%d)\n"
454  "special after offset%d\n",
455  str[j],
456  str[j],
457  j);
458 
459  if (!isfuncptr) {
460  /* multidimensional array pointer case */
461  if (str[j] == 0) {
462  DEBUG_PRINTF(3, "offsetting for multidim array pointer\n");
463  }
464  else {
465  printf("Error during tokening multidim array pointer\n");
466  }
467  }
468  else if (str[j] == 0) {
469  DEBUG_PRINTF(3, "offsetting for space\n");
470  /* get additional offset */
471  int k = 0;
472  while (str[j] != ')') {
473  j++;
474  k++;
475  }
476  DEBUG_PRINTF(3, "extra offset %d\n", k);
478  }
479  else if (str[j] == ')') {
480  DEBUG_PRINTF(3, "offsetting for brace\n");
481  /* don't get extra offset */
482  }
483  else {
484  printf("Error during tokening function pointer argument list\n");
485  }
486 
487  /*
488  * Put `)(void)` at the end? Maybe `)()`. Should check this with
489  * old `sdna`. Actually, sometimes `)()`, sometimes `)(void...)`
490  * Alas.. such is the nature of brain-damage :(
491  *
492  * Sorted it out: always do )(), except for `headdraw` and
493  * `windraw`, part of #ScrArea. This is important, because some
494  * linkers will treat different fp's differently when called
495  * !!! This has to do with interference in byte-alignment and
496  * the way arguments are pushed on the stack.
497  */
498  buf[i] = 0;
499  DEBUG_PRINTF(3, "Name before chomping: %s\n", buf);
500  if ((strncmp(buf, "(*headdraw", 10) == 0) || (strncmp(buf, "(*windraw", 9) == 0)) {
501  buf[i] = ')';
502  buf[i + 1] = '(';
503  buf[i + 2] = 'v';
504  buf[i + 3] = 'o';
505  buf[i + 4] = 'i';
506  buf[i + 5] = 'd';
507  buf[i + 6] = ')';
508  buf[i + 7] = 0;
509  }
510  else {
511  buf[i] = ')';
512  buf[i + 1] = '(';
513  buf[i + 2] = ')';
514  buf[i + 3] = 0;
515  }
516  /* now proceed with buf*/
517  DEBUG_PRINTF(3, "\t\t\t\t\tProposing fp name %s\n", buf);
518  name = buf;
519  }
520  else {
521  /* normal field: old code */
522  name = str;
523  }
524 
525  /* search name array */
526  for (int nr = 0; nr < names_len; nr++) {
527  if (STREQ(name, names[nr])) {
528  return nr;
529  }
530  }
531 
532  /* Sanity check the name. */
533  if (!is_name_legal(name)) {
534  return -1;
535  }
536 
537  /* Append new name. */
538  const int name_size = strlen(name) + 1;
539  char *cp = BLI_memarena_alloc(mem_arena, name_size);
540  memcpy(cp, name, name_size);
541  names[names_len] = cp;
542 
543  if (names_len >= max_array_len) {
544  printf("too many names\n");
545  return names_len - 1;
546  }
547  names_len++;
548 
549  return names_len - 1;
550 }
551 
552 static short *add_struct(int namecode)
553 {
554  if (structs_len == 0) {
555  structs[0] = structdata;
556  }
557  else {
558  short *sp = structs[structs_len - 1];
559  const int len = sp[1];
560  structs[structs_len] = sp + 2 * len + 2;
561  }
562 
563  short *sp = structs[structs_len];
564  sp[0] = namecode;
565 
566  if (structs_len >= max_array_len) {
567  printf("too many structs\n");
568  return sp;
569  }
570  structs_len++;
571 
572  return sp;
573 }
574 
575 static int preprocess_include(char *maindata, const int maindata_len)
576 {
577  /* note: len + 1, last character is a dummy to prevent
578  * comparisons using uninitialized memory */
579  char *temp = MEM_mallocN(maindata_len + 1, "preprocess_include");
580  temp[maindata_len] = ' ';
581 
582  memcpy(temp, maindata, maindata_len);
583 
584  /* remove all c++ comments */
585  /* replace all enters/tabs/etc with spaces */
586  char *cp = temp;
587  int a = maindata_len;
588  int comment = 0;
589  while (a--) {
590  if (cp[0] == '/' && cp[1] == '/') {
591  comment = 1;
592  }
593  else if (*cp == '\n') {
594  comment = 0;
595  }
596  if (comment || *cp < 32 || *cp > 128) {
597  *cp = 32;
598  }
599  cp++;
600  }
601 
602  /* data from temp copy to maindata, remove comments and double spaces */
603  cp = temp;
604  char *md = maindata;
605  int newlen = 0;
606  comment = 0;
607  a = maindata_len;
608  while (a--) {
609 
610  if (cp[0] == '/' && cp[1] == '*') {
611  comment = 1;
612  cp[0] = cp[1] = 32;
613  }
614  if (cp[0] == '*' && cp[1] == '/') {
615  comment = 0;
616  cp[0] = cp[1] = 32;
617  }
618 
619  /* do not copy when: */
620  if (comment) {
621  /* pass */
622  }
623  else if (cp[0] == ' ' && cp[1] == ' ') {
624  /* pass */
625  }
626  else if (cp[-1] == '*' && cp[0] == ' ') {
627  /* pointers with a space */
628  } /* skip special keywords */
629  else if (strncmp("DNA_DEPRECATED", cp, 14) == 0) {
630  /* single values are skipped already, so decrement 1 less */
631  a -= 13;
632  cp += 13;
633  }
634  else {
635  md[0] = cp[0];
636  md++;
637  newlen++;
638  }
639  cp++;
640  }
641 
642  MEM_freeN(temp);
643  return newlen;
644 }
645 
646 static void *read_file_data(const char *filename, int *r_len)
647 {
648 #ifdef WIN32
649  FILE *fp = fopen(filename, "rb");
650 #else
651  FILE *fp = fopen(filename, "r");
652 #endif
653  void *data;
654 
655  if (!fp) {
656  *r_len = -1;
657  return NULL;
658  }
659 
660  fseek(fp, 0L, SEEK_END);
661  *r_len = ftell(fp);
662  fseek(fp, 0L, SEEK_SET);
663 
664  if (*r_len == -1) {
665  fclose(fp);
666  return NULL;
667  }
668 
669  data = MEM_mallocN(*r_len, "read_file_data");
670  if (!data) {
671  *r_len = -1;
672  fclose(fp);
673  return NULL;
674  }
675 
676  if (fread(data, *r_len, 1, fp) != 1) {
677  *r_len = -1;
678  MEM_freeN(data);
679  fclose(fp);
680  return NULL;
681  }
682 
683  fclose(fp);
684  return data;
685 }
686 
687 static int convert_include(const char *filename)
688 {
689  /* read include file, skip structs with a '#' before it.
690  * store all data in temporal arrays.
691  */
692 
693  int maindata_len;
694  char *maindata = read_file_data(filename, &maindata_len);
695  char *md = maindata;
696  if (maindata_len == -1) {
697  fprintf(stderr, "Can't read file %s\n", filename);
698  return 1;
699  }
700 
701  maindata_len = preprocess_include(maindata, maindata_len);
702  char *mainend = maindata + maindata_len - 1;
703 
704  /* we look for '{' and then back to 'struct' */
705  int count = 0;
706  bool skip_struct = false;
707  while (count < maindata_len) {
708 
709  /* code for skipping a struct: two hashes on 2 lines. (preprocess added a space) */
710  if (md[0] == '#' && md[1] == ' ' && md[2] == '#') {
711  skip_struct = true;
712  }
713 
714  if (md[0] == '{') {
715  md[0] = 0;
716  if (skip_struct) {
717  skip_struct = false;
718  }
719  else {
720  if (md[-1] == ' ') {
721  md[-1] = 0;
722  }
723  char *md1 = md - 2;
724  while (*md1 != 32) {
725  /* to beginning of word */
726  md1--;
727  }
728  md1++;
729 
730  /* we've got a struct name when... */
731  if (strncmp(md1 - 7, "struct", 6) == 0) {
732 
733  const int strct = add_type(md1, 0);
734  if (strct == -1) {
735  fprintf(stderr, "File '%s' contains struct we cant parse \"%s\"\n", filename, md1);
736  return 1;
737  }
738 
739  short *structpoin = add_struct(strct);
740  short *sp = structpoin + 2;
741 
742  DEBUG_PRINTF(1, "\t|\t|-- detected struct %s\n", types[strct]);
743 
744  /* first lets make it all nice strings */
745  md1 = md + 1;
746  while (*md1 != '}') {
747  if (md1 > mainend) {
748  break;
749  }
750 
751  if (ELEM(*md1, ',', ' ')) {
752  *md1 = 0;
753  }
754  md1++;
755  }
756 
757  /* read types and names until first character that is not '}' */
758  md1 = md + 1;
759  while (*md1 != '}') {
760  if (md1 > mainend) {
761  break;
762  }
763 
764  /* skip when it says 'struct' or 'unsigned' or 'const' */
765  if (*md1) {
766  if (strncmp(md1, "struct", 6) == 0) {
767  md1 += 7;
768  }
769  if (strncmp(md1, "unsigned", 8) == 0) {
770  md1 += 9;
771  }
772  if (strncmp(md1, "const", 5) == 0) {
773  md1 += 6;
774  }
775 
776  /* we've got a type! */
777  const int type = add_type(md1, 0);
778  if (type == -1) {
779  fprintf(
780  stderr, "File '%s' contains struct we can't parse \"%s\"\n", filename, md1);
781  return 1;
782  }
783 
784  DEBUG_PRINTF(1, "\t|\t|\tfound type %s (", md1);
785 
786  md1 += strlen(md1);
787 
788  /* read until ';' */
789  while (*md1 != ';') {
790  if (md1 > mainend) {
791  break;
792  }
793 
794  if (*md1) {
795  /* We've got a name. slen needs
796  * correction for function
797  * pointers! */
798  int slen = (int)strlen(md1);
799  if (md1[slen - 1] == ';') {
800  md1[slen - 1] = 0;
801 
802  const int name = add_name(version_elem_static_from_alias(strct, md1));
803  if (name == -1) {
804  fprintf(stderr,
805  "File '%s' contains struct with name that can't be added \"%s\"\n",
806  filename,
807  md1);
808  return 1;
809  }
810  slen += additional_slen_offset;
811  sp[0] = type;
812  sp[1] = name;
813 
814  if (names[name] != NULL) {
815  DEBUG_PRINTF(1, "%s |", names[name]);
816  }
817 
818  structpoin[1]++;
819  sp += 2;
820 
821  md1 += slen;
822  break;
823  }
824 
825  const int name = add_name(version_elem_static_from_alias(strct, md1));
826  if (name == -1) {
827  fprintf(stderr,
828  "File '%s' contains struct with name that can't be added \"%s\"\n",
829  filename,
830  md1);
831  return 1;
832  }
833  slen += additional_slen_offset;
834 
835  sp[0] = type;
836  sp[1] = name;
837  if (names[name] != NULL) {
838  DEBUG_PRINTF(1, "%s ||", names[name]);
839  }
840 
841  structpoin[1]++;
842  sp += 2;
843 
844  md1 += slen;
845  }
846  md1++;
847  }
848 
849  DEBUG_PRINTF(1, ")\n");
850  }
851  md1++;
852  }
853  }
854  }
855  }
856  count++;
857  md++;
858  }
859 
860  MEM_freeN(maindata);
861 
862  return 0;
863 }
864 
866  int firststruct, int structtype, int type, int len, const char *name, const char *detail)
867 {
868  bool result = true;
869  if (type < firststruct && types_size_native[type] > 4 && (len % 8)) {
870  fprintf(stderr,
871  "Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n",
872  detail,
873  types[structtype],
874  name,
875  len % 8);
876  result = false;
877  }
878  if (types_size_native[type] > 3 && (len % 4)) {
879  fprintf(stderr,
880  "Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n",
881  detail,
882  types[structtype],
883  name,
884  len % 4);
885  result = false;
886  }
887  if (types_size_native[type] == 2 && (len % 2)) {
888  fprintf(stderr,
889  "Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n",
890  detail,
891  types[structtype],
892  name,
893  len % 2);
894  result = false;
895  }
896  return result;
897 }
898 
899 static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char *base_directory)
900 {
901  bool dna_error = false;
902 
903  /* Write test to verify sizes are accurate. */
904  fprintf(file_verify, "/* Verify struct sizes and member offsets are as expected by DNA. */\n");
905  fprintf(file_verify, "#include \"BLI_assert.h\"\n\n");
906  /* Needed so we can find offsets of deprecated structs. */
907  fprintf(file_verify, "#define DNA_DEPRECATED_ALLOW\n");
908  /* Workaround enum naming collision in static asserts
909  * (ideally this included a unique name/id per file). */
910  fprintf(file_verify, "#define assert_line_ assert_line_DNA_\n");
911  for (int i = 0; *(includefiles[i]) != '\0'; i++) {
912  fprintf(file_verify, "#include \"%s%s\"\n", base_directory, includefiles[i]);
913  }
914  fprintf(file_verify, "#undef assert_line_\n");
915  fprintf(file_verify, "\n");
916 
917  /* Multiple iterations to handle nested structs. */
918  int unknown = structs_len;
919  while (unknown) {
920  const int lastunknown = unknown;
921  unknown = 0;
922 
923  /* check all structs... */
924  for (int a = 0; a < structs_len; a++) {
925  const short *structpoin = structs[a];
926  const int structtype = structpoin[0];
927  const char *structname = version_struct_alias_from_static(types[structtype]);
928 
929  /* when length is not known... */
930  if (types_size_native[structtype] == 0) {
931 
932  const short *sp = structpoin + 2;
933  int size_native = 0;
934  int size_32 = 0;
935  int size_64 = 0;
936  /* Sizes of the largest field in a struct. */
937  int max_align_32 = 0;
938  int max_align_64 = 0;
939 
940  /* check all elements in struct */
941  for (int b = 0; b < structpoin[1]; b++, sp += 2) {
942  int type = sp[0];
943  const char *cp = names[sp[1]];
944  int namelen = (int)strlen(cp);
945 
946  /* Write size verification to file. */
947  {
948  /* Normally 'alloca' would be used here, however we can't in a loop.
949  * Use an over-sized buffer instead. */
950  char name_static[1024];
951  BLI_assert(sizeof(name_static) > namelen);
952 
953  DNA_elem_id_strip_copy(name_static, cp);
954  const char *str_pair[2] = {types[structtype], name_static};
955  const char *name_alias = BLI_ghash_lookup(g_version_data.elem_map_alias_from_static,
956  str_pair);
957  fprintf(file_verify,
958  "BLI_STATIC_ASSERT(offsetof(struct %s, %s) == %d, \"DNA member offset "
959  "verify\");\n",
960  structname,
961  name_alias ? name_alias : name_static,
962  size_native);
963  }
964 
965  /* is it a pointer or function pointer? */
966  if (cp[0] == '*' || cp[1] == '*') {
967  /* has the name an extra length? (array) */
968  int mul = 1;
969  if (cp[namelen - 1] == ']') {
970  mul = DNA_elem_array_size(cp);
971  }
972 
973  if (mul == 0) {
974  fprintf(stderr,
975  "Zero array size found or could not parse %s: '%.*s'\n",
976  types[structtype],
977  namelen + 1,
978  cp);
979  dna_error = 1;
980  }
981 
982  /* 4-8 aligned/ */
983  if (sizeof(void *) == 4) {
984  if (size_native % 4) {
985  fprintf(stderr,
986  "Align pointer error in struct (size_native 4): %s %s\n",
987  types[structtype],
988  cp);
989  dna_error = 1;
990  }
991  }
992  else {
993  if (size_native % 8) {
994  fprintf(stderr,
995  "Align pointer error in struct (size_native 8): %s %s\n",
996  types[structtype],
997  cp);
998  dna_error = 1;
999  }
1000  }
1001 
1002  if (size_64 % 8) {
1003  fprintf(stderr,
1004  "Align pointer error in struct (size_64 8): %s %s\n",
1005  types[structtype],
1006  cp);
1007  dna_error = 1;
1008  }
1009 
1010  size_native += sizeof(void *) * mul;
1011  size_32 += 4 * mul;
1012  size_64 += 8 * mul;
1013  max_align_32 = MAX2(max_align_32, 4);
1014  max_align_64 = MAX2(max_align_64, 8);
1015  }
1016  else if (cp[0] == '[') {
1017  /* parsing can cause names "var" and "[3]"
1018  * to be found for "float var [3]" */
1019  fprintf(stderr,
1020  "Parse error in struct, invalid member name: %s %s\n",
1021  types[structtype],
1022  cp);
1023  dna_error = 1;
1024  }
1025  else if (types_size_native[type]) {
1026  /* has the name an extra length? (array) */
1027  int mul = 1;
1028  if (cp[namelen - 1] == ']') {
1029  mul = DNA_elem_array_size(cp);
1030  }
1031 
1032  if (mul == 0) {
1033  fprintf(stderr,
1034  "Zero array size found or could not parse %s: '%.*s'\n",
1035  types[structtype],
1036  namelen + 1,
1037  cp);
1038  dna_error = 1;
1039  }
1040 
1041  /* struct alignment */
1042  if (type >= firststruct) {
1043  if (sizeof(void *) == 8 && (size_native % 8)) {
1044  fprintf(stderr, "Align struct error: %s %s\n", types[structtype], cp);
1045  dna_error = 1;
1046  }
1047  }
1048 
1049  /* Check 2-4-8 aligned. */
1050  if (!check_field_alignment(firststruct, structtype, type, size_32, cp, "32 bit")) {
1051  dna_error = 1;
1052  }
1053  if (!check_field_alignment(firststruct, structtype, type, size_64, cp, "64 bit")) {
1054  dna_error = 1;
1055  }
1056 
1057  size_native += mul * types_size_native[type];
1058  size_32 += mul * types_size_32[type];
1059  size_64 += mul * types_size_64[type];
1060  max_align_32 = MAX2(max_align_32, types_align_32[type]);
1061  max_align_64 = MAX2(max_align_64, types_align_64[type]);
1062  }
1063  else {
1064  size_native = 0;
1065  size_32 = 0;
1066  size_64 = 0;
1067  break;
1068  }
1069  }
1070 
1071  if (size_native == 0) {
1072  unknown++;
1073  }
1074  else {
1075  types_size_native[structtype] = size_native;
1076  types_size_32[structtype] = size_32;
1077  types_size_64[structtype] = size_64;
1078  types_align_32[structtype] = max_align_32;
1079  types_align_64[structtype] = max_align_64;
1080 
1081  /* Santiy check 1: alignment should never be 0. */
1082  BLI_assert(max_align_32);
1083  BLI_assert(max_align_64);
1084 
1085  /* Santiy check 2: alignment should always be equal or smaller than the maximum
1086  * size of a build in type which is 8 bytes (ie int64_t or double). */
1087  BLI_assert(max_align_32 <= 8);
1088  BLI_assert(max_align_64 <= 8);
1089 
1090  if (size_32 % max_align_32) {
1091  /* There is an one odd case where only the 32 bit struct has alignment issues
1092  * and the 64 bit does not, that can only be fixed by adding a padding pointer
1093  * to the struct to resolve the problem. */
1094  if ((size_64 % max_align_64 == 0) && (size_32 % max_align_32 == 4)) {
1095  fprintf(stderr,
1096  "Sizeerror in 32 bit struct: %s (add paddding pointer)\n",
1097  types[structtype]);
1098  }
1099  else {
1100  fprintf(stderr,
1101  "Sizeerror in 32 bit struct: %s (add %d bytes)\n",
1102  types[structtype],
1103  max_align_32 - (size_32 % max_align_32));
1104  }
1105  dna_error = 1;
1106  }
1107 
1108  if (size_64 % max_align_64) {
1109  fprintf(stderr,
1110  "Sizeerror in 64 bit struct: %s (add %d bytes)\n",
1111  types[structtype],
1112  max_align_64 - (size_64 % max_align_64));
1113  dna_error = 1;
1114  }
1115 
1116  if (size_native % 4 && !ELEM(size_native, 1, 2)) {
1117  fprintf(stderr,
1118  "Sizeerror 4 in struct: %s (add %d bytes)\n",
1119  types[structtype],
1120  size_native % 4);
1121  dna_error = 1;
1122  }
1123 
1124  /* Write size verification to file. */
1125  fprintf(file_verify,
1126  "BLI_STATIC_ASSERT(sizeof(struct %s) == %d, \"DNA struct size verify\");\n\n",
1127  structname,
1128  size_native);
1129  }
1130  }
1131  }
1132 
1133  if (unknown == lastunknown) {
1134  break;
1135  }
1136  }
1137 
1138  if (unknown) {
1139  fprintf(stderr, "ERROR: still %d structs unknown\n", unknown);
1140 
1141  if (debugSDNA) {
1142  fprintf(stderr, "*** Known structs :\n");
1143 
1144  for (int a = 0; a < structs_len; a++) {
1145  const short *structpoin = structs[a];
1146  const int structtype = structpoin[0];
1147 
1148  /* length unknown */
1149  if (types_size_native[structtype] != 0) {
1150  fprintf(stderr, " %s\n", types[structtype]);
1151  }
1152  }
1153  }
1154 
1155  fprintf(stderr, "*** Unknown structs :\n");
1156 
1157  for (int a = 0; a < structs_len; a++) {
1158  const short *structpoin = structs[a];
1159  const int structtype = structpoin[0];
1160 
1161  /* length unknown yet */
1162  if (types_size_native[structtype] == 0) {
1163  fprintf(stderr, " %s\n", types[structtype]);
1164  }
1165  }
1166 
1167  dna_error = 1;
1168  }
1169 
1170  return dna_error;
1171 }
1172 
1173 #define MAX_DNA_LINE_LENGTH 20
1174 
1175 static void dna_write(FILE *file, const void *pntr, const int size)
1176 {
1177  static int linelength = 0;
1178  const char *data = (const char *)pntr;
1179 
1180  for (int i = 0; i < size; i++) {
1181  fprintf(file, "%d, ", data[i]);
1182  linelength++;
1183  if (linelength >= MAX_DNA_LINE_LENGTH) {
1184  fprintf(file, "\n");
1185  linelength = 0;
1186  }
1187  }
1188 }
1189 
1191 {
1192  int unknown = structs_len;
1193  printf("\n\n*** All detected structs:\n");
1194 
1195  while (unknown) {
1196  unknown = 0;
1197 
1198  /* check all structs... */
1199  for (int a = 0; a < structs_len; a++) {
1200  const short *structpoin = structs[a];
1201  const int structtype = structpoin[0];
1202  printf("\t%s\t:%d\n", types[structtype], types_size_native[structtype]);
1203  }
1204  }
1205 
1206  printf("*** End of list\n");
1207 }
1208 
1209 static int make_structDNA(const char *base_directory,
1210  FILE *file,
1211  FILE *file_offsets,
1212  FILE *file_verify)
1213 {
1214  if (debugSDNA > 0) {
1215  fflush(stdout);
1216  printf("Running makesdna at debug level %d\n", debugSDNA);
1217  }
1218 
1220 
1221  /* the longest known struct is 50k, so we assume 100k is sufficient! */
1222  structdata = MEM_callocN(max_data_size, "structdata");
1223 
1224  /* a maximum of 5000 variables, must be sufficient? */
1225  names = MEM_callocN(sizeof(char *) * max_array_len, "names");
1226  types = MEM_callocN(sizeof(char *) * max_array_len, "types");
1227  types_size_native = MEM_callocN(sizeof(short) * max_array_len, "types_size_native");
1228  types_size_32 = MEM_callocN(sizeof(short) * max_array_len, "types_size_32");
1229  types_size_64 = MEM_callocN(sizeof(short) * max_array_len, "types_size_64");
1230  types_align_32 = MEM_callocN(sizeof(short) * max_array_len, "types_size_32");
1231  types_align_64 = MEM_callocN(sizeof(short) * max_array_len, "types_size_64");
1232 
1233  structs = MEM_callocN(sizeof(short *) * max_array_len, "structs");
1234 
1235  /* Build versioning data */
1237  &g_version_data.struct_map_alias_from_static,
1238  &g_version_data.elem_map_alias_from_static);
1240  &g_version_data.struct_map_static_from_alias,
1241  &g_version_data.elem_map_static_from_alias);
1242 
1250  add_type("char", 1); /* SDNA_TYPE_CHAR */
1251  add_type("uchar", 1); /* SDNA_TYPE_UCHAR */
1252  add_type("short", 2); /* SDNA_TYPE_SHORT */
1253  add_type("ushort", 2); /* SDNA_TYPE_USHORT */
1254  add_type("int", 4); /* SDNA_TYPE_INT */
1255 
1256  /* note, long isn't supported,
1257  * these are place-holders to maintain alignment with eSDNA_Type*/
1258  add_type("long", 4); /* SDNA_TYPE_LONG */
1259  add_type("ulong", 4); /* SDNA_TYPE_ULONG */
1260 
1261  add_type("float", 4); /* SDNA_TYPE_FLOAT */
1262  add_type("double", 8); /* SDNA_TYPE_DOUBLE */
1263  add_type("int64_t", 8); /* SDNA_TYPE_INT64 */
1264  add_type("uint64_t", 8); /* SDNA_TYPE_UINT64 */
1265  add_type("void", 0); /* SDNA_TYPE_VOID */
1266  add_type("int8_t", 1); /* SDNA_TYPE_INT8 */
1267 
1268  /* the defines above shouldn't be output in the padding file... */
1269  const int firststruct = types_len;
1270 
1271  /* add all include files defined in the global array */
1272  /* Since the internal file+path name buffer has limited length, I do a */
1273  /* little test first... */
1274  /* Mind the breaking condition here! */
1275  DEBUG_PRINTF(0, "\tStart of header scan:\n");
1276  int header_count = 0;
1277  for (int i = 0; *(includefiles[i]) != '\0'; i++) {
1278  header_count++;
1279 
1280  /* str contains filenames. Since we now include paths, I stretched */
1281  /* it a bit. Hope this is enough :) -nzc- */
1283  sprintf(str, "%s%s", base_directory, includefiles[i]);
1284  DEBUG_PRINTF(0, "\t|-- Converting %s\n", str);
1285  if (convert_include(str)) {
1286  return 1;
1287  }
1288  }
1289  DEBUG_PRINTF(0, "\tFinished scanning %d headers.\n", header_count);
1290 
1291  if (calculate_struct_sizes(firststruct, file_verify, base_directory)) {
1292  /* error */
1293  return 1;
1294  }
1295 
1296  /* FOR DEBUG */
1297  if (debugSDNA > 1) {
1298  int a, b;
1299  /* short *elem; */
1300  short num_types;
1301 
1302  printf("names_len %d types_len %d structs_len %d\n", names_len, types_len, structs_len);
1303  for (a = 0; a < names_len; a++) {
1304  printf(" %s\n", names[a]);
1305  }
1306  printf("\n");
1307 
1308  const short *sp = types_size_native;
1309  for (a = 0; a < types_len; a++, sp++) {
1310  printf(" %s %d\n", types[a], *sp);
1311  }
1312  printf("\n");
1313 
1314  for (a = 0; a < structs_len; a++) {
1315  sp = structs[a];
1316  printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], types_size_native[sp[0]]);
1317  num_types = sp[1];
1318  sp += 2;
1319  /* ? num_types was elem? */
1320  for (b = 0; b < num_types; b++, sp += 2) {
1321  printf(" %s %s allign32:%d, allign64:%d\n",
1322  types[sp[0]],
1323  names[sp[1]],
1324  types_align_32[sp[0]],
1325  types_align_64[sp[0]]);
1326  }
1327  }
1328  }
1329 
1330  /* file writing */
1331 
1332  DEBUG_PRINTF(0, "Writing file ... ");
1333 
1334  if (names_len == 0 || structs_len == 0) {
1335  /* pass */
1336  }
1337  else {
1338  const char nil_bytes[4] = {0};
1339 
1340  dna_write(file, "SDNA", 4);
1341 
1342  /* write names */
1343  dna_write(file, "NAME", 4);
1344  int len = names_len;
1345  dna_write(file, &len, 4);
1346  /* write array */
1347  len = 0;
1348  for (int nr = 0; nr < names_len; nr++) {
1349  int name_size = strlen(names[nr]) + 1;
1350  dna_write(file, names[nr], name_size);
1351  len += name_size;
1352  }
1353  int len_align = (len + 3) & ~3;
1354  if (len != len_align) {
1355  dna_write(file, nil_bytes, len_align - len);
1356  }
1357 
1358  /* write TYPES */
1359  dna_write(file, "TYPE", 4);
1360  len = types_len;
1361  dna_write(file, &len, 4);
1362  /* write array */
1363  len = 0;
1364  for (int nr = 0; nr < types_len; nr++) {
1365  int type_size = strlen(types[nr]) + 1;
1366  dna_write(file, types[nr], type_size);
1367  len += type_size;
1368  }
1369  len_align = (len + 3) & ~3;
1370  if (len != len_align) {
1371  dna_write(file, nil_bytes, len_align - len);
1372  }
1373 
1374  /* WRITE TYPELENGTHS */
1375  dna_write(file, "TLEN", 4);
1376 
1377  len = 2 * types_len;
1378  if (types_len & 1) {
1379  len += 2;
1380  }
1382 
1383  /* WRITE STRUCTS */
1384  dna_write(file, "STRC", 4);
1385  len = structs_len;
1386  dna_write(file, &len, 4);
1387 
1388  /* calc datablock size */
1389  const short *sp = structs[structs_len - 1];
1390  sp += 2 + 2 * (sp[1]);
1391  len = (intptr_t)((char *)sp - (char *)structs[0]);
1392  len = (len + 3) & ~3;
1393 
1394  dna_write(file, structs[0], len);
1395  }
1396 
1397  /* write a simple enum with all structs offsets,
1398  * should only be accessed via SDNA_TYPE_FROM_STRUCT macro */
1399  {
1400  fprintf(file_offsets, "#pragma once\n");
1401  fprintf(file_offsets, "#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n");
1402  fprintf(file_offsets, "enum {\n");
1403  for (int i = 0; i < structs_len; i++) {
1404  const short *structpoin = structs[i];
1405  const int structtype = structpoin[0];
1406  fprintf(file_offsets,
1407  "\t_SDNA_TYPE_%s = %d,\n",
1409  i);
1410  }
1411  fprintf(file_offsets, "\tSDNA_TYPE_MAX = %d,\n", structs_len);
1412  fprintf(file_offsets, "};\n\n");
1413  }
1414 
1415  /* Check versioning errors which could cause duplicate names,
1416  * do last because names are stripped. */
1417  {
1418  GSet *names_unique = BLI_gset_str_new_ex(__func__, 512);
1419  for (int struct_nr = 0; struct_nr < structs_len; struct_nr++) {
1420  const short *sp = structs[struct_nr];
1421  const char *struct_name = types[sp[0]];
1422  const int len = sp[1];
1423  sp += 2;
1424  for (int a = 0; a < len; a++, sp += 2) {
1425  char *name = names[sp[1]];
1426  DNA_elem_id_strip(name);
1427  if (!BLI_gset_add(names_unique, name)) {
1428  fprintf(stderr,
1429  "Error: duplicate name found '%s.%s', "
1430  "likely cause is 'dna_rename_defs.h'\n",
1431  struct_name,
1432  name);
1433  return 1;
1434  }
1435  }
1436  BLI_gset_clear(names_unique, NULL);
1437  }
1438  BLI_gset_free(names_unique, NULL);
1439  }
1440 
1442  MEM_freeN(names);
1443  MEM_freeN(types);
1449  MEM_freeN(structs);
1450 
1452 
1453  BLI_ghash_free(g_version_data.struct_map_alias_from_static, NULL, NULL);
1454  BLI_ghash_free(g_version_data.struct_map_static_from_alias, NULL, NULL);
1455  BLI_ghash_free(g_version_data.elem_map_static_from_alias, MEM_freeN, NULL);
1456  BLI_ghash_free(g_version_data.elem_map_alias_from_static, MEM_freeN, NULL);
1457 
1458  DEBUG_PRINTF(0, "done.\n");
1459 
1460  return 0;
1461 }
1462 
1465 /* end make DNA. */
1466 
1467 /* -------------------------------------------------------------------- */
1471 static void make_bad_file(const char *file, int line)
1472 {
1473  FILE *fp = fopen(file, "w");
1474  fprintf(fp,
1475  "#error \"Error! can't make correct DNA.c file from %s:%d, check alignment.\"\n",
1476  __FILE__,
1477  line);
1478  fclose(fp);
1479 }
1480 
1481 #ifndef BASE_HEADER
1482 # define BASE_HEADER "../"
1483 #endif
1484 
1485 int main(int argc, char **argv)
1486 {
1487  int return_status = 0;
1488 
1489  if (!ELEM(argc, 4, 5)) {
1490  printf("Usage: %s dna.c dna_struct_offsets.h [base directory]\n", argv[0]);
1491  return_status = 1;
1492  }
1493  else {
1494  FILE *file_dna = fopen(argv[1], "w");
1495  FILE *file_dna_offsets = fopen(argv[2], "w");
1496  FILE *file_dna_verify = fopen(argv[3], "w");
1497  if (!file_dna) {
1498  printf("Unable to open file: %s\n", argv[1]);
1499  return_status = 1;
1500  }
1501  else if (!file_dna_offsets) {
1502  printf("Unable to open file: %s\n", argv[2]);
1503  return_status = 1;
1504  }
1505  else if (!file_dna_verify) {
1506  printf("Unable to open file: %s\n", argv[3]);
1507  return_status = 1;
1508  }
1509  else {
1510  const char *base_directory;
1511 
1512  if (argc == 5) {
1513  base_directory = argv[4];
1514  }
1515  else {
1516  base_directory = BASE_HEADER;
1517  }
1518 
1519  fprintf(file_dna, "extern const unsigned char DNAstr[];\n");
1520  fprintf(file_dna, "const unsigned char DNAstr[] = {\n");
1521  if (make_structDNA(base_directory, file_dna, file_dna_offsets, file_dna_verify)) {
1522  /* error */
1523  fclose(file_dna);
1524  file_dna = NULL;
1525  make_bad_file(argv[1], __LINE__);
1526  return_status = 1;
1527  }
1528  else {
1529  fprintf(file_dna, "};\n");
1530  fprintf(file_dna, "extern const int DNAlen;\n");
1531  fprintf(file_dna, "const int DNAlen = sizeof(DNAstr);\n");
1532  }
1533  }
1534 
1535  if (file_dna) {
1536  fclose(file_dna);
1537  }
1538  if (file_dna_offsets) {
1539  fclose(file_dna_offsets);
1540  }
1541  if (file_dna_verify) {
1542  fclose(file_dna_verify);
1543  }
1544  }
1545 
1546  return return_status;
1547 }
1548 
1549 /* handy but fails on struct bounds which makesdna doesn't care about
1550  * with quite the same strictness as GCC does */
1551 #if 0
1552 /* include files for automatic dependencies */
1553 
1554 /* extra safety check that we are aligned,
1555  * warnings here are easier to fix the makesdna's */
1556 # ifdef __GNUC__
1557 # pragma GCC diagnostic error "-Wpadded"
1558 # endif
1559 
1560 #endif /* if 0 */
1561 
1571 #ifdef __GNUC__
1572 # pragma GCC poison long
1573 #endif
1574 
1575 #include "DNA_ID.h"
1576 #include "DNA_action_types.h"
1577 #include "DNA_anim_types.h"
1578 #include "DNA_armature_types.h"
1579 #include "DNA_asset_types.h"
1580 #include "DNA_boid_types.h"
1581 #include "DNA_brush_types.h"
1582 #include "DNA_cachefile_types.h"
1583 #include "DNA_camera_types.h"
1584 #include "DNA_cloth_types.h"
1585 #include "DNA_collection_types.h"
1586 #include "DNA_color_types.h"
1587 #include "DNA_constraint_types.h"
1588 #include "DNA_curve_types.h"
1589 #include "DNA_curveprofile_types.h"
1590 #include "DNA_customdata_types.h"
1591 #include "DNA_dynamicpaint_types.h"
1592 #include "DNA_effect_types.h"
1593 #include "DNA_fileglobal_types.h"
1594 #include "DNA_fluid_types.h"
1595 #include "DNA_freestyle_types.h"
1597 #include "DNA_gpencil_types.h"
1598 #include "DNA_hair_types.h"
1599 #include "DNA_image_types.h"
1600 #include "DNA_ipo_types.h"
1601 #include "DNA_key_types.h"
1602 #include "DNA_lattice_types.h"
1603 #include "DNA_layer_types.h"
1604 #include "DNA_light_types.h"
1605 #include "DNA_lightprobe_types.h"
1606 #include "DNA_lineart_types.h"
1607 #include "DNA_linestyle_types.h"
1608 #include "DNA_listBase.h"
1609 #include "DNA_mask_types.h"
1610 #include "DNA_material_types.h"
1611 #include "DNA_mesh_types.h"
1612 #include "DNA_meshdata_types.h"
1613 #include "DNA_meta_types.h"
1614 #include "DNA_modifier_types.h"
1615 #include "DNA_movieclip_types.h"
1616 #include "DNA_nla_types.h"
1617 #include "DNA_node_types.h"
1618 #include "DNA_object_fluidsim_types.h"
1619 #include "DNA_object_force_types.h"
1620 #include "DNA_object_types.h"
1621 #include "DNA_outliner_types.h"
1622 #include "DNA_packedFile_types.h"
1623 #include "DNA_particle_types.h"
1624 #include "DNA_pointcache_types.h"
1625 #include "DNA_pointcloud_types.h"
1626 #include "DNA_rigidbody_types.h"
1627 #include "DNA_scene_types.h"
1628 #include "DNA_screen_types.h"
1629 #include "DNA_sdna_types.h"
1630 #include "DNA_sequence_types.h"
1631 #include "DNA_session_uuid_types.h"
1632 #include "DNA_shader_fx_types.h"
1633 #include "DNA_simulation_types.h"
1634 #include "DNA_sound_types.h"
1635 #include "DNA_space_types.h"
1636 #include "DNA_speaker_types.h"
1637 #include "DNA_text_types.h"
1638 #include "DNA_texture_types.h"
1639 #include "DNA_tracking_types.h"
1640 #include "DNA_userdef_types.h"
1641 #include "DNA_vec_types.h"
1642 #include "DNA_vfont_types.h"
1643 #include "DNA_view2d_types.h"
1644 #include "DNA_view3d_types.h"
1645 #include "DNA_volume_types.h"
1646 #include "DNA_windowmanager_types.h"
1647 #include "DNA_workspace_types.h"
1648 #include "DNA_world_types.h"
1649 #include "DNA_xr_types.h"
1650 
1651 /* end of list */
1652 
1655 /* -------------------------------------------------------------------- */
1664 {
1665 #define DNA_STRUCT_RENAME(old, new) (void)sizeof(new);
1666 #define DNA_STRUCT_RENAME_ELEM(struct_name, old, new) (void)offsetof(struct_name, new);
1667 #include "dna_rename_defs.h"
1668 #undef DNA_STRUCT_RENAME
1669 #undef DNA_STRUCT_RENAME_ELEM
1670 }
1671 
#define BLI_assert(a)
Definition: BLI_assert.h:58
struct GSet GSet
Definition: BLI_ghash.h:189
GSet * BLI_gset_str_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_gset_clear(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition: BLI_ghash.c:1248
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:1008
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition: BLI_ghash.c:1253
bool BLI_gset_add(GSet *gs, void *key)
Definition: BLI_ghash.c:1160
void * BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:803
void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1)
Definition: BLI_memarena.c:109
#define BLI_MEMARENA_STD_BUFSIZE
Definition: BLI_memarena.h:36
void * BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
Definition: BLI_memarena.c:131
struct MemArena * BLI_memarena_new(const size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2) ATTR_MALLOC
Definition: BLI_memarena.c:79
unsigned int uint
Definition: BLI_sys_types.h:83
#define UNUSED_FUNCTION(x)
#define MAX2(a, b)
#define ELEM(...)
#define STREQ(a, b)
ID and Library types, which are fundamental for sdna.
Object groups, one object can be in many groups at once.
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
Types and defines for representing Rigid Body entities.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
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)
FILE * file
uint DNA_elem_id_strip(char *elem)
Definition: dna_utils.c:122
char * DNA_elem_id_rename(struct MemArena *mem_arena, const char *elem_src, const int elem_src_len, const char *elem_dst, const int elem_dst_len, const char *elem_src_full, const int elem_src_full_len, const uint elem_src_full_offset_len)
Definition: dna_utils.c:157
void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_struct_map, GHash **r_elem_map)
Definition: dna_utils.c:210
uint DNA_elem_id_offset_start(const char *elem_full)
Definition: dna_utils.c:91
uint DNA_elem_id_strip_copy(char *elem_dst, const char *elem_src)
Definition: dna_utils.c:112
int DNA_elem_array_size(const char *str)
Definition: dna_utils.c:46
@ DNA_RENAME_ALIAS_FROM_STATIC
Definition: dna_utils.h:52
@ DNA_RENAME_STATIC_FROM_ALIAS
Definition: dna_utils.h:51
#define str(s)
int count
static int additional_slen_offset
Definition: makesdna.c:200
static const char * version_struct_alias_from_static(const char *str)
Definition: makesdna.c:288
static int types_len
Definition: makesdna.c:159
static void * read_file_data(const char *filename, int *r_len)
Definition: makesdna.c:646
#define MAX_DNA_LINE_LENGTH
Definition: makesdna.c:1173
static char ** names
Definition: makesdna.c:162
static short * types_size_native
Definition: makesdna.c:166
static short * types_align_32
Definition: makesdna.c:168
static int preprocess_include(char *maindata, const int maindata_len)
Definition: makesdna.c:575
static int convert_include(const char *filename)
Definition: makesdna.c:687
static short * types_size_32
Definition: makesdna.c:172
int main(int argc, char **argv)
Definition: makesdna.c:1485
static struct @1095 g_version_data
#define BASE_HEADER
Definition: makesdna.c:1482
static const char * version_elem_static_from_alias(const int strct, const char *elem_alias_full)
Definition: makesdna.c:297
static short * structdata
Definition: makesdna.c:181
static int make_structDNA(const char *base_directory, FILE *file, FILE *file_offsets, FILE *file_verify)
Definition: makesdna.c:1209
static short * types_size_64
Definition: makesdna.c:174
static short * add_struct(int namecode)
Definition: makesdna.c:552
static int structs_len
Definition: makesdna.c:160
static int max_data_size
Definition: makesdna.c:157
void BLI_system_backtrace(FILE *fp)
Definition: makesdna.c:212
static char ** types
Definition: makesdna.c:164
static int add_name(const char *str)
Definition: makesdna.c:413
void print_struct_sizes(void)
Definition: makesdna.c:1190
GHash * struct_map_static_from_alias
Definition: makesdna.c:186
static void dna_write(FILE *file, const void *pntr, const int size)
Definition: makesdna.c:1175
static int names_len
Definition: makesdna.c:158
static int add_type(const char *str, int size)
Definition: makesdna.c:360
#define DEBUG_PRINTF(debug_level,...)
Definition: makesdna.c:202
static short ** structs
Definition: makesdna.c:181
GHash * elem_map_static_from_alias
Definition: makesdna.c:188
static const char * version_struct_static_from_alias(const char *str)
Definition: makesdna.c:279
static int debugSDNA
Definition: makesdna.c:199
GHash * elem_map_alias_from_static
Definition: makesdna.c:187
GHash * struct_map_alias_from_static
Definition: makesdna.c:185
static short * types_align_64
Definition: makesdna.c:170
static void UNUSED_FUNCTION() dna_rename_defs_ensure(void)
Definition: makesdna.c:1663
static bool check_field_alignment(int firststruct, int structtype, int type, int len, const char *name, const char *detail)
Definition: makesdna.c:865
#define SDNA_MAX_FILENAME_LENGTH
Definition: makesdna.c:61
static int max_array_len
Definition: makesdna.c:157
static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char *base_directory)
Definition: makesdna.c:899
static const char * includefiles[]
Definition: makesdna.c:65
static MemArena * mem_arena
Definition: makesdna.c:155
static bool is_name_legal(const char *name)
Definition: makesdna.c:321
static void make_bad_file(const char *file, int line)
Definition: makesdna.c:1471
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
#define L
static unsigned c
Definition: RandGen.cpp:97
static unsigned a[3]
Definition: RandGen.cpp:92
_W64 int intptr_t
Definition: stdint.h:121
uint len