Skip to content

Commit

Permalink
just use wchar everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Jan 7, 2024
1 parent f073672 commit 9cb7291
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "pycore_pystate.h" // _PyInterpreterState_GET()

#include "osdefs.h" // MAXPATHLEN
#include "Python/stdlib_module_names.h" // _Py_stdlib_module_names
#include "../Python/stdlib_module_names.h" // _Py_stdlib_module_names


static PyMemberDef module_members[] = {
Expand Down Expand Up @@ -872,33 +872,19 @@ _Py_module_getattro_impl(PyModuleObject *m, PyObject *name, int suppress)
// Check mod.__name__ in sys.stdlib_module_names
// and os.path.dirname(mod.__spec__.origin) == os.getcwd()
if (origin && is_name_stdlib_module(mod_name)) {
wchar_t cwdbuf[MAXPATHLEN];
wchar_t cwdbuf[MAXPATHLEN], originbuf[MAXPATHLEN];
if(_Py_wgetcwd(cwdbuf, MAXPATHLEN)) {
PyObject *cwd = PyUnicode_FromWideChar(cwdbuf, wcslen(cwdbuf));
if (!cwd) {
int rc = PyUnicode_AsWideChar(origin, originbuf, MAXPATHLEN);
if (rc < 0) {
goto done;
}
const char sep_char = SEP;
PyObject *sep = PyUnicode_FromStringAndSize(&sep_char, 1);
if (!sep) {
Py_DECREF(cwd);
goto done;
}
PyObject *parts = PyUnicode_RPartition(origin, sep);
Py_DECREF(sep);
if (!parts) {
Py_DECREF(cwd);
goto done;
}
int rc = PyUnicode_Compare(cwd, PyTuple_GET_ITEM(parts, 0));
if (rc == -1 && PyErr_Occurred()) {
Py_DECREF(parts);
Py_DECREF(cwd);
goto done;
wchar_t *sep = wcsrchr(originbuf, SEP);
if (sep) {
*sep = L'\0';
if (wcscmp(cwdbuf, originbuf) == 0) {
is_script_shadowing_stdlib = 1;
}
}
is_script_shadowing_stdlib = rc == 0;
Py_DECREF(parts);
Py_DECREF(cwd);
}
}

Expand Down

0 comments on commit 9cb7291

Please sign in to comment.