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

Commit23bace2

Browse files
authored
bpo-36635: Add _testinternalcapi module (GH-12841)
Add a new _testinternalcapi module to test the internal C API.Move _Py_GetConfigsAsDict() function to the internal C API:_testembed now uses _testinternalcapi to access the function.
1 parent11efd79 commit23bace2

File tree

13 files changed

+172
-49
lines changed

13 files changed

+172
-49
lines changed

‎Include/cpython/coreconfig.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,6 @@ typedef struct {
408408
._init_main = 1}
409409
/* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
410410

411-
412-
/* --- Function used for testing ---------------------------------- */
413-
414-
PyAPI_FUNC(PyObject*)_Py_GetConfigsAsDict(void);
415-
416411
#ifdef__cplusplus
417412
}
418413
#endif

‎Include/internal/pycore_coreconfig.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config,
110110
const_PyArgv*args);
111111
PyAPI_FUNC(void)_PyCoreConfig_Write(const_PyCoreConfig*config);
112112

113+
114+
/* --- Function used for testing ---------------------------------- */
115+
116+
PyAPI_FUNC(PyObject*)_Py_GetConfigsAsDict(void);
117+
113118
#ifdef__cplusplus
114119
}
115120
#endif

‎Lib/test/pythoninfo.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def collect_get_config(info_add):
598598
# Dump global configuration variables, _PyCoreConfig
599599
# and _PyMainInterpreterConfig
600600
try:
601-
from_testcapiimportget_configs
601+
from_testinternalcapiimportget_configs
602602
exceptImportError:
603603
return
604604

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a new:mod:`_testinternalcapi` module to test the internal C API.

‎Modules/Setup‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ _symtable symtablemodule.c
173173
#_struct _struct.c# binary structure packing/unpacking
174174
#_weakref _weakref.c# basic weak reference support
175175
#_testcapi _testcapimodule.c # Python C API test module
176+
#_testinternalcapi _testinternalcapi.c -I$(srcdir)/Include/internal -DPy_BUILD_CORE_MODULE # Python internal C API test module
176177
#_random _randommodule.c# Random number generator
177178
#_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c# elementtree accelerator
178179
#_pickle _pickle.c# pickle accelerator

‎Modules/_testcapimodule.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4736,13 +4736,6 @@ decode_locale_ex(PyObject *self, PyObject *args)
47364736
}
47374737

47384738

4739-
staticPyObject*
4740-
get_configs(PyObject*self,PyObject*Py_UNUSED(args))
4741-
{
4742-
return_Py_GetConfigsAsDict();
4743-
}
4744-
4745-
47464739
#ifdefPy_REF_DEBUG
47474740
staticPyObject*
47484741
negative_refcount(PyObject*self,PyObject*Py_UNUSED(args))
@@ -4990,7 +4983,6 @@ static PyMethodDef TestMethods[] = {
49904983
{"bad_get", (PyCFunction)(void(*)(void))bad_get,METH_FASTCALL},
49914984
{"EncodeLocaleEx",encode_locale_ex,METH_VARARGS},
49924985
{"DecodeLocaleEx",decode_locale_ex,METH_VARARGS},
4993-
{"get_configs",get_configs,METH_NOARGS},
49944986
#ifdefPy_REF_DEBUG
49954987
{"negative_refcount",negative_refcount,METH_NOARGS},
49964988
#endif

‎Modules/_testinternalcapi.c‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* C Extension module to test Python internal C APIs (Include/internal).
3+
*/
4+
5+
#if !defined(Py_BUILD_CORE_BUILTIN)&& !defined(Py_BUILD_CORE_MODULE)
6+
# error "Py_BUILD_CORE_BUILTIN or Py_BUILD_CORE_MODULE must be defined"
7+
#endif
8+
9+
#definePY_SSIZE_T_CLEAN
10+
11+
#include"Python.h"
12+
#include"pycore_coreconfig.h"
13+
14+
15+
staticPyObject*
16+
get_configs(PyObject*self,PyObject*Py_UNUSED(args))
17+
{
18+
return_Py_GetConfigsAsDict();
19+
}
20+
21+
22+
staticPyMethodDefTestMethods[]= {
23+
{"get_configs",get_configs,METH_NOARGS},
24+
{NULL,NULL}/* sentinel */
25+
};
26+
27+
28+
staticstructPyModuleDef_testcapimodule= {
29+
PyModuleDef_HEAD_INIT,
30+
"_testinternalcapi",
31+
NULL,
32+
-1,
33+
TestMethods,
34+
NULL,
35+
NULL,
36+
NULL,
37+
NULL
38+
};
39+
40+
41+
PyMODINIT_FUNC
42+
PyInit__testinternalcapi(void)
43+
{
44+
returnPyModule_Create(&_testcapimodule);
45+
}

‎PCbuild/_testinternalcapi.vcxproj‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ProjectDefaultTargets="Build"ToolsVersion="4.0"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroupLabel="ProjectConfigurations">
4+
<ProjectConfigurationInclude="Debug|ARM">
5+
<Configuration>Debug</Configuration>
6+
<Platform>ARM</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfigurationInclude="Debug|Win32">
9+
<Configuration>Debug</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfigurationInclude="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfigurationInclude="PGInstrument|ARM">
17+
<Configuration>PGInstrument</Configuration>
18+
<Platform>ARM</Platform>
19+
</ProjectConfiguration>
20+
<ProjectConfigurationInclude="PGInstrument|Win32">
21+
<Configuration>PGInstrument</Configuration>
22+
<Platform>Win32</Platform>
23+
</ProjectConfiguration>
24+
<ProjectConfigurationInclude="PGInstrument|x64">
25+
<Configuration>PGInstrument</Configuration>
26+
<Platform>x64</Platform>
27+
</ProjectConfiguration>
28+
<ProjectConfigurationInclude="PGUpdate|ARM">
29+
<Configuration>PGUpdate</Configuration>
30+
<Platform>ARM</Platform>
31+
</ProjectConfiguration>
32+
<ProjectConfigurationInclude="PGUpdate|Win32">
33+
<Configuration>PGUpdate</Configuration>
34+
<Platform>Win32</Platform>
35+
</ProjectConfiguration>
36+
<ProjectConfigurationInclude="PGUpdate|x64">
37+
<Configuration>PGUpdate</Configuration>
38+
<Platform>x64</Platform>
39+
</ProjectConfiguration>
40+
<ProjectConfigurationInclude="Release|ARM">
41+
<Configuration>Release</Configuration>
42+
<Platform>ARM</Platform>
43+
</ProjectConfiguration>
44+
<ProjectConfigurationInclude="Release|Win32">
45+
<Configuration>Release</Configuration>
46+
<Platform>Win32</Platform>
47+
</ProjectConfiguration>
48+
<ProjectConfigurationInclude="Release|x64">
49+
<Configuration>Release</Configuration>
50+
<Platform>x64</Platform>
51+
</ProjectConfiguration>
52+
</ItemGroup>
53+
<PropertyGroupLabel="Globals">
54+
<ProjectGuid>{900342D7-516A-4469-B1AD-59A66E49A25F}</ProjectGuid>
55+
<RootNamespace>_testinternalcapi</RootNamespace>
56+
<Keyword>Win32Proj</Keyword>
57+
<SupportPGO>false</SupportPGO>
58+
</PropertyGroup>
59+
<ImportProject="python.props" />
60+
<ImportProject="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
61+
<PropertyGroupLabel="Configuration">
62+
<ConfigurationType>DynamicLibrary</ConfigurationType>
63+
<CharacterSet>NotSet</CharacterSet>
64+
</PropertyGroup>
65+
<ImportProject="$(VCTargetsPath)\Microsoft.Cpp.props" />
66+
<PropertyGroup>
67+
<TargetExt>.pyd</TargetExt>
68+
</PropertyGroup>
69+
<ImportGroupLabel="ExtensionSettings">
70+
</ImportGroup>
71+
<ImportGroupLabel="PropertySheets">
72+
<ImportProject="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"Label="LocalAppDataPlatform" />
73+
<ImportProject="pyproject.props" />
74+
</ImportGroup>
75+
<PropertyGroupLabel="UserMacros" />
76+
<PropertyGroup>
77+
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
78+
</PropertyGroup>
79+
<ItemGroup>
80+
<ClCompileInclude="..\Modules\_testinternalcapi.c" />
81+
</ItemGroup>
82+
<ItemGroup>
83+
<ResourceCompileInclude="..\PC\python_nt.rc" />
84+
</ItemGroup>
85+
<ItemGroup>
86+
<ProjectReferenceInclude="pythoncore.vcxproj">
87+
<Project>{cf7ac3d1-e2df-41d2-bea6-1e2556cdea26}</Project>
88+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
89+
</ProjectReference>
90+
</ItemGroup>
91+
<ImportProject="$(VCTargetsPath)\Microsoft.Cpp.targets" />
92+
<ImportGroupLabel="ExtensionTargets">
93+
</ImportGroup>
94+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ProjectToolsVersion="4.0"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<FilterInclude="Source Files">
5+
<UniqueIdentifier>{136fc5eb-7fe4-4486-8c6d-b49f37a00199}</UniqueIdentifier>
6+
</Filter>
7+
</ItemGroup>
8+
<ItemGroup>
9+
<ClCompileInclude="..\Modules\_testinternalcapi.c">
10+
<Filter>Source Files</Filter>
11+
</ClCompile>
12+
</ItemGroup>
13+
</Project>

‎PCbuild/pcbuild.proj‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@
6262
<ExtensionModulesInclude="@(ExternalModules->'%(Identity)')"Condition="$(IncludeExternals)" />
6363
<ProjectsInclude="@(ExtensionModules->'%(Identity).vcxproj')"Condition="$(IncludeExtensions)" />
6464
<!-- Test modules-->
65-
<TestModulesInclude="_ctypes_test;_testbuffer;_testcapi;_testembed;_testimportmultiple;_testmultiphase;_testconsole" />
65+
<TestModulesInclude="_ctypes_test;_testbuffer;_testcapi;_testinternalcapi;_testembed;_testimportmultiple;_testmultiphase;_testconsole" />
6666
<TestModulesInclude="xxlimited"Condition="'$(Configuration)' == 'Release'" />
6767
<ProjectsInclude="@(TestModules->'%(Identity).vcxproj')"Condition="$(IncludeTests)">
6868
<!-- Disable parallel build for test modules-->
6969
<BuildInParallel>false</BuildInParallel>
7070
</Projects>
71-
71+
7272
<!-- _freeze_importlib-->
7373
<Projects2Condition="$(Platform) != 'ARM'"Include="_freeze_importlib.vcxproj" />
7474
<!-- python[w].exe-->

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp