Better fix for -Wcast-align errors

This commit is contained in:
Behdad Esfahbod 2019-01-22 12:45:40 +01:00
parent 81ec543d80
commit 447323b85a
5 changed files with 35 additions and 49 deletions

View File

@ -139,13 +139,10 @@ hb_font_get_nominal_glyphs_default (hb_font_t *font,
for (unsigned int i = 0; i < count; i++)
{
if (!font->get_nominal_glyph (*first_unicode, first_glyph))
return i;
return i;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
first_unicode = (hb_codepoint_t *) &StructAtOffset<char> (first_unicode, unicode_stride);
first_glyph = (hb_codepoint_t *) &StructAtOffset<char> (first_glyph, glyph_stride);
#pragma GCC diagnostic pop
first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
}
return count;
}
@ -241,11 +238,8 @@ hb_font_get_glyph_h_advances_default (hb_font_t* font,
for (unsigned int i = 0; i < count; i++)
{
*first_advance = font->get_glyph_h_advance (*first_glyph);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
first_glyph = (hb_codepoint_t *) &StructAtOffset<char> (first_glyph, glyph_stride);
first_advance = (hb_position_t *) &StructAtOffset<char> (first_advance, advance_stride);
#pragma GCC diagnostic pop
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
}
return;
}
@ -256,10 +250,7 @@ hb_font_get_glyph_h_advances_default (hb_font_t* font,
for (unsigned int i = 0; i < count; i++)
{
*first_advance = font->parent_scale_x_distance (*first_advance);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
first_advance = (hb_position_t *) &StructAtOffset<char> (first_advance, advance_stride);
#pragma GCC diagnostic pop
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
}
}
@ -279,11 +270,8 @@ hb_font_get_glyph_v_advances_default (hb_font_t* font,
for (unsigned int i = 0; i < count; i++)
{
*first_advance = font->get_glyph_v_advance (*first_glyph);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
first_glyph = (hb_codepoint_t *) &StructAtOffset<char> (first_glyph, glyph_stride);
first_advance = (hb_position_t *) &StructAtOffset<char> (first_advance, advance_stride);
#pragma GCC diagnostic pop
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
}
return;
}
@ -294,10 +282,7 @@ hb_font_get_glyph_v_advances_default (hb_font_t* font,
for (unsigned int i = 0; i < count; i++)
{
*first_advance = font->parent_scale_y_distance (*first_advance);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
first_advance = (hb_position_t *) &StructAtOffset<char> (first_advance, advance_stride);
#pragma GCC diagnostic pop
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
}
}

View File

@ -228,11 +228,8 @@ hb_ft_get_nominal_glyphs (hb_font_t *font HB_UNUSED,
done < count && (*first_glyph = FT_Get_Char_Index (ft_font->ft_face, *first_unicode));
done++)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
first_unicode = (hb_codepoint_t *) &StructAtOffset<char> (first_unicode, unicode_stride);
first_glyph = (hb_codepoint_t *) &StructAtOffset<char> (first_glyph, glyph_stride);
#pragma GCC diagnostic pop
first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
}
/* We don't need to do ft_font->symbol dance here, since HB calls the singular
* nominal_glyph() for what we don't handle here. */
@ -295,11 +292,8 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data,
}
*first_advance = (v * mult + (1<<9)) >> 10;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
first_glyph = (hb_codepoint_t *) &StructAtOffset<char> (first_glyph, glyph_stride);
first_advance = (hb_position_t *) &StructAtOffset<char> (first_advance, advance_stride);
#pragma GCC diagnostic pop
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
}
}

View File

@ -64,6 +64,22 @@ static inline const Type& StructAtOffset(const void *P, unsigned int offset)
template<typename Type>
static inline Type& StructAtOffset(void *P, unsigned int offset)
{ return * reinterpret_cast<Type*> ((char *) P + offset); }
template<typename Type>
static inline const Type& StructAtOffsetUnaligned(const void *P, unsigned int offset)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
return * reinterpret_cast<Type*> ((char *) P + offset);
#pragma GCC diagnostic pop
}
template<typename Type>
static inline Type& StructAtOffsetUnaligned(void *P, unsigned int offset)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
return * reinterpret_cast<Type*> ((char *) P + offset);
#pragma GCC diagnostic pop
}
/* StructAfter<T>(X) returns the struct T& that is placed after X.
* Works with X of variable size also. X must implement get_size() */

View File

@ -1054,11 +1054,8 @@ struct cmap
done < count && get_glyph_funcZ (get_glyph_data, *first_unicode, first_glyph);
done++)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
first_unicode = (hb_codepoint_t *) &StructAtOffset<char> (first_unicode, unicode_stride);
first_glyph = (hb_codepoint_t *) &StructAtOffset<char> (first_glyph, glyph_stride);
#pragma GCC diagnostic pop
first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
}
return done;
}

View File

@ -112,11 +112,8 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data,
for (unsigned int i = 0; i < count; i++)
{
*first_advance = font->em_scale_x (hmtx.get_advance (*first_glyph, font));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
first_glyph = (hb_codepoint_t *) &StructAtOffset<char> (first_glyph, glyph_stride);
first_advance = (hb_position_t *) &StructAtOffset<char> (first_advance, advance_stride);
#pragma GCC diagnostic pop
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
}
}
@ -135,11 +132,8 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data,
for (unsigned int i = 0; i < count; i++)
{
*first_advance = font->em_scale_y (-(int) vmtx.get_advance (*first_glyph, font));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
first_glyph = (hb_codepoint_t *) &StructAtOffset<char> (first_glyph, glyph_stride);
first_advance = (hb_position_t *) &StructAtOffset<char> (first_advance, advance_stride);
#pragma GCC diagnostic pop
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
}
}