Skip to content

Commit

Permalink
sysutils/py-scandir: Apply upstream patch to fix build with python-3.11
Browse files Browse the repository at this point in the history
PR:		277102
Reported by:	wen@
Approved by:	maintainer(timeout, > 20 days)
  • Loading branch information
wenheping committed Mar 11, 2024
1 parent 432c02e commit c37f4c4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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}
Expand Down
68 changes: 61 additions & 7 deletions 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;

0 comments on commit c37f4c4

Please sign in to comment.