Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f33ca39

Browse files
efiringtacaswell
authored andcommitted
Merge pull request #7853 from QuLogic/Py_BuildValue-types
[MRG] Use exact types for Py_BuildValue.
1 parent 126e13b commit f33ca39

File tree

2 files changed

+60
-57
lines changed

2 files changed

+60
-57
lines changed

src/ft2font.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ extern "C" {
1818
/*
1919
By definition, FT_FIXED as 2 16bit values stored in a single long.
2020
*/
21-
#define FIXED_MAJOR(val) (long)((val & 0xffff000) >> 16)
22-
#define FIXED_MINOR(val) (long)(val & 0xffff)
21+
#define FIXED_MAJOR(val) (signed short)((val & 0xffff0000) >> 16)
22+
#define FIXED_MINOR(val) (unsigned short)(val & 0xffff)
2323

2424
// the FreeType string rendered into a width, height buffer
2525
class FT2Image

src/ft2font_wrapper.cpp

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static void PyGlyph_dealloc(PyGlyph *self)
276276
static PyObject *PyGlyph_get_bbox(PyGlyph *self, void *closure)
277277
{
278278
return Py_BuildValue(
279-
"iiii", self->bbox.xMin, self->bbox.yMin, self->bbox.xMax, self->bbox.yMax);
279+
"llll", self->bbox.xMin, self->bbox.yMin, self->bbox.xMax, self->bbox.yMax);
280280
}
281281

282282
static PyTypeObject *PyGlyph_init_type(PyObject *m, PyTypeObject *type)
@@ -1026,7 +1026,7 @@ static PyObject *PyFT2Font_get_sfnt(PyFT2Font *self, PyObject *args, PyObject *k
10261026
}
10271027

10281028
PyObject *key = Py_BuildValue(
1029-
"iiii", sfnt.platform_id, sfnt.encoding_id, sfnt.language_id, sfnt.name_id);
1029+
"HHHH", sfnt.platform_id, sfnt.encoding_id, sfnt.language_id, sfnt.name_id);
10301030
if (key == NULL) {
10311031
Py_DECREF(names);
10321032
return NULL;
@@ -1090,7 +1090,7 @@ static PyObject *PyFT2Font_get_ps_font_info(PyFT2Font *self, PyObject *args, PyO
10901090
return NULL;
10911091
}
10921092

1093-
return Py_BuildValue("sssssliii",
1093+
return Py_BuildValue("ssssslbhH",
10941094
fontinfo.version ? fontinfo.version : "",
10951095
fontinfo.notice ? fontinfo.notice : "",
10961096
fontinfo.full_name ? fontinfo.full_name : "",
@@ -1135,8 +1135,8 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
11351135
switch (tag) {
11361136
case 0: {
11371137
char head_dict[] =
1138-
"{s:(h,h), s:(h,h), s:l, s:l, s:i, s:i,"
1139-
"s:(l,l), s:(l,l), s:h, s:h, s:h, s:h, s:i, s:i, s:h, s:h, s:h}";
1138+
"{s:(h,H), s:(h,H), s:l, s:l, s:H, s:H,"
1139+
"s:(l,l), s:(l,l), s:h, s:h, s:h, s:h, s:H, s:H, s:h, s:h, s:h}";
11401140
TT_Header *t = (TT_Header *)table;
11411141
return Py_BuildValue(head_dict,
11421142
"version",
@@ -1150,9 +1150,9 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
11501150
"magicNumber",
11511151
t->Magic_Number,
11521152
"flags",
1153-
(unsigned)t->Flags,
1153+
t->Flags,
11541154
"unitsPerEm",
1155-
(unsigned)t->Units_Per_EM,
1155+
t->Units_Per_EM,
11561156
"created",
11571157
t->Created[0],
11581158
t->Created[1],
@@ -1168,9 +1168,9 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
11681168
"yMax",
11691169
t->yMax,
11701170
"macStyle",
1171-
(unsigned)t->Mac_Style,
1171+
t->Mac_Style,
11721172
"lowestRecPPEM",
1173-
(unsigned)t->Lowest_Rec_PPEM,
1173+
t->Lowest_Rec_PPEM,
11741174
"fontDirectionHint",
11751175
t->Font_Direction,
11761176
"indexToLocFormat",
@@ -1180,64 +1180,64 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
11801180
}
11811181
case 1: {
11821182
char maxp_dict[] =
1183-
"{s:(h,h), s:i, s:i, s:i, s:i, s:i, s:i,"
1184-
"s:i, s:i, s:i, s:i, s:i, s:i, s:i, s:i}";
1183+
"{s:(h,H), s:H, s:H, s:H, s:H, s:H, s:H,"
1184+
"s:H, s:H, s:H, s:H, s:H, s:H, s:H, s:H}";
11851185
TT_MaxProfile *t = (TT_MaxProfile *)table;
11861186
return Py_BuildValue(maxp_dict,
11871187
"version",
11881188
FIXED_MAJOR(t->version),
11891189
FIXED_MINOR(t->version),
11901190
"numGlyphs",
1191-
(unsigned)t->numGlyphs,
1191+
t->numGlyphs,
11921192
"maxPoints",
1193-
(unsigned)t->maxPoints,
1193+
t->maxPoints,
11941194
"maxContours",
1195-
(unsigned)t->maxContours,
1195+
t->maxContours,
11961196
"maxComponentPoints",
1197-
(unsigned)t->maxCompositePoints,
1197+
t->maxCompositePoints,
11981198
"maxComponentContours",
1199-
(unsigned)t->maxCompositeContours,
1199+
t->maxCompositeContours,
12001200
"maxZones",
1201-
(unsigned)t->maxZones,
1201+
t->maxZones,
12021202
"maxTwilightPoints",
1203-
(unsigned)t->maxTwilightPoints,
1203+
t->maxTwilightPoints,
12041204
"maxStorage",
1205-
(unsigned)t->maxStorage,
1205+
t->maxStorage,
12061206
"maxFunctionDefs",
1207-
(unsigned)t->maxFunctionDefs,
1207+
t->maxFunctionDefs,
12081208
"maxInstructionDefs",
1209-
(unsigned)t->maxInstructionDefs,
1209+
t->maxInstructionDefs,
12101210
"maxStackElements",
1211-
(unsigned)t->maxStackElements,
1211+
t->maxStackElements,
12121212
"maxSizeOfInstructions",
1213-
(unsigned)t->maxSizeOfInstructions,
1213+
t->maxSizeOfInstructions,
12141214
"maxComponentElements",
1215-
(unsigned)t->maxComponentElements,
1215+
t->maxComponentElements,
12161216
"maxComponentDepth",
1217-
(unsigned)t->maxComponentDepth);
1217+
t->maxComponentDepth);
12181218
}
12191219
case 2: {
12201220
#if PY3K
12211221
char os_2_dict[] =
1222-
"{s:h, s:h, s:h, s:h, s:h, s:h, s:h, s:h,"
1223-
"s:h, s:h, s:h, s:h, s:h, s:h, s:h, s:h, s:y#, s:(llll),"
1224-
"s:y#, s:h, s:h, s:h}";
1222+
"{s:H, s:h, s:H, s:H, s:H, s:h, s:h, s:h,"
1223+
"s:h, s:h, s:h, s:h, s:h, s:h, s:h, s:h, s:y#, s:(kkkk),"
1224+
"s:y#, s:H, s:H, s:H}";
12251225
#else
12261226
char os_2_dict[] =
1227-
"{s:h, s:h, s:h, s:h, s:h, s:h, s:h, s:h,"
1228-
"s:h, s:h, s:h, s:h, s:h, s:h, s:h, s:h, s:s#, s:(llll),"
1229-
"s:s#, s:h, s:h, s:h}";
1227+
"{s:H, s:h, s:H, s:H, s:H, s:h, s:h, s:h,"
1228+
"s:h, s:h, s:h, s:h, s:h, s:h, s:h, s:h, s:s#, s:(kkkk),"
1229+
"s:s#, s:H, s:H, s:H}";
12301230
#endif
12311231
TT_OS2 *t = (TT_OS2 *)table;
12321232
return Py_BuildValue(os_2_dict,
12331233
"version",
1234-
(unsigned)t->version,
1234+
t->version,
12351235
"xAvgCharWidth",
12361236
t->xAvgCharWidth,
12371237
"usWeightClass",
1238-
(unsigned)t->usWeightClass,
1238+
t->usWeightClass,
12391239
"usWidthClass",
1240-
(unsigned)t->usWidthClass,
1240+
t->usWidthClass,
12411241
"fsType",
12421242
t->fsType,
12431243
"ySubscriptXSize",
@@ -1266,24 +1266,24 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
12661266
t->panose,
12671267
10,
12681268
"ulCharRange",
1269-
(unsigned long)t->ulUnicodeRange1,
1270-
(unsigned long)t->ulUnicodeRange2,
1271-
(unsigned long)t->ulUnicodeRange3,
1272-
(unsigned long)t->ulUnicodeRange4,
1269+
t->ulUnicodeRange1,
1270+
t->ulUnicodeRange2,
1271+
t->ulUnicodeRange3,
1272+
t->ulUnicodeRange4,
12731273
"achVendID",
12741274
t->achVendID,
12751275
4,
12761276
"fsSelection",
1277-
(unsigned)t->fsSelection,
1277+
t->fsSelection,
12781278
"fsFirstCharIndex",
1279-
(unsigned)t->usFirstCharIndex,
1279+
t->usFirstCharIndex,
12801280
"fsLastCharIndex",
1281-
(unsigned)t->usLastCharIndex);
1281+
t->usLastCharIndex);
12821282
}
12831283
case 3: {
12841284
char hhea_dict[] =
1285-
"{s:(h,h), s:h, s:h, s:h, s:i, s:h, s:h, s:h,"
1286-
"s:h, s:h, s:h, s:h, s:i}";
1285+
"{s:(h,H), s:h, s:h, s:h, s:H, s:h, s:h, s:h,"
1286+
"s:h, s:h, s:h, s:h, s:H}";
12871287
TT_HoriHeader *t = (TT_HoriHeader *)table;
12881288
return Py_BuildValue(hhea_dict,
12891289
"version",
@@ -1296,7 +1296,7 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
12961296
"lineGap",
12971297
t->Line_Gap,
12981298
"advanceWidthMax",
1299-
(unsigned)t->advance_Width_Max,
1299+
t->advance_Width_Max,
13001300
"minLeftBearing",
13011301
t->min_Left_Side_Bearing,
13021302
"minRightBearing",
@@ -1312,12 +1312,12 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
13121312
"metricDataFormat",
13131313
t->metric_Data_Format,
13141314
"numOfLongHorMetrics",
1315-
(unsigned)t->number_Of_HMetrics);
1315+
t->number_Of_HMetrics);
13161316
}
13171317
case 4: {
13181318
char vhea_dict[] =
1319-
"{s:(h,h), s:h, s:h, s:h, s:i, s:h, s:h, s:h,"
1320-
"s:h, s:h, s:h, s:h, s:i}";
1319+
"{s:(h,H), s:h, s:h, s:h, s:H, s:h, s:h, s:h,"
1320+
"s:h, s:h, s:h, s:h, s:H}";
13211321
TT_VertHeader *t = (TT_VertHeader *)table;
13221322
return Py_BuildValue(vhea_dict,
13231323
"version",
@@ -1330,7 +1330,7 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
13301330
"vertTypoLineGap",
13311331
t->Line_Gap,
13321332
"advanceHeightMax",
1333-
(unsigned)t->advance_Height_Max,
1333+
t->advance_Height_Max,
13341334
"minTopSideBearing",
13351335
t->min_Top_Side_Bearing,
13361336
"minBottomSizeBearing",
@@ -1346,10 +1346,10 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
13461346
"metricDataFormat",
13471347
t->metric_Data_Format,
13481348
"numOfLongVerMetrics",
1349-
(unsigned)t->number_Of_VMetrics);
1349+
t->number_Of_VMetrics);
13501350
}
13511351
case 5: {
1352-
char post_dict[] = "{s:(h,h), s:(h,h), s:h, s:h, s:k, s:k, s:k, s:k, s:k}";
1352+
char post_dict[] = "{s:(h,H), s:(h,H), s:h, s:h, s:k, s:k, s:k, s:k, s:k}";
13531353
TT_Postscript *t = (TT_Postscript *)table;
13541354
return Py_BuildValue(post_dict,
13551355
"format",
@@ -1376,12 +1376,12 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
13761376
case 6: {
13771377
#if PY3K
13781378
char pclt_dict[] =
1379-
"{s:(h,h), s:k, s:H, s:H, s:H, s:H, s:H, s:H, s:y, s:y, s:b, s:b, "
1380-
"s:b}";
1379+
"{s:(h,H), s:k, s:H, s:H, s:H, s:H, s:H, s:H, s:y#, s:y#, s:b, "
1380+
"s:b, s:b}";
13811381
#else
13821382
char pclt_dict[] =
1383-
"{s:(h,h), s:k, s:H, s:H, s:H, s:H, s:H, s:H, s:s, s:s, s:b, s:b, "
1384-
"s:b}";
1383+
"{s:(h,H), s:k, s:H, s:H, s:H, s:H, s:H, s:H, s:s#, s:s#, s:b, "
1384+
"s:b, s:b}";
13851385
#endif
13861386
TT_PCLT *t = (TT_PCLT *)table;
13871387
return Py_BuildValue(pclt_dict,
@@ -1404,8 +1404,10 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
14041404
t->SymbolSet,
14051405
"typeFace",
14061406
t->TypeFace,
1407+
16,
14071408
"characterComplement",
14081409
t->CharacterComplement,
1410+
8,
14091411
"strokeWeight",
14101412
t->StrokeWeight,
14111413
"widthType",
@@ -1528,7 +1530,8 @@ static PyObject *PyFT2Font_get_bbox(PyFT2Font *self, void *closure)
15281530
{
15291531
FT_BBox *bbox = &(self->x->get_face()->bbox);
15301532

1531-
return Py_BuildValue("iiii", bbox->xMin, bbox->yMin, bbox->xMax, bbox->yMax);
1533+
return Py_BuildValue("llll",
1534+
bbox->xMin, bbox->yMin, bbox->xMax, bbox->yMax);
15321535
}
15331536

15341537
static PyObject *PyFT2Font_ascender(PyFT2Font *self, void *closure)

0 commit comments

Comments
 (0)