@@ -254,6 +254,25 @@ pylongwriter_create(PyObject *module, PyObject *args)
254254}
255255
256256
257+ static PyObject *
258+ pylongwriter_finish_bug (PyObject * module , PyObject * Py_UNUSED (args ))
259+ {
260+ void * writer_digits ;
261+ PyLongWriter * writer = PyLongWriter_Create (0 , 3 , & writer_digits );
262+ if (writer == NULL ) {
263+ return NULL ;
264+ }
265+
266+ assert (PyLong_GetNativeLayout ()-> digit_size == sizeof (digit ));
267+ digit * digits = writer_digits ;
268+ digits [0 ] = 1 ;
269+ digits [1 ] = 1 ;
270+ // Oops, digits[2] is left uninitialized on purpose
271+ // to test PyLongWriter_Finish()
272+ return PyLongWriter_Finish (writer );
273+ }
274+
275+
257276static PyObject *
258277get_pylong_layout (PyObject * module , PyObject * Py_UNUSED (args ))
259278{
@@ -271,6 +290,7 @@ static PyMethodDef test_methods[] = {
271290 {"pylong_aspid" , pylong_aspid , METH_O },
272291 {"pylong_export" , pylong_export , METH_O },
273292 {"pylongwriter_create" , pylongwriter_create , METH_VARARGS },
293+ {"pylongwriter_finish_bug" , pylongwriter_finish_bug , METH_NOARGS },
274294 {"get_pylong_layout" , get_pylong_layout , METH_NOARGS },
275295 {"pylong_ispositive" , pylong_ispositive , METH_O },
276296 {"pylong_isnegative" , pylong_isnegative , METH_O },
0 commit comments