Skip to content

Commit

Permalink
Fixed astronomy function on older windows versions (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtremeqg authored Oct 29, 2024
1 parent baad15c commit ac4bf52
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions astronomy-356.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
From 34694ee7a8092cf6619c6fa6264f4f72bef9a8dc Mon Sep 17 00:00:00 2001
From: Yani <[email protected]>
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;
40 changes: 40 additions & 0 deletions astronomy-357.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
From 5773820d9cf1c1c1836028f7dd80dfe27669e194 Mon Sep 17 00:00:00 2001
From: Yani <[email protected]>
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;

0 comments on commit ac4bf52

Please sign in to comment.