lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fixes for cross-compilation to x86_64-w64-mingw32 (issue 579340043 b


From: jonas . hahnfeld
Subject: Re: Fixes for cross-compilation to x86_64-w64-mingw32 (issue 579340043 by address@hidden)
Date: Fri, 28 Feb 2020 01:32:57 -0800

Reviewers: lemzwerg, benko.pal,

Message:
On 2020/02/28 09:23:44, benko.pal wrote:
> it may not matter, but actually long is 32 bit, void * is 64 bit on
current
> native 64 bit platforms too, I believe.

Only mingw, on Linux long is 64 bit AFAICT. See also
https://stackoverflow.com/a/384672/10606944

Description:
Fixes for cross-compilation to x86_64-w64-mingw32

1) Define _POSIX_SOURCE for M_PI on mingw

Recently commit 7396a28bde ("Add enabling extension definitions for
`-std=c++11` option") added a few #defines to config.hh to make POSIX
extensions available. This doesn't seem to work in all cases and I
found this change to fix cross-compilation to x86_64-w64-mingw32.

In general I think this method of explicitly spelling out what each
file needs is superior to gathering all of this in config.hh. It serves
as documentation directly in the code and makes sure that the feature
macro is defined before any other header file is included.

2) Improve cast from pointer to integer

When cross-compiling to x86_64-w64-mingw32, 'long' (32 bit) is smaller
than 'void *' (64 bit). This leads to compiler errors because the cast
truncates. After analysis I think that truncation is actually ok here,
so make this explicit by first casting to a suitable integer and then
truncate to long.
Note that 'suitable integer' is quite a mess: Ideally we would use
intptr_t, but it's optional per the C++ standard. So instead rely on
intmax_t and hope that it works.

3) Use host triple when looking for windres

--host=host-type
    the type of system on which the package runs. [...]

The previously used $target variable is meant for compilers.

Please refer to section 14.1 Specifying target triplets in the Autoconf
documentation for more details.

Please review this at https://codereview.appspot.com/579340043/

Affected files (+28, -2 lines):
  M aclocal.m4
  M flower/offset.cc
  M flower/polynomial.cc
  M lily/accidental-engraver.cc
  M lily/bezier-bow.cc
  M lily/stencil-integral.cc
  M lily/tuplet-bracket.cc


Index: aclocal.m4
diff --git a/aclocal.m4 b/aclocal.m4
index 
19345394857c85a6d6f0e8a8cb8796d9bb928245..efb10c6a8dc0aa4c6d50a9ef58bf651cadf8e452
 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1244,6 +1244,6 @@ AC_DEFUN(STEPMAKE_WINDOWS, [
     fi
     AC_MSG_RESULT([$PLATFORM_WINDOWS])
     AC_SUBST(PLATFORM_WINDOWS)
-    STEPMAKE_PROGS(WINDRES, $target-windres windres, x)
+    STEPMAKE_PROGS(WINDRES, $host-windres windres, x)
     AC_SUBST(WINDRES)
 ])
Index: flower/offset.cc
diff --git a/flower/offset.cc b/flower/offset.cc
index 
fa88bd0657542305bbcc73584a955c0439d21a2c..3004679b27080e73448ad27d59b22a715ce8e61f
 100644
--- a/flower/offset.cc
+++ b/flower/offset.cc
@@ -17,8 +17,13 @@
   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+// Need M_PI from math.h header.
+#define _POSIX_SOURCE
+
 #include "offset.hh"
 
+#include <cmath>
+
 using std::string;
 
 #ifndef STANDALONE
Index: flower/polynomial.cc
diff --git a/flower/polynomial.cc b/flower/polynomial.cc
index 
d3a78feb050653dd62c583b5b205acfe2918c583..682380db29c84c0ed42640c1c130fdf254234511
 100644
--- a/flower/polynomial.cc
+++ b/flower/polynomial.cc
@@ -17,6 +17,9 @@
   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+// Need M_PI from math.h header.
+#define _POSIX_SOURCE
+
 #include "polynomial.hh"
 
 #include "warn.hh"
Index: lily/accidental-engraver.cc
diff --git a/lily/accidental-engraver.cc b/lily/accidental-engraver.cc
index 
877ec1cc5ba0c21d96fb808ab20d11d19741e06c..a721ac5dfae0f1675fea97ada023c94996a591ae
 100644
--- a/lily/accidental-engraver.cc
+++ b/lily/accidental-engraver.cc
@@ -37,6 +37,8 @@
 
 #include "translator.icc"
 
+#include <cstdint>
+
 using std::vector;
 
 class Accidental_entry
@@ -332,10 +334,12 @@ Accidental_engraver::make_standard_accidental 
(Stream_event * /* note */,
     accidental_placement_ = make_item ("AccidentalPlacement",
                                        a->self_scm ());
 
+  // Cannot use intptr_t because it is optional and not portable.
+  intmax_t context_hash = reinterpret_cast<intmax_t>(trans);
   Accidental_placement::add_accidental
     (accidental_placement_, a,
      scm_is_eq (get_property ("accidentalGrouping"), ly_symbol2scm ("voice")),
-     (long) trans);
+     static_cast<long>(context_hash));
 
   note_head->set_object ("accidental-grob", a->self_scm ());
 
Index: lily/bezier-bow.cc
diff --git a/lily/bezier-bow.cc b/lily/bezier-bow.cc
index 
c34d2d069c8d22b01b67dfb9212b43d6582fb004..5e0a6c6b3b3c2f72298c054aa385912e7d4566ec
 100644
--- a/lily/bezier-bow.cc
+++ b/lily/bezier-bow.cc
@@ -17,9 +17,14 @@
   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+// Need M_PI from math.h header.
+#define _POSIX_SOURCE
+
 #include "misc.hh"
 #include "bezier.hh"
 
+#include <cmath>
+
 static Real
 F0_1 (Real x)
 {
Index: lily/stencil-integral.cc
diff --git a/lily/stencil-integral.cc b/lily/stencil-integral.cc
index 
31327b4964f7f362d2753affa4f9b7571a727eb1..92a67a33f263e53656bedc68d8cf6cb9963fd092
 100644
--- a/lily/stencil-integral.cc
+++ b/lily/stencil-integral.cc
@@ -33,6 +33,9 @@ when this transforms a point (x,y), the point is written as 
matrix:
 [ 1 ]
 */
 
+// Need M_PI from math.h header.
+#define _POSIX_SOURCE
+
 #include "box.hh"
 #include "bezier.hh"
 #include "dimensions.hh"
@@ -56,6 +59,7 @@ when this transforms a point (x,y), the point is written as 
matrix:
 #include "spanner.hh"
 #include "transform.hh"
 
+#include <cmath>
 
 using std::string;
 using std::vector;
Index: lily/tuplet-bracket.cc
diff --git a/lily/tuplet-bracket.cc b/lily/tuplet-bracket.cc
index 
528e0eb39df3fbc2ce2ca3099b4865399ca2f4c6..09734467fab3d1bef31646d74a65515d589d0377
 100644
--- a/lily/tuplet-bracket.cc
+++ b/lily/tuplet-bracket.cc
@@ -40,6 +40,9 @@
   todo: handle breaking elegantly.
 */
 
+// Need M_PI from math.h header.
+#define _POSIX_SOURCE
+
 #include "tuplet-bracket.hh"
 
 #include "bracket.hh"
@@ -62,6 +65,8 @@
 #include "moment.hh"
 #include "bezier.hh"
 
+#include <cmath>
+
 using std::vector;
 
 static Item *





reply via email to

[Prev in Thread] Current Thread [Next in Thread]