Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Commit77bff5f
committed
Don't abort on FT2Font weakref.
Currently, import weakref, matplotlib.ft2font weakref.ref(matplotlib.ft2font.FT2Font("/usr/share/fonts/TTF/DejaVuSans.ttf"))aborts Py3 with terminate called after throwing an instance of 'char const*' Fatal Python error: Abortedwhereas on Py2 a normal `TypeError: cannot create weak reference to'matplotlib.ft2font.FT2Font' object` is raised.This is because the following happens:- Py3 sets the TypeError for failure to create a weakref.- The FT2Font object gets GC'd as nothing is referring to it (yes, creating a weakref to a temporary is a bit silly).- The FT2Font destructor calls close_file_callback, which calls mpl_PyFile_DupClose, which calls PyObject_AsFileDescriptor... which, on Py3, calls the fileno() method on the file object.- PyObject_AsFileDescriptor fails because the originally set TypeError has not been cleared, so mpl_PyFile_DupClose likewise fails, causing close_file_callback to throw a C++ exception.Instead, carefully stash and restore the current exception state, bothin mpl_PyFile_DupClose, and likewise below, in mpl_PyFile_CloseFile (thelatter is needed because otherwise PyObject_CallMethod will clear theexception, cf comment in CPython's Objects/abstract.c: /* PyObject_Call() must not be called with an exception set, because it may clear it (directly or indirectly) and so the caller loses its exception */Note that if an exception *actually* gets raised by mpl_PyFile_DupCloseor mpl_PyFile_CloseFile, it will overwrite the TypeError. Strictlyspeaking, on Py3, it may be preferrable to chain the exceptions, butthis seems a bit overkill (mostly, I just want to avoid aborting thewhole Python process).1 parentc0bceb1 commit77bff5f
1 file changed
+25
-5
lines changedLines changed: 25 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
126 | 126 |
| |
127 | 127 |
| |
128 | 128 |
| |
| 129 | + | |
| 130 | + | |
| 131 | + | |
129 | 132 |
| |
130 | 133 |
| |
131 | 134 |
| |
| |||
136 | 139 |
| |
137 | 140 |
| |
138 | 141 |
| |
139 |
| - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
140 | 145 |
| |
141 | 146 |
| |
142 |
| - | |
| 147 | + | |
143 | 148 |
| |
144 | 149 |
| |
145 | 150 |
| |
146 | 151 |
| |
147 |
| - | |
| 152 | + | |
148 | 153 |
| |
149 | 154 |
| |
150 | 155 |
| |
151 | 156 |
| |
152 | 157 |
| |
153 |
| - | |
| 158 | + | |
154 | 159 |
| |
155 | 160 |
| |
156 | 161 |
| |
| 162 | + | |
157 | 163 |
| |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
158 | 169 |
| |
159 | 170 |
| |
160 | 171 |
| |
| |||
200 | 211 |
| |
201 | 212 |
| |
202 | 213 |
| |
| 214 | + | |
| 215 | + | |
| 216 | + | |
203 | 217 |
| |
204 | 218 |
| |
205 | 219 |
| |
206 | 220 |
| |
207 |
| - | |
| 221 | + | |
208 | 222 |
| |
209 | 223 |
| |
| 224 | + | |
210 | 225 |
| |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
211 | 231 |
| |
212 | 232 |
| |
213 | 233 |
| |
|
0 commit comments
Comments
(0)