summaryrefslogtreecommitdiffstats
path: root/Modules/clinic
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-11-17 00:00:38 (GMT)
committerGitHub <noreply@github.com>2020-11-17 00:00:38 (GMT)
commita57b3d30f66c90f42da751bf82256b9b22961ed0 (patch)
tree04ec1f393ebfe891fda48a164829bdee76911c0b /Modules/clinic
parentcce3f0b0c88eba98bc11abe703a444bee7880ff8 (diff)
downloadcpython-a57b3d30f66c90f42da751bf82256b9b22961ed0.zip
cpython-a57b3d30f66c90f42da751bf82256b9b22961ed0.tar.gz
cpython-a57b3d30f66c90f42da751bf82256b9b22961ed0.tar.bz2
bpo-41625: Expose the splice() system call in the os module (GH-21947)
Diffstat (limited to 'Modules/clinic')
-rw-r--r--Modules/clinic/posixmodule.c.h106
1 files changed, 105 insertions, 1 deletions
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
index f5826e3..ee4ee8c 100644
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -5674,6 +5674,106 @@ exit:
#endif /* defined(HAVE_COPY_FILE_RANGE) */
+#if defined(HAVE_SPLICE)
+
+PyDoc_STRVAR(os_splice__doc__,
+"splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n"
+" flags=0)\n"
+"--\n"
+"\n"
+"Transfer count bytes from one pipe to a descriptor or vice versa.\n"
+"\n"
+" src\n"
+" Source file descriptor.\n"
+" dst\n"
+" Destination file descriptor.\n"
+" count\n"
+" Number of bytes to copy.\n"
+" offset_src\n"
+" Starting offset in src.\n"
+" offset_dst\n"
+" Starting offset in dst.\n"
+" flags\n"
+" Flags to modify the semantics of the call.\n"
+"\n"
+"If offset_src is None, then src is read from the current position;\n"
+"respectively for offset_dst. The offset associated to the file\n"
+"descriptor that refers to a pipe must be None.");
+
+#define OS_SPLICE_METHODDEF \
+ {"splice", (PyCFunction)(void(*)(void))os_splice, METH_FASTCALL|METH_KEYWORDS, os_splice__doc__},
+
+static PyObject *
+os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
+ PyObject *offset_src, PyObject *offset_dst,
+ unsigned int flags);
+
+static PyObject *
+os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL};
+ static _PyArg_Parser _parser = {NULL, _keywords, "splice", 0};
+ PyObject *argsbuf[6];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
+ int src;
+ int dst;
+ Py_ssize_t count;
+ PyObject *offset_src = Py_None;
+ PyObject *offset_dst = Py_None;
+ unsigned int flags = 0;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 6, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ src = _PyLong_AsInt(args[0]);
+ if (src == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ dst = _PyLong_AsInt(args[1]);
+ if (dst == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = _PyNumber_Index(args[2]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ count = ival;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (args[3]) {
+ offset_src = args[3];
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ if (args[4]) {
+ offset_dst = args[4];
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) {
+ goto exit;
+ }
+skip_optional_pos:
+ return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags);
+
+exit:
+ return return_value;
+}
+
+#endif /* defined(HAVE_SPLICE) */
+
#if defined(HAVE_MKFIFO)
PyDoc_STRVAR(os_mkfifo__doc__,
@@ -8864,6 +8964,10 @@ exit:
#define OS_COPY_FILE_RANGE_METHODDEF
#endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */
+#ifndef OS_SPLICE_METHODDEF
+ #define OS_SPLICE_METHODDEF
+#endif /* !defined(OS_SPLICE_METHODDEF) */
+
#ifndef OS_MKFIFO_METHODDEF
#define OS_MKFIFO_METHODDEF
#endif /* !defined(OS_MKFIFO_METHODDEF) */
@@ -9059,4 +9163,4 @@ exit:
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
-/*[clinic end generated code: output=49b7ed768242ef7c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8a59e91178897267 input=a9049054013a1b77]*/