git: c37f4c4df1ba - main - sysutils/py-scandir: Apply upstream patch to fix build with python-3.11

From: Wen Heping <wen_at_FreeBSD.org>
Date: Mon, 11 Mar 2024 08:18:57 UTC
The branch main has been updated by wen:

URL: https://cgit.FreeBSD.org/ports/commit/?id=c37f4c4df1baaa3c57dbf461bfe97fa1b3644f86

commit c37f4c4df1baaa3c57dbf461bfe97fa1b3644f86
Author:     Wen Heping <wen@FreeBSD.org>
AuthorDate: 2024-03-11 08:15:10 +0000
Commit:     Wen Heping <wen@FreeBSD.org>
CommitDate: 2024-03-11 08:17:33 +0000

    sysutils/py-scandir: Apply upstream patch to fix build with python-3.11
    
    PR:             277102
    Reported by:    wen@
    Approved by:    maintainer(timeout, > 20 days)
---
 sysutils/py-scandir/Makefile               |  2 +-
 sysutils/py-scandir/files/patch-_scandir.c | 68 +++++++++++++++++++++++++++---
 2 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/sysutils/py-scandir/Makefile b/sysutils/py-scandir/Makefile
index 927bd328241c..67883732fa31 100644
--- a/sysutils/py-scandir/Makefile
+++ b/sysutils/py-scandir/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	scandir
 PORTVERSION=	1.10.0
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	sysutils python
 MASTER_SITES=	PYPI
 PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
diff --git a/sysutils/py-scandir/files/patch-_scandir.c b/sysutils/py-scandir/files/patch-_scandir.c
index a0dfd94c9f96..19e8f98f33ce 100644
--- a/sysutils/py-scandir/files/patch-_scandir.c
+++ b/sysutils/py-scandir/files/patch-_scandir.c
@@ -1,14 +1,68 @@
---- _scandir.c.orig	2018-08-02 16:17:16 UTC
+--- _scandir.c.orig	2024-02-16 23:29:35 UTC
 +++ _scandir.c
-@@ -660,7 +660,11 @@ _pystat_fromstructstat(STRUCT_STAT *st)
+@@ -94,7 +94,7 @@ comment):
+ 
+ // _Py_stat_struct is already defined in fileutils.h on Python 3.5+
+ // But not in PyPy
+-#if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 5) || defined(PYPY_VERSION_NUM)
++#if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 5) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 11) || defined(PYPY_VERSION_NUM)
+ #ifdef MS_WINDOWS
+ struct _Py_stat_struct {
+     unsigned long st_dev;
+@@ -660,7 +660,7 @@ _pystat_fromstructstat(STRUCT_STAT *st)
      return v;
  }
  
-+#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 9
-+const char * const PyStructSequence_UnnamedField = "unnamed field";
-+#else
- char *PyStructSequence_UnnamedField = "unnamed field";
-+#endif
+-char *PyStructSequence_UnnamedField = "unnamed field";
++static char *scandir_unnamed_field = "unnamed field";
  
  PyDoc_STRVAR(stat_result__doc__,
  "stat_result: Result from stat, fstat, or lstat.\n\n\
+@@ -681,7 +681,7 @@ static PyStructSequence_Field stat_result_fields[] = {
+     {"st_uid",     "user ID of owner"},
+     {"st_gid",     "group ID of owner"},
+     {"st_size",    "total size, in bytes"},
+-    /* The NULL is replaced with PyStructSequence_UnnamedField later. */
++    /* The NULL is replaced with scandir_unnamed_field later. */
+     {NULL,         "integer time of last access"},
+     {NULL,         "integer time of last modification"},
+     {NULL,         "integer time of last change"},
+@@ -986,10 +986,12 @@ DirEntry_fetch_stat(DirEntry *self, int follow_symlink
+     if (!path)
+         return NULL;
+ 
++    Py_BEGIN_ALLOW_THREADS
+     if (follow_symlinks)
+         result = win32_stat_w(path, &st);
+     else
+         result = win32_lstat_w(path, &st);
++    Py_END_ALLOW_THREADS
+ 
+     if (result != 0) {
+         return PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError,
+@@ -1014,10 +1016,12 @@ DirEntry_fetch_stat(DirEntry *self, int follow_symlink
+ #endif
+     path = PyBytes_AS_STRING(bytes);
+ 
++    Py_BEGIN_ALLOW_THREADS
+     if (follow_symlinks)
+         result = STAT(path, &st);
+     else
+         result = LSTAT(path, &st);
++    Py_END_ALLOW_THREADS
+     Py_DECREF(bytes);
+ 
+     if (result != 0)
+@@ -1813,9 +1817,9 @@ init_scandir(void)
+     if (!billion)
+         INIT_ERROR;
+ 
+-    stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
+-    stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
+-    stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
++    stat_result_desc.fields[7].name = scandir_unnamed_field;
++    stat_result_desc.fields[8].name = scandir_unnamed_field;
++    stat_result_desc.fields[9].name = scandir_unnamed_field;
+     PyStructSequence_InitType(&StatResultType, &stat_result_desc);
+     structseq_new = StatResultType.tp_new;
+     StatResultType.tp_new = statresult_new;