port: advance MSVC600 CPython compatibility frontier

This commit is contained in:
RayPals
2026-08-22 17:36:38 +00:00
parent a7a9560e5c
commit 824b4f0d24
15 changed files with 6150 additions and 41 deletions
File diff suppressed because it is too large Load Diff
+84
View File
@@ -0,0 +1,84 @@
#ifndef PYWIN9X_COMPAT_MSVC600_PATHCCH_H
#define PYWIN9X_COMPAT_MSVC600_PATHCCH_H
/*
* Narrow PathCchFindExtension compatibility for the VC6/MSVC600 probe.
*
* CPython 3.11's Modules/getpath.c includes <pathcch.h> only to call
* PathCchFindExtension() from getpath_isxfile(). MSVC 6.0's Windows SDK
* predates PathCch, so provide just that one API shape for the project-local
* VC6 include path. Modern builds should keep using the platform SDK header;
* this file is not installed into CPython or a system include directory.
*/
#if defined(_MSC_VER) && _MSC_VER <= 1200
#ifndef _WINDOWS_
#include <windows.h>
#endif
#include <stddef.h>
#ifndef PCWSTR
typedef const WCHAR *PCWSTR;
#endif
#ifndef PWSTR
typedef WCHAR *PWSTR;
#endif
#ifndef S_OK
#define S_OK ((HRESULT)0L)
#endif
#ifndef E_INVALIDARG
#define E_INVALIDARG ((HRESULT)0x80070057L)
#endif
static HRESULT
PathCchFindExtension(PCWSTR pszPath, size_t cchPath, PCWSTR *ppszExt)
{
size_t i;
size_t last_sep;
size_t last_dot;
int have_dot;
if (pszPath == NULL || ppszExt == NULL || cchPath == 0) {
return E_INVALIDARG;
}
last_sep = 0;
last_dot = 0;
have_dot = 0;
for (i = 0; i < cchPath; ++i) {
WCHAR ch = pszPath[i];
if (ch == L'\0') {
if (have_dot) {
*ppszExt = pszPath + last_dot;
}
else {
*ppszExt = pszPath + i;
}
return S_OK;
}
if (ch == L'\\' || ch == L'/' || ch == L':') {
last_sep = i + 1;
have_dot = 0;
}
else if (ch == L'.' && i >= last_sep) {
last_dot = i;
have_dot = 1;
}
}
*ppszExt = NULL;
return E_INVALIDARG;
}
#else
/*
* This compatibility header is intentionally scoped to VC6. If a modern
* compiler finds it, the include path is wrong: use the real Windows SDK
* pathcch.h instead to avoid shadowing the platform declaration.
*/
#error "compat/msvc600/pathcch.h is only for MSVC 6.0; use the Windows SDK pathcch.h on modern compilers"
#endif
#endif /* PYWIN9X_COMPAT_MSVC600_PATHCCH_H */
+45
View File
@@ -0,0 +1,45 @@
#ifndef PYTHON_WIN9X_MSVC600_STDINT_H
#define PYTHON_WIN9X_MSVC600_STDINT_H
/* VC6-only fallback for the C99 <stdint.h> header.
*
* Visual C++ 6.0 (_MSC_VER 1200) predates C99 and ships no <stdint.h>. This
* project-local header is found ahead of any system <stdint.h> only because
* compat/msvc600 is placed first on the VC6 probe scripts' include path
* (scripts/vc6-probe.sh, scripts/vc6-probe-core.sh, scripts/vc6-probe-
* pythoncore-frontier.sh); it is never installed anywhere a standards-
* conforming compiler's own <stdint.h> would be found instead, so it never
* shadows a real one.
*
* First consumer: cpython/Modules/_blake2/impl/blake2.h and
* blake2-impl.h, which use only uint8_t, uint32_t, and uint64_t (verified
* by grepping every fixed-width identifier used across Modules/_blake2/,
* including the blake2b/blake2s/*-ref.c reference implementations and
* clinic-generated wrappers: no int8_t/int16_t/int32_t/int64_t or intptr_t/
* uintptr_t appear anywhere in that tree). `size_t` is used too, but that
* already comes from <stddef.h>, which VC6 has natively.
*
* compat/msvc600/inttypes.h already defines exactly these typedefs (plus
* the PRI* macros CPython's own Include/pyport.h needs from a real C99
* <inttypes.h>) for this same VC6 target. Rather than re-declaring
* uint8_t/uint32_t/uint64_t a second time under a second include guard
* (which would risk a duplicate-typedef error in any translation unit that
* ends up including both this header and <inttypes.h>, e.g. anything that
* pulls in both Python.h and a <stdint.h>-using third-party header like
* blake2.h), this header just forwards to it. inttypes.h's own include
* guard makes this forwarding idempotent no matter which of the two headers
* a given translation unit reaches first.
*
* Width assumptions (all already relied upon by inttypes.h and unchanged
* here): uint8_t = unsigned char (1 byte), uint32_t = unsigned long
* (4 bytes on Win32/ILP32), uint64_t = unsigned __int64 (VC6's non-standard
* 64-bit extension, 8 bytes). These match the sizes BLAKE2 requires.
*/
#if !defined(_MSC_VER) || _MSC_VER >= 1300
#error "compat/msvc600/stdint.h is a VC6-only (_MSC_VER < 1300) fallback; a standard <stdint.h> should be used instead."
#endif
#include "inttypes.h"
#endif /* PYTHON_WIN9X_MSVC600_STDINT_H */