I am trying to print PyObject and 'Segmentation fault' occured. I want to use PyObject_Print. How can I solve the problem?
int main(){
Py_Initialize();
///////////////////////////////////////////
PyObject *tmp1 = PyLong_FromLong((1<<29)*3);
PyObject *tmp2 = PyLong_FromLong((1<<20)*41+1264);
PyObject *u;
u = PyNumber_Multiply(tmp1,tmp2);
PyObject_Print(u,stdout,Py_PRINT_RAW); // Segmentation fault here
const char* uu = PyUnicode_AsUTF8(PyObject_Repr(u));
printf("%s\n", uu); // it works
Py_Finalize();
return 0;
}
I am debugging with vscode.
My tasks.json is
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"C:/Users/.../AppData/Local/Programs/Python/Python37/include",
"-L",
"C:/Users/.../AppData/Local/Programs/Python/Python37/libs",
"-lpython37",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
I redownloaded whole python3.7 and it did not help I tried python3.11 cpython in anaconda, and it still 'Segmentation fault' occured.
Edit
I found python3.10.10 in mingw64. I changed my local python version to 3.10.10. However, still I have an error.
message: Thread 1 received signal SIGSEGV, Segmentation fault. ntdll!TpWorkOnBehalfClearTicket () from C:\WINDOWS\SYSTEM32\ntdll.dll
I guess the detail error was different from python3.7