# housekeeping

fix warnings in self tests
make win_pre_main_init manually callable and remove the main() hook (see
rationale at decl of win_pre_main_init)

This was SVN commit r3981.
This commit is contained in:
janwas 2006-06-08 21:27:03 +00:00
parent 9542ecdd7e
commit d0acaecc5c
7 changed files with 36 additions and 49 deletions

View File

@ -26,11 +26,11 @@
#include "lib.h"
#include <cfloat>
#include <cassert>
#pragma warning(push, 3) // VC7.1 STL not /W4 clean :(
#include <list>
#include <map>
#include <queue>
#pragma warning(pop)
template<typename Key, typename T> class DHT_Traits

View File

@ -17,7 +17,6 @@ class TestArchiveBuilder : public CxxTest::TestSuite
{
// 10 chars is enough for (10-1)*5 bits = 45 bits > u32
char name_tmp[10];
const char* atom_fn;
for(;;)
{
@ -25,7 +24,7 @@ class TestArchiveBuilder : public CxxTest::TestSuite
base32(4, (const u8*)&rand_num, (u8*)name_tmp);
// store filename in atom pool
atom_fn = file_make_unique_fn_copy(name_tmp);
const char* atom_fn = file_make_unique_fn_copy(name_tmp);
// done if the filename is unique (not been generated yet)
if(existing_names.find(atom_fn) == existing_names.end())
{
@ -33,8 +32,6 @@ class TestArchiveBuilder : public CxxTest::TestSuite
return atom_fn;
}
}
return atom_fn;
}
struct TestFile

View File

@ -26,7 +26,7 @@ public:
const ssize_t cdata_produced = comp_feed(c, data, data_size);
TS_ASSERT(cdata_produced > 0);
TS_ASSERT_OK(comp_finish(c, &cdata, &csize));
TS_ASSERT(cdata_produced <= csize); // can't have produced more than total
TS_ASSERT(cdata_produced <= (ssize_t)csize); // can't have produced more than total
}
// decompress
@ -38,7 +38,7 @@ public:
TS_ASSERT(ucdata_produced > 0);
void* ucdata_final; size_t ucsize_final;
TS_ASSERT_OK(comp_finish(c, &ucdata_final, &ucsize_final));
TS_ASSERT(ucdata_produced <= ucsize_final); // can't have produced more than total
TS_ASSERT(ucdata_produced <= (ssize_t)ucsize_final); // can't have produced more than total
TS_ASSERT_EQUALS(ucdata_final, ucdata); // output buffer address is same
TS_ASSERT_EQUALS(ucsize_final, data_size); // correct amount of output
}

View File

@ -256,9 +256,6 @@ static void at_exit(void)
}
#ifndef NO_MAIN_REDIRECT
static
#endif
void win_pre_main_init()
{
// enable memory tracking and leak detection;
@ -279,18 +276,6 @@ void win_pre_main_init()
}
#ifndef NO_MAIN_REDIRECT
#undef main
extern int app_main(int argc, char* argv[]);
int main(int argc, char* argv[])
{
win_pre_main_init();
return app_main(argc, argv);
}
#endif
// perform all initialization that needs to run before _cinit
// (which calls C++ ctors).
// be very careful to avoid non-stateless libc functions!

View File

@ -51,32 +51,28 @@
#define WINAPIV __cdecl
//
// main() hook
//
// rationale for manual init:
// our Windows-specific init code needs to run before the regular main() code.
// ideally this would happen automagically, but there are two problems:
// - the C standard expressly forbids calling main() directly;
// VC apparently makes use of this and changes its calling convention.
// if we call it, everything appears to work but stack traces in
// release mode are incorrect (symbol address is off by 4).
// - other libraries may also want to hook main(); in that case,
// "one must fall". we need to provide for disabling our hook.
// this is not enough reason to forego a hook entirely -
// integration into new projects is easier when there is less
// stuff to remember (here, calling our init function directly).
// ideally this would happen automagically.
// one possibility is using WinMain as the entry point, and then calling the
// application's main(), but this is expressly forbidden by the C standard.
// VC apparently makes use of this and changes its calling convention.
// if we call it, everything appears to work but stack traces in
// release mode are incorrect (symbol address is off by 4).
//
// what we'll do is: redefine the app's main function to app_main, have the
// OS call our main, and call app_main from there. in case another library
// (e.g. SDL) has the same idea, #define NO_MAIN_REDIRECT prevents the
// above; you then need to call win_pre_main_init at the beginning of main().
//#define NO_MAIN_REDIRECT
#ifdef NO_MAIN_REDIRECT
// another alternative is re#defining the app's main function to app_main,
// having the OS call our main, and then dispatching to app_main.
// however, this leads to trouble when another library (e.g. SDL) wants to
// do the same.
//
// moreover, this file is compiled into a static library and used both for
// the 0ad executable as well as the separate self-test. this means
// we can't enable the main() hook for one and disable in the other.
//
// the consequence is that automatic init isn't viable. users MUST call this
// at the beginning of main (or at least before using any lib function).
// this is unfortunate because integration into new projects requires
// remembering to call the init function, but it can't be helped.
extern void win_pre_main_init();
#else
#define main app_main
#endif
#endif // #ifndef WIN_H__

View File

@ -29,7 +29,7 @@ public:
{
int was_inserted;
user_data = lfl_insert(&list, (void *)(key+i), sizeof(int), &was_inserted);
user_data = lfl_insert(&list, key+i, sizeof(int), &was_inserted);
TS_ASSERT(user_data != 0 && was_inserted);
*(uint*)user_data = sig+i;
@ -41,7 +41,7 @@ public:
// make sure all "signatures" are present in list
for(uint i = 0; i < ENTRIES; i++)
{
user_data = lfl_find(&list, (void *)(key+i));
user_data = lfl_find(&list, key+i);
TS_ASSERT(user_data != 0);
TS_ASSERT_EQUALS(*(uint*)user_data, sig+i);

View File

@ -37,6 +37,10 @@ that of Atlas depending on commandline parameters.
#include "sound/CMusicPlayer.h"
#include "gui/GUI.h"
#if OS_WIN
# include "lib/sysdep/win/win.h"
#endif
#define LOG_CATEGORY "main"
extern bool g_TerrainModified;
@ -353,6 +357,11 @@ void kill_mainloop()
int main(int argc, char* argv[])
{
// see discussion at declaration of win_pre_main_init.
#if OS_WIN
win_pre_main_init();
#endif
debug_printf("MAIN &argc=%p &argv=%p\n", &argc, &argv);
ATLAS_RunIfOnCmdLine(argc, argv);