[Spice-devel] [PATCH 2/2] use macro to define constructor function
Frediano Ziglio
fziglio at redhat.com
Mon Feb 29 10:36:54 UTC 2016
Avoid having to call function at runtime to inialize static.
Old functions are defined as deprecated for compatibility.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
common/gdi_canvas.c | 2 --
common/gl_canvas.c | 2 --
common/quic.c | 11 ++---------
common/quic.h | 2 +-
common/rop3.c | 8 +-------
common/rop3.h | 2 +-
common/sw_canvas.c | 12 +-----------
common/sw_canvas.h | 2 +-
8 files changed, 7 insertions(+), 34 deletions(-)
diff --git a/common/gdi_canvas.c b/common/gdi_canvas.c
index 3c434d6..fcc5fc9 100644
--- a/common/gdi_canvas.c
+++ b/common/gdi_canvas.c
@@ -1857,6 +1857,4 @@ void gdi_canvas_init(void) //unsafe global function
gdi_canvas_ops.put_image = gdi_canvas_put_image;
gdi_canvas_ops.clear = gdi_canvas_clear;
gdi_canvas_ops.destroy = gdi_canvas_destroy;
-
- rop3_init();
}
diff --git a/common/gl_canvas.c b/common/gl_canvas.c
index 9c5b98c..5ffb47b 100644
--- a/common/gl_canvas.c
+++ b/common/gl_canvas.c
@@ -908,6 +908,4 @@ void gl_canvas_init(void) //unsafe global function
gl_canvas_ops.group_start = gl_canvas_group_start;
gl_canvas_ops.group_end = gl_canvas_group_end;
gl_canvas_ops.destroy = gl_canvas_destroy;
-
- rop3_init();
}
diff --git a/common/quic.c b/common/quic.c
index 88cf143..f014a2a 100644
--- a/common/quic.c
+++ b/common/quic.c
@@ -1634,13 +1634,11 @@ int quic_decode(QuicContext *quic, QuicImageType type, uint8_t *buf, int stride)
return QUIC_OK;
}
-static int need_init = TRUE;
-
QuicContext *quic_create(QuicUsrContext *usr)
{
Encoder *encoder;
- if (!usr || need_init || !usr->error || !usr->warn || !usr->info || !usr->malloc ||
+ if (!usr || !usr->error || !usr->warn || !usr->info || !usr->malloc ||
!usr->free || !usr->more_space || !usr->more_lines) {
return NULL;
}
@@ -1671,13 +1669,8 @@ void quic_destroy(QuicContext *quic)
encoder->usr->free(encoder->usr, encoder);
}
-void quic_init(void)
+SPICE_CONSTRUCTOR_FUNC(quic_global_init)
{
- if (!need_init) {
- return;
- }
- need_init = FALSE;
-
family_init(&family_8bpc, 8, DEFmaxclen);
family_init(&family_5bpc, 5, DEFmaxclen);
}
diff --git a/common/quic.h b/common/quic.h
index ee5fb17..97622b3 100644
--- a/common/quic.h
+++ b/common/quic.h
@@ -63,7 +63,7 @@ int quic_decode(QuicContext *quic, QuicImageType type, uint8_t *buf, int stride)
QuicContext *quic_create(QuicUsrContext *usr);
void quic_destroy(QuicContext *quic);
-void quic_init(void);
+static inline SPICE_GNUC_DEPRECATED void quic_init(void) {}
SPICE_END_DECLS
diff --git a/common/rop3.c b/common/rop3.c
index 1a18fe9..2a0a167 100644
--- a/common/rop3.c
+++ b/common/rop3.c
@@ -376,16 +376,10 @@ ROP3_HANDLERS(DPSoo, *src | *pat | *dest, 0xfe);
rop3_test_handlers_32[index] = rop3_test32_##op; \
rop3_test_handlers_16[index] = rop3_test16_##op;
-void rop3_init(void)
+SPICE_CONSTRUCTOR_FUNC(rop3_global_init)
{
- static int need_init = 1;
int i;
- if (!need_init) {
- return;
- }
- need_init = 0;
-
for (i = 0; i < ROP3_NUM_OPS; i++) {
rop3_with_pattern_handlers_32[i] = default_rop3_with_pattern_handler;
rop3_with_pattern_handlers_16[i] = default_rop3_with_pattern_handler;
diff --git a/common/rop3.h b/common/rop3.h
index 7e00499..20e100c 100644
--- a/common/rop3.h
+++ b/common/rop3.h
@@ -32,7 +32,7 @@ void do_rop3_with_pattern(uint8_t rop3, pixman_image_t *d, pixman_image_t *s, Sp
void do_rop3_with_color(uint8_t rop3, pixman_image_t *d, pixman_image_t *s, SpicePoint *src_pos,
uint32_t rgb);
-void rop3_init(void);
+static inline SPICE_GNUC_DEPRECATED void rop3_init(void) {}
SPICE_END_DECLS
diff --git a/common/sw_canvas.c b/common/sw_canvas.c
index a43cee4..e8b0f3b 100644
--- a/common/sw_canvas.c
+++ b/common/sw_canvas.c
@@ -1188,7 +1188,6 @@ static void canvas_destroy(SpiceCanvas *spice_canvas)
free(canvas);
}
-static int need_init = 1;
static SpiceCanvasOps sw_canvas_ops;
static SpiceCanvas *canvas_create_common(pixman_image_t *image,
@@ -1205,9 +1204,6 @@ static SpiceCanvas *canvas_create_common(pixman_image_t *image,
{
SwCanvas *canvas;
- if (need_init) {
- return NULL;
- }
spice_pixman_image_set_format(image,
spice_surface_format_to_pixman (format));
@@ -1290,13 +1286,8 @@ SpiceCanvas *canvas_create_for_data(int width, int height, uint32_t format,
);
}
-void sw_canvas_init(void) //unsafe global function
+SPICE_CONSTRUCTOR_FUNC(sw_canvas_global_init) //unsafe global function
{
- if (!need_init) {
- return;
- }
- need_init = 0;
-
canvas_base_init_ops(&sw_canvas_ops);
sw_canvas_ops.draw_text = canvas_draw_text;
sw_canvas_ops.put_image = canvas_put_image;
@@ -1329,5 +1320,4 @@ void sw_canvas_init(void) //unsafe global function
sw_canvas_ops.colorkey_scale_image_from_surface = colorkey_scale_image_from_surface;
sw_canvas_ops.copy_region = copy_region;
sw_canvas_ops.get_image = get_image;
- rop3_init();
}
diff --git a/common/sw_canvas.h b/common/sw_canvas.h
index 564d416..8039142 100644
--- a/common/sw_canvas.h
+++ b/common/sw_canvas.h
@@ -52,7 +52,7 @@ SpiceCanvas *canvas_create_for_data(int width, int height, uint32_t format, uint
);
-void sw_canvas_init(void);
+static inline SPICE_GNUC_DEPRECATED void sw_canvas_init(void) {}
SPICE_END_DECLS
--
2.5.0
More information about the Spice-devel
mailing list