[Bf-blender-cvs] [b5ad69832e9] master: Cleanup: reduce variable scopes
Jacques Lucke
noreply at git.blender.org
Fri Oct 2 13:05:18 CEST 2020
Commit: b5ad69832e99f4f4d1bbdac2e57bccb303ba05f5
Author: Jacques Lucke
Date: Fri Oct 2 13:03:39 2020 +0200
Branches: master
https://developer.blender.org/rBb5ad69832e99f4f4d1bbdac2e57bccb303ba05f5
Cleanup: reduce variable scopes
===================================================================
M source/blender/makesdna/intern/makesdna.c
===================================================================
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c
index f5a35783dca..3782f265913 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -354,8 +354,6 @@ static bool is_name_legal(const char *name)
static int add_type(const char *str, int size)
{
- char *cp;
-
/* first do validity check */
if (str[0] == 0) {
return -1;
@@ -382,7 +380,7 @@ static int add_type(const char *str, int size)
/* append new type */
const int str_size = strlen(str) + 1;
- cp = BLI_memarena_alloc(mem_arena, str_size);
+ char *cp = BLI_memarena_alloc(mem_arena, str_size);
memcpy(cp, str, str_size);
types[types_len] = cp;
types_size_native[types_len] = size;
@@ -408,8 +406,6 @@ static int add_type(const char *str, int size)
* */
static int add_name(const char *str)
{
- int nr, i, j, k;
- char *cp;
char buf[255]; /* stupid limit, change it :) */
const char *name;
@@ -428,7 +424,7 @@ static int add_name(const char *str)
DEBUG_PRINTF(3, "\t\t\t\t*** Function pointer or multidim array pointer found\n");
/* functionpointer: transform the type (sometimes) */
- i = 0;
+ int i = 0;
while (str[i] != ')') {
buf[i] = str[i];
@@ -438,7 +434,7 @@ static int add_name(const char *str)
/* Another number we need is the extra slen offset. This extra
* offset is the overshoot after a space. If there is no
* space, no overshoot should be calculated. */
- j = i; /* j at first closing brace */
+ int j = i; /* j at first closing brace */
DEBUG_PRINTF(3, "first brace after offset %d\n", i);
@@ -466,7 +462,7 @@ static int add_name(const char *str)
else if (str[j] == 0) {
DEBUG_PRINTF(3, "offsetting for space\n");
/* get additional offset */
- k = 0;
+ int k = 0;
while (str[j] != ')') {
j++;
k++;
@@ -522,7 +518,7 @@ static int add_name(const char *str)
}
/* search name array */
- for (nr = 0; nr < names_len; nr++) {
+ for (int nr = 0; nr < names_len; nr++) {
if (STREQ(name, names[nr])) {
return nr;
}
@@ -535,7 +531,7 @@ static int add_name(const char *str)
/* Append new name. */
const int name_size = strlen(name) + 1;
- cp = BLI_memarena_alloc(mem_arena, name_size);
+ char *cp = BLI_memarena_alloc(mem_arena, name_size);
memcpy(cp, name, name_size);
names[names_len] = cp;
@@ -550,19 +546,16 @@ static int add_name(const char *str)
static short *add_struct(int namecode)
{
- int len;
- short *sp;
-
if (structs_len == 0) {
structs[0] = structdata;
}
else {
- sp = structs[structs_len - 1];
- len = sp[1];
+ short *sp = structs[structs_len - 1];
+ const int len = sp[1];
structs[structs_len] = sp + 2 * len + 2;
}
- sp = structs[structs_len];
+ short *sp = structs[structs_len];
sp[0] = namecode;
if (structs_len >= max_array_len) {
@@ -576,21 +569,18 @@ static short *add_struct(int namecode)
static int preprocess_include(char *maindata, const int maindata_len)
{
- int a, newlen, comment = 0;
- char *cp, *temp, *md;
-
/* note: len + 1, last character is a dummy to prevent
* comparisons using uninitialized memory */
- temp = MEM_mallocN(maindata_len + 1, "preprocess_include");
+ char *temp = MEM_mallocN(maindata_len + 1, "preprocess_include");
temp[maindata_len] = ' ';
memcpy(temp, maindata, maindata_len);
/* remove all c++ comments */
/* replace all enters/tabs/etc with spaces */
- cp = temp;
- a = maindata_len;
- comment = 0;
+ char *cp = temp;
+ int a = maindata_len;
+ int comment = 0;
while (a--) {
if (cp[0] == '/' && cp[1] == '/') {
comment = 1;
@@ -606,8 +596,8 @@ static int preprocess_include(char *maindata, const int maindata_len)
/* data from temp copy to maindata, remove comments and double spaces */
cp = temp;
- md = maindata;
- newlen = 0;
+ char *md = maindata;
+ int newlen = 0;
comment = 0;
a = maindata_len;
while (a--) {
@@ -694,23 +684,21 @@ static int convert_include(const char *filename)
/* read include file, skip structs with a '#' before it.
* store all data in temporal arrays.
*/
- int maindata_len, count, slen, type, name, strct;
- short *structpoin, *sp;
- char *maindata, *mainend, *md, *md1;
- bool skip_struct;
- md = maindata = read_file_data(filename, &maindata_len);
+ int maindata_len;
+ char *maindata = read_file_data(filename, &maindata_len);
+ char *md = maindata;
if (maindata_len == -1) {
fprintf(stderr, "Can't read file %s\n", filename);
return 1;
}
maindata_len = preprocess_include(maindata, maindata_len);
- mainend = maindata + maindata_len - 1;
+ char *mainend = maindata + maindata_len - 1;
/* we look for '{' and then back to 'struct' */
- count = 0;
- skip_struct = false;
+ int count = 0;
+ bool skip_struct = false;
while (count < maindata_len) {
/* code for skipping a struct: two hashes on 2 lines. (preprocess added a space) */
@@ -727,7 +715,7 @@ static int convert_include(const char *filename)
if (md[-1] == ' ') {
md[-1] = 0;
}
- md1 = md - 2;
+ char *md1 = md - 2;
while (*md1 != 32) {
/* to beginning of word */
md1--;
@@ -737,14 +725,14 @@ static int convert_include(const char *filename)
/* we've got a struct name when... */
if (strncmp(md1 - 7, "struct", 6) == 0) {
- strct = add_type(md1, 0);
+ const int strct = add_type(md1, 0);
if (strct == -1) {
fprintf(stderr, "File '%s' contains struct we cant parse \"%s\"\n", filename, md1);
return 1;
}
- structpoin = add_struct(strct);
- sp = structpoin + 2;
+ short *structpoin = add_struct(strct);
+ short *sp = structpoin + 2;
DEBUG_PRINTF(1, "\t|\t|-- detected struct %s\n", types[strct]);
@@ -781,7 +769,7 @@ static int convert_include(const char *filename)
}
/* we've got a type! */
- type = add_type(md1, 0);
+ const int type = add_type(md1, 0);
if (type == -1) {
fprintf(
stderr, "File '%s' contains struct we can't parse \"%s\"\n", filename, md1);
@@ -802,11 +790,11 @@ static int convert_include(const char *filename)
/* We've got a name. slen needs
* correction for function
* pointers! */
- slen = (int)strlen(md1);
+ int slen = (int)strlen(md1);
if (md1[slen - 1] == ';') {
md1[slen - 1] = 0;
- name = add_name(version_elem_static_from_alias(strct, md1));
+ const int name = add_name(version_elem_static_from_alias(strct, md1));
if (name == -1) {
fprintf(stderr,
"File '%s' contains struct with name that can't be added \"%s\"\n",
@@ -829,7 +817,7 @@ static int convert_include(const char *filename)
break;
}
- name = add_name(version_elem_static_from_alias(strct, md1));
+ const int name = add_name(version_elem_static_from_alias(strct, md1));
if (name == -1) {
fprintf(stderr,
"File '%s' contains struct with name that can't be added \"%s\"\n",
@@ -905,7 +893,6 @@ static bool check_field_alignment(
static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char *base_directory)
{
- int unknown = structs_len, lastunknown;
bool dna_error = false;
/* Write test to verify sizes are accurate. */
@@ -923,8 +910,9 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
fprintf(file_verify, "\n");
/* Multiple iterations to handle nested structs. */
+ int unknown = structs_len;
while (unknown) {
- lastunknown = unknown;
+ const int lastunknown = unknown;
unknown = 0;
/* check all structs... */
@@ -1151,12 +1139,9 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
static void dna_write(FILE *file, const void *pntr, const int size)
{
static int linelength = 0;
- int i;
- const char *data;
+ const char *data = (const char *)pntr;
- data = (const char *)pntr;
-
- for (i = 0; i < size; i++) {
+ for (int i = 0; i < size; i++) {
fprintf(file, "%d, ", data[i]);
linelength++;
if (linelength >= MAX_DNA_LINE_LENGTH) {
@@ -1168,19 +1153,16 @@ static void dna_write(FILE *file, const void *pntr, const int size)
void print_struct_sizes(void)
{
- int a, unknown = structs_len, structtype;
- /*int lastunknown;*/ /*UNUSED*/
- const short *structpoin;
+ int unknown = structs_len;
printf("\n\n*** All detected structs:\n");
while (unknown) {
- /*lastunknown = unknown;*/ /*UNUSED*/
unknown = 0;
/* check all structs... */
- for (a = 0; a < structs_len; a++) {
- structpoin = structs[a];
- structtype = structpoin[0];
+ for (int a = 0; a < structs_len; a++) {
+ const short *structpoin = structs[a];
+ const int structtype = structpoin[0];
printf("\t%s\t:%d\n", types[structtype], types_size_native[structtype]);
}
}
@@ -1193,13 +1175,6 @@ static int make_structDNA(const char *base_directory,
FILE *file_offsets,
FILE *file_verify)
{
- int i;
- const short *sp;
- /* str contains filenames. Since we now include paths, I stretched */
- /* it a bit. Hope this is enough :) -nzc- */
- char str[SDNA_MAX_FILENAME_LENGTH];
- int firststruct;
-
if (debugSDNA > 0) {
fflush(stdout);
printf("Running makesdna at debug level %d\n", debugSDNA);
@@ -1251,21 +1226,27 @@ static int make_structDNA(const char *base_directory,
add_type("void", 0); /* SDNA_TYPE_VOID */
/* the defines above shouldn't be output in the padding file... */
- firststruct = types_len;
+ const i
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list