Skip to content

Commit

Permalink
Fixed|GCC: Illegal and accidental dynamic linkage from plugin to engine
Browse files Browse the repository at this point in the history
The WadMapConverter plugin was accidentally linked to a symbol
in the engine, causing the plugin to disrupt internal engine state.
Added a macro for naming plugin globals in such a way that they
won't clash with engine globals.

This won't be a problem any more after we apply the libdeng
refactoring...
  • Loading branch information
skyjake committed Mar 12, 2012
1 parent 6bbf528 commit 95a2297
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
6 changes: 6 additions & 0 deletions doomsday/engine/api/dd_plugin.h
Expand Up @@ -34,6 +34,12 @@

#define LIBDENG_PLUGINDESC "(" DOOMSDAY_NICENAME " Plugin)"

/**
* Use this for all global variables in plugins so that they will not be
* confused with engine's exported symbols.
*/
#define DENG_PLUGIN_GLOBAL(name) __DengPlugin_##name

#define MAX_HOOKS 16
#define HOOKF_EXCLUSIVE 0x01000000

Expand Down
9 changes: 5 additions & 4 deletions doomsday/plugins/wadmapconverter/include/wadmapconverter.h
Expand Up @@ -31,6 +31,7 @@
#ifndef __MAPCONVERTER_H__
#define __MAPCONVERTER_H__

#include "dd_plugin.h"
#include "dd_types.h"

// Vertex indices.
Expand All @@ -40,8 +41,8 @@ enum { VX, VY, VZ };
#define RIGHT 0
#define LEFT 1

#define VERBOSE(code) { if(verbose >= 1) { code; } }
#define VERBOSE2(code) { if(verbose >= 2) { code; } }
#define VERBOSE(code) { if(DENG_PLUGIN_GLOBAL(verbose) >= 1) { code; } }
#define VERBOSE2(code) { if(DENG_PLUGIN_GLOBAL(verbose) >= 2) { code; } }

typedef struct materialref_s {
char name[9];
Expand Down Expand Up @@ -170,8 +171,8 @@ typedef struct map_s {
void* blockMap;
} map_t;

extern map_t* map;
extern boolean verbose;
extern map_t* DENG_PLUGIN_GLOBAL(map);
extern boolean DENG_PLUGIN_GLOBAL(verbose);

boolean IsSupportedFormat(const lumpnum_t* lumpList, int numLumps);

Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/wadmapconverter/src/load.c
Expand Up @@ -44,6 +44,8 @@

// MACROS ------------------------------------------------------------------

#define map DENG_PLUGIN_GLOBAL(map)

// Size of the map data structures in bytes in the arrived WAD format.
#define SIZEOF_64VERTEX (4 * 2)
#define SIZEOF_VERTEX (2 * 2)
Expand Down
13 changes: 7 additions & 6 deletions doomsday/plugins/wadmapconverter/src/wadmapconverter.c
Expand Up @@ -38,8 +38,9 @@

#include "wadmapconverter.h"

map_t theMap, *map = &theMap;
boolean verbose;
map_t DENG_PLUGIN_GLOBAL(theMap);
map_t* DENG_PLUGIN_GLOBAL(map) = &DENG_PLUGIN_GLOBAL(theMap);
boolean DENG_PLUGIN_GLOBAL(verbose);

/**
* This function will be called when Doomsday is asked to load a map that is
Expand All @@ -52,9 +53,9 @@ int ConvertMapHook(int hookType, int param, void *data)
{
lumpnum_t* lumpList = (int*) data;

verbose = ArgExists("-verbose");
DENG_PLUGIN_GLOBAL(verbose) = ArgExists("-verbose");

memset(map, 0, sizeof(*map));
memset(DENG_PLUGIN_GLOBAL(map), 0, sizeof(*DENG_PLUGIN_GLOBAL(map)));

if(!IsSupportedFormat(lumpList, param))
{
Expand All @@ -63,8 +64,8 @@ int ConvertMapHook(int hookType, int param, void *data)
}

VERBOSE( Con_Message("WadMapConverter: Recognised a %s format map.\n",
(map->format == MF_DOOM64? "DOOM64" :
map->format == MF_HEXEN? "Hexen" : "DOOM")) )
(DENG_PLUGIN_GLOBAL(map)->format == MF_DOOM64? "DOOM64" :
DENG_PLUGIN_GLOBAL(map)->format == MF_HEXEN? "Hexen" : "DOOM")) )

if(!LoadMap(lumpList, param))
{
Expand Down

0 comments on commit 95a2297

Please sign in to comment.