pypy3.9: wrong prototype + segv in PyUnicode_DecodeLocale()
This affects pycurl.
/usr/include/pypy3.9/pypy_decl.h declares:
PyAPI_FUNC(struct _object *) PyUnicode_DecodeLocale(struct _object *arg0, const char *arg1);
However, according to https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_DecodeLocale, it should be:
PyObject *PyUnicode_DecodeLocale(const char *str, const char *errors)
i.e. take const char *
as 1st arg.
Given a fixed string, it segfaults.
My cheap reproducer:
foomodule.c:
#define PY_SSIZE_T_CLEAN
#include <Python.h>
static PyObject *
frobnicate(PyObject *self, PyObject *args)
{
return PyUnicode_DecodeLocale("Couldn't bind to 'not-interface-or-ip'\0r-ip",
"surrogateescape");
}
static PyMethodDef FooMethods[] = {
{"frobnicate", frobnicate, METH_VARARGS,
"frobnicate."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
static struct PyModuleDef foomodule = {
PyModuleDef_HEAD_INIT,
"foo", /* name of module */
NULL, /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
FooMethods
};
PyMODINIT_FUNC
PyInit_foo(void)
{
return PyModule_Create(&foomodule);
}
setup.py:
from setuptools import setup, Extension
setup(name='foo',
ext_modules=[
Extension('foo', sources=['foomodule.c']),
])
Using CPython:
>>> import foo
>>> foo.frobnicate()
"Couldn't bind to 'not-interface-or-ip'"
Using PyPy3.9:
>>>> import foo
>>>> foo.frobnicate()
Segmentation fault (core dumped)