Segfault when defining a C extension type with empty docstring on PyPy3

Create issue
Issue #3055 resolved
timfel created an issue

Given this type definition, we get a segfault when calling PyType_Ready on it:

static PyTypeObject NativeType = {
    PyVarObject_HEAD_INIT(NULL, 0)
    "NativeType.NativeType",
    sizeof(NativeTypeObject),
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT,
    "",
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    PyType_GenericAlloc,
    PyType_GenericNew,
    PyObject_Del,
};

We can avoid the segfault if we give 0 or NULL instead of the empty docstring in line 22. Or just adding any character to make the docstring longer than 0-length also makes it work.

Comments (2)

  1. Armin Rigo

    It's because we call space.newtext() on something that ends up being None in case the docstring is empty (cpyext/typeobject.py)

  2. Log in to comment