[cairo-commit] boilerplate/cairo-boilerplate.c boilerplate/cairo-boilerplate.h

Andrea Canciani ranma42 at kemper.freedesktop.org
Fri Nov 11 07:14:58 PST 2011


 boilerplate/cairo-boilerplate.c |   11 ++++++++---
 boilerplate/cairo-boilerplate.h |    4 +++-
 2 files changed, 11 insertions(+), 4 deletions(-)

New commits:
commit 0e18cc6d27e59e42c6632b21c5502174c8a9eb08
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Fri Nov 11 12:20:28 2011 +0100

    boilerplate: Provide close callback after opening any2ppm output
    
    cairo_boilerplate_open_any2ppm() returns a FILE* obtined from popen()
    or fdopen(). It should hence be closed using pclose() or fclose()
    respectively.
    
    Fixes the crash on every script test on MacOS X.

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index 91abbe2..b4b492f 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -789,7 +789,8 @@ any2ppm_daemon_exists (void)
 FILE *
 cairo_boilerplate_open_any2ppm (const char   *filename,
 				int	      page,
-				unsigned int  flags)
+				unsigned int  flags,
+				int        (**close_cb) (FILE *))
 {
     char command[4096];
 #if HAS_DAEMON
@@ -824,10 +825,13 @@ cairo_boilerplate_open_any2ppm (const char   *filename,
 	goto POPEN;
     }
 
+    *close_cb = fclose;
     return fdopen (sk, "r");
 
 POPEN:
 #endif
+
+    *close_cb = pclose;
     sprintf (command, "./any2ppm %s %d", filename, page);
     return popen (command, "r");
 }
@@ -921,10 +925,11 @@ cairo_boilerplate_convert_to_image (const char *filename,
     FILE *file;
     unsigned int flags = 0;
     cairo_surface_t *image;
+    int (*close_cb) (FILE *);
     int ret;
 
   RETRY:
-    file = cairo_boilerplate_open_any2ppm (filename, page, flags);
+    file = cairo_boilerplate_open_any2ppm (filename, page, flags, &close_cb);
     if (file == NULL) {
 	switch (errno) {
 	case ENOMEM:
@@ -935,7 +940,7 @@ cairo_boilerplate_convert_to_image (const char *filename,
     }
 
     image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
-    ret = pclose (file);
+    ret = close_cb (file);
     /* check for fatal errors from the interpreter */
     if (ret) { /* any2pmm should never die... */
 	cairo_surface_destroy (image);
diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h
index 0615221..b1a1f1c 100644
--- a/boilerplate/cairo-boilerplate.h
+++ b/boilerplate/cairo-boilerplate.h
@@ -218,7 +218,9 @@ enum {
 FILE *
 cairo_boilerplate_open_any2ppm (const char   *filename,
 				int	      page,
-				unsigned int  flags);
+				unsigned int  flags,
+				int        (**close_cb) (FILE *));
+
 cairo_surface_t *
 cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file);
 


More information about the cairo-commit mailing list