use macro to define constructor function

Avoid having to call function at runtime to inialize static.
Old functions are defined as deprecated for compatibility.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
This commit is contained in:
Frediano Ziglio 2016-02-27 19:39:42 +00:00
parent 2505f9ac96
commit 5b6be16b37
8 changed files with 7 additions and 34 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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();
}

View File

@ -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