This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 58b780c280f3bab89d947be17c5c398e6556711a Author: Tiago Medicci <[email protected]> AuthorDate: Thu May 21 14:29:12 2026 +0200 interpreters/python: Add ctypes prototype patches for NuttX Integrate NuttX-specific ctypes and posixmodule updates. Signed-off-by: Tiago Medicci <[email protected]> --- interpreters/python/Kconfig | 1 + interpreters/python/Makefile | 6 ++++++ interpreters/python/Setup.local.in | 1 - interpreters/python/config.site.in | 4 ++++ ...-get_errno-set_errno-to-avoid-nuttx-macro-coll.patch | 17 +++++++++++++++++ .../patch/0020-ctypes-skip-pythonapi-on-nuttx.patch | 11 +++++++++++ .../0021-posixmodule-ignore-utime-enosys-on-nuttx.patch | 16 ++++++++++++++++ 7 files changed, 55 insertions(+), 1 deletion(-) diff --git a/interpreters/python/Kconfig b/interpreters/python/Kconfig index dfc5fd4cc..a0582835f 100644 --- a/interpreters/python/Kconfig +++ b/interpreters/python/Kconfig @@ -6,6 +6,7 @@ config INTERPRETERS_CPYTHON tristate "CPython" depends on LIB_ZLIB + depends on !LIBC_DLFCN || LIB_LIBFFI depends on EXPERIMENTAL default n ---help--- diff --git a/interpreters/python/Makefile b/interpreters/python/Makefile index a339bbe02..1b1392cac 100644 --- a/interpreters/python/Makefile +++ b/interpreters/python/Makefile @@ -88,6 +88,9 @@ $(CPYTHON_UNPACKNAME): $(CPYTHON_ZIP) $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0016-fix-timezone-offset-check-when-time-t-is-unsigned.patch $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0017-stdlib-zip-keep-pydecimal-and-trim-tooling-extras.patch $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0018-ignore-chmod-on-nuttx-like-wasi.patch + $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0019-undef-get_errno-set_errno-to-avoid-nuttx-macro-coll.patch + $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0020-ctypes-skip-pythonapi-on-nuttx.patch + $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0021-posixmodule-ignore-utime-enosys-on-nuttx.patch $(HOSTPYTHON): mkdir -p $(HOSTBUILD) @@ -128,6 +131,9 @@ $(SETUP_LOCAL): ifneq ($(CONFIG_ARCH_HAVE_FORK),y) @echo "_posixsubprocess" >> $@ endif +ifneq ($(CONFIG_LIBC_DLFCN),y) + @echo "_ctypes" >> $@ +endif # For the Python's `configure` script, please consider the following # when building for NuttX: diff --git a/interpreters/python/Setup.local.in b/interpreters/python/Setup.local.in index 0bd116574..d8c27292b 100644 --- a/interpreters/python/Setup.local.in +++ b/interpreters/python/Setup.local.in @@ -11,7 +11,6 @@ _codecs_iso2022 _codecs_jp _codecs_kr _codecs_tw -_ctypes _decimal _elementtree _heapq diff --git a/interpreters/python/config.site.in b/interpreters/python/config.site.in index 52c04725a..d19337ea6 100644 --- a/interpreters/python/config.site.in +++ b/interpreters/python/config.site.in @@ -31,3 +31,7 @@ export ac_cv_func_utimes="yes" export ac_cv_func_getuid="yes" export ac_cv_func_sysconf="yes" export ac_cv_func_umask="yes" +export ac_cv_func_ffi_prep_cif_var="yes" +export ac_cv_func_ffi_prep_closure_loc="yes" +export ac_cv_func_ffi_closure_alloc="yes" +export ac_cv_func_utimes="no" diff --git a/interpreters/python/patch/0019-undef-get_errno-set_errno-to-avoid-nuttx-macro-coll.patch b/interpreters/python/patch/0019-undef-get_errno-set_errno-to-avoid-nuttx-macro-coll.patch new file mode 100644 index 000000000..905827466 --- /dev/null +++ b/interpreters/python/patch/0019-undef-get_errno-set_errno-to-avoid-nuttx-macro-coll.patch @@ -0,0 +1,17 @@ +--- a/Modules/_ctypes/callproc.c ++++ b/Modules/_ctypes/callproc.c +@@ -91,6 +91,14 @@ + #include <alloca.h> + #endif + ++/* NuttX errno.h defines get_errno() and set_errno(e) as macros. ++ Undef them so that CPython's static functions of the same name ++ in this file compile without conflict. */ ++#ifdef __NuttX__ ++#undef get_errno ++#undef set_errno ++#endif ++ + #ifdef _Py_MEMORY_SANITIZER + #include <sanitizer/msan_interface.h> + #endif diff --git a/interpreters/python/patch/0020-ctypes-skip-pythonapi-on-nuttx.patch b/interpreters/python/patch/0020-ctypes-skip-pythonapi-on-nuttx.patch new file mode 100644 index 000000000..99ca460d9 --- /dev/null +++ b/interpreters/python/patch/0020-ctypes-skip-pythonapi-on-nuttx.patch @@ -0,0 +1,11 @@ +--- a/Lib/ctypes/__init__.py ++++ b/Lib/ctypes/__init__.py +@@ -481,6 +481,8 @@ + pythonapi = PyDLL("libpython%d.%d.so" % _sys.version_info[:2]) + elif _sys.platform == "cygwin": + pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2]) ++elif _sys.platform == "nuttx": ++ pythonapi = None + else: + pythonapi = PyDLL(None) + diff --git a/interpreters/python/patch/0021-posixmodule-ignore-utime-enosys-on-nuttx.patch b/interpreters/python/patch/0021-posixmodule-ignore-utime-enosys-on-nuttx.patch new file mode 100644 index 000000000..664d0f174 --- /dev/null +++ b/interpreters/python/patch/0021-posixmodule-ignore-utime-enosys-on-nuttx.patch @@ -0,0 +1,16 @@ +--- a/Modules/posixmodule.c ++++ b/Modules/posixmodule.c +@@ -6666,6 +6666,13 @@ + } + #endif + ++#if defined(__NuttX__) ++ if (result == -1 && errno == ENOSYS) { ++ /* SmartFS and other NuttX fs do not implement chstat. */ ++ Py_RETURN_NONE; ++ } ++#endif ++ + if (result < 0) { + path_error(path); + return NULL;
