| From 479f4647bf0c5a841af6a916c21fdef1fa1b5cdf Mon Sep 17 00:00:00 2001 |
| From: Tiago Medicci <tiago.medicci@espressif.com> |
| Date: Tue, 3 Dec 2024 17:18:50 -0300 |
| Subject: [PATCH 10/14] check for the d_ino member of the structure dirent |
| |
| Signed-off-by: Tiago Medicci <tiago.medicci@espressif.com> |
| --- |
| Modules/clinic/posixmodule.c.h | 2 ++ |
| Modules/posixmodule.c | 18 ++++++++++++-- |
| configure | 43 ++++++++++++++++++++++++++++++++++ |
| configure.ac | 5 ++++ |
| pyconfig.h.in | 3 +++ |
| 5 files changed, 69 insertions(+), 2 deletions(-) |
| |
| diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h |
| index 14a6efb9ac9..6e716f77db8 100644 |
| --- a/Modules/clinic/posixmodule.c.h |
| +++ b/Modules/clinic/posixmodule.c.h |
| @@ -11652,6 +11652,7 @@ PyDoc_STRVAR(os_DirEntry_inode__doc__, |
| #define OS_DIRENTRY_INODE_METHODDEF \ |
| {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
| |
| +#ifdef HAVE_DIRENT_D_INO |
| static PyObject * |
| os_DirEntry_inode_impl(DirEntry *self); |
| |
| @@ -11660,6 +11661,7 @@ os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| { |
| return os_DirEntry_inode_impl(self); |
| } |
| +#endif |
| |
| PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
| "__fspath__($self, /)\n" |
| diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c |
| index 51e34b5f4b7..2aa507aa942 100644 |
| --- a/Modules/posixmodule.c |
| +++ b/Modules/posixmodule.c |
| @@ -15522,7 +15522,9 @@ typedef struct { |
| #ifdef HAVE_DIRENT_D_TYPE |
| unsigned char d_type; |
| #endif |
| +#ifdef HAVE_DIRENT_D_INO |
| ino_t d_ino; |
| +#endif |
| int dir_fd; |
| #endif |
| } DirEntry; |
| @@ -15821,6 +15823,7 @@ os.DirEntry.inode |
| Return inode of the entry; cached per entry. |
| [clinic start generated code]*/ |
| |
| +#ifdef HAVE_DIRENT_D_INO |
| static PyObject * |
| os_DirEntry_inode_impl(DirEntry *self) |
| /*[clinic end generated code: output=156bb3a72162440e input=3ee7b872ae8649f0]*/ |
| @@ -15856,6 +15859,7 @@ os_DirEntry_inode_impl(DirEntry *self) |
| return PyLong_FromUnsignedLongLong(self->d_ino); |
| #endif |
| } |
| +#endif |
| |
| static PyObject * |
| DirEntry_repr(DirEntry *self) |
| @@ -15892,7 +15896,9 @@ static PyMethodDef DirEntry_methods[] = { |
| OS_DIRENTRY_IS_SYMLINK_METHODDEF |
| OS_DIRENTRY_IS_JUNCTION_METHODDEF |
| OS_DIRENTRY_STAT_METHODDEF |
| +#ifdef HAVE_DIRENT_D_INO |
| OS_DIRENTRY_INODE_METHODDEF |
| +#endif |
| OS_DIRENTRY___FSPATH___METHODDEF |
| {"__class_getitem__", Py_GenericAlias, |
| METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, |
| @@ -16043,7 +16049,10 @@ join_path_filename(const char *path_narrow, const char* filename, Py_ssize_t fil |
| |
| static PyObject * |
| DirEntry_from_posix_info(PyObject *module, path_t *path, const char *name, |
| - Py_ssize_t name_len, ino_t d_ino |
| + Py_ssize_t name_len |
| +#ifdef HAVE_DIRENT_D_INO |
| + , ino_t d_ino |
| +#endif |
| #ifdef HAVE_DIRENT_D_TYPE |
| , unsigned char d_type |
| #endif |
| @@ -16095,7 +16104,9 @@ DirEntry_from_posix_info(PyObject *module, path_t *path, const char *name, |
| #ifdef HAVE_DIRENT_D_TYPE |
| entry->d_type = d_type; |
| #endif |
| +#ifdef HAVE_DIRENT_D_INO |
| entry->d_ino = d_ino; |
| +#endif |
| |
| return (PyObject *)entry; |
| |
| @@ -16248,7 +16259,10 @@ ScandirIterator_iternext(ScandirIterator *iterator) |
| PyObject *module = PyType_GetModule(Py_TYPE(iterator)); |
| entry = DirEntry_from_posix_info(module, |
| &iterator->path, direntp->d_name, |
| - name_len, direntp->d_ino |
| + name_len |
| +#ifdef HAVE_DIRENT_D_INO |
| + , direntp->d_ino |
| +#endif |
| #ifdef HAVE_DIRENT_D_TYPE |
| , direntp->d_type |
| #endif |
| diff --git a/configure b/configure |
| index 6da5e9f3832..c89beb7ef6a 100755 |
| --- a/configure |
| +++ b/configure |
| @@ -27746,6 +27746,49 @@ then : |
| printf "%s\n" "#define HAVE_DIRENT_D_TYPE 1" >>confdefs.h |
| |
| |
| +fi |
| + |
| +# check if the dirent structure of a d_ino is defined |
| +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the dirent structure of a d_ino field" >&5 |
| +printf %s "checking if the dirent structure of a d_ino field... " >&6; } |
| +if test ${ac_cv_dirent_d_ino+y} |
| +then : |
| + printf %s "(cached) " >&6 |
| +else $as_nop |
| + |
| +cat confdefs.h - <<_ACEOF >conftest.$ac_ext |
| +/* end confdefs.h. */ |
| + |
| + |
| + #include <dirent.h> |
| + |
| + int main(void) { |
| + struct dirent entry; |
| + return entry.d_ino == 0; |
| + } |
| + |
| + |
| +_ACEOF |
| +if ac_fn_c_try_link "$LINENO" |
| +then : |
| + ac_cv_dirent_d_ino=yes |
| +else $as_nop |
| + ac_cv_dirent_d_ino=no |
| +fi |
| +rm -f core conftest.err conftest.$ac_objext conftest.beam \ |
| + conftest$ac_exeext conftest.$ac_ext |
| + |
| +fi |
| +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_dirent_d_ino" >&5 |
| +printf "%s\n" "$ac_cv_dirent_d_ino" >&6; } |
| + |
| +if test "x$ac_cv_dirent_d_ino" = xyes |
| +then : |
| + |
| + |
| +printf "%s\n" "#define HAVE_DIRENT_D_INO 1" >>confdefs.h |
| + |
| + |
| fi |
| |
| # check if the Linux getrandom() syscall is available |
| diff --git a/configure.ac b/configure.ac |
| index 80d6738fab5..40f2f950b36 100644 |
| --- a/configure.ac |
| +++ b/configure.ac |
| @@ -7084,6 +7084,11 @@ AS_VAR_IF([ac_cv_dirent_d_type], [yes], [ |
| [Define to 1 if the dirent structure has a d_type field]) |
| ]) |
| |
| +AS_VAR_IF([ac_cv_dirent_d_ino], [yes], [ |
| + AC_DEFINE([HAVE_DIRENT_D_INO], [1], |
| + [Define to 1 if the dirent structure has a d_ino field]) |
| +]) |
| + |
| # check if the Linux getrandom() syscall is available |
| AC_CACHE_CHECK([for the Linux getrandom() syscall], [ac_cv_getrandom_syscall], [ |
| AC_LINK_IFELSE( |
| diff --git a/pyconfig.h.in b/pyconfig.h.in |
| index 4d8b1d4f254..4a2ba83a872 100644 |
| --- a/pyconfig.h.in |
| +++ b/pyconfig.h.in |
| @@ -277,6 +277,9 @@ |
| /* Define to 1 if the dirent structure has a d_type field */ |
| #undef HAVE_DIRENT_D_TYPE |
| |
| +/* Define to 1 if the dirent structure has a d_ino field */ |
| +#undef HAVE_DIRENT_D_INO |
| + |
| /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'. |
| */ |
| #undef HAVE_DIRENT_H |
| -- |
| 2.50.0 |
| |