Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

Location:
python/vendor/current/PC
Files:
1 added
82 edited
1 moved

Legend:

Unmodified
Added
Removed
  • python/vendor/current/PC/VC6/_bsddb.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\..\db-4.7.25\build_windows" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\..\db-4.7.25\build_windows" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\..\db-4.7.25\build_windows" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\..\db-4.7.25\build_windows" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
  • python/vendor/current/PC/VC6/_ctypes.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\Modules\_ctypes\libffi_msvc" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\Modules\_ctypes\libffi_msvc" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\Modules\_ctypes\libffi_msvc" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\Modules\_ctypes\libffi_msvc" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
  • python/vendor/current/PC/VC6/_ctypes_test.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
  • python/vendor/current/PC/VC6/_elementtree.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D "BYTEORDER=1234" /D "XML_CONTEXT_BYTES=1024" /D "USE_PYEXPAT_CAPI" /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D "BYTEORDER=1234" /D "XML_CONTEXT_BYTES=1024" /D "USE_PYEXPAT_CAPI" /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D "BYTEORDER=1234" /D "XML_CONTEXT_BYTES=1024" /D "USE_PYEXPAT_CAPI" /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D "BYTEORDER=1234" /D "XML_CONTEXT_BYTES=1024" /D "USE_PYEXPAT_CAPI" /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
  • python/vendor/current/PC/VC6/_msi.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
  • python/vendor/current/PC/VC6/_multiprocessing.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
  • python/vendor/current/PC/VC6/_socket.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
  • python/vendor/current/PC/VC6/_sqlite3.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\..\sqlite-source-3.3.4" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D MODULE_NAME=\"sqlite3\" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\..\sqlite-source-3.3.4" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D MODULE_NAME=\"sqlite3\" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\..\sqlite-source-3.3.4" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D MODULE_NAME=\"sqlite3\" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\..\sqlite-source-3.3.4" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D MODULE_NAME=\"sqlite3\" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
  • python/vendor/current/PC/VC6/_testcapi.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\Include" /I ".." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
  • python/vendor/current/PC/VC6/_tkinter.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\..\tcltk\include" /I "..\..\Include" /I ".." /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "WITH_APPINIT" /YX /FD /c
     46# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\..\tcltk\include" /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "WITH_APPINIT" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\..\tcltk\include" /I "..\..\Include" /I ".." /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "WITH_APPINIT" /YX /FD /c
     74# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\..\tcltk\include" /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "WITH_APPINIT" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
  • python/vendor/current/PC/VC6/build_ssl.py

    r2 r388  
    1313# it should configure and build SSL, then build the ssl Python extension
    1414# without intervention.
     15
     16# Modified by Christian Heimes
     17# Now this script supports pre-generated makefiles and assembly files.
     18# Developers don't need an installation of Perl anymore to build Python. A svn
     19# checkout from our svn repository is enough.
    1520
    1621import os, sys, re, shutil
     
    3742def find_working_perl(perls):
    3843    for perl in perls:
    39         fh = os.popen(perl + ' -e "use Win32;"')
     44        fh = os.popen('"%s" -e "use Win32;"' % perl)
    4045        fh.read()
    4146        rc = fh.close()
     
    121126    os.system(do_script)
    122127
     128def cmp(f1, f2):
     129    bufsize = 1024 * 8
     130    with open(f1, 'rb') as fp1, open(f2, 'rb') as fp2:
     131        while True:
     132            b1 = fp1.read(bufsize)
     133            b2 = fp2.read(bufsize)
     134            if b1 != b2:
     135                return False
     136            if not b1:
     137                return True
     138
     139def copy(src, dst):
     140    if os.path.isfile(dst) and cmp(src, dst):
     141        return
     142    shutil.copy(src, dst)
     143
    123144def main():
    124145    debug = "-d" in sys.argv
     
    130151        makefile="ms\\nt.mak"
    131152        m32 = makefile
     153        dirsuffix = "32"
    132154    configure += " no-idea no-rc5 no-mdc2"
    133155    make_flags = ""
     
    138160    perls = find_all_on_path("perl.exe", ["\\perl\\bin", "C:\\perl\\bin"])
    139161    perl = find_working_perl(perls)
    140     if perl is None:
     162    if perl:
     163        print "Found a working perl at '%s'" % (perl,)
     164    else:
    141165        print "No Perl installation was found. Existing Makefiles are used."
    142     else:
    143         print "Found a working perl at '%s'" % (perl,)
    144166    sys.stdout.flush()
    145     # Look for SSL 3 levels up from pcbuild - ie, same place zlib etc all live.
     167    # Look for SSL 3 levels up from PC/VC6 - ie, same place zlib etc all live.
    146168    ssl_dir = find_best_ssl_dir(("..\\..\\..",))
    147169    if ssl_dir is None:
     
    174196
    175197            fix_makefile(makefile)
    176             shutil.copy(r"crypto\buildinf.h", r"crypto\buildinf_%s.h" % arch)
    177             shutil.copy(r"crypto\opensslconf.h", r"crypto\opensslconf_%s.h" % arch)
     198            copy(r"crypto\buildinf.h", r"crypto\buildinf_%s.h" % arch)
     199            copy(r"crypto\opensslconf.h", r"crypto\opensslconf_%s.h" % arch)
     200
     201        # If the assembler files don't exist in tmpXX, copy them there
     202        if perl is None:
     203            if not os.path.exists("tmp"+dirsuffix):
     204                os.mkdir("tmp"+dirsuffix)
     205            for f in os.listdir("asm"+dirsuffix):
     206                if not f.endswith(".asm"): continue
     207                if os.path.isfile(r"tmp%s\%s" % (dirsuffix, f)): continue
     208                shutil.copy(r"asm%s\%s" % (dirsuffix, f), "tmp"+dirsuffix)
    178209
    179210        # Now run make.
    180         shutil.copy(r"crypto\buildinf_%s.h" % arch, r"crypto\buildinf.h")
    181         shutil.copy(r"crypto\opensslconf_%s.h" % arch, r"crypto\opensslconf.h")
     211        copy(r"crypto\buildinf_%s.h" % arch, r"crypto\buildinf.h")
     212        copy(r"crypto\opensslconf_%s.h" % arch, r"crypto\opensslconf.h")
    182213
    183214        #makeCommand = "nmake /nologo PERL=\"%s\" -f \"%s\"" %(perl, makefile)
  • python/vendor/current/PC/VC6/bz2.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\..\bzip2-1.0.5" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\..\bzip2-1.0.6" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    5555LINK32=link.exe
    5656# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
    57 # ADD LINK32 ..\..\..\bzip2-1.0.5\libbz2.lib /nologo /base:"0x1D170000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./bz2.pyd"
     57# ADD LINK32 ..\..\..\bzip2-1.0.6\libbz2.lib /nologo /base:"0x1D170000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./bz2.pyd"
    5858# SUBTRACT LINK32 /pdb:none /nodefaultlib
    5959
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\..\bzip2-1.0.5" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\..\bzip2-1.0.6" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
     
    8383LINK32=link.exe
    8484# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
    85 # ADD LINK32 ..\..\..\bzip2-1.0.5\libbz2.lib /nologo /base:"0x1D170000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"msvcrt" /nodefaultlib:"libc" /out:"./bz2_d.pyd" /pdbtype:sept
     85# ADD LINK32 ..\..\..\bzip2-1.0.6\libbz2.lib /nologo /base:"0x1D170000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"msvcrt" /nodefaultlib:"libc" /out:"./bz2_d.pyd" /pdbtype:sept
    8686# SUBTRACT LINK32 /pdb:none
    8787
  • python/vendor/current/PC/VC6/pyexpat.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D BYTEORDER=1234 /D XML_CONTEXT_BYTES=1024 /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D BYTEORDER=1234 /D XML_CONTEXT_BYTES=1024 /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "_DEBUG" /D "HAVE_EXPAT_H" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D BYTEORDER=1234 /D XML_CONTEXT_BYTES=1024 /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "HAVE_EXPAT_H" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D BYTEORDER=1234 /D XML_CONTEXT_BYTES=1024 /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
  • python/vendor/current/PC/VC6/pythoncore.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\modules\zlib" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_DL_EXPORT" /YX /FD /Zm200 /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\modules\zlib" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_DL_EXPORT" /YX /FD /Zm200 /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
     
    5555LINK32=link.exe
    5656# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
    57 # ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e000000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python26.dll"
     57# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e000000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python27.dll"
    5858# SUBTRACT LINK32 /pdb:none
    5959
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\modules\zlib" /D "_DEBUG" /D "USE_DL_EXPORT" /D "WIN32" /D "_WINDOWS" /YX /FD /Zm200 /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\modules\zlib" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "USE_DL_EXPORT" /D "WIN32" /D "_WINDOWS" /YX /FD /Zm200 /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
     
    8383LINK32=link.exe
    8484# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
    85 # ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e000000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python26_d.dll" /pdbtype:sept
     85# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e000000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python27_d.dll" /pdbtype:sept
    8686# SUBTRACT LINK32 /pdb:none
    8787
     
    9898# Begin Source File
    9999
    100 SOURCE=..\..\Modules\_bytesio.c
    101 # End Source File
    102 # Begin Source File
    103 
    104100SOURCE=..\..\Modules\cjkcodecs\_codecs_cn.c
    105101# End Source File
     
    138134# Begin Source File
    139135
    140 SOURCE=..\..\Modules\_fileio.c
    141 # End Source File
    142 # Begin Source File
    143 
    144136SOURCE=..\..\Modules\_functoolsmodule.c
    145137# End Source File
     
    154146# Begin Source File
    155147
     148SOURCE=..\..\Modules\_io\_iomodule.c
     149# End Source File
     150# Begin Source File
     151
    156152SOURCE=..\..\Modules\_json.c
    157153# End Source File
     
    166162# Begin Source File
    167163
     164SOURCE=..\..\Modules\_math.c
     165# End Source File
     166# Begin Source File
     167
    168168SOURCE=..\..\Modules\_randommodule.c
    169169# End Source File
     
    238238# Begin Source File
    239239
     240SOURCE=..\..\Modules\_io\bufferedio.c
     241# End Source File
     242# Begin Source File
     243
    240244SOURCE=..\..\Objects\bufferobject.c
    241245# End Source File
     
    246250# Begin Source File
    247251
     252SOURCE=..\..\Modules\_io\bytesio.c
     253# End Source File
     254# Begin Source File
     255
    248256SOURCE=..\..\Objects\bytes_methods.c
    249257# End Source File
    250258# Begin Source File
    251259
     260SOURCE=..\..\Objects\capsule.c
     261# End Source File
     262# Begin Source File
     263
    252264SOURCE=..\..\Objects\cellobject.c
    253265# End Source File
     
    326338# Begin Source File
    327339
     340SOURCE=..\..\Python\dtoa.c
     341# End Source File
     342# Begin Source File
     343
    328344SOURCE=..\..\Python\dynload_win.c
    329345# End Source File
     
    343359
    344360SOURCE=..\..\Objects\exceptions.c
     361# End Source File
     362# Begin Source File
     363
     364SOURCE=..\..\Modules\_io\fileio.c
    345365# End Source File
    346366# Begin Source File
     
    411431# Begin Source File
    412432
    413 SOURCE=..\..\Python\getmtime.c
    414 # End Source File
    415 # Begin Source File
    416 
    417433SOURCE=..\..\Python\getopt.c
    418434# End Source File
     
    444460
    445461SOURCE=..\..\Modules\zlib\gzio.c
     462# End Source File
     463# Begin Source File
     464
     465SOURCE=..\..\Modules\_io\iobase.c
    446466# End Source File
    447467# Begin Source File
     
    524544# Begin Source File
    525545
     546SOURCE=..\..\Objects\memoryobject.c
     547# End Source File
     548# Begin Source File
     549
    526550SOURCE=..\..\Parser\metagrammar.c
    527551# End Source File
     
    604628# Begin Source File
    605629
     630SOURCE=..\..\Python\pyctype.c
     631# End Source File
     632# Begin Source File
     633
    606634SOURCE=..\..\Python\pyfpe.c
    607635# End Source File
     
    636664# Begin Source File
    637665
     666SOURCE=..\..\Python\random.c
     667# End Source File
     668# Begin Source File
     669
    638670SOURCE=..\..\Objects\rangeobject.c
    639671# End Source File
     
    668700# Begin Source File
    669701
     702SOURCE=..\..\Modules\_io\stringio.c
     703# End Source File
     704# Begin Source File
     705
    670706SOURCE=..\..\Objects\stringobject.c
    671707# End Source File
     
    696732# Begin Source File
    697733
     734SOURCE=..\..\Modules\_io\textio.c
     735# End Source File
     736# Begin Source File
     737
    698738SOURCE=..\..\Python\thread.c
    699739# End Source File
     
    745785
    746786SOURCE=..\..\Modules\xxsubtype.c
    747 # End Source File
    748 # Begin Source File
    749 
    750 SOURCE=..\..\Modules\yuvconvert.c
    751787# End Source File
    752788# Begin Source File
  • python/vendor/current/PC/VC6/readme.txt

    r2 r388  
    22-------------------------------------
    33This directory is used to build Python for Win32 platforms, e.g. Windows
    4 2000 and XP.  It requires Microsoft Visual C++ 6.x or 5.x.
     42000 and XP.  It requires Microsoft Visual C++ 6.x or 5.x and Platform
     5SDK February 2003 Edition (Core SDK).
    56(For other Windows platforms and compilers, see ../readme.txt.)
    67
     
    1213
    13141) pythoncore (this builds the main Python DLL and library files,
    14                python26.{dll, lib} in Release mode)
     15               python27.{dll, lib} in Release mode)
    1516
    16172) python (this builds the main Python executable,
     
    2324
    2425When using the Debug setting, the output files have a _d added to
    25 their name:  python26_d.dll, python_d.exe, pyexpat_d.pyd, and so on.
     26their name:  python27_d.dll, python_d.exe, pyexpat_d.pyd, and so on.
    2627
    2728SUBPROJECTS
     
    4041_msi
    4142    _msi.c. You need to install Windows Installer SDK to build this module.
    42     http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm
    4343_socket
    4444    socketmodule.c
     
    121121    directory:
    122122
    123     svn export http://svn.python.org/projects/external/bzip2-1.0.5
     123    svn export http://svn.python.org/projects/external/bzip2-1.0.6
    124124
    125125    And requires building bz2 first.
    126126
    127     cd dist\bzip2-1.0.5
     127    cd dist\bzip2-1.0.6
    128128    nmake -f makefile.msc
    129129
    130     All of this managed to build bzip2-1.0.5\libbz2.lib, which the Python
     130    All of this managed to build bzip2-1.0.6\libbz2.lib, which the Python
    131131    project links in.
    132132
     
    203203        http://www.openssl.org
    204204
    205     You (probably) don't want the "engine" code.  For example, get
    206         openssl-0.9.8g.tar.gz
    207     not
    208         openssl-engine-0.9.8g.tar.gz
     205    You (probably) don't want the "engine" code.  For example, don't get
     206        openssl-engine-0.9.6g.tar.gz
    209207
    210208    Unpack into the "dist" directory, retaining the folder name from
    211209    the archive - for example, the latest stable OpenSSL will install as
    212         dist/openssl-0.9.8g
     210        dist/openssl-1.0.0a
    213211
    214212    You can (theoretically) use any version of OpenSSL you like - the
    215213    build process will automatically select the latest version.
    216214
    217     You must also install ActivePerl from
    218         http://www.activestate.com/Products/ActivePerl/
    219     as this is used by the OpenSSL build process.  Complain to them <wink>.
     215    You can install the NASM assembler from
     216        http://www.nasm.us/
     217    for x86 builds.  Put nasmw.exe anywhere in your PATH.
     218    Note: recent releases of nasm only have nasm.exe. Just rename it to
     219    nasmw.exe.
     220
     221    You can also install ActivePerl from
     222        http://www.activestate.com/activeperl/
     223    if you like to use the official sources instead of the files from
     224    python's subversion repository. The svn version contains pre-build
     225    makefiles and assembly files.
    220226
    221227    The MSVC project simply invokes PC/VC6/build_ssl.py to perform
  • python/vendor/current/PC/VC6/select.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\..\select113" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
     
    5555LINK32=link.exe
    5656# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
    57 # ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /base:"0x1D110000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./select.pyd"
     57# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /base:"0x1D110000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./select.pyd"
    5858# SUBTRACT LINK32 /pdb:none
    5959
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\..\select113" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
     
    8383LINK32=link.exe
    8484# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
    85 # ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /base:"0x1D110000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /nodefaultlib:"msvcrt" /out:"./select_d.pyd" /pdbtype:sept
     85# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /base:"0x1D110000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /nodefaultlib:"msvcrt" /out:"./select_d.pyd" /pdbtype:sept
    8686# SUBTRACT LINK32 /pdb:none
    8787
  • python/vendor/current/PC/VC6/tcl852.patch

    r2 r388  
    1010 #         else
    1111 typedef struct _stat64 Tcl_StatBuf;
    12 --- tcl8.5.2\generic\tcl.h      Fri Jun 13 03:35:39 2008
    13 +++ tcl8.5.2\generic\tcl.h      Sun Jan  4 16:52:30 2009
    14 @@ -367,7 +367,7 @@
    15  typedef struct stati64 Tcl_StatBuf;
    16  #         define TCL_LL_MODIFIER       "L"
    17  #      else /* __BORLANDC__ */
    18 -#         if _MSC_VER < 1400 && !defined(_M_IX86)
    19 +#         if _MSC_VER < 1400 /*&& !defined(_M_IX86)*/
    20  typedef struct _stati64        Tcl_StatBuf;
    21  #         else
    22  typedef struct _stat64 Tcl_StatBuf;
  • python/vendor/current/PC/VC6/unicodedata.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\Include" /I ".." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
  • python/vendor/current/PC/VC6/w9xpopen.dsp

    r2 r388  
    4343# PROP Ignore_Export_Lib 0
    4444# PROP Target_Dir ""
    45 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
    46 # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
     45# ADD BASE CPP /nologo /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
     46# ADD CPP /nologo /MD /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
    4747# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
    4848# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
     
    7070# PROP Ignore_Export_Lib 0
    7171# PROP Target_Dir ""
    72 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
    73 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
     72# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
     73# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
    7474# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
    7575# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
  • python/vendor/current/PC/VC6/winsound.dsp

    r2 r388  
    4444# PROP Target_Dir ""
    4545F90=df.exe
    46 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /c
    47 # ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\Include" /I ".." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /c
     46# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /c
     47# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /c
    4848# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
    4949# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
     
    7272# PROP Target_Dir ""
    7373F90=df.exe
    74 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /GZ /c
    75 # ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /GZ /c
     74# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /GZ /c
     75# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /GZ /c
    7676# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
    7777# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
  • python/vendor/current/PC/VS7.1/_bsddb.vcproj

    r2 r388  
    2222                                Optimization="0"
    2323                                AdditionalIncludeDirectories="..\..\Include;..\..\PC;&quot;..\..\..\db-4.4.20\build_win32&quot;"
    24                                 PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS"
     24                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;_DEBUG;WIN32;_WINDOWS"
    2525                                RuntimeLibrary="3"
    2626                                UsePrecompiledHeader="2"
     
    7777                                InlineFunctionExpansion="1"
    7878                                AdditionalIncludeDirectories="..\..\Include;..\..\PC;&quot;..\..\..\db-4.4.20\build_win32&quot;"
    79                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     79                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    8080                                StringPooling="TRUE"
    8181                                RuntimeLibrary="2"
     
    135135                                InlineFunctionExpansion="1"
    136136                                AdditionalIncludeDirectories="..\..\Include;..\..\PC;&quot;..\..\..\db-4.4.20\build_win32&quot;"
    137                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     137                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    138138                                StringPooling="TRUE"
    139139                                BasicRuntimeChecks="0"
     
    197197                                InlineFunctionExpansion="1"
    198198                                AdditionalIncludeDirectories="..\..\Include;..\..\PC;&quot;..\..\..\db-4.4.20\build_win32&quot;"
    199                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     199                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    200200                                StringPooling="TRUE"
    201201                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/_ctypes.vcproj

    r2 r388  
    2222                                Optimization="0"
    2323                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\_ctypes\libffi_msvc"
    24                                 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
     24                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;_DEBUG;_WINDOWS"
    2525                                MinimalRebuild="FALSE"
    2626                                BasicRuntimeChecks="3"
     
    7676                                InlineFunctionExpansion="1"
    7777                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\_ctypes\libffi_msvc"
    78                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
     78                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS"
    7979                                StringPooling="TRUE"
    8080                                RuntimeLibrary="2"
     
    133133                                InlineFunctionExpansion="1"
    134134                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\_ctypes\libffi_msvc"
    135                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
     135                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS"
    136136                                StringPooling="TRUE"
    137137                                BasicRuntimeChecks="0"
     
    192192                                InlineFunctionExpansion="1"
    193193                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\_ctypes\libffi_msvc"
    194                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
     194                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS"
    195195                                StringPooling="TRUE"
    196196                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/_ctypes_test.vcproj

    r2 r388  
    2121                                Optimization="0"
    2222                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    23                                 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
     23                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;_DEBUG;_WINDOWS"
    2424                                MinimalRebuild="FALSE"
    2525                                BasicRuntimeChecks="3"
     
    7373                                InlineFunctionExpansion="1"
    7474                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    75                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
     75                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS"
    7676                                StringPooling="TRUE"
    7777                                RuntimeLibrary="2"
     
    128128                                Optimization="0"
    129129                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    130                                 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
     130                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;_DEBUG;_WINDOWS"
    131131                                MinimalRebuild="FALSE"
    132132                                BasicRuntimeChecks="0"
     
    183183                                InlineFunctionExpansion="1"
    184184                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    185                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
     185                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS"
    186186                                StringPooling="TRUE"
    187187                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/_elementtree.vcproj

    r2 r388  
    2323                                Optimization="0"
    2424                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\expat"
    25                                 PreprocessorDefinitions="_DEBUG;HAVE_EXPAT_H;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;USE_PYEXPAT_CAPI;XML_STATIC;HAVE_MEMMOVE"
     25                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;_DEBUG;HAVE_EXPAT_H;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;USE_PYEXPAT_CAPI;XML_STATIC;HAVE_MEMMOVE"
    2626                                RuntimeLibrary="3"
    2727                                UsePrecompiledHeader="2"
     
    7676                                InlineFunctionExpansion="1"
    7777                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\expat"
    78                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;USE_PYEXPAT_CAPI;XML_STATIC;HAVE_MEMMOVE"
     78                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;USE_PYEXPAT_CAPI;XML_STATIC;HAVE_MEMMOVE"
    7979                                StringPooling="TRUE"
    8080                                RuntimeLibrary="2"
     
    132132                                InlineFunctionExpansion="1"
    133133                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\expat"
    134                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;USE_PYEXPAT_CAPI;XML_STATIC;HAVE_MEMMOVE"
     134                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;USE_PYEXPAT_CAPI;XML_STATIC;HAVE_MEMMOVE"
    135135                                StringPooling="TRUE"
    136136                                BasicRuntimeChecks="0"
     
    192192                                InlineFunctionExpansion="1"
    193193                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\expat"
    194                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;USE_PYEXPAT_CAPI;XML_STATIC;HAVE_MEMMOVE"
     194                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;USE_PYEXPAT_CAPI;XML_STATIC;HAVE_MEMMOVE"
    195195                                StringPooling="TRUE"
    196196                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/_msi.vcproj

    r2 r388  
    2424                                Optimization="0"
    2525                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    26                                 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL"
     26                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;_DEBUG;_WINDOWS;_USRDLL"
    2727                                BasicRuntimeChecks="3"
    2828                                RuntimeLibrary="3"
     
    7979                                InlineFunctionExpansion="1"
    8080                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    81                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL"
     81                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL"
    8282                                StringPooling="TRUE"
    8383                                RuntimeLibrary="2"
     
    134134                                InlineFunctionExpansion="1"
    135135                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    136                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL"
     136                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL"
    137137                                StringPooling="TRUE"
    138138                                BasicRuntimeChecks="0"
     
    194194                                InlineFunctionExpansion="1"
    195195                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    196                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL"
     196                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL"
    197197                                StringPooling="TRUE"
    198198                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/_socket.vcproj

    r2 r388  
    2222                                Optimization="0"
    2323                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    24                                 PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS"
     24                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;_DEBUG;WIN32;_WINDOWS"
    2525                                RuntimeLibrary="3"
    2626                                UsePrecompiledHeader="2"
     
    7676                                InlineFunctionExpansion="1"
    7777                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    78                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     78                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    7979                                StringPooling="TRUE"
    8080                                RuntimeLibrary="2"
     
    133133                                InlineFunctionExpansion="1"
    134134                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    135                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     135                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    136136                                StringPooling="TRUE"
    137137                                BasicRuntimeChecks="0"
     
    194194                                InlineFunctionExpansion="1"
    195195                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    196                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     196                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    197197                                StringPooling="TRUE"
    198198                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/_sqlite3.vcproj

    r2 r388  
    2323                                Optimization="0"
    2424                                AdditionalIncludeDirectories="..\..\Include;..\..\PC;..\..\..\sqlite-source-3.3.4"
    25                                 PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;MODULE_NAME=\&quot;sqlite3\&quot;"
     25                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;_DEBUG;WIN32;_WINDOWS;MODULE_NAME=\&quot;sqlite3\&quot;"
    2626                                RuntimeLibrary="3"
    2727                                UsePrecompiledHeader="2"
     
    7878                                InlineFunctionExpansion="1"
    7979                                AdditionalIncludeDirectories="..\..\Include;..\..\PC;..\..\..\sqlite-source-3.3.4"
    80                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;MODULE_NAME=\&quot;sqlite3\&quot;"
     80                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;MODULE_NAME=\&quot;sqlite3\&quot;"
    8181                                StringPooling="TRUE"
    8282                                RuntimeLibrary="2"
     
    136136                                InlineFunctionExpansion="1"
    137137                                AdditionalIncludeDirectories="..\..\Include;..\..\PC;..\..\..\sqlite-source-3.3.4"
    138                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;MODULE_NAME=\&quot;sqlite3\&quot;"
     138                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;MODULE_NAME=\&quot;sqlite3\&quot;"
    139139                                StringPooling="TRUE"
    140140                                BasicRuntimeChecks="0"
     
    198198                                InlineFunctionExpansion="1"
    199199                                AdditionalIncludeDirectories="..\..\Include;..\..\PC;..\..\..\sqlite-source-3.3.4"
    200                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;MODULE_NAME=\&quot;sqlite3\&quot;"
     200                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;MODULE_NAME=\&quot;sqlite3\&quot;"
    201201                                StringPooling="TRUE"
    202202                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/_testcapi.vcproj

    r2 r388  
    2424                                InlineFunctionExpansion="1"
    2525                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    26                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
     26                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
    2727                                StringPooling="TRUE"
    2828                                RuntimeLibrary="2"
     
    7676                                Optimization="0"
    7777                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    78                                 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
     78                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;_DEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
    7979                                BasicRuntimeChecks="3"
    8080                                RuntimeLibrary="3"
     
    131131                                InlineFunctionExpansion="1"
    132132                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    133                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
     133                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
    134134                                StringPooling="TRUE"
    135135                                BasicRuntimeChecks="0"
     
    190190                                InlineFunctionExpansion="1"
    191191                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    192                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
     192                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
    193193                                StringPooling="TRUE"
    194194                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/_tkinter.vcproj

    r2 r388  
    2323                                InlineFunctionExpansion="1"
    2424                                AdditionalIncludeDirectories="..\..\..\tcltk\include,..\..\Include,..\..\PC"
    25                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;WITH_APPINIT"
     25                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;WITH_APPINIT"
    2626                                StringPooling="TRUE"
    2727                                RuntimeLibrary="2"
     
    7979                                Optimization="0"
    8080                                AdditionalIncludeDirectories="..\..\..\tcltk\include,..\..\Include,..\..\PC"
    81                                 PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;WITH_APPINIT"
     81                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;_DEBUG;WIN32;_WINDOWS;WITH_APPINIT"
    8282                                RuntimeLibrary="3"
    8383                                UsePrecompiledHeader="2"
     
    135135                                InlineFunctionExpansion="1"
    136136                                AdditionalIncludeDirectories="..\..\..\tcltk\include,..\..\Include,..\..\PC"
    137                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;WITH_APPINIT"
     137                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;WITH_APPINIT"
    138138                                StringPooling="TRUE"
    139139                                BasicRuntimeChecks="0"
     
    197197                                InlineFunctionExpansion="1"
    198198                                AdditionalIncludeDirectories="..\..\..\tcltk\include,..\..\Include,..\..\PC"
    199                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;WITH_APPINIT"
     199                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;WITH_APPINIT"
    200200                                StringPooling="TRUE"
    201201                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/bz2.vcproj

    r2 r388  
    2323                                Optimization="0"
    2424                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\..\bzip2-1.0.3"
    25                                 PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS"
     25                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;_DEBUG;WIN32;_WINDOWS"
    2626                                RuntimeLibrary="3"
    2727                                UsePrecompiledHeader="2"
     
    8181                                InlineFunctionExpansion="1"
    8282                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\..\bzip2-1.0.3"
    83                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     83                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    8484                                StringPooling="TRUE"
    8585                                RuntimeLibrary="2"
     
    142142                                InlineFunctionExpansion="1"
    143143                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\..\bzip2-1.0.3"
    144                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     144                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    145145                                StringPooling="TRUE"
    146146                                BasicRuntimeChecks="0"
     
    207207                                InlineFunctionExpansion="1"
    208208                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\..\bzip2-1.0.3"
    209                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     209                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    210210                                StringPooling="TRUE"
    211211                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/make_buildinfo.c

    r2 r388  
    2222int make_buildinfo2()
    2323{
    24         struct _stat st;
    25         HKEY hTortoise;
    26         char command[500];
    27         DWORD type, size;
    28         if (_stat(".svn", &st) < 0)
    29                 return 0;
    30         /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */
    31         if (_stat("no_subwcrev", &st) == 0)
    32                 return 0;
    33         if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS &&
    34             RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS)
    35                 /* Tortoise not installed */
    36                 return 0;
    37         command[0] = '"';  /* quote the path to the executable */
    38         size = sizeof(command) - 1;
    39         if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS ||
    40             type != REG_SZ)
    41                 /* Registry corrupted */
    42                 return 0;
    43         strcat(command, "bin\\subwcrev.exe");
    44         if (_stat(command+1, &st) < 0)
    45                 /* subwcrev.exe not part of the release */
    46                 return 0;
    47         strcat(command, "\" ..\\.. ..\\..\\Modules\\getbuildinfo.c getbuildinfo2.c");
    48         puts(command); fflush(stdout);
    49         if (system(command) < 0)
    50                 return 0;
    51         return 1;
     24    struct _stat st;
     25    HKEY hTortoise;
     26    char command[500];
     27    DWORD type, size;
     28    if (_stat(".svn", &st) < 0)
     29        return 0;
     30    /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */
     31    if (_stat("no_subwcrev", &st) == 0)
     32        return 0;
     33    if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS &&
     34        RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS)
     35        /* Tortoise not installed */
     36        return 0;
     37    command[0] = '"';  /* quote the path to the executable */
     38    size = sizeof(command) - 1;
     39    if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS ||
     40        type != REG_SZ)
     41        /* Registry corrupted */
     42        return 0;
     43    strcat(command, "bin\\subwcrev.exe");
     44    if (_stat(command+1, &st) < 0)
     45        /* subwcrev.exe not part of the release */
     46        return 0;
     47    strcat(command, "\" ..\\.. ..\\..\\Modules\\getbuildinfo.c getbuildinfo2.c");
     48    puts(command); fflush(stdout);
     49    if (system(command) < 0)
     50        return 0;
     51    return 1;
    5252}
    5353
    5454int main(int argc, char*argv[])
    5555{
    56         char command[500] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
    57         int do_unlink, result;
    58         if (argc != 2) {
    59                 fprintf(stderr, "make_buildinfo $(ConfigurationName)\n");
    60                 return EXIT_FAILURE;
    61         }
    62         if (strcmp(argv[1], "Release") == 0) {
    63                 strcat(command, "-MD ");
    64         }
    65         else if (strcmp(argv[1], "Debug") == 0) {
    66                 strcat(command, "-D_DEBUG -MDd ");
    67         }
    68         else if (strcmp(argv[1], "ReleaseItanium") == 0) {
    69                 strcat(command, "-MD /USECL:MS_ITANIUM ");
    70         }
    71         else if (strcmp(argv[1], "ReleaseAMD64") == 0) {
    72                 strcat(command, "-MD ");
    73                 strcat(command, "-MD /USECL:MS_OPTERON ");
    74         }
    75         else {
    76                 fprintf(stderr, "unsupported configuration %s\n", argv[1]);
    77                 return EXIT_FAILURE;
    78         }
     56    char command[500] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
     57    int do_unlink, result;
     58    if (argc != 2) {
     59        fprintf(stderr, "make_buildinfo $(ConfigurationName)\n");
     60        return EXIT_FAILURE;
     61    }
     62    if (strcmp(argv[1], "Release") == 0) {
     63        strcat(command, "-MD ");
     64    }
     65    else if (strcmp(argv[1], "Debug") == 0) {
     66        strcat(command, "-D_DEBUG -MDd ");
     67    }
     68    else if (strcmp(argv[1], "ReleaseItanium") == 0) {
     69        strcat(command, "-MD /USECL:MS_ITANIUM ");
     70    }
     71    else if (strcmp(argv[1], "ReleaseAMD64") == 0) {
     72        strcat(command, "-MD ");
     73        strcat(command, "-MD /USECL:MS_OPTERON ");
     74    }
     75    else {
     76        fprintf(stderr, "unsupported configuration %s\n", argv[1]);
     77        return EXIT_FAILURE;
     78    }
    7979
    80         if ((do_unlink = make_buildinfo2()))
    81                 strcat(command, "getbuildinfo2.c -DSUBWCREV ");
    82         else
    83                 strcat(command, "..\\..\\Modules\\getbuildinfo.c");
    84         strcat(command, " -Fogetbuildinfo.o -I..\\..\\Include -I..\\..\\PC");
    85         puts(command); fflush(stdout);
    86         result = system(command);
    87         if (do_unlink)
    88                 unlink("getbuildinfo2.c");
    89         if (result < 0)
    90                 return EXIT_FAILURE;
    91         return 0;
     80    if ((do_unlink = make_buildinfo2()))
     81        strcat(command, "getbuildinfo2.c -DSUBWCREV ");
     82    else
     83        strcat(command, "..\\..\\Modules\\getbuildinfo.c");
     84    strcat(command, " -Fogetbuildinfo.o -I..\\..\\Include -I..\\..\\PC");
     85    puts(command); fflush(stdout);
     86    result = system(command);
     87    if (do_unlink)
     88        unlink("getbuildinfo2.c");
     89    if (result < 0)
     90        return EXIT_FAILURE;
     91    return 0;
    9292}
  • python/vendor/current/PC/VS7.1/pyexpat.vcproj

    r2 r388  
    2222                                Optimization="0"
    2323                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\expat"
    24                                 PreprocessorDefinitions="_DEBUG;HAVE_EXPAT_H;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;XML_STATIC;HAVE_MEMMOVE"
     24                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;_DEBUG;HAVE_EXPAT_H;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;XML_STATIC;HAVE_MEMMOVE"
    2525                                RuntimeLibrary="3"
    2626                                UsePrecompiledHeader="2"
     
    7575                                InlineFunctionExpansion="1"
    7676                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\expat"
    77                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;XML_STATIC;HAVE_MEMMOVE"
     77                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;XML_STATIC;HAVE_MEMMOVE"
    7878                                StringPooling="TRUE"
    7979                                RuntimeLibrary="2"
     
    131131                                InlineFunctionExpansion="1"
    132132                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\expat"
    133                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;XML_STATIC;HAVE_MEMMOVE"
     133                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;XML_STATIC;HAVE_MEMMOVE"
    134134                                StringPooling="TRUE"
    135135                                BasicRuntimeChecks="0"
     
    191191                                InlineFunctionExpansion="1"
    192192                                AdditionalIncludeDirectories="..\..\Include,..\..\PC,..\..\Modules\expat"
    193                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;XML_STATIC;HAVE_MEMMOVE"
     193                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;XML_STATIC;HAVE_MEMMOVE"
    194194                                StringPooling="TRUE"
    195195                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/pythoncore.vcproj

    r2 r388  
    2626                                InlineFunctionExpansion="1"
    2727                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    28                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;USE_DL_EXPORT"
     28                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;USE_DL_EXPORT"
    2929                                StringPooling="TRUE"
    3030                                RuntimeLibrary="2"
     
    4040                                Name="VCLinkerTool"
    4141                                AdditionalDependencies="getbuildinfo.o"
    42                                 OutputFile="./python26.dll"
     42                                OutputFile="./python27.dll"
    4343                                LinkIncremental="1"
    4444                                SuppressStartupBanner="TRUE"
    4545                                IgnoreDefaultLibraryNames="libc"
    4646                                GenerateDebugInformation="TRUE"
    47                                 ProgramDatabaseFile=".\./python26.pdb"
     47                                ProgramDatabaseFile=".\./python27.pdb"
    4848                                SubSystem="2"
    4949                                BaseAddress="0x1e000000"
    50                                 ImportLibrary=".\./python26.lib"
     50                                ImportLibrary=".\./python27.lib"
    5151                                TargetMachine="1"/>
    5252                        <Tool
     
    8888                                Optimization="0"
    8989                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    90                                 PreprocessorDefinitions="_DEBUG;USE_DL_EXPORT;WIN32;_WINDOWS"
     90                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;_DEBUG;USE_DL_EXPORT;WIN32;_WINDOWS"
    9191                                RuntimeLibrary="3"
    9292                                UsePrecompiledHeader="2"
     
    100100                                Name="VCLinkerTool"
    101101                                AdditionalDependencies="getbuildinfo.o"
    102                                 OutputFile="./python26_d.dll"
     102                                OutputFile="./python27_d.dll"
    103103                                LinkIncremental="1"
    104104                                SuppressStartupBanner="TRUE"
    105105                                IgnoreDefaultLibraryNames="libc"
    106106                                GenerateDebugInformation="TRUE"
    107                                 ProgramDatabaseFile=".\./python26_d.pdb"
     107                                ProgramDatabaseFile=".\./python27_d.pdb"
    108108                                SubSystem="2"
    109109                                BaseAddress="0x1e000000"
    110                                 ImportLibrary=".\./python26_d.lib"
     110                                ImportLibrary=".\./python27_d.lib"
    111111                                TargetMachine="1"/>
    112112                        <Tool
     
    149149                                InlineFunctionExpansion="1"
    150150                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    151                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;USE_DL_EXPORT"
     151                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;USE_DL_EXPORT"
    152152                                StringPooling="TRUE"
    153153                                BasicRuntimeChecks="0"
     
    167167                                AdditionalOptions=" /MACHINE:IA64 /USELINK:MS_SDK"
    168168                                AdditionalDependencies="getbuildinfo.o"
    169                                 OutputFile="./python26.dll"
     169                                OutputFile="./python27.dll"
    170170                                LinkIncremental="1"
    171171                                SuppressStartupBanner="FALSE"
    172172                                IgnoreDefaultLibraryNames="libc"
    173173                                GenerateDebugInformation="TRUE"
    174                                 ProgramDatabaseFile=".\./python26.pdb"
     174                                ProgramDatabaseFile=".\./python27.pdb"
    175175                                SubSystem="2"
    176176                                BaseAddress="0x1e000000"
    177                                 ImportLibrary=".\./python26.lib"
     177                                ImportLibrary=".\./python27.lib"
    178178                                TargetMachine="0"/>
    179179                        <Tool
     
    216216                                InlineFunctionExpansion="1"
    217217                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    218                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;USE_DL_EXPORT"
     218                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS;USE_DL_EXPORT"
    219219                                StringPooling="TRUE"
    220220                                BasicRuntimeChecks="0"
     
    234234                                AdditionalOptions=" /MACHINE:AMD64 /USELINK:MS_SDK"
    235235                                AdditionalDependencies="getbuildinfo.o"
    236                                 OutputFile="./python26.dll"
     236                                OutputFile="./python27.dll"
    237237                                LinkIncremental="1"
    238238                                SuppressStartupBanner="TRUE"
    239239                                IgnoreDefaultLibraryNames="libc"
    240240                                GenerateDebugInformation="TRUE"
    241                                 ProgramDatabaseFile=".\./python26.pdb"
     241                                ProgramDatabaseFile=".\./python27.pdb"
    242242                                SubSystem="2"
    243243                                BaseAddress="0x1e000000"
    244                                 ImportLibrary=".\./python26.lib"
     244                                ImportLibrary=".\./python27.lib"
    245245                                TargetMachine="0"/>
    246246                        <Tool
     
    363363                </File>
    364364                <File
    365                         RelativePath="..\..\Modules\_bytesio.c">
    366                 </File>
    367                 <File
    368365                        RelativePath="..\..\Modules\_codecsmodule.c">
    369366                </File>
     
    372369                </File>
    373370                <File
    374                         RelativePath="..\..\Modules\_fileio.c">
    375                 </File>
    376                 <File
    377371                        RelativePath="..\..\Modules\_functoolsmodule.c">
    378372                </File>
     
    384378                </File>
    385379                <File
     380                        RelativePath="..\..\Modules\_io\_iomodule.c">
     381                </File>
     382                <File
    386383                        RelativePath="..\..\Modules\_json.c">
    387384                </File>
     
    393390                </File>
    394391                <File
     392                        RelativePath="..\..\Modules\_math.c">
     393                </File>
     394                <File
    395395                        RelativePath="..\..\Modules\_randommodule.c">
    396396                </File>
     
    444444                </File>
    445445                <File
     446                        RelativePath="..\..\Modules\_io\bufferedio.c">
     447                </File>
     448                <File
    446449                        RelativePath="..\..\Objects\bufferobject.c">
    447450                </File>
     
    450453                </File>
    451454                <File
     455                        RelativePath="..\..\Modules\_io\bytesio.c">
     456                </File>
     457                <File
    452458                        RelativePath="..\..\Objects\stringobject.c">
    453459                </File>
    454460                <File
    455461                        RelativePath="..\..\Objects\bytes_methods.c">
     462                </File>
     463                <File
     464                        RelativePath="..\..\Objects\capsule.c">
    456465                </File>
    457466                <File
     
    510519                </File>
    511520                <File
     521                        RelativePath="..\..\Python\dtoa.c">
     522                </File>
     523                <File
    512524                        RelativePath="..\..\Python\dynload_win.c">
    513525                </File>
     
    525537                </File>
    526538                <File
     539                        RelativePath="..\..\Modules\_io\fileio.c">
     540                </File>
     541                <File
    527542                        RelativePath="..\..\Objects\fileobject.c">
    528543                </File>
     
    568583                <File
    569584                        RelativePath="..\..\Python\getcopyright.c">
    570                 </File>
    571                 <File
    572                         RelativePath="..\..\Python\getmtime.c">
    573585                </File>
    574586                <File
     
    633645                </File>
    634646                <File
     647                        RelativePath="..\..\Modules\_io\iobase.c">
     648                </File>
     649                <File
    635650                        RelativePath="..\..\Objects\iterobject.c">
    636651                </File>
     
    663678                </File>
    664679                <File
     680                        RelativePath="..\..\Objects\memoryobject.c">
     681                </File>
     682                <File
    665683                        RelativePath="..\..\Parser\metagrammar.c">
    666684                </File>
     
    723741                </File>
    724742                <File
     743                        RelativePath="..\..\Python\pyctype.c">
     744                </File>
     745                <File
    725746                        RelativePath="..\..\Python\pyfpe.c">
    726747                </File>
     
    747768                </File>
    748769                <File
     770                        RelativePath="..\..\Python\random.c">
     771                </File>
     772                <File
    749773                        RelativePath="..\..\Objects\rangeobject.c">
    750774                </File>
     
    771795                </File>
    772796                <File
     797                        RelativePath="..\..\Modules\_io\stringio.c">
     798                </File>
     799                <File
    773800                        RelativePath="..\..\Modules\stropmodule.c">
    774801                </File>
     
    789816                </File>
    790817                <File
     818                        RelativePath="..\..\Modules\_io\textio.c">
     819                </File>
     820                <File
    791821                        RelativePath="..\..\Python\thread.c">
    792822                </File>
     
    820850                <File
    821851                        RelativePath="..\..\Modules\xxsubtype.c">
    822                 </File>
    823                 <File
    824                         RelativePath="..\..\Modules\yuvconvert.c">
    825852                </File>
    826853                <File
  • python/vendor/current/PC/VS7.1/readme.txt

    r2 r388  
    1313
    14141) pythoncore (this builds the main Python DLL and library files,
    15                python26.{dll, lib} in Release mode)
     15               python27.{dll, lib} in Release mode)
    1616              NOTE:  in previous releases, this subproject was
    1717              named after the release number, e.g. python20.
     
    2727
    2828When using the Debug setting, the output files have a _d added to
    29 their name:  python26_d.dll, python_d.exe, parser_d.pyd, and so on.
     29their name:  python27_d.dll, python_d.exe, parser_d.pyd, and so on.
    3030
    3131SUBPROJECTS
  • python/vendor/current/PC/VS7.1/select.vcproj

    r2 r388  
    2323                                InlineFunctionExpansion="1"
    2424                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    25                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     25                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    2626                                StringPooling="TRUE"
    2727                                RuntimeLibrary="2"
     
    3636                        <Tool
    3737                                Name="VCLinkerTool"
    38                                 AdditionalDependencies="wsock32.lib"
     38                                AdditionalDependencies="ws2_32.lib"
    3939                                OutputFile="./select.pyd"
    4040                                LinkIncremental="1"
     
    7979                                Optimization="0"
    8080                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    81                                 PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS"
     81                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;_DEBUG;WIN32;_WINDOWS"
    8282                                RuntimeLibrary="3"
    8383                                UsePrecompiledHeader="2"
     
    9090                        <Tool
    9191                                Name="VCLinkerTool"
    92                                 AdditionalDependencies="wsock32.lib"
     92                                AdditionalDependencies="ws2_32.lib"
    9393                                OutputFile="./select_d.pyd"
    9494                                LinkIncremental="1"
     
    135135                                InlineFunctionExpansion="1"
    136136                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    137                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     137                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    138138                                StringPooling="TRUE"
    139139                                BasicRuntimeChecks="0"
     
    152152                                Name="VCLinkerTool"
    153153                                AdditionalOptions=" /MACHINE:IA64 /USELINK:MS_SDK"
    154                                 AdditionalDependencies="wsock32.lib"
     154                                AdditionalDependencies="ws2_32.lib"
    155155                                OutputFile="./select.pyd"
    156156                                LinkIncremental="1"
     
    197197                                InlineFunctionExpansion="1"
    198198                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    199                                 PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS"
     199                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;NDEBUG;WIN32;_WINDOWS"
    200200                                StringPooling="TRUE"
    201201                                BasicRuntimeChecks="0"
     
    214214                                Name="VCLinkerTool"
    215215                                AdditionalOptions=" /MACHINE:AMD64 /USELINK:MS_SDK"
    216                                 AdditionalDependencies="wsock32.lib"
     216                                AdditionalDependencies="ws2_32.lib"
    217217                                OutputFile="./select.pyd"
    218218                                LinkIncremental="1"
  • python/vendor/current/PC/VS7.1/unicodedata.vcproj

    r2 r388  
    2424                                InlineFunctionExpansion="1"
    2525                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    26                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
     26                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
    2727                                StringPooling="TRUE"
    2828                                RuntimeLibrary="2"
     
    7676                                Optimization="0"
    7777                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    78                                 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
     78                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;_DEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
    7979                                BasicRuntimeChecks="3"
    8080                                RuntimeLibrary="3"
     
    131131                                InlineFunctionExpansion="1"
    132132                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    133                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
     133                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
    134134                                StringPooling="TRUE"
    135135                                BasicRuntimeChecks="0"
     
    190190                                InlineFunctionExpansion="1"
    191191                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    192                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
     192                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS"
    193193                                StringPooling="TRUE"
    194194                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS7.1/w9xpopen.vcproj

    r2 r388  
    2222                                Name="VCCLCompilerTool"
    2323                                Optimization="0"
    24                                 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
     24                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;_DEBUG;_WINDOWS"
    2525                                BasicRuntimeChecks="3"
    2626                                RuntimeLibrary="3"
     
    7272                                Optimization="2"
    7373                                InlineFunctionExpansion="1"
    74                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
     74                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS"
    7575                                StringPooling="TRUE"
    7676                                RuntimeLibrary="2"
  • python/vendor/current/PC/VS7.1/winsound.vcproj

    r2 r388  
    2323                                Optimization="0"
    2424                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    25                                 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;WINSOUND_EXPORTS"
     25                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;_DEBUG;_WINDOWS;_USRDLL;WINSOUND_EXPORTS"
    2626                                BasicRuntimeChecks="3"
    2727                                RuntimeLibrary="3"
     
    7878                                InlineFunctionExpansion="1"
    7979                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    80                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;WINSOUND_EXPORTS"
     80                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL;WINSOUND_EXPORTS"
    8181                                StringPooling="TRUE"
    8282                                RuntimeLibrary="2"
     
    133133                                InlineFunctionExpansion="1"
    134134                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    135                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;WINSOUND_EXPORTS"
     135                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL;WINSOUND_EXPORTS"
    136136                                StringPooling="TRUE"
    137137                                BasicRuntimeChecks="0"
     
    193193                                InlineFunctionExpansion="1"
    194194                                AdditionalIncludeDirectories="..\..\Include,..\..\PC"
    195                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;WINSOUND_EXPORTS"
     195                                PreprocessorDefinitions="Py_BUILD_CORE_MODULE;WIN32;NDEBUG;_WINDOWS;_USRDLL;WINSOUND_EXPORTS"
    196196                                StringPooling="TRUE"
    197197                                BasicRuntimeChecks="0"
  • python/vendor/current/PC/VS8.0/_multiprocessing.vcproj

    r2 r388  
    44        Version="8.00"
    55        Name="_multiprocessing"
    6         ProjectGUID="{9e48b300-37d1-11dd-8c41-005056c00008}"
     6        ProjectGUID="{9E48B300-37D1-11DD-8C41-005056C00008}"
    77        RootNamespace="_multiprocessing"
    88        Keyword="Win32Proj"
  • python/vendor/current/PC/VS8.0/_sqlite3.vcproj

    r2 r388  
    4343                        <Tool
    4444                                Name="VCCLCompilerTool"
    45                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
     45                                AdditionalIncludeDirectories="..\..\..\sqlite-3.6.21"
    4646                                PreprocessorDefinitions="MODULE_NAME=\&quot;sqlite3\&quot;"
    4747                        />
     
    105105                        <Tool
    106106                                Name="VCCLCompilerTool"
    107                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
     107                                AdditionalIncludeDirectories="..\..\..\sqlite-3.6.21"
    108108                                PreprocessorDefinitions="MODULE_NAME=\&quot;sqlite3\&quot;"
    109109                        />
     
    167167                        <Tool
    168168                                Name="VCCLCompilerTool"
    169                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
     169                                AdditionalIncludeDirectories="..\..\..\sqlite-3.6.21"
    170170                                PreprocessorDefinitions="MODULE_NAME=\&quot;sqlite3\&quot;"
    171171                        />
     
    230230                        <Tool
    231231                                Name="VCCLCompilerTool"
    232                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
     232                                AdditionalIncludeDirectories="..\..\..\sqlite-3.6.21"
    233233                                PreprocessorDefinitions="MODULE_NAME=\&quot;sqlite3\&quot;"
    234234                        />
     
    292292                        <Tool
    293293                                Name="VCCLCompilerTool"
    294                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
     294                                AdditionalIncludeDirectories="..\..\..\sqlite-3.6.21"
    295295                                PreprocessorDefinitions="MODULE_NAME=\&quot;sqlite3\&quot;"
    296296                        />
     
    355355                        <Tool
    356356                                Name="VCCLCompilerTool"
    357                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
     357                                AdditionalIncludeDirectories="..\..\..\sqlite-3.6.21"
    358358                                PreprocessorDefinitions="MODULE_NAME=\&quot;sqlite3\&quot;"
    359359                        />
     
    418418                        <Tool
    419419                                Name="VCCLCompilerTool"
    420                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
     420                                AdditionalIncludeDirectories="..\..\..\sqlite-3.6.21"
    421421                                PreprocessorDefinitions="MODULE_NAME=\&quot;sqlite3\&quot;"
    422422                        />
     
    481481                        <Tool
    482482                                Name="VCCLCompilerTool"
    483                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
     483                                AdditionalIncludeDirectories="..\..\..\sqlite-3.6.21"
    484484                                PreprocessorDefinitions="MODULE_NAME=\&quot;sqlite3\&quot;"
    485485                        />
  • python/vendor/current/PC/VS8.0/bdist_wininst.vcproj

    r2 r388  
    5656                                PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE"
    5757                                StringPooling="true"
    58                                 RuntimeLibrary="2"
     58                                RuntimeLibrary="0"
    5959                                EnableFunctionLevelLinking="true"
    6060                                WarningLevel="3"
     
    146146                                PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE"
    147147                                StringPooling="true"
    148                                 RuntimeLibrary="2"
     148                                RuntimeLibrary="0"
    149149                                EnableFunctionLevelLinking="true"
    150150                                WarningLevel="3"
  • python/vendor/current/PC/VS8.0/build_ssl.bat

    r2 r388  
    33  if %1 EQU Debug (
    44    set HOST_PYTHON=python_d.exe
    5     if not exist python26_d.dll exit 1
     5    if not exist python27_d.dll exit 1
    66  ) ELSE (
    77    set HOST_PYTHON=python.exe
    8     if not exist python26.dll exit 1
     8    if not exist python27.dll exit 1
    99  )
    1010)
  • python/vendor/current/PC/VS8.0/build_ssl.py

    r2 r388  
    99#   any other external packages there.
    1010# * Install ActivePerl and ensure it is somewhere on your path.
    11 # * Run this script from the PCBuild directory.
     11# * Run this script from the PC/VS8.0 directory.
    1212#
    1313# it should configure and build SSL, then build the _ssl and _hashlib
     
    4747def find_working_perl(perls):
    4848    for perl in perls:
    49         fh = os.popen(perl + ' -e "use Win32;"')
     49        fh = os.popen('"%s" -e "use Win32;"' % perl)
    5050        fh.read()
    5151        rc = fh.close()
     
    179179    perls = find_all_on_path("perl.exe", ["\\perl\\bin", "C:\\perl\\bin"])
    180180    perl = find_working_perl(perls)
    181     if perl is None:
     181    if perl:
     182        print("Found a working perl at '%s'" % (perl,))
     183    else:
    182184        print("No Perl installation was found. Existing Makefiles are used.")
    183 
    184     print("Found a working perl at '%s'" % (perl,))
    185185    sys.stdout.flush()
    186     # Look for SSL 2 levels up from pcbuild - ie, same place zlib etc all live.
     186    # Look for SSL 3 levels up from PC/VS8.0 - ie, same place zlib etc all live.
    187187    ssl_dir = find_best_ssl_dir(("..\\..\\..",))
    188188    if ssl_dir is None:
  • python/vendor/current/PC/VS8.0/bz2.vcproj

    r2 r388  
    4444                                Name="VCCLCompilerTool"
    4545                                AdditionalIncludeDirectories="$(bz2Dir)"
    46                         />
    47                         <Tool
    48                                 Name="VCManagedResourceCompilerTool"
    49                         />
    50                         <Tool
    51                                 Name="VCResourceCompilerTool"
    52                         />
    53                         <Tool
    54                                 Name="VCPreLinkEventTool"
    55                                 Description="Build libbz2"
    56                                 CommandLine="cd $(bz2Dir)&#x0D;&#x0A;if exist $(PlatformName)-Debug\libbz2.lib exit 0&#x0D;&#x0A;if not exist $(PlatformName)-Debug mkdir $(PlatformName)-Debug&#x0D;&#x0A;nmake /nologo /f makefile.msc lib&#x0D;&#x0A;copy libbz2.lib $(PlatformName)-Debug&#x0D;&#x0A;nmake /nologo /f makefile.msc clean&#x0D;&#x0A;"
    57                         />
    58                         <Tool
    59                                 Name="VCLinkerTool"
    60                                 AdditionalDependencies="$(bz2Dir)\$(PlatformName)-Debug\libbz2.lib"
     46                                PreprocessorDefinitions="WIN32;_FILE_OFFSET_BITS=64"
     47                        />
     48                        <Tool
     49                                Name="VCManagedResourceCompilerTool"
     50                        />
     51                        <Tool
     52                                Name="VCResourceCompilerTool"
     53                        />
     54                        <Tool
     55                                Name="VCPreLinkEventTool"
     56                        />
     57                        <Tool
     58                                Name="VCLinkerTool"
     59                                BaseAddress="0x1D170000"
    6160                        />
    6261                        <Tool
     
    107106                                Name="VCCLCompilerTool"
    108107                                AdditionalIncludeDirectories="$(bz2Dir)"
    109                         />
    110                         <Tool
    111                                 Name="VCManagedResourceCompilerTool"
    112                         />
    113                         <Tool
    114                                 Name="VCResourceCompilerTool"
    115                         />
    116                         <Tool
    117                                 Name="VCPreLinkEventTool"
    118                                 Description="Build libbz2"
    119                                 CommandLine="cd $(bz2Dir)&#x0D;&#x0A;if exist $(PlatformName)-Debug\libbz2.lib exit 0&#x0D;&#x0A;if not exist $(PlatformName)-Debug mkdir $(PlatformName)-Debug&#x0D;&#x0A;nmake /nologo /f makefile.msc lib&#x0D;&#x0A;copy libbz2.lib $(PlatformName)-Debug&#x0D;&#x0A;nmake /nologo /f makefile.msc clean&#x0D;&#x0A;"
    120                         />
    121                         <Tool
    122                                 Name="VCLinkerTool"
    123                                 AdditionalDependencies="$(bz2Dir)\$(PlatformName)-Debug\libbz2.lib"
     108                                PreprocessorDefinitions="WIN32;_FILE_OFFSET_BITS=64"
     109                        />
     110                        <Tool
     111                                Name="VCManagedResourceCompilerTool"
     112                        />
     113                        <Tool
     114                                Name="VCResourceCompilerTool"
     115                        />
     116                        <Tool
     117                                Name="VCPreLinkEventTool"
     118                        />
     119                        <Tool
     120                                Name="VCLinkerTool"
     121                                BaseAddress="0x1D170000"
    124122                        />
    125123                        <Tool
     
    170168                                Name="VCCLCompilerTool"
    171169                                AdditionalIncludeDirectories="$(bz2Dir)"
    172                         />
    173                         <Tool
    174                                 Name="VCManagedResourceCompilerTool"
    175                         />
    176                         <Tool
    177                                 Name="VCResourceCompilerTool"
    178                         />
    179                         <Tool
    180                                 Name="VCPreLinkEventTool"
    181                                 Description="Build libbz2"
    182                                 CommandLine="cd $(bz2Dir)&#x0D;&#x0A;if exist $(PlatformName)-Release\libbz2.lib exit 0&#x0D;&#x0A;if not exist $(PlatformName)-Release mkdir $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc lib&#x0D;&#x0A;copy libbz2.lib $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc clean&#x0D;&#x0A;"
    183                         />
    184                         <Tool
    185                                 Name="VCLinkerTool"
    186                                 AdditionalDependencies="$(bz2Dir)\$(PlatformName)-Release\libbz2.lib"
     170                                PreprocessorDefinitions="WIN32;_FILE_OFFSET_BITS=64"
     171                        />
     172                        <Tool
     173                                Name="VCManagedResourceCompilerTool"
     174                        />
     175                        <Tool
     176                                Name="VCResourceCompilerTool"
     177                        />
     178                        <Tool
     179                                Name="VCPreLinkEventTool"
     180                        />
     181                        <Tool
     182                                Name="VCLinkerTool"
     183                                BaseAddress="0x1D170000"
    187184                        />
    188185                        <Tool
     
    234231                                Name="VCCLCompilerTool"
    235232                                AdditionalIncludeDirectories="$(bz2Dir)"
    236                         />
    237                         <Tool
    238                                 Name="VCManagedResourceCompilerTool"
    239                         />
    240                         <Tool
    241                                 Name="VCResourceCompilerTool"
    242                         />
    243                         <Tool
    244                                 Name="VCPreLinkEventTool"
    245                                 Description="Build libbz2"
    246                                 CommandLine="cd $(bz2Dir)&#x0D;&#x0A;if exist $(PlatformName)-Release\libbz2.lib exit 0&#x0D;&#x0A;if not exist $(PlatformName)-Release mkdir $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc lib&#x0D;&#x0A;copy libbz2.lib $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc clean&#x0D;&#x0A;"
    247                         />
    248                         <Tool
    249                                 Name="VCLinkerTool"
    250                                 AdditionalDependencies="$(bz2Dir)\$(PlatformName)-Release\libbz2.lib"
     233                                PreprocessorDefinitions="WIN32;_FILE_OFFSET_BITS=64"
     234                        />
     235                        <Tool
     236                                Name="VCManagedResourceCompilerTool"
     237                        />
     238                        <Tool
     239                                Name="VCResourceCompilerTool"
     240                        />
     241                        <Tool
     242                                Name="VCPreLinkEventTool"
     243                        />
     244                        <Tool
     245                                Name="VCLinkerTool"
     246                                BaseAddress="0x1D170000"
    251247                        />
    252248                        <Tool
     
    297293                                Name="VCCLCompilerTool"
    298294                                AdditionalIncludeDirectories="$(bz2Dir)"
    299                         />
    300                         <Tool
    301                                 Name="VCManagedResourceCompilerTool"
    302                         />
    303                         <Tool
    304                                 Name="VCResourceCompilerTool"
    305                         />
    306                         <Tool
    307                                 Name="VCPreLinkEventTool"
    308                                 Description="Build libbz2"
    309                                 CommandLine="cd $(bz2Dir)&#x0D;&#x0A;if exist $(PlatformName)-Release\libbz2.lib exit 0&#x0D;&#x0A;if not exist $(PlatformName)-Release mkdir $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc lib&#x0D;&#x0A;copy libbz2.lib $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc clean&#x0D;&#x0A;"
    310                         />
    311                         <Tool
    312                                 Name="VCLinkerTool"
    313                                 AdditionalDependencies="$(bz2Dir)\$(PlatformName)-Release\libbz2.lib"
     295                                PreprocessorDefinitions="WIN32;_FILE_OFFSET_BITS=64"
     296                        />
     297                        <Tool
     298                                Name="VCManagedResourceCompilerTool"
     299                        />
     300                        <Tool
     301                                Name="VCResourceCompilerTool"
     302                        />
     303                        <Tool
     304                                Name="VCPreLinkEventTool"
     305                        />
     306                        <Tool
     307                                Name="VCLinkerTool"
     308                                BaseAddress="0x1D170000"
    314309                        />
    315310                        <Tool
     
    361356                                Name="VCCLCompilerTool"
    362357                                AdditionalIncludeDirectories="$(bz2Dir)"
    363                         />
    364                         <Tool
    365                                 Name="VCManagedResourceCompilerTool"
    366                         />
    367                         <Tool
    368                                 Name="VCResourceCompilerTool"
    369                         />
    370                         <Tool
    371                                 Name="VCPreLinkEventTool"
    372                                 Description="Build libbz2"
    373                                 CommandLine="cd $(bz2Dir)&#x0D;&#x0A;if exist $(PlatformName)-Release\libbz2.lib exit 0&#x0D;&#x0A;if not exist $(PlatformName)-Release mkdir $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc lib&#x0D;&#x0A;copy libbz2.lib $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc clean&#x0D;&#x0A;"
    374                         />
    375                         <Tool
    376                                 Name="VCLinkerTool"
    377                                 AdditionalDependencies="$(bz2Dir)\$(PlatformName)-Release\libbz2.lib"
     358                                PreprocessorDefinitions="WIN32;_FILE_OFFSET_BITS=64"
     359                        />
     360                        <Tool
     361                                Name="VCManagedResourceCompilerTool"
     362                        />
     363                        <Tool
     364                                Name="VCResourceCompilerTool"
     365                        />
     366                        <Tool
     367                                Name="VCPreLinkEventTool"
     368                        />
     369                        <Tool
     370                                Name="VCLinkerTool"
     371                                BaseAddress="0x1D170000"
    378372                                TargetMachine="17"
    379373                        />
     
    425419                                Name="VCCLCompilerTool"
    426420                                AdditionalIncludeDirectories="$(bz2Dir)"
    427                         />
    428                         <Tool
    429                                 Name="VCManagedResourceCompilerTool"
    430                         />
    431                         <Tool
    432                                 Name="VCResourceCompilerTool"
    433                         />
    434                         <Tool
    435                                 Name="VCPreLinkEventTool"
    436                                 Description="Build libbz2"
    437                                 CommandLine="cd $(bz2Dir)&#x0D;&#x0A;if exist $(PlatformName)-Release\libbz2.lib exit 0&#x0D;&#x0A;if not exist $(PlatformName)-Release mkdir $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc lib&#x0D;&#x0A;copy libbz2.lib $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc clean&#x0D;&#x0A;"
    438                         />
    439                         <Tool
    440                                 Name="VCLinkerTool"
    441                                 AdditionalDependencies="$(bz2Dir)\$(PlatformName)-Release\libbz2.lib"
     421                                PreprocessorDefinitions="WIN32;_FILE_OFFSET_BITS=64"
     422                        />
     423                        <Tool
     424                                Name="VCManagedResourceCompilerTool"
     425                        />
     426                        <Tool
     427                                Name="VCResourceCompilerTool"
     428                        />
     429                        <Tool
     430                                Name="VCPreLinkEventTool"
     431                        />
     432                        <Tool
     433                                Name="VCLinkerTool"
     434                                BaseAddress="0x1D170000"
    442435                        />
    443436                        <Tool
     
    489482                                Name="VCCLCompilerTool"
    490483                                AdditionalIncludeDirectories="$(bz2Dir)"
    491                         />
    492                         <Tool
    493                                 Name="VCManagedResourceCompilerTool"
    494                         />
    495                         <Tool
    496                                 Name="VCResourceCompilerTool"
    497                         />
    498                         <Tool
    499                                 Name="VCPreLinkEventTool"
    500                                 Description="Build libbz2"
    501                                 CommandLine="cd $(bz2Dir)&#x0D;&#x0A;if exist $(PlatformName)-Release\libbz2.lib exit 0&#x0D;&#x0A;if not exist $(PlatformName)-Release mkdir $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc lib&#x0D;&#x0A;copy libbz2.lib $(PlatformName)-Release&#x0D;&#x0A;nmake /nologo /f makefile.msc clean&#x0D;&#x0A;"
    502                         />
    503                         <Tool
    504                                 Name="VCLinkerTool"
    505                                 AdditionalDependencies="$(bz2Dir)\$(PlatformName)-Release\libbz2.lib"
     484                                PreprocessorDefinitions="WIN32;_FILE_OFFSET_BITS=64"
     485                        />
     486                        <Tool
     487                                Name="VCManagedResourceCompilerTool"
     488                        />
     489                        <Tool
     490                                Name="VCResourceCompilerTool"
     491                        />
     492                        <Tool
     493                                Name="VCPreLinkEventTool"
     494                        />
     495                        <Tool
     496                                Name="VCLinkerTool"
     497                                BaseAddress="0x1D170000"
    506498                                TargetMachine="17"
    507499                        />
     
    540532                        </File>
    541533                </Filter>
     534                <Filter
     535                        Name="bzip2 1.0.6 Header Files"
     536                        >
     537                        <File
     538                                RelativePath="$(bz2Dir)\bzlib.h"
     539                                >
     540                        </File>
     541                        <File
     542                                RelativePath="$(bz2Dir)\bzlib_private.h"
     543                                >
     544                        </File>
     545                </Filter>
     546                <Filter
     547                        Name="bzip2 1.0.6 Source Files"
     548                        >
     549                        <File
     550                                RelativePath="$(bz2Dir)\blocksort.c"
     551                                >
     552                        </File>
     553                        <File
     554                                RelativePath="$(bz2Dir)\bzlib.c"
     555                                >
     556                        </File>
     557                        <File
     558                                RelativePath="$(bz2Dir)\compress.c"
     559                                >
     560                        </File>
     561                        <File
     562                                RelativePath="$(bz2Dir)\crctable.c"
     563                                >
     564                        </File>
     565                        <File
     566                                RelativePath="$(bz2Dir)\decompress.c"
     567                                >
     568                        </File>
     569                        <File
     570                                RelativePath="$(bz2Dir)\huffman.c"
     571                                >
     572                        </File>
     573                        <File
     574                                RelativePath="$(bz2Dir)\randtable.c"
     575                                >
     576                        </File>
     577                </Filter>
    542578        </Files>
    543579        <Globals>
  • python/vendor/current/PC/VS8.0/make_buildinfo.c

    r2 r388  
    2424int make_buildinfo2()
    2525{
    26         struct _stat st;
    27         HKEY hTortoise;
    28         char command[CMD_SIZE+1];
    29         DWORD type, size;
    30         if (_stat(".svn", &st) < 0)
    31                 return 0;
    32         /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */
    33         if (_stat("no_subwcrev", &st) == 0)
    34                 return 0;
    35         if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS &&
    36             RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS)
    37                 /* Tortoise not installed */
    38                 return 0;
    39         command[0] = '"';  /* quote the path to the executable */
    40         size = sizeof(command) - 1;
    41         if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS ||
    42             type != REG_SZ)
    43                 /* Registry corrupted */
    44                 return 0;
    45         strcat_s(command, CMD_SIZE, "bin\\subwcrev.exe");
    46         if (_stat(command+1, &st) < 0)
    47                 /* subwcrev.exe not part of the release */
    48                 return 0;
    49         strcat_s(command, CMD_SIZE, "\" ..\\.. ..\\..\\Modules\\getbuildinfo.c getbuildinfo2.c");
    50         puts(command); fflush(stdout);
    51         if (system(command) < 0)
    52                 return 0;
    53         return 1;
     26    struct _stat st;
     27    HKEY hTortoise;
     28    char command[CMD_SIZE+1];
     29    DWORD type, size;
     30    if (_stat(".svn", &st) < 0)
     31        return 0;
     32    /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */
     33    if (_stat("no_subwcrev", &st) == 0)
     34        return 0;
     35    if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS &&
     36        RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS)
     37        /* Tortoise not installed */
     38        return 0;
     39    command[0] = '"';  /* quote the path to the executable */
     40    size = sizeof(command) - 1;
     41    if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS ||
     42        type != REG_SZ)
     43        /* Registry corrupted */
     44        return 0;
     45    strcat_s(command, CMD_SIZE, "bin\\subwcrev.exe");
     46    if (_stat(command+1, &st) < 0)
     47        /* subwcrev.exe not part of the release */
     48        return 0;
     49    strcat_s(command, CMD_SIZE, "\" ..\\.. ..\\..\\Modules\\getbuildinfo.c getbuildinfo2.c");
     50    puts(command); fflush(stdout);
     51    if (system(command) < 0)
     52        return 0;
     53    return 1;
    5454}
    5555
    5656int main(int argc, char*argv[])
    5757{
    58         char command[500] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
    59         int do_unlink, result;
    60         if (argc != 2) {
    61                 fprintf(stderr, "make_buildinfo $(ConfigurationName)\n");
    62                 return EXIT_FAILURE;
    63         }
    64         if (strcmp(argv[1], "Release") == 0) {
    65                 strcat_s(command, CMD_SIZE, "-MD ");
    66         }
    67         else if (strcmp(argv[1], "Debug") == 0) {
    68                 strcat_s(command, CMD_SIZE, "-D_DEBUG -MDd ");
    69         }
    70         else if (strcmp(argv[1], "ReleaseItanium") == 0) {
    71                 strcat_s(command, CMD_SIZE, "-MD /USECL:MS_ITANIUM ");
    72         }
    73         else if (strcmp(argv[1], "ReleaseAMD64") == 0) {
    74                 strcat_s(command, CMD_SIZE, "-MD ");
    75                 strcat_s(command, CMD_SIZE, "-MD /USECL:MS_OPTERON ");
    76         }
    77         else {
    78                 fprintf(stderr, "unsupported configuration %s\n", argv[1]);
    79                 return EXIT_FAILURE;
    80         }
     58    char command[500] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
     59    int do_unlink, result;
     60    if (argc != 2) {
     61        fprintf(stderr, "make_buildinfo $(ConfigurationName)\n");
     62        return EXIT_FAILURE;
     63    }
     64    if (strcmp(argv[1], "Release") == 0) {
     65        strcat_s(command, CMD_SIZE, "-MD ");
     66    }
     67    else if (strcmp(argv[1], "Debug") == 0) {
     68        strcat_s(command, CMD_SIZE, "-D_DEBUG -MDd ");
     69    }
     70    else if (strcmp(argv[1], "ReleaseItanium") == 0) {
     71        strcat_s(command, CMD_SIZE, "-MD /USECL:MS_ITANIUM ");
     72    }
     73    else if (strcmp(argv[1], "ReleaseAMD64") == 0) {
     74        strcat_s(command, CMD_SIZE, "-MD ");
     75        strcat_s(command, CMD_SIZE, "-MD /USECL:MS_OPTERON ");
     76    }
     77    else {
     78        fprintf(stderr, "unsupported configuration %s\n", argv[1]);
     79        return EXIT_FAILURE;
     80    }
    8181
    82         if ((do_unlink = make_buildinfo2()))
    83                 strcat_s(command, CMD_SIZE, "getbuildinfo2.c -DSUBWCREV ");
    84         else
    85                 strcat_s(command, CMD_SIZE, "..\\..\\Modules\\getbuildinfo.c");
    86         strcat_s(command, CMD_SIZE, " -Fogetbuildinfo.o -I..\\..\\Include -I..\\..\\PC");
    87         puts(command); fflush(stdout);
    88         result = system(command);
    89         if (do_unlink)
    90                 _unlink("getbuildinfo2.c");
    91         if (result < 0)
    92                 return EXIT_FAILURE;
    93         return 0;
     82    if ((do_unlink = make_buildinfo2()))
     83        strcat_s(command, CMD_SIZE, "getbuildinfo2.c -DSUBWCREV ");
     84    else
     85        strcat_s(command, CMD_SIZE, "..\\..\\Modules\\getbuildinfo.c");
     86    strcat_s(command, CMD_SIZE, " -Fogetbuildinfo.o -I..\\..\\Include -I..\\..\\PC");
     87    puts(command); fflush(stdout);
     88    result = system(command);
     89    if (do_unlink)
     90        _unlink("getbuildinfo2.c");
     91    if (result < 0)
     92        return EXIT_FAILURE;
     93    return 0;
    9494}
  • python/vendor/current/PC/VS8.0/pyd.vsprops

    r2 r388  
    1616                ProgramDatabaseFile="$(OutDir)\$(ProjectName).pdb"
    1717                ImportLibrary="$(OutDir)\$(TargetName).lib"
     18                GenerateManifest="false"
     19        />
     20        <Tool
     21                Name="VCManifestTool"
     22                EmbedManifest="false"
    1823        />
    1924        <Tool
  • python/vendor/current/PC/VS8.0/pyd_d.vsprops

    r2 r388  
    2020                ProgramDatabaseFile="$(OutDir)\$(ProjectName)_d.pdb"
    2121                ImportLibrary="$(OutDir)\$(TargetName).lib"
     22                GenerateManifest="false"
     23        />
     24        <Tool
     25                Name="VCManifestTool"
     26                EmbedManifest="false"
    2227        />
    2328        <Tool
  • python/vendor/current/PC/VS8.0/pyproject.vsprops

    r2 r388  
    3939        <UserMacro
    4040                Name="PyDllName"
    41                 Value="python26"
     41                Value="python27"
    4242        />
    4343        <UserMacro
     
    4848                Name="externalsDir"
    4949                Value="..\..\.."
     50        />
     51        <UserMacro
     52                Name="bsddb47Dir"
     53                Value="$(externalsDir)\db-4.7.25.0\build_windows"
     54        />
     55        <UserMacro
     56                Name="bsddb47DepLibs"
     57                Value="ws2_32.lib"
    5058        />
    5159        <UserMacro
     
    6674        />
    6775        <UserMacro
    68                 Name="bsddb47Dir"
    69                 Value="$(externalsDir)\db-4.7.25.0\build_windows"
    70         />
    71         <UserMacro
    72                 Name="bsddb47DepLibs"
    73                 Value="ws2_32.lib"
    74         />
    75         <UserMacro
    7676                Name="sqlite3Dir"
    77                 Value="$(externalsDir)\sqlite-3.5.9"
     77                Value="$(externalsDir)\sqlite-3.6.21"
    7878        />
    7979        <UserMacro
    8080                Name="bz2Dir"
    81                 Value="$(externalsDir)\bzip2-1.0.5"
     81                Value="$(externalsDir)\bzip2-1.0.6"
    8282        />
    8383        <UserMacro
    8484                Name="opensslDir"
    85                 Value="$(externalsDir)\openssl-0.9.8g"
     85                Value="$(externalsDir)\openssl-0.9.8y"
    8686        />
    8787        <UserMacro
  • python/vendor/current/PC/VS8.0/pythoncore.vcproj

    r2 r388  
    716716                        </File>
    717717                        <File
     718                                RelativePath="..\..\Include\dtoa.h"
     719                                >
     720                        </File>
     721                        <File
    718722                                RelativePath="..\..\Include\enumobject.h"
    719723                                >
     
    849853                        <File
    850854                                RelativePath="..\..\Include\pyarena.h"
     855                                >
     856                        </File>
     857                        <File
     858                                RelativePath="..\..\Include\pycapsule.h"
     859                                >
     860                        </File>
     861                        <File
     862                                RelativePath="..\..\Include\pyctype.h"
    851863                                >
    852864                        </File>
     
    9961008                        </File>
    9971009                        <File
    998                                 RelativePath="..\..\Modules\_fileio.c"
    999                                 >
    1000                         </File>
    1001                         <File
    1002                                 RelativePath="..\..\Modules\_bytesio.c"
    1003                                 >
    1004                         </File>
    1005                         <File
    10061010                                RelativePath="..\..\Modules\_functoolsmodule.c"
    10071011                                >
     
    10281032                        </File>
    10291033                        <File
     1034                                RelativePath="..\..\Modules\_math.c"
     1035                                >
     1036                        </File>
     1037                        <File
     1038                                RelativePath="..\..\Modules\_math.h"
     1039                                >
     1040                        </File>
     1041                        <File
    10301042                                RelativePath="..\..\Modules\_randommodule.c"
    10311043                                >
     
    11691181                        <File
    11701182                                RelativePath="..\..\Modules\xxsubtype.c"
    1171                                 >
    1172                         </File>
    1173                         <File
    1174                                 RelativePath="..\..\Modules\yuv.h"
    1175                                 >
    1176                         </File>
    1177                         <File
    1178                                 RelativePath="..\..\Modules\yuvconvert.c"
    11791183                                >
    11801184                        </File>
     
    13521356                                <File
    13531357                                        RelativePath="..\..\Modules\cjkcodecs\multibytecodec.h"
     1358                                        >
     1359                                </File>
     1360                        </Filter>
     1361                        <Filter
     1362                                Name="_io"
     1363                                >
     1364                                <File
     1365                                        RelativePath="..\..\Modules\_io\_iomodule.c"
     1366                                        >
     1367                                </File>
     1368                                <File
     1369                                        RelativePath="..\..\Modules\_io\_iomodule.h"
     1370                                        >
     1371                                </File>
     1372                                <File
     1373                                        RelativePath="..\..\Modules\_io\bufferedio.c"
     1374                                        >
     1375                                </File>
     1376                                <File
     1377                                        RelativePath="..\..\Modules\_io\bytesio.c"
     1378                                        >
     1379                                </File>
     1380                                <File
     1381                                        RelativePath="..\..\Modules\_io\fileio.c"
     1382                                        >
     1383                                </File>
     1384                                <File
     1385                                        RelativePath="..\..\Modules\_io\iobase.c"
     1386                                        >
     1387                                </File>
     1388                                <File
     1389                                        RelativePath="..\..\Modules\_io\stringio.c"
     1390                                        >
     1391                                </File>
     1392                                <File
     1393                                        RelativePath="..\..\Modules\_io\textio.c"
    13541394                                        >
    13551395                                </File>
     
    13801420                        </File>
    13811421                        <File
     1422                                RelativePath="..\..\Objects\capsule.c"
     1423                                >
     1424                        </File>
     1425                        <File
     1426                                RelativePath="..\..\Objects\cellobject.c"
     1427                                >
     1428                        </File>
     1429                        <File
     1430                                RelativePath="..\..\Objects\classobject.c"
     1431                                >
     1432                        </File>
     1433                        <File
     1434                                RelativePath="..\..\Objects\cobject.c"
     1435                                >
     1436                        </File>
     1437                        <File
     1438                                RelativePath="..\..\Objects\codeobject.c"
     1439                                >
     1440                        </File>
     1441                        <File
     1442                                RelativePath="..\..\Objects\complexobject.c"
     1443                                >
     1444                        </File>
     1445                        <File
     1446                                RelativePath="..\..\Objects\stringlib\count.h"
     1447                                >
     1448                        </File>
     1449                        <File
     1450                                RelativePath="..\..\Objects\descrobject.c"
     1451                                >
     1452                        </File>
     1453                        <File
     1454                                RelativePath="..\..\Objects\dictobject.c"
     1455                                >
     1456                        </File>
     1457                        <File
     1458                                RelativePath="..\..\Objects\enumobject.c"
     1459                                >
     1460                        </File>
     1461                        <File
     1462                                RelativePath="..\..\Objects\exceptions.c"
     1463                                >
     1464                        </File>
     1465                        <File
     1466                                RelativePath="..\..\Objects\stringlib\fastsearch.h"
     1467                                >
     1468                        </File>
     1469                        <File
     1470                                RelativePath="..\..\Objects\fileobject.c"
     1471                                >
     1472                        </File>
     1473                        <File
     1474                                RelativePath="..\..\Objects\stringlib\find.h"
     1475                                >
     1476                        </File>
     1477                        <File
     1478                                RelativePath="..\..\Objects\floatobject.c"
     1479                                >
     1480                        </File>
     1481                        <File
     1482                                RelativePath="..\..\Objects\frameobject.c"
     1483                                >
     1484                        </File>
     1485                        <File
     1486                                RelativePath="..\..\Objects\funcobject.c"
     1487                                >
     1488                        </File>
     1489                        <File
     1490                                RelativePath="..\..\Objects\genobject.c"
     1491                                >
     1492                        </File>
     1493                        <File
     1494                                RelativePath="..\..\Objects\intobject.c"
     1495                                >
     1496                        </File>
     1497                        <File
     1498                                RelativePath="..\..\Objects\iterobject.c"
     1499                                >
     1500                        </File>
     1501                        <File
     1502                                RelativePath="..\..\Objects\listobject.c"
     1503                                >
     1504                        </File>
     1505                        <File
     1506                                RelativePath="..\..\Objects\longobject.c"
     1507                                >
     1508                        </File>
     1509                        <File
     1510                                RelativePath="..\..\Objects\memoryobject.c"
     1511                                >
     1512                        </File>
     1513                        <File
     1514                                RelativePath="..\..\Objects\methodobject.c"
     1515                                >
     1516                        </File>
     1517                        <File
     1518                                RelativePath="..\..\Objects\moduleobject.c"
     1519                                >
     1520                        </File>
     1521                        <File
     1522                                RelativePath="..\..\Objects\object.c"
     1523                                >
     1524                        </File>
     1525                        <File
     1526                                RelativePath="..\..\Objects\obmalloc.c"
     1527                                >
     1528                        </File>
     1529                        <File
     1530                                RelativePath="..\..\Objects\stringlib\partition.h"
     1531                                >
     1532                        </File>
     1533                        <File
     1534                                RelativePath="..\..\Objects\rangeobject.c"
     1535                                >
     1536                        </File>
     1537                        <File
     1538                                RelativePath="..\..\Objects\setobject.c"
     1539                                >
     1540                        </File>
     1541                        <File
     1542                                RelativePath="..\..\Objects\sliceobject.c"
     1543                                >
     1544                        </File>
     1545                        <File
     1546                                RelativePath="..\..\Objects\stringlib\split.h"
     1547                                >
     1548                        </File>
     1549                        <File
    13821550                                RelativePath="..\..\Objects\stringobject.c"
    1383                                 >
    1384                         </File>
    1385                         <File
    1386                                 RelativePath="..\..\Objects\cellobject.c"
    1387                                 >
    1388                         </File>
    1389                         <File
    1390                                 RelativePath="..\..\Objects\classobject.c"
    1391                                 >
    1392                         </File>
    1393                         <File
    1394                                 RelativePath="..\..\Objects\cobject.c"
    1395                                 >
    1396                         </File>
    1397                         <File
    1398                                 RelativePath="..\..\Objects\codeobject.c"
    1399                                 >
    1400                         </File>
    1401                         <File
    1402                                 RelativePath="..\..\Objects\complexobject.c"
    1403                                 >
    1404                         </File>
    1405                         <File
    1406                                 RelativePath="..\..\Objects\stringlib\count.h"
    1407                                 >
    1408                         </File>
    1409                         <File
    1410                                 RelativePath="..\..\Objects\descrobject.c"
    1411                                 >
    1412                         </File>
    1413                         <File
    1414                                 RelativePath="..\..\Objects\dictobject.c"
    1415                                 >
    1416                         </File>
    1417                         <File
    1418                                 RelativePath="..\..\Objects\enumobject.c"
    1419                                 >
    1420                         </File>
    1421                         <File
    1422                                 RelativePath="..\..\Objects\exceptions.c"
    1423                                 >
    1424                         </File>
    1425                         <File
    1426                                 RelativePath="..\..\Objects\stringlib\fastsearch.h"
    1427                                 >
    1428                         </File>
    1429                         <File
    1430                                 RelativePath="..\..\Objects\fileobject.c"
    1431                                 >
    1432                         </File>
    1433                         <File
    1434                                 RelativePath="..\..\Objects\stringlib\find.h"
    1435                                 >
    1436                         </File>
    1437                         <File
    1438                                 RelativePath="..\..\Objects\floatobject.c"
    1439                                 >
    1440                         </File>
    1441                         <File
    1442                                 RelativePath="..\..\Objects\frameobject.c"
    1443                                 >
    1444                         </File>
    1445                         <File
    1446                                 RelativePath="..\..\Objects\funcobject.c"
    1447                                 >
    1448                         </File>
    1449                         <File
    1450                                 RelativePath="..\..\Objects\genobject.c"
    1451                                 >
    1452                         </File>
    1453                         <File
    1454                                 RelativePath="..\..\Objects\intobject.c"
    1455                                 >
    1456                         </File>
    1457                         <File
    1458                                 RelativePath="..\..\Objects\iterobject.c"
    1459                                 >
    1460                         </File>
    1461                         <File
    1462                                 RelativePath="..\..\Objects\listobject.c"
    1463                                 >
    1464                         </File>
    1465                         <File
    1466                                 RelativePath="..\..\Objects\longobject.c"
    1467                                 >
    1468                         </File>
    1469                         <File
    1470                                 RelativePath="..\..\Objects\methodobject.c"
    1471                                 >
    1472                         </File>
    1473                         <File
    1474                                 RelativePath="..\..\Objects\moduleobject.c"
    1475                                 >
    1476                         </File>
    1477                         <File
    1478                                 RelativePath="..\..\Objects\object.c"
    1479                                 >
    1480                         </File>
    1481                         <File
    1482                                 RelativePath="..\..\Objects\obmalloc.c"
    1483                                 >
    1484                         </File>
    1485                         <File
    1486                                 RelativePath="..\..\Objects\stringlib\partition.h"
    1487                                 >
    1488                         </File>
    1489                         <File
    1490                                 RelativePath="..\..\Objects\rangeobject.c"
    1491                                 >
    1492                         </File>
    1493                         <File
    1494                                 RelativePath="..\..\Objects\setobject.c"
    1495                                 >
    1496                         </File>
    1497                         <File
    1498                                 RelativePath="..\..\Objects\sliceobject.c"
    14991551                                >
    15001552                        </File>
     
    16601712                        </File>
    16611713                        <File
     1714                                RelativePath="..\..\Python\dtoa.c"
     1715                                >
     1716                        </File>
     1717                        <File
    16621718                                RelativePath="..\..\Python\dynload_win.c"
    16631719                                >
     
    16961752                        </File>
    16971753                        <File
    1698                                 RelativePath="..\..\Python\getmtime.c"
    1699                                 >
    1700                         </File>
    1701                         <File
    17021754                                RelativePath="..\..\Python\getopt.c"
    17031755                                >
     
    17521804                        </File>
    17531805                        <File
     1806                                RelativePath="..\..\Python\pyctype.c"
     1807                                >
     1808                        </File>
     1809                        <File
    17541810                                RelativePath="..\..\Python\pyfpe.c"
    17551811                                >
     
    17771833                        <File
    17781834                                RelativePath="..\..\Python\pythonrun.c"
     1835                                >
     1836                        </File>
     1837                        <File
     1838                                RelativePath="..\..\Python\random.c"
    17791839                                >
    17801840                        </File>
  • python/vendor/current/PC/VS8.0/select.vcproj

    r2 r388  
    5555                        <Tool
    5656                                Name="VCLinkerTool"
    57                                 AdditionalDependencies="wsock32.lib"
     57                                AdditionalDependencies="ws2_32.lib"
    5858                                IgnoreDefaultLibraryNames="libc"
    5959                                BaseAddress="0x1D110000"
     
    117117                        <Tool
    118118                                Name="VCLinkerTool"
    119                                 AdditionalDependencies="wsock32.lib"
     119                                AdditionalDependencies="ws2_32.lib"
    120120                                IgnoreDefaultLibraryNames="libc"
    121121                                BaseAddress="0x1D110000"
     
    179179                        <Tool
    180180                                Name="VCLinkerTool"
    181                                 AdditionalDependencies="wsock32.lib"
     181                                AdditionalDependencies="ws2_32.lib"
    182182                                IgnoreDefaultLibraryNames="libc"
    183183                                BaseAddress="0x1D110000"
     
    242242                        <Tool
    243243                                Name="VCLinkerTool"
    244                                 AdditionalDependencies="wsock32.lib"
     244                                AdditionalDependencies="ws2_32.lib"
    245245                                IgnoreDefaultLibraryNames="libc"
    246246                                BaseAddress="0x1D110000"
     
    304304                        <Tool
    305305                                Name="VCLinkerTool"
    306                                 AdditionalDependencies="wsock32.lib"
     306                                AdditionalDependencies="ws2_32.lib"
    307307                                IgnoreDefaultLibraryNames="libc"
    308308                                BaseAddress="0x1D110000"
     
    367367                        <Tool
    368368                                Name="VCLinkerTool"
    369                                 AdditionalDependencies="wsock32.lib"
     369                                AdditionalDependencies="ws2_32.lib"
    370370                                IgnoreDefaultLibraryNames="libc"
    371371                                BaseAddress="0x1D110000"
     
    430430                        <Tool
    431431                                Name="VCLinkerTool"
    432                                 AdditionalDependencies="wsock32.lib"
     432                                AdditionalDependencies="ws2_32.lib"
    433433                                IgnoreDefaultLibraryNames="libc"
    434434                                BaseAddress="0x1D110000"
     
    493493                        <Tool
    494494                                Name="VCLinkerTool"
    495                                 AdditionalDependencies="wsock32.lib"
     495                                AdditionalDependencies="ws2_32.lib"
    496496                                IgnoreDefaultLibraryNames="libc"
    497497                                BaseAddress="0x1D110000"
  • python/vendor/current/PC/VS8.0/sqlite3.vcproj

    r2 r388  
    2323                        Name="Debug|Win32"
    2424                        ConfigurationType="2"
    25                         InheritedPropertySheets=".\pyd_d.vsprops"
    26                         CharacterSet="0"
    27                         >
    28                         <Tool
    29                                 Name="VCPreBuildEventTool"
    30                         />
    31                         <Tool
    32                                 Name="VCCustomBuildTool"
    33                         />
    34                         <Tool
    35                                 Name="VCXMLDataGeneratorTool"
    36                         />
    37                         <Tool
    38                                 Name="VCWebServiceProxyGeneratorTool"
    39                         />
    40                         <Tool
    41                                 Name="VCMIDLTool"
    42                         />
    43                         <Tool
    44                                 Name="VCCLCompilerTool"
    45                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
    46                                 PreprocessorDefinitions="SQLITE_API=__declspec(dllexport)"
     25                        InheritedPropertySheets=".\sqlite3.vsprops;.\debug.vsprops"
     26                        CharacterSet="0"
     27                        >
     28                        <Tool
     29                                Name="VCPreBuildEventTool"
     30                        />
     31                        <Tool
     32                                Name="VCCustomBuildTool"
     33                        />
     34                        <Tool
     35                                Name="VCXMLDataGeneratorTool"
     36                        />
     37                        <Tool
     38                                Name="VCWebServiceProxyGeneratorTool"
     39                        />
     40                        <Tool
     41                                Name="VCMIDLTool"
     42                        />
     43                        <Tool
     44                                Name="VCCLCompilerTool"
     45                                AdditionalIncludeDirectories=""
    4746                        />
    4847                        <Tool
     
    8483                        Name="Debug|x64"
    8584                        ConfigurationType="2"
    86                         InheritedPropertySheets=".\pyd_d.vsprops;.\x64.vsprops"
     85                        InheritedPropertySheets=".\sqlite3.vsprops;.\debug.vsprops;.\x64.vsprops"
    8786                        CharacterSet="0"
    8887                        >
     
    105104                        <Tool
    106105                                Name="VCCLCompilerTool"
    107                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
    108                                 PreprocessorDefinitions="SQLITE_API=__declspec(dllexport)"
     106                                AdditionalIncludeDirectories=""
    109107                        />
    110108                        <Tool
     
    146144                        Name="Release|Win32"
    147145                        ConfigurationType="2"
    148                         InheritedPropertySheets=".\pyd.vsprops"
     146                        InheritedPropertySheets=".\sqlite3.vsprops"
    149147                        CharacterSet="0"
    150148                        WholeProgramOptimization="1"
     
    167165                        <Tool
    168166                                Name="VCCLCompilerTool"
    169                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
    170                                 PreprocessorDefinitions="SQLITE_API=__declspec(dllexport)"
     167                                AdditionalIncludeDirectories=""
    171168                        />
    172169                        <Tool
     
    208205                        Name="Release|x64"
    209206                        ConfigurationType="2"
    210                         InheritedPropertySheets=".\pyd.vsprops;.\x64.vsprops"
     207                        InheritedPropertySheets=".\sqlite3.vsprops;.\x64.vsprops"
    211208                        CharacterSet="0"
    212209                        WholeProgramOptimization="1"
     
    230227                        <Tool
    231228                                Name="VCCLCompilerTool"
    232                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
    233                                 PreprocessorDefinitions="SQLITE_API=__declspec(dllexport)"
     229                                AdditionalIncludeDirectories=""
    234230                        />
    235231                        <Tool
     
    271267                        Name="PGInstrument|Win32"
    272268                        ConfigurationType="2"
    273                         InheritedPropertySheets=".\pyd.vsprops;.\pginstrument.vsprops"
     269                        InheritedPropertySheets=".\sqlite3.vsprops;.\pginstrument.vsprops"
    274270                        CharacterSet="0"
    275271                        WholeProgramOptimization="1"
     
    292288                        <Tool
    293289                                Name="VCCLCompilerTool"
    294                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
    295                                 PreprocessorDefinitions="SQLITE_API=__declspec(dllexport)"
     290                                AdditionalIncludeDirectories="&quot;..\..\..\sqlite-3.6.21&quot;"
    296291                        />
    297292                        <Tool
     
    333328                        Name="PGInstrument|x64"
    334329                        ConfigurationType="2"
    335                         InheritedPropertySheets=".\pyd.vsprops;.\x64.vsprops;.\pginstrument.vsprops"
     330                        InheritedPropertySheets=".\sqlite3.vsprops;.\x64.vsprops;.\pginstrument.vsprops"
    336331                        CharacterSet="0"
    337332                        WholeProgramOptimization="1"
     
    355350                        <Tool
    356351                                Name="VCCLCompilerTool"
    357                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
    358                                 PreprocessorDefinitions="SQLITE_API=__declspec(dllexport)"
     352                                AdditionalIncludeDirectories=""
    359353                        />
    360354                        <Tool
     
    395389                        Name="PGUpdate|Win32"
    396390                        ConfigurationType="2"
    397                         InheritedPropertySheets=".\pyd.vsprops;.\pgupdate.vsprops"
     391                        InheritedPropertySheets=".\sqlite3.vsprops;.\pgupdate.vsprops"
    398392                        CharacterSet="0"
    399393                        WholeProgramOptimization="1"
     
    416410                        <Tool
    417411                                Name="VCCLCompilerTool"
    418                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
    419                                 PreprocessorDefinitions="SQLITE_API=__declspec(dllexport)"
     412                                AdditionalIncludeDirectories=""
    420413                        />
    421414                        <Tool
     
    457450                        Name="PGUpdate|x64"
    458451                        ConfigurationType="2"
    459                         InheritedPropertySheets=".\pyd.vsprops;.\x64.vsprops;.\pgupdate.vsprops"
     452                        InheritedPropertySheets=".\sqlite3.vsprops;.\x64.vsprops;.\pgupdate.vsprops"
    460453                        CharacterSet="0"
    461454                        WholeProgramOptimization="1"
     
    479472                        <Tool
    480473                                Name="VCCLCompilerTool"
    481                                 AdditionalIncludeDirectories="..\..\..\sqlite-3.5.9"
    482                                 PreprocessorDefinitions="SQLITE_API=__declspec(dllexport)"
     474                                AdditionalIncludeDirectories=""
    483475                        />
    484476                        <Tool
     
    524516                        >
    525517                        <File
    526                                 RelativePath="..\..\..\sqlite-3.5.9\sqlite3.h"
     518                                RelativePath="..\..\..\sqlite-3.6.21\sqlite3.h"
    527519                                >
    528520                        </File>
    529521                        <File
    530                                 RelativePath="..\..\..\sqlite-3.5.9\sqlite3ext.h"
     522                                RelativePath="..\..\..\sqlite-3.6.21\sqlite3ext.h"
    531523                                >
    532524                        </File>
     
    536528                        >
    537529                        <File
    538                                 RelativePath="..\..\..\sqlite-3.5.9\sqlite3.c"
     530                                RelativePath="..\..\..\sqlite-3.6.21\sqlite3.c"
    539531                                >
    540532                        </File>
  • python/vendor/current/PC/_msi.c

    r2 r388  
    2121    char *cresult;
    2222    PyObject *oresult;
    23    
     23
    2424    /* May return ok, local only, and no address.
    2525       For local only, the documentation says we still get a uuid.
     
    2727       use the result. */
    2828    if (UuidCreate(&result) == RPC_S_UUID_NO_ADDRESS) {
    29         PyErr_SetString(PyExc_NotImplementedError, "processing 'no address' result");
    30         return NULL;
     29        PyErr_SetString(PyExc_NotImplementedError, "processing 'no address' result");
     30        return NULL;
    3131    }
    3232
    3333    if (UuidToString(&result, &cresult) == RPC_S_OUT_OF_MEMORY) {
    34         PyErr_SetString(PyExc_MemoryError, "out of memory in uuidgen");
    35         return NULL;
     34        PyErr_SetString(PyExc_MemoryError, "out of memory in uuidgen");
     35        return NULL;
    3636    }
    3737
     
    5858    int result = _open(pszFile, oflag, pmode);
    5959    if (result == -1)
    60         *err = errno;
     60        *err = errno;
    6161    return result;
    6262}
     
    6666    UINT result = (UINT)_read(hf, memory, cb);
    6767    if (result != cb)
    68         *err = errno;
     68        *err = errno;
    6969    return result;
    7070}
     
    7474    UINT result = (UINT)_write(hf, memory, cb);
    7575    if (result != cb)
    76         *err = errno;
     76        *err = errno;
    7777    return result;
    7878}
     
    8282    int result = _close(hf);
    8383    if (result != 0)
    84         *err = errno;
     84        *err = errno;
    8585    return result;
    8686}
     
    9090    long result = (long)_lseek(hf, dist, seektype);
    9191    if (result == -1)
    92         *err = errno;
     92        *err = errno;
    9393    return result;
    9494}
     
    9898    int result = remove(pszFile);
    9999    if (result != 0)
    100         *err = errno;
     100        *err = errno;
    101101    return result;
    102102}
     
    111111    char *name = _tempnam("", "tmp");
    112112    if ((name != NULL) && ((int)strlen(name) < cbTempName)) {
    113         strcpy(pszTempName, name);
    114         free(name);
    115         return TRUE;
     113        strcpy(pszTempName, name);
     114        free(name);
     115        return TRUE;
    116116    }
    117117
     
    123123{
    124124    if (pv) {
    125         PyObject *result = PyObject_CallMethod(pv, "status", "iii", typeStatus, cb1, cb2);
    126         if (result == NULL)
    127             return -1;
    128         Py_DECREF(result);
     125        PyObject *result = PyObject_CallMethod(pv, "status", "iii", typeStatus, cb1, cb2);
     126        if (result == NULL)
     127            return -1;
     128        Py_DECREF(result);
    129129    }
    130130    return 0;
     
    134134{
    135135    if (pv) {
    136         PyObject *result = PyObject_CallMethod(pv, "getnextcabinet", "i", pccab->iCab);
    137         if (result == NULL)
    138             return -1;
    139         if (!PyString_Check(result)) {
    140             PyErr_Format(PyExc_TypeError,
    141                 "Incorrect return type %s from getnextcabinet",
    142                 result->ob_type->tp_name);
    143             Py_DECREF(result);
    144             return FALSE;
    145         }
    146         strncpy(pccab->szCab, PyString_AsString(result), sizeof(pccab->szCab));
    147         return TRUE;
     136        PyObject *result = PyObject_CallMethod(pv, "getnextcabinet", "i", pccab->iCab);
     137        if (result == NULL)
     138            return -1;
     139        if (!PyString_Check(result)) {
     140            PyErr_Format(PyExc_TypeError,
     141                "Incorrect return type %s from getnextcabinet",
     142                result->ob_type->tp_name);
     143            Py_DECREF(result);
     144            return FALSE;
     145        }
     146        strncpy(pccab->szCab, PyString_AsString(result), sizeof(pccab->szCab));
     147        return TRUE;
    148148    }
    149149    return FALSE;
     
    158158    /* Need Win32 handle to get time stamps */
    159159    handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL,
    160         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
     160        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    161161    if (handle == INVALID_HANDLE_VALUE)
    162         return -1;
     162        return -1;
    163163
    164164    if (GetFileInformationByHandle(handle, &bhfi) == FALSE)
    165165    {
    166         CloseHandle(handle);
    167         return -1;
     166        CloseHandle(handle);
     167        return -1;
    168168    }
    169169
     
    171171    FileTimeToDosDateTime(&filetime, pdate, ptime);
    172172
    173     *pattribs = (int)(bhfi.dwFileAttributes & 
    174         (_A_RDONLY | _A_SYSTEM | _A_HIDDEN | _A_ARCH));
     173    *pattribs = (int)(bhfi.dwFileAttributes &
     174        (_A_RDONLY | _A_SYSTEM | _A_HIDDEN | _A_ARCH));
    175175
    176176    CloseHandle(handle);
     
    190190
    191191    if (!PyArg_ParseTuple(args, "sO:FCICreate", &cabname, &files))
    192         return NULL;
     192        return NULL;
    193193
    194194    if (!PyList_Check(files)) {
    195         PyErr_SetString(PyExc_TypeError, "FCICreate expects a list");
    196         return NULL;
     195        PyErr_SetString(PyExc_TypeError, "FCICreate expects a list");
     196        return NULL;
    197197    }
    198198
     
    210210
    211211    for (i = 0, p = cabname; *p; p = CharNext(p))
    212         if (*p == '\\' || *p == '/')
    213             i = p - cabname + 1;
     212        if (*p == '\\' || *p == '/')
     213            i = p - cabname + 1;
    214214
    215215    if (i >= sizeof(ccab.szCabPath) ||
    216         strlen(cabname+i) >= sizeof(ccab.szCab)) {
    217         PyErr_SetString(PyExc_ValueError, "path name too long");
    218         return 0;
     216        strlen(cabname+i) >= sizeof(ccab.szCab)) {
     217        PyErr_SetString(PyExc_ValueError, "path name too long");
     218        return 0;
    219219    }
    220220
    221221    if (i > 0) {
    222         memcpy(ccab.szCabPath, cabname, i);
    223         ccab.szCabPath[i] = '\0';
    224         strcpy(ccab.szCab, cabname+i);
     222        memcpy(ccab.szCabPath, cabname, i);
     223        ccab.szCabPath[i] = '\0';
     224        strcpy(ccab.szCab, cabname+i);
    225225    } else {
    226         strcpy(ccab.szCabPath, ".\\");
    227         strcpy(ccab.szCab, cabname);
     226        strcpy(ccab.szCabPath, ".\\");
     227        strcpy(ccab.szCab, cabname);
    228228    }
    229229
    230230    hfci = FCICreate(&erf, cb_fileplaced, cb_alloc, cb_free,
    231         cb_open, cb_read, cb_write, cb_close, cb_seek, cb_delete,
    232         cb_gettempfile, &ccab, NULL);
     231        cb_open, cb_read, cb_write, cb_close, cb_seek, cb_delete,
     232        cb_gettempfile, &ccab, NULL);
    233233
    234234    if (hfci == NULL) {
    235         PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper);
    236         return NULL;
     235        PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper);
     236        return NULL;
    237237    }
    238238
    239239    for (i=0; i < PyList_GET_SIZE(files); i++) {
    240         PyObject *item = PyList_GET_ITEM(files, i);
    241         char *filename, *cabname;
    242         if (!PyArg_ParseTuple(item, "ss", &filename, &cabname))
    243             goto err;
    244         if (!FCIAddFile(hfci, filename, cabname, FALSE,
    245             cb_getnextcabinet, cb_status, cb_getopeninfo,
    246             tcompTYPE_MSZIP))
    247             goto err;
     240        PyObject *item = PyList_GET_ITEM(files, i);
     241        char *filename, *cabname;
     242        if (!PyArg_ParseTuple(item, "ss", &filename, &cabname))
     243            goto err;
     244        if (!FCIAddFile(hfci, filename, cabname, FALSE,
     245            cb_getnextcabinet, cb_status, cb_getopeninfo,
     246            tcompTYPE_MSZIP))
     247            goto err;
    248248    }
    249249
    250250    if (!FCIFlushCabinet(hfci, FALSE, cb_getnextcabinet, cb_status))
    251         goto err;
     251        goto err;
    252252
    253253    if (!FCIDestroy(hfci))
    254         goto err;
     254        goto err;
    255255
    256256    Py_INCREF(Py_None);
     
    267267}msiobj;
    268268
    269 static void 
     269static void
    270270msiobj_dealloc(msiobj* msidb)
    271271{
     
    293293
    294294    if (err == 0) {
    295         switch(status) {
    296         case ERROR_ACCESS_DENIED:
    297             PyErr_SetString(MSIError, "access denied");
    298             return NULL;
    299         case ERROR_FUNCTION_FAILED:
    300             PyErr_SetString(MSIError, "function failed");
    301             return NULL;
    302         case ERROR_INVALID_DATA:
    303             PyErr_SetString(MSIError, "invalid data");
    304             return NULL;
    305         case ERROR_INVALID_HANDLE:
    306             PyErr_SetString(MSIError, "invalid handle");
    307             return NULL;
    308         case ERROR_INVALID_STATE:
    309             PyErr_SetString(MSIError, "invalid state");
    310             return NULL;
    311         case ERROR_INVALID_PARAMETER:
    312             PyErr_SetString(MSIError, "invalid parameter");
    313             return NULL;
    314         default:
    315             PyErr_Format(MSIError, "unknown error %x", status);
    316             return NULL;
    317         }
     295        switch(status) {
     296        case ERROR_ACCESS_DENIED:
     297            PyErr_SetString(MSIError, "access denied");
     298            return NULL;
     299        case ERROR_FUNCTION_FAILED:
     300            PyErr_SetString(MSIError, "function failed");
     301            return NULL;
     302        case ERROR_INVALID_DATA:
     303            PyErr_SetString(MSIError, "invalid data");
     304            return NULL;
     305        case ERROR_INVALID_HANDLE:
     306            PyErr_SetString(MSIError, "invalid handle");
     307            return NULL;
     308        case ERROR_INVALID_STATE:
     309            PyErr_SetString(MSIError, "invalid state");
     310            return NULL;
     311        case ERROR_INVALID_PARAMETER:
     312            PyErr_SetString(MSIError, "invalid parameter");
     313            return NULL;
     314        default:
     315            PyErr_Format(MSIError, "unknown error %x", status);
     316            return NULL;
     317        }
    318318    }
    319319
    320320    code = MsiRecordGetInteger(err, 1); /* XXX code */
    321321    if (MsiFormatRecord(0, err, res, &size) == ERROR_MORE_DATA) {
    322         res = malloc(size+1);
    323         MsiFormatRecord(0, err, res, &size);
    324         res[size]='\0';
     322        res = malloc(size+1);
     323        MsiFormatRecord(0, err, res, &size);
     324        res[size]='\0';
    325325    }
    326326    MsiCloseHandle(err);
    327327    PyErr_SetString(MSIError, res);
    328328    if (res != buf)
    329         free(res);
     329        free(res);
    330330    return NULL;
    331331}
     
    344344    unsigned int field;
    345345    int status;
    346    
     346
    347347    if (!PyArg_ParseTuple(args, "I:GetInteger", &field))
    348348        return NULL;
     
    364364    DWORD size = sizeof(buf);
    365365    PyObject* string;
    366    
     366
    367367    if (!PyArg_ParseTuple(args, "I:GetString", &field))
    368368        return NULL;
     
    387387    int status = MsiRecordClearData(record->h);
    388388    if (status != ERROR_SUCCESS)
    389         return msierror(status);
     389        return msierror(status);
    390390
    391391    Py_INCREF(Py_None);
     
    401401
    402402    if (!PyArg_ParseTuple(args, "is:SetString", &field, &data))
    403         return NULL;
     403        return NULL;
    404404
    405405    if ((status = MsiRecordSetString(record->h, field, data)) != ERROR_SUCCESS)
    406         return msierror(status);
     406        return msierror(status);
    407407
    408408    Py_INCREF(Py_None);
     
    418418
    419419    if (!PyArg_ParseTuple(args, "is:SetStream", &field, &data))
    420         return NULL;
     420        return NULL;
    421421
    422422    if ((status = MsiRecordSetStream(record->h, field, data)) != ERROR_SUCCESS)
    423         return msierror(status);
     423        return msierror(status);
    424424
    425425    Py_INCREF(Py_None);
     
    435435
    436436    if (!PyArg_ParseTuple(args, "ii:SetInteger", &field, &data))
    437         return NULL;
     437        return NULL;
    438438
    439439    if ((status = MsiRecordSetInteger(record->h, field, data)) != ERROR_SUCCESS)
    440         return msierror(status);
     440        return msierror(status);
    441441
    442442    Py_INCREF(Py_None);
     
    447447
    448448static PyMethodDef record_methods[] = {
    449     { "GetFieldCount", (PyCFunction)record_getfieldcount, METH_NOARGS, 
    450         PyDoc_STR("GetFieldCount() -> int\nWraps MsiRecordGetFieldCount")},
     449    { "GetFieldCount", (PyCFunction)record_getfieldcount, METH_NOARGS,
     450        PyDoc_STR("GetFieldCount() -> int\nWraps MsiRecordGetFieldCount")},
    451451    { "GetInteger", (PyCFunction)record_getinteger, METH_VARARGS,
    452452    PyDoc_STR("GetInteger(field) -> int\nWraps MsiRecordGetInteger")},
    453453    { "GetString", (PyCFunction)record_getstring, METH_VARARGS,
    454454    PyDoc_STR("GetString(field) -> string\nWraps MsiRecordGetString")},
    455     { "SetString", (PyCFunction)record_setstring, METH_VARARGS, 
    456         PyDoc_STR("SetString(field,str) -> None\nWraps MsiRecordSetString")},
    457     { "SetStream", (PyCFunction)record_setstream, METH_VARARGS, 
    458         PyDoc_STR("SetStream(field,filename) -> None\nWraps MsiRecordSetInteger")},
    459     { "SetInteger", (PyCFunction)record_setinteger, METH_VARARGS, 
    460         PyDoc_STR("SetInteger(field,int) -> None\nWraps MsiRecordSetInteger")},
    461     { "ClearData", (PyCFunction)record_cleardata, METH_NOARGS, 
    462         PyDoc_STR("ClearData() -> int\nWraps MsiRecordGClearData")},
     455    { "SetString", (PyCFunction)record_setstring, METH_VARARGS,
     456        PyDoc_STR("SetString(field,str) -> None\nWraps MsiRecordSetString")},
     457    { "SetStream", (PyCFunction)record_setstream, METH_VARARGS,
     458        PyDoc_STR("SetStream(field,filename) -> None\nWraps MsiRecordSetInteger")},
     459    { "SetInteger", (PyCFunction)record_setinteger, METH_VARARGS,
     460        PyDoc_STR("SetInteger(field,int) -> None\nWraps MsiRecordSetInteger")},
     461    { "ClearData", (PyCFunction)record_cleardata, METH_NOARGS,
     462        PyDoc_STR("ClearData() -> int\nWraps MsiRecordGClearData")},
    463463    { NULL, NULL }
    464464};
    465465
    466466static PyTypeObject record_Type = {
    467         PyVarObject_HEAD_INIT(NULL, 0)
    468         "_msi.Record",          /*tp_name*/
    469         sizeof(msiobj), /*tp_basicsize*/
    470         0,                      /*tp_itemsize*/
    471         /* methods */
    472         (destructor)msiobj_dealloc, /*tp_dealloc*/
    473         0,                      /*tp_print*/
    474         0,                      /*tp_getattr*/
    475         0,                      /*tp_setattr*/
    476         0,                      /*tp_compare*/
    477         0,                      /*tp_repr*/
    478         0,                      /*tp_as_number*/
    479         0,                      /*tp_as_sequence*/
    480         0,                      /*tp_as_mapping*/
    481         0,                      /*tp_hash*/
     467        PyVarObject_HEAD_INIT(NULL, 0)
     468        "_msi.Record",          /*tp_name*/
     469        sizeof(msiobj), /*tp_basicsize*/
     470        0,                      /*tp_itemsize*/
     471        /* methods */
     472        (destructor)msiobj_dealloc, /*tp_dealloc*/
     473        0,                      /*tp_print*/
     474        0,                      /*tp_getattr*/
     475        0,                      /*tp_setattr*/
     476        0,                      /*tp_compare*/
     477        0,                      /*tp_repr*/
     478        0,                      /*tp_as_number*/
     479        0,                      /*tp_as_sequence*/
     480        0,                      /*tp_as_mapping*/
     481        0,                      /*tp_hash*/
    482482        0,                      /*tp_call*/
    483483        0,                      /*tp_str*/
     
    514514
    515515    if (!result) {
    516         MsiCloseHandle(h);
    517         return NULL;
     516        MsiCloseHandle(h);
     517        return NULL;
    518518    }
    519519
     
    538538
    539539    if (!PyArg_ParseTuple(args, "i:GetProperty", &field))
    540         return NULL;
    541 
    542     status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival, 
    543         &fval, sval, &ssize);
     540        return NULL;
     541
     542    status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival,
     543        &fval, sval, &ssize);
    544544    if (status == ERROR_MORE_DATA) {
    545         sval = malloc(ssize);
    546         status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival, 
    547             &fval, sval, &ssize);
     545        sval = malloc(ssize);
     546        status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival,
     547            &fval, sval, &ssize);
    548548    }
    549549
    550550    switch(type) {
    551         case VT_I2: case VT_I4:
    552             return PyInt_FromLong(ival);
    553         case VT_FILETIME:
    554             PyErr_SetString(PyExc_NotImplementedError, "FILETIME result");
    555             return NULL;
    556         case VT_LPSTR:
    557             result = PyString_FromStringAndSize(sval, ssize);
    558             if (sval != sbuf)
    559                 free(sval);
    560             return result;
     551        case VT_I2: case VT_I4:
     552            return PyInt_FromLong(ival);
     553        case VT_FILETIME:
     554            PyErr_SetString(PyExc_NotImplementedError, "FILETIME result");
     555            return NULL;
     556        case VT_LPSTR:
     557            result = PyString_FromStringAndSize(sval, ssize);
     558            if (sval != sbuf)
     559                free(sval);
     560            return result;
    561561    }
    562562    PyErr_Format(PyExc_NotImplementedError, "result of type %d", type);
     
    572572    status = MsiSummaryInfoGetPropertyCount(si->h, &result);
    573573    if (status != ERROR_SUCCESS)
    574         return msierror(status);
     574        return msierror(status);
    575575
    576576    return PyInt_FromLong(result);
     
    585585
    586586    if (!PyArg_ParseTuple(args, "iO:SetProperty", &field, &data))
    587         return NULL;
     587        return NULL;
    588588
    589589    if (PyString_Check(data)) {
    590         status = MsiSummaryInfoSetProperty(si->h, field, VT_LPSTR,
    591             0, NULL, PyString_AsString(data));
     590        status = MsiSummaryInfoSetProperty(si->h, field, VT_LPSTR,
     591            0, NULL, PyString_AsString(data));
    592592    } else if (PyInt_Check(data)) {
    593         status = MsiSummaryInfoSetProperty(si->h, field, VT_I4,
    594             PyInt_AsLong(data), NULL, NULL);
     593        status = MsiSummaryInfoSetProperty(si->h, field, VT_I4,
     594            PyInt_AsLong(data), NULL, NULL);
    595595    } else {
    596         PyErr_SetString(PyExc_TypeError, "unsupported type");
    597         return NULL;
    598     }
    599    
     596        PyErr_SetString(PyExc_TypeError, "unsupported type");
     597        return NULL;
     598    }
     599
    600600    if (status != ERROR_SUCCESS)
    601         return msierror(status);
     601        return msierror(status);
    602602
    603603    Py_INCREF(Py_None);
     
    613613    status = MsiSummaryInfoPersist(si->h);
    614614    if (status != ERROR_SUCCESS)
    615         return msierror(status);
     615        return msierror(status);
    616616    Py_INCREF(Py_None);
    617617    return Py_None;
     
    619619
    620620static PyMethodDef summary_methods[] = {
    621     { "GetProperty", (PyCFunction)summary_getproperty, METH_VARARGS, 
    622         PyDoc_STR("GetProperty(propid) -> value\nWraps MsiSummaryInfoGetProperty")},
    623     { "GetPropertyCount", (PyCFunction)summary_getpropertycount, METH_NOARGS, 
    624         PyDoc_STR("GetProperty() -> int\nWraps MsiSummaryInfoGetPropertyCount")},
    625     { "SetProperty", (PyCFunction)summary_setproperty, METH_VARARGS, 
    626         PyDoc_STR("SetProperty(value) -> None\nWraps MsiSummaryInfoProperty")},
    627     { "Persist", (PyCFunction)summary_persist, METH_NOARGS, 
    628         PyDoc_STR("Persist() -> None\nWraps MsiSummaryInfoPersist")},
     621    { "GetProperty", (PyCFunction)summary_getproperty, METH_VARARGS,
     622        PyDoc_STR("GetProperty(propid) -> value\nWraps MsiSummaryInfoGetProperty")},
     623    { "GetPropertyCount", (PyCFunction)summary_getpropertycount, METH_NOARGS,
     624        PyDoc_STR("GetProperty() -> int\nWraps MsiSummaryInfoGetPropertyCount")},
     625    { "SetProperty", (PyCFunction)summary_setproperty, METH_VARARGS,
     626        PyDoc_STR("SetProperty(value) -> None\nWraps MsiSummaryInfoProperty")},
     627    { "Persist", (PyCFunction)summary_persist, METH_NOARGS,
     628        PyDoc_STR("Persist() -> None\nWraps MsiSummaryInfoPersist")},
    629629    { NULL, NULL }
    630630};
    631631
    632632static PyTypeObject summary_Type = {
    633         PyVarObject_HEAD_INIT(NULL, 0)
    634         "_msi.SummaryInformation",              /*tp_name*/
    635         sizeof(msiobj), /*tp_basicsize*/
    636         0,                      /*tp_itemsize*/
    637         /* methods */
    638         (destructor)msiobj_dealloc, /*tp_dealloc*/
    639         0,                      /*tp_print*/
    640         0,                      /*tp_getattr*/
    641         0,                      /*tp_setattr*/
    642         0,                      /*tp_compare*/
    643         0,                      /*tp_repr*/
    644         0,                      /*tp_as_number*/
    645         0,                      /*tp_as_sequence*/
    646         0,                      /*tp_as_mapping*/
    647         0,                      /*tp_hash*/
     633        PyVarObject_HEAD_INIT(NULL, 0)
     634        "_msi.SummaryInformation",              /*tp_name*/
     635        sizeof(msiobj), /*tp_basicsize*/
     636        0,                      /*tp_itemsize*/
     637        /* methods */
     638        (destructor)msiobj_dealloc, /*tp_dealloc*/
     639        0,                      /*tp_print*/
     640        0,                      /*tp_getattr*/
     641        0,                      /*tp_setattr*/
     642        0,                      /*tp_compare*/
     643        0,                      /*tp_repr*/
     644        0,                      /*tp_as_number*/
     645        0,                      /*tp_as_sequence*/
     646        0,                      /*tp_as_mapping*/
     647        0,                      /*tp_hash*/
    648648        0,                      /*tp_call*/
    649649        0,                      /*tp_str*/
     
    684684
    685685    if (!PyArg_ParseTuple(args, "O:Execute", &oparams))
    686         return NULL;
     686        return NULL;
    687687
    688688    if (oparams != Py_None) {
     
    696696    status = MsiViewExecute(view->h, params);
    697697    if (status != ERROR_SUCCESS)
    698         return msierror(status);
     698        return msierror(status);
    699699
    700700    Py_INCREF(Py_None);
     
    709709
    710710    if ((status = MsiViewFetch(view->h, &result)) != ERROR_SUCCESS)
    711         return msierror(status);
     711        return msierror(status);
    712712
    713713    return record_new(result);
     
    722722
    723723    if (!PyArg_ParseTuple(args, "i:GetColumnInfo", &kind))
    724         return NULL;
     724        return NULL;
    725725
    726726    if ((status = MsiViewGetColumnInfo(view->h, kind, &result)) != ERROR_SUCCESS)
    727         return msierror(status);
     727        return msierror(status);
    728728
    729729    return record_new(result);
     
    738738
    739739    if (!PyArg_ParseTuple(args, "iO:Modify", &kind, &data))
    740         return NULL;
     740        return NULL;
    741741
    742742    if (data->ob_type != &record_Type) {
    743         PyErr_SetString(PyExc_TypeError, "Modify expects a record object");
    744         return NULL;
     743        PyErr_SetString(PyExc_TypeError, "Modify expects a record object");
     744        return NULL;
    745745    }
    746746
    747747    if ((status = MsiViewModify(view->h, kind, ((msiobj*)data)->h)) != ERROR_SUCCESS)
    748         return msierror(status);
     748        return msierror(status);
    749749
    750750    Py_INCREF(Py_None);
     
    758758
    759759    if ((status = MsiViewClose(view->h)) != ERROR_SUCCESS)
    760         return msierror(status);
     760        return msierror(status);
    761761
    762762    Py_INCREF(Py_None);
     
    765765
    766766static PyMethodDef view_methods[] = {
    767     { "Execute", (PyCFunction)view_execute, METH_VARARGS, 
    768         PyDoc_STR("Execute(params=None) -> None\nWraps MsiViewExecute")},
     767    { "Execute", (PyCFunction)view_execute, METH_VARARGS,
     768        PyDoc_STR("Execute(params=None) -> None\nWraps MsiViewExecute")},
    769769    { "GetColumnInfo", (PyCFunction)view_getcolumninfo, METH_VARARGS,
    770         PyDoc_STR("GetColumnInfo() -> result\nWraps MsiGetColumnInfo")},
     770        PyDoc_STR("GetColumnInfo() -> result\nWraps MsiGetColumnInfo")},
    771771    { "Fetch", (PyCFunction)view_fetch, METH_NOARGS,
    772         PyDoc_STR("Fetch() -> result\nWraps MsiViewFetch")},
     772        PyDoc_STR("Fetch() -> result\nWraps MsiViewFetch")},
    773773    { "Modify", (PyCFunction)view_modify, METH_VARARGS,
    774         PyDoc_STR("Modify(mode,record) -> None\nWraps MsiViewModify")},
     774        PyDoc_STR("Modify(mode,record) -> None\nWraps MsiViewModify")},
    775775    { "Close", (PyCFunction)view_close, METH_NOARGS,
    776         PyDoc_STR("Close() -> result\nWraps MsiViewClose")},
     776        PyDoc_STR("Close() -> result\nWraps MsiViewClose")},
    777777    { NULL, NULL }
    778778};
    779779
    780780static PyTypeObject msiview_Type = {
    781         PyVarObject_HEAD_INIT(NULL, 0)
    782         "_msi.View",            /*tp_name*/
    783         sizeof(msiobj), /*tp_basicsize*/
    784         0,                      /*tp_itemsize*/
    785         /* methods */
    786         (destructor)msiobj_dealloc, /*tp_dealloc*/
    787         0,                      /*tp_print*/
    788         0,                      /*tp_getattr*/
    789         0,                      /*tp_setattr*/
    790         0,                      /*tp_compare*/
    791         0,                      /*tp_repr*/
    792         0,                      /*tp_as_number*/
    793         0,                      /*tp_as_sequence*/
    794         0,                      /*tp_as_mapping*/
    795         0,                      /*tp_hash*/
     781        PyVarObject_HEAD_INIT(NULL, 0)
     782        "_msi.View",            /*tp_name*/
     783        sizeof(msiobj), /*tp_basicsize*/
     784        0,                      /*tp_itemsize*/
     785        /* methods */
     786        (destructor)msiobj_dealloc, /*tp_dealloc*/
     787        0,                      /*tp_print*/
     788        0,                      /*tp_getattr*/
     789        0,                      /*tp_setattr*/
     790        0,                      /*tp_compare*/
     791        0,                      /*tp_repr*/
     792        0,                      /*tp_as_number*/
     793        0,                      /*tp_as_sequence*/
     794        0,                      /*tp_as_mapping*/
     795        0,                      /*tp_hash*/
    796796        0,                      /*tp_call*/
    797797        0,                      /*tp_str*/
     
    833833
    834834    if (!PyArg_ParseTuple(args, "s:OpenView", &sql))
    835         return NULL;
     835        return NULL;
    836836
    837837    if ((status = MsiDatabaseOpenView(msidb->h, sql, &hView)) != ERROR_SUCCESS)
    838         return msierror(status);
     838        return msierror(status);
    839839
    840840    result = PyObject_NEW(struct msiobj, &msiview_Type);
    841841    if (!result) {
    842         MsiCloseHandle(hView);
    843         return NULL;
     842        MsiCloseHandle(hView);
     843        return NULL;
    844844    }
    845845
     
    854854
    855855    if ((status = MsiDatabaseCommit(msidb->h)) != ERROR_SUCCESS)
    856         return msierror(status);
     856        return msierror(status);
    857857
    858858    Py_INCREF(Py_None);
     
    869869
    870870    if (!PyArg_ParseTuple(args, "i:GetSummaryInformation", &count))
    871         return NULL;
     871        return NULL;
    872872
    873873    status = MsiGetSummaryInformation(db->h, NULL, count, &result);
    874874    if (status != ERROR_SUCCESS)
    875         return msierror(status);
     875        return msierror(status);
    876876
    877877    oresult = PyObject_NEW(struct msiobj, &summary_Type);
    878878    if (!result) {
    879         MsiCloseHandle(result);
    880         return NULL;
     879        MsiCloseHandle(result);
     880        return NULL;
    881881    }
    882882
     
    886886
    887887static PyMethodDef db_methods[] = {
    888     { "OpenView", (PyCFunction)msidb_openview, METH_VARARGS, 
    889         PyDoc_STR("OpenView(sql) -> viewobj\nWraps MsiDatabaseOpenView")},
     888    { "OpenView", (PyCFunction)msidb_openview, METH_VARARGS,
     889        PyDoc_STR("OpenView(sql) -> viewobj\nWraps MsiDatabaseOpenView")},
    890890    { "Commit", (PyCFunction)msidb_commit, METH_NOARGS,
    891         PyDoc_STR("Commit() -> None\nWraps MsiDatabaseCommit")},
    892     { "GetSummaryInformation", (PyCFunction)msidb_getsummaryinformation, METH_VARARGS, 
    893         PyDoc_STR("GetSummaryInformation(updateCount) -> viewobj\nWraps MsiGetSummaryInformation")},
     891        PyDoc_STR("Commit() -> None\nWraps MsiDatabaseCommit")},
     892    { "GetSummaryInformation", (PyCFunction)msidb_getsummaryinformation, METH_VARARGS,
     893        PyDoc_STR("GetSummaryInformation(updateCount) -> viewobj\nWraps MsiGetSummaryInformation")},
    894894    { NULL, NULL }
    895895};
    896896
    897897static PyTypeObject msidb_Type = {
    898         PyVarObject_HEAD_INIT(NULL, 0)
    899         "_msi.Database",                /*tp_name*/
    900         sizeof(msiobj), /*tp_basicsize*/
    901         0,                      /*tp_itemsize*/
    902         /* methods */
    903         (destructor)msiobj_dealloc, /*tp_dealloc*/
    904         0,                      /*tp_print*/
    905         0,                      /*tp_getattr*/
    906         0,                      /*tp_setattr*/
    907         0,                      /*tp_compare*/
    908         0,                      /*tp_repr*/
    909         0,                      /*tp_as_number*/
    910         0,                      /*tp_as_sequence*/
    911         0,                      /*tp_as_mapping*/
    912         0,                      /*tp_hash*/
     898        PyVarObject_HEAD_INIT(NULL, 0)
     899        "_msi.Database",                /*tp_name*/
     900        sizeof(msiobj), /*tp_basicsize*/
     901        0,                      /*tp_itemsize*/
     902        /* methods */
     903        (destructor)msiobj_dealloc, /*tp_dealloc*/
     904        0,                      /*tp_print*/
     905        0,                      /*tp_getattr*/
     906        0,                      /*tp_setattr*/
     907        0,                      /*tp_compare*/
     908        0,                      /*tp_repr*/
     909        0,                      /*tp_as_number*/
     910        0,                      /*tp_as_sequence*/
     911        0,                      /*tp_as_mapping*/
     912        0,                      /*tp_hash*/
    913913        0,                      /*tp_call*/
    914914        0,                      /*tp_str*/
     
    946946    MSIHANDLE h;
    947947    msiobj *result;
    948    
     948
    949949    if (!PyArg_ParseTuple(args, "si:MSIOpenDatabase", &path, &persist))
    950         return NULL;
    951 
    952         status = MsiOpenDatabase(path, (LPCSTR)persist, &h);
     950        return NULL;
     951
     952        status = MsiOpenDatabase(path, (LPCSTR)persist, &h);
    953953    if (status != ERROR_SUCCESS)
    954         return msierror(status);
     954        return msierror(status);
    955955
    956956    result = PyObject_NEW(struct msiobj, &msidb_Type);
    957957    if (!result) {
    958         MsiCloseHandle(h);
    959         return NULL;
     958        MsiCloseHandle(h);
     959        return NULL;
    960960    }
    961961    result->h = h;
     
    970970
    971971    if (!PyArg_ParseTuple(args, "i:CreateRecord", &count))
    972         return NULL;
    973    
     972        return NULL;
     973
    974974    h = MsiCreateRecord(count);
    975975    if (h == 0)
    976         return msierror(0);
     976        return msierror(0);
    977977
    978978    return record_new(h);
     
    982982static PyMethodDef msi_methods[] = {
    983983        {"UuidCreate", (PyCFunction)uuidcreate, METH_NOARGS,
    984                 PyDoc_STR("UuidCreate() -> string")},
    985         {"FCICreate",   (PyCFunction)fcicreate, METH_VARARGS,
    986                 PyDoc_STR("fcicreate(cabname,files) -> None")},
    987         {"OpenDatabase", (PyCFunction)msiopendb, METH_VARARGS,
    988         PyDoc_STR("OpenDatabase(name, flags) -> dbobj\nWraps MsiOpenDatabase")},
    989         {"CreateRecord", (PyCFunction)createrecord, METH_VARARGS,
    990         PyDoc_STR("OpenDatabase(name, flags) -> dbobj\nWraps MsiCreateRecord")},
    991         {NULL,          NULL}           /* sentinel */
     984                PyDoc_STR("UuidCreate() -> string")},
     985        {"FCICreate",   (PyCFunction)fcicreate, METH_VARARGS,
     986                PyDoc_STR("fcicreate(cabname,files) -> None")},
     987        {"OpenDatabase", (PyCFunction)msiopendb, METH_VARARGS,
     988        PyDoc_STR("OpenDatabase(name, flags) -> dbobj\nWraps MsiOpenDatabase")},
     989        {"CreateRecord", (PyCFunction)createrecord, METH_VARARGS,
     990        PyDoc_STR("OpenDatabase(name, flags) -> dbobj\nWraps MsiCreateRecord")},
     991        {NULL,          NULL}           /* sentinel */
    992992};
    993993
     
    10011001    m = Py_InitModule3("_msi", msi_methods, msi_doc);
    10021002    if (m == NULL)
    1003         return;
     1003        return;
    10041004
    10051005    PyModule_AddIntConstant(m, "MSIDBOPEN_CREATEDIRECT", (int)MSIDBOPEN_CREATEDIRECT);
     
    10471047    MSIError = PyErr_NewException ("_msi.MSIError", NULL, NULL);
    10481048    if (!MSIError)
    1049         return;
     1049        return;
    10501050    PyModule_AddObject(m, "MSIError", MSIError);
    10511051}
  • python/vendor/current/PC/_subprocess.c

    r2 r388  
    5050
    5151typedef struct {
    52         PyObject_HEAD
    53         HANDLE handle;
     52    PyObject_HEAD
     53    HANDLE handle;
    5454} sp_handle_object;
    5555
     
    5959sp_handle_new(HANDLE handle)
    6060{
    61         sp_handle_object* self;
    62 
    63         self = PyObject_NEW(sp_handle_object, &sp_handle_type);
    64         if (self == NULL)
    65                 return NULL;
    66 
    67         self->handle = handle;
    68 
    69         return (PyObject*) self;
     61    sp_handle_object* self;
     62
     63    self = PyObject_NEW(sp_handle_object, &sp_handle_type);
     64    if (self == NULL)
     65        return NULL;
     66
     67    self->handle = handle;
     68
     69    return (PyObject*) self;
    7070}
    7171
    7272#if defined(MS_WIN32) && !defined(MS_WIN64)
    73 #define HANDLE_TO_PYNUM(handle) PyInt_FromLong((long) handle)
    74 #define PY_HANDLE_PARAM "l"
     73#define HANDLE_TO_PYNUM(handle) PyInt_FromLong((long) handle)
     74#define PY_HANDLE_PARAM "l"
    7575#else
    76 #define HANDLE_TO_PYNUM(handle) PyLong_FromLongLong((long long) handle)
    77 #define PY_HANDLE_PARAM "L"
     76#define HANDLE_TO_PYNUM(handle) PyLong_FromLongLong((long long) handle)
     77#define PY_HANDLE_PARAM "L"
    7878#endif
    7979
     
    8181sp_handle_detach(sp_handle_object* self, PyObject* args)
    8282{
    83         HANDLE handle;
    84 
    85         if (! PyArg_ParseTuple(args, ":Detach"))
    86                 return NULL;
    87 
    88         handle = self->handle;
    89 
    90         self->handle = INVALID_HANDLE_VALUE;
    91 
    92         /* note: return the current handle, as an integer */
    93         return HANDLE_TO_PYNUM(handle);
     83    HANDLE handle;
     84
     85    if (! PyArg_ParseTuple(args, ":Detach"))
     86        return NULL;
     87
     88    handle = self->handle;
     89
     90    self->handle = INVALID_HANDLE_VALUE;
     91
     92    /* note: return the current handle, as an integer */
     93    return HANDLE_TO_PYNUM(handle);
    9494}
    9595
     
    9797sp_handle_close(sp_handle_object* self, PyObject* args)
    9898{
    99         if (! PyArg_ParseTuple(args, ":Close"))
    100                 return NULL;
    101 
    102         if (self->handle != INVALID_HANDLE_VALUE) {
    103                 CloseHandle(self->handle);
    104                 self->handle = INVALID_HANDLE_VALUE;
    105         }
    106         Py_INCREF(Py_None);
    107         return Py_None;
     99    if (! PyArg_ParseTuple(args, ":Close"))
     100        return NULL;
     101
     102    if (self->handle != INVALID_HANDLE_VALUE) {
     103        CloseHandle(self->handle);
     104        self->handle = INVALID_HANDLE_VALUE;
     105    }
     106    Py_INCREF(Py_None);
     107    return Py_None;
    108108}
    109109
     
    111111sp_handle_dealloc(sp_handle_object* self)
    112112{
    113         if (self->handle != INVALID_HANDLE_VALUE)
    114                 CloseHandle(self->handle);
    115         PyObject_FREE(self);
     113    if (self->handle != INVALID_HANDLE_VALUE)
     114        CloseHandle(self->handle);
     115    PyObject_FREE(self);
    116116}
    117117
    118118static PyMethodDef sp_handle_methods[] = {
    119         {"Detach", (PyCFunction) sp_handle_detach, METH_VARARGS},
    120         {"Close",  (PyCFunction) sp_handle_close,  METH_VARARGS},
    121         {NULL, NULL}
     119    {"Detach", (PyCFunction) sp_handle_detach, METH_VARARGS},
     120    {"Close",  (PyCFunction) sp_handle_close,  METH_VARARGS},
     121    {NULL, NULL}
    122122};
    123123
     
    125125sp_handle_getattr(sp_handle_object* self, char* name)
    126126{
    127         return Py_FindMethod(sp_handle_methods, (PyObject*) self, name);
     127    return Py_FindMethod(sp_handle_methods, (PyObject*) self, name);
    128128}
    129129
     
    131131sp_handle_as_int(sp_handle_object* self)
    132132{
    133         return HANDLE_TO_PYNUM(self->handle);
     133    return HANDLE_TO_PYNUM(self->handle);
    134134}
    135135
     
    137137
    138138statichere PyTypeObject sp_handle_type = {
    139         PyObject_HEAD_INIT(NULL)
    140         0,                              /*ob_size*/
    141         "_subprocess_handle", sizeof(sp_handle_object), 0,
    142         (destructor) sp_handle_dealloc, /*tp_dealloc*/
    143         0, /*tp_print*/
    144         (getattrfunc) sp_handle_getattr,/*tp_getattr*/
    145         0,                              /*tp_setattr*/
    146         0,                              /*tp_compare*/
    147         0,                              /*tp_repr*/
    148         &sp_handle_as_number,           /*tp_as_number */
    149         0,                              /*tp_as_sequence */
    150         0,                              /*tp_as_mapping */
    151         0                               /*tp_hash*/
     139    PyObject_HEAD_INIT(NULL)
     140    0,                                  /*ob_size*/
     141    "_subprocess_handle", sizeof(sp_handle_object), 0,
     142    (destructor) sp_handle_dealloc, /*tp_dealloc*/
     143    0, /*tp_print*/
     144    (getattrfunc) sp_handle_getattr,/*tp_getattr*/
     145    0,                                  /*tp_setattr*/
     146    0,                                  /*tp_compare*/
     147    0,                                  /*tp_repr*/
     148    &sp_handle_as_number,               /*tp_as_number */
     149    0,                                  /*tp_as_sequence */
     150    0,                                  /*tp_as_mapping */
     151    0                                   /*tp_hash*/
    152152};
    153153
     
    155155/* windows API functions */
    156156
     157PyDoc_STRVAR(GetStdHandle_doc,
     158"GetStdHandle(handle) -> integer\n\
     159\n\
     160Return a handle to the specified standard device\n\
     161(STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE).\n\
     162The integer associated with the handle object is returned.");
     163
    157164static PyObject *
    158165sp_GetStdHandle(PyObject* self, PyObject* args)
    159166{
    160         HANDLE handle;
    161         int std_handle;
    162 
    163         if (! PyArg_ParseTuple(args, "i:GetStdHandle", &std_handle))
    164                 return NULL;
    165 
    166         Py_BEGIN_ALLOW_THREADS
    167         handle = GetStdHandle((DWORD) std_handle);
    168         Py_END_ALLOW_THREADS
    169 
    170         if (handle == INVALID_HANDLE_VALUE)
    171                 return PyErr_SetFromWindowsErr(GetLastError());
    172 
    173         if (! handle) {
    174                 Py_INCREF(Py_None);
    175                 return Py_None;
    176         }
    177 
    178         /* note: returns integer, not handle object */
    179         return HANDLE_TO_PYNUM(handle);
    180 }
     167    HANDLE handle;
     168    int std_handle;
     169
     170    if (! PyArg_ParseTuple(args, "i:GetStdHandle", &std_handle))
     171        return NULL;
     172
     173    Py_BEGIN_ALLOW_THREADS
     174    handle = GetStdHandle((DWORD) std_handle);
     175    Py_END_ALLOW_THREADS
     176
     177    if (handle == INVALID_HANDLE_VALUE)
     178        return PyErr_SetFromWindowsErr(GetLastError());
     179
     180    if (! handle) {
     181        Py_INCREF(Py_None);
     182        return Py_None;
     183    }
     184
     185    /* note: returns integer, not handle object */
     186    return HANDLE_TO_PYNUM(handle);
     187}
     188
     189PyDoc_STRVAR(GetCurrentProcess_doc,
     190"GetCurrentProcess() -> handle\n\
     191\n\
     192Return a handle object for the current process.");
    181193
    182194static PyObject *
    183195sp_GetCurrentProcess(PyObject* self, PyObject* args)
    184196{
    185         if (! PyArg_ParseTuple(args, ":GetCurrentProcess"))
    186                 return NULL;
    187 
    188         return sp_handle_new(GetCurrentProcess());
    189 }
     197    if (! PyArg_ParseTuple(args, ":GetCurrentProcess"))
     198        return NULL;
     199
     200    return sp_handle_new(GetCurrentProcess());
     201}
     202
     203PyDoc_STRVAR(DuplicateHandle_doc,
     204"DuplicateHandle(source_proc_handle, source_handle,\n\
     205                 target_proc_handle, target_handle, access,\n\
     206                 inherit[, options]) -> handle\n\
     207\n\
     208Return a duplicate handle object.\n\
     209\n\
     210The duplicate handle refers to the same object as the original\n\
     211handle. Therefore, any changes to the object are reflected\n\
     212through both handles.");
    190213
    191214static PyObject *
    192215sp_DuplicateHandle(PyObject* self, PyObject* args)
    193216{
    194         HANDLE target_handle;
    195         BOOL result;
    196 
    197         HANDLE source_process_handle;
    198         HANDLE source_handle;
    199         HANDLE target_process_handle;
    200         int desired_access;
    201         int inherit_handle;
    202         int options = 0;
    203 
    204         if (! PyArg_ParseTuple(args,
    205                                PY_HANDLE_PARAM PY_HANDLE_PARAM PY_HANDLE_PARAM
    206                                "ii|i:DuplicateHandle",
    207                                &source_process_handle,
    208                                &source_handle,
    209                                &target_process_handle,
    210                                &desired_access,
    211                                &inherit_handle,
    212                                &options))
    213                 return NULL;
    214 
    215         Py_BEGIN_ALLOW_THREADS
    216         result = DuplicateHandle(
    217                 source_process_handle,
    218                 source_handle,
    219                 target_process_handle,
    220                 &target_handle,
    221                 desired_access,
    222                 inherit_handle,
    223                 options
    224         );
    225         Py_END_ALLOW_THREADS
    226 
    227         if (! result)
    228                 return PyErr_SetFromWindowsErr(GetLastError());
    229 
    230         return sp_handle_new(target_handle);
    231 }
     217    HANDLE target_handle;
     218    BOOL result;
     219
     220    HANDLE source_process_handle;
     221    HANDLE source_handle;
     222    HANDLE target_process_handle;
     223    int desired_access;
     224    int inherit_handle;
     225    int options = 0;
     226
     227    if (! PyArg_ParseTuple(args,
     228                           PY_HANDLE_PARAM PY_HANDLE_PARAM PY_HANDLE_PARAM
     229                           "ii|i:DuplicateHandle",
     230                           &source_process_handle,
     231                           &source_handle,
     232                           &target_process_handle,
     233                           &desired_access,
     234                           &inherit_handle,
     235                           &options))
     236        return NULL;
     237
     238    Py_BEGIN_ALLOW_THREADS
     239    result = DuplicateHandle(
     240        source_process_handle,
     241        source_handle,
     242        target_process_handle,
     243        &target_handle,
     244        desired_access,
     245        inherit_handle,
     246        options
     247    );
     248    Py_END_ALLOW_THREADS
     249
     250    if (! result)
     251        return PyErr_SetFromWindowsErr(GetLastError());
     252
     253    return sp_handle_new(target_handle);
     254}
     255
     256PyDoc_STRVAR(CreatePipe_doc,
     257"CreatePipe(pipe_attrs, size) -> (read_handle, write_handle)\n\
     258\n\
     259Create an anonymous pipe, and return handles to the read and\n\
     260write ends of the pipe.\n\
     261\n\
     262pipe_attrs is ignored internally and can be None.");
    232263
    233264static PyObject *
    234265sp_CreatePipe(PyObject* self, PyObject* args)
    235266{
    236         HANDLE read_pipe;
    237         HANDLE write_pipe;
    238         BOOL result;
    239 
    240         PyObject* pipe_attributes; /* ignored */
    241         int size;
    242 
    243         if (! PyArg_ParseTuple(args, "Oi:CreatePipe", &pipe_attributes, &size))
    244                 return NULL;
    245 
    246         Py_BEGIN_ALLOW_THREADS
    247         result = CreatePipe(&read_pipe, &write_pipe, NULL, size);
    248         Py_END_ALLOW_THREADS
    249 
    250         if (! result)
    251                 return PyErr_SetFromWindowsErr(GetLastError());
    252 
    253         return Py_BuildValue(
    254                 "NN", sp_handle_new(read_pipe), sp_handle_new(write_pipe));
     267    HANDLE read_pipe;
     268    HANDLE write_pipe;
     269    BOOL result;
     270
     271    PyObject* pipe_attributes; /* ignored */
     272    int size;
     273
     274    if (! PyArg_ParseTuple(args, "Oi:CreatePipe", &pipe_attributes, &size))
     275        return NULL;
     276
     277    Py_BEGIN_ALLOW_THREADS
     278    result = CreatePipe(&read_pipe, &write_pipe, NULL, size);
     279    Py_END_ALLOW_THREADS
     280
     281    if (! result)
     282        return PyErr_SetFromWindowsErr(GetLastError());
     283
     284    return Py_BuildValue(
     285        "NN", sp_handle_new(read_pipe), sp_handle_new(write_pipe));
    255286}
    256287
     
    260291getint(PyObject* obj, char* name)
    261292{
    262         PyObject* value;
    263         int ret;
    264 
    265         value = PyObject_GetAttrString(obj, name);
    266         if (! value) {
    267                 PyErr_Clear(); /* FIXME: propagate error? */
    268                 return 0;
    269         }
    270         ret = (int) PyInt_AsLong(value);
    271         Py_DECREF(value);
    272         return ret;
     293    PyObject* value;
     294    int ret;
     295
     296    value = PyObject_GetAttrString(obj, name);
     297    if (! value) {
     298        PyErr_Clear(); /* FIXME: propagate error? */
     299        return 0;
     300    }
     301    ret = (int) PyInt_AsLong(value);
     302    Py_DECREF(value);
     303    return ret;
    273304}
    274305
     
    276307gethandle(PyObject* obj, char* name)
    277308{
    278         sp_handle_object* value;
    279         HANDLE ret;
    280 
    281         value = (sp_handle_object*) PyObject_GetAttrString(obj, name);
    282         if (! value) {
    283                 PyErr_Clear(); /* FIXME: propagate error? */
    284                 return NULL;
    285         }
    286         if (value->ob_type != &sp_handle_type)
    287                 ret = NULL;
    288         else
    289                 ret = value->handle;
    290         Py_DECREF(value);
    291         return ret;
     309    sp_handle_object* value;
     310    HANDLE ret;
     311
     312    value = (sp_handle_object*) PyObject_GetAttrString(obj, name);
     313    if (! value) {
     314        PyErr_Clear(); /* FIXME: propagate error? */
     315        return NULL;
     316    }
     317    if (value->ob_type != &sp_handle_type)
     318        ret = NULL;
     319    else
     320        ret = value->handle;
     321    Py_DECREF(value);
     322    return ret;
    292323}
    293324
     
    295326getenvironment(PyObject* environment)
    296327{
    297         int i, envsize;
    298         PyObject* out = NULL;
    299         PyObject* keys;
    300         PyObject* values;
    301         char* p;
    302 
    303         /* convert environment dictionary to windows enviroment string */
    304         if (! PyMapping_Check(environment)) {
    305                 PyErr_SetString(
    306                     PyExc_TypeError, "environment must be dictionary or None");
    307                 return NULL;
    308         }
    309 
    310         envsize = PyMapping_Length(environment);
    311 
    312         keys = PyMapping_Keys(environment);
    313         values = PyMapping_Values(environment);
    314         if (!keys || !values)
    315                 goto error;
    316 
    317         out = PyString_FromStringAndSize(NULL, 2048);
    318         if (! out)
    319                 goto error;
    320 
    321         p = PyString_AS_STRING(out);
    322 
    323         for (i = 0; i < envsize; i++) {
    324                 int ksize, vsize, totalsize;
    325                 PyObject* key = PyList_GET_ITEM(keys, i);
    326                 PyObject* value = PyList_GET_ITEM(values, i);
    327 
    328                 if (! PyString_Check(key) || ! PyString_Check(value)) {
    329                         PyErr_SetString(PyExc_TypeError,
    330                                 "environment can only contain strings");
    331                         goto error;
    332                 }
    333                 ksize = PyString_GET_SIZE(key);
    334                 vsize = PyString_GET_SIZE(value);
    335                 totalsize = (p - PyString_AS_STRING(out)) + ksize + 1 +
    336                                                              vsize + 1 + 1;
    337                 if (totalsize > PyString_GET_SIZE(out)) {
    338                         int offset = p - PyString_AS_STRING(out);
    339                         _PyString_Resize(&out, totalsize + 1024);
    340                         p = PyString_AS_STRING(out) + offset;
    341                 }
    342                 memcpy(p, PyString_AS_STRING(key), ksize);
    343                 p += ksize;
    344                 *p++ = '=';
    345                 memcpy(p, PyString_AS_STRING(value), vsize);
    346                 p += vsize;
    347                 *p++ = '\0';
    348         }
    349 
    350         /* add trailing null byte */
    351         *p++ = '\0';
    352         _PyString_Resize(&out, p - PyString_AS_STRING(out));
    353 
    354         /* PyObject_Print(out, stdout, 0); */
    355 
    356         Py_XDECREF(keys);
    357         Py_XDECREF(values);
    358 
    359         return out;
     328    int i, envsize;
     329    PyObject* out = NULL;
     330    PyObject* keys;
     331    PyObject* values;
     332    char* p;
     333
     334    /* convert environment dictionary to windows environment string */
     335    if (! PyMapping_Check(environment)) {
     336        PyErr_SetString(
     337            PyExc_TypeError, "environment must be dictionary or None");
     338        return NULL;
     339    }
     340
     341    envsize = PyMapping_Length(environment);
     342
     343    keys = PyMapping_Keys(environment);
     344    values = PyMapping_Values(environment);
     345    if (!keys || !values)
     346        goto error;
     347
     348    out = PyString_FromStringAndSize(NULL, 2048);
     349    if (! out)
     350        goto error;
     351
     352    p = PyString_AS_STRING(out);
     353
     354    for (i = 0; i < envsize; i++) {
     355        int ksize, vsize, totalsize;
     356        PyObject* key = PyList_GET_ITEM(keys, i);
     357        PyObject* value = PyList_GET_ITEM(values, i);
     358
     359        if (! PyString_Check(key) || ! PyString_Check(value)) {
     360            PyErr_SetString(PyExc_TypeError,
     361                "environment can only contain strings");
     362            goto error;
     363        }
     364        ksize = PyString_GET_SIZE(key);
     365        vsize = PyString_GET_SIZE(value);
     366        totalsize = (p - PyString_AS_STRING(out)) + ksize + 1 +
     367                                                     vsize + 1 + 1;
     368        if (totalsize > PyString_GET_SIZE(out)) {
     369            int offset = p - PyString_AS_STRING(out);
     370            _PyString_Resize(&out, totalsize + 1024);
     371            p = PyString_AS_STRING(out) + offset;
     372        }
     373        memcpy(p, PyString_AS_STRING(key), ksize);
     374        p += ksize;
     375        *p++ = '=';
     376        memcpy(p, PyString_AS_STRING(value), vsize);
     377        p += vsize;
     378        *p++ = '\0';
     379    }
     380
     381    /* add trailing null byte */
     382    *p++ = '\0';
     383    _PyString_Resize(&out, p - PyString_AS_STRING(out));
     384
     385    /* PyObject_Print(out, stdout, 0); */
     386
     387    Py_XDECREF(keys);
     388    Py_XDECREF(values);
     389
     390    return out;
    360391
    361392 error:
    362         Py_XDECREF(out);
    363         Py_XDECREF(keys);
    364         Py_XDECREF(values);
    365         return NULL;
    366 }
     393    Py_XDECREF(out);
     394    Py_XDECREF(keys);
     395    Py_XDECREF(values);
     396    return NULL;
     397}
     398
     399PyDoc_STRVAR(CreateProcess_doc,
     400"CreateProcess(app_name, cmd_line, proc_attrs, thread_attrs,\n\
     401               inherit, flags, env_mapping, curdir,\n\
     402               startup_info) -> (proc_handle, thread_handle,\n\
     403                                 pid, tid)\n\
     404\n\
     405Create a new process and its primary thread. The return\n\
     406value is a tuple of the process handle, thread handle,\n\
     407process ID, and thread ID.\n\
     408\n\
     409proc_attrs and thread_attrs are ignored internally and can be None.");
    367410
    368411static PyObject *
    369412sp_CreateProcess(PyObject* self, PyObject* args)
    370413{
    371         BOOL result;
    372         PROCESS_INFORMATION pi;
    373         STARTUPINFO si;
    374         PyObject* environment;
    375 
    376         char* application_name;
    377         char* command_line;
    378         PyObject* process_attributes; /* ignored */
    379         PyObject* thread_attributes; /* ignored */
    380         int inherit_handles;
    381         int creation_flags;
    382         PyObject* env_mapping;
    383         char* current_directory;
    384         PyObject* startup_info;
    385 
    386         if (! PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess",
    387                                &application_name,
    388                                &command_line,
    389                                &process_attributes,
    390                                &thread_attributes,
    391                                &inherit_handles,
    392                                &creation_flags,
    393                                &env_mapping,
    394                                &current_directory,
    395                                &startup_info))
    396                 return NULL;
    397 
    398         ZeroMemory(&si, sizeof(si));
    399         si.cb = sizeof(si);
    400 
    401         /* note: we only support a small subset of all SI attributes */
    402         si.dwFlags = getint(startup_info, "dwFlags");
    403         si.wShowWindow = getint(startup_info, "wShowWindow");
    404         si.hStdInput = gethandle(startup_info, "hStdInput");
    405         si.hStdOutput = gethandle(startup_info, "hStdOutput");
    406         si.hStdError = gethandle(startup_info, "hStdError");
    407 
    408         if (PyErr_Occurred())
    409                 return NULL;
    410 
    411         if (env_mapping == Py_None)
    412                 environment = NULL;
    413         else {
    414                 environment = getenvironment(env_mapping);
    415                 if (! environment)
    416                         return NULL;
    417         }
    418 
    419         Py_BEGIN_ALLOW_THREADS
    420         result = CreateProcess(application_name,
    421                                command_line,
    422                                NULL,
    423                                NULL,
    424                                inherit_handles,
    425                                creation_flags,
    426                                environment ? PyString_AS_STRING(environment) : NULL,
    427                                current_directory,
    428                                &si,
    429                                &pi);
    430         Py_END_ALLOW_THREADS
    431 
    432         Py_XDECREF(environment);
    433 
    434         if (! result)
    435                 return PyErr_SetFromWindowsErr(GetLastError());
    436 
    437         return Py_BuildValue("NNii",
    438                              sp_handle_new(pi.hProcess),
    439                              sp_handle_new(pi.hThread),
    440                              pi.dwProcessId,
    441                              pi.dwThreadId);
    442 }
     414    BOOL result;
     415    PROCESS_INFORMATION pi;
     416    STARTUPINFO si;
     417    PyObject* environment;
     418
     419    char* application_name;
     420    char* command_line;
     421    PyObject* process_attributes; /* ignored */
     422    PyObject* thread_attributes; /* ignored */
     423    int inherit_handles;
     424    int creation_flags;
     425    PyObject* env_mapping;
     426    char* current_directory;
     427    PyObject* startup_info;
     428
     429    if (! PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess",
     430                           &application_name,
     431                           &command_line,
     432                           &process_attributes,
     433                           &thread_attributes,
     434                           &inherit_handles,
     435                           &creation_flags,
     436                           &env_mapping,
     437                           &current_directory,
     438                           &startup_info))
     439        return NULL;
     440
     441    ZeroMemory(&si, sizeof(si));
     442    si.cb = sizeof(si);
     443
     444    /* note: we only support a small subset of all SI attributes */
     445    si.dwFlags = getint(startup_info, "dwFlags");
     446    si.wShowWindow = getint(startup_info, "wShowWindow");
     447    si.hStdInput = gethandle(startup_info, "hStdInput");
     448    si.hStdOutput = gethandle(startup_info, "hStdOutput");
     449    si.hStdError = gethandle(startup_info, "hStdError");
     450
     451    if (PyErr_Occurred())
     452        return NULL;
     453
     454    if (env_mapping == Py_None)
     455        environment = NULL;
     456    else {
     457        environment = getenvironment(env_mapping);
     458        if (! environment)
     459            return NULL;
     460    }
     461
     462    Py_BEGIN_ALLOW_THREADS
     463    result = CreateProcess(application_name,
     464                           command_line,
     465                           NULL,
     466                           NULL,
     467                           inherit_handles,
     468                           creation_flags,
     469                           environment ? PyString_AS_STRING(environment) : NULL,
     470                           current_directory,
     471                           &si,
     472                           &pi);
     473    Py_END_ALLOW_THREADS
     474
     475    Py_XDECREF(environment);
     476
     477    if (! result)
     478        return PyErr_SetFromWindowsErr(GetLastError());
     479
     480    return Py_BuildValue("NNii",
     481                         sp_handle_new(pi.hProcess),
     482                         sp_handle_new(pi.hThread),
     483                         pi.dwProcessId,
     484                         pi.dwThreadId);
     485}
     486
     487PyDoc_STRVAR(TerminateProcess_doc,
     488"TerminateProcess(handle, exit_code) -> None\n\
     489\n\
     490Terminate the specified process and all of its threads.");
    443491
    444492static PyObject *
    445493sp_TerminateProcess(PyObject* self, PyObject* args)
    446494{
    447         BOOL result;
    448 
    449         HANDLE process;
    450         int exit_code;
    451         if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM "i:TerminateProcess",
    452                                &process, &exit_code))
    453                 return NULL;
    454 
    455         result = TerminateProcess(process, exit_code);
    456 
    457         if (! result)
    458                 return PyErr_SetFromWindowsErr(GetLastError());
    459 
    460         Py_INCREF(Py_None);
    461         return Py_None;
    462 }
     495    BOOL result;
     496
     497    HANDLE process;
     498    int exit_code;
     499    if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM "i:TerminateProcess",
     500                           &process, &exit_code))
     501        return NULL;
     502
     503    result = TerminateProcess(process, exit_code);
     504
     505    if (! result)
     506        return PyErr_SetFromWindowsErr(GetLastError());
     507
     508    Py_INCREF(Py_None);
     509    return Py_None;
     510}
     511
     512PyDoc_STRVAR(GetExitCodeProcess_doc,
     513"GetExitCodeProcess(handle) -> Exit code\n\
     514\n\
     515Return the termination status of the specified process.");
    463516
    464517static PyObject *
    465518sp_GetExitCodeProcess(PyObject* self, PyObject* args)
    466519{
    467         DWORD exit_code;
    468         BOOL result;
    469 
    470         HANDLE process;
    471         if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM ":GetExitCodeProcess", &process))
    472                 return NULL;
    473 
    474         result = GetExitCodeProcess(process, &exit_code);
    475 
    476         if (! result)
    477                 return PyErr_SetFromWindowsErr(GetLastError());
    478 
    479         return PyInt_FromLong(exit_code);
    480 }
     520    DWORD exit_code;
     521    BOOL result;
     522
     523    HANDLE process;
     524    if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM ":GetExitCodeProcess", &process))
     525        return NULL;
     526
     527    result = GetExitCodeProcess(process, &exit_code);
     528
     529    if (! result)
     530        return PyErr_SetFromWindowsErr(GetLastError());
     531
     532    return PyInt_FromLong(exit_code);
     533}
     534
     535PyDoc_STRVAR(WaitForSingleObject_doc,
     536"WaitForSingleObject(handle, timeout) -> result\n\
     537\n\
     538Wait until the specified object is in the signaled state or\n\
     539the time-out interval elapses. The timeout value is specified\n\
     540in milliseconds.");
    481541
    482542static PyObject *
    483543sp_WaitForSingleObject(PyObject* self, PyObject* args)
    484544{
    485         DWORD result;
    486 
    487         HANDLE handle;
    488         int milliseconds;
    489         if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM "i:WaitForSingleObject",
    490                                      &handle,
    491                                      &milliseconds))
    492                 return NULL;
    493 
    494         Py_BEGIN_ALLOW_THREADS
    495         result = WaitForSingleObject(handle, (DWORD) milliseconds);
    496         Py_END_ALLOW_THREADS
    497 
    498         if (result == WAIT_FAILED)
    499                 return PyErr_SetFromWindowsErr(GetLastError());
    500 
    501         return PyInt_FromLong((int) result);
    502 }
     545    DWORD result;
     546
     547    HANDLE handle;
     548    int milliseconds;
     549    if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM "i:WaitForSingleObject",
     550                                 &handle,
     551                                 &milliseconds))
     552        return NULL;
     553
     554    Py_BEGIN_ALLOW_THREADS
     555    result = WaitForSingleObject(handle, (DWORD) milliseconds);
     556    Py_END_ALLOW_THREADS
     557
     558    if (result == WAIT_FAILED)
     559        return PyErr_SetFromWindowsErr(GetLastError());
     560
     561    return PyInt_FromLong((int) result);
     562}
     563
     564PyDoc_STRVAR(GetVersion_doc,
     565"GetVersion() -> version\n\
     566\n\
     567Return the version number of the current operating system.");
    503568
    504569static PyObject *
    505570sp_GetVersion(PyObject* self, PyObject* args)
    506571{
    507         if (! PyArg_ParseTuple(args, ":GetVersion"))
    508                 return NULL;
    509 
    510         return PyInt_FromLong((int) GetVersion());
    511 }
     572    if (! PyArg_ParseTuple(args, ":GetVersion"))
     573        return NULL;
     574
     575    return PyInt_FromLong((int) GetVersion());
     576}
     577
     578PyDoc_STRVAR(GetModuleFileName_doc,
     579"GetModuleFileName(module) -> path\n\
     580\n\
     581Return the fully-qualified path for the file that contains\n\
     582the specified module. The module must have been loaded by the\n\
     583current process.\n\
     584\n\
     585The module parameter should be a handle to the loaded module\n\
     586whose path is being requested. If this parameter is 0, \n\
     587GetModuleFileName retrieves the path of the executable file\n\
     588of the current process.");
    512589
    513590static PyObject *
    514591sp_GetModuleFileName(PyObject* self, PyObject* args)
    515592{
    516         BOOL result;
    517         HMODULE module;
    518         TCHAR filename[MAX_PATH];
    519 
    520         if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM ":GetModuleFileName",
    521                                &module))
    522                 return NULL;
    523 
    524         result = GetModuleFileName(module, filename, MAX_PATH);
    525         filename[MAX_PATH-1] = '\0';
    526 
    527         if (! result)
    528                 return PyErr_SetFromWindowsErr(GetLastError());
    529 
    530         return PyString_FromString(filename);
     593    BOOL result;
     594    HMODULE module;
     595    TCHAR filename[MAX_PATH];
     596
     597    if (! PyArg_ParseTuple(args, PY_HANDLE_PARAM ":GetModuleFileName",
     598                           &module))
     599        return NULL;
     600
     601    result = GetModuleFileName(module, filename, MAX_PATH);
     602    filename[MAX_PATH-1] = '\0';
     603
     604    if (! result)
     605        return PyErr_SetFromWindowsErr(GetLastError());
     606
     607    return PyString_FromString(filename);
    531608}
    532609
    533610static PyMethodDef sp_functions[] = {
    534         {"GetStdHandle",        sp_GetStdHandle,        METH_VARARGS},
    535         {"GetCurrentProcess",   sp_GetCurrentProcess,   METH_VARARGS},
    536         {"DuplicateHandle",     sp_DuplicateHandle,     METH_VARARGS},
    537         {"CreatePipe",          sp_CreatePipe,          METH_VARARGS},
    538         {"CreateProcess",       sp_CreateProcess,       METH_VARARGS},
    539         {"TerminateProcess",    sp_TerminateProcess,    METH_VARARGS},
    540         {"GetExitCodeProcess",  sp_GetExitCodeProcess,  METH_VARARGS},
    541         {"WaitForSingleObject", sp_WaitForSingleObject, METH_VARARGS},
    542         {"GetVersion",          sp_GetVersion,          METH_VARARGS},
    543         {"GetModuleFileName",   sp_GetModuleFileName,   METH_VARARGS},
    544         {NULL, NULL}
     611    {"GetStdHandle", sp_GetStdHandle, METH_VARARGS, GetStdHandle_doc},
     612    {"GetCurrentProcess", sp_GetCurrentProcess,         METH_VARARGS,
     613                                              GetCurrentProcess_doc},
     614    {"DuplicateHandle",         sp_DuplicateHandle,     METH_VARARGS,
     615                                            DuplicateHandle_doc},
     616    {"CreatePipe", sp_CreatePipe, METH_VARARGS, CreatePipe_doc},
     617    {"CreateProcess", sp_CreateProcess, METH_VARARGS, CreateProcess_doc},
     618    {"TerminateProcess", sp_TerminateProcess, METH_VARARGS,
     619                                             TerminateProcess_doc},
     620    {"GetExitCodeProcess", sp_GetExitCodeProcess, METH_VARARGS,
     621                                               GetExitCodeProcess_doc},
     622    {"WaitForSingleObject", sp_WaitForSingleObject, METH_VARARGS,
     623                                                    WaitForSingleObject_doc},
     624    {"GetVersion", sp_GetVersion, METH_VARARGS, GetVersion_doc},
     625    {"GetModuleFileName", sp_GetModuleFileName, METH_VARARGS,
     626                                              GetModuleFileName_doc},
     627    {NULL, NULL}
    545628};
    546629
     
    550633defint(PyObject* d, const char* name, int value)
    551634{
    552         PyObject* v = PyInt_FromLong((long) value);
    553         if (v) {
    554                 PyDict_SetItemString(d, (char*) name, v);
    555                 Py_DECREF(v);
    556         }
     635    PyObject* v = PyInt_FromLong((long) value);
     636    if (v) {
     637        PyDict_SetItemString(d, (char*) name, v);
     638        Py_DECREF(v);
     639    }
    557640}
    558641
     
    564647init_subprocess()
    565648{
    566         PyObject *d;
    567         PyObject *m;
    568 
    569         /* patch up object descriptors */
    570         sp_handle_type.ob_type = &PyType_Type;
    571         sp_handle_as_number.nb_int = (unaryfunc) sp_handle_as_int;
    572 
    573         m = Py_InitModule("_subprocess", sp_functions);
    574         if (m == NULL)
    575                 return;
    576         d = PyModule_GetDict(m);
    577 
    578         /* constants */
    579         defint(d, "STD_INPUT_HANDLE", STD_INPUT_HANDLE);
    580         defint(d, "STD_OUTPUT_HANDLE", STD_OUTPUT_HANDLE);
    581         defint(d, "STD_ERROR_HANDLE", STD_ERROR_HANDLE);
    582         defint(d, "DUPLICATE_SAME_ACCESS", DUPLICATE_SAME_ACCESS);
    583         defint(d, "STARTF_USESTDHANDLES", STARTF_USESTDHANDLES);
    584         defint(d, "STARTF_USESHOWWINDOW", STARTF_USESHOWWINDOW);
    585         defint(d, "SW_HIDE", SW_HIDE);
    586         defint(d, "INFINITE", INFINITE);
    587         defint(d, "WAIT_OBJECT_0", WAIT_OBJECT_0);
    588         defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE);
    589 }
     649    PyObject *d;
     650    PyObject *m;
     651
     652    /* patch up object descriptors */
     653    sp_handle_type.ob_type = &PyType_Type;
     654    sp_handle_as_number.nb_int = (unaryfunc) sp_handle_as_int;
     655
     656    m = Py_InitModule("_subprocess", sp_functions);
     657    if (m == NULL)
     658        return;
     659    d = PyModule_GetDict(m);
     660
     661    /* constants */
     662    defint(d, "STD_INPUT_HANDLE", STD_INPUT_HANDLE);
     663    defint(d, "STD_OUTPUT_HANDLE", STD_OUTPUT_HANDLE);
     664    defint(d, "STD_ERROR_HANDLE", STD_ERROR_HANDLE);
     665    defint(d, "DUPLICATE_SAME_ACCESS", DUPLICATE_SAME_ACCESS);
     666    defint(d, "STARTF_USESTDHANDLES", STARTF_USESTDHANDLES);
     667    defint(d, "STARTF_USESHOWWINDOW", STARTF_USESHOWWINDOW);
     668    defint(d, "SW_HIDE", SW_HIDE);
     669    defint(d, "INFINITE", INFINITE);
     670    defint(d, "WAIT_OBJECT_0", WAIT_OBJECT_0);
     671    defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE);
     672    defint(d, "CREATE_NEW_PROCESS_GROUP", CREATE_NEW_PROCESS_GROUP);
     673    defint(d, "STILL_ACTIVE", STILL_ACTIVE);
     674}
  • python/vendor/current/PC/_winreg.c

    r2 r388  
    55
    66  * Simple registry access written by Mark Hammond in win32api
    7         module circa 1995.
     7    module circa 1995.
    88  * Bill Tutt expanded the support significantly not long after.
    99  * Numerous other people have submitted patches since then.
     
    3030*/
    3131#define PyErr_SetFromWindowsErrWithFunction(rc, fnname) \
    32         PyErr_SetFromWindowsErr(rc)
     32    PyErr_SetFromWindowsErr(rc)
    3333
    3434/* Forward declares */
     
    9090"\n"
    9191"The return value is the handle of the opened key.\n"
    92 "If the function fails, an EnvironmentError exception is raised.");
     92"If the function fails, a WindowsError exception is raised.");
    9393
    9494PyDoc_STRVAR(CreateKey_doc,
     
    105105"If the function fails, an exception is raised.");
    106106
     107PyDoc_STRVAR(CreateKeyEx_doc,
     108"key = CreateKeyEx(key, sub_key, res, sam) - Creates or opens the specified key.\n"
     109"\n"
     110"key is an already open key, or one of the predefined HKEY_* constants\n"
     111"sub_key is a string that names the key this method opens or creates.\n"
     112"res is a reserved integer, and must be zero.  Default is zero.\n"
     113"sam is an integer that specifies an access mask that describes the desired\n"
     114" If key is one of the predefined keys, sub_key may be None. In that case,\n"
     115" the handle returned is the same key handle passed in to the function.\n"
     116"\n"
     117"If the key already exists, this function opens the existing key\n"
     118"\n"
     119"The return value is the handle of the opened key.\n"
     120"If the function fails, an exception is raised.");
     121
    107122PyDoc_STRVAR(DeleteKey_doc,
    108123"DeleteKey(key, sub_key) - Deletes the specified key.\n"
     
    115130"\n"
    116131"If the method succeeds, the entire key, including all of its values,\n"
    117 "is removed.  If the method fails, an EnvironmentError exception is raised.");
     132"is removed.  If the method fails, a WindowsError exception is raised.");
     133
     134PyDoc_STRVAR(DeleteKeyEx_doc,
     135"DeleteKeyEx(key, sub_key, sam, res) - Deletes the specified key.\n"
     136"\n"
     137"key is an already open key, or any one of the predefined HKEY_* constants.\n"
     138"sub_key is a string that must be a subkey of the key identified by the key parameter.\n"
     139"res is a reserved integer, and must be zero.  Default is zero.\n"
     140"sam is an integer that specifies an access mask that describes the desired\n"
     141" This value must not be None, and the key may not have subkeys.\n"
     142"\n"
     143"This method can not delete keys with subkeys.\n"
     144"\n"
     145"If the method succeeds, the entire key, including all of its values,\n"
     146"is removed.  If the method fails, a WindowsError exception is raised.\n"
     147"On unsupported Windows versions, NotImplementedError is raised.");
    118148
    119149PyDoc_STRVAR(DeleteValue_doc,
     
    130160"\n"
    131161"The function retrieves the name of one subkey each time it is called.\n"
    132 "It is typically called repeatedly until an EnvironmentError exception is\n"
     162"It is typically called repeatedly until a WindowsError exception is\n"
    133163"raised, indicating no more values are available.");
    134164
     
    139169"\n"
    140170"The function retrieves the name of one subkey each time it is called.\n"
    141 "It is typically called repeatedly, until an EnvironmentError exception\n"
     171"It is typically called repeatedly, until a WindowsError exception\n"
    142172"is raised, indicating no more values.\n"
    143173"\n"
     
    193223"\n"
    194224"The result is a new handle to the specified key\n"
    195 "If the function fails, an EnvironmentError exception is raised.");
     225"If the function fails, a WindowsError exception is raised.");
    196226
    197227PyDoc_STRVAR(OpenKeyEx_doc, "See OpenKey()");
     
    355385************************************************************************/
    356386typedef struct {
    357         PyObject_VAR_HEAD
    358         HKEY hkey;
     387    PyObject_VAR_HEAD
     388    HKEY hkey;
    359389} PyHKEYObject;
    360390
     
    366396PyHKEY_unaryFailureFunc(PyObject *ob)
    367397{
    368         PyErr_SetString(PyExc_TypeError, failMsg);
    369         return NULL;
     398    PyErr_SetString(PyExc_TypeError, failMsg);
     399    return NULL;
    370400}
    371401static PyObject *
    372402PyHKEY_binaryFailureFunc(PyObject *ob1, PyObject *ob2)
    373403{
    374         PyErr_SetString(PyExc_TypeError, failMsg);
    375         return NULL;
     404    PyErr_SetString(PyExc_TypeError, failMsg);
     405    return NULL;
    376406}
    377407static PyObject *
    378408PyHKEY_ternaryFailureFunc(PyObject *ob1, PyObject *ob2, PyObject *ob3)
    379409{
    380         PyErr_SetString(PyExc_TypeError, failMsg);
    381         return NULL;
     410    PyErr_SetString(PyExc_TypeError, failMsg);
     411    return NULL;
    382412}
    383413
     
    385415PyHKEY_deallocFunc(PyObject *ob)
    386416{
    387         /* Can not call PyHKEY_Close, as the ob->tp_type
    388            has already been cleared, thus causing the type
    389            check to fail!
    390         */
    391         PyHKEYObject *obkey = (PyHKEYObject *)ob;
    392         if (obkey->hkey)
    393                 RegCloseKey((HKEY)obkey->hkey);
    394         PyObject_DEL(ob);
     417    /* Can not call PyHKEY_Close, as the ob->tp_type
     418       has already been cleared, thus causing the type
     419       check to fail!
     420    */
     421    PyHKEYObject *obkey = (PyHKEYObject *)ob;
     422    if (obkey->hkey)
     423        RegCloseKey((HKEY)obkey->hkey);
     424    PyObject_DEL(ob);
    395425}
    396426
     
    398428PyHKEY_nonzeroFunc(PyObject *ob)
    399429{
    400         return ((PyHKEYObject *)ob)->hkey != 0;
     430    return ((PyHKEYObject *)ob)->hkey != 0;
    401431}
    402432
     
    404434PyHKEY_intFunc(PyObject *ob)
    405435{
    406         PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
    407         return PyLong_FromVoidPtr(pyhkey->hkey);
     436    PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
     437    return PyLong_FromVoidPtr(pyhkey->hkey);
    408438}
    409439
     
    411441PyHKEY_printFunc(PyObject *ob, FILE *fp, int flags)
    412442{
    413         PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
    414         char resBuf[160];
    415         wsprintf(resBuf, "<PyHKEY at %p (%p)>",
    416                  ob, pyhkey->hkey);
    417         fputs(resBuf, fp);
    418         return 0;
     443    PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
     444    fprintf(fp, "<PyHKEY at %p (%p)>",
     445        ob, pyhkey->hkey);
     446    return 0;
    419447}
    420448
     
    422450PyHKEY_strFunc(PyObject *ob)
    423451{
    424         PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
    425         char resBuf[160];
    426         wsprintf(resBuf, "<PyHKEY:%p>", pyhkey->hkey);
    427         return PyString_FromString(resBuf);
     452    PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
     453    return PyString_FromFormat("<PyHKEY:%p>", pyhkey->hkey);
    428454}
    429455
     
    431457PyHKEY_compareFunc(PyObject *ob1, PyObject *ob2)
    432458{
    433         PyHKEYObject *pyhkey1 = (PyHKEYObject *)ob1;
    434         PyHKEYObject *pyhkey2 = (PyHKEYObject *)ob2;
    435         return pyhkey1 == pyhkey2 ? 0 :
    436                 (pyhkey1 < pyhkey2 ? -1 : 1);
     459    PyHKEYObject *pyhkey1 = (PyHKEYObject *)ob1;
     460    PyHKEYObject *pyhkey2 = (PyHKEYObject *)ob2;
     461    return pyhkey1 == pyhkey2 ? 0 :
     462        (pyhkey1 < pyhkey2 ? -1 : 1);
    437463}
    438464
     
    440466PyHKEY_hashFunc(PyObject *ob)
    441467{
    442         /* Just use the address.
    443            XXX - should we use the handle value?
    444         */
    445         return _Py_HashPointer(ob);
     468    /* Just use the address.
     469       XXX - should we use the handle value?
     470    */
     471    return _Py_HashPointer(ob);
    446472}
    447473
     
    449475static PyNumberMethods PyHKEY_NumberMethods =
    450476{
    451         PyHKEY_binaryFailureFunc,       /* nb_add */
    452         PyHKEY_binaryFailureFunc,       /* nb_subtract */
    453         PyHKEY_binaryFailureFunc,       /* nb_multiply */
    454         PyHKEY_binaryFailureFunc,       /* nb_divide */
    455         PyHKEY_binaryFailureFunc,       /* nb_remainder */
    456         PyHKEY_binaryFailureFunc,       /* nb_divmod */
    457         PyHKEY_ternaryFailureFunc,      /* nb_power */
    458         PyHKEY_unaryFailureFunc,        /* nb_negative */
    459         PyHKEY_unaryFailureFunc,        /* nb_positive */
    460         PyHKEY_unaryFailureFunc,        /* nb_absolute */
    461         PyHKEY_nonzeroFunc,             /* nb_nonzero */
    462         PyHKEY_unaryFailureFunc,        /* nb_invert */
    463         PyHKEY_binaryFailureFunc,       /* nb_lshift */
    464         PyHKEY_binaryFailureFunc,       /* nb_rshift */
    465         PyHKEY_binaryFailureFunc,       /* nb_and */
    466         PyHKEY_binaryFailureFunc,       /* nb_xor */
    467         PyHKEY_binaryFailureFunc,       /* nb_or */
    468         0,              /* nb_coerce (allowed to be zero) */
    469         PyHKEY_intFunc,                 /* nb_int */
    470         PyHKEY_unaryFailureFunc,        /* nb_long */
    471         PyHKEY_unaryFailureFunc,        /* nb_float */
    472         PyHKEY_unaryFailureFunc,        /* nb_oct */
    473         PyHKEY_unaryFailureFunc,        /* nb_hex */
     477    PyHKEY_binaryFailureFunc,           /* nb_add */
     478    PyHKEY_binaryFailureFunc,           /* nb_subtract */
     479    PyHKEY_binaryFailureFunc,           /* nb_multiply */
     480    PyHKEY_binaryFailureFunc,           /* nb_divide */
     481    PyHKEY_binaryFailureFunc,           /* nb_remainder */
     482    PyHKEY_binaryFailureFunc,           /* nb_divmod */
     483    PyHKEY_ternaryFailureFunc,          /* nb_power */
     484    PyHKEY_unaryFailureFunc,            /* nb_negative */
     485    PyHKEY_unaryFailureFunc,            /* nb_positive */
     486    PyHKEY_unaryFailureFunc,            /* nb_absolute */
     487    PyHKEY_nonzeroFunc,                 /* nb_nonzero */
     488    PyHKEY_unaryFailureFunc,            /* nb_invert */
     489    PyHKEY_binaryFailureFunc,           /* nb_lshift */
     490    PyHKEY_binaryFailureFunc,           /* nb_rshift */
     491    PyHKEY_binaryFailureFunc,           /* nb_and */
     492    PyHKEY_binaryFailureFunc,           /* nb_xor */
     493    PyHKEY_binaryFailureFunc,           /* nb_or */
     494    0,                  /* nb_coerce (allowed to be zero) */
     495    PyHKEY_intFunc,                     /* nb_int */
     496    PyHKEY_unaryFailureFunc,            /* nb_long */
     497    PyHKEY_unaryFailureFunc,            /* nb_float */
     498    PyHKEY_unaryFailureFunc,            /* nb_oct */
     499    PyHKEY_unaryFailureFunc,            /* nb_hex */
    474500};
    475501
    476 
    477 /* fwd declare __getattr__ */
    478 static PyObject *PyHKEY_getattr(PyObject *self, const char *name);
     502static PyObject *PyHKEY_CloseMethod(PyObject *self, PyObject *args);
     503static PyObject *PyHKEY_DetachMethod(PyObject *self, PyObject *args);
     504static PyObject *PyHKEY_Enter(PyObject *self);
     505static PyObject *PyHKEY_Exit(PyObject *self, PyObject *args);
     506
     507static struct PyMethodDef PyHKEY_methods[] = {
     508    {"Close",  PyHKEY_CloseMethod, METH_VARARGS, PyHKEY_Close_doc},
     509    {"Detach", PyHKEY_DetachMethod, METH_VARARGS, PyHKEY_Detach_doc},
     510    {"__enter__", (PyCFunction)PyHKEY_Enter, METH_NOARGS, NULL},
     511    {"__exit__", PyHKEY_Exit, METH_VARARGS, NULL},
     512    {NULL}
     513};
     514
     515static PyMemberDef PyHKEY_memberlist[] = {
     516    {"handle", T_PYSSIZET, offsetof(PyHKEYObject, hkey), READONLY},
     517    {NULL}    /* Sentinel */
     518};
    479519
    480520/* The type itself */
    481521PyTypeObject PyHKEY_Type =
    482522{
    483         PyVarObject_HEAD_INIT(0, 0) /* fill in type at module init */
    484         "PyHKEY",
    485         sizeof(PyHKEYObject),
    486         0,
    487         PyHKEY_deallocFunc,             /* tp_dealloc */
    488         PyHKEY_printFunc,               /* tp_print */
    489         PyHKEY_getattr,                 /* tp_getattr */
    490         0,                              /* tp_setattr */
    491         PyHKEY_compareFunc,             /* tp_compare */
    492         0,                              /* tp_repr */
    493         &PyHKEY_NumberMethods,          /* tp_as_number */
    494         0,                              /* tp_as_sequence */
    495         0,                              /* tp_as_mapping */
    496         PyHKEY_hashFunc,                /* tp_hash */
    497         0,                              /* tp_call */
    498         PyHKEY_strFunc,                 /* tp_str */
    499         0,                              /* tp_getattro */
    500         0,                              /* tp_setattro */
    501         0,                              /* tp_as_buffer */
    502         0,                              /* tp_flags */
    503         PyHKEY_doc,                     /* tp_doc */
     523    PyVarObject_HEAD_INIT(0, 0) /* fill in type at module init */
     524    "PyHKEY",
     525    sizeof(PyHKEYObject),
     526    0,
     527    PyHKEY_deallocFunc,                 /* tp_dealloc */
     528    PyHKEY_printFunc,                   /* tp_print */
     529    0,                                  /* tp_getattr */
     530    0,                                  /* tp_setattr */
     531    PyHKEY_compareFunc,                 /* tp_compare */
     532    0,                                  /* tp_repr */
     533    &PyHKEY_NumberMethods,              /* tp_as_number */
     534    0,                                  /* tp_as_sequence */
     535    0,                                  /* tp_as_mapping */
     536    PyHKEY_hashFunc,                    /* tp_hash */
     537    0,                                  /* tp_call */
     538    PyHKEY_strFunc,                     /* tp_str */
     539    0,                                  /* tp_getattro */
     540    0,                                  /* tp_setattro */
     541    0,                                  /* tp_as_buffer */
     542    Py_TPFLAGS_DEFAULT,                 /* tp_flags */
     543    PyHKEY_doc,                         /* tp_doc */
     544    0,                                  /* tp_traverse */
     545    0,                                  /* tp_clear */
     546    0,                                  /* tp_richcompare */
     547    0,                                  /* tp_weaklistoffset */
     548    0,                                  /* tp_iter */
     549    0,                                  /* tp_iternext */
     550    PyHKEY_methods,                     /* tp_methods */
     551    PyHKEY_memberlist,                  /* tp_members */
    504552};
    505553
    506 #define OFF(e) offsetof(PyHKEYObject, e)
    507 
    508 static struct memberlist PyHKEY_memberlist[] = {
    509         {"handle",      T_INT,      OFF(hkey)},
    510         {NULL}    /* Sentinel */
    511 };
    512 
    513554/************************************************************************
    514555
     
    519560PyHKEY_CloseMethod(PyObject *self, PyObject *args)
    520561{
    521         if (!PyArg_ParseTuple(args, ":Close"))
    522                 return NULL;
    523         if (!PyHKEY_Close(self))
    524                 return NULL;
    525         Py_INCREF(Py_None);
    526         return Py_None;
     562    if (!PyArg_ParseTuple(args, ":Close"))
     563        return NULL;
     564    if (!PyHKEY_Close(self))
     565        return NULL;
     566    Py_INCREF(Py_None);
     567    return Py_None;
    527568}
    528569
     
    530571PyHKEY_DetachMethod(PyObject *self, PyObject *args)
    531572{
    532         void* ret;
    533         PyHKEYObject *pThis = (PyHKEYObject *)self;
    534         if (!PyArg_ParseTuple(args, ":Detach"))
    535                 return NULL;
    536         ret = (void*)pThis->hkey;
    537         pThis->hkey = 0;
    538         return PyLong_FromVoidPtr(ret);
     573    void* ret;
     574    PyHKEYObject *pThis = (PyHKEYObject *)self;
     575    if (!PyArg_ParseTuple(args, ":Detach"))
     576        return NULL;
     577    ret = (void*)pThis->hkey;
     578    pThis->hkey = 0;
     579    return PyLong_FromVoidPtr(ret);
    539580}
    540581
     
    542583PyHKEY_Enter(PyObject *self)
    543584{
    544         Py_XINCREF(self);
    545         return self;
     585    Py_XINCREF(self);
     586    return self;
    546587}
    547588
     
    549590PyHKEY_Exit(PyObject *self, PyObject *args)
    550591{
    551         if (!PyHKEY_Close(self))
    552                 return NULL;
    553         Py_RETURN_NONE;
    554 }
    555 
    556 
    557 static struct PyMethodDef PyHKEY_methods[] = {
    558         {"Close",  PyHKEY_CloseMethod, METH_VARARGS, PyHKEY_Close_doc},
    559         {"Detach", PyHKEY_DetachMethod, METH_VARARGS, PyHKEY_Detach_doc},
    560         {"__enter__", (PyCFunction)PyHKEY_Enter, METH_NOARGS, NULL},
    561         {"__exit__", PyHKEY_Exit, METH_VARARGS, NULL},
    562         {NULL}
    563 };
    564 
    565 /*static*/ PyObject *
    566 PyHKEY_getattr(PyObject *self, const char *name)
    567 {
    568         PyObject *res;
    569 
    570         res = Py_FindMethod(PyHKEY_methods, self, name);
    571         if (res != NULL)
    572                 return res;
    573         PyErr_Clear();
    574         if (strcmp(name, "handle") == 0)
    575                 return PyLong_FromVoidPtr(((PyHKEYObject *)self)->hkey);
    576         return PyMember_Get((char *)self, PyHKEY_memberlist, name);
    577 }
     592    if (!PyHKEY_Close(self))
     593        return NULL;
     594    Py_RETURN_NONE;
     595}
     596
    578597
    579598/************************************************************************
     
    583602PyHKEY_New(HKEY hInit)
    584603{
    585         PyHKEYObject *key = PyObject_NEW(PyHKEYObject, &PyHKEY_Type);
    586         if (key)
    587                 key->hkey = hInit;
    588         return (PyObject *)key;
     604    PyHKEYObject *key = PyObject_NEW(PyHKEYObject, &PyHKEY_Type);
     605    if (key)
     606        key->hkey = hInit;
     607    return (PyObject *)key;
    589608}
    590609
     
    592611PyHKEY_Close(PyObject *ob_handle)
    593612{
    594         LONG rc;
    595         PyHKEYObject *key;
    596 
    597         if (!PyHKEY_Check(ob_handle)) {
    598                 PyErr_SetString(PyExc_TypeError, "bad operand type");
    599                 return FALSE;
    600         }
    601         key = (PyHKEYObject *)ob_handle;
    602         rc = key->hkey ? RegCloseKey((HKEY)key->hkey) : ERROR_SUCCESS;
    603         key->hkey = 0;
    604         if (rc != ERROR_SUCCESS)
    605                 PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
    606         return rc == ERROR_SUCCESS;
     613    LONG rc;
     614    PyHKEYObject *key;
     615
     616    if (!PyHKEY_Check(ob_handle)) {
     617        PyErr_SetString(PyExc_TypeError, "bad operand type");
     618        return FALSE;
     619    }
     620    key = (PyHKEYObject *)ob_handle;
     621    rc = key->hkey ? RegCloseKey((HKEY)key->hkey) : ERROR_SUCCESS;
     622    key->hkey = 0;
     623    if (rc != ERROR_SUCCESS)
     624        PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
     625    return rc == ERROR_SUCCESS;
    607626}
    608627
     
    610629PyHKEY_AsHKEY(PyObject *ob, HKEY *pHANDLE, BOOL bNoneOK)
    611630{
    612         if (ob == Py_None) {
    613                 if (!bNoneOK) {
    614                         PyErr_SetString(
    615                                   PyExc_TypeError,
    616                                   "None is not a valid HKEY in this context");
    617                         return FALSE;
    618                 }
    619                 *pHANDLE = (HKEY)0;
    620         }
    621         else if (PyHKEY_Check(ob)) {
    622                 PyHKEYObject *pH = (PyHKEYObject *)ob;
    623                 *pHANDLE = pH->hkey;
    624         }
    625         else if (PyInt_Check(ob) || PyLong_Check(ob)) {
    626                 /* We also support integers */
    627                 PyErr_Clear();
    628                 *pHANDLE = (HKEY)PyLong_AsVoidPtr(ob);
    629                 if (PyErr_Occurred())
    630                         return FALSE;
    631         }
    632         else {
    633                 PyErr_SetString(
    634                                 PyExc_TypeError,
    635                         "The object is not a PyHKEY object");
    636                 return FALSE;
    637         }
    638         return TRUE;
     631    if (ob == Py_None) {
     632        if (!bNoneOK) {
     633            PyErr_SetString(
     634                      PyExc_TypeError,
     635                      "None is not a valid HKEY in this context");
     636            return FALSE;
     637        }
     638        *pHANDLE = (HKEY)0;
     639    }
     640    else if (PyHKEY_Check(ob)) {
     641        PyHKEYObject *pH = (PyHKEYObject *)ob;
     642        *pHANDLE = pH->hkey;
     643    }
     644    else if (PyInt_Check(ob) || PyLong_Check(ob)) {
     645        /* We also support integers */
     646        PyErr_Clear();
     647        *pHANDLE = (HKEY)PyLong_AsVoidPtr(ob);
     648        if (PyErr_Occurred())
     649            return FALSE;
     650    }
     651    else {
     652        PyErr_SetString(
     653                        PyExc_TypeError,
     654            "The object is not a PyHKEY object");
     655        return FALSE;
     656    }
     657    return TRUE;
    639658}
    640659
     
    642661PyHKEY_FromHKEY(HKEY h)
    643662{
    644         PyHKEYObject *op;
    645 
    646         /* Inline PyObject_New */
    647         op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject));
    648         if (op == NULL)
    649                 return PyErr_NoMemory();
    650         PyObject_INIT(op, &PyHKEY_Type);
    651         op->hkey = h;
    652         return (PyObject *)op;
     663    PyHKEYObject *op;
     664
     665    /* Inline PyObject_New */
     666    op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject));
     667    if (op == NULL)
     668        return PyErr_NoMemory();
     669    PyObject_INIT(op, &PyHKEY_Type);
     670    op->hkey = h;
     671    return (PyObject *)op;
    653672}
    654673
     
    660679PyWinObject_CloseHKEY(PyObject *obHandle)
    661680{
    662         BOOL ok;
    663         if (PyHKEY_Check(obHandle)) {
    664                 ok = PyHKEY_Close(obHandle);
    665         }
     681    BOOL ok;
     682    if (PyHKEY_Check(obHandle)) {
     683        ok = PyHKEY_Close(obHandle);
     684    }
    666685#if SIZEOF_LONG >= SIZEOF_HKEY
    667         else if (PyInt_Check(obHandle)) {
    668                 long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle));
    669                 ok = (rc == ERROR_SUCCESS);
    670                 if (!ok)
    671                         PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
    672         }
     686    else if (PyInt_Check(obHandle)) {
     687        long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle));
     688        ok = (rc == ERROR_SUCCESS);
     689        if (!ok)
     690            PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
     691    }
    673692#else
    674         else if (PyLong_Check(obHandle)) {
    675                 long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle));
    676                 ok = (rc == ERROR_SUCCESS);
    677                 if (!ok)
    678                         PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
    679         }
     693    else if (PyLong_Check(obHandle)) {
     694        long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle));
     695        ok = (rc == ERROR_SUCCESS);
     696        if (!ok)
     697            PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
     698    }
    680699#endif
    681         else {
    682                 PyErr_SetString(
    683                         PyExc_TypeError,
    684                         "A handle must be a HKEY object or an integer");
    685                 return FALSE;
    686         }
    687         return ok;
     700    else {
     701        PyErr_SetString(
     702            PyExc_TypeError,
     703            "A handle must be a HKEY object or an integer");
     704        return FALSE;
     705    }
     706    return ok;
    688707}
    689708
     
    702721fixupMultiSZ(char **str, char *data, int len)
    703722{
    704         char *P;
    705         int i;
    706         char *Q;
    707 
    708         Q = data + len;
    709         for (P = data, i = 0; P < Q && *P != '\0'; P++, i++) {
    710                 str[i] = P;
    711                 for(; *P != '\0'; P++)
    712                         ;
    713         }
     723    char *P;
     724    int i;
     725    char *Q;
     726
     727    Q = data + len;
     728    for (P = data, i = 0; P < Q && *P != '\0'; P++, i++) {
     729        str[i] = P;
     730        for(; *P != '\0'; P++)
     731            ;
     732    }
    714733}
    715734
     
    717736countStrings(char *data, int len)
    718737{
    719         int strings;
    720         char *P;
    721         char *Q = data + len;
    722 
    723         for (P = data, strings = 0; P < Q && *P != '\0'; P++, strings++)
    724                 for (; P < Q && *P != '\0'; P++)
    725                         ;
    726         return strings;
     738    int strings;
     739    char *P;
     740    char *Q = data + len;
     741
     742    for (P = data, strings = 0; P < Q && *P != '\0'; P++, strings++)
     743        for (; P < Q && *P != '\0'; P++)
     744            ;
     745    return strings;
    727746}
    728747
     
    732751Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
    733752{
    734         Py_ssize_t i,j;
    735         switch (typ) {
    736                 case REG_DWORD:
    737                         if (value != Py_None && !PyInt_Check(value))
    738                                 return FALSE;
    739                         *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1);
    740                         if (*retDataBuf==NULL){
    741                                 PyErr_NoMemory();
    742                                 return FALSE;
    743                         }
    744                         *retDataSize = sizeof(DWORD);
    745                         if (value == Py_None) {
    746                                 DWORD zero = 0;
    747                                 memcpy(*retDataBuf, &zero, sizeof(DWORD));
    748                         }
    749                         else
    750                                 memcpy(*retDataBuf,
    751                                        &PyInt_AS_LONG((PyIntObject *)value),
    752                                        sizeof(DWORD));
    753                         break;
    754                 case REG_SZ:
    755                 case REG_EXPAND_SZ:
    756                         {
    757                         int need_decref = 0;
    758                         if (value == Py_None)
    759                                 *retDataSize = 1;
    760                         else {
    761                                 if (PyUnicode_Check(value)) {
    762                                         value = PyUnicode_AsEncodedString(
    763                                                       value,
    764                                                       "mbcs",
    765                                                       NULL);
    766                                         if (value==NULL)
    767                                                 return FALSE;
    768                                         need_decref = 1;
    769                                 }
    770                                 if (!PyString_Check(value))
    771                                         return FALSE;
    772                                 *retDataSize = 1 + strlen(
    773                                         PyString_AS_STRING(
    774                                                 (PyStringObject *)value));
    775                         }
    776                         *retDataBuf = (BYTE *)PyMem_NEW(DWORD, *retDataSize);
    777                         if (*retDataBuf==NULL){
    778                                 PyErr_NoMemory();
    779                                 return FALSE;
    780                         }
    781                         if (value == Py_None)
    782                                 strcpy((char *)*retDataBuf, "");
    783                         else
    784                                 strcpy((char *)*retDataBuf,
    785                                        PyString_AS_STRING(
    786                                                 (PyStringObject *)value));
    787                         if (need_decref)
    788                                 Py_DECREF(value);
    789                         break;
    790                         }
    791                 case REG_MULTI_SZ:
    792                         {
    793                                 DWORD size = 0;
    794                                 char *P;
    795                                 PyObject **obs = NULL;
    796 
    797                                 if (value == Py_None)
    798                                         i = 0;
    799                                 else {
    800                                         if (!PyList_Check(value))
    801                                                 return FALSE;
    802                                         i = PyList_Size(value);
    803                                 }
    804                                 obs = malloc(sizeof(PyObject *) * i);
    805                                 memset(obs, 0, sizeof(PyObject *) * i);
    806                                 for (j = 0; j < i; j++)
    807                                 {
    808                                         PyObject *t;
    809                                         t = PyList_GET_ITEM(
    810                                                 (PyListObject *)value,j);
    811                                         if (PyString_Check(t)) {
    812                                                 obs[j] = t;
    813                                                 Py_INCREF(t);
    814                                         } else if (PyUnicode_Check(t)) {
    815                                                 obs[j] = PyUnicode_AsEncodedString(
    816                                                                 t,
    817                                                                 "mbcs",
    818                                                                 NULL);
    819                                                 if (obs[j]==NULL)
    820                                                         goto reg_multi_fail;
    821                                         } else
    822                                                 goto reg_multi_fail;
    823                                         size += 1 + strlen(
    824                                                 PyString_AS_STRING(
    825                                                         (PyStringObject *)obs[j]));
    826                                 }
    827 
    828                                 *retDataSize = size + 1;
    829                                 *retDataBuf = (BYTE *)PyMem_NEW(char,
    830                                                                 *retDataSize);
    831                                 if (*retDataBuf==NULL){
    832                                         PyErr_NoMemory();
    833                                         goto reg_multi_fail;
    834                                 }
    835                                 P = (char *)*retDataBuf;
    836 
    837                                 for (j = 0; j < i; j++)
    838                                 {
    839                                         PyObject *t;
    840                                         t = obs[j];
    841                                         strcpy(P,
    842                                                PyString_AS_STRING(
    843                                                         (PyStringObject *)t));
    844                                         P += 1 + strlen(
    845                                                 PyString_AS_STRING(
    846                                                         (PyStringObject *)t));
    847                                         Py_DECREF(obs[j]);
    848                                 }
    849                                 /* And doubly-terminate the list... */
    850                                 *P = '\0';
    851                                 free(obs);
    852                                 break;
    853                         reg_multi_fail:
    854                                 if (obs) {
    855                                         for (j = 0; j < i; j++)
    856                                                 Py_XDECREF(obs[j]);
    857 
    858                                         free(obs);
    859                                 }
    860                                 return FALSE;
    861                         }
    862                 case REG_BINARY:
    863                 /* ALSO handle ALL unknown data types here.  Even if we can't
    864                    support it natively, we should handle the bits. */
    865                 default:
    866                         if (value == Py_None)
    867                                 *retDataSize = 0;
    868                         else {
    869                                 void *src_buf;
    870                                 PyBufferProcs *pb = value->ob_type->tp_as_buffer;
    871                                 if (pb==NULL) {
    872                                         PyErr_Format(PyExc_TypeError,
    873                                                 "Objects of type '%s' can not "
    874                                                 "be used as binary registry values",
    875                                                 value->ob_type->tp_name);
    876                                         return FALSE;
    877                                 }
    878                                 *retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf);
    879                                 *retDataBuf = (BYTE *)PyMem_NEW(char,
    880                                                                 *retDataSize);
    881                                 if (*retDataBuf==NULL){
    882                                         PyErr_NoMemory();
    883                                         return FALSE;
    884                                 }
    885                                 memcpy(*retDataBuf, src_buf, *retDataSize);
    886                         }
    887                         break;
    888         }
    889         return TRUE;
     753    Py_ssize_t i,j;
     754    switch (typ) {
     755        case REG_DWORD:
     756            if (value != Py_None &&
     757                !(PyInt_Check(value) || PyLong_Check(value)))
     758                return FALSE;
     759            *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1);
     760            if (*retDataBuf==NULL){
     761                PyErr_NoMemory();
     762                return FALSE;
     763            }
     764            *retDataSize = sizeof(DWORD);
     765            if (value == Py_None) {
     766                DWORD zero = 0;
     767                memcpy(*retDataBuf, &zero, sizeof(DWORD));
     768            }
     769            else {
     770                DWORD d = PyLong_AsUnsignedLong(value);
     771                memcpy(*retDataBuf, &d, sizeof(DWORD));
     772            }
     773            break;
     774        case REG_SZ:
     775        case REG_EXPAND_SZ:
     776            {
     777            int need_decref = 0;
     778            if (value == Py_None)
     779                *retDataSize = 1;
     780            else {
     781                if (PyUnicode_Check(value)) {
     782                    value = PyUnicode_AsEncodedString(
     783                                  value,
     784                                  "mbcs",
     785                                  NULL);
     786                    if (value==NULL)
     787                        return FALSE;
     788                    need_decref = 1;
     789                }
     790                if (!PyString_Check(value))
     791                    return FALSE;
     792                *retDataSize = 1 + strlen(
     793                    PyString_AS_STRING(
     794                        (PyStringObject *)value));
     795            }
     796            *retDataBuf = (BYTE *)PyMem_NEW(DWORD, *retDataSize);
     797            if (*retDataBuf==NULL){
     798                PyErr_NoMemory();
     799                return FALSE;
     800            }
     801            if (value == Py_None)
     802                strcpy((char *)*retDataBuf, "");
     803            else
     804                strcpy((char *)*retDataBuf,
     805                       PyString_AS_STRING(
     806                                (PyStringObject *)value));
     807            if (need_decref)
     808                Py_DECREF(value);
     809            break;
     810            }
     811        case REG_MULTI_SZ:
     812            {
     813                DWORD size = 0;
     814                char *P;
     815                PyObject **obs = NULL;
     816
     817                if (value == Py_None)
     818                    i = 0;
     819                else {
     820                    if (!PyList_Check(value))
     821                        return FALSE;
     822                    i = PyList_Size(value);
     823                }
     824                obs = malloc(sizeof(PyObject *) * i);
     825                memset(obs, 0, sizeof(PyObject *) * i);
     826                for (j = 0; j < i; j++)
     827                {
     828                    PyObject *t;
     829                    t = PyList_GET_ITEM(
     830                        (PyListObject *)value,j);
     831                    if (PyString_Check(t)) {
     832                        obs[j] = t;
     833                        Py_INCREF(t);
     834                    } else if (PyUnicode_Check(t)) {
     835                        obs[j] = PyUnicode_AsEncodedString(
     836                                        t,
     837                                        "mbcs",
     838                                        NULL);
     839                        if (obs[j]==NULL)
     840                            goto reg_multi_fail;
     841                    } else
     842                        goto reg_multi_fail;
     843                    size += 1 + strlen(
     844                        PyString_AS_STRING(
     845                            (PyStringObject *)obs[j]));
     846                }
     847
     848                *retDataSize = size + 1;
     849                *retDataBuf = (BYTE *)PyMem_NEW(char,
     850                                                *retDataSize);
     851                if (*retDataBuf==NULL){
     852                    PyErr_NoMemory();
     853                    goto reg_multi_fail;
     854                }
     855                P = (char *)*retDataBuf;
     856
     857                for (j = 0; j < i; j++)
     858                {
     859                    PyObject *t;
     860                    t = obs[j];
     861                    strcpy(P,
     862                           PyString_AS_STRING(
     863                                    (PyStringObject *)t));
     864                    P += 1 + strlen(
     865                        PyString_AS_STRING(
     866                            (PyStringObject *)t));
     867                    Py_DECREF(obs[j]);
     868                }
     869                /* And doubly-terminate the list... */
     870                *P = '\0';
     871                free(obs);
     872                break;
     873            reg_multi_fail:
     874                if (obs) {
     875                    for (j = 0; j < i; j++)
     876                        Py_XDECREF(obs[j]);
     877
     878                    free(obs);
     879                }
     880                return FALSE;
     881            }
     882        case REG_BINARY:
     883        /* ALSO handle ALL unknown data types here.  Even if we can't
     884           support it natively, we should handle the bits. */
     885        default:
     886            if (value == Py_None)
     887                *retDataSize = 0;
     888            else {
     889                void *src_buf;
     890                PyBufferProcs *pb = value->ob_type->tp_as_buffer;
     891                if (pb==NULL) {
     892                    PyErr_Format(PyExc_TypeError,
     893                        "Objects of type '%s' can not "
     894                        "be used as binary registry values",
     895                        value->ob_type->tp_name);
     896                    return FALSE;
     897                }
     898                *retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf);
     899                *retDataBuf = (BYTE *)PyMem_NEW(char,
     900                                                *retDataSize);
     901                if (*retDataBuf==NULL){
     902                    PyErr_NoMemory();
     903                    return FALSE;
     904                }
     905                memcpy(*retDataBuf, src_buf, *retDataSize);
     906            }
     907            break;
     908    }
     909    return TRUE;
    890910}
    891911
     
    894914Reg2Py(char *retDataBuf, DWORD retDataSize, DWORD typ)
    895915{
    896         PyObject *obData;
    897 
    898         switch (typ) {
    899                 case REG_DWORD:
    900                         if (retDataSize == 0)
    901                                 obData = Py_BuildValue("i", 0);
    902                         else
    903                                 obData = Py_BuildValue("i",
    904                                                        *(int *)retDataBuf);
    905                         break;
    906                 case REG_SZ:
    907                 case REG_EXPAND_SZ:
    908                         /* retDataBuf may or may not have a trailing NULL in
    909                            the buffer. */
    910                         if (retDataSize && retDataBuf[retDataSize-1] == '\0')
    911                                 --retDataSize;
    912                         if (retDataSize ==0)
    913                                 retDataBuf = "";
    914                         obData = PyUnicode_DecodeMBCS(retDataBuf,
    915                                                       retDataSize,
    916                                                       NULL);
    917                         break;
    918                 case REG_MULTI_SZ:
    919                         if (retDataSize == 0)
    920                                 obData = PyList_New(0);
    921                         else
    922                         {
    923                                 int index = 0;
    924                                 int s = countStrings(retDataBuf, retDataSize);
    925                                 char **str = (char **)malloc(sizeof(char *)*s);
    926                                 if (str == NULL)
    927                                         return PyErr_NoMemory();
    928 
    929                                 fixupMultiSZ(str, retDataBuf, retDataSize);
    930                                 obData = PyList_New(s);
    931                                 if (obData == NULL)
    932                                         return NULL;
    933                                 for (index = 0; index < s; index++)
    934                                 {
    935                                         size_t len = _mbstrlen(str[index]);
    936                                         if (len > INT_MAX) {
    937                                                 PyErr_SetString(PyExc_OverflowError,
    938                                                         "registry string is too long for a Python string");
    939                                                 Py_DECREF(obData);
    940                                                 return NULL;
    941                                         }
    942                                         PyList_SetItem(obData,
    943                                                        index,
    944                                                        PyUnicode_DecodeMBCS(
    945                                                             (const char *)str[index],
    946                                                            (int)len,
    947                                                             NULL)
    948                                                        );
    949                                 }
    950                                 free(str);
    951 
    952                                 break;
    953                         }
    954                 case REG_BINARY:
    955                 /* ALSO handle ALL unknown data types here.  Even if we can't
    956                    support it natively, we should handle the bits. */
    957                 default:
    958                         if (retDataSize == 0) {
    959                                 Py_INCREF(Py_None);
    960                                 obData = Py_None;
    961                         }
    962                         else
    963                                 obData = Py_BuildValue("s#",
    964                                                        (char *)retDataBuf,
    965                                                        retDataSize);
    966                         break;
    967         }
    968         if (obData == NULL)
    969                 return NULL;
    970         else
    971                 return obData;
     916    PyObject *obData;
     917
     918    switch (typ) {
     919        case REG_DWORD:
     920            if (retDataSize == 0)
     921                obData = Py_BuildValue("k", 0);
     922            else
     923                obData = Py_BuildValue("k",
     924                                       *(int *)retDataBuf);
     925            break;
     926        case REG_SZ:
     927        case REG_EXPAND_SZ:
     928            /* retDataBuf may or may not have a trailing NULL in
     929               the buffer. */
     930            if (retDataSize && retDataBuf[retDataSize-1] == '\0')
     931                --retDataSize;
     932            if (retDataSize ==0)
     933                retDataBuf = "";
     934            obData = PyUnicode_DecodeMBCS(retDataBuf,
     935                                          retDataSize,
     936                                          NULL);
     937            break;
     938        case REG_MULTI_SZ:
     939            if (retDataSize == 0)
     940                obData = PyList_New(0);
     941            else
     942            {
     943                int index = 0;
     944                int s = countStrings(retDataBuf, retDataSize);
     945                char **str = (char **)malloc(sizeof(char *)*s);
     946                if (str == NULL)
     947                    return PyErr_NoMemory();
     948
     949                fixupMultiSZ(str, retDataBuf, retDataSize);
     950                obData = PyList_New(s);
     951                if (obData == NULL)
     952                    return NULL;
     953                for (index = 0; index < s; index++)
     954                {
     955                    size_t len = _mbstrlen(str[index]);
     956                    if (len > INT_MAX) {
     957                        PyErr_SetString(PyExc_OverflowError,
     958                            "registry string is too long for a Python string");
     959                        Py_DECREF(obData);
     960                        return NULL;
     961                    }
     962                    PyList_SetItem(obData,
     963                                   index,
     964                                   PyUnicode_DecodeMBCS(
     965                                        (const char *)str[index],
     966                                       (int)len,
     967                                        NULL)
     968                                   );
     969                }
     970                free(str);
     971
     972                break;
     973            }
     974        case REG_BINARY:
     975        /* ALSO handle ALL unknown data types here.  Even if we can't
     976           support it natively, we should handle the bits. */
     977        default:
     978            if (retDataSize == 0) {
     979                Py_INCREF(Py_None);
     980                obData = Py_None;
     981            }
     982            else
     983                obData = Py_BuildValue("s#",
     984                                       (char *)retDataBuf,
     985                                       retDataSize);
     986            break;
     987    }
     988    if (obData == NULL)
     989        return NULL;
     990    else
     991        return obData;
    972992}
    973993
     
    977997PyCloseKey(PyObject *self, PyObject *args)
    978998{
    979         PyObject *obKey;
    980         if (!PyArg_ParseTuple(args, "O:CloseKey", &obKey))
    981                 return NULL;
    982         if (!PyHKEY_Close(obKey))
    983                 return NULL;
    984         Py_INCREF(Py_None);
    985         return Py_None;
     999    PyObject *obKey;
     1000    if (!PyArg_ParseTuple(args, "O:CloseKey", &obKey))
     1001        return NULL;
     1002    if (!PyHKEY_Close(obKey))
     1003        return NULL;
     1004    Py_INCREF(Py_None);
     1005    return Py_None;
    9861006}
    9871007
     
    9891009PyConnectRegistry(PyObject *self, PyObject *args)
    9901010{
    991         HKEY hKey;
    992         PyObject *obKey;
    993         char *szCompName = NULL;
    994         HKEY retKey;
    995         long rc;
    996         if (!PyArg_ParseTuple(args, "zO:ConnectRegistry", &szCompName, &obKey))
    997                 return NULL;
    998         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    999                 return NULL;
    1000         Py_BEGIN_ALLOW_THREADS
    1001         rc = RegConnectRegistry(szCompName, hKey, &retKey);
    1002         Py_END_ALLOW_THREADS
    1003         if (rc != ERROR_SUCCESS)
    1004                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1005                                                            "ConnectRegistry");
    1006         return PyHKEY_FromHKEY(retKey);
     1011    HKEY hKey;
     1012    PyObject *obKey;
     1013    char *szCompName = NULL;
     1014    HKEY retKey;
     1015    long rc;
     1016    if (!PyArg_ParseTuple(args, "zO:ConnectRegistry", &szCompName, &obKey))
     1017        return NULL;
     1018    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1019        return NULL;
     1020    Py_BEGIN_ALLOW_THREADS
     1021    rc = RegConnectRegistry(szCompName, hKey, &retKey);
     1022    Py_END_ALLOW_THREADS
     1023    if (rc != ERROR_SUCCESS)
     1024        return PyErr_SetFromWindowsErrWithFunction(rc,
     1025                                                   "ConnectRegistry");
     1026    return PyHKEY_FromHKEY(retKey);
    10071027}
    10081028
     
    10101030PyCreateKey(PyObject *self, PyObject *args)
    10111031{
    1012         HKEY hKey;
    1013         PyObject *obKey;
    1014         char *subKey;
    1015         HKEY retKey;
    1016         long rc;
    1017         if (!PyArg_ParseTuple(args, "Oz:CreateKey", &obKey, &subKey))
    1018                 return NULL;
    1019         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1020                 return NULL;
    1021         rc = RegCreateKey(hKey, subKey, &retKey);
    1022         if (rc != ERROR_SUCCESS)
    1023                 return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey");
    1024         return PyHKEY_FromHKEY(retKey);
     1032    HKEY hKey;
     1033    PyObject *obKey;
     1034    char *subKey;
     1035    HKEY retKey;
     1036    long rc;
     1037    if (!PyArg_ParseTuple(args, "Oz:CreateKey", &obKey, &subKey))
     1038        return NULL;
     1039    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1040        return NULL;
     1041    rc = RegCreateKey(hKey, subKey, &retKey);
     1042    if (rc != ERROR_SUCCESS)
     1043        return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey");
     1044    return PyHKEY_FromHKEY(retKey);
     1045}
     1046
     1047static PyObject *
     1048PyCreateKeyEx(PyObject *self, PyObject *args)
     1049{
     1050    HKEY hKey;
     1051    PyObject *obKey;
     1052    char *subKey;
     1053    HKEY retKey;
     1054    int res = 0;
     1055    REGSAM sam = KEY_WRITE;
     1056    long rc;
     1057    if (!PyArg_ParseTuple(args, "Oz|ii:CreateKeyEx", &obKey, &subKey,
     1058                                              &res, &sam))
     1059        return NULL;
     1060    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1061        return NULL;
     1062
     1063    rc = RegCreateKeyEx(hKey, subKey, res, NULL, (DWORD)NULL,
     1064                                            sam, NULL, &retKey, NULL);
     1065    if (rc != ERROR_SUCCESS)
     1066        return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx");
     1067    return PyHKEY_FromHKEY(retKey);
    10251068}
    10261069
     
    10281071PyDeleteKey(PyObject *self, PyObject *args)
    10291072{
    1030         HKEY hKey;
    1031         PyObject *obKey;
    1032         char *subKey;
    1033         long rc;
    1034         if (!PyArg_ParseTuple(args, "Os:DeleteKey", &obKey, &subKey))
    1035                 return NULL;
    1036         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1037                 return NULL;
    1038         rc = RegDeleteKey(hKey, subKey );
    1039         if (rc != ERROR_SUCCESS)
    1040                 return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey");
    1041         Py_INCREF(Py_None);
    1042         return Py_None;
     1073    HKEY hKey;
     1074    PyObject *obKey;
     1075    char *subKey;
     1076    long rc;
     1077    if (!PyArg_ParseTuple(args, "Os:DeleteKey", &obKey, &subKey))
     1078        return NULL;
     1079    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1080        return NULL;
     1081    rc = RegDeleteKey(hKey, subKey );
     1082    if (rc != ERROR_SUCCESS)
     1083        return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey");
     1084    Py_INCREF(Py_None);
     1085    return Py_None;
     1086}
     1087
     1088static PyObject *
     1089PyDeleteKeyEx(PyObject *self, PyObject *args)
     1090{
     1091    HKEY hKey;
     1092    PyObject *obKey;
     1093    HMODULE hMod;
     1094    typedef LONG (WINAPI *RDKEFunc)(HKEY, const char*, REGSAM, int);
     1095    RDKEFunc pfn = NULL;
     1096    char *subKey;
     1097    long rc;
     1098    int res = 0;
     1099    REGSAM sam = KEY_WOW64_64KEY;
     1100
     1101    if (!PyArg_ParseTuple(args, "Os|ii:DeleteKeyEx",
     1102                                              &obKey, &subKey, &sam, &res))
     1103        return NULL;
     1104    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1105        return NULL;
     1106
     1107    /* Only available on 64bit platforms, so we must load it
     1108       dynamically. */
     1109    hMod = GetModuleHandle("advapi32.dll");
     1110    if (hMod)
     1111        pfn = (RDKEFunc)GetProcAddress(hMod,
     1112                                                                   "RegDeleteKeyExA");
     1113    if (!pfn) {
     1114        PyErr_SetString(PyExc_NotImplementedError,
     1115                                        "not implemented on this platform");
     1116        return NULL;
     1117    }
     1118    Py_BEGIN_ALLOW_THREADS
     1119    rc = (*pfn)(hKey, subKey, sam, res);
     1120    Py_END_ALLOW_THREADS
     1121
     1122    if (rc != ERROR_SUCCESS)
     1123        return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx");
     1124    Py_INCREF(Py_None);
     1125    return Py_None;
    10431126}
    10441127
     
    10461129PyDeleteValue(PyObject *self, PyObject *args)
    10471130{
    1048         HKEY hKey;
    1049         PyObject *obKey;
    1050         char *subKey;
    1051         long rc;
    1052         if (!PyArg_ParseTuple(args, "Oz:DeleteValue", &obKey, &subKey))
    1053                 return NULL;
    1054         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1055                 return NULL;
    1056         Py_BEGIN_ALLOW_THREADS
    1057         rc = RegDeleteValue(hKey, subKey);
    1058         Py_END_ALLOW_THREADS
    1059         if (rc !=ERROR_SUCCESS)
    1060                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1061                                                            "RegDeleteValue");
    1062         Py_INCREF(Py_None);
    1063         return Py_None;
     1131    HKEY hKey;
     1132    PyObject *obKey;
     1133    char *subKey;
     1134    long rc;
     1135    if (!PyArg_ParseTuple(args, "Oz:DeleteValue", &obKey, &subKey))
     1136        return NULL;
     1137    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1138        return NULL;
     1139    Py_BEGIN_ALLOW_THREADS
     1140    rc = RegDeleteValue(hKey, subKey);
     1141    Py_END_ALLOW_THREADS
     1142    if (rc !=ERROR_SUCCESS)
     1143        return PyErr_SetFromWindowsErrWithFunction(rc,
     1144                                                   "RegDeleteValue");
     1145    Py_INCREF(Py_None);
     1146    return Py_None;
    10641147}
    10651148
     
    10671150PyEnumKey(PyObject *self, PyObject *args)
    10681151{
    1069         HKEY hKey;
    1070         PyObject *obKey;
    1071         int index;
    1072         long rc;
    1073         PyObject *retStr;
    1074         char tmpbuf[256]; /* max key name length is 255 */
    1075         DWORD len = sizeof(tmpbuf); /* includes NULL terminator */
    1076 
    1077         if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index))
    1078                 return NULL;
    1079         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1080                 return NULL;
    1081 
    1082         Py_BEGIN_ALLOW_THREADS
    1083         rc = RegEnumKeyEx(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL);
    1084         Py_END_ALLOW_THREADS
    1085         if (rc != ERROR_SUCCESS)
    1086                 return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx");
    1087 
    1088         retStr = PyString_FromStringAndSize(tmpbuf, len);
    1089         return retStr;  /* can be NULL */
     1152    HKEY hKey;
     1153    PyObject *obKey;
     1154    int index;
     1155    long rc;
     1156    PyObject *retStr;
     1157
     1158    /* The Windows docs claim that the max key name length is 255
     1159     * characters, plus a terminating nul character.  However,
     1160     * empirical testing demonstrates that it is possible to
     1161     * create a 256 character key that is missing the terminating
     1162     * nul.  RegEnumKeyEx requires a 257 character buffer to
     1163     * retrieve such a key name. */
     1164    char tmpbuf[257];
     1165    DWORD len = sizeof(tmpbuf); /* includes NULL terminator */
     1166
     1167    if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index))
     1168        return NULL;
     1169    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1170        return NULL;
     1171
     1172    Py_BEGIN_ALLOW_THREADS
     1173    rc = RegEnumKeyEx(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL);
     1174    Py_END_ALLOW_THREADS
     1175    if (rc != ERROR_SUCCESS)
     1176        return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx");
     1177
     1178    retStr = PyString_FromStringAndSize(tmpbuf, len);
     1179    return retStr;  /* can be NULL */
    10901180}
    10911181
     
    10931183PyEnumValue(PyObject *self, PyObject *args)
    10941184{
    1095         HKEY hKey;
    1096         PyObject *obKey;
    1097         int index;
    1098         long rc;
    1099         char *retValueBuf;
    1100         char *retDataBuf;
    1101         DWORD retValueSize;
    1102         DWORD retDataSize;
    1103         DWORD typ;
    1104         PyObject *obData;
    1105         PyObject *retVal;
    1106 
    1107         if (!PyArg_ParseTuple(args, "Oi:EnumValue", &obKey, &index))
    1108                 return NULL;
    1109         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1110                 return NULL;
    1111 
    1112         if ((rc = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
    1113                                   NULL,
    1114                                   &retValueSize, &retDataSize, NULL, NULL))
    1115             != ERROR_SUCCESS)
    1116                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1117                                                            "RegQueryInfoKey");
    1118         ++retValueSize;    /* include null terminators */
    1119         ++retDataSize;
    1120         retValueBuf = (char *)PyMem_Malloc(retValueSize);
    1121         if (retValueBuf == NULL)
    1122                 return PyErr_NoMemory();
    1123         retDataBuf = (char *)PyMem_Malloc(retDataSize);
    1124         if (retDataBuf == NULL) {
    1125                 PyMem_Free(retValueBuf);
    1126                 return PyErr_NoMemory();
    1127         }
    1128 
    1129         Py_BEGIN_ALLOW_THREADS
    1130         rc = RegEnumValue(hKey,
    1131                           index,
    1132                           retValueBuf,
    1133                           &retValueSize,
    1134                           NULL,
    1135                           &typ,
    1136                           (BYTE *)retDataBuf,
    1137                           &retDataSize);
    1138         Py_END_ALLOW_THREADS
    1139 
    1140         if (rc != ERROR_SUCCESS) {
    1141                 retVal = PyErr_SetFromWindowsErrWithFunction(rc,
    1142                                                              "PyRegEnumValue");
    1143                 goto fail;
    1144         }
    1145         obData = Reg2Py(retDataBuf, retDataSize, typ);
    1146         if (obData == NULL) {
    1147                 retVal = NULL;
    1148                 goto fail;
    1149         }
    1150         retVal = Py_BuildValue("sOi", retValueBuf, obData, typ);
    1151         Py_DECREF(obData);
     1185    HKEY hKey;
     1186    PyObject *obKey;
     1187    int index;
     1188    long rc;
     1189    char *retValueBuf;
     1190    char *retDataBuf;
     1191    char *tmpBuf;
     1192    DWORD retValueSize, bufValueSize;
     1193    DWORD retDataSize, bufDataSize;
     1194    DWORD typ;
     1195    PyObject *obData;
     1196    PyObject *retVal;
     1197
     1198    if (!PyArg_ParseTuple(args, "Oi:EnumValue", &obKey, &index))
     1199        return NULL;
     1200    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1201        return NULL;
     1202
     1203    if ((rc = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
     1204                              NULL,
     1205                              &retValueSize, &retDataSize, NULL, NULL))
     1206        != ERROR_SUCCESS)
     1207        return PyErr_SetFromWindowsErrWithFunction(rc,
     1208                                                   "RegQueryInfoKey");
     1209    ++retValueSize;    /* include null terminators */
     1210    ++retDataSize;
     1211    bufDataSize = retDataSize;
     1212    bufValueSize = retValueSize;
     1213    retValueBuf = (char *)PyMem_Malloc(retValueSize);
     1214    if (retValueBuf == NULL)
     1215        return PyErr_NoMemory();
     1216    retDataBuf = (char *)PyMem_Malloc(retDataSize);
     1217    if (retDataBuf == NULL) {
     1218        PyMem_Free(retValueBuf);
     1219        return PyErr_NoMemory();
     1220    }
     1221
     1222    while (1) {
     1223        Py_BEGIN_ALLOW_THREADS
     1224        rc = RegEnumValue(hKey,
     1225                  index,
     1226                  retValueBuf,
     1227                  &retValueSize,
     1228                  NULL,
     1229                  &typ,
     1230                  (BYTE *)retDataBuf,
     1231                  &retDataSize);
     1232        Py_END_ALLOW_THREADS
     1233
     1234        if (rc != ERROR_MORE_DATA)
     1235            break;
     1236
     1237        bufDataSize *= 2;
     1238        tmpBuf = (char *)PyMem_Realloc(retDataBuf, bufDataSize);
     1239        if (tmpBuf == NULL) {
     1240            PyErr_NoMemory();
     1241            retVal = NULL;
     1242            goto fail;
     1243        }
     1244        retDataBuf = tmpBuf;
     1245        retDataSize = bufDataSize;
     1246        retValueSize = bufValueSize;
     1247    }
     1248
     1249    if (rc != ERROR_SUCCESS) {
     1250        retVal = PyErr_SetFromWindowsErrWithFunction(rc,
     1251                                                     "PyRegEnumValue");
     1252        goto fail;
     1253    }
     1254    obData = Reg2Py(retDataBuf, retDataSize, typ);
     1255    if (obData == NULL) {
     1256        retVal = NULL;
     1257        goto fail;
     1258    }
     1259    retVal = Py_BuildValue("sOi", retValueBuf, obData, typ);
     1260    Py_DECREF(obData);
    11521261  fail:
    1153         PyMem_Free(retValueBuf);
    1154         PyMem_Free(retDataBuf);
    1155         return retVal;
     1262    PyMem_Free(retValueBuf);
     1263    PyMem_Free(retDataBuf);
     1264    return retVal;
    11561265}
    11571266
     
    11591268PyExpandEnvironmentStrings(PyObject *self, PyObject *args)
    11601269{
    1161         Py_UNICODE *retValue = NULL;
    1162         Py_UNICODE *src;
    1163         DWORD retValueSize;
    1164         DWORD rc;
    1165         PyObject *o;
    1166 
    1167         if (!PyArg_ParseTuple(args, "u:ExpandEnvironmentStrings", &src))
    1168                 return NULL;
    1169 
    1170         retValueSize = ExpandEnvironmentStringsW(src, retValue, 0);
    1171         if (retValueSize == 0) {
    1172                 return PyErr_SetFromWindowsErrWithFunction(retValueSize,
    1173                                                 "ExpandEnvironmentStrings");
    1174         }
    1175         retValue = (Py_UNICODE *)PyMem_Malloc(retValueSize * sizeof(Py_UNICODE));
    1176         if (retValue == NULL) {
    1177                 return PyErr_NoMemory();
    1178         }
    1179 
    1180         rc = ExpandEnvironmentStringsW(src, retValue, retValueSize);
    1181         if (rc == 0) {
    1182                 PyMem_Free(retValue);
    1183                 return PyErr_SetFromWindowsErrWithFunction(retValueSize,
    1184                                                 "ExpandEnvironmentStrings");
    1185         }
    1186         o = PyUnicode_FromUnicode(retValue, wcslen(retValue));
    1187         PyMem_Free(retValue);
    1188         return o;
     1270    Py_UNICODE *retValue = NULL;
     1271    Py_UNICODE *src;
     1272    DWORD retValueSize;
     1273    DWORD rc;
     1274    PyObject *o;
     1275
     1276    if (!PyArg_ParseTuple(args, "u:ExpandEnvironmentStrings", &src))
     1277        return NULL;
     1278
     1279    retValueSize = ExpandEnvironmentStringsW(src, retValue, 0);
     1280    if (retValueSize == 0) {
     1281        return PyErr_SetFromWindowsErrWithFunction(retValueSize,
     1282                                        "ExpandEnvironmentStrings");
     1283    }
     1284    retValue = (Py_UNICODE *)PyMem_Malloc(retValueSize * sizeof(Py_UNICODE));
     1285    if (retValue == NULL) {
     1286        return PyErr_NoMemory();
     1287    }
     1288
     1289    rc = ExpandEnvironmentStringsW(src, retValue, retValueSize);
     1290    if (rc == 0) {
     1291        PyMem_Free(retValue);
     1292        return PyErr_SetFromWindowsErrWithFunction(retValueSize,
     1293                                        "ExpandEnvironmentStrings");
     1294    }
     1295    o = PyUnicode_FromUnicode(retValue, wcslen(retValue));
     1296    PyMem_Free(retValue);
     1297    return o;
    11891298}
    11901299
     
    11921301PyFlushKey(PyObject *self, PyObject *args)
    11931302{
    1194         HKEY hKey;
    1195         PyObject *obKey;
    1196         long rc;
    1197         if (!PyArg_ParseTuple(args, "O:FlushKey", &obKey))
    1198                 return NULL;
    1199         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1200                 return NULL;
    1201         Py_BEGIN_ALLOW_THREADS
    1202         rc = RegFlushKey(hKey);
    1203         Py_END_ALLOW_THREADS
    1204         if (rc != ERROR_SUCCESS)
    1205                 return PyErr_SetFromWindowsErrWithFunction(rc, "RegFlushKey");
    1206         Py_INCREF(Py_None);
    1207         return Py_None;
     1303    HKEY hKey;
     1304    PyObject *obKey;
     1305    long rc;
     1306    if (!PyArg_ParseTuple(args, "O:FlushKey", &obKey))
     1307        return NULL;
     1308    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1309        return NULL;
     1310    Py_BEGIN_ALLOW_THREADS
     1311    rc = RegFlushKey(hKey);
     1312    Py_END_ALLOW_THREADS
     1313    if (rc != ERROR_SUCCESS)
     1314        return PyErr_SetFromWindowsErrWithFunction(rc, "RegFlushKey");
     1315    Py_INCREF(Py_None);
     1316    return Py_None;
    12081317}
    12091318static PyObject *
    12101319PyLoadKey(PyObject *self, PyObject *args)
    12111320{
    1212         HKEY hKey;
    1213         PyObject *obKey;
    1214         char *subKey;
    1215         char *fileName;
    1216 
    1217         long rc;
    1218         if (!PyArg_ParseTuple(args, "Oss:LoadKey", &obKey, &subKey, &fileName))
    1219                 return NULL;
    1220         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1221                 return NULL;
    1222         Py_BEGIN_ALLOW_THREADS
    1223         rc = RegLoadKey(hKey, subKey, fileName );
    1224         Py_END_ALLOW_THREADS
    1225         if (rc != ERROR_SUCCESS)
    1226                 return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey");
    1227         Py_INCREF(Py_None);
    1228         return Py_None;
     1321    HKEY hKey;
     1322    PyObject *obKey;
     1323    char *subKey;
     1324    char *fileName;
     1325
     1326    long rc;
     1327    if (!PyArg_ParseTuple(args, "Oss:LoadKey", &obKey, &subKey, &fileName))
     1328        return NULL;
     1329    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1330        return NULL;
     1331    Py_BEGIN_ALLOW_THREADS
     1332    rc = RegLoadKey(hKey, subKey, fileName );
     1333    Py_END_ALLOW_THREADS
     1334    if (rc != ERROR_SUCCESS)
     1335        return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey");
     1336    Py_INCREF(Py_None);
     1337    return Py_None;
    12291338}
    12301339
     
    12321341PyOpenKey(PyObject *self, PyObject *args)
    12331342{
    1234         HKEY hKey;
    1235         PyObject *obKey;
    1236 
    1237         char *subKey;
    1238         int res = 0;
    1239         HKEY retKey;
    1240         long rc;
    1241         REGSAM sam = KEY_READ;
    1242         if (!PyArg_ParseTuple(args, "Oz|ii:OpenKey", &obKey, &subKey,
    1243                               &res, &sam))
    1244                 return NULL;
    1245         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1246                 return NULL;
    1247 
    1248         Py_BEGIN_ALLOW_THREADS
    1249         rc = RegOpenKeyEx(hKey, subKey, res, sam, &retKey);
    1250         Py_END_ALLOW_THREADS
    1251         if (rc != ERROR_SUCCESS)
    1252                 return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx");
    1253         return PyHKEY_FromHKEY(retKey);
     1343    HKEY hKey;
     1344    PyObject *obKey;
     1345
     1346    char *subKey;
     1347    int res = 0;
     1348    HKEY retKey;
     1349    long rc;
     1350    REGSAM sam = KEY_READ;
     1351    if (!PyArg_ParseTuple(args, "Oz|ii:OpenKey", &obKey, &subKey,
     1352                          &res, &sam))
     1353        return NULL;
     1354    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1355        return NULL;
     1356
     1357    Py_BEGIN_ALLOW_THREADS
     1358    rc = RegOpenKeyEx(hKey, subKey, res, sam, &retKey);
     1359    Py_END_ALLOW_THREADS
     1360    if (rc != ERROR_SUCCESS)
     1361        return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx");
     1362    return PyHKEY_FromHKEY(retKey);
    12541363}
    12551364
     
    12671376  PyObject *ret;
    12681377  if (!PyArg_ParseTuple(args, "O:QueryInfoKey", &obKey))
    1269         return NULL;
     1378    return NULL;
    12701379  if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1271         return NULL;
     1380    return NULL;
    12721381  if ((rc = RegQueryInfoKey(hKey, NULL, NULL, 0, &nSubKeys, NULL, NULL,
    1273                             &nValues,  NULL,  NULL, NULL, &ft))
     1382                            &nValues,  NULL,  NULL, NULL, &ft))
    12741383      != ERROR_SUCCESS)
    1275         return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey");
     1384    return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey");
    12761385  li.LowPart = ft.dwLowDateTime;
    12771386  li.HighPart = ft.dwHighDateTime;
    12781387  l = PyLong_FromLongLong(li.QuadPart);
    12791388  if (l == NULL)
    1280         return NULL;
     1389    return NULL;
    12811390  ret = Py_BuildValue("iiO", nSubKeys, nValues, l);
    12821391  Py_DECREF(l);
     
    12871396PyQueryValue(PyObject *self, PyObject *args)
    12881397{
    1289         HKEY hKey;
    1290         PyObject *obKey;
    1291         char *subKey;
    1292         long rc;
    1293         PyObject *retStr;
    1294         char *retBuf;
    1295         long bufSize = 0;
    1296 
    1297         if (!PyArg_ParseTuple(args, "Oz:QueryValue", &obKey, &subKey))
    1298                 return NULL;
    1299 
    1300         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1301                 return NULL;
    1302         if ((rc = RegQueryValue(hKey, subKey, NULL, &bufSize))
    1303             != ERROR_SUCCESS)
    1304                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1305                                                            "RegQueryValue");
    1306         retStr = PyString_FromStringAndSize(NULL, bufSize);
    1307         if (retStr == NULL)
    1308                 return NULL;
    1309         retBuf = PyString_AS_STRING(retStr);
    1310         if ((rc = RegQueryValue(hKey, subKey, retBuf, &bufSize))
    1311             != ERROR_SUCCESS) {
    1312                 Py_DECREF(retStr);
    1313                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1314                                                            "RegQueryValue");
    1315         }
    1316         _PyString_Resize(&retStr, strlen(retBuf));
    1317         return retStr;
     1398    HKEY hKey;
     1399    PyObject *obKey;
     1400    char *subKey;
     1401    long rc;
     1402    PyObject *retStr;
     1403    char *retBuf;
     1404    DWORD bufSize = 0;
     1405    DWORD retSize = 0;
     1406    char *tmp;
     1407
     1408    if (!PyArg_ParseTuple(args, "Oz:QueryValue", &obKey, &subKey))
     1409        return NULL;
     1410
     1411    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1412        return NULL;
     1413 
     1414    rc = RegQueryValue(hKey, subKey, NULL, &retSize);
     1415    if (rc == ERROR_MORE_DATA)
     1416        retSize = 256;
     1417    else if (rc != ERROR_SUCCESS)
     1418        return PyErr_SetFromWindowsErrWithFunction(rc,
     1419                                                   "RegQueryValue");
     1420
     1421    bufSize = retSize;
     1422    retBuf = (char *) PyMem_Malloc(bufSize);
     1423    if (retBuf == NULL)
     1424        return PyErr_NoMemory();
     1425
     1426    while (1) {
     1427        retSize = bufSize;
     1428        rc = RegQueryValue(hKey, subKey, retBuf, &retSize);
     1429        if (rc != ERROR_MORE_DATA)
     1430            break;
     1431
     1432        bufSize *= 2;
     1433        tmp = (char *) PyMem_Realloc(retBuf, bufSize);
     1434        if (tmp == NULL) {
     1435            PyMem_Free(retBuf);
     1436            return PyErr_NoMemory();
     1437        }
     1438        retBuf = tmp;
     1439    }
     1440
     1441    if (rc != ERROR_SUCCESS) {
     1442        PyMem_Free(retBuf);
     1443        return PyErr_SetFromWindowsErrWithFunction(rc,
     1444                                                   "RegQueryValue");
     1445    }
     1446
     1447    if (retBuf[retSize-1] == '\x00')
     1448        retSize--;
     1449    retStr = PyString_FromStringAndSize(retBuf, retSize);
     1450    if (retStr == NULL) {
     1451        PyMem_Free(retBuf);
     1452        return NULL;
     1453    }
     1454    return retStr;
    13181455}
    13191456
     
    13211458PyQueryValueEx(PyObject *self, PyObject *args)
    13221459{
    1323         HKEY hKey;
    1324         PyObject *obKey;
    1325         char *valueName;
    1326 
    1327         long rc;
    1328         char *retBuf;
    1329         DWORD bufSize = 0;
    1330         DWORD typ;
    1331         PyObject *obData;
    1332         PyObject *result;
    1333 
    1334         if (!PyArg_ParseTuple(args, "Oz:QueryValueEx", &obKey, &valueName))
    1335                 return NULL;
    1336 
    1337         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1338                 return NULL;
    1339         if ((rc = RegQueryValueEx(hKey, valueName,
    1340                                   NULL, NULL, NULL,
    1341                                   &bufSize))
    1342             != ERROR_SUCCESS)
    1343                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1344                                                            "RegQueryValueEx");
    1345         retBuf = (char *)PyMem_Malloc(bufSize);
    1346         if (retBuf == NULL)
    1347                 return PyErr_NoMemory();
    1348         if ((rc = RegQueryValueEx(hKey, valueName, NULL,
    1349                                   &typ, (BYTE *)retBuf, &bufSize))
    1350             != ERROR_SUCCESS) {
    1351                 PyMem_Free(retBuf);
    1352                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1353                                                            "RegQueryValueEx");
    1354         }
    1355         obData = Reg2Py(retBuf, bufSize, typ);
    1356         PyMem_Free((void *)retBuf);
    1357         if (obData == NULL)
    1358                 return NULL;
    1359         result = Py_BuildValue("Oi", obData, typ);
    1360         Py_DECREF(obData);
    1361         return result;
     1460    HKEY hKey;
     1461    PyObject *obKey;
     1462    char *valueName;
     1463
     1464    long rc;
     1465    char *retBuf, *tmp;
     1466    DWORD bufSize = 0, retSize;
     1467    DWORD typ;
     1468    PyObject *obData;
     1469    PyObject *result;
     1470
     1471    if (!PyArg_ParseTuple(args, "Oz:QueryValueEx", &obKey, &valueName))
     1472        return NULL;
     1473
     1474    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1475        return NULL;
     1476
     1477    rc = RegQueryValueEx(hKey, valueName, NULL, NULL, NULL, &bufSize);
     1478    if (rc == ERROR_MORE_DATA)
     1479        bufSize = 256;
     1480    else if (rc != ERROR_SUCCESS)
     1481        return PyErr_SetFromWindowsErrWithFunction(rc,
     1482                                                   "RegQueryValueEx");
     1483    retBuf = (char *)PyMem_Malloc(bufSize);
     1484    if (retBuf == NULL)
     1485        return PyErr_NoMemory();
     1486
     1487    while (1) {
     1488        retSize = bufSize;
     1489        rc = RegQueryValueEx(hKey, valueName, NULL, &typ,
     1490                             (BYTE *)retBuf, &retSize);
     1491        if (rc != ERROR_MORE_DATA)
     1492            break;
     1493
     1494        bufSize *= 2;
     1495        tmp = (char *) PyMem_Realloc(retBuf, bufSize);
     1496        if (tmp == NULL) {
     1497            PyMem_Free(retBuf);
     1498            return PyErr_NoMemory();
     1499        }
     1500        retBuf = tmp;
     1501    }
     1502
     1503    if (rc != ERROR_SUCCESS) {
     1504        PyMem_Free(retBuf);
     1505        return PyErr_SetFromWindowsErrWithFunction(rc,
     1506                                                   "RegQueryValueEx");
     1507    }
     1508    obData = Reg2Py(retBuf, bufSize, typ);
     1509    PyMem_Free((void *)retBuf);
     1510    if (obData == NULL)
     1511        return NULL;
     1512    result = Py_BuildValue("Oi", obData, typ);
     1513    Py_DECREF(obData);
     1514    return result;
    13621515}
    13631516
     
    13661519PySaveKey(PyObject *self, PyObject *args)
    13671520{
    1368         HKEY hKey;
    1369         PyObject *obKey;
    1370         char *fileName;
    1371         LPSECURITY_ATTRIBUTES pSA = NULL;
    1372 
    1373         long rc;
    1374         if (!PyArg_ParseTuple(args, "Os:SaveKey", &obKey, &fileName))
    1375                 return NULL;
    1376         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1377                 return NULL;
     1521    HKEY hKey;
     1522    PyObject *obKey;
     1523    char *fileName;
     1524    LPSECURITY_ATTRIBUTES pSA = NULL;
     1525
     1526    long rc;
     1527    if (!PyArg_ParseTuple(args, "Os:SaveKey", &obKey, &fileName))
     1528        return NULL;
     1529    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1530        return NULL;
    13781531/*  One day we may get security into the core?
    1379         if (!PyWinObject_AsSECURITY_ATTRIBUTES(obSA, &pSA, TRUE))
    1380                 return NULL;
     1532    if (!PyWinObject_AsSECURITY_ATTRIBUTES(obSA, &pSA, TRUE))
     1533        return NULL;
    13811534*/
    1382         Py_BEGIN_ALLOW_THREADS
    1383         rc = RegSaveKey(hKey, fileName, pSA );
    1384         Py_END_ALLOW_THREADS
    1385         if (rc != ERROR_SUCCESS)
    1386                 return PyErr_SetFromWindowsErrWithFunction(rc, "RegSaveKey");
    1387         Py_INCREF(Py_None);
    1388         return Py_None;
     1535    Py_BEGIN_ALLOW_THREADS
     1536    rc = RegSaveKey(hKey, fileName, pSA );
     1537    Py_END_ALLOW_THREADS
     1538    if (rc != ERROR_SUCCESS)
     1539        return PyErr_SetFromWindowsErrWithFunction(rc, "RegSaveKey");
     1540    Py_INCREF(Py_None);
     1541    return Py_None;
    13891542}
    13901543
     
    13921545PySetValue(PyObject *self, PyObject *args)
    13931546{
    1394         HKEY hKey;
    1395         PyObject *obKey;
    1396         char *subKey;
    1397         char *str;
    1398         DWORD typ;
    1399         DWORD len;
    1400         long rc;
    1401         PyObject *obStrVal;
    1402         PyObject *obSubKey;
    1403         if (!PyArg_ParseTuple(args, "OOiO:SetValue",
    1404                               &obKey,
    1405                               &obSubKey,
    1406                               &typ,
    1407                               &obStrVal))
    1408                 return NULL;
    1409         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1410                 return NULL;
    1411         if (typ != REG_SZ) {
    1412                 PyErr_SetString(PyExc_TypeError,
    1413                                 "Type must be _winreg.REG_SZ");
    1414                 return NULL;
    1415         }
    1416         /* XXX - need Unicode support */
    1417         str = PyString_AsString(obStrVal);
    1418         if (str == NULL)
    1419                 return NULL;
    1420         len = PyString_Size(obStrVal);
    1421         if (obSubKey == Py_None)
    1422                 subKey = NULL;
    1423         else {
    1424                 subKey = PyString_AsString(obSubKey);
    1425                 if (subKey == NULL)
    1426                         return NULL;
    1427         }
    1428         Py_BEGIN_ALLOW_THREADS
    1429         rc = RegSetValue(hKey, subKey, REG_SZ, str, len+1);
    1430         Py_END_ALLOW_THREADS
    1431         if (rc != ERROR_SUCCESS)
    1432                 return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue");
    1433         Py_INCREF(Py_None);
    1434         return Py_None;
     1547    HKEY hKey;
     1548    PyObject *obKey;
     1549    char *subKey;
     1550    char *str;
     1551    DWORD typ;
     1552    DWORD len;
     1553    long rc;
     1554    PyObject *obStrVal;
     1555    PyObject *obSubKey;
     1556    if (!PyArg_ParseTuple(args, "OOiO:SetValue",
     1557                          &obKey,
     1558                          &obSubKey,
     1559                          &typ,
     1560                          &obStrVal))
     1561        return NULL;
     1562    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1563        return NULL;
     1564    if (typ != REG_SZ) {
     1565        PyErr_SetString(PyExc_TypeError,
     1566                        "Type must be _winreg.REG_SZ");
     1567        return NULL;
     1568    }
     1569    /* XXX - need Unicode support */
     1570    str = PyString_AsString(obStrVal);
     1571    if (str == NULL)
     1572        return NULL;
     1573    len = PyString_Size(obStrVal);
     1574    if (obSubKey == Py_None)
     1575        subKey = NULL;
     1576    else {
     1577        subKey = PyString_AsString(obSubKey);
     1578        if (subKey == NULL)
     1579            return NULL;
     1580    }
     1581    Py_BEGIN_ALLOW_THREADS
     1582    rc = RegSetValue(hKey, subKey, REG_SZ, str, len+1);
     1583    Py_END_ALLOW_THREADS
     1584    if (rc != ERROR_SUCCESS)
     1585        return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue");
     1586    Py_INCREF(Py_None);
     1587    return Py_None;
    14351588}
    14361589
     
    14381591PySetValueEx(PyObject *self, PyObject *args)
    14391592{
    1440         HKEY hKey;
    1441         PyObject *obKey;
    1442         char *valueName;
    1443         PyObject *obRes;
    1444         PyObject *value;
    1445         BYTE *data;
    1446         DWORD len;
    1447         DWORD typ;
    1448 
    1449         LONG rc;
    1450 
    1451         if (!PyArg_ParseTuple(args, "OzOiO:SetValueEx",
    1452                               &obKey,
    1453                               &valueName,
    1454                               &obRes,
    1455                               &typ,
    1456                               &value))
    1457                 return NULL;
    1458         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1459                 return NULL;
    1460         if (!Py2Reg(value, typ, &data, &len))
    1461         {
    1462                 if (!PyErr_Occurred())
    1463                         PyErr_SetString(PyExc_ValueError,
    1464                                 "Could not convert the data to the specified type.");
    1465                 return NULL;
    1466         }
    1467         Py_BEGIN_ALLOW_THREADS
    1468         rc = RegSetValueEx(hKey, valueName, 0, typ, data, len);
    1469         Py_END_ALLOW_THREADS
    1470         PyMem_DEL(data);
    1471         if (rc != ERROR_SUCCESS)
    1472                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1473                                                            "RegSetValueEx");
    1474         Py_INCREF(Py_None);
    1475         return Py_None;
     1593    HKEY hKey;
     1594    PyObject *obKey;
     1595    char *valueName;
     1596    PyObject *obRes;
     1597    PyObject *value;
     1598    BYTE *data;
     1599    DWORD len;
     1600    DWORD typ;
     1601
     1602    LONG rc;
     1603
     1604    if (!PyArg_ParseTuple(args, "OzOiO:SetValueEx",
     1605                          &obKey,
     1606                          &valueName,
     1607                          &obRes,
     1608                          &typ,
     1609                          &value))
     1610        return NULL;
     1611    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1612        return NULL;
     1613    if (!Py2Reg(value, typ, &data, &len))
     1614    {
     1615        if (!PyErr_Occurred())
     1616            PyErr_SetString(PyExc_ValueError,
     1617                    "Could not convert the data to the specified type.");
     1618        return NULL;
     1619    }
     1620    Py_BEGIN_ALLOW_THREADS
     1621    rc = RegSetValueEx(hKey, valueName, 0, typ, data, len);
     1622    Py_END_ALLOW_THREADS
     1623    PyMem_DEL(data);
     1624    if (rc != ERROR_SUCCESS)
     1625        return PyErr_SetFromWindowsErrWithFunction(rc,
     1626                                                   "RegSetValueEx");
     1627    Py_INCREF(Py_None);
     1628    return Py_None;
    14761629}
    14771630
     
    14791632PyDisableReflectionKey(PyObject *self, PyObject *args)
    14801633{
    1481         HKEY hKey;
    1482         PyObject *obKey;
    1483         HMODULE hMod;
    1484         typedef LONG (WINAPI *RDRKFunc)(HKEY);
    1485         RDRKFunc pfn = NULL;
    1486         LONG rc;
    1487 
    1488         if (!PyArg_ParseTuple(args, "O:DisableReflectionKey", &obKey))
    1489                 return NULL;
    1490         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1491                 return NULL;
    1492 
    1493         // Only available on 64bit platforms, so we must load it
    1494         // dynamically.
    1495         hMod = GetModuleHandle("advapi32.dll");
    1496         if (hMod)
    1497                 pfn = (RDRKFunc)GetProcAddress(hMod,
    1498                                                "RegDisableReflectionKey");
    1499         if (!pfn) {
    1500                 PyErr_SetString(PyExc_NotImplementedError,
    1501                                 "not implemented on this platform");
    1502                 return NULL;
    1503         }
    1504         Py_BEGIN_ALLOW_THREADS
    1505         rc = (*pfn)(hKey);
    1506         Py_END_ALLOW_THREADS
    1507         if (rc != ERROR_SUCCESS)
    1508                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1509                                                            "RegDisableReflectionKey");
    1510         Py_INCREF(Py_None);
    1511         return Py_None;
     1634    HKEY hKey;
     1635    PyObject *obKey;
     1636    HMODULE hMod;
     1637    typedef LONG (WINAPI *RDRKFunc)(HKEY);
     1638    RDRKFunc pfn = NULL;
     1639    LONG rc;
     1640
     1641    if (!PyArg_ParseTuple(args, "O:DisableReflectionKey", &obKey))
     1642        return NULL;
     1643    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1644        return NULL;
     1645
     1646    /* Only available on 64bit platforms, so we must load it
     1647       dynamically. */
     1648    hMod = GetModuleHandle("advapi32.dll");
     1649    if (hMod)
     1650        pfn = (RDRKFunc)GetProcAddress(hMod,
     1651                                       "RegDisableReflectionKey");
     1652    if (!pfn) {
     1653        PyErr_SetString(PyExc_NotImplementedError,
     1654                        "not implemented on this platform");
     1655        return NULL;
     1656    }
     1657    Py_BEGIN_ALLOW_THREADS
     1658    rc = (*pfn)(hKey);
     1659    Py_END_ALLOW_THREADS
     1660    if (rc != ERROR_SUCCESS)
     1661        return PyErr_SetFromWindowsErrWithFunction(rc,
     1662                                                   "RegDisableReflectionKey");
     1663    Py_INCREF(Py_None);
     1664    return Py_None;
    15121665}
    15131666
     
    15151668PyEnableReflectionKey(PyObject *self, PyObject *args)
    15161669{
    1517         HKEY hKey;
    1518         PyObject *obKey;
    1519         HMODULE hMod;
    1520         typedef LONG (WINAPI *RERKFunc)(HKEY);
    1521         RERKFunc pfn = NULL;
    1522         LONG rc;
    1523 
    1524         if (!PyArg_ParseTuple(args, "O:EnableReflectionKey", &obKey))
    1525                 return NULL;
    1526         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1527                 return NULL;
    1528 
    1529         // Only available on 64bit platforms, so we must load it
    1530         // dynamically.
    1531         hMod = GetModuleHandle("advapi32.dll");
    1532         if (hMod)
    1533                 pfn = (RERKFunc)GetProcAddress(hMod,
    1534                                                "RegEnableReflectionKey");
    1535         if (!pfn) {
    1536                 PyErr_SetString(PyExc_NotImplementedError,
    1537                                 "not implemented on this platform");
    1538                 return NULL;
    1539         }
    1540         Py_BEGIN_ALLOW_THREADS
    1541         rc = (*pfn)(hKey);
    1542         Py_END_ALLOW_THREADS
    1543         if (rc != ERROR_SUCCESS)
    1544                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1545                                                            "RegEnableReflectionKey");
    1546         Py_INCREF(Py_None);
    1547         return Py_None;
     1670    HKEY hKey;
     1671    PyObject *obKey;
     1672    HMODULE hMod;
     1673    typedef LONG (WINAPI *RERKFunc)(HKEY);
     1674    RERKFunc pfn = NULL;
     1675    LONG rc;
     1676
     1677    if (!PyArg_ParseTuple(args, "O:EnableReflectionKey", &obKey))
     1678        return NULL;
     1679    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1680        return NULL;
     1681
     1682    /* Only available on 64bit platforms, so we must load it
     1683       dynamically. */
     1684    hMod = GetModuleHandle("advapi32.dll");
     1685    if (hMod)
     1686        pfn = (RERKFunc)GetProcAddress(hMod,
     1687                                       "RegEnableReflectionKey");
     1688    if (!pfn) {
     1689        PyErr_SetString(PyExc_NotImplementedError,
     1690                        "not implemented on this platform");
     1691        return NULL;
     1692    }
     1693    Py_BEGIN_ALLOW_THREADS
     1694    rc = (*pfn)(hKey);
     1695    Py_END_ALLOW_THREADS
     1696    if (rc != ERROR_SUCCESS)
     1697        return PyErr_SetFromWindowsErrWithFunction(rc,
     1698                                                   "RegEnableReflectionKey");
     1699    Py_INCREF(Py_None);
     1700    return Py_None;
    15481701}
    15491702
     
    15511704PyQueryReflectionKey(PyObject *self, PyObject *args)
    15521705{
    1553         HKEY hKey;
    1554         PyObject *obKey;
    1555         HMODULE hMod;
    1556         typedef LONG (WINAPI *RQRKFunc)(HKEY, BOOL *);
    1557         RQRKFunc pfn = NULL;
    1558         BOOL result;
    1559         LONG rc;
    1560 
    1561         if (!PyArg_ParseTuple(args, "O:QueryReflectionKey", &obKey))
    1562                 return NULL;
    1563         if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
    1564                 return NULL;
    1565 
    1566         // Only available on 64bit platforms, so we must load it
    1567         // dynamically.
    1568         hMod = GetModuleHandle("advapi32.dll");
    1569         if (hMod)
    1570                 pfn = (RQRKFunc)GetProcAddress(hMod,
    1571                                                "RegQueryReflectionKey");
    1572         if (!pfn) {
    1573                 PyErr_SetString(PyExc_NotImplementedError,
    1574                                 "not implemented on this platform");
    1575                 return NULL;
    1576         }
    1577         Py_BEGIN_ALLOW_THREADS
    1578         rc = (*pfn)(hKey, &result);
    1579         Py_END_ALLOW_THREADS
    1580         if (rc != ERROR_SUCCESS)
    1581                 return PyErr_SetFromWindowsErrWithFunction(rc,
    1582                                                            "RegQueryReflectionKey");
    1583         return PyBool_FromLong(rc);
     1706    HKEY hKey;
     1707    PyObject *obKey;
     1708    HMODULE hMod;
     1709    typedef LONG (WINAPI *RQRKFunc)(HKEY, BOOL *);
     1710    RQRKFunc pfn = NULL;
     1711    BOOL result;
     1712    LONG rc;
     1713
     1714    if (!PyArg_ParseTuple(args, "O:QueryReflectionKey", &obKey))
     1715        return NULL;
     1716    if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
     1717        return NULL;
     1718
     1719    /* Only available on 64bit platforms, so we must load it
     1720       dynamically. */
     1721    hMod = GetModuleHandle("advapi32.dll");
     1722    if (hMod)
     1723        pfn = (RQRKFunc)GetProcAddress(hMod,
     1724                                       "RegQueryReflectionKey");
     1725    if (!pfn) {
     1726        PyErr_SetString(PyExc_NotImplementedError,
     1727                        "not implemented on this platform");
     1728        return NULL;
     1729    }
     1730    Py_BEGIN_ALLOW_THREADS
     1731    rc = (*pfn)(hKey, &result);
     1732    Py_END_ALLOW_THREADS
     1733    if (rc != ERROR_SUCCESS)
     1734        return PyErr_SetFromWindowsErrWithFunction(rc,
     1735                                                   "RegQueryReflectionKey");
     1736    return PyBool_FromLong(result);
    15841737}
    15851738
    15861739static struct PyMethodDef winreg_methods[] = {
    1587         {"CloseKey",         PyCloseKey,        METH_VARARGS, CloseKey_doc},
    1588         {"ConnectRegistry",  PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc},
    1589         {"CreateKey",        PyCreateKey,       METH_VARARGS, CreateKey_doc},
    1590         {"DeleteKey",        PyDeleteKey,       METH_VARARGS, DeleteKey_doc},
    1591         {"DeleteValue",      PyDeleteValue,     METH_VARARGS, DeleteValue_doc},
    1592         {"DisableReflectionKey", PyDisableReflectionKey, METH_VARARGS, DisableReflectionKey_doc},
    1593         {"EnableReflectionKey",  PyEnableReflectionKey,  METH_VARARGS, EnableReflectionKey_doc},
    1594         {"EnumKey",          PyEnumKey,         METH_VARARGS, EnumKey_doc},
    1595         {"EnumValue",        PyEnumValue,       METH_VARARGS, EnumValue_doc},
    1596         {"ExpandEnvironmentStrings", PyExpandEnvironmentStrings, METH_VARARGS,
    1597                 ExpandEnvironmentStrings_doc },
    1598         {"FlushKey",         PyFlushKey,        METH_VARARGS, FlushKey_doc},
    1599         {"LoadKey",          PyLoadKey,         METH_VARARGS, LoadKey_doc},
    1600         {"OpenKey",          PyOpenKey,         METH_VARARGS, OpenKey_doc},
    1601         {"OpenKeyEx",        PyOpenKey,         METH_VARARGS, OpenKeyEx_doc},
    1602         {"QueryValue",       PyQueryValue,      METH_VARARGS, QueryValue_doc},
    1603         {"QueryValueEx",     PyQueryValueEx,    METH_VARARGS, QueryValueEx_doc},
    1604         {"QueryInfoKey",     PyQueryInfoKey,    METH_VARARGS, QueryInfoKey_doc},
    1605         {"QueryReflectionKey",PyQueryReflectionKey,METH_VARARGS, QueryReflectionKey_doc},
    1606         {"SaveKey",          PySaveKey,         METH_VARARGS, SaveKey_doc},
    1607         {"SetValue",         PySetValue,        METH_VARARGS, SetValue_doc},
    1608         {"SetValueEx",       PySetValueEx,      METH_VARARGS, SetValueEx_doc},
    1609         NULL,
     1740    {"CloseKey",         PyCloseKey,        METH_VARARGS, CloseKey_doc},
     1741    {"ConnectRegistry",  PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc},
     1742    {"CreateKey",        PyCreateKey,       METH_VARARGS, CreateKey_doc},
     1743    {"CreateKeyEx",      PyCreateKeyEx,     METH_VARARGS, CreateKeyEx_doc},
     1744    {"DeleteKey",        PyDeleteKey,       METH_VARARGS, DeleteKey_doc},
     1745    {"DeleteKeyEx",      PyDeleteKeyEx,     METH_VARARGS, DeleteKeyEx_doc},
     1746    {"DeleteValue",      PyDeleteValue,     METH_VARARGS, DeleteValue_doc},
     1747    {"DisableReflectionKey", PyDisableReflectionKey, METH_VARARGS, DisableReflectionKey_doc},
     1748    {"EnableReflectionKey",  PyEnableReflectionKey,  METH_VARARGS, EnableReflectionKey_doc},
     1749    {"EnumKey",          PyEnumKey,         METH_VARARGS, EnumKey_doc},
     1750    {"EnumValue",        PyEnumValue,       METH_VARARGS, EnumValue_doc},
     1751    {"ExpandEnvironmentStrings", PyExpandEnvironmentStrings, METH_VARARGS,
     1752        ExpandEnvironmentStrings_doc },
     1753    {"FlushKey",         PyFlushKey,        METH_VARARGS, FlushKey_doc},
     1754    {"LoadKey",          PyLoadKey,         METH_VARARGS, LoadKey_doc},
     1755    {"OpenKey",          PyOpenKey,         METH_VARARGS, OpenKey_doc},
     1756    {"OpenKeyEx",        PyOpenKey,         METH_VARARGS, OpenKeyEx_doc},
     1757    {"QueryValue",       PyQueryValue,      METH_VARARGS, QueryValue_doc},
     1758    {"QueryValueEx",     PyQueryValueEx,    METH_VARARGS, QueryValueEx_doc},
     1759    {"QueryInfoKey",     PyQueryInfoKey,    METH_VARARGS, QueryInfoKey_doc},
     1760    {"QueryReflectionKey",PyQueryReflectionKey,METH_VARARGS, QueryReflectionKey_doc},
     1761    {"SaveKey",          PySaveKey,         METH_VARARGS, SaveKey_doc},
     1762    {"SetValue",         PySetValue,        METH_VARARGS, SetValue_doc},
     1763    {"SetValueEx",       PySetValueEx,      METH_VARARGS, SetValueEx_doc},
     1764    NULL,
    16101765};
    16111766
     
    16131768insint(PyObject * d, char * name, long value)
    16141769{
    1615         PyObject *v = PyInt_FromLong(value);
    1616         if (!v || PyDict_SetItemString(d, name, v))
    1617                 PyErr_Clear();
    1618         Py_XDECREF(v);
     1770    PyObject *v = PyInt_FromLong(value);
     1771    if (!v || PyDict_SetItemString(d, name, v))
     1772        PyErr_Clear();
     1773    Py_XDECREF(v);
    16191774}
    16201775
     
    16241779inskey(PyObject * d, char * name, HKEY key)
    16251780{
    1626         PyObject *v = PyLong_FromVoidPtr(key);
    1627         if (!v || PyDict_SetItemString(d, name, v))
    1628                 PyErr_Clear();
    1629         Py_XDECREF(v);
     1781    PyObject *v = PyLong_FromVoidPtr(key);
     1782    if (!v || PyDict_SetItemString(d, name, v))
     1783        PyErr_Clear();
     1784    Py_XDECREF(v);
    16301785}
    16311786
     
    16341789PyMODINIT_FUNC init_winreg(void)
    16351790{
    1636         PyObject *m, *d;
    1637         m = Py_InitModule3("_winreg", winreg_methods, module_doc);
    1638         if (m == NULL)
    1639                 return;
    1640         d = PyModule_GetDict(m);
    1641         PyHKEY_Type.ob_type = &PyType_Type;
    1642         PyHKEY_Type.tp_doc = PyHKEY_doc;
    1643         Py_INCREF(&PyHKEY_Type);
    1644         if (PyDict_SetItemString(d, "HKEYType",
    1645                                  (PyObject *)&PyHKEY_Type) != 0)
    1646                 return;
    1647         Py_INCREF(PyExc_WindowsError);
    1648         if (PyDict_SetItemString(d, "error",
    1649                                  PyExc_WindowsError) != 0)
    1650                 return;
    1651 
    1652         /* Add the relevant constants */
    1653         ADD_KEY(HKEY_CLASSES_ROOT);
    1654         ADD_KEY(HKEY_CURRENT_USER);
    1655         ADD_KEY(HKEY_LOCAL_MACHINE);
    1656         ADD_KEY(HKEY_USERS);
    1657         ADD_KEY(HKEY_PERFORMANCE_DATA);
     1791    PyObject *m, *d;
     1792    m = Py_InitModule3("_winreg", winreg_methods, module_doc);
     1793    if (m == NULL)
     1794        return;
     1795    d = PyModule_GetDict(m);
     1796    if (PyType_Ready(&PyHKEY_Type) < 0)
     1797        return;
     1798    PyHKEY_Type.tp_doc = PyHKEY_doc;
     1799    Py_INCREF(&PyHKEY_Type);
     1800    if (PyDict_SetItemString(d, "HKEYType",
     1801                             (PyObject *)&PyHKEY_Type) != 0)
     1802        return;
     1803    Py_INCREF(PyExc_WindowsError);
     1804    if (PyDict_SetItemString(d, "error",
     1805                             PyExc_WindowsError) != 0)
     1806        return;
     1807
     1808    /* Add the relevant constants */
     1809    ADD_KEY(HKEY_CLASSES_ROOT);
     1810    ADD_KEY(HKEY_CURRENT_USER);
     1811    ADD_KEY(HKEY_LOCAL_MACHINE);
     1812    ADD_KEY(HKEY_USERS);
     1813    ADD_KEY(HKEY_PERFORMANCE_DATA);
    16581814#ifdef HKEY_CURRENT_CONFIG
    1659         ADD_KEY(HKEY_CURRENT_CONFIG);
     1815    ADD_KEY(HKEY_CURRENT_CONFIG);
    16601816#endif
    16611817#ifdef HKEY_DYN_DATA
    1662         ADD_KEY(HKEY_DYN_DATA);
     1818    ADD_KEY(HKEY_DYN_DATA);
    16631819#endif
    1664         ADD_INT(KEY_QUERY_VALUE);
    1665         ADD_INT(KEY_SET_VALUE);
    1666         ADD_INT(KEY_CREATE_SUB_KEY);
    1667         ADD_INT(KEY_ENUMERATE_SUB_KEYS);
    1668         ADD_INT(KEY_NOTIFY);
    1669         ADD_INT(KEY_CREATE_LINK);
    1670         ADD_INT(KEY_READ);
    1671         ADD_INT(KEY_WRITE);
    1672         ADD_INT(KEY_EXECUTE);
    1673         ADD_INT(KEY_ALL_ACCESS);
     1820    ADD_INT(KEY_QUERY_VALUE);
     1821    ADD_INT(KEY_SET_VALUE);
     1822    ADD_INT(KEY_CREATE_SUB_KEY);
     1823    ADD_INT(KEY_ENUMERATE_SUB_KEYS);
     1824    ADD_INT(KEY_NOTIFY);
     1825    ADD_INT(KEY_CREATE_LINK);
     1826    ADD_INT(KEY_READ);
     1827    ADD_INT(KEY_WRITE);
     1828    ADD_INT(KEY_EXECUTE);
     1829    ADD_INT(KEY_ALL_ACCESS);
    16741830#ifdef KEY_WOW64_64KEY
    1675         ADD_INT(KEY_WOW64_64KEY);
     1831    ADD_INT(KEY_WOW64_64KEY);
    16761832#endif
    16771833#ifdef KEY_WOW64_32KEY
    1678         ADD_INT(KEY_WOW64_32KEY);
     1834    ADD_INT(KEY_WOW64_32KEY);
    16791835#endif
    1680         ADD_INT(REG_OPTION_RESERVED);
    1681         ADD_INT(REG_OPTION_NON_VOLATILE);
    1682         ADD_INT(REG_OPTION_VOLATILE);
    1683         ADD_INT(REG_OPTION_CREATE_LINK);
    1684         ADD_INT(REG_OPTION_BACKUP_RESTORE);
    1685         ADD_INT(REG_OPTION_OPEN_LINK);
    1686         ADD_INT(REG_LEGAL_OPTION);
    1687         ADD_INT(REG_CREATED_NEW_KEY);
    1688         ADD_INT(REG_OPENED_EXISTING_KEY);
    1689         ADD_INT(REG_WHOLE_HIVE_VOLATILE);
    1690         ADD_INT(REG_REFRESH_HIVE);
    1691         ADD_INT(REG_NO_LAZY_FLUSH);
    1692         ADD_INT(REG_NOTIFY_CHANGE_NAME);
    1693         ADD_INT(REG_NOTIFY_CHANGE_ATTRIBUTES);
    1694         ADD_INT(REG_NOTIFY_CHANGE_LAST_SET);
    1695         ADD_INT(REG_NOTIFY_CHANGE_SECURITY);
    1696         ADD_INT(REG_LEGAL_CHANGE_FILTER);
    1697         ADD_INT(REG_NONE);
    1698         ADD_INT(REG_SZ);
    1699         ADD_INT(REG_EXPAND_SZ);
    1700         ADD_INT(REG_BINARY);
    1701         ADD_INT(REG_DWORD);
    1702         ADD_INT(REG_DWORD_LITTLE_ENDIAN);
    1703         ADD_INT(REG_DWORD_BIG_ENDIAN);
    1704         ADD_INT(REG_LINK);
    1705         ADD_INT(REG_MULTI_SZ);
    1706         ADD_INT(REG_RESOURCE_LIST);
    1707         ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR);
    1708         ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST);
    1709 }
    1710 
     1836    ADD_INT(REG_OPTION_RESERVED);
     1837    ADD_INT(REG_OPTION_NON_VOLATILE);
     1838    ADD_INT(REG_OPTION_VOLATILE);
     1839    ADD_INT(REG_OPTION_CREATE_LINK);
     1840    ADD_INT(REG_OPTION_BACKUP_RESTORE);
     1841    ADD_INT(REG_OPTION_OPEN_LINK);
     1842    ADD_INT(REG_LEGAL_OPTION);
     1843    ADD_INT(REG_CREATED_NEW_KEY);
     1844    ADD_INT(REG_OPENED_EXISTING_KEY);
     1845    ADD_INT(REG_WHOLE_HIVE_VOLATILE);
     1846    ADD_INT(REG_REFRESH_HIVE);
     1847    ADD_INT(REG_NO_LAZY_FLUSH);
     1848    ADD_INT(REG_NOTIFY_CHANGE_NAME);
     1849    ADD_INT(REG_NOTIFY_CHANGE_ATTRIBUTES);
     1850    ADD_INT(REG_NOTIFY_CHANGE_LAST_SET);
     1851    ADD_INT(REG_NOTIFY_CHANGE_SECURITY);
     1852    ADD_INT(REG_LEGAL_CHANGE_FILTER);
     1853    ADD_INT(REG_NONE);
     1854    ADD_INT(REG_SZ);
     1855    ADD_INT(REG_EXPAND_SZ);
     1856    ADD_INT(REG_BINARY);
     1857    ADD_INT(REG_DWORD);
     1858    ADD_INT(REG_DWORD_LITTLE_ENDIAN);
     1859    ADD_INT(REG_DWORD_BIG_ENDIAN);
     1860    ADD_INT(REG_LINK);
     1861    ADD_INT(REG_MULTI_SZ);
     1862    ADD_INT(REG_RESOURCE_LIST);
     1863    ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR);
     1864    ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST);
     1865}
     1866
  • python/vendor/current/PC/bdist_wininst/archive.h

    r2 r388  
    1515
    1616struct eof_cdir {
    17         long tag;       /* must be 0x06054b50 */
    18         short disknum;
    19         short firstdisk;
    20         short nTotalCDirThis;
    21         short nTotalCDir;
    22         long nBytesCDir;
    23         long ofsCDir;
    24         short commentlen;
     17    long tag;           /* must be 0x06054b50 */
     18    short disknum;
     19    short firstdisk;
     20    short nTotalCDirThis;
     21    short nTotalCDir;
     22    long nBytesCDir;
     23    long ofsCDir;
     24    short commentlen;
    2525};
    2626
    2727struct cdir {
    28         long tag;       /* must be 0x02014b50 */
    29         short version_made;
    30         short version_extract;
    31         short gp_bitflag;
    32         short comp_method;
    33         short last_mod_file_time;
    34         short last_mod_file_date;
    35         long crc32;
    36         long comp_size;
    37         long uncomp_size;
    38         short fname_length;
    39         short extra_length;
    40         short comment_length;
    41         short disknum_start;
    42         short int_file_attr;
    43         long ext_file_attr;
    44         long ofs_local_header;
     28    long tag;           /* must be 0x02014b50 */
     29    short version_made;
     30    short version_extract;
     31    short gp_bitflag;
     32    short comp_method;
     33    short last_mod_file_time;
     34    short last_mod_file_date;
     35    long crc32;
     36    long comp_size;
     37    long uncomp_size;
     38    short fname_length;
     39    short extra_length;
     40    short comment_length;
     41    short disknum_start;
     42    short int_file_attr;
     43    long ext_file_attr;
     44    long ofs_local_header;
    4545};
    4646
    4747struct fhdr {
    48         long tag;       /* must be 0x04034b50 */
    49         short version_needed;
    50         short flags;
    51         short method;
    52         short last_mod_file_time;
    53         short last_mod_file_date;
    54         long crc32;
    55         long comp_size;
    56         long uncomp_size;
    57         short fname_length;
    58         short extra_length;
     48    long tag;           /* must be 0x04034b50 */
     49    short version_needed;
     50    short flags;
     51    short method;
     52    short last_mod_file_time;
     53    short last_mod_file_date;
     54    long crc32;
     55    long comp_size;
     56    long uncomp_size;
     57    short fname_length;
     58    short extra_length;
    5959};
    6060
    6161
    6262struct meta_data_hdr {
    63         int tag;
    64         int uncomp_size;
    65         int bitmap_size;
     63    int tag;
     64    int uncomp_size;
     65    int bitmap_size;
    6666};
    6767
     
    7171
    7272typedef struct tagSCHEME {
    73         char *name;
    74         char *prefix;
     73    char *name;
     74    char *prefix;
    7575} SCHEME;
    7676
     
    7979extern BOOL
    8080extract_file(char *dst, char *src, int method, int comp_size,
    81              int uncomp_size, NOTIFYPROC notify);
     81             int uncomp_size, NOTIFYPROC notify);
    8282
    8383extern BOOL
    8484unzip_archive(SCHEME *scheme, char *dirname, char *data,
    85               DWORD size,  NOTIFYPROC notify);
     85              DWORD size,  NOTIFYPROC notify);
    8686
    8787extern char *
    8888map_new_file(DWORD flags, char *filename, char
    89              *pathname_part, int size,
    90              WORD wFatDate, WORD wFatTime,
    91              NOTIFYPROC callback);
     89             *pathname_part, int size,
     90             WORD wFatDate, WORD wFatTime,
     91             NOTIFYPROC callback);
    9292
    9393extern BOOL
    9494ensure_directory (char *pathname, char *new_part,
    95                   NOTIFYPROC callback);
     95                  NOTIFYPROC callback);
    9696
    9797/* codes for NOITIFYPROC */
  • python/vendor/current/PC/bdist_wininst/extract.c

    r2 r388  
    2020static void normpath(char *path)
    2121{
    22         while (path && *path) {
    23                 if (*path == '/')
    24                         *path = '\\';
    25                 ++path;
    26         }
     22    while (path && *path) {
     23        if (*path == '/')
     24            *path = '\\';
     25        ++path;
     26    }
    2727}
    2828
    2929BOOL ensure_directory(char *pathname, char *new_part, NOTIFYPROC notify)
    3030{
    31         while (new_part && *new_part && (new_part = strchr(new_part, '\\'))) {
    32                 DWORD attr;
    33                 *new_part = '\0';
    34                 attr = GetFileAttributes(pathname);
    35                 if (attr == -1) {
    36                         /* nothing found */
    37                         if (!CreateDirectory(pathname, NULL) && notify)
    38                                 notify(SYSTEM_ERROR,
    39                                        "CreateDirectory (%s)", pathname);
    40                         else
    41                                 notify(DIR_CREATED, pathname);
    42                 }
    43                 if (attr & FILE_ATTRIBUTE_DIRECTORY) {
    44                         ;
    45                 } else {
    46                         SetLastError(183);
    47                         if (notify)
    48                                 notify(SYSTEM_ERROR,
    49                                        "CreateDirectory (%s)", pathname);
    50                 }
    51                 *new_part = '\\';
    52                 ++new_part;
    53         }
    54         return TRUE;
    55 }
    56 
    57 /* XXX Should better explicitely specify
     31    while (new_part && *new_part && (new_part = strchr(new_part, '\\'))) {
     32        DWORD attr;
     33        *new_part = '\0';
     34        attr = GetFileAttributes(pathname);
     35        if (attr == -1) {
     36            /* nothing found */
     37            if (!CreateDirectory(pathname, NULL) && notify)
     38                notify(SYSTEM_ERROR,
     39                       "CreateDirectory (%s)", pathname);
     40            else
     41                notify(DIR_CREATED, pathname);
     42        }
     43        if (attr & FILE_ATTRIBUTE_DIRECTORY) {
     44            ;
     45        } else {
     46            SetLastError(183);
     47            if (notify)
     48                notify(SYSTEM_ERROR,
     49                       "CreateDirectory (%s)", pathname);
     50        }
     51        *new_part = '\\';
     52        ++new_part;
     53    }
     54    return TRUE;
     55}
     56
     57/* XXX Should better explicitly specify
    5858 * uncomp_size and file_times instead of pfhdr!
    5959 */
    6060char *map_new_file(DWORD flags, char *filename,
    61                    char *pathname_part, int size,
    62                    WORD wFatDate, WORD wFatTime,
    63                    NOTIFYPROC notify)
    64 {
    65         HANDLE hFile, hFileMapping;
    66         char *dst;
    67         FILETIME ft;
     61                   char *pathname_part, int size,
     62                   WORD wFatDate, WORD wFatTime,
     63                   NOTIFYPROC notify)
     64{
     65    HANDLE hFile, hFileMapping;
     66    char *dst;
     67    FILETIME ft;
    6868
    6969  try_again:
    70         if (!flags)
    71                 flags = CREATE_NEW;
    72         hFile = CreateFile(filename,
    73                            GENERIC_WRITE | GENERIC_READ,
    74                            0, NULL,
    75                            flags,
    76                            FILE_ATTRIBUTE_NORMAL, NULL);
    77         if (hFile == INVALID_HANDLE_VALUE) {
    78                 DWORD x = GetLastError();
    79                 switch (x) {
    80                 case ERROR_FILE_EXISTS:
    81                         if (notify && notify(CAN_OVERWRITE, filename))
    82                                 hFile = CreateFile(filename,
    83                                                    GENERIC_WRITE|GENERIC_READ,
    84                                                    0, NULL,
    85                                                    CREATE_ALWAYS,
    86                                                    FILE_ATTRIBUTE_NORMAL,
    87                                                    NULL);
    88                         else {
    89                                 if (notify)
    90                                         notify(FILE_OVERWRITTEN, filename);
    91                                 return NULL;
    92                         }
    93                         break;
    94                 case ERROR_PATH_NOT_FOUND:
    95                         if (ensure_directory(filename, pathname_part, notify))
    96                                 goto try_again;
    97                         else
    98                                 return FALSE;
    99                         break;
    100                 default:
    101                         SetLastError(x);
    102                         break;
    103                 }
    104         }
    105         if (hFile == INVALID_HANDLE_VALUE) {
    106                 if (notify)
    107                         notify (SYSTEM_ERROR, "CreateFile (%s)", filename);
    108                 return NULL;
    109         }
    110 
    111         if (notify)
    112                 notify(FILE_CREATED, filename);
    113 
    114         DosDateTimeToFileTime(wFatDate, wFatTime, &ft);
    115         SetFileTime(hFile, &ft, &ft, &ft);
    116 
    117 
    118         if (size == 0) {
    119                 /* We cannot map a zero-length file (Also it makes
    120                    no sense */
    121                 CloseHandle(hFile);
    122                 return NULL;
    123         }
    124 
    125         hFileMapping = CreateFileMapping(hFile,
    126                                         NULL, PAGE_READWRITE, 0, size, NULL);
    127 
    128         CloseHandle(hFile);
    129 
    130         if (hFileMapping == INVALID_HANDLE_VALUE) {
    131                 if (notify)
    132                         notify(SYSTEM_ERROR,
    133                                "CreateFileMapping (%s)", filename);
    134                 return NULL;
    135         }
    136 
    137         dst = MapViewOfFile(hFileMapping,
    138                             FILE_MAP_WRITE, 0, 0, 0);
    139 
    140         CloseHandle(hFileMapping);
    141 
    142         if (!dst) {
    143                 if (notify)
    144                         notify(SYSTEM_ERROR, "MapViewOfFile (%s)", filename);
    145                 return NULL;
    146         }
    147         return dst;
     70    if (!flags)
     71        flags = CREATE_NEW;
     72    hFile = CreateFile(filename,
     73                       GENERIC_WRITE | GENERIC_READ,
     74                       0, NULL,
     75                       flags,
     76                       FILE_ATTRIBUTE_NORMAL, NULL);
     77    if (hFile == INVALID_HANDLE_VALUE) {
     78        DWORD x = GetLastError();
     79        switch (x) {
     80        case ERROR_FILE_EXISTS:
     81            if (notify && notify(CAN_OVERWRITE, filename))
     82                hFile = CreateFile(filename,
     83                                   GENERIC_WRITE|GENERIC_READ,
     84                                   0, NULL,
     85                                   CREATE_ALWAYS,
     86                                   FILE_ATTRIBUTE_NORMAL,
     87                                   NULL);
     88            else {
     89                if (notify)
     90                    notify(FILE_OVERWRITTEN, filename);
     91                return NULL;
     92            }
     93            break;
     94        case ERROR_PATH_NOT_FOUND:
     95            if (ensure_directory(filename, pathname_part, notify))
     96                goto try_again;
     97            else
     98                return FALSE;
     99            break;
     100        default:
     101            SetLastError(x);
     102            break;
     103        }
     104    }
     105    if (hFile == INVALID_HANDLE_VALUE) {
     106        if (notify)
     107            notify (SYSTEM_ERROR, "CreateFile (%s)", filename);
     108        return NULL;
     109    }
     110
     111    if (notify)
     112        notify(FILE_CREATED, filename);
     113
     114    DosDateTimeToFileTime(wFatDate, wFatTime, &ft);
     115    SetFileTime(hFile, &ft, &ft, &ft);
     116
     117
     118    if (size == 0) {
     119        /* We cannot map a zero-length file (Also it makes
     120           no sense */
     121        CloseHandle(hFile);
     122        return NULL;
     123    }
     124
     125    hFileMapping = CreateFileMapping(hFile,
     126                                    NULL, PAGE_READWRITE, 0, size, NULL);
     127
     128    CloseHandle(hFile);
     129
     130    if (hFileMapping == INVALID_HANDLE_VALUE) {
     131        if (notify)
     132            notify(SYSTEM_ERROR,
     133                   "CreateFileMapping (%s)", filename);
     134        return NULL;
     135    }
     136
     137    dst = MapViewOfFile(hFileMapping,
     138                        FILE_MAP_WRITE, 0, 0, 0);
     139
     140    CloseHandle(hFileMapping);
     141
     142    if (!dst) {
     143        if (notify)
     144            notify(SYSTEM_ERROR, "MapViewOfFile (%s)", filename);
     145        return NULL;
     146    }
     147    return dst;
    148148}
    149149
     
    151151BOOL
    152152extract_file(char *dst, char *src, int method, int comp_size,
    153              int uncomp_size, NOTIFYPROC notify)
    154 {
    155         z_stream zstream;
    156         int result;
    157 
    158         if (method == Z_DEFLATED) {
    159                 int x;
    160                 memset(&zstream, 0, sizeof(zstream));
    161                 zstream.next_in = src;
    162                 zstream.avail_in = comp_size+1;
    163                 zstream.next_out = dst;
    164                 zstream.avail_out = uncomp_size;
     153             int uncomp_size, NOTIFYPROC notify)
     154{
     155    z_stream zstream;
     156    int result;
     157
     158    if (method == Z_DEFLATED) {
     159        int x;
     160        memset(&zstream, 0, sizeof(zstream));
     161        zstream.next_in = src;
     162        zstream.avail_in = comp_size+1;
     163        zstream.next_out = dst;
     164        zstream.avail_out = uncomp_size;
    165165
    166166/* Apparently an undocumented feature of zlib: Set windowsize
    167    to negative values to supress the gzip header and be compatible with
     167   to negative values to suppress the gzip header and be compatible with
    168168   zip! */
    169                 result = TRUE;
    170                 if (Z_OK != (x = inflateInit2(&zstream, -15))) {
    171                         if (notify)
    172                                 notify(ZLIB_ERROR,
    173                                        "inflateInit2 returns %d", x);
    174                         result = FALSE;
    175                         goto cleanup;
    176                 }
    177                 if (Z_STREAM_END != (x = inflate(&zstream, Z_FINISH))) {
    178                         if (notify)
    179                                 notify(ZLIB_ERROR,
    180                                        "inflate returns %d", x);
    181                         result = FALSE;
    182                 }
    183           cleanup:
    184                 if (Z_OK != (x = inflateEnd(&zstream))) {
    185                         if (notify)
    186                                 notify (ZLIB_ERROR,
    187                                         "inflateEnd returns %d", x);
    188                         result = FALSE;
    189                 }
    190         } else if (method == 0) {
    191                 memcpy(dst, src, uncomp_size);
    192                 result = TRUE;
    193         } else
    194                 result = FALSE;
    195         UnmapViewOfFile(dst);
    196         return result;
     169        result = TRUE;
     170        if (Z_OK != (x = inflateInit2(&zstream, -15))) {
     171            if (notify)
     172                notify(ZLIB_ERROR,
     173                       "inflateInit2 returns %d", x);
     174            result = FALSE;
     175            goto cleanup;
     176        }
     177        if (Z_STREAM_END != (x = inflate(&zstream, Z_FINISH))) {
     178            if (notify)
     179                notify(ZLIB_ERROR,
     180                       "inflate returns %d", x);
     181            result = FALSE;
     182        }
     183      cleanup:
     184        if (Z_OK != (x = inflateEnd(&zstream))) {
     185            if (notify)
     186                notify (ZLIB_ERROR,
     187                    "inflateEnd returns %d", x);
     188            result = FALSE;
     189        }
     190    } else if (method == 0) {
     191        memcpy(dst, src, uncomp_size);
     192        result = TRUE;
     193    } else
     194        result = FALSE;
     195    UnmapViewOfFile(dst);
     196    return result;
    197197}
    198198
     
    202202BOOL
    203203unzip_archive(SCHEME *scheme, char *dirname, char *data, DWORD size,
    204               NOTIFYPROC notify)
    205 {
    206         int n;
    207         char pathname[MAX_PATH];
    208         char *new_part;
    209 
    210         /* read the end of central directory record */
    211         struct eof_cdir *pe = (struct eof_cdir *)&data[size - sizeof
    212                                                        (struct eof_cdir)];
    213 
    214         int arc_start = size - sizeof (struct eof_cdir) - pe->nBytesCDir -
    215                 pe->ofsCDir;
    216 
    217         /* set position to start of central directory */
    218         int pos = arc_start + pe->ofsCDir;
    219 
    220         /* make sure this is a zip file */
    221         if (pe->tag != 0x06054b50)
    222                 return FALSE;
    223    
    224         /* Loop through the central directory, reading all entries */
    225         for (n = 0; n < pe->nTotalCDir; ++n) {
    226                 int i;
    227                 char *fname;
    228                 char *pcomp;
    229                 char *dst;
    230                 struct cdir *pcdir;
    231                 struct fhdr *pfhdr;
    232 
    233                 pcdir = (struct cdir *)&data[pos];
    234                 pfhdr = (struct fhdr *)&data[pcdir->ofs_local_header +
    235                                              arc_start];
    236 
    237                 if (pcdir->tag != 0x02014b50)
    238                         return FALSE;
    239                 if (pfhdr->tag != 0x04034b50)
    240                         return FALSE;
    241                 pos += sizeof(struct cdir);
    242                 fname = (char *)&data[pos]; /* This is not null terminated! */
    243                 pos += pcdir->fname_length + pcdir->extra_length +
    244                         pcdir->comment_length;
    245 
    246                 pcomp = &data[pcdir->ofs_local_header
    247                               + sizeof(struct fhdr)
    248                               + arc_start
    249                               + pfhdr->fname_length
    250                               + pfhdr->extra_length];
    251 
    252                 /* dirname is the Python home directory (prefix) */
    253                 strcpy(pathname, dirname);
    254                 if (pathname[strlen(pathname)-1] != '\\')
    255                         strcat(pathname, "\\");
    256                 new_part = &pathname[lstrlen(pathname)];
    257                 /* we must now match the first part of the pathname
    258                 * in the archive to a component in the installation
    259                 * scheme (PURELIB, PLATLIB, HEADERS, SCRIPTS, or DATA)
    260                 * and replace this part by the one in the scheme to use
    261                 */
    262                 for (i = 0; scheme[i].name; ++i) {
    263                         if (0 == strnicmp(scheme[i].name, fname,
    264                                           strlen(scheme[i].name))) {
    265                                 char *rest;
    266                                 int len;
    267                                
    268                                 /* length of the replaced part */
    269                                 int namelen = strlen(scheme[i].name);
    270                                
    271                                 strcat(pathname, scheme[i].prefix);
    272                                
    273                                 rest = fname + namelen;
    274                                 len = pfhdr->fname_length - namelen;
    275                                
    276                                 if ((pathname[strlen(pathname)-1] != '\\')
    277                                     && (pathname[strlen(pathname)-1] != '/'))
    278                                         strcat(pathname, "\\");
    279                                 /* Now that pathname ends with a separator,
    280                                 * we must make sure rest does not start with
    281                                 * an additional one.
    282                                 */
    283                                 if ((rest[0] == '\\') || (rest[0] == '/')) {
    284                                         ++rest;
    285                                         --len;
    286                                 }
    287 
    288                                 strncat(pathname, rest, len);
    289                                 goto Done;
    290                         }
    291                 }
    292                 /* no prefix to replace found, go unchanged */
    293                 strncat(pathname, fname, pfhdr->fname_length);
    294           Done:
    295                 normpath(pathname);
    296                 if (pathname[strlen(pathname)-1] != '\\') {
    297                         /*
    298                         * The local file header (pfhdr) does not always
    299                         * contain the compressed and uncompressed sizes of
    300                         * the data depending on bit 3 of the flags field.  So
    301                         * it seems better to use the data from the central
    302                         * directory (pcdir).
    303                         */
    304                         dst = map_new_file(0, pathname, new_part,
    305                                            pcdir->uncomp_size,
    306                                            pcdir->last_mod_file_date,
    307                                            pcdir->last_mod_file_time, notify);
    308                         if (dst) {
    309                                 if (!extract_file(dst, pcomp, pfhdr->method,
    310                                                   pcdir->comp_size,
    311                                                   pcdir->uncomp_size,
    312                                                   notify))
    313                                         return FALSE;
    314                         } /* else ??? */
    315                 }
    316                 if (notify)
    317                         notify(NUM_FILES, new_part, (int)pe->nTotalCDir,
    318                                (int)n+1);
    319         }
    320         return TRUE;
    321 }
     204              NOTIFYPROC notify)
     205{
     206    int n;
     207    char pathname[MAX_PATH];
     208    char *new_part;
     209
     210    /* read the end of central directory record */
     211    struct eof_cdir *pe = (struct eof_cdir *)&data[size - sizeof
     212                                                   (struct eof_cdir)];
     213
     214    int arc_start = size - sizeof (struct eof_cdir) - pe->nBytesCDir -
     215        pe->ofsCDir;
     216
     217    /* set position to start of central directory */
     218    int pos = arc_start + pe->ofsCDir;
     219
     220    /* make sure this is a zip file */
     221    if (pe->tag != 0x06054b50)
     222        return FALSE;
     223
     224    /* Loop through the central directory, reading all entries */
     225    for (n = 0; n < pe->nTotalCDir; ++n) {
     226        int i;
     227        char *fname;
     228        char *pcomp;
     229        char *dst;
     230        struct cdir *pcdir;
     231        struct fhdr *pfhdr;
     232
     233        pcdir = (struct cdir *)&data[pos];
     234        pfhdr = (struct fhdr *)&data[pcdir->ofs_local_header +
     235                                     arc_start];
     236
     237        if (pcdir->tag != 0x02014b50)
     238            return FALSE;
     239        if (pfhdr->tag != 0x04034b50)
     240            return FALSE;
     241        pos += sizeof(struct cdir);
     242        fname = (char *)&data[pos]; /* This is not null terminated! */
     243        pos += pcdir->fname_length + pcdir->extra_length +
     244            pcdir->comment_length;
     245
     246        pcomp = &data[pcdir->ofs_local_header
     247                      + sizeof(struct fhdr)
     248                      + arc_start
     249                      + pfhdr->fname_length
     250                      + pfhdr->extra_length];
     251
     252        /* dirname is the Python home directory (prefix) */
     253        strcpy(pathname, dirname);
     254        if (pathname[strlen(pathname)-1] != '\\')
     255            strcat(pathname, "\\");
     256        new_part = &pathname[lstrlen(pathname)];
     257        /* we must now match the first part of the pathname
     258        * in the archive to a component in the installation
     259        * scheme (PURELIB, PLATLIB, HEADERS, SCRIPTS, or DATA)
     260        * and replace this part by the one in the scheme to use
     261        */
     262        for (i = 0; scheme[i].name; ++i) {
     263            if (0 == strnicmp(scheme[i].name, fname,
     264                              strlen(scheme[i].name))) {
     265                char *rest;
     266                int len;
     267
     268                /* length of the replaced part */
     269                int namelen = strlen(scheme[i].name);
     270
     271                strcat(pathname, scheme[i].prefix);
     272
     273                rest = fname + namelen;
     274                len = pfhdr->fname_length - namelen;
     275
     276                if ((pathname[strlen(pathname)-1] != '\\')
     277                    && (pathname[strlen(pathname)-1] != '/'))
     278                    strcat(pathname, "\\");
     279                /* Now that pathname ends with a separator,
     280                * we must make sure rest does not start with
     281                * an additional one.
     282                */
     283                if ((rest[0] == '\\') || (rest[0] == '/')) {
     284                    ++rest;
     285                    --len;
     286                }
     287
     288                strncat(pathname, rest, len);
     289                goto Done;
     290            }
     291        }
     292        /* no prefix to replace found, go unchanged */
     293        strncat(pathname, fname, pfhdr->fname_length);
     294      Done:
     295        normpath(pathname);
     296        if (pathname[strlen(pathname)-1] != '\\') {
     297            /*
     298            * The local file header (pfhdr) does not always
     299            * contain the compressed and uncompressed sizes of
     300            * the data depending on bit 3 of the flags field.  So
     301            * it seems better to use the data from the central
     302            * directory (pcdir).
     303            */
     304            dst = map_new_file(0, pathname, new_part,
     305                               pcdir->uncomp_size,
     306                               pcdir->last_mod_file_date,
     307                               pcdir->last_mod_file_time, notify);
     308            if (dst) {
     309                if (!extract_file(dst, pcomp, pfhdr->method,
     310                                  pcdir->comp_size,
     311                                  pcdir->uncomp_size,
     312                                  notify))
     313                    return FALSE;
     314            } /* else ??? */
     315        }
     316        if (notify)
     317            notify(NUM_FILES, new_part, (int)pe->nTotalCDir,
     318                   (int)n+1);
     319    }
     320    return TRUE;
     321}
  • python/vendor/current/PC/bdist_wininst/install.c

    r2 r388  
    1111 * Written by Thomas Heller, May 2000
    1212 *
    13  * $Id: install.c 69095 2009-01-29 12:31:51Z mark.hammond $
     13 * $Id$
    1414 */
    1515
     
    2121 * At runtime, the exefile has appended:
    2222 * - compressed setup-data in ini-format, containing the following sections:
    23  *      [metadata]
    24  *      author=Greg Ward
    25  *      author_email=gward@python.net
    26  *      description=Python Distribution Utilities
    27  *      licence=Python
    28  *      name=Distutils
    29  *      url=http://www.python.org/sigs/distutils-sig/
    30  *      version=0.9pre
     23 *      [metadata]
     24 *      author=Greg Ward
     25 *      author_email=gward@python.net
     26 *      description=Python Distribution Utilities
     27 *      licence=Python
     28 *      name=Distutils
     29 *      url=http://www.python.org/sigs/distutils-sig/
     30 *      version=0.9pre
    3131 *
    32  *      [Setup]
    33  *      info= text to be displayed in the edit-box
    34  *      title= to be displayed by this program
    35  *      target_version = if present, python version required
    36  *      pyc_compile = if 0, do not compile py to pyc
    37  *      pyo_compile = if 0, do not compile py to pyo
     32 *      [Setup]
     33 *      info= text to be displayed in the edit-box
     34 *      title= to be displayed by this program
     35 *      target_version = if present, python version required
     36 *      pyc_compile = if 0, do not compile py to pyc
     37 *      pyo_compile = if 0, do not compile py to pyo
    3838 *
    3939 * - a struct meta_data_hdr, describing the above
     
    6363 *
    6464 * Finish the code so that we can use other python installations
    65  * additionaly to those found in the registry,
     65 * additionally to those found in the registry,
    6666 * and then #define USE_OTHER_PYTHON_VERSIONS
    6767 *
     
    119119HWND hDialog;
    120120
    121 char *ini_file;                 /* Full pathname of ini-file */
     121char *ini_file;                 /* Full pathname of ini-file */
    122122/* From ini-file */
    123 char info[4096];                /* [Setup] info= */
    124 char title[80];                 /* [Setup] title=, contains package name
    125                                    including version: "Distutils-1.0.1" */
    126 char target_version[10];        /* [Setup] target_version=, required python
    127                                    version or empty string */
    128 char build_info[80];            /* [Setup] build_info=, distutils version
    129                                    and build date */
    130 
    131 char meta_name[80];             /* package name without version like
    132                                    'Distutils' */
     123char info[4096];                /* [Setup] info= */
     124char title[80];                 /* [Setup] title=, contains package name
     125                                   including version: "Distutils-1.0.1" */
     126char target_version[10];        /* [Setup] target_version=, required python
     127                                   version or empty string */
     128char build_info[80];            /* [Setup] build_info=, distutils version
     129                                   and build date */
     130
     131char meta_name[80];             /* package name without version like
     132                                   'Distutils' */
    133133char install_script[MAX_PATH];
    134134char *pre_install_script; /* run before we install a single file */
     
    136136char user_access_control[10]; // one of 'auto', 'force', otherwise none.
    137137
    138 int py_major, py_minor;         /* Python version selected for installation */
    139 
    140 char *arc_data;                 /* memory mapped archive */
    141 DWORD arc_size;                 /* number of bytes in archive */
    142 int exe_size;                   /* number of bytes for exe-file portion */
     138int py_major, py_minor;         /* Python version selected for installation */
     139
     140char *arc_data;                 /* memory mapped archive */
     141DWORD arc_size;                 /* number of bytes in archive */
     142int exe_size;                   /* number of bytes for exe-file portion */
    143143char python_dir[MAX_PATH];
    144144char pythondll[MAX_PATH];
     
    148148HKEY hkey_root = (HKEY)-1;
    149149
    150 BOOL success;                   /* Installation successfull? */
     150BOOL success;                   /* Installation successful? */
    151151char *failure_reason = NULL;
    152152
     
    166166/* Note: purelib must be the FIRST entry! */
    167167SCHEME old_scheme[] = {
    168         { "PURELIB", "" },
    169         { "PLATLIB", "" },
    170         { "HEADERS", "" }, /* 'Include/dist_name' part already in archive */
    171         { "SCRIPTS", "Scripts\\" },
    172         { "DATA", "" },
    173         { NULL, NULL },
     168    { "PURELIB", "" },
     169    { "PLATLIB", "" },
     170    { "HEADERS", "" }, /* 'Include/dist_name' part already in archive */
     171    { "SCRIPTS", "Scripts\\" },
     172    { "DATA", "" },
     173    { NULL, NULL },
    174174};
    175175
    176176SCHEME new_scheme[] = {
    177         { "PURELIB", "Lib\\site-packages\\" },
    178         { "PLATLIB", "Lib\\site-packages\\" },
    179         { "HEADERS", "" }, /* 'Include/dist_name' part already in archive */
    180         { "SCRIPTS", "Scripts\\" },
    181         { "DATA", "" },
    182         { NULL, NULL },
     177    { "PURELIB", "Lib\\site-packages\\" },
     178    { "PLATLIB", "Lib\\site-packages\\" },
     179    { "HEADERS", "" }, /* 'Include/dist_name' part already in archive */
     180    { "SCRIPTS", "Scripts\\" },
     181    { "DATA", "" },
     182    { NULL, NULL },
    183183};
    184184
    185185static void unescape(char *dst, char *src, unsigned size)
    186186{
    187         char *eon;
    188         char ch;
    189 
    190         while (src && *src && (size > 2)) {
    191                 if (*src == '\\') {
    192                         switch (*++src) {
    193                         case 'n':
    194                                 ++src;
    195                                 *dst++ = '\r';
    196                                 *dst++ = '\n';
    197                                 size -= 2;
    198                                 break;
    199                         case 'r':
    200                                 ++src;
    201                                 *dst++ = '\r';
    202                                 --size;
    203                                 break;
    204                         case '0': case '1': case '2': case '3':
    205                                 ch = (char)strtol(src, &eon, 8);
    206                                 if (ch == '\n') {
    207                                         *dst++ = '\r';
    208                                         --size;
    209                                 }
    210                                 *dst++ = ch;
    211                                 --size;
    212                                 src = eon;
    213                         }
    214                 } else {
    215                         *dst++ = *src++;
    216                         --size;
    217                 }
    218         }
    219         *dst = '\0';
     187    char *eon;
     188    char ch;
     189
     190    while (src && *src && (size > 2)) {
     191        if (*src == '\\') {
     192            switch (*++src) {
     193            case 'n':
     194                ++src;
     195                *dst++ = '\r';
     196                *dst++ = '\n';
     197                size -= 2;
     198                break;
     199            case 'r':
     200                ++src;
     201                *dst++ = '\r';
     202                --size;
     203                break;
     204            case '0': case '1': case '2': case '3':
     205                ch = (char)strtol(src, &eon, 8);
     206                if (ch == '\n') {
     207                    *dst++ = '\r';
     208                    --size;
     209                }
     210                *dst++ = ch;
     211                --size;
     212                src = eon;
     213            }
     214        } else {
     215            *dst++ = *src++;
     216            --size;
     217        }
     218    }
     219    *dst = '\0';
    220220}
    221221
    222222static struct tagFile {
    223         char *path;
    224         struct tagFile *next;
     223    char *path;
     224    struct tagFile *next;
    225225} *file_list = NULL;
    226226
     
    228228{
    229229    if (failure_reason)
    230         free(failure_reason);
     230    free(failure_reason);
    231231    failure_reason = strdup(reason);
    232232    success = FALSE;
     
    235235{
    236236    if (!failure_reason)
    237         return "Installation failed.";
     237    return "Installation failed.";
    238238    return failure_reason;
    239239}
     
    241241static void add_to_filelist(char *path)
    242242{
    243         struct tagFile *p;
    244         p = (struct tagFile *)malloc(sizeof(struct tagFile));
    245         p->path = strdup(path);
    246         p->next = file_list;
    247         file_list = p;
     243    struct tagFile *p;
     244    p = (struct tagFile *)malloc(sizeof(struct tagFile));
     245    p->path = strdup(path);
     246    p->next = file_list;
     247    file_list = p;
    248248}
    249249
    250250static int do_compile_files(int (__cdecl * PyRun_SimpleString)(char *),
    251                              int optimize)
    252 {
    253         struct tagFile *p;
    254         int total, n;
    255         char Buffer[MAX_PATH + 64];
    256         int errors = 0;
    257 
    258         total = 0;
    259         p = file_list;
    260         while (p) {
    261                 ++total;
    262                 p = p->next;
    263         }
    264         SendDlgItemMessage(hDialog, IDC_PROGRESS, PBM_SETRANGE, 0,
    265                             MAKELPARAM(0, total));
    266         SendDlgItemMessage(hDialog, IDC_PROGRESS, PBM_SETPOS, 0, 0);
    267 
    268         n = 0;
    269         p = file_list;
    270         while (p) {
    271                 ++n;
    272                 wsprintf(Buffer,
    273                           "import py_compile; py_compile.compile (r'%s')",
    274                           p->path);
    275                 if (PyRun_SimpleString(Buffer)) {
    276                         ++errors;
    277                 }
    278                 /* We send the notification even if the files could not
    279                 * be created so that the uninstaller will remove them
    280                 * in case they are created later.
    281                 */
    282                 wsprintf(Buffer, "%s%c", p->path, optimize ? 'o' : 'c');
    283                 notify(FILE_CREATED, Buffer);
    284 
    285                 SendDlgItemMessage(hDialog, IDC_PROGRESS, PBM_SETPOS, n, 0);
    286                 SetDlgItemText(hDialog, IDC_INFO, p->path);
    287                 p = p->next;
    288         }
    289         return errors;
     251                             int optimize)
     252{
     253    struct tagFile *p;
     254    int total, n;
     255    char Buffer[MAX_PATH + 64];
     256    int errors = 0;
     257
     258    total = 0;
     259    p = file_list;
     260    while (p) {
     261        ++total;
     262        p = p->next;
     263    }
     264    SendDlgItemMessage(hDialog, IDC_PROGRESS, PBM_SETRANGE, 0,
     265                        MAKELPARAM(0, total));
     266    SendDlgItemMessage(hDialog, IDC_PROGRESS, PBM_SETPOS, 0, 0);
     267
     268    n = 0;
     269    p = file_list;
     270    while (p) {
     271        ++n;
     272        wsprintf(Buffer,
     273                  "import py_compile; py_compile.compile (r'%s')",
     274                  p->path);
     275        if (PyRun_SimpleString(Buffer)) {
     276            ++errors;
     277        }
     278        /* We send the notification even if the files could not
     279        * be created so that the uninstaller will remove them
     280        * in case they are created later.
     281        */
     282        wsprintf(Buffer, "%s%c", p->path, optimize ? 'o' : 'c');
     283        notify(FILE_CREATED, Buffer);
     284
     285        SendDlgItemMessage(hDialog, IDC_PROGRESS, PBM_SETPOS, n, 0);
     286        SetDlgItemText(hDialog, IDC_INFO, p->path);
     287        p = p->next;
     288    }
     289    return errors;
    290290}
    291291
     
    307307static int compile_filelist(HINSTANCE hPython, BOOL optimize_flag)
    308308{
    309         DECLPROC(hPython, void, Py_Initialize, (void));
    310         DECLPROC(hPython, void, Py_SetProgramName, (char *));
    311         DECLPROC(hPython, void, Py_Finalize, (void));
    312         DECLPROC(hPython, int, PyRun_SimpleString, (char *));
    313         DECLPROC(hPython, PyObject *, PySys_GetObject, (char *));
    314         DECLVAR(hPython, int, Py_OptimizeFlag);
    315 
    316         int errors = 0;
    317         struct tagFile *p = file_list;
    318 
    319         if (!p)
    320                 return 0;
    321 
    322         if (!Py_Initialize || !Py_SetProgramName || !Py_Finalize)
    323                 return -1;
    324 
    325         if (!PyRun_SimpleString || !PySys_GetObject || !Py_OptimizeFlag)
    326                 return -1;
    327 
    328         *Py_OptimizeFlag = optimize_flag ? 1 : 0;
    329         Py_SetProgramName(modulename);
    330         Py_Initialize();
    331 
    332         errors += do_compile_files(PyRun_SimpleString, optimize_flag);
    333         Py_Finalize();
    334 
    335         return errors;
     309    DECLPROC(hPython, void, Py_Initialize, (void));
     310    DECLPROC(hPython, void, Py_SetProgramName, (char *));
     311    DECLPROC(hPython, void, Py_Finalize, (void));
     312    DECLPROC(hPython, int, PyRun_SimpleString, (char *));
     313    DECLPROC(hPython, PyObject *, PySys_GetObject, (char *));
     314    DECLVAR(hPython, int, Py_OptimizeFlag);
     315
     316    int errors = 0;
     317    struct tagFile *p = file_list;
     318
     319    if (!p)
     320        return 0;
     321
     322    if (!Py_Initialize || !Py_SetProgramName || !Py_Finalize)
     323        return -1;
     324
     325    if (!PyRun_SimpleString || !PySys_GetObject || !Py_OptimizeFlag)
     326        return -1;
     327
     328    *Py_OptimizeFlag = optimize_flag ? 1 : 0;
     329    Py_SetProgramName(modulename);
     330    Py_Initialize();
     331
     332    errors += do_compile_files(PyRun_SimpleString, optimize_flag);
     333    Py_Finalize();
     334
     335    return errors;
    336336}
    337337
     
    339339
    340340struct PyMethodDef {
    341         char    *ml_name;
    342         PyCFunction  ml_meth;
    343         int              ml_flags;
    344         char    *ml_doc;
     341    char        *ml_name;
     342    PyCFunction  ml_meth;
     343    int                  ml_flags;
     344    char        *ml_doc;
    345345};
    346346typedef struct PyMethodDef PyMethodDef;
    347347
    348348// XXX - all of these are potentially fragile!  We load and unload
    349 // the Python DLL multiple times - so storing functions pointers 
     349// the Python DLL multiple times - so storing functions pointers
    350350// is dangerous (although things *look* OK at present)
    351351// Better might be to roll prepare_script_environment() into
     
    364364
    365365struct {
    366         int nFolder;
    367         char *name;
     366    int nFolder;
     367    char *name;
    368368} csidl_names[] = {
    369         /* Startup menu for all users.
    370            NT only */
    371         DEF_CSIDL(CSIDL_COMMON_STARTMENU),
    372         /* Startup menu. */
    373         DEF_CSIDL(CSIDL_STARTMENU),
     369    /* Startup menu for all users.
     370       NT only */
     371    DEF_CSIDL(CSIDL_COMMON_STARTMENU),
     372    /* Startup menu. */
     373    DEF_CSIDL(CSIDL_STARTMENU),
    374374
    375375/*    DEF_CSIDL(CSIDL_COMMON_APPDATA), */
    376376/*    DEF_CSIDL(CSIDL_LOCAL_APPDATA), */
    377         /* Repository for application-specific data.
    378            Needs Internet Explorer 4.0 */
    379         DEF_CSIDL(CSIDL_APPDATA),
    380 
    381         /* The desktop for all users.
    382            NT only */
    383         DEF_CSIDL(CSIDL_COMMON_DESKTOPDIRECTORY),
    384         /* The desktop. */
    385         DEF_CSIDL(CSIDL_DESKTOPDIRECTORY),
    386 
    387         /* Startup folder for all users.
    388            NT only */
    389         DEF_CSIDL(CSIDL_COMMON_STARTUP),
    390         /* Startup folder. */
    391         DEF_CSIDL(CSIDL_STARTUP),
    392 
    393         /* Programs item in the start menu for all users.
    394            NT only */
    395         DEF_CSIDL(CSIDL_COMMON_PROGRAMS),
    396         /* Program item in the user's start menu. */
    397         DEF_CSIDL(CSIDL_PROGRAMS),
     377    /* Repository for application-specific data.
     378       Needs Internet Explorer 4.0 */
     379    DEF_CSIDL(CSIDL_APPDATA),
     380
     381    /* The desktop for all users.
     382       NT only */
     383    DEF_CSIDL(CSIDL_COMMON_DESKTOPDIRECTORY),
     384    /* The desktop. */
     385    DEF_CSIDL(CSIDL_DESKTOPDIRECTORY),
     386
     387    /* Startup folder for all users.
     388       NT only */
     389    DEF_CSIDL(CSIDL_COMMON_STARTUP),
     390    /* Startup folder. */
     391    DEF_CSIDL(CSIDL_STARTUP),
     392
     393    /* Programs item in the start menu for all users.
     394       NT only */
     395    DEF_CSIDL(CSIDL_COMMON_PROGRAMS),
     396    /* Program item in the user's start menu. */
     397    DEF_CSIDL(CSIDL_PROGRAMS),
    398398
    399399/*    DEF_CSIDL(CSIDL_PROGRAM_FILES_COMMON), */
    400400/*    DEF_CSIDL(CSIDL_PROGRAM_FILES), */
    401401
    402         /* Virtual folder containing fonts. */
    403         DEF_CSIDL(CSIDL_FONTS),
     402    /* Virtual folder containing fonts. */
     403    DEF_CSIDL(CSIDL_FONTS),
    404404};
    405405
     
    408408static PyObject *FileCreated(PyObject *self, PyObject *args)
    409409{
    410         char *path;
    411         if (!g_PyArg_ParseTuple(args, "s", &path))
    412                 return NULL;
    413         notify(FILE_CREATED, path);
    414         return g_Py_BuildValue("");
     410    char *path;
     411    if (!g_PyArg_ParseTuple(args, "s", &path))
     412        return NULL;
     413    notify(FILE_CREATED, path);
     414    return g_Py_BuildValue("");
    415415}
    416416
    417417static PyObject *DirectoryCreated(PyObject *self, PyObject *args)
    418418{
    419         char *path;
    420         if (!g_PyArg_ParseTuple(args, "s", &path))
    421                 return NULL;
    422         notify(DIR_CREATED, path);
    423         return g_Py_BuildValue("");
     419    char *path;
     420    if (!g_PyArg_ParseTuple(args, "s", &path))
     421        return NULL;
     422    notify(DIR_CREATED, path);
     423    return g_Py_BuildValue("");
    424424}
    425425
    426426static PyObject *GetSpecialFolderPath(PyObject *self, PyObject *args)
    427427{
    428         char *name;
    429         char lpszPath[MAX_PATH];
    430         int i;
    431         static HRESULT (WINAPI *My_SHGetSpecialFolderPath)(HWND hwnd,
    432                                                            LPTSTR lpszPath,
    433                                                            int nFolder,
    434                                                            BOOL fCreate);
    435 
    436         if (!My_SHGetSpecialFolderPath) {
    437                 HINSTANCE hLib = LoadLibrary("shell32.dll");
    438                 if (!hLib) {
    439                         g_PyErr_Format(g_PyExc_OSError,
    440                                        "function not available");
    441                         return NULL;
    442                 }
    443                 My_SHGetSpecialFolderPath = (BOOL (WINAPI *)(HWND, LPTSTR,
    444                                                              int, BOOL))
    445                         GetProcAddress(hLib,
    446                                        "SHGetSpecialFolderPathA");
    447         }
    448 
    449         if (!g_PyArg_ParseTuple(args, "s", &name))
    450                 return NULL;
    451    
    452         if (!My_SHGetSpecialFolderPath) {
    453                 g_PyErr_Format(g_PyExc_OSError, "function not available");
    454                 return NULL;
    455         }
    456 
    457         for (i = 0; i < DIM(csidl_names); ++i) {
    458                 if (0 == strcmpi(csidl_names[i].name, name)) {
    459                         int nFolder;
    460                         nFolder = csidl_names[i].nFolder;
    461                         if (My_SHGetSpecialFolderPath(NULL, lpszPath,
    462                                                       nFolder, 0))
    463                                 return g_Py_BuildValue("s", lpszPath);
    464                         else {
    465                                 g_PyErr_Format(g_PyExc_OSError,
    466                                                "no such folder (%s)", name);
    467                                 return NULL;
    468                         }
    469                
    470                 }
    471         };
    472         g_PyErr_Format(g_PyExc_ValueError, "unknown CSIDL (%s)", name);
    473         return NULL;
     428    char *name;
     429    char lpszPath[MAX_PATH];
     430    int i;
     431    static HRESULT (WINAPI *My_SHGetSpecialFolderPath)(HWND hwnd,
     432                                                       LPTSTR lpszPath,
     433                                                       int nFolder,
     434                                                       BOOL fCreate);
     435
     436    if (!My_SHGetSpecialFolderPath) {
     437        HINSTANCE hLib = LoadLibrary("shell32.dll");
     438        if (!hLib) {
     439            g_PyErr_Format(g_PyExc_OSError,
     440                           "function not available");
     441            return NULL;
     442        }
     443        My_SHGetSpecialFolderPath = (BOOL (WINAPI *)(HWND, LPTSTR,
     444                                                     int, BOOL))
     445            GetProcAddress(hLib,
     446                           "SHGetSpecialFolderPathA");
     447    }
     448
     449    if (!g_PyArg_ParseTuple(args, "s", &name))
     450        return NULL;
     451
     452    if (!My_SHGetSpecialFolderPath) {
     453        g_PyErr_Format(g_PyExc_OSError, "function not available");
     454        return NULL;
     455    }
     456
     457    for (i = 0; i < DIM(csidl_names); ++i) {
     458        if (0 == strcmpi(csidl_names[i].name, name)) {
     459            int nFolder;
     460            nFolder = csidl_names[i].nFolder;
     461            if (My_SHGetSpecialFolderPath(NULL, lpszPath,
     462                                          nFolder, 0))
     463                return g_Py_BuildValue("s", lpszPath);
     464            else {
     465                g_PyErr_Format(g_PyExc_OSError,
     466                               "no such folder (%s)", name);
     467                return NULL;
     468            }
     469
     470        }
     471    };
     472    g_PyErr_Format(g_PyExc_ValueError, "unknown CSIDL (%s)", name);
     473    return NULL;
    474474}
    475475
    476476static PyObject *CreateShortcut(PyObject *self, PyObject *args)
    477477{
    478         char *path; /* path and filename */
    479         char *description;
    480         char *filename;
    481 
    482         char *arguments = NULL;
    483         char *iconpath = NULL;
    484         int iconindex = 0;
    485         char *workdir = NULL;
    486 
    487         WCHAR wszFilename[MAX_PATH];
    488 
    489         IShellLink *ps1 = NULL;
    490         IPersistFile *pPf = NULL;
    491 
    492         HRESULT hr;
    493 
    494         hr = CoInitialize(NULL);
    495         if (FAILED(hr)) {
    496                 g_PyErr_Format(g_PyExc_OSError,
    497                                "CoInitialize failed, error 0x%x", hr);
    498                 goto error;
    499         }
    500 
    501         if (!g_PyArg_ParseTuple(args, "sss|sssi",
    502                                 &path, &description, &filename,
    503                                 &arguments, &workdir, &iconpath, &iconindex))
    504                 return NULL;
    505 
    506         hr = CoCreateInstance(&CLSID_ShellLink,
    507                               NULL,
    508                               CLSCTX_INPROC_SERVER,
    509                               &IID_IShellLink,
    510                               &ps1);
    511         if (FAILED(hr)) {
    512                 g_PyErr_Format(g_PyExc_OSError,
    513                                "CoCreateInstance failed, error 0x%x", hr);
    514                 goto error;
    515         }
    516 
    517         hr = ps1->lpVtbl->QueryInterface(ps1, &IID_IPersistFile,
    518                                         (void **)&pPf);
    519         if (FAILED(hr)) {
    520                 g_PyErr_Format(g_PyExc_OSError,
    521                                "QueryInterface(IPersistFile) error 0x%x", hr);
    522                 goto error;
    523         }
    524 
    525 
    526         hr = ps1->lpVtbl->SetPath(ps1, path);
    527         if (FAILED(hr)) {
    528                 g_PyErr_Format(g_PyExc_OSError,
    529                                "SetPath() failed, error 0x%x", hr);
    530                 goto error;
    531         }
    532 
    533         hr = ps1->lpVtbl->SetDescription(ps1, description);
    534         if (FAILED(hr)) {
    535                 g_PyErr_Format(g_PyExc_OSError,
    536                                "SetDescription() failed, error 0x%x", hr);
    537                 goto error;
    538         }
    539 
    540         if (arguments) {
    541                 hr = ps1->lpVtbl->SetArguments(ps1, arguments);
    542                 if (FAILED(hr)) {
    543                         g_PyErr_Format(g_PyExc_OSError,
    544                                        "SetArguments() error 0x%x", hr);
    545                         goto error;
    546                 }
    547         }
    548 
    549         if (iconpath) {
    550                 hr = ps1->lpVtbl->SetIconLocation(ps1, iconpath, iconindex);
    551                 if (FAILED(hr)) {
    552                         g_PyErr_Format(g_PyExc_OSError,
    553                                        "SetIconLocation() error 0x%x", hr);
    554                         goto error;
    555                 }
    556         }
    557 
    558         if (workdir) {
    559                 hr = ps1->lpVtbl->SetWorkingDirectory(ps1, workdir);
    560                 if (FAILED(hr)) {
    561                         g_PyErr_Format(g_PyExc_OSError,
    562                                        "SetWorkingDirectory() error 0x%x", hr);
    563                         goto error;
    564                 }
    565         }
    566 
    567         MultiByteToWideChar(CP_ACP, 0,
    568                             filename, -1,
    569                             wszFilename, MAX_PATH);
    570                        
    571         hr = pPf->lpVtbl->Save(pPf, wszFilename, TRUE);
    572         if (FAILED(hr)) {
    573                 g_PyErr_Format(g_PyExc_OSError,
    574                                "Failed to create shortcut '%s' - error 0x%x", filename, hr);
    575                 goto error;
    576         }
    577    
    578         pPf->lpVtbl->Release(pPf);
    579         ps1->lpVtbl->Release(ps1);
    580         CoUninitialize();
    581         return g_Py_BuildValue("");
    582    
     478    char *path; /* path and filename */
     479    char *description;
     480    char *filename;
     481
     482    char *arguments = NULL;
     483    char *iconpath = NULL;
     484    int iconindex = 0;
     485    char *workdir = NULL;
     486
     487    WCHAR wszFilename[MAX_PATH];
     488
     489    IShellLink *ps1 = NULL;
     490    IPersistFile *pPf = NULL;
     491
     492    HRESULT hr;
     493
     494    hr = CoInitialize(NULL);
     495    if (FAILED(hr)) {
     496        g_PyErr_Format(g_PyExc_OSError,
     497                       "CoInitialize failed, error 0x%x", hr);
     498        goto error;
     499    }
     500
     501    if (!g_PyArg_ParseTuple(args, "sss|sssi",
     502                            &path, &description, &filename,
     503                            &arguments, &workdir, &iconpath, &iconindex))
     504        return NULL;
     505
     506    hr = CoCreateInstance(&CLSID_ShellLink,
     507                          NULL,
     508                          CLSCTX_INPROC_SERVER,
     509                          &IID_IShellLink,
     510                          &ps1);
     511    if (FAILED(hr)) {
     512        g_PyErr_Format(g_PyExc_OSError,
     513                       "CoCreateInstance failed, error 0x%x", hr);
     514        goto error;
     515    }
     516
     517    hr = ps1->lpVtbl->QueryInterface(ps1, &IID_IPersistFile,
     518                                    (void **)&pPf);
     519    if (FAILED(hr)) {
     520        g_PyErr_Format(g_PyExc_OSError,
     521                       "QueryInterface(IPersistFile) error 0x%x", hr);
     522        goto error;
     523    }
     524
     525
     526    hr = ps1->lpVtbl->SetPath(ps1, path);
     527    if (FAILED(hr)) {
     528        g_PyErr_Format(g_PyExc_OSError,
     529                       "SetPath() failed, error 0x%x", hr);
     530        goto error;
     531    }
     532
     533    hr = ps1->lpVtbl->SetDescription(ps1, description);
     534    if (FAILED(hr)) {
     535        g_PyErr_Format(g_PyExc_OSError,
     536                       "SetDescription() failed, error 0x%x", hr);
     537        goto error;
     538    }
     539
     540    if (arguments) {
     541        hr = ps1->lpVtbl->SetArguments(ps1, arguments);
     542        if (FAILED(hr)) {
     543            g_PyErr_Format(g_PyExc_OSError,
     544                           "SetArguments() error 0x%x", hr);
     545            goto error;
     546        }
     547    }
     548
     549    if (iconpath) {
     550        hr = ps1->lpVtbl->SetIconLocation(ps1, iconpath, iconindex);
     551        if (FAILED(hr)) {
     552            g_PyErr_Format(g_PyExc_OSError,
     553                           "SetIconLocation() error 0x%x", hr);
     554            goto error;
     555        }
     556    }
     557
     558    if (workdir) {
     559        hr = ps1->lpVtbl->SetWorkingDirectory(ps1, workdir);
     560        if (FAILED(hr)) {
     561            g_PyErr_Format(g_PyExc_OSError,
     562                           "SetWorkingDirectory() error 0x%x", hr);
     563            goto error;
     564        }
     565    }
     566
     567    MultiByteToWideChar(CP_ACP, 0,
     568                        filename, -1,
     569                        wszFilename, MAX_PATH);
     570
     571    hr = pPf->lpVtbl->Save(pPf, wszFilename, TRUE);
     572    if (FAILED(hr)) {
     573        g_PyErr_Format(g_PyExc_OSError,
     574                       "Failed to create shortcut '%s' - error 0x%x", filename, hr);
     575        goto error;
     576    }
     577
     578    pPf->lpVtbl->Release(pPf);
     579    ps1->lpVtbl->Release(ps1);
     580    CoUninitialize();
     581    return g_Py_BuildValue("");
     582
    583583  error:
    584         if (pPf)
    585                 pPf->lpVtbl->Release(pPf);
    586 
    587         if (ps1)
    588                 ps1->lpVtbl->Release(ps1);
    589 
    590         CoUninitialize();
    591 
    592         return NULL;
     584    if (pPf)
     585        pPf->lpVtbl->Release(pPf);
     586
     587    if (ps1)
     588        ps1->lpVtbl->Release(ps1);
     589
     590    CoUninitialize();
     591
     592    return NULL;
    593593}
    594594
    595595static PyObject *PyMessageBox(PyObject *self, PyObject *args)
    596596{
    597         int rc;
    598         char *text, *caption;
    599         int flags;
    600         if (!g_PyArg_ParseTuple(args, "ssi", &text, &caption, &flags))
    601                 return NULL;
    602         rc = MessageBox(GetFocus(), text, caption, flags);
    603         return g_Py_BuildValue("i", rc);
     597    int rc;
     598    char *text, *caption;
     599    int flags;
     600    if (!g_PyArg_ParseTuple(args, "ssi", &text, &caption, &flags))
     601        return NULL;
     602    rc = MessageBox(GetFocus(), text, caption, flags);
     603    return g_Py_BuildValue("i", rc);
    604604}
    605605
    606606static PyObject *GetRootHKey(PyObject *self)
    607607{
    608         return g_PyLong_FromVoidPtr(hkey_root);
     608    return g_PyLong_FromVoidPtr(hkey_root);
    609609}
    610610
     
    614614
    615615PyMethodDef meth[] = {
    616         {"create_shortcut", CreateShortcut, METH_VARARGS, NULL},
    617         {"get_special_folder_path", GetSpecialFolderPath, METH_VARARGS, NULL},
    618         {"get_root_hkey", (PyCFunction)GetRootHKey, METH_NOARGS, NULL},
    619         {"file_created", FileCreated, METH_VARARGS, NULL},
    620         {"directory_created", DirectoryCreated, METH_VARARGS, NULL},
    621         {"message_box", PyMessageBox, METH_VARARGS, NULL},
     616    {"create_shortcut", CreateShortcut, METH_VARARGS, NULL},
     617    {"get_special_folder_path", GetSpecialFolderPath, METH_VARARGS, NULL},
     618    {"get_root_hkey", (PyCFunction)GetRootHKey, METH_NOARGS, NULL},
     619    {"file_created", FileCreated, METH_VARARGS, NULL},
     620    {"directory_created", DirectoryCreated, METH_VARARGS, NULL},
     621    {"message_box", PyMessageBox, METH_VARARGS, NULL},
    622622};
    623623
    624624static HINSTANCE LoadPythonDll(char *fname)
    625625{
    626         char fullpath[_MAX_PATH];
    627         LONG size = sizeof(fullpath);
    628         char subkey_name[80];
    629         char buffer[260 + 12];
    630         HINSTANCE h;
    631 
    632         /* make sure PYTHONHOME is set, to that sys.path is initialized correctly */
    633         wsprintf(buffer, "PYTHONHOME=%s", python_dir);
    634         _putenv(buffer);
    635         h = LoadLibrary(fname);
    636         if (h)
    637                 return h;
    638         wsprintf(subkey_name,
    639                 "SOFTWARE\\Python\\PythonCore\\%d.%d\\InstallPath",
    640                 py_major, py_minor);
    641         if (ERROR_SUCCESS != RegQueryValue(HKEY_CURRENT_USER, subkey_name,
    642                                            fullpath, &size) &&
    643             ERROR_SUCCESS != RegQueryValue(HKEY_LOCAL_MACHINE, subkey_name,
    644                                            fullpath, &size))
    645                 return NULL;
    646         strcat(fullpath, "\\");
    647         strcat(fullpath, fname);
    648         return LoadLibrary(fullpath);
     626    char fullpath[_MAX_PATH];
     627    LONG size = sizeof(fullpath);
     628    char subkey_name[80];
     629    char buffer[260 + 12];
     630    HINSTANCE h;
     631
     632    /* make sure PYTHONHOME is set, to that sys.path is initialized correctly */
     633    wsprintf(buffer, "PYTHONHOME=%s", python_dir);
     634    _putenv(buffer);
     635    h = LoadLibrary(fname);
     636    if (h)
     637        return h;
     638    wsprintf(subkey_name,
     639            "SOFTWARE\\Python\\PythonCore\\%d.%d\\InstallPath",
     640            py_major, py_minor);
     641    if (ERROR_SUCCESS != RegQueryValue(HKEY_CURRENT_USER, subkey_name,
     642                                       fullpath, &size) &&
     643        ERROR_SUCCESS != RegQueryValue(HKEY_LOCAL_MACHINE, subkey_name,
     644                                       fullpath, &size))
     645        return NULL;
     646    strcat(fullpath, "\\");
     647    strcat(fullpath, fname);
     648    return LoadLibrary(fullpath);
    649649}
    650650
    651651static int prepare_script_environment(HINSTANCE hPython)
    652652{
    653         PyObject *mod;
    654         DECLPROC(hPython, PyObject *, PyImport_ImportModule, (char *));
    655         DECLPROC(hPython, int, PyObject_SetAttrString, (PyObject *, char *, PyObject *));
    656         DECLPROC(hPython, PyObject *, PyObject_GetAttrString, (PyObject *, char *));
    657         DECLPROC(hPython, PyObject *, PyCFunction_New, (PyMethodDef *, PyObject *));
    658         DECLPROC(hPython, PyObject *, Py_BuildValue, (char *, ...));
    659         DECLPROC(hPython, int, PyArg_ParseTuple, (PyObject *, char *, ...));
    660         DECLPROC(hPython, PyObject *, PyErr_Format, (PyObject *, char *));
    661         DECLPROC(hPython, PyObject *, PyLong_FromVoidPtr, (void *));
    662         if (!PyImport_ImportModule || !PyObject_GetAttrString ||
    663             !PyObject_SetAttrString || !PyCFunction_New)
    664                 return 1;
    665         if (!Py_BuildValue || !PyArg_ParseTuple || !PyErr_Format)
    666                 return 1;
    667 
    668         mod = PyImport_ImportModule("__builtin__");
    669         if (mod) {
    670                 int i;
    671                 g_PyExc_ValueError = PyObject_GetAttrString(mod, "ValueError");
    672                 g_PyExc_OSError = PyObject_GetAttrString(mod, "OSError");
    673                 for (i = 0; i < DIM(meth); ++i) {
    674                         PyObject_SetAttrString(mod, meth[i].ml_name,
    675                                                PyCFunction_New(&meth[i], NULL));
    676                 }
    677         }
    678         g_Py_BuildValue = Py_BuildValue;
    679         g_PyArg_ParseTuple = PyArg_ParseTuple;
    680         g_PyErr_Format = PyErr_Format;
    681         g_PyLong_FromVoidPtr = PyLong_FromVoidPtr;
    682 
    683         return 0;
     653    PyObject *mod;
     654    DECLPROC(hPython, PyObject *, PyImport_ImportModule, (char *));
     655    DECLPROC(hPython, int, PyObject_SetAttrString, (PyObject *, char *, PyObject *));
     656    DECLPROC(hPython, PyObject *, PyObject_GetAttrString, (PyObject *, char *));
     657    DECLPROC(hPython, PyObject *, PyCFunction_New, (PyMethodDef *, PyObject *));
     658    DECLPROC(hPython, PyObject *, Py_BuildValue, (char *, ...));
     659    DECLPROC(hPython, int, PyArg_ParseTuple, (PyObject *, char *, ...));
     660    DECLPROC(hPython, PyObject *, PyErr_Format, (PyObject *, char *));
     661    DECLPROC(hPython, PyObject *, PyLong_FromVoidPtr, (void *));
     662    if (!PyImport_ImportModule || !PyObject_GetAttrString ||
     663        !PyObject_SetAttrString || !PyCFunction_New)
     664        return 1;
     665    if (!Py_BuildValue || !PyArg_ParseTuple || !PyErr_Format)
     666        return 1;
     667
     668    mod = PyImport_ImportModule("__builtin__");
     669    if (mod) {
     670        int i;
     671        g_PyExc_ValueError = PyObject_GetAttrString(mod, "ValueError");
     672        g_PyExc_OSError = PyObject_GetAttrString(mod, "OSError");
     673        for (i = 0; i < DIM(meth); ++i) {
     674            PyObject_SetAttrString(mod, meth[i].ml_name,
     675                                   PyCFunction_New(&meth[i], NULL));
     676        }
     677    }
     678    g_Py_BuildValue = Py_BuildValue;
     679    g_PyArg_ParseTuple = PyArg_ParseTuple;
     680    g_PyErr_Format = PyErr_Format;
     681    g_PyLong_FromVoidPtr = PyLong_FromVoidPtr;
     682
     683    return 0;
    684684}
    685685
     
    697697do_run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv)
    698698{
    699         int fh, result;
    700         DECLPROC(hPython, void, Py_Initialize, (void));
    701         DECLPROC(hPython, int, PySys_SetArgv, (int, char **));
    702         DECLPROC(hPython, int, PyRun_SimpleString, (char *));
    703         DECLPROC(hPython, void, Py_Finalize, (void));
    704         DECLPROC(hPython, PyObject *, Py_BuildValue, (char *, ...));
    705         DECLPROC(hPython, PyObject *, PyCFunction_New,
    706                 (PyMethodDef *, PyObject *));
    707         DECLPROC(hPython, int, PyArg_ParseTuple, (PyObject *, char *, ...));
    708         DECLPROC(hPython, PyObject *, PyErr_Format, (PyObject *, char *));
    709 
    710         if (!Py_Initialize || !PySys_SetArgv
    711             || !PyRun_SimpleString || !Py_Finalize)
    712                 return 1;
    713        
    714         if (!Py_BuildValue || !PyArg_ParseTuple || !PyErr_Format)
    715                 return 1;
    716 
    717         if (!PyCFunction_New || !PyArg_ParseTuple || !PyErr_Format)
    718                 return 1;
    719 
    720         if (pathname == NULL || pathname[0] == '\0')
    721                 return 2;
    722 
    723         fh = open(pathname, _O_RDONLY);
    724         if (-1 == fh) {
    725                 fprintf(stderr, "Could not open postinstall-script %s\n",
    726                         pathname);
    727                 return 3;
    728         }
    729 
    730         SetDlgItemText(hDialog, IDC_INFO, "Running Script...");
    731 
    732         Py_Initialize();
    733 
    734         prepare_script_environment(hPython);
    735         PySys_SetArgv(argc, argv);
    736         result = 3;
    737         {
    738                 struct _stat statbuf;
    739                 if(0 == _fstat(fh, &statbuf)) {
    740                         char *script = alloca(statbuf.st_size + 5);
    741                         int n = read(fh, script, statbuf.st_size);
    742                         if (n > 0) {
    743                                 script[n] = '\n';
    744                                 script[n+1] = 0;
    745                                 result = PyRun_SimpleString(script);
    746                         }
    747                 }
    748         }
    749         Py_Finalize();
    750 
    751         close(fh);
    752         return result;
     699    int fh, result;
     700    DECLPROC(hPython, void, Py_Initialize, (void));
     701    DECLPROC(hPython, int, PySys_SetArgv, (int, char **));
     702    DECLPROC(hPython, int, PyRun_SimpleString, (char *));
     703    DECLPROC(hPython, void, Py_Finalize, (void));
     704    DECLPROC(hPython, PyObject *, Py_BuildValue, (char *, ...));
     705    DECLPROC(hPython, PyObject *, PyCFunction_New,
     706            (PyMethodDef *, PyObject *));
     707    DECLPROC(hPython, int, PyArg_ParseTuple, (PyObject *, char *, ...));
     708    DECLPROC(hPython, PyObject *, PyErr_Format, (PyObject *, char *));
     709
     710    if (!Py_Initialize || !PySys_SetArgv
     711        || !PyRun_SimpleString || !Py_Finalize)
     712        return 1;
     713
     714    if (!Py_BuildValue || !PyArg_ParseTuple || !PyErr_Format)
     715        return 1;
     716
     717    if (!PyCFunction_New || !PyArg_ParseTuple || !PyErr_Format)
     718        return 1;
     719
     720    if (pathname == NULL || pathname[0] == '\0')
     721        return 2;
     722
     723    fh = open(pathname, _O_RDONLY);
     724    if (-1 == fh) {
     725        fprintf(stderr, "Could not open postinstall-script %s\n",
     726            pathname);
     727        return 3;
     728    }
     729
     730    SetDlgItemText(hDialog, IDC_INFO, "Running Script...");
     731
     732    Py_Initialize();
     733
     734    prepare_script_environment(hPython);
     735    PySys_SetArgv(argc, argv);
     736    result = 3;
     737    {
     738        struct _stat statbuf;
     739        if(0 == _fstat(fh, &statbuf)) {
     740            char *script = alloca(statbuf.st_size + 5);
     741            int n = read(fh, script, statbuf.st_size);
     742            if (n > 0) {
     743                script[n] = '\n';
     744                script[n+1] = 0;
     745                result = PyRun_SimpleString(script);
     746            }
     747        }
     748    }
     749    Py_Finalize();
     750
     751    close(fh);
     752    return result;
    753753}
    754754
     
    756756run_installscript(char *pathname, int argc, char **argv, char **pOutput)
    757757{
    758         HINSTANCE hPython;
    759         int result = 1;
    760         int out_buf_size;
    761         HANDLE redirected, old_stderr, old_stdout;
    762         char *tempname;
    763 
    764         *pOutput = NULL;
    765 
    766         tempname = tempnam(NULL, NULL);
    767         // We use a static CRT while the Python version we load uses
    768         // the CRT from one of various possibile DLLs.  As a result we
    769         // need to redirect the standard handles using the API rather
    770         // than the CRT.
    771         redirected = CreateFile(
    772                                         tempname,
    773                                         GENERIC_WRITE | GENERIC_READ,
    774                                         FILE_SHARE_READ,
    775                                         NULL,
    776                                         CREATE_ALWAYS,
    777                                         FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
    778                                         NULL);
    779         old_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
    780         old_stderr = GetStdHandle(STD_ERROR_HANDLE);
    781         SetStdHandle(STD_OUTPUT_HANDLE, redirected);
    782         SetStdHandle(STD_ERROR_HANDLE, redirected);
    783 
    784         hPython = LoadPythonDll(pythondll);
    785         if (hPython) {
    786                 result = do_run_installscript(hPython, pathname, argc, argv);
    787                 FreeLibrary(hPython);
    788         } else {
    789                 fprintf(stderr, "*** Could not load Python ***");
    790         }
    791         SetStdHandle(STD_OUTPUT_HANDLE, old_stdout);
    792         SetStdHandle(STD_ERROR_HANDLE, old_stderr);
    793         out_buf_size = min(GetFileSize(redirected, NULL), 4096);
    794         *pOutput = malloc(out_buf_size+1);
    795         if (*pOutput) {
    796                 DWORD nread = 0;
    797                 SetFilePointer(redirected, 0, 0, FILE_BEGIN);
    798                 ReadFile(redirected, *pOutput, out_buf_size, &nread, NULL);
    799                 (*pOutput)[nread] = '\0';
    800         }
    801         CloseHandle(redirected);
    802         DeleteFile(tempname);
    803         return result;
     758    HINSTANCE hPython;
     759    int result = 1;
     760    int out_buf_size;
     761    HANDLE redirected, old_stderr, old_stdout;
     762    char *tempname;
     763
     764    *pOutput = NULL;
     765
     766    tempname = tempnam(NULL, NULL);
     767    // We use a static CRT while the Python version we load uses
     768    // the CRT from one of various possible DLLs.  As a result we
     769    // need to redirect the standard handles using the API rather
     770    // than the CRT.
     771    redirected = CreateFile(
     772                                    tempname,
     773                                    GENERIC_WRITE | GENERIC_READ,
     774                                    FILE_SHARE_READ,
     775                                    NULL,
     776                                    CREATE_ALWAYS,
     777                                    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
     778                                    NULL);
     779    old_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
     780    old_stderr = GetStdHandle(STD_ERROR_HANDLE);
     781    SetStdHandle(STD_OUTPUT_HANDLE, redirected);
     782    SetStdHandle(STD_ERROR_HANDLE, redirected);
     783
     784    hPython = LoadPythonDll(pythondll);
     785    if (hPython) {
     786        result = do_run_installscript(hPython, pathname, argc, argv);
     787        FreeLibrary(hPython);
     788    } else {
     789        fprintf(stderr, "*** Could not load Python ***");
     790    }
     791    SetStdHandle(STD_OUTPUT_HANDLE, old_stdout);
     792    SetStdHandle(STD_ERROR_HANDLE, old_stderr);
     793    out_buf_size = min(GetFileSize(redirected, NULL), 4096);
     794    *pOutput = malloc(out_buf_size+1);
     795    if (*pOutput) {
     796        DWORD nread = 0;
     797        SetFilePointer(redirected, 0, 0, FILE_BEGIN);
     798        ReadFile(redirected, *pOutput, out_buf_size, &nread, NULL);
     799        (*pOutput)[nread] = '\0';
     800    }
     801    CloseHandle(redirected);
     802    DeleteFile(tempname);
     803    return result;
    804804}
    805805
    806806static int do_run_simple_script(HINSTANCE hPython, char *script)
    807807{
    808         int rc;
    809         DECLPROC(hPython, void, Py_Initialize, (void));
    810         DECLPROC(hPython, void, Py_SetProgramName, (char *));
    811         DECLPROC(hPython, void, Py_Finalize, (void));
    812         DECLPROC(hPython, int, PyRun_SimpleString, (char *));
    813         DECLPROC(hPython, void, PyErr_Print, (void));
    814 
    815         if (!Py_Initialize || !Py_SetProgramName || !Py_Finalize ||
    816             !PyRun_SimpleString || !PyErr_Print)
    817                 return -1;
    818 
    819         Py_SetProgramName(modulename);
    820         Py_Initialize();
    821         prepare_script_environment(hPython);
    822         rc = PyRun_SimpleString(script);
    823         if (rc)
    824                 PyErr_Print();
    825         Py_Finalize();
    826         return rc;
     808    int rc;
     809    DECLPROC(hPython, void, Py_Initialize, (void));
     810    DECLPROC(hPython, void, Py_SetProgramName, (char *));
     811    DECLPROC(hPython, void, Py_Finalize, (void));
     812    DECLPROC(hPython, int, PyRun_SimpleString, (char *));
     813    DECLPROC(hPython, void, PyErr_Print, (void));
     814
     815    if (!Py_Initialize || !Py_SetProgramName || !Py_Finalize ||
     816        !PyRun_SimpleString || !PyErr_Print)
     817        return -1;
     818
     819    Py_SetProgramName(modulename);
     820    Py_Initialize();
     821    prepare_script_environment(hPython);
     822    rc = PyRun_SimpleString(script);
     823    if (rc)
     824        PyErr_Print();
     825    Py_Finalize();
     826    return rc;
    827827}
    828828
    829829static int run_simple_script(char *script)
    830830{
    831         int rc;
    832         HINSTANCE hPython;
    833         char *tempname = tempnam(NULL, NULL);
    834         // Redirect output using win32 API - see comments above...
    835         HANDLE redirected = CreateFile(
    836                                         tempname,
    837                                         GENERIC_WRITE | GENERIC_READ,
    838                                         FILE_SHARE_READ,
    839                                         NULL,
    840                                         CREATE_ALWAYS,
    841                                         FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
    842                                         NULL);
    843         HANDLE old_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
    844         HANDLE old_stderr = GetStdHandle(STD_ERROR_HANDLE);
    845         SetStdHandle(STD_OUTPUT_HANDLE, redirected);
    846         SetStdHandle(STD_ERROR_HANDLE, redirected);
    847 
    848         hPython = LoadPythonDll(pythondll);
    849         if (!hPython) {
    850                 char reason[128];
    851                 wsprintf(reason, "Can't load Python for pre-install script (%d)", GetLastError());
    852                 set_failure_reason(reason);
    853                 return -1;
    854         }
    855         rc = do_run_simple_script(hPython, script);
    856         FreeLibrary(hPython);
    857         SetStdHandle(STD_OUTPUT_HANDLE, old_stdout);
    858         SetStdHandle(STD_ERROR_HANDLE, old_stderr);
    859         /* We only care about the output when we fail.  If the script works
    860            OK, then we discard it
    861         */
    862         if (rc) {
    863                 int err_buf_size;
    864                 char *err_buf;
    865                 const char *prefix = "Running the pre-installation script failed\r\n";
    866                 int prefix_len = strlen(prefix);
    867                 err_buf_size = GetFileSize(redirected, NULL);
    868                 if (err_buf_size==INVALID_FILE_SIZE) // an error - let's try anyway...
    869                         err_buf_size = 4096;
    870                 err_buf = malloc(prefix_len + err_buf_size + 1);
    871                 if (err_buf) {
    872                         DWORD n = 0;
    873                         strcpy(err_buf, prefix);
    874                         SetFilePointer(redirected, 0, 0, FILE_BEGIN);
    875                         ReadFile(redirected, err_buf+prefix_len, err_buf_size, &n, NULL);
    876                         err_buf[prefix_len+n] = '\0';
    877                         set_failure_reason(err_buf);
    878                         free(err_buf);
    879                 } else {
    880                         set_failure_reason("Out of memory!");
    881                 }
    882         }
    883         CloseHandle(redirected);
    884         DeleteFile(tempname);
    885         return rc;
     831    int rc;
     832    HINSTANCE hPython;
     833    char *tempname = tempnam(NULL, NULL);
     834    // Redirect output using win32 API - see comments above...
     835    HANDLE redirected = CreateFile(
     836                                    tempname,
     837                                    GENERIC_WRITE | GENERIC_READ,
     838                                    FILE_SHARE_READ,
     839                                    NULL,
     840                                    CREATE_ALWAYS,
     841                                    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
     842                                    NULL);
     843    HANDLE old_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
     844    HANDLE old_stderr = GetStdHandle(STD_ERROR_HANDLE);
     845    SetStdHandle(STD_OUTPUT_HANDLE, redirected);
     846    SetStdHandle(STD_ERROR_HANDLE, redirected);
     847
     848    hPython = LoadPythonDll(pythondll);
     849    if (!hPython) {
     850        char reason[128];
     851        wsprintf(reason, "Can't load Python for pre-install script (%d)", GetLastError());
     852        set_failure_reason(reason);
     853        return -1;
     854    }
     855    rc = do_run_simple_script(hPython, script);
     856    FreeLibrary(hPython);
     857    SetStdHandle(STD_OUTPUT_HANDLE, old_stdout);
     858    SetStdHandle(STD_ERROR_HANDLE, old_stderr);
     859    /* We only care about the output when we fail.  If the script works
     860       OK, then we discard it
     861    */
     862    if (rc) {
     863        int err_buf_size;
     864        char *err_buf;
     865        const char *prefix = "Running the pre-installation script failed\r\n";
     866        int prefix_len = strlen(prefix);
     867        err_buf_size = GetFileSize(redirected, NULL);
     868        if (err_buf_size==INVALID_FILE_SIZE) // an error - let's try anyway...
     869            err_buf_size = 4096;
     870        err_buf = malloc(prefix_len + err_buf_size + 1);
     871        if (err_buf) {
     872            DWORD n = 0;
     873            strcpy(err_buf, prefix);
     874            SetFilePointer(redirected, 0, 0, FILE_BEGIN);
     875            ReadFile(redirected, err_buf+prefix_len, err_buf_size, &n, NULL);
     876            err_buf[prefix_len+n] = '\0';
     877            set_failure_reason(err_buf);
     878            free(err_buf);
     879        } else {
     880            set_failure_reason("Out of memory!");
     881        }
     882    }
     883    CloseHandle(redirected);
     884    DeleteFile(tempname);
     885    return rc;
    886886}
    887887
     
    889889static BOOL SystemError(int error, char *msg)
    890890{
    891         char Buffer[1024];
    892         int n;
    893 
    894         if (error) {
    895                 LPVOID lpMsgBuf;
    896                 FormatMessage(
    897                         FORMAT_MESSAGE_ALLOCATE_BUFFER |
    898                         FORMAT_MESSAGE_FROM_SYSTEM,
    899                         NULL,
    900                         error,
    901                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    902                         (LPSTR)&lpMsgBuf,
    903                         0,
    904                         NULL
    905                         );
    906                 strncpy(Buffer, lpMsgBuf, sizeof(Buffer));
    907                 LocalFree(lpMsgBuf);
    908         } else
    909                 Buffer[0] = '\0';
    910         n = lstrlen(Buffer);
    911         _snprintf(Buffer+n, sizeof(Buffer)-n, msg);
    912         MessageBox(hwndMain, Buffer, "Runtime Error", MB_OK | MB_ICONSTOP);
    913         return FALSE;
     891    char Buffer[1024];
     892    int n;
     893
     894    if (error) {
     895        LPVOID lpMsgBuf;
     896        FormatMessage(
     897            FORMAT_MESSAGE_ALLOCATE_BUFFER |
     898            FORMAT_MESSAGE_FROM_SYSTEM,
     899            NULL,
     900            error,
     901            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
     902            (LPSTR)&lpMsgBuf,
     903            0,
     904            NULL
     905            );
     906        strncpy(Buffer, lpMsgBuf, sizeof(Buffer));
     907        LocalFree(lpMsgBuf);
     908    } else
     909        Buffer[0] = '\0';
     910    n = lstrlen(Buffer);
     911    _snprintf(Buffer+n, sizeof(Buffer)-n, msg);
     912    MessageBox(hwndMain, Buffer, "Runtime Error", MB_OK | MB_ICONSTOP);
     913    return FALSE;
    914914}
    915915
    916916static BOOL notify (int code, char *fmt, ...)
    917917{
    918         char Buffer[1024];
    919         va_list marker;
    920         BOOL result = TRUE;
    921         int a, b;
    922         char *cp;
    923 
    924         va_start(marker, fmt);
    925         _vsnprintf(Buffer, sizeof(Buffer), fmt, marker);
    926 
    927         switch (code) {
     918    char Buffer[1024];
     919    va_list marker;
     920    BOOL result = TRUE;
     921    int a, b;
     922    char *cp;
     923
     924    va_start(marker, fmt);
     925    _vsnprintf(Buffer, sizeof(Buffer), fmt, marker);
     926
     927    switch (code) {
    928928/* Questions */
    929         case CAN_OVERWRITE:
    930                 break;
     929    case CAN_OVERWRITE:
     930        break;
    931931
    932932/* Information notification */
    933         case DIR_CREATED:
    934                 if (logfile)
    935                         fprintf(logfile, "100 Made Dir: %s\n", fmt);
    936                 break;
    937 
    938         case FILE_CREATED:
    939                 if (logfile)
    940                         fprintf(logfile, "200 File Copy: %s\n", fmt);
    941                 goto add_to_filelist_label;
    942                 break;
    943 
    944         case FILE_OVERWRITTEN:
    945                 if (logfile)
    946                         fprintf(logfile, "200 File Overwrite: %s\n", fmt);
    947           add_to_filelist_label:
    948                 if ((cp = strrchr(fmt, '.')) && (0 == strcmp (cp, ".py")))
    949                         add_to_filelist(fmt);
    950                 break;
     933    case DIR_CREATED:
     934        if (logfile)
     935            fprintf(logfile, "100 Made Dir: %s\n", fmt);
     936        break;
     937
     938    case FILE_CREATED:
     939        if (logfile)
     940            fprintf(logfile, "200 File Copy: %s\n", fmt);
     941        goto add_to_filelist_label;
     942        break;
     943
     944    case FILE_OVERWRITTEN:
     945        if (logfile)
     946            fprintf(logfile, "200 File Overwrite: %s\n", fmt);
     947      add_to_filelist_label:
     948        if ((cp = strrchr(fmt, '.')) && (0 == strcmp (cp, ".py")))
     949            add_to_filelist(fmt);
     950        break;
    951951
    952952/* Error Messages */
    953         case ZLIB_ERROR:
    954                 MessageBox(GetFocus(), Buffer, "Error",
    955                             MB_OK | MB_ICONWARNING);
    956                 break;
    957 
    958         case SYSTEM_ERROR:
    959                 SystemError(GetLastError(), Buffer);
    960                 break;
    961 
    962         case NUM_FILES:
    963                 a = va_arg(marker, int);
    964                 b = va_arg(marker, int);
    965                 SendMessage(hDialog, WM_NUMFILES, 0, MAKELPARAM(0, a));
    966                 SendMessage(hDialog, WM_NEXTFILE, b,(LPARAM)fmt);
    967         }
    968         va_end(marker);
    969    
    970         return result;
     953    case ZLIB_ERROR:
     954        MessageBox(GetFocus(), Buffer, "Error",
     955                    MB_OK | MB_ICONWARNING);
     956        break;
     957
     958    case SYSTEM_ERROR:
     959        SystemError(GetLastError(), Buffer);
     960        break;
     961
     962    case NUM_FILES:
     963        a = va_arg(marker, int);
     964        b = va_arg(marker, int);
     965        SendMessage(hDialog, WM_NUMFILES, 0, MAKELPARAM(0, a));
     966        SendMessage(hDialog, WM_NEXTFILE, b,(LPARAM)fmt);
     967    }
     968    va_end(marker);
     969
     970    return result;
    971971}
    972972
    973973static char *MapExistingFile(char *pathname, DWORD *psize)
    974974{
    975         HANDLE hFile, hFileMapping;
    976         DWORD nSizeLow, nSizeHigh;
    977         char *data;
    978 
    979         hFile = CreateFile(pathname,
    980                             GENERIC_READ, FILE_SHARE_READ, NULL,
    981                             OPEN_EXISTING,
    982                             FILE_ATTRIBUTE_NORMAL, NULL);
    983         if (hFile == INVALID_HANDLE_VALUE)
    984                 return NULL;
    985         nSizeLow = GetFileSize(hFile, &nSizeHigh);
    986         hFileMapping = CreateFileMapping(hFile,
    987                                           NULL, PAGE_READONLY, 0, 0, NULL);
    988         CloseHandle(hFile);
    989 
    990         if (hFileMapping == INVALID_HANDLE_VALUE)
    991                 return NULL;
    992    
    993         data = MapViewOfFile(hFileMapping,
    994                               FILE_MAP_READ, 0, 0, 0);
    995 
    996         CloseHandle(hFileMapping);
    997         *psize = nSizeLow;
    998         return data;
     975    HANDLE hFile, hFileMapping;
     976    DWORD nSizeLow, nSizeHigh;
     977    char *data;
     978
     979    hFile = CreateFile(pathname,
     980                        GENERIC_READ, FILE_SHARE_READ, NULL,
     981                        OPEN_EXISTING,
     982                        FILE_ATTRIBUTE_NORMAL, NULL);
     983    if (hFile == INVALID_HANDLE_VALUE)
     984        return NULL;
     985    nSizeLow = GetFileSize(hFile, &nSizeHigh);
     986    hFileMapping = CreateFileMapping(hFile,
     987                                      NULL, PAGE_READONLY, 0, 0, NULL);
     988    CloseHandle(hFile);
     989
     990    if (hFileMapping == INVALID_HANDLE_VALUE)
     991        return NULL;
     992
     993    data = MapViewOfFile(hFileMapping,
     994                          FILE_MAP_READ, 0, 0, 0);
     995
     996    CloseHandle(hFileMapping);
     997    *psize = nSizeLow;
     998    return data;
    999999}
    10001000
     
    10021002static void create_bitmap(HWND hwnd)
    10031003{
    1004         BITMAPFILEHEADER *bfh;
    1005         BITMAPINFO *bi;
    1006         HDC hdc;
    1007 
    1008         if (!bitmap_bytes)
    1009                 return;
    1010 
    1011         if (hBitmap)
    1012                 return;
    1013 
    1014         hdc = GetDC(hwnd);
    1015 
    1016         bfh = (BITMAPFILEHEADER *)bitmap_bytes;
    1017         bi = (BITMAPINFO *)(bitmap_bytes + sizeof(BITMAPFILEHEADER));
    1018 
    1019         hBitmap = CreateDIBitmap(hdc,
    1020                                 &bi->bmiHeader,
    1021                                 CBM_INIT,
    1022                                 bitmap_bytes + bfh->bfOffBits,
    1023                                 bi,
    1024                                 DIB_RGB_COLORS);
    1025         ReleaseDC(hwnd, hdc);
     1004    BITMAPFILEHEADER *bfh;
     1005    BITMAPINFO *bi;
     1006    HDC hdc;
     1007
     1008    if (!bitmap_bytes)
     1009        return;
     1010
     1011    if (hBitmap)
     1012        return;
     1013
     1014    hdc = GetDC(hwnd);
     1015
     1016    bfh = (BITMAPFILEHEADER *)bitmap_bytes;
     1017    bi = (BITMAPINFO *)(bitmap_bytes + sizeof(BITMAPFILEHEADER));
     1018
     1019    hBitmap = CreateDIBitmap(hdc,
     1020                            &bi->bmiHeader,
     1021                            CBM_INIT,
     1022                            bitmap_bytes + bfh->bfOffBits,
     1023                            bi,
     1024                            DIB_RGB_COLORS);
     1025    ReleaseDC(hwnd, hdc);
    10261026}
    10271027
     
    10301030*/
    10311031static BOOL ExtractInstallData(char *data, DWORD size, int *pexe_size,
    1032                                char **out_ini_file, char **out_preinstall_script)
    1033 {
    1034         /* read the end of central directory record */
    1035         struct eof_cdir *pe = (struct eof_cdir *)&data[size - sizeof
    1036                                                        (struct eof_cdir)];
    1037    
    1038         int arc_start = size - sizeof (struct eof_cdir) - pe->nBytesCDir -
    1039                 pe->ofsCDir;
    1040 
    1041         int ofs = arc_start - sizeof (struct meta_data_hdr);
    1042 
    1043         /* read meta_data info */
    1044         struct meta_data_hdr *pmd = (struct meta_data_hdr *)&data[ofs];
    1045         char *src, *dst;
    1046         char *ini_file;
    1047         char tempdir[MAX_PATH];
    1048 
    1049         /* ensure that if we fail, we don't have garbage out pointers */
    1050         *out_ini_file = *out_preinstall_script = NULL;
    1051 
    1052         if (pe->tag != 0x06054b50) {
    1053                 return FALSE;
    1054         }
    1055 
    1056         if (pmd->tag != 0x1234567B) {
    1057                 return SystemError(0,
    1058                            "Invalid cfgdata magic number (see bdist_wininst.py)");
    1059         }
    1060         if (ofs < 0) {
    1061                 return FALSE;
    1062         }
    1063 
    1064         if (pmd->bitmap_size) {
    1065                 /* Store pointer to bitmap bytes */
    1066                 bitmap_bytes = (char *)pmd - pmd->uncomp_size - pmd->bitmap_size;
    1067         }
    1068 
    1069         *pexe_size = ofs - pmd->uncomp_size - pmd->bitmap_size;
    1070 
    1071         src = ((char *)pmd) - pmd->uncomp_size;
    1072         ini_file = malloc(MAX_PATH); /* will be returned, so do not free it */
    1073         if (!ini_file)
    1074                 return FALSE;
    1075         if (!GetTempPath(sizeof(tempdir), tempdir)
    1076             || !GetTempFileName(tempdir, "~du", 0, ini_file)) {
    1077                 SystemError(GetLastError(),
    1078                              "Could not create temporary file");
    1079                 return FALSE;
    1080         }
    1081    
    1082         dst = map_new_file(CREATE_ALWAYS, ini_file, NULL, pmd->uncomp_size,
    1083                             0, 0, NULL/*notify*/);
    1084         if (!dst)
    1085                 return FALSE;
    1086         /* Up to the first \0 is the INI file data. */
    1087         strncpy(dst, src, pmd->uncomp_size);
    1088         src += strlen(dst) + 1;
    1089         /* Up to next \0 is the pre-install script */
    1090         *out_preinstall_script = strdup(src);
    1091         *out_ini_file = ini_file;
    1092         UnmapViewOfFile(dst);
    1093         return TRUE;
     1032                               char **out_ini_file, char **out_preinstall_script)
     1033{
     1034    /* read the end of central directory record */
     1035    struct eof_cdir *pe = (struct eof_cdir *)&data[size - sizeof
     1036                                                   (struct eof_cdir)];
     1037
     1038    int arc_start = size - sizeof (struct eof_cdir) - pe->nBytesCDir -
     1039        pe->ofsCDir;
     1040
     1041    int ofs = arc_start - sizeof (struct meta_data_hdr);
     1042
     1043    /* read meta_data info */
     1044    struct meta_data_hdr *pmd = (struct meta_data_hdr *)&data[ofs];
     1045    char *src, *dst;
     1046    char *ini_file;
     1047    char tempdir[MAX_PATH];
     1048
     1049    /* ensure that if we fail, we don't have garbage out pointers */
     1050    *out_ini_file = *out_preinstall_script = NULL;
     1051
     1052    if (pe->tag != 0x06054b50) {
     1053        return FALSE;
     1054    }
     1055
     1056    if (pmd->tag != 0x1234567B) {
     1057        return SystemError(0,
     1058                   "Invalid cfgdata magic number (see bdist_wininst.py)");
     1059    }
     1060    if (ofs < 0) {
     1061        return FALSE;
     1062    }
     1063
     1064    if (pmd->bitmap_size) {
     1065        /* Store pointer to bitmap bytes */
     1066        bitmap_bytes = (char *)pmd - pmd->uncomp_size - pmd->bitmap_size;
     1067    }
     1068
     1069    *pexe_size = ofs - pmd->uncomp_size - pmd->bitmap_size;
     1070
     1071    src = ((char *)pmd) - pmd->uncomp_size;
     1072    ini_file = malloc(MAX_PATH); /* will be returned, so do not free it */
     1073    if (!ini_file)
     1074        return FALSE;
     1075    if (!GetTempPath(sizeof(tempdir), tempdir)
     1076        || !GetTempFileName(tempdir, "~du", 0, ini_file)) {
     1077        SystemError(GetLastError(),
     1078                     "Could not create temporary file");
     1079        return FALSE;
     1080    }
     1081
     1082    dst = map_new_file(CREATE_ALWAYS, ini_file, NULL, pmd->uncomp_size,
     1083                        0, 0, NULL/*notify*/);
     1084    if (!dst)
     1085        return FALSE;
     1086    /* Up to the first \0 is the INI file data. */
     1087    strncpy(dst, src, pmd->uncomp_size);
     1088    src += strlen(dst) + 1;
     1089    /* Up to next \0 is the pre-install script */
     1090    *out_preinstall_script = strdup(src);
     1091    *out_ini_file = ini_file;
     1092    UnmapViewOfFile(dst);
     1093    return TRUE;
    10941094}
    10951095
    10961096static void PumpMessages(void)
    10971097{
    1098         MSG msg;
    1099         while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
    1100                 TranslateMessage(&msg);
    1101                 DispatchMessage(&msg);
    1102         }
     1098    MSG msg;
     1099    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
     1100        TranslateMessage(&msg);
     1101        DispatchMessage(&msg);
     1102    }
    11031103}
    11041104
     
    11061106WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    11071107{
    1108         HDC hdc;
    1109         HFONT hFont;
    1110         int h;
    1111         PAINTSTRUCT ps;
    1112         switch (msg) {
    1113         case WM_PAINT:
    1114                 hdc = BeginPaint(hwnd, &ps);
    1115                 h = GetSystemMetrics(SM_CYSCREEN) / 10;
    1116                 hFont = CreateFont(h, 0, 0, 0, 700, TRUE,
    1117                                     0, 0, 0, 0, 0, 0, 0, "Times Roman");
    1118                 hFont = SelectObject(hdc, hFont);
    1119                 SetBkMode(hdc, TRANSPARENT);
    1120                 TextOut(hdc, 15, 15, title, strlen(title));
    1121                 SetTextColor(hdc, RGB(255, 255, 255));
    1122                 TextOut(hdc, 10, 10, title, strlen(title));
    1123                 DeleteObject(SelectObject(hdc, hFont));
    1124                 EndPaint(hwnd, &ps);
    1125                 return 0;
    1126         }
    1127         return DefWindowProc(hwnd, msg, wParam, lParam);
     1108    HDC hdc;
     1109    HFONT hFont;
     1110    int h;
     1111    PAINTSTRUCT ps;
     1112    switch (msg) {
     1113    case WM_PAINT:
     1114        hdc = BeginPaint(hwnd, &ps);
     1115        h = GetSystemMetrics(SM_CYSCREEN) / 10;
     1116        hFont = CreateFont(h, 0, 0, 0, 700, TRUE,
     1117                            0, 0, 0, 0, 0, 0, 0, "Times Roman");
     1118        hFont = SelectObject(hdc, hFont);
     1119        SetBkMode(hdc, TRANSPARENT);
     1120        TextOut(hdc, 15, 15, title, strlen(title));
     1121        SetTextColor(hdc, RGB(255, 255, 255));
     1122        TextOut(hdc, 10, 10, title, strlen(title));
     1123        DeleteObject(SelectObject(hdc, hFont));
     1124        EndPaint(hwnd, &ps);
     1125        return 0;
     1126    }
     1127    return DefWindowProc(hwnd, msg, wParam, lParam);
    11281128}
    11291129
    11301130static HWND CreateBackground(char *title)
    11311131{
    1132         WNDCLASS wc;
    1133         HWND hwnd;
    1134         char buffer[4096];
    1135 
    1136         wc.style = CS_VREDRAW | CS_HREDRAW;
    1137         wc.lpfnWndProc = WindowProc;
    1138         wc.cbWndExtra = 0;
    1139         wc.cbClsExtra = 0;
    1140         wc.hInstance = GetModuleHandle(NULL);
    1141         wc.hIcon = NULL;
    1142         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    1143         wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 128));
    1144         wc.lpszMenuName = NULL;
    1145         wc.lpszClassName = "SetupWindowClass";
    1146 
    1147         if (!RegisterClass(&wc))
    1148                 MessageBox(hwndMain,
    1149                             "Could not register window class",
    1150                             "Setup.exe", MB_OK);
    1151 
    1152         wsprintf(buffer, "Setup %s", title);
    1153         hwnd = CreateWindow("SetupWindowClass",
    1154                              buffer,
    1155                              0,
    1156                              0, 0,
    1157                              GetSystemMetrics(SM_CXFULLSCREEN),
    1158                              GetSystemMetrics(SM_CYFULLSCREEN),
    1159                              NULL,
    1160                              NULL,
    1161                              GetModuleHandle(NULL),
    1162                              NULL);
    1163         ShowWindow(hwnd, SW_SHOWMAXIMIZED);
    1164         UpdateWindow(hwnd);
    1165         return hwnd;
     1132    WNDCLASS wc;
     1133    HWND hwnd;
     1134    char buffer[4096];
     1135
     1136    wc.style = CS_VREDRAW | CS_HREDRAW;
     1137    wc.lpfnWndProc = WindowProc;
     1138    wc.cbWndExtra = 0;
     1139    wc.cbClsExtra = 0;
     1140    wc.hInstance = GetModuleHandle(NULL);
     1141    wc.hIcon = NULL;
     1142    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
     1143    wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 128));
     1144    wc.lpszMenuName = NULL;
     1145    wc.lpszClassName = "SetupWindowClass";
     1146
     1147    if (!RegisterClass(&wc))
     1148        MessageBox(hwndMain,
     1149                    "Could not register window class",
     1150                    "Setup.exe", MB_OK);
     1151
     1152    wsprintf(buffer, "Setup %s", title);
     1153    hwnd = CreateWindow("SetupWindowClass",
     1154                         buffer,
     1155                         0,
     1156                         0, 0,
     1157                         GetSystemMetrics(SM_CXFULLSCREEN),
     1158                         GetSystemMetrics(SM_CYFULLSCREEN),
     1159                         NULL,
     1160                         NULL,
     1161                         GetModuleHandle(NULL),
     1162                         NULL);
     1163    ShowWindow(hwnd, SW_SHOWMAXIMIZED);
     1164    UpdateWindow(hwnd);
     1165    return hwnd;
    11661166}
    11671167
     
    11711171static void CenterWindow(HWND hwnd)
    11721172{
    1173         RECT rc;
    1174         int w, h;
    1175 
    1176         GetWindowRect(hwnd, &rc);
    1177         w = GetSystemMetrics(SM_CXSCREEN);
    1178         h = GetSystemMetrics(SM_CYSCREEN);
    1179         MoveWindow(hwnd,
    1180                    (w - (rc.right-rc.left))/2,
    1181                    (h - (rc.bottom-rc.top))/2,
    1182                     rc.right-rc.left, rc.bottom-rc.top, FALSE);
     1173    RECT rc;
     1174    int w, h;
     1175
     1176    GetWindowRect(hwnd, &rc);
     1177    w = GetSystemMetrics(SM_CXSCREEN);
     1178    h = GetSystemMetrics(SM_CYSCREEN);
     1179    MoveWindow(hwnd,
     1180               (w - (rc.right-rc.left))/2,
     1181               (h - (rc.bottom-rc.top))/2,
     1182                rc.right-rc.left, rc.bottom-rc.top, FALSE);
    11831183}
    11841184
     
    11881188IntroDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    11891189{
    1190         LPNMHDR lpnm;
    1191         char Buffer[4096];
    1192 
    1193         switch (msg) {
    1194         case WM_INITDIALOG:
    1195                 create_bitmap(hwnd);
    1196                 if(hBitmap)
    1197                         SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE,
    1198                                            IMAGE_BITMAP, (LPARAM)hBitmap);
    1199                 CenterWindow(GetParent(hwnd));
    1200                 wsprintf(Buffer,
    1201                           "This Wizard will install %s on your computer. "
    1202                           "Click Next to continue "
    1203                           "or Cancel to exit the Setup Wizard.",
    1204                           meta_name);
    1205                 SetDlgItemText(hwnd, IDC_TITLE, Buffer);
    1206                 SetDlgItemText(hwnd, IDC_INTRO_TEXT, info);
    1207                 SetDlgItemText(hwnd, IDC_BUILD_INFO, build_info);
    1208                 return FALSE;
    1209 
    1210         case WM_NOTIFY:
    1211                 lpnm = (LPNMHDR) lParam;
    1212 
    1213                 switch (lpnm->code) {
    1214                 case PSN_SETACTIVE:
    1215                         PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_NEXT);
    1216                         break;
    1217 
    1218                 case PSN_WIZNEXT:
    1219                         break;
    1220 
    1221                 case PSN_RESET:
    1222                         break;
    1223                
    1224                 default:
    1225                         break;
    1226                 }
    1227         }
    1228         return FALSE;
     1190    LPNMHDR lpnm;
     1191    char Buffer[4096];
     1192
     1193    switch (msg) {
     1194    case WM_INITDIALOG:
     1195        create_bitmap(hwnd);
     1196        if(hBitmap)
     1197            SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE,
     1198                               IMAGE_BITMAP, (LPARAM)hBitmap);
     1199        CenterWindow(GetParent(hwnd));
     1200        wsprintf(Buffer,
     1201                  "This Wizard will install %s on your computer. "
     1202                  "Click Next to continue "
     1203                  "or Cancel to exit the Setup Wizard.",
     1204                  meta_name);
     1205        SetDlgItemText(hwnd, IDC_TITLE, Buffer);
     1206        SetDlgItemText(hwnd, IDC_INTRO_TEXT, info);
     1207        SetDlgItemText(hwnd, IDC_BUILD_INFO, build_info);
     1208        return FALSE;
     1209
     1210    case WM_NOTIFY:
     1211        lpnm = (LPNMHDR) lParam;
     1212
     1213        switch (lpnm->code) {
     1214        case PSN_SETACTIVE:
     1215            PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_NEXT);
     1216            break;
     1217
     1218        case PSN_WIZNEXT:
     1219            break;
     1220
     1221        case PSN_RESET:
     1222            break;
     1223
     1224        default:
     1225            break;
     1226        }
     1227    }
     1228    return FALSE;
    12291229}
    12301230
     
    12381238
    12391239static BOOL __stdcall StatusRoutine(IMAGEHLP_STATUS_REASON reason,
    1240                                     PSTR ImageName,
    1241                                     PSTR DllName,
    1242                                     ULONG Va,
    1243                                     ULONG Parameter)
    1244 {
    1245         char fname[_MAX_PATH];
    1246         int int_version;
    1247 
    1248         switch(reason) {
    1249         case BindOutOfMemory:
    1250         case BindRvaToVaFailed:
    1251         case BindNoRoomInImage:
    1252         case BindImportProcedureFailed:
    1253                 break;
    1254 
    1255         case BindImportProcedure:
    1256         case BindForwarder:
    1257         case BindForwarderNOT:
    1258         case BindImageModified:
    1259         case BindExpandFileHeaders:
    1260         case BindImageComplete:
    1261         case BindSymbolsNotUpdated:
    1262         case BindMismatchedSymbols:
    1263         case BindImportModuleFailed:
    1264                 break;
    1265 
    1266         case BindImportModule:
    1267                 if (1 == sscanf(DllName, "python%d", &int_version)) {
    1268                         SearchPath(NULL, DllName, NULL, sizeof(fname),
    1269                                    fname, NULL);
    1270                         strcpy(bound_image_dll, fname);
    1271                         bound_image_major = int_version / 10;
    1272                         bound_image_minor = int_version % 10;
    1273                         OutputDebugString("BOUND ");
    1274                         OutputDebugString(fname);
    1275                         OutputDebugString("\n");
    1276                 }
    1277                 break;
    1278         }
    1279         return TRUE;
     1240                                    PSTR ImageName,
     1241                                    PSTR DllName,
     1242                                    ULONG Va,
     1243                                    ULONG Parameter)
     1244{
     1245    char fname[_MAX_PATH];
     1246    int int_version;
     1247
     1248    switch(reason) {
     1249    case BindOutOfMemory:
     1250    case BindRvaToVaFailed:
     1251    case BindNoRoomInImage:
     1252    case BindImportProcedureFailed:
     1253        break;
     1254
     1255    case BindImportProcedure:
     1256    case BindForwarder:
     1257    case BindForwarderNOT:
     1258    case BindImageModified:
     1259    case BindExpandFileHeaders:
     1260    case BindImageComplete:
     1261    case BindSymbolsNotUpdated:
     1262    case BindMismatchedSymbols:
     1263    case BindImportModuleFailed:
     1264        break;
     1265
     1266    case BindImportModule:
     1267        if (1 == sscanf(DllName, "python%d", &int_version)) {
     1268            SearchPath(NULL, DllName, NULL, sizeof(fname),
     1269                       fname, NULL);
     1270            strcpy(bound_image_dll, fname);
     1271            bound_image_major = int_version / 10;
     1272            bound_image_minor = int_version % 10;
     1273            OutputDebugString("BOUND ");
     1274            OutputDebugString(fname);
     1275            OutputDebugString("\n");
     1276        }
     1277        break;
     1278    }
     1279    return TRUE;
    12801280}
    12811281
     
    12841284static LPSTR get_sys_prefix(LPSTR exe, LPSTR dll)
    12851285{
    1286         void (__cdecl * Py_Initialize)(void);
    1287         void (__cdecl * Py_SetProgramName)(char *);
    1288         void (__cdecl * Py_Finalize)(void);
    1289         void* (__cdecl * PySys_GetObject)(char *);
    1290         void (__cdecl * PySys_SetArgv)(int, char **);
    1291         char* (__cdecl * Py_GetPrefix)(void);
    1292         char* (__cdecl * Py_GetPath)(void);
    1293         HINSTANCE hPython;
    1294         LPSTR prefix = NULL;
    1295         int (__cdecl * PyRun_SimpleString)(char *);
    1296 
    1297         {
    1298                 char Buffer[256];
    1299                 wsprintf(Buffer, "PYTHONHOME=%s", exe);
    1300                 *strrchr(Buffer, '\\') = '\0';
    1301 //      MessageBox(GetFocus(), Buffer, "PYTHONHOME", MB_OK);
    1302                 _putenv(Buffer);
    1303                 _putenv("PYTHONPATH=");
    1304         }
    1305 
    1306         hPython = LoadLibrary(dll);
    1307         if (!hPython)
    1308                 return NULL;
    1309         Py_Initialize = (void (*)(void))GetProcAddress
    1310                 (hPython,"Py_Initialize");
    1311 
    1312         PySys_SetArgv = (void (*)(int, char **))GetProcAddress
    1313                 (hPython,"PySys_SetArgv");
    1314 
    1315         PyRun_SimpleString = (int (*)(char *))GetProcAddress
    1316                 (hPython,"PyRun_SimpleString");
    1317 
    1318         Py_SetProgramName = (void (*)(char *))GetProcAddress
    1319                 (hPython,"Py_SetProgramName");
    1320 
    1321         PySys_GetObject = (void* (*)(char *))GetProcAddress
    1322                 (hPython,"PySys_GetObject");
    1323 
    1324         Py_GetPrefix = (char * (*)(void))GetProcAddress
    1325                 (hPython,"Py_GetPrefix");
    1326 
    1327         Py_GetPath = (char * (*)(void))GetProcAddress
    1328                 (hPython,"Py_GetPath");
    1329 
    1330         Py_Finalize = (void (*)(void))GetProcAddress(hPython,
    1331                                                       "Py_Finalize");
    1332         Py_SetProgramName(exe);
    1333         Py_Initialize();
    1334         PySys_SetArgv(1, &exe);
    1335 
    1336         MessageBox(GetFocus(), Py_GetPrefix(), "PREFIX", MB_OK);
    1337         MessageBox(GetFocus(), Py_GetPath(), "PATH", MB_OK);
    1338 
    1339         Py_Finalize();
    1340         FreeLibrary(hPython);
    1341 
    1342         return prefix;
     1286    void (__cdecl * Py_Initialize)(void);
     1287    void (__cdecl * Py_SetProgramName)(char *);
     1288    void (__cdecl * Py_Finalize)(void);
     1289    void* (__cdecl * PySys_GetObject)(char *);
     1290    void (__cdecl * PySys_SetArgv)(int, char **);
     1291    char* (__cdecl * Py_GetPrefix)(void);
     1292    char* (__cdecl * Py_GetPath)(void);
     1293    HINSTANCE hPython;
     1294    LPSTR prefix = NULL;
     1295    int (__cdecl * PyRun_SimpleString)(char *);
     1296
     1297    {
     1298        char Buffer[256];
     1299        wsprintf(Buffer, "PYTHONHOME=%s", exe);
     1300        *strrchr(Buffer, '\\') = '\0';
     1301//      MessageBox(GetFocus(), Buffer, "PYTHONHOME", MB_OK);
     1302                _putenv(Buffer);
     1303                _putenv("PYTHONPATH=");
     1304    }
     1305
     1306    hPython = LoadLibrary(dll);
     1307    if (!hPython)
     1308        return NULL;
     1309    Py_Initialize = (void (*)(void))GetProcAddress
     1310        (hPython,"Py_Initialize");
     1311
     1312    PySys_SetArgv = (void (*)(int, char **))GetProcAddress
     1313        (hPython,"PySys_SetArgv");
     1314
     1315    PyRun_SimpleString = (int (*)(char *))GetProcAddress
     1316        (hPython,"PyRun_SimpleString");
     1317
     1318    Py_SetProgramName = (void (*)(char *))GetProcAddress
     1319        (hPython,"Py_SetProgramName");
     1320
     1321    PySys_GetObject = (void* (*)(char *))GetProcAddress
     1322        (hPython,"PySys_GetObject");
     1323
     1324    Py_GetPrefix = (char * (*)(void))GetProcAddress
     1325        (hPython,"Py_GetPrefix");
     1326
     1327    Py_GetPath = (char * (*)(void))GetProcAddress
     1328        (hPython,"Py_GetPath");
     1329
     1330    Py_Finalize = (void (*)(void))GetProcAddress(hPython,
     1331                                                  "Py_Finalize");
     1332    Py_SetProgramName(exe);
     1333    Py_Initialize();
     1334    PySys_SetArgv(1, &exe);
     1335
     1336    MessageBox(GetFocus(), Py_GetPrefix(), "PREFIX", MB_OK);
     1337    MessageBox(GetFocus(), Py_GetPath(), "PATH", MB_OK);
     1338
     1339    Py_Finalize();
     1340    FreeLibrary(hPython);
     1341
     1342    return prefix;
    13431343}
    13441344
     
    13461346CheckPythonExe(LPSTR pathname, LPSTR version, int *pmajor, int *pminor)
    13471347{
    1348         bound_image_dll[0] = '\0';
    1349         if (!BindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES,
    1350                         pathname,
    1351                         NULL,
    1352                         NULL,
    1353                         StatusRoutine))
    1354                 return SystemError(0, "Could not bind image");
    1355         if (bound_image_dll[0] == '\0')
    1356                 return SystemError(0, "Does not seem to be a python executable");
    1357         *pmajor = bound_image_major;
    1358         *pminor = bound_image_minor;
    1359         if (version && *version) {
    1360                 char core_version[12];
    1361                 wsprintf(core_version, "%d.%d", bound_image_major, bound_image_minor);
    1362                 if (strcmp(version, core_version))
    1363                         return SystemError(0, "Wrong Python version");
    1364         }
    1365         get_sys_prefix(pathname, bound_image_dll);
    1366         return TRUE;
     1348    bound_image_dll[0] = '\0';
     1349    if (!BindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES,
     1350                    pathname,
     1351                    NULL,
     1352                    NULL,
     1353                    StatusRoutine))
     1354        return SystemError(0, "Could not bind image");
     1355    if (bound_image_dll[0] == '\0')
     1356        return SystemError(0, "Does not seem to be a python executable");
     1357    *pmajor = bound_image_major;
     1358    *pminor = bound_image_minor;
     1359    if (version && *version) {
     1360        char core_version[12];
     1361        wsprintf(core_version, "%d.%d", bound_image_major, bound_image_minor);
     1362        if (strcmp(version, core_version))
     1363            return SystemError(0, "Wrong Python version");
     1364    }
     1365    get_sys_prefix(pathname, bound_image_dll);
     1366    return TRUE;
    13671367}
    13681368
     
    13731373static BOOL GetOtherPythonVersion(HWND hwnd, LPSTR version)
    13741374{
    1375         char vers_name[_MAX_PATH + 80];
    1376         DWORD itemindex;
    1377         OPENFILENAME of;
    1378         char pathname[_MAX_PATH];
    1379         DWORD result;
    1380 
    1381         strcpy(pathname, "python.exe");
    1382 
    1383         memset(&of, 0, sizeof(of));
    1384         of.lStructSize = sizeof(OPENFILENAME);
    1385         of.hwndOwner = GetParent(hwnd);
    1386         of.hInstance = NULL;
    1387         of.lpstrFilter = "python.exe\0python.exe\0";
    1388         of.lpstrCustomFilter = NULL;
    1389         of.nMaxCustFilter = 0;
    1390         of.nFilterIndex = 1;
    1391         of.lpstrFile = pathname;
    1392         of.nMaxFile = sizeof(pathname);
    1393         of.lpstrFileTitle = NULL;
    1394         of.nMaxFileTitle = 0;
    1395         of.lpstrInitialDir = NULL;
    1396         of.lpstrTitle = "Python executable";
    1397         of.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
    1398         of.lpstrDefExt = "exe";
    1399 
    1400         result = GetOpenFileName(&of);
    1401         if (result) {
    1402                 int major, minor;
    1403                 if (!CheckPythonExe(pathname, version, &major, &minor)) {
    1404                         return FALSE;
    1405                 }
    1406                 *strrchr(pathname, '\\') = '\0';
    1407                 wsprintf(vers_name, "Python Version %d.%d in %s",
    1408                           major, minor, pathname);
    1409                 itemindex = SendMessage(hwnd, LB_INSERTSTRING, -1,
    1410                                         (LPARAM)(LPSTR)vers_name);
    1411                 SendMessage(hwnd, LB_SETCURSEL, itemindex, 0);
    1412                 SendMessage(hwnd, LB_SETITEMDATA, itemindex,
    1413                             (LPARAM)(LPSTR)strdup(pathname));
    1414                 return TRUE;
    1415         }
    1416         return FALSE;
     1375    char vers_name[_MAX_PATH + 80];
     1376    DWORD itemindex;
     1377    OPENFILENAME of;
     1378    char pathname[_MAX_PATH];
     1379    DWORD result;
     1380
     1381    strcpy(pathname, "python.exe");
     1382
     1383    memset(&of, 0, sizeof(of));
     1384    of.lStructSize = sizeof(OPENFILENAME);
     1385    of.hwndOwner = GetParent(hwnd);
     1386    of.hInstance = NULL;
     1387    of.lpstrFilter = "python.exe\0python.exe\0";
     1388    of.lpstrCustomFilter = NULL;
     1389    of.nMaxCustFilter = 0;
     1390    of.nFilterIndex = 1;
     1391    of.lpstrFile = pathname;
     1392    of.nMaxFile = sizeof(pathname);
     1393    of.lpstrFileTitle = NULL;
     1394    of.nMaxFileTitle = 0;
     1395    of.lpstrInitialDir = NULL;
     1396    of.lpstrTitle = "Python executable";
     1397    of.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
     1398    of.lpstrDefExt = "exe";
     1399
     1400    result = GetOpenFileName(&of);
     1401    if (result) {
     1402        int major, minor;
     1403        if (!CheckPythonExe(pathname, version, &major, &minor)) {
     1404            return FALSE;
     1405        }
     1406        *strrchr(pathname, '\\') = '\0';
     1407        wsprintf(vers_name, "Python Version %d.%d in %s",
     1408                  major, minor, pathname);
     1409        itemindex = SendMessage(hwnd, LB_INSERTSTRING, -1,
     1410                                (LPARAM)(LPSTR)vers_name);
     1411        SendMessage(hwnd, LB_SETCURSEL, itemindex, 0);
     1412        SendMessage(hwnd, LB_SETITEMDATA, itemindex,
     1413                    (LPARAM)(LPSTR)strdup(pathname));
     1414        return TRUE;
     1415    }
     1416    return FALSE;
    14171417}
    14181418#endif /* USE_OTHER_PYTHON_VERSIONS */
     
    14311431static BOOL GetPythonVersions(HWND hwnd, HKEY hkRoot, LPSTR version)
    14321432{
    1433         DWORD index = 0;
    1434         char core_version[80];
    1435         HKEY hKey;
    1436         BOOL result = TRUE;
    1437         DWORD bufsize;
    1438 
    1439         if (ERROR_SUCCESS != RegOpenKeyEx(hkRoot,
    1440                                            "Software\\Python\\PythonCore",
    1441                                            0,   KEY_READ, &hKey))
    1442                 return FALSE;
    1443         bufsize = sizeof(core_version);
    1444         while (ERROR_SUCCESS == RegEnumKeyEx(hKey, index,
    1445                                               core_version, &bufsize, NULL,
    1446                                               NULL, NULL, NULL)) {
    1447                 char subkey_name[80], vers_name[80];
    1448                 int itemindex;
    1449                 DWORD value_size;
    1450                 HKEY hk;
    1451 
    1452                 bufsize = sizeof(core_version);
    1453                 ++index;
    1454                 if (version && *version && strcmp(version, core_version))
    1455                         continue;
    1456 
    1457                 wsprintf(vers_name, "Python Version %s (found in registry)",
    1458                           core_version);
    1459                 wsprintf(subkey_name,
    1460                           "Software\\Python\\PythonCore\\%s\\InstallPath",
    1461                           core_version);
    1462                 if (ERROR_SUCCESS == RegOpenKeyEx(hkRoot, subkey_name, 0, KEY_READ, &hk)) {
    1463                         InstalledVersionInfo *ivi =
    1464                               (InstalledVersionInfo *)malloc(sizeof(InstalledVersionInfo));
    1465                         value_size = sizeof(ivi->prefix);
    1466                         if (ivi &&
    1467                             ERROR_SUCCESS == RegQueryValueEx(hk, NULL, NULL, NULL,
    1468                                                              ivi->prefix, &value_size)) {
    1469                                 itemindex = SendMessage(hwnd, LB_ADDSTRING, 0,
    1470                                                         (LPARAM)(LPSTR)vers_name);
    1471                                 ivi->hkey = hkRoot;
    1472                                 SendMessage(hwnd, LB_SETITEMDATA, itemindex,
    1473                                             (LPARAM)(LPSTR)ivi);
    1474                         }
    1475                         RegCloseKey(hk);
    1476                 }
    1477         }
    1478         RegCloseKey(hKey);
    1479         return result;
     1433    DWORD index = 0;
     1434    char core_version[80];
     1435    HKEY hKey;
     1436    BOOL result = TRUE;
     1437    DWORD bufsize;
     1438
     1439    if (ERROR_SUCCESS != RegOpenKeyEx(hkRoot,
     1440                                       "Software\\Python\\PythonCore",
     1441                                       0,       KEY_READ, &hKey))
     1442        return FALSE;
     1443    bufsize = sizeof(core_version);
     1444    while (ERROR_SUCCESS == RegEnumKeyEx(hKey, index,
     1445                                          core_version, &bufsize, NULL,
     1446                                          NULL, NULL, NULL)) {
     1447        char subkey_name[80], vers_name[80];
     1448        int itemindex;
     1449        DWORD value_size;
     1450        HKEY hk;
     1451
     1452        bufsize = sizeof(core_version);
     1453        ++index;
     1454        if (version && *version && strcmp(version, core_version))
     1455            continue;
     1456
     1457        wsprintf(vers_name, "Python Version %s (found in registry)",
     1458                  core_version);
     1459        wsprintf(subkey_name,
     1460                  "Software\\Python\\PythonCore\\%s\\InstallPath",
     1461                  core_version);
     1462        if (ERROR_SUCCESS == RegOpenKeyEx(hkRoot, subkey_name, 0, KEY_READ, &hk)) {
     1463            InstalledVersionInfo *ivi =
     1464                  (InstalledVersionInfo *)malloc(sizeof(InstalledVersionInfo));
     1465            value_size = sizeof(ivi->prefix);
     1466            if (ivi &&
     1467                ERROR_SUCCESS == RegQueryValueEx(hk, NULL, NULL, NULL,
     1468                                                 ivi->prefix, &value_size)) {
     1469                itemindex = SendMessage(hwnd, LB_ADDSTRING, 0,
     1470                                        (LPARAM)(LPSTR)vers_name);
     1471                ivi->hkey = hkRoot;
     1472                SendMessage(hwnd, LB_SETITEMDATA, itemindex,
     1473                            (LPARAM)(LPSTR)ivi);
     1474            }
     1475            RegCloseKey(hk);
     1476        }
     1477    }
     1478    RegCloseKey(hKey);
     1479    return result;
    14801480}
    14811481
     
    14831483BOOL HasLocalMachinePrivs()
    14841484{
    1485                 HKEY hKey;
    1486                 DWORD result;
    1487                 static char KeyName[] =
    1488                         "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
    1489 
    1490                 result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
    1491                                           KeyName,
    1492                                           0,
    1493                                           KEY_CREATE_SUB_KEY,
    1494                                           &hKey);
    1495                 if (result==0)
    1496                         RegCloseKey(hKey);
    1497                 return result==0;
     1485                HKEY hKey;
     1486                DWORD result;
     1487                static char KeyName[] =
     1488                        "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
     1489
     1490                result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
     1491                                          KeyName,
     1492                                          0,
     1493                                          KEY_CREATE_SUB_KEY,
     1494                                          &hKey);
     1495                if (result==0)
     1496                        RegCloseKey(hKey);
     1497                return result==0;
    14981498}
    14991499
     
    15081508void CheckRootKey(HWND hwnd)
    15091509{
    1510         if (hkey_root==HKEY_CURRENT_USER) {
    1511                 ; // as above, always install ourself in HKCU too.
    1512         } else if (hkey_root==HKEY_LOCAL_MACHINE) {
    1513                 // Python in HKLM, but we may or may not have permissions there.
    1514                 // Open the uninstall key with 'create' permissions - if this fails,
    1515                 // we don't have permission.
    1516                 if (!HasLocalMachinePrivs())
    1517                         hkey_root = HKEY_CURRENT_USER;
    1518         } else {
    1519                 MessageBox(hwnd, "Don't know Python's installation type",
    1520                                    "Strange", MB_OK | MB_ICONSTOP);
    1521                 /* Default to wherever they can, but preferring HKLM */
    1522                 hkey_root = HasLocalMachinePrivs() ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
    1523         }
     1510    if (hkey_root==HKEY_CURRENT_USER) {
     1511        ; // as above, always install ourself in HKCU too.
     1512    } else if (hkey_root==HKEY_LOCAL_MACHINE) {
     1513        // Python in HKLM, but we may or may not have permissions there.
     1514        // Open the uninstall key with 'create' permissions - if this fails,
     1515        // we don't have permission.
     1516        if (!HasLocalMachinePrivs())
     1517            hkey_root = HKEY_CURRENT_USER;
     1518    } else {
     1519        MessageBox(hwnd, "Don't know Python's installation type",
     1520                           "Strange", MB_OK | MB_ICONSTOP);
     1521        /* Default to wherever they can, but preferring HKLM */
     1522        hkey_root = HasLocalMachinePrivs() ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
     1523    }
    15241524}
    15251525
     
    15271527SCHEME *GetScheme(int major, int minor)
    15281528{
    1529         if (major > 2)
    1530                 return new_scheme;
    1531         else if((major == 2) && (minor >= 2))
    1532                 return new_scheme;
    1533         return old_scheme;
     1529    if (major > 2)
     1530        return new_scheme;
     1531    else if((major == 2) && (minor >= 2))
     1532        return new_scheme;
     1533    return old_scheme;
    15341534}
    15351535
     
    15371537SelectPythonDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    15381538{
    1539         LPNMHDR lpnm;
    1540 
    1541         switch (msg) {
    1542         case WM_INITDIALOG:
    1543                 if (hBitmap)
    1544                         SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE,
    1545                                            IMAGE_BITMAP, (LPARAM)hBitmap);
    1546                 GetPythonVersions(GetDlgItem(hwnd, IDC_VERSIONS_LIST),
    1547                                    HKEY_LOCAL_MACHINE, target_version);
    1548                 GetPythonVersions(GetDlgItem(hwnd, IDC_VERSIONS_LIST),
    1549                                    HKEY_CURRENT_USER, target_version);
    1550                 {       /* select the last entry which is the highest python
    1551                            version found */
    1552                         int count;
    1553                         count = SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
    1554                                                     LB_GETCOUNT, 0, 0);
    1555                         if (count && count != LB_ERR)
    1556                                 SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST, LB_SETCURSEL,
    1557                                                     count-1, 0);
    1558            
    1559                         /* If a specific Python version is required,
    1560                         * display a prominent notice showing this fact.
    1561                         */
    1562                         if (target_version && target_version[0]) {
    1563                                 char buffer[4096];
    1564                                 wsprintf(buffer,
    1565                                         "Python %s is required for this package. "
    1566                                         "Select installation to use:",
    1567                                         target_version);
    1568                                 SetDlgItemText(hwnd, IDC_TITLE, buffer);
    1569                         }
    1570 
    1571                         if (count == 0) {
    1572                                 char Buffer[4096];
    1573                                 char *msg;
    1574                                 if (target_version && target_version[0]) {
    1575                                         wsprintf(Buffer,
    1576                                                 "Python version %s required, which was not found"
    1577                                                 " in the registry.", target_version);
    1578                                         msg = Buffer;
    1579                                 } else
    1580                                         msg = "No Python installation found in the registry.";
    1581                                 MessageBox(hwnd, msg, "Cannot install",
    1582                                            MB_OK | MB_ICONSTOP);
    1583                         }
    1584                 }
    1585                 goto UpdateInstallDir;
    1586                 break;
    1587 
    1588         case WM_COMMAND:
    1589                 switch (LOWORD(wParam)) {
     1539    LPNMHDR lpnm;
     1540
     1541    switch (msg) {
     1542    case WM_INITDIALOG:
     1543        if (hBitmap)
     1544            SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE,
     1545                               IMAGE_BITMAP, (LPARAM)hBitmap);
     1546        GetPythonVersions(GetDlgItem(hwnd, IDC_VERSIONS_LIST),
     1547                           HKEY_LOCAL_MACHINE, target_version);
     1548        GetPythonVersions(GetDlgItem(hwnd, IDC_VERSIONS_LIST),
     1549                           HKEY_CURRENT_USER, target_version);
     1550        {               /* select the last entry which is the highest python
     1551                   version found */
     1552            int count;
     1553            count = SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
     1554                                        LB_GETCOUNT, 0, 0);
     1555            if (count && count != LB_ERR)
     1556                SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST, LB_SETCURSEL,
     1557                                    count-1, 0);
     1558
     1559            /* If a specific Python version is required,
     1560            * display a prominent notice showing this fact.
     1561            */
     1562            if (target_version && target_version[0]) {
     1563                char buffer[4096];
     1564                wsprintf(buffer,
     1565                        "Python %s is required for this package. "
     1566                        "Select installation to use:",
     1567                        target_version);
     1568                SetDlgItemText(hwnd, IDC_TITLE, buffer);
     1569            }
     1570
     1571            if (count == 0) {
     1572                char Buffer[4096];
     1573                char *msg;
     1574                if (target_version && target_version[0]) {
     1575                    wsprintf(Buffer,
     1576                            "Python version %s required, which was not found"
     1577                            " in the registry.", target_version);
     1578                    msg = Buffer;
     1579                } else
     1580                    msg = "No Python installation found in the registry.";
     1581                MessageBox(hwnd, msg, "Cannot install",
     1582                           MB_OK | MB_ICONSTOP);
     1583            }
     1584        }
     1585        goto UpdateInstallDir;
     1586        break;
     1587
     1588    case WM_COMMAND:
     1589        switch (LOWORD(wParam)) {
    15901590/*
    15911591  case IDC_OTHERPYTHON:
     
    15951595  break;
    15961596*/
    1597                 case IDC_VERSIONS_LIST:
    1598                         switch (HIWORD(wParam)) {
    1599                                 int id;
    1600                         case LBN_SELCHANGE:
    1601                           UpdateInstallDir:
    1602                                 PropSheet_SetWizButtons(GetParent(hwnd),
    1603                                                         PSWIZB_BACK | PSWIZB_NEXT);
    1604                                 id = SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
    1605                                                         LB_GETCURSEL, 0, 0);
    1606                                 if (id == LB_ERR) {
    1607                                         PropSheet_SetWizButtons(GetParent(hwnd),
    1608                                                                 PSWIZB_BACK);
    1609                                         SetDlgItemText(hwnd, IDC_PATH, "");
    1610                                         SetDlgItemText(hwnd, IDC_INSTALL_PATH, "");
    1611                                         strcpy(python_dir, "");
    1612                                         strcpy(pythondll, "");
    1613                                 } else {
    1614                                         char *pbuf;
    1615                                         int result;
    1616                                         InstalledVersionInfo *ivi;
    1617                                         PropSheet_SetWizButtons(GetParent(hwnd),
    1618                                                                 PSWIZB_BACK | PSWIZB_NEXT);
    1619                                         /* Get the python directory */
    1620                     ivi = (InstalledVersionInfo *)
    1621                                 SendDlgItemMessage(hwnd,
    1622                                                                         IDC_VERSIONS_LIST,
    1623                                                                         LB_GETITEMDATA,
    1624                                                                         id,
    1625                                                                         0);
    1626                     hkey_root = ivi->hkey;
    1627                                         strcpy(python_dir, ivi->prefix);
    1628                                         SetDlgItemText(hwnd, IDC_PATH, python_dir);
    1629                                         /* retrieve the python version and pythondll to use */
    1630                                         result = SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
    1631                                                                      LB_GETTEXTLEN, (WPARAM)id, 0);
    1632                                         pbuf = (char *)malloc(result + 1);
    1633                                         if (pbuf) {
    1634                                                 /* guess the name of the python-dll */
    1635                                                 SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
    1636                                                                     LB_GETTEXT, (WPARAM)id,
    1637                                                                     (LPARAM)pbuf);
    1638                                                 result = sscanf(pbuf, "Python Version %d.%d",
    1639                                                                 &py_major, &py_minor);
    1640                                                 if (result == 2) {
     1597        case IDC_VERSIONS_LIST:
     1598            switch (HIWORD(wParam)) {
     1599                int id;
     1600            case LBN_SELCHANGE:
     1601              UpdateInstallDir:
     1602                PropSheet_SetWizButtons(GetParent(hwnd),
     1603                                        PSWIZB_BACK | PSWIZB_NEXT);
     1604                id = SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
     1605                                        LB_GETCURSEL, 0, 0);
     1606                if (id == LB_ERR) {
     1607                    PropSheet_SetWizButtons(GetParent(hwnd),
     1608                                            PSWIZB_BACK);
     1609                    SetDlgItemText(hwnd, IDC_PATH, "");
     1610                    SetDlgItemText(hwnd, IDC_INSTALL_PATH, "");
     1611                    strcpy(python_dir, "");
     1612                    strcpy(pythondll, "");
     1613                } else {
     1614                    char *pbuf;
     1615                    int result;
     1616                    InstalledVersionInfo *ivi;
     1617                    PropSheet_SetWizButtons(GetParent(hwnd),
     1618                                            PSWIZB_BACK | PSWIZB_NEXT);
     1619                    /* Get the python directory */
     1620            ivi = (InstalledVersionInfo *)
     1621                        SendDlgItemMessage(hwnd,
     1622                                                                IDC_VERSIONS_LIST,
     1623                                                                LB_GETITEMDATA,
     1624                                                                id,
     1625                                                                0);
     1626            hkey_root = ivi->hkey;
     1627                                strcpy(python_dir, ivi->prefix);
     1628                                SetDlgItemText(hwnd, IDC_PATH, python_dir);
     1629                                /* retrieve the python version and pythondll to use */
     1630                    result = SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
     1631                                                 LB_GETTEXTLEN, (WPARAM)id, 0);
     1632                    pbuf = (char *)malloc(result + 1);
     1633                    if (pbuf) {
     1634                        /* guess the name of the python-dll */
     1635                        SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
     1636                                            LB_GETTEXT, (WPARAM)id,
     1637                                            (LPARAM)pbuf);
     1638                        result = sscanf(pbuf, "Python Version %d.%d",
     1639                                        &py_major, &py_minor);
     1640                        if (result == 2) {
    16411641#ifdef _DEBUG
    1642                                                         wsprintf(pythondll, "python%d%d_d.dll",
    1643                                                                 py_major, py_minor);
     1642                            wsprintf(pythondll, "python%d%d_d.dll",
     1643                                    py_major, py_minor);
    16441644#else
    1645                                                         wsprintf(pythondll, "python%d%d.dll",
    1646                                                                 py_major, py_minor);
     1645                            wsprintf(pythondll, "python%d%d.dll",
     1646                                    py_major, py_minor);
    16471647#endif
    1648                                                 }
    1649                                                 free(pbuf);
    1650                                         } else
    1651                                                 strcpy(pythondll, "");
    1652                                         /* retrieve the scheme for this version */
    1653                                         {
    1654                                                 char install_path[_MAX_PATH];
    1655                                                 SCHEME *scheme = GetScheme(py_major, py_minor);
    1656                                                 strcpy(install_path, python_dir);
    1657                                                 if (install_path[strlen(install_path)-1] != '\\')
    1658                                                         strcat(install_path, "\\");
    1659                                                 strcat(install_path, scheme[0].prefix);
    1660                                                 SetDlgItemText(hwnd, IDC_INSTALL_PATH, install_path);
    1661                                         }
    1662                                 }
    1663                         }
    1664                         break;
    1665                 }
    1666                 return 0;
    1667 
    1668         case WM_NOTIFY:
    1669                 lpnm = (LPNMHDR) lParam;
    1670 
    1671                 switch (lpnm->code) {
    1672                         int id;
    1673                 case PSN_SETACTIVE:
    1674                         id = SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
    1675                                                 LB_GETCURSEL, 0, 0);
    1676                         if (id == LB_ERR)
    1677                                 PropSheet_SetWizButtons(GetParent(hwnd),
    1678                                                         PSWIZB_BACK);
    1679                         else
    1680                                 PropSheet_SetWizButtons(GetParent(hwnd),
    1681                                                         PSWIZB_BACK | PSWIZB_NEXT);
    1682                         break;
    1683 
    1684                 case PSN_WIZNEXT:
    1685                         break;
    1686 
    1687                 case PSN_WIZFINISH:
    1688                         break;
    1689 
    1690                 case PSN_RESET:
    1691                         break;
    1692                
    1693                 default:
    1694                         break;
    1695                 }
    1696         }
    1697         return 0;
     1648                        }
     1649                        free(pbuf);
     1650                    } else
     1651                        strcpy(pythondll, "");
     1652                    /* retrieve the scheme for this version */
     1653                    {
     1654                        char install_path[_MAX_PATH];
     1655                        SCHEME *scheme = GetScheme(py_major, py_minor);
     1656                        strcpy(install_path, python_dir);
     1657                        if (install_path[strlen(install_path)-1] != '\\')
     1658                            strcat(install_path, "\\");
     1659                        strcat(install_path, scheme[0].prefix);
     1660                        SetDlgItemText(hwnd, IDC_INSTALL_PATH, install_path);
     1661                    }
     1662                }
     1663            }
     1664            break;
     1665        }
     1666        return 0;
     1667
     1668    case WM_NOTIFY:
     1669        lpnm = (LPNMHDR) lParam;
     1670
     1671        switch (lpnm->code) {
     1672            int id;
     1673        case PSN_SETACTIVE:
     1674            id = SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
     1675                                    LB_GETCURSEL, 0, 0);
     1676            if (id == LB_ERR)
     1677                PropSheet_SetWizButtons(GetParent(hwnd),
     1678                                        PSWIZB_BACK);
     1679            else
     1680                PropSheet_SetWizButtons(GetParent(hwnd),
     1681                                        PSWIZB_BACK | PSWIZB_NEXT);
     1682            break;
     1683
     1684        case PSN_WIZNEXT:
     1685            break;
     1686
     1687        case PSN_WIZFINISH:
     1688            break;
     1689
     1690        case PSN_RESET:
     1691            break;
     1692
     1693        default:
     1694            break;
     1695        }
     1696    }
     1697    return 0;
    16981698}
    16991699
    17001700static BOOL OpenLogfile(char *dir)
    17011701{
    1702         char buffer[_MAX_PATH+1];
    1703         time_t ltime;
    1704         struct tm *now;
    1705         long result;
    1706         HKEY hKey, hSubkey;
    1707         char subkey_name[256];
    1708         static char KeyName[] =
    1709                 "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
    1710         const char *root_name = (hkey_root==HKEY_LOCAL_MACHINE ?
    1711                                 "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER");
    1712         DWORD disposition;
    1713 
    1714         /* Use Create, as the Uninstall subkey may not exist under HKCU.
    1715            Use CreateKeyEx, so we can specify a SAM specifying write access
    1716         */
    1717                 result = RegCreateKeyEx(hkey_root,
    1718                               KeyName,
    1719                               0, /* reserved */
    1720                               NULL, /* class */
    1721                               0, /* options */
    1722                               KEY_CREATE_SUB_KEY, /* sam */
    1723                               NULL, /* security */
    1724                               &hKey, /* result key */
    1725                               NULL); /* disposition */
    1726         if (result != ERROR_SUCCESS) {
    1727                 if (result == ERROR_ACCESS_DENIED) {
    1728                         /* This should no longer be able to happen - we have already
    1729                            checked if they have permissions in HKLM, and all users
    1730                            should have write access to HKCU.
    1731                         */
    1732                         MessageBox(GetFocus(),
    1733                                    "You do not seem to have sufficient access rights\n"
    1734                                    "on this machine to install this software",
    1735                                    NULL,
    1736                                    MB_OK | MB_ICONSTOP);
    1737                         return FALSE;
    1738                 } else {
    1739                         MessageBox(GetFocus(), KeyName, "Could not open key", MB_OK);
    1740                 }
    1741         }
    1742 
    1743         sprintf(buffer, "%s\\%s-wininst.log", dir, meta_name);
    1744         logfile = fopen(buffer, "a");
    1745         time(&ltime);
    1746         now = localtime(&ltime);
    1747         strftime(buffer, sizeof(buffer),
    1748                 "*** Installation started %Y/%m/%d %H:%M ***\n",
    1749                 localtime(&ltime));
    1750         fprintf(logfile, buffer);
    1751         fprintf(logfile, "Source: %s\n", modulename);
    1752 
    1753         /* Root key must be first entry processed by uninstaller. */
    1754         fprintf(logfile, "999 Root Key: %s\n", root_name);
    1755 
    1756         sprintf(subkey_name, "%s-py%d.%d", meta_name, py_major, py_minor);
    1757 
    1758         result = RegCreateKeyEx(hKey, subkey_name,
    1759                                 0, NULL, 0,
    1760                                 KEY_WRITE,
    1761                                 NULL,
    1762                                 &hSubkey,
    1763                                 &disposition);
    1764 
    1765         if (result != ERROR_SUCCESS)
    1766                 MessageBox(GetFocus(), subkey_name, "Could not create key", MB_OK);
    1767 
    1768         RegCloseKey(hKey);
    1769 
    1770         if (disposition == REG_CREATED_NEW_KEY)
    1771                 fprintf(logfile, "020 Reg DB Key: [%s]%s\n", KeyName, subkey_name);
    1772 
    1773         sprintf(buffer, "Python %d.%d %s", py_major, py_minor, title);
    1774 
    1775         result = RegSetValueEx(hSubkey, "DisplayName",
    1776                                0,
    1777                                REG_SZ,
    1778                                buffer,
    1779                                strlen(buffer)+1);
    1780 
    1781         if (result != ERROR_SUCCESS)
    1782                 MessageBox(GetFocus(), buffer, "Could not set key value", MB_OK);
    1783 
    1784         fprintf(logfile, "040 Reg DB Value: [%s\\%s]%s=%s\n",
    1785                 KeyName, subkey_name, "DisplayName", buffer);
    1786 
    1787         {
    1788                 FILE *fp;
    1789                 sprintf(buffer, "%s\\Remove%s.exe", dir, meta_name);
    1790                 fp = fopen(buffer, "wb");
    1791                 fwrite(arc_data, exe_size, 1, fp);
    1792                 fclose(fp);
    1793 
    1794                 sprintf(buffer, "\"%s\\Remove%s.exe\" -u \"%s\\%s-wininst.log\"",
    1795                         dir, meta_name, dir, meta_name);
    1796 
    1797                 result = RegSetValueEx(hSubkey, "UninstallString",
    1798                                        0,
    1799                                        REG_SZ,
    1800                                        buffer,
    1801                                        strlen(buffer)+1);
    1802        
    1803                 if (result != ERROR_SUCCESS)
    1804                         MessageBox(GetFocus(), buffer, "Could not set key value", MB_OK);
    1805 
    1806                 fprintf(logfile, "040 Reg DB Value: [%s\\%s]%s=%s\n",
    1807                         KeyName, subkey_name, "UninstallString", buffer);
    1808         }
    1809         return TRUE;
     1702    char buffer[_MAX_PATH+1];
     1703    time_t ltime;
     1704    struct tm *now;
     1705    long result;
     1706    HKEY hKey, hSubkey;
     1707    char subkey_name[256];
     1708    static char KeyName[] =
     1709        "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
     1710    const char *root_name = (hkey_root==HKEY_LOCAL_MACHINE ?
     1711                            "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER");
     1712    DWORD disposition;
     1713
     1714    /* Use Create, as the Uninstall subkey may not exist under HKCU.
     1715       Use CreateKeyEx, so we can specify a SAM specifying write access
     1716    */
     1717        result = RegCreateKeyEx(hkey_root,
     1718                      KeyName,
     1719                      0, /* reserved */
     1720                  NULL, /* class */
     1721                  0, /* options */
     1722                  KEY_CREATE_SUB_KEY, /* sam */
     1723                  NULL, /* security */
     1724                  &hKey, /* result key */
     1725                  NULL); /* disposition */
     1726    if (result != ERROR_SUCCESS) {
     1727        if (result == ERROR_ACCESS_DENIED) {
     1728            /* This should no longer be able to happen - we have already
     1729               checked if they have permissions in HKLM, and all users
     1730               should have write access to HKCU.
     1731            */
     1732            MessageBox(GetFocus(),
     1733                       "You do not seem to have sufficient access rights\n"
     1734                       "on this machine to install this software",
     1735                       NULL,
     1736                       MB_OK | MB_ICONSTOP);
     1737            return FALSE;
     1738        } else {
     1739            MessageBox(GetFocus(), KeyName, "Could not open key", MB_OK);
     1740        }
     1741    }
     1742
     1743    sprintf(buffer, "%s\\%s-wininst.log", dir, meta_name);
     1744    logfile = fopen(buffer, "a");
     1745    time(&ltime);
     1746    now = localtime(&ltime);
     1747    strftime(buffer, sizeof(buffer),
     1748            "*** Installation started %Y/%m/%d %H:%M ***\n",
     1749            localtime(&ltime));
     1750    fprintf(logfile, buffer);
     1751    fprintf(logfile, "Source: %s\n", modulename);
     1752
     1753    /* Root key must be first entry processed by uninstaller. */
     1754    fprintf(logfile, "999 Root Key: %s\n", root_name);
     1755
     1756    sprintf(subkey_name, "%s-py%d.%d", meta_name, py_major, py_minor);
     1757
     1758    result = RegCreateKeyEx(hKey, subkey_name,
     1759                            0, NULL, 0,
     1760                            KEY_WRITE,
     1761                            NULL,
     1762                            &hSubkey,
     1763                            &disposition);
     1764
     1765    if (result != ERROR_SUCCESS)
     1766        MessageBox(GetFocus(), subkey_name, "Could not create key", MB_OK);
     1767
     1768    RegCloseKey(hKey);
     1769
     1770    if (disposition == REG_CREATED_NEW_KEY)
     1771        fprintf(logfile, "020 Reg DB Key: [%s]%s\n", KeyName, subkey_name);
     1772
     1773    sprintf(buffer, "Python %d.%d %s", py_major, py_minor, title);
     1774
     1775    result = RegSetValueEx(hSubkey, "DisplayName",
     1776                           0,
     1777                           REG_SZ,
     1778                           buffer,
     1779                           strlen(buffer)+1);
     1780
     1781    if (result != ERROR_SUCCESS)
     1782        MessageBox(GetFocus(), buffer, "Could not set key value", MB_OK);
     1783
     1784    fprintf(logfile, "040 Reg DB Value: [%s\\%s]%s=%s\n",
     1785        KeyName, subkey_name, "DisplayName", buffer);
     1786
     1787    {
     1788        FILE *fp;
     1789        sprintf(buffer, "%s\\Remove%s.exe", dir, meta_name);
     1790        fp = fopen(buffer, "wb");
     1791        fwrite(arc_data, exe_size, 1, fp);
     1792        fclose(fp);
     1793
     1794        sprintf(buffer, "\"%s\\Remove%s.exe\" -u \"%s\\%s-wininst.log\"",
     1795            dir, meta_name, dir, meta_name);
     1796
     1797        result = RegSetValueEx(hSubkey, "UninstallString",
     1798                               0,
     1799                               REG_SZ,
     1800                               buffer,
     1801                               strlen(buffer)+1);
     1802
     1803        if (result != ERROR_SUCCESS)
     1804            MessageBox(GetFocus(), buffer, "Could not set key value", MB_OK);
     1805
     1806        fprintf(logfile, "040 Reg DB Value: [%s\\%s]%s=%s\n",
     1807            KeyName, subkey_name, "UninstallString", buffer);
     1808    }
     1809    return TRUE;
    18101810}
    18111811
    18121812static void CloseLogfile(void)
    18131813{
    1814         char buffer[_MAX_PATH+1];
    1815         time_t ltime;
    1816         struct tm *now;
    1817 
    1818         time(&ltime);
    1819         now = localtime(&ltime);
    1820         strftime(buffer, sizeof(buffer),
    1821                 "*** Installation finished %Y/%m/%d %H:%M ***\n",
    1822                 localtime(&ltime));
    1823         fprintf(logfile, buffer);
    1824         if (logfile)
    1825                 fclose(logfile);
     1814    char buffer[_MAX_PATH+1];
     1815    time_t ltime;
     1816    struct tm *now;
     1817
     1818    time(&ltime);
     1819    now = localtime(&ltime);
     1820    strftime(buffer, sizeof(buffer),
     1821            "*** Installation finished %Y/%m/%d %H:%M ***\n",
     1822            localtime(&ltime));
     1823    fprintf(logfile, buffer);
     1824    if (logfile)
     1825        fclose(logfile);
    18261826}
    18271827
     
    18291829InstallFilesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    18301830{
    1831         LPNMHDR lpnm;
    1832         char Buffer[4096];
    1833         SCHEME *scheme;
    1834 
    1835         switch (msg) {
    1836         case WM_INITDIALOG:
    1837                 if (hBitmap)
    1838                         SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE,
    1839                                            IMAGE_BITMAP, (LPARAM)hBitmap);
    1840                 wsprintf(Buffer,
    1841                           "Click Next to begin the installation of %s. "
    1842                           "If you want to review or change any of your "
    1843                           " installation settings, click Back. "
    1844                           "Click Cancel to exit the wizard.",
    1845                           meta_name);
    1846                 SetDlgItemText(hwnd, IDC_TITLE, Buffer);
    1847                 SetDlgItemText(hwnd, IDC_INFO, "Ready to install");
    1848                 break;
    1849 
    1850         case WM_NUMFILES:
    1851                 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, lParam);
    1852                 PumpMessages();
    1853                 return TRUE;
    1854 
    1855         case WM_NEXTFILE:
    1856                 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, wParam,
    1857                                     0);
    1858                 SetDlgItemText(hwnd, IDC_INFO, (LPSTR)lParam);
    1859                 PumpMessages();
    1860                 return TRUE;
    1861 
    1862         case WM_NOTIFY:
    1863                 lpnm = (LPNMHDR) lParam;
    1864 
    1865                 switch (lpnm->code) {
    1866                 case PSN_SETACTIVE:
    1867                         PropSheet_SetWizButtons(GetParent(hwnd),
    1868                                                 PSWIZB_BACK | PSWIZB_NEXT);
    1869                         break;
    1870 
    1871                 case PSN_WIZFINISH:
    1872                         break;
    1873 
    1874                 case PSN_WIZNEXT:
    1875                         /* Handle a Next button click here */
    1876                         hDialog = hwnd;
    1877                         success = TRUE;
    1878 
    1879                         /* Disable the buttons while we work.  Sending CANCELTOCLOSE has
    1880                           the effect of disabling the cancel button, which is a) as we
    1881                           do everything synchronously we can't cancel, and b) the next
    1882                           step is 'finished', when it is too late to cancel anyway.
    1883                           The next step being 'Finished' means we also don't need to
    1884                           restore the button state back */
    1885                         PropSheet_SetWizButtons(GetParent(hwnd), 0);
    1886                         SendMessage(GetParent(hwnd), PSM_CANCELTOCLOSE, 0, 0);
    1887                         /* Make sure the installation directory name ends in a */
    1888                         /* backslash */
    1889                         if (python_dir[strlen(python_dir)-1] != '\\')
    1890                                 strcat(python_dir, "\\");
    1891                         /* Strip the trailing backslash again */
    1892                         python_dir[strlen(python_dir)-1] = '\0';
    1893            
    1894                         CheckRootKey(hwnd);
    1895            
    1896                         if (!OpenLogfile(python_dir))
    1897                                 break;
     1831    LPNMHDR lpnm;
     1832    char Buffer[4096];
     1833    SCHEME *scheme;
     1834
     1835    switch (msg) {
     1836    case WM_INITDIALOG:
     1837        if (hBitmap)
     1838            SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE,
     1839                               IMAGE_BITMAP, (LPARAM)hBitmap);
     1840        wsprintf(Buffer,
     1841                  "Click Next to begin the installation of %s. "
     1842                  "If you want to review or change any of your "
     1843                  " installation settings, click Back. "
     1844                  "Click Cancel to exit the wizard.",
     1845                  meta_name);
     1846        SetDlgItemText(hwnd, IDC_TITLE, Buffer);
     1847        SetDlgItemText(hwnd, IDC_INFO, "Ready to install");
     1848        break;
     1849
     1850    case WM_NUMFILES:
     1851        SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, lParam);
     1852        PumpMessages();
     1853        return TRUE;
     1854
     1855    case WM_NEXTFILE:
     1856        SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, wParam,
     1857                            0);
     1858        SetDlgItemText(hwnd, IDC_INFO, (LPSTR)lParam);
     1859        PumpMessages();
     1860        return TRUE;
     1861
     1862    case WM_NOTIFY:
     1863        lpnm = (LPNMHDR) lParam;
     1864
     1865        switch (lpnm->code) {
     1866        case PSN_SETACTIVE:
     1867            PropSheet_SetWizButtons(GetParent(hwnd),
     1868                                    PSWIZB_BACK | PSWIZB_NEXT);
     1869            break;
     1870
     1871        case PSN_WIZFINISH:
     1872            break;
     1873
     1874        case PSN_WIZNEXT:
     1875            /* Handle a Next button click here */
     1876            hDialog = hwnd;
     1877            success = TRUE;
     1878
     1879            /* Disable the buttons while we work.  Sending CANCELTOCLOSE has
     1880              the effect of disabling the cancel button, which is a) as we
     1881              do everything synchronously we can't cancel, and b) the next
     1882              step is 'finished', when it is too late to cancel anyway.
     1883              The next step being 'Finished' means we also don't need to
     1884              restore the button state back */
     1885            PropSheet_SetWizButtons(GetParent(hwnd), 0);
     1886            SendMessage(GetParent(hwnd), PSM_CANCELTOCLOSE, 0, 0);
     1887            /* Make sure the installation directory name ends in a */
     1888            /* backslash */
     1889            if (python_dir[strlen(python_dir)-1] != '\\')
     1890                strcat(python_dir, "\\");
     1891            /* Strip the trailing backslash again */
     1892            python_dir[strlen(python_dir)-1] = '\0';
     1893
     1894            CheckRootKey(hwnd);
     1895
     1896            if (!OpenLogfile(python_dir))
     1897                break;
    18981898
    18991899/*
     
    19161916 }
    19171917*/
    1918                         scheme = GetScheme(py_major, py_minor);
    1919                         /* Run the pre-install script. */
    1920                         if (pre_install_script && *pre_install_script) {
    1921                                 SetDlgItemText (hwnd, IDC_TITLE,
    1922                                                 "Running pre-installation script");
    1923                                 run_simple_script(pre_install_script);
    1924                         }
    1925                         if (!success) {
    1926                                 break;
    1927                         }
    1928                         /* Extract all files from the archive */
    1929                         SetDlgItemText(hwnd, IDC_TITLE, "Installing files...");
    1930                         if (!unzip_archive (scheme,
    1931                                             python_dir, arc_data,
    1932                                             arc_size, notify))
    1933                                 set_failure_reason("Failed to unzip installation files");
    1934                         /* Compile the py-files */
    1935                         if (success && pyc_compile) {
    1936                                 int errors;
    1937                                 HINSTANCE hPython;
    1938                                 SetDlgItemText(hwnd, IDC_TITLE,
    1939                                                 "Compiling files to .pyc...");
    1940 
    1941                                 SetDlgItemText(hDialog, IDC_INFO, "Loading python...");
    1942                                 hPython = LoadPythonDll(pythondll);
    1943                                 if (hPython) {
    1944                                         errors = compile_filelist(hPython, FALSE);
    1945                                         FreeLibrary(hPython);
    1946                                 }
    1947                                 /* Compilation errors are intentionally ignored:
    1948                                 * Python2.0 contains a bug which will result
    1949                                 * in sys.path containing garbage under certain
    1950                                 * circumstances, and an error message will only
    1951                                 * confuse the user.
    1952                                 */
    1953                         }
    1954                         if (success && pyo_compile) {
    1955                                 int errors;
    1956                                 HINSTANCE hPython;
    1957                                 SetDlgItemText(hwnd, IDC_TITLE,
    1958                                                 "Compiling files to .pyo...");
    1959 
    1960                                 SetDlgItemText(hDialog, IDC_INFO, "Loading python...");
    1961                                 hPython = LoadPythonDll(pythondll);
    1962                                 if (hPython) {
    1963                                         errors = compile_filelist(hPython, TRUE);
    1964                                         FreeLibrary(hPython);
    1965                                 }
    1966                                 /* Errors ignored: see above */
    1967                         }
    1968 
    1969 
    1970                         break;
    1971 
    1972                 case PSN_RESET:
    1973                         break;
    1974                
    1975                 default:
    1976                         break;
    1977                 }
    1978         }
    1979         return 0;
     1918            scheme = GetScheme(py_major, py_minor);
     1919            /* Run the pre-install script. */
     1920            if (pre_install_script && *pre_install_script) {
     1921                SetDlgItemText (hwnd, IDC_TITLE,
     1922                                "Running pre-installation script");
     1923                run_simple_script(pre_install_script);
     1924            }
     1925            if (!success) {
     1926                break;
     1927            }
     1928            /* Extract all files from the archive */
     1929            SetDlgItemText(hwnd, IDC_TITLE, "Installing files...");
     1930            if (!unzip_archive (scheme,
     1931                                python_dir, arc_data,
     1932                                arc_size, notify))
     1933                set_failure_reason("Failed to unzip installation files");
     1934            /* Compile the py-files */
     1935            if (success && pyc_compile) {
     1936                int errors;
     1937                HINSTANCE hPython;
     1938                SetDlgItemText(hwnd, IDC_TITLE,
     1939                                "Compiling files to .pyc...");
     1940
     1941                SetDlgItemText(hDialog, IDC_INFO, "Loading python...");
     1942                hPython = LoadPythonDll(pythondll);
     1943                if (hPython) {
     1944                    errors = compile_filelist(hPython, FALSE);
     1945                    FreeLibrary(hPython);
     1946                }
     1947                /* Compilation errors are intentionally ignored:
     1948                * Python2.0 contains a bug which will result
     1949                * in sys.path containing garbage under certain
     1950                * circumstances, and an error message will only
     1951                * confuse the user.
     1952                */
     1953            }
     1954            if (success && pyo_compile) {
     1955                int errors;
     1956                HINSTANCE hPython;
     1957                SetDlgItemText(hwnd, IDC_TITLE,
     1958                                "Compiling files to .pyo...");
     1959
     1960                SetDlgItemText(hDialog, IDC_INFO, "Loading python...");
     1961                hPython = LoadPythonDll(pythondll);
     1962                if (hPython) {
     1963                    errors = compile_filelist(hPython, TRUE);
     1964                    FreeLibrary(hPython);
     1965                }
     1966                /* Errors ignored: see above */
     1967            }
     1968
     1969
     1970            break;
     1971
     1972        case PSN_RESET:
     1973            break;
     1974
     1975        default:
     1976            break;
     1977        }
     1978    }
     1979    return 0;
    19801980}
    19811981
     
    19841984FinishedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    19851985{
    1986         LPNMHDR lpnm;
    1987 
    1988         switch (msg) {
    1989         case WM_INITDIALOG:
    1990                 if (hBitmap)
    1991                         SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE,
    1992                                            IMAGE_BITMAP, (LPARAM)hBitmap);
    1993                 if (!success)
    1994                         SetDlgItemText(hwnd, IDC_INFO, get_failure_reason());
    1995 
    1996                 /* async delay: will show the dialog box completely before
    1997                    the install_script is started */
    1998                 PostMessage(hwnd, WM_USER, 0, 0L);
    1999                 return TRUE;
    2000 
    2001         case WM_USER:
    2002 
    2003                 if (success && install_script && install_script[0]) {
    2004                         char fname[MAX_PATH];
    2005                         char *buffer;
    2006                         HCURSOR hCursor;
    2007                         int result;
    2008 
    2009                         char *argv[3] = {NULL, "-install", NULL};
    2010 
    2011                         SetDlgItemText(hwnd, IDC_TITLE,
    2012                                         "Please wait while running postinstall script...");
    2013                         strcpy(fname, python_dir);
    2014                         strcat(fname, "\\Scripts\\");
    2015                         strcat(fname, install_script);
    2016 
    2017                         if (logfile)
    2018                                 fprintf(logfile, "300 Run Script: [%s]%s\n", pythondll, fname);
    2019 
    2020                         hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
    2021 
    2022                         argv[0] = fname;
    2023 
    2024                         result = run_installscript(fname, 2, argv, &buffer);
    2025                         if (0 != result) {
    2026                                 fprintf(stderr, "*** run_installscript: internal error 0x%X ***\n", result);
    2027                         }
    2028                         if (buffer)
    2029                                 SetDlgItemText(hwnd, IDC_INFO, buffer);
    2030                         SetDlgItemText(hwnd, IDC_TITLE,
    2031                                         "Postinstall script finished.\n"
    2032                                         "Click the Finish button to exit the Setup wizard.");
    2033 
    2034                         free(buffer);
    2035                         SetCursor(hCursor);
    2036                         CloseLogfile();
    2037                 }
    2038 
    2039                 return TRUE;
    2040 
    2041         case WM_NOTIFY:
    2042                 lpnm = (LPNMHDR) lParam;
    2043 
    2044                 switch (lpnm->code) {
    2045                 case PSN_SETACTIVE: /* Enable the Finish button */
    2046                         PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_FINISH);
    2047                         break;
    2048 
    2049                 case PSN_WIZNEXT:
    2050                         break;
    2051 
    2052                 case PSN_WIZFINISH:
    2053                         break;
    2054 
    2055                 case PSN_RESET:
    2056                         break;
    2057                
    2058                 default:
    2059                         break;
    2060                 }
    2061         }
    2062         return 0;
     1986    LPNMHDR lpnm;
     1987
     1988    switch (msg) {
     1989    case WM_INITDIALOG:
     1990        if (hBitmap)
     1991            SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE,
     1992                               IMAGE_BITMAP, (LPARAM)hBitmap);
     1993        if (!success)
     1994            SetDlgItemText(hwnd, IDC_INFO, get_failure_reason());
     1995
     1996        /* async delay: will show the dialog box completely before
     1997           the install_script is started */
     1998        PostMessage(hwnd, WM_USER, 0, 0L);
     1999        return TRUE;
     2000
     2001    case WM_USER:
     2002
     2003        if (success && install_script && install_script[0]) {
     2004            char fname[MAX_PATH];
     2005            char *buffer;
     2006            HCURSOR hCursor;
     2007            int result;
     2008
     2009            char *argv[3] = {NULL, "-install", NULL};
     2010
     2011            SetDlgItemText(hwnd, IDC_TITLE,
     2012                            "Please wait while running postinstall script...");
     2013            strcpy(fname, python_dir);
     2014            strcat(fname, "\\Scripts\\");
     2015            strcat(fname, install_script);
     2016
     2017            if (logfile)
     2018                fprintf(logfile, "300 Run Script: [%s]%s\n", pythondll, fname);
     2019
     2020            hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
     2021
     2022            argv[0] = fname;
     2023
     2024            result = run_installscript(fname, 2, argv, &buffer);
     2025            if (0 != result) {
     2026                fprintf(stderr, "*** run_installscript: internal error 0x%X ***\n", result);
     2027            }
     2028            if (buffer)
     2029                SetDlgItemText(hwnd, IDC_INFO, buffer);
     2030            SetDlgItemText(hwnd, IDC_TITLE,
     2031                            "Postinstall script finished.\n"
     2032                            "Click the Finish button to exit the Setup wizard.");
     2033
     2034            free(buffer);
     2035            SetCursor(hCursor);
     2036            CloseLogfile();
     2037        }
     2038
     2039        return TRUE;
     2040
     2041    case WM_NOTIFY:
     2042        lpnm = (LPNMHDR) lParam;
     2043
     2044        switch (lpnm->code) {
     2045        case PSN_SETACTIVE: /* Enable the Finish button */
     2046            PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_FINISH);
     2047            break;
     2048
     2049        case PSN_WIZNEXT:
     2050            break;
     2051
     2052        case PSN_WIZFINISH:
     2053            break;
     2054
     2055        case PSN_RESET:
     2056            break;
     2057
     2058        default:
     2059            break;
     2060        }
     2061    }
     2062    return 0;
    20632063}
    20642064
    20652065void RunWizard(HWND hwnd)
    20662066{
    2067         PROPSHEETPAGE   psp =       {0};
    2068         HPROPSHEETPAGE  ahpsp[4] =  {0};
    2069         PROPSHEETHEADER psh =       {0};
    2070 
    2071         /* Display module information */
    2072         psp.dwSize =        sizeof(psp);
    2073         psp.dwFlags =       PSP_DEFAULT|PSP_HIDEHEADER;
    2074         psp.hInstance =     GetModuleHandle (NULL);
    2075         psp.lParam =        0;
    2076         psp.pfnDlgProc =    IntroDlgProc;
    2077         psp.pszTemplate =   MAKEINTRESOURCE(IDD_INTRO);
    2078 
    2079         ahpsp[0] =          CreatePropertySheetPage(&psp);
    2080 
    2081         /* Select python version to use */
    2082         psp.dwFlags =       PSP_DEFAULT|PSP_HIDEHEADER;
    2083         psp.pszTemplate =       MAKEINTRESOURCE(IDD_SELECTPYTHON);
    2084         psp.pfnDlgProc =        SelectPythonDlgProc;
    2085 
    2086         ahpsp[1] =              CreatePropertySheetPage(&psp);
    2087 
    2088         /* Install the files */
    2089         psp.dwFlags =       PSP_DEFAULT|PSP_HIDEHEADER;
    2090         psp.pszTemplate =       MAKEINTRESOURCE(IDD_INSTALLFILES);
    2091         psp.pfnDlgProc =        InstallFilesDlgProc;
    2092 
    2093         ahpsp[2] =              CreatePropertySheetPage(&psp);
    2094 
    2095         /* Show success or failure */
    2096         psp.dwFlags =           PSP_DEFAULT|PSP_HIDEHEADER;
    2097         psp.pszTemplate =       MAKEINTRESOURCE(IDD_FINISHED);
    2098         psp.pfnDlgProc =        FinishedDlgProc;
    2099 
    2100         ahpsp[3] =              CreatePropertySheetPage(&psp);
    2101 
    2102         /* Create the property sheet */
    2103         psh.dwSize =            sizeof(psh);
    2104         psh.hInstance =         GetModuleHandle(NULL);
    2105         psh.hwndParent =        hwnd;
    2106         psh.phpage =            ahpsp;
    2107         psh.dwFlags =           PSH_WIZARD/*97*//*|PSH_WATERMARK|PSH_HEADER*/;
    2108                 psh.pszbmWatermark =    NULL;
    2109                 psh.pszbmHeader =       NULL;
    2110                 psh.nStartPage =        0;
    2111                 psh.nPages =            4;
    2112 
    2113                 PropertySheet(&psh);
     2067    PROPSHEETPAGE   psp =       {0};
     2068    HPROPSHEETPAGE  ahpsp[4] =  {0};
     2069    PROPSHEETHEADER psh =       {0};
     2070
     2071    /* Display module information */
     2072    psp.dwSize =        sizeof(psp);
     2073    psp.dwFlags =       PSP_DEFAULT|PSP_HIDEHEADER;
     2074    psp.hInstance =     GetModuleHandle (NULL);
     2075    psp.lParam =        0;
     2076    psp.pfnDlgProc =    IntroDlgProc;
     2077    psp.pszTemplate =   MAKEINTRESOURCE(IDD_INTRO);
     2078
     2079    ahpsp[0] =          CreatePropertySheetPage(&psp);
     2080
     2081    /* Select python version to use */
     2082    psp.dwFlags =       PSP_DEFAULT|PSP_HIDEHEADER;
     2083    psp.pszTemplate =       MAKEINTRESOURCE(IDD_SELECTPYTHON);
     2084    psp.pfnDlgProc =        SelectPythonDlgProc;
     2085
     2086    ahpsp[1] =              CreatePropertySheetPage(&psp);
     2087
     2088    /* Install the files */
     2089    psp.dwFlags =           PSP_DEFAULT|PSP_HIDEHEADER;
     2090    psp.pszTemplate =       MAKEINTRESOURCE(IDD_INSTALLFILES);
     2091    psp.pfnDlgProc =        InstallFilesDlgProc;
     2092
     2093    ahpsp[2] =              CreatePropertySheetPage(&psp);
     2094
     2095    /* Show success or failure */
     2096    psp.dwFlags =           PSP_DEFAULT|PSP_HIDEHEADER;
     2097    psp.pszTemplate =       MAKEINTRESOURCE(IDD_FINISHED);
     2098    psp.pfnDlgProc =        FinishedDlgProc;
     2099
     2100    ahpsp[3] =              CreatePropertySheetPage(&psp);
     2101
     2102    /* Create the property sheet */
     2103    psh.dwSize =            sizeof(psh);
     2104    psh.hInstance =         GetModuleHandle(NULL);
     2105    psh.hwndParent =        hwnd;
     2106    psh.phpage =            ahpsp;
     2107    psh.dwFlags =           PSH_WIZARD/*97*//*|PSH_WATERMARK|PSH_HEADER*/;
     2108        psh.pszbmWatermark =    NULL;
     2109        psh.pszbmHeader =       NULL;
     2110        psh.nStartPage =        0;
     2111        psh.nPages =            4;
     2112
     2113        PropertySheet(&psh);
    21142114}
    21152115
     
    21192119BOOL MyIsUserAnAdmin()
    21202120{
    2121         typedef BOOL (WINAPI *PFNIsUserAnAdmin)();
    2122         static PFNIsUserAnAdmin pfnIsUserAnAdmin = NULL;
    2123         HMODULE shell32;
    2124         // This function isn't guaranteed to be available (and it can't hurt
    2125         // to leave the library loaded)
    2126         if (0 == (shell32=LoadLibrary("shell32.dll")))
    2127                 return FALSE;
    2128         if (0 == (pfnIsUserAnAdmin=(PFNIsUserAnAdmin)GetProcAddress(shell32, "IsUserAnAdmin")))
    2129                 return FALSE;
    2130         return (*pfnIsUserAnAdmin)();
     2121    typedef BOOL (WINAPI *PFNIsUserAnAdmin)();
     2122    static PFNIsUserAnAdmin pfnIsUserAnAdmin = NULL;
     2123    HMODULE shell32;
     2124    // This function isn't guaranteed to be available (and it can't hurt
     2125    // to leave the library loaded)
     2126    if (0 == (shell32=LoadLibrary("shell32.dll")))
     2127        return FALSE;
     2128    if (0 == (pfnIsUserAnAdmin=(PFNIsUserAnAdmin)GetProcAddress(shell32, "IsUserAnAdmin")))
     2129        return FALSE;
     2130    return (*pfnIsUserAnAdmin)();
    21312131}
    21322132
     
    21402140BOOL NeedAutoUAC()
    21412141{
    2142         HKEY hk;
    2143         char key_name[80];
    2144         // no Python version info == we can't know yet.
    2145         if (target_version[0] == '\0')
    2146                 return FALSE;
    2147         // see how python is current installed
    2148         wsprintf(key_name,
    2149                         "Software\\Python\\PythonCore\\%s\\InstallPath",
    2150                         target_version);
    2151         if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE,
    2152                                           key_name, 0, KEY_READ, &hk))
    2153                 return FALSE;
    2154         RegCloseKey(hk);
    2155         // Python is installed in HKLM - we must elevate.
    2156         return TRUE;
     2142    HKEY hk;
     2143    char key_name[80];
     2144    // no Python version info == we can't know yet.
     2145    if (target_version[0] == '\0')
     2146        return FALSE;
     2147    // see how python is current installed
     2148    wsprintf(key_name,
     2149                    "Software\\Python\\PythonCore\\%s\\InstallPath",
     2150                    target_version);
     2151    if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE,
     2152                                      key_name, 0, KEY_READ, &hk))
     2153        return FALSE;
     2154    RegCloseKey(hk);
     2155    // Python is installed in HKLM - we must elevate.
     2156    return TRUE;
    21572157}
    21582158
     
    21602160BOOL PlatformSupportsUAC()
    21612161{
    2162         // Note that win2k does seem to support ShellExecute with 'runas',
    2163         // but does *not* support IsUserAnAdmin - so we just pretend things
    2164         // only work on XP and later.
    2165         BOOL bIsWindowsXPorLater;
    2166         OSVERSIONINFO winverinfo;
    2167         winverinfo.dwOSVersionInfoSize = sizeof(winverinfo);
    2168         if (!GetVersionEx(&winverinfo))
    2169                 return FALSE; // something bad has gone wrong
    2170         bIsWindowsXPorLater =
     2162    // Note that win2k does seem to support ShellExecute with 'runas',
     2163    // but does *not* support IsUserAnAdmin - so we just pretend things
     2164    // only work on XP and later.
     2165    BOOL bIsWindowsXPorLater;
     2166    OSVERSIONINFO winverinfo;
     2167    winverinfo.dwOSVersionInfoSize = sizeof(winverinfo);
     2168    if (!GetVersionEx(&winverinfo))
     2169        return FALSE; // something bad has gone wrong
     2170    bIsWindowsXPorLater =
    21712171       ( (winverinfo.dwMajorVersion > 5) ||
    21722172       ( (winverinfo.dwMajorVersion == 5) && (winverinfo.dwMinorVersion >= 1) ));
    2173         return bIsWindowsXPorLater;
     2173    return bIsWindowsXPorLater;
    21742174}
    21752175
     
    21792179void SpawnUAC()
    21802180{
    2181         // interesting failure scenario that has been seen: initial executable
    2182         // runs from a network drive - but once elevated, that network share
    2183         // isn't seen, and ShellExecute fails with SE_ERR_ACCESSDENIED.
    2184         int ret = (int)ShellExecute(0, "runas", modulename, "", NULL,
    2185                                     SW_SHOWNORMAL);
    2186         if (ret <= 32) {
    2187                 char msg[128];
    2188                 wsprintf(msg, "Failed to start elevated process (ShellExecute returned %d)", ret);
    2189                 MessageBox(0, msg, "Setup", MB_OK | MB_ICONERROR);
    2190         }
     2181    // interesting failure scenario that has been seen: initial executable
     2182    // runs from a network drive - but once elevated, that network share
     2183    // isn't seen, and ShellExecute fails with SE_ERR_ACCESSDENIED.
     2184    int ret = (int)ShellExecute(0, "runas", modulename, "", NULL,
     2185                                SW_SHOWNORMAL);
     2186    if (ret <= 32) {
     2187        char msg[128];
     2188        wsprintf(msg, "Failed to start elevated process (ShellExecute returned %d)", ret);
     2189        MessageBox(0, msg, "Setup", MB_OK | MB_ICONERROR);
     2190    }
    21912191}
    21922192
    21932193int DoInstall(void)
    21942194{
    2195         char ini_buffer[4096];
    2196 
    2197         /* Read installation information */
    2198         GetPrivateProfileString("Setup", "title", "", ini_buffer,
    2199                                 sizeof(ini_buffer), ini_file);
    2200         unescape(title, ini_buffer, sizeof(title));
    2201 
    2202         GetPrivateProfileString("Setup", "info", "", ini_buffer,
    2203                                 sizeof(ini_buffer), ini_file);
    2204         unescape(info, ini_buffer, sizeof(info));
    2205 
    2206         GetPrivateProfileString("Setup", "build_info", "", build_info,
    2207                                 sizeof(build_info), ini_file);
    2208 
    2209         pyc_compile = GetPrivateProfileInt("Setup", "target_compile", 1,
    2210                                             ini_file);
    2211         pyo_compile = GetPrivateProfileInt("Setup", "target_optimize", 1,
    2212                                             ini_file);
    2213 
    2214         GetPrivateProfileString("Setup", "target_version", "",
    2215                                 target_version, sizeof(target_version),
    2216                                 ini_file);
    2217 
    2218         GetPrivateProfileString("metadata", "name", "",
    2219                                 meta_name, sizeof(meta_name),
    2220                                 ini_file);
    2221 
    2222         GetPrivateProfileString("Setup", "install_script", "",
    2223                                 install_script, sizeof(install_script),
    2224                                 ini_file);
    2225 
    2226         GetPrivateProfileString("Setup", "user_access_control", "",
    2227                                 user_access_control, sizeof(user_access_control), ini_file);
    2228 
    2229         // See if we need to do the Vista UAC magic.
    2230         if (strcmp(user_access_control, "force")==0) {
    2231                 if (PlatformSupportsUAC() && !MyIsUserAnAdmin()) {
    2232                         SpawnUAC();
    2233                         return 0;
    2234                 }
    2235                 // already admin - keep going
    2236         } else if (strcmp(user_access_control, "auto")==0) {
    2237                 // Check if it looks like we need UAC control, based
    2238                 // on how Python itself was installed.
    2239                 if (PlatformSupportsUAC() && !MyIsUserAnAdmin() && NeedAutoUAC()) {
    2240                         SpawnUAC();
    2241                         return 0;
    2242                 }
    2243         } else {
    2244                 // display a warning about unknown values - only the developer
    2245                 // of the extension will see it (until they fix it!)
    2246                 if (user_access_control[0] && strcmp(user_access_control, "none") != 0) {
    2247                         MessageBox(GetFocus(), "Bad user_access_control value", "oops", MB_OK);
    2248                 // nothing to do.
    2249                 }
    2250         }
    2251 
    2252         hwndMain = CreateBackground(title);
    2253 
    2254         RunWizard(hwndMain);
    2255 
    2256         /* Clean up */
    2257         UnmapViewOfFile(arc_data);
    2258         if (ini_file)
    2259                 DeleteFile(ini_file);
    2260 
    2261         if (hBitmap)
    2262                 DeleteObject(hBitmap);
    2263 
    2264         return 0;
     2195    char ini_buffer[4096];
     2196
     2197    /* Read installation information */
     2198    GetPrivateProfileString("Setup", "title", "", ini_buffer,
     2199                            sizeof(ini_buffer), ini_file);
     2200    unescape(title, ini_buffer, sizeof(title));
     2201
     2202    GetPrivateProfileString("Setup", "info", "", ini_buffer,
     2203                            sizeof(ini_buffer), ini_file);
     2204    unescape(info, ini_buffer, sizeof(info));
     2205
     2206    GetPrivateProfileString("Setup", "build_info", "", build_info,
     2207                            sizeof(build_info), ini_file);
     2208
     2209    pyc_compile = GetPrivateProfileInt("Setup", "target_compile", 1,
     2210                                        ini_file);
     2211    pyo_compile = GetPrivateProfileInt("Setup", "target_optimize", 1,
     2212                                        ini_file);
     2213
     2214    GetPrivateProfileString("Setup", "target_version", "",
     2215                            target_version, sizeof(target_version),
     2216                            ini_file);
     2217
     2218    GetPrivateProfileString("metadata", "name", "",
     2219                            meta_name, sizeof(meta_name),
     2220                            ini_file);
     2221
     2222    GetPrivateProfileString("Setup", "install_script", "",
     2223                            install_script, sizeof(install_script),
     2224                            ini_file);
     2225
     2226    GetPrivateProfileString("Setup", "user_access_control", "",
     2227                            user_access_control, sizeof(user_access_control), ini_file);
     2228
     2229    // See if we need to do the Vista UAC magic.
     2230    if (strcmp(user_access_control, "force")==0) {
     2231        if (PlatformSupportsUAC() && !MyIsUserAnAdmin()) {
     2232            SpawnUAC();
     2233            return 0;
     2234        }
     2235        // already admin - keep going
     2236    } else if (strcmp(user_access_control, "auto")==0) {
     2237        // Check if it looks like we need UAC control, based
     2238        // on how Python itself was installed.
     2239        if (PlatformSupportsUAC() && !MyIsUserAnAdmin() && NeedAutoUAC()) {
     2240            SpawnUAC();
     2241            return 0;
     2242        }
     2243    } else {
     2244        // display a warning about unknown values - only the developer
     2245        // of the extension will see it (until they fix it!)
     2246        if (user_access_control[0] && strcmp(user_access_control, "none") != 0) {
     2247            MessageBox(GetFocus(), "Bad user_access_control value", "oops", MB_OK);
     2248        // nothing to do.
     2249        }
     2250    }
     2251
     2252    hwndMain = CreateBackground(title);
     2253
     2254    RunWizard(hwndMain);
     2255
     2256    /* Clean up */
     2257    UnmapViewOfFile(arc_data);
     2258    if (ini_file)
     2259        DeleteFile(ini_file);
     2260
     2261    if (hBitmap)
     2262        DeleteObject(hBitmap);
     2263
     2264    return 0;
    22652265}
    22662266
     
    22692269static int compare(const void *p1, const void *p2)
    22702270{
    2271         return strcmp(*(char **)p2, *(char **)p1);
     2271    return strcmp(*(char **)p2, *(char **)p1);
    22722272}
    22732273
     
    22832283void remove_exe(void)
    22842284{
    2285         char exename[_MAX_PATH];
    2286         char batname[_MAX_PATH];
    2287         FILE *fp;
    2288         STARTUPINFO si;
    2289         PROCESS_INFORMATION pi;
    2290 
    2291         GetModuleFileName(NULL, exename, sizeof(exename));
    2292         sprintf(batname, "%s.bat", exename);
    2293         fp = fopen(batname, "w");
    2294         fprintf(fp, ":Repeat\n");
    2295         fprintf(fp, "del \"%s\"\n", exename);
    2296         fprintf(fp, "if exist \"%s\" goto Repeat\n", exename);
    2297         fprintf(fp, "del \"%s\"\n", batname);
    2298         fclose(fp);
    2299    
    2300         ZeroMemory(&si, sizeof(si));
    2301         si.cb = sizeof(si);
    2302         si.dwFlags = STARTF_USESHOWWINDOW;
    2303         si.wShowWindow = SW_HIDE;
    2304         if (CreateProcess(NULL,
    2305                           batname,
    2306                           NULL,
    2307                           NULL,
    2308                           FALSE,
    2309                           CREATE_SUSPENDED | IDLE_PRIORITY_CLASS,
    2310                           NULL,
    2311                           "\\",
    2312                           &si,
    2313                           &pi)) {
    2314                 SetThreadPriority(pi.hThread, THREAD_PRIORITY_IDLE);
    2315                 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
    2316                 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
    2317                 CloseHandle(pi.hProcess);
    2318                 ResumeThread(pi.hThread);
    2319                 CloseHandle(pi.hThread);
    2320         }
     2285    char exename[_MAX_PATH];
     2286    char batname[_MAX_PATH];
     2287    FILE *fp;
     2288    STARTUPINFO si;
     2289    PROCESS_INFORMATION pi;
     2290
     2291    GetModuleFileName(NULL, exename, sizeof(exename));
     2292    sprintf(batname, "%s.bat", exename);
     2293    fp = fopen(batname, "w");
     2294    fprintf(fp, ":Repeat\n");
     2295    fprintf(fp, "del \"%s\"\n", exename);
     2296    fprintf(fp, "if exist \"%s\" goto Repeat\n", exename);
     2297    fprintf(fp, "del \"%s\"\n", batname);
     2298    fclose(fp);
     2299
     2300    ZeroMemory(&si, sizeof(si));
     2301    si.cb = sizeof(si);
     2302    si.dwFlags = STARTF_USESHOWWINDOW;
     2303    si.wShowWindow = SW_HIDE;
     2304    if (CreateProcess(NULL,
     2305                      batname,
     2306                      NULL,
     2307                      NULL,
     2308                      FALSE,
     2309                      CREATE_SUSPENDED | IDLE_PRIORITY_CLASS,
     2310                      NULL,
     2311                      "\\",
     2312                      &si,
     2313                      &pi)) {
     2314        SetThreadPriority(pi.hThread, THREAD_PRIORITY_IDLE);
     2315        SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
     2316        SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
     2317        CloseHandle(pi.hProcess);
     2318        ResumeThread(pi.hThread);
     2319        CloseHandle(pi.hThread);
     2320    }
    23212321}
    23222322
    23232323void DeleteRegistryKey(char *string)
    23242324{
    2325         char *keyname;
    2326         char *subkeyname;
    2327         char *delim;
    2328         HKEY hKey;
    2329         long result;
    2330         char *line;
    2331 
    2332         line = strdup(string); /* so we can change it */
    2333 
    2334         keyname = strchr(line, '[');
    2335         if (!keyname)
    2336                 return;
    2337         ++keyname;
    2338 
    2339         subkeyname = strchr(keyname, ']');
    2340         if (!subkeyname)
    2341                 return;
    2342         *subkeyname++='\0';
    2343         delim = strchr(subkeyname, '\n');
    2344         if (delim)
    2345                 *delim = '\0';
    2346 
    2347         result = RegOpenKeyEx(hkey_root,
    2348                               keyname,
    2349                               0,
    2350                               KEY_WRITE,
    2351                               &hKey);
    2352    
    2353         if (result != ERROR_SUCCESS)
    2354                 MessageBox(GetFocus(), string, "Could not open key", MB_OK);
    2355         else {
    2356                 result = RegDeleteKey(hKey, subkeyname);
    2357                 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND)
    2358                         MessageBox(GetFocus(), string, "Could not delete key", MB_OK);
    2359                 RegCloseKey(hKey);
    2360         }
    2361         free(line);
     2325    char *keyname;
     2326    char *subkeyname;
     2327    char *delim;
     2328    HKEY hKey;
     2329    long result;
     2330    char *line;
     2331
     2332    line = strdup(string); /* so we can change it */
     2333
     2334    keyname = strchr(line, '[');
     2335    if (!keyname)
     2336        return;
     2337    ++keyname;
     2338
     2339    subkeyname = strchr(keyname, ']');
     2340    if (!subkeyname)
     2341        return;
     2342    *subkeyname++='\0';
     2343    delim = strchr(subkeyname, '\n');
     2344    if (delim)
     2345        *delim = '\0';
     2346
     2347    result = RegOpenKeyEx(hkey_root,
     2348                          keyname,
     2349                          0,
     2350                          KEY_WRITE,
     2351                          &hKey);
     2352
     2353    if (result != ERROR_SUCCESS)
     2354        MessageBox(GetFocus(), string, "Could not open key", MB_OK);
     2355    else {
     2356        result = RegDeleteKey(hKey, subkeyname);
     2357        if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND)
     2358            MessageBox(GetFocus(), string, "Could not delete key", MB_OK);
     2359        RegCloseKey(hKey);
     2360    }
     2361    free(line);
    23622362}
    23632363
    23642364void DeleteRegistryValue(char *string)
    23652365{
    2366         char *keyname;
    2367         char *valuename;
    2368         char *value;
    2369         HKEY hKey;
    2370         long result;
    2371         char *line;
    2372 
    2373         line = strdup(string); /* so we can change it */
     2366    char *keyname;
     2367    char *valuename;
     2368    char *value;
     2369    HKEY hKey;
     2370    long result;
     2371    char *line;
     2372
     2373    line = strdup(string); /* so we can change it */
    23742374
    23752375/* Format is 'Reg DB Value: [key]name=value' */
    2376         keyname = strchr(line, '[');
    2377         if (!keyname)
    2378                 return;
    2379         ++keyname;
    2380         valuename = strchr(keyname, ']');
    2381         if (!valuename)
    2382                 return;
    2383         *valuename++ = '\0';
    2384         value = strchr(valuename, '=');
    2385         if (!value)
    2386                 return;
    2387 
    2388         *value++ = '\0';
    2389 
    2390         result = RegOpenKeyEx(hkey_root,
    2391                               keyname,
    2392                               0,
    2393                               KEY_WRITE,
    2394                               &hKey);
    2395         if (result != ERROR_SUCCESS)
    2396                 MessageBox(GetFocus(), string, "Could not open key", MB_OK);
    2397         else {
    2398                 result = RegDeleteValue(hKey, valuename);
    2399                 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND)
    2400                         MessageBox(GetFocus(), string, "Could not delete value", MB_OK);
    2401                 RegCloseKey(hKey);
    2402         }
    2403         free(line);
     2376    keyname = strchr(line, '[');
     2377    if (!keyname)
     2378        return;
     2379    ++keyname;
     2380    valuename = strchr(keyname, ']');
     2381    if (!valuename)
     2382        return;
     2383    *valuename++ = '\0';
     2384    value = strchr(valuename, '=');
     2385    if (!value)
     2386        return;
     2387
     2388    *value++ = '\0';
     2389
     2390    result = RegOpenKeyEx(hkey_root,
     2391                          keyname,
     2392                          0,
     2393                          KEY_WRITE,
     2394                          &hKey);
     2395    if (result != ERROR_SUCCESS)
     2396        MessageBox(GetFocus(), string, "Could not open key", MB_OK);
     2397    else {
     2398        result = RegDeleteValue(hKey, valuename);
     2399        if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND)
     2400            MessageBox(GetFocus(), string, "Could not delete value", MB_OK);
     2401        RegCloseKey(hKey);
     2402    }
     2403    free(line);
    24042404}
    24052405
    24062406BOOL MyDeleteFile(char *line)
    24072407{
    2408         char *pathname = strchr(line, ':');
    2409         if (!pathname)
    2410                 return FALSE;
    2411         ++pathname;
    2412         while (isspace(*pathname))
    2413                 ++pathname;
    2414         return DeleteFile(pathname);
     2408    char *pathname = strchr(line, ':');
     2409    if (!pathname)
     2410        return FALSE;
     2411    ++pathname;
     2412    while (isspace(*pathname))
     2413        ++pathname;
     2414    return DeleteFile(pathname);
    24152415}
    24162416
    24172417BOOL MyRemoveDirectory(char *line)
    24182418{
    2419         char *pathname = strchr(line, ':');
    2420         if (!pathname)
    2421                 return FALSE;
    2422         ++pathname;
    2423         while (isspace(*pathname))
    2424                 ++pathname;
    2425         return RemoveDirectory(pathname);
     2419    char *pathname = strchr(line, ':');
     2420    if (!pathname)
     2421        return FALSE;
     2422    ++pathname;
     2423    while (isspace(*pathname))
     2424        ++pathname;
     2425    return RemoveDirectory(pathname);
    24262426}
    24272427
    24282428BOOL Run_RemoveScript(char *line)
    24292429{
    2430         char *dllname;
    2431         char *scriptname;
    2432         static char lastscript[MAX_PATH];
     2430    char *dllname;
     2431    char *scriptname;
     2432    static char lastscript[MAX_PATH];
    24332433
    24342434/* Format is 'Run Scripts: [pythondll]scriptname' */
    24352435/* XXX Currently, pythondll carries no path!!! */
    2436         dllname = strchr(line, '[');
    2437         if (!dllname)
    2438                 return FALSE;
    2439         ++dllname;
    2440         scriptname = strchr(dllname, ']');
    2441         if (!scriptname)
    2442                 return FALSE;
    2443         *scriptname++ = '\0';
    2444         /* this function may be called more than one time with the same
    2445            script, only run it one time */
    2446         if (strcmp(lastscript, scriptname)) {
    2447                 char *argv[3] = {NULL, "-remove", NULL};
    2448                 char *buffer = NULL;
    2449 
    2450                 argv[0] = scriptname;
    2451 
    2452                 if (0 != run_installscript(scriptname, 2, argv, &buffer))
    2453                         fprintf(stderr, "*** Could not run installation script ***");
    2454 
    2455                 if (buffer && buffer[0])
    2456                         MessageBox(GetFocus(), buffer, "uninstall-script", MB_OK);
    2457                 free(buffer);
    2458 
    2459                 strcpy(lastscript, scriptname);
    2460         }
    2461         return TRUE;
     2436    dllname = strchr(line, '[');
     2437    if (!dllname)
     2438        return FALSE;
     2439    ++dllname;
     2440    scriptname = strchr(dllname, ']');
     2441    if (!scriptname)
     2442        return FALSE;
     2443    *scriptname++ = '\0';
     2444    /* this function may be called more than one time with the same
     2445       script, only run it one time */
     2446    if (strcmp(lastscript, scriptname)) {
     2447        char *argv[3] = {NULL, "-remove", NULL};
     2448        char *buffer = NULL;
     2449
     2450        argv[0] = scriptname;
     2451
     2452        if (0 != run_installscript(scriptname, 2, argv, &buffer))
     2453            fprintf(stderr, "*** Could not run installation script ***");
     2454
     2455        if (buffer && buffer[0])
     2456            MessageBox(GetFocus(), buffer, "uninstall-script", MB_OK);
     2457        free(buffer);
     2458
     2459        strcpy(lastscript, scriptname);
     2460    }
     2461    return TRUE;
    24622462}
    24632463
    24642464int DoUninstall(int argc, char **argv)
    24652465{
    2466         FILE *logfile;
    2467         char buffer[4096];
    2468         int nLines = 0;
    2469         int i;
    2470         char *cp;
    2471         int nFiles = 0;
    2472         int nDirs = 0;
    2473         int nErrors = 0;
    2474         char **lines;
    2475         int lines_buffer_size = 10;
    2476    
    2477         if (argc != 3) {
    2478                 MessageBox(NULL,
    2479                            "Wrong number of args",
    2480                            NULL,
    2481                            MB_OK);
    2482                 return 1; /* Error */
    2483         }
    2484         if (strcmp(argv[1], "-u")) {
    2485                 MessageBox(NULL,
    2486                            "2. arg is not -u",
    2487                            NULL,
    2488                            MB_OK);
    2489                 return 1; /* Error */
    2490         }
    2491 
    2492         logfile = fopen(argv[2], "r");
    2493         if (!logfile) {
    2494                 MessageBox(NULL,
    2495                            "could not open logfile",
    2496                            NULL,
    2497                            MB_OK);
    2498                 return 1; /* Error */
    2499         }
    2500    
    2501         lines = (char **)malloc(sizeof(char *) * lines_buffer_size);
    2502         if (!lines)
    2503                 return SystemError(0, "Out of memory");
    2504 
    2505         /* Read the whole logfile, realloacting the buffer */
    2506         while (fgets(buffer, sizeof(buffer), logfile)) {
    2507                 int len = strlen(buffer);
    2508                 /* remove trailing white space */
    2509                 while (isspace(buffer[len-1]))
    2510                         len -= 1;
    2511                 buffer[len] = '\0';
    2512                 lines[nLines++] = strdup(buffer);
    2513                 if (nLines >= lines_buffer_size) {
    2514                         lines_buffer_size += 10;
    2515                         lines = (char **)realloc(lines,
    2516                                                 sizeof(char *) * lines_buffer_size);
    2517                         if (!lines)
    2518                                 return SystemError(0, "Out of memory");
    2519                 }
    2520         }
    2521         fclose(logfile);
    2522 
    2523         /* Sort all the lines, so that highest 3-digit codes are first */
    2524         qsort(&lines[0], nLines, sizeof(char *),
    2525               compare);
    2526 
    2527         if (IDYES != MessageBox(NULL,
    2528                                 "Are you sure you want to remove\n"
    2529                                 "this package from your computer?",
    2530                                 "Please confirm",
    2531                                 MB_YESNO | MB_ICONQUESTION))
    2532                 return 0;
    2533 
    2534         hkey_root = HKEY_LOCAL_MACHINE;
    2535         cp = "";
    2536         for (i = 0; i < nLines; ++i) {
    2537                 /* Ignore duplicate lines */
    2538                 if (strcmp(cp, lines[i])) {
    2539                         int ign;
    2540                         cp = lines[i];
    2541                         /* Parse the lines */
    2542                         if (2 == sscanf(cp, "%d Root Key: %s", &ign, &buffer)) {
    2543                                 if (strcmp(buffer, "HKEY_CURRENT_USER")==0)
    2544                                         hkey_root = HKEY_CURRENT_USER;
    2545                                 else {
    2546                                         // HKLM - check they have permissions.
    2547                                         if (!HasLocalMachinePrivs()) {
    2548                                                 MessageBox(GetFocus(),
    2549                                                            "You do not seem to have sufficient access rights\n"
    2550                                                            "on this machine to uninstall this software",
    2551                                                            NULL,
    2552                                                            MB_OK | MB_ICONSTOP);
    2553                                                 return 1; /* Error */
    2554                                         }
    2555                                 }
    2556                         } else if (2 == sscanf(cp, "%d Made Dir: %s", &ign, &buffer)) {
    2557                                 if (MyRemoveDirectory(cp))
    2558                                         ++nDirs;
    2559                                 else {
    2560                                         int code = GetLastError();
    2561                                         if (code != 2 && code != 3) { /* file or path not found */
    2562                                                 ++nErrors;
    2563                                         }
    2564                                 }
    2565                         } else if (2 == sscanf(cp, "%d File Copy: %s", &ign, &buffer)) {
    2566                                 if (MyDeleteFile(cp))
    2567                                         ++nFiles;
    2568                                 else {
    2569                                         int code = GetLastError();
    2570                                         if (code != 2 && code != 3) { /* file or path not found */
    2571                                                 ++nErrors;
    2572                                         }
    2573                                 }
    2574                         } else if (2 == sscanf(cp, "%d File Overwrite: %s", &ign, &buffer)) {
    2575                                 if (MyDeleteFile(cp))
    2576                                         ++nFiles;
    2577                                 else {
    2578                                         int code = GetLastError();
    2579                                         if (code != 2 && code != 3) { /* file or path not found */
    2580                                                 ++nErrors;
    2581                                         }
    2582                                 }
    2583                         } else if (2 == sscanf(cp, "%d Reg DB Key: %s", &ign, &buffer)) {
    2584                                 DeleteRegistryKey(cp);
    2585                         } else if (2 == sscanf(cp, "%d Reg DB Value: %s", &ign, &buffer)) {
    2586                                 DeleteRegistryValue(cp);
    2587                         } else if (2 == sscanf(cp, "%d Run Script: %s", &ign, &buffer)) {
    2588                                 Run_RemoveScript(cp);
    2589                         }
    2590                 }
    2591         }
    2592 
    2593         if (DeleteFile(argv[2])) {
    2594                 ++nFiles;
    2595         } else {
    2596                 ++nErrors;
    2597                 SystemError(GetLastError(), argv[2]);
    2598         }
    2599         if (nErrors)
    2600                 wsprintf(buffer,
    2601                         "%d files and %d directories removed\n"
    2602                         "%d files or directories could not be removed",
    2603                         nFiles, nDirs, nErrors);
    2604         else
    2605                 wsprintf(buffer, "%d files and %d directories removed",
    2606                         nFiles, nDirs);
    2607         MessageBox(NULL, buffer, "Uninstall Finished!",
    2608                    MB_OK | MB_ICONINFORMATION);
    2609         remove_exe();
    2610         return 0;
     2466    FILE *logfile;
     2467    char buffer[4096];
     2468    int nLines = 0;
     2469    int i;
     2470    char *cp;
     2471    int nFiles = 0;
     2472    int nDirs = 0;
     2473    int nErrors = 0;
     2474    char **lines;
     2475    int lines_buffer_size = 10;
     2476
     2477    if (argc != 3) {
     2478        MessageBox(NULL,
     2479                   "Wrong number of args",
     2480                   NULL,
     2481                   MB_OK);
     2482        return 1; /* Error */
     2483    }
     2484    if (strcmp(argv[1], "-u")) {
     2485        MessageBox(NULL,
     2486                   "2. arg is not -u",
     2487                   NULL,
     2488                   MB_OK);
     2489        return 1; /* Error */
     2490    }
     2491
     2492    logfile = fopen(argv[2], "r");
     2493    if (!logfile) {
     2494        MessageBox(NULL,
     2495                   "could not open logfile",
     2496                   NULL,
     2497                   MB_OK);
     2498        return 1; /* Error */
     2499    }
     2500
     2501    lines = (char **)malloc(sizeof(char *) * lines_buffer_size);
     2502    if (!lines)
     2503        return SystemError(0, "Out of memory");
     2504
     2505    /* Read the whole logfile, realloacting the buffer */
     2506    while (fgets(buffer, sizeof(buffer), logfile)) {
     2507        int len = strlen(buffer);
     2508        /* remove trailing white space */
     2509        while (isspace(buffer[len-1]))
     2510            len -= 1;
     2511        buffer[len] = '\0';
     2512        lines[nLines++] = strdup(buffer);
     2513        if (nLines >= lines_buffer_size) {
     2514            lines_buffer_size += 10;
     2515            lines = (char **)realloc(lines,
     2516                                    sizeof(char *) * lines_buffer_size);
     2517            if (!lines)
     2518                return SystemError(0, "Out of memory");
     2519        }
     2520    }
     2521    fclose(logfile);
     2522
     2523    /* Sort all the lines, so that highest 3-digit codes are first */
     2524    qsort(&lines[0], nLines, sizeof(char *),
     2525          compare);
     2526
     2527    if (IDYES != MessageBox(NULL,
     2528                            "Are you sure you want to remove\n"
     2529                            "this package from your computer?",
     2530                            "Please confirm",
     2531                            MB_YESNO | MB_ICONQUESTION))
     2532        return 0;
     2533
     2534    hkey_root = HKEY_LOCAL_MACHINE;
     2535    cp = "";
     2536    for (i = 0; i < nLines; ++i) {
     2537        /* Ignore duplicate lines */
     2538        if (strcmp(cp, lines[i])) {
     2539            int ign;
     2540            cp = lines[i];
     2541            /* Parse the lines */
     2542            if (2 == sscanf(cp, "%d Root Key: %s", &ign, &buffer)) {
     2543                if (strcmp(buffer, "HKEY_CURRENT_USER")==0)
     2544                    hkey_root = HKEY_CURRENT_USER;
     2545                else {
     2546                    // HKLM - check they have permissions.
     2547                    if (!HasLocalMachinePrivs()) {
     2548                        MessageBox(GetFocus(),
     2549                                   "You do not seem to have sufficient access rights\n"
     2550                                   "on this machine to uninstall this software",
     2551                                   NULL,
     2552                                   MB_OK | MB_ICONSTOP);
     2553                        return 1; /* Error */
     2554                    }
     2555                }
     2556            } else if (2 == sscanf(cp, "%d Made Dir: %s", &ign, &buffer)) {
     2557                if (MyRemoveDirectory(cp))
     2558                    ++nDirs;
     2559                else {
     2560                    int code = GetLastError();
     2561                    if (code != 2 && code != 3) { /* file or path not found */
     2562                        ++nErrors;
     2563                    }
     2564                }
     2565            } else if (2 == sscanf(cp, "%d File Copy: %s", &ign, &buffer)) {
     2566                if (MyDeleteFile(cp))
     2567                    ++nFiles;
     2568                else {
     2569                    int code = GetLastError();
     2570                    if (code != 2 && code != 3) { /* file or path not found */
     2571                        ++nErrors;
     2572                    }
     2573                }
     2574            } else if (2 == sscanf(cp, "%d File Overwrite: %s", &ign, &buffer)) {
     2575                if (MyDeleteFile(cp))
     2576                    ++nFiles;
     2577                else {
     2578                    int code = GetLastError();
     2579                    if (code != 2 && code != 3) { /* file or path not found */
     2580                        ++nErrors;
     2581                    }
     2582                }
     2583            } else if (2 == sscanf(cp, "%d Reg DB Key: %s", &ign, &buffer)) {
     2584                DeleteRegistryKey(cp);
     2585            } else if (2 == sscanf(cp, "%d Reg DB Value: %s", &ign, &buffer)) {
     2586                DeleteRegistryValue(cp);
     2587            } else if (2 == sscanf(cp, "%d Run Script: %s", &ign, &buffer)) {
     2588                Run_RemoveScript(cp);
     2589            }
     2590        }
     2591    }
     2592
     2593    if (DeleteFile(argv[2])) {
     2594        ++nFiles;
     2595    } else {
     2596        ++nErrors;
     2597        SystemError(GetLastError(), argv[2]);
     2598    }
     2599    if (nErrors)
     2600        wsprintf(buffer,
     2601                "%d files and %d directories removed\n"
     2602                "%d files or directories could not be removed",
     2603                nFiles, nDirs, nErrors);
     2604    else
     2605        wsprintf(buffer, "%d files and %d directories removed",
     2606                nFiles, nDirs);
     2607    MessageBox(NULL, buffer, "Uninstall Finished!",
     2608               MB_OK | MB_ICONINFORMATION);
     2609    remove_exe();
     2610    return 0;
    26112611}
    26122612
    26132613int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
    2614                     LPSTR lpszCmdLine, INT nCmdShow)
    2615 {
    2616         extern int __argc;
    2617         extern char **__argv;
    2618         char *basename;
    2619 
    2620         GetModuleFileName(NULL, modulename, sizeof(modulename));
    2621 
    2622         /* Map the executable file to memory */
    2623         arc_data = MapExistingFile(modulename, &arc_size);
    2624         if (!arc_data) {
    2625                 SystemError(GetLastError(), "Could not open archive");
    2626                 return 1;
    2627         }
    2628 
    2629         /* OK. So this program can act as installer (self-extracting
    2630         * zip-file, or as uninstaller when started with '-u logfile'
    2631         * command line flags.
    2632         *
    2633         * The installer is usually started without command line flags,
    2634         * and the uninstaller is usually started with the '-u logfile'
    2635         * flag. What to do if some innocent user double-clicks the
    2636         * exe-file?
    2637         * The following implements a defensive strategy...
    2638         */
    2639 
    2640         /* Try to extract the configuration data into a temporary file */
    2641         if (ExtractInstallData(arc_data, arc_size, &exe_size,
    2642                                &ini_file, &pre_install_script))
    2643                 return DoInstall();
    2644 
    2645         if (!ini_file && __argc > 1) {
    2646                 return DoUninstall(__argc, __argv);
    2647         }
    2648 
    2649 
    2650         basename = strrchr(modulename, '\\');
    2651         if (basename)
    2652                 ++basename;
    2653 
    2654         /* Last guess about the purpose of this program */
    2655         if (basename && (0 == strncmp(basename, "Remove", 6)))
    2656                 SystemError(0, "This program is normally started by windows");
    2657         else
    2658                 SystemError(0, "Setup program invalid or damaged");
    2659         return 1;
    2660 }
     2614                    LPSTR lpszCmdLine, INT nCmdShow)
     2615{
     2616    extern int __argc;
     2617    extern char **__argv;
     2618    char *basename;
     2619
     2620    GetModuleFileName(NULL, modulename, sizeof(modulename));
     2621
     2622    /* Map the executable file to memory */
     2623    arc_data = MapExistingFile(modulename, &arc_size);
     2624    if (!arc_data) {
     2625        SystemError(GetLastError(), "Could not open archive");
     2626        return 1;
     2627    }
     2628
     2629    /* OK. So this program can act as installer (self-extracting
     2630    * zip-file, or as uninstaller when started with '-u logfile'
     2631    * command line flags.
     2632    *
     2633    * The installer is usually started without command line flags,
     2634    * and the uninstaller is usually started with the '-u logfile'
     2635    * flag. What to do if some innocent user double-clicks the
     2636    * exe-file?
     2637    * The following implements a defensive strategy...
     2638    */
     2639
     2640    /* Try to extract the configuration data into a temporary file */
     2641    if (ExtractInstallData(arc_data, arc_size, &exe_size,
     2642                           &ini_file, &pre_install_script))
     2643        return DoInstall();
     2644
     2645    if (!ini_file && __argc > 1) {
     2646        return DoUninstall(__argc, __argv);
     2647    }
     2648
     2649
     2650    basename = strrchr(modulename, '\\');
     2651    if (basename)
     2652        ++basename;
     2653
     2654    /* Last guess about the purpose of this program */
     2655    if (basename && (0 == strncmp(basename, "Remove", 6)))
     2656        SystemError(0, "This program is normally started by windows");
     2657    else
     2658        SystemError(0, "Setup program invalid or damaged");
     2659    return 1;
     2660}
  • python/vendor/current/PC/config.c

    r2 r388  
    5353extern void init_struct(void);
    5454extern void initdatetime(void);
    55 extern void init_fileio(void);
    56 extern void init_bytesio(void);
    5755extern void init_functools(void);
    5856extern void init_json(void);
     
    6967extern void init_lsprof(void);
    7068extern void init_ast(void);
     69extern void init_io(void);
    7170extern void _PyWarnings_Init(void);
    7271
     
    7978struct _inittab _PyImport_Inittab[] = {
    8079
    81         {"array", initarray},
    82         {"_ast", init_ast},
     80    {"array", initarray},
     81    {"_ast", init_ast},
    8382#ifdef MS_WINDOWS
    8483#ifndef MS_WINI64
    85         {"audioop", initaudioop},
     84    {"audioop", initaudioop},
    8685#endif
    8786#endif
    88         {"binascii", initbinascii},
    89         {"cmath", initcmath},
    90         {"errno", initerrno},
    91         {"future_builtins", initfuture_builtins},
    92         {"gc", initgc},
     87    {"binascii", initbinascii},
     88    {"cmath", initcmath},
     89    {"errno", initerrno},
     90    {"future_builtins", initfuture_builtins},
     91    {"gc", initgc},
    9392#ifndef MS_WINI64
    94         {"imageop", initimageop},
     93    {"imageop", initimageop},
    9594#endif
    96         {"math", initmath},
    97         {"_md5", init_md5},
    98         {"nt", initnt}, /* Use the NT os functions, not posix */
    99         {"operator", initoperator},
    100         {"signal", initsignal},
    101         {"_sha", init_sha},
    102         {"_sha256", init_sha256},
    103         {"_sha512", init_sha512},
    104         {"strop", initstrop},
    105         {"time", inittime},
     95    {"math", initmath},
     96    {"_md5", init_md5},
     97    {"nt", initnt}, /* Use the NT os functions, not posix */
     98    {"operator", initoperator},
     99    {"signal", initsignal},
     100    {"_sha", init_sha},
     101    {"_sha256", init_sha256},
     102    {"_sha512", init_sha512},
     103    {"strop", initstrop},
     104    {"time", inittime},
    106105#ifdef WITH_THREAD
    107         {"thread", initthread},
     106    {"thread", initthread},
    108107#endif
    109         {"cStringIO", initcStringIO},
    110         {"cPickle", initcPickle},
     108    {"cStringIO", initcStringIO},
     109    {"cPickle", initcPickle},
    111110#ifdef WIN32
    112         {"msvcrt", initmsvcrt},
    113         {"_locale", init_locale},
     111    {"msvcrt", initmsvcrt},
     112    {"_locale", init_locale},
    114113#endif
    115         /* XXX Should _subprocess go in a WIN32 block?  not WIN64? */
    116         {"_subprocess", init_subprocess},
     114    /* XXX Should _subprocess go in a WIN32 block?  not WIN64? */
     115    {"_subprocess", init_subprocess},
    117116
    118         {"_codecs", init_codecs},
    119         {"_weakref", init_weakref},
    120         {"_hotshot", init_hotshot},
    121         {"_random", init_random},
    122         {"_bisect", init_bisect},
    123         {"_heapq", init_heapq},
    124         {"_lsprof", init_lsprof},
    125         {"itertools", inititertools},
    126         {"_collections", init_collections},
    127         {"_symtable", init_symtable},
    128         {"mmap", initmmap},
    129         {"_csv", init_csv},
    130         {"_sre", init_sre},
    131         {"parser", initparser},
    132         {"_winreg", init_winreg},
    133         {"_struct", init_struct},
    134         {"datetime", initdatetime},
    135         {"_fileio", init_fileio},
    136         {"_bytesio", init_bytesio},
    137         {"_functools", init_functools},
    138         {"_json", init_json},
     117    {"_codecs", init_codecs},
     118    {"_weakref", init_weakref},
     119    {"_hotshot", init_hotshot},
     120    {"_random", init_random},
     121    {"_bisect", init_bisect},
     122    {"_heapq", init_heapq},
     123    {"_lsprof", init_lsprof},
     124    {"itertools", inititertools},
     125    {"_collections", init_collections},
     126    {"_symtable", init_symtable},
     127    {"mmap", initmmap},
     128    {"_csv", init_csv},
     129    {"_sre", init_sre},
     130    {"parser", initparser},
     131    {"_winreg", init_winreg},
     132    {"_struct", init_struct},
     133    {"datetime", initdatetime},
     134    {"_functools", init_functools},
     135    {"_json", init_json},
    139136
    140         {"xxsubtype", initxxsubtype},
    141         {"zipimport", initzipimport},
    142         {"zlib", initzlib},
    143        
    144         /* CJK codecs */
    145         {"_multibytecodec", init_multibytecodec},
    146         {"_codecs_cn", init_codecs_cn},
    147         {"_codecs_hk", init_codecs_hk},
    148         {"_codecs_iso2022", init_codecs_iso2022},
    149         {"_codecs_jp", init_codecs_jp},
    150         {"_codecs_kr", init_codecs_kr},
    151         {"_codecs_tw", init_codecs_tw},
     137    {"xxsubtype", initxxsubtype},
     138    {"zipimport", initzipimport},
     139    {"zlib", initzlib},
     140
     141    /* CJK codecs */
     142    {"_multibytecodec", init_multibytecodec},
     143    {"_codecs_cn", init_codecs_cn},
     144    {"_codecs_hk", init_codecs_hk},
     145    {"_codecs_iso2022", init_codecs_iso2022},
     146    {"_codecs_jp", init_codecs_jp},
     147    {"_codecs_kr", init_codecs_kr},
     148    {"_codecs_tw", init_codecs_tw},
    152149
    153150/* tools/freeze/makeconfig.py marker for additional "_inittab" entries */
    154151/* -- ADDMODULE MARKER 2 -- */
    155152
    156         /* This module "lives in" with marshal.c */
    157         {"marshal", PyMarshal_Init},
     153    /* This module "lives in" with marshal.c */
     154    {"marshal", PyMarshal_Init},
    158155
    159         /* This lives it with import.c */
    160         {"imp", initimp},
     156    /* This lives it with import.c */
     157    {"imp", initimp},
    161158
    162         /* These entries are here for sys.builtin_module_names */
    163         {"__main__", NULL},
    164         {"__builtin__", NULL},
    165         {"sys", NULL},
    166         {"exceptions", NULL},
    167         {"_warnings", _PyWarnings_Init},
     159    /* These entries are here for sys.builtin_module_names */
     160    {"__main__", NULL},
     161    {"__builtin__", NULL},
     162    {"sys", NULL},
     163    {"exceptions", NULL},
     164    {"_warnings", _PyWarnings_Init},
    168165
    169         /* Sentinel */
    170         {0, 0}
     166    {"_io", init_io},
     167
     168    /* Sentinel */
     169    {0, 0}
    171170};
  • python/vendor/current/PC/dl_nt.c

    r2 r388  
    44
    55About the only reason for having this, is so initall() can automatically
    6 be called, removing that burden (and possible source of frustration if 
     6be called, removing that burden (and possible source of frustration if
    77forgotten) from the programmer.
    88
     
    4747void _LoadActCtxPointers()
    4848{
    49         HINSTANCE hKernel32 = GetModuleHandleW(L"kernel32.dll");
    50         if (hKernel32)
    51                 pfnGetCurrentActCtx = (PFN_GETCURRENTACTCTX) GetProcAddress(hKernel32, "GetCurrentActCtx");
    52         // If we can't load GetCurrentActCtx (ie, pre XP) , don't bother with the rest.
    53         if (pfnGetCurrentActCtx) {
    54                 pfnActivateActCtx = (PFN_ACTIVATEACTCTX) GetProcAddress(hKernel32, "ActivateActCtx");
    55                 pfnDeactivateActCtx = (PFN_DEACTIVATEACTCTX) GetProcAddress(hKernel32, "DeactivateActCtx");
    56                 pfnAddRefActCtx = (PFN_ADDREFACTCTX) GetProcAddress(hKernel32, "AddRefActCtx");
    57                 pfnReleaseActCtx = (PFN_RELEASEACTCTX) GetProcAddress(hKernel32, "ReleaseActCtx");
    58         }
     49    HINSTANCE hKernel32 = GetModuleHandleW(L"kernel32.dll");
     50    if (hKernel32)
     51        pfnGetCurrentActCtx = (PFN_GETCURRENTACTCTX) GetProcAddress(hKernel32, "GetCurrentActCtx");
     52    // If we can't load GetCurrentActCtx (ie, pre XP) , don't bother with the rest.
     53    if (pfnGetCurrentActCtx) {
     54        pfnActivateActCtx = (PFN_ACTIVATEACTCTX) GetProcAddress(hKernel32, "ActivateActCtx");
     55        pfnDeactivateActCtx = (PFN_DEACTIVATEACTCTX) GetProcAddress(hKernel32, "DeactivateActCtx");
     56        pfnAddRefActCtx = (PFN_ADDREFACTCTX) GetProcAddress(hKernel32, "AddRefActCtx");
     57        pfnReleaseActCtx = (PFN_RELEASEACTCTX) GetProcAddress(hKernel32, "ReleaseActCtx");
     58    }
    5959}
    6060
    6161ULONG_PTR _Py_ActivateActCtx()
    6262{
    63         ULONG_PTR ret = 0;
    64         if (PyWin_DLLhActivationContext && pfnActivateActCtx)
    65                 if (!(*pfnActivateActCtx)(PyWin_DLLhActivationContext, &ret)) {
    66                         OutputDebugString("Python failed to activate the activation context before loading a DLL\n");
    67                         ret = 0; // no promise the failing function didn't change it!
    68                 }
    69         return ret;
     63    ULONG_PTR ret = 0;
     64    if (PyWin_DLLhActivationContext && pfnActivateActCtx)
     65        if (!(*pfnActivateActCtx)(PyWin_DLLhActivationContext, &ret)) {
     66            OutputDebugString("Python failed to activate the activation context before loading a DLL\n");
     67            ret = 0; // no promise the failing function didn't change it!
     68        }
     69    return ret;
    7070}
    7171
    7272void _Py_DeactivateActCtx(ULONG_PTR cookie)
    7373{
    74         if (cookie && pfnDeactivateActCtx)
    75                 if (!(*pfnDeactivateActCtx)(0, cookie))
    76                         OutputDebugString("Python failed to de-activate the activation context\n");
     74    if (cookie && pfnDeactivateActCtx)
     75        if (!(*pfnDeactivateActCtx)(0, cookie))
     76            OutputDebugString("Python failed to de-activate the activation context\n");
    7777}
    7878
    79 BOOL    WINAPI  DllMain (HANDLE hInst,
    80                                                 ULONG ul_reason_for_call,
    81                                                 LPVOID lpReserved)
     79BOOL    WINAPI  DllMain (HANDLE hInst,
     80                                                ULONG ul_reason_for_call,
     81                                                LPVOID lpReserved)
    8282{
    83         switch (ul_reason_for_call)
    84         {
    85                 case DLL_PROCESS_ATTACH:
    86                         PyWin_DLLhModule = hInst;
    87                         // 1000 is a magic number I picked out of the air.  Could do with a #define, I spose...
    88                         LoadString(hInst, 1000, dllVersionBuffer, sizeof(dllVersionBuffer));
     83    switch (ul_reason_for_call)
     84    {
     85        case DLL_PROCESS_ATTACH:
     86            PyWin_DLLhModule = hInst;
     87            // 1000 is a magic number I picked out of the air.  Could do with a #define, I spose...
     88            LoadString(hInst, 1000, dllVersionBuffer, sizeof(dllVersionBuffer));
    8989
    90                         // and capture our activation context for use when loading extensions.
    91                         _LoadActCtxPointers();
    92                         if (pfnGetCurrentActCtx && pfnAddRefActCtx)
    93                                 if ((*pfnGetCurrentActCtx)(&PyWin_DLLhActivationContext))
    94                                         if (!(*pfnAddRefActCtx)(PyWin_DLLhActivationContext))
    95                                                 OutputDebugString("Python failed to load the default activation context\n");
    96                         break;
     90            // and capture our activation context for use when loading extensions.
     91            _LoadActCtxPointers();
     92            if (pfnGetCurrentActCtx && pfnAddRefActCtx)
     93                if ((*pfnGetCurrentActCtx)(&PyWin_DLLhActivationContext))
     94                    if (!(*pfnAddRefActCtx)(PyWin_DLLhActivationContext))
     95                        OutputDebugString("Python failed to load the default activation context\n");
     96            break;
    9797
    98                 case DLL_PROCESS_DETACH:
    99                         if (pfnReleaseActCtx)
    100                                 (*pfnReleaseActCtx)(PyWin_DLLhActivationContext);
    101                         break;
    102         }
    103         return TRUE;
     98        case DLL_PROCESS_DETACH:
     99            if (pfnReleaseActCtx)
     100                (*pfnReleaseActCtx)(PyWin_DLLhActivationContext);
     101            break;
     102    }
     103    return TRUE;
    104104}
    105105
  • python/vendor/current/PC/errmap.h

    r2 r388  
    22int winerror_to_errno(int winerror)
    33{
    4         switch(winerror) {
    5                 case 2: return 2;
    6                 case 3: return 2;
    7                 case 4: return 24;
    8                 case 5: return 13;
    9                 case 6: return 9;
    10                 case 7: return 12;
    11                 case 8: return 12;
    12                 case 9: return 12;
    13                 case 10: return 7;
    14                 case 11: return 8;
    15                 case 15: return 2;
    16                 case 16: return 13;
    17                 case 17: return 18;
    18                 case 18: return 2;
    19                 case 19: return 13;
    20                 case 20: return 13;
    21                 case 21: return 13;
    22                 case 22: return 13;
    23                 case 23: return 13;
    24                 case 24: return 13;
    25                 case 25: return 13;
    26                 case 26: return 13;
    27                 case 27: return 13;
    28                 case 28: return 13;
    29                 case 29: return 13;
    30                 case 30: return 13;
    31                 case 31: return 13;
    32                 case 32: return 13;
    33                 case 33: return 13;
    34                 case 34: return 13;
    35                 case 35: return 13;
    36                 case 36: return 13;
    37                 case 53: return 2;
    38                 case 65: return 13;
    39                 case 67: return 2;
    40                 case 80: return 17;
    41                 case 82: return 13;
    42                 case 83: return 13;
    43                 case 89: return 11;
    44                 case 108: return 13;
    45                 case 109: return 32;
    46                 case 112: return 28;
    47                 case 114: return 9;
    48                 case 128: return 10;
    49                 case 129: return 10;
    50                 case 130: return 9;
    51                 case 132: return 13;
    52                 case 145: return 41;
    53                 case 158: return 13;
    54                 case 161: return 2;
    55                 case 164: return 11;
    56                 case 167: return 13;
    57                 case 183: return 17;
    58                 case 188: return 8;
    59                 case 189: return 8;
    60                 case 190: return 8;
    61                 case 191: return 8;
    62                 case 192: return 8;
    63                 case 193: return 8;
    64                 case 194: return 8;
    65                 case 195: return 8;
    66                 case 196: return 8;
    67                 case 197: return 8;
    68                 case 198: return 8;
    69                 case 199: return 8;
    70                 case 200: return 8;
    71                 case 201: return 8;
    72                 case 202: return 8;
    73                 case 206: return 2;
    74                 case 215: return 11;
    75                 case 1816: return 12;
    76                 default: return EINVAL;
    77         }
     4    switch(winerror) {
     5        case 2: return 2;
     6        case 3: return 2;
     7        case 4: return 24;
     8        case 5: return 13;
     9        case 6: return 9;
     10        case 7: return 12;
     11        case 8: return 12;
     12        case 9: return 12;
     13        case 10: return 7;
     14        case 11: return 8;
     15        case 15: return 2;
     16        case 16: return 13;
     17        case 17: return 18;
     18        case 18: return 2;
     19        case 19: return 13;
     20        case 20: return 13;
     21        case 21: return 13;
     22        case 22: return 13;
     23        case 23: return 13;
     24        case 24: return 13;
     25        case 25: return 13;
     26        case 26: return 13;
     27        case 27: return 13;
     28        case 28: return 13;
     29        case 29: return 13;
     30        case 30: return 13;
     31        case 31: return 13;
     32        case 32: return 13;
     33        case 33: return 13;
     34        case 34: return 13;
     35        case 35: return 13;
     36        case 36: return 13;
     37        case 53: return 2;
     38        case 65: return 13;
     39        case 67: return 2;
     40        case 80: return 17;
     41        case 82: return 13;
     42        case 83: return 13;
     43        case 89: return 11;
     44        case 108: return 13;
     45        case 109: return 32;
     46        case 112: return 28;
     47        case 114: return 9;
     48        case 128: return 10;
     49        case 129: return 10;
     50        case 130: return 9;
     51        case 132: return 13;
     52        case 145: return 41;
     53        case 158: return 13;
     54        case 161: return 2;
     55        case 164: return 11;
     56        case 167: return 13;
     57        case 183: return 17;
     58        case 188: return 8;
     59        case 189: return 8;
     60        case 190: return 8;
     61        case 191: return 8;
     62        case 192: return 8;
     63        case 193: return 8;
     64        case 194: return 8;
     65        case 195: return 8;
     66        case 196: return 8;
     67        case 197: return 8;
     68        case 198: return 8;
     69        case 199: return 8;
     70        case 200: return 8;
     71        case 201: return 8;
     72        case 202: return 8;
     73        case 206: return 2;
     74        case 215: return 11;
     75        case 1816: return 12;
     76        default: return EINVAL;
     77    }
    7878}
  • python/vendor/current/PC/example_nt/example.vcproj

    r2 r388  
    4040                                Name="VCLinkerTool"
    4141                                AdditionalOptions="/export:initexample"
    42                                 AdditionalDependencies="odbc32.lib odbccp32.lib python26.lib"
     42                                AdditionalDependencies="odbc32.lib odbccp32.lib python27.lib"
    4343                                OutputFile=".\Release/example.pyd"
    4444                                LinkIncremental="1"
     
    106106                                Name="VCLinkerTool"
    107107                                AdditionalOptions="/export:initexample"
    108                                 AdditionalDependencies="odbc32.lib odbccp32.lib python26_d.lib"
     108                                AdditionalDependencies="odbc32.lib odbccp32.lib python27_d.lib"
    109109                                OutputFile=".\Debug/example_d.pyd"
    110110                                LinkIncremental="1"
  • python/vendor/current/PC/frozen_dllmain.c

    r2 r388  
    1010The solution is:
    1111* Each module checks for a frozen build, and if so, defines its DLLMain
    12   function as "__declspec(dllexport) DllMain%module%" 
     12  function as "__declspec(dllexport) DllMain%module%"
    1313  (eg, DllMainpythoncom, or DllMainpywintypes)
    1414
     
    4848
    4949static char *possibleModules[] = {
    50         "pywintypes",
    51         "pythoncom",
    52         "win32ui",
    53         NULL,
     50    "pywintypes",
     51    "pythoncom",
     52    "win32ui",
     53    NULL,
    5454};
    5555
     
    6363void PyWinFreeze_ExeInit(void)
    6464{
    65         char **modName;
    66         for (modName = possibleModules;*modName;*modName++) {
    67 /*              printf("Initialising '%s'\n", *modName); */
    68                 CallModuleDllMain(*modName, DLL_PROCESS_ATTACH);
    69         }
     65    char **modName;
     66    for (modName = possibleModules;*modName;*modName++) {
     67/*              printf("Initialising '%s'\n", *modName); */
     68        CallModuleDllMain(*modName, DLL_PROCESS_ATTACH);
     69    }
    7070}
    7171
    7272/*
    7373  Called by a frozen .EXE only, so that built-in extension
    74   modules are cleaned up 
     74  modules are cleaned up
    7575*/
    7676void PyWinFreeze_ExeTerm(void)
    7777{
    78         // Must go backwards
    79         char **modName;
    80         for (modName = possibleModules+(sizeof(possibleModules) / sizeof(char *))-2;
    81              modName >= possibleModules;
    82              *modName--) {
    83 /*              printf("Terminating '%s'\n", *modName);*/
    84                 CallModuleDllMain(*modName, DLL_PROCESS_DETACH);
    85         }
     78    // Must go backwards
     79    char **modName;
     80    for (modName = possibleModules+(sizeof(possibleModules) / sizeof(char *))-2;
     81         modName >= possibleModules;
     82         *modName--) {
     83/*              printf("Terminating '%s'\n", *modName);*/
     84        CallModuleDllMain(*modName, DLL_PROCESS_DETACH);
     85    }
    8686}
    8787
    8888BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
    8989{
    90         BOOL ret = TRUE;
    91         switch (dwReason) {
    92                 case DLL_PROCESS_ATTACH:
    93                 {
    94                         char **modName;
    95                         for (modName = possibleModules;*modName;*modName++) {
    96                                 BOOL ok = CallModuleDllMain(*modName, dwReason);
    97                                 if (!ok)
    98                                         ret = FALSE;
    99                         }
    100                         break;
    101                 }
    102                 case DLL_PROCESS_DETACH:
    103                 {
    104                         // Must go backwards
    105                         char **modName;
    106                         for (modName = possibleModules+(sizeof(possibleModules) / sizeof(char *))-2;
    107                              modName >= possibleModules;
    108                              *modName--)
    109                                 CallModuleDllMain(*modName, DLL_PROCESS_DETACH);
    110                         break;
    111                 }
    112         }
    113         return ret;
     90    BOOL ret = TRUE;
     91    switch (dwReason) {
     92        case DLL_PROCESS_ATTACH:
     93        {
     94            char **modName;
     95            for (modName = possibleModules;*modName;*modName++) {
     96                BOOL ok = CallModuleDllMain(*modName, dwReason);
     97                if (!ok)
     98                    ret = FALSE;
     99            }
     100            break;
     101        }
     102        case DLL_PROCESS_DETACH:
     103        {
     104            // Must go backwards
     105            char **modName;
     106            for (modName = possibleModules+(sizeof(possibleModules) / sizeof(char *))-2;
     107                 modName >= possibleModules;
     108                 *modName--)
     109                CallModuleDllMain(*modName, DLL_PROCESS_DETACH);
     110            break;
     111        }
     112    }
     113    return ret;
    114114}
    115115
    116116BOOL CallModuleDllMain(char *modName, DWORD dwReason)
    117117{
    118         BOOL (WINAPI * pfndllmain)(HINSTANCE, DWORD, LPVOID);
     118    BOOL (WINAPI * pfndllmain)(HINSTANCE, DWORD, LPVOID);
    119119
    120         char funcName[255];
    121         HMODULE hmod = GetModuleHandle(NULL);
    122         strcpy(funcName, "_DllMain");
    123         strcat(funcName, modName);
    124         strcat(funcName, "@12"); // stdcall convention.
    125         pfndllmain = (BOOL (WINAPI *)(HINSTANCE, DWORD, LPVOID))GetProcAddress(hmod, funcName);
    126         if (pfndllmain==NULL) {
    127                 /* No function by that name exported - then that module does
    128                    not appear in our frozen program - return OK
    129                 */
    130                 return TRUE;
    131         }
    132         return (*pfndllmain)(hmod, dwReason, NULL);
     120    char funcName[255];
     121    HMODULE hmod = GetModuleHandle(NULL);
     122    strcpy(funcName, "_DllMain");
     123    strcat(funcName, modName);
     124    strcat(funcName, "@12"); // stdcall convention.
     125    pfndllmain = (BOOL (WINAPI *)(HINSTANCE, DWORD, LPVOID))GetProcAddress(hmod, funcName);
     126    if (pfndllmain==NULL) {
     127        /* No function by that name exported - then that module does
     128           not appear in our frozen program - return OK
     129        */
     130        return TRUE;
     131    }
     132    return (*pfndllmain)(hmod, dwReason, NULL);
    133133}
    134134
  • python/vendor/current/PC/generrmap.c

    r2 r388  
    66int main()
    77{
    8         int i;
    9         printf("/* Generated file. Do not edit. */\n");
    10         printf("int winerror_to_errno(int winerror)\n");
    11         printf("{\n\tswitch(winerror) {\n");
    12         for(i=1; i < 65000; i++) {
    13                 _dosmaperr(i);
    14                 if (errno == EINVAL)
    15                         continue;
    16                 printf("\t\tcase %d: return %d;\n", i, errno);
    17         }
    18         printf("\t\tdefault: return EINVAL;\n");
    19         printf("\t}\n}\n");
     8    int i;
     9    printf("/* Generated file. Do not edit. */\n");
     10    printf("int winerror_to_errno(int winerror)\n");
     11    printf("{\n\tswitch(winerror) {\n");
     12    for(i=1; i < 65000; i++) {
     13        _dosmaperr(i);
     14        if (errno == EINVAL)
     15            continue;
     16        printf("\t\tcase %d: return %d;\n", i, errno);
     17    }
     18    printf("\t\tdefault: return EINVAL;\n");
     19    printf("\t}\n}\n");
    2020}
  • python/vendor/current/PC/getpathp.c

    r2 r388  
    55/* ----------------------------------------------------------------
    66   PATH RULES FOR WINDOWS:
    7    This describes how sys.path is formed on Windows.  It describes the 
    8    functionality, not the implementation (ie, the order in which these 
     7   This describes how sys.path is formed on Windows.  It describes the
     8   functionality, not the implementation (ie, the order in which these
    99   are actually fetched is different)
    1010
     
    2525     is set, we believe it.  Otherwise, we use the path of our host .EXE's
    2626     to try and locate our "landmark" (lib\\os.py) and deduce our home.
    27      - If we DO have a Python Home: The relevant sub-directories (Lib, 
     27     - If we DO have a Python Home: The relevant sub-directories (Lib,
    2828       plat-win, lib-tk, etc) are based on the Python Home
    2929     - If we DO NOT have a Python Home, the core Python Path is
    30        loaded from the registry.  This is the main PythonPath key, 
     30       loaded from the registry.  This is the main PythonPath key,
    3131       and both HKLM and HKCU are combined to form the path)
    3232
    3333   * Iff - we can not locate the Python Home, have not had a PYTHONPATH
    3434     specified, and can't locate any Registry entries (ie, we have _nothing_
    35      we can assume is a good path), a default path with relative entries is 
     35     we can assume is a good path), a default path with relative entries is
    3636     used (eg. .\Lib;.\plat-win, etc)
    3737
     
    4343    ignored.  Other "application paths" in the registry are always read.
    4444
    45   * When Python is hosted in another exe (different directory, embedded via 
     45  * When Python is hosted in another exe (different directory, embedded via
    4646    COM, etc), the Python Home will not be deduced, so the core path from
    47     the registry is used.  Other "application paths" in the registry are 
     47    the registry is used.  Other "application paths" in the registry are
    4848    always read.
    4949
     
    9393
    9494static int
    95 is_sep(char ch) /* determine if "ch" is a separator character */
     95is_sep(char ch) /* determine if "ch" is a separator character */
    9696{
    9797#ifdef ALTSEP
    98         return ch == SEP || ch == ALTSEP;
     98    return ch == SEP || ch == ALTSEP;
    9999#else
    100         return ch == SEP;
     100    return ch == SEP;
    101101#endif
    102102}
     
    108108reduce(char *dir)
    109109{
    110         size_t i = strlen(dir);
    111         while (i > 0 && !is_sep(dir[i]))
    112                 --i;
    113         dir[i] = '\0';
    114 }
    115        
     110    size_t i = strlen(dir);
     111    while (i > 0 && !is_sep(dir[i]))
     112        --i;
     113    dir[i] = '\0';
     114}
     115
    116116
    117117static int
    118118exists(char *filename)
    119119{
    120         struct stat buf;
    121         return stat(filename, &buf) == 0;
    122 }
    123 
    124 /* Assumes 'filename' MAXPATHLEN+1 bytes long - 
     120    struct stat buf;
     121    return stat(filename, &buf) == 0;
     122}
     123
     124/* Assumes 'filename' MAXPATHLEN+1 bytes long -
    125125   may extend 'filename' by one character.
    126126*/
    127127static int
    128 ismodule(char *filename)        /* Is module -- check for .pyc/.pyo too */
    129 {
    130         if (exists(filename))
    131                 return 1;
    132 
    133         /* Check for the compiled version of prefix. */
    134         if (strlen(filename) < MAXPATHLEN) {
    135                 strcat(filename, Py_OptimizeFlag ? "o" : "c");
    136                 if (exists(filename))
    137                         return 1;
    138         }
    139         return 0;
     128ismodule(char *filename)        /* Is module -- check for .pyc/.pyo too */
     129{
     130    if (exists(filename))
     131        return 1;
     132
     133    /* Check for the compiled version of prefix. */
     134    if (strlen(filename) < MAXPATHLEN) {
     135        strcat(filename, Py_OptimizeFlag ? "o" : "c");
     136        if (exists(filename))
     137            return 1;
     138    }
     139    return 0;
    140140}
    141141
     
    152152join(char *buffer, char *stuff)
    153153{
    154         size_t n, k;
    155         if (is_sep(stuff[0]))
    156                 n = 0;
    157         else {
    158                 n = strlen(buffer);
    159                 if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN)
    160                         buffer[n++] = SEP;
    161         }
    162         if (n > MAXPATHLEN)
    163                 Py_FatalError("buffer overflow in getpathp.c's joinpath()");
    164         k = strlen(stuff);
    165         if (n + k > MAXPATHLEN)
    166                 k = MAXPATHLEN - n;
    167         strncpy(buffer+n, stuff, k);
    168         buffer[n+k] = '\0';
     154    size_t n, k;
     155    if (is_sep(stuff[0]))
     156        n = 0;
     157    else {
     158        n = strlen(buffer);
     159        if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN)
     160            buffer[n++] = SEP;
     161    }
     162    if (n > MAXPATHLEN)
     163        Py_FatalError("buffer overflow in getpathp.c's joinpath()");
     164    k = strlen(stuff);
     165    if (n + k > MAXPATHLEN)
     166        k = MAXPATHLEN - n;
     167    strncpy(buffer+n, stuff, k);
     168    buffer[n+k] = '\0';
    169169}
    170170
     
    176176gotlandmark(char *landmark)
    177177{
    178         int ok;
    179         Py_ssize_t n;
    180 
    181         n = strlen(prefix);
    182         join(prefix, landmark);
    183         ok = ismodule(prefix);
    184         prefix[n] = '\0';
    185         return ok;
    186 }
    187 
    188 /* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd. 
     178    int ok;
     179    Py_ssize_t n;
     180
     181    n = strlen(prefix);
     182    join(prefix, landmark);
     183    ok = ismodule(prefix);
     184    prefix[n] = '\0';
     185    return ok;
     186}
     187
     188/* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd.
    189189   assumption provided by only caller, calculate_path() */
    190190static int
    191191search_for_prefix(char *argv0_path, char *landmark)
    192192{
    193         /* Search from argv0_path, until landmark is found */
    194         strcpy(prefix, argv0_path);
    195         do {
    196                 if (gotlandmark(landmark))
    197                         return 1;
    198                 reduce(prefix);
    199         } while (prefix[0]);
    200         return 0;
     193    /* Search from argv0_path, until landmark is found */
     194    strcpy(prefix, argv0_path);
     195    do {
     196        if (gotlandmark(landmark))
     197            return 1;
     198        reduce(prefix);
     199    } while (prefix[0]);
     200    return 0;
    201201}
    202202
     
    224224getpythonregpath(HKEY keyBase, int skipcore)
    225225{
    226         HKEY newKey = 0;
    227         DWORD dataSize = 0;
    228         DWORD numKeys = 0;
    229         LONG rc;
    230         char *retval = NULL;
    231         TCHAR *dataBuf = NULL;
    232         static const TCHAR keyPrefix[] = _T("Software\\Python\\PythonCore\\");
    233         static const TCHAR keySuffix[] = _T("\\PythonPath");
    234         size_t versionLen;
    235         DWORD index;
    236         TCHAR *keyBuf = NULL;
    237         TCHAR *keyBufPtr;
    238         TCHAR **ppPaths = NULL;
    239 
    240         /* Tried to use sysget("winver") but here is too early :-( */
    241         versionLen = _tcslen(PyWin_DLLVersionString);
    242         /* Space for all the chars, plus one \0 */
    243         keyBuf = keyBufPtr = malloc(sizeof(keyPrefix) +
    244                                     sizeof(TCHAR)*(versionLen-1) +
    245                                     sizeof(keySuffix));
    246         if (keyBuf==NULL) goto done;
    247 
    248         memcpy(keyBufPtr, keyPrefix, sizeof(keyPrefix)-sizeof(TCHAR));
    249         keyBufPtr += sizeof(keyPrefix)/sizeof(TCHAR) - 1;
    250         memcpy(keyBufPtr, PyWin_DLLVersionString, versionLen * sizeof(TCHAR));
    251         keyBufPtr += versionLen;
    252         /* NULL comes with this one! */
    253         memcpy(keyBufPtr, keySuffix, sizeof(keySuffix));
    254         /* Open the root Python key */
    255         rc=RegOpenKeyEx(keyBase,
    256                         keyBuf, /* subkey */
    257                         0, /* reserved */
    258                         KEY_READ,
    259                         &newKey);
    260         if (rc!=ERROR_SUCCESS) goto done;
    261         /* Find out how big our core buffer is, and how many subkeys we have */
    262         rc = RegQueryInfoKey(newKey, NULL, NULL, NULL, &numKeys, NULL, NULL,
    263                         NULL, NULL, &dataSize, NULL, NULL);
    264         if (rc!=ERROR_SUCCESS) goto done;
    265         if (skipcore) dataSize = 0; /* Only count core ones if we want them! */
    266         /* Allocate a temp array of char buffers, so we only need to loop
    267            reading the registry once
    268         */
    269         ppPaths = malloc( sizeof(TCHAR *) * numKeys );
    270         if (ppPaths==NULL) goto done;
    271         memset(ppPaths, 0, sizeof(TCHAR *) * numKeys);
    272         /* Loop over all subkeys, allocating a temp sub-buffer. */
    273         for(index=0;index<numKeys;index++) {
    274                 TCHAR keyBuf[MAX_PATH+1];
    275                 HKEY subKey = 0;
    276                 DWORD reqdSize = MAX_PATH+1;
    277                 /* Get the sub-key name */
    278                 DWORD rc = RegEnumKeyEx(newKey, index, keyBuf, &reqdSize,
    279                                         NULL, NULL, NULL, NULL );
    280                 if (rc!=ERROR_SUCCESS) goto done;
    281                 /* Open the sub-key */
    282                 rc=RegOpenKeyEx(newKey,
    283                                                 keyBuf, /* subkey */
    284                                                 0, /* reserved */
    285                                                 KEY_READ,
    286                                                 &subKey);
    287                 if (rc!=ERROR_SUCCESS) goto done;
    288                 /* Find the value of the buffer size, malloc, then read it */
    289                 RegQueryValueEx(subKey, NULL, 0, NULL, NULL, &reqdSize);
    290                 if (reqdSize) {
    291                         ppPaths[index] = malloc(reqdSize);
    292                         if (ppPaths[index]) {
    293                                 RegQueryValueEx(subKey, NULL, 0, NULL,
    294                                                 (LPBYTE)ppPaths[index],
    295                                                 &reqdSize);
    296                                 dataSize += reqdSize + 1; /* 1 for the ";" */
    297                         }
    298                 }
    299                 RegCloseKey(subKey);
    300         }
    301 
    302         /* return null if no path to return */
    303         if (dataSize == 0) goto done;
    304 
    305         /* original datasize from RegQueryInfo doesn't include the \0 */
    306         dataBuf = malloc((dataSize+1) * sizeof(TCHAR));
    307         if (dataBuf) {
    308                 TCHAR *szCur = dataBuf;
    309                 DWORD reqdSize = dataSize;
    310                 /* Copy our collected strings */
    311                 for (index=0;index<numKeys;index++) {
    312                         if (index > 0) {
    313                                 *(szCur++) = _T(';');
    314                                 dataSize--;
    315                         }
    316                         if (ppPaths[index]) {
    317                                 Py_ssize_t len = _tcslen(ppPaths[index]);
    318                                 _tcsncpy(szCur, ppPaths[index], len);
    319                                 szCur += len;
    320                                 assert(dataSize > (DWORD)len);
    321                                 dataSize -= (DWORD)len;
    322                         }
    323                 }
    324                 if (skipcore)
    325                         *szCur = '\0';
    326                 else {
    327                         /* If we have no values, we dont need a ';' */
    328                         if (numKeys) {
    329                                 *(szCur++) = _T(';');
    330                                 dataSize--;
    331                         }
    332                         /* Now append the core path entries -
    333                            this will include the NULL
    334                         */
    335                         rc = RegQueryValueEx(newKey, NULL, 0, NULL,
    336                                              (LPBYTE)szCur, &dataSize);
    337                 }
    338                 /* And set the result - caller must free
    339                    If MBCS, it is fine as is.  If Unicode, allocate new
    340                    buffer and convert.
    341                 */
     226    HKEY newKey = 0;
     227    DWORD dataSize = 0;
     228    DWORD numKeys = 0;
     229    LONG rc;
     230    char *retval = NULL;
     231    TCHAR *dataBuf = NULL;
     232    static const TCHAR keyPrefix[] = _T("Software\\Python\\PythonCore\\");
     233    static const TCHAR keySuffix[] = _T("\\PythonPath");
     234    size_t versionLen;
     235    DWORD index;
     236    TCHAR *keyBuf = NULL;
     237    TCHAR *keyBufPtr;
     238    TCHAR **ppPaths = NULL;
     239
     240    /* Tried to use sysget("winver") but here is too early :-( */
     241    versionLen = _tcslen(PyWin_DLLVersionString);
     242    /* Space for all the chars, plus one \0 */
     243    keyBuf = keyBufPtr = malloc(sizeof(keyPrefix) +
     244                                sizeof(TCHAR)*(versionLen-1) +
     245                                sizeof(keySuffix));
     246    if (keyBuf==NULL) goto done;
     247
     248    memcpy(keyBufPtr, keyPrefix, sizeof(keyPrefix)-sizeof(TCHAR));
     249    keyBufPtr += sizeof(keyPrefix)/sizeof(TCHAR) - 1;
     250    memcpy(keyBufPtr, PyWin_DLLVersionString, versionLen * sizeof(TCHAR));
     251    keyBufPtr += versionLen;
     252    /* NULL comes with this one! */
     253    memcpy(keyBufPtr, keySuffix, sizeof(keySuffix));
     254    /* Open the root Python key */
     255    rc=RegOpenKeyEx(keyBase,
     256                    keyBuf, /* subkey */
     257            0, /* reserved */
     258            KEY_READ,
     259            &newKey);
     260    if (rc!=ERROR_SUCCESS) goto done;
     261    /* Find out how big our core buffer is, and how many subkeys we have */
     262    rc = RegQueryInfoKey(newKey, NULL, NULL, NULL, &numKeys, NULL, NULL,
     263                    NULL, NULL, &dataSize, NULL, NULL);
     264    if (rc!=ERROR_SUCCESS) goto done;
     265    if (skipcore) dataSize = 0; /* Only count core ones if we want them! */
     266    /* Allocate a temp array of char buffers, so we only need to loop
     267       reading the registry once
     268    */
     269    ppPaths = malloc( sizeof(TCHAR *) * numKeys );
     270    if (ppPaths==NULL) goto done;
     271    memset(ppPaths, 0, sizeof(TCHAR *) * numKeys);
     272    /* Loop over all subkeys, allocating a temp sub-buffer. */
     273    for(index=0;index<numKeys;index++) {
     274        TCHAR keyBuf[MAX_PATH+1];
     275        HKEY subKey = 0;
     276        DWORD reqdSize = MAX_PATH+1;
     277        /* Get the sub-key name */
     278        DWORD rc = RegEnumKeyEx(newKey, index, keyBuf, &reqdSize,
     279                                NULL, NULL, NULL, NULL );
     280        if (rc!=ERROR_SUCCESS) goto done;
     281        /* Open the sub-key */
     282        rc=RegOpenKeyEx(newKey,
     283                                        keyBuf, /* subkey */
     284                        0, /* reserved */
     285                        KEY_READ,
     286                        &subKey);
     287        if (rc!=ERROR_SUCCESS) goto done;
     288        /* Find the value of the buffer size, malloc, then read it */
     289        RegQueryValueEx(subKey, NULL, 0, NULL, NULL, &reqdSize);
     290        if (reqdSize) {
     291            ppPaths[index] = malloc(reqdSize);
     292            if (ppPaths[index]) {
     293                RegQueryValueEx(subKey, NULL, 0, NULL,
     294                                (LPBYTE)ppPaths[index],
     295                                &reqdSize);
     296                dataSize += reqdSize + 1; /* 1 for the ";" */
     297            }
     298        }
     299        RegCloseKey(subKey);
     300    }
     301
     302    /* return null if no path to return */
     303    if (dataSize == 0) goto done;
     304
     305    /* original datasize from RegQueryInfo doesn't include the \0 */
     306    dataBuf = malloc((dataSize+1) * sizeof(TCHAR));
     307    if (dataBuf) {
     308        TCHAR *szCur = dataBuf;
     309        DWORD reqdSize = dataSize;
     310        /* Copy our collected strings */
     311        for (index=0;index<numKeys;index++) {
     312            if (index > 0) {
     313                *(szCur++) = _T(';');
     314                dataSize--;
     315            }
     316            if (ppPaths[index]) {
     317                Py_ssize_t len = _tcslen(ppPaths[index]);
     318                _tcsncpy(szCur, ppPaths[index], len);
     319                szCur += len;
     320                assert(dataSize > (DWORD)len);
     321                dataSize -= (DWORD)len;
     322            }
     323        }
     324        if (skipcore)
     325            *szCur = '\0';
     326        else {
     327            /* If we have no values, we dont need a ';' */
     328            if (numKeys) {
     329                *(szCur++) = _T(';');
     330                dataSize--;
     331            }
     332            /* Now append the core path entries -
     333               this will include the NULL
     334            */
     335            rc = RegQueryValueEx(newKey, NULL, 0, NULL,
     336                                 (LPBYTE)szCur, &dataSize);
     337        }
     338        /* And set the result - caller must free
     339           If MBCS, it is fine as is.  If Unicode, allocate new
     340           buffer and convert.
     341        */
    342342#ifdef UNICODE
    343                 retval = (char *)malloc(reqdSize+1);
    344                 if (retval)
    345                         WideCharToMultiByte(CP_ACP, 0,
    346                                         dataBuf, -1, /* source */
    347                                         retval, reqdSize+1, /* dest */
    348                                         NULL, NULL);
    349                 free(dataBuf);
     343        retval = (char *)malloc(reqdSize+1);
     344        if (retval)
     345            WideCharToMultiByte(CP_ACP, 0,
     346                            dataBuf, -1, /* source */
     347                    retval, reqdSize+1, /* dest */
     348                    NULL, NULL);
     349        free(dataBuf);
    350350#else
    351                 retval = dataBuf;
    352 #endif
    353         }
     351        retval = dataBuf;
     352#endif
     353    }
    354354done:
    355         /* Loop freeing my temp buffers */
    356         if (ppPaths) {
    357                 for(index=0;index<numKeys;index++)
    358                         if (ppPaths[index]) free(ppPaths[index]);
    359                 free(ppPaths);
    360         }
    361         if (newKey)
    362                 RegCloseKey(newKey);
    363         if (keyBuf)
    364                 free(keyBuf);
    365         return retval;
     355    /* Loop freeing my temp buffers */
     356    if (ppPaths) {
     357        for(index=0;index<numKeys;index++)
     358            if (ppPaths[index]) free(ppPaths[index]);
     359        free(ppPaths);
     360    }
     361    if (newKey)
     362        RegCloseKey(newKey);
     363    if (keyBuf)
     364        free(keyBuf);
     365    return retval;
    366366}
    367367#endif /* Py_ENABLE_SHARED */
     
    371371get_progpath(void)
    372372{
    373         extern char *Py_GetProgramName(void);
    374         char *path = getenv("PATH");
    375         char *prog = Py_GetProgramName();
     373    extern char *Py_GetProgramName(void);
     374    char *path = getenv("PATH");
     375    char *prog = Py_GetProgramName();
    376376
    377377#ifdef MS_WINDOWS
    378         extern HANDLE PyWin_DLLhModule;
     378    extern HANDLE PyWin_DLLhModule;
    379379#ifdef UNICODE
    380         WCHAR wprogpath[MAXPATHLEN+1];
    381         /* Windows documents that GetModuleFileName() will "truncate",
    382            but makes no mention of the null terminator.  Play it safe.
    383            PLUS Windows itself defines MAX_PATH as the same, but anyway...
    384         */
     380    WCHAR wprogpath[MAXPATHLEN+1];
     381    /* Windows documents that GetModuleFileName() will "truncate",
     382       but makes no mention of the null terminator.  Play it safe.
     383       PLUS Windows itself defines MAX_PATH as the same, but anyway...
     384    */
    385385#ifdef Py_ENABLE_SHARED
    386         wprogpath[MAXPATHLEN]=_T('\0');
    387         if (PyWin_DLLhModule &&
    388             GetModuleFileName(PyWin_DLLhModule, wprogpath, MAXPATHLEN)) {
    389                 WideCharToMultiByte(CP_ACP, 0,
    390                                     wprogpath, -1,
    391                                     dllpath, MAXPATHLEN+1,
    392                                     NULL, NULL);
    393         }
     386    wprogpath[MAXPATHLEN]=_T('\0');
     387    if (PyWin_DLLhModule &&
     388        GetModuleFileName(PyWin_DLLhModule, wprogpath, MAXPATHLEN)) {
     389        WideCharToMultiByte(CP_ACP, 0,
     390                            wprogpath, -1,
     391                            dllpath, MAXPATHLEN+1,
     392                            NULL, NULL);
     393    }
    394394#else
    395         dllpath[0] = 0;
    396 #endif
    397         wprogpath[MAXPATHLEN]=_T('\0');
    398         if (GetModuleFileName(NULL, wprogpath, MAXPATHLEN)) {
    399                 WideCharToMultiByte(CP_ACP, 0,
    400                                     wprogpath, -1,
    401                                     progpath, MAXPATHLEN+1,
    402                                     NULL, NULL);
    403                 return;
    404         }
     395    dllpath[0] = 0;
     396#endif
     397    wprogpath[MAXPATHLEN]=_T('\0');
     398    if (GetModuleFileName(NULL, wprogpath, MAXPATHLEN)) {
     399        WideCharToMultiByte(CP_ACP, 0,
     400                            wprogpath, -1,
     401                            progpath, MAXPATHLEN+1,
     402                            NULL, NULL);
     403        return;
     404    }
    405405#else
    406         /* static init of progpath ensures final char remains \0 */
     406    /* static init of progpath ensures final char remains \0 */
    407407#ifdef Py_ENABLE_SHARED
    408         if (PyWin_DLLhModule)
    409                 if (!GetModuleFileName(PyWin_DLLhModule, dllpath, MAXPATHLEN))
    410                         dllpath[0] = 0;
     408    if (PyWin_DLLhModule)
     409        if (!GetModuleFileName(PyWin_DLLhModule, dllpath, MAXPATHLEN))
     410            dllpath[0] = 0;
    411411#else
    412         dllpath[0] = 0;
    413 #endif
    414         if (GetModuleFileName(NULL, progpath, MAXPATHLEN))
    415                 return;
    416 #endif
    417 #endif
    418         if (prog == NULL || *prog == '\0')
    419                 prog = "python";
    420 
    421         /* If there is no slash in the argv0 path, then we have to
    422         * assume python is on the user's $PATH, since there's no
    423         * other way to find a directory to start the search from.  If
    424         * $PATH isn't exported, you lose.
    425         */
     412    dllpath[0] = 0;
     413#endif
     414    if (GetModuleFileName(NULL, progpath, MAXPATHLEN))
     415        return;
     416#endif
     417#endif
     418    if (prog == NULL || *prog == '\0')
     419        prog = "python";
     420
     421    /* If there is no slash in the argv0 path, then we have to
     422    * assume python is on the user's $PATH, since there's no
     423    * other way to find a directory to start the search from.  If
     424    * $PATH isn't exported, you lose.
     425    */
    426426#ifdef ALTSEP
    427         if (strchr(prog, SEP) || strchr(prog, ALTSEP))
     427    if (strchr(prog, SEP) || strchr(prog, ALTSEP))
    428428#else
    429         if (strchr(prog, SEP))
    430 #endif
    431                 strncpy(progpath, prog, MAXPATHLEN);
    432         else if (path) {
    433                 while (1) {
    434                         char *delim = strchr(path, DELIM);
    435 
    436                         if (delim) {
    437                                 size_t len = delim - path;
    438                                 /* ensure we can't overwrite buffer */
    439                                 len = min(MAXPATHLEN,len);
    440                                 strncpy(progpath, path, len);
    441                                 *(progpath + len) = '\0';
    442                         }
    443                         else
    444                                 strncpy(progpath, path, MAXPATHLEN);
    445 
    446                         /* join() is safe for MAXPATHLEN+1 size buffer */
    447                         join(progpath, prog);
    448                         if (exists(progpath))
    449                                 break;
    450 
    451                         if (!delim) {
    452                                 progpath[0] = '\0';
    453                                 break;
    454                         }
    455                         path = delim + 1;
    456                 }
    457         }
    458         else
    459                 progpath[0] = '\0';
     429    if (strchr(prog, SEP))
     430#endif
     431        strncpy(progpath, prog, MAXPATHLEN);
     432    else if (path) {
     433        while (1) {
     434            char *delim = strchr(path, DELIM);
     435
     436            if (delim) {
     437                size_t len = delim - path;
     438                /* ensure we can't overwrite buffer */
     439                len = min(MAXPATHLEN,len);
     440                strncpy(progpath, path, len);
     441                *(progpath + len) = '\0';
     442            }
     443            else
     444                strncpy(progpath, path, MAXPATHLEN);
     445
     446            /* join() is safe for MAXPATHLEN+1 size buffer */
     447            join(progpath, prog);
     448            if (exists(progpath))
     449                break;
     450
     451            if (!delim) {
     452                progpath[0] = '\0';
     453                break;
     454            }
     455            path = delim + 1;
     456        }
     457    }
     458    else
     459        progpath[0] = '\0';
    460460}
    461461
     
    463463calculate_path(void)
    464464{
    465         char argv0_path[MAXPATHLEN+1];
    466         char *buf;
    467         size_t bufsz;
    468         char *pythonhome = Py_GetPythonHome();
    469         char *envpath = Py_GETENV("PYTHONPATH");
     465    char argv0_path[MAXPATHLEN+1];
     466    char *buf;
     467    size_t bufsz;
     468    char *pythonhome = Py_GetPythonHome();
     469    char *envpath = Py_GETENV("PYTHONPATH");
    470470
    471471#ifdef MS_WINDOWS
    472         int skiphome, skipdefault;
    473         char *machinepath = NULL;
    474         char *userpath = NULL;
    475         char zip_path[MAXPATHLEN+1];
    476         size_t len;
    477 #endif
    478 
    479         get_progpath();
    480         /* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */
    481         strcpy(argv0_path, progpath);
    482         reduce(argv0_path);
    483         if (pythonhome == NULL || *pythonhome == '\0') {
    484                 if (search_for_prefix(argv0_path, LANDMARK))
    485                         pythonhome = prefix;
    486                 else
    487                         pythonhome = NULL;
    488         }
    489         else
    490                 strncpy(prefix, pythonhome, MAXPATHLEN);
    491 
    492         if (envpath && *envpath == '\0')
    493                 envpath = NULL;
     472    int skiphome, skipdefault;
     473    char *machinepath = NULL;
     474    char *userpath = NULL;
     475    char zip_path[MAXPATHLEN+1];
     476    size_t len;
     477#endif
     478
     479    get_progpath();
     480    /* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */
     481    strcpy(argv0_path, progpath);
     482    reduce(argv0_path);
     483    if (pythonhome == NULL || *pythonhome == '\0') {
     484        if (search_for_prefix(argv0_path, LANDMARK))
     485            pythonhome = prefix;
     486        else
     487            pythonhome = NULL;
     488    }
     489    else
     490        strncpy(prefix, pythonhome, MAXPATHLEN);
     491
     492    if (envpath && *envpath == '\0')
     493        envpath = NULL;
    494494
    495495
    496496#ifdef MS_WINDOWS
    497         /* Calculate zip archive path */
    498         if (dllpath[0])         /* use name of python DLL */
    499                 strncpy(zip_path, dllpath, MAXPATHLEN);
    500         else                    /* use name of executable program */
    501                 strncpy(zip_path, progpath, MAXPATHLEN);
    502         zip_path[MAXPATHLEN] = '\0';
    503         len = strlen(zip_path);
    504         if (len > 4) {
    505                 zip_path[len-3] = 'z';  /* change ending to "zip" */
    506                 zip_path[len-2] = 'i';
    507                 zip_path[len-1] = 'p';
    508         }
    509         else {
    510                 zip_path[0] = 0;
    511         }
    512  
    513         skiphome = pythonhome==NULL ? 0 : 1;
     497    /* Calculate zip archive path */
     498    if (dllpath[0])             /* use name of python DLL */
     499        strncpy(zip_path, dllpath, MAXPATHLEN);
     500    else                        /* use name of executable program */
     501        strncpy(zip_path, progpath, MAXPATHLEN);
     502    zip_path[MAXPATHLEN] = '\0';
     503    len = strlen(zip_path);
     504    if (len > 4) {
     505        zip_path[len-3] = 'z';          /* change ending to "zip" */
     506        zip_path[len-2] = 'i';
     507        zip_path[len-1] = 'p';
     508    }
     509    else {
     510        zip_path[0] = 0;
     511    }
     512
     513    skiphome = pythonhome==NULL ? 0 : 1;
    514514#ifdef Py_ENABLE_SHARED
    515         machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, skiphome);
    516         userpath = getpythonregpath(HKEY_CURRENT_USER, skiphome);
    517 #endif
    518         /* We only use the default relative PYTHONPATH if we havent
    519            anything better to use! */
    520         skipdefault = envpath!=NULL || pythonhome!=NULL || \
    521                       machinepath!=NULL || userpath!=NULL;
    522 #endif
    523 
    524         /* We need to construct a path from the following parts.
    525            (1) the PYTHONPATH environment variable, if set;
    526            (2) for Win32, the zip archive file path;
    527            (3) for Win32, the machinepath and userpath, if set;
    528            (4) the PYTHONPATH config macro, with the leading "."
    529                of each component replaced with pythonhome, if set;
    530            (5) the directory containing the executable (argv0_path).
    531            The length calculation calculates #4 first.
    532            Extra rules:
    533            - If PYTHONHOME is set (in any way) item (3) is ignored.
    534            - If registry values are used, (4) and (5) are ignored.
    535         */
    536 
    537         /* Calculate size of return buffer */
    538         if (pythonhome != NULL) {
    539                 char *p;
    540                 bufsz = 1;     
    541                 for (p = PYTHONPATH; *p; p++) {
    542                         if (*p == DELIM)
    543                                 bufsz++; /* number of DELIM plus one */
    544                 }
    545                 bufsz *= strlen(pythonhome);
    546         }
    547         else
    548                 bufsz = 0;
    549         bufsz += strlen(PYTHONPATH) + 1;
    550         bufsz += strlen(argv0_path) + 1;
     515    machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, skiphome);
     516    userpath = getpythonregpath(HKEY_CURRENT_USER, skiphome);
     517#endif
     518    /* We only use the default relative PYTHONPATH if we havent
     519       anything better to use! */
     520    skipdefault = envpath!=NULL || pythonhome!=NULL || \
     521                  machinepath!=NULL || userpath!=NULL;
     522#endif
     523
     524    /* We need to construct a path from the following parts.
     525       (1) the PYTHONPATH environment variable, if set;
     526       (2) for Win32, the zip archive file path;
     527       (3) for Win32, the machinepath and userpath, if set;
     528       (4) the PYTHONPATH config macro, with the leading "."
     529           of each component replaced with pythonhome, if set;
     530       (5) the directory containing the executable (argv0_path).
     531       The length calculation calculates #4 first.
     532       Extra rules:
     533       - If PYTHONHOME is set (in any way) item (3) is ignored.
     534       - If registry values are used, (4) and (5) are ignored.
     535    */
     536
     537    /* Calculate size of return buffer */
     538    if (pythonhome != NULL) {
     539        char *p;
     540        bufsz = 1;
     541        for (p = PYTHONPATH; *p; p++) {
     542            if (*p == DELIM)
     543                bufsz++; /* number of DELIM plus one */
     544        }
     545        bufsz *= strlen(pythonhome);
     546    }
     547    else
     548        bufsz = 0;
     549    bufsz += strlen(PYTHONPATH) + 1;
     550    bufsz += strlen(argv0_path) + 1;
    551551#ifdef MS_WINDOWS
    552         if (userpath)
    553                 bufsz += strlen(userpath) + 1;
    554         if (machinepath)
    555                 bufsz += strlen(machinepath) + 1;
    556         bufsz += strlen(zip_path) + 1;
    557 #endif
    558         if (envpath != NULL)
    559                 bufsz += strlen(envpath) + 1;
    560 
    561         module_search_path = buf = malloc(bufsz);
    562         if (buf == NULL) {
    563                 /* We can't exit, so print a warning and limp along */
    564                 fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
    565                 if (envpath) {
    566                         fprintf(stderr, "Using environment $PYTHONPATH.\n");
    567                         module_search_path = envpath;
    568                 }
    569                 else {
    570                         fprintf(stderr, "Using default static path.\n");
    571                         module_search_path = PYTHONPATH;
    572                 }
     552    if (userpath)
     553        bufsz += strlen(userpath) + 1;
     554    if (machinepath)
     555        bufsz += strlen(machinepath) + 1;
     556    bufsz += strlen(zip_path) + 1;
     557#endif
     558    if (envpath != NULL)
     559        bufsz += strlen(envpath) + 1;
     560
     561    module_search_path = buf = malloc(bufsz);
     562    if (buf == NULL) {
     563        /* We can't exit, so print a warning and limp along */
     564        fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
     565        if (envpath) {
     566            fprintf(stderr, "Using environment $PYTHONPATH.\n");
     567            module_search_path = envpath;
     568        }
     569        else {
     570            fprintf(stderr, "Using default static path.\n");
     571            module_search_path = PYTHONPATH;
     572        }
    573573#ifdef MS_WINDOWS
    574                 if (machinepath)
    575                         free(machinepath);
    576                 if (userpath)
    577                         free(userpath);
     574        if (machinepath)
     575            free(machinepath);
     576        if (userpath)
     577            free(userpath);
    578578#endif /* MS_WINDOWS */
    579                 return;
    580         }
    581 
    582         if (envpath) {
    583                 strcpy(buf, envpath);
    584                 buf = strchr(buf, '\0');
    585                 *buf++ = DELIM;
    586         }
     579        return;
     580    }
     581
     582    if (envpath) {
     583        strcpy(buf, envpath);
     584        buf = strchr(buf, '\0');
     585        *buf++ = DELIM;
     586    }
    587587#ifdef MS_WINDOWS
    588         if (zip_path[0]) {
    589                 strcpy(buf, zip_path);
    590                 buf = strchr(buf, '\0');
    591                 *buf++ = DELIM;
    592         }
    593         if (userpath) {
    594                 strcpy(buf, userpath);
    595                 buf = strchr(buf, '\0');
    596                 *buf++ = DELIM;
    597                 free(userpath);
    598         }
    599         if (machinepath) {
    600                 strcpy(buf, machinepath);
    601                 buf = strchr(buf, '\0');
    602                 *buf++ = DELIM;
    603                 free(machinepath);
    604         }
    605         if (pythonhome == NULL) {
    606                 if (!skipdefault) {
    607                         strcpy(buf, PYTHONPATH);
    608                         buf = strchr(buf, '\0');
    609                 }
    610         }
     588    if (zip_path[0]) {
     589        strcpy(buf, zip_path);
     590        buf = strchr(buf, '\0');
     591        *buf++ = DELIM;
     592    }
     593    if (userpath) {
     594        strcpy(buf, userpath);
     595        buf = strchr(buf, '\0');
     596        *buf++ = DELIM;
     597        free(userpath);
     598    }
     599    if (machinepath) {
     600        strcpy(buf, machinepath);
     601        buf = strchr(buf, '\0');
     602        *buf++ = DELIM;
     603        free(machinepath);
     604    }
     605    if (pythonhome == NULL) {
     606        if (!skipdefault) {
     607            strcpy(buf, PYTHONPATH);
     608            buf = strchr(buf, '\0');
     609        }
     610    }
    611611#else
    612         if (pythonhome == NULL) {
    613                 strcpy(buf, PYTHONPATH);
    614                 buf = strchr(buf, '\0');
    615         }
     612    if (pythonhome == NULL) {
     613        strcpy(buf, PYTHONPATH);
     614        buf = strchr(buf, '\0');
     615    }
    616616#endif /* MS_WINDOWS */
    617         else {
    618                 char *p = PYTHONPATH;
    619                 char *q;
    620                 size_t n;
    621                 for (;;) {
    622                         q = strchr(p, DELIM);
    623                         if (q == NULL)
    624                                 n = strlen(p);
    625                         else
    626                                 n = q-p;
    627                         if (p[0] == '.' && is_sep(p[1])) {
    628                                 strcpy(buf, pythonhome);
    629                                 buf = strchr(buf, '\0');
    630                                 p++;
    631                                 n--;
    632                         }
    633                         strncpy(buf, p, n);
    634                         buf += n;
    635                         if (q == NULL)
    636                                 break;
    637                         *buf++ = DELIM;
    638                         p = q+1;
    639                 }
    640         }
    641         if (argv0_path) {
    642                 *buf++ = DELIM;
    643                 strcpy(buf, argv0_path);
    644                 buf = strchr(buf, '\0');
    645         }
    646         *buf = '\0';
    647         /* Now to pull one last hack/trick.  If sys.prefix is
    648            empty, then try and find it somewhere on the paths
    649            we calculated.  We scan backwards, as our general policy
    650            is that Python core directories are at the *end* of
    651            sys.path.  We assume that our "lib" directory is
    652            on the path, and that our 'prefix' directory is
    653            the parent of that.
    654         */
    655         if (*prefix=='\0') {
    656                 char lookBuf[MAXPATHLEN+1];
    657                 char *look = buf - 1; /* 'buf' is at the end of the buffer */
    658                 while (1) {
    659                         Py_ssize_t nchars;
    660                         char *lookEnd = look;
    661                         /* 'look' will end up one character before the
    662                            start of the path in question - even if this
    663                            is one character before the start of the buffer
    664                         */
    665                         while (look >= module_search_path && *look != DELIM)
    666                                 look--;
    667                         nchars = lookEnd-look;
    668                         strncpy(lookBuf, look+1, nchars);
    669                         lookBuf[nchars] = '\0';
    670                         /* Up one level to the parent */
    671                         reduce(lookBuf);
    672                         if (search_for_prefix(lookBuf, LANDMARK)) {
    673                                 break;
    674                         }
    675                         /* If we are out of paths to search - give up */
    676                         if (look < module_search_path)
    677                                 break;
    678                         look--;
    679                 }
    680         }
     617    else {
     618        char *p = PYTHONPATH;
     619        char *q;
     620        size_t n;
     621        for (;;) {
     622            q = strchr(p, DELIM);
     623            if (q == NULL)
     624                n = strlen(p);
     625            else
     626                n = q-p;
     627            if (p[0] == '.' && is_sep(p[1])) {
     628                strcpy(buf, pythonhome);
     629                buf = strchr(buf, '\0');
     630                p++;
     631                n--;
     632            }
     633            strncpy(buf, p, n);
     634            buf += n;
     635            if (q == NULL)
     636                break;
     637            *buf++ = DELIM;
     638            p = q+1;
     639        }
     640    }
     641    if (argv0_path) {
     642        *buf++ = DELIM;
     643        strcpy(buf, argv0_path);
     644        buf = strchr(buf, '\0');
     645    }
     646    *buf = '\0';
     647    /* Now to pull one last hack/trick.  If sys.prefix is
     648       empty, then try and find it somewhere on the paths
     649       we calculated.  We scan backwards, as our general policy
     650       is that Python core directories are at the *end* of
     651       sys.path.  We assume that our "lib" directory is
     652       on the path, and that our 'prefix' directory is
     653       the parent of that.
     654    */
     655    if (*prefix=='\0') {
     656        char lookBuf[MAXPATHLEN+1];
     657        char *look = buf - 1; /* 'buf' is at the end of the buffer */
     658        while (1) {
     659            Py_ssize_t nchars;
     660            char *lookEnd = look;
     661            /* 'look' will end up one character before the
     662               start of the path in question - even if this
     663               is one character before the start of the buffer
     664            */
     665            while (look >= module_search_path && *look != DELIM)
     666                look--;
     667            nchars = lookEnd-look;
     668            strncpy(lookBuf, look+1, nchars);
     669            lookBuf[nchars] = '\0';
     670            /* Up one level to the parent */
     671            reduce(lookBuf);
     672            if (search_for_prefix(lookBuf, LANDMARK)) {
     673                break;
     674            }
     675            /* If we are out of paths to search - give up */
     676            if (look < module_search_path)
     677                break;
     678            look--;
     679        }
     680    }
    681681}
    682682
     
    687687Py_GetPath(void)
    688688{
    689         if (!module_search_path)
    690                 calculate_path();
    691         return module_search_path;
     689    if (!module_search_path)
     690        calculate_path();
     691    return module_search_path;
    692692}
    693693
     
    695695Py_GetPrefix(void)
    696696{
    697         if (!module_search_path)
    698                 calculate_path();
    699         return prefix;
     697    if (!module_search_path)
     698        calculate_path();
     699    return prefix;
    700700}
    701701
     
    703703Py_GetExecPrefix(void)
    704704{
    705         return Py_GetPrefix();
     705    return Py_GetPrefix();
    706706}
    707707
     
    709709Py_GetProgramFullPath(void)
    710710{
    711         if (!module_search_path)
    712                 calculate_path();
    713         return progpath;
    714 }
     711    if (!module_search_path)
     712        calculate_path();
     713    return progpath;
     714}
  • python/vendor/current/PC/import_nt.c

    r2 r388  
    11/********************************************************************
    22
    3  import_nt.c 
     3 import_nt.c
    44
    55  Win32 specific import code.
     
    1717
    1818FILE *PyWin_FindRegisteredModule(const char *moduleName,
    19                                 struct filedescr **ppFileDesc,
    20                                 char *pathBuf,
    21                                 Py_ssize_t pathLen)
     19                                struct filedescr **ppFileDesc,
     20                                char *pathBuf,
     21                                Py_ssize_t pathLen)
    2222{
    23         char *moduleKey;
    24         const char keyPrefix[] = "Software\\Python\\PythonCore\\";
    25         const char keySuffix[] = "\\Modules\\";
     23    char *moduleKey;
     24    const char keyPrefix[] = "Software\\Python\\PythonCore\\";
     25    const char keySuffix[] = "\\Modules\\";
    2626#ifdef _DEBUG
    27         /* In debugging builds, we _must_ have the debug version
    28         * registered.
    29         */
    30         const char debugString[] = "\\Debug";
     27    /* In debugging builds, we _must_ have the debug version
     28    * registered.
     29    */
     30    const char debugString[] = "\\Debug";
    3131#else
    32         const char debugString[] = "";
     32    const char debugString[] = "";
    3333#endif
    34         struct filedescr *fdp = NULL;
    35         FILE *fp;
    36         HKEY keyBase = HKEY_CURRENT_USER;
    37         int modNameSize;
    38         long regStat;
     34    struct filedescr *fdp = NULL;
     35    FILE *fp;
     36    HKEY keyBase = HKEY_CURRENT_USER;
     37    int modNameSize;
     38    long regStat;
    3939
    40         /* Calculate the size for the sprintf buffer.
    41         * Get the size of the chars only, plus 1 NULL.
    42         */
    43         size_t bufSize = sizeof(keyPrefix)-1 +
    44                          strlen(PyWin_DLLVersionString) +
    45                          sizeof(keySuffix) +
    46                          strlen(moduleName) +
    47                          sizeof(debugString) - 1;
    48         /* alloca == no free required, but memory only local to fn,
    49         * also no heap fragmentation!
    50         */
    51         moduleKey = alloca(bufSize);
    52         PyOS_snprintf(moduleKey, bufSize,
    53                       "Software\\Python\\PythonCore\\%s\\Modules\\%s%s",
    54                       PyWin_DLLVersionString, moduleName, debugString);
     40    /* Calculate the size for the sprintf buffer.
     41    * Get the size of the chars only, plus 1 NULL.
     42    */
     43    size_t bufSize = sizeof(keyPrefix)-1 +
     44                     strlen(PyWin_DLLVersionString) +
     45                     sizeof(keySuffix) +
     46                     strlen(moduleName) +
     47                     sizeof(debugString) - 1;
     48    /* alloca == no free required, but memory only local to fn,
     49    * also no heap fragmentation!
     50    */
     51    moduleKey = alloca(bufSize);
     52    PyOS_snprintf(moduleKey, bufSize,
     53                  "Software\\Python\\PythonCore\\%s\\Modules\\%s%s",
     54                  PyWin_DLLVersionString, moduleName, debugString);
    5555
    56         assert(pathLen < INT_MAX);
    57         modNameSize = (int)pathLen;
    58         regStat = RegQueryValue(keyBase, moduleKey, pathBuf, &modNameSize);
    59         if (regStat != ERROR_SUCCESS) {
    60                 /* No user setting - lookup in machine settings */
    61                 keyBase = HKEY_LOCAL_MACHINE;
    62                 /* be anal - failure may have reset size param */
    63                 modNameSize = (int)pathLen;
    64                 regStat = RegQueryValue(keyBase, moduleKey,
    65                                         pathBuf, &modNameSize);
     56    assert(pathLen < INT_MAX);
     57    modNameSize = (int)pathLen;
     58    regStat = RegQueryValue(keyBase, moduleKey, pathBuf, &modNameSize);
     59    if (regStat != ERROR_SUCCESS) {
     60        /* No user setting - lookup in machine settings */
     61        keyBase = HKEY_LOCAL_MACHINE;
     62        /* be anal - failure may have reset size param */
     63        modNameSize = (int)pathLen;
     64        regStat = RegQueryValue(keyBase, moduleKey,
     65                                pathBuf, &modNameSize);
    6666
    67                 if (regStat != ERROR_SUCCESS)
    68                         return NULL;
    69         }
    70         /* use the file extension to locate the type entry. */
    71         for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
    72                 size_t extLen = strlen(fdp->suffix);
    73                 assert(modNameSize >= 0); /* else cast to size_t is wrong */
    74                 if ((size_t)modNameSize > extLen &&
    75                     strnicmp(pathBuf + ((size_t)modNameSize-extLen-1),
    76                              fdp->suffix,
    77                              extLen) == 0)
    78                         break;
    79         }
    80         if (fdp->suffix == NULL)
    81                 return NULL;
    82         fp = fopen(pathBuf, fdp->mode);
    83         if (fp != NULL)
    84                 *ppFileDesc = fdp;
    85         return fp;
     67        if (regStat != ERROR_SUCCESS)
     68            return NULL;
     69    }
     70    /* use the file extension to locate the type entry. */
     71    for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
     72        size_t extLen = strlen(fdp->suffix);
     73        assert(modNameSize >= 0); /* else cast to size_t is wrong */
     74        if ((size_t)modNameSize > extLen &&
     75            strnicmp(pathBuf + ((size_t)modNameSize-extLen-1),
     76                     fdp->suffix,
     77                     extLen) == 0)
     78            break;
     79    }
     80    if (fdp->suffix == NULL)
     81        return NULL;
     82    fp = fopen(pathBuf, fdp->mode);
     83    if (fp != NULL)
     84        *ppFileDesc = fdp;
     85    return fp;
    8686}
  • python/vendor/current/PC/make_versioninfo.c

    r2 r388  
    2323int main(int argc, char **argv)
    2424{
    25         printf("/* This file created by make_versioninfo.exe */\n");
    26         printf("#define FIELD3 %d\n",
    27                 PY_MICRO_VERSION*1000 + PY_RELEASE_LEVEL*10 + PY_RELEASE_SERIAL);
    28         printf("#define MS_DLL_ID \"%d.%d\"\n",
    29                PY_MAJOR_VERSION, PY_MINOR_VERSION);
    30         printf("#ifndef _DEBUG\n");
    31         printf("#define PYTHON_DLL_NAME \"python%d%d.dll\"\n",
    32                PY_MAJOR_VERSION, PY_MINOR_VERSION);
    33         printf("#else\n");
    34         printf("#define PYTHON_DLL_NAME \"python%d%d_d.dll\"\n",
    35                PY_MAJOR_VERSION, PY_MINOR_VERSION);
    36         printf("#endif\n");
    37         return 0;
     25    printf("/* This file created by make_versioninfo.exe */\n");
     26    printf("#define FIELD3 %d\n",
     27        PY_MICRO_VERSION*1000 + PY_RELEASE_LEVEL*10 + PY_RELEASE_SERIAL);
     28    printf("#define MS_DLL_ID \"%d.%d\"\n",
     29           PY_MAJOR_VERSION, PY_MINOR_VERSION);
     30    printf("#ifndef _DEBUG\n");
     31    printf("#define PYTHON_DLL_NAME \"python%d%d.dll\"\n",
     32           PY_MAJOR_VERSION, PY_MINOR_VERSION);
     33    printf("#else\n");
     34    printf("#define PYTHON_DLL_NAME \"python%d%d_d.dll\"\n",
     35           PY_MAJOR_VERSION, PY_MINOR_VERSION);
     36    printf("#endif\n");
     37    return 0;
    3838}
  • python/vendor/current/PC/msvcrtmodule.c

    r2 r388  
    11/*********************************************************
    22
    3         msvcrtmodule.c
    4 
    5         A Python interface to the Microsoft Visual C Runtime
    6         Library, providing access to those non-portable, but
    7         still useful routines.
    8 
    9         Only ever compiled with an MS compiler, so no attempt
    10         has been made to avoid MS language extensions, etc...
    11 
    12         This may only work on NT or 95...
    13 
    14         Author: Mark Hammond and Guido van Rossum.
    15         Maintenance: Guido van Rossum.
     3    msvcrtmodule.c
     4
     5    A Python interface to the Microsoft Visual C Runtime
     6    Library, providing access to those non-portable, but
     7    still useful routines.
     8
     9    Only ever compiled with an MS compiler, so no attempt
     10    has been made to avoid MS language extensions, etc...
     11
     12    This may only work on NT or 95...
     13
     14    Author: Mark Hammond and Guido van Rossum.
     15    Maintenance: Guido van Rossum.
    1616
    1717***********************************************************/
     
    3434msvcrt_heapmin(PyObject *self, PyObject *args)
    3535{
    36         if (!PyArg_ParseTuple(args, ":heapmin"))
    37                 return NULL;
    38 
    39         if (_heapmin() != 0)
    40                 return PyErr_SetFromErrno(PyExc_IOError);
    41 
    42         Py_INCREF(Py_None);
    43         return Py_None;
    44 }
     36    if (!PyArg_ParseTuple(args, ":heapmin"))
     37        return NULL;
     38
     39    if (_heapmin() != 0)
     40        return PyErr_SetFromErrno(PyExc_IOError);
     41
     42    Py_INCREF(Py_None);
     43    return Py_None;
     44}
     45
     46PyDoc_STRVAR(heapmin_doc,
     47"heapmin() -> None\n\
     48\n\
     49Force the malloc() heap to clean itself up and return unused blocks\n\
     50to the operating system. On failure, this raises IOError.");
    4551
    4652// Perform locking operations on a C runtime file descriptor.
     
    4854msvcrt_locking(PyObject *self, PyObject *args)
    4955{
    50         int fd;
    51         int mode;
    52         long nbytes;
    53         int err;
    54 
    55         if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes))
    56                 return NULL;
    57 
    58         Py_BEGIN_ALLOW_THREADS
    59         err = _locking(fd, mode, nbytes);
    60         Py_END_ALLOW_THREADS
    61         if (err != 0)
    62                 return PyErr_SetFromErrno(PyExc_IOError);
    63 
    64         Py_INCREF(Py_None);
    65         return Py_None;
    66 }
     56    int fd;
     57    int mode;
     58    long nbytes;
     59    int err;
     60
     61    if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes))
     62        return NULL;
     63
     64    Py_BEGIN_ALLOW_THREADS
     65    err = _locking(fd, mode, nbytes);
     66    Py_END_ALLOW_THREADS
     67    if (err != 0)
     68        return PyErr_SetFromErrno(PyExc_IOError);
     69
     70    Py_INCREF(Py_None);
     71    return Py_None;
     72}
     73
     74PyDoc_STRVAR(locking_doc,
     75"locking(fd, mode, nbytes) -> None\n\
     76\n\
     77Lock part of a file based on file descriptor fd from the C runtime.\n\
     78Raises IOError on failure. The locked region of the file extends from\n\
     79the current file position for nbytes bytes, and may continue beyond\n\
     80the end of the file. mode must be one of the LK_* constants listed\n\
     81below. Multiple regions in a file may be locked at the same time, but\n\
     82may not overlap. Adjacent regions are not merged; they must be unlocked\n\
     83individually.");
    6784
    6885// Set the file translation mode for a C runtime file descriptor.
     
    7087msvcrt_setmode(PyObject *self, PyObject *args)
    7188{
    72         int fd;
    73         int flags;
    74         if (!PyArg_ParseTuple(args,"ii:setmode", &fd, &flags))
    75                 return NULL;
    76 
    77         flags = _setmode(fd, flags);
    78         if (flags == -1)
    79                 return PyErr_SetFromErrno(PyExc_IOError);
    80 
    81         return PyInt_FromLong(flags);
    82 }
     89    int fd;
     90    int flags;
     91    if (!PyArg_ParseTuple(args,"ii:setmode", &fd, &flags))
     92        return NULL;
     93
     94    flags = _setmode(fd, flags);
     95    if (flags == -1)
     96        return PyErr_SetFromErrno(PyExc_IOError);
     97
     98    return PyInt_FromLong(flags);
     99}
     100
     101PyDoc_STRVAR(setmode_doc,
     102"setmode(fd, mode) -> Previous mode\n\
     103\n\
     104Set the line-end translation mode for the file descriptor fd. To set\n\
     105it to text mode, flags should be os.O_TEXT; for binary, it should be\n\
     106os.O_BINARY.");
    83107
    84108// Convert an OS file handle to a C runtime file descriptor.
     
    86110msvcrt_open_osfhandle(PyObject *self, PyObject *args)
    87111{
    88         long handle;
    89         int flags;
    90         int fd;
    91 
    92         if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags))
    93                 return NULL;
    94 
    95         fd = _open_osfhandle(handle, flags);
    96         if (fd == -1)
    97                 return PyErr_SetFromErrno(PyExc_IOError);
    98 
    99         return PyInt_FromLong(fd);
    100 }
     112    long handle;
     113    int flags;
     114    int fd;
     115
     116    if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags))
     117        return NULL;
     118
     119    fd = _open_osfhandle(handle, flags);
     120    if (fd == -1)
     121        return PyErr_SetFromErrno(PyExc_IOError);
     122
     123    return PyInt_FromLong(fd);
     124}
     125
     126PyDoc_STRVAR(open_osfhandle_doc,
     127"open_osfhandle(handle, flags) -> file descriptor\n\
     128\n\
     129Create a C runtime file descriptor from the file handle handle. The\n\
     130flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n\
     131and os.O_TEXT. The returned file descriptor may be used as a parameter\n\
     132to os.fdopen() to create a file object.");
    101133
    102134// Convert a C runtime file descriptor to an OS file handle.
     
    104136msvcrt_get_osfhandle(PyObject *self, PyObject *args)
    105137{
    106         int fd;
    107         Py_intptr_t handle;
    108 
    109         if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
    110                 return NULL;
    111 
    112         handle = _get_osfhandle(fd);
    113         if (handle == -1)
    114                 return PyErr_SetFromErrno(PyExc_IOError);
    115 
    116         /* technically 'handle' is not a pointer, but a integer as
    117            large as a pointer, Python's *VoidPtr interface is the
    118            most appropriate here */
    119         return PyLong_FromVoidPtr((void*)handle);
    120 }
     138    int fd;
     139    Py_intptr_t handle;
     140
     141    if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
     142        return NULL;
     143
     144    if (!_PyVerify_fd(fd))
     145        return PyErr_SetFromErrno(PyExc_IOError);
     146
     147    handle = _get_osfhandle(fd);
     148    if (handle == -1)
     149        return PyErr_SetFromErrno(PyExc_IOError);
     150
     151    /* technically 'handle' is not a pointer, but a integer as
     152       large as a pointer, Python's *VoidPtr interface is the
     153       most appropriate here */
     154    return PyLong_FromVoidPtr((void*)handle);
     155}
     156
     157PyDoc_STRVAR(get_osfhandle_doc,
     158"get_osfhandle(fd) -> file handle\n\
     159\n\
     160Return the file handle for the file descriptor fd. Raises IOError\n\
     161if fd is not recognized.");
    121162
    122163/* Console I/O */
     
    125166msvcrt_kbhit(PyObject *self, PyObject *args)
    126167{
    127         int ok;
    128 
    129         if (!PyArg_ParseTuple(args, ":kbhit"))
    130                 return NULL;
    131 
    132         ok = _kbhit();
    133         return PyInt_FromLong(ok);
    134 }
     168    int ok;
     169
     170    if (!PyArg_ParseTuple(args, ":kbhit"))
     171        return NULL;
     172
     173    ok = _kbhit();
     174    return PyInt_FromLong(ok);
     175}
     176
     177PyDoc_STRVAR(kbhit_doc,
     178"kbhit() -> bool\n\
     179\n\
     180Return true if a keypress is waiting to be read.");
    135181
    136182static PyObject *
    137183msvcrt_getch(PyObject *self, PyObject *args)
    138184{
    139         int ch;
    140         char s[1];
    141 
    142         if (!PyArg_ParseTuple(args, ":getch"))
    143                 return NULL;
    144 
    145         Py_BEGIN_ALLOW_THREADS
    146         ch = _getch();
    147         Py_END_ALLOW_THREADS
    148         s[0] = ch;
    149         return PyString_FromStringAndSize(s, 1);
    150 }
     185    int ch;
     186    char s[1];
     187
     188    if (!PyArg_ParseTuple(args, ":getch"))
     189        return NULL;
     190
     191    Py_BEGIN_ALLOW_THREADS
     192    ch = _getch();
     193    Py_END_ALLOW_THREADS
     194    s[0] = ch;
     195    return PyString_FromStringAndSize(s, 1);
     196}
     197
     198PyDoc_STRVAR(getch_doc,
     199"getch() -> key character\n\
     200\n\
     201Read a keypress and return the resulting character. Nothing is echoed to\n\
     202the console. This call will block if a keypress is not already\n\
     203available, but will not wait for Enter to be pressed. If the pressed key\n\
     204was a special function key, this will return '\\000' or '\\xe0'; the next\n\
     205call will return the keycode. The Control-C keypress cannot be read with\n\
     206this function.");
    151207
    152208#ifdef _WCONIO_DEFINED
     
    154210msvcrt_getwch(PyObject *self, PyObject *args)
    155211{
    156         Py_UNICODE ch;
    157         Py_UNICODE u[1];
    158 
    159         if (!PyArg_ParseTuple(args, ":getwch"))
    160                 return NULL;
    161 
    162         Py_BEGIN_ALLOW_THREADS
    163         ch = _getwch();
    164         Py_END_ALLOW_THREADS
    165         u[0] = ch;
    166         return PyUnicode_FromUnicode(u, 1);
    167 }
     212    Py_UNICODE ch;
     213    Py_UNICODE u[1];
     214
     215    if (!PyArg_ParseTuple(args, ":getwch"))
     216        return NULL;
     217
     218    Py_BEGIN_ALLOW_THREADS
     219    ch = _getwch();
     220    Py_END_ALLOW_THREADS
     221    u[0] = ch;
     222    return PyUnicode_FromUnicode(u, 1);
     223}
     224
     225PyDoc_STRVAR(getwch_doc,
     226"getwch() -> Unicode key character\n\
     227\n\
     228Wide char variant of getch(), returning a Unicode value.");
    168229#endif
    169230
     
    171232msvcrt_getche(PyObject *self, PyObject *args)
    172233{
    173         int ch;
    174         char s[1];
    175 
    176         if (!PyArg_ParseTuple(args, ":getche"))
    177                 return NULL;
    178 
    179         Py_BEGIN_ALLOW_THREADS
    180         ch = _getche();
    181         Py_END_ALLOW_THREADS
    182         s[0] = ch;
    183         return PyString_FromStringAndSize(s, 1);
    184 }
     234    int ch;
     235    char s[1];
     236
     237    if (!PyArg_ParseTuple(args, ":getche"))
     238        return NULL;
     239
     240    Py_BEGIN_ALLOW_THREADS
     241    ch = _getche();
     242    Py_END_ALLOW_THREADS
     243    s[0] = ch;
     244    return PyString_FromStringAndSize(s, 1);
     245}
     246
     247PyDoc_STRVAR(getche_doc,
     248"getche() -> key character\n\
     249\n\
     250Similar to getch(), but the keypress will be echoed if it represents\n\
     251a printable character.");
    185252
    186253#ifdef _WCONIO_DEFINED
     
    188255msvcrt_getwche(PyObject *self, PyObject *args)
    189256{
    190         Py_UNICODE ch;
    191         Py_UNICODE s[1];
    192 
    193         if (!PyArg_ParseTuple(args, ":getwche"))
    194                 return NULL;
    195 
    196         Py_BEGIN_ALLOW_THREADS
    197         ch = _getwche();
    198         Py_END_ALLOW_THREADS
    199         s[0] = ch;
    200         return PyUnicode_FromUnicode(s, 1);
    201 }
     257    Py_UNICODE ch;
     258    Py_UNICODE s[1];
     259
     260    if (!PyArg_ParseTuple(args, ":getwche"))
     261        return NULL;
     262
     263    Py_BEGIN_ALLOW_THREADS
     264    ch = _getwche();
     265    Py_END_ALLOW_THREADS
     266    s[0] = ch;
     267    return PyUnicode_FromUnicode(s, 1);
     268}
     269
     270PyDoc_STRVAR(getwche_doc,
     271"getwche() -> Unicode key character\n\
     272\n\
     273Wide char variant of getche(), returning a Unicode value.");
    202274#endif
    203275
     
    205277msvcrt_putch(PyObject *self, PyObject *args)
    206278{
    207         char ch;
    208 
    209         if (!PyArg_ParseTuple(args, "c:putch", &ch))
    210                 return NULL;
    211 
    212         _putch(ch);
    213         Py_INCREF(Py_None);
    214         return Py_None;
    215 }
     279    char ch;
     280
     281    if (!PyArg_ParseTuple(args, "c:putch", &ch))
     282        return NULL;
     283
     284    _putch(ch);
     285    Py_INCREF(Py_None);
     286    return Py_None;
     287}
     288
     289PyDoc_STRVAR(putch_doc,
     290"putch(char) -> None\n\
     291\n\
     292Print the character char to the console without buffering.");
    216293
    217294#ifdef _WCONIO_DEFINED
     
    219296msvcrt_putwch(PyObject *self, PyObject *args)
    220297{
    221         Py_UNICODE *ch;
    222         int size;
    223 
    224         if (!PyArg_ParseTuple(args, "u#:putwch", &ch, &size))
    225                 return NULL;
    226 
    227         if (size == 0) {
    228                 PyErr_SetString(PyExc_ValueError,
    229                         "Expected unicode string of length 1");
    230                 return NULL;
    231         }
    232         _putwch(*ch);
    233         Py_RETURN_NONE;
    234 
    235 }
     298    Py_UNICODE *ch;
     299    int size;
     300
     301    if (!PyArg_ParseTuple(args, "u#:putwch", &ch, &size))
     302        return NULL;
     303
     304    if (size == 0) {
     305        PyErr_SetString(PyExc_ValueError,
     306            "Expected unicode string of length 1");
     307        return NULL;
     308    }
     309    _putwch(*ch);
     310    Py_RETURN_NONE;
     311
     312}
     313
     314PyDoc_STRVAR(putwch_doc,
     315"putwch(unicode_char) -> None\n\
     316\n\
     317Wide char variant of putch(), accepting a Unicode value.");
    236318#endif
    237319
     
    239321msvcrt_ungetch(PyObject *self, PyObject *args)
    240322{
    241         char ch;
    242 
    243         if (!PyArg_ParseTuple(args, "c:ungetch", &ch))
    244                 return NULL;
    245 
    246         if (_ungetch(ch) == EOF)
    247                 return PyErr_SetFromErrno(PyExc_IOError);
    248         Py_INCREF(Py_None);
    249         return Py_None;
    250 }
     323    char ch;
     324
     325    if (!PyArg_ParseTuple(args, "c:ungetch", &ch))
     326        return NULL;
     327
     328    if (_ungetch(ch) == EOF)
     329        return PyErr_SetFromErrno(PyExc_IOError);
     330    Py_INCREF(Py_None);
     331    return Py_None;
     332}
     333
     334PyDoc_STRVAR(ungetch_doc,
     335"ungetch(char) -> None\n\
     336\n\
     337Cause the character char to be \"pushed back\" into the console buffer;\n\
     338it will be the next character read by getch() or getche().");
    251339
    252340#ifdef _WCONIO_DEFINED
     
    254342msvcrt_ungetwch(PyObject *self, PyObject *args)
    255343{
    256         Py_UNICODE ch;
    257 
    258         if (!PyArg_ParseTuple(args, "u:ungetwch", &ch))
    259                 return NULL;
    260 
    261         if (_ungetch(ch) == EOF)
    262                 return PyErr_SetFromErrno(PyExc_IOError);
    263         Py_INCREF(Py_None);
    264         return Py_None;
    265 }
     344    Py_UNICODE ch;
     345
     346    if (!PyArg_ParseTuple(args, "u:ungetwch", &ch))
     347        return NULL;
     348
     349    if (_ungetch(ch) == EOF)
     350        return PyErr_SetFromErrno(PyExc_IOError);
     351    Py_INCREF(Py_None);
     352    return Py_None;
     353}
     354
     355PyDoc_STRVAR(ungetwch_doc,
     356"ungetwch(unicode_char) -> None\n\
     357\n\
     358Wide char variant of ungetch(), accepting a Unicode value.");
    266359#endif
    267360
     
    269362insertint(PyObject *d, char *name, int value)
    270363{
    271         PyObject *v = PyInt_FromLong((long) value);
    272         if (v == NULL) {
    273                 /* Don't bother reporting this error */
    274                 PyErr_Clear();
    275         }
    276         else {
    277                 PyDict_SetItemString(d, name, v);
    278                 Py_DECREF(v);
    279         }
     364    PyObject *v = PyInt_FromLong((long) value);
     365    if (v == NULL) {
     366        /* Don't bother reporting this error */
     367        PyErr_Clear();
     368    }
     369    else {
     370        PyDict_SetItemString(d, name, v);
     371        Py_DECREF(v);
     372    }
    280373}
    281374
     
    283376/* List of functions exported by this module */
    284377static struct PyMethodDef msvcrt_functions[] = {
    285         {"heapmin",             msvcrt_heapmin, METH_VARARGS},
    286         {"locking",             msvcrt_locking, METH_VARARGS},
    287         {"setmode",             msvcrt_setmode, METH_VARARGS},
    288         {"open_osfhandle",      msvcrt_open_osfhandle, METH_VARARGS},
    289         {"get_osfhandle",       msvcrt_get_osfhandle, METH_VARARGS},
    290         {"kbhit",               msvcrt_kbhit, METH_VARARGS},
    291         {"getch",               msvcrt_getch, METH_VARARGS},
    292         {"getche",              msvcrt_getche, METH_VARARGS},
    293         {"putch",               msvcrt_putch, METH_VARARGS},
    294         {"ungetch",             msvcrt_ungetch, METH_VARARGS},
     378    {"heapmin",                 msvcrt_heapmin, METH_VARARGS, heapmin_doc},
     379    {"locking",             msvcrt_locking, METH_VARARGS, locking_doc},
     380    {"setmode",                 msvcrt_setmode, METH_VARARGS, setmode_doc},
     381    {"open_osfhandle",          msvcrt_open_osfhandle, METH_VARARGS, open_osfhandle_doc},
     382    {"get_osfhandle",           msvcrt_get_osfhandle, METH_VARARGS, get_osfhandle_doc},
     383    {"kbhit",                   msvcrt_kbhit, METH_VARARGS, kbhit_doc},
     384    {"getch",                   msvcrt_getch, METH_VARARGS, getch_doc},
     385    {"getche",                  msvcrt_getche, METH_VARARGS, getche_doc},
     386    {"putch",                   msvcrt_putch, METH_VARARGS, putch_doc},
     387    {"ungetch",                 msvcrt_ungetch, METH_VARARGS, ungetch_doc},
    295388#ifdef _WCONIO_DEFINED
    296         {"getwch",              msvcrt_getwch, METH_VARARGS},
    297         {"getwche",             msvcrt_getwche, METH_VARARGS},
    298         {"putwch",              msvcrt_putwch, METH_VARARGS},
    299         {"ungetwch",            msvcrt_ungetwch, METH_VARARGS},
    300 #endif
    301         {NULL,                  NULL}
     389    {"getwch",                  msvcrt_getwch, METH_VARARGS, getwch_doc},
     390    {"getwche",                 msvcrt_getwche, METH_VARARGS, getwche_doc},
     391    {"putwch",                  msvcrt_putwch, METH_VARARGS, putwch_doc},
     392    {"ungetwch",                msvcrt_ungetwch, METH_VARARGS, ungetwch_doc},
     393#endif
     394    {NULL,                      NULL}
    302395};
    303396
     
    305398initmsvcrt(void)
    306399{
    307         int st;
    308         PyObject *d;
    309         PyObject *m = Py_InitModule("msvcrt", msvcrt_functions);
    310         if (m == NULL)
    311                 return;
    312         d = PyModule_GetDict(m);
    313 
    314         /* constants for the locking() function's mode argument */
    315         insertint(d, "LK_LOCK", _LK_LOCK);
    316         insertint(d, "LK_NBLCK", _LK_NBLCK);
    317         insertint(d, "LK_NBRLCK", _LK_NBRLCK);
    318         insertint(d, "LK_RLCK", _LK_RLCK);
    319         insertint(d, "LK_UNLCK", _LK_UNLCK);
    320 
    321         /* constants for the crt versions */
     400    int st;
     401    PyObject *d;
     402    PyObject *m = Py_InitModule("msvcrt", msvcrt_functions);
     403    if (m == NULL)
     404        return;
     405    d = PyModule_GetDict(m);
     406
     407    /* constants for the locking() function's mode argument */
     408    insertint(d, "LK_LOCK", _LK_LOCK);
     409    insertint(d, "LK_NBLCK", _LK_NBLCK);
     410    insertint(d, "LK_NBRLCK", _LK_NBRLCK);
     411    insertint(d, "LK_RLCK", _LK_RLCK);
     412    insertint(d, "LK_UNLCK", _LK_UNLCK);
     413
     414    /* constants for the crt versions */
    322415#ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN
    323         st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN",
    324                                         _VC_ASSEMBLY_PUBLICKEYTOKEN);
    325         if (st < 0)return;
     416    st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN",
     417                                    _VC_ASSEMBLY_PUBLICKEYTOKEN);
     418    if (st < 0)return;
    326419#endif
    327420#ifdef _CRT_ASSEMBLY_VERSION
    328         st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION",
    329                                         _CRT_ASSEMBLY_VERSION);
    330         if (st < 0)return;
     421    st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION",
     422                                    _CRT_ASSEMBLY_VERSION);
     423    if (st < 0)return;
    331424#endif
    332425#ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX
    333         st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX",
    334                                         __LIBRARIES_ASSEMBLY_NAME_PREFIX);
    335         if (st < 0)return;
    336 #endif
    337 }
     426    st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX",
     427                                    __LIBRARIES_ASSEMBLY_NAME_PREFIX);
     428    if (st < 0)return;
     429#endif
     430}
  • python/vendor/current/PC/os2emx/Makefile

    r2 r388  
    238238# Output file names
    239239PYTHON_VER=     2.6
    240 PYTHON_LIB=     python26
     240PYTHON_LIB=     python27
    241241PYTHON.LIB=     $(PYTHON_LIB)_s$A
    242242PYTHON.IMPLIB=  $(PYTHON_LIB)$A
     
    352352                Python/getcompiler.c \
    353353                Python/getcopyright.c \
    354                 Python/getmtime.c \
    355354                Python/getplatform.c \
    356355                Python/getversion.c \
     
    364363                Python/peephole.c \
    365364                Python/pyarena.c \
     365                Python/pyctype.c \
    366366                Python/pyfpe.c \
    367367                Python/pymath.c \
     
    385385                Objects/cellobject.c \
    386386                Objects/classobject.c \
     387                Objects/capsule.c \
    387388                Objects/cobject.c \
    388389                Objects/codeobject.c \
  • python/vendor/current/PC/os2emx/README.os2emx

    r2 r388  
    310310   the value of the Makefile variable EXE_DIR to the appropriate directory.
    311311
    312 3. If you wish the Python core DLL (python26.dll) to be installed in a
     3123. If you wish the Python core DLL (python27.dll) to be installed in a
    313313   directory other than the directory in which the Python executables are
    314314   installed (by default, the PYTHONHOME directory), set the value of the
  • python/vendor/current/PC/os2emx/config.c

    r2 r388  
    103103struct _inittab _PyImport_Inittab[] = {
    104104
    105         {"os2", initos2},
    106         {"signal", initsignal},
     105    {"os2", initos2},
     106    {"signal", initsignal},
    107107#ifdef WITH_THREAD
    108         {"thread", initthread},
     108    {"thread", initthread},
    109109#endif
    110         {"_codecs", init_codecs},
    111         {"_csv", init_csv},
    112         {"_locale", init_locale},
    113         {"_random", init_random},
    114         {"_sre", init_sre},
    115         {"_symtable", init_symtable},
    116         {"_weakref", init_weakref},
    117         {"array", initarray},
    118         {"binascii", initbinascii},
    119         {"cPickle", initcPickle},
    120         {"cStringIO", initcStringIO},
    121         {"_collections", init_collections},
    122         {"cmath", initcmath},
    123         {"datetime", initdatetime},
    124         {"dl", initdl},
    125         {"errno", initerrno},
    126         {"fcntl", initfcntl},
    127         {"_fileio", init_fileio},
    128         {"_functools", init_functools},
    129         {"_heapq", init_heapq},
    130         {"imageop", initimageop},
    131         {"itertools", inititertools},
    132         {"math", initmath},
    133         {"_md5", init_md5},
    134         {"operator", initoperator},
    135         {"_sha", init_sha},
    136         {"_sha256", init_sha256},
    137         {"_sha512", init_sha512},
    138         {"strop", initstrop},
    139         {"_struct", init_struct},
    140         {"termios", inittermios},
    141         {"time", inittime},
    142         {"timing", inittiming},
    143         {"xxsubtype", initxxsubtype},
    144         {"zipimport", initzipimport},
     110    {"_codecs", init_codecs},
     111    {"_csv", init_csv},
     112    {"_locale", init_locale},
     113    {"_random", init_random},
     114    {"_sre", init_sre},
     115    {"_symtable", init_symtable},
     116    {"_weakref", init_weakref},
     117    {"array", initarray},
     118    {"binascii", initbinascii},
     119    {"cPickle", initcPickle},
     120    {"cStringIO", initcStringIO},
     121    {"_collections", init_collections},
     122    {"cmath", initcmath},
     123    {"datetime", initdatetime},
     124    {"dl", initdl},
     125    {"errno", initerrno},
     126    {"fcntl", initfcntl},
     127    {"_fileio", init_fileio},
     128    {"_functools", init_functools},
     129    {"_heapq", init_heapq},
     130    {"imageop", initimageop},
     131    {"itertools", inititertools},
     132    {"math", initmath},
     133    {"_md5", init_md5},
     134    {"operator", initoperator},
     135    {"_sha", init_sha},
     136    {"_sha256", init_sha256},
     137    {"_sha512", init_sha512},
     138    {"strop", initstrop},
     139    {"_struct", init_struct},
     140    {"termios", inittermios},
     141    {"time", inittime},
     142    {"timing", inittiming},
     143    {"xxsubtype", initxxsubtype},
     144    {"zipimport", initzipimport},
    145145#if !HAVE_DYNAMIC_LOADING
    146         {"_curses", init_curses},
    147         {"_curses_panel", init_curses_panel},
    148         {"_hotshot", init_hotshot},
    149         {"_testcapi", init_testcapi},
    150         {"bsddb185", initbsddb185},
    151         {"bz2", initbz2},
    152         {"fpectl", initfpectl},
    153         {"fpetest", initfpetest},
    154         {"parser", initparser},
    155         {"pwd", initpwd},
    156         {"unicodedata", initunicodedata},
    157         {"zlib", initzlib},
     146    {"_curses", init_curses},
     147    {"_curses_panel", init_curses_panel},
     148    {"_hotshot", init_hotshot},
     149    {"_testcapi", init_testcapi},
     150    {"bsddb185", initbsddb185},
     151    {"bz2", initbz2},
     152    {"fpectl", initfpectl},
     153    {"fpetest", initfpetest},
     154    {"parser", initparser},
     155    {"pwd", initpwd},
     156    {"unicodedata", initunicodedata},
     157    {"zlib", initzlib},
    158158#ifdef USE_SOCKET
    159         {"_socket", init_socket},
    160         {"select", initselect},
     159    {"_socket", init_socket},
     160    {"select", initselect},
    161161#endif
    162162#endif
    163163/* -- ADDMODULE MARKER 2 -- */
    164164
    165         /* This module "lives in" with marshal.c */
    166         {"marshal", PyMarshal_Init},
     165    /* This module "lives in" with marshal.c */
     166    {"marshal", PyMarshal_Init},
    167167
    168         /* This lives it with import.c */
    169         {"imp", initimp},
     168    /* This lives it with import.c */
     169    {"imp", initimp},
    170170
    171         /* These entries are here for sys.builtin_module_names */
    172         {"__main__", NULL},
    173         {"__builtin__", NULL},
    174         {"sys", NULL},
    175         {"exceptions", NULL},
     171    /* These entries are here for sys.builtin_module_names */
     172    {"__main__", NULL},
     173    {"__builtin__", NULL},
     174    {"sys", NULL},
     175    {"exceptions", NULL},
    176176
    177         /* This lives in gcmodule.c */
    178         {"gc", initgc},
     177    /* This lives in gcmodule.c */
     178    {"gc", initgc},
    179179
    180         /* Sentinel */
    181         {0, 0}
     180    /* Sentinel */
     181    {0, 0}
    182182};
  • python/vendor/current/PC/os2emx/dlfcn.c

    r2 r388  
    4747
    4848typedef struct _track_rec {
    49         char *name;
    50         HMODULE handle;
    51         void *id;
    52         struct _track_rec *next;
     49    char *name;
     50    HMODULE handle;
     51    void *id;
     52    struct _track_rec *next;
    5353} tDLLchain, *DLLchain;
    5454
    55 static DLLchain dlload = NULL;  /* A simple chained list of DLL names */
    56 static char dlerr [256];        /* last error text string */
     55static DLLchain dlload = NULL;  /* A simple chained list of DLL names */
     56static char dlerr [256];        /* last error text string */
    5757static void *last_id;
    5858
    5959static DLLchain find_id(void *id)
    6060{
    61         DLLchain tmp;
    62 
    63         for (tmp = dlload; tmp; tmp = tmp->next)
    64                 if (id == tmp->id)
    65                         return tmp;
    66 
    67         return NULL;
     61    DLLchain tmp;
     62
     63    for (tmp = dlload; tmp; tmp = tmp->next)
     64        if (id == tmp->id)
     65            return tmp;
     66
     67    return NULL;
    6868}
    6969
     
    7171void *dlopen(char *filename, int flags)
    7272{
    73         HMODULE hm;
    74         DLLchain tmp;
    75         char err[256];
    76         char *errtxt;
    77         int rc = 0, set_chain = 0;
    78 
    79         for (tmp = dlload; tmp; tmp = tmp->next)
    80                 if (strnicmp(tmp->name, filename, 999) == 0)
    81                         break;
    82 
    83         if (!tmp)
    84         {
    85                 tmp = (DLLchain) malloc(sizeof(tDLLchain));
    86                 if (!tmp)
    87                         goto nomem;
    88                 tmp->name = strdup(filename);
    89                 tmp->next = dlload;
    90                 set_chain = 1;
    91         }
    92 
    93         switch (rc = DosLoadModule((PSZ)&err, sizeof(err), filename, &hm))
    94         {
    95                 case NO_ERROR:
    96                         tmp->handle = hm;
    97                         if (set_chain)
    98                         {
    99                                 do
    100                                         last_id++;
    101                                 while ((last_id == 0) || (find_id(last_id)));
    102                                 tmp->id = last_id;
    103                                 dlload = tmp;
    104                         }
    105                         return tmp->id;
    106                 case ERROR_FILE_NOT_FOUND:
    107                 case ERROR_PATH_NOT_FOUND:
    108                         errtxt = "module `%s' not found";
    109                         break;
    110                 case ERROR_TOO_MANY_OPEN_FILES:
    111                 case ERROR_NOT_ENOUGH_MEMORY:
    112                 case ERROR_SHARING_BUFFER_EXCEEDED:
     73    HMODULE hm;
     74    DLLchain tmp;
     75    char err[256];
     76    char *errtxt;
     77    int rc = 0, set_chain = 0;
     78
     79    for (tmp = dlload; tmp; tmp = tmp->next)
     80        if (strnicmp(tmp->name, filename, 999) == 0)
     81            break;
     82
     83    if (!tmp)
     84    {
     85        tmp = (DLLchain) malloc(sizeof(tDLLchain));
     86        if (!tmp)
     87            goto nomem;
     88        tmp->name = strdup(filename);
     89        tmp->next = dlload;
     90        set_chain = 1;
     91    }
     92
     93    switch (rc = DosLoadModule((PSZ)&err, sizeof(err), filename, &hm))
     94    {
     95        case NO_ERROR:
     96            tmp->handle = hm;
     97            if (set_chain)
     98            {
     99                do
     100                    last_id++;
     101                while ((last_id == 0) || (find_id(last_id)));
     102                tmp->id = last_id;
     103                dlload = tmp;
     104            }
     105            return tmp->id;
     106        case ERROR_FILE_NOT_FOUND:
     107        case ERROR_PATH_NOT_FOUND:
     108            errtxt = "module `%s' not found";
     109            break;
     110        case ERROR_TOO_MANY_OPEN_FILES:
     111        case ERROR_NOT_ENOUGH_MEMORY:
     112        case ERROR_SHARING_BUFFER_EXCEEDED:
    113113nomem:
    114                         errtxt = "out of system resources";
    115                         break;
    116                 case ERROR_ACCESS_DENIED:
    117                         errtxt = "access denied";
    118                         break;
    119                 case ERROR_BAD_FORMAT:
    120                 case ERROR_INVALID_SEGMENT_NUMBER:
    121                 case ERROR_INVALID_ORDINAL:
    122                 case ERROR_INVALID_MODULETYPE:
    123                 case ERROR_INVALID_EXE_SIGNATURE:
    124                 case ERROR_EXE_MARKED_INVALID:
    125                 case ERROR_ITERATED_DATA_EXCEEDS_64K:
    126                 case ERROR_INVALID_MINALLOCSIZE:
    127                 case ERROR_INVALID_SEGDPL:
    128                 case ERROR_AUTODATASEG_EXCEEDS_64K:
    129                 case ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT:
    130                         errtxt = "invalid module format";
    131                         break;
    132                 case ERROR_INVALID_NAME:
    133                         errtxt = "filename doesn't match module name";
    134                         break;
    135                 case ERROR_SHARING_VIOLATION:
    136                 case ERROR_LOCK_VIOLATION:
    137                         errtxt = "sharing violation";
    138                         break;
    139                 case ERROR_INIT_ROUTINE_FAILED:
    140                         errtxt = "module initialization failed";
    141                         break;
    142                 default:
    143                         errtxt = "cause `%s', error code = %d";
    144                         break;
    145         }
    146         snprintf(dlerr, sizeof(dlerr), errtxt, &err, rc);
    147         if (tmp)
    148         {
    149                 if (tmp->name)
    150                         free(tmp->name);
    151                 free(tmp);
    152         }
    153         return 0;
     114            errtxt = "out of system resources";
     115            break;
     116        case ERROR_ACCESS_DENIED:
     117            errtxt = "access denied";
     118            break;
     119        case ERROR_BAD_FORMAT:
     120        case ERROR_INVALID_SEGMENT_NUMBER:
     121        case ERROR_INVALID_ORDINAL:
     122        case ERROR_INVALID_MODULETYPE:
     123        case ERROR_INVALID_EXE_SIGNATURE:
     124        case ERROR_EXE_MARKED_INVALID:
     125        case ERROR_ITERATED_DATA_EXCEEDS_64K:
     126        case ERROR_INVALID_MINALLOCSIZE:
     127        case ERROR_INVALID_SEGDPL:
     128        case ERROR_AUTODATASEG_EXCEEDS_64K:
     129        case ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT:
     130            errtxt = "invalid module format";
     131            break;
     132        case ERROR_INVALID_NAME:
     133            errtxt = "filename doesn't match module name";
     134            break;
     135        case ERROR_SHARING_VIOLATION:
     136        case ERROR_LOCK_VIOLATION:
     137            errtxt = "sharing violation";
     138            break;
     139        case ERROR_INIT_ROUTINE_FAILED:
     140            errtxt = "module initialization failed";
     141            break;
     142        default:
     143            errtxt = "cause `%s', error code = %d";
     144            break;
     145    }
     146    snprintf(dlerr, sizeof(dlerr), errtxt, &err, rc);
     147    if (tmp)
     148    {
     149        if (tmp->name)
     150            free(tmp->name);
     151        free(tmp);
     152    }
     153    return 0;
    154154}
    155155
     
    157157void *dlsym(void *handle, char *symbol)
    158158{
    159         int rc = 0;
    160         PFN addr;
    161         char *errtxt;
    162         int symord = 0;
    163         DLLchain tmp = find_id(handle);
    164 
    165         if (!tmp)
    166                 goto inv_handle;
    167 
    168         if (*symbol == '#')
    169                 symord = atoi(symbol + 1);
    170 
    171         switch (rc = DosQueryProcAddr(tmp->handle, symord, symbol, &addr))
    172         {
    173                 case NO_ERROR:
    174                         return (void *)addr;
    175                 case ERROR_INVALID_HANDLE:
     159    int rc = 0;
     160    PFN addr;
     161    char *errtxt;
     162    int symord = 0;
     163    DLLchain tmp = find_id(handle);
     164
     165    if (!tmp)
     166        goto inv_handle;
     167
     168    if (*symbol == '#')
     169        symord = atoi(symbol + 1);
     170
     171    switch (rc = DosQueryProcAddr(tmp->handle, symord, symbol, &addr))
     172    {
     173        case NO_ERROR:
     174            return (void *)addr;
     175        case ERROR_INVALID_HANDLE:
    176176inv_handle:
    177                         errtxt = "invalid module handle";
    178                         break;
    179                 case ERROR_PROC_NOT_FOUND:
    180                 case ERROR_INVALID_NAME:
    181                         errtxt = "no symbol `%s' in module";
    182                         break;
    183                 default:
    184                         errtxt = "symbol `%s', error code = %d";
    185                         break;
    186         }
    187         snprintf(dlerr, sizeof(dlerr), errtxt, symbol, rc);
    188         return NULL;
    189 }
    190 
    191 /* free dynamicaly-linked library */
     177            errtxt = "invalid module handle";
     178            break;
     179        case ERROR_PROC_NOT_FOUND:
     180        case ERROR_INVALID_NAME:
     181            errtxt = "no symbol `%s' in module";
     182            break;
     183        default:
     184            errtxt = "symbol `%s', error code = %d";
     185            break;
     186    }
     187    snprintf(dlerr, sizeof(dlerr), errtxt, symbol, rc);
     188    return NULL;
     189}
     190
     191/* free dynamically-linked library */
    192192int dlclose(void *handle)
    193193{
    194         int rc;
    195         DLLchain tmp = find_id(handle);
    196 
    197         if (!tmp)
    198                 goto inv_handle;
    199 
    200         switch (rc = DosFreeModule(tmp->handle))
    201         {
    202                 case NO_ERROR:
    203                         free(tmp->name);
    204                         dlload = tmp->next;
    205                         free(tmp);
    206                         return 0;
    207                 case ERROR_INVALID_HANDLE:
     194    int rc;
     195    DLLchain tmp = find_id(handle);
     196
     197    if (!tmp)
     198        goto inv_handle;
     199
     200    switch (rc = DosFreeModule(tmp->handle))
     201    {
     202        case NO_ERROR:
     203            free(tmp->name);
     204            dlload = tmp->next;
     205            free(tmp);
     206            return 0;
     207        case ERROR_INVALID_HANDLE:
    208208inv_handle:
    209                         strcpy(dlerr, "invalid module handle");
    210                         return -1;
    211                 case ERROR_INVALID_ACCESS:
    212                         strcpy(dlerr, "access denied");
    213                         return -1;
    214                 default:
    215                         return -1;
    216         }
     209            strcpy(dlerr, "invalid module handle");
     210            return -1;
     211        case ERROR_INVALID_ACCESS:
     212            strcpy(dlerr, "access denied");
     213            return -1;
     214        default:
     215            return -1;
     216    }
    217217}
    218218
     
    220220char *dlerror()
    221221{
    222         return dlerr;
    223 }
     222    return dlerr;
     223}
  • python/vendor/current/PC/os2emx/dlfcn.h

    r2 r388  
    4343void *dlsym(void *handle, char *symbol);
    4444
    45 /* free dynamicaly-linked library */
     45/* free dynamically-linked library */
    4646int dlclose(void *handle);
    4747
  • python/vendor/current/PC/os2emx/dllentry.c

    r2 r388  
    55#define NULL 0
    66
    7 #define REF(s)  extern void s(); void *____ref_##s = &s;
     7#define REF(s)  extern void s(); void *____ref_##s = &s;
    88
    99/* Make references to imported symbols to pull them from static library */
     
    1919unsigned long _DLL_InitTerm(unsigned long mod_handle, unsigned long flag)
    2020{
    21         switch (flag)
    22         {
    23                 case 0:
    24                         if (_CRT_init())
    25                                 return 0;
    26                         __ctordtorInit();
     21    switch (flag)
     22    {
     23        case 0:
     24            if (_CRT_init())
     25                return 0;
     26            __ctordtorInit();
    2727
    28                         /* Ignore fatal signals */
    29                         signal(SIGSEGV, SIG_IGN);
    30                         signal(SIGFPE, SIG_IGN);
     28            /* Ignore fatal signals */
     29            signal(SIGSEGV, SIG_IGN);
     30            signal(SIGFPE, SIG_IGN);
    3131
    32                         return 1;
     32            return 1;
    3333
    34                 case 1:
    35                         __ctordtorTerm();
    36                         _CRT_term();
    37                         return 1;
     34        case 1:
     35            __ctordtorTerm();
     36            _CRT_term();
     37            return 1;
    3838
    39                 default:
    40                         return 0;
    41         }
     39        default:
     40            return 0;
     41    }
    4242}
  • python/vendor/current/PC/os2emx/getpathp.c

    r2 r388  
    55/* ----------------------------------------------------------------
    66   PATH RULES FOR OS/2+EMX:
    7    This describes how sys.path is formed on OS/2+EMX.  It describes the 
    8    functionality, not the implementation (ie, the order in which these 
     7   This describes how sys.path is formed on OS/2+EMX.  It describes the
     8   functionality, not the implementation (ie, the order in which these
    99   are actually fetched is different)
    1010
     
    1717     is set, we believe it.  Otherwise, we use the path of our host .EXE's
    1818     to try and locate our "landmark" (lib\\os.py) and deduce our home.
    19      - If we DO have a Python Home: The relevant sub-directories (Lib, 
     19     - If we DO have a Python Home: The relevant sub-directories (Lib,
    2020       plat-win, lib-tk, etc) are based on the Python Home
    2121     - If we DO NOT have a Python Home, the core Python Path is
    22        loaded from the registry.  This is the main PythonPath key, 
     22       loaded from the registry.  This is the main PythonPath key,
    2323       and both HKLM and HKCU are combined to form the path)
    2424
     
    3333    the core path is deduced.
    3434
    35   * When Python is hosted in another exe (different directory, embedded via 
     35  * When Python is hosted in another exe (different directory, embedded via
    3636    COM, etc), the Python Home will not be deduced, so the core path from
    37     the registry is used.  Other "application paths "in the registry are 
     37    the registry is used.  Other "application paths "in the registry are
    3838    always read.
    3939
     
    8686
    8787static int
    88 is_sep(char ch) /* determine if "ch" is a separator character */
     88is_sep(char ch) /* determine if "ch" is a separator character */
    8989{
    9090#ifdef ALTSEP
    91         return ch == SEP || ch == ALTSEP;
     91    return ch == SEP || ch == ALTSEP;
    9292#else
    93         return ch == SEP;
     93    return ch == SEP;
    9494#endif
    9595}
     
    101101reduce(char *dir)
    102102{
    103         size_t i = strlen(dir);
    104         while (i > 0 && !is_sep(dir[i]))
    105                 --i;
    106         dir[i] = '\0';
    107 }
    108        
     103    size_t i = strlen(dir);
     104    while (i > 0 && !is_sep(dir[i]))
     105        --i;
     106    dir[i] = '\0';
     107}
     108
    109109static int
    110110exists(char *filename)
    111111{
    112         struct stat buf;
    113         return stat(filename, &buf) == 0;
     112    struct stat buf;
     113    return stat(filename, &buf) == 0;
    114114}
    115115
    116116/* Is module  (check for .pyc/.pyo too)
    117  * Assumes 'filename' MAXPATHLEN+1 bytes long - 
     117 * Assumes 'filename' MAXPATHLEN+1 bytes long -
    118118 * may extend 'filename' by one character.
    119119 */
     
    121121ismodule(char *filename)
    122122{
    123         if (exists(filename))
    124                 return 1;
    125 
    126         /* Check for the compiled version of prefix. */
    127         if (strlen(filename) < MAXPATHLEN) {
    128                 strcat(filename, Py_OptimizeFlag ? "o" : "c");
    129                 if (exists(filename))
    130                         return 1;
    131         }
    132         return 0;
     123    if (exists(filename))
     124        return 1;
     125
     126    /* Check for the compiled version of prefix. */
     127    if (strlen(filename) < MAXPATHLEN) {
     128        strcat(filename, Py_OptimizeFlag ? "o" : "c");
     129        if (exists(filename))
     130            return 1;
     131    }
     132    return 0;
    133133}
    134134
     
    146146join(char *buffer, char *stuff)
    147147{
    148         size_t n, k;
    149         if (is_sep(stuff[0]))
    150                 n = 0;
    151         else {
    152                 n = strlen(buffer);
    153                 if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN)
    154                         buffer[n++] = SEP;
    155         }
    156         if (n > MAXPATHLEN)
    157                 Py_FatalError("buffer overflow in getpathp.c's joinpath()");
    158         k = strlen(stuff);
    159         if (n + k > MAXPATHLEN)
    160                 k = MAXPATHLEN - n;
    161         strncpy(buffer+n, stuff, k);
    162         buffer[n+k] = '\0';
     148    size_t n, k;
     149    if (is_sep(stuff[0]))
     150        n = 0;
     151    else {
     152        n = strlen(buffer);
     153        if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN)
     154            buffer[n++] = SEP;
     155    }
     156    if (n > MAXPATHLEN)
     157        Py_FatalError("buffer overflow in getpathp.c's joinpath()");
     158    k = strlen(stuff);
     159    if (n + k > MAXPATHLEN)
     160        k = MAXPATHLEN - n;
     161    strncpy(buffer+n, stuff, k);
     162    buffer[n+k] = '\0';
    163163}
    164164
     
    170170gotlandmark(char *landmark)
    171171{
    172         int n, ok;
    173 
    174         n = strlen(prefix);
    175         join(prefix, landmark);
    176         ok = ismodule(prefix);
    177         prefix[n] = '\0';
    178         return ok;
    179 }
    180 
    181 /* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd. 
     172    int n, ok;
     173
     174    n = strlen(prefix);
     175    join(prefix, landmark);
     176    ok = ismodule(prefix);
     177    prefix[n] = '\0';
     178    return ok;
     179}
     180
     181/* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd.
    182182 * assumption provided by only caller, calculate_path()
    183183 */
     
    185185search_for_prefix(char *argv0_path, char *landmark)
    186186{
    187         /* Search from argv0_path, until landmark is found */
    188         strcpy(prefix, argv0_path);
    189         do {
    190                 if (gotlandmark(landmark))
    191                         return 1;
    192                 reduce(prefix);
    193         } while (prefix[0]);
    194         return 0;
     187    /* Search from argv0_path, until landmark is found */
     188    strcpy(prefix, argv0_path);
     189    do {
     190        if (gotlandmark(landmark))
     191            return 1;
     192        reduce(prefix);
     193    } while (prefix[0]);
     194    return 0;
    195195}
    196196
     
    199199get_progpath(void)
    200200{
    201         extern char *Py_GetProgramName(void);
    202         char *path = getenv("PATH");
    203         char *prog = Py_GetProgramName();
    204 
    205         PPIB pib;
    206         if ((DosGetInfoBlocks(NULL, &pib) == 0) &&
    207             (DosQueryModuleName(pib->pib_hmte, sizeof(progpath), progpath) == 0))
    208                 return;
    209 
    210         if (prog == NULL || *prog == '\0')
    211                 prog = "python";
    212 
    213         /* If there is no slash in the argv0 path, then we have to
    214         * assume python is on the user's $PATH, since there's no
    215         * other way to find a directory to start the search from.  If
    216         * $PATH isn't exported, you lose.
    217         */
     201    extern char *Py_GetProgramName(void);
     202    char *path = getenv("PATH");
     203    char *prog = Py_GetProgramName();
     204
     205    PPIB pib;
     206    if ((DosGetInfoBlocks(NULL, &pib) == 0) &&
     207        (DosQueryModuleName(pib->pib_hmte, sizeof(progpath), progpath) == 0))
     208        return;
     209
     210    if (prog == NULL || *prog == '\0')
     211        prog = "python";
     212
     213    /* If there is no slash in the argv0 path, then we have to
     214    * assume python is on the user's $PATH, since there's no
     215    * other way to find a directory to start the search from.  If
     216    * $PATH isn't exported, you lose.
     217    */
    218218#ifdef ALTSEP
    219         if (strchr(prog, SEP) || strchr(prog, ALTSEP))
     219    if (strchr(prog, SEP) || strchr(prog, ALTSEP))
    220220#else
    221         if (strchr(prog, SEP))
    222 #endif
    223                 strncpy(progpath, prog, MAXPATHLEN);
    224         else if (path) {
    225                 while (1) {
    226                         char *delim = strchr(path, DELIM);
    227 
    228                         if (delim) {
    229                                 size_t len = delim - path;
    230                                 /* ensure we can't overwrite buffer */
     221    if (strchr(prog, SEP))
     222#endif
     223        strncpy(progpath, prog, MAXPATHLEN);
     224    else if (path) {
     225        while (1) {
     226            char *delim = strchr(path, DELIM);
     227
     228            if (delim) {
     229                size_t len = delim - path;
     230                /* ensure we can't overwrite buffer */
    231231#if !defined(PYCC_GCC)
    232                                 len = min(MAXPATHLEN,len);
     232                len = min(MAXPATHLEN,len);
    233233#else
    234                                 len = MAXPATHLEN < len ? MAXPATHLEN : len;
    235 #endif
    236                                 strncpy(progpath, path, len);
    237                                 *(progpath + len) = '\0';
    238                         }
    239                         else
    240                                 strncpy(progpath, path, MAXPATHLEN);
    241 
    242                         /* join() is safe for MAXPATHLEN+1 size buffer */
    243                         join(progpath, prog);
    244                         if (exists(progpath))
    245                                 break;
    246 
    247                         if (!delim) {
    248                                 progpath[0] = '\0';
    249                                 break;
    250                         }
    251                         path = delim + 1;
    252                 }
    253         }
    254         else
    255                 progpath[0] = '\0';
     234                len = MAXPATHLEN < len ? MAXPATHLEN : len;
     235#endif
     236                strncpy(progpath, path, len);
     237                *(progpath + len) = '\0';
     238            }
     239            else
     240                strncpy(progpath, path, MAXPATHLEN);
     241
     242            /* join() is safe for MAXPATHLEN+1 size buffer */
     243            join(progpath, prog);
     244            if (exists(progpath))
     245                break;
     246
     247            if (!delim) {
     248                progpath[0] = '\0';
     249                break;
     250            }
     251            path = delim + 1;
     252        }
     253    }
     254    else
     255        progpath[0] = '\0';
    256256}
    257257
     
    259259calculate_path(void)
    260260{
    261         char argv0_path[MAXPATHLEN+1];
    262         char *buf;
    263         size_t bufsz;
    264         char *pythonhome = Py_GetPythonHome();
    265         char *envpath = getenv("PYTHONPATH");
    266         char zip_path[MAXPATHLEN+1];
    267         size_t len;
    268 
    269         get_progpath();
    270         /* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */
    271         strcpy(argv0_path, progpath);
    272         reduce(argv0_path);
    273         if (pythonhome == NULL || *pythonhome == '\0') {
    274                 if (search_for_prefix(argv0_path, LANDMARK))
    275                         pythonhome = prefix;
    276                 else
    277                         pythonhome = NULL;
    278         }
    279         else
    280                 strncpy(prefix, pythonhome, MAXPATHLEN);
    281 
    282         if (envpath && *envpath == '\0')
    283                 envpath = NULL;
    284 
    285         /* Calculate zip archive path */
    286         strncpy(zip_path, progpath, MAXPATHLEN);
    287         zip_path[MAXPATHLEN] = '\0';
    288         len = strlen(zip_path);
    289         if (len > 4) {
    290                 zip_path[len-3] = 'z';  /* change ending to "zip" */
    291                 zip_path[len-2] = 'i';
    292                 zip_path[len-1] = 'p';
    293         }
    294         else {
    295                 zip_path[0] = 0;
    296         }
    297 
    298         /* We need to construct a path from the following parts.
    299         * (1) the PYTHONPATH environment variable, if set;
    300         * (2) the zip archive file path;
    301         * (3) the PYTHONPATH config macro, with the leading "."
    302         *     of each component replaced with pythonhome, if set;
    303         * (4) the directory containing the executable (argv0_path).
    304         * The length calculation calculates #3 first.
    305         */
    306 
    307         /* Calculate size of return buffer */
    308         if (pythonhome != NULL) {
    309                 char *p;
    310                 bufsz = 1;     
    311                 for (p = PYTHONPATH; *p; p++) {
    312                         if (*p == DELIM)
    313                                 bufsz++; /* number of DELIM plus one */
    314                 }
    315                 bufsz *= strlen(pythonhome);
    316         }
    317         else
    318                 bufsz = 0;
    319         bufsz += strlen(PYTHONPATH) + 1;
    320         bufsz += strlen(argv0_path) + 1;
    321         bufsz += strlen(zip_path) + 1;
    322         if (envpath != NULL)
    323                 bufsz += strlen(envpath) + 1;
    324 
    325         module_search_path = buf = malloc(bufsz);
    326         if (buf == NULL) {
    327                 /* We can't exit, so print a warning and limp along */
    328                 fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
    329                 if (envpath) {
    330                         fprintf(stderr, "Using environment $PYTHONPATH.\n");
    331                         module_search_path = envpath;
    332                 }
    333                 else {
    334                         fprintf(stderr, "Using default static path.\n");
    335                         module_search_path = PYTHONPATH;
    336                 }
    337                 return;
    338         }
    339 
    340         if (envpath) {
    341                 strcpy(buf, envpath);
    342                 buf = strchr(buf, '\0');
    343                 *buf++ = DELIM;
    344         }
    345         if (zip_path[0]) {
    346                 strcpy(buf, zip_path);
    347                 buf = strchr(buf, '\0');
    348                 *buf++ = DELIM;
    349         }
    350 
    351         if (pythonhome == NULL) {
    352                 strcpy(buf, PYTHONPATH);
    353                 buf = strchr(buf, '\0');
    354         }
    355         else {
    356                 char *p = PYTHONPATH;
    357                 char *q;
    358                 size_t n;
    359                 for (;;) {
    360                         q = strchr(p, DELIM);
    361                         if (q == NULL)
    362                                 n = strlen(p);
    363                         else
    364                                 n = q-p;
    365                         if (p[0] == '.' && is_sep(p[1])) {
    366                                 strcpy(buf, pythonhome);
    367                                 buf = strchr(buf, '\0');
    368                                 p++;
    369                                 n--;
    370                         }
    371                         strncpy(buf, p, n);
    372                         buf += n;
    373                         if (q == NULL)
    374                                 break;
    375                         *buf++ = DELIM;
    376                         p = q+1;
    377                 }
    378         }
    379         if (argv0_path) {
    380                 *buf++ = DELIM;
    381                 strcpy(buf, argv0_path);
    382                 buf = strchr(buf, '\0');
    383         }
    384         *buf = '\0';
     261    char argv0_path[MAXPATHLEN+1];
     262    char *buf;
     263    size_t bufsz;
     264    char *pythonhome = Py_GetPythonHome();
     265    char *envpath = getenv("PYTHONPATH");
     266    char zip_path[MAXPATHLEN+1];
     267    size_t len;
     268
     269    get_progpath();
     270    /* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */
     271    strcpy(argv0_path, progpath);
     272    reduce(argv0_path);
     273    if (pythonhome == NULL || *pythonhome == '\0') {
     274        if (search_for_prefix(argv0_path, LANDMARK))
     275            pythonhome = prefix;
     276        else
     277            pythonhome = NULL;
     278    }
     279    else
     280        strncpy(prefix, pythonhome, MAXPATHLEN);
     281
     282    if (envpath && *envpath == '\0')
     283        envpath = NULL;
     284
     285    /* Calculate zip archive path */
     286    strncpy(zip_path, progpath, MAXPATHLEN);
     287    zip_path[MAXPATHLEN] = '\0';
     288    len = strlen(zip_path);
     289    if (len > 4) {
     290        zip_path[len-3] = 'z';  /* change ending to "zip" */
     291        zip_path[len-2] = 'i';
     292        zip_path[len-1] = 'p';
     293    }
     294    else {
     295        zip_path[0] = 0;
     296    }
     297
     298    /* We need to construct a path from the following parts.
     299    * (1) the PYTHONPATH environment variable, if set;
     300    * (2) the zip archive file path;
     301    * (3) the PYTHONPATH config macro, with the leading "."
     302    *     of each component replaced with pythonhome, if set;
     303    * (4) the directory containing the executable (argv0_path).
     304    * The length calculation calculates #3 first.
     305    */
     306
     307    /* Calculate size of return buffer */
     308    if (pythonhome != NULL) {
     309        char *p;
     310        bufsz = 1;
     311        for (p = PYTHONPATH; *p; p++) {
     312            if (*p == DELIM)
     313                bufsz++; /* number of DELIM plus one */
     314        }
     315        bufsz *= strlen(pythonhome);
     316    }
     317    else
     318        bufsz = 0;
     319    bufsz += strlen(PYTHONPATH) + 1;
     320    bufsz += strlen(argv0_path) + 1;
     321    bufsz += strlen(zip_path) + 1;
     322    if (envpath != NULL)
     323        bufsz += strlen(envpath) + 1;
     324
     325    module_search_path = buf = malloc(bufsz);
     326    if (buf == NULL) {
     327        /* We can't exit, so print a warning and limp along */
     328        fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
     329        if (envpath) {
     330            fprintf(stderr, "Using environment $PYTHONPATH.\n");
     331            module_search_path = envpath;
     332        }
     333        else {
     334            fprintf(stderr, "Using default static path.\n");
     335            module_search_path = PYTHONPATH;
     336        }
     337        return;
     338    }
     339
     340    if (envpath) {
     341        strcpy(buf, envpath);
     342        buf = strchr(buf, '\0');
     343        *buf++ = DELIM;
     344    }
     345    if (zip_path[0]) {
     346        strcpy(buf, zip_path);
     347        buf = strchr(buf, '\0');
     348        *buf++ = DELIM;
     349    }
     350
     351    if (pythonhome == NULL) {
     352        strcpy(buf, PYTHONPATH);
     353        buf = strchr(buf, '\0');
     354    }
     355    else {
     356        char *p = PYTHONPATH;
     357        char *q;
     358        size_t n;
     359        for (;;) {
     360            q = strchr(p, DELIM);
     361            if (q == NULL)
     362                n = strlen(p);
     363            else
     364                n = q-p;
     365            if (p[0] == '.' && is_sep(p[1])) {
     366                strcpy(buf, pythonhome);
     367                buf = strchr(buf, '\0');
     368                p++;
     369                n--;
     370            }
     371            strncpy(buf, p, n);
     372            buf += n;
     373            if (q == NULL)
     374                break;
     375            *buf++ = DELIM;
     376            p = q+1;
     377        }
     378    }
     379    if (argv0_path) {
     380        *buf++ = DELIM;
     381        strcpy(buf, argv0_path);
     382        buf = strchr(buf, '\0');
     383    }
     384    *buf = '\0';
    385385}
    386386
     
    391391Py_GetPath(void)
    392392{
    393         if (!module_search_path)
    394                 calculate_path();
    395         return module_search_path;
     393    if (!module_search_path)
     394        calculate_path();
     395    return module_search_path;
    396396}
    397397
     
    399399Py_GetPrefix(void)
    400400{
    401         if (!module_search_path)
    402                 calculate_path();
    403         return prefix;
     401    if (!module_search_path)
     402        calculate_path();
     403    return prefix;
    404404}
    405405
     
    407407Py_GetExecPrefix(void)
    408408{
    409         return Py_GetPrefix();
     409    return Py_GetPrefix();
    410410}
    411411
     
    413413Py_GetProgramFullPath(void)
    414414{
    415         if (!module_search_path)
    416                 calculate_path();
    417         return progpath;
    418 }
     415    if (!module_search_path)
     416        calculate_path();
     417    return progpath;
     418}
  • python/vendor/current/PC/os2emx/python27.def

    r385 r388  
    1 LIBRARY python26 INITINSTANCE TERMINSTANCE
     1LIBRARY python27 INITINSTANCE TERMINSTANCE
    22DESCRIPTION "Python 2.6 Core DLL"
    33PROTMODE
     
    55EXPORTS
    66
    7 ; From python26_s.lib(config)
     7; From python27_s.lib(config)
    88  "_PyImport_Inittab"
    99
    10 ; From python26_s.lib(dlfcn)
     10; From python27_s.lib(dlfcn)
    1111;  "dlopen"
    1212;  "dlsym"
     
    1414;  "dlerror"
    1515
    16 ; From python26_s.lib(getpathp)
     16; From python27_s.lib(getpathp)
    1717  "Py_GetProgramFullPath"
    1818  "Py_GetPrefix"
     
    2020  "Py_GetPath"
    2121
    22 ; From python26_s.lib(getbuildinfo)
     22; From python27_s.lib(getbuildinfo)
    2323  "Py_GetBuildInfo"
    2424  "_Py_svnversion"
    2525
    26 ; From python26_s.lib(main)
     26; From python27_s.lib(main)
    2727  "Py_Main"
    2828  "Py_GetArgcArgv"
    2929
    30 ; From python26_s.lib(acceler)
     30; From python27_s.lib(acceler)
    3131  "PyGrammar_AddAccelerators"
    3232  "PyGrammar_RemoveAccelerators"
    3333
    34 ; From python26_s.lib(grammar1)
     34; From python27_s.lib(grammar1)
    3535  "PyGrammar_FindDFA"
    3636  "PyGrammar_LabelRepr"
    3737
    38 ; From python26_s.lib(listnode)
     38; From python27_s.lib(listnode)
    3939  "PyNode_ListTree"
    4040
    41 ; From python26_s.lib(node)
     41; From python27_s.lib(node)
    4242  "PyNode_New"
    4343  "PyNode_AddChild"
    4444  "PyNode_Free"
    4545
    46 ; From python26_s.lib(parser)
     46; From python27_s.lib(parser)
    4747  "PyParser_AddToken"
    4848  "PyParser_New"
    4949  "PyParser_Delete"
    5050
    51 ; From python26_s.lib(parsetok)
     51; From python27_s.lib(parsetok)
    5252  "Py_TabcheckFlag"
    5353  "PyParser_ParseString"
     
    5757  "PyParser_ParseStringFlags"
    5858
    59 ; From python26_s.lib(bitset)
     59; From python27_s.lib(bitset)
    6060  "_Py_newbitset"
    6161  "_Py_delbitset"
     
    6464  "_Py_mergebitset"
    6565
    66 ; From python26_s.lib(metagrammar)
     66; From python27_s.lib(metagrammar)
    6767  "_Py_meta_grammar"
    6868  "Py_meta_grammar"
    6969
    70 ; From python26_s.lib(tokenizer)
     70; From python27_s.lib(tokenizer)
    7171  "PyToken_OneChar"
    7272  "PyToken_TwoChars"
     
    7878  "_PyParser_TokenNames"
    7979
    80 ; From python26_s.lib(myreadline)
     80; From python27_s.lib(myreadline)
    8181  "_PyOS_ReadlineTState"
    8282  "PyOS_ReadlineFunctionPointer"
     
    8585  "PyOS_InputHook"
    8686
    87 ; From python26_s.lib(abstract)
     87; From python27_s.lib(abstract)
    8888  "_PyObject_LengthHint"
    8989  "PyMapping_Size"
     
    176176  "PyObject_IsSubclass"
    177177
    178 ; From python26_s.lib(boolobject)
     178; From python27_s.lib(boolobject)
    179179  "PyBool_FromLong"
    180180  "PyBool_Type"
     
    182182  "_Py_TrueStruct"
    183183
    184 ; From python26_s.lib(bufferobject)
     184; From python27_s.lib(bufferobject)
    185185  "PyBuffer_FromObject"
    186186  "PyBuffer_FromReadWriteObject"
     
    190190  "PyBuffer_Type"
    191191
    192 ; From python26_s.lib(cellobject)
     192; From python27_s.lib(cellobject)
    193193  "PyCell_New"
    194194  "PyCell_Get"
     
    196196  "PyCell_Type"
    197197
    198 ; From python26_s.lib(classobject)
     198; From python27_s.lib(classobject)
    199199  "PyClass_New"
    200200  "PyClass_IsSubclass"
     
    211211  "PyMethod_Type"
    212212
    213 ; From python26_s.lib(cobject)
     213; From python27_s.lib(capsule)
     214  "PyCapsule_GetContext"
     215  "PyCapsule_GetDestructor"
     216  "PyCapsule_GetName"
     217  "PyCapsule_GetPointer"
     218  "PyCapsule_Import"
     219  "PyCapsule_IsValid"
     220  "PyCapsule_New"
     221  "PyCapsule_SetContext"
     222  "PyCapsule_SetDestructor"
     223  "PyCapsule_SetName"
     224  "PyCapsule_SetPointer"
     225
     226; From python27_s.lib(cobject)
    214227  "PyCObject_FromVoidPtr"
    215228  "PyCObject_FromVoidPtrAndDesc"
     
    220233  "PyCObject_Type"
    221234
    222 ; From python26_s.lib(codeobject)
     235; From python27_s.lib(codeobject)
    223236  "PyCode_New"
    224237  "PyCode_Addr2Line"
     
    226239  "PyCode_Type"
    227240
    228 ; From python26_s.lib(complexobject)
     241; From python27_s.lib(complexobject)
    229242  "_Py_c_pow"
    230243  "_Py_c_sum"
     
    240253  "PyComplex_Type"
    241254
    242 ; From python26_s.lib(descrobject)
     255; From python27_s.lib(descrobject)
    243256  "PyWrapper_New"
    244257  "PyDescr_NewMethod"
     
    251264  "PyProperty_Type"
    252265
    253 ; From python26_s.lib(dictobject)
     266; From python27_s.lib(dictobject)
    254267  "PyDict_New"
    255268  "PyDict_GetItem"
     
    275288  "PyDictIterItem_Type"
    276289
    277 ; From python26_s.lib(enumobject)
     290; From python27_s.lib(enumobject)
    278291  "PyEnum_Type"
    279292  "PyReversed_Type"
    280293
    281 ; From python26_s.lib(fileobject)
     294; From python27_s.lib(fileobject)
    282295  "PyFile_FromString"
    283296  "Py_UniversalNewlineFread"
     
    295308  "PyFile_Type"
    296309
    297 ; From python26_s.lib(floatobject)
     310; From python27_s.lib(floatobject)
    298311  "PyFloat_FromString"
    299312  "PyFloat_AsDouble"
     
    307320  "PyFloat_AsString"
    308321  "_PyFloat_Init"
    309   "PyFloat_AsStringEx"
    310322  "PyFloat_Type"
    311323
    312 ; From python26_s.lib(frameobject)
     324; From python27_s.lib(frameobject)
    313325  "PyFrame_New"
    314326  "PyFrame_FastToLocals"
     
    320332  "PyFrame_Type"
    321333
    322 ; From python26_s.lib(funcobject)
     334; From python27_s.lib(funcobject)
    323335  "PyFunction_New"
    324336  "PyFunction_GetCode"
     
    335347  "PyStaticMethod_Type"
    336348
    337 ; From python26_s.lib(genobject)
     349; From python27_s.lib(genobject)
    338350  "PyGen_New"
    339351  "PyGen_NeedsFinalizing"
    340352  "PyGen_Type"
    341353
    342 ; From python26_s.lib(intobject)
     354; From python27_s.lib(intobject)
    343355  "PyInt_AsLong"
    344356  "PyInt_AsUnsignedLongMask"
     
    355367  "PyInt_Type"
    356368
    357 ; From python26_s.lib(iterobject)
     369; From python27_s.lib(iterobject)
    358370  "PySeqIter_New"
    359371  "PyCallIter_New"
     
    361373  "PyCallIter_Type"
    362374
    363 ; From python26_s.lib(listobject)
     375; From python27_s.lib(listobject)
    364376  "PyList_New"
    365377  "PyList_Append"
     
    379391  "PyListRevIter_Type"
    380392
    381 ; From python26_s.lib(longobject)
     393; From python27_s.lib(longobject)
    382394  "PyLong_FromDouble"
    383395  "PyLong_AsLong"
     
    409421  "_PyLong_DigitValue"
    410422
    411 ; From python26_s.lib(methodobject)
     423; From python27_s.lib(methodobject)
    412424  "PyCFunction_Call"
    413425  "Py_FindMethodInChain"
     
    421433  "PyCFunction_Type"
    422434
    423 ; From python26_s.lib(moduleobject)
     435; From python27_s.lib(moduleobject)
    424436  "PyModule_New"
    425437  "_PyModule_Clear"
     
    429441  "PyModule_Type"
    430442
    431 ; From python26_s.lib(object)
     443; From python27_s.lib(object)
    432444  "Py_DivisionWarningFlag"
    433445  "PyObject_Str"
     
    482494  "_PyTrash_delete_later"
    483495
    484 ; From python26_s.lib(obmalloc)
     496; From python27_s.lib(obmalloc)
    485497  "PyObject_Malloc"
    486498  "PyObject_Free"
    487499  "PyObject_Realloc"
    488500
    489 ; From python26_s.lib(rangeobject)
     501; From python27_s.lib(rangeobject)
    490502  "PyRange_Type"
    491503
    492 ; From python26_s.lib(setobject)
     504; From python27_s.lib(setobject)
    493505  "PySet_Pop"
    494506  "PySet_New"
     
    505517  "PyFrozenSet_Type"
    506518
    507 ; From python26_s.lib(sliceobject)
     519; From python27_s.lib(sliceobject)
    508520  "_PySlice_FromIndices"
    509521  "PySlice_GetIndices"
     
    513525  "PySlice_Type"
    514526
    515 ; From python26_s.lib(stringobject)
     527; From python27_s.lib(stringobject)
    516528  "PyString_FromStringAndSize"
    517529  "PyString_InternInPlace"
     
    544556  "PyBaseString_Type"
    545557
    546 ; From python26_s.lib(structseq)
     558; From python27_s.lib(structseq)
    547559  "PyStructSequence_InitType"
    548560  "PyStructSequence_New"
    549561  "PyStructSequence_UnnamedField"
    550562
    551 ; From python26_s.lib(tupleobject)
     563; From python27_s.lib(tupleobject)
    552564  "PyTuple_New"
    553565  "PyTuple_Pack"
     
    561573  "PyTupleIter_Type"
    562574
    563 ; From python26_s.lib(typeobject)
     575; From python27_s.lib(typeobject)
    564576  "PyType_IsSubtype"
    565577  "_PyType_Lookup"
     
    572584  "PySuper_Type"
    573585
    574 ; From python26_s.lib(unicodeobject)
     586; From python27_s.lib(unicodeobject)
    575587  "PyUnicodeUCS2_Resize"
    576588  "PyUnicodeUCS2_FromOrdinal"
     
    638650  "PyUnicode_Type"
    639651
    640 ; From python26_s.lib(unicodectype)
     652; From python27_s.lib(unicodectype)
    641653  "_PyUnicode_TypeRecords"
    642654  "_PyUnicodeUCS2_ToNumeric"
     
    656668  "_PyUnicodeUCS2_IsAlpha"
    657669
    658 ; From python26_s.lib(weakrefobject)
     670; From python27_s.lib(weakrefobject)
    659671  "PyWeakref_NewRef"
    660672  "PyWeakref_NewProxy"
     
    667679  "_PyWeakref_CallableProxyType"
    668680
    669 ; From python26_s.lib(Python-ast)
     681; From python27_s.lib(Python-ast)
    670682;  "init_ast"
    671683  "Module"
     
    726738  "PyAST_mod2obj"
    727739
    728 ; From python26_s.lib(asdl)
     740; From python27_s.lib(asdl)
    729741  "asdl_seq_new"
    730742  "asdl_int_seq_new"
    731743
    732 ; From python26_s.lib(ast)
     744; From python27_s.lib(ast)
    733745  "PyAST_FromNode"
    734746
    735 ; From python26_s.lib(bltinmodule)
     747; From python27_s.lib(bltinmodule)
    736748  "_PyBuiltin_Init"
    737749  "Py_FileSystemDefaultEncoding"
    738750
    739 ; From python26_s.lib(exceptions)
     751; From python27_s.lib(exceptions)
    740752  "PyUnicodeEncodeError_GetStart"
    741753  "PyUnicodeDecodeError_GetStart"
     
    813825  "PyExc_MemoryErrorInst"
    814826
    815 ; From python26_s.lib(ceval)
     827; From python27_s.lib(ceval)
    816828  "PyEval_EvalFrameEx"
    817829  "PyEval_CallObjectWithKeywords"
     
    852864  "_Py_Ticker"
    853865
    854 ; From python26_s.lib(compile)
     866; From python27_s.lib(compile)
    855867  "_Py_Mangle"
    856868  "PyAST_Compile"
     
    858870  "Py_OptimizeFlag"
    859871
    860 ; From python26_s.lib(codecs)
     872; From python27_s.lib(codecs)
    861873  "_PyCodec_Lookup"
    862874  "PyCodec_Encode"
     
    877889  "PyCodec_StrictErrors"
    878890
    879 ; From python26_s.lib(errors)
     891; From python27_s.lib(errors)
    880892  "PyErr_SetNone"
    881893  "PyErr_SetString"
     
    903915  "PyErr_WarnExplicit"
    904916
    905 ; From python26_s.lib(frozen)
     917; From python27_s.lib(frozen)
    906918  "PyImport_FrozenModules"
    907919
    908 ; From python26_s.lib(frozenmain)
     920; From python27_s.lib(frozenmain)
    909921  "Py_FrozenMain"
    910922
    911 ; From python26_s.lib(future)
     923; From python27_s.lib(future)
    912924  "PyFuture_FromAST"
    913925
    914 ; From python26_s.lib(getargs)
     926; From python27_s.lib(getargs)
    915927  "PyArg_Parse"
    916928  "_PyArg_Parse_SizeT"
     
    926938  "_PyArg_VaParseTupleAndKeywords_SizeT"
    927939
    928 ; From python26_s.lib(getcompiler)
     940; From python27_s.lib(getcompiler)
    929941  "Py_GetCompiler"
    930942
    931 ; From python26_s.lib(getcopyright)
     943; From python27_s.lib(getcopyright)
    932944  "Py_GetCopyright"
    933945
    934 ; From python26_s.lib(getmtime)
    935   "PyOS_GetLastModificationTime"
    936 
    937 ; From python26_s.lib(getplatform)
     946; From python27_s.lib(getplatform)
    938947  "Py_GetPlatform"
    939948
    940 ; From python26_s.lib(getversion)
     949; From python27_s.lib(getversion)
    941950  "Py_GetVersion"
    942951
    943 ; From python26_s.lib(graminit)
     952; From python27_s.lib(graminit)
    944953  "_PyParser_Grammar"
    945954
    946 ; From python26_s.lib(import)
     955; From python27_s.lib(import)
    947956  "_PyImport_Init"
    948957  "_PyImportHooks_Init"
     
    971980  "_PyImport_Filetab"
    972981
    973 ; From python26_s.lib(importdl)
     982; From python27_s.lib(importdl)
    974983  "_PyImport_LoadDynamicModule"
    975984
    976 ; From python26_s.lib(marshal)
     985; From python27_s.lib(marshal)
    977986  "PyMarshal_ReadLongFromFile"
    978987  "PyMarshal_WriteObjectToString"
     
    985994  "PyMarshal_Init"
    986995
    987 ; From python26_s.lib(modsupport)
     996; From python27_s.lib(modsupport)
    988997  "Py_InitModule4"
    989998  "Py_BuildValue"
     
    9981007  "_Py_PackageContext"
    9991008
    1000 ; From python26_s.lib(mysnprintf)
     1009; From python27_s.lib(mysnprintf)
    10011010  "PyOS_snprintf"
    10021011  "PyOS_vsnprintf"
    10031012
    1004 ; From python26_s.lib(mystrtoul)
     1013; From python27_s.lib(mystrtoul)
    10051014  "PyOS_strtoul"
    10061015  "PyOS_strtol"
    10071016
    1008 ; From python26_s.lib(pyarena)
     1017; From python27_s.lib(pyarena)
    10091018  "PyArena_New"
    10101019  "PyArena_Free"
     
    10121021  "PyArena_AddPyObject"
    10131022
    1014 ; From python26_s.lib(pyfpe)
     1023; From python27_s.lib(pyfpe)
    10151024  "PyFPE_dummy"
    10161025
    1017 ; From python26_s.lib(pystate)
     1026; From python27_s.lib(pystate)
    10181027  "PyInterpreterState_Clear"
    10191028  "PyThreadState_Clear"
     
    10401049  "_PyThreadState_GetFrame"
    10411050
    1042 ; From python26_s.lib(pystrtod)
     1051; From python27_s.lib(pystrtod)
    10431052  "PyOS_ascii_strtod"
    10441053  "PyOS_ascii_formatd"
    10451054  "PyOS_ascii_atof"
    10461055
    1047 ; From python26_s.lib(pythonrun)
     1056; From python27_s.lib(pythonrun)
    10481057  "Py_IgnoreEnvironmentFlag"
    10491058  "Py_DebugFlag"
     
    11071116  "_Py_QnewFlag"
    11081117
    1109 ; From python26_s.lib(structmember)
     1118; From python27_s.lib(structmember)
    11101119  "PyMember_Get"
    11111120  "PyMember_GetOne"
     
    11131122  "PyMember_Set"
    11141123
    1115 ; From python26_s.lib(symtable)
     1124; From python27_s.lib(symtable)
    11161125  "PySymtable_Build"
    11171126  "PySymtable_Free"
     
    11201129  "PySTEntry_Type"
    11211130
    1122 ; From python26_s.lib(sysmodule)
     1131; From python27_s.lib(sysmodule)
    11231132  "_PySys_Init"
    11241133  "PySys_WriteStderr"
     
    11341143  "PySys_AddWarnOption"
    11351144
    1136 ; From python26_s.lib(traceback)
     1145; From python27_s.lib(traceback)
    11371146  "PyTraceBack_Here"
    11381147  "PyTraceBack_Print"
    11391148  "PyTraceBack_Type"
    11401149
    1141 ; From python26_s.lib(getopt)
     1150; From python27_s.lib(getopt)
    11421151  "_PyOS_GetOpt"
    11431152  "_PyOS_opterr"
     
    11451154  "_PyOS_optarg"
    11461155
    1147 ; From python26_s.lib(dynload_shlib)
     1156; From python27_s.lib(dynload_shlib)
    11481157  "_PyImport_DynLoadFiletab"
    11491158  "_PyImport_GetDynLoadFunc"
    11501159
    1151 ; From python26_s.lib(thread)
     1160; From python27_s.lib(thread)
    11521161  "PyThread_delete_key_value"
    11531162  "PyThread_init_thread"
     
    11651174  "PyThread_set_key_value"
    11661175  "PyThread_get_key_value"
    1167   "PyThread__exit_thread"
    1168 
    1169 ; From python26_s.lib(gcmodule)
     1176
     1177; From python27_s.lib(gcmodule)
    11701178;  "initgc"
    11711179  "_PyObject_GC_New"
     
    11831191  "_PyGC_generation0"
    11841192
    1185 ; From python26_s.lib(signalmodule)
     1193; From python27_s.lib(signalmodule)
    11861194;  "initsignal"
    11871195  "PyErr_CheckSignals"
     
    11921200  "PyOS_AfterFork"
    11931201
    1194 ; From python26_s.lib(posixmodule)
     1202; From python27_s.lib(posixmodule)
    11951203;  "initos2"
    11961204
    1197 ; From python26_s.lib(threadmodule)
     1205; From python27_s.lib(threadmodule)
    11981206;  "initthread"
    11991207
    1200 ; From python26_s.lib(arraymodule)
     1208; From python27_s.lib(arraymodule)
    12011209;  "initarray"
    12021210;  "array_methods"
    12031211
    1204 ; From python26_s.lib(binascii)
     1212; From python27_s.lib(binascii)
    12051213;  "initbinascii"
    12061214
    1207 ; From python26_s.lib(cmathmodule)
     1215; From python27_s.lib(cmathmodule)
    12081216;  "initcmath"
    12091217
    1210 ; From python26_s.lib(_codecsmodule)
     1218; From python27_s.lib(_codecsmodule)
    12111219;  "init_codecs"
    12121220
    1213 ; From python26_s.lib(collectionsmodule)
     1221; From python27_s.lib(collectionsmodule)
    12141222;  "initcollections"
    12151223  "dequeiter_type"
    12161224  "dequereviter_type"
    12171225
    1218 ; From python26_s.lib(cPickle)
     1226; From python27_s.lib(cPickle)
    12191227;  "initcPickle"
    12201228;  "fast_save_leave"
    12211229
    1222 ; From python26_s.lib(cStringIO)
     1230; From python27_s.lib(cStringIO)
    12231231;  "initcStringIO"
    12241232
    1225 ; From python26_s.lib(_csv)
     1233; From python27_s.lib(_csv)
    12261234;  "init_csv"
    12271235
    1228 ; From python26_s.lib(datetimemodule)
     1236; From python27_s.lib(datetimemodule)
    12291237;  "initdatetime"
    12301238
    1231 ; From python26_s.lib(dlmodule)
     1239; From python27_s.lib(dlmodule)
    12321240;  "initdl"
    12331241
    1234 ; From python26_s.lib(errnomodule)
     1242; From python27_s.lib(errnomodule)
    12351243;  "initerrno"
    12361244
    1237 ; From python26_s.lib(fcntlmodule)
     1245; From python27_s.lib(fcntlmodule)
    12381246;  "initfcntl"
    12391247
    1240 ; From python26_s.lib(_functoolsmodule)
     1248; From python27_s.lib(_functoolsmodule)
    12411249;  "init_functools"
    12421250
    1243 ; From python26_s.lib(_heapqmodule)
     1251; From python27_s.lib(_heapqmodule)
    12441252;  "init_heapq"
    12451253
    1246 ; From python26_s.lib(imageop)
     1254; From python27_s.lib(imageop)
    12471255;  "initimageop"
    12481256
    1249 ; From python26_s.lib(itertoolsmodule)
     1257; From python27_s.lib(itertoolsmodule)
    12501258;  "inititertools"
    12511259
    1252 ; From python26_s.lib(_localemodule)
     1260; From python27_s.lib(_localemodule)
    12531261;  "init_locale"
    12541262
    1255 ; From python26_s.lib(mathmodule)
     1263; From python27_s.lib(mathmodule)
    12561264;  "initmath"
    12571265
    1258 ; From python26_s.lib(md5)
     1266; From python27_s.lib(md5)
    12591267  "md5_finish"
    12601268  "md5_init"
    12611269  "md5_append"
    12621270
    1263 ; From python26_s.lib(md5module)
     1271; From python27_s.lib(md5module)
    12641272;  "init_md5"
    12651273
    1266 ; From python26_s.lib(operator)
     1274; From python27_s.lib(operator)
    12671275;  "initoperator"
    12681276
    1269 ; From python26_s.lib(_randommodule)
     1277; From python27_s.lib(_randommodule)
    12701278;  "init_random"
    12711279
    1272 ; From python26_s.lib(rgbimgmodule)
     1280; From python27_s.lib(rgbimgmodule)
    12731281;  "initrgbimg"
    12741282
    1275 ; From python26_s.lib(shamodule)
     1283; From python27_s.lib(shamodule)
    12761284;  "init_sha"
    12771285
    1278 ; From python26_s.lib(sha256module)
     1286; From python27_s.lib(sha256module)
    12791287;  "init_sha256"
    12801288
    1281 ; From python26_s.lib(sha512module)
     1289; From python27_s.lib(sha512module)
    12821290;  "init_sha512"
    12831291
    1284 ; From python26_s.lib(_sre)
     1292; From python27_s.lib(_sre)
    12851293;  "init_sre"
    12861294
    1287 ; From python26_s.lib(stropmodule)
     1295; From python27_s.lib(stropmodule)
    12881296;  "initstrop"
    12891297
    1290 ; From python26_s.lib(_struct)
     1298; From python27_s.lib(_struct)
    12911299;  "init_struct"
    12921300
    1293 ; From python26_s.lib(symtablemodule)
     1301; From python27_s.lib(symtablemodule)
    12941302;  "init_symtable"
    12951303
    1296 ; From python26_s.lib(termios)
     1304; From python27_s.lib(termios)
    12971305;  "inittermios"
    12981306
    1299 ; From python26_s.lib(timemodule)
     1307; From python27_s.lib(timemodule)
    13001308;  "inittime"
    13011309  "_PyTime_DoubleToTimet"
    13021310;  "inittimezone"
    13031311
    1304 ; From python26_s.lib(timingmodule)
     1312; From python27_s.lib(timingmodule)
    13051313;  "inittiming"
    13061314
    1307 ; From python26_s.lib(_weakref)
     1315; From python27_s.lib(_weakref)
    13081316;  "init_weakref"
    13091317
    1310 ; From python26_s.lib(xxsubtype)
     1318; From python27_s.lib(xxsubtype)
    13111319;  "initxxsubtype"
    13121320
    1313 ; From python26_s.lib(zipimport)
     1321; From python27_s.lib(zipimport)
    13141322;  "initzipimport"
  • python/vendor/current/PC/os2emx/pythonpm.c

    r2 r388  
    2828typedef struct
    2929{
    30         int argc;
    31         char **argv;
    32         HWND Frame;
    33         int running;
     30    int argc;
     31    char **argv;
     32    HWND Frame;
     33    int running;
    3434} arglist;
    3535
     
    4646main(int argc, char **argv)
    4747{
    48         ULONG FrameFlags = FCF_TITLEBAR |
    49                            FCF_SYSMENU |
    50                            FCF_SIZEBORDER |
    51                            FCF_HIDEBUTTON |
    52                            FCF_SHELLPOSITION |
    53                            FCF_TASKLIST;
    54         HAB hab;
    55         HMQ hmq;
    56         HWND Client;
    57         QMSG qmsg;
    58         arglist args;
    59         int python_tid;
     48    ULONG FrameFlags = FCF_TITLEBAR |
     49                       FCF_SYSMENU |
     50                       FCF_SIZEBORDER |
     51                       FCF_HIDEBUTTON |
     52                       FCF_SHELLPOSITION |
     53                       FCF_TASKLIST;
     54    HAB hab;
     55    HMQ hmq;
     56    HWND Client;
     57    QMSG qmsg;
     58    arglist args;
     59    int python_tid;
    6060
    61         /* init PM and create message queue */
    62         hab = WinInitialize(0);
    63         hmq = WinCreateMsgQueue(hab, 0);
     61    /* init PM and create message queue */
     62    hab = WinInitialize(0);
     63    hmq = WinCreateMsgQueue(hab, 0);
    6464
    65         /* create a (hidden) Window to house the window procedure */
    66         args.Frame = WinCreateStdWindow(HWND_DESKTOP,
    67                                         0,
    68                                         &FrameFlags,
    69                                         NULL,
    70                                         "PythonPM",
    71                                         0L,
    72                                         0,
    73                                         0,
    74                                         &Client);
     65    /* create a (hidden) Window to house the window procedure */
     66    args.Frame = WinCreateStdWindow(HWND_DESKTOP,
     67                                    0,
     68                                    &FrameFlags,
     69                                    NULL,
     70                                    "PythonPM",
     71                                    0L,
     72                                    0,
     73                                    0,
     74                                    &Client);
    7575
    76         /* run Python interpreter in a thread */
    77         args.argc = argc;
    78         args.argv = argv;
    79         args.running = 0;
    80         if (-1 == (python_tid = _beginthread(PythonThread, NULL, 1024 * 1024, &args)))
    81         {
    82                 /* couldn't start thread */
    83                 WinAlarm(HWND_DESKTOP, WA_ERROR);
    84                 PythonRC = 1;
    85         }
    86         else
    87         {
    88                 /* process PM messages, until Python exits */
    89                 while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
    90                         WinDispatchMsg(hab, &qmsg);
    91                 if (args.running > 0)
    92                         DosKillThread(python_tid);
    93         }
    94                
    95         /* destroy window, shutdown message queue and PM */
    96         WinDestroyWindow(args.Frame);
    97         WinDestroyMsgQueue(hmq);
    98         WinTerminate(hab);
     76    /* run Python interpreter in a thread */
     77    args.argc = argc;
     78    args.argv = argv;
     79    args.running = 0;
     80    if (-1 == (python_tid = _beginthread(PythonThread, NULL, 1024 * 1024, &args)))
     81    {
     82        /* couldn't start thread */
     83        WinAlarm(HWND_DESKTOP, WA_ERROR);
     84        PythonRC = 1;
     85    }
     86    else
     87    {
     88        /* process PM messages, until Python exits */
     89        while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
     90            WinDispatchMsg(hab, &qmsg);
     91        if (args.running > 0)
     92            DosKillThread(python_tid);
     93    }
    9994
    100         return PythonRC;
     95    /* destroy window, shutdown message queue and PM */
     96    WinDestroyWindow(args.Frame);
     97    WinDestroyMsgQueue(hmq);
     98    WinTerminate(hab);
     99
     100    return PythonRC;
    101101}
    102102
    103103void PythonThread(void *argl)
    104104{
    105         HAB hab;
    106         arglist *args;
     105    HAB hab;
     106    arglist *args;
    107107
    108         /* PM initialisation */
    109         hab = WinInitialize(0);
     108    /* PM initialisation */
     109    hab = WinInitialize(0);
    110110
    111         /* start Python */
    112         args = (arglist *)argl;
    113         args->running = 1;
    114         PythonRC = Py_Main(args->argc, args->argv);
     111    /* start Python */
     112    args = (arglist *)argl;
     113    args->running = 1;
     114    PythonRC = Py_Main(args->argc, args->argv);
    115115
    116         /* enter a critical section and send the termination message */
    117         DosEnterCritSec();
    118         args->running = 0;
    119         WinPostMsg(args->Frame, WM_QUIT, NULL, NULL);
     116    /* enter a critical section and send the termination message */
     117    DosEnterCritSec();
     118    args->running = 0;
     119    WinPostMsg(args->Frame, WM_QUIT, NULL, NULL);
    120120
    121         /* shutdown PM and terminate thread */
    122         WinTerminate(hab);
    123         _endthread();
     121    /* shutdown PM and terminate thread */
     122    WinTerminate(hab);
     123    _endthread();
    124124}
  • python/vendor/current/PC/os2vacpp/getpathp.c

    r2 r388  
    5656
    5757static int
    58 is_sep(char ch) /* determine if "ch" is a separator character */
     58is_sep(char ch) /* determine if "ch" is a separator character */
    5959{
    6060#ifdef ALTSEP
    61         return ch == SEP || ch == ALTSEP;
     61    return ch == SEP || ch == ALTSEP;
    6262#else
    63         return ch == SEP;
     63    return ch == SEP;
    6464#endif
    6565}
     
    6969reduce(char *dir)
    7070{
    71         int i = strlen(dir);
    72         while (i > 0 && !is_sep(dir[i]))
    73                 --i;
    74         dir[i] = '\0';
    75 }
    76        
     71    int i = strlen(dir);
     72    while (i > 0 && !is_sep(dir[i]))
     73        --i;
     74    dir[i] = '\0';
     75}
     76
    7777
    7878static int
    7979exists(char *filename)
    8080{
    81         struct stat buf;
    82         return stat(filename, &buf) == 0;
     81    struct stat buf;
     82    return stat(filename, &buf) == 0;
    8383}
    8484
     
    9696join(char *buffer, char *stuff)
    9797{
    98         int n, k;
    99         if (is_sep(stuff[0]))
    100                 n = 0;
    101         else {
    102                 n = strlen(buffer);
    103                 if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN)
    104                         buffer[n++] = SEP;
    105         }
    106         if (n > MAXPATHLEN)
    107                 Py_FatalError("buffer overflow in getpathp.c's joinpath()");
    108         k = strlen(stuff);
    109         if (n + k > MAXPATHLEN)
    110                 k = MAXPATHLEN - n;
    111         strncpy(buffer+n, stuff, k);
    112         buffer[n+k] = '\0';
     98    int n, k;
     99    if (is_sep(stuff[0]))
     100        n = 0;
     101    else {
     102        n = strlen(buffer);
     103        if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN)
     104            buffer[n++] = SEP;
     105    }
     106    if (n > MAXPATHLEN)
     107        Py_FatalError("buffer overflow in getpathp.c's joinpath()");
     108    k = strlen(stuff);
     109    if (n + k > MAXPATHLEN)
     110        k = MAXPATHLEN - n;
     111    strncpy(buffer+n, stuff, k);
     112    buffer[n+k] = '\0';
    113113}
    114114
     
    117117search_for_prefix(char *argv0_path, char *landmark)
    118118{
    119         int n;
    120 
    121         /* Search from argv0_path, until root is found */
    122         strcpy(prefix, argv0_path);
    123         do {
    124                 n = strlen(prefix);
    125                 join(prefix, landmark);
    126                 if (exists(prefix)) {
    127                         prefix[n] = '\0';
    128                         return 1;
    129                 }
    130                 prefix[n] = '\0';
    131                 reduce(prefix);
    132         } while (prefix[0]);
    133         return 0;
     119    int n;
     120
     121    /* Search from argv0_path, until root is found */
     122    strcpy(prefix, argv0_path);
     123    do {
     124        n = strlen(prefix);
     125        join(prefix, landmark);
     126        if (exists(prefix)) {
     127            prefix[n] = '\0';
     128            return 1;
     129        }
     130        prefix[n] = '\0';
     131        reduce(prefix);
     132    } while (prefix[0]);
     133    return 0;
    134134}
    135135
     
    148148getpythonregpath(HKEY keyBase, BOOL bWin32s)
    149149{
    150         HKEY newKey = 0;
    151         DWORD nameSize = 0;
    152         DWORD dataSize = 0;
    153         DWORD numEntries = 0;
    154         LONG rc;
    155         char *retval = NULL;
    156         char *dataBuf;
    157         const char keyPrefix[] = "Software\\Python\\PythonCore\\";
    158         const char keySuffix[] = "\\PythonPath";
    159         int versionLen;
    160         char *keyBuf;
    161 
    162         // Tried to use sysget("winver") but here is too early :-(
    163         versionLen = strlen(PyWin_DLLVersionString);
    164         // alloca == no free required, but memory only local to fn.
    165         // also no heap fragmentation!  Am I being silly?
    166         keyBuf = alloca(sizeof(keyPrefix)-1 + versionLen + sizeof(keySuffix)); // chars only, plus 1 NULL.
    167         // lots of constants here for the compiler to optimize away :-)
    168         memcpy(keyBuf, keyPrefix, sizeof(keyPrefix)-1);
    169         memcpy(keyBuf+sizeof(keyPrefix)-1, PyWin_DLLVersionString, versionLen);
    170         memcpy(keyBuf+sizeof(keyPrefix)-1+versionLen, keySuffix, sizeof(keySuffix)); // NULL comes with this one!
    171 
    172         rc=RegOpenKey(keyBase,
    173                       keyBuf,
    174                       &newKey);
    175         if (rc==ERROR_SUCCESS) {
    176                 RegQueryInfoKey(newKey, NULL, NULL, NULL, NULL, NULL, NULL,
    177                                 &numEntries, &nameSize, &dataSize, NULL, NULL);
    178         }
    179         if (bWin32s && numEntries==0 && dataSize==0) {
    180                 /* must hardcode for Win32s */
    181                 numEntries = 1;
    182                 dataSize = 511;
    183         }
    184         if (numEntries) {
    185                 /* Loop over all subkeys. */
    186                 /* Win32s doesnt know how many subkeys, so we do
    187                    it twice */
    188                 char keyBuf[MAX_PATH+1];
    189                 int index = 0;
    190                 int off = 0;
    191                 for(index=0;;index++) {
    192                         long reqdSize = 0;
    193                         DWORD rc = RegEnumKey(newKey,
    194                                               index, keyBuf, MAX_PATH+1);
    195                         if (rc) break;
    196                         rc = RegQueryValue(newKey, keyBuf, NULL, &reqdSize);
    197                         if (rc) break;
    198                         if (bWin32s && reqdSize==0) reqdSize = 512;
    199                         dataSize += reqdSize + 1; /* 1 for the ";" */
    200                 }
    201                 dataBuf = malloc(dataSize+1);
    202                 if (dataBuf==NULL)
    203                         return NULL; /* pretty serious?  Raise error? */
    204                 /* Now loop over, grabbing the paths.
    205                    Subkeys before main library */
    206                 for(index=0;;index++) {
    207                         int adjust;
    208                         long reqdSize = dataSize;
    209                         DWORD rc = RegEnumKey(newKey,
    210                                               index, keyBuf,MAX_PATH+1);
    211                         if (rc) break;
    212                         rc = RegQueryValue(newKey,
    213                                            keyBuf, dataBuf+off, &reqdSize);
    214                         if (rc) break;
    215                         if (reqdSize>1) {
    216                                 /* If Nothing, or only '\0' copied. */
    217                                 adjust = strlen(dataBuf+off);
    218                                 dataSize -= adjust;
    219                                 off += adjust;
    220                                 dataBuf[off++] = ';';
    221                                 dataBuf[off] = '\0';
    222                                 dataSize--;
    223                         }
    224                 }
    225                 /* Additionally, win32s doesnt work as expected, so
    226                    the specific strlen() is required for 3.1. */
    227                 rc = RegQueryValue(newKey, "", dataBuf+off, &dataSize);
    228                 if (rc==ERROR_SUCCESS) {
    229                         if (strlen(dataBuf)==0)
    230                                 free(dataBuf);
    231                         else
    232                                 retval = dataBuf; /* caller will free */
    233                 }
    234                 else
    235                         free(dataBuf);
    236         }
    237 
    238         if (newKey)
    239                 RegCloseKey(newKey);
    240         return retval;
     150    HKEY newKey = 0;
     151    DWORD nameSize = 0;
     152    DWORD dataSize = 0;
     153    DWORD numEntries = 0;
     154    LONG rc;
     155    char *retval = NULL;
     156    char *dataBuf;
     157    const char keyPrefix[] = "Software\\Python\\PythonCore\\";
     158    const char keySuffix[] = "\\PythonPath";
     159    int versionLen;
     160    char *keyBuf;
     161
     162    // Tried to use sysget("winver") but here is too early :-(
     163    versionLen = strlen(PyWin_DLLVersionString);
     164    // alloca == no free required, but memory only local to fn.
     165    // also no heap fragmentation!  Am I being silly?
     166    keyBuf = alloca(sizeof(keyPrefix)-1 + versionLen + sizeof(keySuffix)); // chars only, plus 1 NULL.
     167    // lots of constants here for the compiler to optimize away :-)
     168    memcpy(keyBuf, keyPrefix, sizeof(keyPrefix)-1);
     169    memcpy(keyBuf+sizeof(keyPrefix)-1, PyWin_DLLVersionString, versionLen);
     170    memcpy(keyBuf+sizeof(keyPrefix)-1+versionLen, keySuffix, sizeof(keySuffix)); // NULL comes with this one!
     171
     172    rc=RegOpenKey(keyBase,
     173                  keyBuf,
     174                  &newKey);
     175    if (rc==ERROR_SUCCESS) {
     176        RegQueryInfoKey(newKey, NULL, NULL, NULL, NULL, NULL, NULL,
     177                        &numEntries, &nameSize, &dataSize, NULL, NULL);
     178    }
     179    if (bWin32s && numEntries==0 && dataSize==0) {
     180        /* must hardcode for Win32s */
     181        numEntries = 1;
     182        dataSize = 511;
     183    }
     184    if (numEntries) {
     185        /* Loop over all subkeys. */
     186        /* Win32s doesnt know how many subkeys, so we do
     187           it twice */
     188        char keyBuf[MAX_PATH+1];
     189        int index = 0;
     190        int off = 0;
     191        for(index=0;;index++) {
     192            long reqdSize = 0;
     193            DWORD rc = RegEnumKey(newKey,
     194                                  index, keyBuf, MAX_PATH+1);
     195            if (rc) break;
     196            rc = RegQueryValue(newKey, keyBuf, NULL, &reqdSize);
     197            if (rc) break;
     198            if (bWin32s && reqdSize==0) reqdSize = 512;
     199            dataSize += reqdSize + 1; /* 1 for the ";" */
     200        }
     201        dataBuf = malloc(dataSize+1);
     202        if (dataBuf==NULL)
     203            return NULL; /* pretty serious?  Raise error? */
     204        /* Now loop over, grabbing the paths.
     205           Subkeys before main library */
     206        for(index=0;;index++) {
     207            int adjust;
     208            long reqdSize = dataSize;
     209            DWORD rc = RegEnumKey(newKey,
     210                                  index, keyBuf,MAX_PATH+1);
     211            if (rc) break;
     212            rc = RegQueryValue(newKey,
     213                               keyBuf, dataBuf+off, &reqdSize);
     214            if (rc) break;
     215            if (reqdSize>1) {
     216                /* If Nothing, or only '\0' copied. */
     217                adjust = strlen(dataBuf+off);
     218                dataSize -= adjust;
     219                off += adjust;
     220                dataBuf[off++] = ';';
     221                dataBuf[off] = '\0';
     222                dataSize--;
     223            }
     224        }
     225        /* Additionally, win32s doesnt work as expected, so
     226           the specific strlen() is required for 3.1. */
     227        rc = RegQueryValue(newKey, "", dataBuf+off, &dataSize);
     228        if (rc==ERROR_SUCCESS) {
     229            if (strlen(dataBuf)==0)
     230                free(dataBuf);
     231            else
     232                retval = dataBuf; /* caller will free */
     233        }
     234        else
     235            free(dataBuf);
     236    }
     237
     238    if (newKey)
     239        RegCloseKey(newKey);
     240    return retval;
    241241}
    242242#endif /* MS_WIN32 */
     
    245245get_progpath(void)
    246246{
    247         extern char *Py_GetProgramName(void);
    248         char *path = getenv("PATH");
    249         char *prog = Py_GetProgramName();
    250 
    251 #ifdef MS_WIN32
    252         if (GetModuleFileName(NULL, progpath, MAXPATHLEN))
    253                 return;
    254 #endif
    255         if (prog == NULL || *prog == '\0')
    256                 prog = "python";
    257 
    258         /* If there is no slash in the argv0 path, then we have to
    259         * assume python is on the user's $PATH, since there's no
    260         * other way to find a directory to start the search from.  If
    261         * $PATH isn't exported, you lose.
    262         */
     247    extern char *Py_GetProgramName(void);
     248    char *path = getenv("PATH");
     249    char *prog = Py_GetProgramName();
     250
     251#ifdef MS_WIN32
     252    if (GetModuleFileName(NULL, progpath, MAXPATHLEN))
     253        return;
     254#endif
     255    if (prog == NULL || *prog == '\0')
     256        prog = "python";
     257
     258    /* If there is no slash in the argv0 path, then we have to
     259    * assume python is on the user's $PATH, since there's no
     260    * other way to find a directory to start the search from.  If
     261    * $PATH isn't exported, you lose.
     262    */
    263263#ifdef ALTSEP
    264         if (strchr(prog, SEP) || strchr(prog, ALTSEP))
     264    if (strchr(prog, SEP) || strchr(prog, ALTSEP))
    265265#else
    266         if (strchr(prog, SEP))
    267 #endif
    268                 strcpy(progpath, prog);
    269         else if (path) {
    270                 while (1) {
    271                         char *delim = strchr(path, DELIM);
    272 
    273                         if (delim) {
    274                                 int len = delim - path;
    275                                 strncpy(progpath, path, len);
    276                                 *(progpath + len) = '\0';
    277                         }
    278                         else
    279                                 strcpy(progpath, path);
    280 
    281                         join(progpath, prog);
    282                         if (exists(progpath))
    283                                 break;
    284 
    285                         if (!delim) {
    286                                 progpath[0] = '\0';
    287                                 break;
    288                         }
    289                         path = delim + 1;
    290                 }
    291         }
    292         else
    293                 progpath[0] = '\0';
     266    if (strchr(prog, SEP))
     267#endif
     268        strcpy(progpath, prog);
     269    else if (path) {
     270        while (1) {
     271            char *delim = strchr(path, DELIM);
     272
     273            if (delim) {
     274                int len = delim - path;
     275                strncpy(progpath, path, len);
     276                *(progpath + len) = '\0';
     277            }
     278            else
     279                strcpy(progpath, path);
     280
     281            join(progpath, prog);
     282            if (exists(progpath))
     283                break;
     284
     285            if (!delim) {
     286                progpath[0] = '\0';
     287                break;
     288            }
     289            path = delim + 1;
     290        }
     291    }
     292    else
     293        progpath[0] = '\0';
    294294}
    295295
     
    297297calculate_path(void)
    298298{
    299         char argv0_path[MAXPATHLEN+1];
    300         char *buf;
    301         int bufsz;
    302         char *pythonhome = Py_GetPythonHome();
    303         char *envpath = Py_GETENV("PYTHONPATH");
    304 #ifdef MS_WIN32
    305         char *machinepath, *userpath;
    306 
    307         /* Are we running under Windows 3.1(1) Win32s? */
    308         if (PyWin_IsWin32s()) {
    309                 /* Only CLASSES_ROOT is supported */
    310                 machinepath = getpythonregpath(HKEY_CLASSES_ROOT, TRUE);
    311                 userpath = NULL;
    312         } else {
    313                 machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, FALSE);
    314                 userpath = getpythonregpath(HKEY_CURRENT_USER, FALSE);
    315         }
    316 #endif
    317 
    318         get_progpath();
    319         strcpy(argv0_path, progpath);
    320         reduce(argv0_path);
    321         if (pythonhome == NULL || *pythonhome == '\0') {
    322                 if (search_for_prefix(argv0_path, LANDMARK))
    323                         pythonhome = prefix;
    324                 else
    325                         pythonhome = NULL;
    326         }
    327         else {
    328         char *delim;
    329 
    330                 strcpy(prefix, pythonhome);
    331 
    332         /* Extract Any Optional Trailing EXEC_PREFIX */
    333         /* e.g. PYTHONHOME=<prefix>:<exec_prefix>   */
    334         delim = strchr(prefix, DELIM);
    335         if (delim) {
    336             *delim = '\0';
    337             strcpy(exec_prefix, delim+1);
    338         } else
    339             strcpy(exec_prefix, EXEC_PREFIX);
    340     }
    341 
    342         if (envpath && *envpath == '\0')
    343                 envpath = NULL;
    344 
    345         /* We need to construct a path from the following parts:
    346            (1) the PYTHONPATH environment variable, if set;
    347            (2) for Win32, the machinepath and userpath, if set;
    348            (3) the PYTHONPATH config macro, with the leading "."
    349                of each component replaced with pythonhome, if set;
    350            (4) the directory containing the executable (argv0_path).
    351            The length calculation calculates #3 first.
    352         */
    353 
    354         /* Calculate size of return buffer */
    355         if (pythonhome != NULL) {
    356                 char *p;
    357                 bufsz = 1;     
    358                 for (p = PYTHONPATH; *p; p++) {
    359                         if (*p == DELIM)
    360                                 bufsz++; /* number of DELIM plus one */
    361                 }
    362                 bufsz *= strlen(pythonhome);
    363         }
    364         else
    365                 bufsz = 0;
    366         bufsz += strlen(PYTHONPATH) + 1;
    367         if (envpath != NULL)
    368                 bufsz += strlen(envpath) + 1;
    369         bufsz += strlen(argv0_path) + 1;
    370 #ifdef MS_WIN32
    371         if (machinepath)
    372                 bufsz += strlen(machinepath) + 1;
    373         if (userpath)
    374                 bufsz += strlen(userpath) + 1;
    375 #endif
    376 
    377         module_search_path = buf = malloc(bufsz);
    378         if (buf == NULL) {
    379                 /* We can't exit, so print a warning and limp along */
    380                 fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
    381                 if (envpath) {
    382                         fprintf(stderr, "Using default static $PYTHONPATH.\n");
    383                         module_search_path = envpath;
    384                 }
    385                 else {
    386                         fprintf(stderr, "Using environment $PYTHONPATH.\n");
    387                         module_search_path = PYTHONPATH;
    388                 }
    389                 return;
    390         }
    391 
    392         if (envpath) {
    393                 strcpy(buf, envpath);
    394                 buf = strchr(buf, '\0');
    395                 *buf++ = DELIM;
    396         }
    397 #ifdef MS_WIN32
    398         if (machinepath) {
    399                 strcpy(buf, machinepath);
    400                 buf = strchr(buf, '\0');
    401                 *buf++ = DELIM;
    402         }
    403         if (userpath) {
    404                 strcpy(buf, userpath);
    405                 buf = strchr(buf, '\0');
    406                 *buf++ = DELIM;
    407         }
    408 #endif
    409         if (pythonhome == NULL) {
    410                 strcpy(buf, PYTHONPATH);
    411                 buf = strchr(buf, '\0');
    412         }
    413         else {
    414                 char *p = PYTHONPATH;
    415                 char *q;
    416                 int n;
    417                 for (;;) {
    418                         q = strchr(p, DELIM);
    419                         if (q == NULL)
    420                                 n = strlen(p);
    421                         else
    422                                 n = q-p;
    423                         if (p[0] == '.' && is_sep(p[1])) {
    424                                 strcpy(buf, pythonhome);
    425                                 buf = strchr(buf, '\0');
    426                                 p++;
    427                                 n--;
    428                         }
    429                         strncpy(buf, p, n);
    430                         buf += n;
    431                         if (q == NULL)
    432                                 break;
    433                         *buf++ = DELIM;
    434                         p = q+1;
    435                 }
    436         }
    437         if (argv0_path) {
    438                 *buf++ = DELIM;
    439                 strcpy(buf, argv0_path);
    440                 buf = strchr(buf, '\0');
    441         }
    442         *buf = '\0';
     299    char argv0_path[MAXPATHLEN+1];
     300    char *buf;
     301    int bufsz;
     302    char *pythonhome = Py_GetPythonHome();
     303    char *envpath = Py_GETENV("PYTHONPATH");
     304#ifdef MS_WIN32
     305    char *machinepath, *userpath;
     306
     307    /* Are we running under Windows 3.1(1) Win32s? */
     308    if (PyWin_IsWin32s()) {
     309        /* Only CLASSES_ROOT is supported */
     310        machinepath = getpythonregpath(HKEY_CLASSES_ROOT, TRUE);
     311        userpath = NULL;
     312    } else {
     313        machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, FALSE);
     314        userpath = getpythonregpath(HKEY_CURRENT_USER, FALSE);
     315    }
     316#endif
     317
     318    get_progpath();
     319    strcpy(argv0_path, progpath);
     320    reduce(argv0_path);
     321    if (pythonhome == NULL || *pythonhome == '\0') {
     322        if (search_for_prefix(argv0_path, LANDMARK))
     323            pythonhome = prefix;
     324        else
     325            pythonhome = NULL;
     326    }
     327    else {
     328    char *delim;
     329
     330        strcpy(prefix, pythonhome);
     331
     332    /* Extract Any Optional Trailing EXEC_PREFIX */
     333    /* e.g. PYTHONHOME=<prefix>:<exec_prefix>   */
     334    delim = strchr(prefix, DELIM);
     335    if (delim) {
     336        *delim = '\0';
     337        strcpy(exec_prefix, delim+1);
     338    } else
     339        strcpy(exec_prefix, EXEC_PREFIX);
     340    }
     341
     342    if (envpath && *envpath == '\0')
     343        envpath = NULL;
     344
     345    /* We need to construct a path from the following parts:
     346       (1) the PYTHONPATH environment variable, if set;
     347       (2) for Win32, the machinepath and userpath, if set;
     348       (3) the PYTHONPATH config macro, with the leading "."
     349           of each component replaced with pythonhome, if set;
     350       (4) the directory containing the executable (argv0_path).
     351       The length calculation calculates #3 first.
     352    */
     353
     354    /* Calculate size of return buffer */
     355    if (pythonhome != NULL) {
     356        char *p;
     357        bufsz = 1;
     358        for (p = PYTHONPATH; *p; p++) {
     359            if (*p == DELIM)
     360                bufsz++; /* number of DELIM plus one */
     361        }
     362        bufsz *= strlen(pythonhome);
     363    }
     364    else
     365        bufsz = 0;
     366    bufsz += strlen(PYTHONPATH) + 1;
     367    if (envpath != NULL)
     368        bufsz += strlen(envpath) + 1;
     369    bufsz += strlen(argv0_path) + 1;
     370#ifdef MS_WIN32
     371    if (machinepath)
     372        bufsz += strlen(machinepath) + 1;
     373    if (userpath)
     374        bufsz += strlen(userpath) + 1;
     375#endif
     376
     377    module_search_path = buf = malloc(bufsz);
     378    if (buf == NULL) {
     379        /* We can't exit, so print a warning and limp along */
     380        fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
     381        if (envpath) {
     382            fprintf(stderr, "Using default static $PYTHONPATH.\n");
     383            module_search_path = envpath;
     384        }
     385        else {
     386            fprintf(stderr, "Using environment $PYTHONPATH.\n");
     387            module_search_path = PYTHONPATH;
     388        }
     389        return;
     390    }
     391
     392    if (envpath) {
     393        strcpy(buf, envpath);
     394        buf = strchr(buf, '\0');
     395        *buf++ = DELIM;
     396    }
     397#ifdef MS_WIN32
     398    if (machinepath) {
     399        strcpy(buf, machinepath);
     400        buf = strchr(buf, '\0');
     401        *buf++ = DELIM;
     402    }
     403    if (userpath) {
     404        strcpy(buf, userpath);
     405        buf = strchr(buf, '\0');
     406        *buf++ = DELIM;
     407    }
     408#endif
     409    if (pythonhome == NULL) {
     410        strcpy(buf, PYTHONPATH);
     411        buf = strchr(buf, '\0');
     412    }
     413    else {
     414        char *p = PYTHONPATH;
     415        char *q;
     416        int n;
     417        for (;;) {
     418            q = strchr(p, DELIM);
     419            if (q == NULL)
     420                n = strlen(p);
     421            else
     422                n = q-p;
     423            if (p[0] == '.' && is_sep(p[1])) {
     424                strcpy(buf, pythonhome);
     425                buf = strchr(buf, '\0');
     426                p++;
     427                n--;
     428            }
     429            strncpy(buf, p, n);
     430            buf += n;
     431            if (q == NULL)
     432                break;
     433            *buf++ = DELIM;
     434            p = q+1;
     435        }
     436    }
     437    if (argv0_path) {
     438        *buf++ = DELIM;
     439        strcpy(buf, argv0_path);
     440        buf = strchr(buf, '\0');
     441    }
     442    *buf = '\0';
    443443}
    444444
     
    449449Py_GetPath(void)
    450450{
    451         if (!module_search_path)
    452                 calculate_path();
    453 
    454         return module_search_path;
     451    if (!module_search_path)
     452        calculate_path();
     453
     454    return module_search_path;
    455455}
    456456
     
    458458Py_GetPrefix(void)
    459459{
    460         if (!module_search_path)
    461                 calculate_path();
    462 
    463         return prefix;
     460    if (!module_search_path)
     461        calculate_path();
     462
     463    return prefix;
    464464}
    465465
     
    467467Py_GetExecPrefix(void)
    468468{
    469         if (!module_search_path)
    470                 calculate_path();
    471 
    472         return exec_prefix;
     469    if (!module_search_path)
     470        calculate_path();
     471
     472    return exec_prefix;
    473473}
    474474
     
    476476Py_GetProgramFullPath(void)
    477477{
    478         if (!module_search_path)
    479                 calculate_path();
    480 
    481         return progpath;
    482 }
     478    if (!module_search_path)
     479        calculate_path();
     480
     481    return progpath;
     482}
  • python/vendor/current/PC/os2vacpp/makefile

    r2 r388  
    204204                  $(PATHOBJ)\StructModule.obj  \
    205205                  $(PATHOBJ)\TimeModule.obj    \
    206                   $(PATHOBJ)\ThreadModule.obj  \
    207                   $(PATHOBJ)\YUVConvert.obj
     206                  $(PATHOBJ)\ThreadModule.obj
    208207
    209208# Standalone Parser Generator Program (Shares Some of Python's Modules)
     
    11141113         $(PY_INCLUDE)\python.h $(PY_INCLUDE)\pythonrun.h $(PY_INCLUDE)\rangeobject.h \
    11151114         $(PY_INCLUDE)\sliceobject.h $(PY_INCLUDE)\stringobject.h \
    1116          $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h $(PY_INCLUDE)\tupleobject.h \
    1117          $(PY_MODULES)\yuv.h
     1115         $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h $(PY_INCLUDE)\tupleobject.h
    11181116
    11191117syslogmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \
     
    11981196         $(PY_INCLUDE)\sliceobject.h $(PY_INCLUDE)\stringobject.h \
    11991197         $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h $(PY_INCLUDE)\tupleobject.h
    1200 
    1201 yuvconvert.obj: $(PY_MODULES)\yuv.h
    12021198
    12031199zlibmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h $(PY_INCLUDE)\classobject.h \
     
    16971693         $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \
    16981694         $(PY_INCLUDE)\tupleobject.h
    1699 
    1700 getmtime.obj: pyconfig.h
    17011695
    17021696getplatform.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \
  • python/vendor/current/PC/os2vacpp/makefile.omk

    r2 r388  
    165165                  StructModule.obj  \
    166166                  TimeModule.obj    \
    167                   ThreadModule.obj  \
    168                   YUVConvert.obj
     167                  ThreadModule.obj
    169168
    170169# Omitted Modules (and Description/Reason):
     
    804803         moduleobject.h mymalloc.h myproto.h object.h objimpl.h pydebug.h \
    805804         pyerrors.h pyfpe.h pystate.h python.h pythonrun.h rangeobject.h \
    806          sliceobject.h stringobject.h sysmodule.h traceback.h tupleobject.h \
    807          yuv.h
     805         sliceobject.h stringobject.h sysmodule.h traceback.h tupleobject.h
    808806
    809807syslogmodule.obj: abstract.h ceval.h classobject.h cobject.h \
     
    854852         pythonrun.h rangeobject.h sliceobject.h stringobject.h sysmodule.h \
    855853         traceback.h tupleobject.h
    856 
    857 yuvconvert.obj: yuv.h
    858854
    859855zlibmodule.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \
     
    11601156         stringobject.h sysmodule.h traceback.h tupleobject.h
    11611157
    1162 getmtime.obj: pyconfig.h
    1163 
    11641158getplatform.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \
    11651159         pyconfig.h dictobject.h fileobject.h floatobject.h funcobject.h \
  • python/vendor/current/PC/os2vacpp/python.def

    r2 r388  
    77               ; Data
    88               PyCFunction_Type
     9               PyCapsule_Type
    910               PyCObject_Type
    1011               PyClass_Type
     
    7677               _Py_ZeroStruct
    7778               _Py_abstract_hack
     79               _Py_capsule_hack
    7880               _Py_cobject_hack
    7981               _Py_re_syntax
     
    9092               PyCFunction_GetSelf
    9193               PyCFunction_New
     94               PyCapsule_GetContext
     95               PyCapsule_GetDestructor
     96               PyCapsule_GetName
     97               PyCapsule_GetPointer
     98               PyCapsule_Import
     99               PyCapsule_IsValid
     100               PyCapsule_New
     101               PyCapsule_SetContext
     102               PyCapsule_SetDestructor
     103               PyCapsule_SetName
     104               PyCapsule_SetPointer
    92105               PyCObject_AsVoidPtr
    93106               PyCObject_FromVoidPtrAndDesc
     
    285298               PyOS_AfterFork
    286299               PyOS_FiniInterrupts
    287                PyOS_GetLastModificationTime
    288300               PyOS_InitInterrupts
    289301               PyOS_InterruptOccurred
     
    370382               PyThreadState_New
    371383               PyThreadState_Swap
    372                PyThread__exit_thread
    373384               PyThread_acquire_lock
    374385               PyThread_allocate_lock
  • python/vendor/current/PC/pyconfig.h

    r2 r388  
    9696
    9797#ifdef MS_WINCE
    98 /* Python uses GetVersion() to distinguish between
    99  * Windows NT and 9x/ME where OS Unicode support is concerned.
    100  * Windows CE supports Unicode in the same way as NT so we
    101  * define the missing GetVersion() accordingly.
    102  */
    103 #define GetVersion() (4)
    10498/* Windows CE does not support environment variables */
    10599#define getenv(v) (NULL)
     
    330324                        taken care of by distutils.) */
    331325#                       ifdef _DEBUG
    332 #                               pragma comment(lib,"python26_d.lib")
     326#                               pragma comment(lib,"python27_d.lib")
    333327#                       else
    334 #                               pragma comment(lib,"python26.lib")
     328#                               pragma comment(lib,"python27.lib")
    335329#                       endif /* _DEBUG */
    336330#               endif /* _MSC_VER */
     
    349343#       define SIZEOF_HKEY 8
    350344#       define SIZEOF_SIZE_T 8
    351 /* configure.in defines HAVE_LARGEFILE_SUPPORT iff HAVE_LONG_LONG,
     345/* configure.ac defines HAVE_LARGEFILE_SUPPORT iff HAVE_LONG_LONG,
    352346   sizeof(off_t) > sizeof(long), and sizeof(PY_LONG_LONG) >= sizeof(off_t).
    353347   On Win64 the second condition is not true, but if fpos_t replaces off_t
     
    401395#endif
    402396
     397/* define signed and unsigned exact-width 32-bit and 64-bit types, used in the
     398   implementation of Python long integers. */
     399#ifndef PY_UINT32_T
     400#if SIZEOF_INT == 4
     401#define HAVE_UINT32_T 1
     402#define PY_UINT32_T unsigned int
     403#elif SIZEOF_LONG == 4
     404#define HAVE_UINT32_T 1
     405#define PY_UINT32_T unsigned long
     406#endif
     407#endif
     408
     409#ifndef PY_UINT64_T
     410#if SIZEOF_LONG_LONG == 8
     411#define HAVE_UINT64_T 1
     412#define PY_UINT64_T unsigned PY_LONG_LONG
     413#endif
     414#endif
     415
     416#ifndef PY_INT32_T
     417#if SIZEOF_INT == 4
     418#define HAVE_INT32_T 1
     419#define PY_INT32_T int
     420#elif SIZEOF_LONG == 4
     421#define HAVE_INT32_T 1
     422#define PY_INT32_T long
     423#endif
     424#endif
     425
     426#ifndef PY_INT64_T
     427#if SIZEOF_LONG_LONG == 8
     428#define HAVE_INT64_T 1
     429#define PY_INT64_T PY_LONG_LONG
     430#endif
     431#endif
     432
    403433/* Fairly standard from here! */
    404434
     
    530560#define Py_UNICODE_SIZE 2
    531561
    532 /* Define to indicate that the Python Unicode representation can be passed
    533    as-is to Win32 Wide API.  */
    534 #define Py_WIN_WIDE_FILENAMES
    535 
    536562/* Use Python's own small-block memory-allocator. */
    537563#define WITH_PYMALLOC 1
     
    617643#define HAVE_WCSCOLL 1
    618644#endif
     645
     646/* Define if the zlib library has inflateCopy */
     647#define HAVE_ZLIB_COPY 1
    619648
    620649/* Define if you have the <dlfcn.h> header file.  */
     
    724753#define Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
    725754
     755/* Define if C doubles are 64-bit IEEE 754 binary format, stored with the
     756   least significant byte first */
     757#define DOUBLE_IS_LITTLE_ENDIAN_IEEE754 1
     758
    726759#endif /* !Py_CONFIG_H */
  • python/vendor/current/PC/python_nt.rc

    r2 r388  
    6262            VALUE "FileVersion", PYTHON_VERSION
    6363            VALUE "InternalName", "Python DLL\0"
    64             VALUE "LegalCopyright", "Copyright © 2001-2010 Python Software Foundation. Copyright © 2000 BeOpen.com. Copyright © 1995-2001 CNRI. Copyright © 1991-1995 SMC.\0"
     64            VALUE "LegalCopyright", "Copyright © 2001-2008 Python Software Foundation. Copyright © 2000 BeOpen.com. Copyright © 1995-2001 CNRI. Copyright © 1991-1995 SMC.\0"
    6565            VALUE "OriginalFilename", PYTHON_DLL_NAME "\0"
    6666            VALUE "ProductName", "Python\0"
  • python/vendor/current/PC/winsound.c

    r2 r388  
    7979
    8080    if(!PyArg_ParseTuple(args,"z#i:PlaySound",&sound,&length,&flags)) {
    81         return NULL;
     81    return NULL;
    8282    }
    8383
    8484    if(flags&SND_ASYNC && flags &SND_MEMORY) {
    85         /* Sidestep reference counting headache; unfortunately this also
    86            prevent SND_LOOP from memory. */
    87         PyErr_SetString(PyExc_RuntimeError,"Cannot play asynchronously from memory");
    88         return NULL;
     85    /* Sidestep reference counting headache; unfortunately this also
     86       prevent SND_LOOP from memory. */
     87    PyErr_SetString(PyExc_RuntimeError,"Cannot play asynchronously from memory");
     88    return NULL;
    8989    }
    9090
     
    9494    if(!ok)
    9595    {
    96         PyErr_SetString(PyExc_RuntimeError,"Failed to play sound");
    97         return NULL;
     96    PyErr_SetString(PyExc_RuntimeError,"Failed to play sound");
     97    return NULL;
    9898    }
    9999
     
    105105sound_beep(PyObject *self, PyObject *args)
    106106{
    107         int freq;
    108         int dur;
    109         BOOL ok;
     107    int freq;
     108    int dur;
     109    BOOL ok;
    110110
    111         if (!PyArg_ParseTuple(args, "ii:Beep", &freq,  &dur))
    112                 return NULL;
     111    if (!PyArg_ParseTuple(args, "ii:Beep", &freq,  &dur))
     112        return NULL;
    113113
    114         if (freq < 37 || freq > 32767) {
    115                 PyErr_SetString(PyExc_ValueError,
    116                                 "frequency must be in 37 thru 32767");
    117                 return NULL;
    118         }
     114    if (freq < 37 || freq > 32767) {
     115        PyErr_SetString(PyExc_ValueError,
     116                        "frequency must be in 37 thru 32767");
     117        return NULL;
     118    }
    119119
    120         Py_BEGIN_ALLOW_THREADS
    121         ok = Beep(freq, dur);
    122         Py_END_ALLOW_THREADS
    123         if (!ok) {
    124                 PyErr_SetString(PyExc_RuntimeError,"Failed to beep");
    125                 return NULL;
    126         }
     120    Py_BEGIN_ALLOW_THREADS
     121    ok = Beep(freq, dur);
     122    Py_END_ALLOW_THREADS
     123    if (!ok) {
     124        PyErr_SetString(PyExc_RuntimeError,"Failed to beep");
     125        return NULL;
     126    }
    127127
    128         Py_INCREF(Py_None);
    129         return Py_None;
     128    Py_INCREF(Py_None);
     129    return Py_None;
    130130}
    131131
     
    133133sound_msgbeep(PyObject *self, PyObject *args)
    134134{
    135         int x = MB_OK;
    136         if (!PyArg_ParseTuple(args, "|i:MessageBeep", &x))
    137                 return NULL;
    138         MessageBeep(x);
    139         Py_INCREF(Py_None);
    140         return Py_None;
     135    int x = MB_OK;
     136    if (!PyArg_ParseTuple(args, "|i:MessageBeep", &x))
     137        return NULL;
     138    MessageBeep(x);
     139    Py_INCREF(Py_None);
     140    return Py_None;
    141141}
    142142
     
    156156    if(v&&k)
    157157    {
    158         PyDict_SetItem(dict,k,v);
     158    PyDict_SetItem(dict,k,v);
    159159    }
    160160    Py_XDECREF(k);
     
    167167initwinsound(void)
    168168{
    169         PyObject *dict;
    170         PyObject *module = Py_InitModule3("winsound",
    171                                           sound_methods,
    172                                           sound_module_doc);
    173         if (module == NULL)
    174                 return;
    175         dict = PyModule_GetDict(module);
     169    PyObject *dict;
     170    PyObject *module = Py_InitModule3("winsound",
     171                                      sound_methods,
     172                                      sound_module_doc);
     173    if (module == NULL)
     174        return;
     175    dict = PyModule_GetDict(module);
    176176
    177         ADD_DEFINE(SND_ASYNC);
    178         ADD_DEFINE(SND_NODEFAULT);
    179         ADD_DEFINE(SND_NOSTOP);
    180         ADD_DEFINE(SND_NOWAIT);
    181         ADD_DEFINE(SND_ALIAS);
    182         ADD_DEFINE(SND_FILENAME);
    183         ADD_DEFINE(SND_MEMORY);
    184         ADD_DEFINE(SND_PURGE);
    185         ADD_DEFINE(SND_LOOP);
    186         ADD_DEFINE(SND_APPLICATION);
     177    ADD_DEFINE(SND_ASYNC);
     178    ADD_DEFINE(SND_NODEFAULT);
     179    ADD_DEFINE(SND_NOSTOP);
     180    ADD_DEFINE(SND_NOWAIT);
     181    ADD_DEFINE(SND_ALIAS);
     182    ADD_DEFINE(SND_FILENAME);
     183    ADD_DEFINE(SND_MEMORY);
     184    ADD_DEFINE(SND_PURGE);
     185    ADD_DEFINE(SND_LOOP);
     186    ADD_DEFINE(SND_APPLICATION);
    187187
    188         ADD_DEFINE(MB_OK);
    189         ADD_DEFINE(MB_ICONASTERISK);
    190         ADD_DEFINE(MB_ICONEXCLAMATION);
    191         ADD_DEFINE(MB_ICONHAND);
    192         ADD_DEFINE(MB_ICONQUESTION);
     188    ADD_DEFINE(MB_OK);
     189    ADD_DEFINE(MB_ICONASTERISK);
     190    ADD_DEFINE(MB_ICONEXCLAMATION);
     191    ADD_DEFINE(MB_ICONHAND);
     192    ADD_DEFINE(MB_ICONQUESTION);
    193193}
Note: See TracChangeset for help on using the changeset viewer.