mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-05 08:48:00 +02:00
Fix cairo_copy_path and cairo_copy_path_flat to propagate errors.
One of these functions was already documented to be doing this, and the other one should have been. Now the documentation and behavior for both are consistent, (and the path-data test case verifies this).
This commit is contained in:
parent
f9165638bf
commit
5f833c134b
4 changed files with 56 additions and 7 deletions
|
|
@ -48,6 +48,9 @@ cairo_private cairo_path_t *
|
|||
_cairo_path_data_create_flat (cairo_path_fixed_t *path,
|
||||
cairo_gstate_t *gstate);
|
||||
|
||||
cairo_private cairo_path_t *
|
||||
_cairo_path_data_create_for_status (cairo_status_t status);
|
||||
|
||||
cairo_private cairo_status_t
|
||||
_cairo_path_data_append_to_context (cairo_path_t *path,
|
||||
cairo_t *cr);
|
||||
|
|
|
|||
|
|
@ -331,6 +331,22 @@ _cairo_path_data_populate (cairo_path_t *path,
|
|||
assert (cpdp.data - path->data == path->num_data);
|
||||
}
|
||||
|
||||
cairo_path_t *
|
||||
_cairo_path_data_create_for_status (cairo_status_t status)
|
||||
{
|
||||
cairo_path_t *path;
|
||||
|
||||
path = malloc (sizeof (cairo_path_t));
|
||||
if (path == NULL)
|
||||
return (cairo_path_t*) &_cairo_path_nil;
|
||||
|
||||
path->num_data = 0;
|
||||
path->data = NULL;
|
||||
path->status = status;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static cairo_path_t *
|
||||
_cairo_path_data_create_real (cairo_path_fixed_t *path_fixed,
|
||||
cairo_gstate_t *gstate,
|
||||
|
|
|
|||
16
src/cairo.c
16
src/cairo.c
|
|
@ -2981,8 +2981,12 @@ cairo_get_group_target (cairo_t *cr)
|
|||
* conditions hold:
|
||||
*
|
||||
* <orderedlist>
|
||||
* <listitem>If there is insufficient memory to copy the path.</listitem>
|
||||
* <listitem>If @cr is already in an error state.</listitem>
|
||||
* <listitem>If there is insufficient memory to copy the path. In this
|
||||
* case <literal>path->status</literal> will be set to
|
||||
* %CAIRO_STATUS_NO_MEMORY.</listitem>
|
||||
* <listitem>If @cr is already in an error state. In this case
|
||||
* <literal>path->status</literal> will contain the same status that
|
||||
* would be returned by cairo_status().</listitem>
|
||||
* </orderedlist>
|
||||
*
|
||||
* In either case, <literal>path->status</literal> will be set to
|
||||
|
|
@ -2997,7 +3001,7 @@ cairo_path_t *
|
|||
cairo_copy_path (cairo_t *cr)
|
||||
{
|
||||
if (cr->status)
|
||||
return (cairo_path_t*) &_cairo_path_nil;
|
||||
return _cairo_path_data_create_for_status (cr->status);
|
||||
|
||||
return _cairo_path_data_create (&cr->path, cr->gstate);
|
||||
}
|
||||
|
|
@ -3039,9 +3043,9 @@ cairo_path_t *
|
|||
cairo_copy_path_flat (cairo_t *cr)
|
||||
{
|
||||
if (cr->status)
|
||||
return (cairo_path_t*) &_cairo_path_nil;
|
||||
else
|
||||
return _cairo_path_data_create_flat (&cr->path, cr->gstate);
|
||||
return _cairo_path_data_create_for_status (cr->status);
|
||||
|
||||
return _cairo_path_data_create_flat (&cr->path, cr->gstate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ static cairo_test_draw_function_t draw;
|
|||
|
||||
cairo_test_t test = {
|
||||
"path-data",
|
||||
"Tests calls to path_data functions: cairo_copy_path_data, cairo_copy_path_data_flat, and cairo_append_path_data",
|
||||
"Tests calls to path_data functions: cairo_copy_path, cairo_copy_path_flat, and cairo_append_path",
|
||||
45, 53,
|
||||
draw
|
||||
};
|
||||
|
|
@ -97,6 +97,32 @@ static cairo_test_status_t
|
|||
draw (cairo_t *cr, int width, int height)
|
||||
{
|
||||
cairo_path_t *path;
|
||||
cairo_t *cr_error;
|
||||
|
||||
/* Ensure that calling cairo_copy_path on an in-error cairo_t will
|
||||
* propagate the error. */
|
||||
cr_error = cairo_create (NULL);
|
||||
path = cairo_copy_path (cr_error);
|
||||
if (path->status == CAIRO_STATUS_SUCCESS ||
|
||||
path->status != cairo_status (cr_error)) {
|
||||
cairo_test_log ("Error: cairo_copy_path returned status of %s rather than propagating %s\n",
|
||||
cairo_status_to_string (path->status),
|
||||
cairo_status_to_string (cairo_status (cr_error)));
|
||||
cairo_path_destroy (path);
|
||||
return CAIRO_TEST_FAILURE;
|
||||
}
|
||||
cairo_path_destroy (path);
|
||||
|
||||
path = cairo_copy_path_flat (cr_error);
|
||||
if (path->status == CAIRO_STATUS_SUCCESS ||
|
||||
path->status != cairo_status (cr_error)) {
|
||||
cairo_test_log ("Error: cairo_copy_path_flat returned status of %s rather than propagating %s\n",
|
||||
cairo_status_to_string (path->status),
|
||||
cairo_status_to_string (cairo_status (cr_error)));
|
||||
cairo_path_destroy (path);
|
||||
return CAIRO_TEST_FAILURE;
|
||||
}
|
||||
cairo_path_destroy (path);
|
||||
|
||||
/* We draw in the default black, so paint white first. */
|
||||
cairo_save (cr);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue