Commit adec698
fix: guard __del__ against partially-constructed objects (PyPy safe)
On PyPy, the GC may call __del__ on an object whose __init__ raised
before all attributes were set (e.g. SolverGurobi.__init__ raises early
when Gurobi is not installed, before _ownsModel/_venv_loaded are set).
CPython avoids this because reference-counting drops the object
immediately; PyPy's tracing GC processes it later.
Replace bare attribute access in __del__ with getattr(..., default) in:
- SolverGurobi.__del__: guard _ownsModel and _venv_loaded
- SolverHighs.__del__: guard _model (avoid calling Highs_destroy(NULL))
- SolverCbc.__del__: guard _model (avoid calling Cbc_deleteModel(NULL))
- SolverOsi.__del__: guard owns_solver
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 10854ab commit adec698
3 files changed
Lines changed: 9 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1645 | 1645 | | |
1646 | 1646 | | |
1647 | 1647 | | |
1648 | | - | |
| 1648 | + | |
| 1649 | + | |
1649 | 1650 | | |
1650 | 1651 | | |
1651 | 1652 | | |
| |||
1776 | 1777 | | |
1777 | 1778 | | |
1778 | 1779 | | |
1779 | | - | |
| 1780 | + | |
1780 | 1781 | | |
1781 | 1782 | | |
1782 | 1783 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
431 | | - | |
432 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
433 | 434 | | |
434 | 435 | | |
435 | | - | |
| 436 | + | |
436 | 437 | | |
437 | 438 | | |
438 | 439 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
800 | 800 | | |
801 | 801 | | |
802 | 802 | | |
803 | | - | |
| 803 | + | |
| 804 | + | |
804 | 805 | | |
805 | 806 | | |
806 | 807 | | |
| |||
0 commit comments