[m-rev.] diff: mercury_cairo: Do not enumerate possible return statuses.
Peter Wang
novalazy at gmail.com
Fri Dec 4 17:03:24 AEDT 2015
Do not try to exhaustively enumerate possible status values after
creating cairo objects. It is error prone and unnecessary.
extras/graphics/mercury_cairo/cairo.image.m:
extras/graphics/mercury_cairo/cairo.pdf.m:
extras/graphics/mercury_cairo/cairo.ps.m:
extras/graphics/mercury_cairo/cairo.recording.m:
extras/graphics/mercury_cairo/cairo.svg.m:
As above. After creating a cairo object, return the status
to the user whether successful or not.
---
extras/graphics/mercury_cairo/cairo.image.m | 24 ++++++-----------------
extras/graphics/mercury_cairo/cairo.pdf.m | 25 ++++++------------------
extras/graphics/mercury_cairo/cairo.ps.m | 26 ++++++-------------------
extras/graphics/mercury_cairo/cairo.recording.m | 24 ++++++-----------------
extras/graphics/mercury_cairo/cairo.svg.m | 25 ++++++------------------
5 files changed, 30 insertions(+), 94 deletions(-)
diff --git a/extras/graphics/mercury_cairo/cairo.image.m b/extras/graphics/mercury_cairo/cairo.image.m
index 7aa59c7..1360731 100644
--- a/extras/graphics/mercury_cairo/cairo.image.m
+++ b/extras/graphics/mercury_cairo/cairo.image.m
@@ -90,24 +90,12 @@ create_surface(Format, Width, Height, Surface, !IO) :-
(int)W, (int)H);
Status = cairo_surface_status(raw_surface);
- switch (Status) {
- case CAIRO_STATUS_SUCCESS:
- Surface = MR_GC_NEW(MCAIRO_surface);
- Surface->mcairo_raw_surface = raw_surface;
- MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
- break;
-
- case CAIRO_STATUS_NULL_POINTER:
- case CAIRO_STATUS_NO_MEMORY:
- case CAIRO_STATUS_READ_ERROR:
- case CAIRO_STATUS_INVALID_CONTENT:
- case CAIRO_STATUS_INVALID_FORMAT:
- case CAIRO_STATUS_INVALID_VISUAL:
- Surface = NULL;
- break;
-
- default:
- MR_external_fatal_error(\"Mercury cairo\", \"invalid status\");
+ if (Status == CAIRO_STATUS_SUCCESS) {
+ Surface = MR_GC_NEW(MCAIRO_surface);
+ Surface->mcairo_raw_surface = raw_surface;
+ MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
+ } else {
+ Surface = NULL;
}
").
diff --git a/extras/graphics/mercury_cairo/cairo.pdf.m b/extras/graphics/mercury_cairo/cairo.pdf.m
index a6f3e56..d3b8ff3 100644
--- a/extras/graphics/mercury_cairo/cairo.pdf.m
+++ b/extras/graphics/mercury_cairo/cairo.pdf.m
@@ -112,25 +112,12 @@ create_surface(FileName, Width, Height, Surface, !IO) :-
raw_surface = cairo_pdf_surface_create(FileName, W, H);
Status = cairo_surface_status(raw_surface);
- switch (Status) {
- case CAIRO_STATUS_SUCCESS:
- Surface = MR_GC_NEW(MCAIRO_surface);
- Surface->mcairo_raw_surface = raw_surface;
- MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
- break;
-
- case CAIRO_STATUS_NULL_POINTER:
- case CAIRO_STATUS_NO_MEMORY:
- case CAIRO_STATUS_READ_ERROR:
- case CAIRO_STATUS_INVALID_CONTENT:
- case CAIRO_STATUS_INVALID_FORMAT:
- case CAIRO_STATUS_INVALID_VISUAL:
- Surface = NULL;
- break;
-
- default:
- MR_external_fatal_error(\"Mercury cairo\",
- \"unknown PDF surface status\");
+ if (Status == CAIRO_STATUS_SUCCESS) {
+ Surface = MR_GC_NEW(MCAIRO_surface);
+ Surface->mcairo_raw_surface = raw_surface;
+ MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
+ } else {
+ Surface = NULL;
}
#else
Supported = MR_NO;
diff --git a/extras/graphics/mercury_cairo/cairo.ps.m b/extras/graphics/mercury_cairo/cairo.ps.m
index 12984ea..ffada5f 100644
--- a/extras/graphics/mercury_cairo/cairo.ps.m
+++ b/extras/graphics/mercury_cairo/cairo.ps.m
@@ -164,27 +164,13 @@ create_surface(FileName, Width, Height, Surface, !IO) :-
raw_surface = cairo_ps_surface_create(FileName, W, H);
Status = cairo_surface_status(raw_surface);
- switch (Status) {
- case CAIRO_STATUS_SUCCESS:
- Surface = MR_GC_NEW(MCAIRO_surface);
- Surface->mcairo_raw_surface = raw_surface;
- MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
- break;
-
- case CAIRO_STATUS_NULL_POINTER:
- case CAIRO_STATUS_NO_MEMORY:
- case CAIRO_STATUS_READ_ERROR:
- case CAIRO_STATUS_INVALID_CONTENT:
- case CAIRO_STATUS_INVALID_FORMAT:
- case CAIRO_STATUS_INVALID_VISUAL:
- Surface = NULL;
- break;
-
- default:
- MR_external_fatal_error(\"Mercury cairo\",
- \"unknown PostScript surface status\");
+ if (Status == CAIRO_STATUS_SUCCESS) {
+ Surface = MR_GC_NEW(MCAIRO_surface);
+ Surface->mcairo_raw_surface = raw_surface;
+ MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
+ } else {
+ Surface = NULL;
}
-
#else
Supported = MR_NO;
Status = CAIRO_STATUS_SUCCESS;
diff --git a/extras/graphics/mercury_cairo/cairo.recording.m b/extras/graphics/mercury_cairo/cairo.recording.m
index 4312008..7b03f88 100644
--- a/extras/graphics/mercury_cairo/cairo.recording.m
+++ b/extras/graphics/mercury_cairo/cairo.recording.m
@@ -130,24 +130,12 @@ create_surface(Content, MaybeExtents, Surface, !IO) :-
Status = cairo_surface_status(raw_surface);
- switch (Status) {
- case CAIRO_STATUS_SUCCESS:
- Surface = MR_GC_NEW(MCAIRO_surface);
- Surface->mcairo_raw_surface = raw_surface;
- MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
- break;
-
- case CAIRO_STATUS_NULL_POINTER:
- case CAIRO_STATUS_NO_MEMORY:
- case CAIRO_STATUS_READ_ERROR:
- case CAIRO_STATUS_INVALID_CONTENT:
- case CAIRO_STATUS_INVALID_FORMAT:
- case CAIRO_STATUS_INVALID_VISUAL:
- Surface = NULL;
- break;
-
- default:
- MR_external_fatal_error(\"Mercury cairo\", \"invalid status\");
+ if (Status == CAIRO_STATUS_SUCCESS) {
+ Surface = MR_GC_NEW(MCAIRO_surface);
+ Surface->mcairo_raw_surface = raw_surface;
+ MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
+ } else {
+ Surface = NULL;
}
#else
Supported = MR_NO;
diff --git a/extras/graphics/mercury_cairo/cairo.svg.m b/extras/graphics/mercury_cairo/cairo.svg.m
index a27e49b..fbb511a 100644
--- a/extras/graphics/mercury_cairo/cairo.svg.m
+++ b/extras/graphics/mercury_cairo/cairo.svg.m
@@ -126,25 +126,12 @@ create_surface(FileName, Width, Height, Surface, !IO) :-
raw_surface = cairo_svg_surface_create(FileName, (int)W, (int)H);
Status = cairo_surface_status(raw_surface);
- switch (Status) {
- case CAIRO_STATUS_SUCCESS:
- Surface = MR_GC_NEW(MCAIRO_surface);
- Surface->mcairo_raw_surface = raw_surface;
- MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
- break;
-
- case CAIRO_STATUS_NULL_POINTER:
- case CAIRO_STATUS_NO_MEMORY:
- case CAIRO_STATUS_READ_ERROR:
- case CAIRO_STATUS_INVALID_CONTENT:
- case CAIRO_STATUS_INVALID_FORMAT:
- case CAIRO_STATUS_INVALID_VISUAL:
- Surface = NULL;
- break;
-
- default:
- MR_external_fatal_error(\"Mercury cairo\",
- \"unknown SVG surface status\");
+ if (Status == CAIRO_STATUS_SUCCESS) {
+ Surface = MR_GC_NEW(MCAIRO_surface);
+ Surface->mcairo_raw_surface = raw_surface;
+ MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
+ } else {
+ Surface = NULL;
}
#else
Supported = MR_NO;
--
2.1.2
More information about the reviews
mailing list