10000 [3.12] Document PyOS_strtoul and PyOS_strtol (GH-114048) (GH-114618) · python/cpython@c95cdd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit c95cdd0

Browse files
[3.12] Document PyOS_strtoul and PyOS_strtol (GH-114048) (GH-114618)
(cherry picked from commit 3f62bf3) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
1 parent fd8aafd commit c95cdd0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Doc/c-api/conversion.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,42 @@ The return value (*rv*) for these functions should be interpreted as follows:
4848
4949
The following functions provide locale-independent string to number conversions.
5050
51+
.. c:function:: unsigned long PyOS_strtoul(const char *str, char **ptr, int base)
52+
53+
Convert the initial part of the string in ``str`` to an :c:expr:`unsigned
54+
long` value according to the given ``base``, which must be between ``2`` and
55+
``36`` inclusive, or be the special value ``0``.
56+
57+
Leading white space and case of characters are ignored. If ``base`` is zero
58+
it looks for a leading ``0b``, ``0o`` or ``0x`` to tell which base. If
59+
these are absent it defaults to ``10``. Base must be 0 or between 2 and 36
60+
(inclusive). If ``ptr`` is non-``NULL`` it will contain a pointer to the
61+
end of the scan.
62+
63+
If the converted value falls out of range of corresponding return type,
64+
range error occurs (:c:data:`errno` is set to :c:macro:`!ERANGE`) and
65+
:c:macro:`!ULONG_MAX` is returned. If no conversion can be performed, ``0``
66+
is returned.
67+
68+
See also the Unix man page :manpage:`strtoul(3)`.
69+
70+
.. versionadded:: 3.2
71+
72+
73+
.. c:function:: long PyOS_strtol(const char *str, char **ptr, int base)
74+
75+
Convert the initial part of the string in ``str`` to an :c:expr:`long` value
76+
according to the given ``base``, which must be between ``2`` and ``36``
77+
inclusive, or be the special value ``0``.
78+
79+
Same as :c:func:`PyOS_strtoul`, but return a :c:expr:`long` value instead
80+
and :c:macro:`LONG_MAX` on overflows.
81+
82+
See also the Unix man page :manpage:`strtol(3)`.
83+
84+
.. versionadded:: 3.2
85+
86+
5187
.. c:function:: double PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_exception)
5288
5389
Convert a string ``s`` to a :c:expr:`double`, raising a Python

0 commit comments

Comments
 (0)
0