Issue 37072: PyNode_Compile() crashes in Python 3.8. (original) (raw)

The code:

#include <Python.h>

int main(int argc, char *argv[]) { FILE *fp = NULL; PyObject *co = NULL; struct _node *n = NULL; const char * filename = "/dev/null";

Py_Initialize();

fprintf(stderr, "START\n");

fp = fopen(filename, "r");

fprintf(stderr, "CALL PyParser_SimpleParseFile()\n");

n = PyParser_SimpleParseFile(fp, filename, Py_file_input);

fprintf(stderr, "CALL PyNode_Compile()\n");

co = (PyObject *)PyNode_Compile(n, filename);

fprintf(stderr, "DONE\n");

Py_Finalize();

return 0;

}

has worked fine since Python 2.3 (and maybe earlier) through Python 3.7, but now crashes in Python 3.8.

It crashes in PyNode_Compile().

START CALL PyParser_SimpleParseFile() CALL PyNode_Compile() Segmentation fault: 11

Although it is part of the public interface of compile.h, the PyNode_Compile() seems never to actually be called anywhere in Python itself, and perhaps isn't even covered by tests. So if Python 3.8 internal changes mean this function implementation needs to be changed, that fact may have been missed.