Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 80177cbee3d0025d34a6dc423f56b6dc5992ee12
Ticket: 2651823fffffffffffffffffffffffffffffffff
Tcl_StatBuf definition problem with VS2005 and Win XP x64
User & Date: patthoyts on 2009-04-30 16:56:29
Changes

  1. icomment:
    This is a bigger mess than I thought. Using the following program we can explore the size of the Tcl_StatBuf structure members for Tcl compiled with various compilers:
    #include <sys/stat.h>
    #include <tcl.h>
    int main(void) {
        Tcl_StatBuf st; st.st_size = 0;
        printf("time_t %u st_size %u st_atime %u\n",
            sizeof(time_t), sizeof(st.st_size), sizeof(st.st_atime));
        return 0;
    }
    Using this with tcl8.4 headers we get:
    ix86 gcc-3.4.5 time_t 4 st_size 4 st_atime 4
    ix86 msvc-6    time_t 4 st_size 8 st_atime 4
    ix86 msvc-9    time_t 8 st_size 8 st_atime 8
    
    amd64 msvc9     time_t 8 st_size 8 st_atime 8
    amd64 msvc8     time_t 8 st_size 8 st_atime 8
    amd64 gcc-4.4.0 time_t 8 st_size 4 st_atime 8 
    
    So it's pretty well screwed whichever way you go. There is no chance that an extension compiled with gcc will be able to use this structure properly in a msvc compiled tclsh.
    
    We can fix this with the most hideously complex looking pile of crap:
    #if defined(__GNUC__)
    #    if defined(_WIN64)
    typedef struct _stat64 Tcl_StatBuf;
    #    else /* !_WIN64 */
    typedef struct _stati64 Tcl_StatBuf;
    #    endif /* !_WIN64 */
    #else /* !__GNUC__*/
    #    if defined(__BORLANDC__)
    typedef struct stati64 Tcl_StatBuf;
    #    else /* !__BORLANDC__ */
    #        if _MSC_VER < 1500
    typedef struct _stati64 Tcl_StatBuf;
    #        else  /* _MSC_VER >= 1500 */
    #            if defined(_M_IX86)
    #                define _USE_32BIT_TIME_T
    typedef struct _stat32i64 Tcl_StatBuf;
    #            else /* !defined(_M_IX86) */
    typedef struct _stat64 Tcl_StatBuf;
    #            endif /* !defined(_M_IX86) */
    #        endif /* _MSC_VER >= 1400 */
    #    endif /* !__BORLANDC__ */
    #endif /* !__GNUC__*/
    
    This produces a 32bit time_t and 64bit st_size member for 32 bit Windows with msvc6 and 9 and gcc 3. On 64bit windows we get 64 bit time_t and 64 bit st_size. 
    
    With msvc9 (aka MSVC 2008 or cl 1500) the compiler headers for IX86 seem to produce a 64bit time_t by default so I've had to include the _USE_32BIT_TIME_T. I don't understand the use of this in the Microsoft headers. In the newer gcc headers they define this macro when the target system will be a 32 bit version of windows which seems correct. In the MSVC headers, with this macro defined _stati64 becomes defined as _stat32i64 which is what we need.
    
    Hideous.
    
    Given that this is utterly broken anyway I see no reason not to use an explicitly defined structure with the correct Tcl types as mentioned is earlier posts.
    
    
  2. login: "patthoyts"
  3. mimetype: "text/plain"
  4. username: "patthoyts"