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

Commitabdd1f9

Browse files
authored
gh-85283: Build _testconsole extension with limited C API (#117125)
1 parent8bea6c4 commitabdd1f9

File tree

4 files changed

+43
-98
lines changed

4 files changed

+43
-98
lines changed

‎Doc/whatsnew/3.13.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ Build Changes
15271527
* The ``errno``, ``fcntl``, ``grp``, ``md5``, ``pwd``, ``resource``,
15281528
``termios``, ``winsound``,
15291529
``_ctypes_test``, ``_multiprocessing.posixshmem``, ``_scproxy``, ``_stat``,
1530-
``_statistics``, ``_testimportmultiple`` and ``_uuid``
1530+
``_statistics``, ``_testconsole``, ``_testimportmultiple`` and ``_uuid``
15311531
C extensions are now built with the
15321532
:ref:`limited C API<limited-c-api>`.
15331533
(Contributed by Victor Stinner in:gh:`85283`.)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
The ``fcntl``, ``grp``, ``pwd``, ``termios`` and ``_statistics`` C extensions are now
2-
built with the:ref:`limited C API<limited-c-api>`. Patch by Victor Stinner.
1+
The ``fcntl``, ``grp``, ``pwd``, ``termios``, ``_statistics`` and
2+
``_testconsole`` C extensions are now built with the:ref:`limited C API
3+
<limited-c-api>`. Patch by Victor Stinner.

‎PC/_testconsole.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/* Testing module for multi-phase initialization of extension modules (PEP 489)
22
*/
33

4-
#ifndefPy_BUILD_CORE_BUILTIN
5-
# definePy_BUILD_CORE_MODULE 1
4+
// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
5+
#include"pyconfig.h"// Py_GIL_DISABLED
6+
#ifndefPy_GIL_DISABLED
7+
# definePy_LIMITED_API 0x030c0000
68
#endif
79

810
#include"Python.h"
911

1012
#ifdefMS_WINDOWS
1113

12-
#include"pycore_fileutils.h"// _Py_get_osfhandle()
13-
#include"pycore_runtime.h"// _Py_ID()
14-
1514
#defineWIN32_LEAN_AND_MEAN
1615
#include<windows.h>
1716
#include<fcntl.h>
@@ -57,20 +56,24 @@ module _testconsole
5756
5857
_testconsole.write_input
5958
file: object
60-
s:PyBytesObject
59+
s:Py_buffer
6160
6261
Writes UTF-16-LE encoded bytes to the console as if typed by a user.
6362
[clinic start generated code]*/
6463

6564
staticPyObject*
66-
_testconsole_write_input_impl(PyObject*module,PyObject*file,
67-
PyBytesObject*s)
68-
/*[clinic end generated code: output=48f9563db34aedb3 input=4c774f2d05770bc6]*/
65+
_testconsole_write_input_impl(PyObject*module,PyObject*file,Py_buffer*s)
66+
/*[clinic end generated code: output=58631a8985426ad3 input=68062f1bb2e52206]*/
6967
{
7068
INPUT_RECORD*rec=NULL;
7169

72-
PyTypeObject*winconsoleio_type= (PyTypeObject*)_PyImport_GetModuleAttr(
73-
&_Py_ID(_io),&_Py_ID(_WindowsConsoleIO));
70+
PyObject*mod=PyImport_ImportModule("_io");
71+
if (mod==NULL) {
72+
returnNULL;
73+
}
74+
75+
PyTypeObject*winconsoleio_type= (PyTypeObject*)PyObject_GetAttrString(mod,"_WindowsConsoleIO");
76+
Py_DECREF(mod);
7477
if (winconsoleio_type==NULL) {
7578
returnNULL;
7679
}
@@ -81,8 +84,8 @@ _testconsole_write_input_impl(PyObject *module, PyObject *file,
8184
returnNULL;
8285
}
8386

84-
constwchar_t*p= (constwchar_t*)PyBytes_AS_STRING(s);
85-
DWORDsize= (DWORD)PyBytes_GET_SIZE(s) /sizeof(wchar_t);
87+
constwchar_t*p= (constwchar_t*)s->buf;
88+
DWORDsize= (DWORD)s->len /sizeof(wchar_t);
8689

8790
rec= (INPUT_RECORD*)PyMem_Calloc(size,sizeof(INPUT_RECORD));
8891
if (!rec)
@@ -96,9 +99,11 @@ _testconsole_write_input_impl(PyObject *module, PyObject *file,
9699
prec->Event.KeyEvent.uChar.UnicodeChar=*p;
97100
}
98101

99-
HANDLEhInput=_Py_get_osfhandle(((winconsoleio*)file)->fd);
100-
if (hInput==INVALID_HANDLE_VALUE)
102+
HANDLEhInput= (HANDLE)_get_osfhandle(((winconsoleio*)file)->fd);
103+
if (hInput==INVALID_HANDLE_VALUE) {
104+
PyErr_SetFromErrno(PyExc_OSError);
101105
gotoerror;
106+
}
102107

103108
DWORDtotal=0;
104109
while (total<size) {

‎PC/clinic/_testconsole.c.h

Lines changed: 19 additions & 80 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp