mirror of
https://github.com/irssi/irssi.git
synced 2026-08-11 04:43:34 +02:00
Object type checking fixes
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@638 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
cf7eb945ea
commit
b4bdec4436
15 changed files with 78 additions and 75 deletions
|
|
@ -3,13 +3,12 @@
|
|||
|
||||
#include "servers.h"
|
||||
|
||||
#define IS_CHANNEL(channel) \
|
||||
((channel) != NULL && \
|
||||
module_find_id("CHANNEL", ((CHANNEL_REC *) (channel))->type) != -1)
|
||||
|
||||
/* Returns CHANNEL_REC if it's channel, NULL if it isn't. */
|
||||
#define CHANNEL(channel) \
|
||||
(IS_CHANNEL(channel) ? (CHANNEL_REC *) (channel) : NULL)
|
||||
MODULE_CHECK_CAST(channel, CHANNEL_REC, type, "CHANNEL")
|
||||
|
||||
#define IS_CHANNEL(channel) \
|
||||
(CHANNEL(channel) ? TRUE : FALSE)
|
||||
|
||||
#define STRUCT_SERVER_REC SERVER_REC
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@
|
|||
|
||||
#include "modules.h"
|
||||
|
||||
#define IS_CHATNET(chatnet) \
|
||||
((chatnet) != NULL && \
|
||||
module_find_id("CHATNET", (chatnet)->type) != -1)
|
||||
|
||||
/* Returns CHATNET_REC if it's chatnet, NULL if it isn't. */
|
||||
#define CHATNET(chatnet) \
|
||||
(IS_CHATNET(chatnet) ? (CHATNET_REC *) (chatnet) : NULL)
|
||||
MODULE_CHECK_CAST(chatnet, CHATNET_REC, type, "CHATNET")
|
||||
|
||||
#define IS_CHATNET(chatnet) \
|
||||
(CHATNET(chatnet) ? TRUE : FALSE)
|
||||
|
||||
typedef struct {
|
||||
#include "chatnet-rec.h"
|
||||
|
|
|
|||
|
|
@ -28,6 +28,12 @@ static GHashTable *uniqids, *uniqstrids;
|
|||
static GHashTable *idlookup, *stridlookup;
|
||||
static int next_uniq_id;
|
||||
|
||||
void *module_check_cast(void *object, int type_pos, const char *id)
|
||||
{
|
||||
return object == NULL ||
|
||||
module_find_id(id, G_STRUCT_MEMBER(int, object, type_pos)) == -1 ? NULL : object;
|
||||
}
|
||||
|
||||
/* return unique number across all modules for `id' */
|
||||
int module_get_uniq_id(const char *module, int id)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,18 @@
|
|||
#ifndef __MODULES_H
|
||||
#define __MODULES_H
|
||||
|
||||
#define MODULE_DATA_INIT(rec) \
|
||||
(rec)->module_data = g_hash_table_new(g_str_hash, g_str_equal)
|
||||
|
||||
#define MODULE_DATA_DEINIT(rec) \
|
||||
g_hash_table_destroy((rec)->module_data)
|
||||
|
||||
#define MODULE_DATA_SET(rec, data) \
|
||||
g_hash_table_insert((rec)->module_data, MODULE_NAME, data)
|
||||
|
||||
#define MODULE_DATA(rec) \
|
||||
g_hash_table_lookup((rec)->module_data, MODULE_NAME)
|
||||
|
||||
enum {
|
||||
MODULE_ERROR_ALREADY_LOADED,
|
||||
MODULE_ERROR_LOAD,
|
||||
|
|
@ -19,17 +31,9 @@ MODULE_REC *module_find(const char *name);
|
|||
int module_load(const char *path);
|
||||
void module_unload(MODULE_REC *module);
|
||||
|
||||
#define MODULE_DATA_INIT(rec) \
|
||||
(rec)->module_data = g_hash_table_new(g_str_hash, g_str_equal)
|
||||
|
||||
#define MODULE_DATA_DEINIT(rec) \
|
||||
g_hash_table_destroy((rec)->module_data)
|
||||
|
||||
#define MODULE_DATA_SET(rec, data) \
|
||||
g_hash_table_insert((rec)->module_data, MODULE_NAME, data)
|
||||
|
||||
#define MODULE_DATA(rec) \
|
||||
g_hash_table_lookup((rec)->module_data, MODULE_NAME)
|
||||
#define MODULE_CHECK_CAST(object, cast, type_field, id) \
|
||||
((cast *) module_check_cast(object, offsetof(cast, type_field), id))
|
||||
void *module_check_cast(void *object, int type_pos, const char *id);
|
||||
|
||||
/* return unique number across all modules for `id' */
|
||||
int module_get_uniq_id(const char *module, int id);
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@
|
|||
|
||||
#include "servers.h"
|
||||
|
||||
#define IS_QUERY(query) \
|
||||
((query) != NULL && \
|
||||
module_find_id("QUERY", ((QUERY_REC *) (query))->type) != -1)
|
||||
|
||||
/* Returns QUERY_REC if it's query, NULL if it isn't. */
|
||||
#define QUERY(query) \
|
||||
(IS_QUERY(query) ? (QUERY_REC *) (query) : NULL)
|
||||
MODULE_CHECK_CAST(query, QUERY_REC, type, "QUERY")
|
||||
|
||||
#define IS_QUERY(query) \
|
||||
(QUERY(query) ? TRUE : FALSE)
|
||||
|
||||
#define STRUCT_SERVER_REC SERVER_REC
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@
|
|||
|
||||
#include "servers.h"
|
||||
|
||||
#define IS_SERVER_SETUP(server) \
|
||||
((server) != NULL && \
|
||||
module_find_id("SERVER SETUP", (server)->type) != -1)
|
||||
|
||||
#define SERVER_SETUP(server) \
|
||||
(IS_SERVER_SETUP(server) ? (SERVER_SETUP_REC *) (server) : NULL)
|
||||
MODULE_CHECK_CAST(server, SERVER_SETUP_REC, type, "SERVER SETUP")
|
||||
|
||||
#define IS_SERVER_SETUP(server) \
|
||||
(SERVER_SETUP(server) ? TRUE : FALSE)
|
||||
|
||||
/* servers */
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -7,20 +7,19 @@
|
|||
typedef struct _ipaddr IPADDR;
|
||||
#endif
|
||||
|
||||
#define IS_SERVER(server) \
|
||||
((server) != NULL && module_find_id("SERVER", (server)->type) != -1)
|
||||
|
||||
#define IS_SERVER_CONNECT(conn) \
|
||||
((conn) != NULL && \
|
||||
module_find_id("SERVER CONNECT", (conn)->type) != -1)
|
||||
|
||||
/* Returns SERVER_REC if it's server, NULL if it isn't. */
|
||||
#define SERVER(server) \
|
||||
(IS_SERVER(server) ? (SERVER_REC *) (server) : NULL)
|
||||
MODULE_CHECK_CAST(server, SERVER_REC, type, "SERVER")
|
||||
|
||||
/* Returns SERVER_CONNECT_REC if it's server connection, NULL if it isn't. */
|
||||
#define SERVER_CONNECT(conn) \
|
||||
(IS_SERVER_CONNECT(conn) ? (SERVER_CONNECT_REC *) (conn) : NULL)
|
||||
MODULE_CHECK_CAST(conn, SERVER_CONNECT_REC, type, "SERVER CONNECT")
|
||||
|
||||
#define IS_SERVER(server) \
|
||||
(SERVER(server) ? TRUE : FALSE)
|
||||
|
||||
#define IS_SERVER_CONNECT(conn) \
|
||||
(SERVER_CONNECT(conn) ? TRUE : FALSE)
|
||||
|
||||
/* all strings should be either NULL or dynamically allocated */
|
||||
/* address and nick are mandatory, rest are optional */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue