[PATCH] Move GCC attributes wrapping into a separate header.

Chris Wilson chris at chris-wilson.co.uk
Sun Sep 23 13:00:23 PDT 2007


The wrapping of GCC attributes (such as cairo_private) needs to be
visible to any header file, including those that avoid cairoint.h such
as cairo-boilerplate. To achieve this we move the pre-processor magic to
its own header file and include it as required.
---
 src/Makefile.am                   |    1 +
 src/cairo-cache-private.h         |    1 +
 src/cairo-clip-private.h          |    1 +
 src/cairo-compiler-private.h      |  115 +++++++++++++++++++++++++++++++++++++
 src/cairo-hash-private.h          |    1 +
 src/cairo-mutex-private.h         |    1 +
 src/cairo-output-stream-private.h |    1 +
 src/cairo-region-private.h        |    2 +
 src/cairo-wideint-private.h       |    2 +
 src/cairo-xlib-private.h          |    5 +-
 src/cairoint.h                    |   71 +----------------------
 11 files changed, 131 insertions(+), 70 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index ae7cb63..85964e3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -178,6 +178,7 @@ libcairo_la_base_sources =			\
 	cairo-clip.c				\
 	cairo-clip-private.h			\
 	cairo-color.c				\
+	cairo-compiler-private.h		\
 	cairo-debug.c				\
 	cairo-fixed.c				\
 	cairo-font-face.c			\
diff --git a/src/cairo-cache-private.h b/src/cairo-cache-private.h
index 7ab14e2..4b3164a 100644
--- a/src/cairo-cache-private.h
+++ b/src/cairo-cache-private.h
@@ -39,6 +39,7 @@
 #ifndef CAIRO_CACHE_PRIVATE_H
 #define CAIRO_CACHE_PRIVATE_H
 
+#include "cairo-compiler-private.h"
 #include "cairo-types-private.h"
 
 /**
diff --git a/src/cairo-clip-private.h b/src/cairo-clip-private.h
index 61559ce..7f880d8 100644
--- a/src/cairo-clip-private.h
+++ b/src/cairo-clip-private.h
@@ -36,6 +36,7 @@
 #ifndef CAIRO_CLIP_PRIVATE_H
 #define CAIRO_CLIP_PRIVATE_H
 
+#include "cairo-compiler-private.h"
 #include "cairo-path-fixed-private.h"
 
 extern const cairo_private cairo_rectangle_list_t _cairo_rectangles_nil;
diff --git a/src/cairo-compiler-private.h b/src/cairo-compiler-private.h
new file mode 100644
index 0000000..da80b89
--- /dev/null
+++ b/src/cairo-compiler-private.h
@@ -0,0 +1,115 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright © 2002 University of Southern California
+ * Copyright © 2005 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * The Initial Developer of the Original Code is University of Southern
+ * California.
+ *
+ * Contributor(s):
+ *	Carl D. Worth <cworth at cworth.org>
+ */
+
+#ifndef CAIRO_COMPILER_PRIVATE_H
+#define CAIRO_COMPILER_PRIVATE_H
+
+CAIRO_BEGIN_DECLS
+
+#if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun)
+# define slim_hidden_proto(name)		slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private
+# define slim_hidden_proto_no_warn(name)	slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private_no_warn
+# define slim_hidden_def(name)			slim_hidden_def1(name, slim_hidden_int_name(name))
+# define slim_hidden_int_name(name) INT_##name
+# define slim_hidden_proto1(name, internal)				\
+  extern __typeof (name) name						\
+	__asm__ (slim_hidden_asmname (internal))
+# define slim_hidden_def1(name, internal)				\
+  extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name))	\
+	__attribute__((__alias__(slim_hidden_asmname(internal))))
+# define slim_hidden_ulp		slim_hidden_ulp1(__USER_LABEL_PREFIX__)
+# define slim_hidden_ulp1(x)		slim_hidden_ulp2(x)
+# define slim_hidden_ulp2(x)		#x
+# define slim_hidden_asmname(name)	slim_hidden_asmname1(name)
+# define slim_hidden_asmname1(name)	slim_hidden_ulp #name
+#else
+# define slim_hidden_proto(name)		int _cairo_dummy_prototype(void)
+# define slim_hidden_proto_no_warn(name)	int _cairo_dummy_prototype(void)
+# define slim_hidden_def(name)			int _cairo_dummy_prototype(void)
+#endif
+
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
+#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
+	__attribute__((__format__(__printf__, fmt_index, va_index)))
+#else
+#define CAIRO_PRINTF_FORMAT(fmt_index, va_index)
+#endif
+
+/* slim_internal.h */
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
+#define cairo_private_no_warn	__attribute__((__visibility__("hidden")))
+#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
+#define cairo_private_no_warn	__hidden
+#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
+#define cairo_private_no_warn
+#endif
+
+#ifndef WARN_UNUSED_RESULT
+#define WARN_UNUSED_RESULT
+#endif
+/* Add attribute(warn_unused_result) if supported */
+#define cairo_warn	    WARN_UNUSED_RESULT
+#define cairo_private	    cairo_private_no_warn cairo_warn
+
+/* This macro allow us to deprecate a function by providing an alias
+   for the old function name to the new function name. With this
+   macro, binary compatibility is preserved. The macro only works on
+   some platforms --- tough.
+
+   Meanwhile, new definitions in the public header file break the
+   source code so that it will no longer link against the old
+   symbols. Instead it will give a descriptive error message
+   indicating that the old function has been deprecated by the new
+   function.
+*/
+#if __GNUC__ >= 2 && defined(__ELF__)
+# define CAIRO_FUNCTION_ALIAS(old, new)		\
+	extern __typeof (new) old		\
+	__asm__ ("" #old)			\
+	__attribute__((__alias__("" #new)))
+#else
+# define CAIRO_FUNCTION_ALIAS(old, new)
+#endif
+
+#ifndef __GNUC__
+#define __attribute__(x)
+#endif
+
+
+CAIRO_END_DECLS
+
+#endif
diff --git a/src/cairo-hash-private.h b/src/cairo-hash-private.h
index 8ed3ba8..9101f2e 100644
--- a/src/cairo-hash-private.h
+++ b/src/cairo-hash-private.h
@@ -39,6 +39,7 @@
 #ifndef CAIRO_HASH_PRIVATE_H
 #define CAIRO_HASH_PRIVATE_H
 
+#include "cairo-compiler-private.h"
 #include "cairo-types-private.h"
 
 /* XXX: I'd like this file to be self-contained in terms of
diff --git a/src/cairo-mutex-private.h b/src/cairo-mutex-private.h
index 88e88bb..ac803c8 100644
--- a/src/cairo-mutex-private.h
+++ b/src/cairo-mutex-private.h
@@ -47,6 +47,7 @@
 
 #include <cairo-features.h>
 
+#include "cairo-compiler-private.h"
 #include "cairo-mutex-type-private.h"
 
 /* Only the following three are mandatory at this point */
diff --git a/src/cairo-output-stream-private.h b/src/cairo-output-stream-private.h
index 0600431..0e7d4db 100644
--- a/src/cairo-output-stream-private.h
+++ b/src/cairo-output-stream-private.h
@@ -37,6 +37,7 @@
 #ifndef CAIRO_OUTPUT_STREAM_PRIVATE_H
 #define CAIRO_OUTPUT_STREAM_PRIVATE_H
 
+#include "cairo-compiler-private.h"
 #include "cairo-types-private.h"
 
 typedef cairo_status_t (*cairo_output_stream_write_func_t) (cairo_output_stream_t *output_stream,
diff --git a/src/cairo-region-private.h b/src/cairo-region-private.h
index 7f92f9c..8fc6567 100644
--- a/src/cairo-region-private.h
+++ b/src/cairo-region-private.h
@@ -39,6 +39,8 @@
 
 #include <pixman.h>
 
+#include "cairo-compiler-private.h"
+
 /* cairo_region_t is defined in cairoint.h */
 
 struct _cairo_region {
diff --git a/src/cairo-wideint-private.h b/src/cairo-wideint-private.h
index 636d8a6..69fa156 100644
--- a/src/cairo-wideint-private.h
+++ b/src/cairo-wideint-private.h
@@ -74,6 +74,8 @@
 #error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.)
 #endif
 
+#include "cairo-compiler-private.h"
+
 /*
  * 64-bit datatypes.  Two separate implementations, one using
  * built-in 64-bit signed/unsigned types another implemented
diff --git a/src/cairo-xlib-private.h b/src/cairo-xlib-private.h
index 9b806ee..28ab1d3 100644
--- a/src/cairo-xlib-private.h
+++ b/src/cairo-xlib-private.h
@@ -34,9 +34,12 @@
 #define CAIRO_XLIB_PRIVATE_H
 
 #include "cairoint.h"
+
 #include "cairo-xlib.h"
-#include "cairo-xlib-xrender-private.h"
+
+#include "cairo-compiler-private.h"
 #include "cairo-freelist-private.h"
+#include "cairo-xlib-xrender-private.h"
 
 #include <X11/Xutil.h> /* for XDestroyImage */
 
diff --git a/src/cairoint.h b/src/cairoint.h
index 22eb165..695cb8f 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -66,6 +66,8 @@
 #include "cairo.h"
 #include <pixman.h>
 
+#include "cairo-compiler-private.h"
+
 #ifdef _MSC_VER
 #define snprintf _snprintf
 #undef inline
@@ -74,75 +76,6 @@
 
 CAIRO_BEGIN_DECLS
 
-#if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun)
-# define slim_hidden_proto(name)		slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private
-# define slim_hidden_proto_no_warn(name)	slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private_no_warn
-# define slim_hidden_def(name)			slim_hidden_def1(name, slim_hidden_int_name(name))
-# define slim_hidden_int_name(name) INT_##name
-# define slim_hidden_proto1(name, internal)				\
-  extern __typeof (name) name						\
-	__asm__ (slim_hidden_asmname (internal))
-# define slim_hidden_def1(name, internal)				\
-  extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name))	\
-	__attribute__((__alias__(slim_hidden_asmname(internal))))
-# define slim_hidden_ulp		slim_hidden_ulp1(__USER_LABEL_PREFIX__)
-# define slim_hidden_ulp1(x)		slim_hidden_ulp2(x)
-# define slim_hidden_ulp2(x)		#x
-# define slim_hidden_asmname(name)	slim_hidden_asmname1(name)
-# define slim_hidden_asmname1(name)	slim_hidden_ulp #name
-#else
-# define slim_hidden_proto(name)		int _cairo_dummy_prototype(void)
-# define slim_hidden_proto_no_warn(name)	int _cairo_dummy_prototype(void)
-# define slim_hidden_def(name)			int _cairo_dummy_prototype(void)
-#endif
-
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
-#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
-	__attribute__((__format__(__printf__, fmt_index, va_index)))
-#else
-#define CAIRO_PRINTF_FORMAT(fmt_index, va_index)
-#endif
-
-/* slim_internal.h */
-#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
-#define cairo_private_no_warn	__attribute__((__visibility__("hidden")))
-#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
-#define cairo_private_no_warn	__hidden
-#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
-#define cairo_private_no_warn
-#endif
-
-#ifndef WARN_UNUSED_RESULT
-#define WARN_UNUSED_RESULT
-#endif
-/* Add attribute(warn_unused_result) if supported */
-#define cairo_warn	    WARN_UNUSED_RESULT
-#define cairo_private	    cairo_private_no_warn cairo_warn
-
-/* This macro allow us to deprecate a function by providing an alias
-   for the old function name to the new function name. With this
-   macro, binary compatibility is preserved. The macro only works on
-   some platforms --- tough.
-
-   Meanwhile, new definitions in the public header file break the
-   source code so that it will no longer link against the old
-   symbols. Instead it will give a descriptive error message
-   indicating that the old function has been deprecated by the new
-   function.
-*/
-#if __GNUC__ >= 2 && defined(__ELF__)
-# define CAIRO_FUNCTION_ALIAS(old, new)		\
-	extern __typeof (new) old		\
-	__asm__ ("" #old)			\
-	__attribute__((__alias__("" #new)))
-#else
-# define CAIRO_FUNCTION_ALIAS(old, new)
-#endif
-
-#ifndef __GNUC__
-#define __attribute__(x)
-#endif
-
 #undef MIN
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 
-- 
1.4.4.2


--df+09Je9rNq3P+GE
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: attachment; filename="0002-cairo-atomic-Introduce-atomic-ops.txt"
Content-Transfer-Encoding: 8bit



More information about the cairo mailing list