64-bit fixes (the parts of lib/ in use at work are now fully operational in 64-bit mode)

- x86_x64.cpp: fix: test ARCH_AMD64 instead of ARCH_IA32 because both
are defined on x64
- manifest.cpp: fix processor architecture
- wdbg_heap.cpp: only enable on ia32
- winit, wstartup: take (lack of) name mangling into account

compiler.h: add STRINGIZE and DECORATED_NAME for use by winit
dir_watch: fix: smart pointers were never actually released due to a
remaining reference

This was SVN commit r6375.
This commit is contained in:
janwas 2008-09-16 17:46:45 +00:00
parent 1d5c796a79
commit 4132549c2c
15 changed files with 63 additions and 50 deletions

View File

@ -31,8 +31,6 @@ TraceEntry::TraceEntry(EAction action, const char* pathname, size_t size)
}
#define STRINGIZE(number) #number
TraceEntry::TraceEntry(const char* text)
{
const char* fmt = "%f: %c \"" STRINGIZE(PATH_MAX) "[^\"]\" %d\n";

View File

@ -60,7 +60,7 @@
* call before using any other function, and after each video mode change.
* fails if OpenGL not ready for use.
**/
extern void ogl_Init(void);
extern void ogl_Init();
//-----------------------------------------------------------------------------

View File

@ -60,7 +60,7 @@
// using Boost via DLL. (otherwise, we would have to ensure the exact same
// compiler is used, which is a pain because MSC8, MSC9 and ICC 10 are in use)
#ifndef LIB_STATIC_LINK
//# define BOOST_ALL_DYN_LINK
# define BOOST_ALL_DYN_LINK
#endif
#include <boost/utility.hpp> // noncopyable
// the following boost libraries have been included in TR1 and are

View File

@ -23,10 +23,10 @@
#include "lib/sysdep/cpu.h"
#include "lib/sysdep/os_cpu.h"
#if ARCH_IA32
# include "../ia32/ia32_asm.h"
#else
#if ARCH_AMD64
# include "../amd64/amd64_asm.h"
#else
# include "../ia32/ia32_asm.h"
#endif
#if MSC_VERSION
@ -43,10 +43,10 @@
// in assembly for both IA-32 and AMD64.
static void cpuid_impl(x86_x64_CpuidRegs* regs)
{
#if ARCH_IA32
ia32_asm_cpuid(regs);
#else
#if ARCH_AMD64
amd64_asm_cpuid(regs);
#else
ia32_asm_cpuid(regs);
#endif
}

View File

@ -185,4 +185,15 @@
# define CALL_CONV
#endif
#if MSC_VERSION && !ARCH_AMD64
# define DECORATED_NAME(name) _##name
#else
# define DECORATED_NAME(name) name
#endif
// workaround for preprocessor limitation: macro args aren't expanded
// before being pasted.
#define STRINGIZE2(id) # id
#define STRINGIZE(id) STRINGIZE2(id)
#endif // #ifndef INCLUDED_COMPILER

View File

@ -19,8 +19,6 @@ typedef shared_ptr<DirWatch> PDirWatch;
*
* @param path native path of the directory to watch.
* @param dirWatch receives a smart pointer to the watch object.
* note: freeing it does not prevent any previously queued notifications
* from being returned.
*
* note: the FAM backend can only watch single directories, so that is
* all we can guarantee. the Win32 implementation watches entire trees;
@ -28,6 +26,13 @@ typedef shared_ptr<DirWatch> PDirWatch;
**/
LIB_API LibError dir_watch_Add(const fs::wpath& path, PDirWatch& dirWatch);
/**
* stop watching a directory.
*
* note: any previously queued notifications will still be returned.
**/
LIB_API void dir_watch_Remove(PDirWatch& dirWatch);
class DirWatchNotification
{
public:

View File

@ -15,6 +15,6 @@ is currently disabled there.
# if ARCH_IA32
# pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"")
# elif ARCH_AMD64
# pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x64' publicKeyToken='6595b64144ccf1df'\"")
# pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df'\"")
# endif
#endif

View File

@ -61,7 +61,15 @@ void wdbg_heap_Validate()
// (this relies on the debug CRT; not compiling it at all in release builds
// avoids unreferenced local function warnings)
#ifndef NDEBUG
// (this has only been tested on IA32 and seems to have trouble with larger
// pointers, so it's disabled for now.)
#if !defined(NDEBUG) && ARCH_IA32
# define ENABLE_LEAK_INSTRUMENTATION 1
#else
# define ENABLE_LEAK_INSTRUMENTATION 0
#endif
#if ENABLE_LEAK_INSTRUMENTATION
// leak detectors often rely on macro redirection to determine the file and
// line of allocation owners (see _CRTDBG_MAP_ALLOC). unfortunately this
@ -473,7 +481,7 @@ public:
size_t outputBitsLeft = numOutputBits;
while(outputBitsLeft > 0)
{
const size_t numBits = std::min(outputBitsLeft, 8u);
const size_t numBits = std::min(outputBitsLeft, size_t(8));
m_bitsLeft -= numBits;
// (NB: there is no need to extract exactly numBits because
@ -527,7 +535,7 @@ public:
size_t inputBitsLeft = numInputBits;
while(inputBitsLeft > 0)
{
const size_t numBits = std::min(inputBitsLeft, 8u);
const size_t numBits = std::min(inputBitsLeft, size_t(8));
m_bitsLeft -= numBits;
if(m_numRemainderBits < numBits)
@ -901,13 +909,13 @@ intptr_t wdbg_heap_NumberOfAllocations()
//-----------------------------------------------------------------------------
#ifndef NDEBUG
#if ENABLE_LEAK_INSTRUMENTATION
static AllocationTracker* s_tracker;
#endif
static LibError wdbg_heap_Init()
{
#ifndef NDEBUG
#if ENABLE_LEAK_INSTRUMENTATION
FindCodeSegment();
// load symbol information now (fails if it happens during shutdown)
@ -928,7 +936,7 @@ static LibError wdbg_heap_Init()
static LibError wdbg_heap_Shutdown()
{
#ifndef NDEBUG
#if ENABLE_LEAK_INSTRUMENTATION
SAFE_DELETE(s_tracker);
#endif

View File

@ -149,10 +149,6 @@ private:
//-----------------------------------------------------------------------------
// (watches are removed by resetting shared_ptr; the DirWatch dtor must
// notify DirWatchManager and remove itself from the list there)
static void RemoveFromList(DirWatch* dirWatch);
class DirWatch
{
public:
@ -185,8 +181,6 @@ public:
CloseHandle(m_hDir);
m_hDir = INVALID_HANDLE_VALUE;
RemoveFromList(this);
}
void Issue()
@ -333,16 +327,9 @@ public:
return INFO::OK;
}
void Remove(DirWatch* dirWatch)
void Remove(PDirWatch& dirWatch)
{
for(Watches::iterator it = m_watches.begin(); it != m_watches.end(); ++it)
{
if(it->get() == dirWatch)
{
m_watches.erase(it);
break;
}
}
m_watches.remove(dirWatch);
}
LibError Poll(DirWatchNotification& notification)
@ -381,7 +368,7 @@ LibError dir_watch_Add(const fs::wpath& path, PDirWatch& dirWatch)
return s_dirWatchManager->Add(path, dirWatch);
}
static void RemoveFromList(DirWatch* dirWatch)
void dir_watch_Remove(PDirWatch& dirWatch)
{
WinScopedLock lock(WDIR_WATCH_CS);
return s_dirWatchManager->Remove(dirWatch);

View File

@ -52,7 +52,7 @@ static LibError ReadVersionString(const OsPath& modulePathname_, char* out_ver,
WARN_RETURN(ERR::FAIL);
u16* lang; // -> 16 bit language ID, 16 bit codepage
size_t lang_len;
UINT lang_len;
const BOOL ok = VerQueryValue(mem.get(), "\\VarFileInfo\\Translation", (void**)&lang, &lang_len);
if(!ok || !lang || lang_len != 4)
WARN_RETURN(ERR::FAIL);
@ -60,7 +60,7 @@ static LibError ReadVersionString(const OsPath& modulePathname_, char* out_ver,
char subblock[64];
sprintf(subblock, "\\StringFileInfo\\%04X%04X\\FileVersion", lang[0], lang[1]);
const char* in_ver;
size_t in_ver_len;
UINT in_ver_len;
if(!VerQueryValue(mem.get(), subblock, (void**)&in_ver, &in_ver_len))
WARN_RETURN(ERR::FAIL);

View File

@ -117,30 +117,29 @@ Several methods of module init are possible: (see Large Scale C++ Design)
// very early init; must not fail, since error handling code *crashes*
// if called before these have completed.
#define WINIT_REGISTER_CRITICAL_INIT(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$I0")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:_p"#func))
#define WINIT_REGISTER_CRITICAL_INIT(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$I0")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:" STRINGIZE(DECORATED_NAME(p##func))))
// meant for modules with dependents but whose init is complicated and may
// raise error/warning messages (=> can't go in WINIT_REGISTER_CRITICAL_INIT)
#define WINIT_REGISTER_EARLY_INIT(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$I1")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:_p"#func))
#define WINIT_REGISTER_EARLY_INIT(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$I1")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:" STRINGIZE(DECORATED_NAME(p##func))))
// available for dependents of WINIT_REGISTER_EARLY_INIT-modules that
// must still come before WINIT_REGISTER_MAIN_INIT.
#define WINIT_REGISTER_EARLY_INIT2(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$I2")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:_p"#func))
#define WINIT_REGISTER_EARLY_INIT2(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$I2")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:" STRINGIZE(DECORATED_NAME(p##func))))
// most modules will go here unless they are often used or
// have many dependents.
#define WINIT_REGISTER_MAIN_INIT(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$I6")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:_p"#func))
#define WINIT_REGISTER_MAIN_INIT(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$I6")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:" STRINGIZE(DECORATED_NAME(p##func))))
// available for any modules that may need to come after
// WINIT_REGISTER_MAIN_INIT (unlikely)
#define WINIT_REGISTER_LATE_INIT(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$I7")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:_p"#func))
#define WINIT_REGISTER_EARLY_SHUTDOWN(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$S0")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:_p"#func))
#define WINIT_REGISTER_EARLY_SHUTDOWN2(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$S1")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:_p"#func))
#define WINIT_REGISTER_MAIN_SHUTDOWN(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$S6")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:_p"#func))
#define WINIT_REGISTER_LATE_SHUTDOWN(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$S7")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:_p"#func))
#define WINIT_REGISTER_LATE_SHUTDOWN2(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$S8")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:_p"#func))
#define WINIT_REGISTER_LATE_INIT(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$I7")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:" STRINGIZE(DECORATED_NAME(p##func))))
#define WINIT_REGISTER_EARLY_SHUTDOWN(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$S0")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:" STRINGIZE(DECORATED_NAME(p##func))))
#define WINIT_REGISTER_EARLY_SHUTDOWN2(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$S1")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:" STRINGIZE(DECORATED_NAME(p##func))))
#define WINIT_REGISTER_MAIN_SHUTDOWN(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$S6")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:" STRINGIZE(DECORATED_NAME(p##func))))
#define WINIT_REGISTER_LATE_SHUTDOWN(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$S7")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:" STRINGIZE(DECORATED_NAME(p##func))))
#define WINIT_REGISTER_LATE_SHUTDOWN2(func) static LibError func(void); EXTERN_C __declspec(allocate(".WINIT$S8")) LibError (*p##func)(void) = func; __pragma(comment(linker, "/include:" STRINGIZE(DECORATED_NAME(p##func))))
//-----------------------------------------------------------------------------

View File

@ -55,6 +55,7 @@ typedef unsigned long long uint64_t;
typedef long ssize_t;
// prevent wxWidgets from (incompatibly) redefining it
#define HAVE_SSIZE_T
typedef long off_t;
//

View File

@ -8,6 +8,8 @@
#include "precompiled.h"
#if ARCH_IA32
/*
See http://www.opengroup.org/onlinepubs/009695399/functions/fprintf.html
for the specification (apparently an extension to ISO C) that was used
@ -486,3 +488,5 @@ finished_reading:
return ret;
}
#endif

View File

@ -104,4 +104,4 @@ EXTERN_C int wstartup_InitAndRegisterShutdown()
#pragma section(".CRT$XIV", long,SECTION_ATTRIBUTES)
#undef SECTION_ATTRIBUTES
EXTERN_C __declspec(allocate(".CRT$XIV")) int(*wstartup_pInitAndRegisterShutdown)() = wstartup_InitAndRegisterShutdown;
#pragma comment(linker, "/include:_wstartup_pInitAndRegisterShutdown")
#pragma comment(linker, "/include:" STRINGIZE(DECORATED_NAME(wstartup_pInitAndRegisterShutdown)))

View File

@ -301,7 +301,7 @@ static void DetectWindowsVersion()
DWORD size = ARRAY_SIZE(windowsVersionString);
(void)RegQueryValueEx(hKey, "CurrentVersion", 0, 0, (LPBYTE)windowsVersionString, &size);
size_t major = 0, minor = 0;
int major = 0, minor = 0;
int ret = sscanf(windowsVersionString, "%d.%d", &major, &minor);
debug_assert(ret == 2);
debug_assert(major <= 0xFF && minor <= 0xFF);