Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redo {spmatrix,matrix}iter_tp to use PyType_Ready #165

Merged
merged 1 commit into from
Apr 16, 2020
Merged

redo {spmatrix,matrix}iter_tp to use PyType_Ready #165

merged 1 commit into from
Apr 16, 2020

Conversation

mattip
Copy link
Contributor

@mattip mattip commented Apr 16, 2020

xref conda-forge/cvxopt-feedstock#45

It turns out spmatrixiter_tp and matrixiter_tp never called PyType_Ready. They also modified pointers to functions on new instances, which is not officially supported by the C-API. This caused segfaults when using cvxopt on PyPy.

@mattip
Copy link
Contributor Author

mattip commented Apr 16, 2020

Would you accept a PR to add PyPy to your CI matrix?

@@ -2006,7 +2008,7 @@ PyMODINIT_FUNC initbase(void)
if (PyType_Ready(&matrix_tp) < 0)
INITERROR;

if (PyType_Ready(&matrix_tp) < 0)
if (PyType_Ready(&matrixiter_tp) < 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible typo? Maybe the intent was to do this all along?

@@ -2150,9 +2150,6 @@ matrix_iter(matrix *obj)
it = PyObject_GC_New(matrixiter, &matrixiter_tp);
if (!it) return NULL;

matrixiter_tp.tp_iter = PyObject_SelfIter;
matrixiter_tp.tp_getattro = PyObject_GenericGetAttr;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works on CPython and PyPy, but is not really supported in general. All assignments are meant to be done before calling PyType_Ready

@h-vetinari
Copy link

Thanks for investigating & fixing this!

@martinandersen
do you think it would be possible to have a patch release with this (and possibly #164) to unblock the pypy-migration on conda-forge? :)

@coveralls
Copy link

coveralls commented Apr 16, 2020

Coverage Status

Coverage remained the same at 55.475% when pulling b62085e on mattip:fix-iter into cc46cbd on cvxopt:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.004%) to 55.471% when pulling b62085e on mattip:fix-iter into cc46cbd on cvxopt:master.

@martinandersen martinandersen merged commit f1e9437 into cvxopt:master Apr 16, 2020
@martinandersen
Copy link
Contributor

Yes, I'll prepare a patch release tomorrow

@h-vetinari
Copy link

Yes, I'll prepare a patch release tomorrow

Awesome, thanks!

sanurielf pushed a commit to sanurielf/kvxopt that referenced this pull request Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants