Commit cf5958d
committed
Streamline implementation and avoid unsafe
The `reinterpret_cast<instance *>(self)` is unsafe if `__new__` is mocked,
which was actually found in the wild: the mock returned `None` for `self`.
This was inconsequential because `inst` is currently cast straight back to
`PyObject *` to compute `all_type_info()`, which is empty if `self` is not
a pybind11 `instance`, and then `inst` is never dereferenced. However, the
unsafe detour through `instance *` is easily avoided and the updated
implementation is less prone to accidents while debugging or refactoring.reinterpret_cast<instance *>() introduced with PR #2152
1 parent d708836 commit cf5958d
2 files changed
+19
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | 183 | | |
195 | 184 | | |
196 | 185 | | |
| |||
201 | 190 | | |
202 | 191 | | |
203 | 192 | | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
| 193 | + | |
208 | 194 | | |
209 | | - | |
| 195 | + | |
210 | 196 | | |
211 | 197 | | |
212 | 198 | | |
213 | 199 | | |
214 | 200 | | |
215 | 201 | | |
216 | | - | |
217 | 202 | | |
218 | 203 | | |
219 | 204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
339 | 346 | | |
340 | 347 | | |
341 | 348 | | |
| |||
378 | 385 | | |
379 | 386 | | |
380 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
381 | 398 | | |
382 | 399 | | |
383 | 400 | | |
| |||
0 commit comments