summaryrefslogtreecommitdiffstats
path: root/Modules/clinic
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-03-14 12:01:13 (GMT)
committerGitHub <noreply@github.com>2024-03-14 12:01:13 (GMT)
commit97b80af897cd3376a5be66c8d5d63310723a1590 (patch)
tree1dcaf05b15529c2a9859305b9291d18228b6ae5f /Modules/clinic
parentf20dfb7569a769da50cd75f4932b9abe78e55d75 (diff)
downloadcpython-97b80af897cd3376a5be66c8d5d63310723a1590.zip
cpython-97b80af897cd3376a5be66c8d5d63310723a1590.tar.gz
cpython-97b80af897cd3376a5be66c8d5d63310723a1590.tar.bz2
gh-85283: Build fcntl extension with the limited C API (#116791)
Diffstat (limited to 'Modules/clinic')
-rw-r--r--Modules/clinic/fcntlmodule.c.h49
1 files changed, 33 insertions, 16 deletions
diff --git a/Modules/clinic/fcntlmodule.c.h b/Modules/clinic/fcntlmodule.c.h
index 5dc2fc0..d4846dd 100644
--- a/Modules/clinic/fcntlmodule.c.h
+++ b/Modules/clinic/fcntlmodule.c.h
@@ -2,9 +2,6 @@
preserve
[clinic start generated code]*/
-#include "pycore_fileutils.h" // _PyLong_FileDescriptor_Converter()
-#include "pycore_modsupport.h" // _PyArg_CheckPositional()
-
PyDoc_STRVAR(fcntl_fcntl__doc__,
"fcntl($module, fd, cmd, arg=0, /)\n"
"--\n"
@@ -22,7 +19,7 @@ PyDoc_STRVAR(fcntl_fcntl__doc__,
"corresponding to the return value of the fcntl call in the C code.");
#define FCNTL_FCNTL_METHODDEF \
- {"fcntl", _PyCFunction_CAST(fcntl_fcntl), METH_FASTCALL, fcntl_fcntl__doc__},
+ {"fcntl", (PyCFunction)(void(*)(void))fcntl_fcntl, METH_FASTCALL, fcntl_fcntl__doc__},
static PyObject *
fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg);
@@ -35,10 +32,16 @@ fcntl_fcntl(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
int code;
PyObject *arg = NULL;
- if (!_PyArg_CheckPositional("fcntl", nargs, 2, 3)) {
+ if (nargs < 2) {
+ PyErr_Format(PyExc_TypeError, "fcntl expected at least 2 arguments, got %zd", nargs);
+ goto exit;
+ }
+ if (nargs > 3) {
+ PyErr_Format(PyExc_TypeError, "fcntl expected at most 3 arguments, got %zd", nargs);
goto exit;
}
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
+ fd = PyObject_AsFileDescriptor(args[0]);
+ if (fd < 0) {
goto exit;
}
code = PyLong_AsInt(args[1]);
@@ -90,7 +93,7 @@ PyDoc_STRVAR(fcntl_ioctl__doc__,
"code.");
#define FCNTL_IOCTL_METHODDEF \
- {"ioctl", _PyCFunction_CAST(fcntl_ioctl), METH_FASTCALL, fcntl_ioctl__doc__},
+ {"ioctl", (PyCFunction)(void(*)(void))fcntl_ioctl, METH_FASTCALL, fcntl_ioctl__doc__},
static PyObject *
fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
@@ -105,10 +108,16 @@ fcntl_ioctl(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
PyObject *ob_arg = NULL;
int mutate_arg = 1;
- if (!_PyArg_CheckPositional("ioctl", nargs, 2, 4)) {
+ if (nargs < 2) {
+ PyErr_Format(PyExc_TypeError, "ioctl expected at least 2 arguments, got %zd", nargs);
goto exit;
}
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
+ if (nargs > 4) {
+ PyErr_Format(PyExc_TypeError, "ioctl expected at most 4 arguments, got %zd", nargs);
+ goto exit;
+ }
+ fd = PyObject_AsFileDescriptor(args[0]);
+ if (fd < 0) {
goto exit;
}
code = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
@@ -143,7 +152,7 @@ PyDoc_STRVAR(fcntl_flock__doc__,
"function is emulated using fcntl()).");
#define FCNTL_FLOCK_METHODDEF \
- {"flock", _PyCFunction_CAST(fcntl_flock), METH_FASTCALL, fcntl_flock__doc__},
+ {"flock", (PyCFunction)(void(*)(void))fcntl_flock, METH_FASTCALL, fcntl_flock__doc__},
static PyObject *
fcntl_flock_impl(PyObject *module, int fd, int code);
@@ -155,10 +164,12 @@ fcntl_flock(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
int fd;
int code;
- if (!_PyArg_CheckPositional("flock", nargs, 2, 2)) {
+ if (nargs != 2) {
+ PyErr_Format(PyExc_TypeError, "flock expected 2 arguments, got %zd", nargs);
goto exit;
}
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
+ fd = PyObject_AsFileDescriptor(args[0]);
+ if (fd < 0) {
goto exit;
}
code = PyLong_AsInt(args[1]);
@@ -199,7 +210,7 @@ PyDoc_STRVAR(fcntl_lockf__doc__,
" 2 - relative to the end of the file (SEEK_END)");
#define FCNTL_LOCKF_METHODDEF \
- {"lockf", _PyCFunction_CAST(fcntl_lockf), METH_FASTCALL, fcntl_lockf__doc__},
+ {"lockf", (PyCFunction)(void(*)(void))fcntl_lockf, METH_FASTCALL, fcntl_lockf__doc__},
static PyObject *
fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj,
@@ -215,10 +226,16 @@ fcntl_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
PyObject *startobj = NULL;
int whence = 0;
- if (!_PyArg_CheckPositional("lockf", nargs, 2, 5)) {
+ if (nargs < 2) {
+ PyErr_Format(PyExc_TypeError, "lockf expected at least 2 arguments, got %zd", nargs);
+ goto exit;
+ }
+ if (nargs > 5) {
+ PyErr_Format(PyExc_TypeError, "lockf expected at most 5 arguments, got %zd", nargs);
goto exit;
}
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
+ fd = PyObject_AsFileDescriptor(args[0]);
+ if (fd < 0) {
goto exit;
}
code = PyLong_AsInt(args[1]);
@@ -246,4 +263,4 @@ skip_optional:
exit:
return return_value;
}
-/*[clinic end generated code: output=732e33ba92042031 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=26793691ab1c75ba input=a9049054013a1b77]*/