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

gh-85283: Build _testconsole extension with limited C API#117125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:mainfromvstinner:test_console
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionDoc/whatsnew/3.13.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1527,7 +1527,7 @@ Build Changes
* The ``errno``, ``fcntl``, ``grp``, ``md5``, ``pwd``, ``resource``,
``termios``, ``winsound``,
``_ctypes_test``, ``_multiprocessing.posixshmem``, ``_scproxy``, ``_stat``,
``_statistics``, ``_testimportmultiple`` and ``_uuid``
``_statistics``, ``_testconsole``, ``_testimportmultiple`` and ``_uuid``
C extensions are now built with the
:ref:`limited C API <limited-c-api>`.
(Contributed by Victor Stinner in :gh:`85283`.)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
The ``fcntl``, ``grp``, ``pwd``, ``termios`` and ``_statistics`` C extensions are now
built with the :ref:`limited C API <limited-c-api>`. Patch by Victor Stinner.
The ``fcntl``, ``grp``, ``pwd``, ``termios``, ``_statistics`` and
``_testconsole`` C extensions are now built with the :ref:`limited C API
<limited-c-api>`. Patch by Victor Stinner.
35 changes: 20 additions & 15 deletionsPC/_testconsole.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
/* Testing module for multi-phase initialization of extension modules (PEP 489)
*/

#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
#include "pyconfig.h" // Py_GIL_DISABLED
#ifndef Py_GIL_DISABLED
# define Py_LIMITED_API 0x030c0000
#endif

#include "Python.h"

#ifdef MS_WINDOWS

#include "pycore_fileutils.h" // _Py_get_osfhandle()
#include "pycore_runtime.h" // _Py_ID()

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <fcntl.h>
Expand DownExpand Up@@ -57,20 +56,24 @@ module _testconsole

_testconsole.write_input
file: object
s:PyBytesObject
s:Py_buffer

Writes UTF-16-LE encoded bytes to the console as if typed by a user.
[clinic start generated code]*/

static PyObject *
_testconsole_write_input_impl(PyObject *module, PyObject *file,
PyBytesObject *s)
/*[clinic end generated code: output=48f9563db34aedb3 input=4c774f2d05770bc6]*/
_testconsole_write_input_impl(PyObject *module, PyObject *file, Py_buffer *s)
/*[clinic end generated code: output=58631a8985426ad3 input=68062f1bb2e52206]*/
{
INPUT_RECORD *rec = NULL;

PyTypeObject *winconsoleio_type = (PyTypeObject *)_PyImport_GetModuleAttr(
&_Py_ID(_io), &_Py_ID(_WindowsConsoleIO));
PyObject *mod = PyImport_ImportModule("_io");
if (mod == NULL) {
return NULL;
}

PyTypeObject *winconsoleio_type = (PyTypeObject *)PyObject_GetAttrString(mod, "_WindowsConsoleIO");
Py_DECREF(mod);
if (winconsoleio_type == NULL) {
return NULL;
}
Expand All@@ -81,8 +84,8 @@ _testconsole_write_input_impl(PyObject *module, PyObject *file,
return NULL;
}

const wchar_t *p = (const wchar_t *)PyBytes_AS_STRING(s);
DWORD size = (DWORD)PyBytes_GET_SIZE(s) / sizeof(wchar_t);
const wchar_t *p = (const wchar_t *)s->buf;
DWORD size = (DWORD)s->len / sizeof(wchar_t);

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

HANDLE hInput = _Py_get_osfhandle(((winconsoleio*)file)->fd);
if (hInput == INVALID_HANDLE_VALUE)
HANDLE hInput = (HANDLE)_get_osfhandle(((winconsoleio*)file)->fd);
if (hInput == INVALID_HANDLE_VALUE) {
PyErr_SetFromErrno(PyExc_OSError);
goto error;
}

DWORD total = 0;
while (total < size) {
Expand Down
99 changes: 19 additions & 80 deletionsPC/clinic/_testconsole.c.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.


[8]ページ先頭

©2009-2025 Movatter.jp