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

Skip to content

Commit 5bb414d

Browse files
committed
Issue #19343: Expose FreeBSD-specific APIs in resource module. Original patch by Koobs.
1 parent ead8d08 commit 5bb414d

4 files changed

Lines changed: 51 additions & 0 deletions

File tree

Doc/library/resource.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,34 @@ platform.
217217

218218
.. versionadded:: 3.4
219219

220+
.. data:: RLIMIT_SBSIZE
221+
222+
The maximum size (in bytes) of socket buffer usage for this user.
223+
This limits the amount of network memory, and hence the amount of mbufs,
224+
that this user may hold at any time.
225+
226+
Availability: FreeBSD 9 or later.
227+
228+
.. versionadded:: 3.4
229+
230+
.. data:: RLIMIT_SWAP
231+
232+
The maximum size (in bytes) of the swap space that may be reserved or
233+
used by all of this user id's processes.
234+
This limit is enforced only if bit 1 of the vm.overcommit sysctl is set.
235+
Please see :manpage:`tuning(7)` for a complete description of this sysctl.
236+
237+
Availability: FreeBSD 9 or later.
238+
239+
.. versionadded:: 3.4
240+
241+
.. data:: RLIMIT_NPTS
242+
243+
The maximum number of pseudo-terminals created by this user id.
244+
245+
Availability: FreeBSD 9 or later.
246+
247+
.. versionadded:: 3.4
220248

221249
Resource Usage
222250
--------------

Lib/test/test_resource.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ def test_linux_constants(self):
138138
with contextlib.suppress(AttributeError):
139139
self.assertIsInstance(getattr(resource, 'RLIMIT_' + attr), int)
140140

141+
@support.requires_freebsd_version(9)
142+
def test_freebsd_contants(self):
143+
for attr in ['SWAP', 'SBSIZE', 'NPTS']:
144+
with contextlib.suppress(AttributeError):
145+
self.assertIsInstance(getattr(resource, 'RLIMIT_' + attr), int)
146+
141147
@unittest.skipUnless(hasattr(resource, 'prlimit'), 'no prlimit')
142148
@support.requires_linux_version(2, 6, 36)
143149
def test_prlimit(self):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Core and Builtins
1818
Library
1919
-------
2020

21+
- Issue #19343: Expose FreeBSD-specific APIs in resource module. Original
22+
patch by Koobs.
23+
2124
- Issue #19506: Use a memoryview to avoid a data copy when piping data
2225
to stdin within subprocess.Popen.communicate. 5-10% less cpu usage.
2326

Modules/resource.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,20 @@ PyInit_resource(void)
424424
PyModule_AddIntMacro(m, RUSAGE_THREAD);
425425
#endif
426426

427+
/* FreeBSD specific */
428+
429+
#ifdef RLIMIT_SWAP
430+
PyModule_AddIntMacro(m, RLIMIT_SWAP);
431+
#endif
432+
433+
#ifdef RLIMIT_SBSIZE
434+
PyModule_AddIntMacro(m, RLIMIT_SBSIZE);
435+
#endif
436+
437+
#ifdef RLIMIT_NPTS
438+
PyModule_AddIntMacro(m, RLIMIT_NPTS);
439+
#endif
440+
427441
#if defined(HAVE_LONG_LONG)
428442
if (sizeof(RLIM_INFINITY) > sizeof(long)) {
429443
v = PyLong_FromLongLong((PY_LONG_LONG) RLIM_INFINITY);

0 commit comments

Comments
 (0)