Skip to content

Commit

Permalink
[boilerplate] Retry conversion in process if first attempt fails.
Browse files Browse the repository at this point in the history
One possibility for a read failure whilst converting the image is if the
external utility crashed. This information is important for the test suite
as knowing input that causes the converter to crash is just as vital as
identifying a crash within the library.
  • Loading branch information
Chris Wilson committed Sep 26, 2008
1 parent f2c484d commit 48099af
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
11 changes: 1 addition & 10 deletions boilerplate/cairo-boilerplate-pdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,8 @@ _cairo_boilerplate_pdf_convert_to_image (cairo_surface_t *surface)
{
pdf_target_closure_t *ptc = cairo_surface_get_user_data (surface,
&pdf_closure_key);
FILE *file;
cairo_surface_t *image;

file = cairo_boilerplate_open_any2ppm (ptc->filename, 1);
if (file == NULL)
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);

image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
fclose (file);

return image;
return cairo_boilerplate_convert_to_image (ptc->filename, 1);
}

cairo_surface_t *
Expand Down
11 changes: 1 addition & 10 deletions boilerplate/cairo-boilerplate-svg.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,8 @@ _cairo_boilerplate_svg_convert_to_image (cairo_surface_t *surface)
{
svg_target_closure_t *ptc = cairo_surface_get_user_data (surface,
&svg_closure_key);
FILE *file;
cairo_surface_t *image;

file = cairo_boilerplate_open_any2ppm (ptc->filename, 0);
if (file == NULL)
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);

image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
fclose (file);

return image;
return cairo_boilerplate_convert_to_image (ptc->filename, 0);
}

cairo_surface_t *
Expand Down
35 changes: 33 additions & 2 deletions boilerplate/cairo-boilerplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,18 @@ any2ppm_daemon_exists (void)

FILE *
cairo_boilerplate_open_any2ppm (const char *filename,
int page)
int page,
unsigned int flags)
{
char command[4096];
#if HAS_DAEMON
int sk;
struct sockaddr_un addr;
int len;

if (flags & CAIRO_BOILERPLATE_OPEN_NO_DAEMON)
goto POPEN;

if (! any2ppm_daemon_exists ()) {
if (system ("./any2ppm") != 0)
goto POPEN;
Expand Down Expand Up @@ -747,7 +751,7 @@ cairo_boilerplate_open_any2ppm (const char *filename,
}

static cairo_bool_t
freadn (char *buf, int len, FILE *file)
freadn (unsigned char *buf, int len, FILE *file)
{
int ret;

Expand Down Expand Up @@ -822,6 +826,33 @@ cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file)
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);
}

cairo_surface_t *
cairo_boilerplate_convert_to_image (const char *filename, int page)
{
FILE *file;
unsigned int flags = 0;
cairo_surface_t *image;

RETRY:
file = cairo_boilerplate_open_any2ppm (filename, 1, flags);
if (file == NULL)
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);

image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
fclose (file);

if (cairo_surface_status (image) == CAIRO_STATUS_READ_ERROR) {
if (flags == 0) {
/* Try again in process, e.g. to propagate a CRASH. */
cairo_surface_destroy (image);
flags = CAIRO_BOILERPLATE_OPEN_NO_DAEMON;
goto RETRY;
}
}

return image;
}

int
cairo_boilerplate_version (void)
{
Expand Down
11 changes: 9 additions & 2 deletions boilerplate/cairo-boilerplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,20 @@ cairo_boilerplate_get_image_surface_from_png (const char *filename,
cairo_surface_t *
cairo_boilerplate_surface_create_in_error (cairo_status_t status);

enum {
CAIRO_BOILERPLATE_OPEN_NO_DAEMON = 0x1,
};

FILE *
cairo_boilerplate_open_any2ppm (const char *filename,
int page);

int page,
unsigned int flags);
cairo_surface_t *
cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file);

cairo_surface_t *
cairo_boilerplate_convert_to_image (const char *filename, int page);

int
cairo_boilerplate_version (void);

Expand Down

0 comments on commit 48099af

Please sign in to comment.