diff options
Diffstat (limited to 'util/cairo-script')
-rw-r--r-- | util/cairo-script/cairo-script-file.c | 3 | ||||
-rw-r--r-- | util/cairo-script/cairo-script-hash.c | 7 | ||||
-rw-r--r-- | util/cairo-script/cairo-script-objects.c | 7 | ||||
-rw-r--r-- | util/cairo-script/cairo-script-operators.c | 15 | ||||
-rw-r--r-- | util/cairo-script/cairo-script-private.h | 8 | ||||
-rw-r--r-- | util/cairo-script/cairo-script-scanner.c | 5 | ||||
-rw-r--r-- | util/cairo-script/cairo-script-stack.c | 7 | ||||
-rw-r--r-- | util/cairo-script/csi-replay.c | 122 |
8 files changed, 95 insertions, 79 deletions
diff --git a/util/cairo-script/cairo-script-file.c b/util/cairo-script/cairo-script-file.c index fcdccf14..9a3ff70a 100644 --- a/util/cairo-script/cairo-script-file.c +++ b/util/cairo-script/cairo-script-file.c @@ -35,6 +35,7 @@ #include "cairo-script-private.h" #include <stdio.h> +#include <limits.h> /* INT_MAX */ #include <string.h> #define CHUNK_SIZE 32768 @@ -996,7 +997,7 @@ _csi_file_as_string (csi_t *ctx, char *newbytes; int newlen; - if (_csi_unlikely (allocated > INT32_MAX / 2)) + if (_csi_unlikely (allocated > INT_MAX / 2)) return _csi_error (CAIRO_STATUS_NO_MEMORY); newlen = allocated * 2; diff --git a/util/cairo-script/cairo-script-hash.c b/util/cairo-script/cairo-script-hash.c index 4fa9e492..67451117 100644 --- a/util/cairo-script/cairo-script-hash.c +++ b/util/cairo-script/cairo-script-hash.c @@ -279,7 +279,7 @@ _csi_hash_table_lookup (csi_hash_table_t *hash_table, entry = &hash_table->entries[idx]; if (ENTRY_IS_LIVE (*entry)) { - if (hash_table->keys_equal (key, *entry)) + if ((*entry)->hash == key->hash && hash_table->keys_equal (key, *entry)) return *entry; } else if (ENTRY_IS_FREE (*entry)) return NULL; @@ -295,8 +295,11 @@ _csi_hash_table_lookup (csi_hash_table_t *hash_table, entry = &hash_table->entries[idx]; if (ENTRY_IS_LIVE (*entry)) { - if (hash_table->keys_equal (key, *entry)) + if ((*entry)->hash == key->hash && + hash_table->keys_equal (key, *entry)) + { return *entry; + } } else if (ENTRY_IS_FREE (*entry)) return NULL; } while (++i < table_size); diff --git a/util/cairo-script/cairo-script-objects.c b/util/cairo-script/cairo-script-objects.c index 552241f3..84398f18 100644 --- a/util/cairo-script/cairo-script-objects.c +++ b/util/cairo-script/cairo-script-objects.c @@ -34,6 +34,7 @@ #include "cairo-script-private.h" +#include <limits.h> /* INT_MAX */ #include <string.h> csi_status_t @@ -193,9 +194,7 @@ csi_boolean_new (csi_t *ctx, static cairo_bool_t _dictionary_name_equal (const void *_a, const void *_b) { - const csi_dictionary_entry_t *a = _a; - const csi_dictionary_entry_t *b = _b; - return a->hash_entry.hash == b->hash_entry.hash; + return TRUE; } csi_status_t @@ -523,7 +522,7 @@ csi_string_new (csi_t *ctx, if (len < 0) len = strlen (str); - if (_csi_unlikely (len >= INT32_MAX)) + if (_csi_unlikely (len >= INT_MAX)) return _csi_error (CSI_STATUS_NO_MEMORY); if (ctx->free_string == NULL || ctx->free_string->len <= len) { diff --git a/util/cairo-script/cairo-script-operators.c b/util/cairo-script/cairo-script-operators.c index d2bdb4c8..0ed3dd3f 100644 --- a/util/cairo-script/cairo-script-operators.c +++ b/util/cairo-script/cairo-script-operators.c @@ -39,6 +39,7 @@ #include <stdio.h> /* snprintf */ #include <string.h> #include <math.h> +#include <limits.h> /* INT_MAX */ #include <assert.h> typedef struct _csi_proxy { @@ -2136,7 +2137,7 @@ _glyph_path (csi_t *ctx) } if (nglyphs > ARRAY_LENGTH (stack_glyphs)) { - if (_csi_unlikely ((unsigned) nglyphs >= INT32_MAX / sizeof (cairo_glyph_t))) + if (_csi_unlikely ((unsigned) nglyphs >= INT_MAX / sizeof (cairo_glyph_t))) return _csi_error (CSI_STATUS_NO_MEMORY); glyphs = _csi_alloc (ctx, sizeof (cairo_glyph_t) * nglyphs); if (_csi_unlikely (glyphs == NULL)) @@ -3898,7 +3899,7 @@ _set_dash (csi_t *ctx) if (_csi_likely (array->stack.len < ARRAY_LENGTH (stack_dashes))) { dashes = stack_dashes; } else { - if (_csi_unlikely ((unsigned) array->stack.len >= INT32_MAX / sizeof (double))) + if (_csi_unlikely ((unsigned) array->stack.len >= INT_MAX / sizeof (double))) return _csi_error (CSI_STATUS_NO_MEMORY); dashes = _csi_alloc (ctx, sizeof (double) * array->stack.len); if (_csi_unlikely (dashes == NULL)) @@ -4734,7 +4735,7 @@ _show_glyphs (csi_t *ctx) } if (nglyphs > ARRAY_LENGTH (stack_glyphs)) { - if (_csi_unlikely ((unsigned) nglyphs >= INT32_MAX / sizeof (cairo_glyph_t))) + if (_csi_unlikely ((unsigned) nglyphs >= INT_MAX / sizeof (cairo_glyph_t))) return _csi_error (CSI_STATUS_NO_MEMORY); glyphs = _csi_alloc (ctx, sizeof (cairo_glyph_t) * nglyphs); if (_csi_unlikely (glyphs == NULL)) @@ -4880,7 +4881,7 @@ _show_text_glyphs (csi_t *ctx) array = obj->datum.array; nclusters = array->stack.len / 2; if (nclusters > ARRAY_LENGTH (stack_clusters)) { - if (_csi_unlikely ((unsigned) nclusters >= INT32_MAX / sizeof (cairo_text_cluster_t))) + if (_csi_unlikely ((unsigned) nclusters >= INT_MAX / sizeof (cairo_text_cluster_t))) return _csi_error (CSI_STATUS_NO_MEMORY); clusters = _csi_alloc (ctx, sizeof (cairo_text_cluster_t) * nclusters); if (_csi_unlikely (clusters == NULL)) @@ -4898,7 +4899,7 @@ _show_text_glyphs (csi_t *ctx) string = obj->datum.string; nclusters = string->len / 2; if (nclusters > ARRAY_LENGTH (stack_clusters)) { - if (_csi_unlikely ((unsigned) nclusters >= INT32_MAX / sizeof (cairo_text_cluster_t))) + if (_csi_unlikely ((unsigned) nclusters >= INT_MAX / sizeof (cairo_text_cluster_t))) return _csi_error (CSI_STATUS_NO_MEMORY); clusters = _csi_alloc (ctx, sizeof (cairo_text_cluster_t) * nclusters); if (_csi_unlikely (clusters == NULL)) @@ -4943,7 +4944,7 @@ _show_text_glyphs (csi_t *ctx) return CSI_STATUS_SUCCESS; if (nglyphs > ARRAY_LENGTH (stack_glyphs)) { - if (_csi_unlikely ((unsigned) nglyphs >= INT32_MAX / sizeof (cairo_glyph_t))) + if (_csi_unlikely ((unsigned) nglyphs >= INT_MAX / sizeof (cairo_glyph_t))) return _csi_error (CSI_STATUS_NO_MEMORY); glyphs = _csi_alloc (ctx, sizeof (cairo_glyph_t) * nglyphs); if (_csi_unlikely (glyphs == NULL)) { @@ -5415,7 +5416,7 @@ _debug_print (csi_t *ctx) fprintf (stderr, "name: %s\n", (char *) obj->datum.name); break; case CSI_OBJECT_TYPE_OPERATOR: - fprintf (stderr, "operator: %p\n", obj->datum.op); + fprintf (stderr, "operator: %p\n", obj->datum.ptr); break; case CSI_OBJECT_TYPE_REAL: fprintf (stderr, "real: %g\n", obj->datum.real); diff --git a/util/cairo-script/cairo-script-private.h b/util/cairo-script/cairo-script-private.h index f74cb49f..d2ebc0c8 100644 --- a/util/cairo-script/cairo-script-private.h +++ b/util/cairo-script/cairo-script-private.h @@ -247,7 +247,7 @@ typedef enum { CSI_OBJECT_TYPE_FONT, CSI_OBJECT_TYPE_PATTERN, CSI_OBJECT_TYPE_SCALED_FONT, - CSI_OBJECT_TYPE_SURFACE, + CSI_OBJECT_TYPE_SURFACE } csi_object_type_t; #define CSI_OBJECT_IS_ATOM(OBJ) (((OBJ)->type & CSI_OBJECT_TYPE_MASK) < 0x08) @@ -256,7 +256,7 @@ typedef enum { enum { /* attributes */ CSI_OBJECT_ATTR_EXECUTABLE = 1 << 6, - CSI_OBJECT_ATTR_WRITABLE = 1 << 7, + CSI_OBJECT_ATTR_WRITABLE = 1 << 7 }; #define CSI_OBJECT_ATTR_MASK (CSI_OBJECT_ATTR_EXECUTABLE | \ CSI_OBJECT_ATTR_WRITABLE) @@ -400,7 +400,7 @@ struct _csi_file { STDIO, BYTES, PROCEDURE, - FILTER, + FILTER } type; void *src; void *data; @@ -429,7 +429,7 @@ struct _csi_scanner { COMMENT, STRING, HEX, - BASE85, + BASE85 } state; csi_buffer_t buffer; diff --git a/util/cairo-script/cairo-script-scanner.c b/util/cairo-script/cairo-script-scanner.c index c08e447d..22d1721e 100644 --- a/util/cairo-script/cairo-script-scanner.c +++ b/util/cairo-script/cairo-script-scanner.c @@ -34,9 +34,10 @@ #include "cairo-script-private.h" +#include <limits.h> /* INT_MAX */ +#include <math.h> /* pow */ #include <stdio.h> /* EOF */ #include <string.h> /* memset */ -#include <math.h> /* pow */ /* * whitespace: @@ -88,7 +89,7 @@ _csi_buffer_grow (csi_t *ctx, csi_buffer_t *buffer) if (_csi_unlikely (buffer->status)) return buffer->status; - if (_csi_unlikely (buffer->size > INT32_MAX / 2)) + if (_csi_unlikely (buffer->size > INT_MAX / 2)) return buffer->status = _csi_error (CSI_STATUS_NO_MEMORY); offset = buffer->ptr - buffer->base; diff --git a/util/cairo-script/cairo-script-stack.c b/util/cairo-script/cairo-script-stack.c index d6c123b4..59d2c6a0 100644 --- a/util/cairo-script/cairo-script-stack.c +++ b/util/cairo-script/cairo-script-stack.c @@ -34,6 +34,7 @@ #include "cairo-script-private.h" +#include <limits.h> /* INT_MAX */ #include <string.h> csi_status_t @@ -43,7 +44,7 @@ _csi_stack_init (csi_t *ctx, csi_stack_t *stack, csi_integer_t size) stack->len = 0; stack->size = size; - /* assert ((unsigned) size < INT32_MAX / sizeof (csi_object_t)); */ + /* assert ((unsigned) size < INT_MAX / sizeof (csi_object_t)); */ stack->objects = _csi_alloc (ctx, size * sizeof (csi_object_t)); if (_csi_unlikely (stack->objects == NULL)) status = _csi_error (CSI_STATUS_NO_MEMORY); @@ -90,7 +91,7 @@ _csi_stack_roll (csi_t *ctx, /* fall back to a copy */ if (n > ARRAY_LENGTH (stack_copy)) { - if (_csi_unlikely ((unsigned) n > INT32_MAX / sizeof (csi_object_t))) + if (_csi_unlikely ((unsigned) n > INT_MAX / sizeof (csi_object_t))) return _csi_error (CSI_STATUS_NO_MEMORY); copy = _csi_alloc (ctx, n * sizeof (csi_object_t)); if (copy == NULL) @@ -124,7 +125,7 @@ _csi_stack_grow (csi_t *ctx, csi_stack_t *stack, csi_integer_t cnt) if (_csi_likely (cnt <= stack->size)) return CSI_STATUS_SUCCESS; - if (_csi_unlikely ((unsigned) cnt >= INT32_MAX / sizeof (csi_object_t))) + if (_csi_unlikely ((unsigned) cnt >= INT_MAX / sizeof (csi_object_t))) return _csi_error (CSI_STATUS_NO_MEMORY); newsize = stack->size; diff --git a/util/cairo-script/csi-replay.c b/util/cairo-script/csi-replay.c index 8a1f3cd9..16b733cc 100644 --- a/util/cairo-script/csi-replay.c +++ b/util/cairo-script/csi-replay.c @@ -7,10 +7,8 @@ static const cairo_user_data_key_t _key; -#if CAIRO_HAS_XLIB_XRENDER_SURFACE +#if CAIRO_HAS_XLIB_SURFACE #include <cairo-xlib.h> -#include <cairo-xlib-xrender.h> - static Display * _get_display (void) { @@ -29,16 +27,49 @@ _get_display (void) } static void -_destroy_pixmap (void *closure) +_destroy_window (void *closure) { - XFreePixmap (_get_display(), (Pixmap) closure); + XFlush (_get_display ()); + XDestroyWindow (_get_display(), (Window) closure); +} + +static cairo_surface_t * +_xlib_surface_create (void *closure, + cairo_content_t content, + double width, double height) +{ + Display *dpy; + XSetWindowAttributes attr; + Visual *visual; + int depth; + Window w; + cairo_surface_t *surface; + + dpy = _get_display (); + + visual = DefaultVisual (dpy, DefaultScreen (dpy)); + depth = DefaultDepth (dpy, DefaultScreen (dpy)); + attr.override_redirect = True; + w = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0, + width <= 0 ? 1 : width, + height <= 0 ? 1 : height, + 0, depth, + InputOutput, visual, CWOverrideRedirect, &attr); + XMapWindow (dpy, w); + + surface = cairo_xlib_surface_create (dpy, w, visual, width, height); + cairo_surface_set_user_data (surface, &_key, (void *) w, _destroy_window); + + return surface; } +#if CAIRO_HAS_XLIB_XRENDER_SURFACE +#include <cairo-xlib-xrender.h> + static void -_destroy_window (void *closure) +_destroy_pixmap (void *closure) { - XFlush (_get_display ()); - XDestroyWindow (_get_display(), (Window) closure); + XFreePixmap (_get_display(), (Pixmap) closure); } static cairo_surface_t * @@ -47,66 +78,40 @@ _xrender_surface_create (void *closure, double width, double height) { Display *dpy; + Pixmap pixmap; XRenderPictFormat *xrender_format; cairo_surface_t *surface; dpy = _get_display (); content = CAIRO_CONTENT_COLOR_ALPHA; - if (1) { - Pixmap pixmap; - - switch (content) { - case CAIRO_CONTENT_COLOR_ALPHA: - xrender_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); - break; - case CAIRO_CONTENT_COLOR: - xrender_format = XRenderFindStandardFormat (dpy, PictStandardRGB24); - break; - case CAIRO_CONTENT_ALPHA: - default: - xrender_format = XRenderFindStandardFormat (dpy, PictStandardA8); - } - - pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy), - width, height, xrender_format->depth); - - surface = cairo_xlib_surface_create_with_xrender_format (dpy, pixmap, - DefaultScreenOfDisplay (dpy), - xrender_format, - width, height); - cairo_surface_set_user_data (surface, &_key, - (void *) pixmap, _destroy_pixmap); - } else { - XSetWindowAttributes attr; - Visual *visual; - Window w; - - visual = DefaultVisual (dpy, DefaultScreen (dpy)); - xrender_format = XRenderFindVisualFormat (dpy, visual); - if (xrender_format == NULL) { - fprintf (stderr, "X server does not have the Render extension.\n"); - exit (1); - } - attr.override_redirect = True; - w = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0, - width <= 0 ? 1 : width, - height <= 0 ? 1 : height, - 0, xrender_format->depth, - InputOutput, visual, CWOverrideRedirect, &attr); - XMapWindow (dpy, w); - - surface = cairo_xlib_surface_create_with_xrender_format (dpy, w, - DefaultScreenOfDisplay (dpy), - xrender_format, - width, height); - cairo_surface_set_user_data (surface, &_key, (void *) w, _destroy_window); + switch (content) { + case CAIRO_CONTENT_COLOR_ALPHA: + xrender_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); + break; + case CAIRO_CONTENT_COLOR: + xrender_format = XRenderFindStandardFormat (dpy, PictStandardRGB24); + break; + case CAIRO_CONTENT_ALPHA: + default: + xrender_format = XRenderFindStandardFormat (dpy, PictStandardA8); } + pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy), + width, height, xrender_format->depth); + + surface = cairo_xlib_surface_create_with_xrender_format (dpy, pixmap, + DefaultScreenOfDisplay (dpy), + xrender_format, + width, height); + cairo_surface_set_user_data (surface, &_key, + (void *) pixmap, _destroy_pixmap); + return surface; } #endif +#endif #if CAIRO_HAS_GL_GLX_SURFACE #include <cairo-gl.h> @@ -213,6 +218,8 @@ main (int argc, char **argv) cairo_script_interpreter_hooks_t hooks = { #if CAIRO_HAS_XLIB_XRENDER_SURFACE .surface_create = _xrender_surface_create +#elif CAIRO_HAS_XLIB_SURFACE + .surface_create = _xlib_surface_create #elif CAIRO_PDF_SURFACE .surface_create = _pdf_surface_create #elif CAIRO_PS_SURFACE @@ -235,6 +242,9 @@ main (int argc, char **argv) #if CAIRO_HAS_GL_GLX_SURFACE { "--glx", _glx_surface_create }, #endif +#if CAIRO_HAS_XLIB_SURFACE + { "--xlib", _xlib_surface_create }, +#endif #if CAIRO_HAS_PDF_SURFACE { "--pdf", _pdf_surface_create }, #endif |