More mingw fixes
authorPatrick von Reth <patrick.vonreth@gmail.com>
Mon, 1 Feb 2010 00:01:17 +0000 (01:01 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 16 Feb 2010 10:51:24 +0000 (11:51 +0100)
mingw and unicode definition fix cleaned up logbacktrace_win.cpp gcc asm currenly missing

CMakeLists.txt
src/common/identity.cpp
src/common/logbacktrace_win.cpp
src/common/syncableobject.h

index 64409ef..7fdc6fd 100644 (file)
@@ -218,6 +218,12 @@ else(WITH_KDE)
   message(STATUS "Not enabling KDE4 integration")
 endif(WITH_KDE)
 
   message(STATUS "Not enabling KDE4 integration")
 endif(WITH_KDE)
 
+# needed to compile with mingw without kde
+if(MINGW AND NOT HAVE_KDE)
+    add_definitions(-D_WIN32_WINNT=0x0500)
+     message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
+endif(MINGW AND NOT HAVE_KDE)
+
 # Setup Phonon support - we only need this if we don't have or want KDE4
 if(NOT HAVE_KDE)
   if(WITH_PHONON)
 # Setup Phonon support - we only need this if we don't have or want KDE4
 if(NOT HAVE_KDE)
   if(WITH_PHONON)
index 275afcc..6cb3780 100644 (file)
@@ -76,6 +76,18 @@ Identity::Identity(const Identity &other, QObject *parent)
   init();
 }
 
   init();
 }
 
+#ifdef Q_WS_WIN
+#ifdef UNICODE
+QString tcharToQString(TCHAR *tchar){
+  return QString::fromUtf16( reinterpret_cast<ushort*>(tchar));
+}
+#else
+QString tcharToQString(TCHAR *tchar){
+  return QString::fromLocal8Bit(tchar);
+}
+#endif
+
+#endif
 void Identity::init() {
   setObjectName(QString::number(id().toInt()));
   setAllowClientUpdates(true);
 void Identity::init() {
   setObjectName(QString::number(id().toInt()));
   setAllowClientUpdates(true);
@@ -102,7 +114,7 @@ QString Identity::defaultNick() {
   DWORD  bufCharCount = 128;
   //if(GetUserNameEx(/* NameSamCompatible */ 1, infoBuf, &bufCharCount))
   if(GetUserNameEx(NameSamCompatible, infoBuf, &bufCharCount)) {
   DWORD  bufCharCount = 128;
   //if(GetUserNameEx(/* NameSamCompatible */ 1, infoBuf, &bufCharCount))
   if(GetUserNameEx(NameSamCompatible, infoBuf, &bufCharCount)) {
-    QString nickName(infoBuf);
+    QString nickName(tcharToQString(infoBuf));
     int lastBs = nickName.lastIndexOf('\\');
     if(lastBs != -1) {
       nickName = nickName.mid(lastBs + 1);
     int lastBs = nickName.lastIndexOf('\\');
     if(lastBs != -1) {
       nickName = nickName.mid(lastBs + 1);
@@ -138,7 +150,7 @@ QString Identity::defaultRealName() {
   TCHAR  infoBuf[128];
   DWORD  bufCharCount = 128;
   if(GetUserName(infoBuf, &bufCharCount))
   TCHAR  infoBuf[128];
   DWORD  bufCharCount = 128;
   if(GetUserName(infoBuf, &bufCharCount))
-    return QString(infoBuf);
+    return tcharToQString(infoBuf);
   else
     return generalDefault;
 #else
   else
     return generalDefault;
 #else
index 31d1f95..ed11ea4 100644 (file)
@@ -49,7 +49,7 @@ struct EnumModulesContext {
   EnumModulesContext(HANDLE hProcess, QTextStream &stream) : hProcess(hProcess), stream(stream) {}
 };
 
   EnumModulesContext(HANDLE hProcess, QTextStream &stream) : hProcess(hProcess), stream(stream) {}
 };
 
-BOOL CALLBACK EnumModulesCB(PCTSTR ModuleName, DWORD64 BaseOfDll, PVOID UserContext) {
+BOOL CALLBACK EnumModulesCB(LPCSTR ModuleName, DWORD64 BaseOfDll, PVOID UserContext) {
   IMAGEHLP_MODULE64 mod;
   EnumModulesContext *context = (EnumModulesContext *)UserContext;
   mod.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
   IMAGEHLP_MODULE64 mod;
   EnumModulesContext *context = (EnumModulesContext *)UserContext;
   mod.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
@@ -70,14 +70,12 @@ BOOL CALLBACK EnumModulesCB(PCTSTR ModuleName, DWORD64 BaseOfDll, PVOID UserCont
   return TRUE;
 }
 
   return TRUE;
 }
 
-// we don't use the ModuleName anyways so we can easily "convert" this
-inline BOOL CALLBACK EnumModulesCB(PSTR ModuleName, DWORD64 BaseOfDll, PVOID UserContext) {
-  return EnumModulesCB(PCTSTR(0), BaseOfDll, UserContext);
-}
 
 
-#ifdef _M_IX86
+
+#if defined( _M_IX86 ) && defined(Q_CC_MSVC)
   // Disable global optimization and ignore /GS waning caused by
   // inline assembly.
   // Disable global optimization and ignore /GS waning caused by
   // inline assembly.
+  // not needed with mingw cause we can tell mingw which registers we use
   #pragma optimize("g", off)
   #pragma warning(push)
   #pragma warning(disable : 4748)
   #pragma optimize("g", off)
   #pragma warning(push)
   #pragma warning(disable : 4748)
@@ -90,13 +88,26 @@ void Quassel::logBacktrace(const QString &filename) {
 #ifdef _M_IX86
     ZeroMemory(&Context, sizeof(CONTEXT));
     Context.ContextFlags = CONTEXT_CONTROL;
 #ifdef _M_IX86
     ZeroMemory(&Context, sizeof(CONTEXT));
     Context.ContextFlags = CONTEXT_CONTROL;
-    __asm {
+
+// TODO: port asssembler to mingw32
+#ifdef __MINGW32__
+//      asm("Label:\n\t"
+//        "movl %%ebp,%0;\n\t"
+//        "movl %%esp,%1;\n\t"
+//        "movl $Label,%%eax;\n\t"
+//        "movl %%eax,;\n\t"
+//        :"=r"(Content.Epb),"=r"(Context.Esp),"=r"(Context.Eip)
+//        ://no input
+//        :"ebp","esp","eax");
+#else
+    _asm {
     Label:
       mov [Context.Ebp], ebp;
       mov [Context.Esp], esp;
       mov eax, [Label];
       mov [Context.Eip], eax;
     }
     Label:
       mov [Context.Ebp], ebp;
       mov [Context.Esp], esp;
       mov eax, [Label];
       mov [Context.Eip], eax;
     }
+#endif
 #else
     RtlCaptureContext(&Context);
 #endif
 #else
     RtlCaptureContext(&Context);
 #endif
@@ -202,7 +213,7 @@ void Quassel::logBacktrace(const QString &filename) {
 
   logFile.close();
 }
 
   logFile.close();
 }
-#ifdef _M_IX86
+#if defined(_M_IX86) && defined(Q_CC_MSVC)
   #pragma warning(pop)
   #pragma optimize("g", on)
 #endif
   #pragma warning(pop)
   #pragma optimize("g", on)
 #endif
index 28e1472..bec189a 100644 (file)
 #define SYNCABLE_OBJECT static const int _classNameOffset__;
 #define INIT_SYNCABLE_OBJECT(x) const int x ::_classNameOffset__ = QByteArray(staticMetaObject.className()).length() + 2;
 
 #define SYNCABLE_OBJECT static const int _classNameOffset__;
 #define INIT_SYNCABLE_OBJECT(x) const int x ::_classNameOffset__ = QByteArray(staticMetaObject.className()).length() + 2;
 
-#ifdef Q_WS_WIN
+#ifdef Q_CC_MSVC
 #    define SYNC(...) sync_call__(SignalProxy::Server, (__FUNCTION__ + _classNameOffset__), __VA_ARGS__);
 #    define REQUEST(...) sync_call__(SignalProxy::Client, (__FUNCTION__ + _classNameOffset__) , __VA_ARGS__);
 #else
 #    define SYNC(...) sync_call__(SignalProxy::Server, __func__, __VA_ARGS__);
 #    define REQUEST(...) sync_call__(SignalProxy::Client, __func__, __VA_ARGS__);
 #    define SYNC(...) sync_call__(SignalProxy::Server, (__FUNCTION__ + _classNameOffset__), __VA_ARGS__);
 #    define REQUEST(...) sync_call__(SignalProxy::Client, (__FUNCTION__ + _classNameOffset__) , __VA_ARGS__);
 #else
 #    define SYNC(...) sync_call__(SignalProxy::Server, __func__, __VA_ARGS__);
 #    define REQUEST(...) sync_call__(SignalProxy::Client, __func__, __VA_ARGS__);
-#endif //Q_WS_WIN
+#endif //Q_CC_MSVC
 
 #define SYNC_OTHER(x, ...) sync_call__(SignalProxy::Server, #x, __VA_ARGS__);
 #define REQUEST_OTHER(x, ...) sync_call__(SignalProxy::Client, #x, __VA_ARGS__);
 
 #define SYNC_OTHER(x, ...) sync_call__(SignalProxy::Server, #x, __VA_ARGS__);
 #define REQUEST_OTHER(x, ...) sync_call__(SignalProxy::Client, #x, __VA_ARGS__);