Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Add check for tp_basicsize
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed May 3, 2015
1 parent 30fe462 commit d4ba872
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/sage/misc/cython_metaclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ static CYTHON_INLINE int Sage_PyType_Ready(PyTypeObject* t)
if (init == NULL || init == PyType_Type.tp_init)
return 0;

/* Safety check: since we didn't call tp_new of metaclass,
* we cannot safely call tp_init if the size of the structure
* differs. */
if (metaclass->tp_basicsize != PyType_Type.tp_basicsize)
{
PyErr_SetString(PyExc_TypeError,
"metaclass is not compatible with 'type' (you cannot use cdef attributes in Cython metaclasses)");
return -1;
}

/* Initialize a tuple (None, None, None) */
if (!NoneNoneNone)
{
Expand Down

0 comments on commit d4ba872

Please sign in to comment.