Browse Source

A sad workaround for a sad misery with Python bindings on Windows.

pull/388/head
Vladimír Vondruš 7 years ago
parent
commit
909887ad7c
  1. 4
      doc/changelog.dox
  2. 2
      src/Magnum/Audio/Context.cpp
  3. 2
      src/Magnum/GL/Context.cpp
  4. 11
      src/Magnum/Implementation/WindowsWeakSymbol.cpp
  5. 2
      src/Magnum/Implementation/WindowsWeakSymbol.h

4
doc/changelog.dox

@ -371,7 +371,9 @@ See also:
@ref Corrade::Containers::Array instead of being deleted
- Global state used by @ref GL::Context and @ref Audio::Context is no longer
duplicated when Magnum is built statically and linked to more than one
dynamic library or executable.
dynamic library or executable. This works on all platforms except for
Python bindings on Windows at the moment, where the workaround is to build
both Corrade and Magnum dynamically.
- The [base-qt](https://github.com/mosra/magnum-bootstrap/tree/base-qt)
bootstrap project is fixed to use OpenGL 4.1 on macOS instead of being
stuck on 2.1 (see [mosra/magnum-bootstrap#22](https://github.com/mosra/magnum-bootstrap/issues/22))

2
src/Magnum/Audio/Context.cpp

@ -161,7 +161,7 @@ namespace {
Context*& windowsCurrentContext() {
/* A function-local static to ensure it's only initialized once without any
race conditions among threads */
static Context** const uniqueGlobals = reinterpret_cast<Context**>(Magnum::Implementation::windowsWeakSymbol("magnumAudioUniqueCurrentContext"));
static Context** const uniqueGlobals = reinterpret_cast<Context**>(Magnum::Implementation::windowsWeakSymbol("magnumAudioUniqueCurrentContext", &magnumAudioUniqueCurrentContext));
return *uniqueGlobals;
}

2
src/Magnum/GL/Context.cpp

@ -522,7 +522,7 @@ namespace {
Context*& windowsCurrentContext() {
/* A function-local static to ensure it's only initialized once without any
race conditions among threads */
static Context*&(*const uniqueGlobals)() = reinterpret_cast<Context*&(*)()>(Magnum::Implementation::windowsWeakSymbol("magnumGLUniqueCurrentContext"));
static Context*&(*const uniqueGlobals)() = reinterpret_cast<Context*&(*)()>(Magnum::Implementation::windowsWeakSymbol("magnumGLUniqueCurrentContext", reinterpret_cast<void*>(magnumGLUniqueCurrentContext)));
return uniqueGlobals();
}

11
src/Magnum/Implementation/WindowsWeakSymbol.cpp

@ -25,7 +25,7 @@
#include "WindowsWeakSymbol.h"
#include <Corrade/Utility/Assert.h>
#include <cstdio>
#define WIN32_LEAN_AND_MEAN 1
#define VC_EXTRALEAN
@ -33,10 +33,15 @@
namespace Magnum { namespace Implementation {
void* windowsWeakSymbol(const char* name) {
void* windowsWeakSymbol(const char* name, void* backup) {
/* FARPROC?! I want either a function pointer or a variable pointer */
void* address = reinterpret_cast<void*>(GetProcAddress(GetModuleHandleA(nullptr), name));
CORRADE_INTERNAL_ASSERT(address);
/* This shouldn't fail, except in Python, where it's a sad, sad misery. */
if(!address) {
std::fprintf(stderr, "Cannot query global symbol %s and make it unique\n"
"across DLLs. App may misbehave, sorry. Build Magnum as dynamic as a workaround.\n", name);
address = backup;
}
return address;
}

2
src/Magnum/Implementation/WindowsWeakSymbol.h

@ -39,7 +39,7 @@
namespace Magnum { namespace Implementation {
void* windowsWeakSymbol(const char* name);
void* windowsWeakSymbol(const char* name, void* backup);
}}

Loading…
Cancel
Save