diff options
author | Inada Naoki <songofacandy@gmail.com> | 2019-04-13 01:46:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-13 01:46:21 (GMT) |
commit | c88feceb449d6e85d7e17ec36559206094d10d81 (patch) | |
tree | cda7737ab74c0419b952e440b86e10a6101e3d7f /Doc/extending | |
parent | a304b136adda3575898d8b5debedcd48d5072272 (diff) | |
download | cpython-c88feceb449d6e85d7e17ec36559206094d10d81.zip cpython-c88feceb449d6e85d7e17ec36559206094d10d81.tar.gz cpython-c88feceb449d6e85d7e17ec36559206094d10d81.tar.bz2 |
Doc: define PY_SSIZE_T_CLEAN always (GH-12794)
Diffstat (limited to 'Doc/extending')
-rw-r--r-- | Doc/extending/embedding.rst | 1 | ||||
-rw-r--r-- | Doc/extending/extending.rst | 11 |
2 files changed, 9 insertions, 3 deletions
diff --git a/Doc/extending/embedding.rst b/Doc/extending/embedding.rst index 7e4fc19..13d83b7 100644 --- a/Doc/extending/embedding.rst +++ b/Doc/extending/embedding.rst @@ -53,6 +53,7 @@ interface. This interface is intended to execute a Python script without needing to interact with the application directly. This can for example be used to perform some operation on a file. :: + #define PY_SSIZE_T_CLEAN #include <Python.h> int diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst index 9fbd91f..433178a 100644 --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -55,8 +55,9 @@ called ``spam``, the C file containing its implementation is called :file:`spammodule.c`; if the module name is very long, like ``spammify``, the module name can be just :file:`spammify.c`.) -The first line of our file can be:: +The first two lines of our file can be:: + #define PY_SSIZE_T_CLEAN #include <Python.h> which pulls in the Python API (you can add a comment describing the purpose of @@ -68,6 +69,9 @@ the module and a copyright notice if you like). headers on some systems, you *must* include :file:`Python.h` before any standard headers are included. + It is recommended to always define ``PY_SSIZE_T_CLEAN`` before including + ``Python.h``. See :ref:`parsetuple` for a description of this macro. + All user-visible symbols defined by :file:`Python.h` have a prefix of ``Py`` or ``PY``, except those defined in standard header files. For convenience, and since they are used extensively by the Python interpreter, ``"Python.h"`` @@ -729,7 +733,8 @@ it returns false and raises an appropriate exception. Here is an example module which uses keywords, based on an example by Geoff Philbrick (philbrick@hks.com):: - #include "Python.h" + #define PY_SSIZE_T_CLEAN /* Make "s#" use Py_ssize_t rather than int. */ + #include <Python.h> static PyObject * keywdarg_parrot(PyObject *self, PyObject *args, PyObject *keywds) @@ -1228,7 +1233,7 @@ The function :c:func:`spam_system` is modified in a trivial way:: In the beginning of the module, right after the line :: - #include "Python.h" + #include <Python.h> two more lines must be added:: |