Skip to content

Commit ed719e2

Browse files
committed
Switch PyArg_ParseTupleAndKeywords from "es" to "s".
This avoids having to call PyMem_Free ourselves. Note that all call sites either already use utf-8 (which "s" does), or use ascii but then match the string against some ascii-only strings (or glyph names), so the change is fine encoding-wise.
1 parent 4f41946 commit ed719e2

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

src/_macosx.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,9 @@ static CGFloat _get_device_scale(CGContextRef cr)
813813
PyObject *args, PyObject *kwds)
814814
{
815815
char* title;
816-
if(!PyArg_ParseTuple(args, "es", "UTF-8", &title))
816+
if (!PyArg_ParseTuple(args, "s", &title)) {
817817
return NULL;
818-
818+
}
819819
Window* window = self->window;
820820
if(window)
821821
{
@@ -826,7 +826,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
826826
[window setTitle: ns_title];
827827
[pool release];
828828
}
829-
PyMem_Free(title);
830829
Py_RETURN_NONE;
831830
}
832831

@@ -1370,17 +1369,16 @@ -(void)save_figure:(id)sender
13701369
int result;
13711370
const char* title;
13721371
char* default_filename;
1373-
if(!PyArg_ParseTuple(args, "ses", &title, "UTF-8", &default_filename))
1372+
if (!PyArg_ParseTuple(args, "ss", &title, &default_filename)) {
13741373
return NULL;
1375-
1374+
}
13761375
NSSavePanel* panel = [NSSavePanel savePanel];
13771376
[panel setTitle: [NSString stringWithCString: title
13781377
encoding: NSASCIIStringEncoding]];
13791378
NSString* ns_default_filename =
13801379
[[NSString alloc]
13811380
initWithCString: default_filename
13821381
encoding: NSUTF8StringEncoding];
1383-
PyMem_Free(default_filename);
13841382
#ifdef COMPILING_FOR_10_6
13851383
[panel setNameFieldStringValue: ns_default_filename];
13861384
result = [panel runModal];

src/ft2font_wrapper.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,15 +1066,10 @@ static PyObject *PyFT2Font_get_name_index(PyFT2Font *self, PyObject *args, PyObj
10661066
{
10671067
char *glyphname;
10681068
long name_index;
1069-
1070-
if (!PyArg_ParseTuple(args, "es:get_name_index", "ascii", &glyphname)) {
1069+
if (!PyArg_ParseTuple(args, "s:get_name_index", &glyphname)) {
10711070
return NULL;
10721071
}
1073-
10741072
CALL_CPP("get_name_index", name_index = self->x->get_name_index(glyphname));
1075-
1076-
PyMem_Free(glyphname);
1077-
10781073
return PyLong_FromLong(name_index);
10791074
}
10801075

@@ -1114,8 +1109,7 @@ const char *PyFT2Font_get_sfnt_table__doc__ =
11141109
static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObject *kwds)
11151110
{
11161111
char *tagname;
1117-
1118-
if (!PyArg_ParseTuple(args, "es:get_sfnt_table", "ascii", &tagname)) {
1112+
if (!PyArg_ParseTuple(args, "s:get_sfnt_table", "ascii", &tagname)) {
11191113
return NULL;
11201114
}
11211115

@@ -1128,8 +1122,6 @@ static PyObject *PyFT2Font_get_sfnt_table(PyFT2Font *self, PyObject *args, PyObj
11281122
}
11291123
}
11301124

1131-
PyMem_Free(tagname);
1132-
11331125
void *table = FT_Get_Sfnt_Table(self->x->get_face(), (FT_Sfnt_Tag)tag);
11341126
if (!table) {
11351127
Py_RETURN_NONE;

0 commit comments

Comments
 (0)