Commit 84b8e92e authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-29918: Add missed "const" modifiers in C API documentation. (#846)

parent 576def09
...@@ -138,7 +138,7 @@ which disallows mutable objects such as :class:`bytearray`. ...@@ -138,7 +138,7 @@ which disallows mutable objects such as :class:`bytearray`.
attempting any conversion. Raises :exc:`TypeError` if the object is not attempting any conversion. Raises :exc:`TypeError` if the object is not
a :class:`bytearray` object. The C variable may also be declared as :c:type:`PyObject\*`. a :class:`bytearray` object. The C variable may also be declared as :c:type:`PyObject\*`.
``u`` (:class:`str`) [Py_UNICODE \*] ``u`` (:class:`str`) [const Py_UNICODE \*]
Convert a Python Unicode object to a C pointer to a NUL-terminated buffer of Convert a Python Unicode object to a C pointer to a NUL-terminated buffer of
Unicode characters. You must pass the address of a :c:type:`Py_UNICODE` Unicode characters. You must pass the address of a :c:type:`Py_UNICODE`
pointer variable, which will be filled with the pointer to an existing pointer variable, which will be filled with the pointer to an existing
...@@ -151,16 +151,16 @@ which disallows mutable objects such as :class:`bytearray`. ...@@ -151,16 +151,16 @@ which disallows mutable objects such as :class:`bytearray`.
Previously, :exc:`TypeError` was raised when embedded null code points Previously, :exc:`TypeError` was raised when embedded null code points
were encountered in the Python string. were encountered in the Python string.
``u#`` (:class:`str`) [Py_UNICODE \*, int] ``u#`` (:class:`str`) [const Py_UNICODE \*, int]
This variant on ``u`` stores into two C variables, the first one a pointer to a This variant on ``u`` stores into two C variables, the first one a pointer to a
Unicode data buffer, the second one its length. This variant allows Unicode data buffer, the second one its length. This variant allows
null code points. null code points.
``Z`` (:class:`str` or ``None``) [Py_UNICODE \*] ``Z`` (:class:`str` or ``None``) [const Py_UNICODE \*]
Like ``u``, but the Python object may also be ``None``, in which case the Like ``u``, but the Python object may also be ``None``, in which case the
:c:type:`Py_UNICODE` pointer is set to *NULL*. :c:type:`Py_UNICODE` pointer is set to *NULL*.
``Z#`` (:class:`str` or ``None``) [Py_UNICODE \*, int] ``Z#`` (:class:`str` or ``None``) [const Py_UNICODE \*, int]
Like ``u#``, but the Python object may also be ``None``, in which case the Like ``u#``, but the Python object may also be ``None``, in which case the
:c:type:`Py_UNICODE` pointer is set to *NULL*. :c:type:`Py_UNICODE` pointer is set to *NULL*.
...@@ -529,42 +529,42 @@ Building values ...@@ -529,42 +529,42 @@ Building values
not within format units such as ``s#``). This can be used to make long format not within format units such as ``s#``). This can be used to make long format
strings a tad more readable. strings a tad more readable.
``s`` (:class:`str` or ``None``) [char \*] ``s`` (:class:`str` or ``None``) [const char \*]
Convert a null-terminated C string to a Python :class:`str` object using ``'utf-8'`` Convert a null-terminated C string to a Python :class:`str` object using ``'utf-8'``
encoding. If the C string pointer is *NULL*, ``None`` is used. encoding. If the C string pointer is *NULL*, ``None`` is used.
``s#`` (:class:`str` or ``None``) [char \*, int] ``s#`` (:class:`str` or ``None``) [const char \*, int]
Convert a C string and its length to a Python :class:`str` object using ``'utf-8'`` Convert a C string and its length to a Python :class:`str` object using ``'utf-8'``
encoding. If the C string pointer is *NULL*, the length is ignored and encoding. If the C string pointer is *NULL*, the length is ignored and
``None`` is returned. ``None`` is returned.
``y`` (:class:`bytes`) [char \*] ``y`` (:class:`bytes`) [const char \*]
This converts a C string to a Python :class:`bytes` object. If the C This converts a C string to a Python :class:`bytes` object. If the C
string pointer is *NULL*, ``None`` is returned. string pointer is *NULL*, ``None`` is returned.
``y#`` (:class:`bytes`) [char \*, int] ``y#`` (:class:`bytes`) [const char \*, int]
This converts a C string and its lengths to a Python object. If the C This converts a C string and its lengths to a Python object. If the C
string pointer is *NULL*, ``None`` is returned. string pointer is *NULL*, ``None`` is returned.
``z`` (:class:`str` or ``None``) [char \*] ``z`` (:class:`str` or ``None``) [const char \*]
Same as ``s``. Same as ``s``.
``z#`` (:class:`str` or ``None``) [char \*, int] ``z#`` (:class:`str` or ``None``) [const char \*, int]
Same as ``s#``. Same as ``s#``.
``u`` (:class:`str`) [Py_UNICODE \*] ``u`` (:class:`str`) [const Py_UNICODE \*]
Convert a null-terminated buffer of Unicode (UCS-2 or UCS-4) data to a Python Convert a null-terminated buffer of Unicode (UCS-2 or UCS-4) data to a Python
Unicode object. If the Unicode buffer pointer is *NULL*, ``None`` is returned. Unicode object. If the Unicode buffer pointer is *NULL*, ``None`` is returned.
``u#`` (:class:`str`) [Py_UNICODE \*, int] ``u#`` (:class:`str`) [const Py_UNICODE \*, int]
Convert a Unicode (UCS-2 or UCS-4) data buffer and its length to a Python Convert a Unicode (UCS-2 or UCS-4) data buffer and its length to a Python
Unicode object. If the Unicode buffer pointer is *NULL*, the length is ignored Unicode object. If the Unicode buffer pointer is *NULL*, the length is ignored
and ``None`` is returned. and ``None`` is returned.
``U`` (:class:`str` or ``None``) [char \*] ``U`` (:class:`str` or ``None``) [const char \*]
Same as ``s``. Same as ``s``.
``U#`` (:class:`str` or ``None``) [char \*, int] ``U#`` (:class:`str` or ``None``) [const char \*, int]
Same as ``s#``. Same as ``s#``.
``i`` (:class:`int`) [int] ``i`` (:class:`int`) [int]
......
...@@ -96,10 +96,10 @@ called with a non-bytes parameter. ...@@ -96,10 +96,10 @@ called with a non-bytes parameter.
| :attr:`%x` | int | Exactly equivalent to | | :attr:`%x` | int | Exactly equivalent to |
| | | ``printf("%x")``. | | | | ``printf("%x")``. |
+-------------------+---------------+--------------------------------+ +-------------------+---------------+--------------------------------+
| :attr:`%s` | char\* | A null-terminated C character | | :attr:`%s` | const char\* | A null-terminated C character |
| | | array. | | | | array. |
+-------------------+---------------+--------------------------------+ +-------------------+---------------+--------------------------------+
| :attr:`%p` | void\* | The hex representation of a C | | :attr:`%p` | const void\* | The hex representation of a C |
| | | pointer. Mostly equivalent to | | | | pointer. Mostly equivalent to |
| | | ``printf("%p")`` except that | | | | ``printf("%p")`` except that |
| | | it is guaranteed to start with | | | | it is guaranteed to start with |
......
...@@ -72,7 +72,7 @@ Dictionary Objects ...@@ -72,7 +72,7 @@ Dictionary Objects
.. index:: single: PyUnicode_FromString() .. index:: single: PyUnicode_FromString()
Insert *value* into the dictionary *p* using *key* as a key. *key* should Insert *value* into the dictionary *p* using *key* as a key. *key* should
be a :c:type:`char\*`. The key object is created using be a :c:type:`const char\*`. The key object is created using
``PyUnicode_FromString(key)``. Return ``0`` on success or ``-1`` on ``PyUnicode_FromString(key)``. Return ``0`` on success or ``-1`` on
failure. failure.
...@@ -107,7 +107,7 @@ Dictionary Objects ...@@ -107,7 +107,7 @@ Dictionary Objects
.. c:function:: PyObject* PyDict_GetItemString(PyObject *p, const char *key) .. c:function:: PyObject* PyDict_GetItemString(PyObject *p, const char *key)
This is the same as :c:func:`PyDict_GetItem`, but *key* is specified as a This is the same as :c:func:`PyDict_GetItem`, but *key* is specified as a
:c:type:`char\*`, rather than a :c:type:`PyObject\*`. :c:type:`const char\*`, rather than a :c:type:`PyObject\*`.
.. c:function:: PyObject* PyDict_SetDefault(PyObject *p, PyObject *key, PyObject *default) .. c:function:: PyObject* PyDict_SetDefault(PyObject *p, PyObject *key, PyObject *default)
......
...@@ -231,11 +231,6 @@ Importing Modules ...@@ -231,11 +231,6 @@ Importing Modules
Finalize the import mechanism. For internal use only. Finalize the import mechanism. For internal use only.
.. c:function:: PyObject* _PyImport_FindExtension(char *, char *)
For internal use only.
.. c:function:: int PyImport_ImportFrozenModuleObject(PyObject *name) .. c:function:: int PyImport_ImportFrozenModuleObject(PyObject *name)
Load a frozen module named *name*. Return ``1`` for success, ``0`` if the Load a frozen module named *name*. Return ``1`` for success, ``0`` if the
...@@ -266,8 +261,8 @@ Importing Modules ...@@ -266,8 +261,8 @@ Importing Modules
is:: is::
struct _frozen { struct _frozen {
char *name; const char *name;
unsigned char *code; const unsigned char *code;
int size; int size;
}; };
...@@ -300,7 +295,7 @@ Importing Modules ...@@ -300,7 +295,7 @@ Importing Modules
The structure is defined in :file:`Include/import.h` as:: The structure is defined in :file:`Include/import.h` as::
struct _inittab { struct _inittab {
char *name; /* ASCII encoded string */ const char *name; /* ASCII encoded string */
PyObject* (*initfunc)(void); PyObject* (*initfunc)(void);
}; };
......
...@@ -80,7 +80,7 @@ Module Objects ...@@ -80,7 +80,7 @@ Module Objects
.. versionadded:: 3.3 .. versionadded:: 3.3
.. c:function:: char* PyModule_GetName(PyObject *module) .. c:function:: const char* PyModule_GetName(PyObject *module)
Similar to :c:func:`PyModule_GetNameObject` but return the name encoded to Similar to :c:func:`PyModule_GetNameObject` but return the name encoded to
``'utf-8'``. ``'utf-8'``.
...@@ -112,7 +112,7 @@ Module Objects ...@@ -112,7 +112,7 @@ Module Objects
.. versionadded:: 3.2 .. versionadded:: 3.2
.. c:function:: char* PyModule_GetFilename(PyObject *module) .. c:function:: const char* PyModule_GetFilename(PyObject *module)
Similar to :c:func:`PyModule_GetFilenameObject` but return the filename Similar to :c:func:`PyModule_GetFilenameObject` but return the filename
encoded to 'utf-8'. encoded to 'utf-8'.
...@@ -146,11 +146,11 @@ or request "multi-phase initialization" by returning the definition struct itsel ...@@ -146,11 +146,11 @@ or request "multi-phase initialization" by returning the definition struct itsel
Always initialize this member to :const:`PyModuleDef_HEAD_INIT`. Always initialize this member to :const:`PyModuleDef_HEAD_INIT`.
.. c:member:: char* m_name .. c:member:: const char *m_name
Name for the new module. Name for the new module.
.. c:member:: char* m_doc .. c:member:: const char *m_doc
Docstring for the module; usually a docstring variable created with Docstring for the module; usually a docstring variable created with
:c:func:`PyDoc_STRVAR` is used. :c:func:`PyDoc_STRVAR` is used.
......
...@@ -125,20 +125,20 @@ the definition of all other Python objects. ...@@ -125,20 +125,20 @@ the definition of all other Python objects.
Structure used to describe a method of an extension type. This structure has Structure used to describe a method of an extension type. This structure has
four fields: four fields:
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
| Field | C Type | Meaning | | Field | C Type | Meaning |
+==================+=============+===============================+ +==================+===============+===============================+
| :attr:`ml_name` | char \* | name of the method | | :attr:`ml_name` | const char \* | name of the method |
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
| :attr:`ml_meth` | PyCFunction | pointer to the C | | :attr:`ml_meth` | PyCFunction | pointer to the C |
| | | implementation | | | | implementation |
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
| :attr:`ml_flags` | int | flag bits indicating how the | | :attr:`ml_flags` | int | flag bits indicating how the |
| | | call should be constructed | | | | call should be constructed |
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
| :attr:`ml_doc` | char \* | points to the contents of the | | :attr:`ml_doc` | const char \* | points to the contents of the |
| | | docstring | | | | docstring |
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
The :attr:`ml_meth` is a C function pointer. The functions may be of different The :attr:`ml_meth` is a C function pointer. The functions may be of different
types, but they always return :c:type:`PyObject\*`. If the function is not of types, but they always return :c:type:`PyObject\*`. If the function is not of
...@@ -236,25 +236,25 @@ definition with the same method name. ...@@ -236,25 +236,25 @@ definition with the same method name.
Structure which describes an attribute of a type which corresponds to a C Structure which describes an attribute of a type which corresponds to a C
struct member. Its fields are: struct member. Its fields are:
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
| Field | C Type | Meaning | | Field | C Type | Meaning |
+==================+=============+===============================+ +==================+===============+===============================+
| :attr:`name` | char \* | name of the member | | :attr:`name` | const char \* | name of the member |
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
| :attr:`!type` | int | the type of the member in the | | :attr:`!type` | int | the type of the member in the |
| | | C struct | | | | C struct |
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
| :attr:`offset` | Py_ssize_t | the offset in bytes that the | | :attr:`offset` | Py_ssize_t | the offset in bytes that the |
| | | member is located on the | | | | member is located on the |
| | | type's object struct | | | | type's object struct |
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
| :attr:`flags` | int | flag bits indicating if the | | :attr:`flags` | int | flag bits indicating if the |
| | | field should be read-only or | | | | field should be read-only or |
| | | writable | | | | writable |
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
| :attr:`doc` | char \* | points to the contents of the | | :attr:`doc` | const char \* | points to the contents of the |
| | | docstring | | | | docstring |
+------------------+-------------+-------------------------------+ +------------------+---------------+-------------------------------+
:attr:`!type` can be one of many ``T_`` macros corresponding to various C :attr:`!type` can be one of many ``T_`` macros corresponding to various C
types. When the member is accessed in Python, it will be converted to the types. When the member is accessed in Python, it will be converted to the
...@@ -268,7 +268,7 @@ definition with the same method name. ...@@ -268,7 +268,7 @@ definition with the same method name.
T_LONG long T_LONG long
T_FLOAT float T_FLOAT float
T_DOUBLE double T_DOUBLE double
T_STRING char \* T_STRING const char \*
T_OBJECT PyObject \* T_OBJECT PyObject \*
T_OBJECT_EX PyObject \* T_OBJECT_EX PyObject \*
T_CHAR char T_CHAR char
......
...@@ -136,7 +136,7 @@ accessible to C code. They all work with the current interpreter thread's ...@@ -136,7 +136,7 @@ accessible to C code. They all work with the current interpreter thread's
Reset :data:`sys.warnoptions` to an empty list. Reset :data:`sys.warnoptions` to an empty list.
.. c:function:: void PySys_AddWarnOption(wchar_t *s) .. c:function:: void PySys_AddWarnOption(const wchar_t *s)
Append *s* to :data:`sys.warnoptions`. Append *s* to :data:`sys.warnoptions`.
...@@ -144,7 +144,7 @@ accessible to C code. They all work with the current interpreter thread's ...@@ -144,7 +144,7 @@ accessible to C code. They all work with the current interpreter thread's
Append *unicode* to :data:`sys.warnoptions`. Append *unicode* to :data:`sys.warnoptions`.
.. c:function:: void PySys_SetPath(wchar_t *path) .. c:function:: void PySys_SetPath(const wchar_t *path)
Set :data:`sys.path` to a list object of paths found in *path* which should Set :data:`sys.path` to a list object of paths found in *path* which should
be a list of paths separated with the platform's search path delimiter be a list of paths separated with the platform's search path delimiter
......
...@@ -144,9 +144,9 @@ type. ...@@ -144,9 +144,9 @@ type.
+-------------------+------------------------------+------------------------------------+ +-------------------+------------------------------+------------------------------------+
| Field | C Type | Meaning | | Field | C Type | Meaning |
+===================+==============================+====================================+ +===================+==============================+====================================+
| ``name`` | ``char *`` | name of the struct sequence type | | ``name`` | ``const char *`` | name of the struct sequence type |
+-------------------+------------------------------+------------------------------------+ +-------------------+------------------------------+------------------------------------+
| ``doc`` | ``char *`` | pointer to docstring for the type | | ``doc`` | ``const char *`` | pointer to docstring for the type |
| | | or NULL to omit | | | | or NULL to omit |
+-------------------+------------------------------+------------------------------------+ +-------------------+------------------------------+------------------------------------+
| ``fields`` | ``PyStructSequence_Field *`` | pointer to *NULL*-terminated array | | ``fields`` | ``PyStructSequence_Field *`` | pointer to *NULL*-terminated array |
...@@ -164,16 +164,16 @@ type. ...@@ -164,16 +164,16 @@ type.
:attr:`fields` array of the :c:type:`PyStructSequence_Desc` determines which :attr:`fields` array of the :c:type:`PyStructSequence_Desc` determines which
field of the struct sequence is described. field of the struct sequence is described.
+-----------+---------------+--------------------------------------+ +-----------+------------------+--------------------------------------+
| Field | C Type | Meaning | | Field | C Type | Meaning |
+===========+===============+======================================+ +===========+==================+======================================+
| ``name`` | ``char *`` | name for the field or *NULL* to end | | ``name`` | ``const char *`` | name for the field or *NULL* to end |
| | | the list of named fields, set to | | | | the list of named fields, set to |
| | | PyStructSequence_UnnamedField to | | | | PyStructSequence_UnnamedField to |
| | | leave unnamed | | | | leave unnamed |
+-----------+---------------+--------------------------------------+ +-----------+------------------+--------------------------------------+
| ``doc`` | ``char *`` | field docstring or *NULL* to omit | | ``doc`` | ``const char *`` | field docstring or *NULL* to omit |
+-----------+---------------+--------------------------------------+ +-----------+------------------+--------------------------------------+
.. c:var:: char* PyStructSequence_UnnamedField .. c:var:: char* PyStructSequence_UnnamedField
......
...@@ -490,10 +490,10 @@ APIs: ...@@ -490,10 +490,10 @@ APIs:
| :attr:`%x` | int | Exactly equivalent to | | :attr:`%x` | int | Exactly equivalent to |
| | | ``printf("%x")``. | | | | ``printf("%x")``. |
+-------------------+---------------------+--------------------------------+ +-------------------+---------------------+--------------------------------+
| :attr:`%s` | char\* | A null-terminated C character | | :attr:`%s` | const char\* | A null-terminated C character |
| | | array. | | | | array. |
+-------------------+---------------------+--------------------------------+ +-------------------+---------------------+--------------------------------+
| :attr:`%p` | void\* | The hex representation of a C | | :attr:`%p` | const void\* | The hex representation of a C |
| | | pointer. Mostly equivalent to | | | | pointer. Mostly equivalent to |
| | | ``printf("%p")`` except that | | | | ``printf("%p")`` except that |
| | | it is guaranteed to start with | | | | it is guaranteed to start with |
...@@ -506,8 +506,8 @@ APIs: ...@@ -506,8 +506,8 @@ APIs:
+-------------------+---------------------+--------------------------------+ +-------------------+---------------------+--------------------------------+
| :attr:`%U` | PyObject\* | A unicode object. | | :attr:`%U` | PyObject\* | A unicode object. |
+-------------------+---------------------+--------------------------------+ +-------------------+---------------------+--------------------------------+
| :attr:`%V` | PyObject\*, char \* | A unicode object (which may be | | :attr:`%V` | PyObject\*, | A unicode object (which may be |
| | | *NULL*) and a null-terminated | | | const char\* | *NULL*) and a null-terminated |
| | | C character array as a second | | | | C character array as a second |
| | | parameter (which will be used, | | | | parameter (which will be used, |
| | | if the first parameter is | | | | if the first parameter is |
......
...@@ -727,9 +727,9 @@ Philbrick (philbrick@hks.com):: ...@@ -727,9 +727,9 @@ Philbrick (philbrick@hks.com)::
keywdarg_parrot(PyObject *self, PyObject *args, PyObject *keywds) keywdarg_parrot(PyObject *self, PyObject *args, PyObject *keywds)
{ {
int voltage; int voltage;
char *state = "a stiff"; const char *state = "a stiff";
char *action = "voom"; const char *action = "voom";
char *type = "Norwegian Blue"; const char *type = "Norwegian Blue";
static char *kwlist[] = {"voltage", "state", "action", "type", NULL}; static char *kwlist[] = {"voltage", "state", "action", "type", NULL};
......
...@@ -1361,9 +1361,9 @@ Here is a desultory example of the implementation of the call function. :: ...@@ -1361,9 +1361,9 @@ Here is a desultory example of the implementation of the call function. ::
newdatatype_call(newdatatypeobject *obj, PyObject *args, PyObject *other) newdatatype_call(newdatatypeobject *obj, PyObject *args, PyObject *other)
{ {
PyObject *result; PyObject *result;
char *arg1; const char *arg1;
char *arg2; const char *arg2;
char *arg3; const char *arg3;
if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) { if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) {
return NULL; return NULL;
......
...@@ -1050,7 +1050,7 @@ Currently Argument Clinic supports only a few return converters: ...@@ -1050,7 +1050,7 @@ Currently Argument Clinic supports only a few return converters:
DecodeFSDefault DecodeFSDefault
None of these take parameters. For the first three, return -1 to indicate None of these take parameters. For the first three, return -1 to indicate
error. For ``DecodeFSDefault``, the return type is ``char *``; return a NULL error. For ``DecodeFSDefault``, the return type is ``const char *``; return a NULL
pointer to indicate an error. pointer to indicate an error.
(There's also an experimental ``NoneType`` converter, which lets you (There's also an experimental ``NoneType`` converter, which lets you
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment