[cairo-commit] cairo/src Makefile.am, 1.54, 1.55 cairo-debug.c, NONE, 1.1 cairo-debug.h, NONE, 1.1 cairo-features.h.in, 1.19, 1.20 cairo-font.c, 1.59, 1.60 cairo-ft-font.c, 1.85, 1.86 cairo-xlib-screen.c, 1.3, 1.4 cairo-xlib-surface.c, 1.101, 1.102 cairo.h, 1.143, 1.144 cairoint.h, 1.176, 1.177

Carl Worth commit at pdx.freedesktop.org
Mon Aug 1 13:33:49 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv22964/src

Modified Files:
	Makefile.am cairo-features.h.in cairo-font.c cairo-ft-font.c 
	cairo-xlib-screen.c cairo-xlib-surface.c cairo.h cairoint.h 
Added Files:
	cairo-debug.c cairo-debug.h 
Log Message:

2005-08-01  Carl Worth  <cworth at cworth.org>

        * src/cairo-debug.h: New public header file.

        * src/cairo-debug.c: (cairo_debug_reset_static_data): New function
        to reset all static data (eg. caches) to their initial state.

        * Makefile.am: Fix check-valgrind target to depend on the 'all'
        target.

        * configure.in: Add check for a new, proposed, XrmFinalize
        function.

        * src/Makefile.am: Add cairo-debug.c.

        * src/cairo.h:
        * src/cairo-features.h.in: Move the definition of
        CAIRO_BEGIN_DECLS to cairo-features.h so that it can be shared
        between public header files, and so that it doesn't clutter
        cairo.h

        * src/cairoint.h:
        * src/cairo-font.c: (_get_global_simple_cache),
        (_get_outer_font_cache), (_get_inner_font_cache),
        (_cairo_unlock_global_image_glyph_cache),
        (_cairo_font_reset_static_data):
        * src/cairo-ft-font.c: (_cairo_ft_font_reset_static_data):
        * src/cairo-xlib-screen.c: (_cairo_xlib_close_display),
        (_cairo_xlib_screen_info_reset),
        (_cairo_xlib_screen_reset_static_data):
        * src/cairo-xlib-surface.c: (_unlock_xlib_glyphset_caches),
        (_destroy_glyphset_cache_recurse),
        (_cairo_xlib_surface_reset_static_data): Implement
        reset_static_data in all modules as required.

        * test/xlib-surface.c: (main):
        * test/cairo-test.h:
        * test/cairo-test.c: (cairo_test_for_target),
        (cairo_test_expecting): Call cairo_debug_reset_static_data and
        FcFini so that we can have all tests be valgrind-clean with
        respect to memory leaks and still-reachable data.


Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/cairo/src/Makefile.am,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- Makefile.am	21 Jul 2005 13:52:13 -0000	1.54
+++ Makefile.am	1 Aug 2005 20:33:47 -0000	1.55
@@ -86,6 +86,7 @@
 	cairo-array.c				\
 	cairo-cache.c				\
 	cairo-color.c				\
+	cairo-debug.c				\
 	cairo-fixed.c				\
 	cairo-font.c				\
 	cairo-font-options.c			\

--- NEW FILE: cairo-debug.c ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: cairo-debug.h ---
(This appears to be a binary file; contents omitted.)

Index: cairo-features.h.in
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-features.h.in,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- cairo-features.h.in	9 May 2005 15:34:57 -0000	1.19
+++ cairo-features.h.in	1 Aug 2005 20:33:47 -0000	1.20
@@ -37,6 +37,14 @@
 #ifndef CAIRO_FEATURES_H
 #define CAIRO_FEATURES_H
 
+#ifdef  __cplusplus
+# define CAIRO_BEGIN_DECLS  extern "C" {
+# define CAIRO_END_DECLS    }
+#else
+# define CAIRO_BEGIN_DECLS
+# define CAIRO_END_DECLS
+#endif
+
 @PS_SURFACE_FEATURE@
 
 @PDF_SURFACE_FEATURE@

Index: cairo-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-font.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- cairo-font.c	29 Jul 2005 19:45:01 -0000	1.59
+++ cairo-font.c	1 Aug 2005 20:33:47 -0000	1.60
@@ -233,11 +233,11 @@
     CAIRO_MUTEX_UNLOCK (_global_simple_cache_mutex);
 }
 
+static cairo_cache_t *global_simple_cache = NULL;
+
 static cairo_cache_t *
 _get_global_simple_cache (void)
 {
-    static cairo_cache_t *global_simple_cache = NULL;
-
     if (global_simple_cache == NULL)
     {
 	global_simple_cache = malloc (sizeof (cairo_cache_t));	
@@ -564,11 +564,11 @@
     CAIRO_MUTEX_UNLOCK (_global_font_cache_mutex);
 }
 
+static cairo_cache_t *outer_font_cache = NULL;
+
 static cairo_cache_t *
 _get_outer_font_cache (void)
 {
-    static cairo_cache_t *outer_font_cache = NULL;
-
     if (outer_font_cache == NULL)
     {
 	outer_font_cache = malloc (sizeof (cairo_cache_t));	
@@ -589,11 +589,11 @@
     return NULL;
 }
 
+static cairo_cache_t *inner_font_cache = NULL;
+
 static cairo_cache_t *
 _get_inner_font_cache (void)
 {
-    static cairo_cache_t *inner_font_cache = NULL;
-
     if (inner_font_cache == NULL)
     {
 	inner_font_cache = malloc (sizeof (cairo_cache_t));	
@@ -1352,8 +1352,10 @@
 void
 _cairo_unlock_global_image_glyph_cache()
 {
-    _cairo_cache_shrink_to (_global_image_glyph_cache, 
-			    CAIRO_IMAGE_GLYPH_CACHE_MEMORY_DEFAULT);
+    if (_global_image_glyph_cache) {
+	_cairo_cache_shrink_to (_global_image_glyph_cache, 
+				CAIRO_IMAGE_GLYPH_CACHE_MEMORY_DEFAULT);
+    }
     CAIRO_MUTEX_UNLOCK (_global_image_glyph_cache_mutex);
 }
 
@@ -1380,3 +1382,24 @@
     _global_image_glyph_cache = NULL;
     return NULL;
 }
+
+void
+_cairo_font_reset_static_data (void)
+{
+    _lock_global_font_cache ();
+    _cairo_cache_destroy (outer_font_cache);
+    outer_font_cache = NULL;
+    _cairo_cache_destroy (inner_font_cache);
+    inner_font_cache = NULL;
+    _unlock_global_font_cache ();
+
+    _cairo_lock_global_image_glyph_cache();
+    _cairo_cache_destroy (_global_image_glyph_cache);
+    _global_image_glyph_cache = NULL;
+    _cairo_unlock_global_image_glyph_cache();
+
+    _lock_global_simple_cache ();
+    _cairo_cache_destroy (global_simple_cache);
+    global_simple_cache = NULL;
+    _unlock_global_simple_cache ();
+}

Index: cairo-ft-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ft-font.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- cairo-ft-font.c	31 Jul 2005 18:19:47 -0000	1.85
+++ cairo-ft-font.c	1 Aug 2005 20:33:47 -0000	1.86
@@ -2440,3 +2440,16 @@
 {
     _ft_unscaled_font_unlock_face ((ft_unscaled_font_t *)unscaled_font);
 }
+
+void
+_cairo_ft_font_reset_static_data (void)
+{
+    _lock_global_ft_cache ();
+    if (_global_ft_cache) {
+	FT_Done_FreeType (_global_ft_cache->lib);
+	_global_ft_cache->lib = NULL;
+    }
+    _cairo_cache_destroy (&_global_ft_cache->base);
+    _global_ft_cache = NULL;
+    _unlock_global_ft_cache ();
+}

Index: cairo-xlib-screen.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-xlib-screen.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cairo-xlib-screen.c	24 Jul 2005 12:18:16 -0000	1.3
+++ cairo-xlib-screen.c	1 Aug 2005 20:33:47 -0000	1.4
@@ -245,34 +245,59 @@
 
 CAIRO_MUTEX_DECLARE(_xlib_screen_mutex);
 
-static cairo_xlib_screen_info_t *_cairo_xlib_screen_list;
+static cairo_xlib_screen_info_t *_cairo_xlib_screen_list = NULL;
 
 static int
 _cairo_xlib_close_display (Display *dpy, XExtCodes *codes)
 {
-    cairo_xlib_screen_info_t *info;
-    cairo_xlib_screen_info_t **prev;
+    cairo_xlib_screen_info_t *info, *prev;
 
     /*
      * Unhook from the global list
      */
     CAIRO_MUTEX_LOCK (_xlib_screen_mutex);
 
-    for (prev = &_cairo_xlib_screen_list; (info = *prev); prev = &(*prev)->next) {
+    prev = NULL;
+    for (info = _cairo_xlib_screen_list; info; info = info->next) {
 	if (info->display == dpy) {
-	    *prev = info->next;
+	    if (prev)
+		prev->next = info->next;
+	    else
+		_cairo_xlib_screen_list = info->next;
 	    free (info);
-	    if (!*prev)
-		break;
+	    break;
 	}
+	prev = info;
     }
     CAIRO_MUTEX_UNLOCK (_xlib_screen_mutex);
-    
+
+    /* Return value in accordance with requirements of
+     * XESetCloseDisplay */
     return 0;
 }
 
+static void
+_cairo_xlib_screen_info_reset (void)
+{
+    cairo_xlib_screen_info_t *info, *next;
 
-cairo_private cairo_xlib_screen_info_t *
+    /*
+     * Delete everything in the list.
+     */
+    CAIRO_MUTEX_LOCK (_xlib_screen_mutex);
+
+    for (info = _cairo_xlib_screen_list; info; info = next) {
+	next = info->next;
+	free (info);
+    }
+
+    _cairo_xlib_screen_list = NULL;
+
+    CAIRO_MUTEX_UNLOCK (_xlib_screen_mutex);
+
+}
+
+cairo_xlib_screen_info_t *
 _cairo_xlib_screen_info_get (Display *dpy, Screen *screen)
 {
     cairo_xlib_screen_info_t *info;
@@ -344,3 +369,13 @@
     return info;
 }
 
+void
+_cairo_xlib_screen_reset_static_data (void)
+{
+    _cairo_xlib_screen_info_reset ();
+
+#if HAVE_XRMFINALIZE
+    XrmFinalize ();
+#endif
+
+}

Index: cairo-xlib-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-xlib-surface.c,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- cairo-xlib-surface.c	28 Jul 2005 17:02:54 -0000	1.101
+++ cairo-xlib-surface.c	1 Aug 2005 20:33:47 -0000	1.102
@@ -1943,8 +1943,10 @@
 static void
 _unlock_xlib_glyphset_caches (glyphset_cache_t *cache)
 {
-    _cairo_cache_shrink_to (&cache->base,
-			    CAIRO_XLIB_GLYPH_CACHE_MEMORY_DEFAULT);
+    if (cache) {
+	_cairo_cache_shrink_to (&cache->base,
+				CAIRO_XLIB_GLYPH_CACHE_MEMORY_DEFAULT);
+    }
     CAIRO_MUTEX_UNLOCK(_xlib_glyphset_caches_mutex);
 }
 
@@ -2452,3 +2454,23 @@
     
     return status;
 }
+
+static void
+_destroy_glyphset_cache_recurse (glyphset_cache_t *cache)
+{
+    if (cache == NULL)
+	return;
+
+    _destroy_glyphset_cache_recurse (cache->next);
+    _cairo_cache_destroy (&cache->base);
+    free (cache);
+}
+
+void
+_cairo_xlib_surface_reset_static_data (void)
+{
+    _lock_xlib_glyphset_caches ();
+    _destroy_glyphset_cache_recurse (_xlib_glyphset_caches);
+    _xlib_glyphset_caches = NULL;
+    _unlock_xlib_glyphset_caches (NULL);
+}

Index: cairo.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.h,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -d -r1.143 -r1.144
--- cairo.h	1 Aug 2005 18:45:42 -0000	1.143
+++ cairo.h	1 Aug 2005 20:33:47 -0000	1.144
@@ -38,14 +38,6 @@
 #ifndef CAIRO_H
 #define CAIRO_H
 
-#ifdef  __cplusplus
-# define CAIRO_BEGIN_DECLS  extern "C" {
-# define CAIRO_END_DECLS    }
-#else
-# define CAIRO_BEGIN_DECLS
-# define CAIRO_END_DECLS
-#endif
-
 #include <cairo-features.h>
 
 CAIRO_BEGIN_DECLS

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.176
retrieving revision 1.177
diff -u -d -r1.176 -r1.177
--- cairoint.h	1 Aug 2005 18:45:42 -0000	1.176
+++ cairoint.h	1 Aug 2005 20:33:47 -0000	1.177
@@ -63,6 +63,7 @@
 #include <stdio.h>
 
 #include "cairo.h"
+#include "cairo-debug.h"
 #include <pixman.h>
 
 #if __GNUC__ >= 3 && defined(__ELF__)
@@ -518,6 +519,18 @@
 cairo_private cairo_cache_t *
 _cairo_get_global_image_glyph_cache (void);
 
+cairo_private void
+_cairo_font_reset_static_data (void);
+
+cairo_private void
+_cairo_ft_font_reset_static_data (void);
+
+cairo_private void
+_cairo_xlib_surface_reset_static_data (void);
+
+cairo_private void
+_cairo_xlib_screen_reset_static_data (void);
+
 /* Some glyph cache functions you can reuse. */
 
 cairo_private unsigned long




More information about the cairo-commit mailing list