From ad4d7dca53b359de966e79a7e8b8423a061f48b1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Oct 2018 11:50:52 +0200 Subject: [PATCH 01/13] use latest clibs, like develop --- clibs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clibs b/clibs index d86c85254..12139c7ce 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit d86c8525489d7f11b7ba13e101bb59ecf160b871 +Subproject commit 12139c7ce25e6731393f863e248ab16aa0578a3a From 01edb1e204d3f24acd12503da2fed58f7fa26d82 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 20 Oct 2018 19:56:38 +0200 Subject: [PATCH 02/13] move that errno-preserving atoi to strings.c --- src/kernel/build.c | 4 ++-- src/util/base36.c | 8 -------- src/util/strings.c | 11 ++++++++++- src/util/strings.h | 1 + src/util/strings.test.c | 22 ++++++++++++++++++++++ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/kernel/build.c b/src/kernel/build.c index 71d5543fd..4ad7815c8 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -54,13 +54,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* from libutil */ -#include #include #include #include #include #include #include +#include /* from libc */ #include @@ -180,7 +180,7 @@ int destroy_cmd(unit * u, struct order *ord) s = gettoken(token, sizeof(token)); if (s && *s) { - n = atoi10((const char *)s); + n = str_atoi(s); if (n <= 0) { n = INT_MAX; diff --git a/src/util/base36.c b/src/util/base36.c index e68fd76f6..3b5543e88 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -23,14 +23,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include - -int atoi10(const char *str) -{ - int i = atoi(str); - errno = 0; - return i; -} int atoi36(const char *str) { diff --git a/src/util/strings.c b/src/util/strings.c index ef351ab1f..e85d8ca56 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -22,10 +22,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "strings.h" /* libc includes */ +#include #include +#include #include #include -#include #include #ifdef HAVE_LIBBSD @@ -34,6 +35,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif +int str_atoi(const char *str) +{ + int e = errno; + int i = atoi(str); + errno = e; + return i; +} + size_t str_strlcpy(char *dst, const char *src, size_t len) { #ifdef HAVE_BSDSTRING diff --git a/src/util/strings.h b/src/util/strings.h index bd6f0de58..6524f5970 100644 --- a/src/util/strings.h +++ b/src/util/strings.h @@ -27,6 +27,7 @@ extern "C" { void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, const char *value); int str_hash(const char *s); + int str_atoi(const char *s); size_t str_slprintf(char * dst, size_t size, const char * format, ...); size_t str_strlcpy(char *dst, const char *src, size_t len); size_t str_strlcat(char *dst, const char *src, size_t len); diff --git a/src/util/strings.test.c b/src/util/strings.test.c index 2205e538b..211ec65cc 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -71,6 +71,27 @@ static void test_str_hash(CuTest * tc) CuAssertIntEquals(tc, 140703196, str_hash("Hodor")); } +static void test_str_atoi(CuTest * tc) +{ + errno = 0; + CuAssertIntEquals(tc, 0, str_atoi("0")); + CuAssertIntEquals(tc, 4, str_atoi("4")); + CuAssertIntEquals(tc, 42, str_atoi("42")); + CuAssertIntEquals(tc, -4, str_atoi("-4")); + CuAssertIntEquals(tc, 0, errno); + CuAssertIntEquals(tc, 4, str_atoi("4a")); + CuAssertIntEquals(tc, 8, str_atoi("08")); + CuAssertIntEquals(tc, 0, str_atoi("0x8")); + CuAssertIntEquals(tc, 0, str_atoi("a")); + CuAssertIntEquals(tc, 0, errno); + errno = ERANGE; + CuAssertIntEquals(tc, 0, str_atoi("a")); + CuAssertIntEquals(tc, ERANGE, errno); + errno = EINVAL; + CuAssertIntEquals(tc, 0, str_atoi("a")); + CuAssertIntEquals(tc, EINVAL, errno); +} + static void test_str_slprintf(CuTest * tc) { char buffer[32]; @@ -157,6 +178,7 @@ static void test_sbstring(CuTest * tc) CuSuite *get_strings_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_str_atoi); SUITE_ADD_TEST(suite, test_str_hash); SUITE_ADD_TEST(suite, test_str_escape); SUITE_ADD_TEST(suite, test_str_escape_ex); From 57be0f2e6a2fa86318aa964f5927d3602c2205e5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 20 Oct 2018 20:10:11 +0200 Subject: [PATCH 03/13] Ich habe mich geirrt, was das Verhalten von atoi in Windows angeht. Alles zurueck. --- src/kernel/build.c | 5 +++-- src/util/strings.c | 9 --------- src/util/strings.h | 2 +- src/util/strings.test.c | 22 ---------------------- 4 files changed, 4 insertions(+), 34 deletions(-) diff --git a/src/kernel/build.c b/src/kernel/build.c index 4ad7815c8..f5e1eec91 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -180,8 +180,9 @@ int destroy_cmd(unit * u, struct order *ord) s = gettoken(token, sizeof(token)); if (s && *s) { - n = str_atoi(s); - + ERRNO_CHECK(); + n = atoi(s); + errno = 0; if (n <= 0) { n = INT_MAX; } diff --git a/src/util/strings.c b/src/util/strings.c index e85d8ca56..e9434fb25 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -24,7 +24,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include #include -#include #include #include #include @@ -35,14 +34,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif -int str_atoi(const char *str) -{ - int e = errno; - int i = atoi(str); - errno = e; - return i; -} - size_t str_strlcpy(char *dst, const char *src, size_t len) { #ifdef HAVE_BSDSTRING diff --git a/src/util/strings.h b/src/util/strings.h index 6524f5970..bd58c0eb2 100644 --- a/src/util/strings.h +++ b/src/util/strings.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define STRINGS_H #include +#include #ifdef __cplusplus extern "C" { @@ -27,7 +28,6 @@ extern "C" { void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, const char *value); int str_hash(const char *s); - int str_atoi(const char *s); size_t str_slprintf(char * dst, size_t size, const char * format, ...); size_t str_strlcpy(char *dst, const char *src, size_t len); size_t str_strlcat(char *dst, const char *src, size_t len); diff --git a/src/util/strings.test.c b/src/util/strings.test.c index 211ec65cc..2205e538b 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -71,27 +71,6 @@ static void test_str_hash(CuTest * tc) CuAssertIntEquals(tc, 140703196, str_hash("Hodor")); } -static void test_str_atoi(CuTest * tc) -{ - errno = 0; - CuAssertIntEquals(tc, 0, str_atoi("0")); - CuAssertIntEquals(tc, 4, str_atoi("4")); - CuAssertIntEquals(tc, 42, str_atoi("42")); - CuAssertIntEquals(tc, -4, str_atoi("-4")); - CuAssertIntEquals(tc, 0, errno); - CuAssertIntEquals(tc, 4, str_atoi("4a")); - CuAssertIntEquals(tc, 8, str_atoi("08")); - CuAssertIntEquals(tc, 0, str_atoi("0x8")); - CuAssertIntEquals(tc, 0, str_atoi("a")); - CuAssertIntEquals(tc, 0, errno); - errno = ERANGE; - CuAssertIntEquals(tc, 0, str_atoi("a")); - CuAssertIntEquals(tc, ERANGE, errno); - errno = EINVAL; - CuAssertIntEquals(tc, 0, str_atoi("a")); - CuAssertIntEquals(tc, EINVAL, errno); -} - static void test_str_slprintf(CuTest * tc) { char buffer[32]; @@ -178,7 +157,6 @@ static void test_sbstring(CuTest * tc) CuSuite *get_strings_suite(void) { CuSuite *suite = CuSuiteNew(); - SUITE_ADD_TEST(suite, test_str_atoi); SUITE_ADD_TEST(suite, test_str_hash); SUITE_ADD_TEST(suite, test_str_escape); SUITE_ADD_TEST(suite, test_str_escape_ex); From b8c49914e986cac6d4efe401c2cff598d308cff9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 20 Oct 2018 20:28:05 +0200 Subject: [PATCH 04/13] missing include --- src/CMakeLists.txt | 2 +- src/kernel/build.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e8db8bf9..50f625053 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,7 +25,7 @@ IF (CMAKE_COMPILER_IS_GNUCC) ENDIF() IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -no-pie -g -pg -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89") ELSEIF(MSVC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /MP /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES") diff --git a/src/kernel/build.c b/src/kernel/build.c index f5e1eec91..2b7251f1d 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -64,6 +64,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* from libc */ #include +#include #include #include #include From 9ecf87188f58f36aaa57ef89d4fc1b451f23e35e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 20 Oct 2018 20:31:21 +0200 Subject: [PATCH 05/13] remove gprof options --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50f625053..4e8db8bf9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,7 +25,7 @@ IF (CMAKE_COMPILER_IS_GNUCC) ENDIF() IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -no-pie -g -pg -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89") ELSEIF(MSVC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /MP /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES") From 4056f08afa3849b7e9d892a49801c6ff8917c0aa Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Oct 2018 14:45:05 +0200 Subject: [PATCH 06/13] Switching to VS2017 compiler has found a bug in pofile.c --- src/util/pofile.c | 4 ++-- tests/runtests.bat | 3 ++- vs2015-build.bat | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/util/pofile.c b/src/util/pofile.c index 8de04364d..e1126ba0e 100644 --- a/src/util/pofile.c +++ b/src/util/pofile.c @@ -77,7 +77,7 @@ int pofile_read(const char *filename, int (*callback)(const char *msgid, const c int err = sscanf(line, "%8s", token); if (err == 1) { char *text = NULL; - size_t size, len = strlen(token); + size_t size = 0, len = strlen(token); line = line + len + 1; if (len == 7 && memcmp(token, "msgctxt", 7) == 0) { @@ -99,7 +99,7 @@ int pofile_read(const char *filename, int (*callback)(const char *msgid, const c msgid[0] = 0; } } - if (text) { + if (size > 0) { line = read_multiline(F, line, text, size); } } diff --git a/tests/runtests.bat b/tests/runtests.bat index 95ac17be4..88afc8d31 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -3,7 +3,8 @@ IF EXIST ..\build-vs10 SET BUILD=..\build-vs10\eressea\Debug IF EXIST ..\build-vs11 SET BUILD=..\build-vs11\eressea\Debug IF EXIST ..\build-vs12 SET BUILD=..\build-vs12\eressea\Debug IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\eressea\Debug -REM IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\eressea\Debug +IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\eressea\Debug + SET SERVER=%BUILD%\eressea.exe %BUILD%\test_eressea.exe %SERVER% ..\scripts\run-tests.lua diff --git a/vs2015-build.bat b/vs2015-build.bat index 1ad2c8da2..8d5c276ed 100644 --- a/vs2015-build.bat +++ b/vs2015-build.bat @@ -1,5 +1,7 @@ @ECHO OFF -SET VSVERSION=14 +SET VSVERSION=15 +IF NOT "%1" == "" SET VSVERSION=%1% + SET SRCDIR=%CD% CD .. SET ERESSEA=%CD% From 0f3f7a68b977735f0e1662d02786db879a91e446 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Oct 2018 19:10:20 +0200 Subject: [PATCH 07/13] upgrade clibs --- clibs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clibs b/clibs index 12139c7ce..1e1c947c8 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 12139c7ce25e6731393f863e248ab16aa0578a3a +Subproject commit 1e1c947c8034f071c6848dcf1c11138733949825 From 38c1dfe26f10e898f55feb545176d61d46d82cf8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Oct 2018 19:22:30 +0200 Subject: [PATCH 08/13] BUG 2503: statistics API, logging monster creation --- src/main.c | 2 ++ src/monsters.c | 4 +++ src/test_eressea.c | 2 ++ src/tests.c | 2 ++ src/util/log.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ src/util/log.h | 6 ++++ src/util/log.test.c | 42 ++++++++++++++++++++++++- 7 files changed, 133 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index bb353fc2f..e9d058b28 100644 --- a/src/main.c +++ b/src/main.c @@ -334,6 +334,8 @@ int main(int argc, char **argv) game_done(); lua_done(L); log_close(); + stats_write(stdout, ""); + stats_close(); if (d) { iniparser_freedict(d); } diff --git a/src/monsters.c b/src/monsters.c index d009f8bda..ab465e133 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -606,6 +606,7 @@ static void recruit_dracoids(unit * dragon, int size) region *r = dragon->region; const struct item *weapon = NULL; unit *un = create_unit(r, f, size, get_race(RC_DRACOID), 0, NULL, NULL); + stats_count("monsters.create.dracoid", 1); fset(un, UFL_ISNEW | UFL_MOVED); @@ -863,6 +864,7 @@ static int nrand(int handle_start, int sub) unit *spawn_seaserpent(region *r, faction *f) { unit *u = create_unit(r, f, 1, get_race(RC_SEASERPENT), 0, NULL, NULL); + stats_count("monsters.create.seaserpent", 1); fset(u, UFL_ISNEW | UFL_MOVED); equip_unit(u, "seed_seaserpent"); return u; @@ -903,6 +905,7 @@ void spawn_dragons(void) else { u = create_unit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON), 0, NULL, NULL); } + stats_count("monsters.create.dragon", 1); fset(u, UFL_ISNEW | UFL_MOVED); equip_unit(u, "seed_dragon"); @@ -963,6 +966,7 @@ void spawn_undead(void) } u = create_unit(r, monsters, undead, rc, 0, NULL, NULL); + stats_count("monsters.create.undead", 1); fset(u, UFL_ISNEW | UFL_MOVED); if ((rc == get_race(RC_SKELETON) || rc == get_race(RC_ZOMBIE)) && rng_int() % 10 < 4) { diff --git a/src/test_eressea.c b/src/test_eressea.c index 5684a8ad4..13a638e3b 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -173,6 +173,8 @@ int RunAllTests(int argc, char *argv[]) fail_count = summary->failCount; CuSuiteDelete(summary); game_done(); + log_close(); + stats_close(); return fail_count; } return 0; diff --git a/src/tests.c b/src/tests.c index 4ee38d195..f8035e129 100644 --- a/src/tests.c +++ b/src/tests.c @@ -229,6 +229,8 @@ static void test_reset(void) { default_locale = 0; calendar_cleanup(); close_orders(); + log_close(); + stats_close(); free_special_directions(); free_locales(); free_spells(); diff --git a/src/util/log.c b/src/util/log.c index 4b29332a8..0a24503e1 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -15,6 +15,8 @@ without prior permission by the authors of Eressea. #include "unicode.h" #include "strings.h" +#include + #include #include #include @@ -317,3 +319,77 @@ int log_level(log_t * log, int flags) log->flags = flags; return old; } + +static critbit_tree stats = CRITBIT_TREE(); + +int stats_count(const char *stat, int delta) { + size_t len; + char data[128]; + void * match; + if (cb_find_prefix_str(&stats, stat, &match, 1, 0) == 0) { + len = cb_new_kv(stat, strlen(stat), &delta, sizeof(delta), data); + cb_insert(&stats, data, len); + return delta; + } + else { + int *num; + cb_get_kv_ex(match, (void **)&num); + return *num += delta; + } +} + +#if 0 +#define STATS_BATCH 8 +void stats_walk(const char *prefix, void(*callback)(const char *, int, void *), void *udata) { + void *match[STATS_BATCH]; + int n, off = 0; + do { + int i; + n = cb_find_prefix_str(&stats, prefix, match, STATS_BATCH, off); + if (n == 0) { + break; + } + off += n; + for (i = 0; i != n; ++i) { + const void *kv = match[i]; + int *num; + cb_get_kv_ex(kv, &(void *)num); + callback(kv, *num, udata); + } + } while (n == STATS_BATCH); +} +#else + +struct walk_data { + int (*callback)(const char *, int, void *); + void *udata; +}; + +static int walk_cb(void * match, const void * key, size_t keylen, void *udata) { + struct walk_data *data = (struct walk_data *)udata; + int *num; + cb_get_kv_ex(match, (void **)&num); + return data->callback((const char*)match, *num, data->udata); +} + +int stats_walk(const char *prefix, int (*callback)(const char *, int, void *), void *udata) { + struct walk_data data; + data.callback = callback; + data.udata = udata; + return cb_foreach(&stats, prefix, strlen(prefix), walk_cb, &data); +} +#endif + +static int write_cb(const char *key, int val, void *udata) { + FILE * F = (FILE *)udata; + fprintf(F, "%s: %d\n", (const char *)key, val); + return 0; +} + +void stats_write(FILE *F, const char *prefix) { + stats_walk(prefix, write_cb, F); +} + +void stats_close(void) { + cb_clear(&stats); +} diff --git a/src/util/log.h b/src/util/log.h index 15872d6dc..98a0d3af6 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -36,6 +36,12 @@ extern "C" { void log_printf(FILE * ios, const char *format, ...); void errno_check(const char *file, int line); + + int stats_count(const char *stat, int delta); + void stats_write(FILE *F, const char *prefix); + int stats_walk(const char *prefix, int (*callback)(const char *key, int val, void * udata), void *udata); + void stats_close(void); + #define ERRNO_CHECK() errno_check(__FILE__, __LINE__) diff --git a/src/util/log.test.c b/src/util/log.test.c index 86f13ea9c..928ba5660 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -1,11 +1,13 @@ #ifdef _MSC_VER #include #endif -#include #include "log.h" #include "macros.h" +#include +#include + #include #include @@ -32,9 +34,47 @@ static void test_logging(CuTest * tc) CuAssertStrEquals(tc, "World", str2); } +static int stats_cb(const char *stat, int num, void *udata) { + int *counter = (int *)udata; + if (counter) { + *counter += num; + } + return 0; +} + +static void test_stats(CuTest * tc) +{ + int n = 0; + test_setup(); + CuAssertIntEquals(tc, 1, stats_count("foobar", 1)); + CuAssertIntEquals(tc, 2, stats_count("test.one", 2)); + CuAssertIntEquals(tc, 1, stats_count("test.two", 1)); + CuAssertIntEquals(tc, 4, stats_count("test.one", 2)); + CuAssertIntEquals(tc, 1, stats_count("test.two", 0)); + + n = 0; + CuAssertIntEquals(tc, 0, stats_walk("", stats_cb, &n)); + CuAssertIntEquals(tc, 6, n); + + n = 0; + CuAssertIntEquals(tc, 0, stats_walk("test", stats_cb, &n)); + CuAssertIntEquals(tc, 5, n); + + n = 0; + CuAssertIntEquals(tc, 0, stats_walk("test.one", stats_cb, &n)); + CuAssertIntEquals(tc, 4, n); + + n = 0; + CuAssertIntEquals(tc, 0, stats_walk("foobar", stats_cb, &n)); + CuAssertIntEquals(tc, 1, n); + + test_teardown(); +} + CuSuite *get_log_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_logging); + SUITE_ADD_TEST(suite, test_stats); return suite; } From 820de2ee35504452cb02d960a2e7f89b2aec94e0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Oct 2018 19:30:19 +0200 Subject: [PATCH 09/13] fix cont arguments for new clibs version --- clibs | 2 +- src/kernel/item.c | 6 +++--- src/magic.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clibs b/clibs index 1e1c947c8..ed5c4fee3 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 1e1c947c8034f071c6848dcf1c11138733949825 +Subproject commit ed5c4fee3afbc3d8be79d64857f30702aed522f8 diff --git a/src/kernel/item.c b/src/kernel/item.c index 4e707a48c..00f54a656 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -723,7 +723,7 @@ int change_money(unit * u, int v) return 0; } -static int add_resourcename_cb(const void * match, const void * key, +static int add_resourcename_cb(void * match, const void * key, size_t keylen, void *data) { struct locale * lang = (struct locale *)data; @@ -773,7 +773,7 @@ attrib_type at_showitem = { "showitem" }; -static int add_itemname_cb(const void * match, const void * key, +static int add_itemname_cb(void * match, const void * key, size_t keylen, void *data) { struct locale * lang = (struct locale *)data; @@ -919,7 +919,7 @@ void free_rtype(resource_type *rtype) { free(rtype); } -static int free_rtype_cb(const void * match, const void * key, +static int free_rtype_cb(void * match, const void * key, size_t keylen, void *cbdata) { resource_type *rtype = ((rt_entry *)match)->value;; diff --git a/src/magic.c b/src/magic.c index 7464e286d..415746db0 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2949,7 +2949,7 @@ void free_spellbook(spellbook *sb) { free(sb); } -static int free_spellbook_cb(const void *match, const void *key, size_t keylen, void *data) { +static int free_spellbook_cb(void *match, const void *key, size_t keylen, void *data) { const sb_entry *ent = (const sb_entry *)match; UNUSED_ARG(data); UNUSED_ARG(keylen); From 297312ddb349a413d5936e1372e89a41e49b4e37 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Oct 2018 19:56:46 +0200 Subject: [PATCH 10/13] Hirntoeter auch zaehlen. --- src/teleport.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/teleport.c b/src/teleport.c index 36634c5cd..2d8fafe72 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -182,6 +182,7 @@ void spawn_braineaters(float chance) u = create_unit(r, f, 1 + rng_int() % 10 + rng_int() % 10, rc_brain, 0, NULL, NULL); equip_unit(u, "seed_braineater"); + stats_count("monsters.create.braineater", 1); next = rng_int() % (int)(chance * 100); } From 1305edb744401db1dad658be1c9072eb9f1fecef Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 22 Oct 2018 19:59:18 +0200 Subject: [PATCH 11/13] BUG 2503: fix undead spawn rate --- src/monsters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monsters.c b/src/monsters.c index ab465e133..89a678f11 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -938,7 +938,7 @@ void spawn_undead(void) } if (r->land && unburied > rpeasants(r) / 20 - && rng_int() % 10000 < 200) { + && rng_int() % 10000 < 100) { message *msg; unit *u; /* es ist sinnfrei, wenn irgendwo im Wald 3er-Einheiten Untote entstehen. From 35ed981cd578b81397be0159096bbd85a9df55dd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 22 Oct 2018 21:51:11 +0200 Subject: [PATCH 12/13] help the VS heap profiler understand the code. reorder calloc arguments. rename ursprung -> origin. --- src/alchemy.c | 4 ++-- src/battle.c | 4 ++-- src/bind_faction.c | 16 ++-------------- src/gmtool.c | 2 +- src/kernel/ally.c | 4 +--- src/kernel/building.c | 2 +- src/kernel/faction.c | 37 ++++++++++++++++++++----------------- src/kernel/faction.h | 10 ++++++++-- src/kernel/faction.test.c | 12 ++++++------ src/kernel/plane.c | 8 ++++---- src/kernel/region.c | 2 +- src/kernel/save.c | 12 ++++++------ src/kernel/types.h | 6 ------ src/listbox.c | 4 ++-- src/modules/autoseed.c | 2 +- src/spells/borders.c | 2 +- src/util/umlaut.c | 2 +- 17 files changed, 59 insertions(+), 70 deletions(-) diff --git a/src/alchemy.c b/src/alchemy.c index d2dd64a04..c84374e28 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -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 diff --git a/src/battle.c b/src/battle.c index 6ab969c93..8b71f17e1 100644 --- a/src/battle.c +++ b/src/battle.c @@ -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; diff --git a/src/bind_faction.c b/src/bind_faction.c index 632fcec3d..bb0920395 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -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); diff --git a/src/gmtool.c b/src/gmtool.c index cd0580fcc..36c05a244 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -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; diff --git a/src/kernel/ally.c b/src/kernel/ally.c index 1fd7c0efd..0660f148a 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -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; } diff --git a/src/kernel/building.c b/src/kernel/building.c index f5698eaa9..3a3d7e4e5 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -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; diff --git a/src/kernel/faction.c b/src/kernel/faction.c index a78cd943a..21ea35833 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -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); } diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 63c5a9993..0fe38cb1d 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -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; diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index d2931c669..6c2ed3aa6 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -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(); diff --git a/src/kernel/plane.c b/src/kernel/plane.c index 71c0dbd86..89de42618 100644 --- a/src/kernel/plane.c +++ b/src/kernel/plane.c @@ -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; } diff --git a/src/kernel/region.c b/src/kernel/region.c index 377bf1e22..fee51d13c 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -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; diff --git a/src/kernel/save.c b/src/kernel/save.c index cdc951fad..a61e4348f 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -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); diff --git a/src/kernel/types.h b/src/kernel/types.h index d4f46ae8d..34c50e0a1 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -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, diff --git a/src/listbox.c b/src/listbox.c index 4aa00adaf..542ab13e8 100644 --- a/src/listbox.c +++ b/src/listbox.c @@ -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; diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 65585441c..bb31d3f4e 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -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 { diff --git a/src/spells/borders.c b/src/spells/borders.c index 5d99b1307..c0e51a9b1 100644 --- a/src/spells/borders.c +++ b/src/spells/borders.c @@ -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; } diff --git a/src/util/umlaut.c b/src/util/umlaut.c index 1f9e32b1f..00252fb02 100644 --- a/src/util/umlaut.c +++ b/src/util/umlaut.c @@ -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; } From 6a615ab0cde704e1c7e9a5bd1af61ba7430b6a48 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 23 Oct 2018 17:43:11 +0200 Subject: [PATCH 13/13] disable ASM implementation of bcrypt --- src/util/crypto/crypt_blowfish/crypt_blowfish.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/util/crypto/crypt_blowfish/crypt_blowfish.c b/src/util/crypto/crypt_blowfish/crypt_blowfish.c index b0b11d3ad..701ddddf0 100644 --- a/src/util/crypto/crypt_blowfish/crypt_blowfish.c +++ b/src/util/crypto/crypt_blowfish/crypt_blowfish.c @@ -53,10 +53,7 @@ /* Just to make sure the prototypes match the actual definitions */ #include "crypt_blowfish.h" -#ifdef __i386__ -#define BF_ASM 1 -#define BF_SCALE 1 -#elif defined(__x86_64__) || defined(__alpha__) || defined(__hppa__) +#if defined(__x86_64__) || defined(__alpha__) || defined(__hppa__) #define BF_ASM 0 #define BF_SCALE 1 #else