Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c0dff5

Browse files
committed
Adress more code reviews
- initval is a uint32_t - improve documentation - add whatsnew Signed-off-by: Christian Heimes <[email protected]>
1 parent c0e9b4b commit 9c0dff5

4 files changed

Lines changed: 34 additions & 26 deletions

File tree

Doc/library/os.rst

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,14 @@ features:
32833283
:func:`~select.select`, :func:`~select.poll` and similar. By default, the
32843284
new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
32853285

3286+
*initval* is the initial value of the event counter. The initial value
3287+
must be an 32 bit unsigned integer. Please note that the initial value is
3288+
limited to a 32 bit unsigned int although the event counter is an unsigned
3289+
64 bit integer with a maximum value of 2\ :sup:`64`\ -\ 2.
3290+
3291+
*flags* can be constructed from :const:`EFD_CLOEXEC`,
3292+
:const:`EFD_NONBLOCK`, and :const:`EFD_SEMAPHORE`.
3293+
32863294
If :const:`EFD_SEMAPHORE` is specified and the event counter is non-zero,
32873295
:func:`eventfd_read` returns 1 and decrements the counter by one.
32883296

@@ -3292,53 +3300,55 @@ features:
32923300

32933301
If the event counter is zero, :func:`eventfd_read` blocks.
32943302

3295-
:func:`eventfd_write` increments the event counter.
3296-
3297-
*initval* is the initial value of the event counter. It must be an
3298-
unsigned integer between 0 and 2\ :sup:`64`\ -\ 2.
3299-
3300-
*flags* can be constructed from :const:`EFD_CLOEXEC`,
3301-
:const:`EFD_NONBLOCK`, and :const:`EFD_SEMAPHORE`.
3303+
:func:`eventfd_write` increments the event counter. Write blocks if the
3304+
write operation would increment the counter to a value larger than
3305+
2\ :sup:`64`\ -\ 2.
33023306

33033307
.. availability:: Linux 2.6.27 or newer with glibc 2.8 or newer.
33043308

33053309
.. versionadded:: 3.10
33063310

33073311
.. function:: eventfd_read(fd)
33083312

3309-
Read value from an :func:`eventfd` file descriptor and return
3310-
an unsigned integer between 0 and 2\ :sup:`64`\ -\ 2. The function does
3311-
not verify that *fd* is an :func:`eventfd`.
3313+
Read value from an :func:`eventfd` file descriptor and return a 64 bit
3314+
unsigned int. The function does not verify that *fd* is an :func:`eventfd`.
3315+
3316+
.. availability:: See :func:`eventfd`
33123317

33133318
.. versionadded:: 3.10
33143319

33153320
.. function:: eventfd_write(fd, value)
33163321

3317-
Add value to an :func:`eventfd` file descriptor. *value* must be
3318-
an unsigned integer between 0 and 2\ :sup:`64`\ -\ 2. The function does
3319-
not verify that *fd* is an :func:`eventfd`.
3322+
Add value to an :func:`eventfd` file descriptor. *value* must be a 64 bit
3323+
unsigned int. The function does not verify that *fd* is an :func:`eventfd`.
3324+
3325+
.. availability:: See :func:`eventfd`
33203326

33213327
.. versionadded:: 3.10
33223328

33233329
.. data:: EFD_CLOEXEC
33243330

33253331
Set close-on-exec flag for new :func:`eventfd` file descriptor.
33263332

3333+
.. availability:: See :func:`eventfd`
3334+
33273335
.. versionadded:: 3.10
33283336

33293337
.. data:: EFD_NONBLOCK
33303338

33313339
Set :const:`O_NONBLOCK` status flag for new :func:`eventfd` file
33323340
descriptor.
33333341

3342+
.. availability:: See :func:`eventfd`
3343+
33343344
.. versionadded:: 3.10
33353345

33363346
.. data:: EFD_SEMAPHORE
33373347

33383348
Provide semaphore-like semantics for reads from a :func:`eventfd` file
33393349
descriptor. On read the internal counter is decremented by one.
33403350

3341-
.. availability:: Linux 2.6.30 or newer
3351+
.. availability:: Linux 2.6.30 or newer with glibc 2.8 or newer.
33423352

33433353
.. versionadded:: 3.10
33443354

Doc/whatsnew/3.10.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ os
229229
Added :func:`os.cpu_count()` support for VxWorks RTOS.
230230
(Contributed by Peixing Xin in :issue:`41440`.)
231231

232+
A new :func:`os.eventfd` function and related helpers were added to wrap the
233+
``eventfd2`` syscall on Linux
234+
(Contributed by Christian Heimes in :issue:`41001`.)
235+
232236
py_compile
233237
----------
234238

Modules/clinic/posixmodule.c.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/posixmodule.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12877,12 +12877,10 @@ Creates and returns an event notification file descriptor.
1287712877
static PyObject *
1287812878
os_eventfd_impl(PyObject *module, unsigned int initval, int flags)
1287912879
/*[clinic end generated code: output=ce9c9bbd1446f2de input=66203e3c50c4028b]*/
12880+
1288012881
{
12882+
/* initval is limited to uint32_t, internal counter is uint64_t */
1288112883
int fd;
12882-
if (initval > (PY_ULLONG_MAX - 1)) {
12883-
PyErr_SetString(PyExc_OverflowError, "initval too large");
12884-
return NULL;
12885-
}
1288612884
Py_BEGIN_ALLOW_THREADS
1288712885
fd = eventfd(initval, flags);
1288812886
Py_END_ALLOW_THREADS
@@ -12921,18 +12919,14 @@ os.eventfd_write
1292112919
fd: fildes
1292212920
value: unsigned_long_long
1292312921
12924-
Write eventfd value
12922+
Write eventfd value.
1292512923
[clinic start generated code]*/
1292612924

1292712925
static PyObject *
1292812926
os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value)
12929-
/*[clinic end generated code: output=bebd9040bbf987f5 input=82da3dd0d6e62f28]*/
12927+
/*[clinic end generated code: output=bebd9040bbf987f5 input=156de8555be5a949]*/
1293012928
{
1293112929
int result;
12932-
if (value > (PY_ULLONG_MAX - 1)) {
12933-
PyErr_SetString(PyExc_OverflowError, "value too large");
12934-
return NULL;
12935-
}
1293612930
Py_BEGIN_ALLOW_THREADS
1293712931
result = eventfd_write(fd, value);
1293812932
Py_END_ALLOW_THREADS

0 commit comments

Comments
 (0)