[cairo-commit] 2 commits - acinclude.m4 boilerplate/cairo-boilerplate.h boilerplate/cairo-boilerplate-system.c boilerplate/cairo-boilerplate-system.h boilerplate/Makefile.am boilerplate/xmalloc.c boilerplate/xmalloc.h build/enable.ac build/system.ac src/cairo-atomic.c src/cairo-atomic-private.h src/cairo-mutex-list-private.h
Behdad Esfahbod
behdad at kemper.freedesktop.org
Thu Sep 4 13:08:48 PDT 2008
acinclude.m4 | 107 ++++++++++++++++--------
boilerplate/Makefile.am | 5 -
boilerplate/cairo-boilerplate-system.c | 147 +++++++++++++++++++++++++++++++++
boilerplate/cairo-boilerplate-system.h | 51 +++++++++++
boilerplate/cairo-boilerplate.h | 2
boilerplate/xmalloc.c | 147 ---------------------------------
boilerplate/xmalloc.h | 51 -----------
build/enable.ac | 11 +-
build/system.ac | 122 +++++++++++----------------
src/cairo-atomic-private.h | 13 +-
src/cairo-atomic.c | 2
src/cairo-mutex-list-private.h | 2
12 files changed, 341 insertions(+), 319 deletions(-)
New commits:
commit 44155f7e5941351b224b60644632b55448369e49
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Thu Sep 4 16:00:40 2008 -0400
Cleanup configure.in macros
diff --git a/acinclude.m4 b/acinclude.m4
index b4b1100..a2d0b30 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -124,18 +124,19 @@ dnl
AC_DEFUN([CAIRO_BIGENDIAN], [
case $host_os in
darwin*)
- AH_VERBATIM([X_BYTE_ORDER],[
- /* Deal with multiple architecture compiles on Mac OS X */
- #ifdef __APPLE_CC__
- #ifdef __BIG_ENDIAN__
- #define WORDS_BIGENDIAN 1
- #define FLOAT_WORDS_BIGENDIAN 1
- #else
- #undef WORDS_BIGENDIAN
- #undef FLOAT_WORDS_BIGENDIAN
- #endif
- #endif
- ])
+ AH_VERBATIM([X_BYTE_ORDER],
+[
+/* Deal with multiple architecture compiles on Mac OS X */
+#ifdef __APPLE_CC__
+#ifdef __BIG_ENDIAN__
+#define WORDS_BIGENDIAN 1
+#define FLOAT_WORDS_BIGENDIAN 1
+#else
+#undef WORDS_BIGENDIAN
+#undef FLOAT_WORDS_BIGENDIAN
+#endif
+#endif
+])
;;
*)
AC_C_BIGENDIAN
@@ -150,13 +151,13 @@ dnl Like AC_CHECK_FUNCS but with additional CFLAGS and LIBS
dnl --------------------------------------------------------------------
AC_DEFUN([CAIRO_CHECK_FUNCS_WITH_FLAGS],
[
- _save_cflags="$CFLAGS"
- _save_libs="$LIBS"
- CFLAGS="$CFLAGS $2"
- LIBS="$LIBS $3"
- AC_CHECK_FUNCS($1, $4, $5)
- CFLAGS="$_save_cflags"
- LIBS="$_save_libs"
+ _save_cflags="$CFLAGS"
+ _save_libs="$LIBS"
+ CFLAGS="$CFLAGS $2"
+ LIBS="$LIBS $3"
+ AC_CHECK_FUNCS($1, $4, $5)
+ CFLAGS="$_save_cflags"
+ LIBS="$_save_libs"
])
dnl CAIRO_CONFIG_COMMANDS is like AC_CONFIG_COMMANDS, except that:
@@ -164,7 +165,8 @@ dnl
dnl 1) It redirects the stdout of the command to the file.
dnl 2) It does not recreate the file if contents didn't change.
dnl
-AC_DEFUN([CAIRO_CONFIG_COMMANDS], [
+AC_DEFUN([CAIRO_CONFIG_COMMANDS],
+[
AC_CONFIG_COMMANDS($1,
[
_config_file=$1
@@ -172,7 +174,9 @@ AC_DEFUN([CAIRO_CONFIG_COMMANDS], [
AC_MSG_NOTICE([creating $_config_file])
{
$2
- } >> "$_tmp_file"
+ } >> "$_tmp_file" ||
+ AC_MSG_ERROR([failed to write to $_tmp_file])
+
if cmp -s "$_tmp_file" "$_config_file"; then
AC_MSG_NOTICE([$_config_file is unchanged])
rm -f "$_tmp_file"
@@ -184,21 +188,58 @@ AC_DEFUN([CAIRO_CONFIG_COMMANDS], [
])
dnl check compiler flags
-AC_DEFUN([CAIRO_CC_TRY_FLAG], [
- AC_MSG_CHECKING([whether $CC supports $1])
+AC_DEFUN([CAIRO_CC_TRY_FLAG],
+[
+ AC_MSG_CHECKING([whether $CC supports $1])
+
+ _save_cflags="$CFLAGS"
+ CFLAGS="$CFLAGS -Werror $1"
+ AC_COMPILE_IFELSE([ ], [cairo_cc_flag=yes], [cairo_cc_flag=no])
+ CFLAGS="$_save_cflags"
+
+ if test "x$cairo_cc_flag" = "xyes"; then
+ ifelse([$2], , :, [$2])
+ else
+ ifelse([$3], , :, [$3])
+ fi
+ AC_MSG_RESULT([$cairo_cc_flag])
+])
- _save_cflags="$CFLAGS"
- CFLAGS="$CFLAGS -Werror $1"
+dnl Usage:
+dnl CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES
+AC_DEFUN([CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES],
+[
+ AC_CACHE_CHECK([for native atomic primitives], cairo_cv_atomic_primitives,
+ [
+ cairo_cv_atomic_primitives="none"
- AC_COMPILE_IFELSE([ ], [cairo_cc_flag=yes], [cairo_cc_flag=no])
- CFLAGS="$_save_cflags"
+ AC_TRY_LINK([int atomic_add(int i) { return __sync_fetch_and_add (&i, 1); }], [],
+ cairo_cv_atomic_primitives="Intel"
+ )
+ ])
+ if test "x$cairo_cv_atomic_primitives" = xIntel; then
+ AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1,
+ [Enable if your compiler supports the Intel __sync_* atomic primitives])
+ fi
+])
- if test "x$cairo_cc_flag" = "xyes"; then
- ifelse([$2], , :, [$2])
- else
- ifelse([$3], , :, [$3])
- fi
- AC_MSG_RESULT([$cairo_cc_flag])
+dnl Usage:
+dnl CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER
+AC_DEFUN([CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER],
+[
+ AC_CACHE_CHECK([whether atomic ops require a memory barrier], cairo_cv_atomic_op_needs_memory_barrier,
+ [
+ case $host_cpu in
+ i?86) cairo_cv_atomic_op_needs_memory_barrier="no" ;;
+ x86_64) cairo_cv_atomic_op_needs_memory_barrier="no" ;;
+ arm*) cairo_cv_atomic_op_needs_memory_barrier="no" ;;
+ *) cairo_cv_atomic_op_needs_memory_barrier="yes" ;;
+ esac
+ ])
+ if test "x$cairo_cv_atomic_op_needs_memory_barrier" = "xyes"; then
+ AC_DEFINE_UNQUOTED(ATOMIC_OP_NEEDS_MEMORY_BARRIER, 1,
+ [whether memory barriers are needed around atomic operations])
+ fi
])
dnl Parse Version.mk and declare m4 variables out of it
diff --git a/build/enable.ac b/build/enable.ac
index 3ef37cf..c390e7b 100644
--- a/build/enable.ac
+++ b/build/enable.ac
@@ -1,5 +1,9 @@
-AC_CHECK_LIBM
-LIBS="$LIBS $LIBM"
+dnl
+dnl These are the facilities for enable/disabling various backends/features,
+dnl and for collecting CFLAGS/LIBS and generating per backend/feature .pc
+dnl files, assembling list of source files to compile, and creating
+dnl cairo-features.h and other generated files.
+dnl
dnl ===========================================================================
dnl
@@ -189,7 +193,7 @@ CAIRO_NO_FEATURES=""
CAIRO_SUPPORTED_FEATURES=""
CAIRO_REQUIRES=""
CAIRO_NONPKGCONFIG_CFLAGS=""
-CAIRO_NONPKGCONFIG_LIBS="$LIBM"
+CAIRO_NONPKGCONFIG_LIBS="$LIBS"
CAIRO_LDADD=""
CAIRO_CFLAGS=$CAIRO_NONPKGCONFIG_CFLAGS
CAIRO_LIBS=$CAIRO_NONPKGCONFIG_LIBS
@@ -218,7 +222,6 @@ AC_SUBST(CAIRO_NONPKGCONFIG_LIBS)
AC_SUBST(CAIRO_CFLAGS)
AC_SUBST(CAIRO_LDADD)
AC_SUBST(CAIRO_LIBS)
-AC_SUBST(CAIROPERF_LIBS)
CAIRO_CONFIG_COMMANDS([$srcdir/src/Config.mk],
[echo "$CAIRO_CONFIG_AMAKE"],
diff --git a/build/system.ac b/build/system.ac
index 8263299..2102627 100644
--- a/build/system.ac
+++ b/build/system.ac
@@ -1,38 +1,27 @@
dnl
-dnl Check for functions, headers, libraries, etc go here
+dnl Non-failing checks for functions, headers, libraries, etc go here
dnl
-AM_CONDITIONAL(CROSS_COMPILING, test "x$cross_compiling" = "xyes")
+dnl ====================================================================
+dnl Feature checks
+dnl ====================================================================
+AM_CONDITIONAL(CROSS_COMPILING, test "x$cross_compiling" = "xyes")
CAIRO_BIGENDIAN
+CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES
+CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER
-AC_STDC_HEADERS
-
-dnl Checks for precise integer types
-AC_CHECK_HEADERS([stdint.h signal.h setjmp.h inttypes.h sys/int_types.h])
-AC_CHECK_TYPES([uint64_t, uint128_t])
-
-dnl Check for socket support for any2ppm daemon
-AC_CHECK_HEADERS([fcntl.h unistd.h signal.h sys/stat.h sys/socket.h sys/poll.h sys/un.h])
-
-dnl Checks for misc headers
-AC_CHECK_HEADERS([libgen.h byteswap.h])
-
-dnl check for CPU affinity support
-AC_CHECK_HEADERS([sched.h], [
- AC_CHECK_FUNCS([sched_getaffinity], [
- AC_DEFINE([HAVE_SCHED_GETAFFINITY], [1],
- [Define to 1 if you have Linux compatible sched_getaffinity])
- ])
-])
-
-AC_CHECK_FUNCS(vasnprintf link ctime_r drand48 flockfile)
-
-AC_CHECK_LIB(rt, sched_yield, [RT_LIBS=-lrt], [RT_LIBS=])
-CAIROPERF_LIBS=$RT_LIBS
-
-# check for GNU-extensions to fenv
-AC_CHECK_HEADER(fenv.h, [AC_CHECK_FUNCS(feenableexcept fedisableexcept)])
+AC_MSG_CHECKING([for native Win32])
+case "$host" in
+ *-*-mingw*)
+ cairo_os_win32=yes
+ ;;
+ *)
+ cairo_os_win32=no
+ ;;
+esac
+AC_MSG_RESULT([$cairo_os_win32])
+AM_CONDITIONAL(OS_WIN32, test "$cairo_os_win32" = "yes")
AC_MSG_CHECKING([for Sun Solaris (non-POSIX ctime_r)])
case "$host" in
@@ -46,53 +35,40 @@ case "$host" in
esac
AC_MSG_RESULT([$solaris_posix_pthread])
-dnl ===========================================================================
-dnl
-dnl Test for native atomic operations.
-dnl
-AC_CACHE_CHECK([for native atomic primitives], cairo_cv_atomic_primitives, [
-cairo_cv_atomic_primitives="none"
+dnl ====================================================================
+dnl Library checks
+dnl ====================================================================
-AC_TRY_LINK([int atomic_add(int i) { return __sync_fetch_and_add (&i, 1); }], [],
- cairo_cv_atomic_primitives="Intel"
- )
-])
-if test "x$cairo_cv_atomic_primitives" = xIntel; then
- AC_DEFINE(CAIRO_HAS_INTEL_ATOMIC_PRIMITIVES, 1, [Enable if your compiler supports the Intel __sync_* atomic primitives])
-fi
+AC_CHECK_LIBM
+LIBS="$LIBS $LIBM"
-AC_CACHE_CHECK([whether atomic ops require a memory barrier], cairo_cv_atomic_op_needs_memory_barrier, [
-case $host_cpu in
- i?86)
- cairo_cv_atomic_op_needs_memory_barrier="no"
- ;;
- x86_64)
- cairo_cv_atomic_op_needs_memory_barrier="no"
- ;;
- arm*)
- cairo_cv_atomic_op_needs_memory_barrier="no"
- ;;
- *)
- cairo_cv_atomic_op_needs_memory_barrier="yes"
- ;;
-esac
-])
-if test "x$cairo_cv_atomic_op_needs_memory_barrier" = "xyes"; then
- AC_DEFINE_UNQUOTED(CAIRO_ATOMIC_OP_NEEDS_MEMORY_BARRIER, 1,
- [whether Cairo needs memory barriers around atomic ops])
-fi
+AC_CHECK_LIB(rt, sched_yield, [RT_LIBS=-lrt], [RT_LIBS=])
+CAIROPERF_LIBS=$RT_LIBS
+AC_SUBST(CAIROPERF_LIBS)
-AC_MSG_CHECKING([for native Win32])
-case "$host" in
- *-*-mingw*)
- cairo_os_win32=yes
- ;;
- *)
- cairo_os_win32=no
- ;;
-esac
-AC_MSG_RESULT([$cairo_os_win32])
-AM_CONDITIONAL(OS_WIN32, test "$cairo_os_win32" = "yes")
+dnl ====================================================================
+dnl Header/function checks
+dnl ====================================================================
+
+dnl Checks for precise integer types
+AC_CHECK_HEADERS([stdint.h inttypes.h sys/int_types.h])
+AC_CHECK_TYPES([uint64_t, uint128_t])
+
+dnl Check for socket support for any2ppm daemon
+AC_CHECK_HEADERS([fcntl.h unistd.h signal.h sys/stat.h sys/socket.h sys/poll.h sys/un.h])
+
+dnl check for CPU affinity support
+AC_CHECK_HEADERS([sched.h],
+ [AC_CHECK_FUNCS([sched_getaffinity])])
+
+dnl check for GNU-extensions to fenv
+AC_CHECK_HEADER(fenv.h,
+ [AC_CHECK_FUNCS(feenableexcept fedisableexcept)])
+
+dnl check for misc headers and functions
+AC_CHECK_HEADERS([libgen.h byteswap.h signal.h setjmp.h])
+AC_CHECK_FUNCS([vasnprintf link ctime_r drand48 flockfile])
+dnl check for win32 headers (this detects mingw as well)
AC_CHECK_HEADERS([windows.h], have_windows=yes, have_windows=no)
diff --git a/src/cairo-atomic-private.h b/src/cairo-atomic-private.h
index 85fe956..56ae7d2 100644
--- a/src/cairo-atomic-private.h
+++ b/src/cairo-atomic-private.h
@@ -41,11 +41,13 @@
#include "config.h"
#endif
+# include "cairo-compiler-private.h"
+
CAIRO_BEGIN_DECLS
-#define CAIRO_HAS_ATOMIC_OPS 1
+#if HAVE_INTEL_ATOMIC_PRIMITIVES
-#if CAIRO_HAS_INTEL_ATOMIC_PRIMITIVES
+#define CAIRO_HAS_ATOMIC_OPS 1
typedef int cairo_atomic_int_t;
@@ -53,11 +55,10 @@ typedef int cairo_atomic_int_t;
# define _cairo_atomic_int_dec_and_test(x) (__sync_fetch_and_add(x, -1) == 1)
# define _cairo_atomic_int_cmpxchg(x, oldv, newv) __sync_val_compare_and_swap (x, oldv, newv)
-#else
+#endif
-# include "cairo-compiler-private.h"
-# undef CAIRO_HAS_ATOMIC_OPS
+#ifndef CAIRO_HAS_ATOMIC_OPS
typedef int cairo_atomic_int_t;
@@ -73,7 +74,7 @@ _cairo_atomic_int_cmpxchg (int *x, int oldv, int newv);
#endif
-#ifdef CAIRO_ATOMIC_OP_NEEDS_MEMORY_BARRIER
+#ifdef ATOMIC_OP_NEEDS_MEMORY_BARRIER
# include "cairo-compiler-private.h"
diff --git a/src/cairo-atomic.c b/src/cairo-atomic.c
index 9e388ac..9fe53e6 100644
--- a/src/cairo-atomic.c
+++ b/src/cairo-atomic.c
@@ -73,7 +73,7 @@ _cairo_atomic_int_cmpxchg (int *x, int oldv, int newv)
#endif
-#ifdef CAIRO_ATOMIC_OP_NEEDS_MEMORY_BARRIER
+#ifdef ATOMIC_OP_NEEDS_MEMORY_BARRIER
int
_cairo_atomic_int_get (int *x)
{
diff --git a/src/cairo-mutex-list-private.h b/src/cairo-mutex-list-private.h
index 1fe5bd5..5393790 100644
--- a/src/cairo-mutex-list-private.h
+++ b/src/cairo-mutex-list-private.h
@@ -47,7 +47,7 @@ CAIRO_MUTEX_DECLARE (_cairo_ft_unscaled_font_map_mutex);
CAIRO_MUTEX_DECLARE (_cairo_xlib_display_mutex);
#endif
-#if !defined (CAIRO_HAS_ATOMIC_OPS) || defined (CAIRO_ATOMIC_OP_NEEDS_MEMORY_BARRIER)
+#if !defined (CAIRO_HAS_ATOMIC_OPS) || defined (ATOMIC_OP_NEEDS_MEMORY_BARRIER)
CAIRO_MUTEX_DECLARE (_cairo_atomic_mutex);
#endif
commit 0e01534bf0bd64af840ccfa8aeaa1ac1a7cb31b7
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Thu Sep 4 09:13:49 2008 -0400
[boilerplate] Rename xmalloc.[ch] to boilerplate namespace
diff --git a/boilerplate/Makefile.am b/boilerplate/Makefile.am
index 9733b5b..b47b061 100644
--- a/boilerplate/Makefile.am
+++ b/boilerplate/Makefile.am
@@ -8,8 +8,9 @@ libcairoboilerplate_la_SOURCES = \
cairo-boilerplate-getopt.c \
cairo-boilerplate-getopt.h \
cairo-boilerplate-scaled-font.h \
- xmalloc.c \
- xmalloc.h
+ cairo-boilerplate-system.c \
+ cairo-boilerplate-system.h \
+ $(NULL)
libcairoboilerplate_la_LIBADD = $(top_builddir)/src/libcairo.la $(CAIRO_LDADD)
if CAIRO_HAS_BEOS_SURFACE
diff --git a/boilerplate/cairo-boilerplate-system.c b/boilerplate/cairo-boilerplate-system.c
new file mode 100644
index 0000000..af07681
--- /dev/null
+++ b/boilerplate/cairo-boilerplate-system.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright © 2004 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ */
+
+#define _GNU_SOURCE 1 /* for vasprintf */
+
+#include "cairo-boilerplate.h"
+#include "cairo-boilerplate-system.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <errno.h>
+
+void *
+xmalloc (size_t size)
+{
+ void *buf;
+
+ if (size == 0)
+ return NULL;
+
+ buf = malloc (size);
+ if (buf == NULL) {
+ CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting.\n");
+ exit (1);
+ }
+
+ return buf;
+}
+
+void *
+xcalloc (size_t nmemb, size_t size)
+{
+ void *buf;
+
+ if (nmemb == 0 || size == 0)
+ return NULL;
+
+ buf = calloc (nmemb, size);
+ if (buf == NULL) {
+ CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting\n");
+ exit (1);
+ }
+
+ return buf;
+}
+
+void *
+xrealloc (void *buf, size_t size)
+{
+ buf = realloc (buf, size);
+ if (buf == NULL && size != 0) {
+ CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting\n");
+ exit (1);
+ }
+
+ return buf;
+}
+
+void
+xasprintf (char **strp, const char *fmt, ...)
+{
+#ifdef HAVE_VASPRINTF
+ va_list va;
+ int ret;
+
+ va_start (va, fmt);
+ ret = vasprintf (strp, fmt, va);
+ va_end (va);
+
+ if (ret < 0) {
+ CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting.\n");
+ exit (1);
+ }
+#else /* !HAVE_VASNPRINTF */
+#define BUF_SIZE 1024
+ va_list va;
+ char buffer[BUF_SIZE];
+ int ret, len;
+
+ va_start (va, fmt);
+ ret = vsnprintf (buffer, sizeof (buffer), fmt, va);
+ va_end (va);
+
+ if (ret < 0) {
+ CAIRO_BOILERPLATE_LOG ("Failure in vsnprintf\n");
+ exit (1);
+ }
+
+ len = (ret + sizeof (int)) & -sizeof (int);
+ *strp = malloc (len);
+ if (*strp == NULL) {
+ CAIRO_BOILERPLATE_LOG ("Out of memory\n");
+ exit (1);
+ }
+
+ if ((unsigned) ret < sizeof (buffer)) {
+ memcpy (*strp, buffer, ret);
+ } else {
+ va_start (va, fmt);
+ ret = vsnprintf (*strp, len, fmt, va);
+ va_end (va);
+
+ if (ret >= len) {
+ free (*strp);
+ CAIRO_BOILERPLATE_LOG ("Overflowed dynamic buffer\n");
+ exit (1);
+ }
+ }
+ memset (*strp + ret, 0, len-ret);
+#endif /* !HAVE_VASNPRINTF */
+}
+
+void
+xunlink (const char *pathname)
+{
+ if (unlink (pathname) < 0 && errno != ENOENT) {
+ CAIRO_BOILERPLATE_LOG ("Error: Cannot remove %s: %s\n",
+ pathname, strerror (errno));
+ exit (1);
+ }
+}
diff --git a/boilerplate/cairo-boilerplate-system.h b/boilerplate/cairo-boilerplate-system.h
new file mode 100644
index 0000000..51273a7
--- /dev/null
+++ b/boilerplate/cairo-boilerplate-system.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2004 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ */
+
+#ifndef _XMALLOC_H_
+#define _XMALLOC_H_
+
+#include "cairo-boilerplate.h"
+
+#define xmalloc cairo_boilerplate_xmalloc
+void *
+xmalloc (size_t size);
+
+#define xcalloc cairo_boilerplate_xcalloc
+void *
+xcalloc (size_t nmemb, size_t size);
+
+#define xrealloc cairo_boilerplate_xrealloc
+void *
+xrealloc (void *buf, size_t size);
+
+#define xasprintf cairo_boilerplate_xasprintf
+void
+xasprintf (char **strp, const char *fmt, ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(2, 3);
+
+#define xunlink cairo_boilerplate_xunlink
+void
+xunlink (const char *path);
+
+#endif
diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h
index d2fa470..b5c7295 100644
--- a/boilerplate/cairo-boilerplate.h
+++ b/boilerplate/cairo-boilerplate.h
@@ -187,6 +187,6 @@ cairo_boilerplate_version (void);
const char*
cairo_boilerplate_version_string (void);
-#include "xmalloc.h"
+#include "cairo-boilerplate-system.h"
#endif
diff --git a/boilerplate/xmalloc.c b/boilerplate/xmalloc.c
deleted file mode 100644
index 12f12e9..0000000
--- a/boilerplate/xmalloc.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright © 2004 Red Hat, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software
- * and its documentation for any purpose is hereby granted without
- * fee, provided that the above copyright notice appear in all copies
- * and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of
- * Red Hat, Inc. not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. Red Hat, Inc. makes no representations about the
- * suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
- * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Carl D. Worth <cworth at cworth.org>
- */
-
-#define _GNU_SOURCE 1 /* for vasprintf */
-
-#include "cairo-boilerplate.h"
-#include "xmalloc.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <errno.h>
-
-void *
-xmalloc (size_t size)
-{
- void *buf;
-
- if (size == 0)
- return NULL;
-
- buf = malloc (size);
- if (buf == NULL) {
- CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting.\n");
- exit (1);
- }
-
- return buf;
-}
-
-void *
-xcalloc (size_t nmemb, size_t size)
-{
- void *buf;
-
- if (nmemb == 0 || size == 0)
- return NULL;
-
- buf = calloc (nmemb, size);
- if (buf == NULL) {
- CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting\n");
- exit (1);
- }
-
- return buf;
-}
-
-void *
-xrealloc (void *buf, size_t size)
-{
- buf = realloc (buf, size);
- if (buf == NULL && size != 0) {
- CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting\n");
- exit (1);
- }
-
- return buf;
-}
-
-void
-xasprintf (char **strp, const char *fmt, ...)
-{
-#ifdef HAVE_VASPRINTF
- va_list va;
- int ret;
-
- va_start (va, fmt);
- ret = vasprintf (strp, fmt, va);
- va_end (va);
-
- if (ret < 0) {
- CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting.\n");
- exit (1);
- }
-#else /* !HAVE_VASNPRINTF */
-#define BUF_SIZE 1024
- va_list va;
- char buffer[BUF_SIZE];
- int ret, len;
-
- va_start (va, fmt);
- ret = vsnprintf (buffer, sizeof (buffer), fmt, va);
- va_end (va);
-
- if (ret < 0) {
- CAIRO_BOILERPLATE_LOG ("Failure in vsnprintf\n");
- exit (1);
- }
-
- len = (ret + sizeof (int)) & -sizeof (int);
- *strp = malloc (len);
- if (*strp == NULL) {
- CAIRO_BOILERPLATE_LOG ("Out of memory\n");
- exit (1);
- }
-
- if ((unsigned) ret < sizeof (buffer)) {
- memcpy (*strp, buffer, ret);
- } else {
- va_start (va, fmt);
- ret = vsnprintf (*strp, len, fmt, va);
- va_end (va);
-
- if (ret >= len) {
- free (*strp);
- CAIRO_BOILERPLATE_LOG ("Overflowed dynamic buffer\n");
- exit (1);
- }
- }
- memset (*strp + ret, 0, len-ret);
-#endif /* !HAVE_VASNPRINTF */
-}
-
-void
-xunlink (const char *pathname)
-{
- if (unlink (pathname) < 0 && errno != ENOENT) {
- CAIRO_BOILERPLATE_LOG ("Error: Cannot remove %s: %s\n",
- pathname, strerror (errno));
- exit (1);
- }
-}
diff --git a/boilerplate/xmalloc.h b/boilerplate/xmalloc.h
deleted file mode 100644
index 51273a7..0000000
--- a/boilerplate/xmalloc.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright © 2004 Red Hat, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software
- * and its documentation for any purpose is hereby granted without
- * fee, provided that the above copyright notice appear in all copies
- * and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of
- * Red Hat, Inc. not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. Red Hat, Inc. makes no representations about the
- * suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
- * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Carl D. Worth <cworth at cworth.org>
- */
-
-#ifndef _XMALLOC_H_
-#define _XMALLOC_H_
-
-#include "cairo-boilerplate.h"
-
-#define xmalloc cairo_boilerplate_xmalloc
-void *
-xmalloc (size_t size);
-
-#define xcalloc cairo_boilerplate_xcalloc
-void *
-xcalloc (size_t nmemb, size_t size);
-
-#define xrealloc cairo_boilerplate_xrealloc
-void *
-xrealloc (void *buf, size_t size);
-
-#define xasprintf cairo_boilerplate_xasprintf
-void
-xasprintf (char **strp, const char *fmt, ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(2, 3);
-
-#define xunlink cairo_boilerplate_xunlink
-void
-xunlink (const char *path);
-
-#endif
More information about the cairo-commit
mailing list