Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8165345

JDK macro definition re-defined by MacOS core framework

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • client-libs
    • 2d
    • b137

      Because of some overlapping changes I happened to stumble on a problem
      with a macro definition introduced in fixing https://bugs.openjdk.java.net/browse/JDK-8164818

      // Use 16.16 for better precision than 26.6
      #define FloatToFixedScale ((float)(1 << 16))
      #define FloatToFixed(f) ((unsigned int)((f) * FloatToFixedScale))

      I found that if I changed "16" to anything else my change was ignored on Mac.

      The reason is that a definition in an MacOS framework header which just
      so happened to amount to the same as I was using was always winning.
      /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/FixMath.h has
      #define fixed1 ((Fixed) 0x00010000L)
      #define FloatToFixed(a) (_IntSaturate((a) * fixed1))

      So why was there no redefinition warning ?
      The order of includes I have is :
      #include "hb.h"
      #include "hb-jdk.h"
      #ifdef MACOSX
      #include "hb-coretext.h"
      #endif
      #include <stdlib.h>

      If I swap this to
      #ifdef MACOSX
      #include "hb-coretext.h"
      #endif
      #include "hb.h"
      #include "hb-jdk.h"
      #include <stdlib.h>

      Then I get a warning :

      Building target 'default (exploded-image)' in configuration 'macosx-x86_64-normal-server-release'
      Building JVM variant 'server' with features 'all-gcs cds closed-src commercial-features compiler1 compiler2 dtrace fprof jni-check jvmci jvmti management nmt services trace vm-structs'
      Updating libfontmanager.dylib due to 1 file(s)
      In file included from ~/jdk9-client/jdk/src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc:30:
      ~/jdk9-client/jdk/src/java.desktop/share/native/libfontmanager/hb-jdk.h:56:9: error: 'FloatToFixed' macro redefined [-Werror,-Wmacro-redefined]
      #define FloatToFixed(f) ((unsigned int)((f) * 64.0f))
              ^
      /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/FixMath.h:93:9: note: previous definition is here
      #define FloatToFixed(a) (_IntSaturate((a) * fixed1))
              ^
      1 error generated.
      make[3]: *** [~/jdk9-client/build/macosx-x86_64-normal-server-release/support/native/java.desktop/libfontmanager/hb-jdk-font.o] Error 1
      make[2]: *** [java.desktop-libs] Error 2

      I do not know why "no warning" in the case when apparently the Carbon definition over-rides mine but not vice versa.
      I can't find an undef or a pragma that would cause this.
      But to make guard against this I intend to make my macro name less generic.

            prr Philip Race
            prr Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: