text: font: add owner field to font_ops
authorDavid Herrmann <dh.herrmann@googlemail.com>
Thu, 3 Jan 2013 15:23:52 +0000 (16:23 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Thu, 3 Jan 2013 15:23:52 +0000 (16:23 +0100)
The owner fields specifies the module that provides the code for the given
backend. The font-core is responsible of ref/unref'ing the module so its
code is always available as long as the module exists.

We cannot push this into the modules as modules _must_ never call
kmscon_module_unref(KMSCON_THIS_MODULE)! Because this might drop the last
reference and hence the function might disallocate the module. However,
this means that it cannot return because the caller is _part_ of the
module and so no longer valid.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/text.h
src/text_font.c
src/text_font_8x16.c
src/text_font_freetype2.c
src/text_font_pango.c
src/text_font_unifont.c

index 9ce7178..3d4556f 100644 (file)
@@ -40,6 +40,7 @@
 
 #include <errno.h>
 #include <stdlib.h>
+#include "kmscon_module.h"
 #include "tsm_screen.h"
 #include "uterm.h"
 
@@ -85,6 +86,7 @@ struct kmscon_font {
 
 struct kmscon_font_ops {
        const char *name;
+       struct kmscon_module *owner;
        int (*init) (struct kmscon_font *out,
                     const struct kmscon_font_attr *attr);
        void (*destroy) (struct kmscon_font *font);
@@ -95,7 +97,6 @@ struct kmscon_font_ops {
                             const struct kmscon_glyph **out);
        int (*render_inval) (struct kmscon_font *font,
                             const struct kmscon_glyph **out);
-       void (*finalize) (void);
 };
 
 int kmscon_font_register(const struct kmscon_font_ops *ops);
index bdcaff9..000f201 100644 (file)
@@ -56,6 +56,7 @@
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
+#include "kmscon_module.h"
 #include "log.h"
 #include "shl_dlist.h"
 #include "shl_register.h"
@@ -137,8 +138,7 @@ static inline void kmscon_font_destroy(void *data)
 {
        const struct kmscon_font_ops *ops = data;
 
-       if (ops->finalize)
-               ops->finalize();
+       kmscon_module_unref(ops->owner);
 }
 
 /**
@@ -172,6 +172,7 @@ int kmscon_font_register(const struct kmscon_font_ops *ops)
                return ret;
        }
 
+       kmscon_module_ref(ops->owner);
        return 0;
 }
 
index 0714ce3..5622c68 100644 (file)
@@ -107,12 +107,12 @@ static int kmscon_font_8x16_render_inval(struct kmscon_font *font,
 
 struct kmscon_font_ops kmscon_font_8x16_ops = {
        .name = "8x16",
+       .owner = NULL,
        .init = kmscon_font_8x16_init,
        .destroy = kmscon_font_8x16_destroy,
        .render = kmscon_font_8x16_render,
        .render_empty = kmscon_font_8x16_render_empty,
        .render_inval = kmscon_font_8x16_render_inval,
-       .finalize = NULL,
 };
 
 static const struct kmscon_glyph kmscon_font_8x16_glyphs[256] = {
index fb1c30e..277afd6 100644 (file)
@@ -684,10 +684,10 @@ static int kmscon_font_freetype2_render_inval(struct kmscon_font *font,
 
 struct kmscon_font_ops kmscon_font_freetype2_ops = {
        .name = "freetype2",
+       .owner = NULL,
        .init = kmscon_font_freetype2_init,
        .destroy = kmscon_font_freetype2_destroy,
        .render = kmscon_font_freetype2_render,
        .render_empty = kmscon_font_freetype2_render_empty,
        .render_inval = kmscon_font_freetype2_render_inval,
-       .finalize = NULL,
 };
index 34c83c1..155dd0e 100644 (file)
@@ -430,10 +430,10 @@ static int kmscon_font_pango_render_inval(struct kmscon_font *font,
 
 struct kmscon_font_ops kmscon_font_pango_ops = {
        .name = "pango",
+       .owner = NULL,
        .init = kmscon_font_pango_init,
        .destroy = kmscon_font_pango_destroy,
        .render = kmscon_font_pango_render,
        .render_empty = kmscon_font_pango_render_empty,
        .render_inval = kmscon_font_pango_render_inval,
-       .finalize = NULL,
 };
index f3c1c19..6970c2a 100644 (file)
@@ -113,10 +113,10 @@ static int kmscon_font_unifont_render_empty(struct kmscon_font *font,
 
 struct kmscon_font_ops kmscon_font_unifont_ops = {
        .name = "unifont",
+       .owner = NULL,
        .init = kmscon_font_unifont_init,
        .destroy = kmscon_font_unifont_destroy,
        .render = kmscon_font_unifont_render,
        .render_empty = kmscon_font_unifont_render_empty,
        .render_inval = kmscon_font_unifont_render_inval,
-       .finalize = NULL,
 };