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