Use uintptr_t for all casts between pointer and integer

On 64-bit windows, long is 32-bit. When compiling there are a large
number of warnings about mismatched sizes when casting long to/from a
pointer.

Use the (u)intptr_t type for any integer that will have a pointer stored
in it. Use a (u)intptr_t cast when integers are stored in pointers to
silence warnings.

Fixes #263
This commit is contained in:
Adrian Johnson 2021-07-25 06:18:37 +09:30
parent 099d71fb9f
commit 9fbf427548
24 changed files with 74 additions and 74 deletions

View file

@ -84,7 +84,7 @@
* not be initialized if so desired.
**/
typedef struct _cairo_cache_entry {
unsigned long hash;
uintptr_t hash;
unsigned long size;
} cairo_cache_entry_t;

View file

@ -315,18 +315,18 @@ _cairo_cache_foreach (cairo_cache_t *cache,
closure);
}
unsigned long
uintptr_t
_cairo_hash_string (const char *c)
{
/* This is the djb2 hash. */
unsigned long hash = _CAIRO_HASH_INIT_VALUE;
uintptr_t hash = _CAIRO_HASH_INIT_VALUE;
while (c && *c)
hash = ((hash << 5) + hash) + *c++;
return hash;
}
unsigned long
_cairo_hash_bytes (unsigned long hash,
uintptr_t
_cairo_hash_bytes (uintptr_t hash,
const void *ptr,
unsigned int length)
{

View file

@ -39,7 +39,7 @@
//#define DUMP_GRADIENTS_TO_PNG
static unsigned long
static uintptr_t
_cairo_cogl_linear_gradient_hash (unsigned int n_stops,
const cairo_gradient_stop_t *stops)
{
@ -49,7 +49,7 @@ _cairo_cogl_linear_gradient_hash (unsigned int n_stops,
static cairo_cogl_linear_gradient_t *
_cairo_cogl_linear_gradient_lookup (cairo_cogl_device_t *ctx,
unsigned long hash,
uintptr_t hash,
unsigned int n_stops,
const cairo_gradient_stop_t *stops)
{
@ -359,7 +359,7 @@ _cairo_cogl_get_linear_gradient (cairo_cogl_device_t *device,
const cairo_bool_t need_mirrored_gradient,
cairo_cogl_linear_gradient_t **gradient_out)
{
unsigned long hash;
uintptr_t hash;
cairo_cogl_linear_gradient_t *gradient;
cairo_cogl_linear_texture_entry_t *entry;
cairo_gradient_stop_t *internal_stops;

View file

@ -700,7 +700,7 @@ _cairo_cogl_fill_to_primitive (cairo_cogl_surface_t *surface,
cairo_cogl_path_fill_meta_t *acquired_meta;
cairo_cogl_path_fill_meta_t *insert_meta = NULL;
cairo_cogl_device_t *dev = to_device (surface->base.device);
unsigned long hash;
uintptr_t hash;
*primitive = NULL;
@ -842,8 +842,8 @@ _cairo_cogl_path_stroke_meta_destroy (cairo_cogl_path_stroke_meta_t *meta)
_cairo_freelist_free (meta->freelist, meta);
}
static unsigned long
_cairo_cogl_stroke_style_hash (unsigned long hash,
static uintptr_t
_cairo_cogl_stroke_style_hash (uintptr_t hash,
const cairo_stroke_style_t *style)
{
unsigned int i;
@ -874,7 +874,7 @@ _cairo_cogl_stroke_to_primitive (cairo_cogl_surface_t *surface,
cairo_cogl_path_stroke_meta_t *insert_meta = NULL;
cairo_matrix_t identity;
cairo_cogl_device_t *dev = to_device (surface->base.device);
unsigned long hash;
uintptr_t hash;
*primitive = NULL;

View file

@ -397,7 +397,7 @@ _cairo_ft_unscaled_font_init_key (cairo_ft_unscaled_font_t *key,
int id,
FT_Face face)
{
unsigned long hash;
uintptr_t hash;
key->from_face = from_face;
key->filename = filename;
@ -406,8 +406,8 @@ _cairo_ft_unscaled_font_init_key (cairo_ft_unscaled_font_t *key,
hash = _cairo_hash_string (filename);
/* the constants are just arbitrary primes */
hash += ((unsigned long) id) * 1607;
hash += ((unsigned long) face) * 2137;
hash += ((uintptr_t) id) * 1607;
hash += ((uintptr_t) face) * 2137;
key->base.hash_entry.hash = hash;
}

View file

@ -188,7 +188,7 @@ _cairo_gl_gradient_render (const cairo_gl_context_t *ctx,
return CAIRO_STATUS_SUCCESS;
}
static unsigned long
static uintptr_t
_cairo_gl_gradient_hash (unsigned int n_stops,
const cairo_gradient_stop_t *stops)
{
@ -199,7 +199,7 @@ _cairo_gl_gradient_hash (unsigned int n_stops,
static cairo_gl_gradient_t *
_cairo_gl_gradient_lookup (cairo_gl_context_t *ctx,
unsigned long hash,
uintptr_t hash,
unsigned int n_stops,
const cairo_gradient_stop_t *stops)
{
@ -230,7 +230,7 @@ _cairo_gl_gradient_create (cairo_gl_context_t *ctx,
const cairo_gradient_stop_t *stops,
cairo_gl_gradient_t **gradient_out)
{
unsigned long hash;
uintptr_t hash;
cairo_gl_gradient_t *gradient;
cairo_status_t status;
int tex_width;

View file

@ -898,7 +898,7 @@ composite_glyphs (void *_dst,
index = index | (xphase << 24) | (yphase << 26);
glyph = pixman_glyph_cache_lookup (glyph_cache, info->font, (void *)index);
glyph = pixman_glyph_cache_lookup (glyph_cache, info->font, (void *)(uintptr_t)index);
if (!glyph) {
cairo_scaled_glyph_t *scaled_glyph;
cairo_image_surface_t *glyph_surface;
@ -916,7 +916,7 @@ composite_glyphs (void *_dst,
goto out_thaw;
glyph_surface = scaled_glyph->surface;
glyph = pixman_glyph_cache_insert (glyph_cache, info->font, (void *)index,
glyph = pixman_glyph_cache_insert (glyph_cache, info->font, (void *)(uintptr_t)index,
glyph_surface->base.device_transform.x0,
glyph_surface->base.device_transform.y0,
glyph_surface->pixman_image);

View file

@ -284,19 +284,19 @@ _cairo_mempool_init (cairo_mempool_t *pool,
void *base, size_t bytes,
int min_bits, int num_sizes)
{
unsigned long tmp;
uintptr_t tmp;
int num_blocks;
int i;
/* Align the start to an integral chunk */
tmp = ((unsigned long) base) & ((1 << min_bits) - 1);
tmp = ((uintptr_t) base) & ((1 << min_bits) - 1);
if (tmp) {
tmp = (1 << min_bits) - tmp;
base = (char *)base + tmp;
bytes -= tmp;
}
assert ((((unsigned long) base) & ((1 << min_bits) - 1)) == 0);
assert ((((uintptr_t) base) & ((1 << min_bits) - 1)) == 0);
assert (num_sizes < ARRAY_LENGTH (pool->free));
pool->base = base;

View file

@ -126,7 +126,7 @@ _cairo_path_fixed_append (cairo_path_fixed_t *path,
cairo_fixed_t tx,
cairo_fixed_t ty);
cairo_private unsigned long
cairo_private uintptr_t
_cairo_path_fixed_hash (const cairo_path_fixed_t *path);
cairo_private unsigned long

View file

@ -172,10 +172,10 @@ _cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
return CAIRO_STATUS_SUCCESS;
}
unsigned long
uintptr_t
_cairo_path_fixed_hash (const cairo_path_fixed_t *path)
{
unsigned long hash = _CAIRO_HASH_INIT_VALUE;
uintptr_t hash = _CAIRO_HASH_INIT_VALUE;
const cairo_path_buf_t *buf;
unsigned int count;

View file

@ -308,15 +308,15 @@ cairo_private cairo_int_status_t
_cairo_pattern_get_ink_extents (const cairo_pattern_t *pattern,
cairo_rectangle_int_t *extents);
cairo_private unsigned long
cairo_private uintptr_t
_cairo_pattern_hash (const cairo_pattern_t *pattern);
cairo_private unsigned long
_cairo_linear_pattern_hash (unsigned long hash,
cairo_private uintptr_t
_cairo_linear_pattern_hash (uintptr_t hash,
const cairo_linear_pattern_t *linear);
cairo_private unsigned long
_cairo_radial_pattern_hash (unsigned long hash,
cairo_private uintptr_t
_cairo_radial_pattern_hash (uintptr_t hash,
const cairo_radial_pattern_t *radial);
cairo_private cairo_bool_t

View file

@ -3863,8 +3863,8 @@ _cairo_pattern_get_ink_extents (const cairo_pattern_t *pattern,
return CAIRO_STATUS_SUCCESS;
}
static unsigned long
_cairo_solid_pattern_hash (unsigned long hash,
static uintptr_t
_cairo_solid_pattern_hash (uintptr_t hash,
const cairo_solid_pattern_t *solid)
{
hash = _cairo_hash_bytes (hash, &solid->color, sizeof (solid->color));
@ -3872,8 +3872,8 @@ _cairo_solid_pattern_hash (unsigned long hash,
return hash;
}
static unsigned long
_cairo_gradient_color_stops_hash (unsigned long hash,
static uintptr_t
_cairo_gradient_color_stops_hash (uintptr_t hash,
const cairo_gradient_pattern_t *gradient)
{
unsigned int n;
@ -3894,8 +3894,8 @@ _cairo_gradient_color_stops_hash (unsigned long hash,
return hash;
}
unsigned long
_cairo_linear_pattern_hash (unsigned long hash,
uintptr_t
_cairo_linear_pattern_hash (uintptr_t hash,
const cairo_linear_pattern_t *linear)
{
hash = _cairo_hash_bytes (hash, &linear->pd1, sizeof (linear->pd1));
@ -3904,8 +3904,8 @@ _cairo_linear_pattern_hash (unsigned long hash,
return _cairo_gradient_color_stops_hash (hash, &linear->base);
}
unsigned long
_cairo_radial_pattern_hash (unsigned long hash,
uintptr_t
_cairo_radial_pattern_hash (uintptr_t hash,
const cairo_radial_pattern_t *radial)
{
hash = _cairo_hash_bytes (hash, &radial->cd1.center, sizeof (radial->cd1.center));
@ -3916,8 +3916,8 @@ _cairo_radial_pattern_hash (unsigned long hash,
return _cairo_gradient_color_stops_hash (hash, &radial->base);
}
static unsigned long
_cairo_mesh_pattern_hash (unsigned long hash, const cairo_mesh_pattern_t *mesh)
static uintptr_t
_cairo_mesh_pattern_hash (uintptr_t hash, const cairo_mesh_pattern_t *mesh)
{
const cairo_mesh_patch_t *patch = _cairo_array_index_const (&mesh->patches, 0);
unsigned int i, n = _cairo_array_num_elements (&mesh->patches);
@ -3928,8 +3928,8 @@ _cairo_mesh_pattern_hash (unsigned long hash, const cairo_mesh_pattern_t *mesh)
return hash;
}
static unsigned long
_cairo_surface_pattern_hash (unsigned long hash,
static uintptr_t
_cairo_surface_pattern_hash (uintptr_t hash,
const cairo_surface_pattern_t *surface)
{
hash ^= surface->surface->unique_id;
@ -3937,8 +3937,8 @@ _cairo_surface_pattern_hash (unsigned long hash,
return hash;
}
static unsigned long
_cairo_raster_source_pattern_hash (unsigned long hash,
static uintptr_t
_cairo_raster_source_pattern_hash (uintptr_t hash,
const cairo_raster_source_pattern_t *raster)
{
hash ^= (uintptr_t)raster->user_data;
@ -3946,10 +3946,10 @@ _cairo_raster_source_pattern_hash (unsigned long hash,
return hash;
}
unsigned long
uintptr_t
_cairo_pattern_hash (const cairo_pattern_t *pattern)
{
unsigned long hash = _CAIRO_HASH_INIT_VALUE;
uintptr_t hash = _CAIRO_HASH_INIT_VALUE;
if (pattern->status)
return 0;

View file

@ -255,12 +255,12 @@ _cairo_sub_font_init_key (cairo_sub_font_t *sub_font,
{
if (sub_font->is_scaled)
{
sub_font->base.hash = (unsigned long) scaled_font;
sub_font->base.hash = (uintptr_t) scaled_font;
sub_font->scaled_font = scaled_font;
}
else
{
sub_font->base.hash = (unsigned long) scaled_font->font_face;
sub_font->base.hash = (uintptr_t) scaled_font->font_face;
sub_font->scaled_font = scaled_font;
}
}

View file

@ -56,7 +56,7 @@
* size and transformation and a certain set of font options.
**/
static uint32_t
static uintptr_t
_cairo_scaled_font_compute_hash (cairo_scaled_font_t *scaled_font);
/* Global Glyph Cache
@ -626,17 +626,17 @@ _hash_mix_bits (uint32_t hash)
return hash;
}
static uint32_t
static uintptr_t
_cairo_scaled_font_compute_hash (cairo_scaled_font_t *scaled_font)
{
uint32_t hash = FNV1_32_INIT;
uintptr_t hash = FNV1_32_INIT;
/* We do a bytewise hash on the font matrices */
hash = _hash_matrix_fnv (&scaled_font->font_matrix, hash);
hash = _hash_matrix_fnv (&scaled_font->ctm, hash);
hash = _hash_mix_bits (hash);
hash ^= (unsigned long) scaled_font->original_font_face;
hash ^= (uintptr_t) scaled_font->original_font_face;
hash ^= cairo_font_options_hash (&scaled_font->options);
/* final mixing of bits */
@ -2879,7 +2879,7 @@ _cairo_scaled_font_allocate_glyph (cairo_scaled_font_t *scaled_font,
if (unlikely (page == NULL))
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
page->cache_entry.hash = (unsigned long) scaled_font;
page->cache_entry.hash = (uintptr_t) scaled_font;
page->scaled_font = scaled_font;
page->cache_entry.size = 1; /* XXX occupancy weighting? */
page->num_glyphs = 0;

View file

@ -3047,7 +3047,7 @@ _emit_scaled_glyph_vector (cairo_script_surface_t *surface,
index = ++font_private->subset_glyph_index;
scaled_glyph->dev_private_key = ctx;
scaled_glyph->dev_private = (void *) index;
scaled_glyph->dev_private = (void *)(uintptr_t)index;
_cairo_output_stream_printf (ctx->stream,
"%lu <<\n"
@ -3095,7 +3095,7 @@ _emit_scaled_glyph_bitmap (cairo_script_surface_t *surface,
index = ++font_private->subset_glyph_index;
scaled_glyph->dev_private_key = ctx;
scaled_glyph->dev_private = (void *) index;
scaled_glyph->dev_private = (void *)(uintptr_t)index;
_cairo_output_stream_printf (ctx->stream,
"%lu <<\n"
@ -3395,7 +3395,7 @@ _cairo_script_surface_show_text_glyphs (void *abstract_surface,
goto BAIL;
}
if ((long unsigned) scaled_glyph->dev_private > 256)
if ((uintptr_t)scaled_glyph->dev_private > 256)
break;
}
}
@ -3466,7 +3466,7 @@ _cairo_script_surface_show_text_glyphs (void *abstract_surface,
if (font_private->has_sfnt)
c = glyphs[n].index;
else
c = (uint8_t) (long unsigned) scaled_glyph->dev_private;
c = (uint8_t) (uintptr_t) scaled_glyph->dev_private;
_cairo_output_stream_write (base85_stream, &c, 1);
} else {
@ -3475,7 +3475,7 @@ _cairo_script_surface_show_text_glyphs (void *abstract_surface,
glyphs[n].index);
else
_cairo_output_stream_printf (ctx->stream, " %lu",
(long unsigned) scaled_glyph->dev_private);
(long unsigned) (uintptr_t)scaled_glyph->dev_private);
}
dx = scaled_glyph->metrics.x_advance;

View file

@ -135,7 +135,7 @@ _cairo_toy_font_face_init_key (cairo_toy_font_face_t *key,
cairo_font_slant_t slant,
cairo_font_weight_t weight)
{
unsigned long hash;
uintptr_t hash;
key->family = family;
key->owns_family = FALSE;
@ -145,8 +145,8 @@ _cairo_toy_font_face_init_key (cairo_toy_font_face_t *key,
/* 1607 and 1451 are just a couple of arbitrary primes. */
hash = _cairo_hash_string (family);
hash += ((unsigned long) slant) * 1607;
hash += ((unsigned long) weight) * 1451;
hash += ((uintptr_t) slant) * 1607;
hash += ((uintptr_t) weight) * 1451;
key->base.hash_entry.hash = hash;
}

View file

@ -147,7 +147,7 @@ struct _cairo_observer {
* the entry need not be initialized if so desired.
**/
struct _cairo_hash_entry {
unsigned long hash;
uintptr_t hash;
};
struct _cairo_array {

View file

@ -67,7 +67,7 @@ struct _cairo_vg_context {
cairo_status_t status;
cairo_reference_count_t ref_count;
unsigned long target_id;
uintptr_t target_id;
VGPaint paint;
cairo_vg_surface_t *source;
@ -100,7 +100,7 @@ struct _cairo_vg_surface {
cairo_surface_clipper_t clipper;
unsigned long target_id;
uintptr_t target_id;
};
static const cairo_surface_backend_t cairo_vg_surface_backend;
@ -1782,7 +1782,7 @@ egl_create_target (cairo_vg_context_t *context,
(EGLClientBuffer) surface->image,
config,
NULL);
surface->target_id = (unsigned long) egl_surface;
surface->target_id = (uintptr_t) egl_surface;
return CAIRO_STATUS_SUCCESS;
}

View file

@ -424,11 +424,11 @@ _cairo_user_data_array_foreach (cairo_user_data_array_t *array,
#define _CAIRO_HASH_INIT_VALUE 5381
cairo_private unsigned long
cairo_private uintptr_t
_cairo_hash_string (const char *c);
cairo_private unsigned long
_cairo_hash_bytes (unsigned long hash,
cairo_private uintptr_t
_cairo_hash_bytes (uintptr_t hash,
const void *bytes,
unsigned int length);

View file

@ -1126,7 +1126,7 @@ intel_snapshot_cache_insert (intel_device_t *device,
if (device->snapshot_cache.freeze_count == 0)
_cairo_cache_freeze (&device->snapshot_cache);
surface->snapshot_cache_entry.hash = (unsigned long) surface;
surface->snapshot_cache_entry.hash = (uintptr_t) surface;
status = _cairo_cache_insert (&device->snapshot_cache,
&surface->snapshot_cache_entry);
if (unlikely (status)) {

View file

@ -1960,7 +1960,7 @@ _cairo_win32_font_face_init_key (cairo_win32_font_face_t *key,
LOGFONTW *logfont,
HFONT font)
{
unsigned long hash = _CAIRO_HASH_INIT_VALUE;
uintptr_t hash = _CAIRO_HASH_INIT_VALUE;
key->logfont = *logfont;
key->hfont = font;

View file

@ -284,7 +284,7 @@ typedef cairo_bool_t csi_boolean_t;
typedef csi_status_t (*csi_operator_t) (csi_t *);
typedef float csi_real_t;
typedef long csi_integer_t;
typedef long csi_name_t;
typedef intptr_t csi_name_t;
typedef struct _csi_array csi_array_t;
typedef struct _csi_buffer csi_buffer_t;
typedef struct _csi_compound_object csi_compound_object_t;

View file

@ -262,7 +262,7 @@ lookup_symbol (char *buf, int buflen, const void *ptr)
int bucket;
int len;
bucket = (unsigned long) ptr % (sizeof (symbol_cache_hash) / sizeof (symbol_cache_hash[0]));
bucket = (uintptr_t) ptr % (sizeof (symbol_cache_hash) / sizeof (symbol_cache_hash[0]));
pthread_mutex_lock (&symbol_cache_mutex);
for (cache = symbol_cache_hash[bucket];
cache != NULL;

View file

@ -134,7 +134,7 @@ static void *_dlhandle = RTLD_NEXT;
#else
#error Unexpected pointer size
#endif
#define BUCKET(b, ptr) (((unsigned long) (ptr) >> PTR_SHIFT) % ARRAY_LENGTH (b))
#define BUCKET(b, ptr) (((uintptr_t) (ptr) >> PTR_SHIFT) % ARRAY_LENGTH (b))
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define _BOOLEAN_EXPR(expr) \