[Spice-devel] [PATCH 07/15] common: add extern "C" guards to headers

Christophe Fergeau cfergeau at redhat.com
Thu Apr 21 04:53:32 PDT 2011


Since some spice C++ code is using code from common/, the C
functions need to be marked as such for the C++ compiler, otherwise
we'll get linkage issues.
---
 common/canvas_base.h  |    8 ++++++++
 common/canvas_utils.h |    8 ++++++++
 common/draw.h         |    8 ++++++++
 common/gdi_canvas.h   |    8 ++++++++
 common/gl_canvas.h    |    7 +++++++
 common/gl_utils.h     |    8 ++++++++
 common/glc.h          |    8 ++++++++
 common/lines.h        |    8 ++++++++
 common/lz.h           |    7 +++++++
 common/lz_common.h    |    7 +++++++
 common/marshaller.h   |    8 ++++++++
 common/mem.h          |    7 +++++++
 common/messages.h     |   10 ++++++++--
 common/mutex.h        |    9 +++++++++
 common/ogl_ctx.h      |    8 ++++++++
 common/pixman_utils.h |    8 ++++++++
 common/quic.h         |    8 ++++++++
 common/quic_config.h  |    8 ++++++++
 common/rect.h         |    8 ++++++++
 common/region.h       |    8 ++++++++
 common/ring.h         |    8 ++++++++
 common/rop3.h         |    9 +++++++++
 common/sw_canvas.h    |    8 ++++++++
 23 files changed, 182 insertions(+), 2 deletions(-)

diff --git a/common/canvas_base.h b/common/canvas_base.h
index 2166dcf..ff0f972 100644
--- a/common/canvas_base.h
+++ b/common/canvas_base.h
@@ -25,6 +25,10 @@
 #include "region.h"
 #include "draw.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef void (*spice_destroy_fn_t)(void *data);
 
 typedef struct _SpiceImageCache SpiceImageCache;
@@ -310,4 +314,8 @@ struct _SpiceCanvas {
   SpiceCanvasOps *ops;
 };
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/common/canvas_utils.h b/common/canvas_utils.h
index b87b816..ffed927 100644
--- a/common/canvas_utils.h
+++ b/common/canvas_utils.h
@@ -24,6 +24,10 @@
 #include "pixman_utils.h"
 #include "lz.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct PixmanData {
 #ifdef WIN32
     HBITMAP bitmap;
@@ -65,4 +69,8 @@ typedef struct LzDecodeUsrData {
 pixman_image_t *alloc_lz_image_surface(LzDecodeUsrData *canvas_data,
                                        pixman_format_code_t pixman_format, int width,
                                        int height, int gross_pixels, int top_down);
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/common/draw.h b/common/draw.h
index cb15672..793169f 100644
--- a/common/draw.h
+++ b/common/draw.h
@@ -35,6 +35,10 @@
 #include <spice/enums.h>
 #include "mem.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define SPICE_GET_ADDRESS(addr) ((void *)(unsigned long)(addr))
 #define SPICE_SET_ADDRESS(addr, val) ((addr) = (unsigned long)(val))
 
@@ -270,4 +274,8 @@ typedef struct SpiceCursorHeader {
     uint16_t hot_spot_y;
 } SpiceCursorHeader;
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _H_SPICE_DRAW */
diff --git a/common/gdi_canvas.h b/common/gdi_canvas.h
index b3d4b15..5cdffb3 100644
--- a/common/gdi_canvas.h
+++ b/common/gdi_canvas.h
@@ -21,6 +21,10 @@
 
 #include <stdint.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "pixman_utils.h"
 #include "canvas_base.h"
 #include "region.h"
@@ -36,4 +40,8 @@ SpiceCanvas *gdi_canvas_create(int width, int height,
 
 void gdi_canvas_init();
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/common/gl_canvas.h b/common/gl_canvas.h
index d7125e6..ff3fba0 100644
--- a/common/gl_canvas.h
+++ b/common/gl_canvas.h
@@ -20,6 +20,10 @@
 #include "canvas_base.h"
 #include "region.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 SpiceCanvas *gl_canvas_create(int width, int height, uint32_t format
 #ifdef SW_CANVAS_CACHE
                            , SpiceImageCache *bits_cache
@@ -35,3 +39,6 @@ SpiceCanvas *gl_canvas_create(int width, int height, uint32_t format
 void gl_canvas_set_textures_lost(SpiceCanvas *canvas, int textures_lost);
 void gl_canvas_init();
 
+#ifdef __cplusplus
+}
+#endif
diff --git a/common/gl_utils.h b/common/gl_utils.h
index eecff26..175f131 100644
--- a/common/gl_utils.h
+++ b/common/gl_utils.h
@@ -21,6 +21,10 @@
 #ifndef GL_UTILS_H
 #define GL_UTILS_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifdef RED_DEBUG
 #define GLC_ERROR_TEST_FLUSH {                                        \
     GLenum gl_err;  glFlush();                                        \
@@ -102,4 +106,8 @@ static inline int gl_get_to_power_two(unsigned int val)
     return 1 << find_msb(val);
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/common/glc.h b/common/glc.h
index a6b8579..d77f003 100644
--- a/common/glc.h
+++ b/common/glc.h
@@ -23,6 +23,10 @@
 
 #include <stdint.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef void * GLCCtx;
 typedef void * GLCPattern;
 typedef void * GLCPath;
@@ -156,4 +160,8 @@ void glc_clear(GLCCtx glc);
 GLCCtx glc_create(int width, int height);
 void glc_destroy(GLCCtx glc, int textures_lost);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/common/lines.h b/common/lines.h
index 1d092f0..73eef9b 100644
--- a/common/lines.h
+++ b/common/lines.h
@@ -54,6 +54,10 @@ SOFTWARE.
 #include <string.h>
 #include "draw.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct lineGC lineGC;
 
 typedef struct {
@@ -127,4 +131,8 @@ extern int spice_canvas_clip_spans(pixman_region32_t *clip_region,
                                    int *new_widths,
                                    int sorted);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* LINES_H */
diff --git a/common/lz.h b/common/lz.h
index 993609f..472e34d 100644
--- a/common/lz.h
+++ b/common/lz.h
@@ -10,6 +10,10 @@
 #include "lz_config.h"
 #include "draw.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef void *LzContext;
 
 typedef struct LzUsrContext LzUsrContext;
@@ -71,5 +75,8 @@ LzContext *lz_create(LzUsrContext *usr);
 
 void lz_destroy(LzContext *lz);
 
+#ifdef __cplusplus
+}
+#endif
 
 #endif  // __LZ_H
diff --git a/common/lz_common.h b/common/lz_common.h
index 34276af..4156cff 100644
--- a/common/lz_common.h
+++ b/common/lz_common.h
@@ -23,6 +23,10 @@
 #ifndef _LZ_COMMON_H
 #define _LZ_COMMON_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 //#define DEBUG
 
 /* change the max window size will require change in the encoding format*/
@@ -58,5 +62,8 @@ static const int RGB_BYTES_PER_PIXEL[] = {0, 1, 1, 1, 1, 1, 2, 3, 4, 4, 4};
 #define LZ_VERSION_MINOR 1U
 #define LZ_VERSION ((LZ_VERSION_MAJOR << 16) | (LZ_VERSION_MINOR & 0xffff))
 
+#ifdef __cplusplus
+}
+#endif
 
 #endif  // _LZ_COMMON_H
diff --git a/common/marshaller.h b/common/marshaller.h
index 4d77140..0a61fef 100644
--- a/common/marshaller.h
+++ b/common/marshaller.h
@@ -25,6 +25,10 @@
 #include <sys/uio.h>
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct SpiceMarshaller SpiceMarshaller;
 typedef void (*spice_marshaller_item_free_func)(uint8_t *data, void *opaque);
 
@@ -63,4 +67,8 @@ void *spice_marshaller_add_int8(SpiceMarshaller *m, int8_t v);
 
 void  spice_marshaller_set_uint32(SpiceMarshaller *m, void *ref, uint32_t v);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/common/mem.h b/common/mem.h
index 797bba0..8ba6586 100644
--- a/common/mem.h
+++ b/common/mem.h
@@ -22,6 +22,10 @@
 #include <stdlib.h>
 #include <spice/macros.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct SpiceChunk {
     uint8_t *data;
     uint32_t len;
@@ -120,4 +124,7 @@ void spice_buffer_append(SpiceBuffer *buffer, const void *data, size_t len);
 size_t spice_buffer_copy(SpiceBuffer *buffer, void *dest, size_t len);
 size_t spice_buffer_remove(SpiceBuffer *buffer, size_t len);
 
+#ifdef __cplusplus
+}
+#endif
 #endif
diff --git a/common/messages.h b/common/messages.h
index 1a60a9f..6fcd8be 100644
--- a/common/messages.h
+++ b/common/messages.h
@@ -34,6 +34,10 @@
 #include <spice/protocol.h>
 #include "draw.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct SpiceMsgData {
     uint32_t data_size;
     uint8_t data[0];
@@ -494,6 +498,8 @@ typedef struct SpiceMsgcTunnelSocketTokens {
     uint32_t num_tokens;
 } SpiceMsgcTunnelSocketTokens;
 
-#endif /* _H_SPICE_PROTOCOL */
-
+#ifdef __cplusplus
+}
+#endif
 
+#endif /* _H_SPICE_PROTOCOL */
diff --git a/common/mutex.h b/common/mutex.h
index a2d35de..6789b8f 100644
--- a/common/mutex.h
+++ b/common/mutex.h
@@ -18,6 +18,11 @@
 
 #ifndef _H_MUTEX
 #define _H_MUTEX
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifdef _WIN32
 #include <windows.h>
 typedef CRITICAL_SECTION mutex_t;
@@ -32,4 +37,8 @@ typedef pthread_mutex_t mutex_t;
 #define MUTEX_UNLOCK(mutex) pthread_mutex_unlock(&mutex)
 #endif
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif // _H_MUTEX
diff --git a/common/ogl_ctx.h b/common/ogl_ctx.h
index 3abe6d7..ae2ce7e 100644
--- a/common/ogl_ctx.h
+++ b/common/ogl_ctx.h
@@ -19,6 +19,10 @@
 #ifndef _H_GLCTX
 #define _H_GLCTX
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct OGLCtx OGLCtx;
 
 const char *oglctx_type_str(OGLCtx *ctx);
@@ -27,5 +31,9 @@ OGLCtx *pbuf_create(int width, int heigth);
 OGLCtx *pixmap_create(int width, int heigth);
 void oglctx_destroy(OGLCtx *ctx);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 
diff --git a/common/pixman_utils.h b/common/pixman_utils.h
index e15b682..61eaddd 100644
--- a/common/pixman_utils.h
+++ b/common/pixman_utils.h
@@ -26,6 +26,10 @@
 
 #include "draw.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* This lists all possible 2 argument binary raster ops.
  * This enum has the same values as the X11 GXcopy type
  * and same as the GL constants (GL_AND etc) if you
@@ -125,4 +129,8 @@ void spice_pixman_copy_rect(pixman_image_t *image,
                             int w, int h,
                             int dest_x, int dest_y);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _H__PIXMAN_UTILS */
diff --git a/common/quic.h b/common/quic.h
index f4ef854..d031777 100644
--- a/common/quic.h
+++ b/common/quic.h
@@ -21,6 +21,10 @@
 
 #include "quic_config.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef enum {
     QUIC_IMAGE_TYPE_INVALID,
     QUIC_IMAGE_TYPE_GRAY,
@@ -61,5 +65,9 @@ void quic_destroy(QuicContext *quic);
 
 void quic_init();
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 
diff --git a/common/quic_config.h b/common/quic_config.h
index 1273dbc..da5e51c 100644
--- a/common/quic_config.h
+++ b/common/quic_config.h
@@ -21,6 +21,10 @@
 
 #include <spice/types.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifdef __GNUC__
 
 #include <string.h>
@@ -47,5 +51,9 @@
 
 #endif
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 
diff --git a/common/rect.h b/common/rect.h
index cdd4335..6d7c446 100644
--- a/common/rect.h
+++ b/common/rect.h
@@ -22,6 +22,10 @@
 #include "draw.h"
 #include <spice/macros.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 static inline void rect_sect(SpiceRect* r, const SpiceRect* bounds)
 {
     r->left = MAX(r->left, bounds->left);
@@ -73,6 +77,10 @@ static inline int rect_is_same_size(const SpiceRect *r1, const SpiceRect *r2)
 }
 
 #ifdef __cplusplus
+}
+#endif
+
+#ifdef __cplusplus
 
 static inline void rect_sect(SpiceRect& r, const SpiceRect& bounds)
 {
diff --git a/common/region.h b/common/region.h
index bad7494..16ec6eb 100644
--- a/common/region.h
+++ b/common/region.h
@@ -23,6 +23,10 @@
 #include "draw.h"
 #include <pixman_utils.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef pixman_region32_t QRegion;
 
 #define REGION_TEST_LEFT_EXCLUSIVE (1 << 0)
@@ -59,5 +63,9 @@ void region_offset(QRegion *rgn, int32_t dx, int32_t dy);
 
 void region_dump(const QRegion *rgn, const char *prefix);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 
diff --git a/common/ring.h b/common/ring.h
index a013a2f..ff4ef6d 100644
--- a/common/ring.h
+++ b/common/ring.h
@@ -21,6 +21,10 @@
 
 #include "spice_common.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct Ring RingItem;
 typedef struct Ring {
     RingItem *prev;
@@ -150,5 +154,9 @@ static inline RingItem *ring_prev(Ring *ring, RingItem *pos)
             (var) = ring_prev(ring, var))
 
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 
diff --git a/common/rop3.h b/common/rop3.h
index 0211130..549b02c 100644
--- a/common/rop3.h
+++ b/common/rop3.h
@@ -24,11 +24,20 @@
 #include "draw.h"
 #include "pixman_utils.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void do_rop3_with_pattern(uint8_t rop3, pixman_image_t *d, pixman_image_t *s, SpicePoint *src_pos,
                           pixman_image_t *p, SpicePoint *pat_pos);
 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();
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 
diff --git a/common/sw_canvas.h b/common/sw_canvas.h
index 99deac8..42f2573 100644
--- a/common/sw_canvas.h
+++ b/common/sw_canvas.h
@@ -26,6 +26,10 @@
 #include "canvas_base.h"
 #include "region.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 SpiceCanvas *canvas_create(int width, int height, uint32_t format
 #ifdef SW_CANVAS_CACHE
                            , SpiceImageCache *bits_cache
@@ -55,4 +59,8 @@ SpiceCanvas *canvas_create_for_data(int width, int height, uint32_t format, uint
 
 void sw_canvas_init();
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
-- 
1.7.4.4



More information about the Spice-devel mailing list