Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ceedbd

Browse filesBrowse files
committed
Simplify filename tracking in FT2Font.
We don't need to separately track (and maintain refcounts) for PyFT2Font.fname; we can simply infer it from py_file (the file object) as needed. Note that if FT2Font was directly constructed with a file-like arg, the fname attribute (both previously and with this PR) is the file-like, not its name.
1 parent 8a8dd90 commit 0ceedbd
Copy full SHA for 0ceedbd

File tree

Expand file treeCollapse file tree

1 file changed

+5
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-11
lines changed

‎src/ft2font_wrapper.cpp

Copy file name to clipboardExpand all lines: src/ft2font_wrapper.cpp
+5-11Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ typedef struct
258258
{
259259
PyObject_HEAD
260260
FT2Font *x;
261-
PyObject *fname;
262261
PyObject *py_file;
263262
FT_StreamRec stream;
264263
Py_ssize_t shape[2];
@@ -317,7 +316,6 @@ static PyObject *PyFT2Font_new(PyTypeObject *type, PyObject *args, PyObject *kwd
317316
PyFT2Font *self;
318317
self = (PyFT2Font *)type->tp_alloc(type, 0);
319318
self->x = NULL;
320-
self->fname = NULL;
321319
self->py_file = NULL;
322320
memset(&self->stream, 0, sizeof(FT_StreamRec));
323321
return (PyObject *)self;
@@ -408,9 +406,6 @@ static int PyFT2Font_init(PyFT2Font *self, PyObject *args, PyObject *kwds)
408406

409407
CALL_CPP_INIT("FT2Font->set_kerning_factor", (self->x->set_kerning_factor(kerning_factor)));
410408

411-
Py_INCREF(filename);
412-
self->fname = filename;
413-
414409
exit:
415410
return PyErr_Occurred() ? -1 : 0;
416411
}
@@ -419,7 +414,6 @@ static void PyFT2Font_dealloc(PyFT2Font *self)
419414
{
420415
delete self->x;
421416
Py_XDECREF(self->py_file);
422-
Py_XDECREF(self->fname);
423417
Py_TYPE(self)->tp_free((PyObject *)self);
424418
}
425419

@@ -1420,12 +1414,12 @@ static PyObject *PyFT2Font_underline_thickness(PyFT2Font *self, void *closure)
14201414

14211415
static PyObject *PyFT2Font_fname(PyFT2Font *self, void *closure)
14221416
{
1423-
if (self->fname) {
1424-
Py_INCREF(self->fname);
1425-
return self->fname;
1417+
if (self->stream.close) { // Called passed a filename to the constructor.
1418+
return PyObject_GetAttrString(self->py_file, "name");
1419+
} else {
1420+
Py_INCREF(self->py_file);
1421+
return self->py_file;
14261422
}
1427-
1428-
Py_RETURN_NONE;
14291423
}
14301424

14311425
static int PyFT2Font_get_buffer(PyFT2Font *self, Py_buffer *buf, int flags)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.