Trying to reason about the CPython source and was curious about the built-in open()
method.
This method is defined in _pyio.py and returns a FileIO
object, so I dug through source and found that (on Windows) there is a call to _wopen
(source line). Interestingly enough, I stumbled into fileutils.c where _Py_open
is defined and subsequently _Py_open_impl
. The latter makes a call to open
(source line) which has a different signature than _wopen
which I presume is referencing _wfopen
; however, below that there are _Py_wfopen
, _Py_fopen
and _Py_fopen_obj
. Their comment lines seem to indicate that they are wrappers around the C functions provided from #include
's, so I know they're calling the originals and extending their functionality.
I'm not a C person by any means, mostly I can dig around code for debugging. This, however, has me lost. How are all these methods tied together (on Windows)? So far I have:
open() -> io.py -> _pyio.py (_io) -> _iomodule.c -> ?
Not seeing where _Py_fopen
or _Py_wfopen
are called explicitly called (or used to wrap library functions) other than in main.c
for startup file operations.