After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 780350 - gjs 1.48.0: does not compile on macOS with clang
gjs 1.48.0: does not compile on macOS with clang
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
1.48.x
Other Mac OS
: Normal normal
: ---
Assigned To: Philip Chimento
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2017-03-21 12:47 UTC by Tom Schoonjans
Modified: 2017-05-01 04:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
jsapi-util-args: Mark functions as always-inline (4.01 KB, patch)
2017-04-25 18:50 UTC, Philip Chimento
committed Details | Review

Description Tom Schoonjans 2017-03-21 12:47:47 UTC
After trying to compile gjs 1.48.0 on macOS, I encountered the following error:

gi/arg.cpp:2614:13: error: call to 'abs' is ambiguous
        if (std::abs(arg->v_int64) > MAX_SAFE_INT64)
            ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:664:1: note: candidate function
abs(float __lcpp_x) _NOEXCEPT {return fabsf(__lcpp_x);}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:668:1: note: candidate function
abs(double __lcpp_x) _NOEXCEPT {return fabs(__lcpp_x);}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:672:1: note: candidate function
abs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);}
^
1 error generated.
make[1]: *** [gi/libgjs_la-arg.lo] Error 1
make[1]: *** Waiting for unfinished jobs....

The fix was easy:

diff --git a/gi/arg.cpp b/gi/arg.cpp
index 5502b00..aacc07d 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -37,6 +37,8 @@
 #include "gjs/byteArray.h"
 #include "gjs/jsapi-wrapper.h"
 #include <util/log.h>
+#include <cstdlib>
+#include <cmath>
 
 bool
 _gjs_flags_value_is_valid(JSContext   *context,
Comment 1 Philip Chimento 2017-03-22 13:28:52 UTC
Seems reasonable. My Apple hardware is defunct right now so I haven't been testing compilation on macOS since about 2 months ago, unfortunately.
Comment 2 Philip Chimento 2017-04-25 18:46:06 UTC
Thanks for the fix Tom, I've got my macOS system back and indeed that fixes the problem. I'll commit it later.

I also got an annoying warning about --param inline-unit-growth=50 which doesn't do anything on Clang. But, the compiler also doesn't report that the flag doesn't exist, because the --param flag does exist on Clang. Following is an alternative (and in my opinion better) fix for that.
Comment 3 Philip Chimento 2017-04-25 18:50:01 UTC
Created attachment 350423 [details] [review]
jsapi-util-args: Mark functions as always-inline

On GCC, we get warnings about the inline functions causing too much code
growth. However, we do want these functions always inlined, since they're
in a header file.

Previously we dealt with the warnings by increasing --param
inline-unit-growth, but that causes other warnings on Clang since Clang
doesn't have that parameter. I also noticed that it requires different
values on other versions of GCC, so it's not a very good solution.

Instead, we use the always_inline attribute on GCC, which causes the
functions to be inlined regardless of the compiler's inlining heuristics.
Comment 4 Cosimo Cecchi 2017-04-30 23:16:51 UTC
Review of attachment 350423 [details] [review]:

Looks correct to me.
Comment 5 Philip Chimento 2017-05-01 04:41:26 UTC
Attachment 350423 [details] pushed as bdbf717 - jsapi-util-args: Mark functions as always-inline