Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7686c75

Browse files
authored
[3.14]gh-133779: Revert Windows generation of pyconfig.h and go back to a static header. (GH-133966)
Extension builders must specify Py_GIL_DISABLED if they want to link to the free-threaded builds.This was usually the case already, but this change guarantees it in all circumstances.
1 parent89b744a commit7686c75

File tree

13 files changed

+68
-78
lines changed

13 files changed

+68
-78
lines changed

‎Doc/howto/free-threading-extensions.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ You can use it to enable code that only runs under the free-threaded build::
2323
/* code that only runs in the free-threaded build */
2424
#endif
2525

26+
..note::
27+
28+
On Windows, this macro is not defined automatically, but must be specified
29+
to the compiler when building. The:func:`sysconfig.get_config_var` function
30+
can be used to determine whether the current running interpreter had the
31+
macro defined.
32+
33+
2634
Module Initialization
2735
=====================
2836

‎Doc/whatsnew/3.14.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,12 @@ Kumar Aditya, Edgar Margffoy, and many others.
829829
Some of these contributors are employed by Meta, which has continued to provide
830830
significant engineering resources to support this project.
831831

832+
From 3.14, when compiling extension modules for the free-threaded build of
833+
CPython on Windows, the preprocessor variable ``Py_GIL_DISABLED`` now needs to
834+
be specified by the build backend, as it will no longer be determined
835+
automatically by the C compiler. For a running interpreter, the setting that
836+
was used at compile time can be found using:func:`sysconfig.get_config_var`.
837+
832838

833839
.. _whatsnew314-pyrepl-highlighting:
834840

‎Include/Python.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@
5959
# include<intrin.h>// __readgsqword()
6060
#endif
6161

62+
// Suppress known warnings in Python header files.
63+
#if defined(_MSC_VER)
64+
// Warning that alignas behaviour has changed. Doesn't affect us, because we
65+
// never relied on the old behaviour.
66+
#pragma warning(push)
67+
#pragma warning(disable: 5274)
68+
#endif
69+
6270
// Include Python header files
6371
#include"pyport.h"
6472
#include"pymacro.h"
@@ -138,4 +146,9 @@
138146
#include"cpython/pyfpe.h"
139147
#include"cpython/tracemalloc.h"
140148

149+
// Restore warning filter
150+
#ifdef_MSC_VER
151+
#pragma warning(pop)
152+
#endif
153+
141154
#endif/* !Py_PYTHON_H */

‎Lib/sysconfig/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def get_config_h_filename():
468468
"""Return the path of pyconfig.h."""
469469
if_PYTHON_BUILD:
470470
ifos.name=="nt":
471-
inc_dir=os.path.dirname(sys._base_executable)
471+
inc_dir=os.path.join(_PROJECT_BASE,'PC')
472472
else:
473473
inc_dir=_PROJECT_BASE
474474
else:

‎Lib/test/test_sysconfig.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,10 @@ def test_srcdir(self):
531531
Python_h=os.path.join(srcdir,'Include','Python.h')
532532
self.assertTrue(os.path.exists(Python_h),Python_h)
533533
# <srcdir>/PC/pyconfig.h.in always exists even if unused
534-
pyconfig_h=os.path.join(srcdir,'PC','pyconfig.h.in')
535-
self.assertTrue(os.path.exists(pyconfig_h),pyconfig_h)
536534
pyconfig_h_in=os.path.join(srcdir,'pyconfig.h.in')
537535
self.assertTrue(os.path.exists(pyconfig_h_in),pyconfig_h_in)
538536
ifos.name=='nt':
539-
# <executable dir>/pyconfig.h exists on Windows in a build tree
540-
pyconfig_h=os.path.join(sys.executable,'..','pyconfig.h')
537+
pyconfig_h=os.path.join(srcdir,'PC','pyconfig.h')
541538
self.assertTrue(os.path.exists(pyconfig_h),pyconfig_h)
542539
elifos.name=='posix':
543540
makefile_dir=os.path.dirname(sysconfig.get_makefile_filename())
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Reverts the change to generate different:file:`pyconfig.h` files based on
2+
compiler settings, as it was frequently causing extension builds to break.
3+
In particular, the ``Py_GIL_DISABLED`` preprocessor variable must now always
4+
be defined explicitly when compiling for the experimental free-threaded
5+
runtime. The:func:`sysconfig.get_config_var` function can be used to
6+
determine whether the current runtime was compiled with that flag or not.

‎PC/pyconfig.h.inrenamed to‎PC/pyconfig.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,22 @@ WIN32 is still required for the locale module.
9494
#endif
9595
#endif/* Py_BUILD_CORE || Py_BUILD_CORE_BUILTIN || Py_BUILD_CORE_MODULE */
9696

97-
/* Define to 1 if you want to disable the GIL */
98-
/* Uncomment the definition for free-threaded builds, or define it manually
99-
* when compiling extension modules. Note that we test with #ifdef, so
100-
* defining as 0 will still disable the GIL. */
101-
#ifndefPy_GIL_DISABLED
102-
/* #define Py_GIL_DISABLED 1 */
97+
/* _DEBUG implies Py_DEBUG */
98+
#ifdef_DEBUG
99+
# definePy_DEBUG 1
100+
#endif
101+
102+
/* Define to 1 when compiling for experimental free-threaded builds */
103+
#ifdefPy_GIL_DISABLED
104+
/* We undefine if it was set to zero because all later checks are #ifdef.
105+
* Note that non-Windows builds do not do this, and so every effort should
106+
* be made to avoid defining the variable at all when not desired. However,
107+
* sysconfig.get_config_var always returns a 1 or a 0, and so it seems likely
108+
* that a build backend will define it with the value.
109+
*/
110+
#ifPy_GIL_DISABLED==0
111+
#undef Py_GIL_DISABLED
112+
#endif
103113
#endif
104114

105115
/* Compiler specific defines */

‎PCbuild/_freeze_module.vcxproj

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@
276276
<ClCompileInclude="..\Python\uniqueid.c" />
277277
</ItemGroup>
278278
<ItemGroup>
279-
<ClIncludeInclude="..\PC\pyconfig.h.in" />
279+
<ClIncludeInclude="..\PC\pyconfig.h" />
280280
</ItemGroup>
281281
<ItemGroup>
282282
<!-- BEGIN frozen modules-->
@@ -436,31 +436,6 @@
436436
<ImportGroupLabel="ExtensionTargets">
437437
</ImportGroup>
438438

439-
<!-- Direct copy from pythoncore.vcxproj, but this one is only used for our
440-
own build. All other extension modules will use the copy that pythoncore
441-
generates.-->
442-
<TargetName="_UpdatePyconfig"BeforeTargets="PrepareForBuild">
443-
<MakeDirDirectories="$(IntDir)"Condition="!Exists($(IntDir))" />
444-
<ItemGroup>
445-
<PyConfigHRemove="@(PyConfigH)" />
446-
<PyConfigHInclude="@(ClInclude)"Condition="'%(Filename)%(Extension)' == 'pyconfig.h.in'" />
447-
</ItemGroup>
448-
<ErrorText="Did not find pyconfig.h"Condition="@(ClInclude) == ''" />
449-
<PropertyGroup>
450-
<PyConfigH>@(PyConfigH->'%(FullPath)', ';')</PyConfigH>
451-
<PyConfigHText>$([System.IO.File]::ReadAllText($(PyConfigH)))</PyConfigHText>
452-
<OldPyConfigHCondition="Exists('$(IntDir)pyconfig.h')">$([System.IO.File]::ReadAllText('$(IntDir)pyconfig.h'))</OldPyConfigH>
453-
</PropertyGroup>
454-
<PropertyGroupCondition="$(DisableGil) == 'true'">
455-
<PyConfigHText>$(PyConfigHText.Replace('/* #define Py_GIL_DISABLED 1 */', '#define Py_GIL_DISABLED 1'))</PyConfigHText>
456-
</PropertyGroup>
457-
<MessageText="Updating pyconfig.h"Condition="$(PyConfigHText.TrimEnd()) != $(OldPyConfigH.TrimEnd())" />
458-
<WriteLinesToFileFile="$(IntDir)pyconfig.h"
459-
Lines="$(PyConfigHText)"
460-
Overwrite="true"
461-
Condition="$(PyConfigHText.TrimEnd()) != $(OldPyConfigH.TrimEnd())" />
462-
</Target>
463-
464439
<TargetName="_RebuildGetPath"AfterTargets="_RebuildFrozen"Condition="$(Configuration) != 'PGUpdate'">
465440
<ExecCommand='"$(TargetPath)" "%(GetPath.ModName)" "%(GetPath.FullPath)" "%(GetPath.IntFile)"' />
466441

‎PCbuild/pyproject.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
<Py_IntDirCondition="'$(Py_IntDir)' == ''">$(MSBuildThisFileDirectory)obj\</Py_IntDir>
1111
<IntDir>$(Py_IntDir)\$(MajorVersionNumber)$(MinorVersionNumber)$(ArchName)_$(Configuration)\$(ProjectName)\</IntDir>
1212
<IntDir>$(IntDir.Replace(`\\`, `\`))</IntDir>
13-
<!-- pyconfig.h is updated by pythoncore.vcxproj, so it's always in pythoncore's IntDir-->
14-
<GeneratedPyConfigDir>$(Py_IntDir)\$(MajorVersionNumber)$(MinorVersionNumber)$(ArchName)_$(Configuration)\pythoncore\</GeneratedPyConfigDir>
1513
<GeneratedFrozenModulesDir>$(Py_IntDir)\$(MajorVersionNumber)$(MinorVersionNumber)_frozen\</GeneratedFrozenModulesDir>
1614
<GeneratedZlibNgDir>$(Py_IntDir)\$(MajorVersionNumber)$(MinorVersionNumber)$(ArchName)_$(Configuration)\zlib-ng\</GeneratedZlibNgDir>
15+
<GeneratedJitStencilsDir>$(Py_IntDir)\$(MajorVersionNumber)$(MinorVersionNumber)_$(Configuration)</GeneratedJitStencilsDir>
1716
<TargetNameCondition="'$(TargetName)' == ''">$(ProjectName)</TargetName>
1817
<TargetName>$(TargetName)$(PyDebugExt)</TargetName>
1918
<GenerateManifest>false</GenerateManifest>
@@ -49,11 +48,12 @@
4948
<_PlatformPreprocessorDefinitionCondition="$(Platform) == 'x64'">_WIN64;</_PlatformPreprocessorDefinition>
5049
<_PlatformPreprocessorDefinitionCondition="$(Platform) == 'x64' and $(PlatformToolset) != 'ClangCL'">_M_X64;$(_PlatformPreprocessorDefinition)</_PlatformPreprocessorDefinition>
5150
<_Py3NamePreprocessorDefinition>PY3_DLLNAME=L"$(Py3DllName)$(PyDebugExt)";</_Py3NamePreprocessorDefinition>
51+
<_FreeThreadedPreprocessorDefinitionCondition="$(DisableGil) == 'true'">Py_GIL_DISABLED=1;</_FreeThreadedPreprocessorDefinition>
5252
</PropertyGroup>
5353
<ItemDefinitionGroup>
5454
<ClCompile>
55-
<AdditionalIncludeDirectories>$(PySourcePath)Include;$(PySourcePath)Include\internal;$(PySourcePath)Include\internal\mimalloc;$(GeneratedPyConfigDir);$(PySourcePath)PC;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
56-
<PreprocessorDefinitions>WIN32;$(_Py3NamePreprocessorDefinition);$(_PlatformPreprocessorDefinition)$(_DebugPreprocessorDefinition)$(_PyStatsPreprocessorDefinition)$(_PydPreprocessorDefinition)%(PreprocessorDefinitions)</PreprocessorDefinitions>
55+
<AdditionalIncludeDirectories>$(PySourcePath)Include;$(PySourcePath)Include\internal;$(PySourcePath)Include\internal\mimalloc;$(PySourcePath)PC;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
56+
<PreprocessorDefinitions>WIN32;$(_Py3NamePreprocessorDefinition)$(_PlatformPreprocessorDefinition)$(_DebugPreprocessorDefinition)$(_PyStatsPreprocessorDefinition)$(_PydPreprocessorDefinition)$(_FreeThreadedPreprocessorDefinition)%(PreprocessorDefinitions)</PreprocessorDefinitions>
5757
<PreprocessorDefinitionsCondition="'$(SupportPGO)' and ($(Configuration) == 'PGInstrument' or $(Configuration) == 'PGUpdate')">_Py_USING_PGO=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
5858

5959
<Optimization>MaxSpeed</Optimization>

‎PCbuild/pythoncore.vcxproj

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<AdditionalOptions>/Zm200 %(AdditionalOptions)</AdditionalOptions>
103103
<AdditionalIncludeDirectories>$(PySourcePath)Modules\_hacl;$(PySourcePath)Modules\_hacl\include;$(PySourcePath)Python;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
104104
<AdditionalIncludeDirectoriesCondition="$(IncludeExternals)">$(zlibNgDir);$(GeneratedZlibNgDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
105+
<AdditionalIncludeDirectoriesCondition="'$(UseJIT)' == 'true'">$(GeneratedJitStencilsDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
105106
<PreprocessorDefinitions>_USRDLL;Py_BUILD_CORE;Py_BUILD_CORE_BUILTIN;Py_ENABLE_SHARED;MS_DLL_ID="$(SysWinVer)";ZLIB_COMPAT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
106107
<PreprocessorDefinitionsCondition="$(IncludeExternals)">_Py_HAVE_ZLIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107108
<PreprocessorDefinitionsCondition="'$(UseJIT)' == 'true'">_Py_JIT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -409,7 +410,7 @@
409410
<ClIncludeInclude="..\Parser\string_parser.h" />
410411
<ClIncludeInclude="..\Parser\pegen.h" />
411412
<ClIncludeInclude="..\PC\errmap.h" />
412-
<ClIncludeInclude="..\PC\pyconfig.h.in" />
413+
<ClIncludeInclude="..\PC\pyconfig.h" />
413414
<ClIncludeInclude="..\Python\condvar.h" />
414415
<ClIncludeInclude="..\Python\stdlib_module_names.h" />
415416
<ClIncludeInclude="..\Python\thread_nt.h" />
@@ -688,34 +689,6 @@
688689
</ImportGroup>
689690
<TargetName="_TriggerRegen"BeforeTargets="PrepareForBuild"DependsOnTargets="Regen" />
690691

691-
<TargetName="_UpdatePyconfig"BeforeTargets="PrepareForBuild">
692-
<MakeDirDirectories="$(IntDir)"Condition="!Exists($(IntDir))" />
693-
<ItemGroup>
694-
<PyConfigHRemove="@(PyConfigH)" />
695-
<PyConfigHInclude="@(ClInclude)"Condition="'%(Filename)%(Extension)' == 'pyconfig.h.in'" />
696-
</ItemGroup>
697-
<ErrorText="Did not find pyconfig.h"Condition="@(ClInclude) == ''" />
698-
<PropertyGroup>
699-
<PyConfigH>@(PyConfigH->'%(FullPath)', ';')</PyConfigH>
700-
<PyConfigHText>$([System.IO.File]::ReadAllText($(PyConfigH)))</PyConfigHText>
701-
<OldPyConfigHCondition="Exists('$(IntDir)pyconfig.h')">$([System.IO.File]::ReadAllText('$(IntDir)pyconfig.h'))</OldPyConfigH>
702-
</PropertyGroup>
703-
<PropertyGroupCondition="$(DisableGil) == 'true'">
704-
<PyConfigHText>$(PyConfigHText.Replace('/* #define Py_GIL_DISABLED 1 */', '#define Py_GIL_DISABLED 1'))</PyConfigHText>
705-
</PropertyGroup>
706-
<MessageText="Updating pyconfig.h"Condition="$(PyConfigHText.TrimEnd()) != $(OldPyConfigH.TrimEnd())" />
707-
<WriteLinesToFileFile="$(IntDir)pyconfig.h"
708-
Lines="$(PyConfigHText)"
709-
Overwrite="true"
710-
Condition="$(PyConfigHText.TrimEnd()) != $(OldPyConfigH.TrimEnd())" />
711-
</Target>
712-
<TargetName="_CopyPyconfig"Inputs="$(IntDir)pyconfig.h"Outputs="$(OutDir)pyconfig.h"AfterTargets="Build"DependsOnTargets="_UpdatePyconfig">
713-
<CopySourceFiles="$(IntDir)pyconfig.h"DestinationFolder="$(OutDir)" />
714-
</Target>
715-
<TargetName="_CleanPyconfig"AfterTargets="Clean">
716-
<DeleteFiles="$(IntDir)pyconfig.h;$(OutDir)pyconfig.h" />
717-
</Target>
718-
719692
<TargetName="_GetBuildInfo"BeforeTargets="PrepareForBuild">
720693
<PropertyGroup>
721694
<GITCondition="$(GIT) == ''">git</GIT>

‎PCbuild/regen.targets

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
<_KeywordSourcesInclude="$(PySourcePath)Grammar\python.gram;$(PySourcePath)Grammar\Tokens" />
3030
<_KeywordOutputsInclude="$(PySourcePath)Lib\keyword.py" />
3131
<!-- Taken from _Target._compute_digest in Tools\jit\_targets.py:-->
32-
<_JITSourcesInclude="$(PySourcePath)Python\executor_cases.c.h;$(GeneratedPyConfigDir)pyconfig.h;$(PySourcePath)Tools\jit\**"/>
32+
<_JITSourcesInclude="$(PySourcePath)Python\executor_cases.c.h;$(PySourcePath)PC\pyconfig.h;$(PySourcePath)Tools\jit\**"/>
3333
<!-- Need to explicitly enumerate these, since globbing doesn't work for missing outputs:-->
34-
<_JITOutputsInclude="$(GeneratedPyConfigDir)jit_stencils.h"/>
35-
<_JITOutputsInclude="$(GeneratedPyConfigDir)jit_stencils-aarch64-pc-windows-msvc.h"Condition="$(Platform) == 'ARM64'"/>
36-
<_JITOutputsInclude="$(GeneratedPyConfigDir)jit_stencils-i686-pc-windows-msvc.h"Condition="$(Platform) == 'Win32'"/>
37-
<_JITOutputsInclude="$(GeneratedPyConfigDir)jit_stencils-x86_64-pc-windows-msvc.h"Condition="$(Platform) == 'x64'"/>
34+
<_JITOutputsInclude="$(GeneratedJitStencilsDir)jit_stencils.h"/>
35+
<_JITOutputsInclude="$(GeneratedJitStencilsDir)jit_stencils-aarch64-pc-windows-msvc.h"Condition="$(Platform) == 'ARM64'"/>
36+
<_JITOutputsInclude="$(GeneratedJitStencilsDir)jit_stencils-i686-pc-windows-msvc.h"Condition="$(Platform) == 'Win32'"/>
37+
<_JITOutputsInclude="$(GeneratedJitStencilsDir)jit_stencils-x86_64-pc-windows-msvc.h"Condition="$(Platform) == 'x64'"/>
3838
<_CasesSourcesInclude="$(PySourcePath)Python\bytecodes.c;$(PySourcePath)Python\optimizer_bytecodes.c;"/>
3939
<_CasesOutputsInclude="$(PySourcePath)Python\generated_cases.c.h;$(PySourcePath)Include\opcode_ids.h;$(PySourcePath)Include\internal\pycore_uop_ids.h;$(PySourcePath)Python\opcode_targets.h;$(PySourcePath)Include\internal\pycore_opcode_metadata.h;$(PySourcePath)Include\internal\pycore_uop_metadata.h;$(PySourcePath)Python\optimizer_cases.c.h;$(PySourcePath)Lib\_opcode_metadata.py"/>
4040
<_SbomSourcesInclude="$(PySourcePath)PCbuild\get_externals.bat" />
@@ -116,7 +116,7 @@
116116

117117
<TargetName="_RegenJIT"
118118
Condition="'$(UseJIT)' == 'true'"
119-
DependsOnTargets="_UpdatePyconfig;FindPythonForBuild"
119+
DependsOnTargets="FindPythonForBuild"
120120
Inputs="@(_JITSources)"
121121
Outputs="@(_JITOutputs)">
122122
<PropertyGroup>
@@ -126,7 +126,7 @@
126126
<JITArgsCondition="$(Configuration) == 'Debug'">$(JITArgs) --debug</JITArgs>
127127
</PropertyGroup>
128128
<ExecCommand='$(PythonForBuild) "$(PySourcePath)Tools\jit\build.py" $(JITArgs)'
129-
WorkingDirectory="$(GeneratedPyConfigDir)"/>
129+
WorkingDirectory="$(GeneratedJitStencilsDir)"/>
130130
</Target>
131131
<TargetName="_CleanJIT"AfterTargets="Clean">
132132
<DeleteFiles="@(_JITOutputs)"/>

‎Tools/msi/dev/dev_files.wxs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Fragment>
44
<ComponentGroupId="dev_pyconfig">
55
<ComponentId="include_pyconfig.h"Directory="include"Guid="*">
6-
<FileId="include_pyconfig.h"Name="pyconfig.h"Source="pyconfig.h"KeyPath="yes" />
6+
<FileId="include_pyconfig.h"Name="pyconfig.h"Source="!(bindpath.src)PC\pyconfig.h"KeyPath="yes" />
77
</Component>
88
</ComponentGroup>
99
</Fragment>

‎Tools/peg_generator/pegen/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def compile_c_extension(
108108
extra_compile_args.append("-DPy_BUILD_CORE_MODULE")
109109
# Define _Py_TEST_PEGEN to not call PyAST_Validate() in Parser/pegen.c
110110
extra_compile_args.append("-D_Py_TEST_PEGEN")
111+
ifsys.platform=="win32"andsysconfig.get_config_var("Py_GIL_DISABLED"):
112+
extra_compile_args.append("-DPy_GIL_DISABLED")
111113
extra_link_args=get_extra_flags("LDFLAGS","PY_LDFLAGS_NODIST")
112114
ifkeep_asserts:
113115
extra_compile_args.append("-UNDEBUG")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp