Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType
Commits:
-
70fd20e6
by Alexei Podtelezhnikov at 2021-02-12T19:28:05-05:00
10 changed files:
- ChangeLog
- include/freetype/internal/compiler-macros.h
- src/base/ftrfork.c
- src/bdf/bdflib.c
- src/gxvalid/gxvcommn.c
- src/psaux/afmparse.c
- src/psnames/psmodule.c
- src/sfnt/sfwoff.c
- src/sfnt/sfwoff2.c
- src/type1/t1afm.c
Changes:
1 |
+2021-02-12 Alexei Podtelezhnikov <apodtele@gmail.com>
|
|
2 |
+ |
|
3 |
+ Decorate qsort callbacks with cdecl.
|
|
4 |
+ |
|
5 |
+ * include/freetype/internal/compiler-macros.h (FT_COMPARE_DEF):
|
|
6 |
+ Add new macro.
|
|
7 |
+ * src/base/ftrfork.c, src/bdf/bdflib.c, src/gxvalid/gxvcommn.c,
|
|
8 |
+ src/psaux/afmparse.c, src/psnames/psmodule.c, src/type1/t1afm.c,
|
|
9 |
+ src/sfnt/sfwoff.c, src/sfnt/sfwoff2.c: Update qsort callbacks.
|
|
10 |
+ |
|
11 |
+ Fixes #1026 when compiling FreeType with an unusual calling convention
|
|
12 |
+ while the C library qsort still expects cdecl.
|
|
13 |
+ |
|
1 | 14 |
2021-02-10 Dominik Röttsches <drott@chromium.org>
|
2 | 15 |
|
3 | 16 |
[sfnt] Implement 'COLR' v1 sweep gradients.
|
... | ... | @@ -267,7 +267,8 @@ FT_BEGIN_HEADER |
267 | 267 |
/* */
|
268 | 268 |
/* FT_CALLBACK_DEF is used to _define_ a callback function, */
|
269 | 269 |
/* located in the same source code file as the structure that uses */
|
270 |
- /* it. */
|
|
270 |
+ /* it. FT_COMPARE_DEF, in addition, ensures the cdecl calling */
|
|
271 |
+ /* convention on x86, required by the C library qsort. */
|
|
271 | 272 |
/* */
|
272 | 273 |
/* FT_BASE_CALLBACK and FT_BASE_CALLBACK_DEF are used to declare */
|
273 | 274 |
/* and define a callback function, respectively, in a similar way */
|
... | ... | @@ -289,6 +290,14 @@ FT_BEGIN_HEADER |
289 | 290 |
#define FT_CALLBACK_DEF( x ) static x
|
290 | 291 |
#endif
|
291 | 292 |
|
293 |
+#if defined( __i386__ )
|
|
294 |
+#define FT_COMPARE_DEF( x ) FT_CALLBACK_DEF( x ) __attribute__(( cdecl ))
|
|
295 |
+#elif defined( _M_IX86 )
|
|
296 |
+#define FT_COMPARE_DEF( x ) FT_CALLBACK_DEF( x ) __cdecl
|
|
297 |
+#else
|
|
298 |
+#define FT_COMPARE_DEF( x ) FT_CALLBACK_DEF( x )
|
|
299 |
+#endif
|
|
300 |
+ |
|
292 | 301 |
#define FT_BASE_CALLBACK( x ) FT_FUNCTION_DECLARATION( x )
|
293 | 302 |
#define FT_BASE_CALLBACK_DEF( x ) FT_FUNCTION_DEFINITION( x )
|
294 | 303 |
|
... | ... | @@ -167,16 +167,11 @@ |
167 | 167 |
}
|
168 | 168 |
|
169 | 169 |
|
170 |
- static int
|
|
171 |
- ft_raccess_sort_ref_by_id( FT_RFork_Ref* a,
|
|
172 |
- FT_RFork_Ref* b )
|
|
170 |
+ FT_COMPARE_DEF( int )
|
|
171 |
+ ft_raccess_sort_ref_by_id( const void* a,
|
|
172 |
+ const void* b )
|
|
173 | 173 |
{
|
174 |
- if ( a->res_id < b->res_id )
|
|
175 |
- return -1;
|
|
176 |
- else if ( a->res_id > b->res_id )
|
|
177 |
- return 1;
|
|
178 |
- else
|
|
179 |
- return 0;
|
|
174 |
+ return ( (FT_RFork_Ref*)a )->res_id - ( (FT_RFork_Ref*)b )->res_id;
|
|
180 | 175 |
}
|
181 | 176 |
|
182 | 177 |
|
... | ... | @@ -294,8 +289,7 @@ |
294 | 289 |
ft_qsort( ref,
|
295 | 290 |
(size_t)*count,
|
296 | 291 |
sizeof ( FT_RFork_Ref ),
|
297 |
- ( int(*)(const void*,
|
|
298 |
- const void*) )ft_raccess_sort_ref_by_id );
|
|
292 |
+ ft_raccess_sort_ref_by_id );
|
|
299 | 293 |
|
300 | 294 |
FT_TRACE3(( " -- sort resources by their ids --\n" ));
|
301 | 295 |
|
... | ... | @@ -807,7 +807,7 @@ |
807 | 807 |
|
808 | 808 |
|
809 | 809 |
/* Routine to compare two glyphs by encoding so they can be sorted. */
|
810 |
- static int
|
|
810 |
+ FT_COMPARE_DEF( int )
|
|
811 | 811 |
by_encoding( const void* a,
|
812 | 812 |
const void* b )
|
813 | 813 |
{
|
... | ... | @@ -46,16 +46,11 @@ |
46 | 46 |
/*************************************************************************/
|
47 | 47 |
/*************************************************************************/
|
48 | 48 |
|
49 |
- static int
|
|
50 |
- gxv_compare_ushort_offset( FT_UShort* a,
|
|
51 |
- FT_UShort* b )
|
|
49 |
+ FT_COMPARE_DEF( int )
|
|
50 |
+ gxv_compare_ushort_offset( const void* a,
|
|
51 |
+ const void* b )
|
|
52 | 52 |
{
|
53 |
- if ( *a < *b )
|
|
54 |
- return -1;
|
|
55 |
- else if ( *a > *b )
|
|
56 |
- return 1;
|
|
57 |
- else
|
|
58 |
- return 0;
|
|
53 |
+ return *(FT_UShort*)a - *(FT_UShort*)b;
|
|
59 | 54 |
}
|
60 | 55 |
|
61 | 56 |
|
... | ... | @@ -78,7 +73,7 @@ |
78 | 73 |
buff[nmemb] = limit;
|
79 | 74 |
|
80 | 75 |
ft_qsort( buff, ( nmemb + 1 ), sizeof ( FT_UShort ),
|
81 |
- ( int(*)(const void*, const void*) )gxv_compare_ushort_offset );
|
|
76 |
+ gxv_compare_ushort_offset );
|
|
82 | 77 |
|
83 | 78 |
if ( buff[nmemb] > limit )
|
84 | 79 |
FT_INVALID_OFFSET;
|
... | ... | @@ -111,13 +106,17 @@ |
111 | 106 |
/*************************************************************************/
|
112 | 107 |
/*************************************************************************/
|
113 | 108 |
|
114 |
- static int
|
|
115 |
- gxv_compare_ulong_offset( FT_ULong* a,
|
|
116 |
- FT_ULong* b )
|
|
109 |
+ FT_COMPARE_DEF( int )
|
|
110 |
+ gxv_compare_ulong_offset( const void* a,
|
|
111 |
+ const void* b )
|
|
117 | 112 |
{
|
118 |
- if ( *a < *b )
|
|
113 |
+ FT_ULong a_ = *(FT_ULong*)a;
|
|
114 |
+ FT_ULong b_ = *(FT_ULong*)b;
|
|
115 |
+ |
|
116 |
+ |
|
117 |
+ if ( a_ < b_ )
|
|
119 | 118 |
return -1;
|
120 |
- else if ( *a > *b )
|
|
119 |
+ else if ( a_ > b_ )
|
|
121 | 120 |
return 1;
|
122 | 121 |
else
|
123 | 122 |
return 0;
|
... | ... | @@ -143,7 +142,7 @@ |
143 | 142 |
buff[nmemb] = limit;
|
144 | 143 |
|
145 | 144 |
ft_qsort( buff, ( nmemb + 1 ), sizeof ( FT_ULong ),
|
146 |
- ( int(*)(const void*, const void*) )gxv_compare_ulong_offset );
|
|
145 |
+ gxv_compare_ulong_offset );
|
|
147 | 146 |
|
148 | 147 |
if ( buff[nmemb] > limit )
|
149 | 148 |
FT_INVALID_OFFSET;
|
... | ... | @@ -667,7 +667,7 @@ |
667 | 667 |
|
668 | 668 |
|
669 | 669 |
/* compare two kerning pairs */
|
670 |
- FT_CALLBACK_DEF( int )
|
|
670 |
+ FT_COMPARE_DEF( int )
|
|
671 | 671 |
afm_compare_kern_pairs( const void* a,
|
672 | 672 |
const void* b )
|
673 | 673 |
{
|
... | ... | @@ -179,7 +179,7 @@ |
179 | 179 |
|
180 | 180 |
|
181 | 181 |
/* ft_qsort callback to sort the unicode map */
|
182 |
- FT_CALLBACK_DEF( int )
|
|
182 |
+ FT_COMPARE_DEF( int )
|
|
183 | 183 |
compare_uni_maps( const void* a,
|
184 | 184 |
const void* b )
|
185 | 185 |
{
|
... | ... | @@ -66,7 +66,7 @@ |
66 | 66 |
}
|
67 | 67 |
|
68 | 68 |
|
69 |
- FT_CALLBACK_DEF( int )
|
|
69 |
+ FT_COMPARE_DEF( int )
|
|
70 | 70 |
compare_offsets( const void* a,
|
71 | 71 |
const void* b )
|
72 | 72 |
{
|
... | ... | @@ -101,7 +101,7 @@ |
101 | 101 |
}
|
102 | 102 |
|
103 | 103 |
|
104 |
- FT_CALLBACK_DEF( int )
|
|
104 |
+ FT_COMPARE_DEF( int )
|
|
105 | 105 |
compare_tags( const void* a,
|
106 | 106 |
const void* b )
|
107 | 107 |
{
|
... | ... | @@ -83,7 +83,7 @@ |
83 | 83 |
|
84 | 84 |
|
85 | 85 |
/* compare two kerning pairs */
|
86 |
- FT_CALLBACK_DEF( int )
|
|
86 |
+ FT_COMPARE_DEF( int )
|
|
87 | 87 |
compare_kern_pairs( const void* a,
|
88 | 88 |
const void* b )
|
89 | 89 |
{
|