[tlbuild] graphite2-1.2.0 and gcc3

Peter Breitenlohner peb at mppmu.mpg.de
Wed Jan 9 11:54:19 CET 2013


On Tue, 8 Jan 2013, Peter Breitenlohner wrote:

> I know and I had the same problem with the linux->mingw32 gcc-3.4.5.  The
> attached patch solves this problem.  However, there were subsequent problems
> compiling harfbuzz were I did not see any simple workaround.  Consequently I
> have built the gcc-4.6.3 cross compiler and now use that one (and gcc-4.4.7
> for linux).

Hi Karl,

here now a patch that allows to compile harfbuzz with gcc-3.4.6 (and perhaps
also with gcc-3.3.x).  This is ugly and I'd certainly prefer to require a
sufficiently recent compiler (I think everyone could install gcc4).

The C++ code in harfbuzz is designed to do something that can not be done in
C, i.e., to declare the template analogue of something like
   char *strchr(char *s, int c);
   const char *strchr(const char *s, int c);

This would avoid the anomaly that in C
   char *un_const(const char *s)
   { return strchr(s, s[0]); }
cast a const string into a non-const one without the compiler knowing
about it.

Regards
Peter
-------------- next part --------------
diff -ur harfbuzz-0.9.10.orig/src/hb-open-type-private.hh harfbuzz-0.9.10/src/hb-open-type-private.hh
--- harfbuzz-0.9.10.orig/src/hb-open-type-private.hh	2013-01-03 07:14:24.000000000 +0100
+++ harfbuzz-0.9.10/src/hb-open-type-private.hh	2013-01-09 10:51:57.414196925 +0100
@@ -44,19 +44,19 @@
 
 /* Cast to struct T, reference to reference */
 template<typename Type, typename TObject>
-inline const Type& CastR(const TObject &X)
+inline const Type& CCastR(const TObject &X)
 { return reinterpret_cast<const Type&> (X); }
 template<typename Type, typename TObject>
 inline Type& CastR(TObject &X)
 { return reinterpret_cast<Type&> (X); }
 
 /* Cast to struct T, pointer to pointer */
-template<typename Type, typename TObject>
-inline const Type* CastP(const TObject *X)
-{ return reinterpret_cast<const Type*> (X); }
+//template<typename Type, typename TObject>
+//inline const Type* CastP(const TObject *X)
+//{ return reinterpret_cast<const Type*> (X); }
 template<typename Type, typename TObject>
 inline Type* CastP(TObject *X)
-{ return reinterpret_cast<Type*> (X); }
+{ return (Type*) (X); }
 
 /* StructAtOffset<T>(P,Ofs) returns the struct T& that is placed at memory
  * location pointed to by P plus Ofs bytes. */
@@ -70,7 +70,7 @@
 /* StructAfter<T>(X) returns the struct T& that is placed after X.
  * Works with X of variable size also.  X must implement get_size() */
 template<typename Type, typename TObject>
-inline const Type& StructAfter(const TObject &X)
+inline const Type& CStructAfter(const TObject &X)
 { return StructAtOffset<Type>(&X, X.get_size()); }
 template<typename Type, typename TObject>
 inline Type& StructAfter(TObject &X)
diff -ur harfbuzz-0.9.10.orig/src/hb-ot-layout-common-private.hh harfbuzz-0.9.10/src/hb-ot-layout-common-private.hh
--- harfbuzz-0.9.10.orig/src/hb-ot-layout-common-private.hh	2013-01-03 07:14:24.000000000 +0100
+++ harfbuzz-0.9.10/src/hb-ot-layout-common-private.hh	2013-01-09 10:53:52.942202598 +0100
@@ -569,7 +569,7 @@
     unsigned int flag = lookupFlag;
     if (unlikely (flag & LookupFlag::UseMarkFilteringSet))
     {
-      const USHORT &markFilteringSet = StructAfter<USHORT> (subTable);
+      const USHORT &markFilteringSet = CStructAfter<USHORT> (subTable);
       flag += (markFilteringSet << 16);
     }
     return flag;
diff -ur harfbuzz-0.9.10.orig/src/hb-ot-layout-gpos-table.hh harfbuzz-0.9.10/src/hb-ot-layout-gpos-table.hh
--- harfbuzz-0.9.10.orig/src/hb-ot-layout-gpos-table.hh	2013-01-03 07:14:24.000000000 +0100
+++ harfbuzz-0.9.10/src/hb-ot-layout-gpos-table.hh	2013-01-09 10:39:16.938401358 +0100
@@ -1425,7 +1425,7 @@
 struct PosLookup : Lookup
 {
   inline const PosLookupSubTable& get_subtable (unsigned int i) const
-  { return this+CastR<OffsetArrayOf<PosLookupSubTable> > (subTable)[i]; }
+  { return this+CCastR<OffsetArrayOf<PosLookupSubTable> > (subTable)[i]; }
 
   template <typename context_t>
   inline typename context_t::return_t process (context_t *c) const
@@ -1519,7 +1519,7 @@
   static const hb_tag_t Tag	= HB_OT_TAG_GPOS;
 
   inline const PosLookup& get_lookup (unsigned int i) const
-  { return CastR<PosLookup> (GSUBGPOS::get_lookup (i)); }
+  { return CCastR<PosLookup> (GSUBGPOS::get_lookup (i)); }
 
   static inline void position_start (hb_font_t *font, hb_buffer_t *buffer);
   static inline void position_finish (hb_font_t *font, hb_buffer_t *buffer, hb_bool_t zero_width_attahced_marks);
diff -ur harfbuzz-0.9.10.orig/src/hb-ot-layout-gsub-table.hh harfbuzz-0.9.10/src/hb-ot-layout-gsub-table.hh
--- harfbuzz-0.9.10.orig/src/hb-ot-layout-gsub-table.hh	2013-01-03 07:14:24.000000000 +0100
+++ harfbuzz-0.9.10/src/hb-ot-layout-gsub-table.hh	2013-01-09 11:06:29.409256083 +0100
@@ -903,7 +903,7 @@
   inline void closure (hb_closure_context_t *c) const
   {
     TRACE_CLOSURE (this);
-    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
+    const OffsetArrayOf<Coverage> &lookahead = CStructAfter<OffsetArrayOf<Coverage> > (backtrack);
 
     unsigned int count;
 
@@ -917,7 +917,7 @@
       if (!(this+lookahead[i]).intersects (c->glyphs))
         return;
 
-    const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
+    const ArrayOf<GlyphID> &substitute = CStructAfter<ArrayOf<GlyphID> > (lookahead);
     Coverage::Iter iter;
     for (iter.init (this+coverage); iter.more (); iter.next ()) {
       if (c->glyphs->has (iter.get_glyph ()))
@@ -929,7 +929,7 @@
   {
     TRACE_COLLECT_GLYPHS (this);
 
-    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
+    const OffsetArrayOf<Coverage> &lookahead = CStructAfter<OffsetArrayOf<Coverage> > (backtrack);
 
     unsigned int count;
 
@@ -943,7 +943,7 @@
     for (unsigned int i = 0; i < count; i++)
       (this+lookahead[i]).add_coverage (c->after);
 
-    const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
+    const ArrayOf<GlyphID> &substitute = CStructAfter<ArrayOf<GlyphID> > (lookahead);
     count = substitute.len;
     for (unsigned int i = 0; i < count; i++)
       c->output->add (substitute[i]);
@@ -969,8 +969,8 @@
     unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
     if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
 
-    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
-    const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
+    const OffsetArrayOf<Coverage> &lookahead = CStructAfter<OffsetArrayOf<Coverage> > (backtrack);
+    const ArrayOf<GlyphID> &substitute = CStructAfter<ArrayOf<GlyphID> > (lookahead);
 
     if (match_backtrack (c,
 			 backtrack.len, (USHORT *) backtrack.array,
@@ -1124,7 +1124,7 @@
 struct SubstLookup : Lookup
 {
   inline const SubstLookupSubTable& get_subtable (unsigned int i) const
-  { return this+CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable)[i]; }
+  { return this+CCastR<OffsetArrayOf<SubstLookupSubTable> > (subTable)[i]; }
 
   inline static bool lookup_type_is_reverse (unsigned int lookup_type)
   { return lookup_type == SubstLookupSubTable::ReverseChainSingle; }
@@ -1133,7 +1133,7 @@
   {
     unsigned int type = get_type ();
     if (unlikely (type == SubstLookupSubTable::Extension))
-      return CastR<ExtensionSubst> (get_subtable(0)).is_reverse ();
+      return CCastR<ExtensionSubst> (get_subtable(0)).is_reverse ();
     return lookup_type_is_reverse (type);
   }
 
@@ -1339,7 +1339,7 @@
   static const hb_tag_t Tag	= HB_OT_TAG_GSUB;
 
   inline const SubstLookup& get_lookup (unsigned int i) const
-  { return CastR<SubstLookup> (GSUBGPOS::get_lookup (i)); }
+  { return CCastR<SubstLookup> (GSUBGPOS::get_lookup (i)); }
 
   static inline void substitute_start (hb_font_t *font, hb_buffer_t *buffer);
   static inline void substitute_finish (hb_font_t *font, hb_buffer_t *buffer);
@@ -1382,7 +1382,7 @@
 {
   unsigned int type = get_type ();
   if (unlikely (type == SubstLookupSubTable::Extension))
-    return CastR<ExtensionSubst> (get_subtable<SubstLookupSubTable>()).is_reverse ();
+    return CCastR<ExtensionSubst> (get_subtable<SubstLookupSubTable>()).is_reverse ();
   return SubstLookup::lookup_type_is_reverse (type);
 }
 
diff -ur harfbuzz-0.9.10.orig/src/hb-ot-layout-gsubgpos-private.hh harfbuzz-0.9.10/src/hb-ot-layout-gsubgpos-private.hh
--- harfbuzz-0.9.10.orig/src/hb-ot-layout-gsubgpos-private.hh	2013-01-04 13:31:51.000000000 +0100
+++ harfbuzz-0.9.10/src/hb-ot-layout-gsubgpos-private.hh	2013-01-09 11:05:27.442041180 +0100
@@ -1503,9 +1503,9 @@
   inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const
   {
     TRACE_CLOSURE (this);
-    const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
-    const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
-    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
+    const HeadlessArrayOf<USHORT> &input = CStructAfter<HeadlessArrayOf<USHORT> > (backtrack);
+    const ArrayOf<USHORT> &lookahead = CStructAfter<ArrayOf<USHORT> > (input);
+    const ArrayOf<LookupRecord> &lookup = CStructAfter<ArrayOf<LookupRecord> > (lookahead);
     chain_context_closure_lookup (c,
 				  backtrack.len, backtrack.array,
 				  input.len, input.array,
@@ -1517,9 +1517,9 @@
   inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const
   {
     TRACE_COLLECT_GLYPHS (this);
-    const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
-    const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
-    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
+    const HeadlessArrayOf<USHORT> &input = CStructAfter<HeadlessArrayOf<USHORT> > (backtrack);
+    const ArrayOf<USHORT> &lookahead = CStructAfter<ArrayOf<USHORT> > (input);
+    const ArrayOf<LookupRecord> &lookup = CStructAfter<ArrayOf<LookupRecord> > (lookahead);
     chain_context_collect_glyphs_lookup (c,
 					 backtrack.len, backtrack.array,
 					 input.len, input.array,
@@ -1531,9 +1531,9 @@
   inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
   {
     TRACE_WOULD_APPLY (this);
-    const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
-    const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
-    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
+    const HeadlessArrayOf<USHORT> &input = CStructAfter<HeadlessArrayOf<USHORT> > (backtrack);
+    const ArrayOf<USHORT> &lookahead = CStructAfter<ArrayOf<USHORT> > (input);
+    const ArrayOf<LookupRecord> &lookup = CStructAfter<ArrayOf<LookupRecord> > (lookahead);
     return TRACE_RETURN (chain_context_would_apply_lookup (c,
 							   backtrack.len, backtrack.array,
 							   input.len, input.array,
@@ -1544,9 +1544,9 @@
   inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
   {
     TRACE_APPLY (this);
-    const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
-    const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
-    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
+    const HeadlessArrayOf<USHORT> &input = CStructAfter<HeadlessArrayOf<USHORT> > (backtrack);
+    const ArrayOf<USHORT> &lookahead = CStructAfter<ArrayOf<USHORT> > (input);
+    const ArrayOf<LookupRecord> &lookup = CStructAfter<ArrayOf<LookupRecord> > (lookahead);
     return TRACE_RETURN (chain_context_apply_lookup (c,
 						     backtrack.len, backtrack.array,
 						     input.len, input.array,
@@ -1848,13 +1848,13 @@
   inline void closure (hb_closure_context_t *c) const
   {
     TRACE_CLOSURE (this);
-    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
+    const OffsetArrayOf<Coverage> &input = CStructAfter<OffsetArrayOf<Coverage> > (backtrack);
 
     if (!(this+input[0]).intersects (c->glyphs))
       return;
 
-    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
-    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
+    const OffsetArrayOf<Coverage> &lookahead = CStructAfter<OffsetArrayOf<Coverage> > (input);
+    const ArrayOf<LookupRecord> &lookup = CStructAfter<ArrayOf<LookupRecord> > (lookahead);
     struct ChainContextClosureLookupContext lookup_context = {
       {intersects_coverage},
       {this, this, this}
@@ -1870,12 +1870,12 @@
   inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
   {
     TRACE_COLLECT_GLYPHS (this);
-    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
+    const OffsetArrayOf<Coverage> &input = CStructAfter<OffsetArrayOf<Coverage> > (backtrack);
 
     (this+input[0]).add_coverage (c->input);
 
-    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
-    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
+    const OffsetArrayOf<Coverage> &lookahead = CStructAfter<OffsetArrayOf<Coverage> > (input);
+    const ArrayOf<LookupRecord> &lookup = CStructAfter<ArrayOf<LookupRecord> > (lookahead);
     struct ChainContextCollectGlyphsLookupContext lookup_context = {
       {collect_coverage},
       {this, this, this}
@@ -1892,9 +1892,9 @@
   {
     TRACE_WOULD_APPLY (this);
 
-    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
-    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
-    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
+    const OffsetArrayOf<Coverage> &input = CStructAfter<OffsetArrayOf<Coverage> > (backtrack);
+    const OffsetArrayOf<Coverage> &lookahead = CStructAfter<OffsetArrayOf<Coverage> > (input);
+    const ArrayOf<LookupRecord> &lookup = CStructAfter<ArrayOf<LookupRecord> > (lookahead);
     struct ChainContextApplyLookupContext lookup_context = {
       {match_coverage},
       {this, this, this}
@@ -1908,20 +1908,20 @@
 
   inline const Coverage &get_coverage (void) const
   {
-    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
+    const OffsetArrayOf<Coverage> &input = CStructAfter<OffsetArrayOf<Coverage> > (backtrack);
     return this+input[0];
   }
 
   inline bool apply (hb_apply_context_t *c) const
   {
     TRACE_APPLY (this);
-    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
+    const OffsetArrayOf<Coverage> &input = CStructAfter<OffsetArrayOf<Coverage> > (backtrack);
 
     unsigned int index = (this+input[0]).get_coverage (c->buffer->cur().codepoint);
     if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
 
-    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
-    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
+    const OffsetArrayOf<Coverage> &lookahead = CStructAfter<OffsetArrayOf<Coverage> > (input);
+    const ArrayOf<LookupRecord> &lookup = CStructAfter<ArrayOf<LookupRecord> > (lookahead);
     struct ChainContextApplyLookupContext lookup_context = {
       {match_coverage},
       {this, this, this}


More information about the tlbuild mailing list