diff --git a/.gitignore b/.gitignore index 8c8273fc7a3aa3..f568cd9fa82208 100644 --- a/.gitignore +++ b/.gitignore @@ -92,6 +92,7 @@ Programs/_testembed PC/python_nt*.h PC/pythonnt_rc*.h Modules/python.exp +PC/pyconfig.h PC/*/*.exp PC/*/*.lib PC/*/*.bsc diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py index 2a6813f00bccc6..69c676584582f3 100644 --- a/Lib/test/test_sysconfig.py +++ b/Lib/test/test_sysconfig.py @@ -472,9 +472,10 @@ def test_srcdir(self): # should be a full source checkout. Python_h = os.path.join(srcdir, 'Include', 'Python.h') self.assertTrue(os.path.exists(Python_h), Python_h) - # /PC/pyconfig.h always exists even if unused on POSIX. - pyconfig_h = os.path.join(srcdir, 'PC', 'pyconfig.h') - self.assertTrue(os.path.exists(pyconfig_h), pyconfig_h) + if os.name == 'nt': + # /PC/pyconfig.h only exists on Windows. + pyconfig_h = os.path.join(srcdir, 'PC', 'pyconfig.h') + self.assertTrue(os.path.exists(pyconfig_h), pyconfig_h) pyconfig_h_in = os.path.join(srcdir, 'pyconfig.h.in') self.assertTrue(os.path.exists(pyconfig_h_in), pyconfig_h_in) elif os.name == 'posix': diff --git a/Misc/NEWS.d/next/Windows/2023-11-16-16-19-51.gh-issue-111650.zdWe-n.rst b/Misc/NEWS.d/next/Windows/2023-11-16-16-19-51.gh-issue-111650.zdWe-n.rst new file mode 100644 index 00000000000000..eefa1f0c5e7ccc --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2023-11-16-16-19-51.gh-issue-111650.zdWe-n.rst @@ -0,0 +1,2 @@ +On Windows, ``PC\pyconfig.h`` is now generated from ``PC\pyconfig.h.in`` +during the build process. diff --git a/PC/pyconfig.h b/PC/pyconfig.h.in similarity index 99% rename from PC/pyconfig.h rename to PC/pyconfig.h.in index e6b368caffe280..1508e0280fc02d 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h.in @@ -1,7 +1,7 @@ #ifndef Py_CONFIG_H #define Py_CONFIG_H -/* pyconfig.h. NOT Generated automatically by configure. +/* pyconfig.h.in. This is a manually maintained version used for the Watcom, Borland and Microsoft Visual C++ compilers. It is a @@ -710,6 +710,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Define to 1 if you have the `erfc' function. */ #define HAVE_ERFC 1 +/* Define if you want to disable the GIL */ +#undef Py_GIL_DISABLED + // netdb.h functions (provided by winsock.h) #define HAVE_GETHOSTNAME 1 #define HAVE_GETHOSTBYADDR 1 diff --git a/PCbuild/generate_pyconfig.ps1 b/PCbuild/generate_pyconfig.ps1 new file mode 100644 index 00000000000000..525a3582e12f65 --- /dev/null +++ b/PCbuild/generate_pyconfig.ps1 @@ -0,0 +1,50 @@ +# +# Generates pyconfig.h from PC\pyconfig.h.in +# + +param ( + [string[]]$define, + [string]$File +) + +$definedValues = @{} + +foreach ($arg in $define) { + $parts = $arg -split '=' + + if ($parts.Count -eq 1) { + $key = $parts[0] + $definedValues[$key] = "" + } elseif ($parts.Count -eq 2) { + $key = $parts[0] + $value = $parts[1] + $definedValues[$key] = $value + } else { + Write-Host "Invalid argument: $arg" + exit 1 + } +} + +$cpythonRoot = Split-Path $PSScriptRoot -Parent +$pyconfigPath = Join-Path $cpythonRoot "PC\pyconfig.h.in" + +$header = "/* pyconfig.h. Generated from PC\pyconfig.h.in by generate_pyconfig.ps1. */" + +$lines = Get-Content -Path $pyconfigPath +$lines = @($header) + $lines + +foreach ($i in 0..($lines.Length - 1)) { + if ($lines[$i] -match "^#undef (\w+)$") { + $key = $Matches[1] + if ($definedValues.ContainsKey($key)) { + $value = $definedValues[$key] + $lines[$i] = "#define $key $value".TrimEnd() + } else { + $lines[$i] = "/* #undef $key */" + } + } +} + +$ParentDir = Split-Path -Path $File -Parent +New-Item -ItemType Directory -Force -Path $ParentDir | Out-Null +Set-Content -Path $File -Value $lines diff --git a/PCbuild/pcbuild.proj b/PCbuild/pcbuild.proj index b7b78be768d7ec..fb5b9912d80808 100644 --- a/PCbuild/pcbuild.proj +++ b/PCbuild/pcbuild.proj @@ -3,6 +3,7 @@ + {CC9B93A2-439D-4058-9D29-6DCF43774405} Win32 @@ -14,6 +15,7 @@ true true false + Py_GIL_DISABLED=1,$(PyConfigArgs) @@ -94,6 +96,11 @@ + + + + +