From ac4bf52ad99fc495f200f2988390a9be26a62043 Mon Sep 17 00:00:00 2001 From: xtremeqg Date: Tue, 29 Oct 2024 16:06:08 +0200 Subject: [PATCH] Fixed astronomy function on older windows versions (#1) See https://github.com/cosinekitty/astronomy/pull/357 --- .github/workflows/build.yml | 5 ++++- astronomy-356.patch | 22 ++++++++++++++++++++ astronomy-357.patch | 40 +++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 astronomy-356.patch create mode 100644 astronomy-357.patch diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ecddee7..5273431 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -123,7 +123,6 @@ jobs: path: | ${{github.workspace}}/libspng/build/include/*.h ${{github.workspace}}/libspng/build/libspng.a - centijson-mingw32: runs-on: ubuntu-latest steps: @@ -173,6 +172,10 @@ jobs: repository: cosinekitty/astronomy ref: master path: astronomy + - name: Apply patches + run: | + cd ${{github.workspace}}/astronomy && git apply ${{github.workspace}}/astronomy-356.patch + cd ${{github.workspace}}/astronomy && git apply ${{github.workspace}}/astronomy-357.patch - name: Build run: | mkdir -p ${{github.workspace}}/astronomy/build diff --git a/astronomy-356.patch b/astronomy-356.patch new file mode 100644 index 0000000..abc60b6 --- /dev/null +++ b/astronomy-356.patch @@ -0,0 +1,22 @@ +From 34694ee7a8092cf6619c6fa6264f4f72bef9a8dc Mon Sep 17 00:00:00 2001 +From: Yani <6956790+yani@users.noreply.github.com> +Date: Wed, 31 Jul 2024 00:34:45 +0200 +Subject: [PATCH] fix missing initializer warning + +--- + source/c/astronomy.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/source/c/astronomy.c b/source/c/astronomy.c +index 08ec6c76..07fc730e 100644 +--- a/source/c/astronomy.c ++++ b/source/c/astronomy.c +@@ -11230,7 +11230,7 @@ static const constel_boundary_t ConstelBounds[] = { + astro_constellation_t Astronomy_Constellation(double ra, double dec) + { + static astro_time_t epoch2000; +- static astro_rotation_t rot = { ASTRO_NOT_INITIALIZED }; ++ static astro_rotation_t rot = { ASTRO_NOT_INITIALIZED, {{0}} }; + astro_constellation_t constel; + astro_spherical_t s2000; + astro_equatorial_t b1875; diff --git a/astronomy-357.patch b/astronomy-357.patch new file mode 100644 index 0000000..fffa1cf --- /dev/null +++ b/astronomy-357.patch @@ -0,0 +1,40 @@ +From 5773820d9cf1c1c1836028f7dd80dfe27669e194 Mon Sep 17 00:00:00 2001 +From: Yani <6956790+yani@users.noreply.github.com> +Date: Sat, 10 Aug 2024 18:02:10 +0200 +Subject: [PATCH] Check if GetSystemTimePreciseAsFileTime() is available and + fallback to GetSystemTimeAsFileTime() + +--- + source/c/astronomy.c | 19 ++++++++++++++++++- + 1 file changed, 18 insertions(+), 1 deletion(-) + +diff --git a/source/c/astronomy.c b/source/c/astronomy.c +index 08ec6c76..8325a764 100644 +--- a/source/c/astronomy.c ++++ b/source/c/astronomy.c +@@ -1013,7 +1013,24 @@ astro_time_t Astronomy_CurrentTime(void) + FILETIME ft; + ULARGE_INTEGER large; + /* Get time in 100-nanosecond units from January 1, 1601. */ +- GetSystemTimePreciseAsFileTime(&ft); ++ /* GetSystemTimePreciseAsFileTime is only available since Windows 8 */ ++ typedef void (WINAPI *GetSystemTimePreciseAsFileTimeFunc)(LPFILETIME); ++ GetSystemTimePreciseAsFileTimeFunc pGetSystemTimePreciseAsFileTime = NULL; ++ HMODULE hModule = GetModuleHandleA("kernel32.dll"); ++ if (hModule) { ++ union { ++ FARPROC proc; ++ GetSystemTimePreciseAsFileTimeFunc func; ++ } converter; ++ converter.proc = GetProcAddress(hModule, "GetSystemTimePreciseAsFileTime"); ++ pGetSystemTimePreciseAsFileTime = converter.func; ++ } ++ // Use the function if available, otherwise fallback ++ if (pGetSystemTimePreciseAsFileTime) { ++ pGetSystemTimePreciseAsFileTime(&ft); ++ } else { ++ GetSystemTimeAsFileTime(&ft); ++ } + large.u.LowPart = ft.dwLowDateTime; + large.u.HighPart = ft.dwHighDateTime; + sec = (large.QuadPart - 116444736000000000ULL) / 1.0e+7;