summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2012-07-12 11:11:16 +0200
committerAndrea Canciani <ranma42@gmail.com>2012-07-12 11:11:16 +0200
commitcb54ab6d99df120c5c78c6f106661fb99b19e938 (patch)
tree26a24aabe1f96dc6da63e0509d8e1b352dd71385
parent0da5c7387320e2e1a922a5777a02de41c959c509 (diff)
-rwxr-xr-xbuild_cairo.sh19
-rwxr-xr-xbuild_pixman.sh15
-rwxr-xr-xbuild_xserver.sh9
-rw-r--r--cocci.spatches/#0012-new-error.cocci#12
-rw-r--r--cocci.spatches/0011-pyerror.cocci73
-rw-r--r--cocci.spatches/0012-new-error.cocci20
-rw-r--r--cocci.spatches/1001-cairo_status.cocci66
-rw-r--r--cocci.spatches/1002-cairo_surface_status.cocci151
-rw-r--r--cocci.spatches/1003-cairo_scaled_font_status.cocci72
-rw-r--r--cocci.spatches/1004-cairo_region_status.cocci66
-rw-r--r--cocci.spatches/1005-cairo_pattern_status.cocci72
-rw-r--r--cocci.spatches/1006-cairo_font_face_status.cocci90
-rw-r--r--cocci.spatches/1007-cairo_device_status.cocci72
-rw-r--r--cocci.spatches/2001-user-data.cocci64
-rw-r--r--cocci.spatches/2002-is-static.cocci66
-rw-r--r--cocci.spatches/cairo-cocci-builtin.h15
-rw-r--r--cocci.spatches/cairo_find.cocci8
-rw-r--r--cocci.spatches/cleanup-array-lenght.cocci11
-rw-r--r--cocci.spatches/cleanup-free-NULL.cocci26
-rw-r--r--cocci.spatches/cleanup-whitespace.sed53
-rwxr-xr-xcocci.spatches/coccinelle-commit.sh10
-rw-r--r--cocci.spatches/dis0005-unlikely.cocci13
-rw-r--r--cocci.spatches/dis0015-unlikely-error.cocci18
-rw-r--r--cocci.spatches/malloc-coding-style.cocci27
-rw-r--r--cocci.spatches/show-whitespace.sed3
-rw-r--r--cocci.spatches/test-pyerr.cocci5
26 files changed, 1056 insertions, 0 deletions
diff --git a/build_cairo.sh b/build_cairo.sh
new file mode 100755
index 0000000..954f3fc
--- /dev/null
+++ b/build_cairo.sh
@@ -0,0 +1,19 @@
+#!/bin/sh -e
+
+BASEDIR="/home/ranma42/Code/fdo"
+SRCDIR="$BASEDIR/cairo"
+PREFIXDIR="$BASEDIR/build/cairo"
+
+cd "$SRCDIR"
+BUILDDIR="$BASEDIR/build/cairo-`git rev-parse --verify HEAD`"
+
+mkdir -p "$BUILDDIR"
+ln -sf "$BUILDDIR" "$PREFIXDIR"
+PKG_CONFIG_PATH="$BASEDIR/build/pixman/lib/pkgconfig/" ./autogen.sh --prefix="$PREFIXDIR" --enable-gtk-doc \
+ --disable-sphinx \
+ --enable-xml --enable-tee --enable-gl
+# --enable-vg \
+# --enable-qt --enable-directfb \
+
+make -j4
+make install
diff --git a/build_pixman.sh b/build_pixman.sh
new file mode 100755
index 0000000..33b156e
--- /dev/null
+++ b/build_pixman.sh
@@ -0,0 +1,15 @@
+#!/bin/sh -e
+
+BASEDIR="/home/ranma42/Code/fdo"
+SRCDIR="$BASEDIR/pixman"
+PREFIXDIR="$BASEDIR/build/pixman"
+
+cd "$SRCDIR"
+BUILDDIR="$BASEDIR/build/pixman-`git rev-parse --verify HEAD`"
+
+mkdir -p "$BUILDDIR"
+ln -sf "$BUILDDIR" "$PREFIXDIR"
+./autogen.sh --prefix="$PREFIXDIR"
+make -j4
+make check
+make install
diff --git a/build_xserver.sh b/build_xserver.sh
new file mode 100755
index 0000000..a8cbae8
--- /dev/null
+++ b/build_xserver.sh
@@ -0,0 +1,9 @@
+#!/bin/sh -e
+
+export PKG_CONFIG_PATH=/opt/xorg/lib/pkgconfig:${PKG_CONFIG_PATH}
+export LD_LIBRARY_PATH=/opt/xorg/lib:${LD_LIBRARY_PATH}
+export LD_RUN_PATH=/opt/xorg/lib:${LD_RUN_PATH}
+
+cd xserver
+./autogen.sh --prefix=/opt/xorg --disable-xorg --disable-dmx --enable-xvfb --disable-xnest --disable-xwin --disable-xprint --disable-xorgcfg
+
diff --git a/cocci.spatches/#0012-new-error.cocci# b/cocci.spatches/#0012-new-error.cocci#
new file mode 100644
index 0000000..e219d44
--- /dev/null
+++ b/cocci.spatches/#0012-new-error.cocci#
@@ -0,0 +1,12 @@
+// Clean up _cairo_error()
+//
+// _cairo_error() should be invoked whenever an error status would be
+// set on a public object. It should be invoked only once for each
+// such event and it should not be invoked upon error creation
+
+@@
+expression status;
+@@
+- _cairo_error (
+ status
+- )
diff --git a/cocci.spatches/0011-pyerror.cocci b/cocci.spatches/0011-pyerror.cocci
new file mode 100644
index 0000000..9a41bc5
--- /dev/null
+++ b/cocci.spatches/0011-pyerror.cocci
@@ -0,0 +1,73 @@
+// Make sure that new error statuses are introduced with CAIRO_ERROR_
+
+@s@
+identifier status ~= "^CAIRO_STATUS_(?!SUCCESS).*$";
+@@
+status
+
+@err1fun@
+identifier fun ~= "^_cairo(.*_create_in_error|_error_throw)$";
+@@
+fun
+
+@err2fun@
+identifier fun ~= "^_cairo.*_set_error$";
+@@
+fun
+
+@script:python err@
+status << s.status;
+errid;
+@@
+coccinelle.errid = "CAIRO_ERROR" + str(status)[len("CAIRO_STATUS"):]
+
+@@
+identifier s.status;
+identifier err.errid;
+@@
+- _cairo_error (status)
++ errid
+
+@@
+expression E;
+@@
+- _cairo_error (
+ E
+- )
+
+@@
+identifier s.status;
+identifier err.errid;
+@@
+ return
+- status
++ errid
+ ;
+
+@@
+identifier err1fun.fun;
+identifier s.status;
+identifier err.errid;
+@@
+ fun
+ (
+- status
++ errid
+ )
+
+@@
+identifier err2fun.fun;
+identifier s.status;
+identifier err.errid;
+expression obj;
+@@
+ fun
+ (obj,
+- status
++ errid
+ )
+
+@@
+expression E;
+@@
+- _cairo_device_create_in_error(E) \ No newline at end of file
diff --git a/cocci.spatches/0012-new-error.cocci b/cocci.spatches/0012-new-error.cocci
new file mode 100644
index 0000000..add7e95
--- /dev/null
+++ b/cocci.spatches/0012-new-error.cocci
@@ -0,0 +1,20 @@
+// Clean up _cairo_error()
+//
+// _cairo_error() should be invoked whenever an error status would be
+// set on a public object. It should be invoked only once for each
+// such event and it should not be invoked upon error creation
+
+@@
+expression status;
+@@
+- _cairo_error (
+ status
+- )
+
+@@
+expression obj, status;
+@@
+ _cairo_status_set_error (obj,
+- status
++ _cairo_error (status)
+ )
diff --git a/cocci.spatches/1001-cairo_status.cocci b/cocci.spatches/1001-cairo_status.cocci
new file mode 100644
index 0000000..e941f1c
--- /dev/null
+++ b/cocci.spatches/1001-cairo_status.cocci
@@ -0,0 +1,66 @@
+// cairo: Do not access the status member directly
+//
+// The only exceptions are the functions which initialize the status
+// or set it to an error.
+
+@disable fld_to_ptr@
+cairo_t *cr;
+@@
+(
+- (cr)->status
++ _cairo_status (cr)
+|
+- cairo_cairo_status
++ _cairo_status
+ (
+ cr
+ )
+)
+
+@disable fld_to_ptr@
+cairo_t cr;
+@@
+- cr.status
++ _cairo_status (&cr)
+
+@@
+cairo_t *cr;
+expression E;
+@@
+(
+- _cairo_status (cr)
++ cr->status
+ = E
+|
+ _cairo_status_set_error (
+-&_cairo_status (cr),
++&cr->status,
+ E)
+)
+
+@disable fld_to_ptr@
+cairo_t *cr;
+statement S1, S2;
+@@
+ if (
+-unlikely (_cairo_status (cr))
++unlikely (_cairo_status (cr))
+ )
+ S1
+ else
+ S2
+
+
+@cairo_status@
+expression cr;
+@@
+_cairo_status (cr)
+
+@already_include@
+@@
+#include "cairo-private.h"
+
+@ins_include depends on cairo_status && !already_include@
+@@
+#include "cairoint.h"
++#include "cairo-private.h"
diff --git a/cocci.spatches/1002-cairo_surface_status.cocci b/cocci.spatches/1002-cairo_surface_status.cocci
new file mode 100644
index 0000000..b5451bf
--- /dev/null
+++ b/cocci.spatches/1002-cairo_surface_status.cocci
@@ -0,0 +1,151 @@
+// surface: Do not access the status member directly
+//
+// The only exceptions are the functions which initialize the status
+// or set it to an error.
+
+@disable fld_to_ptr@
+cairo_image_surface_t *image;
+@@
+- image->base.status
++ _cairo_surface_status (&image->base)
+
+@disable fld_to_ptr@
+cairo_pdf_surface_t *pdf;
+@@
+- pdf->base.status
++ _cairo_surface_status (&pdf->base)
+
+@disable fld_to_ptr@
+cairo_script_surface_t *script;
+@@
+- script->base.status
++ _cairo_surface_status (&script->base)
+
+@disable fld_to_ptr@
+cairo_xcb_picture_t *picture;
+@@
+- picture->base.status
++ _cairo_surface_status (&picture->base)
+
+@disable fld_to_ptr@
+cairo_xcb_surface_t *xcb;
+@@
+- xcb->base.status
++ _cairo_surface_status (&xcb->base)
+
+@disable fld_to_ptr@
+cairo_xlib_surface_t *xlib;
+@@
+- xlib->base.status
++ _cairo_surface_status (&xlib->base)
+
+@disable fld_to_ptr@
+cairo_vg_surface_t *vg;
+@@
+- vg->base.status
++ _cairo_surface_status (&vg->base)
+
+@disable fld_to_ptr@
+i915_surface_t *i915;
+@@
+- i915->intel.drm.base.status
++ _cairo_surface_status (&i915->intel.drm.base)
+
+@disable fld_to_ptr@
+i965_surface_t *i965;
+@@
+- i965->intel.drm.base.status
++ _cairo_surface_status (&i915->intel.drm.base)
+
+@disable fld_to_ptr@
+cairo_surface_snapshot_t *snapshot;
+@@
+- snapshot->clone->status
++ _cairo_surface_status (snapshot->clone)
+
+@disable fld_to_ptr@
+cairo_surface_subsurface_t *subsurface;
+@@
+- subsurface->target->status
++ _cairo_surface_status (subsurface->target)
+
+@disable fld_to_ptr@
+cairo_surface_wrapper_t *wrapper;
+@@
+- wrapper->target->status
++ _cairo_surface_status (wrapper->target)
+
+@disable fld_to_ptr@
+cairo_pdf_surface_t *pdf;
+@@
+- pdf->paginated_surface->status
++ _cairo_surface_status (pdf->paginated_surface)
+
+@disable fld_to_ptr@
+cairo_surface_pattern_t *surface_pattern;
+@@
+- surface_pattern->surface->status
++ _cairo_surface_status (surface_pattern->surface)
+
+
+@disable fld_to_ptr@
+cairo_surface_t *surface;
+@@
+(
+- (surface)->status
++ _cairo_surface_status (surface)
+|
+- cairo_surface_status
++ _cairo_surface_status
+ (
+ surface
+ )
+)
+
+@disable fld_to_ptr@
+cairo_surface_t surface;
+@@
+- surface.status
++ _cairo_surface_status (&surface)
+
+@@
+cairo_surface_t *surface;
+expression E;
+@@
+(
+- _cairo_surface_status (surface)
++ surface->status
+ = E
+|
+ _cairo_status_set_error (
+-&_cairo_surface_status (surface),
++&surface->status,
+ E)
+)
+
+@disable fld_to_ptr@
+cairo_surface_t *surface;
+statement S1, S2;
+@@
+ if (
+-unlikely (_cairo_surface_status (surface))
++unlikely (_cairo_surface_status (surface))
+ )
+ S1
+ else
+ S2
+
+
+@cairo_surface_status@
+expr surface;
+@@
+_cairo_surface_status (surface)
+
+@already_include@
+@@
+#include "cairo-surface-private.h"
+
+@ins_include depends on cairo_surface_status && !already_include@
+@@
+#include "cairoint.h"
++#include "cairo-surface-private.h"
diff --git a/cocci.spatches/1003-cairo_scaled_font_status.cocci b/cocci.spatches/1003-cairo_scaled_font_status.cocci
new file mode 100644
index 0000000..2b08610
--- /dev/null
+++ b/cocci.spatches/1003-cairo_scaled_font_status.cocci
@@ -0,0 +1,72 @@
+// scaled-font: Do not access the status member directly
+//
+// The only exceptions are the functions which initialize the status
+// or set it to an error.
+
+@disable fld_to_ptr@
+cairo_gstate_t *gstate;
+@@
+- gstate->scaled_font->status
++ _cairo_scaled_font_status (gstate->scaled_font)
+
+@disable fld_to_ptr@
+cairo_scaled_font_t *scaled_font;
+@@
+(
+- (scaled_font)->status
++ _cairo_scaled_font_status (scaled_font)
+|
+- cairo_scaled_font_status
++ _cairo_scaled_font_status
+ (
+ scaled_font
+ )
+)
+
+@disable fld_to_ptr@
+cairo_scaled_font_t scaled_font;
+@@
+- scaled_font.status
++ _cairo_scaled_font_status (&scaled_font)
+
+@@
+cairo_scaled_font_t *scaled_font;
+expression E;
+@@
+(
+- _cairo_scaled_font_status (scaled_font)
++ scaled_font->status
+ = E
+|
+ _cairo_status_set_error (
+-&_cairo_scaled_font_status (scaled_font),
++&scaled_font->status,
+ E)
+)
+
+@disable fld_to_ptr@
+cairo_scaled_font_t *scaled_font;
+statement S1, S2;
+@@
+ if (
+-unlikely (_cairo_scaled_font_status (scaled_font))
++unlikely (_cairo_scaled_font_status (scaled_font))
+ )
+ S1
+ else
+ S2
+
+
+@cairo_scaled_font_status@
+expression scaled_font;
+@@
+_cairo_scaled_font_status (scaled_font)
+
+@already_include@
+@@
+#include "cairo-scaled-font-private.h"
+
+@ins_include depends on cairo_scaled_font_status && !already_include@
+@@
+#include "cairoint.h"
++#include "cairo-scaled-font-private.h"
diff --git a/cocci.spatches/1004-cairo_region_status.cocci b/cocci.spatches/1004-cairo_region_status.cocci
new file mode 100644
index 0000000..31aaeda
--- /dev/null
+++ b/cocci.spatches/1004-cairo_region_status.cocci
@@ -0,0 +1,66 @@
+// region: Do not access the status member directly
+//
+// The only exceptions are the functions which initialize the status
+// or set it to an error.
+
+@disable fld_to_ptr@
+cairo_region_t *region;
+@@
+(
+- (region)->status
++ _cairo_region_status (region)
+|
+- cairo_region_status
++ _cairo_region_status
+ (
+ region
+ )
+)
+
+@disable fld_to_ptr@
+cairo_region_t region;
+@@
+- region.status
++ _cairo_region_status (&region)
+
+@@
+cairo_region_t *region;
+expression E;
+@@
+(
+- _cairo_region_status (region)
++ region->status
+ = E
+|
+ _cairo_status_set_error (
+-&_cairo_region_status (region),
++&region->status,
+ E)
+)
+
+@disable fld_to_ptr@
+cairo_region_t *region;
+statement S1, S2;
+@@
+ if (
+-unlikely (_cairo_region_status (region))
++unlikely (_cairo_region_status (region))
+ )
+ S1
+ else
+ S2
+
+
+@cairo_region_status@
+expression region;
+@@
+_cairo_region_status (region)
+
+@already_include@
+@@
+#include "cairo-region-private.h"
+
+@ins_include depends on cairo_region_status && !already_include@
+@@
+#include "cairoint.h"
++#include "cairo-region-private.h"
diff --git a/cocci.spatches/1005-cairo_pattern_status.cocci b/cocci.spatches/1005-cairo_pattern_status.cocci
new file mode 100644
index 0000000..18cec13
--- /dev/null
+++ b/cocci.spatches/1005-cairo_pattern_status.cocci
@@ -0,0 +1,72 @@
+// pattern: Do not access the status member directly
+//
+// The only exceptions are the functions which initialize the status
+// or set it to an error.
+
+@disable fld_to_ptr@
+cairo_mesh_pattern_t *mesh;
+@@
+- mesh->base.status
++ _cairo_pattern_status (&mesh->base)
+
+@disable fld_to_ptr@
+cairo_pattern_t *pattern;
+@@
+(
+- (pattern)->status
++ _cairo_pattern_status (pattern)
+|
+- cairo_pattern_status
++ _cairo_pattern_status
+ (
+ pattern
+ )
+)
+
+@disable fld_to_ptr@
+cairo_pattern_t pattern;
+@@
+- pattern.status
++ _cairo_pattern_status (&pattern)
+
+@@
+cairo_pattern_t *pattern;
+expression E;
+@@
+(
+- _cairo_pattern_status (pattern)
++ pattern->status
+ = E
+|
+ _cairo_status_set_error (
+-&_cairo_pattern_status (pattern),
++&pattern->status,
+ E)
+)
+
+@disable fld_to_ptr@
+cairo_pattern_t *pattern;
+statement S1, S2;
+@@
+ if (
+-unlikely (_cairo_pattern_status (pattern))
++unlikely (_cairo_pattern_status (pattern))
+ )
+ S1
+ else
+ S2
+
+
+@cairo_pattern_status@
+expression pattern;
+@@
+_cairo_pattern_status (pattern)
+
+@already_include@
+@@
+#include "cairo-pattern-private.h"
+
+@ins_include depends on cairo_pattern_status && !already_include@
+@@
+#include "cairoint.h"
++#include "cairo-pattern-private.h"
diff --git a/cocci.spatches/1006-cairo_font_face_status.cocci b/cocci.spatches/1006-cairo_font_face_status.cocci
new file mode 100644
index 0000000..6b9ecfd
--- /dev/null
+++ b/cocci.spatches/1006-cairo_font_face_status.cocci
@@ -0,0 +1,90 @@
+// font-face: Do not access the status member directly
+//
+// The only exceptions are the functions which initialize the status
+// or set it to an error.
+
+@disable fld_to_ptr@
+cairo_ft_font_face_t *ft;
+@@
+- ft->base.status
++ _cairo_font_face_status (&ft->base)
+
+@disable fld_to_ptr@
+cairo_toy_font_face_t *toy;
+@@
+- toy->base.status
++ _cairo_font_face_status (&toy->base)
+
+@disable fld_to_ptr@
+cairo_win32_font_face_t *win32;
+@@
+- win32->base.status
++ _cairo_font_face_status (&win32->base)
+
+@disable fld_to_ptr@
+cairo_gstate_t *gstate;
+@@
+- gstate->font_face->status
++ _cairo_font_face_status (gstate->font_face)
+
+@disable fld_to_ptr@
+cairo_font_face_t *font_face;
+@@
+(
+- (font_face)->status
++ _cairo_font_face_status (font_face)
+|
+- cairo_font_face_status
++ _cairo_font_face_status
+ (
+ font_face
+ )
+)
+
+@disable fld_to_ptr@
+cairo_font_face_t font_face;
+@@
+- font_face.status
++ _cairo_font_face_status (&font_face)
+
+@@
+cairo_font_face_t *font_face;
+expression E;
+@@
+(
+- _cairo_font_face_status (font_face)
++ font_face->status
+ = E
+|
+ _cairo_status_set_error (
+-&_cairo_font_face_status (font_face),
++&font_face->status,
+ E)
+)
+
+@disable fld_to_ptr@
+cairo_font_face_t *font_face;
+statement S1, S2;
+@@
+ if (
+-unlikely (_cairo_font_face_status (font_face))
++unlikely (_cairo_font_face_status (font_face))
+ )
+ S1
+ else
+ S2
+
+
+@cairo_font_face_status@
+expression font_face;
+@@
+_cairo_font_face_status (font_face)
+
+@already_include@
+@@
+#include "cairo-font-face-private.h"
+
+@ins_include depends on cairo_font_face_status && !already_include@
+@@
+#include "cairoint.h"
++#include "cairo-font-face-private.h"
diff --git a/cocci.spatches/1007-cairo_device_status.cocci b/cocci.spatches/1007-cairo_device_status.cocci
new file mode 100644
index 0000000..5176335
--- /dev/null
+++ b/cocci.spatches/1007-cairo_device_status.cocci
@@ -0,0 +1,72 @@
+// device: Do not access the status member directly
+//
+// The only exceptions are the functions which initialize the status
+// or set it to an error.
+
+@disable fld_to_ptr@
+cairo_drm_device_t *drm;
+@@
+- drm->base.status
++ _cairo_device_status (&drm->base)
+
+@disable fld_to_ptr@
+cairo_device_t *device;
+@@
+(
+- (device)->status
++ _cairo_device_status (device)
+|
+- cairo_device_status
++ _cairo_device_status
+ (
+ device
+ )
+)
+
+@disable fld_to_ptr@
+cairo_device_t device;
+@@
+- device.status
++ _cairo_device_status (&device)
+
+@@
+cairo_device_t *device;
+expression E;
+@@
+(
+- _cairo_device_status (device)
++ device->status
+ = E
+|
+ _cairo_status_set_error (
+-&_cairo_device_status (device),
++&device->status,
+ E)
+)
+
+@disable fld_to_ptr@
+cairo_device_t *device;
+statement S1, S2;
+@@
+ if (
+-unlikely (_cairo_device_status (device))
++unlikely (_cairo_device_status (device))
+ )
+ S1
+ else
+ S2
+
+
+@cairo_device_status@
+expression device;
+@@
+_cairo_device_status (device)
+
+@already_include@
+@@
+#include "cairo-device-private.h"
+
+@ins_include depends on cairo_device_status && !already_include@
+@@
+#include "cairoint.h"
++#include "cairo-device-private.h"
diff --git a/cocci.spatches/2001-user-data.cocci b/cocci.spatches/2001-user-data.cocci
new file mode 100644
index 0000000..57b1be1
--- /dev/null
+++ b/cocci.spatches/2001-user-data.cocci
@@ -0,0 +1,64 @@
+// surface: Do not access the user data directly
+//
+// All the accesses to the user data should pass through the
+// accessors.
+
+@@
+cairo_image_surface_t *image;
+expression a,b,c;
+@@
+(
+-_cairo_user_data_array_set_data (&image->base.user_data,
++_cairo_surface_set_user_data (&image->base,
+ a, b, c)
+|
+-_cairo_user_data_array_get_data (&image->base.user_data,
++_cairo_surface_get_user_data (&image->base,
+ a)
+)
+
+@@
+cairo_surface_t *surface;
+expression a,b,c;
+@@
+(
+-_cairo_user_data_array_set_data (&surface->user_data,
++_cairo_surface_set_user_data (surface,
+ a, b, c)
+|
+-_cairo_user_data_array_get_data (&surface->user_data,
++_cairo_surface_get_user_data (surface,
+ a)
+)
+
+@@
+expression a,b,c,d;
+@@
+(
+-cairo_surface_set_user_data (
++_cairo_surface_set_user_data (
+a, b, c, d)
+|
+-cairo_surface_get_user_data (
++_cairo_surface_get_user_data (
+a, b)
+)
+
+
+@cairo_surface_user_data@
+expression a,b,c,d;
+@@
+(
+_cairo_surface_set_user_data (a, b, c, d)
+|
+_cairo_surface_get_user_data (a, b)
+)
+
+@already_include@
+@@
+#include "cairo-surface-private.h"
+
+@ins_include depends on cairo_surface_user_data && !already_include@
+@@
+#include "cairoint.h"
++#include "cairo-surface-private.h"
diff --git a/cocci.spatches/2002-is-static.cocci b/cocci.spatches/2002-is-static.cocci
new file mode 100644
index 0000000..9b8c7c4
--- /dev/null
+++ b/cocci.spatches/2002-is-static.cocci
@@ -0,0 +1,66 @@
+// invalid reference count...
+//
+// All the accesses to the user data should pass through the
+// accessors.
+
+@@
+cairo_image_surface_t *image;
+expression a,b,c;
+@@
+CAIRO_REFERENCE_COUN
+
+(
+-_cairo_user_data_array_set_data (&image->base.user_data,
++_cairo_surface_set_user_data (&image->base,
+ a, b, c)
+|
+-_cairo_user_data_array_get_data (&image->base.user_data,
++_cairo_surface_get_user_data (&image->base,
+ a)
+)
+
+@@
+cairo_surface_t *surface;
+expression a,b,c;
+@@
+(
+-_cairo_user_data_array_set_data (&surface->user_data,
++_cairo_surface_set_user_data (surface,
+ a, b, c)
+|
+-_cairo_user_data_array_get_data (&surface->user_data,
++_cairo_surface_get_user_data (surface,
+ a)
+)
+
+@@
+expression a,b,c,d;
+@@
+(
+-cairo_surface_set_user_data (
++_cairo_surface_set_user_data (
+a, b, c, d)
+|
+-cairo_surface_get_user_data (
++_cairo_surface_get_user_data (
+a, b)
+)
+
+
+@cairo_surface_user_data@
+expression a,b,c,d;
+@@
+(
+_cairo_surface_set_user_data (a, b, c, d)
+|
+_cairo_surface_get_user_data (a, b)
+)
+
+@already_include@
+@@
+#include "cairo-surface-private.h"
+
+@ins_include depends on cairo_surface_user_data && !already_include@
+@@
+#include "cairoint.h"
++#include "cairo-surface-private.h"
diff --git a/cocci.spatches/cairo-cocci-builtin.h b/cocci.spatches/cairo-cocci-builtin.h
new file mode 100644
index 0000000..71b94da
--- /dev/null
+++ b/cocci.spatches/cairo-cocci-builtin.h
@@ -0,0 +1,15 @@
+#define cairo_public
+#define cairo_private
+#define cairo_warn
+#define cairo_always_inline
+#define CAIRO_BEGIN_DECLS
+#define CAIRO_END_DECLS
+#define CG_EXTERN
+#define png_byte unsigned char
+#define _Xconst const
+
+#define CAIRO_PRINTF_FORMAT(a,b)
+#define udev_list_entry_foreach(a,b)
+
+#define slim_hidden_def(a)
+#define slim_hidden_proto(a)
diff --git a/cocci.spatches/cairo_find.cocci b/cocci.spatches/cairo_find.cocci
new file mode 100644
index 0000000..6472ab5
--- /dev/null
+++ b/cocci.spatches/cairo_find.cocci
@@ -0,0 +1,8 @@
+@@
+identifier id, device;
+@@
+ struct id {
+ ...
+* cairo_font_face_t *obj;
+ ...
+ };
diff --git a/cocci.spatches/cleanup-array-lenght.cocci b/cocci.spatches/cleanup-array-lenght.cocci
new file mode 100644
index 0000000..7f30613
--- /dev/null
+++ b/cocci.spatches/cleanup-array-lenght.cocci
@@ -0,0 +1,11 @@
+// Use the ARRAY_LENGTH() macro when possible
+//
+// Replace open-coded array length computations with the
+// ARRAY_LENGTH() macro
+
+@@
+type T;
+T[] E;
+@@
+- (sizeof(E)/sizeof(T))
++ ARRAY_LENGTH (E)
diff --git a/cocci.spatches/cleanup-free-NULL.cocci b/cocci.spatches/cleanup-free-NULL.cocci
new file mode 100644
index 0000000..e22dab7
--- /dev/null
+++ b/cocci.spatches/cleanup-free-NULL.cocci
@@ -0,0 +1,26 @@
+// Remove useless checks for NULL before freeing
+//
+// free (NULL) is a no-op, so there is no need to avoid it
+
+@@
+expression E;
+@@
++ free (E);
++ E = NULL;
+- if (unlikely (E != NULL)) {
+- free(E);
+(
+- E = NULL;
+|
+- E = 0;
+)
+ ...
+- }
+
+@@
+expression E;
+@@
++ free (E);
+- if (unlikely (E != NULL)) {
+- free (E);
+- }
diff --git a/cocci.spatches/cleanup-whitespace.sed b/cocci.spatches/cleanup-whitespace.sed
new file mode 100644
index 0000000..d62a73e
--- /dev/null
+++ b/cocci.spatches/cleanup-whitespace.sed
@@ -0,0 +1,53 @@
+# only modify new lines
+/^+/ {
+
+# remove diff-style + line prefix
+s/^+//
+
+# remove trailing whitespace
+s/[[:space:]]*$//
+
+# replace 8 spaces at the beginning of a line with a single tab
+s/^ /\t/
+
+# remove 1-7 spaces at the beginning of a line if they are followed by
+# a tab (which would hide them in the resulting layout)
+s/^ \{1,7\}\t/\t/
+
+:spacestotab
+# replace 8 tab-aligned spaces with a single tab
+s/\t /\t\t/
+t spacestotab
+
+:removespaces
+# remove 1-7 tab-aligned spaces if they are followed by a tab (which
+# would hide them in the resulting layout)
+s/\t \{1,7\}\t/\t\t/
+t removespaces
+
+:tabtospaces
+# replace non-leading tabs with spaces (except for trailing tabs in
+# macros) to make reindentation easier
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{8\}\)\t\(.*[^\\]\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{1\}\)\t\(.*[^\\]\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{2\}\)\t\(.*[^\\]\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{3\}\)\t\(.*[^\\]\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{4\}\)\t\(.*[^\\]\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{5\}\)\t\(.*[^\\]\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{6\}\)\t\(.*[^\\]\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{7\}\)\t\(.*[^\\]\)$/\1 \3/
+
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{8\}\)\t\(.*[^\t].*\\\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{1\}\)\t\(.*[^\t].*\\\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{2\}\)\t\(.*[^\t].*\\\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{3\}\)\t\(.*[^\t].*\\\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{4\}\)\t\(.*[^\t].*\\\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{5\}\)\t\(.*[^\t].*\\\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{6\}\)\t\(.*[^\t].*\\\)$/\1 \3/
+s/^\(\t*\([^\t]\{8\}\)*[^\t]\{7\}\)\t\(.*[^\t].*\\\)$/\1 \3/
+
+t tabtospaces
+
+# restore diff-style + line prefix
+s/^/+/
+}
diff --git a/cocci.spatches/coccinelle-commit.sh b/cocci.spatches/coccinelle-commit.sh
new file mode 100755
index 0000000..ca48aad
--- /dev/null
+++ b/cocci.spatches/coccinelle-commit.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# Helper script to use a Coccinelle semantic patch as a commit message
+# USAGE: coccinelle-commit.sh <your_cocci_patch> | git commit -F-
+
+head -n1 "$1" | sed 's/^\/\/[[:blank:]]*//'
+echo
+echo 'This patch has been generated by the following Coccinelle semantic patch:'
+echo
+cat "$1"
diff --git a/cocci.spatches/dis0005-unlikely.cocci b/cocci.spatches/dis0005-unlikely.cocci
new file mode 100644
index 0000000..bb3aeca
--- /dev/null
+++ b/cocci.spatches/dis0005-unlikely.cocci
@@ -0,0 +1,13 @@
+// Mark branches that test for an error status as unlikely
+
+@@
+cairo_status_t status;
+statement S1, S2;
+@@
+ if (
+- unlikely (status)
++ unlikely (status)
+ )
+ S1
+ else
+ S2
diff --git a/cocci.spatches/dis0015-unlikely-error.cocci b/cocci.spatches/dis0015-unlikely-error.cocci
new file mode 100644
index 0000000..2e41233
--- /dev/null
+++ b/cocci.spatches/dis0015-unlikely-error.cocci
@@ -0,0 +1,18 @@
+// Mark branches which generate an error status as unlikely
+
+@@
+identifier id ~= "CAIRO_ERROR";
+expression E;
+statement S;
+@@
+ if (
+- unlikely (E)
++ unlikely (E)
+ )
+ {
+ <+...
+ id
+ ...+>
+ }
+ else
+ S
diff --git a/cocci.spatches/malloc-coding-style.cocci b/cocci.spatches/malloc-coding-style.cocci
new file mode 100644
index 0000000..90cd4da
--- /dev/null
+++ b/cocci.spatches/malloc-coding-style.cocci
@@ -0,0 +1,27 @@
+// Apply the malloc replacements suggested in CODING_STYLE
+//
+// Cairo has some utility macros to check that the expressions used to
+// compute the argument of a malloc() call do not overflow.
+// CODING_STYLE indicates the replacements that should be done in
+// order to use these functions correctly.
+
+// malloc (n * size + k) => _cairo_malloc_ab_plus_c (n, size, k)
+@@
+expression n,size,k;
+@@
+-malloc ((n) * (size) + (k))
++_cairo_malloc_ab_plus_c (n, size, k)
+
+// malloc (a * b * size) => _cairo_malloc_abc (a, b, size)
+@@
+expression a,b,size;
+@@
+-malloc ((a) * (b) * (size))
++_cairo_malloc3 (a, b, size)
+
+// malloc (n * size) => _cairo_malloc_ab (n, size)
+@@
+expression n,size;
+@@
+-malloc ((n) * (size))
++_cairo_malloc_ab (n, size)
diff --git a/cocci.spatches/show-whitespace.sed b/cocci.spatches/show-whitespace.sed
new file mode 100644
index 0000000..53eda8d
--- /dev/null
+++ b/cocci.spatches/show-whitespace.sed
@@ -0,0 +1,3 @@
+s/$/EOL/
+s/\t/T12345678/g
+s/ /s/g
diff --git a/cocci.spatches/test-pyerr.cocci b/cocci.spatches/test-pyerr.cocci
new file mode 100644
index 0000000..6a67e7b
--- /dev/null
+++ b/cocci.spatches/test-pyerr.cocci
@@ -0,0 +1,5 @@
+// Make sure that new error statuses are introduced with CAIRO_ERROR_
+
+@@
+@@
+- _cairo_device_create_in_error \ No newline at end of file