Skip to content

Commit

Permalink
Hotfix for p4est output routines on Windows (#3095)
Browse files Browse the repository at this point in the history
  • Loading branch information
sloede authored May 28, 2021
1 parent 16ee4af commit 53fcb8d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions P/P4est/build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version = v"2.3.1"
# Collection of sources required to complete build
sources = [
ArchiveSource("https://p4est.github.io/release/p4est-2.3.1.tar.gz", "be66893b039fb3f27aca3d5d00acff42c67bfad5aa09cea9253cdd628b2bdc9a"),
DirectorySource("./bundled"),
]

# Bash recipe for building across all platforms
Expand Down Expand Up @@ -38,6 +39,10 @@ if [[ "${target}" == *-mingw* ]]; then
# Add manual definitions to fix missing `htonl` according to `INSTALL_WINDOWS` file
# (see https://github.com/cburstedde/p4est/blob/master/INSTALL_WINDOWS)
sed -i "1s/^/#define htonl(_val) ( ((uint16_t)(_val) \& 0xff00) >> 8 | ((uint16_t)(_val) \& 0xff) << 8 )\n/" src/p4est_algorithms.c src/p8est_algorithms.c src/p6est.c src/p4est_ghost.c
# Add patch to hotfix `p4est_save_ext`/`p6est_save_ext` until
# https://github.com/cburstedde/p4est/issues/113 is fixed and released
atomic_patch -p1 $WORKSPACE/srcdir/patches/fix-bad-ftell-return-value-windows.patch
fi
# Configure, build, install
Expand Down
30 changes: 30 additions & 0 deletions P/P4est/bundled/patches/fix-bad-ftell-return-value-windows.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/src/p4est.c b/src/p4est.c
index 834b70f6..9b71cc90 100644
--- a/src/p4est.c
+++ b/src/p4est.c
@@ -3522,6 +3522,10 @@ p4est_save_ext (const char *filename, p4est_t * p4est,
file = fopen (filename, "ab");
SC_CHECK_ABORT (file != NULL, "file open");

+ /* explicitly seek to end to avoid bad ftell return value on Windows */
+ retval = fseek(file, 0, SEEK_END);
+ SC_CHECK_ABORT (retval == 0, "file seek");
+
/* align the start of the header */
fpos = ftell (file);
SC_CHECK_ABORT (fpos > 0, "first file tell");
diff --git a/src/p6est.c b/src/p6est.c
index 9bb7b546..d115952f 100644
--- a/src/p6est.c
+++ b/src/p6est.c
@@ -756,6 +756,10 @@ p6est_save_ext (const char *filename, p6est_t * p6est,
file = fopen (filename, "ab");
SC_CHECK_ABORT (file != NULL, "file open");

+ /* explicitly seek to end to avoid bad ftell return value on Windows */
+ retval = fseek(file, 0, SEEK_END);
+ SC_CHECK_ABORT (retval == 0, "file seek");
+
/* align */
fpos = ftell (file);
SC_CHECK_ABORT (fpos > 0, "first file tell");

0 comments on commit 53fcb8d

Please sign in to comment.