help the VS heap profiler understand the code.

reorder calloc arguments.
rename ursprung -> origin.
This commit is contained in:
Enno Rehling 2018-10-22 21:51:11 +02:00
parent 835d900f73
commit 35ed981cd5
17 changed files with 59 additions and 70 deletions

View File

@ -66,7 +66,7 @@ void new_potiontype(item_type * itype, int level)
{
potion_type *ptype;
ptype = (potion_type *)calloc(sizeof(potion_type), 1);
ptype = (potion_type *)calloc(1, sizeof(potion_type));
itype->flags |= ITF_POTION;
ptype->itype = itype;
ptype->level = level;
@ -181,7 +181,7 @@ int use_potion(unit * u, const item_type * itype, int amount, struct order *ord)
static void a_initeffect(variant *var)
{
var->v = calloc(sizeof(effect_data), 1);
var->v = calloc(1, sizeof(effect_data));
}
static void

View File

@ -3226,7 +3226,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
assert(w != WMAX);
}
assert(w >= 0);
fig->weapons = (weapon *)calloc(sizeof(weapon), (size_t)(w + 1));
fig->weapons = (weapon *)calloc((size_t)(w + 1), sizeof(weapon));
memcpy(fig->weapons, weapons, (size_t)w * sizeof(weapon));
for (i = 0; i != w; ++i) {
@ -3452,7 +3452,7 @@ battle *make_battle(region * r)
break;
}
if (!bf) {
bf = (bfaction *)calloc(sizeof(bfaction), 1);
bf = (bfaction *)calloc(1, sizeof(bfaction));
++b->nfactions;
bf->faction = u->faction;
bf->next = b->factions;

View File

@ -382,20 +382,8 @@ static int tolua_faction_set_origin(lua_State * L)
static int tolua_faction_get_origin(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
ursprung *origin = self->ursprung;
int x, y;
while (origin != NULL && origin->id != 0) {
origin = origin->next;
}
if (origin) {
x = origin->x;
y = origin->y;
}
else {
x = 0;
y = 0;
}
int x = 0, y = 0;
faction_getorigin(self, 0, &x, &y);
lua_pushinteger(L, x);
lua_pushinteger(L, y);

View File

@ -1361,7 +1361,7 @@ static void update_view(view * vi)
state *state_open(void)
{
state *st = calloc(sizeof(state), 1);
state *st = (state *)calloc(1, sizeof(state));
st->display.pl = get_homeplane();
st->cursor.pl = get_homeplane();
st->cursor.x = 0;

View File

@ -56,10 +56,8 @@ ally * ally_add(ally **al_p, struct faction *f) {
if (f && al->faction == f) return al;
al_p = &al->next;
}
al = (ally *)malloc(sizeof(ally));
al = (ally *)calloc(1, sizeof(ally));
al->faction = f;
al->status = 0;
al->next = 0;
*al_p = al;
return al;
}

View File

@ -135,7 +135,7 @@ building_type *bt_get_or_create(const char *name)
if (name != NULL) {
building_type *btype = bt_find_i(name);
if (btype == NULL) {
btype = calloc(sizeof(building_type), 1);
btype = (building_type *)calloc(1, sizeof(building_type));
btype->_name = str_strdup(name);
btype->flags = BTF_DEFAULT;
btype->auraregen = 1.0;

View File

@ -119,7 +119,7 @@ static void free_faction(faction * f)
i_freeall(&f->items);
freelist(f->ursprung);
freelist(f->origin);
}
#define FMAXHASH 2039
@ -727,10 +727,10 @@ bool faction_alive(const faction *f) {
void faction_getorigin(const faction * f, int id, int *x, int *y)
{
ursprung *ur;
origin *ur;
assert(f && x && y);
for (ur = f->ursprung; ur; ur = ur->next) {
for (ur = f->origin; ur; ur = ur->next) {
if (ur->id == id) {
*x = ur->x;
*y = ur->y;
@ -739,24 +739,27 @@ void faction_getorigin(const faction * f, int id, int *x, int *y)
}
}
void faction_setorigin(faction * f, int id, int x, int y)
{
ursprung *ur;
assert(f != NULL);
for (ur = f->ursprung; ur; ur = ur->next) {
if (ur->id == id) {
ur->x = ur->x + x;
ur->y = ur->y + y;
return;
}
}
ur = calloc(1, sizeof(ursprung));
static origin *new_origin(int id, int x, int y) {
origin *ur = (origin *)calloc(1, sizeof(origin));
ur->id = id;
ur->x = x;
ur->y = y;
return ur;
}
addlist(&f->ursprung, ur);
void faction_setorigin(faction * f, int id, int x, int y)
{
origin **urp;
assert(f != NULL);
for (urp = &f->origin; *urp; urp = &(*urp)->next) {
origin *ur = *urp;
if (ur->id == id) {
ur->x += x;
ur->y += y;
return;
}
}
*urp = new_origin(id, x, y);
}

View File

@ -37,7 +37,7 @@ extern "C" {
struct attrib_type;
struct gamedata;
struct selist;
/* faction flags */
#define FFL_NOAID (1<<0) /* Hilfsflag Kampf */
#define FFL_ISNEW (1<<1)
@ -54,6 +54,12 @@ extern "C" {
#define FFL_NPC (1<<25) /* eine Partei mit Monstern */
#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NPC|FFL_NOIDLEOUT|FFL_CURSED)
typedef struct origin {
struct origin *next;
int id;
int x, y;
} origin;
typedef struct faction {
struct faction *next;
struct faction *nexthash;
@ -72,7 +78,7 @@ extern "C" {
const struct locale *locale;
int lastorders;
int age;
struct ursprung *ursprung;
struct origin *origin;
const struct race *race;
magic_t magiegebiet;
int newbies;

View File

@ -119,7 +119,7 @@ static void test_addfaction(CuTest *tc) {
CuAssertPtrEquals(tc, NULL, (void *)f->next);
CuAssertPtrEquals(tc, NULL, (void *)f->banner);
CuAssertPtrEquals(tc, NULL, (void *)f->spellbook);
CuAssertPtrEquals(tc, NULL, (void *)f->ursprung);
CuAssertPtrEquals(tc, NULL, (void *)f->origin);
CuAssertPtrEquals(tc, (void *)factions, (void *)f);
CuAssertStrEquals(tc, "test@eressea.de", f->email);
CuAssertTrue(tc, checkpasswd(f, "hurrdurr"));
@ -162,11 +162,11 @@ static void test_set_origin(CuTest *tc) {
test_setup();
pl = create_new_plane(0, "", 0, 19, 0, 19, 0);
f = test_create_faction(NULL);
CuAssertPtrEquals(tc, NULL, f->ursprung);
CuAssertPtrEquals(tc, NULL, f->origin);
faction_setorigin(f, 0, 1, 1);
CuAssertIntEquals(tc, 0, f->ursprung->id);
CuAssertIntEquals(tc, 1, f->ursprung->x);
CuAssertIntEquals(tc, 1, f->ursprung->y);
CuAssertIntEquals(tc, 0, f->origin->id);
CuAssertIntEquals(tc, 1, f->origin->x);
CuAssertIntEquals(tc, 1, f->origin->y);
faction_getorigin(f, 0, &x, &y);
CuAssertIntEquals(tc, 1, x);
CuAssertIntEquals(tc, 1, y);
@ -190,7 +190,7 @@ static void test_set_origin_bug(CuTest *tc) {
faction_setorigin(f, 0, -10, 3);
faction_setorigin(f, 0, -13, -4);
adjust_coordinates(f, &x, &y, pl);
CuAssertIntEquals(tc, 0, f->ursprung->id);
CuAssertIntEquals(tc, 0, f->origin->id);
CuAssertIntEquals(tc, -9, x);
CuAssertIntEquals(tc, 2, y);
test_teardown();

View File

@ -122,7 +122,7 @@ int getplaneid(const region * r)
static int
ursprung_x(const faction * f, const plane * pl, const region * rdefault)
{
ursprung *ur;
origin *ur;
int id = 0;
if (!f)
@ -131,7 +131,7 @@ ursprung_x(const faction * f, const plane * pl, const region * rdefault)
if (pl)
id = pl->id;
for (ur = f->ursprung; ur; ur = ur->next) {
for (ur = f->origin; ur; ur = ur->next) {
if (ur->id == id)
return ur->x;
}
@ -145,7 +145,7 @@ ursprung_x(const faction * f, const plane * pl, const region * rdefault)
static int
ursprung_y(const faction * f, const plane * pl, const region * rdefault)
{
ursprung *ur;
origin *ur;
int id = 0;
if (!f)
@ -154,7 +154,7 @@ ursprung_y(const faction * f, const plane * pl, const region * rdefault)
if (pl)
id = pl->id;
for (ur = f->ursprung; ur; ur = ur->next) {
for (ur = f->origin; ur; ur = ur->next) {
if (ur->id == id)
return ur->y;
}

View File

@ -774,7 +774,7 @@ region *new_region(int x, int y, struct plane *pl, int uid)
log_error("duplicate region contains units\n");
return r;
}
r = calloc(1, sizeof(region));
r = (region *)calloc(sizeof(region), 1);
assert_alloc(r);
r->x = x;
r->y = y;

View File

@ -357,14 +357,14 @@ static void read_skills(gamedata *data, unit *u)
size_t sz = u->skill_size * sizeof(skill);
qsort(skills, u->skill_size, sizeof(skill), skill_cmp);
u->skills = malloc(sz);
u->skills = (skill *)malloc(sz);
memcpy(u->skills, skills, sz);
}
}
else {
int i;
READ_INT(data->store, &u->skill_size);
u->skills = malloc(sizeof(skill)*u->skill_size);
u->skills = (skill *)malloc(sizeof(skill)*u->skill_size);
for (i = 0; i != u->skill_size; ++i) {
skill *sv = u->skills + i;
read_skill(data, sv);
@ -420,7 +420,7 @@ unit *read_unit(gamedata *data)
u_setfaction(u, NULL);
}
else {
u = calloc(sizeof(unit), 1);
u = (unit *)calloc(1, sizeof(unit));
assert_alloc(u);
u->no = n;
uhash(u);
@ -1095,7 +1095,7 @@ faction *read_faction(gamedata * data)
void write_faction(gamedata *data, const faction * f)
{
ally *sf;
ursprung *ur;
origin *ur;
assert(f->_alive);
assert(f->no > 0 && f->no <= MAX_UNIT_NR);
@ -1134,8 +1134,8 @@ void write_faction(gamedata *data, const faction * f)
WRITE_SECTION(data->store);
WRITE_TOK(data->store, "end");
WRITE_SECTION(data->store);
WRITE_INT(data->store, listlen(f->ursprung));
for (ur = f->ursprung; ur; ur = ur->next) {
WRITE_INT(data->store, listlen(f->origin));
for (ur = f->origin; ur; ur = ur->next) {
WRITE_INT(data->store, ur->id);
WRITE_INT(data->store, ur->x);
WRITE_INT(data->store, ur->y);

View File

@ -55,12 +55,6 @@ struct terrain_type;
struct unit;
struct weapon_type;
typedef struct ursprung {
struct ursprung *next;
int id;
int x, y;
} ursprung;
/* seen_mode: visibility in the report */
typedef enum {
seen_none,

View File

@ -28,7 +28,7 @@ void
insert_selection(list_selection ** p_sel, list_selection * prev,
const char *str, void *payload)
{
list_selection *sel = calloc(sizeof(list_selection), 1);
list_selection *sel = (list_selection *)calloc(1, sizeof(list_selection));
sel->str = str_strdup(str);
sel->data = payload;
if (*p_sel) {
@ -56,7 +56,7 @@ const char *str, void *payload)
list_selection **push_selection(list_selection ** p_sel, char *str,
void *payload)
{
list_selection *sel = calloc(sizeof(list_selection), 1);
list_selection *sel = (list_selection *)calloc(1, sizeof(list_selection));
list_selection *prev = NULL;
sel->str = str;
sel->data = payload;

View File

@ -133,7 +133,7 @@ newfaction *read_newfactions(const char *filename)
if (nf) {
continue;
}
nf = calloc(sizeof(newfaction), 1);
nf = (newfaction *)calloc(1, sizeof(newfaction));
if (check_email(email) == 0) {
nf->email = str_strdup(email);
} else {

View File

@ -79,7 +79,7 @@ const curse_type ct_firewall = {
static void wall_init(connection * b)
{
wall_data *fd = (wall_data *)calloc(sizeof(wall_data), 1);
wall_data *fd = (wall_data *)calloc(1, sizeof(wall_data));
fd->countdown = -1; /* infinite */
b->data.v = fd;
}

View File

@ -117,7 +117,7 @@ char * transliterate(char * out, size_t size, const char * in)
}
tnode * mknode(void) {
tnode * node = calloc(1, sizeof(tnode));
tnode * node = (tnode *)calloc(1, sizeof(tnode));
node->refcount = 1;
return node;
}