[cairo-commit]
cairo/src cairo-array.c, 1.6, 1.7 cairo-font-subset.c,
1.5, 1.6 cairo-meta-surface.c, 1.14, 1.15 cairo-pdf-surface.c,
1.67, 1.68 cairo-ps-surface.c, 1.57, 1.58 cairo-win32-font.c,
1.43, 1.44 cairoint.h, 1.223, 1.224
Carl Worth
commit at pdx.freedesktop.org
Fri Nov 4 16:13:33 PST 2005
Committed by: cworth
Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv2481/src
Modified Files:
cairo-array.c cairo-font-subset.c cairo-meta-surface.c
cairo-pdf-surface.c cairo-ps-surface.c cairo-win32-font.c
cairoint.h
Log Message:
2005-11-04 Carl Worth <cworth at cworth.org>
* src/cairoint.h:
* src/cairo-array.c: (_cairo_array_append),
(_cairo_array_append_multiple): Rename old, rarely used
_cairo_array_append to _cairo_array_append_multiple. Add much more
common _cairo_array_append. Fix both to return a
cairo_status_t. Remove undocumented code to allow a non-copying
append when elements is NULL, (let's not encourage unintialized
data, shall we?)
* src/cairo-array.c: (_cairo_user_data_array_set_data): Cleanup to
not rely on undocumented copy-avoidance in _cairo_array_append.
* src/cairo-font-subset.c: (cairo_pdf_ft_font_write):
* src/cairo-meta-surface.c: (_cairo_meta_surface_composite),
(_cairo_meta_surface_fill_rectangles),
(_cairo_meta_surface_composite_trapezoids),
(_cairo_meta_surface_intersect_clip_path),
(_cairo_meta_surface_old_show_glyphs), (_cairo_meta_surface_fill):
* src/cairo-pdf-surface.c: (_cairo_pdf_document_new_object),
(_cairo_pdf_surface_add_stream), (_cairo_pdf_surface_add_pattern),
(_cairo_pdf_surface_add_xobject), (_cairo_pdf_surface_add_alpha),
(_cairo_pdf_surface_add_font), (_cairo_pdf_document_get_font),
(_cairo_pdf_document_add_page):
* src/cairo-ps-surface.c: (_cairo_ps_surface_show_page),
(_cairo_ps_surface_get_font):
* src/cairo-win32-font.c: (_flush_glyphs), (_add_glyph): Track
change in number of arguments and return value of
_cairo_array_append.
Index: cairo-array.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-array.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cairo-array.c 4 Nov 2005 23:15:30 -0000 1.6
+++ cairo-array.c 5 Nov 2005 00:13:31 -0000 1.7
@@ -32,6 +32,7 @@
*
* Contributor(s):
* Kristian Høgsberg <krh at redhat.com>
+ * Carl Worth <cworth at cworth.org>
*/
#include "cairoint.h"
@@ -168,31 +169,58 @@
/**
* _cairo_array_append:
*
- * Append one or more elements onto the end of @array.
+ * Append single item onto the array by growing the array by at least
+ * one element, then copying element_size bytes from @element into the
+ * array. The address of the resulting object within the array can be
+ * determined with:
*
- * Return value: The address of the initial element as stored in the
- * array or NULL if out of memory.
+ * _cairo_array_index (array, _cairo_array_num_elements (array) - 1);
+ *
+ * Return value: CAIRO_STATUS_SUCCESS if successful or
+ * CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the
+ * operation.
**/
-void *
-_cairo_array_append (cairo_array_t *array,
- const void *elements, int num_elements)
+cairo_status_t
+_cairo_array_append (cairo_array_t *array,
+ const void *element)
+{
+ return _cairo_array_append_multiple (array, element, 1);
+}
+
+/**
+ * _cairo_array_append:
+ *
+ * Append one or more items onto the array by growing the array by
+ * @num_elements, then copying @num_elements * element_size bytes from
+ * @elements into the array. The address of the first data object
+ * within the array can be determined with:
+ *
+ * _cairo_array_index (array, _cairo_array_num_elements (array) - num_elements);
+ *
+ * Return value: CAIRO_STATUS_SUCCESS if successful or
+ * CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the
+ * operation.
+ **/
+cairo_status_t
+_cairo_array_append_multiple (cairo_array_t *array,
+ const void *elements,
+ int num_elements)
{
cairo_status_t status;
void *dest;
status = _cairo_array_grow_by (array, num_elements);
- if (status != CAIRO_STATUS_SUCCESS)
- return NULL;
+ if (status)
+ return status;
assert (array->num_elements + num_elements <= array->size);
dest = &array->elements[array->num_elements * array->element_size];
array->num_elements += num_elements;
- if (elements != NULL)
- memcpy (dest, elements, num_elements * array->element_size);
+ memcpy (dest, elements, num_elements * array->element_size);
- return dest;
+ return CAIRO_STATUS_SUCCESS;
}
/**
@@ -308,44 +336,44 @@
void *user_data,
cairo_destroy_func_t destroy)
{
+ cairo_status_t status;
int i, num_slots;
- cairo_user_data_slot_t *slots, *s;
+ cairo_user_data_slot_t *slots, *slot, new_slot;
- s = NULL;
+ if (user_data) {
+ new_slot.key = key;
+ new_slot.user_data = user_data;
+ new_slot.destroy = destroy;
+ } else {
+ new_slot.key = NULL;
+ new_slot.user_data = NULL;
+ new_slot.destroy = NULL;
+ }
+
+ slot = NULL;
num_slots = array->num_elements;
slots = (cairo_user_data_slot_t *) array->elements;
for (i = 0; i < num_slots; i++) {
if (slots[i].key == key) {
- if (slots[i].user_data != NULL && slots[i].destroy != NULL)
- slots[i].destroy (slots[i].user_data);
- s = &slots[i];
+ slot = &slots[i];
+ if (slot->destroy && slot->user_data)
+ slot->destroy (slot->user_data);
break;
}
if (user_data && slots[i].user_data == NULL) {
- s = &slots[i]; /* Have to keep searching for an exact match */
+ slot = &slots[i]; /* Have to keep searching for an exact match */
}
}
- if (user_data == NULL) {
- if (s != NULL) {
- s->key = NULL;
- s->user_data = NULL;
- s->destroy = NULL;
- }
-
+ if (slot) {
+ *slot = new_slot;
return CAIRO_STATUS_SUCCESS;
-
- } else {
- if (s == NULL)
- s = _cairo_array_append (array, NULL, 1);
- if (s == NULL)
- return CAIRO_STATUS_NO_MEMORY;
-
- s->key = key;
- s->user_data = user_data;
- s->destroy = destroy;
}
+ status = _cairo_array_append (array, &new_slot);
+ if (status)
+ return status;
+
return CAIRO_STATUS_SUCCESS;
}
Index: cairo-font-subset.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-font-subset.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cairo-font-subset.c 5 Aug 2005 06:10:26 -0000 1.5
+++ cairo-font-subset.c 5 Nov 2005 00:13:31 -0000 1.6
@@ -235,13 +235,14 @@
cairo_pdf_ft_font_write (cairo_pdf_ft_font_t *font,
const void *data, size_t length)
{
- void *p;
+ cairo_status_t status;
- p = _cairo_array_append (&font->output, data, length);
- if (p == NULL)
- font->status = CAIRO_STATUS_NO_MEMORY;
+ status = _cairo_array_append_multiple (&font->output, data, length);
+ if (status)
+ return NULL;
- return p;
+ return _cairo_array_index (&font->output,
+ _cairo_array_num_elements (&font->output) - length);
}
static void
Index: cairo-meta-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-meta-surface.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cairo-meta-surface.c 4 Nov 2005 19:16:39 -0000 1.14
+++ cairo-meta-surface.c 5 Nov 2005 00:13:31 -0000 1.15
@@ -164,6 +164,7 @@
unsigned int width,
unsigned int height)
{
+ cairo_status_t status;
cairo_meta_surface_t *meta = abstract_surface;
cairo_command_composite_t *command;
@@ -173,9 +174,15 @@
command->type = CAIRO_COMMAND_COMPOSITE;
command->operator = operator;
- _init_pattern_with_snapshot (&command->src_pattern.base, src_pattern);
+
+ status = _init_pattern_with_snapshot (&command->src_pattern.base, src_pattern);
+ if (status)
+ goto CLEANUP_COMMAND;
+
if (mask_pattern) {
- _init_pattern_with_snapshot (&command->mask_pattern.base, mask_pattern);
+ status = _init_pattern_with_snapshot (&command->mask_pattern.base, mask_pattern);
+ if (status)
+ goto CLEANUP_SOURCE;
command->mask_pattern_pointer = &command->mask_pattern.base;
} else {
command->mask_pattern_pointer = NULL;
@@ -190,14 +197,20 @@
command->width = width;
command->height = height;
- if (_cairo_array_append (&meta->commands, &command, 1) == NULL) {
- _cairo_pattern_fini (&command->src_pattern.base);
- _cairo_pattern_fini (command->mask_pattern_pointer);
- free (command);
- return CAIRO_STATUS_NO_MEMORY;
- }
+ status = _cairo_array_append (&meta->commands, &command);
+ if (status)
+ goto CLEANUP_MASK;
return CAIRO_STATUS_SUCCESS;
+
+ CLEANUP_MASK:
+ _cairo_pattern_fini (command->mask_pattern_pointer);
+ CLEANUP_SOURCE:
+ _cairo_pattern_fini (&command->src_pattern.base);
+ CLEANUP_COMMAND:
+ free (command);
+
+ return status;
}
static cairo_int_status_t
@@ -207,6 +220,7 @@
cairo_rectangle_t *rects,
int num_rects)
{
+ cairo_status_t status;
cairo_meta_surface_t *meta = abstract_surface;
cairo_command_fill_rectangles_t *command;
@@ -227,10 +241,11 @@
command->num_rects = num_rects;
- if (_cairo_array_append (&meta->commands, &command, 1) == NULL) {
+ status = _cairo_array_append (&meta->commands, &command);
+ if (status) {
free (command->rects);
free (command);
- return CAIRO_STATUS_NO_MEMORY;
+ return status;
}
return CAIRO_STATUS_SUCCESS;
@@ -250,6 +265,7 @@
cairo_trapezoid_t *traps,
int num_traps)
{
+ cairo_status_t status;
cairo_meta_surface_t *meta = abstract_surface;
cairo_command_composite_trapezoids_t *command;
@@ -278,11 +294,12 @@
command->num_traps = num_traps;
- if (_cairo_array_append (&meta->commands, &command, 1) == NULL) {
+ status = _cairo_array_append (&meta->commands, &command);
+ if (status) {
_cairo_pattern_fini (&command->pattern.base);
free (command->traps);
free (command);
- return CAIRO_STATUS_NO_MEMORY;
+ return status;
}
return CAIRO_STATUS_SUCCESS;
@@ -319,11 +336,12 @@
command->tolerance = tolerance;
command->antialias = antialias;
- if (_cairo_array_append (&meta->commands, &command, 1) == NULL) {
+ status = _cairo_array_append (&meta->commands, &command);
+ if (status) {
if (path)
_cairo_path_fixed_fini (&command->path);
free (command);
- return CAIRO_STATUS_NO_MEMORY;
+ return status;
}
return CAIRO_STATUS_SUCCESS;
@@ -362,6 +380,7 @@
const cairo_glyph_t *glyphs,
int num_glyphs)
{
+ cairo_status_t status;
cairo_meta_surface_t *meta = abstract_surface;
cairo_command_show_glyphs_t *command;
@@ -390,11 +409,12 @@
command->num_glyphs = num_glyphs;
- if (_cairo_array_append (&meta->commands, &command, 1) == NULL) {
+ status = _cairo_array_append (&meta->commands, &command);
+ if (status) {
_cairo_pattern_fini (&command->pattern.base);
free (command->glyphs);
free (command);
- return CAIRO_STATUS_NO_MEMORY;
+ return status;
}
return CAIRO_STATUS_SUCCESS;
@@ -430,11 +450,12 @@
command->tolerance = tolerance;
command->antialias = antialias;
- if (_cairo_array_append (&meta->commands, &command, 1) == NULL) {
+ status = _cairo_array_append (&meta->commands, &command);
+ if (status) {
_cairo_path_fixed_fini (&command->path);
_cairo_pattern_fini (&command->pattern.base);
free (command);
- return CAIRO_STATUS_NO_MEMORY;
+ return status;
}
return CAIRO_STATUS_SUCCESS;
Index: cairo-pdf-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-pdf-surface.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- cairo-pdf-surface.c 4 Nov 2005 19:16:39 -0000 1.67
+++ cairo-pdf-surface.c 5 Nov 2005 00:13:31 -0000 1.68
@@ -189,10 +189,13 @@
static unsigned int
_cairo_pdf_document_new_object (cairo_pdf_document_t *document)
{
+ cairo_status_t status;
cairo_pdf_object_t object;
object.offset = _cairo_output_stream_get_position (document->output_stream);
- if (_cairo_array_append (&document->objects, &object, 1) == NULL)
+
+ status = _cairo_array_append (&document->objects, &object);
+ if (status)
return 0;
return document->next_available_id++;
@@ -212,7 +215,8 @@
_cairo_pdf_surface_add_stream (cairo_pdf_surface_t *surface,
cairo_pdf_stream_t *stream)
{
- _cairo_array_append (&surface->streams, &stream, 1);
+ /* XXX: Should be checking the return value here. */
+ _cairo_array_append (&surface->streams, &stream);
surface->current_stream = stream;
}
@@ -222,7 +226,8 @@
cairo_pdf_resource_t resource;
resource.id = id;
- _cairo_array_append (&surface->patterns, &resource, 1);
+ /* XXX: Should be checking the return value here. */
+ _cairo_array_append (&surface->patterns, &resource);
}
static void
@@ -239,7 +244,8 @@
}
resource.id = id;
- _cairo_array_append (&surface->xobjects, &resource, 1);
+ /* XXX: Should be checking the return value here. */
+ _cairo_array_append (&surface->xobjects, &resource);
}
static unsigned int
@@ -255,7 +261,8 @@
return i;
}
- _cairo_array_append (&surface->alphas, &alpha, 1);
+ /* XXX: Should be checking the return value here. */
+ _cairo_array_append (&surface->alphas, &alpha);
return _cairo_array_num_elements (&surface->alphas) - 1;
}
@@ -273,7 +280,8 @@
}
resource.id = id;
- _cairo_array_append (&surface->fonts, &resource, 1);
+ /* XXX: Should be checking the return value here. */
+ _cairo_array_append (&surface->fonts, &resource);
}
static cairo_surface_t *
@@ -1391,6 +1399,7 @@
_cairo_pdf_document_get_font (cairo_pdf_document_t *document,
cairo_scaled_font_t *scaled_font)
{
+ cairo_status_t status;
cairo_unscaled_font_t *unscaled_font;
cairo_font_subset_t *pdf_font;
unsigned int num_fonts, i;
@@ -1417,7 +1426,8 @@
pdf_font->font_id = _cairo_pdf_document_new_object (document);
- if (_cairo_array_append (&document->fonts, &pdf_font, 1) == NULL) {
+ status = _cairo_array_append (&document->fonts, &pdf_font);
+ if (status) {
_cairo_font_subset_destroy (pdf_font);
return NULL;
}
@@ -1899,6 +1909,7 @@
_cairo_pdf_document_add_page (cairo_pdf_document_t *document,
cairo_pdf_surface_t *surface)
{
+ cairo_status_t status;
cairo_pdf_stream_t *stream;
cairo_pdf_resource_t *res;
cairo_output_stream_t *output = document->output_stream;
@@ -2004,7 +2015,9 @@
">>\r\n"
"endobj\r\n");
- _cairo_array_append (&document->pages, &page_id, 1);
+ status = _cairo_array_append (&document->pages, &page_id);
+ if (status)
+ return status;
return CAIRO_STATUS_SUCCESS;
}
Index: cairo-ps-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ps-surface.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- cairo-ps-surface.c 4 Nov 2005 19:16:39 -0000 1.57
+++ cairo-ps-surface.c 5 Nov 2005 00:13:31 -0000 1.58
@@ -339,7 +339,10 @@
{
cairo_ps_surface_t *surface = abstract_surface;
- _cairo_array_append (&surface->pages, &surface->current_page, 1);
+ status = _cairo_array_append (&surface->pages, &surface->current_page);
+ if (status)
+ return status;
+
surface->current_page = _cairo_meta_surface_create (surface->width,
surface->height);
if (surface->current_page->status)
@@ -410,7 +413,9 @@
return NULL;
subset->font_id = surface->fonts.num_elements;
- if (_cairo_array_append (&surface->fonts, &subset, 1) == NULL) {
+
+ status = _cairo_array_append (&surface->fonts, &subset);
+ if (status) {
_cairo_font_subset_destroy (subset);
return NULL;
}
Index: cairo-win32-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-win32-font.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- cairo-win32-font.c 31 Oct 2005 19:10:14 -0000 1.43
+++ cairo-win32-font.c 5 Nov 2005 00:13:31 -0000 1.44
@@ -891,9 +891,12 @@
static cairo_status_t
_flush_glyphs (cairo_glyph_state_t *state)
{
+ cairo_status_t status;
int dx = 0;
- if (!_cairo_array_append (&state->dx, &dx, 1))
- return CAIRO_STATUS_NO_MEMORY;
+
+ status = _cairo_array_append (&state->dx, &dx);
+ if (status)
+ return status;
if (!ExtTextOutW (state->hdc,
state->start_x, state->last_y,
@@ -917,6 +920,7 @@
double device_x,
double device_y)
{
+ cairo_status_t status;
double user_x = device_x;
double user_y = device_y;
WCHAR glyph_index = index;
@@ -931,15 +935,16 @@
int dx;
if (logical_y != state->last_y) {
- cairo_status_t status = _flush_glyphs (state);
+ status = _flush_glyphs (state);
if (status)
return status;
state->start_x = logical_x;
}
dx = logical_x - state->last_x;
- if (!_cairo_array_append (&state->dx, &dx, 1))
- return CAIRO_STATUS_NO_MEMORY;
+ status = _cairo_array_append (&state->dx, &dx);
+ if (status)
+ return status;
} else {
state->start_x = logical_x;
}
@@ -947,7 +952,9 @@
state->last_x = logical_x;
state->last_y = logical_y;
- _cairo_array_append (&state->glyphs, &glyph_index, 1);
+ status = _cairo_array_append (&state->glyphs, &glyph_index);
+ if (status)
+ return status;
return CAIRO_STATUS_SUCCESS;
}
Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.223
retrieving revision 1.224
diff -u -d -r1.223 -r1.224
--- cairoint.h 4 Nov 2005 19:16:40 -0000 1.223
+++ cairoint.h 5 Nov 2005 00:13:31 -0000 1.224
@@ -332,9 +332,12 @@
cairo_private void
_cairo_array_truncate (cairo_array_t *array, int length);
-cairo_private void *
-_cairo_array_append (cairo_array_t *array,
- const void *elements, int num_elements);
+cairo_private cairo_status_t
+_cairo_array_append (cairo_array_t *array, const void *element);
+
+cairo_private cairo_status_t
+_cairo_array_append_multiple (cairo_array_t *array,
+ const void *elements, int num_elements);
cairo_private void *
_cairo_array_index (cairo_array_t *array, int index);
More information about the cairo-commit
mailing list