[cairo] Making cairo_error weak

Behdad Esfahbod behdad at cs.toronto.edu
Tue Aug 2 12:43:05 PDT 2005


Hi,

Attached patch sets a mechanism for toolkits and applications to
override _cairo_error calls by defining cairo_error(status).

If applied, then we need a function to map status codes to
some meaningful strings.

We can also define a default cairo_status that prints out a
message, instead of aliasing it to _cairo_error that does sanity
checks.

--behdad
http://behdad.org/
-------------- next part --------------
Index: src/cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.177
diff -u -p -r1.177 cairoint.h
--- src/cairoint.h	1 Aug 2005 20:33:47 -0000	1.177
+++ src/cairoint.h	2 Aug 2005 19:38:57 -0000
@@ -109,14 +119,25 @@
 	extern __typeof (new) old		\
 	__asm__ ("" #old)			\
 	__attribute__((__alias__("" #new)))
+# define CAIRO_FUNCTION_WEAK_ALIAS(old, new)	\
+	extern __typeof (new) old		\
+	__asm__ ("" #old)			\
+	__attribute__((__weak__,__alias__("" #new)))
+# define CAIRO_HAS_WEAK_ALIAS 1
 #else
 # define CAIRO_FUNCTION_ALIAS(old, new)
+# define CAIRO_FUNCTION_WEAK_ALIAS(old, new)
 #endif
 
 #ifndef __GNUC__
 #define __attribute__(x)
 #endif
 
+#if CAIRO_HAS_WEAK_ALIAS
+  CAIRO_FUNCTION_WEAK_ALIAS(cairo_error, _cairo_error);
+# define _cairo_error(status) cairo_error(status)
+#endif
+
 /* XXX: There's a bad bug in the cache locking code that attempts to
  * recursively lock a mutex, (which we shouldn't actually need to ever
  * do). This leads to deadlocks in even single-threaded applications,
@@ -1952,9 +1973,6 @@ _cairo_output_stream_get_status (cairo_o
 cairo_output_stream_t *
 _cairo_output_stream_create_for_file (const char *filename);
 
-cairo_private void
-_cairo_error (cairo_status_t status);
-
 /* Avoid unnecessary PLT entries.  */
 
 slim_hidden_proto(cairo_get_current_point)
Index: src/Makefile.am
===================================================================
RCS file: /cvs/cairo/cairo/src/Makefile.am,v
retrieving revision 1.55
diff -u -p -r1.55 Makefile.am
--- src/Makefile.am	1 Aug 2005 20:33:47 -0000	1.55
+++ src/Makefile.am	2 Aug 2005 19:38:57 -0000
@@ -64,6 +64,7 @@ XRENDER_LIBS=@XRENDER_LIBS@
 cairoincludedir = $(includedir)/cairo
 cairoinclude_HEADERS =			\
 	cairo.h				\
+	cairo-debug.h			\
 	cairo-features.h		\
 	$(libcairo_atsui_headers)	\
 	$(libcairo_ft_headers)		\
Index: src/cairo-debug.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-debug.h,v
retrieving revision 1.1
diff -u -p -r1.1 cairo-debug.h
--- src/cairo-debug.h	1 Aug 2005 20:33:47 -0000	1.1
+++ src/cairo-debug.h	2 Aug 2005 19:38:57 -0000
@@ -43,6 +43,35 @@ CAIRO_BEGIN_DECLS
 void
 cairo_debug_reset_static_data (void);
 
+
+/**
+ * _cairo_error:
+ * @status: an error status
+ *
+ * This function should never be called, unless when overriding
+ * cairo_error, to chain into the default error handler, that
+ * basically only checks that @status is a valid error status.
+ */
+void
+_cairo_error (cairo_status_t status);
+
+/**
+ * cairo_error:
+ * @status: an error status
+ *
+ * This function should never be called.  Applications are allowed
+ * to define this function, to override the cairo error handler.
+ * All errors would pass the defined function once and only once
+ * then.  If to chain into the default error handler, that
+ * basically only checks that @status is a valid error status.
+ *
+ * On systems that do not support this mechanism, no errors will be
+ * passed to the application-defined cairo_error, but it is not
+ * an error to define such a function.
+ */
+void
+cairo_error (cairo_status_t status);
+
 CAIRO_END_DECLS
 
 #endif /* CAIRO_H */


More information about the cairo mailing list