Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix for p4est output routines on Windows #3095

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");