Add quick'n dirty abi check.

This commit is contained in:
Dave Davenport 2017-02-14 18:12:07 +01:00
parent fb05409365
commit 9bd4096346
2 changed files with 19 additions and 4 deletions

View file

@ -1,6 +1,8 @@
#ifndef ROFI_MODE_PRIVATE_H
#define ROFI_MODE_PRIVATE_H
#define ABI_VERSION 0x00000001
/**
* @param data Pointer to #Mode object.
*
@ -98,6 +100,8 @@ typedef char* ( *_mode_preprocess_input )( Mode *sw, const char *input );
*/
struct rofi_mode
{
/** Used for external plugins. */
unsigned int abi_version;
/** Name (max 31 char long) */
char name[32];
char cfg_name_key[128];

View file

@ -48,6 +48,7 @@
#include <libgwater-xcb.h>
#include "xcb-internal.h"
#include "xkb-internal.h"
@ -69,6 +70,10 @@
#include "timings.h"
// Plugin abi version.
// TODO: move this check to mode.c
#include "mode-private.h"
// Pidfile.
char *pidfile = NULL;
const char *cache_dir = NULL;
@ -450,10 +455,16 @@ static int add_mode ( const char * token )
// Load module.
GModule *mod = g_module_open ( token, G_MODULE_BIND_LAZY|G_MODULE_BIND_LOCAL );
if ( mod ) {
gpointer m = NULL;
if ( g_module_symbol ( mod, "mode", &m) ){
modi[num_modi] = m;
num_modi++;
Mode *m = NULL;
if ( g_module_symbol ( mod, "mode", (gpointer *)&m) ){
// Simple abi check.
if ( m->abi_version != ABI_VERSION ){
fprintf(stderr, "ABI version of plugin does not match: %08X expecting: %08X\n", m->abi_version, ABI_VERSION);
g_module_close ( mod );
} else {
modi[num_modi] = m;
num_modi++;
}
} else {
fprintf(stderr, "Symbol 'mode' not found in module: %s\n", token);
g_module_close ( mod );