Skip to content
Tcl Source Code History Of Ticket 1cc44617e2b4ed0a
Login

History Of Ticket 1cc44617e2b4ed0a

Artifacts Associated With Ticket 1cc44617e2b4ed0a

  1. Ticket change [bf7395f332] (rid 152626) by anonymous on 2017-03-23 19:04:49:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/html"
    4. comment initialized to:
      For 64 bit support in tcl.h the following constants will be used: TCL_WIDE_INT_TYPE (on 32 bit arch) or TCL_WIDE_INT_IS_LONG (on 64 bit arch).
      
      <p>
      With Mac the following (stripped) code seems to work:
      
      <verbatim>
      #ifdef __APPLE__
      #   ifdef __LP64__
      #       undef TCL_WIDE_INT_TYPE
      #	define TCL_WIDE_INT_IS_LONG 1
      #    else /* !__LP64__ */
      #       define TCL_WIDE_INT_TYPE long long
      #       undef TCL_WIDE_INT_IS_LONG
      #    endif /* __LP64__ */
      #endif /* __APPLE__ */
      </verbatim>
      
      For Windows/Linux/UNIX it cannot work properly, see this annotated code snippet:
      
      <verbatim>
      #if !defined(TCL_WIDE_INT_TYPE)&&!defined(TCL_WIDE_INT_IS_LONG)*
      /*****************************************************************
       This is the case when compiling outside of Tcl core, because none
       of these constants is pre-defined. Mac is excluded here, because
       handled above.
      *******************************************************************/
      #   if defined(_WIN32)
      /******************************************************************
       This branch will be reached when compiling under Windows, even
       when compiling with any other compiler than MSVC.
       Now TCL_WIDE_INT_TYPE will be defined even on 64 bit architectures,
       but due to documentation on 64 bit architectures the constant
       TCL_WIDE_INT_IS_LONG should be defined instead.
       Note that on 64 bit machines the constant _WIN32 is also
       pre-defined.
       Also note that the definition of TCL_WIDE_INT_TYPE is probably
       incorrect when compiling with an other compiler than MSVC.
      *******************************************************************/
      #      define TCL_WIDE_INT_TYPE __int64
      #      ifdef __BORLANDC__
      #         define TCL_LL_MODIFIER  "L"
      #      else /* __BORLANDC__ */
      #         define TCL_LL_MODIFIER  "I64"
      #      endif /* __BORLANDC__ */
      #   elif defined(__GNUC__)
      /******************************************************************
       This is the case when compiling with gcc under Linux/UNIX.
       Now TCL_WIDE_INT_TYPE will be defined, whether 32 bit or 64 bit
       architecture, but due to documentation on 64 bit architectures
       the constant TCL_WIDE_INT_IS_LONG should be defined instead.
       And the definition of TCL_LL_MODIFIER is incorrect on 64 bit
       architectures, should be "l" instead.
      *******************************************************************/
      #      define TCL_WIDE_INT_TYPE long long
      #      define TCL_LL_MODIFIER "ll"
      #   else /* ! _WIN32 && ! __GNUC__ */
      #      ...
      #   endif /* _WIN32 */
      #endif /* !TCL_WIDE_INT_TYPE & !TCL_WIDE_INT_IS_LONG */
      </verbatim>
      
      A technical note: for me it seems to be more logical to change the order for __GCC__ and _WIN32, because the __GCC__ branch works in any case, whether Windows or not:
      
      <verbatim>
      #if defined(__GCC__)
      #   ...
      #elif defined(_WIN32)
      #   ...
      #endif
      </verbatim>
      
      At this place I suggest to use the opportunity for modernizing the definitions of 64 bit support based on C99, see this example:
      
      <verbatim>
      #if HAVE_STDINT_H
      #   include <stdint.h>
      #elif defined(_MSC_VER) && _MSC_VER < 1600
      /* work around for the support of ancient compilers */
      #   include "tkWinStdInt.h"
      #else
      /* this is not expected with compilers from this century, except MSVC (handled above) */
      #   error "C99 support is required - can't include stdint.h"
      #endif
      
      typedef int64_t  Tcl_WideInt;
      typedef uint64_t Tcl_WideUInt;
      
      #if HAVE_STDINT_H
      #   if (UINTPTR_MAX == 0xffffffffu)
      #	define TCL_IS_32_BIT_ARCH
      #   elif (UINTPTR_MAX >= 0xffffffffffffffffu)
              /* We handle >64 bit also as 64 bit architectures. */
      #	define TCL_IS_64_BIT_ARCH
      #   else
      #	error "unsupported architecture" /* can never happen */
      #   endif
      #elif defined(_WIN64) /* ancient compiler support */
      #   define TCL_IS_64_BIT_ARCH
      #elif defined(_WIN32) /* ancient compiler support */
      #   define TCL_IS_32_BIT_ARCH
      #else
      #   error "cannot detect architecture" /* can never happen */
      #endif /* HAVE_STDINT_H */
      
      #if TCL_IS_64_BIT_ARCH
      #   define Tcl_WideAsLong(val)    ((long)(val))
          ...
      #else  /* if TCL_IS_32_BIT_ARCH */
      #   define Tcl_WideAsLong(val)    ((long)((Tcl_WideInt)(val)))
          ...
      #endif /* TCL_IS_64_BIT_ARCH */
      
      #if defined(_MSC_VER) /* only MSVC (Windows) */
      #   define TCL_LL_MODIFIER    "I64"
      #elif defined(TCL_IS_64_BIT_ARCH)
      #   define TCL_LL_MODIFIER    "l"
      #else /* if TCL_IS_32_BIT_ARCH */
      #   define TCL_LL_MODIFIER    "ll"
      #endif /* _WIN32 */
      
      ...
      </verbatim>
      
      <p>
      For file tkWinStdInt.h see repository of Tk project <a href="http://core.tcl.tk/tk/timeline?r=revised_text&nd&c=2017-03-23+10%3A03%3A05&n=200">revised_text</a>. Note that every compiler of these days is supplying the header files <stdint.h> and <inttypes.h> (belongs to C99). The ancient compiler support (old MSVC versions) is only for ActiveState (they don't have enough money for a newer compiler?).
      
      <p>
      Please ote that the Tk developers would benefit with the modern definitions, because in this project <stdint.h> will be used, and also the differentiation between 32 and 64 bit architectures is important for Tk.
      
    5. foundin initialized to: "8.6/8.7"
    6. is_private initialized to: "0"
    7. login: "anonymous"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "9b7155594aadef44d10a978838b8fe108cdafdd1"
    10. resolution initialized to: "None"
    11. severity initialized to: "Important"
    12. status initialized to: "Open"
    13. submitter initialized to: "anonymous"
    14. subsystem initialized to: "69. Other"
    15. title initialized to:
      Mechanism with 64 bit support in tcl.h does not work outside of core
      
    16. type initialized to: "Bug"
  2. Ticket change [a55978405d] (rid 152627) by anonymous on 2017-03-23 19:06:48:

    1. comment changed to:
      For 64 bit support in tcl.h the following constants will be used: TCL_WIDE_INT_TYPE (on 32 bit arch) or TCL_WIDE_INT_IS_LONG (on 64 bit arch).
      
      <p>
      With Mac the following (stripped) code seems to work:
      
      <verbatim>
      #ifdef __APPLE__
      #   ifdef __LP64__
      #       undef TCL_WIDE_INT_TYPE
      #	define TCL_WIDE_INT_IS_LONG 1
      #    else /* !__LP64__ */
      #       define TCL_WIDE_INT_TYPE long long
      #       undef TCL_WIDE_INT_IS_LONG
      #    endif /* __LP64__ */
      #endif /* __APPLE__ */
      </verbatim>
      
      For Windows/Linux/UNIX it cannot work properly, see this annotated code snippet:
      
      <verbatim>
      #if !defined(TCL_WIDE_INT_TYPE)&&!defined(TCL_WIDE_INT_IS_LONG)*
      /*****************************************************************
       This is the case when compiling outside of Tcl core, because none
       of these constants is pre-defined. Mac is excluded here, because
       handled above.
      *******************************************************************/
      #   if defined(_WIN32)
      /******************************************************************
       This branch will be reached when compiling under Windows, even
       when compiling with any other compiler than MSVC.
       Now TCL_WIDE_INT_TYPE will be defined even on 64 bit architectures,
       but due to documentation on 64 bit architectures the constant
       TCL_WIDE_INT_IS_LONG should be defined instead.
       Note that on 64 bit machines the constant _WIN32 is also
       pre-defined.
       Also note that the definition of TCL_WIDE_INT_TYPE is probably
       incorrect when compiling with an other compiler than MSVC.
      *******************************************************************/
      #      define TCL_WIDE_INT_TYPE __int64
      #      ifdef __BORLANDC__
      #         define TCL_LL_MODIFIER  "L"
      #      else /* __BORLANDC__ */
      #         define TCL_LL_MODIFIER  "I64"
      #      endif /* __BORLANDC__ */
      #   elif defined(__GNUC__)
      /******************************************************************
       This is the case when compiling with gcc under Linux/UNIX.
       Now TCL_WIDE_INT_TYPE will be defined, whether 32 bit or 64 bit
       architecture, but due to documentation on 64 bit architectures
       the constant TCL_WIDE_INT_IS_LONG should be defined instead.
       And the definition of TCL_LL_MODIFIER is incorrect on 64 bit
       architectures, should be "l" instead.
      *******************************************************************/
      #      define TCL_WIDE_INT_TYPE long long
      #      define TCL_LL_MODIFIER "ll"
      #   else /* ! _WIN32 && ! __GNUC__ */
      #      ...
      #   endif /* _WIN32 */
      #endif /* !TCL_WIDE_INT_TYPE & !TCL_WIDE_INT_IS_LONG */
      </verbatim>
      
      A technical note: for me it seems to be more logical to change the order for __GCC__ and _WIN32, because the __GCC__ branch works in any case, whether Windows or not:
      
      <verbatim>
      #if defined(__GCC__)
      #   ...
      #elif defined(_WIN32)
      #   ...
      #endif
      </verbatim>
      
      At this place I suggest to use the opportunity for modernizing the definitions of 64 bit support based on C99, see this example:
      
      <verbatim>
      #if HAVE_STDINT_H
      #   include <stdint.h>
      #elif defined(_MSC_VER) && _MSC_VER < 1600
      /* work around for the support of ancient compilers */
      #   include "tkWinStdInt.h"
      #else
      /* this is not expected with compilers from this century, except MSVC (handled above) */
      #   error "C99 support is required - can't include stdint.h"
      #endif
      
      typedef int64_t  Tcl_WideInt;
      typedef uint64_t Tcl_WideUInt;
      
      #if HAVE_STDINT_H
      #   if (UINTPTR_MAX == 0xffffffffu)
      #	define TCL_IS_32_BIT_ARCH
      #   elif (UINTPTR_MAX >= 0xffffffffffffffffu)
              /* We handle >64 bit also as 64 bit architectures. */
      #	define TCL_IS_64_BIT_ARCH
      #   else
      #	error "unsupported architecture" /* can never happen */
      #   endif
      #elif defined(_WIN64) /* ancient compiler support */
      #   define TCL_IS_64_BIT_ARCH
      #elif defined(_WIN32) /* ancient compiler support */
      #   define TCL_IS_32_BIT_ARCH
      #else
      #   error "cannot detect architecture" /* can never happen */
      #endif /* HAVE_STDINT_H */
      
      #if TCL_IS_64_BIT_ARCH
      #   define Tcl_WideAsLong(val)    ((long)(val))
          ...
      #else  /* if TCL_IS_32_BIT_ARCH */
      #   define Tcl_WideAsLong(val)    ((long)((Tcl_WideInt)(val)))
          ...
      #endif /* TCL_IS_64_BIT_ARCH */
      
      #if defined(_MSC_VER) /* only MSVC (Windows) */
      #   define TCL_LL_MODIFIER    "I64"
      #elif defined(TCL_IS_64_BIT_ARCH)
      #   define TCL_LL_MODIFIER    "l"
      #else /* if TCL_IS_32_BIT_ARCH */
      #   define TCL_LL_MODIFIER    "ll"
      #endif /* _WIN32 */
      
      ...
      </verbatim>
      
      <p>
      For file tkWinStdInt.h see repository of Tk project <a href="http://core.tcl.tk/tk/timeline?r=revised_text&nd&c=2017-03-23+10%3A03%3A05&n=200">revised_text</a>. Note that every compiler of these days is supplying the header files <stdint.h> and <inttypes.h> (belongs to C99). The ancient compiler support (old MSVC versions) is only for ActiveState (they don't have enough money for a newer compiler?).
      
      <p>
      Please note that the Tk developers would benefit with the modern definitions, because in this project <stdint.h> will be used, and also the differentiation between 32 and 64 bit architectures is important for Tk.
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  3. Ticket change [95e00d35c9] (rid 152651) by jan.nijtmans on 2017-03-24 13:35:48:

    1. assignee changed to: "jan.nijtmans"
    2. icomment:
      So, if it (as you claim) doesn't work outside of the core, the best thing to do is create a test-case. Committed here:
          [http://core.tcl.tk/tk/info/dd4d4f822dd767de|dd4d4f822dd767de]
      This test-case works fine on any platform I know.
      
      So, what's wrong with this test-case? Why does it work despite you claiming that it doesn't work?
      
      Sure, the 64-bit support could be improved, the current macro organization is not really 'transparant'. But - still - I fail to see the bug here.
      
      In my view, TCL_LL_MODIFIER should be "I64" on Win32/Win64 (any compiler, including gcc), "l" on LP64 systems, "ll" on any other system. TCL_WIDE_INT_TYPE should be __int64 on Win32/Win64 (any compiler, including gcc), long on LP64 systems, and long long on any other system. What am I missing?
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"
    5. resolution changed to: "Works For Me"
  4. Ticket change [a5d5154860] (rid 152652) by anonymous on 2017-03-24 15:02:56:

    1. icomment:
      I don't have a 64 bit architecture, so I cannot test. On my 32 bit machine indeed the mechanism works. But I refer to verbal statements:
      
      <ol>
      <li><p>
      I asked Francois Vogel - he is compiling under Windows on a 64 bit architecture - whether the constant TCL_WIDE_INT_IS_LONG is defined, and he tested with:
      <verbatim>
      #ifdef TCL_WIDE_INT_IS_LONG
      # error here
      #endif
      </verbatim>
      His response was that the compiler accepted, with other words, TCL_WIDE_INT_IS_LONG is not defined, although he has a 64 bit machine.
      </li>
      
      <li><p>
      See <a href="http://core.tcl.tk/tk/info/cd374e7d05710373">[cd374e7d]</a> and <a href="http://core.tcl.tk/tk/info/f80552981cbc2f84">[f8055298]</a>, the author says "TCL_WIDE_INT_IS_LONG doesn't behave as expected on WIN64". I conclude that TCL_WIDE_INT_IS_LONG wasn't set on his 64 bit machine.
      </li>
      </ol>
      
      What's wrong with my analysis of tcl.h, due to my analysis it cannot work. Certainly it works if TCL_WIDE_INT_IS_LONG or TCL_WIDE_INT_TYPE is already properly defined by call of compiler - <pre>gcc -DTCL_WIDE_INT_IS_LONG=1</pre> - is it possible that in your test environment the makefile contains this definition?. Outside of Tcl core, when TCL_WIDE_INT_IS_LONG is not predefined, the mechanism cannot work.
      
      <p>
      If you remove -DTCL_WIDE_INT_IS_LONG=1, what happens now?
      
      <p>
      If it works although you have removed -DTCL_WIDE_INT_IS_LONG=1, in which line of tcl.h the correct setup (TCL_WIDE_INT_IS_LONG=1) will be done?
      
    2. login: "anonymous"
    3. mimetype: "text/html"
  5. Ticket change [1a99208b8d] (rid 152661) by jan.nijtmans on 2017-03-24 16:03:01:

    1. icomment:
      Well, I think you misunderstand the intention of TCL_WIDE_INT_IS_LONG. On Win64, sizeof(long) == 4 and sizeof(void *) == 8. So, although pointers are 64-bit, long is 32-bit. So it is correct that on Win32/Win64, TCL_WIDE_INT_IS_LONG is NOT
      defined. That's as expected! TCL_WIDE_INT_IS_LONG doesn't tell anything about the platform being 32-bit or 64-bit. It just tells whether "long" is 32-bit or 64-bit. Not really what you expect, isn't it?
      
      In your analysis, you expect TCL_WIDE_INT_IS_LONG to be set on Win64. Well, that's incorrect, and that's where your analysis is wrong. Sorry ;-)
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/plain"
  6. Ticket change [575eb8fb40] (rid 152662) by anonymous on 2017-03-24 17:33:14:

    1. icomment:
      Yes, I trapped into a pitfall because of this comment in tcl.h:
      
      <verbatim>
       * TCL_WIDE_INT_IS_LONG - if wide ints are really longs (i.e. we're on a real
       *	64-bit system.)
      </verbatim>
      
      This comment "we're on a real 64-bit system" is misleading. That's why I've used this constant for testing whether it's a 64 bit machine. But probably I didn't understand the term "real" here.
      
      <p>
      BTW: And this shows that a modernization is more clear, because in C99 you can simply use:
      
      <verbatim>
      typedef uint64_t Tcl_WideInt;
      #define TCL_LL_MODIFIER __PRI64_PREFIX
      </verbatim>
      
      <p>
      But of course here the name TCL_LL_MODIFIER is not useful anymore, should be TCL_WIDE_INT_MODIFIER.
      
    2. login: "anonymous"
    3. mimetype: "text/html"