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

Commit2e92edb

Browse files
authored
gh-106320: Remove private _PyImport C API functions (#106383)
* Remove private _PyImport C API functions: move them to the internal C API (pycore_import.h).* No longer export most of these private functions.* _testcapi avoids private _PyImport_GetModuleAttrString().
1 parentf6d2bb1 commit2e92edb

File tree

8 files changed

+46
-22
lines changed

8 files changed

+46
-22
lines changed

‎Include/cpython/import.h‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,6 @@
44

55
PyMODINIT_FUNCPyInit__imp(void);
66

7-
PyAPI_FUNC(int)_PyImport_IsInitialized(PyInterpreterState*);
8-
9-
PyAPI_FUNC(PyObject*)_PyImport_GetModuleId(_Py_Identifier*name);
10-
PyAPI_FUNC(int)_PyImport_SetModule(PyObject*name,PyObject*module);
11-
PyAPI_FUNC(int)_PyImport_SetModuleString(constchar*name,PyObject*module);
12-
13-
PyAPI_FUNC(void)_PyImport_AcquireLock(PyInterpreterState*interp);
14-
PyAPI_FUNC(int)_PyImport_ReleaseLock(PyInterpreterState*interp);
15-
16-
PyAPI_FUNC(int)_PyImport_FixupBuiltin(
17-
PyObject*mod,
18-
constchar*name,/* UTF-8 encoded string */
19-
PyObject*modules
20-
);
21-
PyAPI_FUNC(int)_PyImport_FixupExtensionObject(PyObject*,PyObject*,
22-
PyObject*,PyObject*);
23-
247
struct_inittab {
258
constchar*name;/* ASCII encoded string */
269
PyObject* (*initfunc)(void);
@@ -41,6 +24,3 @@ struct _frozen {
4124
collection of frozen modules: */
4225

4326
PyAPI_DATA(conststruct_frozen*)PyImport_FrozenModules;
44-
45-
PyAPI_DATA(PyObject*)_PyImport_GetModuleAttr(PyObject*,PyObject*);
46-
PyAPI_DATA(PyObject*)_PyImport_GetModuleAttrString(constchar*,constchar*);

‎Include/internal/pycore_import.h‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ extern "C" {
77

88
#include"pycore_time.h"// _PyTime_t
99

10+
externint_PyImport_IsInitialized(PyInterpreterState*);
11+
12+
PyAPI_FUNC(PyObject*)_PyImport_GetModuleId(_Py_Identifier*name);
13+
PyAPI_FUNC(int)_PyImport_SetModule(PyObject*name,PyObject*module);
14+
PyAPI_FUNC(int)_PyImport_SetModuleString(constchar*name,PyObject*module);
15+
16+
externvoid_PyImport_AcquireLock(PyInterpreterState*interp);
17+
externint_PyImport_ReleaseLock(PyInterpreterState*interp);
18+
19+
externint_PyImport_FixupBuiltin(
20+
PyObject*mod,
21+
constchar*name,/* UTF-8 encoded string */
22+
PyObject*modules
23+
);
24+
externint_PyImport_FixupExtensionObject(PyObject*,PyObject*,
25+
PyObject*,PyObject*);
26+
27+
PyAPI_DATA(PyObject*)_PyImport_GetModuleAttr(PyObject*,PyObject*);
28+
PyAPI_DATA(PyObject*)_PyImport_GetModuleAttrString(constchar*,constchar*);
29+
1030

1131
struct_import_runtime_state {
1232
/* The builtin modules (defined in config.c). */

‎Modules/_elementtree.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
*--------------------------------------------------------------------
1212
*/
1313

14+
#ifndefPy_BUILD_CORE_BUILTIN
15+
# definePy_BUILD_CORE_MODULE 1
16+
#endif
17+
1418
#include"Python.h"
19+
#include"pycore_import.h"// _PyImport_GetModuleAttrString()
1520
#include"structmember.h"// PyMemberDef
1621
#include"expat.h"
1722
#include"pyexpat.h"

‎Modules/_sqlite/connection.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include"blob.h"
3434
#include"prepare_protocol.h"
3535
#include"util.h"
36+
#include"pycore_import.h"// _PyImport_GetModuleAttrString()
3637
#include"pycore_weakref.h"// _PyWeakref_IS_DEAD()
3738

3839
#include<stdbool.h>

‎Modules/_sqlite/module.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
* 3. This notice may not be removed or altered from any source distribution.
2222
*/
2323

24+
#ifndefPy_BUILD_CORE_BUILTIN
25+
# definePy_BUILD_CORE_MODULE 1
26+
#endif
27+
2428
#include"connection.h"
2529
#include"statement.h"
2630
#include"cursor.h"
@@ -29,6 +33,8 @@
2933
#include"row.h"
3034
#include"blob.h"
3135

36+
#include"pycore_import.h"// _PyImport_GetModuleAttrString()
37+
3238
#ifSQLITE_VERSION_NUMBER<3015002
3339
#error "SQLite 3.15.2 or higher required"
3440
#endif

‎Modules/_testcapimodule.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,9 +1267,15 @@ test_pep3118_obsolete_write_locks(PyObject* self, PyObject *Py_UNUSED(ignored))
12671267
if (ret!=-1||match==0)
12681268
gotoerror;
12691269

1270+
PyObject*mod_io=PyImport_ImportModule("_io");
1271+
if (mod_io==NULL) {
1272+
returnNULL;
1273+
}
1274+
12701275
/* bytesiobuf_getbuffer() */
1271-
PyTypeObject*type= (PyTypeObject*)_PyImport_GetModuleAttrString(
1272-
"_io","_BytesIOBuffer");
1276+
PyTypeObject*type= (PyTypeObject*)PyObject_GetAttrString(
1277+
mod_io,"_BytesIOBuffer");
1278+
Py_DECREF(mod_io);
12731279
if (type==NULL) {
12741280
returnNULL;
12751281
}

‎Modules/cjkcodecs/cjkcodecs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include"Python.h"
1515
#include"multibytecodec.h"
16+
#include"pycore_import.h"// _PyImport_GetModuleAttrString()
1617

1718

1819
/* a unicode "undefined" code point */

‎Modules/pyexpat.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
#ifndefPy_BUILD_CORE_BUILTIN
2+
# definePy_BUILD_CORE_MODULE 1
3+
#endif
4+
15
#include"Python.h"
6+
#include"pycore_import.h"// _PyImport_SetModule()
27
#include<ctype.h>
38

49
#include"structmember.h"// PyMemberDef

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp