From 276dbdfaf62127eff9ed727e31551715005e5efa Mon Sep 17 00:00:00 2001
From: Naveen M K <naveen521kk@gmail.com>
Date: Sun, 25 Jun 2023 19:39:30 +0530
Subject: [PATCH 093/N] getpath.py: fix `dirname`

also, fix finding prefix when in a venv
---
 Modules/getpath.c  | 12 ++++++++++++
 Modules/getpath.py |  3 +++
 2 files changed, 15 insertions(+)

diff --git a/Modules/getpath.c b/Modules/getpath.c
index eff9ccc..59a57fb 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -92,6 +92,12 @@ getpath_basename(PyObject *Py_UNUSED(self), PyObject *args)
     }
     Py_ssize_t end = PyUnicode_GET_LENGTH(path);
     Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
+#ifdef ALTSEP
+    if (pos < 0) {
+        // try using altsep
+        pos = PyUnicode_FindChar(path, ALTSEP, 0, end, -1);
+    }
+#endif
     if (pos < 0) {
         return Py_NewRef(path);
     }
@@ -108,6 +114,12 @@ getpath_dirname(PyObject *Py_UNUSED(self), PyObject *args)
     }
     Py_ssize_t end = PyUnicode_GET_LENGTH(path);
     Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
+#ifdef ALTSEP
+    if (pos < 0) {
+        // try using altsep
+        pos = PyUnicode_FindChar(path, ALTSEP, 0, end, -1);
+    }
+#endif
     if (pos < 0) {
         return PyUnicode_FromStringAndSize(NULL, 0);
     }
diff --git a/Modules/getpath.py b/Modules/getpath.py
index 93e99a3..3adcf04 100644
--- a/Modules/getpath.py
+++ b/Modules/getpath.py
@@ -581,6 +581,9 @@ else:
     # First try to detect prefix by looking alongside our runtime library, if known
     if library and not prefix:
         library_dir = dirname(library)
+        if os_name == 'nt' and is_mingw:
+            # QUIRK: On Windows, mingw Python DLLs are in the bin directory
+            library_dir = joinpath(library_dir, '..')
         if ZIP_LANDMARK:
             if os_name == 'nt':
                 # QUIRK: Windows does not search up for ZIP file
