bpo-31368: Expose preadv and pwritev in the os module (#5239) · python/cpython@4defba3 (original) (raw)

`@@ -3705,6 +3705,61 @@ os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)

`

3705

3705

``

3706

3706

`#endif /* defined(HAVE_PREAD) */

`

3707

3707

``

``

3708

`+

#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))

`

``

3709

+

``

3710

`+

PyDoc_STRVAR(os_preadv__doc__,

`

``

3711

`+

"preadv($module, fd, buffers, offset, flags=0, /)\n"

`

``

3712

`+

"--\n"

`

``

3713

`+

"\n"

`

``

3714

`+

"Reads from a file descriptor into a number of mutable bytes-like objects.\n"

`

``

3715

`+

"\n"

`

``

3716

`+

"Combines the functionality of readv() and pread(). As readv(), it will\n"

`

``

3717

`+

"transfer data into each buffer until it is full and then move on to the next\n"

`

``

3718

`+

"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"

`

``

3719

`+

"specifies the file offset at which the input operation is to be performed. It\n"

`

``

3720

`+

"will return the total number of bytes read (which can be less than the total\n"

`

``

3721

`+

"capacity of all the objects).\n"

`

``

3722

`+

"\n"

`

``

3723

`+

"The flags argument contains a bitwise OR of zero or more of the following flags:\n"

`

``

3724

`+

"\n"

`

``

3725

`+

"- RWF_HIPRI\n"

`

``

3726

`+

"- RWF_NOWAIT\n"

`

``

3727

`+

"\n"

`

``

3728

`+

"Using non-zero flags requires Linux 4.6 or newer.");

`

``

3729

+

``

3730

`+

#define OS_PREADV_METHODDEF \

`

``

3731

`+

{"preadv", (PyCFunction)os_preadv, METH_FASTCALL, os_preadv__doc__},

`

``

3732

+

``

3733

`+

static Py_ssize_t

`

``

3734

`+

os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,

`

``

3735

`+

int flags);

`

``

3736

+

``

3737

`+

static PyObject *

`

``

3738

`+

os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)

`

``

3739

`+

{

`

``

3740

`+

PyObject *return_value = NULL;

`

``

3741

`+

int fd;

`

``

3742

`+

PyObject *buffers;

`

``

3743

`+

Py_off_t offset;

`

``

3744

`+

int flags = 0;

`

``

3745

`+

Py_ssize_t _return_value;

`

``

3746

+

``

3747

`+

if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv",

`

``

3748

`+

&fd, &buffers, Py_off_t_converter, &offset, &flags)) {

`

``

3749

`+

goto exit;

`

``

3750

`+

}

`

``

3751

`+

_return_value = os_preadv_impl(module, fd, buffers, offset, flags);

`

``

3752

`+

if ((_return_value == -1) && PyErr_Occurred()) {

`

``

3753

`+

goto exit;

`

``

3754

`+

}

`

``

3755

`+

return_value = PyLong_FromSsize_t(_return_value);

`

``

3756

+

``

3757

`+

exit:

`

``

3758

`+

return return_value;

`

``

3759

`+

}

`

``

3760

+

``

3761

`+

#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */

`

``

3762

+

3708

3763

`PyDoc_STRVAR(os_write__doc__,

`

3709

3764

`"write($module, fd, data, /)\n"

`

3710

3765

`"--\n"

`

`@@ -3963,6 +4018,61 @@ os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)

`

3963

4018

``

3964

4019

`#endif /* defined(HAVE_PWRITE) */

`

3965

4020

``

``

4021

`+

#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))

`

``

4022

+

``

4023

`+

PyDoc_STRVAR(os_pwritev__doc__,

`

``

4024

`+

"pwritev($module, fd, buffers, offset, flags=0, /)\n"

`

``

4025

`+

"--\n"

`

``

4026

`+

"\n"

`

``

4027

`+

"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"

`

``

4028

`+

"\n"

`

``

4029

`+

"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"

`

``

4030

`+

"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"

`

``

4031

`+

"buffer is written before proceeding to second, and so on. The operating system may\n"

`

``

4032

`+

"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"

`

``

4033

`+

"This function writes the contents of each object to the file descriptor and returns\n"

`

``

4034

`+

"the total number of bytes written.\n"

`

``

4035

`+

"\n"

`

``

4036

`+

"The flags argument contains a bitwise OR of zero or more of the following flags:\n"

`

``

4037

`+

"\n"

`

``

4038

`+

"- RWF_DSYNC\n"

`

``

4039

`+

"- RWF_SYNC\n"

`

``

4040

`+

"\n"

`

``

4041

`+

"Using non-zero flags requires Linux 4.7 or newer.");

`

``

4042

+

``

4043

`+

#define OS_PWRITEV_METHODDEF \

`

``

4044

`+

{"pwritev", (PyCFunction)os_pwritev, METH_FASTCALL, os_pwritev__doc__},

`

``

4045

+

``

4046

`+

static Py_ssize_t

`

``

4047

`+

os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,

`

``

4048

`+

int flags);

`

``

4049

+

``

4050

`+

static PyObject *

`

``

4051

`+

os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)

`

``

4052

`+

{

`

``

4053

`+

PyObject *return_value = NULL;

`

``

4054

`+

int fd;

`

``

4055

`+

PyObject *buffers;

`

``

4056

`+

Py_off_t offset;

`

``

4057

`+

int flags = 0;

`

``

4058

`+

Py_ssize_t _return_value;

`

``

4059

+

``

4060

`+

if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",

`

``

4061

`+

&fd, &buffers, Py_off_t_converter, &offset, &flags)) {

`

``

4062

`+

goto exit;

`

``

4063

`+

}

`

``

4064

`+

_return_value = os_pwritev_impl(module, fd, buffers, offset, flags);

`

``

4065

`+

if ((_return_value == -1) && PyErr_Occurred()) {

`

``

4066

`+

goto exit;

`

``

4067

`+

}

`

``

4068

`+

return_value = PyLong_FromSsize_t(_return_value);

`

``

4069

+

``

4070

`+

exit:

`

``

4071

`+

return return_value;

`

``

4072

`+

}

`

``

4073

+

``

4074

`+

#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */

`

``

4075

+

3966

4076

`#if defined(HAVE_MKFIFO)

`

3967

4077

``

3968

4078

`PyDoc_STRVAR(os_mkfifo__doc__,

`

`@@ -6239,6 +6349,10 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject

`

6239

6349

`#define OS_PREAD_METHODDEF

`

6240

6350

`#endif /* !defined(OS_PREAD_METHODDEF) */

`

6241

6351

``

``

6352

`+

#ifndef OS_PREADV_METHODDEF

`

``

6353

`+

#define OS_PREADV_METHODDEF

`

``

6354

`+

#endif /* !defined(OS_PREADV_METHODDEF) */

`

``

6355

+

6242

6356

`#ifndef OS_PIPE_METHODDEF

`

6243

6357

`#define OS_PIPE_METHODDEF

`

6244

6358

`#endif /* !defined(OS_PIPE_METHODDEF) */

`

`@@ -6255,6 +6369,10 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject

`

6255

6369

`#define OS_PWRITE_METHODDEF

`

6256

6370

`#endif /* !defined(OS_PWRITE_METHODDEF) */

`

6257

6371

``

``

6372

`+

#ifndef OS_PWRITEV_METHODDEF

`

``

6373

`+

#define OS_PWRITEV_METHODDEF

`

``

6374

`+

#endif /* !defined(OS_PWRITEV_METHODDEF) */

`

``

6375

+

6258

6376

`#ifndef OS_MKFIFO_METHODDEF

`

6259

6377

`#define OS_MKFIFO_METHODDEF

`

6260

6378

`#endif /* !defined(OS_MKFIFO_METHODDEF) */

`

`@@ -6410,4 +6528,4 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject

`

6410

6528

`#ifndef OS_GETRANDOM_METHODDEF

`

6411

6529

`#define OS_GETRANDOM_METHODDEF

`

6412

6530

`#endif /* !defined(OS_GETRANDOM_METHODDEF) */

`

6413

``

`-

/[clinic end generated code: output=6345053cd5992caf input=a9049054013a1b77]/

`

``

6531

`+

/[clinic end generated code: output=06ace805893aa10c input=a9049054013a1b77]/

`