I'm trying to embed CPython 3.13.9 into my program using Zig. The idea is that I'll import a Python module using PyImport_ImportModule and hold on to it. And later PyObject_GetAttrString and PyObject_CallObject will be used to call functions in the module.
But segment fault occurs when I call PyObject_GetAttrString, and sometimes PyObject_CallObject too (I'm unsure about this because I did changed some stuff when debugging, but I can't recall any changes that might relate to this happening). I'm sure that I didn't call PY_DECREF on the module nor Py_Finalize before trying to call PyObject_GetAttrString and PyObject_CallObject.
I needed to call multiple functions in Python from Zig, at some point I got it to work with the first function call. But later on it somehow stopped working again, and will always crash on the second PyObject_GetAttrString call (segment fault at address 0x0).
Even after hours of research, back and forth with ChatGPT, I still can't figure out why this is happening. Am I miss understand how object or module lifetime work? Any help is appreciated!