cpython/Modules/getpath.c

/* Return the initial module search path. */

#include "Python.h"
#include "pycore_fileutils.h"     // _Py_abspath()
#include "pycore_initconfig.h"    // _PyStatus_EXCEPTION()
#include "pycore_pathconfig.h"    // _PyPathConfig_ReadGlobal()
#include "pycore_pymem.h"         // _PyMem_RawWcsdup()
#include "pycore_pystate.h"       // _PyThreadState_GET()

#include "marshal.h"              // PyMarshal_ReadObjectFromString
#include "osdefs.h"               // DELIM
#include <wchar.h>

#ifdef MS_WINDOWS
#  include <windows.h>            // GetFullPathNameW(), MAX_PATH
#  include <pathcch.h>
#endif

#ifdef __APPLE__
#  include <dlfcn.h>
#  include <mach-o/dyld.h>
#endif

/* Reference the precompiled getpath.py */
#include "Python/frozen_modules/getpath.h"

#if (!defined(PREFIX) || !defined(EXEC_PREFIX) \
        || !defined(VERSION) || !defined(VPATH) \
        || !defined(PLATLIBDIR))
#error "PREFIX, EXEC_PREFIX, VERSION, VPATH and PLATLIBDIR macros must be defined"
#endif

#if !defined(PYTHONPATH)
#define PYTHONPATH
#endif

#if !defined(PYDEBUGEXT)
#define PYDEBUGEXT
#endif

#if !defined(PYWINVER)
#ifdef MS_DLL_ID
#define PYWINVER
#else
#define PYWINVER
#endif
#endif

#if !defined(EXE_SUFFIX)
#if defined(MS_WINDOWS) || defined(__CYGWIN__) || defined(__MINGW32__)
#define EXE_SUFFIX
#else
#define EXE_SUFFIX
#endif
#endif


/* HELPER FUNCTIONS for getpath.py */

static PyObject *
getpath_abspath(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_basename(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_dirname(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_isabs(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_hassuffix(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_isdir(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_isfile(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_realpath(PyObject *Py_UNUSED(self) , PyObject *args)
{}


static PyMethodDef getpath_methods[] =;


/* Two implementations of warn() to use depending on whether warnings
   are enabled or not. */

static PyObject *
getpath_warn(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyObject *
getpath_nowarn(PyObject *Py_UNUSED(self), PyObject *args)
{}


static PyMethodDef getpath_warn_method =;
static PyMethodDef getpath_nowarn_method =;

/* Add the helper functions to the dict */
static int
funcs_to_dict(PyObject *dict, int warnings)
{}


/* Add a wide-character string constant to the dict */
static int
wchar_to_dict(PyObject *dict, const char *key, const wchar_t *s)
{}


/* Add a narrow string constant to the dict, using default locale decoding */
static int
decode_to_dict(PyObject *dict, const char *key, const char *s)
{}

/* Add an environment variable to the dict, optionally clearing it afterwards */
static int
env_to_dict(PyObject *dict, const char *key, int and_clear)
{}


/* Add an integer constant to the dict */
static int
int_to_dict(PyObject *dict, const char *key, int v)
{}


#ifdef MS_WINDOWS
static int
winmodule_to_dict(PyObject *dict, const char *key, HMODULE mod)
{
    wchar_t *buffer = NULL;
    for (DWORD cch = 256; buffer == NULL && cch < (1024 * 1024); cch *= 2) {
        buffer = (wchar_t*)PyMem_RawMalloc(cch * sizeof(wchar_t));
        if (buffer) {
            if (GetModuleFileNameW(mod, buffer, cch) == cch) {
                PyMem_RawFree(buffer);
                buffer = NULL;
            }
        }
    }
    int r = wchar_to_dict(dict, key, buffer);
    PyMem_RawFree(buffer);
    return r;
}
#endif


/* Add the current executable's path to the dict */
static int
progname_to_dict(PyObject *dict, const char *key)
{}


/* Add the runtime library's path to the dict */
static int
library_to_dict(PyObject *dict, const char *key)
{}


PyObject *
_Py_Get_Getpath_CodeObject(void)
{}


/* Perform the actual path calculation.

   When compute_path_config is 0, this only reads any initialised path
   config values into the PyConfig struct. For example, Py_SetHome() or
   Py_SetPath(). The only error should be due to failed memory allocation.

   When compute_path_config is 1, full path calculation is performed.
   The GIL must be held, and there may be filesystem access, side
   effects, and potential unraisable errors that are reported directly
   to stderr.

   Calling this function multiple times on the same PyConfig is only
   safe because already-configured values are not recalculated. To
   actually recalculate paths, you need a clean PyConfig.
*/
PyStatus
_PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
{}