summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-11-21 15:15:49 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-11-21 19:00:56 +0100
commitd4cbc576e28ab48474438db7820d47ce24c2099c (patch)
treeeeac1424b609f9e865a83a35fd79a8b7972a017f
parent9bb9c9868c0523b81acf078f330c85c4b8086bdd (diff)
downloadxK-d4cbc576e28ab48474438db7820d47ce24c2099c.tar.gz
xK-d4cbc576e28ab48474438db7820d47ce24c2099c.tar.xz
xK-d4cbc576e28ab48474438db7820d47ce24c2099c.zip
degesch: typos, cleanups
-rw-r--r--common.c3
-rw-r--r--degesch.c66
2 files changed, 39 insertions, 30 deletions
diff --git a/common.c b/common.c
index f76554d..43e53b9 100644
--- a/common.c
+++ b/common.c
@@ -41,6 +41,9 @@
return 0; \
BLOCK_END
+#define CONTAINER_OF(pointer, type, member) \
+ (type *) ((char *) pointer - offsetof (type, member))
+
// --- To be moved to liberty --------------------------------------------------
static void
diff --git a/degesch.c b/degesch.c
index e04e92b..6bd0449 100644
--- a/degesch.c
+++ b/degesch.c
@@ -758,6 +758,25 @@ struct weak_ref_link
void *user_data; ///< User data
};
+static struct weak_ref_link *
+weak_ref (struct weak_ref_link **list, destroy_cb_fn cb, void *user_data)
+{
+ struct weak_ref_link *link = xcalloc (1, sizeof *link);
+ link->on_destroy = cb;
+ link->user_data = user_data;
+ LIST_PREPEND (*list, link);
+ return link;
+}
+
+static void
+weak_unref (struct weak_ref_link **list, struct weak_ref_link **link)
+{
+ if (*link)
+ LIST_UNLINK (*list, *link);
+ free (*link);
+ *link = NULL;
+}
+
#define REF_COUNTABLE_HEADER \
size_t ref_count; /**< Reference count */ \
struct weak_ref_link *weak_refs; /**< To remove any weak references */
@@ -785,22 +804,11 @@ struct weak_ref_link
\
static struct weak_ref_link * \
name ## _weak_ref (struct name *self, destroy_cb_fn cb, void *user_data) \
- { \
- struct weak_ref_link *link = xcalloc (1, sizeof *link); \
- link->on_destroy = cb; \
- link->user_data = user_data; \
- LIST_PREPEND (self->weak_refs, link); \
- return link; \
- } \
+ { return weak_ref (&self->weak_refs, cb, user_data); } \
\
static void \
name ## _weak_unref (struct name *self, struct weak_ref_link **link) \
- { \
- if (*link) \
- LIST_UNLINK (self->weak_refs, *link); \
- free (*link); \
- *link = NULL; \
- }
+ { weak_unref (&self->weak_refs, link); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -7266,8 +7274,8 @@ input_hook_insert (struct app_context *ctx, struct input_hook *hook)
static bool
irc_hook_less (const void *a, const void *b)
{
- return ((const struct input_hook *) a)->priority
- < ((const struct input_hook *) b)->priority;
+ return ((const struct irc_hook *) a)->priority
+ < ((const struct irc_hook *) b)->priority;
}
static void
@@ -7394,7 +7402,7 @@ lua_buffer_invalidate (void *object, void *user_data)
static void
lua_plugin_push_buffer (struct lua_plugin *plugin, struct buffer *buffer)
{
- struct lua_State *L = plugin->L;
+ lua_State *L = plugin->L;
if (lua_cache_get (L, buffer))
return;
@@ -7463,7 +7471,7 @@ lua_server_invalidate (void *object, void *user_data)
static void
lua_plugin_push_server (struct lua_plugin *plugin, struct server *server)
{
- struct lua_State *L = plugin->L;
+ lua_State *L = plugin->L;
if (lua_cache_get (L, server))
return;
@@ -7518,9 +7526,8 @@ lua_hook_unhook (lua_State *L)
}
// The hook no longer has to stay alive
- lua_pushnil (L);
- lua_rawsetp (L, LUA_REGISTRYINDEX, hook);
hook->type = XLUA_HOOK_DEFUNCT;
+ lua_cache_invalidate (L, hook);
return 0;
}
@@ -7598,8 +7605,8 @@ static char *
lua_input_hook_filter (struct input_hook *self, struct buffer *buffer,
char *input)
{
- struct lua_hook *hook = (struct lua_hook *)
- ((char *) self - offsetof (struct lua_hook, data.input_hook));
+ struct lua_hook *hook =
+ CONTAINER_OF (self, struct lua_hook, data.input_hook);
struct lua_plugin *plugin = hook->plugin;
lua_State *L = plugin->L;
@@ -7607,7 +7614,7 @@ lua_input_hook_filter (struct input_hook *self, struct buffer *buffer,
lua_rawgetp (L, LUA_REGISTRYINDEX, hook); // 1: hook
lua_getuservalue (L, -1); // Retrieve function
- lua_insert (L, -2); // Swap with thet hook
+ lua_insert (L, -2); // Swap with the hook
lua_plugin_push_buffer (plugin, buffer); // 2: buffer
lua_pushstring (L, input); // 3: input
@@ -7636,8 +7643,8 @@ struct input_hook_vtable lua_input_hook_vtable =
static char *
lua_irc_hook_filter (struct irc_hook *self, struct server *s, char *message)
{
- struct lua_hook *hook = (struct lua_hook *)
- ((char *) self - offsetof (struct lua_hook, data.irc_hook));
+ struct lua_hook *hook =
+ CONTAINER_OF (self, struct lua_hook, data.irc_hook);
struct lua_plugin *plugin = hook->plugin;
lua_State *L = plugin->L;
@@ -7645,7 +7652,7 @@ lua_irc_hook_filter (struct irc_hook *self, struct server *s, char *message)
lua_rawgetp (L, LUA_REGISTRYINDEX, hook); // 1: hook
lua_getuservalue (L, -1); // Retrieve function
- lua_insert (L, -2); // Swap with thet hook
+ lua_insert (L, -2); // Swap with the hook
lua_plugin_push_server (plugin, s); // 2: server
lua_pushstring (L, message); // 3: message
@@ -7675,7 +7682,7 @@ static struct lua_hook *
lua_plugin_push_hook
(struct lua_plugin *plugin, int callback_index, enum lua_hook_type type)
{
- struct lua_State *L = plugin->L;
+ lua_State *L = plugin->L;
struct lua_hook *hook = lua_newuserdata (L, sizeof *hook);
luaL_setmetatable (L, XLUA_HOOK_METATABLE);
memset (hook, 0, sizeof *hook);
@@ -7687,8 +7694,7 @@ lua_plugin_push_hook
lua_setuservalue (L, -2);
// Make sure the hook doesn't get garbage collected and return it
- lua_pushvalue (L, -1);
- lua_rawsetp (L, LUA_REGISTRYINDEX, hook);
+ lua_cache_store (L, hook, -1);
return hook;
}
@@ -8750,7 +8756,7 @@ mass_channel_mode_mask_list
str_vector_init (&v);
cstr_split_ignore_empty (a->arguments, ' ', &v);
- // XXX: this may be a bit too trivial; we could map also nicknames
+ // XXX: this may be a bit too trivial; we could also map nicknames
// to information from WHO polling or userhost-in-names
for (size_t i = 0; i < v.len; i++)
{
@@ -8987,7 +8993,7 @@ handle_command_whois (struct handler_args *a)
irc_send (a->s, "WHOIS %s", a->s->irc_user->nickname);
else
log_server_error (a->s, a->buffer, "#s: #s", "Can't request info",
- "no target given and this buffer is not a PM nor a server");
+ "no target given and this buffer is neither a PM nor a server");
return true;
}