From 16dd95e6e7318ffccf693bcac9fef4d504c99e99 Mon Sep 17 00:00:00 2001
From: Luigi Scarso <luigi.scarso@gmail.com>
Date: Sat, 4 Jan 2025 17:47:42 +0100
Subject: [PATCH] Clean-up ffi.h. LuaTeX 1.20.1

---
 source/texk/web2c/luatexdir/ChangeLog         |  5 ++
 source/texk/web2c/luatexdir/luaffi/ffi.h      | 53 ++++++++++++-------
 source/texk/web2c/luatexdir/luatex.c          |  4 +-
 .../texk/web2c/luatexdir/luatex_svnversion.h  |  2 +-
 4 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/source/texk/web2c/luatexdir/ChangeLog b/source/texk/web2c/luatexdir/ChangeLog
index f4f2f1d87..259863641 100644
--- a/source/texk/web2c/luatexdir/ChangeLog
+++ b/source/texk/web2c/luatexdir/ChangeLog
@@ -1,3 +1,8 @@
+2025-01-04 Luigi Scarso <luigi.scarso@gmail.com>
+	* Clean-up ffi.h
+	* LuaTeX 1.20.1
+
+
 2025-01-01 Luigi Scarso <luigi.scarso@gmail.com>
 	* New luaffi, support for aarch64.
 	* LuaTeX 1.20.0
diff --git a/source/texk/web2c/luatexdir/luaffi/ffi.h b/source/texk/web2c/luatexdir/luaffi/ffi.h
index 5555894e0..08f42f96c 100644
--- a/source/texk/web2c/luatexdir/luaffi/ffi.h
+++ b/source/texk/web2c/luatexdir/luaffi/ffi.h
@@ -44,11 +44,27 @@ extern "C" {
 
 #if __STDC_VERSION__+0 >= 199901L
 
+#if ( defined( _WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__) || defined(__DragonFly__))
+/* We should include something equivalent to */
+/* complex.h                                 */
+/* e.g. Mingw GCC >=10 should have complex functions builtin */
+/* and we can check them with the macro __has_include */
+#if (__GNUC__ >= 10)
+# if defined __has_include
+#  if __has_include (<complex.h>)
+#    include <complex.h>
+#    define HAVE_COMPLEX
+#    define HAVE_LONG_DOUBLE
+#  endif
+# endif
+#endif 
+#else
 #include <complex.h>
 #define HAVE_COMPLEX
 #define HAVE_LONG_DOUBLE
-
 #endif
+#endif
+
 
 #ifndef NDEBUG
 #define DASM_CHECKS
@@ -121,13 +137,18 @@ struct jit;
 #if defined ARCH_X86 || defined ARCH_X64
 #define ALLOW_MISALIGNED_ACCESS
 #endif
-#ifdef OS_WIN
-#define ALWAYS_INLINE __forceinline
-#elif defined(__GNUC__)
-#define ALWAYS_INLINE __attribute__ ((always_inline))
-#else
+
+/* #ifdef OS_WIN */
+/* #define ALWAYS_INLINE __forceinline */
+/* #elif defined(__GNUC__) */
+/* #define ALWAYS_INLINE __attribute__ ((always_inline)) */
+/* #else */
+/* #define ALWAYS_INLINE inline */
+/* #endif */
+
 #define ALWAYS_INLINE inline
-#endif
+
+
 EXTERN_C EXPORT int luaopen_ffi(lua_State* L);
 
 static int lua_absindex2(lua_State* L, int idx) {
@@ -463,18 +484,12 @@ static ALWAYS_INLINE complex_float mk_complex_float(double real, double imag) {
     return real + imag * 1i;
 }
 #endif
-/* static ALWAYS_INLINE complex_double mk_complex_double(double real, double imag) { */
-/*       return (complex_double){real , imag }; */
-/* } */
-/* static ALWAYS_INLINE complex_float mk_complex_float(double real, double imag) { */
-/*       return (complex_float){real , imag}; */
-/* } */
 
-
-extern float cimagf(complex_float);
-extern float crealf(complex_float);
-extern double cimag(complex_double);
-extern double creal(complex_double);
+/* AlpineLinux musl doesn't like them */
+/* extern float cimagf(complex_float); */
+/* extern float crealf(complex_float); */
+/* extern double cimag(complex_double); */
+/* extern double creal(complex_double); */
 
 
 #if defined(OS_ANDROID) && __ANDROID_API__<26
@@ -514,6 +529,7 @@ static ALWAYS_INLINE complex_double mk_complex_double(double real, double imag)
 static ALWAYS_INLINE complex_float mk_complex_float(double real, double imag) {
     return (complex_float){ real, imag };
 }
+
 static ALWAYS_INLINE double creal(complex_double c) {
     return c.real;
 }
@@ -544,6 +560,7 @@ static complex_double cpow(complex_double f, complex_double s) {
     r = exp(f.real);
     return (complex_double) {r*cos(f.imag),r*sin(f.imag)};
 }
+
 #endif
 
 #define CALLBACK_FUNC_USR_IDX 1
diff --git a/source/texk/web2c/luatexdir/luatex.c b/source/texk/web2c/luatexdir/luatex.c
index 413ddfd77..517672f86 100644
--- a/source/texk/web2c/luatexdir/luatex.c
+++ b/source/texk/web2c/luatexdir/luatex.c
@@ -33,8 +33,8 @@
 */
 
 int luatex_version = 120;
-int luatex_revision = '0';
-const char *luatex_version_string = "1.20.0";
+int luatex_revision = '1';
+const char *luatex_version_string = "1.20.1";
 const char *engine_name = my_name;
 
 #include <kpathsea/c-ctype.h>
diff --git a/source/texk/web2c/luatexdir/luatex_svnversion.h b/source/texk/web2c/luatexdir/luatex_svnversion.h
index e88e01b48..e79a15c30 100644
--- a/source/texk/web2c/luatexdir/luatex_svnversion.h
+++ b/source/texk/web2c/luatexdir/luatex_svnversion.h
@@ -1,4 +1,4 @@
 #ifndef luatex_svn_revision_h
 #define luatex_svn_revision_h
-#define luatex_svn_revision 7635
+#define luatex_svn_revision 7636
 #endif
-- 
GitLab