Publish LoLBench Harbor tasks from artifact branch (part 3)
Browse files100 Harbor tasks; seven-column viewer; immutable DockerHub validation manifest; all union verifiers pass.
This view is limited to 50 files because it contains too many changes. See raw diff
- cpython_2/environment/repo/Doc/c-api/float.rst +78 -0
- cpython_2/environment/repo/Doc/c-api/function.rst +108 -0
- cpython_2/environment/repo/Doc/c-api/gcsupport.rst +175 -0
- cpython_2/environment/repo/Doc/c-api/gen.rst +44 -0
- cpython_2/environment/repo/Doc/c-api/import.rst +302 -0
- cpython_2/environment/repo/Doc/c-api/index.rst +27 -0
- cpython_2/environment/repo/Doc/c-api/init.rst +1766 -0
- cpython_2/environment/repo/Doc/c-api/init_config.rst +1064 -0
- cpython_2/environment/repo/Doc/c-api/intro.rst +785 -0
- cpython_2/environment/repo/Doc/c-api/iter.rst +46 -0
- cpython_2/environment/repo/Doc/c-api/iterator.rst +50 -0
- cpython_2/environment/repo/Doc/c-api/list.rst +144 -0
- cpython_2/environment/repo/Doc/c-api/long.rst +337 -0
- cpython_2/environment/repo/Doc/c-api/mapping.rst +103 -0
- cpython_2/environment/repo/Doc/c-api/marshal.rst +94 -0
- cpython_2/environment/repo/Doc/c-api/memory.rst +604 -0
- cpython_2/environment/repo/Doc/c-api/memoryview.rst +63 -0
- cpython_2/environment/repo/Doc/c-api/method.rst +94 -0
- cpython_2/environment/repo/Doc/c-api/module.rst +543 -0
- cpython_2/environment/repo/Doc/c-api/none.rst +26 -0
- cpython_2/environment/repo/Doc/c-api/number.rst +286 -0
- cpython_2/environment/repo/Doc/c-api/objbuffer.rst +55 -0
- cpython_2/environment/repo/Doc/c-api/object.rst +358 -0
- cpython_2/environment/repo/Doc/c-api/objimpl.rst +17 -0
- cpython_2/environment/repo/Doc/c-api/refcounting.rst +73 -0
- cpython_2/environment/repo/Doc/c-api/reflection.rst +75 -0
- cpython_2/environment/repo/Doc/c-api/sequence.rst +176 -0
- cpython_2/environment/repo/Doc/c-api/set.rst +159 -0
- cpython_2/environment/repo/Doc/c-api/slice.rst +122 -0
- cpython_2/environment/repo/Doc/c-api/stable.rst +38 -0
- cpython_2/environment/repo/Doc/c-api/structures.rst +476 -0
- cpython_2/environment/repo/Doc/c-api/sys.rst +425 -0
- cpython_2/environment/repo/Doc/c-api/tuple.rst +222 -0
- cpython_2/environment/repo/Doc/c-api/type.rst +244 -0
- cpython_2/environment/repo/Doc/c-api/typeobj.rst +0 -0
- cpython_2/environment/repo/Doc/c-api/unicode.rst +1731 -0
- cpython_2/environment/repo/Doc/c-api/utilities.rst +21 -0
- cpython_2/environment/repo/Doc/c-api/veryhigh.rst +412 -0
- cpython_2/environment/repo/Doc/c-api/weakref.rst +69 -0
- cpython_2/environment/repo/Doc/conf.py +230 -0
- cpython_2/environment/repo/Doc/contents.rst +31 -0
- cpython_2/environment/repo/Doc/copyright.rst +19 -0
- cpython_2/environment/repo/Doc/data/refcounts.dat +3085 -0
- cpython_2/environment/repo/Doc/distributing/index.rst +176 -0
- cpython_2/environment/repo/Doc/distutils/_setuptools_disclaimer.rst +5 -0
- cpython_2/environment/repo/Doc/distutils/apiref.rst +2070 -0
- cpython_2/environment/repo/Doc/distutils/builtdist.rst +479 -0
- cpython_2/environment/repo/Doc/distutils/commandref.rst +106 -0
- cpython_2/environment/repo/Doc/distutils/configfile.rst +144 -0
- cpython_2/environment/repo/Doc/distutils/examples.rst +340 -0
cpython_2/environment/repo/Doc/c-api/float.rst
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _floatobjects:
|
| 4 |
+
|
| 5 |
+
Floating Point Objects
|
| 6 |
+
----------------------
|
| 7 |
+
|
| 8 |
+
.. index:: object: floating point
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
.. c:type:: PyFloatObject
|
| 12 |
+
|
| 13 |
+
This subtype of :c:type:`PyObject` represents a Python floating point object.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
.. c:var:: PyTypeObject PyFloat_Type
|
| 17 |
+
|
| 18 |
+
This instance of :c:type:`PyTypeObject` represents the Python floating point
|
| 19 |
+
type. This is the same object as :class:`float` in the Python layer.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
.. c:function:: int PyFloat_Check(PyObject *p)
|
| 23 |
+
|
| 24 |
+
Return true if its argument is a :c:type:`PyFloatObject` or a subtype of
|
| 25 |
+
:c:type:`PyFloatObject`.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
.. c:function:: int PyFloat_CheckExact(PyObject *p)
|
| 29 |
+
|
| 30 |
+
Return true if its argument is a :c:type:`PyFloatObject`, but not a subtype of
|
| 31 |
+
:c:type:`PyFloatObject`.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
.. c:function:: PyObject* PyFloat_FromString(PyObject *str)
|
| 35 |
+
|
| 36 |
+
Create a :c:type:`PyFloatObject` object based on the string value in *str*, or
|
| 37 |
+
``NULL`` on failure.
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
.. c:function:: PyObject* PyFloat_FromDouble(double v)
|
| 41 |
+
|
| 42 |
+
Create a :c:type:`PyFloatObject` object from *v*, or ``NULL`` on failure.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
.. c:function:: double PyFloat_AsDouble(PyObject *pyfloat)
|
| 46 |
+
|
| 47 |
+
Return a C :c:type:`double` representation of the contents of *pyfloat*. If
|
| 48 |
+
*pyfloat* is not a Python floating point object but has a :meth:`__float__`
|
| 49 |
+
method, this method will first be called to convert *pyfloat* into a float.
|
| 50 |
+
If ``__float__()`` is not defined then it falls back to :meth:`__index__`.
|
| 51 |
+
This method returns ``-1.0`` upon failure, so one should call
|
| 52 |
+
:c:func:`PyErr_Occurred` to check for errors.
|
| 53 |
+
|
| 54 |
+
.. versionchanged:: 3.8
|
| 55 |
+
Use :meth:`__index__` if available.
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
.. c:function:: double PyFloat_AS_DOUBLE(PyObject *pyfloat)
|
| 59 |
+
|
| 60 |
+
Return a C :c:type:`double` representation of the contents of *pyfloat*, but
|
| 61 |
+
without error checking.
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
.. c:function:: PyObject* PyFloat_GetInfo(void)
|
| 65 |
+
|
| 66 |
+
Return a structseq instance which contains information about the
|
| 67 |
+
precision, minimum and maximum values of a float. It's a thin wrapper
|
| 68 |
+
around the header file :file:`float.h`.
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
.. c:function:: double PyFloat_GetMax()
|
| 72 |
+
|
| 73 |
+
Return the maximum representable finite float *DBL_MAX* as C :c:type:`double`.
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
.. c:function:: double PyFloat_GetMin()
|
| 77 |
+
|
| 78 |
+
Return the minimum normalized positive float *DBL_MIN* as C :c:type:`double`.
|
cpython_2/environment/repo/Doc/c-api/function.rst
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _function-objects:
|
| 4 |
+
|
| 5 |
+
Function Objects
|
| 6 |
+
----------------
|
| 7 |
+
|
| 8 |
+
.. index:: object: function
|
| 9 |
+
|
| 10 |
+
There are a few functions specific to Python functions.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
.. c:type:: PyFunctionObject
|
| 14 |
+
|
| 15 |
+
The C structure used for functions.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
.. c:var:: PyTypeObject PyFunction_Type
|
| 19 |
+
|
| 20 |
+
.. index:: single: MethodType (in module types)
|
| 21 |
+
|
| 22 |
+
This is an instance of :c:type:`PyTypeObject` and represents the Python function
|
| 23 |
+
type. It is exposed to Python programmers as ``types.FunctionType``.
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
.. c:function:: int PyFunction_Check(PyObject *o)
|
| 27 |
+
|
| 28 |
+
Return true if *o* is a function object (has type :c:data:`PyFunction_Type`).
|
| 29 |
+
The parameter must not be ``NULL``.
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
.. c:function:: PyObject* PyFunction_New(PyObject *code, PyObject *globals)
|
| 33 |
+
|
| 34 |
+
Return a new function object associated with the code object *code*. *globals*
|
| 35 |
+
must be a dictionary with the global variables accessible to the function.
|
| 36 |
+
|
| 37 |
+
The function's docstring and name are retrieved from the code object. *__module__*
|
| 38 |
+
is retrieved from *globals*. The argument defaults, annotations and closure are
|
| 39 |
+
set to ``NULL``. *__qualname__* is set to the same value as the function's name.
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
.. c:function:: PyObject* PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname)
|
| 43 |
+
|
| 44 |
+
As :c:func:`PyFunction_New`, but also allows setting the function object's
|
| 45 |
+
``__qualname__`` attribute. *qualname* should be a unicode object or ``NULL``;
|
| 46 |
+
if ``NULL``, the ``__qualname__`` attribute is set to the same value as its
|
| 47 |
+
``__name__`` attribute.
|
| 48 |
+
|
| 49 |
+
.. versionadded:: 3.3
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
.. c:function:: PyObject* PyFunction_GetCode(PyObject *op)
|
| 53 |
+
|
| 54 |
+
Return the code object associated with the function object *op*.
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
.. c:function:: PyObject* PyFunction_GetGlobals(PyObject *op)
|
| 58 |
+
|
| 59 |
+
Return the globals dictionary associated with the function object *op*.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
.. c:function:: PyObject* PyFunction_GetModule(PyObject *op)
|
| 63 |
+
|
| 64 |
+
Return the *__module__* attribute of the function object *op*. This is normally
|
| 65 |
+
a string containing the module name, but can be set to any other object by
|
| 66 |
+
Python code.
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
.. c:function:: PyObject* PyFunction_GetDefaults(PyObject *op)
|
| 70 |
+
|
| 71 |
+
Return the argument default values of the function object *op*. This can be a
|
| 72 |
+
tuple of arguments or ``NULL``.
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
.. c:function:: int PyFunction_SetDefaults(PyObject *op, PyObject *defaults)
|
| 76 |
+
|
| 77 |
+
Set the argument default values for the function object *op*. *defaults* must be
|
| 78 |
+
``Py_None`` or a tuple.
|
| 79 |
+
|
| 80 |
+
Raises :exc:`SystemError` and returns ``-1`` on failure.
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
.. c:function:: PyObject* PyFunction_GetClosure(PyObject *op)
|
| 84 |
+
|
| 85 |
+
Return the closure associated with the function object *op*. This can be ``NULL``
|
| 86 |
+
or a tuple of cell objects.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
.. c:function:: int PyFunction_SetClosure(PyObject *op, PyObject *closure)
|
| 90 |
+
|
| 91 |
+
Set the closure associated with the function object *op*. *closure* must be
|
| 92 |
+
``Py_None`` or a tuple of cell objects.
|
| 93 |
+
|
| 94 |
+
Raises :exc:`SystemError` and returns ``-1`` on failure.
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
.. c:function:: PyObject *PyFunction_GetAnnotations(PyObject *op)
|
| 98 |
+
|
| 99 |
+
Return the annotations of the function object *op*. This can be a
|
| 100 |
+
mutable dictionary or ``NULL``.
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
.. c:function:: int PyFunction_SetAnnotations(PyObject *op, PyObject *annotations)
|
| 104 |
+
|
| 105 |
+
Set the annotations for the function object *op*. *annotations*
|
| 106 |
+
must be a dictionary or ``Py_None``.
|
| 107 |
+
|
| 108 |
+
Raises :exc:`SystemError` and returns ``-1`` on failure.
|
cpython_2/environment/repo/Doc/c-api/gcsupport.rst
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 7 |
+
|
| 8 |
+
Python's support for detecting and collecting garbage which involves circular
|
| 9 |
+
references requires support from object types which are "containers" for other
|
| 10 |
+
objects which may also be containers. Types which do not store references to
|
| 11 |
+
other objects, or which only store references to atomic types (such as numbers
|
| 12 |
+
or strings), do not need to provide any explicit support for garbage
|
| 13 |
+
collection.
|
| 14 |
+
|
| 15 |
+
To create a container type, the :c:member:`~PyTypeObject.tp_flags` field of the type object must
|
| 16 |
+
include the :const:`Py_TPFLAGS_HAVE_GC` and provide an implementation of the
|
| 17 |
+
:c:member:`~PyTypeObject.tp_traverse` handler. If instances of the type are mutable, a
|
| 18 |
+
:c:member:`~PyTypeObject.tp_clear` implementation must also be provided.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
.. data:: Py_TPFLAGS_HAVE_GC
|
| 22 |
+
:noindex:
|
| 23 |
+
|
| 24 |
+
Objects with a type with this flag set must conform with the rules
|
| 25 |
+
documented here. For convenience these objects will be referred to as
|
| 26 |
+
container objects.
|
| 27 |
+
|
| 28 |
+
Constructors for container types must conform to two rules:
|
| 29 |
+
|
| 30 |
+
#. The memory for the object must be allocated using :c:func:`PyObject_GC_New`
|
| 31 |
+
or :c:func:`PyObject_GC_NewVar`.
|
| 32 |
+
|
| 33 |
+
#. Once all the fields which may contain references to other containers are
|
| 34 |
+
initialized, it must call :c:func:`PyObject_GC_Track`.
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
.. c:function:: TYPE* PyObject_GC_New(TYPE, PyTypeObject *type)
|
| 38 |
+
|
| 39 |
+
Analogous to :c:func:`PyObject_New` but for container objects with the
|
| 40 |
+
:const:`Py_TPFLAGS_HAVE_GC` flag set.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
.. c:function:: TYPE* PyObject_GC_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size)
|
| 44 |
+
|
| 45 |
+
Analogous to :c:func:`PyObject_NewVar` but for container objects with the
|
| 46 |
+
:const:`Py_TPFLAGS_HAVE_GC` flag set.
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
.. c:function:: TYPE* PyObject_GC_Resize(TYPE, PyVarObject *op, Py_ssize_t newsize)
|
| 50 |
+
|
| 51 |
+
Resize an object allocated by :c:func:`PyObject_NewVar`. Returns the
|
| 52 |
+
resized object or ``NULL`` on failure. *op* must not be tracked by the collector yet.
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
.. c:function:: void PyObject_GC_Track(PyObject *op)
|
| 56 |
+
|
| 57 |
+
Adds the object *op* to the set of container objects tracked by the
|
| 58 |
+
collector. The collector can run at unexpected times so objects must be
|
| 59 |
+
valid while being tracked. This should be called once all the fields
|
| 60 |
+
followed by the :c:member:`~PyTypeObject.tp_traverse` handler become valid, usually near the
|
| 61 |
+
end of the constructor.
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
.. c:function:: int PyObject_IS_GC(PyObject *obj)
|
| 65 |
+
|
| 66 |
+
Returns non-zero if the object implements the garbage collector protocol,
|
| 67 |
+
otherwise returns 0.
|
| 68 |
+
|
| 69 |
+
The object cannot be tracked by the garbage collector if this function returns 0.
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
.. c:function:: int PyObject_GC_IsTracked(PyObject *op)
|
| 73 |
+
|
| 74 |
+
Returns 1 if the object type of *op* implements the GC protocol and *op* is being
|
| 75 |
+
currently tracked by the garbage collector and 0 otherwise.
|
| 76 |
+
|
| 77 |
+
This is analogous to the Python function :func:`gc.is_tracked`.
|
| 78 |
+
|
| 79 |
+
.. versionadded:: 3.9
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
.. c:function:: int PyObject_GC_IsFinalized(PyObject *op)
|
| 83 |
+
|
| 84 |
+
Returns 1 if the object type of *op* implements the GC protocol and *op* has been
|
| 85 |
+
already finalized by the garbage collector and 0 otherwise.
|
| 86 |
+
|
| 87 |
+
This is analogous to the Python function :func:`gc.is_finalized`.
|
| 88 |
+
|
| 89 |
+
.. versionadded:: 3.9
|
| 90 |
+
|
| 91 |
+
Similarly, the deallocator for the object must conform to a similar pair of
|
| 92 |
+
rules:
|
| 93 |
+
|
| 94 |
+
#. Before fields which refer to other containers are invalidated,
|
| 95 |
+
:c:func:`PyObject_GC_UnTrack` must be called.
|
| 96 |
+
|
| 97 |
+
#. The object's memory must be deallocated using :c:func:`PyObject_GC_Del`.
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
.. c:function:: void PyObject_GC_Del(void *op)
|
| 101 |
+
|
| 102 |
+
Releases memory allocated to an object using :c:func:`PyObject_GC_New` or
|
| 103 |
+
:c:func:`PyObject_GC_NewVar`.
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
.. c:function:: void PyObject_GC_UnTrack(void *op)
|
| 107 |
+
|
| 108 |
+
Remove the object *op* from the set of container objects tracked by the
|
| 109 |
+
collector. Note that :c:func:`PyObject_GC_Track` can be called again on
|
| 110 |
+
this object to add it back to the set of tracked objects. The deallocator
|
| 111 |
+
(:c:member:`~PyTypeObject.tp_dealloc` handler) should call this for the object before any of
|
| 112 |
+
the fields used by the :c:member:`~PyTypeObject.tp_traverse` handler become invalid.
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
.. versionchanged:: 3.8
|
| 116 |
+
|
| 117 |
+
The :c:func:`_PyObject_GC_TRACK` and :c:func:`_PyObject_GC_UNTRACK` macros
|
| 118 |
+
have been removed from the public C API.
|
| 119 |
+
|
| 120 |
+
The :c:member:`~PyTypeObject.tp_traverse` handler accepts a function parameter of this type:
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
.. c:type:: int (*visitproc)(PyObject *object, void *arg)
|
| 124 |
+
|
| 125 |
+
Type of the visitor function passed to the :c:member:`~PyTypeObject.tp_traverse` handler.
|
| 126 |
+
The function should be called with an object to traverse as *object* and
|
| 127 |
+
the third parameter to the :c:member:`~PyTypeObject.tp_traverse` handler as *arg*. The
|
| 128 |
+
Python core uses several visitor functions to implement cyclic garbage
|
| 129 |
+
detection; it's not expected that users will need to write their own
|
| 130 |
+
visitor functions.
|
| 131 |
+
|
| 132 |
+
The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type:
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
.. c:type:: int (*traverseproc)(PyObject *self, visitproc visit, void *arg)
|
| 136 |
+
|
| 137 |
+
Traversal function for a container object. Implementations must call the
|
| 138 |
+
*visit* function for each object directly contained by *self*, with the
|
| 139 |
+
parameters to *visit* being the contained object and the *arg* value passed
|
| 140 |
+
to the handler. The *visit* function must not be called with a ``NULL``
|
| 141 |
+
object argument. If *visit* returns a non-zero value that value should be
|
| 142 |
+
returned immediately.
|
| 143 |
+
|
| 144 |
+
To simplify writing :c:member:`~PyTypeObject.tp_traverse` handlers, a :c:func:`Py_VISIT` macro is
|
| 145 |
+
provided. In order to use this macro, the :c:member:`~PyTypeObject.tp_traverse` implementation
|
| 146 |
+
must name its arguments exactly *visit* and *arg*:
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
.. c:function:: void Py_VISIT(PyObject *o)
|
| 150 |
+
|
| 151 |
+
If *o* is not ``NULL``, call the *visit* callback, with arguments *o*
|
| 152 |
+
and *arg*. If *visit* returns a non-zero value, then return it.
|
| 153 |
+
Using this macro, :c:member:`~PyTypeObject.tp_traverse` handlers
|
| 154 |
+
look like::
|
| 155 |
+
|
| 156 |
+
static int
|
| 157 |
+
my_traverse(Noddy *self, visitproc visit, void *arg)
|
| 158 |
+
{
|
| 159 |
+
Py_VISIT(self->foo);
|
| 160 |
+
Py_VISIT(self->bar);
|
| 161 |
+
return 0;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
The :c:member:`~PyTypeObject.tp_clear` handler must be of the :c:type:`inquiry` type, or ``NULL``
|
| 165 |
+
if the object is immutable.
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
.. c:type:: int (*inquiry)(PyObject *self)
|
| 169 |
+
|
| 170 |
+
Drop references that may have created reference cycles. Immutable objects
|
| 171 |
+
do not have to define this method since they can never directly create
|
| 172 |
+
reference cycles. Note that the object must still be valid after calling
|
| 173 |
+
this method (don't just call :c:func:`Py_DECREF` on a reference). The
|
| 174 |
+
collector will call this method if it detects that this object is involved
|
| 175 |
+
in a reference cycle.
|
cpython_2/environment/repo/Doc/c-api/gen.rst
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _gen-objects:
|
| 4 |
+
|
| 5 |
+
Generator Objects
|
| 6 |
+
-----------------
|
| 7 |
+
|
| 8 |
+
Generator objects are what Python uses to implement generator iterators. They
|
| 9 |
+
are normally created by iterating over a function that yields values, rather
|
| 10 |
+
than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
.. c:type:: PyGenObject
|
| 14 |
+
|
| 15 |
+
The C structure used for generator objects.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
.. c:var:: PyTypeObject PyGen_Type
|
| 19 |
+
|
| 20 |
+
The type object corresponding to generator objects.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
.. c:function:: int PyGen_Check(PyObject *ob)
|
| 24 |
+
|
| 25 |
+
Return true if *ob* is a generator object; *ob* must not be ``NULL``.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
.. c:function:: int PyGen_CheckExact(PyObject *ob)
|
| 29 |
+
|
| 30 |
+
Return true if *ob*'s type is :c:type:`PyGen_Type`; *ob* must not be ``NULL``.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
.. c:function:: PyObject* PyGen_New(PyFrameObject *frame)
|
| 34 |
+
|
| 35 |
+
Create and return a new generator object based on the *frame* object.
|
| 36 |
+
A reference to *frame* is stolen by this function. The argument must not be
|
| 37 |
+
``NULL``.
|
| 38 |
+
|
| 39 |
+
.. c:function:: PyObject* PyGen_NewWithQualName(PyFrameObject *frame, PyObject *name, PyObject *qualname)
|
| 40 |
+
|
| 41 |
+
Create and return a new generator object based on the *frame* object,
|
| 42 |
+
with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
|
| 43 |
+
A reference to *frame* is stolen by this function. The *frame* argument
|
| 44 |
+
must not be ``NULL``.
|
cpython_2/environment/repo/Doc/c-api/import.rst
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _importing:
|
| 4 |
+
|
| 5 |
+
Importing Modules
|
| 6 |
+
=================
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
.. c:function:: PyObject* PyImport_ImportModule(const char *name)
|
| 10 |
+
|
| 11 |
+
.. index::
|
| 12 |
+
single: package variable; __all__
|
| 13 |
+
single: __all__ (package variable)
|
| 14 |
+
single: modules (in module sys)
|
| 15 |
+
|
| 16 |
+
This is a simplified interface to :c:func:`PyImport_ImportModuleEx` below,
|
| 17 |
+
leaving the *globals* and *locals* arguments set to ``NULL`` and *level* set
|
| 18 |
+
to 0. When the *name*
|
| 19 |
+
argument contains a dot (when it specifies a submodule of a package), the
|
| 20 |
+
*fromlist* argument is set to the list ``['*']`` so that the return value is the
|
| 21 |
+
named module rather than the top-level package containing it as would otherwise
|
| 22 |
+
be the case. (Unfortunately, this has an additional side effect when *name* in
|
| 23 |
+
fact specifies a subpackage instead of a submodule: the submodules specified in
|
| 24 |
+
the package's ``__all__`` variable are loaded.) Return a new reference to the
|
| 25 |
+
imported module, or ``NULL`` with an exception set on failure. A failing
|
| 26 |
+
import of a module doesn't leave the module in :data:`sys.modules`.
|
| 27 |
+
|
| 28 |
+
This function always uses absolute imports.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
.. c:function:: PyObject* PyImport_ImportModuleNoBlock(const char *name)
|
| 32 |
+
|
| 33 |
+
This function is a deprecated alias of :c:func:`PyImport_ImportModule`.
|
| 34 |
+
|
| 35 |
+
.. versionchanged:: 3.3
|
| 36 |
+
This function used to fail immediately when the import lock was held
|
| 37 |
+
by another thread. In Python 3.3 though, the locking scheme switched
|
| 38 |
+
to per-module locks for most purposes, so this function's special
|
| 39 |
+
behaviour isn't needed anymore.
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
.. c:function:: PyObject* PyImport_ImportModuleEx(const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)
|
| 43 |
+
|
| 44 |
+
.. index:: builtin: __import__
|
| 45 |
+
|
| 46 |
+
Import a module. This is best described by referring to the built-in Python
|
| 47 |
+
function :func:`__import__`.
|
| 48 |
+
|
| 49 |
+
The return value is a new reference to the imported module or top-level
|
| 50 |
+
package, or ``NULL`` with an exception set on failure. Like for
|
| 51 |
+
:func:`__import__`, the return value when a submodule of a package was
|
| 52 |
+
requested is normally the top-level package, unless a non-empty *fromlist*
|
| 53 |
+
was given.
|
| 54 |
+
|
| 55 |
+
Failing imports remove incomplete module objects, like with
|
| 56 |
+
:c:func:`PyImport_ImportModule`.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
.. c:function:: PyObject* PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)
|
| 60 |
+
|
| 61 |
+
Import a module. This is best described by referring to the built-in Python
|
| 62 |
+
function :func:`__import__`, as the standard :func:`__import__` function calls
|
| 63 |
+
this function directly.
|
| 64 |
+
|
| 65 |
+
The return value is a new reference to the imported module or top-level package,
|
| 66 |
+
or ``NULL`` with an exception set on failure. Like for :func:`__import__`,
|
| 67 |
+
the return value when a submodule of a package was requested is normally the
|
| 68 |
+
top-level package, unless a non-empty *fromlist* was given.
|
| 69 |
+
|
| 70 |
+
.. versionadded:: 3.3
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
.. c:function:: PyObject* PyImport_ImportModuleLevel(const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)
|
| 74 |
+
|
| 75 |
+
Similar to :c:func:`PyImport_ImportModuleLevelObject`, but the name is a
|
| 76 |
+
UTF-8 encoded string instead of a Unicode object.
|
| 77 |
+
|
| 78 |
+
.. versionchanged:: 3.3
|
| 79 |
+
Negative values for *level* are no longer accepted.
|
| 80 |
+
|
| 81 |
+
.. c:function:: PyObject* PyImport_Import(PyObject *name)
|
| 82 |
+
|
| 83 |
+
This is a higher-level interface that calls the current "import hook
|
| 84 |
+
function" (with an explicit *level* of 0, meaning absolute import). It
|
| 85 |
+
invokes the :func:`__import__` function from the ``__builtins__`` of the
|
| 86 |
+
current globals. This means that the import is done using whatever import
|
| 87 |
+
hooks are installed in the current environment.
|
| 88 |
+
|
| 89 |
+
This function always uses absolute imports.
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
.. c:function:: PyObject* PyImport_ReloadModule(PyObject *m)
|
| 93 |
+
|
| 94 |
+
Reload a module. Return a new reference to the reloaded module, or ``NULL`` with
|
| 95 |
+
an exception set on failure (the module still exists in this case).
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
.. c:function:: PyObject* PyImport_AddModuleObject(PyObject *name)
|
| 99 |
+
|
| 100 |
+
Return the module object corresponding to a module name. The *name* argument
|
| 101 |
+
may be of the form ``package.module``. First check the modules dictionary if
|
| 102 |
+
there's one there, and if not, create a new one and insert it in the modules
|
| 103 |
+
dictionary. Return ``NULL`` with an exception set on failure.
|
| 104 |
+
|
| 105 |
+
.. note::
|
| 106 |
+
|
| 107 |
+
This function does not load or import the module; if the module wasn't already
|
| 108 |
+
loaded, you will get an empty module object. Use :c:func:`PyImport_ImportModule`
|
| 109 |
+
or one of its variants to import a module. Package structures implied by a
|
| 110 |
+
dotted name for *name* are not created if not already present.
|
| 111 |
+
|
| 112 |
+
.. versionadded:: 3.3
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
.. c:function:: PyObject* PyImport_AddModule(const char *name)
|
| 116 |
+
|
| 117 |
+
Similar to :c:func:`PyImport_AddModuleObject`, but the name is a UTF-8
|
| 118 |
+
encoded string instead of a Unicode object.
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
.. c:function:: PyObject* PyImport_ExecCodeModule(const char *name, PyObject *co)
|
| 122 |
+
|
| 123 |
+
.. index:: builtin: compile
|
| 124 |
+
|
| 125 |
+
Given a module name (possibly of the form ``package.module``) and a code object
|
| 126 |
+
read from a Python bytecode file or obtained from the built-in function
|
| 127 |
+
:func:`compile`, load the module. Return a new reference to the module object,
|
| 128 |
+
or ``NULL`` with an exception set if an error occurred. *name*
|
| 129 |
+
is removed from :attr:`sys.modules` in error cases, even if *name* was already
|
| 130 |
+
in :attr:`sys.modules` on entry to :c:func:`PyImport_ExecCodeModule`. Leaving
|
| 131 |
+
incompletely initialized modules in :attr:`sys.modules` is dangerous, as imports of
|
| 132 |
+
such modules have no way to know that the module object is an unknown (and
|
| 133 |
+
probably damaged with respect to the module author's intents) state.
|
| 134 |
+
|
| 135 |
+
The module's :attr:`__spec__` and :attr:`__loader__` will be set, if
|
| 136 |
+
not set already, with the appropriate values. The spec's loader will
|
| 137 |
+
be set to the module's ``__loader__`` (if set) and to an instance of
|
| 138 |
+
:class:`SourceFileLoader` otherwise.
|
| 139 |
+
|
| 140 |
+
The module's :attr:`__file__` attribute will be set to the code object's
|
| 141 |
+
:c:member:`co_filename`. If applicable, :attr:`__cached__` will also
|
| 142 |
+
be set.
|
| 143 |
+
|
| 144 |
+
This function will reload the module if it was already imported. See
|
| 145 |
+
:c:func:`PyImport_ReloadModule` for the intended way to reload a module.
|
| 146 |
+
|
| 147 |
+
If *name* points to a dotted name of the form ``package.module``, any package
|
| 148 |
+
structures not already created will still not be created.
|
| 149 |
+
|
| 150 |
+
See also :c:func:`PyImport_ExecCodeModuleEx` and
|
| 151 |
+
:c:func:`PyImport_ExecCodeModuleWithPathnames`.
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
.. c:function:: PyObject* PyImport_ExecCodeModuleEx(const char *name, PyObject *co, const char *pathname)
|
| 155 |
+
|
| 156 |
+
Like :c:func:`PyImport_ExecCodeModule`, but the :attr:`__file__` attribute of
|
| 157 |
+
the module object is set to *pathname* if it is non-``NULL``.
|
| 158 |
+
|
| 159 |
+
See also :c:func:`PyImport_ExecCodeModuleWithPathnames`.
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
.. c:function:: PyObject* PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname, PyObject *cpathname)
|
| 163 |
+
|
| 164 |
+
Like :c:func:`PyImport_ExecCodeModuleEx`, but the :attr:`__cached__`
|
| 165 |
+
attribute of the module object is set to *cpathname* if it is
|
| 166 |
+
non-``NULL``. Of the three functions, this is the preferred one to use.
|
| 167 |
+
|
| 168 |
+
.. versionadded:: 3.3
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
.. c:function:: PyObject* PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co, const char *pathname, const char *cpathname)
|
| 172 |
+
|
| 173 |
+
Like :c:func:`PyImport_ExecCodeModuleObject`, but *name*, *pathname* and
|
| 174 |
+
*cpathname* are UTF-8 encoded strings. Attempts are also made to figure out
|
| 175 |
+
what the value for *pathname* should be from *cpathname* if the former is
|
| 176 |
+
set to ``NULL``.
|
| 177 |
+
|
| 178 |
+
.. versionadded:: 3.2
|
| 179 |
+
.. versionchanged:: 3.3
|
| 180 |
+
Uses :func:`imp.source_from_cache()` in calculating the source path if
|
| 181 |
+
only the bytecode path is provided.
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
.. c:function:: long PyImport_GetMagicNumber()
|
| 185 |
+
|
| 186 |
+
Return the magic number for Python bytecode files (a.k.a. :file:`.pyc` file).
|
| 187 |
+
The magic number should be present in the first four bytes of the bytecode
|
| 188 |
+
file, in little-endian byte order. Returns ``-1`` on error.
|
| 189 |
+
|
| 190 |
+
.. versionchanged:: 3.3
|
| 191 |
+
Return value of ``-1`` upon failure.
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
.. c:function:: const char * PyImport_GetMagicTag()
|
| 195 |
+
|
| 196 |
+
Return the magic tag string for :pep:`3147` format Python bytecode file
|
| 197 |
+
names. Keep in mind that the value at ``sys.implementation.cache_tag`` is
|
| 198 |
+
authoritative and should be used instead of this function.
|
| 199 |
+
|
| 200 |
+
.. versionadded:: 3.2
|
| 201 |
+
|
| 202 |
+
.. c:function:: PyObject* PyImport_GetModuleDict()
|
| 203 |
+
|
| 204 |
+
Return the dictionary used for the module administration (a.k.a.
|
| 205 |
+
``sys.modules``). Note that this is a per-interpreter variable.
|
| 206 |
+
|
| 207 |
+
.. c:function:: PyObject* PyImport_GetModule(PyObject *name)
|
| 208 |
+
|
| 209 |
+
Return the already imported module with the given name. If the
|
| 210 |
+
module has not been imported yet then returns ``NULL`` but does not set
|
| 211 |
+
an error. Returns ``NULL`` and sets an error if the lookup failed.
|
| 212 |
+
|
| 213 |
+
.. versionadded:: 3.7
|
| 214 |
+
|
| 215 |
+
.. c:function:: PyObject* PyImport_GetImporter(PyObject *path)
|
| 216 |
+
|
| 217 |
+
Return a finder object for a :data:`sys.path`/:attr:`pkg.__path__` item
|
| 218 |
+
*path*, possibly by fetching it from the :data:`sys.path_importer_cache`
|
| 219 |
+
dict. If it wasn't yet cached, traverse :data:`sys.path_hooks` until a hook
|
| 220 |
+
is found that can handle the path item. Return ``None`` if no hook could;
|
| 221 |
+
this tells our caller that the :term:`path based finder` could not find a
|
| 222 |
+
finder for this path item. Cache the result in :data:`sys.path_importer_cache`.
|
| 223 |
+
Return a new reference to the finder object.
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
.. c:function:: int PyImport_ImportFrozenModuleObject(PyObject *name)
|
| 227 |
+
|
| 228 |
+
Load a frozen module named *name*. Return ``1`` for success, ``0`` if the
|
| 229 |
+
module is not found, and ``-1`` with an exception set if the initialization
|
| 230 |
+
failed. To access the imported module on a successful load, use
|
| 231 |
+
:c:func:`PyImport_ImportModule`. (Note the misnomer --- this function would
|
| 232 |
+
reload the module if it was already imported.)
|
| 233 |
+
|
| 234 |
+
.. versionadded:: 3.3
|
| 235 |
+
|
| 236 |
+
.. versionchanged:: 3.4
|
| 237 |
+
The ``__file__`` attribute is no longer set on the module.
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
.. c:function:: int PyImport_ImportFrozenModule(const char *name)
|
| 241 |
+
|
| 242 |
+
Similar to :c:func:`PyImport_ImportFrozenModuleObject`, but the name is a
|
| 243 |
+
UTF-8 encoded string instead of a Unicode object.
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
.. c:type:: struct _frozen
|
| 247 |
+
|
| 248 |
+
.. index:: single: freeze utility
|
| 249 |
+
|
| 250 |
+
This is the structure type definition for frozen module descriptors, as
|
| 251 |
+
generated by the :program:`freeze` utility (see :file:`Tools/freeze/` in the
|
| 252 |
+
Python source distribution). Its definition, found in :file:`Include/import.h`,
|
| 253 |
+
is::
|
| 254 |
+
|
| 255 |
+
struct _frozen {
|
| 256 |
+
const char *name;
|
| 257 |
+
const unsigned char *code;
|
| 258 |
+
int size;
|
| 259 |
+
};
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
.. c:var:: const struct _frozen* PyImport_FrozenModules
|
| 263 |
+
|
| 264 |
+
This pointer is initialized to point to an array of :c:type:`struct _frozen`
|
| 265 |
+
records, terminated by one whose members are all ``NULL`` or zero. When a frozen
|
| 266 |
+
module is imported, it is searched in this table. Third-party code could play
|
| 267 |
+
tricks with this to provide a dynamically created collection of frozen modules.
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
.. c:function:: int PyImport_AppendInittab(const char *name, PyObject* (*initfunc)(void))
|
| 271 |
+
|
| 272 |
+
Add a single module to the existing table of built-in modules. This is a
|
| 273 |
+
convenience wrapper around :c:func:`PyImport_ExtendInittab`, returning ``-1`` if
|
| 274 |
+
the table could not be extended. The new module can be imported by the name
|
| 275 |
+
*name*, and uses the function *initfunc* as the initialization function called
|
| 276 |
+
on the first attempted import. This should be called before
|
| 277 |
+
:c:func:`Py_Initialize`.
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
.. c:type:: struct _inittab
|
| 281 |
+
|
| 282 |
+
Structure describing a single entry in the list of built-in modules. Each of
|
| 283 |
+
these structures gives the name and initialization function for a module built
|
| 284 |
+
into the interpreter. The name is an ASCII encoded string. Programs which
|
| 285 |
+
embed Python may use an array of these structures in conjunction with
|
| 286 |
+
:c:func:`PyImport_ExtendInittab` to provide additional built-in modules.
|
| 287 |
+
The structure is defined in :file:`Include/import.h` as::
|
| 288 |
+
|
| 289 |
+
struct _inittab {
|
| 290 |
+
const char *name; /* ASCII encoded string */
|
| 291 |
+
PyObject* (*initfunc)(void);
|
| 292 |
+
};
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
.. c:function:: int PyImport_ExtendInittab(struct _inittab *newtab)
|
| 296 |
+
|
| 297 |
+
Add a collection of modules to the table of built-in modules. The *newtab*
|
| 298 |
+
array must end with a sentinel entry which contains ``NULL`` for the :attr:`name`
|
| 299 |
+
field; failure to provide the sentinel value can result in a memory fault.
|
| 300 |
+
Returns ``0`` on success or ``-1`` if insufficient memory could be allocated to
|
| 301 |
+
extend the internal table. In the event of failure, no modules are added to the
|
| 302 |
+
internal table. This should be called before :c:func:`Py_Initialize`.
|
cpython_2/environment/repo/Doc/c-api/index.rst
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. _c-api-index:
|
| 2 |
+
|
| 3 |
+
##################################
|
| 4 |
+
Python/C API Reference Manual
|
| 5 |
+
##################################
|
| 6 |
+
|
| 7 |
+
This manual documents the API used by C and C++ programmers who want to write
|
| 8 |
+
extension modules or embed Python. It is a companion to :ref:`extending-index`,
|
| 9 |
+
which describes the general principles of extension writing but does not
|
| 10 |
+
document the API functions in detail.
|
| 11 |
+
|
| 12 |
+
.. toctree::
|
| 13 |
+
:maxdepth: 2
|
| 14 |
+
|
| 15 |
+
intro.rst
|
| 16 |
+
stable.rst
|
| 17 |
+
veryhigh.rst
|
| 18 |
+
refcounting.rst
|
| 19 |
+
exceptions.rst
|
| 20 |
+
utilities.rst
|
| 21 |
+
abstract.rst
|
| 22 |
+
concrete.rst
|
| 23 |
+
init.rst
|
| 24 |
+
init_config.rst
|
| 25 |
+
memory.rst
|
| 26 |
+
objimpl.rst
|
| 27 |
+
apiabiversion.rst
|
cpython_2/environment/repo/Doc/c-api/init.rst
ADDED
|
@@ -0,0 +1,1766 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
.. _initialization:
|
| 5 |
+
|
| 6 |
+
*****************************************
|
| 7 |
+
Initialization, Finalization, and Threads
|
| 8 |
+
*****************************************
|
| 9 |
+
|
| 10 |
+
See also :ref:`Python Initialization Configuration <init-config>`.
|
| 11 |
+
|
| 12 |
+
.. _pre-init-safe:
|
| 13 |
+
|
| 14 |
+
Before Python Initialization
|
| 15 |
+
============================
|
| 16 |
+
|
| 17 |
+
In an application embedding Python, the :c:func:`Py_Initialize` function must
|
| 18 |
+
be called before using any other Python/C API functions; with the exception of
|
| 19 |
+
a few functions and the :ref:`global configuration variables
|
| 20 |
+
<global-conf-vars>`.
|
| 21 |
+
|
| 22 |
+
The following functions can be safely called before Python is initialized:
|
| 23 |
+
|
| 24 |
+
* Configuration functions:
|
| 25 |
+
|
| 26 |
+
* :c:func:`PyImport_AppendInittab`
|
| 27 |
+
* :c:func:`PyImport_ExtendInittab`
|
| 28 |
+
* :c:func:`PyInitFrozenExtensions`
|
| 29 |
+
* :c:func:`PyMem_SetAllocator`
|
| 30 |
+
* :c:func:`PyMem_SetupDebugHooks`
|
| 31 |
+
* :c:func:`PyObject_SetArenaAllocator`
|
| 32 |
+
* :c:func:`Py_SetPath`
|
| 33 |
+
* :c:func:`Py_SetProgramName`
|
| 34 |
+
* :c:func:`Py_SetPythonHome`
|
| 35 |
+
* :c:func:`Py_SetStandardStreamEncoding`
|
| 36 |
+
* :c:func:`PySys_AddWarnOption`
|
| 37 |
+
* :c:func:`PySys_AddXOption`
|
| 38 |
+
* :c:func:`PySys_ResetWarnOptions`
|
| 39 |
+
|
| 40 |
+
* Informative functions:
|
| 41 |
+
|
| 42 |
+
* :c:func:`Py_IsInitialized`
|
| 43 |
+
* :c:func:`PyMem_GetAllocator`
|
| 44 |
+
* :c:func:`PyObject_GetArenaAllocator`
|
| 45 |
+
* :c:func:`Py_GetBuildInfo`
|
| 46 |
+
* :c:func:`Py_GetCompiler`
|
| 47 |
+
* :c:func:`Py_GetCopyright`
|
| 48 |
+
* :c:func:`Py_GetPlatform`
|
| 49 |
+
* :c:func:`Py_GetVersion`
|
| 50 |
+
|
| 51 |
+
* Utilities:
|
| 52 |
+
|
| 53 |
+
* :c:func:`Py_DecodeLocale`
|
| 54 |
+
|
| 55 |
+
* Memory allocators:
|
| 56 |
+
|
| 57 |
+
* :c:func:`PyMem_RawMalloc`
|
| 58 |
+
* :c:func:`PyMem_RawRealloc`
|
| 59 |
+
* :c:func:`PyMem_RawCalloc`
|
| 60 |
+
* :c:func:`PyMem_RawFree`
|
| 61 |
+
|
| 62 |
+
.. note::
|
| 63 |
+
|
| 64 |
+
The following functions **should not be called** before
|
| 65 |
+
:c:func:`Py_Initialize`: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPath`,
|
| 66 |
+
:c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`,
|
| 67 |
+
:c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`,
|
| 68 |
+
:c:func:`Py_GetProgramName` and :c:func:`PyEval_InitThreads`.
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
.. _global-conf-vars:
|
| 72 |
+
|
| 73 |
+
Global configuration variables
|
| 74 |
+
==============================
|
| 75 |
+
|
| 76 |
+
Python has variables for the global configuration to control different features
|
| 77 |
+
and options. By default, these flags are controlled by :ref:`command line
|
| 78 |
+
options <using-on-interface-options>`.
|
| 79 |
+
|
| 80 |
+
When a flag is set by an option, the value of the flag is the number of times
|
| 81 |
+
that the option was set. For example, ``-b`` sets :c:data:`Py_BytesWarningFlag`
|
| 82 |
+
to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
|
| 83 |
+
|
| 84 |
+
.. c:var:: Py_BytesWarningFlag
|
| 85 |
+
|
| 86 |
+
Issue a warning when comparing :class:`bytes` or :class:`bytearray` with
|
| 87 |
+
:class:`str` or :class:`bytes` with :class:`int`. Issue an error if greater
|
| 88 |
+
or equal to ``2``.
|
| 89 |
+
|
| 90 |
+
Set by the :option:`-b` option.
|
| 91 |
+
|
| 92 |
+
.. c:var:: Py_DebugFlag
|
| 93 |
+
|
| 94 |
+
Turn on parser debugging output (for expert only, depending on compilation
|
| 95 |
+
options).
|
| 96 |
+
|
| 97 |
+
Set by the :option:`-d` option and the :envvar:`PYTHONDEBUG` environment
|
| 98 |
+
variable.
|
| 99 |
+
|
| 100 |
+
.. c:var:: Py_DontWriteBytecodeFlag
|
| 101 |
+
|
| 102 |
+
If set to non-zero, Python won't try to write ``.pyc`` files on the
|
| 103 |
+
import of source modules.
|
| 104 |
+
|
| 105 |
+
Set by the :option:`-B` option and the :envvar:`PYTHONDONTWRITEBYTECODE`
|
| 106 |
+
environment variable.
|
| 107 |
+
|
| 108 |
+
.. c:var:: Py_FrozenFlag
|
| 109 |
+
|
| 110 |
+
Suppress error messages when calculating the module search path in
|
| 111 |
+
:c:func:`Py_GetPath`.
|
| 112 |
+
|
| 113 |
+
Private flag used by ``_freeze_importlib`` and ``frozenmain`` programs.
|
| 114 |
+
|
| 115 |
+
.. c:var:: Py_HashRandomizationFlag
|
| 116 |
+
|
| 117 |
+
Set to ``1`` if the :envvar:`PYTHONHASHSEED` environment variable is set to
|
| 118 |
+
a non-empty string.
|
| 119 |
+
|
| 120 |
+
If the flag is non-zero, read the :envvar:`PYTHONHASHSEED` environment
|
| 121 |
+
variable to initialize the secret hash seed.
|
| 122 |
+
|
| 123 |
+
.. c:var:: Py_IgnoreEnvironmentFlag
|
| 124 |
+
|
| 125 |
+
Ignore all :envvar:`PYTHON*` environment variables, e.g.
|
| 126 |
+
:envvar:`PYTHONPATH` and :envvar:`PYTHONHOME`, that might be set.
|
| 127 |
+
|
| 128 |
+
Set by the :option:`-E` and :option:`-I` options.
|
| 129 |
+
|
| 130 |
+
.. c:var:: Py_InspectFlag
|
| 131 |
+
|
| 132 |
+
When a script is passed as first argument or the :option:`-c` option is used,
|
| 133 |
+
enter interactive mode after executing the script or the command, even when
|
| 134 |
+
:data:`sys.stdin` does not appear to be a terminal.
|
| 135 |
+
|
| 136 |
+
Set by the :option:`-i` option and the :envvar:`PYTHONINSPECT` environment
|
| 137 |
+
variable.
|
| 138 |
+
|
| 139 |
+
.. c:var:: Py_InteractiveFlag
|
| 140 |
+
|
| 141 |
+
Set by the :option:`-i` option.
|
| 142 |
+
|
| 143 |
+
.. c:var:: Py_IsolatedFlag
|
| 144 |
+
|
| 145 |
+
Run Python in isolated mode. In isolated mode :data:`sys.path` contains
|
| 146 |
+
neither the script's directory nor the user's site-packages directory.
|
| 147 |
+
|
| 148 |
+
Set by the :option:`-I` option.
|
| 149 |
+
|
| 150 |
+
.. versionadded:: 3.4
|
| 151 |
+
|
| 152 |
+
.. c:var:: Py_LegacyWindowsFSEncodingFlag
|
| 153 |
+
|
| 154 |
+
If the flag is non-zero, use the ``mbcs`` encoding instead of the UTF-8
|
| 155 |
+
encoding for the filesystem encoding.
|
| 156 |
+
|
| 157 |
+
Set to ``1`` if the :envvar:`PYTHONLEGACYWINDOWSFSENCODING` environment
|
| 158 |
+
variable is set to a non-empty string.
|
| 159 |
+
|
| 160 |
+
See :pep:`529` for more details.
|
| 161 |
+
|
| 162 |
+
.. availability:: Windows.
|
| 163 |
+
|
| 164 |
+
.. c:var:: Py_LegacyWindowsStdioFlag
|
| 165 |
+
|
| 166 |
+
If the flag is non-zero, use :class:`io.FileIO` instead of
|
| 167 |
+
:class:`WindowsConsoleIO` for :mod:`sys` standard streams.
|
| 168 |
+
|
| 169 |
+
Set to ``1`` if the :envvar:`PYTHONLEGACYWINDOWSSTDIO` environment
|
| 170 |
+
variable is set to a non-empty string.
|
| 171 |
+
|
| 172 |
+
See :pep:`528` for more details.
|
| 173 |
+
|
| 174 |
+
.. availability:: Windows.
|
| 175 |
+
|
| 176 |
+
.. c:var:: Py_NoSiteFlag
|
| 177 |
+
|
| 178 |
+
Disable the import of the module :mod:`site` and the site-dependent
|
| 179 |
+
manipulations of :data:`sys.path` that it entails. Also disable these
|
| 180 |
+
manipulations if :mod:`site` is explicitly imported later (call
|
| 181 |
+
:func:`site.main` if you want them to be triggered).
|
| 182 |
+
|
| 183 |
+
Set by the :option:`-S` option.
|
| 184 |
+
|
| 185 |
+
.. c:var:: Py_NoUserSiteDirectory
|
| 186 |
+
|
| 187 |
+
Don't add the :data:`user site-packages directory <site.USER_SITE>` to
|
| 188 |
+
:data:`sys.path`.
|
| 189 |
+
|
| 190 |
+
Set by the :option:`-s` and :option:`-I` options, and the
|
| 191 |
+
:envvar:`PYTHONNOUSERSITE` environment variable.
|
| 192 |
+
|
| 193 |
+
.. c:var:: Py_OptimizeFlag
|
| 194 |
+
|
| 195 |
+
Set by the :option:`-O` option and the :envvar:`PYTHONOPTIMIZE` environment
|
| 196 |
+
variable.
|
| 197 |
+
|
| 198 |
+
.. c:var:: Py_QuietFlag
|
| 199 |
+
|
| 200 |
+
Don't display the copyright and version messages even in interactive mode.
|
| 201 |
+
|
| 202 |
+
Set by the :option:`-q` option.
|
| 203 |
+
|
| 204 |
+
.. versionadded:: 3.2
|
| 205 |
+
|
| 206 |
+
.. c:var:: Py_UnbufferedStdioFlag
|
| 207 |
+
|
| 208 |
+
Force the stdout and stderr streams to be unbuffered.
|
| 209 |
+
|
| 210 |
+
Set by the :option:`-u` option and the :envvar:`PYTHONUNBUFFERED`
|
| 211 |
+
environment variable.
|
| 212 |
+
|
| 213 |
+
.. c:var:: Py_VerboseFlag
|
| 214 |
+
|
| 215 |
+
Print a message each time a module is initialized, showing the place
|
| 216 |
+
(filename or built-in module) from which it is loaded. If greater or equal
|
| 217 |
+
to ``2``, print a message for each file that is checked for when
|
| 218 |
+
searching for a module. Also provides information on module cleanup at exit.
|
| 219 |
+
|
| 220 |
+
Set by the :option:`-v` option and the :envvar:`PYTHONVERBOSE` environment
|
| 221 |
+
variable.
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
Initializing and finalizing the interpreter
|
| 225 |
+
===========================================
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
.. c:function:: void Py_Initialize()
|
| 229 |
+
|
| 230 |
+
.. index::
|
| 231 |
+
single: Py_SetProgramName()
|
| 232 |
+
single: PyEval_InitThreads()
|
| 233 |
+
single: modules (in module sys)
|
| 234 |
+
single: path (in module sys)
|
| 235 |
+
module: builtins
|
| 236 |
+
module: __main__
|
| 237 |
+
module: sys
|
| 238 |
+
triple: module; search; path
|
| 239 |
+
single: PySys_SetArgv()
|
| 240 |
+
single: PySys_SetArgvEx()
|
| 241 |
+
single: Py_FinalizeEx()
|
| 242 |
+
|
| 243 |
+
Initialize the Python interpreter. In an application embedding Python,
|
| 244 |
+
this should be called before using any other Python/C API functions; see
|
| 245 |
+
:ref:`Before Python Initialization <pre-init-safe>` for the few exceptions.
|
| 246 |
+
|
| 247 |
+
This initializes
|
| 248 |
+
the table of loaded modules (``sys.modules``), and creates the fundamental
|
| 249 |
+
modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`. It also initializes
|
| 250 |
+
the module search path (``sys.path``). It does not set ``sys.argv``; use
|
| 251 |
+
:c:func:`PySys_SetArgvEx` for that. This is a no-op when called for a second time
|
| 252 |
+
(without calling :c:func:`Py_FinalizeEx` first). There is no return value; it is a
|
| 253 |
+
fatal error if the initialization fails.
|
| 254 |
+
|
| 255 |
+
.. note::
|
| 256 |
+
On Windows, changes the console mode from ``O_TEXT`` to ``O_BINARY``, which will
|
| 257 |
+
also affect non-Python uses of the console using the C Runtime.
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
.. c:function:: void Py_InitializeEx(int initsigs)
|
| 261 |
+
|
| 262 |
+
This function works like :c:func:`Py_Initialize` if *initsigs* is ``1``. If
|
| 263 |
+
*initsigs* is ``0``, it skips initialization registration of signal handlers, which
|
| 264 |
+
might be useful when Python is embedded.
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
.. c:function:: int Py_IsInitialized()
|
| 268 |
+
|
| 269 |
+
Return true (nonzero) when the Python interpreter has been initialized, false
|
| 270 |
+
(zero) if not. After :c:func:`Py_FinalizeEx` is called, this returns false until
|
| 271 |
+
:c:func:`Py_Initialize` is called again.
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
.. c:function:: int Py_FinalizeEx()
|
| 275 |
+
|
| 276 |
+
Undo all initializations made by :c:func:`Py_Initialize` and subsequent use of
|
| 277 |
+
Python/C API functions, and destroy all sub-interpreters (see
|
| 278 |
+
:c:func:`Py_NewInterpreter` below) that were created and not yet destroyed since
|
| 279 |
+
the last call to :c:func:`Py_Initialize`. Ideally, this frees all memory
|
| 280 |
+
allocated by the Python interpreter. This is a no-op when called for a second
|
| 281 |
+
time (without calling :c:func:`Py_Initialize` again first). Normally the
|
| 282 |
+
return value is ``0``. If there were errors during finalization
|
| 283 |
+
(flushing buffered data), ``-1`` is returned.
|
| 284 |
+
|
| 285 |
+
This function is provided for a number of reasons. An embedding application
|
| 286 |
+
might want to restart Python without having to restart the application itself.
|
| 287 |
+
An application that has loaded the Python interpreter from a dynamically
|
| 288 |
+
loadable library (or DLL) might want to free all memory allocated by Python
|
| 289 |
+
before unloading the DLL. During a hunt for memory leaks in an application a
|
| 290 |
+
developer might want to free all memory allocated by Python before exiting from
|
| 291 |
+
the application.
|
| 292 |
+
|
| 293 |
+
**Bugs and caveats:** The destruction of modules and objects in modules is done
|
| 294 |
+
in random order; this may cause destructors (:meth:`__del__` methods) to fail
|
| 295 |
+
when they depend on other objects (even functions) or modules. Dynamically
|
| 296 |
+
loaded extension modules loaded by Python are not unloaded. Small amounts of
|
| 297 |
+
memory allocated by the Python interpreter may not be freed (if you find a leak,
|
| 298 |
+
please report it). Memory tied up in circular references between objects is not
|
| 299 |
+
freed. Some memory allocated by extension modules may not be freed. Some
|
| 300 |
+
extensions may not work properly if their initialization routine is called more
|
| 301 |
+
than once; this can happen if an application calls :c:func:`Py_Initialize` and
|
| 302 |
+
:c:func:`Py_FinalizeEx` more than once.
|
| 303 |
+
|
| 304 |
+
.. audit-event:: cpython._PySys_ClearAuditHooks "" c.Py_FinalizeEx
|
| 305 |
+
|
| 306 |
+
.. versionadded:: 3.6
|
| 307 |
+
|
| 308 |
+
.. c:function:: void Py_Finalize()
|
| 309 |
+
|
| 310 |
+
This is a backwards-compatible version of :c:func:`Py_FinalizeEx` that
|
| 311 |
+
disregards the return value.
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
Process-wide parameters
|
| 315 |
+
=======================
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
.. c:function:: int Py_SetStandardStreamEncoding(const char *encoding, const char *errors)
|
| 319 |
+
|
| 320 |
+
.. index::
|
| 321 |
+
single: Py_Initialize()
|
| 322 |
+
single: main()
|
| 323 |
+
triple: stdin; stdout; sdterr
|
| 324 |
+
|
| 325 |
+
This function should be called before :c:func:`Py_Initialize`, if it is
|
| 326 |
+
called at all. It specifies which encoding and error handling to use
|
| 327 |
+
with standard IO, with the same meanings as in :func:`str.encode`.
|
| 328 |
+
|
| 329 |
+
It overrides :envvar:`PYTHONIOENCODING` values, and allows embedding code
|
| 330 |
+
to control IO encoding when the environment variable does not work.
|
| 331 |
+
|
| 332 |
+
*encoding* and/or *errors* may be ``NULL`` to use
|
| 333 |
+
:envvar:`PYTHONIOENCODING` and/or default values (depending on other
|
| 334 |
+
settings).
|
| 335 |
+
|
| 336 |
+
Note that :data:`sys.stderr` always uses the "backslashreplace" error
|
| 337 |
+
handler, regardless of this (or any other) setting.
|
| 338 |
+
|
| 339 |
+
If :c:func:`Py_FinalizeEx` is called, this function will need to be called
|
| 340 |
+
again in order to affect subsequent calls to :c:func:`Py_Initialize`.
|
| 341 |
+
|
| 342 |
+
Returns ``0`` if successful, a nonzero value on error (e.g. calling after the
|
| 343 |
+
interpreter has already been initialized).
|
| 344 |
+
|
| 345 |
+
.. versionadded:: 3.4
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
.. c:function:: void Py_SetProgramName(const wchar_t *name)
|
| 349 |
+
|
| 350 |
+
.. index::
|
| 351 |
+
single: Py_Initialize()
|
| 352 |
+
single: main()
|
| 353 |
+
single: Py_GetPath()
|
| 354 |
+
|
| 355 |
+
This function should be called before :c:func:`Py_Initialize` is called for
|
| 356 |
+
the first time, if it is called at all. It tells the interpreter the value
|
| 357 |
+
of the ``argv[0]`` argument to the :c:func:`main` function of the program
|
| 358 |
+
(converted to wide characters).
|
| 359 |
+
This is used by :c:func:`Py_GetPath` and some other functions below to find
|
| 360 |
+
the Python run-time libraries relative to the interpreter executable. The
|
| 361 |
+
default value is ``'python'``. The argument should point to a
|
| 362 |
+
zero-terminated wide character string in static storage whose contents will not
|
| 363 |
+
change for the duration of the program's execution. No code in the Python
|
| 364 |
+
interpreter will change the contents of this storage.
|
| 365 |
+
|
| 366 |
+
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
|
| 367 |
+
:c:type:`wchar_*` string.
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
.. c:function:: wchar* Py_GetProgramName()
|
| 371 |
+
|
| 372 |
+
.. index:: single: Py_SetProgramName()
|
| 373 |
+
|
| 374 |
+
Return the program name set with :c:func:`Py_SetProgramName`, or the default.
|
| 375 |
+
The returned string points into static storage; the caller should not modify its
|
| 376 |
+
value.
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
.. c:function:: wchar_t* Py_GetPrefix()
|
| 380 |
+
|
| 381 |
+
Return the *prefix* for installed platform-independent files. This is derived
|
| 382 |
+
through a number of complicated rules from the program name set with
|
| 383 |
+
:c:func:`Py_SetProgramName` and some environment variables; for example, if the
|
| 384 |
+
program name is ``'/usr/local/bin/python'``, the prefix is ``'/usr/local'``. The
|
| 385 |
+
returned string points into static storage; the caller should not modify its
|
| 386 |
+
value. This corresponds to the :makevar:`prefix` variable in the top-level
|
| 387 |
+
:file:`Makefile` and the ``--prefix`` argument to the :program:`configure`
|
| 388 |
+
script at build time. The value is available to Python code as ``sys.prefix``.
|
| 389 |
+
It is only useful on Unix. See also the next function.
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
.. c:function:: wchar_t* Py_GetExecPrefix()
|
| 393 |
+
|
| 394 |
+
Return the *exec-prefix* for installed platform-*dependent* files. This is
|
| 395 |
+
derived through a number of complicated rules from the program name set with
|
| 396 |
+
:c:func:`Py_SetProgramName` and some environment variables; for example, if the
|
| 397 |
+
program name is ``'/usr/local/bin/python'``, the exec-prefix is
|
| 398 |
+
``'/usr/local'``. The returned string points into static storage; the caller
|
| 399 |
+
should not modify its value. This corresponds to the :makevar:`exec_prefix`
|
| 400 |
+
variable in the top-level :file:`Makefile` and the ``--exec-prefix``
|
| 401 |
+
argument to the :program:`configure` script at build time. The value is
|
| 402 |
+
available to Python code as ``sys.exec_prefix``. It is only useful on Unix.
|
| 403 |
+
|
| 404 |
+
Background: The exec-prefix differs from the prefix when platform dependent
|
| 405 |
+
files (such as executables and shared libraries) are installed in a different
|
| 406 |
+
directory tree. In a typical installation, platform dependent files may be
|
| 407 |
+
installed in the :file:`/usr/local/plat` subtree while platform independent may
|
| 408 |
+
be installed in :file:`/usr/local`.
|
| 409 |
+
|
| 410 |
+
Generally speaking, a platform is a combination of hardware and software
|
| 411 |
+
families, e.g. Sparc machines running the Solaris 2.x operating system are
|
| 412 |
+
considered the same platform, but Intel machines running Solaris 2.x are another
|
| 413 |
+
platform, and Intel machines running Linux are yet another platform. Different
|
| 414 |
+
major revisions of the same operating system generally also form different
|
| 415 |
+
platforms. Non-Unix operating systems are a different story; the installation
|
| 416 |
+
strategies on those systems are so different that the prefix and exec-prefix are
|
| 417 |
+
meaningless, and set to the empty string. Note that compiled Python bytecode
|
| 418 |
+
files are platform independent (but not independent from the Python version by
|
| 419 |
+
which they were compiled!).
|
| 420 |
+
|
| 421 |
+
System administrators will know how to configure the :program:`mount` or
|
| 422 |
+
:program:`automount` programs to share :file:`/usr/local` between platforms
|
| 423 |
+
while having :file:`/usr/local/plat` be a different filesystem for each
|
| 424 |
+
platform.
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
.. c:function:: wchar_t* Py_GetProgramFullPath()
|
| 428 |
+
|
| 429 |
+
.. index::
|
| 430 |
+
single: Py_SetProgramName()
|
| 431 |
+
single: executable (in module sys)
|
| 432 |
+
|
| 433 |
+
Return the full program name of the Python executable; this is computed as a
|
| 434 |
+
side-effect of deriving the default module search path from the program name
|
| 435 |
+
(set by :c:func:`Py_SetProgramName` above). The returned string points into
|
| 436 |
+
static storage; the caller should not modify its value. The value is available
|
| 437 |
+
to Python code as ``sys.executable``.
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
.. c:function:: wchar_t* Py_GetPath()
|
| 441 |
+
|
| 442 |
+
.. index::
|
| 443 |
+
triple: module; search; path
|
| 444 |
+
single: path (in module sys)
|
| 445 |
+
single: Py_SetPath()
|
| 446 |
+
|
| 447 |
+
Return the default module search path; this is computed from the program name
|
| 448 |
+
(set by :c:func:`Py_SetProgramName` above) and some environment variables.
|
| 449 |
+
The returned string consists of a series of directory names separated by a
|
| 450 |
+
platform dependent delimiter character. The delimiter character is ``':'``
|
| 451 |
+
on Unix and Mac OS X, ``';'`` on Windows. The returned string points into
|
| 452 |
+
static storage; the caller should not modify its value. The list
|
| 453 |
+
:data:`sys.path` is initialized with this value on interpreter startup; it
|
| 454 |
+
can be (and usually is) modified later to change the search path for loading
|
| 455 |
+
modules.
|
| 456 |
+
|
| 457 |
+
.. XXX should give the exact rules
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
.. c:function:: void Py_SetPath(const wchar_t *)
|
| 461 |
+
|
| 462 |
+
.. index::
|
| 463 |
+
triple: module; search; path
|
| 464 |
+
single: path (in module sys)
|
| 465 |
+
single: Py_GetPath()
|
| 466 |
+
|
| 467 |
+
Set the default module search path. If this function is called before
|
| 468 |
+
:c:func:`Py_Initialize`, then :c:func:`Py_GetPath` won't attempt to compute a
|
| 469 |
+
default search path but uses the one provided instead. This is useful if
|
| 470 |
+
Python is embedded by an application that has full knowledge of the location
|
| 471 |
+
of all modules. The path components should be separated by the platform
|
| 472 |
+
dependent delimiter character, which is ``':'`` on Unix and Mac OS X, ``';'``
|
| 473 |
+
on Windows.
|
| 474 |
+
|
| 475 |
+
This also causes :data:`sys.executable` to be set to the program
|
| 476 |
+
full path (see :c:func:`Py_GetProgramFullPath`) and for :data:`sys.prefix` and
|
| 477 |
+
:data:`sys.exec_prefix` to be empty. It is up to the caller to modify these
|
| 478 |
+
if required after calling :c:func:`Py_Initialize`.
|
| 479 |
+
|
| 480 |
+
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
|
| 481 |
+
:c:type:`wchar_*` string.
|
| 482 |
+
|
| 483 |
+
The path argument is copied internally, so the caller may free it after the
|
| 484 |
+
call completes.
|
| 485 |
+
|
| 486 |
+
.. versionchanged:: 3.8
|
| 487 |
+
The program full path is now used for :data:`sys.executable`, instead
|
| 488 |
+
of the program name.
|
| 489 |
+
|
| 490 |
+
|
| 491 |
+
.. c:function:: const char* Py_GetVersion()
|
| 492 |
+
|
| 493 |
+
Return the version of this Python interpreter. This is a string that looks
|
| 494 |
+
something like ::
|
| 495 |
+
|
| 496 |
+
"3.0a5+ (py3k:63103M, May 12 2008, 00:53:55) \n[GCC 4.2.3]"
|
| 497 |
+
|
| 498 |
+
.. index:: single: version (in module sys)
|
| 499 |
+
|
| 500 |
+
The first word (up to the first space character) is the current Python version;
|
| 501 |
+
the first three characters are the major and minor version separated by a
|
| 502 |
+
period. The returned string points into static storage; the caller should not
|
| 503 |
+
modify its value. The value is available to Python code as :data:`sys.version`.
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
.. c:function:: const char* Py_GetPlatform()
|
| 507 |
+
|
| 508 |
+
.. index:: single: platform (in module sys)
|
| 509 |
+
|
| 510 |
+
Return the platform identifier for the current platform. On Unix, this is
|
| 511 |
+
formed from the "official" name of the operating system, converted to lower
|
| 512 |
+
case, followed by the major revision number; e.g., for Solaris 2.x, which is
|
| 513 |
+
also known as SunOS 5.x, the value is ``'sunos5'``. On Mac OS X, it is
|
| 514 |
+
``'darwin'``. On Windows, it is ``'win'``. The returned string points into
|
| 515 |
+
static storage; the caller should not modify its value. The value is available
|
| 516 |
+
to Python code as ``sys.platform``.
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
.. c:function:: const char* Py_GetCopyright()
|
| 520 |
+
|
| 521 |
+
Return the official copyright string for the current Python version, for example
|
| 522 |
+
|
| 523 |
+
``'Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam'``
|
| 524 |
+
|
| 525 |
+
.. index:: single: copyright (in module sys)
|
| 526 |
+
|
| 527 |
+
The returned string points into static storage; the caller should not modify its
|
| 528 |
+
value. The value is available to Python code as ``sys.copyright``.
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
.. c:function:: const char* Py_GetCompiler()
|
| 532 |
+
|
| 533 |
+
Return an indication of the compiler used to build the current Python version,
|
| 534 |
+
in square brackets, for example::
|
| 535 |
+
|
| 536 |
+
"[GCC 2.7.2.2]"
|
| 537 |
+
|
| 538 |
+
.. index:: single: version (in module sys)
|
| 539 |
+
|
| 540 |
+
The returned string points into static storage; the caller should not modify its
|
| 541 |
+
value. The value is available to Python code as part of the variable
|
| 542 |
+
``sys.version``.
|
| 543 |
+
|
| 544 |
+
|
| 545 |
+
.. c:function:: const char* Py_GetBuildInfo()
|
| 546 |
+
|
| 547 |
+
Return information about the sequence number and build date and time of the
|
| 548 |
+
current Python interpreter instance, for example ::
|
| 549 |
+
|
| 550 |
+
"#67, Aug 1 1997, 22:34:28"
|
| 551 |
+
|
| 552 |
+
.. index:: single: version (in module sys)
|
| 553 |
+
|
| 554 |
+
The returned string points into static storage; the caller should not modify its
|
| 555 |
+
value. The value is available to Python code as part of the variable
|
| 556 |
+
``sys.version``.
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
.. c:function:: void PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
|
| 560 |
+
|
| 561 |
+
.. index::
|
| 562 |
+
single: main()
|
| 563 |
+
single: Py_FatalError()
|
| 564 |
+
single: argv (in module sys)
|
| 565 |
+
|
| 566 |
+
Set :data:`sys.argv` based on *argc* and *argv*. These parameters are
|
| 567 |
+
similar to those passed to the program's :c:func:`main` function with the
|
| 568 |
+
difference that the first entry should refer to the script file to be
|
| 569 |
+
executed rather than the executable hosting the Python interpreter. If there
|
| 570 |
+
isn't a script that will be run, the first entry in *argv* can be an empty
|
| 571 |
+
string. If this function fails to initialize :data:`sys.argv`, a fatal
|
| 572 |
+
condition is signalled using :c:func:`Py_FatalError`.
|
| 573 |
+
|
| 574 |
+
If *updatepath* is zero, this is all the function does. If *updatepath*
|
| 575 |
+
is non-zero, the function also modifies :data:`sys.path` according to the
|
| 576 |
+
following algorithm:
|
| 577 |
+
|
| 578 |
+
- If the name of an existing script is passed in ``argv[0]``, the absolute
|
| 579 |
+
path of the directory where the script is located is prepended to
|
| 580 |
+
:data:`sys.path`.
|
| 581 |
+
- Otherwise (that is, if *argc* is ``0`` or ``argv[0]`` doesn't point
|
| 582 |
+
to an existing file name), an empty string is prepended to
|
| 583 |
+
:data:`sys.path`, which is the same as prepending the current working
|
| 584 |
+
directory (``"."``).
|
| 585 |
+
|
| 586 |
+
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
|
| 587 |
+
:c:type:`wchar_*` string.
|
| 588 |
+
|
| 589 |
+
.. note::
|
| 590 |
+
It is recommended that applications embedding the Python interpreter
|
| 591 |
+
for purposes other than executing a single script pass ``0`` as *updatepath*,
|
| 592 |
+
and update :data:`sys.path` themselves if desired.
|
| 593 |
+
See `CVE-2008-5983 <https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983>`_.
|
| 594 |
+
|
| 595 |
+
On versions before 3.1.3, you can achieve the same effect by manually
|
| 596 |
+
popping the first :data:`sys.path` element after having called
|
| 597 |
+
:c:func:`PySys_SetArgv`, for example using::
|
| 598 |
+
|
| 599 |
+
PyRun_SimpleString("import sys; sys.path.pop(0)\n");
|
| 600 |
+
|
| 601 |
+
.. versionadded:: 3.1.3
|
| 602 |
+
|
| 603 |
+
.. XXX impl. doesn't seem consistent in allowing ``0``/``NULL`` for the params;
|
| 604 |
+
check w/ Guido.
|
| 605 |
+
|
| 606 |
+
|
| 607 |
+
.. c:function:: void PySys_SetArgv(int argc, wchar_t **argv)
|
| 608 |
+
|
| 609 |
+
This function works like :c:func:`PySys_SetArgvEx` with *updatepath* set
|
| 610 |
+
to ``1`` unless the :program:`python` interpreter was started with the
|
| 611 |
+
:option:`-I`.
|
| 612 |
+
|
| 613 |
+
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
|
| 614 |
+
:c:type:`wchar_*` string.
|
| 615 |
+
|
| 616 |
+
.. versionchanged:: 3.4 The *updatepath* value depends on :option:`-I`.
|
| 617 |
+
|
| 618 |
+
|
| 619 |
+
.. c:function:: void Py_SetPythonHome(const wchar_t *home)
|
| 620 |
+
|
| 621 |
+
Set the default "home" directory, that is, the location of the standard
|
| 622 |
+
Python libraries. See :envvar:`PYTHONHOME` for the meaning of the
|
| 623 |
+
argument string.
|
| 624 |
+
|
| 625 |
+
The argument should point to a zero-terminated character string in static
|
| 626 |
+
storage whose contents will not change for the duration of the program's
|
| 627 |
+
execution. No code in the Python interpreter will change the contents of
|
| 628 |
+
this storage.
|
| 629 |
+
|
| 630 |
+
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
|
| 631 |
+
:c:type:`wchar_*` string.
|
| 632 |
+
|
| 633 |
+
|
| 634 |
+
.. c:function:: w_char* Py_GetPythonHome()
|
| 635 |
+
|
| 636 |
+
Return the default "home", that is, the value set by a previous call to
|
| 637 |
+
:c:func:`Py_SetPythonHome`, or the value of the :envvar:`PYTHONHOME`
|
| 638 |
+
environment variable if it is set.
|
| 639 |
+
|
| 640 |
+
|
| 641 |
+
.. _threads:
|
| 642 |
+
|
| 643 |
+
Thread State and the Global Interpreter Lock
|
| 644 |
+
============================================
|
| 645 |
+
|
| 646 |
+
.. index::
|
| 647 |
+
single: global interpreter lock
|
| 648 |
+
single: interpreter lock
|
| 649 |
+
single: lock, interpreter
|
| 650 |
+
|
| 651 |
+
The Python interpreter is not fully thread-safe. In order to support
|
| 652 |
+
multi-threaded Python programs, there's a global lock, called the :term:`global
|
| 653 |
+
interpreter lock` or :term:`GIL`, that must be held by the current thread before
|
| 654 |
+
it can safely access Python objects. Without the lock, even the simplest
|
| 655 |
+
operations could cause problems in a multi-threaded program: for example, when
|
| 656 |
+
two threads simultaneously increment the reference count of the same object, the
|
| 657 |
+
reference count could end up being incremented only once instead of twice.
|
| 658 |
+
|
| 659 |
+
.. index:: single: setswitchinterval() (in module sys)
|
| 660 |
+
|
| 661 |
+
Therefore, the rule exists that only the thread that has acquired the
|
| 662 |
+
:term:`GIL` may operate on Python objects or call Python/C API functions.
|
| 663 |
+
In order to emulate concurrency of execution, the interpreter regularly
|
| 664 |
+
tries to switch threads (see :func:`sys.setswitchinterval`). The lock is also
|
| 665 |
+
released around potentially blocking I/O operations like reading or writing
|
| 666 |
+
a file, so that other Python threads can run in the meantime.
|
| 667 |
+
|
| 668 |
+
.. index::
|
| 669 |
+
single: PyThreadState
|
| 670 |
+
single: PyThreadState
|
| 671 |
+
|
| 672 |
+
The Python interpreter keeps some thread-specific bookkeeping information
|
| 673 |
+
inside a data structure called :c:type:`PyThreadState`. There's also one
|
| 674 |
+
global variable pointing to the current :c:type:`PyThreadState`: it can
|
| 675 |
+
be retrieved using :c:func:`PyThreadState_Get`.
|
| 676 |
+
|
| 677 |
+
Releasing the GIL from extension code
|
| 678 |
+
-------------------------------------
|
| 679 |
+
|
| 680 |
+
Most extension code manipulating the :term:`GIL` has the following simple
|
| 681 |
+
structure::
|
| 682 |
+
|
| 683 |
+
Save the thread state in a local variable.
|
| 684 |
+
Release the global interpreter lock.
|
| 685 |
+
... Do some blocking I/O operation ...
|
| 686 |
+
Reacquire the global interpreter lock.
|
| 687 |
+
Restore the thread state from the local variable.
|
| 688 |
+
|
| 689 |
+
This is so common that a pair of macros exists to simplify it::
|
| 690 |
+
|
| 691 |
+
Py_BEGIN_ALLOW_THREADS
|
| 692 |
+
... Do some blocking I/O operation ...
|
| 693 |
+
Py_END_ALLOW_THREADS
|
| 694 |
+
|
| 695 |
+
.. index::
|
| 696 |
+
single: Py_BEGIN_ALLOW_THREADS
|
| 697 |
+
single: Py_END_ALLOW_THREADS
|
| 698 |
+
|
| 699 |
+
The :c:macro:`Py_BEGIN_ALLOW_THREADS` macro opens a new block and declares a
|
| 700 |
+
hidden local variable; the :c:macro:`Py_END_ALLOW_THREADS` macro closes the
|
| 701 |
+
block.
|
| 702 |
+
|
| 703 |
+
The block above expands to the following code::
|
| 704 |
+
|
| 705 |
+
PyThreadState *_save;
|
| 706 |
+
|
| 707 |
+
_save = PyEval_SaveThread();
|
| 708 |
+
... Do some blocking I/O operation ...
|
| 709 |
+
PyEval_RestoreThread(_save);
|
| 710 |
+
|
| 711 |
+
.. index::
|
| 712 |
+
single: PyEval_RestoreThread()
|
| 713 |
+
single: PyEval_SaveThread()
|
| 714 |
+
|
| 715 |
+
Here is how these functions work: the global interpreter lock is used to protect the pointer to the
|
| 716 |
+
current thread state. When releasing the lock and saving the thread state,
|
| 717 |
+
the current thread state pointer must be retrieved before the lock is released
|
| 718 |
+
(since another thread could immediately acquire the lock and store its own thread
|
| 719 |
+
state in the global variable). Conversely, when acquiring the lock and restoring
|
| 720 |
+
the thread state, the lock must be acquired before storing the thread state
|
| 721 |
+
pointer.
|
| 722 |
+
|
| 723 |
+
.. note::
|
| 724 |
+
Calling system I/O functions is the most common use case for releasing
|
| 725 |
+
the GIL, but it can also be useful before calling long-running computations
|
| 726 |
+
which don't need access to Python objects, such as compression or
|
| 727 |
+
cryptographic functions operating over memory buffers. For example, the
|
| 728 |
+
standard :mod:`zlib` and :mod:`hashlib` modules release the GIL when
|
| 729 |
+
compressing or hashing data.
|
| 730 |
+
|
| 731 |
+
|
| 732 |
+
.. _gilstate:
|
| 733 |
+
|
| 734 |
+
Non-Python created threads
|
| 735 |
+
--------------------------
|
| 736 |
+
|
| 737 |
+
When threads are created using the dedicated Python APIs (such as the
|
| 738 |
+
:mod:`threading` module), a thread state is automatically associated to them
|
| 739 |
+
and the code showed above is therefore correct. However, when threads are
|
| 740 |
+
created from C (for example by a third-party library with its own thread
|
| 741 |
+
management), they don't hold the GIL, nor is there a thread state structure
|
| 742 |
+
for them.
|
| 743 |
+
|
| 744 |
+
If you need to call Python code from these threads (often this will be part
|
| 745 |
+
of a callback API provided by the aforementioned third-party library),
|
| 746 |
+
you must first register these threads with the interpreter by
|
| 747 |
+
creating a thread state data structure, then acquiring the GIL, and finally
|
| 748 |
+
storing their thread state pointer, before you can start using the Python/C
|
| 749 |
+
API. When you are done, you should reset the thread state pointer, release
|
| 750 |
+
the GIL, and finally free the thread state data structure.
|
| 751 |
+
|
| 752 |
+
The :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release` functions do
|
| 753 |
+
all of the above automatically. The typical idiom for calling into Python
|
| 754 |
+
from a C thread is::
|
| 755 |
+
|
| 756 |
+
PyGILState_STATE gstate;
|
| 757 |
+
gstate = PyGILState_Ensure();
|
| 758 |
+
|
| 759 |
+
/* Perform Python actions here. */
|
| 760 |
+
result = CallSomeFunction();
|
| 761 |
+
/* evaluate result or handle exception */
|
| 762 |
+
|
| 763 |
+
/* Release the thread. No Python API allowed beyond this point. */
|
| 764 |
+
PyGILState_Release(gstate);
|
| 765 |
+
|
| 766 |
+
Note that the :c:func:`PyGILState_\*` functions assume there is only one global
|
| 767 |
+
interpreter (created automatically by :c:func:`Py_Initialize`). Python
|
| 768 |
+
supports the creation of additional interpreters (using
|
| 769 |
+
:c:func:`Py_NewInterpreter`), but mixing multiple interpreters and the
|
| 770 |
+
:c:func:`PyGILState_\*` API is unsupported.
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
.. _fork-and-threads:
|
| 774 |
+
|
| 775 |
+
Cautions about fork()
|
| 776 |
+
---------------------
|
| 777 |
+
|
| 778 |
+
Another important thing to note about threads is their behaviour in the face
|
| 779 |
+
of the C :c:func:`fork` call. On most systems with :c:func:`fork`, after a
|
| 780 |
+
process forks only the thread that issued the fork will exist. This has a
|
| 781 |
+
concrete impact both on how locks must be handled and on all stored state
|
| 782 |
+
in CPython's runtime.
|
| 783 |
+
|
| 784 |
+
The fact that only the "current" thread remains
|
| 785 |
+
means any locks held by other threads will never be released. Python solves
|
| 786 |
+
this for :func:`os.fork` by acquiring the locks it uses internally before
|
| 787 |
+
the fork, and releasing them afterwards. In addition, it resets any
|
| 788 |
+
:ref:`lock-objects` in the child. When extending or embedding Python, there
|
| 789 |
+
is no way to inform Python of additional (non-Python) locks that need to be
|
| 790 |
+
acquired before or reset after a fork. OS facilities such as
|
| 791 |
+
:c:func:`pthread_atfork` would need to be used to accomplish the same thing.
|
| 792 |
+
Additionally, when extending or embedding Python, calling :c:func:`fork`
|
| 793 |
+
directly rather than through :func:`os.fork` (and returning to or calling
|
| 794 |
+
into Python) may result in a deadlock by one of Python's internal locks
|
| 795 |
+
being held by a thread that is defunct after the fork.
|
| 796 |
+
:c:func:`PyOS_AfterFork_Child` tries to reset the necessary locks, but is not
|
| 797 |
+
always able to.
|
| 798 |
+
|
| 799 |
+
The fact that all other threads go away also means that CPython's
|
| 800 |
+
runtime state there must be cleaned up properly, which :func:`os.fork`
|
| 801 |
+
does. This means finalizing all other :c:type:`PyThreadState` objects
|
| 802 |
+
belonging to the current interpreter and all other
|
| 803 |
+
:c:type:`PyInterpreterState` objects. Due to this and the special
|
| 804 |
+
nature of the :ref:`"main" interpreter <sub-interpreter-support>`,
|
| 805 |
+
:c:func:`fork` should only be called in that interpreter's "main"
|
| 806 |
+
thread, where the CPython global runtime was originally initialized.
|
| 807 |
+
The only exception is if :c:func:`exec` will be called immediately
|
| 808 |
+
after.
|
| 809 |
+
|
| 810 |
+
|
| 811 |
+
High-level API
|
| 812 |
+
--------------
|
| 813 |
+
|
| 814 |
+
These are the most commonly used types and functions when writing C extension
|
| 815 |
+
code, or when embedding the Python interpreter:
|
| 816 |
+
|
| 817 |
+
.. c:type:: PyInterpreterState
|
| 818 |
+
|
| 819 |
+
This data structure represents the state shared by a number of cooperating
|
| 820 |
+
threads. Threads belonging to the same interpreter share their module
|
| 821 |
+
administration and a few other internal items. There are no public members in
|
| 822 |
+
this structure.
|
| 823 |
+
|
| 824 |
+
Threads belonging to different interpreters initially share nothing, except
|
| 825 |
+
process state like available memory, open file descriptors and such. The global
|
| 826 |
+
interpreter lock is also shared by all threads, regardless of to which
|
| 827 |
+
interpreter they belong.
|
| 828 |
+
|
| 829 |
+
|
| 830 |
+
.. c:type:: PyThreadState
|
| 831 |
+
|
| 832 |
+
This data structure represents the state of a single thread. The only public
|
| 833 |
+
data member is :c:type:`PyInterpreterState \*`:attr:`interp`, which points to
|
| 834 |
+
this thread's interpreter state.
|
| 835 |
+
|
| 836 |
+
|
| 837 |
+
.. c:function:: void PyEval_InitThreads()
|
| 838 |
+
|
| 839 |
+
.. index::
|
| 840 |
+
single: PyEval_AcquireThread()
|
| 841 |
+
single: PyEval_ReleaseThread()
|
| 842 |
+
single: PyEval_SaveThread()
|
| 843 |
+
single: PyEval_RestoreThread()
|
| 844 |
+
|
| 845 |
+
Deprecated function which does nothing.
|
| 846 |
+
|
| 847 |
+
In Python 3.6 and older, this function created the GIL if it didn't exist.
|
| 848 |
+
|
| 849 |
+
.. versionchanged:: 3.9
|
| 850 |
+
The function now does nothing.
|
| 851 |
+
|
| 852 |
+
.. versionchanged:: 3.7
|
| 853 |
+
This function is now called by :c:func:`Py_Initialize()`, so you don't
|
| 854 |
+
have to call it yourself anymore.
|
| 855 |
+
|
| 856 |
+
.. versionchanged:: 3.2
|
| 857 |
+
This function cannot be called before :c:func:`Py_Initialize()` anymore.
|
| 858 |
+
|
| 859 |
+
.. deprecated-removed:: 3.9 3.11
|
| 860 |
+
|
| 861 |
+
.. index:: module: _thread
|
| 862 |
+
|
| 863 |
+
|
| 864 |
+
.. c:function:: int PyEval_ThreadsInitialized()
|
| 865 |
+
|
| 866 |
+
Returns a non-zero value if :c:func:`PyEval_InitThreads` has been called. This
|
| 867 |
+
function can be called without holding the GIL, and therefore can be used to
|
| 868 |
+
avoid calls to the locking API when running single-threaded.
|
| 869 |
+
|
| 870 |
+
.. versionchanged:: 3.7
|
| 871 |
+
The :term:`GIL` is now initialized by :c:func:`Py_Initialize()`.
|
| 872 |
+
|
| 873 |
+
.. deprecated-removed:: 3.9 3.11
|
| 874 |
+
|
| 875 |
+
|
| 876 |
+
.. c:function:: PyThreadState* PyEval_SaveThread()
|
| 877 |
+
|
| 878 |
+
Release the global interpreter lock (if it has been created) and reset the
|
| 879 |
+
thread state to ``NULL``, returning the previous thread state (which is not
|
| 880 |
+
``NULL``). If the lock has been created, the current thread must have
|
| 881 |
+
acquired it.
|
| 882 |
+
|
| 883 |
+
|
| 884 |
+
.. c:function:: void PyEval_RestoreThread(PyThreadState *tstate)
|
| 885 |
+
|
| 886 |
+
Acquire the global interpreter lock (if it has been created) and set the
|
| 887 |
+
thread state to *tstate*, which must not be ``NULL``. If the lock has been
|
| 888 |
+
created, the current thread must not have acquired it, otherwise deadlock
|
| 889 |
+
ensues.
|
| 890 |
+
|
| 891 |
+
.. note::
|
| 892 |
+
Calling this function from a thread when the runtime is finalizing
|
| 893 |
+
will terminate the thread, even if the thread was not created by Python.
|
| 894 |
+
You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
|
| 895 |
+
check if the interpreter is in process of being finalized before calling
|
| 896 |
+
this function to avoid unwanted termination.
|
| 897 |
+
|
| 898 |
+
.. c:function:: PyThreadState* PyThreadState_Get()
|
| 899 |
+
|
| 900 |
+
Return the current thread state. The global interpreter lock must be held.
|
| 901 |
+
When the current thread state is ``NULL``, this issues a fatal error (so that
|
| 902 |
+
the caller needn't check for ``NULL``).
|
| 903 |
+
|
| 904 |
+
|
| 905 |
+
.. c:function:: PyThreadState* PyThreadState_Swap(PyThreadState *tstate)
|
| 906 |
+
|
| 907 |
+
Swap the current thread state with the thread state given by the argument
|
| 908 |
+
*tstate*, which may be ``NULL``. The global interpreter lock must be held
|
| 909 |
+
and is not released.
|
| 910 |
+
|
| 911 |
+
|
| 912 |
+
The following functions use thread-local storage, and are not compatible
|
| 913 |
+
with sub-interpreters:
|
| 914 |
+
|
| 915 |
+
.. c:function:: PyGILState_STATE PyGILState_Ensure()
|
| 916 |
+
|
| 917 |
+
Ensure that the current thread is ready to call the Python C API regardless
|
| 918 |
+
of the current state of Python, or of the global interpreter lock. This may
|
| 919 |
+
be called as many times as desired by a thread as long as each call is
|
| 920 |
+
matched with a call to :c:func:`PyGILState_Release`. In general, other
|
| 921 |
+
thread-related APIs may be used between :c:func:`PyGILState_Ensure` and
|
| 922 |
+
:c:func:`PyGILState_Release` calls as long as the thread state is restored to
|
| 923 |
+
its previous state before the Release(). For example, normal usage of the
|
| 924 |
+
:c:macro:`Py_BEGIN_ALLOW_THREADS` and :c:macro:`Py_END_ALLOW_THREADS` macros is
|
| 925 |
+
acceptable.
|
| 926 |
+
|
| 927 |
+
The return value is an opaque "handle" to the thread state when
|
| 928 |
+
:c:func:`PyGILState_Ensure` was called, and must be passed to
|
| 929 |
+
:c:func:`PyGILState_Release` to ensure Python is left in the same state. Even
|
| 930 |
+
though recursive calls are allowed, these handles *cannot* be shared - each
|
| 931 |
+
unique call to :c:func:`PyGILState_Ensure` must save the handle for its call
|
| 932 |
+
to :c:func:`PyGILState_Release`.
|
| 933 |
+
|
| 934 |
+
When the function returns, the current thread will hold the GIL and be able
|
| 935 |
+
to call arbitrary Python code. Failure is a fatal error.
|
| 936 |
+
|
| 937 |
+
.. note::
|
| 938 |
+
Calling this function from a thread when the runtime is finalizing
|
| 939 |
+
will terminate the thread, even if the thread was not created by Python.
|
| 940 |
+
You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
|
| 941 |
+
check if the interpreter is in process of being finalized before calling
|
| 942 |
+
this function to avoid unwanted termination.
|
| 943 |
+
|
| 944 |
+
.. c:function:: void PyGILState_Release(PyGILState_STATE)
|
| 945 |
+
|
| 946 |
+
Release any resources previously acquired. After this call, Python's state will
|
| 947 |
+
be the same as it was prior to the corresponding :c:func:`PyGILState_Ensure` call
|
| 948 |
+
(but generally this state will be unknown to the caller, hence the use of the
|
| 949 |
+
GILState API).
|
| 950 |
+
|
| 951 |
+
Every call to :c:func:`PyGILState_Ensure` must be matched by a call to
|
| 952 |
+
:c:func:`PyGILState_Release` on the same thread.
|
| 953 |
+
|
| 954 |
+
|
| 955 |
+
.. c:function:: PyThreadState* PyGILState_GetThisThreadState()
|
| 956 |
+
|
| 957 |
+
Get the current thread state for this thread. May return ``NULL`` if no
|
| 958 |
+
GILState API has been used on the current thread. Note that the main thread
|
| 959 |
+
always has such a thread-state, even if no auto-thread-state call has been
|
| 960 |
+
made on the main thread. This is mainly a helper/diagnostic function.
|
| 961 |
+
|
| 962 |
+
|
| 963 |
+
.. c:function:: int PyGILState_Check()
|
| 964 |
+
|
| 965 |
+
Return ``1`` if the current thread is holding the GIL and ``0`` otherwise.
|
| 966 |
+
This function can be called from any thread at any time.
|
| 967 |
+
Only if it has had its Python thread state initialized and currently is
|
| 968 |
+
holding the GIL will it return ``1``.
|
| 969 |
+
This is mainly a helper/diagnostic function. It can be useful
|
| 970 |
+
for example in callback contexts or memory allocation functions when
|
| 971 |
+
knowing that the GIL is locked can allow the caller to perform sensitive
|
| 972 |
+
actions or otherwise behave differently.
|
| 973 |
+
|
| 974 |
+
.. versionadded:: 3.4
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
The following macros are normally used without a trailing semicolon; look for
|
| 978 |
+
example usage in the Python source distribution.
|
| 979 |
+
|
| 980 |
+
|
| 981 |
+
.. c:macro:: Py_BEGIN_ALLOW_THREADS
|
| 982 |
+
|
| 983 |
+
This macro expands to ``{ PyThreadState *_save; _save = PyEval_SaveThread();``.
|
| 984 |
+
Note that it contains an opening brace; it must be matched with a following
|
| 985 |
+
:c:macro:`Py_END_ALLOW_THREADS` macro. See above for further discussion of this
|
| 986 |
+
macro.
|
| 987 |
+
|
| 988 |
+
|
| 989 |
+
.. c:macro:: Py_END_ALLOW_THREADS
|
| 990 |
+
|
| 991 |
+
This macro expands to ``PyEval_RestoreThread(_save); }``. Note that it contains
|
| 992 |
+
a closing brace; it must be matched with an earlier
|
| 993 |
+
:c:macro:`Py_BEGIN_ALLOW_THREADS` macro. See above for further discussion of
|
| 994 |
+
this macro.
|
| 995 |
+
|
| 996 |
+
|
| 997 |
+
.. c:macro:: Py_BLOCK_THREADS
|
| 998 |
+
|
| 999 |
+
This macro expands to ``PyEval_RestoreThread(_save);``: it is equivalent to
|
| 1000 |
+
:c:macro:`Py_END_ALLOW_THREADS` without the closing brace.
|
| 1001 |
+
|
| 1002 |
+
|
| 1003 |
+
.. c:macro:: Py_UNBLOCK_THREADS
|
| 1004 |
+
|
| 1005 |
+
This macro expands to ``_save = PyEval_SaveThread();``: it is equivalent to
|
| 1006 |
+
:c:macro:`Py_BEGIN_ALLOW_THREADS` without the opening brace and variable
|
| 1007 |
+
declaration.
|
| 1008 |
+
|
| 1009 |
+
|
| 1010 |
+
Low-level API
|
| 1011 |
+
-------------
|
| 1012 |
+
|
| 1013 |
+
All of the following functions must be called after :c:func:`Py_Initialize`.
|
| 1014 |
+
|
| 1015 |
+
.. versionchanged:: 3.7
|
| 1016 |
+
:c:func:`Py_Initialize()` now initializes the :term:`GIL`.
|
| 1017 |
+
|
| 1018 |
+
|
| 1019 |
+
.. c:function:: PyInterpreterState* PyInterpreterState_New()
|
| 1020 |
+
|
| 1021 |
+
Create a new interpreter state object. The global interpreter lock need not
|
| 1022 |
+
be held, but may be held if it is necessary to serialize calls to this
|
| 1023 |
+
function.
|
| 1024 |
+
|
| 1025 |
+
.. audit-event:: cpython.PyInterpreterState_New "" c.PyInterpreterState_New
|
| 1026 |
+
|
| 1027 |
+
|
| 1028 |
+
.. c:function:: void PyInterpreterState_Clear(PyInterpreterState *interp)
|
| 1029 |
+
|
| 1030 |
+
Reset all information in an interpreter state object. The global interpreter
|
| 1031 |
+
lock must be held.
|
| 1032 |
+
|
| 1033 |
+
.. audit-event:: cpython.PyInterpreterState_Clear "" c.PyInterpreterState_Clear
|
| 1034 |
+
|
| 1035 |
+
|
| 1036 |
+
.. c:function:: void PyInterpreterState_Delete(PyInterpreterState *interp)
|
| 1037 |
+
|
| 1038 |
+
Destroy an interpreter state object. The global interpreter lock need not be
|
| 1039 |
+
held. The interpreter state must have been reset with a previous call to
|
| 1040 |
+
:c:func:`PyInterpreterState_Clear`.
|
| 1041 |
+
|
| 1042 |
+
|
| 1043 |
+
.. c:function:: PyThreadState* PyThreadState_New(PyInterpreterState *interp)
|
| 1044 |
+
|
| 1045 |
+
Create a new thread state object belonging to the given interpreter object.
|
| 1046 |
+
The global interpreter lock need not be held, but may be held if it is
|
| 1047 |
+
necessary to serialize calls to this function.
|
| 1048 |
+
|
| 1049 |
+
|
| 1050 |
+
.. c:function:: void PyThreadState_Clear(PyThreadState *tstate)
|
| 1051 |
+
|
| 1052 |
+
Reset all information in a thread state object. The global interpreter lock
|
| 1053 |
+
must be held.
|
| 1054 |
+
|
| 1055 |
+
.. versionchanged:: 3.9
|
| 1056 |
+
This function now calls the :c:member:`PyThreadState.on_delete` callback.
|
| 1057 |
+
Previously, that happened in :c:func:`PyThreadState_Delete`.
|
| 1058 |
+
|
| 1059 |
+
|
| 1060 |
+
.. c:function:: void PyThreadState_Delete(PyThreadState *tstate)
|
| 1061 |
+
|
| 1062 |
+
Destroy a thread state object. The global interpreter lock need not be held.
|
| 1063 |
+
The thread state must have been reset with a previous call to
|
| 1064 |
+
:c:func:`PyThreadState_Clear`.
|
| 1065 |
+
|
| 1066 |
+
|
| 1067 |
+
.. c:function:: void PyThreadState_DeleteCurrent(void)
|
| 1068 |
+
|
| 1069 |
+
Destroy the current thread state and release the global interpreter lock.
|
| 1070 |
+
Like :c:func:`PyThreadState_Delete`, the global interpreter lock need not
|
| 1071 |
+
be held. The thread state must have been reset with a previous call
|
| 1072 |
+
to :c:func:`PyThreadState_Clear`.
|
| 1073 |
+
|
| 1074 |
+
|
| 1075 |
+
.. c:function:: PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate)
|
| 1076 |
+
|
| 1077 |
+
Get the current frame of the Python thread state *tstate*.
|
| 1078 |
+
|
| 1079 |
+
Return a strong reference. Return ``NULL`` if no frame is currently
|
| 1080 |
+
executing.
|
| 1081 |
+
|
| 1082 |
+
See also :c:func:`PyEval_GetFrame`.
|
| 1083 |
+
|
| 1084 |
+
*tstate* must not be ``NULL``.
|
| 1085 |
+
|
| 1086 |
+
.. versionadded:: 3.9
|
| 1087 |
+
|
| 1088 |
+
|
| 1089 |
+
.. c:function:: uint64_t PyThreadState_GetID(PyThreadState *tstate)
|
| 1090 |
+
|
| 1091 |
+
Get the unique thread state identifier of the Python thread state *tstate*.
|
| 1092 |
+
|
| 1093 |
+
*tstate* must not be ``NULL``.
|
| 1094 |
+
|
| 1095 |
+
.. versionadded:: 3.9
|
| 1096 |
+
|
| 1097 |
+
|
| 1098 |
+
.. c:function:: PyInterpreterState* PyThreadState_GetInterpreter(PyThreadState *tstate)
|
| 1099 |
+
|
| 1100 |
+
Get the interpreter of the Python thread state *tstate*.
|
| 1101 |
+
|
| 1102 |
+
*tstate* must not be ``NULL``.
|
| 1103 |
+
|
| 1104 |
+
.. versionadded:: 3.9
|
| 1105 |
+
|
| 1106 |
+
|
| 1107 |
+
.. c:function:: PyInterpreterState* PyInterpreterState_Get(void)
|
| 1108 |
+
|
| 1109 |
+
Get the current interpreter.
|
| 1110 |
+
|
| 1111 |
+
Issue a fatal error if there no current Python thread state or no current
|
| 1112 |
+
interpreter. It cannot return NULL.
|
| 1113 |
+
|
| 1114 |
+
The caller must hold the GIL.
|
| 1115 |
+
|
| 1116 |
+
.. versionadded:: 3.9
|
| 1117 |
+
|
| 1118 |
+
|
| 1119 |
+
.. c:function:: int64_t PyInterpreterState_GetID(PyInterpreterState *interp)
|
| 1120 |
+
|
| 1121 |
+
Return the interpreter's unique ID. If there was any error in doing
|
| 1122 |
+
so then ``-1`` is returned and an error is set.
|
| 1123 |
+
|
| 1124 |
+
The caller must hold the GIL.
|
| 1125 |
+
|
| 1126 |
+
.. versionadded:: 3.7
|
| 1127 |
+
|
| 1128 |
+
|
| 1129 |
+
.. c:function:: PyObject* PyInterpreterState_GetDict(PyInterpreterState *interp)
|
| 1130 |
+
|
| 1131 |
+
Return a dictionary in which interpreter-specific data may be stored.
|
| 1132 |
+
If this function returns ``NULL`` then no exception has been raised and
|
| 1133 |
+
the caller should assume no interpreter-specific dict is available.
|
| 1134 |
+
|
| 1135 |
+
This is not a replacement for :c:func:`PyModule_GetState()`, which
|
| 1136 |
+
extensions should use to store interpreter-specific state information.
|
| 1137 |
+
|
| 1138 |
+
.. versionadded:: 3.8
|
| 1139 |
+
|
| 1140 |
+
.. c:type:: PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, PyFrameObject *frame, int throwflag)
|
| 1141 |
+
|
| 1142 |
+
Type of a frame evaluation function.
|
| 1143 |
+
|
| 1144 |
+
The *throwflag* parameter is used by the ``throw()`` method of generators:
|
| 1145 |
+
if non-zero, handle the current exception.
|
| 1146 |
+
|
| 1147 |
+
.. versionchanged:: 3.9
|
| 1148 |
+
The function now takes a *tstate* parameter.
|
| 1149 |
+
|
| 1150 |
+
.. c:function:: _PyFrameEvalFunction _PyInterpreterState_GetEvalFrameFunc(PyInterpreterState *interp)
|
| 1151 |
+
|
| 1152 |
+
Get the frame evaluation function.
|
| 1153 |
+
|
| 1154 |
+
See the :pep:`523` "Adding a frame evaluation API to CPython".
|
| 1155 |
+
|
| 1156 |
+
.. versionadded:: 3.9
|
| 1157 |
+
|
| 1158 |
+
.. c:function:: void _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp, _PyFrameEvalFunction eval_frame);
|
| 1159 |
+
|
| 1160 |
+
Set the frame evaluation function.
|
| 1161 |
+
|
| 1162 |
+
See the :pep:`523` "Adding a frame evaluation API to CPython".
|
| 1163 |
+
|
| 1164 |
+
.. versionadded:: 3.9
|
| 1165 |
+
|
| 1166 |
+
|
| 1167 |
+
.. c:function:: PyObject* PyThreadState_GetDict()
|
| 1168 |
+
|
| 1169 |
+
Return a dictionary in which extensions can store thread-specific state
|
| 1170 |
+
information. Each extension should use a unique key to use to store state in
|
| 1171 |
+
the dictionary. It is okay to call this function when no current thread state
|
| 1172 |
+
is available. If this function returns ``NULL``, no exception has been raised and
|
| 1173 |
+
the caller should assume no current thread state is available.
|
| 1174 |
+
|
| 1175 |
+
|
| 1176 |
+
.. c:function:: int PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
|
| 1177 |
+
|
| 1178 |
+
Asynchronously raise an exception in a thread. The *id* argument is the thread
|
| 1179 |
+
id of the target thread; *exc* is the exception object to be raised. This
|
| 1180 |
+
function does not steal any references to *exc*. To prevent naive misuse, you
|
| 1181 |
+
must write your own C extension to call this. Must be called with the GIL held.
|
| 1182 |
+
Returns the number of thread states modified; this is normally one, but will be
|
| 1183 |
+
zero if the thread id isn't found. If *exc* is :const:`NULL`, the pending
|
| 1184 |
+
exception (if any) for the thread is cleared. This raises no exceptions.
|
| 1185 |
+
|
| 1186 |
+
.. versionchanged:: 3.7
|
| 1187 |
+
The type of the *id* parameter changed from :c:type:`long` to
|
| 1188 |
+
:c:type:`unsigned long`.
|
| 1189 |
+
|
| 1190 |
+
.. c:function:: void PyEval_AcquireThread(PyThreadState *tstate)
|
| 1191 |
+
|
| 1192 |
+
Acquire the global interpreter lock and set the current thread state to
|
| 1193 |
+
*tstate*, which must not be ``NULL``. The lock must have been created earlier.
|
| 1194 |
+
If this thread already has the lock, deadlock ensues.
|
| 1195 |
+
|
| 1196 |
+
.. note::
|
| 1197 |
+
Calling this function from a thread when the runtime is finalizing
|
| 1198 |
+
will terminate the thread, even if the thread was not created by Python.
|
| 1199 |
+
You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
|
| 1200 |
+
check if the interpreter is in process of being finalized before calling
|
| 1201 |
+
this function to avoid unwanted termination.
|
| 1202 |
+
|
| 1203 |
+
.. versionchanged:: 3.8
|
| 1204 |
+
Updated to be consistent with :c:func:`PyEval_RestoreThread`,
|
| 1205 |
+
:c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`,
|
| 1206 |
+
and terminate the current thread if called while the interpreter is finalizing.
|
| 1207 |
+
|
| 1208 |
+
:c:func:`PyEval_RestoreThread` is a higher-level function which is always
|
| 1209 |
+
available (even when threads have not been initialized).
|
| 1210 |
+
|
| 1211 |
+
|
| 1212 |
+
.. c:function:: void PyEval_ReleaseThread(PyThreadState *tstate)
|
| 1213 |
+
|
| 1214 |
+
Reset the current thread state to ``NULL`` and release the global interpreter
|
| 1215 |
+
lock. The lock must have been created earlier and must be held by the current
|
| 1216 |
+
thread. The *tstate* argument, which must not be ``NULL``, is only used to check
|
| 1217 |
+
that it represents the current thread state --- if it isn't, a fatal error is
|
| 1218 |
+
reported.
|
| 1219 |
+
|
| 1220 |
+
:c:func:`PyEval_SaveThread` is a higher-level function which is always
|
| 1221 |
+
available (even when threads have not been initialized).
|
| 1222 |
+
|
| 1223 |
+
|
| 1224 |
+
.. c:function:: void PyEval_AcquireLock()
|
| 1225 |
+
|
| 1226 |
+
Acquire the global interpreter lock. The lock must have been created earlier.
|
| 1227 |
+
If this thread already has the lock, a deadlock ensues.
|
| 1228 |
+
|
| 1229 |
+
.. deprecated:: 3.2
|
| 1230 |
+
This function does not update the current thread state. Please use
|
| 1231 |
+
:c:func:`PyEval_RestoreThread` or :c:func:`PyEval_AcquireThread`
|
| 1232 |
+
instead.
|
| 1233 |
+
|
| 1234 |
+
.. note::
|
| 1235 |
+
Calling this function from a thread when the runtime is finalizing
|
| 1236 |
+
will terminate the thread, even if the thread was not created by Python.
|
| 1237 |
+
You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
|
| 1238 |
+
check if the interpreter is in process of being finalized before calling
|
| 1239 |
+
this function to avoid unwanted termination.
|
| 1240 |
+
|
| 1241 |
+
.. versionchanged:: 3.8
|
| 1242 |
+
Updated to be consistent with :c:func:`PyEval_RestoreThread`,
|
| 1243 |
+
:c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`,
|
| 1244 |
+
and terminate the current thread if called while the interpreter is finalizing.
|
| 1245 |
+
|
| 1246 |
+
|
| 1247 |
+
.. c:function:: void PyEval_ReleaseLock()
|
| 1248 |
+
|
| 1249 |
+
Release the global interpreter lock. The lock must have been created earlier.
|
| 1250 |
+
|
| 1251 |
+
.. deprecated:: 3.2
|
| 1252 |
+
This function does not update the current thread state. Please use
|
| 1253 |
+
:c:func:`PyEval_SaveThread` or :c:func:`PyEval_ReleaseThread`
|
| 1254 |
+
instead.
|
| 1255 |
+
|
| 1256 |
+
|
| 1257 |
+
.. _sub-interpreter-support:
|
| 1258 |
+
|
| 1259 |
+
Sub-interpreter support
|
| 1260 |
+
=======================
|
| 1261 |
+
|
| 1262 |
+
While in most uses, you will only embed a single Python interpreter, there
|
| 1263 |
+
are cases where you need to create several independent interpreters in the
|
| 1264 |
+
same process and perhaps even in the same thread. Sub-interpreters allow
|
| 1265 |
+
you to do that.
|
| 1266 |
+
|
| 1267 |
+
The "main" interpreter is the first one created when the runtime initializes.
|
| 1268 |
+
It is usually the only Python interpreter in a process. Unlike sub-interpreters,
|
| 1269 |
+
the main interpreter has unique process-global responsibilities like signal
|
| 1270 |
+
handling. It is also responsible for execution during runtime initialization and
|
| 1271 |
+
is usually the active interpreter during runtime finalization. The
|
| 1272 |
+
:c:func:`PyInterpreterState_Main` function returns a pointer to its state.
|
| 1273 |
+
|
| 1274 |
+
You can switch between sub-interpreters using the :c:func:`PyThreadState_Swap`
|
| 1275 |
+
function. You can create and destroy them using the following functions:
|
| 1276 |
+
|
| 1277 |
+
|
| 1278 |
+
.. c:function:: PyThreadState* Py_NewInterpreter()
|
| 1279 |
+
|
| 1280 |
+
.. index::
|
| 1281 |
+
module: builtins
|
| 1282 |
+
module: __main__
|
| 1283 |
+
module: sys
|
| 1284 |
+
single: stdout (in module sys)
|
| 1285 |
+
single: stderr (in module sys)
|
| 1286 |
+
single: stdin (in module sys)
|
| 1287 |
+
|
| 1288 |
+
Create a new sub-interpreter. This is an (almost) totally separate environment
|
| 1289 |
+
for the execution of Python code. In particular, the new interpreter has
|
| 1290 |
+
separate, independent versions of all imported modules, including the
|
| 1291 |
+
fundamental modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`. The
|
| 1292 |
+
table of loaded modules (``sys.modules``) and the module search path
|
| 1293 |
+
(``sys.path``) are also separate. The new environment has no ``sys.argv``
|
| 1294 |
+
variable. It has new standard I/O stream file objects ``sys.stdin``,
|
| 1295 |
+
``sys.stdout`` and ``sys.stderr`` (however these refer to the same underlying
|
| 1296 |
+
file descriptors).
|
| 1297 |
+
|
| 1298 |
+
The return value points to the first thread state created in the new
|
| 1299 |
+
sub-interpreter. This thread state is made in the current thread state.
|
| 1300 |
+
Note that no actual thread is created; see the discussion of thread states
|
| 1301 |
+
below. If creation of the new interpreter is unsuccessful, ``NULL`` is
|
| 1302 |
+
returned; no exception is set since the exception state is stored in the
|
| 1303 |
+
current thread state and there may not be a current thread state. (Like all
|
| 1304 |
+
other Python/C API functions, the global interpreter lock must be held before
|
| 1305 |
+
calling this function and is still held when it returns; however, unlike most
|
| 1306 |
+
other Python/C API functions, there needn't be a current thread state on
|
| 1307 |
+
entry.)
|
| 1308 |
+
|
| 1309 |
+
.. index::
|
| 1310 |
+
single: Py_FinalizeEx()
|
| 1311 |
+
single: Py_Initialize()
|
| 1312 |
+
|
| 1313 |
+
Extension modules are shared between (sub-)interpreters as follows:
|
| 1314 |
+
|
| 1315 |
+
* For modules using multi-phase initialization,
|
| 1316 |
+
e.g. :c:func:`PyModule_FromDefAndSpec`, a separate module object is
|
| 1317 |
+
created and initialized for each interpreter.
|
| 1318 |
+
Only C-level static and global variables are shared between these
|
| 1319 |
+
module objects.
|
| 1320 |
+
|
| 1321 |
+
* For modules using single-phase initialization,
|
| 1322 |
+
e.g. :c:func:`PyModule_Create`, the first time a particular extension
|
| 1323 |
+
is imported, it is initialized normally, and a (shallow) copy of its
|
| 1324 |
+
module's dictionary is squirreled away.
|
| 1325 |
+
When the same extension is imported by another (sub-)interpreter, a new
|
| 1326 |
+
module is initialized and filled with the contents of this copy; the
|
| 1327 |
+
extension's ``init`` function is not called.
|
| 1328 |
+
Objects in the module's dictionary thus end up shared across
|
| 1329 |
+
(sub-)interpreters, which might cause unwanted behavior (see
|
| 1330 |
+
`Bugs and caveats`_ below).
|
| 1331 |
+
|
| 1332 |
+
Note that this is different from what happens when an extension is
|
| 1333 |
+
imported after the interpreter has been completely re-initialized by
|
| 1334 |
+
calling :c:func:`Py_FinalizeEx` and :c:func:`Py_Initialize`; in that
|
| 1335 |
+
case, the extension's ``initmodule`` function *is* called again.
|
| 1336 |
+
As with multi-phase initialization, this means that only C-level static
|
| 1337 |
+
and global variables are shared between these modules.
|
| 1338 |
+
|
| 1339 |
+
.. index:: single: close() (in module os)
|
| 1340 |
+
|
| 1341 |
+
|
| 1342 |
+
.. c:function:: void Py_EndInterpreter(PyThreadState *tstate)
|
| 1343 |
+
|
| 1344 |
+
.. index:: single: Py_FinalizeEx()
|
| 1345 |
+
|
| 1346 |
+
Destroy the (sub-)interpreter represented by the given thread state. The given
|
| 1347 |
+
thread state must be the current thread state. See the discussion of thread
|
| 1348 |
+
states below. When the call returns, the current thread state is ``NULL``. All
|
| 1349 |
+
thread states associated with this interpreter are destroyed. (The global
|
| 1350 |
+
interpreter lock must be held before calling this function and is still held
|
| 1351 |
+
when it returns.) :c:func:`Py_FinalizeEx` will destroy all sub-interpreters that
|
| 1352 |
+
haven't been explicitly destroyed at that point.
|
| 1353 |
+
|
| 1354 |
+
|
| 1355 |
+
Bugs and caveats
|
| 1356 |
+
----------------
|
| 1357 |
+
|
| 1358 |
+
Because sub-interpreters (and the main interpreter) are part of the same
|
| 1359 |
+
process, the insulation between them isn't perfect --- for example, using
|
| 1360 |
+
low-level file operations like :func:`os.close` they can
|
| 1361 |
+
(accidentally or maliciously) affect each other's open files. Because of the
|
| 1362 |
+
way extensions are shared between (sub-)interpreters, some extensions may not
|
| 1363 |
+
work properly; this is especially likely when using single-phase initialization
|
| 1364 |
+
or (static) global variables.
|
| 1365 |
+
It is possible to insert objects created in one sub-interpreter into
|
| 1366 |
+
a namespace of another (sub-)interpreter; this should be avoided if possible.
|
| 1367 |
+
|
| 1368 |
+
Special care should be taken to avoid sharing user-defined functions,
|
| 1369 |
+
methods, instances or classes between sub-interpreters, since import
|
| 1370 |
+
operations executed by such objects may affect the wrong (sub-)interpreter's
|
| 1371 |
+
dictionary of loaded modules. It is equally important to avoid sharing
|
| 1372 |
+
objects from which the above are reachable.
|
| 1373 |
+
|
| 1374 |
+
Also note that combining this functionality with :c:func:`PyGILState_\*` APIs
|
| 1375 |
+
is delicate, because these APIs assume a bijection between Python thread states
|
| 1376 |
+
and OS-level threads, an assumption broken by the presence of sub-interpreters.
|
| 1377 |
+
It is highly recommended that you don't switch sub-interpreters between a pair
|
| 1378 |
+
of matching :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release` calls.
|
| 1379 |
+
Furthermore, extensions (such as :mod:`ctypes`) using these APIs to allow calling
|
| 1380 |
+
of Python code from non-Python created threads will probably be broken when using
|
| 1381 |
+
sub-interpreters.
|
| 1382 |
+
|
| 1383 |
+
|
| 1384 |
+
Asynchronous Notifications
|
| 1385 |
+
==========================
|
| 1386 |
+
|
| 1387 |
+
A mechanism is provided to make asynchronous notifications to the main
|
| 1388 |
+
interpreter thread. These notifications take the form of a function
|
| 1389 |
+
pointer and a void pointer argument.
|
| 1390 |
+
|
| 1391 |
+
|
| 1392 |
+
.. c:function:: int Py_AddPendingCall(int (*func)(void *), void *arg)
|
| 1393 |
+
|
| 1394 |
+
.. index:: single: Py_AddPendingCall()
|
| 1395 |
+
|
| 1396 |
+
Schedule a function to be called from the main interpreter thread. On
|
| 1397 |
+
success, ``0`` is returned and *func* is queued for being called in the
|
| 1398 |
+
main thread. On failure, ``-1`` is returned without setting any exception.
|
| 1399 |
+
|
| 1400 |
+
When successfully queued, *func* will be *eventually* called from the
|
| 1401 |
+
main interpreter thread with the argument *arg*. It will be called
|
| 1402 |
+
asynchronously with respect to normally running Python code, but with
|
| 1403 |
+
both these conditions met:
|
| 1404 |
+
|
| 1405 |
+
* on a :term:`bytecode` boundary;
|
| 1406 |
+
* with the main thread holding the :term:`global interpreter lock`
|
| 1407 |
+
(*func* can therefore use the full C API).
|
| 1408 |
+
|
| 1409 |
+
*func* must return ``0`` on success, or ``-1`` on failure with an exception
|
| 1410 |
+
set. *func* won't be interrupted to perform another asynchronous
|
| 1411 |
+
notification recursively, but it can still be interrupted to switch
|
| 1412 |
+
threads if the global interpreter lock is released.
|
| 1413 |
+
|
| 1414 |
+
This function doesn't need a current thread state to run, and it doesn't
|
| 1415 |
+
need the global interpreter lock.
|
| 1416 |
+
|
| 1417 |
+
To call this function in a subinterpreter, the caller must hold the GIL.
|
| 1418 |
+
Otherwise, the function *func* can be scheduled to be called from the wrong
|
| 1419 |
+
interpreter.
|
| 1420 |
+
|
| 1421 |
+
.. warning::
|
| 1422 |
+
This is a low-level function, only useful for very special cases.
|
| 1423 |
+
There is no guarantee that *func* will be called as quick as
|
| 1424 |
+
possible. If the main thread is busy executing a system call,
|
| 1425 |
+
*func* won't be called before the system call returns. This
|
| 1426 |
+
function is generally **not** suitable for calling Python code from
|
| 1427 |
+
arbitrary C threads. Instead, use the :ref:`PyGILState API<gilstate>`.
|
| 1428 |
+
|
| 1429 |
+
.. versionchanged:: 3.9
|
| 1430 |
+
If this function is called in a subinterpreter, the function *func* is
|
| 1431 |
+
now scheduled to be called from the subinterpreter, rather than being
|
| 1432 |
+
called from the main interpreter. Each subinterpreter now has its own
|
| 1433 |
+
list of scheduled calls.
|
| 1434 |
+
|
| 1435 |
+
.. versionadded:: 3.1
|
| 1436 |
+
|
| 1437 |
+
.. _profiling:
|
| 1438 |
+
|
| 1439 |
+
Profiling and Tracing
|
| 1440 |
+
=====================
|
| 1441 |
+
|
| 1442 |
+
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
|
| 1443 |
+
|
| 1444 |
+
|
| 1445 |
+
The Python interpreter provides some low-level support for attaching profiling
|
| 1446 |
+
and execution tracing facilities. These are used for profiling, debugging, and
|
| 1447 |
+
coverage analysis tools.
|
| 1448 |
+
|
| 1449 |
+
This C interface allows the profiling or tracing code to avoid the overhead of
|
| 1450 |
+
calling through Python-level callable objects, making a direct C function call
|
| 1451 |
+
instead. The essential attributes of the facility have not changed; the
|
| 1452 |
+
interface allows trace functions to be installed per-thread, and the basic
|
| 1453 |
+
events reported to the trace function are the same as had been reported to the
|
| 1454 |
+
Python-level trace functions in previous versions.
|
| 1455 |
+
|
| 1456 |
+
|
| 1457 |
+
.. c:type:: int (*Py_tracefunc)(PyObject *obj, PyFrameObject *frame, int what, PyObject *arg)
|
| 1458 |
+
|
| 1459 |
+
The type of the trace function registered using :c:func:`PyEval_SetProfile` and
|
| 1460 |
+
:c:func:`PyEval_SetTrace`. The first parameter is the object passed to the
|
| 1461 |
+
registration function as *obj*, *frame* is the frame object to which the event
|
| 1462 |
+
pertains, *what* is one of the constants :const:`PyTrace_CALL`,
|
| 1463 |
+
:const:`PyTrace_EXCEPTION`, :const:`PyTrace_LINE`, :const:`PyTrace_RETURN`,
|
| 1464 |
+
:const:`PyTrace_C_CALL`, :const:`PyTrace_C_EXCEPTION`, :const:`PyTrace_C_RETURN`,
|
| 1465 |
+
or :const:`PyTrace_OPCODE`, and *arg* depends on the value of *what*:
|
| 1466 |
+
|
| 1467 |
+
+------------------------------+----------------------------------------+
|
| 1468 |
+
| Value of *what* | Meaning of *arg* |
|
| 1469 |
+
+==============================+========================================+
|
| 1470 |
+
| :const:`PyTrace_CALL` | Always :c:data:`Py_None`. |
|
| 1471 |
+
+------------------------------+----------------------------------------+
|
| 1472 |
+
| :const:`PyTrace_EXCEPTION` | Exception information as returned by |
|
| 1473 |
+
| | :func:`sys.exc_info`. |
|
| 1474 |
+
+------------------------------+----------------------------------------+
|
| 1475 |
+
| :const:`PyTrace_LINE` | Always :c:data:`Py_None`. |
|
| 1476 |
+
+------------------------------+----------------------------------------+
|
| 1477 |
+
| :const:`PyTrace_RETURN` | Value being returned to the caller, |
|
| 1478 |
+
| | or ``NULL`` if caused by an exception. |
|
| 1479 |
+
+------------------------------+----------------------------------------+
|
| 1480 |
+
| :const:`PyTrace_C_CALL` | Function object being called. |
|
| 1481 |
+
+------------------------------+----------------------------------------+
|
| 1482 |
+
| :const:`PyTrace_C_EXCEPTION` | Function object being called. |
|
| 1483 |
+
+------------------------------+----------------------------------------+
|
| 1484 |
+
| :const:`PyTrace_C_RETURN` | Function object being called. |
|
| 1485 |
+
+------------------------------+----------------------------------------+
|
| 1486 |
+
| :const:`PyTrace_OPCODE` | Always :c:data:`Py_None`. |
|
| 1487 |
+
+------------------------------+----------------------------------------+
|
| 1488 |
+
|
| 1489 |
+
.. c:var:: int PyTrace_CALL
|
| 1490 |
+
|
| 1491 |
+
The value of the *what* parameter to a :c:type:`Py_tracefunc` function when a new
|
| 1492 |
+
call to a function or method is being reported, or a new entry into a generator.
|
| 1493 |
+
Note that the creation of the iterator for a generator function is not reported
|
| 1494 |
+
as there is no control transfer to the Python bytecode in the corresponding
|
| 1495 |
+
frame.
|
| 1496 |
+
|
| 1497 |
+
|
| 1498 |
+
.. c:var:: int PyTrace_EXCEPTION
|
| 1499 |
+
|
| 1500 |
+
The value of the *what* parameter to a :c:type:`Py_tracefunc` function when an
|
| 1501 |
+
exception has been raised. The callback function is called with this value for
|
| 1502 |
+
*what* when after any bytecode is processed after which the exception becomes
|
| 1503 |
+
set within the frame being executed. The effect of this is that as exception
|
| 1504 |
+
propagation causes the Python stack to unwind, the callback is called upon
|
| 1505 |
+
return to each frame as the exception propagates. Only trace functions receives
|
| 1506 |
+
these events; they are not needed by the profiler.
|
| 1507 |
+
|
| 1508 |
+
|
| 1509 |
+
.. c:var:: int PyTrace_LINE
|
| 1510 |
+
|
| 1511 |
+
The value passed as the *what* parameter to a :c:type:`Py_tracefunc` function
|
| 1512 |
+
(but not a profiling function) when a line-number event is being reported.
|
| 1513 |
+
It may be disabled for a frame by setting :attr:`f_trace_lines` to *0* on that frame.
|
| 1514 |
+
|
| 1515 |
+
|
| 1516 |
+
.. c:var:: int PyTrace_RETURN
|
| 1517 |
+
|
| 1518 |
+
The value for the *what* parameter to :c:type:`Py_tracefunc` functions when a
|
| 1519 |
+
call is about to return.
|
| 1520 |
+
|
| 1521 |
+
|
| 1522 |
+
.. c:var:: int PyTrace_C_CALL
|
| 1523 |
+
|
| 1524 |
+
The value for the *what* parameter to :c:type:`Py_tracefunc` functions when a C
|
| 1525 |
+
function is about to be called.
|
| 1526 |
+
|
| 1527 |
+
|
| 1528 |
+
.. c:var:: int PyTrace_C_EXCEPTION
|
| 1529 |
+
|
| 1530 |
+
The value for the *what* parameter to :c:type:`Py_tracefunc` functions when a C
|
| 1531 |
+
function has raised an exception.
|
| 1532 |
+
|
| 1533 |
+
|
| 1534 |
+
.. c:var:: int PyTrace_C_RETURN
|
| 1535 |
+
|
| 1536 |
+
The value for the *what* parameter to :c:type:`Py_tracefunc` functions when a C
|
| 1537 |
+
function has returned.
|
| 1538 |
+
|
| 1539 |
+
|
| 1540 |
+
.. c:var:: int PyTrace_OPCODE
|
| 1541 |
+
|
| 1542 |
+
The value for the *what* parameter to :c:type:`Py_tracefunc` functions (but not
|
| 1543 |
+
profiling functions) when a new opcode is about to be executed. This event is
|
| 1544 |
+
not emitted by default: it must be explicitly requested by setting
|
| 1545 |
+
:attr:`f_trace_opcodes` to *1* on the frame.
|
| 1546 |
+
|
| 1547 |
+
|
| 1548 |
+
.. c:function:: void PyEval_SetProfile(Py_tracefunc func, PyObject *obj)
|
| 1549 |
+
|
| 1550 |
+
Set the profiler function to *func*. The *obj* parameter is passed to the
|
| 1551 |
+
function as its first parameter, and may be any Python object, or ``NULL``. If
|
| 1552 |
+
the profile function needs to maintain state, using a different value for *obj*
|
| 1553 |
+
for each thread provides a convenient and thread-safe place to store it. The
|
| 1554 |
+
profile function is called for all monitored events except :const:`PyTrace_LINE`
|
| 1555 |
+
:const:`PyTrace_OPCODE` and :const:`PyTrace_EXCEPTION`.
|
| 1556 |
+
|
| 1557 |
+
The caller must hold the :term:`GIL`.
|
| 1558 |
+
|
| 1559 |
+
|
| 1560 |
+
.. c:function:: void PyEval_SetTrace(Py_tracefunc func, PyObject *obj)
|
| 1561 |
+
|
| 1562 |
+
Set the tracing function to *func*. This is similar to
|
| 1563 |
+
:c:func:`PyEval_SetProfile`, except the tracing function does receive line-number
|
| 1564 |
+
events and per-opcode events, but does not receive any event related to C function
|
| 1565 |
+
objects being called. Any trace function registered using :c:func:`PyEval_SetTrace`
|
| 1566 |
+
will not receive :const:`PyTrace_C_CALL`, :const:`PyTrace_C_EXCEPTION` or
|
| 1567 |
+
:const:`PyTrace_C_RETURN` as a value for the *what* parameter.
|
| 1568 |
+
|
| 1569 |
+
The caller must hold the :term:`GIL`.
|
| 1570 |
+
|
| 1571 |
+
|
| 1572 |
+
.. _advanced-debugging:
|
| 1573 |
+
|
| 1574 |
+
Advanced Debugger Support
|
| 1575 |
+
=========================
|
| 1576 |
+
|
| 1577 |
+
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
|
| 1578 |
+
|
| 1579 |
+
|
| 1580 |
+
These functions are only intended to be used by advanced debugging tools.
|
| 1581 |
+
|
| 1582 |
+
|
| 1583 |
+
.. c:function:: PyInterpreterState* PyInterpreterState_Head()
|
| 1584 |
+
|
| 1585 |
+
Return the interpreter state object at the head of the list of all such objects.
|
| 1586 |
+
|
| 1587 |
+
|
| 1588 |
+
.. c:function:: PyInterpreterState* PyInterpreterState_Main()
|
| 1589 |
+
|
| 1590 |
+
Return the main interpreter state object.
|
| 1591 |
+
|
| 1592 |
+
|
| 1593 |
+
.. c:function:: PyInterpreterState* PyInterpreterState_Next(PyInterpreterState *interp)
|
| 1594 |
+
|
| 1595 |
+
Return the next interpreter state object after *interp* from the list of all
|
| 1596 |
+
such objects.
|
| 1597 |
+
|
| 1598 |
+
|
| 1599 |
+
.. c:function:: PyThreadState * PyInterpreterState_ThreadHead(PyInterpreterState *interp)
|
| 1600 |
+
|
| 1601 |
+
Return the pointer to the first :c:type:`PyThreadState` object in the list of
|
| 1602 |
+
threads associated with the interpreter *interp*.
|
| 1603 |
+
|
| 1604 |
+
|
| 1605 |
+
.. c:function:: PyThreadState* PyThreadState_Next(PyThreadState *tstate)
|
| 1606 |
+
|
| 1607 |
+
Return the next thread state object after *tstate* from the list of all such
|
| 1608 |
+
objects belonging to the same :c:type:`PyInterpreterState` object.
|
| 1609 |
+
|
| 1610 |
+
|
| 1611 |
+
.. _thread-local-storage:
|
| 1612 |
+
|
| 1613 |
+
Thread Local Storage Support
|
| 1614 |
+
============================
|
| 1615 |
+
|
| 1616 |
+
.. sectionauthor:: Masayuki Yamamoto <ma3yuki.8mamo10@gmail.com>
|
| 1617 |
+
|
| 1618 |
+
The Python interpreter provides low-level support for thread-local storage
|
| 1619 |
+
(TLS) which wraps the underlying native TLS implementation to support the
|
| 1620 |
+
Python-level thread local storage API (:class:`threading.local`). The
|
| 1621 |
+
CPython C level APIs are similar to those offered by pthreads and Windows:
|
| 1622 |
+
use a thread key and functions to associate a :c:type:`void\*` value per
|
| 1623 |
+
thread.
|
| 1624 |
+
|
| 1625 |
+
The GIL does *not* need to be held when calling these functions; they supply
|
| 1626 |
+
their own locking.
|
| 1627 |
+
|
| 1628 |
+
Note that :file:`Python.h` does not include the declaration of the TLS APIs,
|
| 1629 |
+
you need to include :file:`pythread.h` to use thread-local storage.
|
| 1630 |
+
|
| 1631 |
+
.. note::
|
| 1632 |
+
None of these API functions handle memory management on behalf of the
|
| 1633 |
+
:c:type:`void\*` values. You need to allocate and deallocate them yourself.
|
| 1634 |
+
If the :c:type:`void\*` values happen to be :c:type:`PyObject\*`, these
|
| 1635 |
+
functions don't do refcount operations on them either.
|
| 1636 |
+
|
| 1637 |
+
.. _thread-specific-storage-api:
|
| 1638 |
+
|
| 1639 |
+
Thread Specific Storage (TSS) API
|
| 1640 |
+
---------------------------------
|
| 1641 |
+
|
| 1642 |
+
TSS API is introduced to supersede the use of the existing TLS API within the
|
| 1643 |
+
CPython interpreter. This API uses a new type :c:type:`Py_tss_t` instead of
|
| 1644 |
+
:c:type:`int` to represent thread keys.
|
| 1645 |
+
|
| 1646 |
+
.. versionadded:: 3.7
|
| 1647 |
+
|
| 1648 |
+
.. seealso:: "A New C-API for Thread-Local Storage in CPython" (:pep:`539`)
|
| 1649 |
+
|
| 1650 |
+
|
| 1651 |
+
.. c:type:: Py_tss_t
|
| 1652 |
+
|
| 1653 |
+
This data structure represents the state of a thread key, the definition of
|
| 1654 |
+
which may depend on the underlying TLS implementation, and it has an
|
| 1655 |
+
internal field representing the key's initialization state. There are no
|
| 1656 |
+
public members in this structure.
|
| 1657 |
+
|
| 1658 |
+
When :ref:`Py_LIMITED_API <stable>` is not defined, static allocation of
|
| 1659 |
+
this type by :c:macro:`Py_tss_NEEDS_INIT` is allowed.
|
| 1660 |
+
|
| 1661 |
+
|
| 1662 |
+
.. c:macro:: Py_tss_NEEDS_INIT
|
| 1663 |
+
|
| 1664 |
+
This macro expands to the initializer for :c:type:`Py_tss_t` variables.
|
| 1665 |
+
Note that this macro won't be defined with :ref:`Py_LIMITED_API <stable>`.
|
| 1666 |
+
|
| 1667 |
+
|
| 1668 |
+
Dynamic Allocation
|
| 1669 |
+
~~~~~~~~~~~~~~~~~~
|
| 1670 |
+
|
| 1671 |
+
Dynamic allocation of the :c:type:`Py_tss_t`, required in extension modules
|
| 1672 |
+
built with :ref:`Py_LIMITED_API <stable>`, where static allocation of this type
|
| 1673 |
+
is not possible due to its implementation being opaque at build time.
|
| 1674 |
+
|
| 1675 |
+
|
| 1676 |
+
.. c:function:: Py_tss_t* PyThread_tss_alloc()
|
| 1677 |
+
|
| 1678 |
+
Return a value which is the same state as a value initialized with
|
| 1679 |
+
:c:macro:`Py_tss_NEEDS_INIT`, or ``NULL`` in the case of dynamic allocation
|
| 1680 |
+
failure.
|
| 1681 |
+
|
| 1682 |
+
|
| 1683 |
+
.. c:function:: void PyThread_tss_free(Py_tss_t *key)
|
| 1684 |
+
|
| 1685 |
+
Free the given *key* allocated by :c:func:`PyThread_tss_alloc`, after
|
| 1686 |
+
first calling :c:func:`PyThread_tss_delete` to ensure any associated
|
| 1687 |
+
thread locals have been unassigned. This is a no-op if the *key*
|
| 1688 |
+
argument is `NULL`.
|
| 1689 |
+
|
| 1690 |
+
.. note::
|
| 1691 |
+
A freed key becomes a dangling pointer, you should reset the key to
|
| 1692 |
+
`NULL`.
|
| 1693 |
+
|
| 1694 |
+
|
| 1695 |
+
Methods
|
| 1696 |
+
~~~~~~~
|
| 1697 |
+
|
| 1698 |
+
The parameter *key* of these functions must not be ``NULL``. Moreover, the
|
| 1699 |
+
behaviors of :c:func:`PyThread_tss_set` and :c:func:`PyThread_tss_get` are
|
| 1700 |
+
undefined if the given :c:type:`Py_tss_t` has not been initialized by
|
| 1701 |
+
:c:func:`PyThread_tss_create`.
|
| 1702 |
+
|
| 1703 |
+
|
| 1704 |
+
.. c:function:: int PyThread_tss_is_created(Py_tss_t *key)
|
| 1705 |
+
|
| 1706 |
+
Return a non-zero value if the given :c:type:`Py_tss_t` has been initialized
|
| 1707 |
+
by :c:func:`PyThread_tss_create`.
|
| 1708 |
+
|
| 1709 |
+
|
| 1710 |
+
.. c:function:: int PyThread_tss_create(Py_tss_t *key)
|
| 1711 |
+
|
| 1712 |
+
Return a zero value on successful initialization of a TSS key. The behavior
|
| 1713 |
+
is undefined if the value pointed to by the *key* argument is not
|
| 1714 |
+
initialized by :c:macro:`Py_tss_NEEDS_INIT`. This function can be called
|
| 1715 |
+
repeatedly on the same key -- calling it on an already initialized key is a
|
| 1716 |
+
no-op and immediately returns success.
|
| 1717 |
+
|
| 1718 |
+
|
| 1719 |
+
.. c:function:: void PyThread_tss_delete(Py_tss_t *key)
|
| 1720 |
+
|
| 1721 |
+
Destroy a TSS key to forget the values associated with the key across all
|
| 1722 |
+
threads, and change the key's initialization state to uninitialized. A
|
| 1723 |
+
destroyed key is able to be initialized again by
|
| 1724 |
+
:c:func:`PyThread_tss_create`. This function can be called repeatedly on
|
| 1725 |
+
the same key -- calling it on an already destroyed key is a no-op.
|
| 1726 |
+
|
| 1727 |
+
|
| 1728 |
+
.. c:function:: int PyThread_tss_set(Py_tss_t *key, void *value)
|
| 1729 |
+
|
| 1730 |
+
Return a zero value to indicate successfully associating a :c:type:`void\*`
|
| 1731 |
+
value with a TSS key in the current thread. Each thread has a distinct
|
| 1732 |
+
mapping of the key to a :c:type:`void\*` value.
|
| 1733 |
+
|
| 1734 |
+
|
| 1735 |
+
.. c:function:: void* PyThread_tss_get(Py_tss_t *key)
|
| 1736 |
+
|
| 1737 |
+
Return the :c:type:`void\*` value associated with a TSS key in the current
|
| 1738 |
+
thread. This returns ``NULL`` if no value is associated with the key in the
|
| 1739 |
+
current thread.
|
| 1740 |
+
|
| 1741 |
+
|
| 1742 |
+
.. _thread-local-storage-api:
|
| 1743 |
+
|
| 1744 |
+
Thread Local Storage (TLS) API
|
| 1745 |
+
------------------------------
|
| 1746 |
+
|
| 1747 |
+
.. deprecated:: 3.7
|
| 1748 |
+
This API is superseded by
|
| 1749 |
+
:ref:`Thread Specific Storage (TSS) API <thread-specific-storage-api>`.
|
| 1750 |
+
|
| 1751 |
+
.. note::
|
| 1752 |
+
This version of the API does not support platforms where the native TLS key
|
| 1753 |
+
is defined in a way that cannot be safely cast to ``int``. On such platforms,
|
| 1754 |
+
:c:func:`PyThread_create_key` will return immediately with a failure status,
|
| 1755 |
+
and the other TLS functions will all be no-ops on such platforms.
|
| 1756 |
+
|
| 1757 |
+
Due to the compatibility problem noted above, this version of the API should not
|
| 1758 |
+
be used in new code.
|
| 1759 |
+
|
| 1760 |
+
.. c:function:: int PyThread_create_key()
|
| 1761 |
+
.. c:function:: void PyThread_delete_key(int key)
|
| 1762 |
+
.. c:function:: int PyThread_set_key_value(int key, void *value)
|
| 1763 |
+
.. c:function:: void* PyThread_get_key_value(int key)
|
| 1764 |
+
.. c:function:: void PyThread_delete_key_value(int key)
|
| 1765 |
+
.. c:function:: void PyThread_ReInitTLS()
|
| 1766 |
+
|
cpython_2/environment/repo/Doc/c-api/init_config.rst
ADDED
|
@@ -0,0 +1,1064 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _init-config:
|
| 4 |
+
|
| 5 |
+
***********************************
|
| 6 |
+
Python Initialization Configuration
|
| 7 |
+
***********************************
|
| 8 |
+
|
| 9 |
+
.. versionadded:: 3.8
|
| 10 |
+
|
| 11 |
+
Structures:
|
| 12 |
+
|
| 13 |
+
* :c:type:`PyConfig`
|
| 14 |
+
* :c:type:`PyPreConfig`
|
| 15 |
+
* :c:type:`PyStatus`
|
| 16 |
+
* :c:type:`PyWideStringList`
|
| 17 |
+
|
| 18 |
+
Functions:
|
| 19 |
+
|
| 20 |
+
* :c:func:`PyConfig_Clear`
|
| 21 |
+
* :c:func:`PyConfig_InitIsolatedConfig`
|
| 22 |
+
* :c:func:`PyConfig_InitPythonConfig`
|
| 23 |
+
* :c:func:`PyConfig_Read`
|
| 24 |
+
* :c:func:`PyConfig_SetArgv`
|
| 25 |
+
* :c:func:`PyConfig_SetBytesArgv`
|
| 26 |
+
* :c:func:`PyConfig_SetBytesString`
|
| 27 |
+
* :c:func:`PyConfig_SetString`
|
| 28 |
+
* :c:func:`PyConfig_SetWideStringList`
|
| 29 |
+
* :c:func:`PyPreConfig_InitIsolatedConfig`
|
| 30 |
+
* :c:func:`PyPreConfig_InitPythonConfig`
|
| 31 |
+
* :c:func:`PyStatus_Error`
|
| 32 |
+
* :c:func:`PyStatus_Exception`
|
| 33 |
+
* :c:func:`PyStatus_Exit`
|
| 34 |
+
* :c:func:`PyStatus_IsError`
|
| 35 |
+
* :c:func:`PyStatus_IsExit`
|
| 36 |
+
* :c:func:`PyStatus_NoMemory`
|
| 37 |
+
* :c:func:`PyStatus_Ok`
|
| 38 |
+
* :c:func:`PyWideStringList_Append`
|
| 39 |
+
* :c:func:`PyWideStringList_Insert`
|
| 40 |
+
* :c:func:`Py_ExitStatusException`
|
| 41 |
+
* :c:func:`Py_InitializeFromConfig`
|
| 42 |
+
* :c:func:`Py_PreInitialize`
|
| 43 |
+
* :c:func:`Py_PreInitializeFromArgs`
|
| 44 |
+
* :c:func:`Py_PreInitializeFromBytesArgs`
|
| 45 |
+
* :c:func:`Py_RunMain`
|
| 46 |
+
|
| 47 |
+
The preconfiguration (``PyPreConfig`` type) is stored in
|
| 48 |
+
``_PyRuntime.preconfig`` and the configuration (``PyConfig`` type) is stored in
|
| 49 |
+
``PyInterpreterState.config``.
|
| 50 |
+
|
| 51 |
+
See also :ref:`Initialization, Finalization, and Threads <initialization>`.
|
| 52 |
+
|
| 53 |
+
.. seealso::
|
| 54 |
+
:pep:`587` "Python Initialization Configuration".
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
PyWideStringList
|
| 58 |
+
----------------
|
| 59 |
+
|
| 60 |
+
.. c:type:: PyWideStringList
|
| 61 |
+
|
| 62 |
+
List of ``wchar_t*`` strings.
|
| 63 |
+
|
| 64 |
+
If *length* is non-zero, *items* must be non-``NULL`` and all strings must be
|
| 65 |
+
non-``NULL``.
|
| 66 |
+
|
| 67 |
+
Methods:
|
| 68 |
+
|
| 69 |
+
.. c:function:: PyStatus PyWideStringList_Append(PyWideStringList *list, const wchar_t *item)
|
| 70 |
+
|
| 71 |
+
Append *item* to *list*.
|
| 72 |
+
|
| 73 |
+
Python must be preinitialized to call this function.
|
| 74 |
+
|
| 75 |
+
.. c:function:: PyStatus PyWideStringList_Insert(PyWideStringList *list, Py_ssize_t index, const wchar_t *item)
|
| 76 |
+
|
| 77 |
+
Insert *item* into *list* at *index*.
|
| 78 |
+
|
| 79 |
+
If *index* is greater than or equal to *list* length, append *item* to
|
| 80 |
+
*list*.
|
| 81 |
+
|
| 82 |
+
*index* must be greater than or equal to 0.
|
| 83 |
+
|
| 84 |
+
Python must be preinitialized to call this function.
|
| 85 |
+
|
| 86 |
+
Structure fields:
|
| 87 |
+
|
| 88 |
+
.. c:member:: Py_ssize_t length
|
| 89 |
+
|
| 90 |
+
List length.
|
| 91 |
+
|
| 92 |
+
.. c:member:: wchar_t** items
|
| 93 |
+
|
| 94 |
+
List items.
|
| 95 |
+
|
| 96 |
+
PyStatus
|
| 97 |
+
--------
|
| 98 |
+
|
| 99 |
+
.. c:type:: PyStatus
|
| 100 |
+
|
| 101 |
+
Structure to store an initialization function status: success, error
|
| 102 |
+
or exit.
|
| 103 |
+
|
| 104 |
+
For an error, it can store the C function name which created the error.
|
| 105 |
+
|
| 106 |
+
Structure fields:
|
| 107 |
+
|
| 108 |
+
.. c:member:: int exitcode
|
| 109 |
+
|
| 110 |
+
Exit code. Argument passed to ``exit()``.
|
| 111 |
+
|
| 112 |
+
.. c:member:: const char *err_msg
|
| 113 |
+
|
| 114 |
+
Error message.
|
| 115 |
+
|
| 116 |
+
.. c:member:: const char *func
|
| 117 |
+
|
| 118 |
+
Name of the function which created an error, can be ``NULL``.
|
| 119 |
+
|
| 120 |
+
Functions to create a status:
|
| 121 |
+
|
| 122 |
+
.. c:function:: PyStatus PyStatus_Ok(void)
|
| 123 |
+
|
| 124 |
+
Success.
|
| 125 |
+
|
| 126 |
+
.. c:function:: PyStatus PyStatus_Error(const char *err_msg)
|
| 127 |
+
|
| 128 |
+
Initialization error with a message.
|
| 129 |
+
|
| 130 |
+
.. c:function:: PyStatus PyStatus_NoMemory(void)
|
| 131 |
+
|
| 132 |
+
Memory allocation failure (out of memory).
|
| 133 |
+
|
| 134 |
+
.. c:function:: PyStatus PyStatus_Exit(int exitcode)
|
| 135 |
+
|
| 136 |
+
Exit Python with the specified exit code.
|
| 137 |
+
|
| 138 |
+
Functions to handle a status:
|
| 139 |
+
|
| 140 |
+
.. c:function:: int PyStatus_Exception(PyStatus status)
|
| 141 |
+
|
| 142 |
+
Is the status an error or an exit? If true, the exception must be
|
| 143 |
+
handled; by calling :c:func:`Py_ExitStatusException` for example.
|
| 144 |
+
|
| 145 |
+
.. c:function:: int PyStatus_IsError(PyStatus status)
|
| 146 |
+
|
| 147 |
+
Is the result an error?
|
| 148 |
+
|
| 149 |
+
.. c:function:: int PyStatus_IsExit(PyStatus status)
|
| 150 |
+
|
| 151 |
+
Is the result an exit?
|
| 152 |
+
|
| 153 |
+
.. c:function:: void Py_ExitStatusException(PyStatus status)
|
| 154 |
+
|
| 155 |
+
Call ``exit(exitcode)`` if *status* is an exit. Print the error
|
| 156 |
+
message and exit with a non-zero exit code if *status* is an error. Must
|
| 157 |
+
only be called if ``PyStatus_Exception(status)`` is non-zero.
|
| 158 |
+
|
| 159 |
+
.. note::
|
| 160 |
+
Internally, Python uses macros which set ``PyStatus.func``,
|
| 161 |
+
whereas functions to create a status set ``func`` to ``NULL``.
|
| 162 |
+
|
| 163 |
+
Example::
|
| 164 |
+
|
| 165 |
+
PyStatus alloc(void **ptr, size_t size)
|
| 166 |
+
{
|
| 167 |
+
*ptr = PyMem_RawMalloc(size);
|
| 168 |
+
if (*ptr == NULL) {
|
| 169 |
+
return PyStatus_NoMemory();
|
| 170 |
+
}
|
| 171 |
+
return PyStatus_Ok();
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
int main(int argc, char **argv)
|
| 175 |
+
{
|
| 176 |
+
void *ptr;
|
| 177 |
+
PyStatus status = alloc(&ptr, 16);
|
| 178 |
+
if (PyStatus_Exception(status)) {
|
| 179 |
+
Py_ExitStatusException(status);
|
| 180 |
+
}
|
| 181 |
+
PyMem_Free(ptr);
|
| 182 |
+
return 0;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
PyPreConfig
|
| 187 |
+
-----------
|
| 188 |
+
|
| 189 |
+
.. c:type:: PyPreConfig
|
| 190 |
+
|
| 191 |
+
Structure used to preinitialize Python:
|
| 192 |
+
|
| 193 |
+
* Set the Python memory allocator
|
| 194 |
+
* Configure the LC_CTYPE locale
|
| 195 |
+
* Set the UTF-8 mode
|
| 196 |
+
|
| 197 |
+
Function to initialize a preconfiguration:
|
| 198 |
+
|
| 199 |
+
.. c:function:: void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig)
|
| 200 |
+
|
| 201 |
+
Initialize the preconfiguration with :ref:`Python Configuration
|
| 202 |
+
<init-python-config>`.
|
| 203 |
+
|
| 204 |
+
.. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
|
| 205 |
+
|
| 206 |
+
Initialize the preconfiguration with :ref:`Isolated Configuration
|
| 207 |
+
<init-isolated-conf>`.
|
| 208 |
+
|
| 209 |
+
Structure fields:
|
| 210 |
+
|
| 211 |
+
.. c:member:: int allocator
|
| 212 |
+
|
| 213 |
+
Name of the memory allocator:
|
| 214 |
+
|
| 215 |
+
* ``PYMEM_ALLOCATOR_NOT_SET`` (``0``): don't change memory allocators
|
| 216 |
+
(use defaults)
|
| 217 |
+
* ``PYMEM_ALLOCATOR_DEFAULT`` (``1``): default memory allocators
|
| 218 |
+
* ``PYMEM_ALLOCATOR_DEBUG`` (``2``): default memory allocators with
|
| 219 |
+
debug hooks
|
| 220 |
+
* ``PYMEM_ALLOCATOR_MALLOC`` (``3``): force usage of ``malloc()``
|
| 221 |
+
* ``PYMEM_ALLOCATOR_MALLOC_DEBUG`` (``4``): force usage of
|
| 222 |
+
``malloc()`` with debug hooks
|
| 223 |
+
* ``PYMEM_ALLOCATOR_PYMALLOC`` (``5``): :ref:`Python pymalloc memory
|
| 224 |
+
allocator <pymalloc>`
|
| 225 |
+
* ``PYMEM_ALLOCATOR_PYMALLOC_DEBUG`` (``6``): :ref:`Python pymalloc
|
| 226 |
+
memory allocator <pymalloc>` with debug hooks
|
| 227 |
+
|
| 228 |
+
``PYMEM_ALLOCATOR_PYMALLOC`` and ``PYMEM_ALLOCATOR_PYMALLOC_DEBUG``
|
| 229 |
+
are not supported if Python is configured using ``--without-pymalloc``
|
| 230 |
+
|
| 231 |
+
See :ref:`Memory Management <memory>`.
|
| 232 |
+
|
| 233 |
+
.. c:member:: int configure_locale
|
| 234 |
+
|
| 235 |
+
Set the LC_CTYPE locale to the user preferred locale? If equals to 0, set
|
| 236 |
+
:c:member:`coerce_c_locale` and :c:member:`coerce_c_locale_warn` to 0.
|
| 237 |
+
|
| 238 |
+
.. c:member:: int coerce_c_locale
|
| 239 |
+
|
| 240 |
+
If equals to 2, coerce the C locale; if equals to 1, read the LC_CTYPE
|
| 241 |
+
locale to decide if it should be coerced.
|
| 242 |
+
|
| 243 |
+
.. c:member:: int coerce_c_locale_warn
|
| 244 |
+
|
| 245 |
+
If non-zero, emit a warning if the C locale is coerced.
|
| 246 |
+
|
| 247 |
+
.. c:member:: int dev_mode
|
| 248 |
+
|
| 249 |
+
See :c:member:`PyConfig.dev_mode`.
|
| 250 |
+
|
| 251 |
+
.. c:member:: int isolated
|
| 252 |
+
|
| 253 |
+
See :c:member:`PyConfig.isolated`.
|
| 254 |
+
|
| 255 |
+
.. c:member:: int legacy_windows_fs_encoding (Windows only)
|
| 256 |
+
|
| 257 |
+
If non-zero, disable UTF-8 Mode, set the Python filesystem encoding to
|
| 258 |
+
``mbcs``, set the filesystem error handler to ``replace``.
|
| 259 |
+
|
| 260 |
+
Only available on Windows. ``#ifdef MS_WINDOWS`` macro can be used for
|
| 261 |
+
Windows specific code.
|
| 262 |
+
|
| 263 |
+
.. c:member:: int parse_argv
|
| 264 |
+
|
| 265 |
+
If non-zero, :c:func:`Py_PreInitializeFromArgs` and
|
| 266 |
+
:c:func:`Py_PreInitializeFromBytesArgs` parse their ``argv`` argument the
|
| 267 |
+
same way the regular Python parses command line arguments: see
|
| 268 |
+
:ref:`Command Line Arguments <using-on-cmdline>`.
|
| 269 |
+
|
| 270 |
+
.. c:member:: int use_environment
|
| 271 |
+
|
| 272 |
+
See :c:member:`PyConfig.use_environment`.
|
| 273 |
+
|
| 274 |
+
.. c:member:: int utf8_mode
|
| 275 |
+
|
| 276 |
+
If non-zero, enable the UTF-8 mode.
|
| 277 |
+
|
| 278 |
+
Preinitialization with PyPreConfig
|
| 279 |
+
----------------------------------
|
| 280 |
+
|
| 281 |
+
Functions to preinitialize Python:
|
| 282 |
+
|
| 283 |
+
.. c:function:: PyStatus Py_PreInitialize(const PyPreConfig *preconfig)
|
| 284 |
+
|
| 285 |
+
Preinitialize Python from *preconfig* preconfiguration.
|
| 286 |
+
|
| 287 |
+
.. c:function:: PyStatus Py_PreInitializeFromBytesArgs(const PyPreConfig *preconfig, int argc, char * const *argv)
|
| 288 |
+
|
| 289 |
+
Preinitialize Python from *preconfig* preconfiguration and command line
|
| 290 |
+
arguments (bytes strings).
|
| 291 |
+
|
| 292 |
+
.. c:function:: PyStatus Py_PreInitializeFromArgs(const PyPreConfig *preconfig, int argc, wchar_t * const * argv)
|
| 293 |
+
|
| 294 |
+
Preinitialize Python from *preconfig* preconfiguration and command line
|
| 295 |
+
arguments (wide strings).
|
| 296 |
+
|
| 297 |
+
The caller is responsible to handle exceptions (error or exit) using
|
| 298 |
+
:c:func:`PyStatus_Exception` and :c:func:`Py_ExitStatusException`.
|
| 299 |
+
|
| 300 |
+
For :ref:`Python Configuration <init-python-config>`
|
| 301 |
+
(:c:func:`PyPreConfig_InitPythonConfig`), if Python is initialized with
|
| 302 |
+
command line arguments, the command line arguments must also be passed to
|
| 303 |
+
preinitialize Python, since they have an effect on the pre-configuration
|
| 304 |
+
like encodings. For example, the :option:`-X utf8 <-X>` command line option
|
| 305 |
+
enables the UTF-8 Mode.
|
| 306 |
+
|
| 307 |
+
``PyMem_SetAllocator()`` can be called after :c:func:`Py_PreInitialize` and
|
| 308 |
+
before :c:func:`Py_InitializeFromConfig` to install a custom memory allocator.
|
| 309 |
+
It can be called before :c:func:`Py_PreInitialize` if
|
| 310 |
+
:c:member:`PyPreConfig.allocator` is set to ``PYMEM_ALLOCATOR_NOT_SET``.
|
| 311 |
+
|
| 312 |
+
Python memory allocation functions like :c:func:`PyMem_RawMalloc` must not be
|
| 313 |
+
used before Python preinitialization, whereas calling directly ``malloc()`` and
|
| 314 |
+
``free()`` is always safe. :c:func:`Py_DecodeLocale` must not be called before
|
| 315 |
+
the preinitialization.
|
| 316 |
+
|
| 317 |
+
Example using the preinitialization to enable the UTF-8 Mode::
|
| 318 |
+
|
| 319 |
+
PyStatus status;
|
| 320 |
+
PyPreConfig preconfig;
|
| 321 |
+
PyPreConfig_InitPythonConfig(&preconfig);
|
| 322 |
+
|
| 323 |
+
preconfig.utf8_mode = 1;
|
| 324 |
+
|
| 325 |
+
status = Py_PreInitialize(&preconfig);
|
| 326 |
+
if (PyStatus_Exception(status)) {
|
| 327 |
+
Py_ExitStatusException(status);
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
/* at this point, Python will speak UTF-8 */
|
| 331 |
+
|
| 332 |
+
Py_Initialize();
|
| 333 |
+
/* ... use Python API here ... */
|
| 334 |
+
Py_Finalize();
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
PyConfig
|
| 338 |
+
--------
|
| 339 |
+
|
| 340 |
+
.. c:type:: PyConfig
|
| 341 |
+
|
| 342 |
+
Structure containing most parameters to configure Python.
|
| 343 |
+
|
| 344 |
+
Structure methods:
|
| 345 |
+
|
| 346 |
+
.. c:function:: void PyConfig_InitPythonConfig(PyConfig *config)
|
| 347 |
+
|
| 348 |
+
Initialize configuration with :ref:`Python Configuration
|
| 349 |
+
<init-python-config>`.
|
| 350 |
+
|
| 351 |
+
.. c:function:: void PyConfig_InitIsolatedConfig(PyConfig *config)
|
| 352 |
+
|
| 353 |
+
Initialize configuration with :ref:`Isolated Configuration
|
| 354 |
+
<init-isolated-conf>`.
|
| 355 |
+
|
| 356 |
+
.. c:function:: PyStatus PyConfig_SetString(PyConfig *config, wchar_t * const *config_str, const wchar_t *str)
|
| 357 |
+
|
| 358 |
+
Copy the wide character string *str* into ``*config_str``.
|
| 359 |
+
|
| 360 |
+
Preinitialize Python if needed.
|
| 361 |
+
|
| 362 |
+
.. c:function:: PyStatus PyConfig_SetBytesString(PyConfig *config, wchar_t * const *config_str, const char *str)
|
| 363 |
+
|
| 364 |
+
Decode *str* using ``Py_DecodeLocale()`` and set the result into ``*config_str``.
|
| 365 |
+
|
| 366 |
+
Preinitialize Python if needed.
|
| 367 |
+
|
| 368 |
+
.. c:function:: PyStatus PyConfig_SetArgv(PyConfig *config, int argc, wchar_t * const *argv)
|
| 369 |
+
|
| 370 |
+
Set command line arguments from wide character strings.
|
| 371 |
+
|
| 372 |
+
Preinitialize Python if needed.
|
| 373 |
+
|
| 374 |
+
.. c:function:: PyStatus PyConfig_SetBytesArgv(PyConfig *config, int argc, char * const *argv)
|
| 375 |
+
|
| 376 |
+
Set command line arguments: decode bytes using :c:func:`Py_DecodeLocale`.
|
| 377 |
+
|
| 378 |
+
Preinitialize Python if needed.
|
| 379 |
+
|
| 380 |
+
.. c:function:: PyStatus PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list, Py_ssize_t length, wchar_t **items)
|
| 381 |
+
|
| 382 |
+
Set the list of wide strings *list* to *length* and *items*.
|
| 383 |
+
|
| 384 |
+
Preinitialize Python if needed.
|
| 385 |
+
|
| 386 |
+
.. c:function:: PyStatus PyConfig_Read(PyConfig *config)
|
| 387 |
+
|
| 388 |
+
Read all Python configuration.
|
| 389 |
+
|
| 390 |
+
Fields which are already initialized are left unchanged.
|
| 391 |
+
|
| 392 |
+
Preinitialize Python if needed.
|
| 393 |
+
|
| 394 |
+
.. c:function:: void PyConfig_Clear(PyConfig *config)
|
| 395 |
+
|
| 396 |
+
Release configuration memory.
|
| 397 |
+
|
| 398 |
+
Most ``PyConfig`` methods preinitialize Python if needed. In that case, the
|
| 399 |
+
Python preinitialization configuration in based on the :c:type:`PyConfig`.
|
| 400 |
+
If configuration fields which are in common with :c:type:`PyPreConfig` are
|
| 401 |
+
tuned, they must be set before calling a :c:type:`PyConfig` method:
|
| 402 |
+
|
| 403 |
+
* :c:member:`~PyConfig.dev_mode`
|
| 404 |
+
* :c:member:`~PyConfig.isolated`
|
| 405 |
+
* :c:member:`~PyConfig.parse_argv`
|
| 406 |
+
* :c:member:`~PyConfig.use_environment`
|
| 407 |
+
|
| 408 |
+
Moreover, if :c:func:`PyConfig_SetArgv` or :c:func:`PyConfig_SetBytesArgv`
|
| 409 |
+
is used, this method must be called first, before other methods, since the
|
| 410 |
+
preinitialization configuration depends on command line arguments (if
|
| 411 |
+
:c:member:`parse_argv` is non-zero).
|
| 412 |
+
|
| 413 |
+
The caller of these methods is responsible to handle exceptions (error or
|
| 414 |
+
exit) using ``PyStatus_Exception()`` and ``Py_ExitStatusException()``.
|
| 415 |
+
|
| 416 |
+
Structure fields:
|
| 417 |
+
|
| 418 |
+
.. c:member:: PyWideStringList argv
|
| 419 |
+
|
| 420 |
+
Command line arguments, :data:`sys.argv`. See
|
| 421 |
+
:c:member:`~PyConfig.parse_argv` to parse :c:member:`~PyConfig.argv` the
|
| 422 |
+
same way the regular Python parses Python command line arguments. If
|
| 423 |
+
:c:member:`~PyConfig.argv` is empty, an empty string is added to ensure
|
| 424 |
+
that :data:`sys.argv` always exists and is never empty.
|
| 425 |
+
|
| 426 |
+
.. c:member:: wchar_t* base_exec_prefix
|
| 427 |
+
|
| 428 |
+
:data:`sys.base_exec_prefix`.
|
| 429 |
+
|
| 430 |
+
.. c:member:: wchar_t* base_executable
|
| 431 |
+
|
| 432 |
+
:data:`sys._base_executable`: ``__PYVENV_LAUNCHER__`` environment
|
| 433 |
+
variable value, or copy of :c:member:`PyConfig.executable`.
|
| 434 |
+
|
| 435 |
+
.. c:member:: wchar_t* base_prefix
|
| 436 |
+
|
| 437 |
+
:data:`sys.base_prefix`.
|
| 438 |
+
|
| 439 |
+
.. c:member:: int buffered_stdio
|
| 440 |
+
|
| 441 |
+
If equals to 0, enable unbuffered mode, making the stdout and stderr
|
| 442 |
+
streams unbuffered.
|
| 443 |
+
|
| 444 |
+
stdin is always opened in buffered mode.
|
| 445 |
+
|
| 446 |
+
.. c:member:: int bytes_warning
|
| 447 |
+
|
| 448 |
+
If equals to 1, issue a warning when comparing :class:`bytes` or
|
| 449 |
+
:class:`bytearray` with :class:`str`, or comparing :class:`bytes` with
|
| 450 |
+
:class:`int`. If equal or greater to 2, raise a :exc:`BytesWarning`
|
| 451 |
+
exception.
|
| 452 |
+
|
| 453 |
+
.. c:member:: wchar_t* check_hash_pycs_mode
|
| 454 |
+
|
| 455 |
+
Control the validation behavior of hash-based ``.pyc`` files (see
|
| 456 |
+
:pep:`552`): :option:`--check-hash-based-pycs` command line option value.
|
| 457 |
+
|
| 458 |
+
Valid values: ``always``, ``never`` and ``default``.
|
| 459 |
+
|
| 460 |
+
The default value is: ``default``.
|
| 461 |
+
|
| 462 |
+
.. c:member:: int configure_c_stdio
|
| 463 |
+
|
| 464 |
+
If non-zero, configure C standard streams (``stdio``, ``stdout``,
|
| 465 |
+
``stdout``). For example, set their mode to ``O_BINARY`` on Windows.
|
| 466 |
+
|
| 467 |
+
.. c:member:: int dev_mode
|
| 468 |
+
|
| 469 |
+
If non-zero, enable the :ref:`Python Development Mode <devmode>`.
|
| 470 |
+
|
| 471 |
+
.. c:member:: int dump_refs
|
| 472 |
+
|
| 473 |
+
If non-zero, dump all objects which are still alive at exit.
|
| 474 |
+
|
| 475 |
+
``Py_TRACE_REFS`` macro must be defined in build.
|
| 476 |
+
|
| 477 |
+
.. c:member:: wchar_t* exec_prefix
|
| 478 |
+
|
| 479 |
+
:data:`sys.exec_prefix`.
|
| 480 |
+
|
| 481 |
+
.. c:member:: wchar_t* executable
|
| 482 |
+
|
| 483 |
+
:data:`sys.executable`.
|
| 484 |
+
|
| 485 |
+
.. c:member:: int faulthandler
|
| 486 |
+
|
| 487 |
+
If non-zero, call :func:`faulthandler.enable` at startup.
|
| 488 |
+
|
| 489 |
+
.. c:member:: wchar_t* filesystem_encoding
|
| 490 |
+
|
| 491 |
+
Filesystem encoding, :func:`sys.getfilesystemencoding`.
|
| 492 |
+
|
| 493 |
+
.. c:member:: wchar_t* filesystem_errors
|
| 494 |
+
|
| 495 |
+
Filesystem encoding errors, :func:`sys.getfilesystemencodeerrors`.
|
| 496 |
+
|
| 497 |
+
.. c:member:: unsigned long hash_seed
|
| 498 |
+
.. c:member:: int use_hash_seed
|
| 499 |
+
|
| 500 |
+
Randomized hash function seed.
|
| 501 |
+
|
| 502 |
+
If :c:member:`~PyConfig.use_hash_seed` is zero, a seed is chosen randomly
|
| 503 |
+
at Pythonstartup, and :c:member:`~PyConfig.hash_seed` is ignored.
|
| 504 |
+
|
| 505 |
+
.. c:member:: wchar_t* home
|
| 506 |
+
|
| 507 |
+
Python home directory.
|
| 508 |
+
|
| 509 |
+
Initialized from :envvar:`PYTHONHOME` environment variable value by
|
| 510 |
+
default.
|
| 511 |
+
|
| 512 |
+
.. c:member:: int import_time
|
| 513 |
+
|
| 514 |
+
If non-zero, profile import time.
|
| 515 |
+
|
| 516 |
+
.. c:member:: int inspect
|
| 517 |
+
|
| 518 |
+
Enter interactive mode after executing a script or a command.
|
| 519 |
+
|
| 520 |
+
.. c:member:: int install_signal_handlers
|
| 521 |
+
|
| 522 |
+
Install signal handlers?
|
| 523 |
+
|
| 524 |
+
.. c:member:: int interactive
|
| 525 |
+
|
| 526 |
+
Interactive mode.
|
| 527 |
+
|
| 528 |
+
.. c:member:: int isolated
|
| 529 |
+
|
| 530 |
+
If greater than 0, enable isolated mode:
|
| 531 |
+
|
| 532 |
+
* :data:`sys.path` contains neither the script's directory (computed from
|
| 533 |
+
``argv[0]`` or the current directory) nor the user's site-packages
|
| 534 |
+
directory.
|
| 535 |
+
* Python REPL doesn't import :mod:`readline` nor enable default readline
|
| 536 |
+
configuration on interactive prompts.
|
| 537 |
+
* Set :c:member:`~PyConfig.use_environment` and
|
| 538 |
+
:c:member:`~PyConfig.user_site_directory` to 0.
|
| 539 |
+
|
| 540 |
+
.. c:member:: int legacy_windows_stdio
|
| 541 |
+
|
| 542 |
+
If non-zero, use :class:`io.FileIO` instead of
|
| 543 |
+
:class:`io.WindowsConsoleIO` for :data:`sys.stdin`, :data:`sys.stdout`
|
| 544 |
+
and :data:`sys.stderr`.
|
| 545 |
+
|
| 546 |
+
Only available on Windows. ``#ifdef MS_WINDOWS`` macro can be used for
|
| 547 |
+
Windows specific code.
|
| 548 |
+
|
| 549 |
+
.. c:member:: int malloc_stats
|
| 550 |
+
|
| 551 |
+
If non-zero, dump statistics on :ref:`Python pymalloc memory allocator
|
| 552 |
+
<pymalloc>` at exit.
|
| 553 |
+
|
| 554 |
+
The option is ignored if Python is built using ``--without-pymalloc``.
|
| 555 |
+
|
| 556 |
+
.. c:member:: wchar_t* pythonpath_env
|
| 557 |
+
|
| 558 |
+
Module search paths as a string separated by ``DELIM``
|
| 559 |
+
(:data:`os.path.pathsep`).
|
| 560 |
+
|
| 561 |
+
Initialized from :envvar:`PYTHONPATH` environment variable value by
|
| 562 |
+
default.
|
| 563 |
+
|
| 564 |
+
.. c:member:: PyWideStringList module_search_paths
|
| 565 |
+
.. c:member:: int module_search_paths_set
|
| 566 |
+
|
| 567 |
+
:data:`sys.path`. If :c:member:`~PyConfig.module_search_paths_set` is
|
| 568 |
+
equal to 0, the :c:member:`~PyConfig.module_search_paths` is overridden
|
| 569 |
+
by the function calculating the :ref:`Path Configuration
|
| 570 |
+
<init-path-config>`.
|
| 571 |
+
|
| 572 |
+
.. c:member:: int optimization_level
|
| 573 |
+
|
| 574 |
+
Compilation optimization level:
|
| 575 |
+
|
| 576 |
+
* 0: Peephole optimizer (and ``__debug__`` is set to ``True``)
|
| 577 |
+
* 1: Remove assertions, set ``__debug__`` to ``False``
|
| 578 |
+
* 2: Strip docstrings
|
| 579 |
+
|
| 580 |
+
.. c:member:: int parse_argv
|
| 581 |
+
|
| 582 |
+
If non-zero, parse :c:member:`~PyConfig.argv` the same way the regular
|
| 583 |
+
Python command line arguments, and strip Python arguments from
|
| 584 |
+
:c:member:`~PyConfig.argv`: see :ref:`Command Line Arguments
|
| 585 |
+
<using-on-cmdline>`.
|
| 586 |
+
|
| 587 |
+
.. c:member:: int parser_debug
|
| 588 |
+
|
| 589 |
+
If non-zero, turn on parser debugging output (for expert only, depending
|
| 590 |
+
on compilation options).
|
| 591 |
+
|
| 592 |
+
.. c:member:: int pathconfig_warnings
|
| 593 |
+
|
| 594 |
+
If equal to 0, suppress warnings when calculating the :ref:`Path
|
| 595 |
+
Configuration <init-path-config>` (Unix only, Windows does not log any
|
| 596 |
+
warning). Otherwise, warnings are written into ``stderr``.
|
| 597 |
+
|
| 598 |
+
.. c:member:: wchar_t* prefix
|
| 599 |
+
|
| 600 |
+
:data:`sys.prefix`.
|
| 601 |
+
|
| 602 |
+
.. c:member:: wchar_t* program_name
|
| 603 |
+
|
| 604 |
+
Program name. Used to initialize :c:member:`~PyConfig.executable`, and in
|
| 605 |
+
early error messages.
|
| 606 |
+
|
| 607 |
+
.. c:member:: wchar_t* pycache_prefix
|
| 608 |
+
|
| 609 |
+
:data:`sys.pycache_prefix`: ``.pyc`` cache prefix.
|
| 610 |
+
|
| 611 |
+
If ``NULL``, :data:`sys.pycache_prefix` is set to ``None``.
|
| 612 |
+
|
| 613 |
+
.. c:member:: int quiet
|
| 614 |
+
|
| 615 |
+
Quiet mode. For example, don't display the copyright and version messages
|
| 616 |
+
in interactive mode.
|
| 617 |
+
|
| 618 |
+
.. c:member:: wchar_t* run_command
|
| 619 |
+
|
| 620 |
+
``python3 -c COMMAND`` argument. Used by :c:func:`Py_RunMain`.
|
| 621 |
+
|
| 622 |
+
.. c:member:: wchar_t* run_filename
|
| 623 |
+
|
| 624 |
+
``python3 FILENAME`` argument. Used by :c:func:`Py_RunMain`.
|
| 625 |
+
|
| 626 |
+
.. c:member:: wchar_t* run_module
|
| 627 |
+
|
| 628 |
+
``python3 -m MODULE`` argument. Used by :c:func:`Py_RunMain`.
|
| 629 |
+
|
| 630 |
+
.. c:member:: int show_ref_count
|
| 631 |
+
|
| 632 |
+
Show total reference count at exit?
|
| 633 |
+
|
| 634 |
+
Set to 1 by :option:`-X showrefcount <-X>` command line option.
|
| 635 |
+
|
| 636 |
+
Need a debug build of Python (``Py_REF_DEBUG`` macro must be defined).
|
| 637 |
+
|
| 638 |
+
.. c:member:: int site_import
|
| 639 |
+
|
| 640 |
+
Import the :mod:`site` module at startup?
|
| 641 |
+
|
| 642 |
+
.. c:member:: int skip_source_first_line
|
| 643 |
+
|
| 644 |
+
Skip the first line of the source?
|
| 645 |
+
|
| 646 |
+
.. c:member:: wchar_t* stdio_encoding
|
| 647 |
+
.. c:member:: wchar_t* stdio_errors
|
| 648 |
+
|
| 649 |
+
Encoding and encoding errors of :data:`sys.stdin`, :data:`sys.stdout` and
|
| 650 |
+
:data:`sys.stderr`.
|
| 651 |
+
|
| 652 |
+
.. c:member:: int tracemalloc
|
| 653 |
+
|
| 654 |
+
If non-zero, call :func:`tracemalloc.start` at startup.
|
| 655 |
+
|
| 656 |
+
.. c:member:: int use_environment
|
| 657 |
+
|
| 658 |
+
If greater than 0, use :ref:`environment variables <using-on-envvars>`.
|
| 659 |
+
|
| 660 |
+
.. c:member:: int user_site_directory
|
| 661 |
+
|
| 662 |
+
If non-zero, add user site directory to :data:`sys.path`.
|
| 663 |
+
|
| 664 |
+
.. c:member:: int verbose
|
| 665 |
+
|
| 666 |
+
If non-zero, enable verbose mode.
|
| 667 |
+
|
| 668 |
+
.. c:member:: PyWideStringList warnoptions
|
| 669 |
+
|
| 670 |
+
:data:`sys.warnoptions`: options of the :mod:`warnings` module to build
|
| 671 |
+
warnings filters: lowest to highest priority.
|
| 672 |
+
|
| 673 |
+
The :mod:`warnings` module adds :data:`sys.warnoptions` in the reverse
|
| 674 |
+
order: the last :c:member:`PyConfig.warnoptions` item becomes the first
|
| 675 |
+
item of :data:`warnings.filters` which is checked first (highest
|
| 676 |
+
priority).
|
| 677 |
+
|
| 678 |
+
.. c:member:: int write_bytecode
|
| 679 |
+
|
| 680 |
+
If non-zero, write ``.pyc`` files.
|
| 681 |
+
|
| 682 |
+
:data:`sys.dont_write_bytecode` is initialized to the inverted value of
|
| 683 |
+
:c:member:`~PyConfig.write_bytecode`.
|
| 684 |
+
|
| 685 |
+
.. c:member:: PyWideStringList xoptions
|
| 686 |
+
|
| 687 |
+
:data:`sys._xoptions`.
|
| 688 |
+
|
| 689 |
+
.. c:member:: int _use_peg_parser
|
| 690 |
+
|
| 691 |
+
Enable PEG parser? Default: 1.
|
| 692 |
+
|
| 693 |
+
Set to 0 by :option:`-X oldparser <-X>` and :envvar:`PYTHONOLDPARSER`.
|
| 694 |
+
|
| 695 |
+
See also :pep:`617`.
|
| 696 |
+
|
| 697 |
+
.. deprecated-removed:: 3.9 3.10
|
| 698 |
+
|
| 699 |
+
If ``parse_argv`` is non-zero, ``argv`` arguments are parsed the same
|
| 700 |
+
way the regular Python parses command line arguments, and Python
|
| 701 |
+
arguments are stripped from ``argv``: see :ref:`Command Line Arguments
|
| 702 |
+
<using-on-cmdline>`.
|
| 703 |
+
|
| 704 |
+
The ``xoptions`` options are parsed to set other options: see :option:`-X`
|
| 705 |
+
option.
|
| 706 |
+
|
| 707 |
+
.. versionchanged:: 3.9
|
| 708 |
+
|
| 709 |
+
The ``show_alloc_count`` field has been removed.
|
| 710 |
+
|
| 711 |
+
|
| 712 |
+
Initialization with PyConfig
|
| 713 |
+
----------------------------
|
| 714 |
+
|
| 715 |
+
Function to initialize Python:
|
| 716 |
+
|
| 717 |
+
.. c:function:: PyStatus Py_InitializeFromConfig(const PyConfig *config)
|
| 718 |
+
|
| 719 |
+
Initialize Python from *config* configuration.
|
| 720 |
+
|
| 721 |
+
The caller is responsible to handle exceptions (error or exit) using
|
| 722 |
+
:c:func:`PyStatus_Exception` and :c:func:`Py_ExitStatusException`.
|
| 723 |
+
|
| 724 |
+
If ``PyImport_FrozenModules``, ``PyImport_AppendInittab()`` or
|
| 725 |
+
``PyImport_ExtendInittab()`` are used, they must be set or called after Python
|
| 726 |
+
preinitialization and before the Python initialization.
|
| 727 |
+
|
| 728 |
+
Example setting the program name::
|
| 729 |
+
|
| 730 |
+
void init_python(void)
|
| 731 |
+
{
|
| 732 |
+
PyStatus status;
|
| 733 |
+
|
| 734 |
+
PyConfig config;
|
| 735 |
+
PyConfig_InitPythonConfig(&config);
|
| 736 |
+
|
| 737 |
+
/* Set the program name. Implicitly preinitialize Python. */
|
| 738 |
+
status = PyConfig_SetString(&config, &config.program_name,
|
| 739 |
+
L"/path/to/my_program");
|
| 740 |
+
if (PyStatus_Exception(status)) {
|
| 741 |
+
goto fail;
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
status = Py_InitializeFromConfig(&config);
|
| 745 |
+
if (PyStatus_Exception(status)) {
|
| 746 |
+
goto fail;
|
| 747 |
+
}
|
| 748 |
+
PyConfig_Clear(&config);
|
| 749 |
+
return;
|
| 750 |
+
|
| 751 |
+
fail:
|
| 752 |
+
PyConfig_Clear(&config);
|
| 753 |
+
Py_ExitStatusException(status);
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
More complete example modifying the default configuration, read the
|
| 757 |
+
configuration, and then override some parameters::
|
| 758 |
+
|
| 759 |
+
PyStatus init_python(const char *program_name)
|
| 760 |
+
{
|
| 761 |
+
PyStatus status;
|
| 762 |
+
|
| 763 |
+
PyConfig config;
|
| 764 |
+
PyConfig_InitPythonConfig(&config);
|
| 765 |
+
|
| 766 |
+
/* Set the program name before reading the configuration
|
| 767 |
+
(decode byte string from the locale encoding).
|
| 768 |
+
|
| 769 |
+
Implicitly preinitialize Python. */
|
| 770 |
+
status = PyConfig_SetBytesString(&config, &config.program_name,
|
| 771 |
+
program_name);
|
| 772 |
+
if (PyStatus_Exception(status)) {
|
| 773 |
+
goto done;
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
/* Read all configuration at once */
|
| 777 |
+
status = PyConfig_Read(&config);
|
| 778 |
+
if (PyStatus_Exception(status)) {
|
| 779 |
+
goto done;
|
| 780 |
+
}
|
| 781 |
+
|
| 782 |
+
/* Append our custom search path to sys.path */
|
| 783 |
+
status = PyWideStringList_Append(&config.module_search_paths,
|
| 784 |
+
L"/path/to/more/modules");
|
| 785 |
+
if (PyStatus_Exception(status)) {
|
| 786 |
+
goto done;
|
| 787 |
+
}
|
| 788 |
+
|
| 789 |
+
/* Override executable computed by PyConfig_Read() */
|
| 790 |
+
status = PyConfig_SetString(&config, &config.executable,
|
| 791 |
+
L"/path/to/my_executable");
|
| 792 |
+
if (PyStatus_Exception(status)) {
|
| 793 |
+
goto done;
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
status = Py_InitializeFromConfig(&config);
|
| 797 |
+
|
| 798 |
+
done:
|
| 799 |
+
PyConfig_Clear(&config);
|
| 800 |
+
return status;
|
| 801 |
+
}
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
.. _init-isolated-conf:
|
| 805 |
+
|
| 806 |
+
Isolated Configuration
|
| 807 |
+
----------------------
|
| 808 |
+
|
| 809 |
+
:c:func:`PyPreConfig_InitIsolatedConfig` and
|
| 810 |
+
:c:func:`PyConfig_InitIsolatedConfig` functions create a configuration to
|
| 811 |
+
isolate Python from the system. For example, to embed Python into an
|
| 812 |
+
application.
|
| 813 |
+
|
| 814 |
+
This configuration ignores global configuration variables, environments
|
| 815 |
+
variables, command line arguments (:c:member:`PyConfig.argv` is not parsed)
|
| 816 |
+
and user site directory. The C standard streams (ex: ``stdout``) and the
|
| 817 |
+
LC_CTYPE locale are left unchanged. Signal handlers are not installed.
|
| 818 |
+
|
| 819 |
+
Configuration files are still used with this configuration. Set the
|
| 820 |
+
:ref:`Path Configuration <init-path-config>` ("output fields") to ignore these
|
| 821 |
+
configuration files and avoid the function computing the default path
|
| 822 |
+
configuration.
|
| 823 |
+
|
| 824 |
+
|
| 825 |
+
.. _init-python-config:
|
| 826 |
+
|
| 827 |
+
Python Configuration
|
| 828 |
+
--------------------
|
| 829 |
+
|
| 830 |
+
:c:func:`PyPreConfig_InitPythonConfig` and :c:func:`PyConfig_InitPythonConfig`
|
| 831 |
+
functions create a configuration to build a customized Python which behaves as
|
| 832 |
+
the regular Python.
|
| 833 |
+
|
| 834 |
+
Environments variables and command line arguments are used to configure
|
| 835 |
+
Python, whereas global configuration variables are ignored.
|
| 836 |
+
|
| 837 |
+
This function enables C locale coercion (:pep:`538`) and UTF-8 Mode
|
| 838 |
+
(:pep:`540`) depending on the LC_CTYPE locale, :envvar:`PYTHONUTF8` and
|
| 839 |
+
:envvar:`PYTHONCOERCECLOCALE` environment variables.
|
| 840 |
+
|
| 841 |
+
Example of customized Python always running in isolated mode::
|
| 842 |
+
|
| 843 |
+
int main(int argc, char **argv)
|
| 844 |
+
{
|
| 845 |
+
PyStatus status;
|
| 846 |
+
|
| 847 |
+
PyConfig config;
|
| 848 |
+
PyConfig_InitPythonConfig(&config);
|
| 849 |
+
config.isolated = 1;
|
| 850 |
+
|
| 851 |
+
/* Decode command line arguments.
|
| 852 |
+
Implicitly preinitialize Python (in isolated mode). */
|
| 853 |
+
status = PyConfig_SetBytesArgv(&config, argc, argv);
|
| 854 |
+
if (PyStatus_Exception(status)) {
|
| 855 |
+
goto fail;
|
| 856 |
+
}
|
| 857 |
+
|
| 858 |
+
status = Py_InitializeFromConfig(&config);
|
| 859 |
+
if (PyStatus_Exception(status)) {
|
| 860 |
+
goto fail;
|
| 861 |
+
}
|
| 862 |
+
PyConfig_Clear(&config);
|
| 863 |
+
|
| 864 |
+
return Py_RunMain();
|
| 865 |
+
|
| 866 |
+
fail:
|
| 867 |
+
PyConfig_Clear(&config);
|
| 868 |
+
if (PyStatus_IsExit(status)) {
|
| 869 |
+
return status.exitcode;
|
| 870 |
+
}
|
| 871 |
+
/* Display the error message and exit the process with
|
| 872 |
+
non-zero exit code */
|
| 873 |
+
Py_ExitStatusException(status);
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
|
| 877 |
+
.. _init-path-config:
|
| 878 |
+
|
| 879 |
+
Path Configuration
|
| 880 |
+
------------------
|
| 881 |
+
|
| 882 |
+
:c:type:`PyConfig` contains multiple fields for the path configuration:
|
| 883 |
+
|
| 884 |
+
* Path configuration inputs:
|
| 885 |
+
|
| 886 |
+
* :c:member:`PyConfig.home`
|
| 887 |
+
* :c:member:`PyConfig.pathconfig_warnings`
|
| 888 |
+
* :c:member:`PyConfig.program_name`
|
| 889 |
+
* :c:member:`PyConfig.pythonpath_env`
|
| 890 |
+
* current working directory: to get absolute paths
|
| 891 |
+
* ``PATH`` environment variable to get the program full path
|
| 892 |
+
(from :c:member:`PyConfig.program_name`)
|
| 893 |
+
* ``__PYVENV_LAUNCHER__`` environment variable
|
| 894 |
+
* (Windows only) Application paths in the registry under
|
| 895 |
+
"Software\Python\PythonCore\X.Y\PythonPath" of HKEY_CURRENT_USER and
|
| 896 |
+
HKEY_LOCAL_MACHINE (where X.Y is the Python version).
|
| 897 |
+
|
| 898 |
+
* Path configuration output fields:
|
| 899 |
+
|
| 900 |
+
* :c:member:`PyConfig.base_exec_prefix`
|
| 901 |
+
* :c:member:`PyConfig.base_executable`
|
| 902 |
+
* :c:member:`PyConfig.base_prefix`
|
| 903 |
+
* :c:member:`PyConfig.exec_prefix`
|
| 904 |
+
* :c:member:`PyConfig.executable`
|
| 905 |
+
* :c:member:`PyConfig.module_search_paths_set`,
|
| 906 |
+
:c:member:`PyConfig.module_search_paths`
|
| 907 |
+
* :c:member:`PyConfig.prefix`
|
| 908 |
+
|
| 909 |
+
If at least one "output field" is not set, Python calculates the path
|
| 910 |
+
configuration to fill unset fields. If
|
| 911 |
+
:c:member:`~PyConfig.module_search_paths_set` is equal to 0,
|
| 912 |
+
:c:member:`~PyConfig.module_search_paths` is overridden and
|
| 913 |
+
:c:member:`~PyConfig.module_search_paths_set` is set to 1.
|
| 914 |
+
|
| 915 |
+
It is possible to completely ignore the function calculating the default
|
| 916 |
+
path configuration by setting explicitly all path configuration output
|
| 917 |
+
fields listed above. A string is considered as set even if it is non-empty.
|
| 918 |
+
``module_search_paths`` is considered as set if
|
| 919 |
+
``module_search_paths_set`` is set to 1. In this case, path
|
| 920 |
+
configuration input fields are ignored as well.
|
| 921 |
+
|
| 922 |
+
Set :c:member:`~PyConfig.pathconfig_warnings` to 0 to suppress warnings when
|
| 923 |
+
calculating the path configuration (Unix only, Windows does not log any warning).
|
| 924 |
+
|
| 925 |
+
If :c:member:`~PyConfig.base_prefix` or :c:member:`~PyConfig.base_exec_prefix`
|
| 926 |
+
fields are not set, they inherit their value from :c:member:`~PyConfig.prefix`
|
| 927 |
+
and :c:member:`~PyConfig.exec_prefix` respectively.
|
| 928 |
+
|
| 929 |
+
:c:func:`Py_RunMain` and :c:func:`Py_Main` modify :data:`sys.path`:
|
| 930 |
+
|
| 931 |
+
* If :c:member:`~PyConfig.run_filename` is set and is a directory which contains a
|
| 932 |
+
``__main__.py`` script, prepend :c:member:`~PyConfig.run_filename` to
|
| 933 |
+
:data:`sys.path`.
|
| 934 |
+
* If :c:member:`~PyConfig.isolated` is zero:
|
| 935 |
+
|
| 936 |
+
* If :c:member:`~PyConfig.run_module` is set, prepend the current directory
|
| 937 |
+
to :data:`sys.path`. Do nothing if the current directory cannot be read.
|
| 938 |
+
* If :c:member:`~PyConfig.run_filename` is set, prepend the directory of the
|
| 939 |
+
filename to :data:`sys.path`.
|
| 940 |
+
* Otherwise, prepend an empty string to :data:`sys.path`.
|
| 941 |
+
|
| 942 |
+
If :c:member:`~PyConfig.site_import` is non-zero, :data:`sys.path` can be
|
| 943 |
+
modified by the :mod:`site` module. If
|
| 944 |
+
:c:member:`~PyConfig.user_site_directory` is non-zero and the user's
|
| 945 |
+
site-package directory exists, the :mod:`site` module appends the user's
|
| 946 |
+
site-package directory to :data:`sys.path`.
|
| 947 |
+
|
| 948 |
+
The following configuration files are used by the path configuration:
|
| 949 |
+
|
| 950 |
+
* ``pyvenv.cfg``
|
| 951 |
+
* ``python._pth`` (Windows only)
|
| 952 |
+
* ``pybuilddir.txt`` (Unix only)
|
| 953 |
+
|
| 954 |
+
The ``__PYVENV_LAUNCHER__`` environment variable is used to set
|
| 955 |
+
:c:member:`PyConfig.base_executable`
|
| 956 |
+
|
| 957 |
+
|
| 958 |
+
Py_RunMain()
|
| 959 |
+
------------
|
| 960 |
+
|
| 961 |
+
.. c:function:: int Py_RunMain(void)
|
| 962 |
+
|
| 963 |
+
Execute the command (:c:member:`PyConfig.run_command`), the script
|
| 964 |
+
(:c:member:`PyConfig.run_filename`) or the module
|
| 965 |
+
(:c:member:`PyConfig.run_module`) specified on the command line or in the
|
| 966 |
+
configuration.
|
| 967 |
+
|
| 968 |
+
By default and when if :option:`-i` option is used, run the REPL.
|
| 969 |
+
|
| 970 |
+
Finally, finalizes Python and returns an exit status that can be passed to
|
| 971 |
+
the ``exit()`` function.
|
| 972 |
+
|
| 973 |
+
See :ref:`Python Configuration <init-python-config>` for an example of
|
| 974 |
+
customized Python always running in isolated mode using
|
| 975 |
+
:c:func:`Py_RunMain`.
|
| 976 |
+
|
| 977 |
+
|
| 978 |
+
Multi-Phase Initialization Private Provisional API
|
| 979 |
+
--------------------------------------------------
|
| 980 |
+
|
| 981 |
+
This section is a private provisional API introducing multi-phase
|
| 982 |
+
initialization, the core feature of the :pep:`432`:
|
| 983 |
+
|
| 984 |
+
* "Core" initialization phase, "bare minimum Python":
|
| 985 |
+
|
| 986 |
+
* Builtin types;
|
| 987 |
+
* Builtin exceptions;
|
| 988 |
+
* Builtin and frozen modules;
|
| 989 |
+
* The :mod:`sys` module is only partially initialized
|
| 990 |
+
(ex: :data:`sys.path` doesn't exist yet).
|
| 991 |
+
|
| 992 |
+
* "Main" initialization phase, Python is fully initialized:
|
| 993 |
+
|
| 994 |
+
* Install and configure :mod:`importlib`;
|
| 995 |
+
* Apply the :ref:`Path Configuration <init-path-config>`;
|
| 996 |
+
* Install signal handlers;
|
| 997 |
+
* Finish :mod:`sys` module initialization (ex: create :data:`sys.stdout`
|
| 998 |
+
and :data:`sys.path`);
|
| 999 |
+
* Enable optional features like :mod:`faulthandler` and :mod:`tracemalloc`;
|
| 1000 |
+
* Import the :mod:`site` module;
|
| 1001 |
+
* etc.
|
| 1002 |
+
|
| 1003 |
+
Private provisional API:
|
| 1004 |
+
|
| 1005 |
+
* :c:member:`PyConfig._init_main`: if set to 0,
|
| 1006 |
+
:c:func:`Py_InitializeFromConfig` stops at the "Core" initialization phase.
|
| 1007 |
+
* :c:member:`PyConfig._isolated_interpreter`: if non-zero,
|
| 1008 |
+
disallow threads, subprocesses and fork.
|
| 1009 |
+
|
| 1010 |
+
.. c:function:: PyStatus _Py_InitializeMain(void)
|
| 1011 |
+
|
| 1012 |
+
Move to the "Main" initialization phase, finish the Python initialization.
|
| 1013 |
+
|
| 1014 |
+
No module is imported during the "Core" phase and the ``importlib`` module is
|
| 1015 |
+
not configured: the :ref:`Path Configuration <init-path-config>` is only
|
| 1016 |
+
applied during the "Main" phase. It may allow to customize Python in Python to
|
| 1017 |
+
override or tune the :ref:`Path Configuration <init-path-config>`, maybe
|
| 1018 |
+
install a custom :data:`sys.meta_path` importer or an import hook, etc.
|
| 1019 |
+
|
| 1020 |
+
It may become possible to calculatin the :ref:`Path Configuration
|
| 1021 |
+
<init-path-config>` in Python, after the Core phase and before the Main phase,
|
| 1022 |
+
which is one of the :pep:`432` motivation.
|
| 1023 |
+
|
| 1024 |
+
The "Core" phase is not properly defined: what should be and what should
|
| 1025 |
+
not be available at this phase is not specified yet. The API is marked
|
| 1026 |
+
as private and provisional: the API can be modified or even be removed
|
| 1027 |
+
anytime until a proper public API is designed.
|
| 1028 |
+
|
| 1029 |
+
Example running Python code between "Core" and "Main" initialization
|
| 1030 |
+
phases::
|
| 1031 |
+
|
| 1032 |
+
void init_python(void)
|
| 1033 |
+
{
|
| 1034 |
+
PyStatus status;
|
| 1035 |
+
|
| 1036 |
+
PyConfig config;
|
| 1037 |
+
PyConfig_InitPythonConfig(&config);
|
| 1038 |
+
config._init_main = 0;
|
| 1039 |
+
|
| 1040 |
+
/* ... customize 'config' configuration ... */
|
| 1041 |
+
|
| 1042 |
+
status = Py_InitializeFromConfig(&config);
|
| 1043 |
+
PyConfig_Clear(&config);
|
| 1044 |
+
if (PyStatus_Exception(status)) {
|
| 1045 |
+
Py_ExitStatusException(status);
|
| 1046 |
+
}
|
| 1047 |
+
|
| 1048 |
+
/* Use sys.stderr because sys.stdout is only created
|
| 1049 |
+
by _Py_InitializeMain() */
|
| 1050 |
+
int res = PyRun_SimpleString(
|
| 1051 |
+
"import sys; "
|
| 1052 |
+
"print('Run Python code before _Py_InitializeMain', "
|
| 1053 |
+
"file=sys.stderr)");
|
| 1054 |
+
if (res < 0) {
|
| 1055 |
+
exit(1);
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
/* ... put more configuration code here ... */
|
| 1059 |
+
|
| 1060 |
+
status = _Py_InitializeMain();
|
| 1061 |
+
if (PyStatus_Exception(status)) {
|
| 1062 |
+
Py_ExitStatusException(status);
|
| 1063 |
+
}
|
| 1064 |
+
}
|
cpython_2/environment/repo/Doc/c-api/intro.rst
ADDED
|
@@ -0,0 +1,785 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
************
|
| 7 |
+
Introduction
|
| 8 |
+
************
|
| 9 |
+
|
| 10 |
+
The Application Programmer's Interface to Python gives C and C++ programmers
|
| 11 |
+
access to the Python interpreter at a variety of levels. The API is equally
|
| 12 |
+
usable from C++, but for brevity it is generally referred to as the Python/C
|
| 13 |
+
API. There are two fundamentally different reasons for using the Python/C API.
|
| 14 |
+
The first reason is to write *extension modules* for specific purposes; these
|
| 15 |
+
are C modules that extend the Python interpreter. This is probably the most
|
| 16 |
+
common use. The second reason is to use Python as a component in a larger
|
| 17 |
+
application; this technique is generally referred to as :dfn:`embedding` Python
|
| 18 |
+
in an application.
|
| 19 |
+
|
| 20 |
+
Writing an extension module is a relatively well-understood process, where a
|
| 21 |
+
"cookbook" approach works well. There are several tools that automate the
|
| 22 |
+
process to some extent. While people have embedded Python in other
|
| 23 |
+
applications since its early existence, the process of embedding Python is
|
| 24 |
+
less straightforward than writing an extension.
|
| 25 |
+
|
| 26 |
+
Many API functions are useful independent of whether you're embedding or
|
| 27 |
+
extending Python; moreover, most applications that embed Python will need to
|
| 28 |
+
provide a custom extension as well, so it's probably a good idea to become
|
| 29 |
+
familiar with writing an extension before attempting to embed Python in a real
|
| 30 |
+
application.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Coding standards
|
| 34 |
+
================
|
| 35 |
+
|
| 36 |
+
If you're writing C code for inclusion in CPython, you **must** follow the
|
| 37 |
+
guidelines and standards defined in :PEP:`7`. These guidelines apply
|
| 38 |
+
regardless of the version of Python you are contributing to. Following these
|
| 39 |
+
conventions is not necessary for your own third party extension modules,
|
| 40 |
+
unless you eventually expect to contribute them to Python.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
.. _api-includes:
|
| 44 |
+
|
| 45 |
+
Include Files
|
| 46 |
+
=============
|
| 47 |
+
|
| 48 |
+
All function, type and macro definitions needed to use the Python/C API are
|
| 49 |
+
included in your code by the following line::
|
| 50 |
+
|
| 51 |
+
#define PY_SSIZE_T_CLEAN
|
| 52 |
+
#include <Python.h>
|
| 53 |
+
|
| 54 |
+
This implies inclusion of the following standard headers: ``<stdio.h>``,
|
| 55 |
+
``<string.h>``, ``<errno.h>``, ``<limits.h>``, ``<assert.h>`` and ``<stdlib.h>``
|
| 56 |
+
(if available).
|
| 57 |
+
|
| 58 |
+
.. note::
|
| 59 |
+
|
| 60 |
+
Since Python may define some pre-processor definitions which affect the standard
|
| 61 |
+
headers on some systems, you *must* include :file:`Python.h` before any standard
|
| 62 |
+
headers are included.
|
| 63 |
+
|
| 64 |
+
It is recommended to always define ``PY_SSIZE_T_CLEAN`` before including
|
| 65 |
+
``Python.h``. See :ref:`arg-parsing` for a description of this macro.
|
| 66 |
+
|
| 67 |
+
All user visible names defined by Python.h (except those defined by the included
|
| 68 |
+
standard headers) have one of the prefixes ``Py`` or ``_Py``. Names beginning
|
| 69 |
+
with ``_Py`` are for internal use by the Python implementation and should not be
|
| 70 |
+
used by extension writers. Structure member names do not have a reserved prefix.
|
| 71 |
+
|
| 72 |
+
.. note::
|
| 73 |
+
|
| 74 |
+
User code should never define names that begin with ``Py`` or ``_Py``. This
|
| 75 |
+
confuses the reader, and jeopardizes the portability of the user code to
|
| 76 |
+
future Python versions, which may define additional names beginning with one
|
| 77 |
+
of these prefixes.
|
| 78 |
+
|
| 79 |
+
The header files are typically installed with Python. On Unix, these are
|
| 80 |
+
located in the directories :file:`{prefix}/include/pythonversion/` and
|
| 81 |
+
:file:`{exec_prefix}/include/pythonversion/`, where :envvar:`prefix` and
|
| 82 |
+
:envvar:`exec_prefix` are defined by the corresponding parameters to Python's
|
| 83 |
+
:program:`configure` script and *version* is
|
| 84 |
+
``'%d.%d' % sys.version_info[:2]``. On Windows, the headers are installed
|
| 85 |
+
in :file:`{prefix}/include`, where :envvar:`prefix` is the installation
|
| 86 |
+
directory specified to the installer.
|
| 87 |
+
|
| 88 |
+
To include the headers, place both directories (if different) on your compiler's
|
| 89 |
+
search path for includes. Do *not* place the parent directories on the search
|
| 90 |
+
path and then use ``#include <pythonX.Y/Python.h>``; this will break on
|
| 91 |
+
multi-platform builds since the platform independent headers under
|
| 92 |
+
:envvar:`prefix` include the platform specific headers from
|
| 93 |
+
:envvar:`exec_prefix`.
|
| 94 |
+
|
| 95 |
+
C++ users should note that although the API is defined entirely using C, the
|
| 96 |
+
header files properly declare the entry points to be ``extern "C"``. As a result,
|
| 97 |
+
there is no need to do anything special to use the API from C++.
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
Useful macros
|
| 101 |
+
=============
|
| 102 |
+
|
| 103 |
+
Several useful macros are defined in the Python header files. Many are
|
| 104 |
+
defined closer to where they are useful (e.g. :c:macro:`Py_RETURN_NONE`).
|
| 105 |
+
Others of a more general utility are defined here. This is not necessarily a
|
| 106 |
+
complete listing.
|
| 107 |
+
|
| 108 |
+
.. c:macro:: Py_UNREACHABLE()
|
| 109 |
+
|
| 110 |
+
Use this when you have a code path that cannot be reached by design.
|
| 111 |
+
For example, in the ``default:`` clause in a ``switch`` statement for which
|
| 112 |
+
all possible values are covered in ``case`` statements. Use this in places
|
| 113 |
+
where you might be tempted to put an ``assert(0)`` or ``abort()`` call.
|
| 114 |
+
|
| 115 |
+
In release mode, the macro helps the compiler to optimize the code, and
|
| 116 |
+
avoids a warning about unreachable code. For example, the macro is
|
| 117 |
+
implemented with ``__builtin_unreachable()`` on GCC in release mode.
|
| 118 |
+
|
| 119 |
+
A use for ``Py_UNREACHABLE()`` is following a call a function that
|
| 120 |
+
never returns but that is not declared :c:macro:`_Py_NO_RETURN`.
|
| 121 |
+
|
| 122 |
+
If a code path is very unlikely code but can be reached under exceptional
|
| 123 |
+
case, this macro must not be used. For example, under low memory condition
|
| 124 |
+
or if a system call returns a value out of the expected range. In this
|
| 125 |
+
case, it's better to report the error to the caller. If the error cannot
|
| 126 |
+
be reported to caller, :c:func:`Py_FatalError` can be used.
|
| 127 |
+
|
| 128 |
+
.. versionadded:: 3.7
|
| 129 |
+
|
| 130 |
+
.. c:macro:: Py_ABS(x)
|
| 131 |
+
|
| 132 |
+
Return the absolute value of ``x``.
|
| 133 |
+
|
| 134 |
+
.. versionadded:: 3.3
|
| 135 |
+
|
| 136 |
+
.. c:macro:: Py_MIN(x, y)
|
| 137 |
+
|
| 138 |
+
Return the minimum value between ``x`` and ``y``.
|
| 139 |
+
|
| 140 |
+
.. versionadded:: 3.3
|
| 141 |
+
|
| 142 |
+
.. c:macro:: Py_MAX(x, y)
|
| 143 |
+
|
| 144 |
+
Return the maximum value between ``x`` and ``y``.
|
| 145 |
+
|
| 146 |
+
.. versionadded:: 3.3
|
| 147 |
+
|
| 148 |
+
.. c:macro:: Py_STRINGIFY(x)
|
| 149 |
+
|
| 150 |
+
Convert ``x`` to a C string. E.g. ``Py_STRINGIFY(123)`` returns
|
| 151 |
+
``"123"``.
|
| 152 |
+
|
| 153 |
+
.. versionadded:: 3.4
|
| 154 |
+
|
| 155 |
+
.. c:macro:: Py_MEMBER_SIZE(type, member)
|
| 156 |
+
|
| 157 |
+
Return the size of a structure (``type``) ``member`` in bytes.
|
| 158 |
+
|
| 159 |
+
.. versionadded:: 3.6
|
| 160 |
+
|
| 161 |
+
.. c:macro:: Py_CHARMASK(c)
|
| 162 |
+
|
| 163 |
+
Argument must be a character or an integer in the range [-128, 127] or [0,
|
| 164 |
+
255]. This macro returns ``c`` cast to an ``unsigned char``.
|
| 165 |
+
|
| 166 |
+
.. c:macro:: Py_GETENV(s)
|
| 167 |
+
|
| 168 |
+
Like ``getenv(s)``, but returns ``NULL`` if :option:`-E` was passed on the
|
| 169 |
+
command line (i.e. if ``Py_IgnoreEnvironmentFlag`` is set).
|
| 170 |
+
|
| 171 |
+
.. c:macro:: Py_UNUSED(arg)
|
| 172 |
+
|
| 173 |
+
Use this for unused arguments in a function definition to silence compiler
|
| 174 |
+
warnings. Example: ``int func(int a, int Py_UNUSED(b)) { return a; }``.
|
| 175 |
+
|
| 176 |
+
.. versionadded:: 3.4
|
| 177 |
+
|
| 178 |
+
.. c:macro:: Py_DEPRECATED(version)
|
| 179 |
+
|
| 180 |
+
Use this for deprecated declarations. The macro must be placed before the
|
| 181 |
+
symbol name.
|
| 182 |
+
|
| 183 |
+
Example::
|
| 184 |
+
|
| 185 |
+
Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);
|
| 186 |
+
|
| 187 |
+
.. versionchanged:: 3.8
|
| 188 |
+
MSVC support was added.
|
| 189 |
+
|
| 190 |
+
.. c:macro:: PyDoc_STRVAR(name, str)
|
| 191 |
+
|
| 192 |
+
Creates a variable with name ``name`` that can be used in docstrings.
|
| 193 |
+
If Python is built without docstrings, the value will be empty.
|
| 194 |
+
|
| 195 |
+
Use :c:macro:`PyDoc_STRVAR` for docstrings to support building
|
| 196 |
+
Python without docstrings, as specified in :pep:`7`.
|
| 197 |
+
|
| 198 |
+
Example::
|
| 199 |
+
|
| 200 |
+
PyDoc_STRVAR(pop_doc, "Remove and return the rightmost element.");
|
| 201 |
+
|
| 202 |
+
static PyMethodDef deque_methods[] = {
|
| 203 |
+
// ...
|
| 204 |
+
{"pop", (PyCFunction)deque_pop, METH_NOARGS, pop_doc},
|
| 205 |
+
// ...
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
.. c:macro:: PyDoc_STR(str)
|
| 209 |
+
|
| 210 |
+
Creates a docstring for the given input string or an empty string
|
| 211 |
+
if docstrings are disabled.
|
| 212 |
+
|
| 213 |
+
Use :c:macro:`PyDoc_STR` in specifying docstrings to support
|
| 214 |
+
building Python without docstrings, as specified in :pep:`7`.
|
| 215 |
+
|
| 216 |
+
Example::
|
| 217 |
+
|
| 218 |
+
static PyMethodDef pysqlite_row_methods[] = {
|
| 219 |
+
{"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS,
|
| 220 |
+
PyDoc_STR("Returns the keys of the row.")},
|
| 221 |
+
{NULL, NULL}
|
| 222 |
+
};
|
| 223 |
+
|
| 224 |
+
.. _api-objects:
|
| 225 |
+
|
| 226 |
+
Objects, Types and Reference Counts
|
| 227 |
+
===================================
|
| 228 |
+
|
| 229 |
+
.. index:: object: type
|
| 230 |
+
|
| 231 |
+
Most Python/C API functions have one or more arguments as well as a return value
|
| 232 |
+
of type :c:type:`PyObject\*`. This type is a pointer to an opaque data type
|
| 233 |
+
representing an arbitrary Python object. Since all Python object types are
|
| 234 |
+
treated the same way by the Python language in most situations (e.g.,
|
| 235 |
+
assignments, scope rules, and argument passing), it is only fitting that they
|
| 236 |
+
should be represented by a single C type. Almost all Python objects live on the
|
| 237 |
+
heap: you never declare an automatic or static variable of type
|
| 238 |
+
:c:type:`PyObject`, only pointer variables of type :c:type:`PyObject\*` can be
|
| 239 |
+
declared. The sole exception are the type objects; since these must never be
|
| 240 |
+
deallocated, they are typically static :c:type:`PyTypeObject` objects.
|
| 241 |
+
|
| 242 |
+
All Python objects (even Python integers) have a :dfn:`type` and a
|
| 243 |
+
:dfn:`reference count`. An object's type determines what kind of object it is
|
| 244 |
+
(e.g., an integer, a list, or a user-defined function; there are many more as
|
| 245 |
+
explained in :ref:`types`). For each of the well-known types there is a macro
|
| 246 |
+
to check whether an object is of that type; for instance, ``PyList_Check(a)`` is
|
| 247 |
+
true if (and only if) the object pointed to by *a* is a Python list.
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
.. _api-refcounts:
|
| 251 |
+
|
| 252 |
+
Reference Counts
|
| 253 |
+
----------------
|
| 254 |
+
|
| 255 |
+
The reference count is important because today's computers have a finite (and
|
| 256 |
+
often severely limited) memory size; it counts how many different places there
|
| 257 |
+
are that have a reference to an object. Such a place could be another object,
|
| 258 |
+
or a global (or static) C variable, or a local variable in some C function.
|
| 259 |
+
When an object's reference count becomes zero, the object is deallocated. If
|
| 260 |
+
it contains references to other objects, their reference count is decremented.
|
| 261 |
+
Those other objects may be deallocated in turn, if this decrement makes their
|
| 262 |
+
reference count become zero, and so on. (There's an obvious problem with
|
| 263 |
+
objects that reference each other here; for now, the solution is "don't do
|
| 264 |
+
that.")
|
| 265 |
+
|
| 266 |
+
.. index::
|
| 267 |
+
single: Py_INCREF()
|
| 268 |
+
single: Py_DECREF()
|
| 269 |
+
|
| 270 |
+
Reference counts are always manipulated explicitly. The normal way is to use
|
| 271 |
+
the macro :c:func:`Py_INCREF` to increment an object's reference count by one,
|
| 272 |
+
and :c:func:`Py_DECREF` to decrement it by one. The :c:func:`Py_DECREF` macro
|
| 273 |
+
is considerably more complex than the incref one, since it must check whether
|
| 274 |
+
the reference count becomes zero and then cause the object's deallocator to be
|
| 275 |
+
called. The deallocator is a function pointer contained in the object's type
|
| 276 |
+
structure. The type-specific deallocator takes care of decrementing the
|
| 277 |
+
reference counts for other objects contained in the object if this is a compound
|
| 278 |
+
object type, such as a list, as well as performing any additional finalization
|
| 279 |
+
that's needed. There's no chance that the reference count can overflow; at
|
| 280 |
+
least as many bits are used to hold the reference count as there are distinct
|
| 281 |
+
memory locations in virtual memory (assuming ``sizeof(Py_ssize_t) >= sizeof(void*)``).
|
| 282 |
+
Thus, the reference count increment is a simple operation.
|
| 283 |
+
|
| 284 |
+
It is not necessary to increment an object's reference count for every local
|
| 285 |
+
variable that contains a pointer to an object. In theory, the object's
|
| 286 |
+
reference count goes up by one when the variable is made to point to it and it
|
| 287 |
+
goes down by one when the variable goes out of scope. However, these two
|
| 288 |
+
cancel each other out, so at the end the reference count hasn't changed. The
|
| 289 |
+
only real reason to use the reference count is to prevent the object from being
|
| 290 |
+
deallocated as long as our variable is pointing to it. If we know that there
|
| 291 |
+
is at least one other reference to the object that lives at least as long as
|
| 292 |
+
our variable, there is no need to increment the reference count temporarily.
|
| 293 |
+
An important situation where this arises is in objects that are passed as
|
| 294 |
+
arguments to C functions in an extension module that are called from Python;
|
| 295 |
+
the call mechanism guarantees to hold a reference to every argument for the
|
| 296 |
+
duration of the call.
|
| 297 |
+
|
| 298 |
+
However, a common pitfall is to extract an object from a list and hold on to it
|
| 299 |
+
for a while without incrementing its reference count. Some other operation might
|
| 300 |
+
conceivably remove the object from the list, decrementing its reference count
|
| 301 |
+
and possibly deallocating it. The real danger is that innocent-looking
|
| 302 |
+
operations may invoke arbitrary Python code which could do this; there is a code
|
| 303 |
+
path which allows control to flow back to the user from a :c:func:`Py_DECREF`, so
|
| 304 |
+
almost any operation is potentially dangerous.
|
| 305 |
+
|
| 306 |
+
A safe approach is to always use the generic operations (functions whose name
|
| 307 |
+
begins with ``PyObject_``, ``PyNumber_``, ``PySequence_`` or ``PyMapping_``).
|
| 308 |
+
These operations always increment the reference count of the object they return.
|
| 309 |
+
This leaves the caller with the responsibility to call :c:func:`Py_DECREF` when
|
| 310 |
+
they are done with the result; this soon becomes second nature.
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
.. _api-refcountdetails:
|
| 314 |
+
|
| 315 |
+
Reference Count Details
|
| 316 |
+
^^^^^^^^^^^^^^^^^^^^^^^
|
| 317 |
+
|
| 318 |
+
The reference count behavior of functions in the Python/C API is best explained
|
| 319 |
+
in terms of *ownership of references*. Ownership pertains to references, never
|
| 320 |
+
to objects (objects are not owned: they are always shared). "Owning a
|
| 321 |
+
reference" means being responsible for calling Py_DECREF on it when the
|
| 322 |
+
reference is no longer needed. Ownership can also be transferred, meaning that
|
| 323 |
+
the code that receives ownership of the reference then becomes responsible for
|
| 324 |
+
eventually decref'ing it by calling :c:func:`Py_DECREF` or :c:func:`Py_XDECREF`
|
| 325 |
+
when it's no longer needed---or passing on this responsibility (usually to its
|
| 326 |
+
caller). When a function passes ownership of a reference on to its caller, the
|
| 327 |
+
caller is said to receive a *new* reference. When no ownership is transferred,
|
| 328 |
+
the caller is said to *borrow* the reference. Nothing needs to be done for a
|
| 329 |
+
borrowed reference.
|
| 330 |
+
|
| 331 |
+
Conversely, when a calling function passes in a reference to an object, there
|
| 332 |
+
are two possibilities: the function *steals* a reference to the object, or it
|
| 333 |
+
does not. *Stealing a reference* means that when you pass a reference to a
|
| 334 |
+
function, that function assumes that it now owns that reference, and you are not
|
| 335 |
+
responsible for it any longer.
|
| 336 |
+
|
| 337 |
+
.. index::
|
| 338 |
+
single: PyList_SetItem()
|
| 339 |
+
single: PyTuple_SetItem()
|
| 340 |
+
|
| 341 |
+
Few functions steal references; the two notable exceptions are
|
| 342 |
+
:c:func:`PyList_SetItem` and :c:func:`PyTuple_SetItem`, which steal a reference
|
| 343 |
+
to the item (but not to the tuple or list into which the item is put!). These
|
| 344 |
+
functions were designed to steal a reference because of a common idiom for
|
| 345 |
+
populating a tuple or list with newly created objects; for example, the code to
|
| 346 |
+
create the tuple ``(1, 2, "three")`` could look like this (forgetting about
|
| 347 |
+
error handling for the moment; a better way to code this is shown below)::
|
| 348 |
+
|
| 349 |
+
PyObject *t;
|
| 350 |
+
|
| 351 |
+
t = PyTuple_New(3);
|
| 352 |
+
PyTuple_SetItem(t, 0, PyLong_FromLong(1L));
|
| 353 |
+
PyTuple_SetItem(t, 1, PyLong_FromLong(2L));
|
| 354 |
+
PyTuple_SetItem(t, 2, PyUnicode_FromString("three"));
|
| 355 |
+
|
| 356 |
+
Here, :c:func:`PyLong_FromLong` returns a new reference which is immediately
|
| 357 |
+
stolen by :c:func:`PyTuple_SetItem`. When you want to keep using an object
|
| 358 |
+
although the reference to it will be stolen, use :c:func:`Py_INCREF` to grab
|
| 359 |
+
another reference before calling the reference-stealing function.
|
| 360 |
+
|
| 361 |
+
Incidentally, :c:func:`PyTuple_SetItem` is the *only* way to set tuple items;
|
| 362 |
+
:c:func:`PySequence_SetItem` and :c:func:`PyObject_SetItem` refuse to do this
|
| 363 |
+
since tuples are an immutable data type. You should only use
|
| 364 |
+
:c:func:`PyTuple_SetItem` for tuples that you are creating yourself.
|
| 365 |
+
|
| 366 |
+
Equivalent code for populating a list can be written using :c:func:`PyList_New`
|
| 367 |
+
and :c:func:`PyList_SetItem`.
|
| 368 |
+
|
| 369 |
+
However, in practice, you will rarely use these ways of creating and populating
|
| 370 |
+
a tuple or list. There's a generic function, :c:func:`Py_BuildValue`, that can
|
| 371 |
+
create most common objects from C values, directed by a :dfn:`format string`.
|
| 372 |
+
For example, the above two blocks of code could be replaced by the following
|
| 373 |
+
(which also takes care of the error checking)::
|
| 374 |
+
|
| 375 |
+
PyObject *tuple, *list;
|
| 376 |
+
|
| 377 |
+
tuple = Py_BuildValue("(iis)", 1, 2, "three");
|
| 378 |
+
list = Py_BuildValue("[iis]", 1, 2, "three");
|
| 379 |
+
|
| 380 |
+
It is much more common to use :c:func:`PyObject_SetItem` and friends with items
|
| 381 |
+
whose references you are only borrowing, like arguments that were passed in to
|
| 382 |
+
the function you are writing. In that case, their behaviour regarding reference
|
| 383 |
+
counts is much saner, since you don't have to increment a reference count so you
|
| 384 |
+
can give a reference away ("have it be stolen"). For example, this function
|
| 385 |
+
sets all items of a list (actually, any mutable sequence) to a given item::
|
| 386 |
+
|
| 387 |
+
int
|
| 388 |
+
set_all(PyObject *target, PyObject *item)
|
| 389 |
+
{
|
| 390 |
+
Py_ssize_t i, n;
|
| 391 |
+
|
| 392 |
+
n = PyObject_Length(target);
|
| 393 |
+
if (n < 0)
|
| 394 |
+
return -1;
|
| 395 |
+
for (i = 0; i < n; i++) {
|
| 396 |
+
PyObject *index = PyLong_FromSsize_t(i);
|
| 397 |
+
if (!index)
|
| 398 |
+
return -1;
|
| 399 |
+
if (PyObject_SetItem(target, index, item) < 0) {
|
| 400 |
+
Py_DECREF(index);
|
| 401 |
+
return -1;
|
| 402 |
+
}
|
| 403 |
+
Py_DECREF(index);
|
| 404 |
+
}
|
| 405 |
+
return 0;
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
.. index:: single: set_all()
|
| 409 |
+
|
| 410 |
+
The situation is slightly different for function return values. While passing
|
| 411 |
+
a reference to most functions does not change your ownership responsibilities
|
| 412 |
+
for that reference, many functions that return a reference to an object give
|
| 413 |
+
you ownership of the reference. The reason is simple: in many cases, the
|
| 414 |
+
returned object is created on the fly, and the reference you get is the only
|
| 415 |
+
reference to the object. Therefore, the generic functions that return object
|
| 416 |
+
references, like :c:func:`PyObject_GetItem` and :c:func:`PySequence_GetItem`,
|
| 417 |
+
always return a new reference (the caller becomes the owner of the reference).
|
| 418 |
+
|
| 419 |
+
It is important to realize that whether you own a reference returned by a
|
| 420 |
+
function depends on which function you call only --- *the plumage* (the type of
|
| 421 |
+
the object passed as an argument to the function) *doesn't enter into it!*
|
| 422 |
+
Thus, if you extract an item from a list using :c:func:`PyList_GetItem`, you
|
| 423 |
+
don't own the reference --- but if you obtain the same item from the same list
|
| 424 |
+
using :c:func:`PySequence_GetItem` (which happens to take exactly the same
|
| 425 |
+
arguments), you do own a reference to the returned object.
|
| 426 |
+
|
| 427 |
+
.. index::
|
| 428 |
+
single: PyList_GetItem()
|
| 429 |
+
single: PySequence_GetItem()
|
| 430 |
+
|
| 431 |
+
Here is an example of how you could write a function that computes the sum of
|
| 432 |
+
the items in a list of integers; once using :c:func:`PyList_GetItem`, and once
|
| 433 |
+
using :c:func:`PySequence_GetItem`. ::
|
| 434 |
+
|
| 435 |
+
long
|
| 436 |
+
sum_list(PyObject *list)
|
| 437 |
+
{
|
| 438 |
+
Py_ssize_t i, n;
|
| 439 |
+
long total = 0, value;
|
| 440 |
+
PyObject *item;
|
| 441 |
+
|
| 442 |
+
n = PyList_Size(list);
|
| 443 |
+
if (n < 0)
|
| 444 |
+
return -1; /* Not a list */
|
| 445 |
+
for (i = 0; i < n; i++) {
|
| 446 |
+
item = PyList_GetItem(list, i); /* Can't fail */
|
| 447 |
+
if (!PyLong_Check(item)) continue; /* Skip non-integers */
|
| 448 |
+
value = PyLong_AsLong(item);
|
| 449 |
+
if (value == -1 && PyErr_Occurred())
|
| 450 |
+
/* Integer too big to fit in a C long, bail out */
|
| 451 |
+
return -1;
|
| 452 |
+
total += value;
|
| 453 |
+
}
|
| 454 |
+
return total;
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
.. index:: single: sum_list()
|
| 458 |
+
|
| 459 |
+
::
|
| 460 |
+
|
| 461 |
+
long
|
| 462 |
+
sum_sequence(PyObject *sequence)
|
| 463 |
+
{
|
| 464 |
+
Py_ssize_t i, n;
|
| 465 |
+
long total = 0, value;
|
| 466 |
+
PyObject *item;
|
| 467 |
+
n = PySequence_Length(sequence);
|
| 468 |
+
if (n < 0)
|
| 469 |
+
return -1; /* Has no length */
|
| 470 |
+
for (i = 0; i < n; i++) {
|
| 471 |
+
item = PySequence_GetItem(sequence, i);
|
| 472 |
+
if (item == NULL)
|
| 473 |
+
return -1; /* Not a sequence, or other failure */
|
| 474 |
+
if (PyLong_Check(item)) {
|
| 475 |
+
value = PyLong_AsLong(item);
|
| 476 |
+
Py_DECREF(item);
|
| 477 |
+
if (value == -1 && PyErr_Occurred())
|
| 478 |
+
/* Integer too big to fit in a C long, bail out */
|
| 479 |
+
return -1;
|
| 480 |
+
total += value;
|
| 481 |
+
}
|
| 482 |
+
else {
|
| 483 |
+
Py_DECREF(item); /* Discard reference ownership */
|
| 484 |
+
}
|
| 485 |
+
}
|
| 486 |
+
return total;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
.. index:: single: sum_sequence()
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
.. _api-types:
|
| 493 |
+
|
| 494 |
+
Types
|
| 495 |
+
-----
|
| 496 |
+
|
| 497 |
+
There are few other data types that play a significant role in the Python/C
|
| 498 |
+
API; most are simple C types such as :c:type:`int`, :c:type:`long`,
|
| 499 |
+
:c:type:`double` and :c:type:`char\*`. A few structure types are used to
|
| 500 |
+
describe static tables used to list the functions exported by a module or the
|
| 501 |
+
data attributes of a new object type, and another is used to describe the value
|
| 502 |
+
of a complex number. These will be discussed together with the functions that
|
| 503 |
+
use them.
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
.. _api-exceptions:
|
| 507 |
+
|
| 508 |
+
Exceptions
|
| 509 |
+
==========
|
| 510 |
+
|
| 511 |
+
The Python programmer only needs to deal with exceptions if specific error
|
| 512 |
+
handling is required; unhandled exceptions are automatically propagated to the
|
| 513 |
+
caller, then to the caller's caller, and so on, until they reach the top-level
|
| 514 |
+
interpreter, where they are reported to the user accompanied by a stack
|
| 515 |
+
traceback.
|
| 516 |
+
|
| 517 |
+
.. index:: single: PyErr_Occurred()
|
| 518 |
+
|
| 519 |
+
For C programmers, however, error checking always has to be explicit. All
|
| 520 |
+
functions in the Python/C API can raise exceptions, unless an explicit claim is
|
| 521 |
+
made otherwise in a function's documentation. In general, when a function
|
| 522 |
+
encounters an error, it sets an exception, discards any object references that
|
| 523 |
+
it owns, and returns an error indicator. If not documented otherwise, this
|
| 524 |
+
indicator is either ``NULL`` or ``-1``, depending on the function's return type.
|
| 525 |
+
A few functions return a Boolean true/false result, with false indicating an
|
| 526 |
+
error. Very few functions return no explicit error indicator or have an
|
| 527 |
+
ambiguous return value, and require explicit testing for errors with
|
| 528 |
+
:c:func:`PyErr_Occurred`. These exceptions are always explicitly documented.
|
| 529 |
+
|
| 530 |
+
.. index::
|
| 531 |
+
single: PyErr_SetString()
|
| 532 |
+
single: PyErr_Clear()
|
| 533 |
+
|
| 534 |
+
Exception state is maintained in per-thread storage (this is equivalent to
|
| 535 |
+
using global storage in an unthreaded application). A thread can be in one of
|
| 536 |
+
two states: an exception has occurred, or not. The function
|
| 537 |
+
:c:func:`PyErr_Occurred` can be used to check for this: it returns a borrowed
|
| 538 |
+
reference to the exception type object when an exception has occurred, and
|
| 539 |
+
``NULL`` otherwise. There are a number of functions to set the exception state:
|
| 540 |
+
:c:func:`PyErr_SetString` is the most common (though not the most general)
|
| 541 |
+
function to set the exception state, and :c:func:`PyErr_Clear` clears the
|
| 542 |
+
exception state.
|
| 543 |
+
|
| 544 |
+
The full exception state consists of three objects (all of which can be
|
| 545 |
+
``NULL``): the exception type, the corresponding exception value, and the
|
| 546 |
+
traceback. These have the same meanings as the Python result of
|
| 547 |
+
``sys.exc_info()``; however, they are not the same: the Python objects represent
|
| 548 |
+
the last exception being handled by a Python :keyword:`try` ...
|
| 549 |
+
:keyword:`except` statement, while the C level exception state only exists while
|
| 550 |
+
an exception is being passed on between C functions until it reaches the Python
|
| 551 |
+
bytecode interpreter's main loop, which takes care of transferring it to
|
| 552 |
+
``sys.exc_info()`` and friends.
|
| 553 |
+
|
| 554 |
+
.. index:: single: exc_info() (in module sys)
|
| 555 |
+
|
| 556 |
+
Note that starting with Python 1.5, the preferred, thread-safe way to access the
|
| 557 |
+
exception state from Python code is to call the function :func:`sys.exc_info`,
|
| 558 |
+
which returns the per-thread exception state for Python code. Also, the
|
| 559 |
+
semantics of both ways to access the exception state have changed so that a
|
| 560 |
+
function which catches an exception will save and restore its thread's exception
|
| 561 |
+
state so as to preserve the exception state of its caller. This prevents common
|
| 562 |
+
bugs in exception handling code caused by an innocent-looking function
|
| 563 |
+
overwriting the exception being handled; it also reduces the often unwanted
|
| 564 |
+
lifetime extension for objects that are referenced by the stack frames in the
|
| 565 |
+
traceback.
|
| 566 |
+
|
| 567 |
+
As a general principle, a function that calls another function to perform some
|
| 568 |
+
task should check whether the called function raised an exception, and if so,
|
| 569 |
+
pass the exception state on to its caller. It should discard any object
|
| 570 |
+
references that it owns, and return an error indicator, but it should *not* set
|
| 571 |
+
another exception --- that would overwrite the exception that was just raised,
|
| 572 |
+
and lose important information about the exact cause of the error.
|
| 573 |
+
|
| 574 |
+
.. index:: single: sum_sequence()
|
| 575 |
+
|
| 576 |
+
A simple example of detecting exceptions and passing them on is shown in the
|
| 577 |
+
:c:func:`sum_sequence` example above. It so happens that this example doesn't
|
| 578 |
+
need to clean up any owned references when it detects an error. The following
|
| 579 |
+
example function shows some error cleanup. First, to remind you why you like
|
| 580 |
+
Python, we show the equivalent Python code::
|
| 581 |
+
|
| 582 |
+
def incr_item(dict, key):
|
| 583 |
+
try:
|
| 584 |
+
item = dict[key]
|
| 585 |
+
except KeyError:
|
| 586 |
+
item = 0
|
| 587 |
+
dict[key] = item + 1
|
| 588 |
+
|
| 589 |
+
.. index:: single: incr_item()
|
| 590 |
+
|
| 591 |
+
Here is the corresponding C code, in all its glory::
|
| 592 |
+
|
| 593 |
+
int
|
| 594 |
+
incr_item(PyObject *dict, PyObject *key)
|
| 595 |
+
{
|
| 596 |
+
/* Objects all initialized to NULL for Py_XDECREF */
|
| 597 |
+
PyObject *item = NULL, *const_one = NULL, *incremented_item = NULL;
|
| 598 |
+
int rv = -1; /* Return value initialized to -1 (failure) */
|
| 599 |
+
|
| 600 |
+
item = PyObject_GetItem(dict, key);
|
| 601 |
+
if (item == NULL) {
|
| 602 |
+
/* Handle KeyError only: */
|
| 603 |
+
if (!PyErr_ExceptionMatches(PyExc_KeyError))
|
| 604 |
+
goto error;
|
| 605 |
+
|
| 606 |
+
/* Clear the error and use zero: */
|
| 607 |
+
PyErr_Clear();
|
| 608 |
+
item = PyLong_FromLong(0L);
|
| 609 |
+
if (item == NULL)
|
| 610 |
+
goto error;
|
| 611 |
+
}
|
| 612 |
+
const_one = PyLong_FromLong(1L);
|
| 613 |
+
if (const_one == NULL)
|
| 614 |
+
goto error;
|
| 615 |
+
|
| 616 |
+
incremented_item = PyNumber_Add(item, const_one);
|
| 617 |
+
if (incremented_item == NULL)
|
| 618 |
+
goto error;
|
| 619 |
+
|
| 620 |
+
if (PyObject_SetItem(dict, key, incremented_item) < 0)
|
| 621 |
+
goto error;
|
| 622 |
+
rv = 0; /* Success */
|
| 623 |
+
/* Continue with cleanup code */
|
| 624 |
+
|
| 625 |
+
error:
|
| 626 |
+
/* Cleanup code, shared by success and failure path */
|
| 627 |
+
|
| 628 |
+
/* Use Py_XDECREF() to ignore NULL references */
|
| 629 |
+
Py_XDECREF(item);
|
| 630 |
+
Py_XDECREF(const_one);
|
| 631 |
+
Py_XDECREF(incremented_item);
|
| 632 |
+
|
| 633 |
+
return rv; /* -1 for error, 0 for success */
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
.. index:: single: incr_item()
|
| 637 |
+
|
| 638 |
+
.. index::
|
| 639 |
+
single: PyErr_ExceptionMatches()
|
| 640 |
+
single: PyErr_Clear()
|
| 641 |
+
single: Py_XDECREF()
|
| 642 |
+
|
| 643 |
+
This example represents an endorsed use of the ``goto`` statement in C!
|
| 644 |
+
It illustrates the use of :c:func:`PyErr_ExceptionMatches` and
|
| 645 |
+
:c:func:`PyErr_Clear` to handle specific exceptions, and the use of
|
| 646 |
+
:c:func:`Py_XDECREF` to dispose of owned references that may be ``NULL`` (note the
|
| 647 |
+
``'X'`` in the name; :c:func:`Py_DECREF` would crash when confronted with a
|
| 648 |
+
``NULL`` reference). It is important that the variables used to hold owned
|
| 649 |
+
references are initialized to ``NULL`` for this to work; likewise, the proposed
|
| 650 |
+
return value is initialized to ``-1`` (failure) and only set to success after
|
| 651 |
+
the final call made is successful.
|
| 652 |
+
|
| 653 |
+
|
| 654 |
+
.. _api-embedding:
|
| 655 |
+
|
| 656 |
+
Embedding Python
|
| 657 |
+
================
|
| 658 |
+
|
| 659 |
+
The one important task that only embedders (as opposed to extension writers) of
|
| 660 |
+
the Python interpreter have to worry about is the initialization, and possibly
|
| 661 |
+
the finalization, of the Python interpreter. Most functionality of the
|
| 662 |
+
interpreter can only be used after the interpreter has been initialized.
|
| 663 |
+
|
| 664 |
+
.. index::
|
| 665 |
+
single: Py_Initialize()
|
| 666 |
+
module: builtins
|
| 667 |
+
module: __main__
|
| 668 |
+
module: sys
|
| 669 |
+
triple: module; search; path
|
| 670 |
+
single: path (in module sys)
|
| 671 |
+
|
| 672 |
+
The basic initialization function is :c:func:`Py_Initialize`. This initializes
|
| 673 |
+
the table of loaded modules, and creates the fundamental modules
|
| 674 |
+
:mod:`builtins`, :mod:`__main__`, and :mod:`sys`. It also
|
| 675 |
+
initializes the module search path (``sys.path``).
|
| 676 |
+
|
| 677 |
+
.. index:: single: PySys_SetArgvEx()
|
| 678 |
+
|
| 679 |
+
:c:func:`Py_Initialize` does not set the "script argument list" (``sys.argv``).
|
| 680 |
+
If this variable is needed by Python code that will be executed later, it must
|
| 681 |
+
be set explicitly with a call to ``PySys_SetArgvEx(argc, argv, updatepath)``
|
| 682 |
+
after the call to :c:func:`Py_Initialize`.
|
| 683 |
+
|
| 684 |
+
On most systems (in particular, on Unix and Windows, although the details are
|
| 685 |
+
slightly different), :c:func:`Py_Initialize` calculates the module search path
|
| 686 |
+
based upon its best guess for the location of the standard Python interpreter
|
| 687 |
+
executable, assuming that the Python library is found in a fixed location
|
| 688 |
+
relative to the Python interpreter executable. In particular, it looks for a
|
| 689 |
+
directory named :file:`lib/python{X.Y}` relative to the parent directory
|
| 690 |
+
where the executable named :file:`python` is found on the shell command search
|
| 691 |
+
path (the environment variable :envvar:`PATH`).
|
| 692 |
+
|
| 693 |
+
For instance, if the Python executable is found in
|
| 694 |
+
:file:`/usr/local/bin/python`, it will assume that the libraries are in
|
| 695 |
+
:file:`/usr/local/lib/python{X.Y}`. (In fact, this particular path is also
|
| 696 |
+
the "fallback" location, used when no executable file named :file:`python` is
|
| 697 |
+
found along :envvar:`PATH`.) The user can override this behavior by setting the
|
| 698 |
+
environment variable :envvar:`PYTHONHOME`, or insert additional directories in
|
| 699 |
+
front of the standard path by setting :envvar:`PYTHONPATH`.
|
| 700 |
+
|
| 701 |
+
.. index::
|
| 702 |
+
single: Py_SetProgramName()
|
| 703 |
+
single: Py_GetPath()
|
| 704 |
+
single: Py_GetPrefix()
|
| 705 |
+
single: Py_GetExecPrefix()
|
| 706 |
+
single: Py_GetProgramFullPath()
|
| 707 |
+
|
| 708 |
+
The embedding application can steer the search by calling
|
| 709 |
+
``Py_SetProgramName(file)`` *before* calling :c:func:`Py_Initialize`. Note that
|
| 710 |
+
:envvar:`PYTHONHOME` still overrides this and :envvar:`PYTHONPATH` is still
|
| 711 |
+
inserted in front of the standard path. An application that requires total
|
| 712 |
+
control has to provide its own implementation of :c:func:`Py_GetPath`,
|
| 713 |
+
:c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, and
|
| 714 |
+
:c:func:`Py_GetProgramFullPath` (all defined in :file:`Modules/getpath.c`).
|
| 715 |
+
|
| 716 |
+
.. index:: single: Py_IsInitialized()
|
| 717 |
+
|
| 718 |
+
Sometimes, it is desirable to "uninitialize" Python. For instance, the
|
| 719 |
+
application may want to start over (make another call to
|
| 720 |
+
:c:func:`Py_Initialize`) or the application is simply done with its use of
|
| 721 |
+
Python and wants to free memory allocated by Python. This can be accomplished
|
| 722 |
+
by calling :c:func:`Py_FinalizeEx`. The function :c:func:`Py_IsInitialized` returns
|
| 723 |
+
true if Python is currently in the initialized state. More information about
|
| 724 |
+
these functions is given in a later chapter. Notice that :c:func:`Py_FinalizeEx`
|
| 725 |
+
does *not* free all memory allocated by the Python interpreter, e.g. memory
|
| 726 |
+
allocated by extension modules currently cannot be released.
|
| 727 |
+
|
| 728 |
+
|
| 729 |
+
.. _api-debugging:
|
| 730 |
+
|
| 731 |
+
Debugging Builds
|
| 732 |
+
================
|
| 733 |
+
|
| 734 |
+
Python can be built with several macros to enable extra checks of the
|
| 735 |
+
interpreter and extension modules. These checks tend to add a large amount of
|
| 736 |
+
overhead to the runtime so they are not enabled by default.
|
| 737 |
+
|
| 738 |
+
A full list of the various types of debugging builds is in the file
|
| 739 |
+
:file:`Misc/SpecialBuilds.txt` in the Python source distribution. Builds are
|
| 740 |
+
available that support tracing of reference counts, debugging the memory
|
| 741 |
+
allocator, or low-level profiling of the main interpreter loop. Only the most
|
| 742 |
+
frequently-used builds will be described in the remainder of this section.
|
| 743 |
+
|
| 744 |
+
Compiling the interpreter with the :c:macro:`Py_DEBUG` macro defined produces
|
| 745 |
+
what is generally meant by "a debug build" of Python. :c:macro:`Py_DEBUG` is
|
| 746 |
+
enabled in the Unix build by adding ``--with-pydebug`` to the
|
| 747 |
+
:file:`./configure` command. It is also implied by the presence of the
|
| 748 |
+
not-Python-specific :c:macro:`_DEBUG` macro. When :c:macro:`Py_DEBUG` is enabled
|
| 749 |
+
in the Unix build, compiler optimization is disabled.
|
| 750 |
+
|
| 751 |
+
In addition to the reference count debugging described below, the following
|
| 752 |
+
extra checks are performed:
|
| 753 |
+
|
| 754 |
+
* Extra checks are added to the object allocator.
|
| 755 |
+
|
| 756 |
+
* Extra checks are added to the parser and compiler.
|
| 757 |
+
|
| 758 |
+
* Downcasts from wide types to narrow types are checked for loss of information.
|
| 759 |
+
|
| 760 |
+
* A number of assertions are added to the dictionary and set implementations.
|
| 761 |
+
In addition, the set object acquires a :meth:`test_c_api` method.
|
| 762 |
+
|
| 763 |
+
* Sanity checks of the input arguments are added to frame creation.
|
| 764 |
+
|
| 765 |
+
* The storage for ints is initialized with a known invalid pattern to catch
|
| 766 |
+
reference to uninitialized digits.
|
| 767 |
+
|
| 768 |
+
* Low-level tracing and extra exception checking are added to the runtime
|
| 769 |
+
virtual machine.
|
| 770 |
+
|
| 771 |
+
* Extra checks are added to the memory arena implementation.
|
| 772 |
+
|
| 773 |
+
* Extra debugging is added to the thread module.
|
| 774 |
+
|
| 775 |
+
There may be additional checks not mentioned here.
|
| 776 |
+
|
| 777 |
+
Defining :c:macro:`Py_TRACE_REFS` enables reference tracing. When defined, a
|
| 778 |
+
circular doubly linked list of active objects is maintained by adding two extra
|
| 779 |
+
fields to every :c:type:`PyObject`. Total allocations are tracked as well. Upon
|
| 780 |
+
exit, all existing references are printed. (In interactive mode this happens
|
| 781 |
+
after every statement run by the interpreter.) Implied by :c:macro:`Py_DEBUG`.
|
| 782 |
+
|
| 783 |
+
Please refer to :file:`Misc/SpecialBuilds.txt` in the Python source distribution
|
| 784 |
+
for more detailed information.
|
| 785 |
+
|
cpython_2/environment/repo/Doc/c-api/iter.rst
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _iterator:
|
| 4 |
+
|
| 5 |
+
Iterator Protocol
|
| 6 |
+
=================
|
| 7 |
+
|
| 8 |
+
There are two functions specifically for working with iterators.
|
| 9 |
+
|
| 10 |
+
.. c:function:: int PyIter_Check(PyObject *o)
|
| 11 |
+
|
| 12 |
+
Return true if the object *o* supports the iterator protocol.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
.. c:function:: PyObject* PyIter_Next(PyObject *o)
|
| 16 |
+
|
| 17 |
+
Return the next value from the iteration *o*. The object must be an iterator
|
| 18 |
+
(it is up to the caller to check this). If there are no remaining values,
|
| 19 |
+
returns ``NULL`` with no exception set. If an error occurs while retrieving
|
| 20 |
+
the item, returns ``NULL`` and passes along the exception.
|
| 21 |
+
|
| 22 |
+
To write a loop which iterates over an iterator, the C code should look
|
| 23 |
+
something like this::
|
| 24 |
+
|
| 25 |
+
PyObject *iterator = PyObject_GetIter(obj);
|
| 26 |
+
PyObject *item;
|
| 27 |
+
|
| 28 |
+
if (iterator == NULL) {
|
| 29 |
+
/* propagate error */
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
while ((item = PyIter_Next(iterator))) {
|
| 33 |
+
/* do something with item */
|
| 34 |
+
...
|
| 35 |
+
/* release reference when done */
|
| 36 |
+
Py_DECREF(item);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
Py_DECREF(iterator);
|
| 40 |
+
|
| 41 |
+
if (PyErr_Occurred()) {
|
| 42 |
+
/* propagate error */
|
| 43 |
+
}
|
| 44 |
+
else {
|
| 45 |
+
/* continue doing useful work */
|
| 46 |
+
}
|
cpython_2/environment/repo/Doc/c-api/iterator.rst
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _iterator-objects:
|
| 4 |
+
|
| 5 |
+
Iterator Objects
|
| 6 |
+
----------------
|
| 7 |
+
|
| 8 |
+
Python provides two general-purpose iterator objects. The first, a sequence
|
| 9 |
+
iterator, works with an arbitrary sequence supporting the :meth:`__getitem__`
|
| 10 |
+
method. The second works with a callable object and a sentinel value, calling
|
| 11 |
+
the callable for each item in the sequence, and ending the iteration when the
|
| 12 |
+
sentinel value is returned.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
.. c:var:: PyTypeObject PySeqIter_Type
|
| 16 |
+
|
| 17 |
+
Type object for iterator objects returned by :c:func:`PySeqIter_New` and the
|
| 18 |
+
one-argument form of the :func:`iter` built-in function for built-in sequence
|
| 19 |
+
types.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
.. c:function:: int PySeqIter_Check(op)
|
| 23 |
+
|
| 24 |
+
Return true if the type of *op* is :c:data:`PySeqIter_Type`.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
.. c:function:: PyObject* PySeqIter_New(PyObject *seq)
|
| 28 |
+
|
| 29 |
+
Return an iterator that works with a general sequence object, *seq*. The
|
| 30 |
+
iteration ends when the sequence raises :exc:`IndexError` for the subscripting
|
| 31 |
+
operation.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
.. c:var:: PyTypeObject PyCallIter_Type
|
| 35 |
+
|
| 36 |
+
Type object for iterator objects returned by :c:func:`PyCallIter_New` and the
|
| 37 |
+
two-argument form of the :func:`iter` built-in function.
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
.. c:function:: int PyCallIter_Check(op)
|
| 41 |
+
|
| 42 |
+
Return true if the type of *op* is :c:data:`PyCallIter_Type`.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
.. c:function:: PyObject* PyCallIter_New(PyObject *callable, PyObject *sentinel)
|
| 46 |
+
|
| 47 |
+
Return a new iterator. The first parameter, *callable*, can be any Python
|
| 48 |
+
callable object that can be called with no parameters; each call to it should
|
| 49 |
+
return the next item in the iteration. When *callable* returns a value equal to
|
| 50 |
+
*sentinel*, the iteration will be terminated.
|
cpython_2/environment/repo/Doc/c-api/list.rst
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _listobjects:
|
| 4 |
+
|
| 5 |
+
List Objects
|
| 6 |
+
------------
|
| 7 |
+
|
| 8 |
+
.. index:: object: list
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
.. c:type:: PyListObject
|
| 12 |
+
|
| 13 |
+
This subtype of :c:type:`PyObject` represents a Python list object.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
.. c:var:: PyTypeObject PyList_Type
|
| 17 |
+
|
| 18 |
+
This instance of :c:type:`PyTypeObject` represents the Python list type.
|
| 19 |
+
This is the same object as :class:`list` in the Python layer.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
.. c:function:: int PyList_Check(PyObject *p)
|
| 23 |
+
|
| 24 |
+
Return true if *p* is a list object or an instance of a subtype of the list
|
| 25 |
+
type.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
.. c:function:: int PyList_CheckExact(PyObject *p)
|
| 29 |
+
|
| 30 |
+
Return true if *p* is a list object, but not an instance of a subtype of
|
| 31 |
+
the list type.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
.. c:function:: PyObject* PyList_New(Py_ssize_t len)
|
| 35 |
+
|
| 36 |
+
Return a new list of length *len* on success, or ``NULL`` on failure.
|
| 37 |
+
|
| 38 |
+
.. note::
|
| 39 |
+
|
| 40 |
+
If *len* is greater than zero, the returned list object's items are
|
| 41 |
+
set to ``NULL``. Thus you cannot use abstract API functions such as
|
| 42 |
+
:c:func:`PySequence_SetItem` or expose the object to Python code before
|
| 43 |
+
setting all items to a real object with :c:func:`PyList_SetItem`.
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
.. c:function:: Py_ssize_t PyList_Size(PyObject *list)
|
| 47 |
+
|
| 48 |
+
.. index:: builtin: len
|
| 49 |
+
|
| 50 |
+
Return the length of the list object in *list*; this is equivalent to
|
| 51 |
+
``len(list)`` on a list object.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
.. c:function:: Py_ssize_t PyList_GET_SIZE(PyObject *list)
|
| 55 |
+
|
| 56 |
+
Macro form of :c:func:`PyList_Size` without error checking.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
.. c:function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
|
| 60 |
+
|
| 61 |
+
Return the object at position *index* in the list pointed to by *list*. The
|
| 62 |
+
position must be non-negative; indexing from the end of the list is not
|
| 63 |
+
supported. If *index* is out of bounds (<0 or >=len(list)),
|
| 64 |
+
return ``NULL`` and set an :exc:`IndexError` exception.
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
.. c:function:: PyObject* PyList_GET_ITEM(PyObject *list, Py_ssize_t i)
|
| 68 |
+
|
| 69 |
+
Macro form of :c:func:`PyList_GetItem` without error checking.
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
.. c:function:: int PyList_SetItem(PyObject *list, Py_ssize_t index, PyObject *item)
|
| 73 |
+
|
| 74 |
+
Set the item at index *index* in list to *item*. Return ``0`` on success.
|
| 75 |
+
If *index* is out of bounds, return ``-1`` and set an :exc:`IndexError`
|
| 76 |
+
exception.
|
| 77 |
+
|
| 78 |
+
.. note::
|
| 79 |
+
|
| 80 |
+
This function "steals" a reference to *item* and discards a reference to
|
| 81 |
+
an item already in the list at the affected position.
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
.. c:function:: void PyList_SET_ITEM(PyObject *list, Py_ssize_t i, PyObject *o)
|
| 85 |
+
|
| 86 |
+
Macro form of :c:func:`PyList_SetItem` without error checking. This is
|
| 87 |
+
normally only used to fill in new lists where there is no previous content.
|
| 88 |
+
|
| 89 |
+
.. note::
|
| 90 |
+
|
| 91 |
+
This macro "steals" a reference to *item*, and, unlike
|
| 92 |
+
:c:func:`PyList_SetItem`, does *not* discard a reference to any item that
|
| 93 |
+
is being replaced; any reference in *list* at position *i* will be
|
| 94 |
+
leaked.
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
.. c:function:: int PyList_Insert(PyObject *list, Py_ssize_t index, PyObject *item)
|
| 98 |
+
|
| 99 |
+
Insert the item *item* into list *list* in front of index *index*. Return
|
| 100 |
+
``0`` if successful; return ``-1`` and set an exception if unsuccessful.
|
| 101 |
+
Analogous to ``list.insert(index, item)``.
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
.. c:function:: int PyList_Append(PyObject *list, PyObject *item)
|
| 105 |
+
|
| 106 |
+
Append the object *item* at the end of list *list*. Return ``0`` if
|
| 107 |
+
successful; return ``-1`` and set an exception if unsuccessful. Analogous
|
| 108 |
+
to ``list.append(item)``.
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
.. c:function:: PyObject* PyList_GetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high)
|
| 112 |
+
|
| 113 |
+
Return a list of the objects in *list* containing the objects *between* *low*
|
| 114 |
+
and *high*. Return ``NULL`` and set an exception if unsuccessful. Analogous
|
| 115 |
+
to ``list[low:high]``. Indexing from the end of the list is not supported.
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
.. c:function:: int PyList_SetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high, PyObject *itemlist)
|
| 119 |
+
|
| 120 |
+
Set the slice of *list* between *low* and *high* to the contents of
|
| 121 |
+
*itemlist*. Analogous to ``list[low:high] = itemlist``. The *itemlist* may
|
| 122 |
+
be ``NULL``, indicating the assignment of an empty list (slice deletion).
|
| 123 |
+
Return ``0`` on success, ``-1`` on failure. Indexing from the end of the
|
| 124 |
+
list is not supported.
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
.. c:function:: int PyList_Sort(PyObject *list)
|
| 128 |
+
|
| 129 |
+
Sort the items of *list* in place. Return ``0`` on success, ``-1`` on
|
| 130 |
+
failure. This is equivalent to ``list.sort()``.
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
.. c:function:: int PyList_Reverse(PyObject *list)
|
| 134 |
+
|
| 135 |
+
Reverse the items of *list* in place. Return ``0`` on success, ``-1`` on
|
| 136 |
+
failure. This is the equivalent of ``list.reverse()``.
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
.. c:function:: PyObject* PyList_AsTuple(PyObject *list)
|
| 140 |
+
|
| 141 |
+
.. index:: builtin: tuple
|
| 142 |
+
|
| 143 |
+
Return a new tuple object containing the contents of *list*; equivalent to
|
| 144 |
+
``tuple(list)``.
|
cpython_2/environment/repo/Doc/c-api/long.rst
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _longobjects:
|
| 4 |
+
|
| 5 |
+
Integer Objects
|
| 6 |
+
---------------
|
| 7 |
+
|
| 8 |
+
.. index:: object: long integer
|
| 9 |
+
object: integer
|
| 10 |
+
|
| 11 |
+
All integers are implemented as "long" integer objects of arbitrary size.
|
| 12 |
+
|
| 13 |
+
On error, most ``PyLong_As*`` APIs return ``(return type)-1`` which cannot be
|
| 14 |
+
distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
|
| 15 |
+
|
| 16 |
+
.. c:type:: PyLongObject
|
| 17 |
+
|
| 18 |
+
This subtype of :c:type:`PyObject` represents a Python integer object.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
.. c:var:: PyTypeObject PyLong_Type
|
| 22 |
+
|
| 23 |
+
This instance of :c:type:`PyTypeObject` represents the Python integer type.
|
| 24 |
+
This is the same object as :class:`int` in the Python layer.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
.. c:function:: int PyLong_Check(PyObject *p)
|
| 28 |
+
|
| 29 |
+
Return true if its argument is a :c:type:`PyLongObject` or a subtype of
|
| 30 |
+
:c:type:`PyLongObject`.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
.. c:function:: int PyLong_CheckExact(PyObject *p)
|
| 34 |
+
|
| 35 |
+
Return true if its argument is a :c:type:`PyLongObject`, but not a subtype of
|
| 36 |
+
:c:type:`PyLongObject`.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
.. c:function:: PyObject* PyLong_FromLong(long v)
|
| 40 |
+
|
| 41 |
+
Return a new :c:type:`PyLongObject` object from *v*, or ``NULL`` on failure.
|
| 42 |
+
|
| 43 |
+
The current implementation keeps an array of integer objects for all integers
|
| 44 |
+
between ``-5`` and ``256``, when you create an int in that range you actually
|
| 45 |
+
just get back a reference to the existing object.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
.. c:function:: PyObject* PyLong_FromUnsignedLong(unsigned long v)
|
| 49 |
+
|
| 50 |
+
Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long`, or
|
| 51 |
+
``NULL`` on failure.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
.. c:function:: PyObject* PyLong_FromSsize_t(Py_ssize_t v)
|
| 55 |
+
|
| 56 |
+
Return a new :c:type:`PyLongObject` object from a C :c:type:`Py_ssize_t`, or
|
| 57 |
+
``NULL`` on failure.
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
.. c:function:: PyObject* PyLong_FromSize_t(size_t v)
|
| 61 |
+
|
| 62 |
+
Return a new :c:type:`PyLongObject` object from a C :c:type:`size_t`, or
|
| 63 |
+
``NULL`` on failure.
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
.. c:function:: PyObject* PyLong_FromLongLong(long long v)
|
| 67 |
+
|
| 68 |
+
Return a new :c:type:`PyLongObject` object from a C :c:type:`long long`, or ``NULL``
|
| 69 |
+
on failure.
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
.. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned long long v)
|
| 73 |
+
|
| 74 |
+
Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long long`,
|
| 75 |
+
or ``NULL`` on failure.
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
.. c:function:: PyObject* PyLong_FromDouble(double v)
|
| 79 |
+
|
| 80 |
+
Return a new :c:type:`PyLongObject` object from the integer part of *v*, or
|
| 81 |
+
``NULL`` on failure.
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
.. c:function:: PyObject* PyLong_FromString(const char *str, char **pend, int base)
|
| 85 |
+
|
| 86 |
+
Return a new :c:type:`PyLongObject` based on the string value in *str*, which
|
| 87 |
+
is interpreted according to the radix in *base*. If *pend* is non-``NULL``,
|
| 88 |
+
*\*pend* will point to the first character in *str* which follows the
|
| 89 |
+
representation of the number. If *base* is ``0``, *str* is interpreted using
|
| 90 |
+
the :ref:`integers` definition; in this case, leading zeros in a
|
| 91 |
+
non-zero decimal number raises a :exc:`ValueError`. If *base* is not ``0``,
|
| 92 |
+
it must be between ``2`` and ``36``, inclusive. Leading spaces and single
|
| 93 |
+
underscores after a base specifier and between digits are ignored. If there
|
| 94 |
+
are no digits, :exc:`ValueError` will be raised.
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
.. c:function:: PyObject* PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
|
| 98 |
+
|
| 99 |
+
Convert a sequence of Unicode digits to a Python integer value. The Unicode
|
| 100 |
+
string is first encoded to a byte string using :c:func:`PyUnicode_EncodeDecimal`
|
| 101 |
+
and then converted using :c:func:`PyLong_FromString`.
|
| 102 |
+
|
| 103 |
+
.. deprecated-removed:: 3.3 4.0
|
| 104 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 105 |
+
:c:func:`PyLong_FromUnicodeObject`.
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
.. c:function:: PyObject* PyLong_FromUnicodeObject(PyObject *u, int base)
|
| 109 |
+
|
| 110 |
+
Convert a sequence of Unicode digits in the string *u* to a Python integer
|
| 111 |
+
value. The Unicode string is first encoded to a byte string using
|
| 112 |
+
:c:func:`PyUnicode_EncodeDecimal` and then converted using
|
| 113 |
+
:c:func:`PyLong_FromString`.
|
| 114 |
+
|
| 115 |
+
.. versionadded:: 3.3
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
.. c:function:: PyObject* PyLong_FromVoidPtr(void *p)
|
| 119 |
+
|
| 120 |
+
Create a Python integer from the pointer *p*. The pointer value can be
|
| 121 |
+
retrieved from the resulting value using :c:func:`PyLong_AsVoidPtr`.
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
.. XXX alias PyLong_AS_LONG (for now)
|
| 125 |
+
.. c:function:: long PyLong_AsLong(PyObject *obj)
|
| 126 |
+
|
| 127 |
+
.. index::
|
| 128 |
+
single: LONG_MAX
|
| 129 |
+
single: OverflowError (built-in exception)
|
| 130 |
+
|
| 131 |
+
Return a C :c:type:`long` representation of *obj*. If *obj* is not an
|
| 132 |
+
instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or
|
| 133 |
+
:meth:`__int__` method (if present) to convert it to a
|
| 134 |
+
:c:type:`PyLongObject`.
|
| 135 |
+
|
| 136 |
+
Raise :exc:`OverflowError` if the value of *obj* is out of range for a
|
| 137 |
+
:c:type:`long`.
|
| 138 |
+
|
| 139 |
+
Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
|
| 140 |
+
|
| 141 |
+
.. versionchanged:: 3.8
|
| 142 |
+
Use :meth:`__index__` if available.
|
| 143 |
+
|
| 144 |
+
.. deprecated:: 3.8
|
| 145 |
+
Using :meth:`__int__` is deprecated.
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
.. c:function:: long PyLong_AsLongAndOverflow(PyObject *obj, int *overflow)
|
| 149 |
+
|
| 150 |
+
Return a C :c:type:`long` representation of *obj*. If *obj* is not an
|
| 151 |
+
instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or
|
| 152 |
+
:meth:`__int__` method (if present) to convert it to a
|
| 153 |
+
:c:type:`PyLongObject`.
|
| 154 |
+
|
| 155 |
+
If the value of *obj* is greater than :const:`LONG_MAX` or less than
|
| 156 |
+
:const:`LONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively, and
|
| 157 |
+
return ``-1``; otherwise, set *\*overflow* to ``0``. If any other exception
|
| 158 |
+
occurs set *\*overflow* to ``0`` and return ``-1`` as usual.
|
| 159 |
+
|
| 160 |
+
Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
|
| 161 |
+
|
| 162 |
+
.. versionchanged:: 3.8
|
| 163 |
+
Use :meth:`__index__` if available.
|
| 164 |
+
|
| 165 |
+
.. deprecated:: 3.8
|
| 166 |
+
Using :meth:`__int__` is deprecated.
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
.. c:function:: long long PyLong_AsLongLong(PyObject *obj)
|
| 170 |
+
|
| 171 |
+
.. index::
|
| 172 |
+
single: OverflowError (built-in exception)
|
| 173 |
+
|
| 174 |
+
Return a C :c:type:`long long` representation of *obj*. If *obj* is not an
|
| 175 |
+
instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or
|
| 176 |
+
:meth:`__int__` method (if present) to convert it to a
|
| 177 |
+
:c:type:`PyLongObject`.
|
| 178 |
+
|
| 179 |
+
Raise :exc:`OverflowError` if the value of *obj* is out of range for a
|
| 180 |
+
:c:type:`long long`.
|
| 181 |
+
|
| 182 |
+
Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
|
| 183 |
+
|
| 184 |
+
.. versionchanged:: 3.8
|
| 185 |
+
Use :meth:`__index__` if available.
|
| 186 |
+
|
| 187 |
+
.. deprecated:: 3.8
|
| 188 |
+
Using :meth:`__int__` is deprecated.
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
.. c:function:: long long PyLong_AsLongLongAndOverflow(PyObject *obj, int *overflow)
|
| 192 |
+
|
| 193 |
+
Return a C :c:type:`long long` representation of *obj*. If *obj* is not an
|
| 194 |
+
instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or
|
| 195 |
+
:meth:`__int__` method (if present) to convert it to a
|
| 196 |
+
:c:type:`PyLongObject`.
|
| 197 |
+
|
| 198 |
+
If the value of *obj* is greater than :const:`LLONG_MAX` or less than
|
| 199 |
+
:const:`LLONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively,
|
| 200 |
+
and return ``-1``; otherwise, set *\*overflow* to ``0``. If any other
|
| 201 |
+
exception occurs set *\*overflow* to ``0`` and return ``-1`` as usual.
|
| 202 |
+
|
| 203 |
+
Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
|
| 204 |
+
|
| 205 |
+
.. versionadded:: 3.2
|
| 206 |
+
|
| 207 |
+
.. versionchanged:: 3.8
|
| 208 |
+
Use :meth:`__index__` if available.
|
| 209 |
+
|
| 210 |
+
.. deprecated:: 3.8
|
| 211 |
+
Using :meth:`__int__` is deprecated.
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
.. c:function:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong)
|
| 215 |
+
|
| 216 |
+
.. index::
|
| 217 |
+
single: PY_SSIZE_T_MAX
|
| 218 |
+
single: OverflowError (built-in exception)
|
| 219 |
+
|
| 220 |
+
Return a C :c:type:`Py_ssize_t` representation of *pylong*. *pylong* must
|
| 221 |
+
be an instance of :c:type:`PyLongObject`.
|
| 222 |
+
|
| 223 |
+
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
|
| 224 |
+
:c:type:`Py_ssize_t`.
|
| 225 |
+
|
| 226 |
+
Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
.. c:function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
|
| 230 |
+
|
| 231 |
+
.. index::
|
| 232 |
+
single: ULONG_MAX
|
| 233 |
+
single: OverflowError (built-in exception)
|
| 234 |
+
|
| 235 |
+
Return a C :c:type:`unsigned long` representation of *pylong*. *pylong*
|
| 236 |
+
must be an instance of :c:type:`PyLongObject`.
|
| 237 |
+
|
| 238 |
+
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
|
| 239 |
+
:c:type:`unsigned long`.
|
| 240 |
+
|
| 241 |
+
Returns ``(unsigned long)-1`` on error.
|
| 242 |
+
Use :c:func:`PyErr_Occurred` to disambiguate.
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
.. c:function:: size_t PyLong_AsSize_t(PyObject *pylong)
|
| 246 |
+
|
| 247 |
+
.. index::
|
| 248 |
+
single: SIZE_MAX
|
| 249 |
+
single: OverflowError (built-in exception)
|
| 250 |
+
|
| 251 |
+
Return a C :c:type:`size_t` representation of *pylong*. *pylong* must be
|
| 252 |
+
an instance of :c:type:`PyLongObject`.
|
| 253 |
+
|
| 254 |
+
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
|
| 255 |
+
:c:type:`size_t`.
|
| 256 |
+
|
| 257 |
+
Returns ``(size_t)-1`` on error.
|
| 258 |
+
Use :c:func:`PyErr_Occurred` to disambiguate.
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
.. c:function:: unsigned long long PyLong_AsUnsignedLongLong(PyObject *pylong)
|
| 262 |
+
|
| 263 |
+
.. index::
|
| 264 |
+
single: OverflowError (built-in exception)
|
| 265 |
+
|
| 266 |
+
Return a C :c:type:`unsigned long long` representation of *pylong*. *pylong*
|
| 267 |
+
must be an instance of :c:type:`PyLongObject`.
|
| 268 |
+
|
| 269 |
+
Raise :exc:`OverflowError` if the value of *pylong* is out of range for an
|
| 270 |
+
:c:type:`unsigned long long`.
|
| 271 |
+
|
| 272 |
+
Returns ``(unsigned long long)-1`` on error.
|
| 273 |
+
Use :c:func:`PyErr_Occurred` to disambiguate.
|
| 274 |
+
|
| 275 |
+
.. versionchanged:: 3.1
|
| 276 |
+
A negative *pylong* now raises :exc:`OverflowError`, not :exc:`TypeError`.
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
.. c:function:: unsigned long PyLong_AsUnsignedLongMask(PyObject *obj)
|
| 280 |
+
|
| 281 |
+
Return a C :c:type:`unsigned long` representation of *obj*. If *obj*
|
| 282 |
+
is not an instance of :c:type:`PyLongObject`, first call its
|
| 283 |
+
:meth:`__index__` or :meth:`__int__` method (if present) to convert
|
| 284 |
+
it to a :c:type:`PyLongObject`.
|
| 285 |
+
|
| 286 |
+
If the value of *obj* is out of range for an :c:type:`unsigned long`,
|
| 287 |
+
return the reduction of that value modulo ``ULONG_MAX + 1``.
|
| 288 |
+
|
| 289 |
+
Returns ``(unsigned long)-1`` on error. Use :c:func:`PyErr_Occurred` to
|
| 290 |
+
disambiguate.
|
| 291 |
+
|
| 292 |
+
.. versionchanged:: 3.8
|
| 293 |
+
Use :meth:`__index__` if available.
|
| 294 |
+
|
| 295 |
+
.. deprecated:: 3.8
|
| 296 |
+
Using :meth:`__int__` is deprecated.
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
.. c:function:: unsigned long long PyLong_AsUnsignedLongLongMask(PyObject *obj)
|
| 300 |
+
|
| 301 |
+
Return a C :c:type:`unsigned long long` representation of *obj*. If *obj*
|
| 302 |
+
is not an instance of :c:type:`PyLongObject`, first call its
|
| 303 |
+
:meth:`__index__` or :meth:`__int__` method (if present) to convert
|
| 304 |
+
it to a :c:type:`PyLongObject`.
|
| 305 |
+
|
| 306 |
+
If the value of *obj* is out of range for an :c:type:`unsigned long long`,
|
| 307 |
+
return the reduction of that value modulo ``ULLONG_MAX + 1``.
|
| 308 |
+
|
| 309 |
+
Returns ``(unsigned long long)-1`` on error. Use :c:func:`PyErr_Occurred`
|
| 310 |
+
to disambiguate.
|
| 311 |
+
|
| 312 |
+
.. versionchanged:: 3.8
|
| 313 |
+
Use :meth:`__index__` if available.
|
| 314 |
+
|
| 315 |
+
.. deprecated:: 3.8
|
| 316 |
+
Using :meth:`__int__` is deprecated.
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
.. c:function:: double PyLong_AsDouble(PyObject *pylong)
|
| 320 |
+
|
| 321 |
+
Return a C :c:type:`double` representation of *pylong*. *pylong* must be
|
| 322 |
+
an instance of :c:type:`PyLongObject`.
|
| 323 |
+
|
| 324 |
+
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
|
| 325 |
+
:c:type:`double`.
|
| 326 |
+
|
| 327 |
+
Returns ``-1.0`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
.. c:function:: void* PyLong_AsVoidPtr(PyObject *pylong)
|
| 331 |
+
|
| 332 |
+
Convert a Python integer *pylong* to a C :c:type:`void` pointer.
|
| 333 |
+
If *pylong* cannot be converted, an :exc:`OverflowError` will be raised. This
|
| 334 |
+
is only assured to produce a usable :c:type:`void` pointer for values created
|
| 335 |
+
with :c:func:`PyLong_FromVoidPtr`.
|
| 336 |
+
|
| 337 |
+
Returns ``NULL`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
|
cpython_2/environment/repo/Doc/c-api/mapping.rst
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _mapping:
|
| 4 |
+
|
| 5 |
+
Mapping Protocol
|
| 6 |
+
================
|
| 7 |
+
|
| 8 |
+
See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
|
| 9 |
+
:c:func:`PyObject_DelItem`.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
.. c:function:: int PyMapping_Check(PyObject *o)
|
| 13 |
+
|
| 14 |
+
Return ``1`` if the object provides mapping protocol or supports slicing,
|
| 15 |
+
and ``0`` otherwise. Note that it returns ``1`` for Python classes with
|
| 16 |
+
a :meth:`__getitem__` method since in general case it is impossible to
|
| 17 |
+
determine what type of keys it supports. This function always succeeds.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
.. c:function:: Py_ssize_t PyMapping_Size(PyObject *o)
|
| 21 |
+
Py_ssize_t PyMapping_Length(PyObject *o)
|
| 22 |
+
|
| 23 |
+
.. index:: builtin: len
|
| 24 |
+
|
| 25 |
+
Returns the number of keys in object *o* on success, and ``-1`` on failure.
|
| 26 |
+
This is equivalent to the Python expression ``len(o)``.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
.. c:function:: PyObject* PyMapping_GetItemString(PyObject *o, const char *key)
|
| 30 |
+
|
| 31 |
+
Return element of *o* corresponding to the string *key* or ``NULL`` on failure.
|
| 32 |
+
This is the equivalent of the Python expression ``o[key]``.
|
| 33 |
+
See also :c:func:`PyObject_GetItem`.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
.. c:function:: int PyMapping_SetItemString(PyObject *o, const char *key, PyObject *v)
|
| 37 |
+
|
| 38 |
+
Map the string *key* to the value *v* in object *o*. Returns ``-1`` on
|
| 39 |
+
failure. This is the equivalent of the Python statement ``o[key] = v``.
|
| 40 |
+
See also :c:func:`PyObject_SetItem`. This function *does not* steal a
|
| 41 |
+
reference to *v*.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
.. c:function:: int PyMapping_DelItem(PyObject *o, PyObject *key)
|
| 45 |
+
|
| 46 |
+
Remove the mapping for the object *key* from the object *o*. Return ``-1``
|
| 47 |
+
on failure. This is equivalent to the Python statement ``del o[key]``.
|
| 48 |
+
This is an alias of :c:func:`PyObject_DelItem`.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
.. c:function:: int PyMapping_DelItemString(PyObject *o, const char *key)
|
| 52 |
+
|
| 53 |
+
Remove the mapping for the string *key* from the object *o*. Return ``-1``
|
| 54 |
+
on failure. This is equivalent to the Python statement ``del o[key]``.
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
.. c:function:: int PyMapping_HasKey(PyObject *o, PyObject *key)
|
| 58 |
+
|
| 59 |
+
Return ``1`` if the mapping object has the key *key* and ``0`` otherwise.
|
| 60 |
+
This is equivalent to the Python expression ``key in o``.
|
| 61 |
+
This function always succeeds.
|
| 62 |
+
|
| 63 |
+
Note that exceptions which occur while calling the :meth:`__getitem__`
|
| 64 |
+
method will get suppressed.
|
| 65 |
+
To get error reporting use :c:func:`PyObject_GetItem()` instead.
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
.. c:function:: int PyMapping_HasKeyString(PyObject *o, const char *key)
|
| 69 |
+
|
| 70 |
+
Return ``1`` if the mapping object has the key *key* and ``0`` otherwise.
|
| 71 |
+
This is equivalent to the Python expression ``key in o``.
|
| 72 |
+
This function always succeeds.
|
| 73 |
+
|
| 74 |
+
Note that exceptions which occur while calling the :meth:`__getitem__`
|
| 75 |
+
method and creating a temporary string object will get suppressed.
|
| 76 |
+
To get error reporting use :c:func:`PyMapping_GetItemString()` instead.
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
.. c:function:: PyObject* PyMapping_Keys(PyObject *o)
|
| 80 |
+
|
| 81 |
+
On success, return a list of the keys in object *o*. On failure, return
|
| 82 |
+
``NULL``.
|
| 83 |
+
|
| 84 |
+
.. versionchanged:: 3.7
|
| 85 |
+
Previously, the function returned a list or a tuple.
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
.. c:function:: PyObject* PyMapping_Values(PyObject *o)
|
| 89 |
+
|
| 90 |
+
On success, return a list of the values in object *o*. On failure, return
|
| 91 |
+
``NULL``.
|
| 92 |
+
|
| 93 |
+
.. versionchanged:: 3.7
|
| 94 |
+
Previously, the function returned a list or a tuple.
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
.. c:function:: PyObject* PyMapping_Items(PyObject *o)
|
| 98 |
+
|
| 99 |
+
On success, return a list of the items in object *o*, where each item is a
|
| 100 |
+
tuple containing a key-value pair. On failure, return ``NULL``.
|
| 101 |
+
|
| 102 |
+
.. versionchanged:: 3.7
|
| 103 |
+
Previously, the function returned a list or a tuple.
|
cpython_2/environment/repo/Doc/c-api/marshal.rst
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _marshalling-utils:
|
| 4 |
+
|
| 5 |
+
Data marshalling support
|
| 6 |
+
========================
|
| 7 |
+
|
| 8 |
+
These routines allow C code to work with serialized objects using the same
|
| 9 |
+
data format as the :mod:`marshal` module. There are functions to write data
|
| 10 |
+
into the serialization format, and additional functions that can be used to
|
| 11 |
+
read the data back. Files used to store marshalled data must be opened in
|
| 12 |
+
binary mode.
|
| 13 |
+
|
| 14 |
+
Numeric values are stored with the least significant byte first.
|
| 15 |
+
|
| 16 |
+
The module supports two versions of the data format: version 0 is the
|
| 17 |
+
historical version, version 1 shares interned strings in the file, and upon
|
| 18 |
+
unmarshalling. Version 2 uses a binary format for floating point numbers.
|
| 19 |
+
``Py_MARSHAL_VERSION`` indicates the current file format (currently 2).
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
.. c:function:: void PyMarshal_WriteLongToFile(long value, FILE *file, int version)
|
| 23 |
+
|
| 24 |
+
Marshal a :c:type:`long` integer, *value*, to *file*. This will only write
|
| 25 |
+
the least-significant 32 bits of *value*; regardless of the size of the
|
| 26 |
+
native :c:type:`long` type. *version* indicates the file format.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
.. c:function:: void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version)
|
| 30 |
+
|
| 31 |
+
Marshal a Python object, *value*, to *file*.
|
| 32 |
+
*version* indicates the file format.
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
.. c:function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version)
|
| 36 |
+
|
| 37 |
+
Return a bytes object containing the marshalled representation of *value*.
|
| 38 |
+
*version* indicates the file format.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
The following functions allow marshalled values to be read back in.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
.. c:function:: long PyMarshal_ReadLongFromFile(FILE *file)
|
| 45 |
+
|
| 46 |
+
Return a C :c:type:`long` from the data stream in a :c:type:`FILE\*` opened
|
| 47 |
+
for reading. Only a 32-bit value can be read in using this function,
|
| 48 |
+
regardless of the native size of :c:type:`long`.
|
| 49 |
+
|
| 50 |
+
On error, sets the appropriate exception (:exc:`EOFError`) and returns
|
| 51 |
+
``-1``.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
.. c:function:: int PyMarshal_ReadShortFromFile(FILE *file)
|
| 55 |
+
|
| 56 |
+
Return a C :c:type:`short` from the data stream in a :c:type:`FILE\*` opened
|
| 57 |
+
for reading. Only a 16-bit value can be read in using this function,
|
| 58 |
+
regardless of the native size of :c:type:`short`.
|
| 59 |
+
|
| 60 |
+
On error, sets the appropriate exception (:exc:`EOFError`) and returns
|
| 61 |
+
``-1``.
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
.. c:function:: PyObject* PyMarshal_ReadObjectFromFile(FILE *file)
|
| 65 |
+
|
| 66 |
+
Return a Python object from the data stream in a :c:type:`FILE\*` opened for
|
| 67 |
+
reading.
|
| 68 |
+
|
| 69 |
+
On error, sets the appropriate exception (:exc:`EOFError`, :exc:`ValueError`
|
| 70 |
+
or :exc:`TypeError`) and returns ``NULL``.
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
.. c:function:: PyObject* PyMarshal_ReadLastObjectFromFile(FILE *file)
|
| 74 |
+
|
| 75 |
+
Return a Python object from the data stream in a :c:type:`FILE\*` opened for
|
| 76 |
+
reading. Unlike :c:func:`PyMarshal_ReadObjectFromFile`, this function
|
| 77 |
+
assumes that no further objects will be read from the file, allowing it to
|
| 78 |
+
aggressively load file data into memory so that the de-serialization can
|
| 79 |
+
operate from data in memory rather than reading a byte at a time from the
|
| 80 |
+
file. Only use these variant if you are certain that you won't be reading
|
| 81 |
+
anything else from the file.
|
| 82 |
+
|
| 83 |
+
On error, sets the appropriate exception (:exc:`EOFError`, :exc:`ValueError`
|
| 84 |
+
or :exc:`TypeError`) and returns ``NULL``.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
.. c:function:: PyObject* PyMarshal_ReadObjectFromString(const char *data, Py_ssize_t len)
|
| 88 |
+
|
| 89 |
+
Return a Python object from the data stream in a byte buffer
|
| 90 |
+
containing *len* bytes pointed to by *data*.
|
| 91 |
+
|
| 92 |
+
On error, sets the appropriate exception (:exc:`EOFError`, :exc:`ValueError`
|
| 93 |
+
or :exc:`TypeError`) and returns ``NULL``.
|
| 94 |
+
|
cpython_2/environment/repo/Doc/c-api/memory.rst
ADDED
|
@@ -0,0 +1,604 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 14 |
+
.. _memoryoverview:
|
| 15 |
+
|
| 16 |
+
Overview
|
| 17 |
+
========
|
| 18 |
+
|
| 19 |
+
Memory management in Python involves a private heap containing all Python
|
| 20 |
+
objects and data structures. The management of this private heap is ensured
|
| 21 |
+
internally by the *Python memory manager*. The Python memory manager has
|
| 22 |
+
different components which deal with various dynamic storage management aspects,
|
| 23 |
+
like sharing, segmentation, preallocation or caching.
|
| 24 |
+
|
| 25 |
+
At the lowest level, a raw memory allocator ensures that there is enough room in
|
| 26 |
+
the private heap for storing all Python-related data by interacting with the
|
| 27 |
+
memory manager of the operating system. On top of the raw memory allocator,
|
| 28 |
+
several object-specific allocators operate on the same heap and implement
|
| 29 |
+
distinct memory management policies adapted to the peculiarities of every object
|
| 30 |
+
type. For example, integer objects are managed differently within the heap than
|
| 31 |
+
strings, tuples or dictionaries because integers imply different storage
|
| 32 |
+
requirements and speed/space tradeoffs. The Python memory manager thus delegates
|
| 33 |
+
some of the work to the object-specific allocators, but ensures that the latter
|
| 34 |
+
operate within the bounds of the private heap.
|
| 35 |
+
|
| 36 |
+
It is important to understand that the management of the Python heap is
|
| 37 |
+
performed by the interpreter itself and that the user has no control over it,
|
| 38 |
+
even if they regularly manipulate object pointers to memory blocks inside that
|
| 39 |
+
heap. The allocation of heap space for Python objects and other internal
|
| 40 |
+
buffers is performed on demand by the Python memory manager through the Python/C
|
| 41 |
+
API functions listed in this document.
|
| 42 |
+
|
| 43 |
+
.. index::
|
| 44 |
+
single: malloc()
|
| 45 |
+
single: calloc()
|
| 46 |
+
single: realloc()
|
| 47 |
+
single: free()
|
| 48 |
+
|
| 49 |
+
To avoid memory corruption, extension writers should never try to operate on
|
| 50 |
+
Python objects with the functions exported by the C library: :c:func:`malloc`,
|
| 51 |
+
:c:func:`calloc`, :c:func:`realloc` and :c:func:`free`. This will result in mixed
|
| 52 |
+
calls between the C allocator and the Python memory manager with fatal
|
| 53 |
+
consequences, because they implement different algorithms and operate on
|
| 54 |
+
different heaps. However, one may safely allocate and release memory blocks
|
| 55 |
+
with the C library allocator for individual purposes, as shown in the following
|
| 56 |
+
example::
|
| 57 |
+
|
| 58 |
+
PyObject *res;
|
| 59 |
+
char *buf = (char *) malloc(BUFSIZ); /* for I/O */
|
| 60 |
+
|
| 61 |
+
if (buf == NULL)
|
| 62 |
+
return PyErr_NoMemory();
|
| 63 |
+
...Do some I/O operation involving buf...
|
| 64 |
+
res = PyBytes_FromString(buf);
|
| 65 |
+
free(buf); /* malloc'ed */
|
| 66 |
+
return res;
|
| 67 |
+
|
| 68 |
+
In this example, the memory request for the I/O buffer is handled by the C
|
| 69 |
+
library allocator. The Python memory manager is involved only in the allocation
|
| 70 |
+
of the bytes object returned as a result.
|
| 71 |
+
|
| 72 |
+
In most situations, however, it is recommended to allocate memory from the
|
| 73 |
+
Python heap specifically because the latter is under control of the Python
|
| 74 |
+
memory manager. For example, this is required when the interpreter is extended
|
| 75 |
+
with new object types written in C. Another reason for using the Python heap is
|
| 76 |
+
the desire to *inform* the Python memory manager about the memory needs of the
|
| 77 |
+
extension module. Even when the requested memory is used exclusively for
|
| 78 |
+
internal, highly-specific purposes, delegating all memory requests to the Python
|
| 79 |
+
memory manager causes the interpreter to have a more accurate image of its
|
| 80 |
+
memory footprint as a whole. Consequently, under certain circumstances, the
|
| 81 |
+
Python memory manager may or may not trigger appropriate actions, like garbage
|
| 82 |
+
collection, memory compaction or other preventive procedures. Note that by using
|
| 83 |
+
the C library allocator as shown in the previous example, the allocated memory
|
| 84 |
+
for the I/O buffer escapes completely the Python memory manager.
|
| 85 |
+
|
| 86 |
+
.. seealso::
|
| 87 |
+
|
| 88 |
+
The :envvar:`PYTHONMALLOC` environment variable can be used to configure
|
| 89 |
+
the memory allocators used by Python.
|
| 90 |
+
|
| 91 |
+
The :envvar:`PYTHONMALLOCSTATS` environment variable can be used to print
|
| 92 |
+
statistics of the :ref:`pymalloc memory allocator <pymalloc>` every time a
|
| 93 |
+
new pymalloc object arena is created, and on shutdown.
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
Raw Memory Interface
|
| 97 |
+
====================
|
| 98 |
+
|
| 99 |
+
The following function sets are wrappers to the system allocator. These
|
| 100 |
+
functions are thread-safe, the :term:`GIL <global interpreter lock>` does not
|
| 101 |
+
need to be held.
|
| 102 |
+
|
| 103 |
+
The :ref:`default raw memory allocator <default-memory-allocators>` uses
|
| 104 |
+
the following functions: :c:func:`malloc`, :c:func:`calloc`, :c:func:`realloc`
|
| 105 |
+
and :c:func:`free`; call ``malloc(1)`` (or ``calloc(1, 1)``) when requesting
|
| 106 |
+
zero bytes.
|
| 107 |
+
|
| 108 |
+
.. versionadded:: 3.4
|
| 109 |
+
|
| 110 |
+
.. c:function:: void* PyMem_RawMalloc(size_t n)
|
| 111 |
+
|
| 112 |
+
Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the
|
| 113 |
+
allocated memory, or ``NULL`` if the request fails.
|
| 114 |
+
|
| 115 |
+
Requesting zero bytes returns a distinct non-``NULL`` pointer if possible, as
|
| 116 |
+
if ``PyMem_RawMalloc(1)`` had been called instead. The memory will not have
|
| 117 |
+
been initialized in any way.
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
.. c:function:: void* PyMem_RawCalloc(size_t nelem, size_t elsize)
|
| 121 |
+
|
| 122 |
+
Allocates *nelem* elements each whose size in bytes is *elsize* and returns
|
| 123 |
+
a pointer of type :c:type:`void\*` to the allocated memory, or ``NULL`` if the
|
| 124 |
+
request fails. The memory is initialized to zeros.
|
| 125 |
+
|
| 126 |
+
Requesting zero elements or elements of size zero bytes returns a distinct
|
| 127 |
+
non-``NULL`` pointer if possible, as if ``PyMem_RawCalloc(1, 1)`` had been
|
| 128 |
+
called instead.
|
| 129 |
+
|
| 130 |
+
.. versionadded:: 3.5
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
.. c:function:: void* PyMem_RawRealloc(void *p, size_t n)
|
| 134 |
+
|
| 135 |
+
Resizes the memory block pointed to by *p* to *n* bytes. The contents will
|
| 136 |
+
be unchanged to the minimum of the old and the new sizes.
|
| 137 |
+
|
| 138 |
+
If *p* is ``NULL``, the call is equivalent to ``PyMem_RawMalloc(n)``; else if
|
| 139 |
+
*n* is equal to zero, the memory block is resized but is not freed, and the
|
| 140 |
+
returned pointer is non-``NULL``.
|
| 141 |
+
|
| 142 |
+
Unless *p* is ``NULL``, it must have been returned by a previous call to
|
| 143 |
+
:c:func:`PyMem_RawMalloc`, :c:func:`PyMem_RawRealloc` or
|
| 144 |
+
:c:func:`PyMem_RawCalloc`.
|
| 145 |
+
|
| 146 |
+
If the request fails, :c:func:`PyMem_RawRealloc` returns ``NULL`` and *p*
|
| 147 |
+
remains a valid pointer to the previous memory area.
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
.. c:function:: void PyMem_RawFree(void *p)
|
| 151 |
+
|
| 152 |
+
Frees the memory block pointed to by *p*, which must have been returned by a
|
| 153 |
+
previous call to :c:func:`PyMem_RawMalloc`, :c:func:`PyMem_RawRealloc` or
|
| 154 |
+
:c:func:`PyMem_RawCalloc`. Otherwise, or if ``PyMem_RawFree(p)`` has been
|
| 155 |
+
called before, undefined behavior occurs.
|
| 156 |
+
|
| 157 |
+
If *p* is ``NULL``, no operation is performed.
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
.. _memoryinterface:
|
| 161 |
+
|
| 162 |
+
Memory Interface
|
| 163 |
+
================
|
| 164 |
+
|
| 165 |
+
The following function sets, modeled after the ANSI C standard, but specifying
|
| 166 |
+
behavior when requesting zero bytes, are available for allocating and releasing
|
| 167 |
+
memory from the Python heap.
|
| 168 |
+
|
| 169 |
+
The :ref:`default memory allocator <default-memory-allocators>` uses the
|
| 170 |
+
:ref:`pymalloc memory allocator <pymalloc>`.
|
| 171 |
+
|
| 172 |
+
.. warning::
|
| 173 |
+
|
| 174 |
+
The :term:`GIL <global interpreter lock>` must be held when using these
|
| 175 |
+
functions.
|
| 176 |
+
|
| 177 |
+
.. versionchanged:: 3.6
|
| 178 |
+
|
| 179 |
+
The default allocator is now pymalloc instead of system :c:func:`malloc`.
|
| 180 |
+
|
| 181 |
+
.. c:function:: void* PyMem_Malloc(size_t n)
|
| 182 |
+
|
| 183 |
+
Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the
|
| 184 |
+
allocated memory, or ``NULL`` if the request fails.
|
| 185 |
+
|
| 186 |
+
Requesting zero bytes returns a distinct non-``NULL`` pointer if possible, as
|
| 187 |
+
if ``PyMem_Malloc(1)`` had been called instead. The memory will not have
|
| 188 |
+
been initialized in any way.
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
.. c:function:: void* PyMem_Calloc(size_t nelem, size_t elsize)
|
| 192 |
+
|
| 193 |
+
Allocates *nelem* elements each whose size in bytes is *elsize* and returns
|
| 194 |
+
a pointer of type :c:type:`void\*` to the allocated memory, or ``NULL`` if the
|
| 195 |
+
request fails. The memory is initialized to zeros.
|
| 196 |
+
|
| 197 |
+
Requesting zero elements or elements of size zero bytes returns a distinct
|
| 198 |
+
non-``NULL`` pointer if possible, as if ``PyMem_Calloc(1, 1)`` had been called
|
| 199 |
+
instead.
|
| 200 |
+
|
| 201 |
+
.. versionadded:: 3.5
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
.. c:function:: void* PyMem_Realloc(void *p, size_t n)
|
| 205 |
+
|
| 206 |
+
Resizes the memory block pointed to by *p* to *n* bytes. The contents will be
|
| 207 |
+
unchanged to the minimum of the old and the new sizes.
|
| 208 |
+
|
| 209 |
+
If *p* is ``NULL``, the call is equivalent to ``PyMem_Malloc(n)``; else if *n*
|
| 210 |
+
is equal to zero, the memory block is resized but is not freed, and the
|
| 211 |
+
returned pointer is non-``NULL``.
|
| 212 |
+
|
| 213 |
+
Unless *p* is ``NULL``, it must have been returned by a previous call to
|
| 214 |
+
:c:func:`PyMem_Malloc`, :c:func:`PyMem_Realloc` or :c:func:`PyMem_Calloc`.
|
| 215 |
+
|
| 216 |
+
If the request fails, :c:func:`PyMem_Realloc` returns ``NULL`` and *p* remains
|
| 217 |
+
a valid pointer to the previous memory area.
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
.. c:function:: void PyMem_Free(void *p)
|
| 221 |
+
|
| 222 |
+
Frees the memory block pointed to by *p*, which must have been returned by a
|
| 223 |
+
previous call to :c:func:`PyMem_Malloc`, :c:func:`PyMem_Realloc` or
|
| 224 |
+
:c:func:`PyMem_Calloc`. Otherwise, or if ``PyMem_Free(p)`` has been called
|
| 225 |
+
before, undefined behavior occurs.
|
| 226 |
+
|
| 227 |
+
If *p* is ``NULL``, no operation is performed.
|
| 228 |
+
|
| 229 |
+
The following type-oriented macros are provided for convenience. Note that
|
| 230 |
+
*TYPE* refers to any C type.
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
.. c:function:: TYPE* PyMem_New(TYPE, size_t n)
|
| 234 |
+
|
| 235 |
+
Same as :c:func:`PyMem_Malloc`, but allocates ``(n * sizeof(TYPE))`` bytes of
|
| 236 |
+
memory. Returns a pointer cast to :c:type:`TYPE\*`. The memory will not have
|
| 237 |
+
been initialized in any way.
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
.. c:function:: TYPE* PyMem_Resize(void *p, TYPE, size_t n)
|
| 241 |
+
|
| 242 |
+
Same as :c:func:`PyMem_Realloc`, but the memory block is resized to ``(n *
|
| 243 |
+
sizeof(TYPE))`` bytes. Returns a pointer cast to :c:type:`TYPE\*`. On return,
|
| 244 |
+
*p* will be a pointer to the new memory area, or ``NULL`` in the event of
|
| 245 |
+
failure.
|
| 246 |
+
|
| 247 |
+
This is a C preprocessor macro; *p* is always reassigned. Save the original
|
| 248 |
+
value of *p* to avoid losing memory when handling errors.
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
.. c:function:: void PyMem_Del(void *p)
|
| 252 |
+
|
| 253 |
+
Same as :c:func:`PyMem_Free`.
|
| 254 |
+
|
| 255 |
+
In addition, the following macro sets are provided for calling the Python memory
|
| 256 |
+
allocator directly, without involving the C API functions listed above. However,
|
| 257 |
+
note that their use does not preserve binary compatibility across Python
|
| 258 |
+
versions and is therefore deprecated in extension modules.
|
| 259 |
+
|
| 260 |
+
* ``PyMem_MALLOC(size)``
|
| 261 |
+
* ``PyMem_NEW(type, size)``
|
| 262 |
+
* ``PyMem_REALLOC(ptr, size)``
|
| 263 |
+
* ``PyMem_RESIZE(ptr, type, size)``
|
| 264 |
+
* ``PyMem_FREE(ptr)``
|
| 265 |
+
* ``PyMem_DEL(ptr)``
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
Object allocators
|
| 269 |
+
=================
|
| 270 |
+
|
| 271 |
+
The following function sets, modeled after the ANSI C standard, but specifying
|
| 272 |
+
behavior when requesting zero bytes, are available for allocating and releasing
|
| 273 |
+
memory from the Python heap.
|
| 274 |
+
|
| 275 |
+
The :ref:`default object allocator <default-memory-allocators>` uses the
|
| 276 |
+
:ref:`pymalloc memory allocator <pymalloc>`.
|
| 277 |
+
|
| 278 |
+
.. warning::
|
| 279 |
+
|
| 280 |
+
The :term:`GIL <global interpreter lock>` must be held when using these
|
| 281 |
+
functions.
|
| 282 |
+
|
| 283 |
+
.. c:function:: void* PyObject_Malloc(size_t n)
|
| 284 |
+
|
| 285 |
+
Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the
|
| 286 |
+
allocated memory, or ``NULL`` if the request fails.
|
| 287 |
+
|
| 288 |
+
Requesting zero bytes returns a distinct non-``NULL`` pointer if possible, as
|
| 289 |
+
if ``PyObject_Malloc(1)`` had been called instead. The memory will not have
|
| 290 |
+
been initialized in any way.
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
.. c:function:: void* PyObject_Calloc(size_t nelem, size_t elsize)
|
| 294 |
+
|
| 295 |
+
Allocates *nelem* elements each whose size in bytes is *elsize* and returns
|
| 296 |
+
a pointer of type :c:type:`void\*` to the allocated memory, or ``NULL`` if the
|
| 297 |
+
request fails. The memory is initialized to zeros.
|
| 298 |
+
|
| 299 |
+
Requesting zero elements or elements of size zero bytes returns a distinct
|
| 300 |
+
non-``NULL`` pointer if possible, as if ``PyObject_Calloc(1, 1)`` had been called
|
| 301 |
+
instead.
|
| 302 |
+
|
| 303 |
+
.. versionadded:: 3.5
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
.. c:function:: void* PyObject_Realloc(void *p, size_t n)
|
| 307 |
+
|
| 308 |
+
Resizes the memory block pointed to by *p* to *n* bytes. The contents will be
|
| 309 |
+
unchanged to the minimum of the old and the new sizes.
|
| 310 |
+
|
| 311 |
+
If *p* is ``NULL``, the call is equivalent to ``PyObject_Malloc(n)``; else if *n*
|
| 312 |
+
is equal to zero, the memory block is resized but is not freed, and the
|
| 313 |
+
returned pointer is non-``NULL``.
|
| 314 |
+
|
| 315 |
+
Unless *p* is ``NULL``, it must have been returned by a previous call to
|
| 316 |
+
:c:func:`PyObject_Malloc`, :c:func:`PyObject_Realloc` or :c:func:`PyObject_Calloc`.
|
| 317 |
+
|
| 318 |
+
If the request fails, :c:func:`PyObject_Realloc` returns ``NULL`` and *p* remains
|
| 319 |
+
a valid pointer to the previous memory area.
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
.. c:function:: void PyObject_Free(void *p)
|
| 323 |
+
|
| 324 |
+
Frees the memory block pointed to by *p*, which must have been returned by a
|
| 325 |
+
previous call to :c:func:`PyObject_Malloc`, :c:func:`PyObject_Realloc` or
|
| 326 |
+
:c:func:`PyObject_Calloc`. Otherwise, or if ``PyObject_Free(p)`` has been called
|
| 327 |
+
before, undefined behavior occurs.
|
| 328 |
+
|
| 329 |
+
If *p* is ``NULL``, no operation is performed.
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
.. _default-memory-allocators:
|
| 333 |
+
|
| 334 |
+
Default Memory Allocators
|
| 335 |
+
=========================
|
| 336 |
+
|
| 337 |
+
Default memory allocators:
|
| 338 |
+
|
| 339 |
+
=============================== ==================== ================== ===================== ====================
|
| 340 |
+
Configuration Name PyMem_RawMalloc PyMem_Malloc PyObject_Malloc
|
| 341 |
+
=============================== ==================== ================== ===================== ====================
|
| 342 |
+
Release build ``"pymalloc"`` ``malloc`` ``pymalloc`` ``pymalloc``
|
| 343 |
+
Debug build ``"pymalloc_debug"`` ``malloc`` + debug ``pymalloc`` + debug ``pymalloc`` + debug
|
| 344 |
+
Release build, without pymalloc ``"malloc"`` ``malloc`` ``malloc`` ``malloc``
|
| 345 |
+
Debug build, without pymalloc ``"malloc_debug"`` ``malloc`` + debug ``malloc`` + debug ``malloc`` + debug
|
| 346 |
+
=============================== ==================== ================== ===================== ====================
|
| 347 |
+
|
| 348 |
+
Legend:
|
| 349 |
+
|
| 350 |
+
* Name: value for :envvar:`PYTHONMALLOC` environment variable
|
| 351 |
+
* ``malloc``: system allocators from the standard C library, C functions:
|
| 352 |
+
:c:func:`malloc`, :c:func:`calloc`, :c:func:`realloc` and :c:func:`free`
|
| 353 |
+
* ``pymalloc``: :ref:`pymalloc memory allocator <pymalloc>`
|
| 354 |
+
* "+ debug": with debug hooks installed by :c:func:`PyMem_SetupDebugHooks`
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
Customize Memory Allocators
|
| 358 |
+
===========================
|
| 359 |
+
|
| 360 |
+
.. versionadded:: 3.4
|
| 361 |
+
|
| 362 |
+
.. c:type:: PyMemAllocatorEx
|
| 363 |
+
|
| 364 |
+
Structure used to describe a memory block allocator. The structure has
|
| 365 |
+
four fields:
|
| 366 |
+
|
| 367 |
+
+----------------------------------------------------------+---------------------------------------+
|
| 368 |
+
| Field | Meaning |
|
| 369 |
+
+==========================================================+=======================================+
|
| 370 |
+
| ``void *ctx`` | user context passed as first argument |
|
| 371 |
+
+----------------------------------------------------------+---------------------------------------+
|
| 372 |
+
| ``void* malloc(void *ctx, size_t size)`` | allocate a memory block |
|
| 373 |
+
+----------------------------------------------------------+---------------------------------------+
|
| 374 |
+
| ``void* calloc(void *ctx, size_t nelem, size_t elsize)`` | allocate a memory block initialized |
|
| 375 |
+
| | with zeros |
|
| 376 |
+
+----------------------------------------------------------+---------------------------------------+
|
| 377 |
+
| ``void* realloc(void *ctx, void *ptr, size_t new_size)`` | allocate or resize a memory block |
|
| 378 |
+
+----------------------------------------------------------+---------------------------------------+
|
| 379 |
+
| ``void free(void *ctx, void *ptr)`` | free a memory block |
|
| 380 |
+
+----------------------------------------------------------+---------------------------------------+
|
| 381 |
+
|
| 382 |
+
.. versionchanged:: 3.5
|
| 383 |
+
The :c:type:`PyMemAllocator` structure was renamed to
|
| 384 |
+
:c:type:`PyMemAllocatorEx` and a new ``calloc`` field was added.
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
.. c:type:: PyMemAllocatorDomain
|
| 388 |
+
|
| 389 |
+
Enum used to identify an allocator domain. Domains:
|
| 390 |
+
|
| 391 |
+
.. c:var:: PYMEM_DOMAIN_RAW
|
| 392 |
+
|
| 393 |
+
Functions:
|
| 394 |
+
|
| 395 |
+
* :c:func:`PyMem_RawMalloc`
|
| 396 |
+
* :c:func:`PyMem_RawRealloc`
|
| 397 |
+
* :c:func:`PyMem_RawCalloc`
|
| 398 |
+
* :c:func:`PyMem_RawFree`
|
| 399 |
+
|
| 400 |
+
.. c:var:: PYMEM_DOMAIN_MEM
|
| 401 |
+
|
| 402 |
+
Functions:
|
| 403 |
+
|
| 404 |
+
* :c:func:`PyMem_Malloc`,
|
| 405 |
+
* :c:func:`PyMem_Realloc`
|
| 406 |
+
* :c:func:`PyMem_Calloc`
|
| 407 |
+
* :c:func:`PyMem_Free`
|
| 408 |
+
|
| 409 |
+
.. c:var:: PYMEM_DOMAIN_OBJ
|
| 410 |
+
|
| 411 |
+
Functions:
|
| 412 |
+
|
| 413 |
+
* :c:func:`PyObject_Malloc`
|
| 414 |
+
* :c:func:`PyObject_Realloc`
|
| 415 |
+
* :c:func:`PyObject_Calloc`
|
| 416 |
+
* :c:func:`PyObject_Free`
|
| 417 |
+
|
| 418 |
+
.. c:function:: void PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator)
|
| 419 |
+
|
| 420 |
+
Get the memory block allocator of the specified domain.
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
.. c:function:: void PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator)
|
| 424 |
+
|
| 425 |
+
Set the memory block allocator of the specified domain.
|
| 426 |
+
|
| 427 |
+
The new allocator must return a distinct non-``NULL`` pointer when requesting
|
| 428 |
+
zero bytes.
|
| 429 |
+
|
| 430 |
+
For the :c:data:`PYMEM_DOMAIN_RAW` domain, the allocator must be
|
| 431 |
+
thread-safe: the :term:`GIL <global interpreter lock>` is not held when the
|
| 432 |
+
allocator is called.
|
| 433 |
+
|
| 434 |
+
If the new allocator is not a hook (does not call the previous allocator),
|
| 435 |
+
the :c:func:`PyMem_SetupDebugHooks` function must be called to reinstall the
|
| 436 |
+
debug hooks on top on the new allocator.
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
.. c:function:: void PyMem_SetupDebugHooks(void)
|
| 440 |
+
|
| 441 |
+
Setup hooks to detect bugs in the Python memory allocator functions.
|
| 442 |
+
|
| 443 |
+
Newly allocated memory is filled with the byte ``0xCD`` (``CLEANBYTE``),
|
| 444 |
+
freed memory is filled with the byte ``0xDD`` (``DEADBYTE``). Memory blocks
|
| 445 |
+
are surrounded by "forbidden bytes" (``FORBIDDENBYTE``: byte ``0xFD``).
|
| 446 |
+
|
| 447 |
+
Runtime checks:
|
| 448 |
+
|
| 449 |
+
- Detect API violations, ex: :c:func:`PyObject_Free` called on a buffer
|
| 450 |
+
allocated by :c:func:`PyMem_Malloc`
|
| 451 |
+
- Detect write before the start of the buffer (buffer underflow)
|
| 452 |
+
- Detect write after the end of the buffer (buffer overflow)
|
| 453 |
+
- Check that the :term:`GIL <global interpreter lock>` is held when
|
| 454 |
+
allocator functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex:
|
| 455 |
+
:c:func:`PyObject_Malloc`) and :c:data:`PYMEM_DOMAIN_MEM` (ex:
|
| 456 |
+
:c:func:`PyMem_Malloc`) domains are called
|
| 457 |
+
|
| 458 |
+
On error, the debug hooks use the :mod:`tracemalloc` module to get the
|
| 459 |
+
traceback where a memory block was allocated. The traceback is only
|
| 460 |
+
displayed if :mod:`tracemalloc` is tracing Python memory allocations and the
|
| 461 |
+
memory block was traced.
|
| 462 |
+
|
| 463 |
+
These hooks are :ref:`installed by default <default-memory-allocators>` if
|
| 464 |
+
Python is compiled in debug
|
| 465 |
+
mode. The :envvar:`PYTHONMALLOC` environment variable can be used to install
|
| 466 |
+
debug hooks on a Python compiled in release mode.
|
| 467 |
+
|
| 468 |
+
.. versionchanged:: 3.6
|
| 469 |
+
This function now also works on Python compiled in release mode.
|
| 470 |
+
On error, the debug hooks now use :mod:`tracemalloc` to get the traceback
|
| 471 |
+
where a memory block was allocated. The debug hooks now also check
|
| 472 |
+
if the GIL is held when functions of :c:data:`PYMEM_DOMAIN_OBJ` and
|
| 473 |
+
:c:data:`PYMEM_DOMAIN_MEM` domains are called.
|
| 474 |
+
|
| 475 |
+
.. versionchanged:: 3.8
|
| 476 |
+
Byte patterns ``0xCB`` (``CLEANBYTE``), ``0xDB`` (``DEADBYTE``) and
|
| 477 |
+
``0xFB`` (``FORBIDDENBYTE``) have been replaced with ``0xCD``, ``0xDD``
|
| 478 |
+
and ``0xFD`` to use the same values than Windows CRT debug ``malloc()``
|
| 479 |
+
and ``free()``.
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
.. _pymalloc:
|
| 483 |
+
|
| 484 |
+
The pymalloc allocator
|
| 485 |
+
======================
|
| 486 |
+
|
| 487 |
+
Python has a *pymalloc* allocator optimized for small objects (smaller or equal
|
| 488 |
+
to 512 bytes) with a short lifetime. It uses memory mappings called "arenas"
|
| 489 |
+
with a fixed size of 256 KiB. It falls back to :c:func:`PyMem_RawMalloc` and
|
| 490 |
+
:c:func:`PyMem_RawRealloc` for allocations larger than 512 bytes.
|
| 491 |
+
|
| 492 |
+
*pymalloc* is the :ref:`default allocator <default-memory-allocators>` of the
|
| 493 |
+
:c:data:`PYMEM_DOMAIN_MEM` (ex: :c:func:`PyMem_Malloc`) and
|
| 494 |
+
:c:data:`PYMEM_DOMAIN_OBJ` (ex: :c:func:`PyObject_Malloc`) domains.
|
| 495 |
+
|
| 496 |
+
The arena allocator uses the following functions:
|
| 497 |
+
|
| 498 |
+
* :c:func:`VirtualAlloc` and :c:func:`VirtualFree` on Windows,
|
| 499 |
+
* :c:func:`mmap` and :c:func:`munmap` if available,
|
| 500 |
+
* :c:func:`malloc` and :c:func:`free` otherwise.
|
| 501 |
+
|
| 502 |
+
Customize pymalloc Arena Allocator
|
| 503 |
+
----------------------------------
|
| 504 |
+
|
| 505 |
+
.. versionadded:: 3.4
|
| 506 |
+
|
| 507 |
+
.. c:type:: PyObjectArenaAllocator
|
| 508 |
+
|
| 509 |
+
Structure used to describe an arena allocator. The structure has
|
| 510 |
+
three fields:
|
| 511 |
+
|
| 512 |
+
+--------------------------------------------------+---------------------------------------+
|
| 513 |
+
| Field | Meaning |
|
| 514 |
+
+==================================================+=======================================+
|
| 515 |
+
| ``void *ctx`` | user context passed as first argument |
|
| 516 |
+
+--------------------------------------------------+---------------------------------------+
|
| 517 |
+
| ``void* alloc(void *ctx, size_t size)`` | allocate an arena of size bytes |
|
| 518 |
+
+--------------------------------------------------+---------------------------------------+
|
| 519 |
+
| ``void free(void *ctx, size_t size, void *ptr)`` | free an arena |
|
| 520 |
+
+--------------------------------------------------+---------------------------------------+
|
| 521 |
+
|
| 522 |
+
.. c:function:: PyObject_GetArenaAllocator(PyObjectArenaAllocator *allocator)
|
| 523 |
+
|
| 524 |
+
Get the arena allocator.
|
| 525 |
+
|
| 526 |
+
.. c:function:: PyObject_SetArenaAllocator(PyObjectArenaAllocator *allocator)
|
| 527 |
+
|
| 528 |
+
Set the arena allocator.
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
tracemalloc C API
|
| 532 |
+
=================
|
| 533 |
+
|
| 534 |
+
.. versionadded:: 3.7
|
| 535 |
+
|
| 536 |
+
.. c:function:: int PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr, size_t size)
|
| 537 |
+
|
| 538 |
+
Track an allocated memory block in the :mod:`tracemalloc` module.
|
| 539 |
+
|
| 540 |
+
Return ``0`` on success, return ``-1`` on error (failed to allocate memory to
|
| 541 |
+
store the trace). Return ``-2`` if tracemalloc is disabled.
|
| 542 |
+
|
| 543 |
+
If memory block is already tracked, update the existing trace.
|
| 544 |
+
|
| 545 |
+
.. c:function:: int PyTraceMalloc_Untrack(unsigned int domain, uintptr_t ptr)
|
| 546 |
+
|
| 547 |
+
Untrack an allocated memory block in the :mod:`tracemalloc` module.
|
| 548 |
+
Do nothing if the block was not tracked.
|
| 549 |
+
|
| 550 |
+
Return ``-2`` if tracemalloc is disabled, otherwise return ``0``.
|
| 551 |
+
|
| 552 |
+
|
| 553 |
+
.. _memoryexamples:
|
| 554 |
+
|
| 555 |
+
Examples
|
| 556 |
+
========
|
| 557 |
+
|
| 558 |
+
Here is the example from section :ref:`memoryoverview`, rewritten so that the
|
| 559 |
+
I/O buffer is allocated from the Python heap by using the first function set::
|
| 560 |
+
|
| 561 |
+
PyObject *res;
|
| 562 |
+
char *buf = (char *) PyMem_Malloc(BUFSIZ); /* for I/O */
|
| 563 |
+
|
| 564 |
+
if (buf == NULL)
|
| 565 |
+
return PyErr_NoMemory();
|
| 566 |
+
/* ...Do some I/O operation involving buf... */
|
| 567 |
+
res = PyBytes_FromString(buf);
|
| 568 |
+
PyMem_Free(buf); /* allocated with PyMem_Malloc */
|
| 569 |
+
return res;
|
| 570 |
+
|
| 571 |
+
The same code using the type-oriented function set::
|
| 572 |
+
|
| 573 |
+
PyObject *res;
|
| 574 |
+
char *buf = PyMem_New(char, BUFSIZ); /* for I/O */
|
| 575 |
+
|
| 576 |
+
if (buf == NULL)
|
| 577 |
+
return PyErr_NoMemory();
|
| 578 |
+
/* ...Do some I/O operation involving buf... */
|
| 579 |
+
res = PyBytes_FromString(buf);
|
| 580 |
+
PyMem_Del(buf); /* allocated with PyMem_New */
|
| 581 |
+
return res;
|
| 582 |
+
|
| 583 |
+
Note that in the two examples above, the buffer is always manipulated via
|
| 584 |
+
functions belonging to the same set. Indeed, it is required to use the same
|
| 585 |
+
memory API family for a given memory block, so that the risk of mixing different
|
| 586 |
+
allocators is reduced to a minimum. The following code sequence contains two
|
| 587 |
+
errors, one of which is labeled as *fatal* because it mixes two different
|
| 588 |
+
allocators operating on different heaps. ::
|
| 589 |
+
|
| 590 |
+
char *buf1 = PyMem_New(char, BUFSIZ);
|
| 591 |
+
char *buf2 = (char *) malloc(BUFSIZ);
|
| 592 |
+
char *buf3 = (char *) PyMem_Malloc(BUFSIZ);
|
| 593 |
+
...
|
| 594 |
+
PyMem_Del(buf3); /* Wrong -- should be PyMem_Free() */
|
| 595 |
+
free(buf2); /* Right -- allocated via malloc() */
|
| 596 |
+
free(buf1); /* Fatal -- should be PyMem_Del() */
|
| 597 |
+
|
| 598 |
+
In addition to the functions aimed at handling raw memory blocks from the Python
|
| 599 |
+
heap, objects in Python are allocated and released with :c:func:`PyObject_New`,
|
| 600 |
+
:c:func:`PyObject_NewVar` and :c:func:`PyObject_Del`.
|
| 601 |
+
|
| 602 |
+
These will be explained in the next chapter on defining and implementing new
|
| 603 |
+
object types in C.
|
| 604 |
+
|
cpython_2/environment/repo/Doc/c-api/memoryview.rst
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _memoryview-objects:
|
| 4 |
+
|
| 5 |
+
.. index::
|
| 6 |
+
object: memoryview
|
| 7 |
+
|
| 8 |
+
MemoryView objects
|
| 9 |
+
------------------
|
| 10 |
+
|
| 11 |
+
A :class:`memoryview` object exposes the C level :ref:`buffer interface
|
| 12 |
+
<bufferobjects>` as a Python object which can then be passed around like
|
| 13 |
+
any other object.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
.. c:function:: PyObject *PyMemoryView_FromObject(PyObject *obj)
|
| 17 |
+
|
| 18 |
+
Create a memoryview object from an object that provides the buffer interface.
|
| 19 |
+
If *obj* supports writable buffer exports, the memoryview object will be
|
| 20 |
+
read/write, otherwise it may be either read-only or read/write at the
|
| 21 |
+
discretion of the exporter.
|
| 22 |
+
|
| 23 |
+
.. c:function:: PyObject *PyMemoryView_FromMemory(char *mem, Py_ssize_t size, int flags)
|
| 24 |
+
|
| 25 |
+
Create a memoryview object using *mem* as the underlying buffer.
|
| 26 |
+
*flags* can be one of :c:macro:`PyBUF_READ` or :c:macro:`PyBUF_WRITE`.
|
| 27 |
+
|
| 28 |
+
.. versionadded:: 3.3
|
| 29 |
+
|
| 30 |
+
.. c:function:: PyObject *PyMemoryView_FromBuffer(Py_buffer *view)
|
| 31 |
+
|
| 32 |
+
Create a memoryview object wrapping the given buffer structure *view*.
|
| 33 |
+
For simple byte buffers, :c:func:`PyMemoryView_FromMemory` is the preferred
|
| 34 |
+
function.
|
| 35 |
+
|
| 36 |
+
.. c:function:: PyObject *PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order)
|
| 37 |
+
|
| 38 |
+
Create a memoryview object to a :term:`contiguous` chunk of memory (in either
|
| 39 |
+
'C' or 'F'ortran *order*) from an object that defines the buffer
|
| 40 |
+
interface. If memory is contiguous, the memoryview object points to the
|
| 41 |
+
original memory. Otherwise, a copy is made and the memoryview points to a
|
| 42 |
+
new bytes object.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
.. c:function:: int PyMemoryView_Check(PyObject *obj)
|
| 46 |
+
|
| 47 |
+
Return true if the object *obj* is a memoryview object. It is not
|
| 48 |
+
currently allowed to create subclasses of :class:`memoryview`.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
.. c:function:: Py_buffer *PyMemoryView_GET_BUFFER(PyObject *mview)
|
| 52 |
+
|
| 53 |
+
Return a pointer to the memoryview's private copy of the exporter's buffer.
|
| 54 |
+
*mview* **must** be a memoryview instance; this macro doesn't check its type,
|
| 55 |
+
you must do it yourself or you will risk crashes.
|
| 56 |
+
|
| 57 |
+
.. c:function:: Py_buffer *PyMemoryView_GET_BASE(PyObject *mview)
|
| 58 |
+
|
| 59 |
+
Return either a pointer to the exporting object that the memoryview is based
|
| 60 |
+
on or ``NULL`` if the memoryview has been created by one of the functions
|
| 61 |
+
:c:func:`PyMemoryView_FromMemory` or :c:func:`PyMemoryView_FromBuffer`.
|
| 62 |
+
*mview* **must** be a memoryview instance.
|
| 63 |
+
|
cpython_2/environment/repo/Doc/c-api/method.rst
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _instancemethod-objects:
|
| 4 |
+
|
| 5 |
+
Instance Method Objects
|
| 6 |
+
-----------------------
|
| 7 |
+
|
| 8 |
+
.. index:: object: instancemethod
|
| 9 |
+
|
| 10 |
+
An instance method is a wrapper for a :c:data:`PyCFunction` and the new way
|
| 11 |
+
to bind a :c:data:`PyCFunction` to a class object. It replaces the former call
|
| 12 |
+
``PyMethod_New(func, NULL, class)``.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
.. c:var:: PyTypeObject PyInstanceMethod_Type
|
| 16 |
+
|
| 17 |
+
This instance of :c:type:`PyTypeObject` represents the Python instance
|
| 18 |
+
method type. It is not exposed to Python programs.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
.. c:function:: int PyInstanceMethod_Check(PyObject *o)
|
| 22 |
+
|
| 23 |
+
Return true if *o* is an instance method object (has type
|
| 24 |
+
:c:data:`PyInstanceMethod_Type`). The parameter must not be ``NULL``.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
.. c:function:: PyObject* PyInstanceMethod_New(PyObject *func)
|
| 28 |
+
|
| 29 |
+
Return a new instance method object, with *func* being any callable object
|
| 30 |
+
*func* is the function that will be called when the instance method is
|
| 31 |
+
called.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
.. c:function:: PyObject* PyInstanceMethod_Function(PyObject *im)
|
| 35 |
+
|
| 36 |
+
Return the function object associated with the instance method *im*.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
.. c:function:: PyObject* PyInstanceMethod_GET_FUNCTION(PyObject *im)
|
| 40 |
+
|
| 41 |
+
Macro version of :c:func:`PyInstanceMethod_Function` which avoids error checking.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
.. _method-objects:
|
| 45 |
+
|
| 46 |
+
Method Objects
|
| 47 |
+
--------------
|
| 48 |
+
|
| 49 |
+
.. index:: object: method
|
| 50 |
+
|
| 51 |
+
Methods are bound function objects. Methods are always bound to an instance of
|
| 52 |
+
a user-defined class. Unbound methods (methods bound to a class object) are
|
| 53 |
+
no longer available.
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
.. c:var:: PyTypeObject PyMethod_Type
|
| 57 |
+
|
| 58 |
+
.. index:: single: MethodType (in module types)
|
| 59 |
+
|
| 60 |
+
This instance of :c:type:`PyTypeObject` represents the Python method type. This
|
| 61 |
+
is exposed to Python programs as ``types.MethodType``.
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
.. c:function:: int PyMethod_Check(PyObject *o)
|
| 65 |
+
|
| 66 |
+
Return true if *o* is a method object (has type :c:data:`PyMethod_Type`). The
|
| 67 |
+
parameter must not be ``NULL``.
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
.. c:function:: PyObject* PyMethod_New(PyObject *func, PyObject *self)
|
| 71 |
+
|
| 72 |
+
Return a new method object, with *func* being any callable object and *self*
|
| 73 |
+
the instance the method should be bound. *func* is the function that will
|
| 74 |
+
be called when the method is called. *self* must not be ``NULL``.
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
.. c:function:: PyObject* PyMethod_Function(PyObject *meth)
|
| 78 |
+
|
| 79 |
+
Return the function object associated with the method *meth*.
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
.. c:function:: PyObject* PyMethod_GET_FUNCTION(PyObject *meth)
|
| 83 |
+
|
| 84 |
+
Macro version of :c:func:`PyMethod_Function` which avoids error checking.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
.. c:function:: PyObject* PyMethod_Self(PyObject *meth)
|
| 88 |
+
|
| 89 |
+
Return the instance associated with the method *meth*.
|
| 90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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _moduleobjects:
|
| 4 |
+
|
| 5 |
+
Module Objects
|
| 6 |
+
--------------
|
| 7 |
+
|
| 8 |
+
.. index:: object: module
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
.. c:var:: PyTypeObject PyModule_Type
|
| 12 |
+
|
| 13 |
+
.. index:: single: ModuleType (in module types)
|
| 14 |
+
|
| 15 |
+
This instance of :c:type:`PyTypeObject` represents the Python module type. This
|
| 16 |
+
is exposed to Python programs as ``types.ModuleType``.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
.. c:function:: int PyModule_Check(PyObject *p)
|
| 20 |
+
|
| 21 |
+
Return true if *p* is a module object, or a subtype of a module object.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
.. c:function:: int PyModule_CheckExact(PyObject *p)
|
| 25 |
+
|
| 26 |
+
Return true if *p* is a module object, but not a subtype of
|
| 27 |
+
:c:data:`PyModule_Type`.
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
.. c:function:: PyObject* PyModule_NewObject(PyObject *name)
|
| 31 |
+
|
| 32 |
+
.. index::
|
| 33 |
+
single: __name__ (module attribute)
|
| 34 |
+
single: __doc__ (module attribute)
|
| 35 |
+
single: __file__ (module attribute)
|
| 36 |
+
single: __package__ (module attribute)
|
| 37 |
+
single: __loader__ (module attribute)
|
| 38 |
+
|
| 39 |
+
Return a new module object with the :attr:`__name__` attribute set to *name*.
|
| 40 |
+
The module's :attr:`__name__`, :attr:`__doc__`, :attr:`__package__`, and
|
| 41 |
+
:attr:`__loader__` attributes are filled in (all but :attr:`__name__` are set
|
| 42 |
+
to ``None``); the caller is responsible for providing a :attr:`__file__`
|
| 43 |
+
attribute.
|
| 44 |
+
|
| 45 |
+
.. versionadded:: 3.3
|
| 46 |
+
|
| 47 |
+
.. versionchanged:: 3.4
|
| 48 |
+
:attr:`__package__` and :attr:`__loader__` are set to ``None``.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
.. c:function:: PyObject* PyModule_New(const char *name)
|
| 52 |
+
|
| 53 |
+
Similar to :c:func:`PyModule_NewObject`, but the name is a UTF-8 encoded
|
| 54 |
+
string instead of a Unicode object.
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
.. c:function:: PyObject* PyModule_GetDict(PyObject *module)
|
| 58 |
+
|
| 59 |
+
.. index:: single: __dict__ (module attribute)
|
| 60 |
+
|
| 61 |
+
Return the dictionary object that implements *module*'s namespace; this object
|
| 62 |
+
is the same as the :attr:`~object.__dict__` attribute of the module object.
|
| 63 |
+
If *module* is not a module object (or a subtype of a module object),
|
| 64 |
+
:exc:`SystemError` is raised and ``NULL`` is returned.
|
| 65 |
+
|
| 66 |
+
It is recommended extensions use other :c:func:`PyModule_\*` and
|
| 67 |
+
:c:func:`PyObject_\*` functions rather than directly manipulate a module's
|
| 68 |
+
:attr:`~object.__dict__`.
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
.. c:function:: PyObject* PyModule_GetNameObject(PyObject *module)
|
| 72 |
+
|
| 73 |
+
.. index::
|
| 74 |
+
single: __name__ (module attribute)
|
| 75 |
+
single: SystemError (built-in exception)
|
| 76 |
+
|
| 77 |
+
Return *module*'s :attr:`__name__` value. If the module does not provide one,
|
| 78 |
+
or if it is not a string, :exc:`SystemError` is raised and ``NULL`` is returned.
|
| 79 |
+
|
| 80 |
+
.. versionadded:: 3.3
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
.. c:function:: const char* PyModule_GetName(PyObject *module)
|
| 84 |
+
|
| 85 |
+
Similar to :c:func:`PyModule_GetNameObject` but return the name encoded to
|
| 86 |
+
``'utf-8'``.
|
| 87 |
+
|
| 88 |
+
.. c:function:: void* PyModule_GetState(PyObject *module)
|
| 89 |
+
|
| 90 |
+
Return the "state" of the module, that is, a pointer to the block of memory
|
| 91 |
+
allocated at module creation time, or ``NULL``. See
|
| 92 |
+
:c:member:`PyModuleDef.m_size`.
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
.. c:function:: PyModuleDef* PyModule_GetDef(PyObject *module)
|
| 96 |
+
|
| 97 |
+
Return a pointer to the :c:type:`PyModuleDef` struct from which the module was
|
| 98 |
+
created, or ``NULL`` if the module wasn't created from a definition.
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
.. c:function:: PyObject* PyModule_GetFilenameObject(PyObject *module)
|
| 102 |
+
|
| 103 |
+
.. index::
|
| 104 |
+
single: __file__ (module attribute)
|
| 105 |
+
single: SystemError (built-in exception)
|
| 106 |
+
|
| 107 |
+
Return the name of the file from which *module* was loaded using *module*'s
|
| 108 |
+
:attr:`__file__` attribute. If this is not defined, or if it is not a
|
| 109 |
+
unicode string, raise :exc:`SystemError` and return ``NULL``; otherwise return
|
| 110 |
+
a reference to a Unicode object.
|
| 111 |
+
|
| 112 |
+
.. versionadded:: 3.2
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
.. c:function:: const char* PyModule_GetFilename(PyObject *module)
|
| 116 |
+
|
| 117 |
+
Similar to :c:func:`PyModule_GetFilenameObject` but return the filename
|
| 118 |
+
encoded to 'utf-8'.
|
| 119 |
+
|
| 120 |
+
.. deprecated:: 3.2
|
| 121 |
+
:c:func:`PyModule_GetFilename` raises :c:type:`UnicodeEncodeError` on
|
| 122 |
+
unencodable filenames, use :c:func:`PyModule_GetFilenameObject` instead.
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
.. _initializing-modules:
|
| 126 |
+
|
| 127 |
+
Initializing C modules
|
| 128 |
+
^^^^^^^^^^^^^^^^^^^^^^
|
| 129 |
+
|
| 130 |
+
Modules objects are usually created from extension modules (shared libraries
|
| 131 |
+
which export an initialization function), or compiled-in modules
|
| 132 |
+
(where the initialization function is added using :c:func:`PyImport_AppendInittab`).
|
| 133 |
+
See :ref:`building` or :ref:`extending-with-embedding` for details.
|
| 134 |
+
|
| 135 |
+
The initialization function can either pass a module definition instance
|
| 136 |
+
to :c:func:`PyModule_Create`, and return the resulting module object,
|
| 137 |
+
or request "multi-phase initialization" by returning the definition struct itself.
|
| 138 |
+
|
| 139 |
+
.. c:type:: PyModuleDef
|
| 140 |
+
|
| 141 |
+
The module definition struct, which holds all information needed to create
|
| 142 |
+
a module object. There is usually only one statically initialized variable
|
| 143 |
+
of this type for each module.
|
| 144 |
+
|
| 145 |
+
.. c:member:: PyModuleDef_Base m_base
|
| 146 |
+
|
| 147 |
+
Always initialize this member to :const:`PyModuleDef_HEAD_INIT`.
|
| 148 |
+
|
| 149 |
+
.. c:member:: const char *m_name
|
| 150 |
+
|
| 151 |
+
Name for the new module.
|
| 152 |
+
|
| 153 |
+
.. c:member:: const char *m_doc
|
| 154 |
+
|
| 155 |
+
Docstring for the module; usually a docstring variable created with
|
| 156 |
+
:c:macro:`PyDoc_STRVAR` is used.
|
| 157 |
+
|
| 158 |
+
.. c:member:: Py_ssize_t m_size
|
| 159 |
+
|
| 160 |
+
Module state may be kept in a per-module memory area that can be
|
| 161 |
+
retrieved with :c:func:`PyModule_GetState`, rather than in static globals.
|
| 162 |
+
This makes modules safe for use in multiple sub-interpreters.
|
| 163 |
+
|
| 164 |
+
This memory area is allocated based on *m_size* on module creation,
|
| 165 |
+
and freed when the module object is deallocated, after the
|
| 166 |
+
:c:member:`m_free` function has been called, if present.
|
| 167 |
+
|
| 168 |
+
Setting ``m_size`` to ``-1`` means that the module does not support
|
| 169 |
+
sub-interpreters, because it has global state.
|
| 170 |
+
|
| 171 |
+
Setting it to a non-negative value means that the module can be
|
| 172 |
+
re-initialized and specifies the additional amount of memory it requires
|
| 173 |
+
for its state. Non-negative ``m_size`` is required for multi-phase
|
| 174 |
+
initialization.
|
| 175 |
+
|
| 176 |
+
See :PEP:`3121` for more details.
|
| 177 |
+
|
| 178 |
+
.. c:member:: PyMethodDef* m_methods
|
| 179 |
+
|
| 180 |
+
A pointer to a table of module-level functions, described by
|
| 181 |
+
:c:type:`PyMethodDef` values. Can be ``NULL`` if no functions are present.
|
| 182 |
+
|
| 183 |
+
.. c:member:: PyModuleDef_Slot* m_slots
|
| 184 |
+
|
| 185 |
+
An array of slot definitions for multi-phase initialization, terminated by
|
| 186 |
+
a ``{0, NULL}`` entry.
|
| 187 |
+
When using single-phase initialization, *m_slots* must be ``NULL``.
|
| 188 |
+
|
| 189 |
+
.. versionchanged:: 3.5
|
| 190 |
+
|
| 191 |
+
Prior to version 3.5, this member was always set to ``NULL``,
|
| 192 |
+
and was defined as:
|
| 193 |
+
|
| 194 |
+
.. c:member:: inquiry m_reload
|
| 195 |
+
|
| 196 |
+
.. c:member:: traverseproc m_traverse
|
| 197 |
+
|
| 198 |
+
A traversal function to call during GC traversal of the module object, or
|
| 199 |
+
``NULL`` if not needed.
|
| 200 |
+
|
| 201 |
+
This function is not called if the module state was requested but is not
|
| 202 |
+
allocated yet. This is the case immediately after the module is created
|
| 203 |
+
and before the module is executed (:c:data:`Py_mod_exec` function). More
|
| 204 |
+
precisely, this function is not called if :c:member:`m_size` is greater
|
| 205 |
+
than 0 and the module state (as returned by :c:func:`PyModule_GetState`)
|
| 206 |
+
is ``NULL``.
|
| 207 |
+
|
| 208 |
+
.. versionchanged:: 3.9
|
| 209 |
+
No longer called before the module state is allocated.
|
| 210 |
+
|
| 211 |
+
.. c:member:: inquiry m_clear
|
| 212 |
+
|
| 213 |
+
A clear function to call during GC clearing of the module object, or
|
| 214 |
+
``NULL`` if not needed.
|
| 215 |
+
|
| 216 |
+
This function is not called if the module state was requested but is not
|
| 217 |
+
allocated yet. This is the case immediately after the module is created
|
| 218 |
+
and before the module is executed (:c:data:`Py_mod_exec` function). More
|
| 219 |
+
precisely, this function is not called if :c:member:`m_size` is greater
|
| 220 |
+
than 0 and the module state (as returned by :c:func:`PyModule_GetState`)
|
| 221 |
+
is ``NULL``.
|
| 222 |
+
|
| 223 |
+
.. versionchanged:: 3.9
|
| 224 |
+
No longer called before the module state is allocated.
|
| 225 |
+
|
| 226 |
+
.. c:member:: freefunc m_free
|
| 227 |
+
|
| 228 |
+
A function to call during deallocation of the module object, or ``NULL``
|
| 229 |
+
if not needed.
|
| 230 |
+
|
| 231 |
+
This function is not called if the module state was requested but is not
|
| 232 |
+
allocated yet. This is the case immediately after the module is created
|
| 233 |
+
and before the module is executed (:c:data:`Py_mod_exec` function). More
|
| 234 |
+
precisely, this function is not called if :c:member:`m_size` is greater
|
| 235 |
+
than 0 and the module state (as returned by :c:func:`PyModule_GetState`)
|
| 236 |
+
is ``NULL``.
|
| 237 |
+
|
| 238 |
+
.. versionchanged:: 3.9
|
| 239 |
+
No longer called before the module state is allocated.
|
| 240 |
+
|
| 241 |
+
Single-phase initialization
|
| 242 |
+
...........................
|
| 243 |
+
|
| 244 |
+
The module initialization function may create and return the module object
|
| 245 |
+
directly. This is referred to as "single-phase initialization", and uses one
|
| 246 |
+
of the following two module creation functions:
|
| 247 |
+
|
| 248 |
+
.. c:function:: PyObject* PyModule_Create(PyModuleDef *def)
|
| 249 |
+
|
| 250 |
+
Create a new module object, given the definition in *def*. This behaves
|
| 251 |
+
like :c:func:`PyModule_Create2` with *module_api_version* set to
|
| 252 |
+
:const:`PYTHON_API_VERSION`.
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
.. c:function:: PyObject* PyModule_Create2(PyModuleDef *def, int module_api_version)
|
| 256 |
+
|
| 257 |
+
Create a new module object, given the definition in *def*, assuming the
|
| 258 |
+
API version *module_api_version*. If that version does not match the version
|
| 259 |
+
of the running interpreter, a :exc:`RuntimeWarning` is emitted.
|
| 260 |
+
|
| 261 |
+
.. note::
|
| 262 |
+
|
| 263 |
+
Most uses of this function should be using :c:func:`PyModule_Create`
|
| 264 |
+
instead; only use this if you are sure you need it.
|
| 265 |
+
|
| 266 |
+
Before it is returned from in the initialization function, the resulting module
|
| 267 |
+
object is typically populated using functions like :c:func:`PyModule_AddObject`.
|
| 268 |
+
|
| 269 |
+
.. _multi-phase-initialization:
|
| 270 |
+
|
| 271 |
+
Multi-phase initialization
|
| 272 |
+
..........................
|
| 273 |
+
|
| 274 |
+
An alternate way to specify extensions is to request "multi-phase initialization".
|
| 275 |
+
Extension modules created this way behave more like Python modules: the
|
| 276 |
+
initialization is split between the *creation phase*, when the module object
|
| 277 |
+
is created, and the *execution phase*, when it is populated.
|
| 278 |
+
The distinction is similar to the :py:meth:`__new__` and :py:meth:`__init__` methods
|
| 279 |
+
of classes.
|
| 280 |
+
|
| 281 |
+
Unlike modules created using single-phase initialization, these modules are not
|
| 282 |
+
singletons: if the *sys.modules* entry is removed and the module is re-imported,
|
| 283 |
+
a new module object is created, and the old module is subject to normal garbage
|
| 284 |
+
collection -- as with Python modules.
|
| 285 |
+
By default, multiple modules created from the same definition should be
|
| 286 |
+
independent: changes to one should not affect the others.
|
| 287 |
+
This means that all state should be specific to the module object (using e.g.
|
| 288 |
+
using :c:func:`PyModule_GetState`), or its contents (such as the module's
|
| 289 |
+
:attr:`__dict__` or individual classes created with :c:func:`PyType_FromSpec`).
|
| 290 |
+
|
| 291 |
+
All modules created using multi-phase initialization are expected to support
|
| 292 |
+
:ref:`sub-interpreters <sub-interpreter-support>`. Making sure multiple modules
|
| 293 |
+
are independent is typically enough to achieve this.
|
| 294 |
+
|
| 295 |
+
To request multi-phase initialization, the initialization function
|
| 296 |
+
(PyInit_modulename) returns a :c:type:`PyModuleDef` instance with non-empty
|
| 297 |
+
:c:member:`~PyModuleDef.m_slots`. Before it is returned, the ``PyModuleDef``
|
| 298 |
+
instance must be initialized with the following function:
|
| 299 |
+
|
| 300 |
+
.. c:function:: PyObject* PyModuleDef_Init(PyModuleDef *def)
|
| 301 |
+
|
| 302 |
+
Ensures a module definition is a properly initialized Python object that
|
| 303 |
+
correctly reports its type and reference count.
|
| 304 |
+
|
| 305 |
+
Returns *def* cast to ``PyObject*``, or ``NULL`` if an error occurred.
|
| 306 |
+
|
| 307 |
+
.. versionadded:: 3.5
|
| 308 |
+
|
| 309 |
+
The *m_slots* member of the module definition must point to an array of
|
| 310 |
+
``PyModuleDef_Slot`` structures:
|
| 311 |
+
|
| 312 |
+
.. c:type:: PyModuleDef_Slot
|
| 313 |
+
|
| 314 |
+
.. c:member:: int slot
|
| 315 |
+
|
| 316 |
+
A slot ID, chosen from the available values explained below.
|
| 317 |
+
|
| 318 |
+
.. c:member:: void* value
|
| 319 |
+
|
| 320 |
+
Value of the slot, whose meaning depends on the slot ID.
|
| 321 |
+
|
| 322 |
+
.. versionadded:: 3.5
|
| 323 |
+
|
| 324 |
+
The *m_slots* array must be terminated by a slot with id 0.
|
| 325 |
+
|
| 326 |
+
The available slot types are:
|
| 327 |
+
|
| 328 |
+
.. c:var:: Py_mod_create
|
| 329 |
+
|
| 330 |
+
Specifies a function that is called to create the module object itself.
|
| 331 |
+
The *value* pointer of this slot must point to a function of the signature:
|
| 332 |
+
|
| 333 |
+
.. c:function:: PyObject* create_module(PyObject *spec, PyModuleDef *def)
|
| 334 |
+
|
| 335 |
+
The function receives a :py:class:`~importlib.machinery.ModuleSpec`
|
| 336 |
+
instance, as defined in :PEP:`451`, and the module definition.
|
| 337 |
+
It should return a new module object, or set an error
|
| 338 |
+
and return ``NULL``.
|
| 339 |
+
|
| 340 |
+
This function should be kept minimal. In particular, it should not
|
| 341 |
+
call arbitrary Python code, as trying to import the same module again may
|
| 342 |
+
result in an infinite loop.
|
| 343 |
+
|
| 344 |
+
Multiple ``Py_mod_create`` slots may not be specified in one module
|
| 345 |
+
definition.
|
| 346 |
+
|
| 347 |
+
If ``Py_mod_create`` is not specified, the import machinery will create
|
| 348 |
+
a normal module object using :c:func:`PyModule_New`. The name is taken from
|
| 349 |
+
*spec*, not the definition, to allow extension modules to dynamically adjust
|
| 350 |
+
to their place in the module hierarchy and be imported under different
|
| 351 |
+
names through symlinks, all while sharing a single module definition.
|
| 352 |
+
|
| 353 |
+
There is no requirement for the returned object to be an instance of
|
| 354 |
+
:c:type:`PyModule_Type`. Any type can be used, as long as it supports
|
| 355 |
+
setting and getting import-related attributes.
|
| 356 |
+
However, only ``PyModule_Type`` instances may be returned if the
|
| 357 |
+
``PyModuleDef`` has non-``NULL`` ``m_traverse``, ``m_clear``,
|
| 358 |
+
``m_free``; non-zero ``m_size``; or slots other than ``Py_mod_create``.
|
| 359 |
+
|
| 360 |
+
.. c:var:: Py_mod_exec
|
| 361 |
+
|
| 362 |
+
Specifies a function that is called to *execute* the module.
|
| 363 |
+
This is equivalent to executing the code of a Python module: typically,
|
| 364 |
+
this function adds classes and constants to the module.
|
| 365 |
+
The signature of the function is:
|
| 366 |
+
|
| 367 |
+
.. c:function:: int exec_module(PyObject* module)
|
| 368 |
+
|
| 369 |
+
If multiple ``Py_mod_exec`` slots are specified, they are processed in the
|
| 370 |
+
order they appear in the *m_slots* array.
|
| 371 |
+
|
| 372 |
+
See :PEP:`489` for more details on multi-phase initialization.
|
| 373 |
+
|
| 374 |
+
Low-level module creation functions
|
| 375 |
+
...................................
|
| 376 |
+
|
| 377 |
+
The following functions are called under the hood when using multi-phase
|
| 378 |
+
initialization. They can be used directly, for example when creating module
|
| 379 |
+
objects dynamically. Note that both ``PyModule_FromDefAndSpec`` and
|
| 380 |
+
``PyModule_ExecDef`` must be called to fully initialize a module.
|
| 381 |
+
|
| 382 |
+
.. c:function:: PyObject * PyModule_FromDefAndSpec(PyModuleDef *def, PyObject *spec)
|
| 383 |
+
|
| 384 |
+
Create a new module object, given the definition in *module* and the
|
| 385 |
+
ModuleSpec *spec*. This behaves like :c:func:`PyModule_FromDefAndSpec2`
|
| 386 |
+
with *module_api_version* set to :const:`PYTHON_API_VERSION`.
|
| 387 |
+
|
| 388 |
+
.. versionadded:: 3.5
|
| 389 |
+
|
| 390 |
+
.. c:function:: PyObject * PyModule_FromDefAndSpec2(PyModuleDef *def, PyObject *spec, int module_api_version)
|
| 391 |
+
|
| 392 |
+
Create a new module object, given the definition in *module* and the
|
| 393 |
+
ModuleSpec *spec*, assuming the API version *module_api_version*.
|
| 394 |
+
If that version does not match the version of the running interpreter,
|
| 395 |
+
a :exc:`RuntimeWarning` is emitted.
|
| 396 |
+
|
| 397 |
+
.. note::
|
| 398 |
+
|
| 399 |
+
Most uses of this function should be using :c:func:`PyModule_FromDefAndSpec`
|
| 400 |
+
instead; only use this if you are sure you need it.
|
| 401 |
+
|
| 402 |
+
.. versionadded:: 3.5
|
| 403 |
+
|
| 404 |
+
.. c:function:: int PyModule_ExecDef(PyObject *module, PyModuleDef *def)
|
| 405 |
+
|
| 406 |
+
Process any execution slots (:c:data:`Py_mod_exec`) given in *def*.
|
| 407 |
+
|
| 408 |
+
.. versionadded:: 3.5
|
| 409 |
+
|
| 410 |
+
.. c:function:: int PyModule_SetDocString(PyObject *module, const char *docstring)
|
| 411 |
+
|
| 412 |
+
Set the docstring for *module* to *docstring*.
|
| 413 |
+
This function is called automatically when creating a module from
|
| 414 |
+
``PyModuleDef``, using either ``PyModule_Create`` or
|
| 415 |
+
``PyModule_FromDefAndSpec``.
|
| 416 |
+
|
| 417 |
+
.. versionadded:: 3.5
|
| 418 |
+
|
| 419 |
+
.. c:function:: int PyModule_AddFunctions(PyObject *module, PyMethodDef *functions)
|
| 420 |
+
|
| 421 |
+
Add the functions from the ``NULL`` terminated *functions* array to *module*.
|
| 422 |
+
Refer to the :c:type:`PyMethodDef` documentation for details on individual
|
| 423 |
+
entries (due to the lack of a shared module namespace, module level
|
| 424 |
+
"functions" implemented in C typically receive the module as their first
|
| 425 |
+
parameter, making them similar to instance methods on Python classes).
|
| 426 |
+
This function is called automatically when creating a module from
|
| 427 |
+
``PyModuleDef``, using either ``PyModule_Create`` or
|
| 428 |
+
``PyModule_FromDefAndSpec``.
|
| 429 |
+
|
| 430 |
+
.. versionadded:: 3.5
|
| 431 |
+
|
| 432 |
+
Support functions
|
| 433 |
+
.................
|
| 434 |
+
|
| 435 |
+
The module initialization function (if using single phase initialization) or
|
| 436 |
+
a function called from a module execution slot (if using multi-phase
|
| 437 |
+
initialization), can use the following functions to help initialize the module
|
| 438 |
+
state:
|
| 439 |
+
|
| 440 |
+
.. c:function:: int PyModule_AddObject(PyObject *module, const char *name, PyObject *value)
|
| 441 |
+
|
| 442 |
+
Add an object to *module* as *name*. This is a convenience function which can
|
| 443 |
+
be used from the module's initialization function. This steals a reference to
|
| 444 |
+
*value* on success. Return ``-1`` on error, ``0`` on success.
|
| 445 |
+
|
| 446 |
+
.. note::
|
| 447 |
+
|
| 448 |
+
Unlike other functions that steal references, ``PyModule_AddObject()`` only
|
| 449 |
+
decrements the reference count of *value* **on success**.
|
| 450 |
+
|
| 451 |
+
This means that its return value must be checked, and calling code must
|
| 452 |
+
:c:func:`Py_DECREF` *value* manually on error. Example usage::
|
| 453 |
+
|
| 454 |
+
Py_INCREF(spam);
|
| 455 |
+
if (PyModule_AddObject(module, "spam", spam) < 0) {
|
| 456 |
+
Py_DECREF(module);
|
| 457 |
+
Py_DECREF(spam);
|
| 458 |
+
return NULL;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
.. c:function:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value)
|
| 462 |
+
|
| 463 |
+
Add an integer constant to *module* as *name*. This convenience function can be
|
| 464 |
+
used from the module's initialization function. Return ``-1`` on error, ``0`` on
|
| 465 |
+
success.
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
.. c:function:: int PyModule_AddStringConstant(PyObject *module, const char *name, const char *value)
|
| 469 |
+
|
| 470 |
+
Add a string constant to *module* as *name*. This convenience function can be
|
| 471 |
+
used from the module's initialization function. The string *value* must be
|
| 472 |
+
``NULL``-terminated. Return ``-1`` on error, ``0`` on success.
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
.. c:function:: int PyModule_AddIntMacro(PyObject *module, macro)
|
| 476 |
+
|
| 477 |
+
Add an int constant to *module*. The name and the value are taken from
|
| 478 |
+
*macro*. For example ``PyModule_AddIntMacro(module, AF_INET)`` adds the int
|
| 479 |
+
constant *AF_INET* with the value of *AF_INET* to *module*.
|
| 480 |
+
Return ``-1`` on error, ``0`` on success.
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
.. c:function:: int PyModule_AddStringMacro(PyObject *module, macro)
|
| 484 |
+
|
| 485 |
+
Add a string constant to *module*.
|
| 486 |
+
|
| 487 |
+
.. c:function:: int PyModule_AddType(PyObject *module, PyTypeObject *type)
|
| 488 |
+
|
| 489 |
+
Add a type object to *module*.
|
| 490 |
+
The type object is finalized by calling internally :c:func:`PyType_Ready`.
|
| 491 |
+
The name of the type object is taken from the last component of
|
| 492 |
+
:c:member:`~PyTypeObject.tp_name` after dot.
|
| 493 |
+
Return ``-1`` on error, ``0`` on success.
|
| 494 |
+
|
| 495 |
+
.. versionadded:: 3.9
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
Module lookup
|
| 499 |
+
^^^^^^^^^^^^^
|
| 500 |
+
|
| 501 |
+
Single-phase initialization creates singleton modules that can be looked up
|
| 502 |
+
in the context of the current interpreter. This allows the module object to be
|
| 503 |
+
retrieved later with only a reference to the module definition.
|
| 504 |
+
|
| 505 |
+
These functions will not work on modules created using multi-phase initialization,
|
| 506 |
+
since multiple such modules can be created from a single definition.
|
| 507 |
+
|
| 508 |
+
.. c:function:: PyObject* PyState_FindModule(PyModuleDef *def)
|
| 509 |
+
|
| 510 |
+
Returns the module object that was created from *def* for the current interpreter.
|
| 511 |
+
This method requires that the module object has been attached to the interpreter state with
|
| 512 |
+
:c:func:`PyState_AddModule` beforehand. In case the corresponding module object is not
|
| 513 |
+
found or has not been attached to the interpreter state yet, it returns ``NULL``.
|
| 514 |
+
|
| 515 |
+
.. c:function:: int PyState_AddModule(PyObject *module, PyModuleDef *def)
|
| 516 |
+
|
| 517 |
+
Attaches the module object passed to the function to the interpreter state. This allows
|
| 518 |
+
the module object to be accessible via :c:func:`PyState_FindModule`.
|
| 519 |
+
|
| 520 |
+
Only effective on modules created using single-phase initialization.
|
| 521 |
+
|
| 522 |
+
Python calls ``PyState_AddModule`` automatically after importing a module,
|
| 523 |
+
so it is unnecessary (but harmless) to call it from module initialization
|
| 524 |
+
code. An explicit call is needed only if the module's own init code
|
| 525 |
+
subsequently calls ``PyState_FindModule``.
|
| 526 |
+
The function is mainly intended for implementing alternative import
|
| 527 |
+
mechanisms (either by calling it directly, or by referring to its
|
| 528 |
+
implementation for details of the required state updates).
|
| 529 |
+
|
| 530 |
+
The caller must hold the GIL.
|
| 531 |
+
|
| 532 |
+
Return 0 on success or -1 on failure.
|
| 533 |
+
|
| 534 |
+
.. versionadded:: 3.3
|
| 535 |
+
|
| 536 |
+
.. c:function:: int PyState_RemoveModule(PyModuleDef *def)
|
| 537 |
+
|
| 538 |
+
Removes the module object created from *def* from the interpreter state.
|
| 539 |
+
Return 0 on success or -1 on failure.
|
| 540 |
+
|
| 541 |
+
The caller must hold the GIL.
|
| 542 |
+
|
| 543 |
+
.. versionadded:: 3.3
|
cpython_2/environment/repo/Doc/c-api/none.rst
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _noneobject:
|
| 4 |
+
|
| 5 |
+
The ``None`` Object
|
| 6 |
+
-------------------
|
| 7 |
+
|
| 8 |
+
.. index:: object: None
|
| 9 |
+
|
| 10 |
+
Note that the :c:type:`PyTypeObject` for ``None`` is not directly exposed in the
|
| 11 |
+
Python/C API. Since ``None`` is a singleton, testing for object identity (using
|
| 12 |
+
``==`` in C) is sufficient. There is no :c:func:`PyNone_Check` function for the
|
| 13 |
+
same reason.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
.. c:var:: PyObject* Py_None
|
| 17 |
+
|
| 18 |
+
The Python ``None`` object, denoting lack of value. This object has no methods.
|
| 19 |
+
It needs to be treated just like any other object with respect to reference
|
| 20 |
+
counts.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
.. c:macro:: Py_RETURN_NONE
|
| 24 |
+
|
| 25 |
+
Properly handle returning :c:data:`Py_None` from within a C function (that is,
|
| 26 |
+
increment the reference count of ``None`` and return it.)
|
cpython_2/environment/repo/Doc/c-api/number.rst
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _number:
|
| 4 |
+
|
| 5 |
+
Number Protocol
|
| 6 |
+
===============
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
.. c:function:: int PyNumber_Check(PyObject *o)
|
| 10 |
+
|
| 11 |
+
Returns ``1`` if the object *o* provides numeric protocols, and false otherwise.
|
| 12 |
+
This function always succeeds.
|
| 13 |
+
|
| 14 |
+
.. versionchanged:: 3.8
|
| 15 |
+
Returns ``1`` if *o* is an index integer.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
.. c:function:: PyObject* PyNumber_Add(PyObject *o1, PyObject *o2)
|
| 19 |
+
|
| 20 |
+
Returns the result of adding *o1* and *o2*, or ``NULL`` on failure. This is the
|
| 21 |
+
equivalent of the Python expression ``o1 + o2``.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
.. c:function:: PyObject* PyNumber_Subtract(PyObject *o1, PyObject *o2)
|
| 25 |
+
|
| 26 |
+
Returns the result of subtracting *o2* from *o1*, or ``NULL`` on failure. This is
|
| 27 |
+
the equivalent of the Python expression ``o1 - o2``.
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
.. c:function:: PyObject* PyNumber_Multiply(PyObject *o1, PyObject *o2)
|
| 31 |
+
|
| 32 |
+
Returns the result of multiplying *o1* and *o2*, or ``NULL`` on failure. This is
|
| 33 |
+
the equivalent of the Python expression ``o1 * o2``.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
.. c:function:: PyObject* PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2)
|
| 37 |
+
|
| 38 |
+
Returns the result of matrix multiplication on *o1* and *o2*, or ``NULL`` on
|
| 39 |
+
failure. This is the equivalent of the Python expression ``o1 @ o2``.
|
| 40 |
+
|
| 41 |
+
.. versionadded:: 3.5
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
.. c:function:: PyObject* PyNumber_FloorDivide(PyObject *o1, PyObject *o2)
|
| 45 |
+
|
| 46 |
+
Return the floor of *o1* divided by *o2*, or ``NULL`` on failure. This is
|
| 47 |
+
equivalent to the "classic" division of integers.
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
.. c:function:: PyObject* PyNumber_TrueDivide(PyObject *o1, PyObject *o2)
|
| 51 |
+
|
| 52 |
+
Return a reasonable approximation for the mathematical value of *o1* divided by
|
| 53 |
+
*o2*, or ``NULL`` on failure. The return value is "approximate" because binary
|
| 54 |
+
floating point numbers are approximate; it is not possible to represent all real
|
| 55 |
+
numbers in base two. This function can return a floating point value when
|
| 56 |
+
passed two integers.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
.. c:function:: PyObject* PyNumber_Remainder(PyObject *o1, PyObject *o2)
|
| 60 |
+
|
| 61 |
+
Returns the remainder of dividing *o1* by *o2*, or ``NULL`` on failure. This is
|
| 62 |
+
the equivalent of the Python expression ``o1 % o2``.
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
.. c:function:: PyObject* PyNumber_Divmod(PyObject *o1, PyObject *o2)
|
| 66 |
+
|
| 67 |
+
.. index:: builtin: divmod
|
| 68 |
+
|
| 69 |
+
See the built-in function :func:`divmod`. Returns ``NULL`` on failure. This is
|
| 70 |
+
the equivalent of the Python expression ``divmod(o1, o2)``.
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
.. c:function:: PyObject* PyNumber_Power(PyObject *o1, PyObject *o2, PyObject *o3)
|
| 74 |
+
|
| 75 |
+
.. index:: builtin: pow
|
| 76 |
+
|
| 77 |
+
See the built-in function :func:`pow`. Returns ``NULL`` on failure. This is the
|
| 78 |
+
equivalent of the Python expression ``pow(o1, o2, o3)``, where *o3* is optional.
|
| 79 |
+
If *o3* is to be ignored, pass :c:data:`Py_None` in its place (passing ``NULL`` for
|
| 80 |
+
*o3* would cause an illegal memory access).
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
.. c:function:: PyObject* PyNumber_Negative(PyObject *o)
|
| 84 |
+
|
| 85 |
+
Returns the negation of *o* on success, or ``NULL`` on failure. This is the
|
| 86 |
+
equivalent of the Python expression ``-o``.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
.. c:function:: PyObject* PyNumber_Positive(PyObject *o)
|
| 90 |
+
|
| 91 |
+
Returns *o* on success, or ``NULL`` on failure. This is the equivalent of the
|
| 92 |
+
Python expression ``+o``.
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
.. c:function:: PyObject* PyNumber_Absolute(PyObject *o)
|
| 96 |
+
|
| 97 |
+
.. index:: builtin: abs
|
| 98 |
+
|
| 99 |
+
Returns the absolute value of *o*, or ``NULL`` on failure. This is the equivalent
|
| 100 |
+
of the Python expression ``abs(o)``.
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
.. c:function:: PyObject* PyNumber_Invert(PyObject *o)
|
| 104 |
+
|
| 105 |
+
Returns the bitwise negation of *o* on success, or ``NULL`` on failure. This is
|
| 106 |
+
the equivalent of the Python expression ``~o``.
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
.. c:function:: PyObject* PyNumber_Lshift(PyObject *o1, PyObject *o2)
|
| 110 |
+
|
| 111 |
+
Returns the result of left shifting *o1* by *o2* on success, or ``NULL`` on
|
| 112 |
+
failure. This is the equivalent of the Python expression ``o1 << o2``.
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
.. c:function:: PyObject* PyNumber_Rshift(PyObject *o1, PyObject *o2)
|
| 116 |
+
|
| 117 |
+
Returns the result of right shifting *o1* by *o2* on success, or ``NULL`` on
|
| 118 |
+
failure. This is the equivalent of the Python expression ``o1 >> o2``.
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
.. c:function:: PyObject* PyNumber_And(PyObject *o1, PyObject *o2)
|
| 122 |
+
|
| 123 |
+
Returns the "bitwise and" of *o1* and *o2* on success and ``NULL`` on failure.
|
| 124 |
+
This is the equivalent of the Python expression ``o1 & o2``.
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
.. c:function:: PyObject* PyNumber_Xor(PyObject *o1, PyObject *o2)
|
| 128 |
+
|
| 129 |
+
Returns the "bitwise exclusive or" of *o1* by *o2* on success, or ``NULL`` on
|
| 130 |
+
failure. This is the equivalent of the Python expression ``o1 ^ o2``.
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
.. c:function:: PyObject* PyNumber_Or(PyObject *o1, PyObject *o2)
|
| 134 |
+
|
| 135 |
+
Returns the "bitwise or" of *o1* and *o2* on success, or ``NULL`` on failure.
|
| 136 |
+
This is the equivalent of the Python expression ``o1 | o2``.
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
.. c:function:: PyObject* PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2)
|
| 140 |
+
|
| 141 |
+
Returns the result of adding *o1* and *o2*, or ``NULL`` on failure. The operation
|
| 142 |
+
is done *in-place* when *o1* supports it. This is the equivalent of the Python
|
| 143 |
+
statement ``o1 += o2``.
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
.. c:function:: PyObject* PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2)
|
| 147 |
+
|
| 148 |
+
Returns the result of subtracting *o2* from *o1*, or ``NULL`` on failure. The
|
| 149 |
+
operation is done *in-place* when *o1* supports it. This is the equivalent of
|
| 150 |
+
the Python statement ``o1 -= o2``.
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
.. c:function:: PyObject* PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2)
|
| 154 |
+
|
| 155 |
+
Returns the result of multiplying *o1* and *o2*, or ``NULL`` on failure. The
|
| 156 |
+
operation is done *in-place* when *o1* supports it. This is the equivalent of
|
| 157 |
+
the Python statement ``o1 *= o2``.
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
.. c:function:: PyObject* PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2)
|
| 161 |
+
|
| 162 |
+
Returns the result of matrix multiplication on *o1* and *o2*, or ``NULL`` on
|
| 163 |
+
failure. The operation is done *in-place* when *o1* supports it. This is
|
| 164 |
+
the equivalent of the Python statement ``o1 @= o2``.
|
| 165 |
+
|
| 166 |
+
.. versionadded:: 3.5
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
.. c:function:: PyObject* PyNumber_InPlaceFloorDivide(PyObject *o1, PyObject *o2)
|
| 170 |
+
|
| 171 |
+
Returns the mathematical floor of dividing *o1* by *o2*, or ``NULL`` on failure.
|
| 172 |
+
The operation is done *in-place* when *o1* supports it. This is the equivalent
|
| 173 |
+
of the Python statement ``o1 //= o2``.
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
.. c:function:: PyObject* PyNumber_InPlaceTrueDivide(PyObject *o1, PyObject *o2)
|
| 177 |
+
|
| 178 |
+
Return a reasonable approximation for the mathematical value of *o1* divided by
|
| 179 |
+
*o2*, or ``NULL`` on failure. The return value is "approximate" because binary
|
| 180 |
+
floating point numbers are approximate; it is not possible to represent all real
|
| 181 |
+
numbers in base two. This function can return a floating point value when
|
| 182 |
+
passed two integers. The operation is done *in-place* when *o1* supports it.
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
.. c:function:: PyObject* PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2)
|
| 186 |
+
|
| 187 |
+
Returns the remainder of dividing *o1* by *o2*, or ``NULL`` on failure. The
|
| 188 |
+
operation is done *in-place* when *o1* supports it. This is the equivalent of
|
| 189 |
+
the Python statement ``o1 %= o2``.
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
.. c:function:: PyObject* PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3)
|
| 193 |
+
|
| 194 |
+
.. index:: builtin: pow
|
| 195 |
+
|
| 196 |
+
See the built-in function :func:`pow`. Returns ``NULL`` on failure. The operation
|
| 197 |
+
is done *in-place* when *o1* supports it. This is the equivalent of the Python
|
| 198 |
+
statement ``o1 **= o2`` when o3 is :c:data:`Py_None`, or an in-place variant of
|
| 199 |
+
``pow(o1, o2, o3)`` otherwise. If *o3* is to be ignored, pass :c:data:`Py_None`
|
| 200 |
+
in its place (passing ``NULL`` for *o3* would cause an illegal memory access).
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
.. c:function:: PyObject* PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2)
|
| 204 |
+
|
| 205 |
+
Returns the result of left shifting *o1* by *o2* on success, or ``NULL`` on
|
| 206 |
+
failure. The operation is done *in-place* when *o1* supports it. This is the
|
| 207 |
+
equivalent of the Python statement ``o1 <<= o2``.
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
.. c:function:: PyObject* PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2)
|
| 211 |
+
|
| 212 |
+
Returns the result of right shifting *o1* by *o2* on success, or ``NULL`` on
|
| 213 |
+
failure. The operation is done *in-place* when *o1* supports it. This is the
|
| 214 |
+
equivalent of the Python statement ``o1 >>= o2``.
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
.. c:function:: PyObject* PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2)
|
| 218 |
+
|
| 219 |
+
Returns the "bitwise and" of *o1* and *o2* on success and ``NULL`` on failure. The
|
| 220 |
+
operation is done *in-place* when *o1* supports it. This is the equivalent of
|
| 221 |
+
the Python statement ``o1 &= o2``.
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
.. c:function:: PyObject* PyNumber_InPlaceXor(PyObject *o1, PyObject *o2)
|
| 225 |
+
|
| 226 |
+
Returns the "bitwise exclusive or" of *o1* by *o2* on success, or ``NULL`` on
|
| 227 |
+
failure. The operation is done *in-place* when *o1* supports it. This is the
|
| 228 |
+
equivalent of the Python statement ``o1 ^= o2``.
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
.. c:function:: PyObject* PyNumber_InPlaceOr(PyObject *o1, PyObject *o2)
|
| 232 |
+
|
| 233 |
+
Returns the "bitwise or" of *o1* and *o2* on success, or ``NULL`` on failure. The
|
| 234 |
+
operation is done *in-place* when *o1* supports it. This is the equivalent of
|
| 235 |
+
the Python statement ``o1 |= o2``.
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
.. c:function:: PyObject* PyNumber_Long(PyObject *o)
|
| 239 |
+
|
| 240 |
+
.. index:: builtin: int
|
| 241 |
+
|
| 242 |
+
Returns the *o* converted to an integer object on success, or ``NULL`` on
|
| 243 |
+
failure. This is the equivalent of the Python expression ``int(o)``.
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
.. c:function:: PyObject* PyNumber_Float(PyObject *o)
|
| 247 |
+
|
| 248 |
+
.. index:: builtin: float
|
| 249 |
+
|
| 250 |
+
Returns the *o* converted to a float object on success, or ``NULL`` on failure.
|
| 251 |
+
This is the equivalent of the Python expression ``float(o)``.
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
.. c:function:: PyObject* PyNumber_Index(PyObject *o)
|
| 255 |
+
|
| 256 |
+
Returns the *o* converted to a Python int on success or ``NULL`` with a
|
| 257 |
+
:exc:`TypeError` exception raised on failure.
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
.. c:function:: PyObject* PyNumber_ToBase(PyObject *n, int base)
|
| 261 |
+
|
| 262 |
+
Returns the integer *n* converted to base *base* as a string. The *base*
|
| 263 |
+
argument must be one of 2, 8, 10, or 16. For base 2, 8, or 16, the
|
| 264 |
+
returned string is prefixed with a base marker of ``'0b'``, ``'0o'``, or
|
| 265 |
+
``'0x'``, respectively. If *n* is not a Python int, it is converted with
|
| 266 |
+
:c:func:`PyNumber_Index` first.
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
.. c:function:: Py_ssize_t PyNumber_AsSsize_t(PyObject *o, PyObject *exc)
|
| 270 |
+
|
| 271 |
+
Returns *o* converted to a Py_ssize_t value if *o* can be interpreted as an
|
| 272 |
+
integer. If the call fails, an exception is raised and ``-1`` is returned.
|
| 273 |
+
|
| 274 |
+
If *o* can be converted to a Python int but the attempt to
|
| 275 |
+
convert to a Py_ssize_t value would raise an :exc:`OverflowError`, then the
|
| 276 |
+
*exc* argument is the type of exception that will be raised (usually
|
| 277 |
+
:exc:`IndexError` or :exc:`OverflowError`). If *exc* is ``NULL``, then the
|
| 278 |
+
exception is cleared and the value is clipped to ``PY_SSIZE_T_MIN`` for a negative
|
| 279 |
+
integer or ``PY_SSIZE_T_MAX`` for a positive integer.
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
.. c:function:: int PyIndex_Check(PyObject *o)
|
| 283 |
+
|
| 284 |
+
Returns ``1`` if *o* is an index integer (has the nb_index slot of the
|
| 285 |
+
tp_as_number structure filled in), and ``0`` otherwise.
|
| 286 |
+
This function always succeeds.
|
cpython_2/environment/repo/Doc/c-api/objbuffer.rst
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
Old Buffer Protocol
|
| 4 |
+
-------------------
|
| 5 |
+
|
| 6 |
+
.. deprecated:: 3.0
|
| 7 |
+
|
| 8 |
+
These functions were part of the "old buffer protocol" API in Python 2.
|
| 9 |
+
In Python 3, this protocol doesn't exist anymore but the functions are still
|
| 10 |
+
exposed to ease porting 2.x code. They act as a compatibility wrapper
|
| 11 |
+
around the :ref:`new buffer protocol <bufferobjects>`, but they don't give
|
| 12 |
+
you control over the lifetime of the resources acquired when a buffer is
|
| 13 |
+
exported.
|
| 14 |
+
|
| 15 |
+
Therefore, it is recommended that you call :c:func:`PyObject_GetBuffer`
|
| 16 |
+
(or the ``y*`` or ``w*`` :ref:`format codes <arg-parsing>` with the
|
| 17 |
+
:c:func:`PyArg_ParseTuple` family of functions) to get a buffer view over
|
| 18 |
+
an object, and :c:func:`PyBuffer_Release` when the buffer view can be released.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
.. c:function:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len)
|
| 22 |
+
|
| 23 |
+
Returns a pointer to a read-only memory location usable as character-based
|
| 24 |
+
input. The *obj* argument must support the single-segment character buffer
|
| 25 |
+
interface. On success, returns ``0``, sets *buffer* to the memory location
|
| 26 |
+
and *buffer_len* to the buffer length. Returns ``-1`` and sets a
|
| 27 |
+
:exc:`TypeError` on error.
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
.. c:function:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
|
| 31 |
+
|
| 32 |
+
Returns a pointer to a read-only memory location containing arbitrary data.
|
| 33 |
+
The *obj* argument must support the single-segment readable buffer
|
| 34 |
+
interface. On success, returns ``0``, sets *buffer* to the memory location
|
| 35 |
+
and *buffer_len* to the buffer length. Returns ``-1`` and sets a
|
| 36 |
+
:exc:`TypeError` on error.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
.. c:function:: int PyObject_CheckReadBuffer(PyObject *o)
|
| 40 |
+
|
| 41 |
+
Returns ``1`` if *o* supports the single-segment readable buffer interface.
|
| 42 |
+
Otherwise returns ``0``. This function always succeeds.
|
| 43 |
+
|
| 44 |
+
Note that this function tries to get and release a buffer, and exceptions
|
| 45 |
+
which occur while calling corresponding functions will get suppressed.
|
| 46 |
+
To get error reporting use :c:func:`PyObject_GetBuffer()` instead.
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
.. c:function:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)
|
| 50 |
+
|
| 51 |
+
Returns a pointer to a writable memory location. The *obj* argument must
|
| 52 |
+
support the single-segment, character buffer interface. On success,
|
| 53 |
+
returns ``0``, sets *buffer* to the memory location and *buffer_len* to the
|
| 54 |
+
buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error.
|
| 55 |
+
|
cpython_2/environment/repo/Doc/c-api/object.rst
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _object:
|
| 4 |
+
|
| 5 |
+
Object Protocol
|
| 6 |
+
===============
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
.. c:var:: PyObject* Py_NotImplemented
|
| 10 |
+
|
| 11 |
+
The ``NotImplemented`` singleton, used to signal that an operation is
|
| 12 |
+
not implemented for the given type combination.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
.. c:macro:: Py_RETURN_NOTIMPLEMENTED
|
| 16 |
+
|
| 17 |
+
Properly handle returning :c:data:`Py_NotImplemented` from within a C
|
| 18 |
+
function (that is, increment the reference count of NotImplemented and
|
| 19 |
+
return it).
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
.. c:function:: int PyObject_Print(PyObject *o, FILE *fp, int flags)
|
| 23 |
+
|
| 24 |
+
Print an object *o*, on file *fp*. Returns ``-1`` on error. The flags argument
|
| 25 |
+
is used to enable certain printing options. The only option currently supported
|
| 26 |
+
is :const:`Py_PRINT_RAW`; if given, the :func:`str` of the object is written
|
| 27 |
+
instead of the :func:`repr`.
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
.. c:function:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name)
|
| 31 |
+
|
| 32 |
+
Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This
|
| 33 |
+
is equivalent to the Python expression ``hasattr(o, attr_name)``. This function
|
| 34 |
+
always succeeds.
|
| 35 |
+
|
| 36 |
+
Note that exceptions which occur while calling :meth:`__getattr__` and
|
| 37 |
+
:meth:`__getattribute__` methods will get suppressed.
|
| 38 |
+
To get error reporting use :c:func:`PyObject_GetAttr()` instead.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
.. c:function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name)
|
| 42 |
+
|
| 43 |
+
Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This
|
| 44 |
+
is equivalent to the Python expression ``hasattr(o, attr_name)``. This function
|
| 45 |
+
always succeeds.
|
| 46 |
+
|
| 47 |
+
Note that exceptions which occur while calling :meth:`__getattr__` and
|
| 48 |
+
:meth:`__getattribute__` methods and creating a temporary string object
|
| 49 |
+
will get suppressed.
|
| 50 |
+
To get error reporting use :c:func:`PyObject_GetAttrString()` instead.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
.. c:function:: PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name)
|
| 54 |
+
|
| 55 |
+
Retrieve an attribute named *attr_name* from object *o*. Returns the attribute
|
| 56 |
+
value on success, or ``NULL`` on failure. This is the equivalent of the Python
|
| 57 |
+
expression ``o.attr_name``.
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
.. c:function:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name)
|
| 61 |
+
|
| 62 |
+
Retrieve an attribute named *attr_name* from object *o*. Returns the attribute
|
| 63 |
+
value on success, or ``NULL`` on failure. This is the equivalent of the Python
|
| 64 |
+
expression ``o.attr_name``.
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
.. c:function:: PyObject* PyObject_GenericGetAttr(PyObject *o, PyObject *name)
|
| 68 |
+
|
| 69 |
+
Generic attribute getter function that is meant to be put into a type
|
| 70 |
+
object's ``tp_getattro`` slot. It looks for a descriptor in the dictionary
|
| 71 |
+
of classes in the object's MRO as well as an attribute in the object's
|
| 72 |
+
:attr:`~object.__dict__` (if present). As outlined in :ref:`descriptors`,
|
| 73 |
+
data descriptors take preference over instance attributes, while non-data
|
| 74 |
+
descriptors don't. Otherwise, an :exc:`AttributeError` is raised.
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
.. c:function:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v)
|
| 78 |
+
|
| 79 |
+
Set the value of the attribute named *attr_name*, for object *o*, to the value
|
| 80 |
+
*v*. Raise an exception and return ``-1`` on failure;
|
| 81 |
+
return ``0`` on success. This is the equivalent of the Python statement
|
| 82 |
+
``o.attr_name = v``.
|
| 83 |
+
|
| 84 |
+
If *v* is ``NULL``, the attribute is deleted, however this feature is
|
| 85 |
+
deprecated in favour of using :c:func:`PyObject_DelAttr`.
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
.. c:function:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v)
|
| 89 |
+
|
| 90 |
+
Set the value of the attribute named *attr_name*, for object *o*, to the value
|
| 91 |
+
*v*. Raise an exception and return ``-1`` on failure;
|
| 92 |
+
return ``0`` on success. This is the equivalent of the Python statement
|
| 93 |
+
``o.attr_name = v``.
|
| 94 |
+
|
| 95 |
+
If *v* is ``NULL``, the attribute is deleted, however this feature is
|
| 96 |
+
deprecated in favour of using :c:func:`PyObject_DelAttrString`.
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
.. c:function:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value)
|
| 100 |
+
|
| 101 |
+
Generic attribute setter and deleter function that is meant
|
| 102 |
+
to be put into a type object's :c:member:`~PyTypeObject.tp_setattro`
|
| 103 |
+
slot. It looks for a data descriptor in the
|
| 104 |
+
dictionary of classes in the object's MRO, and if found it takes preference
|
| 105 |
+
over setting or deleting the attribute in the instance dictionary. Otherwise, the
|
| 106 |
+
attribute is set or deleted in the object's :attr:`~object.__dict__` (if present).
|
| 107 |
+
On success, ``0`` is returned, otherwise an :exc:`AttributeError`
|
| 108 |
+
is raised and ``-1`` is returned.
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
.. c:function:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name)
|
| 112 |
+
|
| 113 |
+
Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure.
|
| 114 |
+
This is the equivalent of the Python statement ``del o.attr_name``.
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
.. c:function:: int PyObject_DelAttrString(PyObject *o, const char *attr_name)
|
| 118 |
+
|
| 119 |
+
Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure.
|
| 120 |
+
This is the equivalent of the Python statement ``del o.attr_name``.
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
.. c:function:: PyObject* PyObject_GenericGetDict(PyObject *o, void *context)
|
| 124 |
+
|
| 125 |
+
A generic implementation for the getter of a ``__dict__`` descriptor. It
|
| 126 |
+
creates the dictionary if necessary.
|
| 127 |
+
|
| 128 |
+
.. versionadded:: 3.3
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
.. c:function:: int PyObject_GenericSetDict(PyObject *o, PyObject *value, void *context)
|
| 132 |
+
|
| 133 |
+
A generic implementation for the setter of a ``__dict__`` descriptor. This
|
| 134 |
+
implementation does not allow the dictionary to be deleted.
|
| 135 |
+
|
| 136 |
+
.. versionadded:: 3.3
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
.. c:function:: PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid)
|
| 140 |
+
|
| 141 |
+
Compare the values of *o1* and *o2* using the operation specified by *opid*,
|
| 142 |
+
which must be one of :const:`Py_LT`, :const:`Py_LE`, :const:`Py_EQ`,
|
| 143 |
+
:const:`Py_NE`, :const:`Py_GT`, or :const:`Py_GE`, corresponding to ``<``,
|
| 144 |
+
``<=``, ``==``, ``!=``, ``>``, or ``>=`` respectively. This is the equivalent of
|
| 145 |
+
the Python expression ``o1 op o2``, where ``op`` is the operator corresponding
|
| 146 |
+
to *opid*. Returns the value of the comparison on success, or ``NULL`` on failure.
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
.. c:function:: int PyObject_RichCompareBool(PyObject *o1, PyObject *o2, int opid)
|
| 150 |
+
|
| 151 |
+
Compare the values of *o1* and *o2* using the operation specified by *opid*,
|
| 152 |
+
which must be one of :const:`Py_LT`, :const:`Py_LE`, :const:`Py_EQ`,
|
| 153 |
+
:const:`Py_NE`, :const:`Py_GT`, or :const:`Py_GE`, corresponding to ``<``,
|
| 154 |
+
``<=``, ``==``, ``!=``, ``>``, or ``>=`` respectively. Returns ``-1`` on error,
|
| 155 |
+
``0`` if the result is false, ``1`` otherwise. This is the equivalent of the
|
| 156 |
+
Python expression ``o1 op o2``, where ``op`` is the operator corresponding to
|
| 157 |
+
*opid*.
|
| 158 |
+
|
| 159 |
+
.. note::
|
| 160 |
+
If *o1* and *o2* are the same object, :c:func:`PyObject_RichCompareBool`
|
| 161 |
+
will always return ``1`` for :const:`Py_EQ` and ``0`` for :const:`Py_NE`.
|
| 162 |
+
|
| 163 |
+
.. c:function:: PyObject* PyObject_Repr(PyObject *o)
|
| 164 |
+
|
| 165 |
+
.. index:: builtin: repr
|
| 166 |
+
|
| 167 |
+
Compute a string representation of object *o*. Returns the string
|
| 168 |
+
representation on success, ``NULL`` on failure. This is the equivalent of the
|
| 169 |
+
Python expression ``repr(o)``. Called by the :func:`repr` built-in function.
|
| 170 |
+
|
| 171 |
+
.. versionchanged:: 3.4
|
| 172 |
+
This function now includes a debug assertion to help ensure that it
|
| 173 |
+
does not silently discard an active exception.
|
| 174 |
+
|
| 175 |
+
.. c:function:: PyObject* PyObject_ASCII(PyObject *o)
|
| 176 |
+
|
| 177 |
+
.. index:: builtin: ascii
|
| 178 |
+
|
| 179 |
+
As :c:func:`PyObject_Repr`, compute a string representation of object *o*, but
|
| 180 |
+
escape the non-ASCII characters in the string returned by
|
| 181 |
+
:c:func:`PyObject_Repr` with ``\x``, ``\u`` or ``\U`` escapes. This generates
|
| 182 |
+
a string similar to that returned by :c:func:`PyObject_Repr` in Python 2.
|
| 183 |
+
Called by the :func:`ascii` built-in function.
|
| 184 |
+
|
| 185 |
+
.. index:: string; PyObject_Str (C function)
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
.. c:function:: PyObject* PyObject_Str(PyObject *o)
|
| 189 |
+
|
| 190 |
+
Compute a string representation of object *o*. Returns the string
|
| 191 |
+
representation on success, ``NULL`` on failure. This is the equivalent of the
|
| 192 |
+
Python expression ``str(o)``. Called by the :func:`str` built-in function
|
| 193 |
+
and, therefore, by the :func:`print` function.
|
| 194 |
+
|
| 195 |
+
.. versionchanged:: 3.4
|
| 196 |
+
This function now includes a debug assertion to help ensure that it
|
| 197 |
+
does not silently discard an active exception.
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
.. c:function:: PyObject* PyObject_Bytes(PyObject *o)
|
| 201 |
+
|
| 202 |
+
.. index:: builtin: bytes
|
| 203 |
+
|
| 204 |
+
Compute a bytes representation of object *o*. ``NULL`` is returned on
|
| 205 |
+
failure and a bytes object on success. This is equivalent to the Python
|
| 206 |
+
expression ``bytes(o)``, when *o* is not an integer. Unlike ``bytes(o)``,
|
| 207 |
+
a TypeError is raised when *o* is an integer instead of a zero-initialized
|
| 208 |
+
bytes object.
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
.. c:function:: int PyObject_IsSubclass(PyObject *derived, PyObject *cls)
|
| 212 |
+
|
| 213 |
+
Return ``1`` if the class *derived* is identical to or derived from the class
|
| 214 |
+
*cls*, otherwise return ``0``. In case of an error, return ``-1``.
|
| 215 |
+
|
| 216 |
+
If *cls* is a tuple, the check will be done against every entry in *cls*.
|
| 217 |
+
The result will be ``1`` when at least one of the checks returns ``1``,
|
| 218 |
+
otherwise it will be ``0``.
|
| 219 |
+
|
| 220 |
+
If *cls* has a :meth:`~class.__subclasscheck__` method, it will be called to
|
| 221 |
+
determine the subclass status as described in :pep:`3119`. Otherwise,
|
| 222 |
+
*derived* is a subclass of *cls* if it is a direct or indirect subclass,
|
| 223 |
+
i.e. contained in ``cls.__mro__``.
|
| 224 |
+
|
| 225 |
+
Normally only class objects, i.e. instances of :class:`type` or a derived
|
| 226 |
+
class, are considered classes. However, objects can override this by having
|
| 227 |
+
a :attr:`__bases__` attribute (which must be a tuple of base classes).
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
.. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)
|
| 231 |
+
|
| 232 |
+
Return ``1`` if *inst* is an instance of the class *cls* or a subclass of
|
| 233 |
+
*cls*, or ``0`` if not. On error, returns ``-1`` and sets an exception.
|
| 234 |
+
|
| 235 |
+
If *cls* is a tuple, the check will be done against every entry in *cls*.
|
| 236 |
+
The result will be ``1`` when at least one of the checks returns ``1``,
|
| 237 |
+
otherwise it will be ``0``.
|
| 238 |
+
|
| 239 |
+
If *cls* has a :meth:`~class.__instancecheck__` method, it will be called to
|
| 240 |
+
determine the subclass status as described in :pep:`3119`. Otherwise, *inst*
|
| 241 |
+
is an instance of *cls* if its class is a subclass of *cls*.
|
| 242 |
+
|
| 243 |
+
An instance *inst* can override what is considered its class by having a
|
| 244 |
+
:attr:`__class__` attribute.
|
| 245 |
+
|
| 246 |
+
An object *cls* can override if it is considered a class, and what its base
|
| 247 |
+
classes are, by having a :attr:`__bases__` attribute (which must be a tuple
|
| 248 |
+
of base classes).
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
.. c:function:: Py_hash_t PyObject_Hash(PyObject *o)
|
| 252 |
+
|
| 253 |
+
.. index:: builtin: hash
|
| 254 |
+
|
| 255 |
+
Compute and return the hash value of an object *o*. On failure, return ``-1``.
|
| 256 |
+
This is the equivalent of the Python expression ``hash(o)``.
|
| 257 |
+
|
| 258 |
+
.. versionchanged:: 3.2
|
| 259 |
+
The return type is now Py_hash_t. This is a signed integer the same size
|
| 260 |
+
as Py_ssize_t.
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
.. c:function:: Py_hash_t PyObject_HashNotImplemented(PyObject *o)
|
| 264 |
+
|
| 265 |
+
Set a :exc:`TypeError` indicating that ``type(o)`` is not hashable and return ``-1``.
|
| 266 |
+
This function receives special treatment when stored in a ``tp_hash`` slot,
|
| 267 |
+
allowing a type to explicitly indicate to the interpreter that it is not
|
| 268 |
+
hashable.
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
.. c:function:: int PyObject_IsTrue(PyObject *o)
|
| 272 |
+
|
| 273 |
+
Returns ``1`` if the object *o* is considered to be true, and ``0`` otherwise.
|
| 274 |
+
This is equivalent to the Python expression ``not not o``. On failure, return
|
| 275 |
+
``-1``.
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
.. c:function:: int PyObject_Not(PyObject *o)
|
| 279 |
+
|
| 280 |
+
Returns ``0`` if the object *o* is considered to be true, and ``1`` otherwise.
|
| 281 |
+
This is equivalent to the Python expression ``not o``. On failure, return
|
| 282 |
+
``-1``.
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
.. c:function:: PyObject* PyObject_Type(PyObject *o)
|
| 286 |
+
|
| 287 |
+
.. index:: builtin: type
|
| 288 |
+
|
| 289 |
+
When *o* is non-``NULL``, returns a type object corresponding to the object type
|
| 290 |
+
of object *o*. On failure, raises :exc:`SystemError` and returns ``NULL``. This
|
| 291 |
+
is equivalent to the Python expression ``type(o)``. This function increments the
|
| 292 |
+
reference count of the return value. There's really no reason to use this
|
| 293 |
+
function instead of the common expression ``o->ob_type``, which returns a
|
| 294 |
+
pointer of type :c:type:`PyTypeObject\*`, except when the incremented reference
|
| 295 |
+
count is needed.
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
.. c:function:: int PyObject_TypeCheck(PyObject *o, PyTypeObject *type)
|
| 299 |
+
|
| 300 |
+
Return true if the object *o* is of type *type* or a subtype of *type*. Both
|
| 301 |
+
parameters must be non-``NULL``.
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
.. c:function:: Py_ssize_t PyObject_Size(PyObject *o)
|
| 305 |
+
Py_ssize_t PyObject_Length(PyObject *o)
|
| 306 |
+
|
| 307 |
+
.. index:: builtin: len
|
| 308 |
+
|
| 309 |
+
Return the length of object *o*. If the object *o* provides either the sequence
|
| 310 |
+
and mapping protocols, the sequence length is returned. On error, ``-1`` is
|
| 311 |
+
returned. This is the equivalent to the Python expression ``len(o)``.
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
.. c:function:: Py_ssize_t PyObject_LengthHint(PyObject *o, Py_ssize_t default)
|
| 315 |
+
|
| 316 |
+
Return an estimated length for the object *o*. First try to return its
|
| 317 |
+
actual length, then an estimate using :meth:`~object.__length_hint__`, and
|
| 318 |
+
finally return the default value. On error return ``-1``. This is the
|
| 319 |
+
equivalent to the Python expression ``operator.length_hint(o, default)``.
|
| 320 |
+
|
| 321 |
+
.. versionadded:: 3.4
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
.. c:function:: PyObject* PyObject_GetItem(PyObject *o, PyObject *key)
|
| 325 |
+
|
| 326 |
+
Return element of *o* corresponding to the object *key* or ``NULL`` on failure.
|
| 327 |
+
This is the equivalent of the Python expression ``o[key]``.
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
.. c:function:: int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v)
|
| 331 |
+
|
| 332 |
+
Map the object *key* to the value *v*. Raise an exception and
|
| 333 |
+
return ``-1`` on failure; return ``0`` on success. This is the
|
| 334 |
+
equivalent of the Python statement ``o[key] = v``. This function *does
|
| 335 |
+
not* steal a reference to *v*.
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
.. c:function:: int PyObject_DelItem(PyObject *o, PyObject *key)
|
| 339 |
+
|
| 340 |
+
Remove the mapping for the object *key* from the object *o*. Return ``-1``
|
| 341 |
+
on failure. This is equivalent to the Python statement ``del o[key]``.
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
.. c:function:: PyObject* PyObject_Dir(PyObject *o)
|
| 345 |
+
|
| 346 |
+
This is equivalent to the Python expression ``dir(o)``, returning a (possibly
|
| 347 |
+
empty) list of strings appropriate for the object argument, or ``NULL`` if there
|
| 348 |
+
was an error. If the argument is ``NULL``, this is like the Python ``dir()``,
|
| 349 |
+
returning the names of the current locals; in this case, if no execution frame
|
| 350 |
+
is active then ``NULL`` is returned but :c:func:`PyErr_Occurred` will return false.
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
.. c:function:: PyObject* PyObject_GetIter(PyObject *o)
|
| 354 |
+
|
| 355 |
+
This is equivalent to the Python expression ``iter(o)``. It returns a new
|
| 356 |
+
iterator for the object argument, or the object itself if the object is already
|
| 357 |
+
an iterator. Raises :exc:`TypeError` and returns ``NULL`` if the object cannot be
|
| 358 |
+
iterated.
|
cpython_2/environment/repo/Doc/c-api/objimpl.rst
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _newtypes:
|
| 4 |
+
|
| 5 |
+
*****************************
|
| 6 |
+
Object Implementation Support
|
| 7 |
+
*****************************
|
| 8 |
+
|
| 9 |
+
This chapter describes the functions, types, and macros used when defining new
|
| 10 |
+
object types.
|
| 11 |
+
|
| 12 |
+
.. toctree::
|
| 13 |
+
|
| 14 |
+
allocation.rst
|
| 15 |
+
structures.rst
|
| 16 |
+
typeobj.rst
|
| 17 |
+
gcsupport.rst
|
cpython_2/environment/repo/Doc/c-api/refcounting.rst
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
.. _countingrefs:
|
| 5 |
+
|
| 6 |
+
******************
|
| 7 |
+
Reference Counting
|
| 8 |
+
******************
|
| 9 |
+
|
| 10 |
+
The macros in this section are used for managing reference counts of Python
|
| 11 |
+
objects.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
.. c:function:: void Py_INCREF(PyObject *o)
|
| 15 |
+
|
| 16 |
+
Increment the reference count for object *o*. The object must not be ``NULL``; if
|
| 17 |
+
you aren't sure that it isn't ``NULL``, use :c:func:`Py_XINCREF`.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
.. c:function:: void Py_XINCREF(PyObject *o)
|
| 21 |
+
|
| 22 |
+
Increment the reference count for object *o*. The object may be ``NULL``, in
|
| 23 |
+
which case the macro has no effect.
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
.. c:function:: void Py_DECREF(PyObject *o)
|
| 27 |
+
|
| 28 |
+
Decrement the reference count for object *o*. The object must not be ``NULL``; if
|
| 29 |
+
you aren't sure that it isn't ``NULL``, use :c:func:`Py_XDECREF`. If the reference
|
| 30 |
+
count reaches zero, the object's type's deallocation function (which must not be
|
| 31 |
+
``NULL``) is invoked.
|
| 32 |
+
|
| 33 |
+
.. warning::
|
| 34 |
+
|
| 35 |
+
The deallocation function can cause arbitrary Python code to be invoked (e.g.
|
| 36 |
+
when a class instance with a :meth:`__del__` method is deallocated). While
|
| 37 |
+
exceptions in such code are not propagated, the executed code has free access to
|
| 38 |
+
all Python global variables. This means that any object that is reachable from
|
| 39 |
+
a global variable should be in a consistent state before :c:func:`Py_DECREF` is
|
| 40 |
+
invoked. For example, code to delete an object from a list should copy a
|
| 41 |
+
reference to the deleted object in a temporary variable, update the list data
|
| 42 |
+
structure, and then call :c:func:`Py_DECREF` for the temporary variable.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
.. c:function:: void Py_XDECREF(PyObject *o)
|
| 46 |
+
|
| 47 |
+
Decrement the reference count for object *o*. The object may be ``NULL``, in
|
| 48 |
+
which case the macro has no effect; otherwise the effect is the same as for
|
| 49 |
+
:c:func:`Py_DECREF`, and the same warning applies.
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
.. c:function:: void Py_CLEAR(PyObject *o)
|
| 53 |
+
|
| 54 |
+
Decrement the reference count for object *o*. The object may be ``NULL``, in
|
| 55 |
+
which case the macro has no effect; otherwise the effect is the same as for
|
| 56 |
+
:c:func:`Py_DECREF`, except that the argument is also set to ``NULL``. The warning
|
| 57 |
+
for :c:func:`Py_DECREF` does not apply with respect to the object passed because
|
| 58 |
+
the macro carefully uses a temporary variable and sets the argument to ``NULL``
|
| 59 |
+
before decrementing its reference count.
|
| 60 |
+
|
| 61 |
+
It is a good idea to use this macro whenever decrementing the reference
|
| 62 |
+
count of an object that might be traversed during garbage collection.
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
The following functions are for runtime dynamic embedding of Python:
|
| 66 |
+
``Py_IncRef(PyObject *o)``, ``Py_DecRef(PyObject *o)``. They are
|
| 67 |
+
simply exported function versions of :c:func:`Py_XINCREF` and
|
| 68 |
+
:c:func:`Py_XDECREF`, respectively.
|
| 69 |
+
|
| 70 |
+
The following functions or macros are only for use within the interpreter core:
|
| 71 |
+
:c:func:`_Py_Dealloc`, :c:func:`_Py_ForgetReference`, :c:func:`_Py_NewReference`,
|
| 72 |
+
as well as the global variable :c:data:`_Py_RefTotal`.
|
| 73 |
+
|
cpython_2/environment/repo/Doc/c-api/reflection.rst
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _reflection:
|
| 4 |
+
|
| 5 |
+
Reflection
|
| 6 |
+
==========
|
| 7 |
+
|
| 8 |
+
.. c:function:: PyObject* PyEval_GetBuiltins(void)
|
| 9 |
+
|
| 10 |
+
Return a dictionary of the builtins in the current execution frame,
|
| 11 |
+
or the interpreter of the thread state if no frame is currently executing.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
.. c:function:: PyObject* PyEval_GetLocals(void)
|
| 15 |
+
|
| 16 |
+
Return a dictionary of the local variables in the current execution frame,
|
| 17 |
+
or ``NULL`` if no frame is currently executing.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
.. c:function:: PyObject* PyEval_GetGlobals(void)
|
| 21 |
+
|
| 22 |
+
Return a dictionary of the global variables in the current execution frame,
|
| 23 |
+
or ``NULL`` if no frame is currently executing.
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
.. c:function:: PyFrameObject* PyEval_GetFrame(void)
|
| 27 |
+
|
| 28 |
+
Return the current thread state's frame, which is ``NULL`` if no frame is
|
| 29 |
+
currently executing.
|
| 30 |
+
|
| 31 |
+
See also :c:func:`PyThreadState_GetFrame`.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
.. c:function:: int PyFrame_GetBack(PyFrameObject *frame)
|
| 35 |
+
|
| 36 |
+
Get the *frame* next outer frame.
|
| 37 |
+
|
| 38 |
+
Return a strong reference, or ``NULL`` if *frame* has no outer frame.
|
| 39 |
+
|
| 40 |
+
*frame* must not be ``NULL``.
|
| 41 |
+
|
| 42 |
+
.. versionadded:: 3.9
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
.. c:function:: int PyFrame_GetCode(PyFrameObject *frame)
|
| 46 |
+
|
| 47 |
+
Get the *frame* code.
|
| 48 |
+
|
| 49 |
+
Return a strong reference.
|
| 50 |
+
|
| 51 |
+
*frame* must not be ``NULL``. The result (frame code) cannot be ``NULL``.
|
| 52 |
+
|
| 53 |
+
.. versionadded:: 3.9
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
.. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame)
|
| 57 |
+
|
| 58 |
+
Return the line number that *frame* is currently executing.
|
| 59 |
+
|
| 60 |
+
*frame* must not be ``NULL``.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
.. c:function:: const char* PyEval_GetFuncName(PyObject *func)
|
| 64 |
+
|
| 65 |
+
Return the name of *func* if it is a function, class or instance object, else the
|
| 66 |
+
name of *func*\s type.
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
.. c:function:: const char* PyEval_GetFuncDesc(PyObject *func)
|
| 70 |
+
|
| 71 |
+
Return a description string, depending on the type of *func*.
|
| 72 |
+
Return values include "()" for functions and methods, " constructor",
|
| 73 |
+
" instance", and " object". Concatenated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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _sequence:
|
| 4 |
+
|
| 5 |
+
Sequence Protocol
|
| 6 |
+
=================
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
.. c:function:: int PySequence_Check(PyObject *o)
|
| 10 |
+
|
| 11 |
+
Return ``1`` if the object provides sequence protocol, and ``0`` otherwise.
|
| 12 |
+
Note that it returns ``1`` for Python classes with a :meth:`__getitem__`
|
| 13 |
+
method unless they are :class:`dict` subclasses since in general case it
|
| 14 |
+
is impossible to determine what the type of keys it supports. This
|
| 15 |
+
function always succeeds.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
.. c:function:: Py_ssize_t PySequence_Size(PyObject *o)
|
| 19 |
+
Py_ssize_t PySequence_Length(PyObject *o)
|
| 20 |
+
|
| 21 |
+
.. index:: builtin: len
|
| 22 |
+
|
| 23 |
+
Returns the number of objects in sequence *o* on success, and ``-1`` on
|
| 24 |
+
failure. This is equivalent to the Python expression ``len(o)``.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
.. c:function:: PyObject* PySequence_Concat(PyObject *o1, PyObject *o2)
|
| 28 |
+
|
| 29 |
+
Return the concatenation of *o1* and *o2* on success, and ``NULL`` on failure.
|
| 30 |
+
This is the equivalent of the Python expression ``o1 + o2``.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
.. c:function:: PyObject* PySequence_Repeat(PyObject *o, Py_ssize_t count)
|
| 34 |
+
|
| 35 |
+
Return the result of repeating sequence object *o* *count* times, or ``NULL`` on
|
| 36 |
+
failure. This is the equivalent of the Python expression ``o * count``.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
.. c:function:: PyObject* PySequence_InPlaceConcat(PyObject *o1, PyObject *o2)
|
| 40 |
+
|
| 41 |
+
Return the concatenation of *o1* and *o2* on success, and ``NULL`` on failure.
|
| 42 |
+
The operation is done *in-place* when *o1* supports it. This is the equivalent
|
| 43 |
+
of the Python expression ``o1 += o2``.
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
.. c:function:: PyObject* PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count)
|
| 47 |
+
|
| 48 |
+
Return the result of repeating sequence object *o* *count* times, or ``NULL`` on
|
| 49 |
+
failure. The operation is done *in-place* when *o* supports it. This is the
|
| 50 |
+
equivalent of the Python expression ``o *= count``.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
.. c:function:: PyObject* PySequence_GetItem(PyObject *o, Py_ssize_t i)
|
| 54 |
+
|
| 55 |
+
Return the *i*\ th element of *o*, or ``NULL`` on failure. This is the equivalent of
|
| 56 |
+
the Python expression ``o[i]``.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
.. c:function:: PyObject* PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)
|
| 60 |
+
|
| 61 |
+
Return the slice of sequence object *o* between *i1* and *i2*, or ``NULL`` on
|
| 62 |
+
failure. This is the equivalent of the Python expression ``o[i1:i2]``.
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
.. c:function:: int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v)
|
| 66 |
+
|
| 67 |
+
Assign object *v* to the *i*\ th element of *o*. Raise an exception
|
| 68 |
+
and return ``-1`` on failure; return ``0`` on success. This
|
| 69 |
+
is the equivalent of the Python statement ``o[i] = v``. This function *does
|
| 70 |
+
not* steal a reference to *v*.
|
| 71 |
+
|
| 72 |
+
If *v* is ``NULL``, the element is deleted, however this feature is
|
| 73 |
+
deprecated in favour of using :c:func:`PySequence_DelItem`.
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
.. c:function:: int PySequence_DelItem(PyObject *o, Py_ssize_t i)
|
| 77 |
+
|
| 78 |
+
Delete the *i*\ th element of object *o*. Returns ``-1`` on failure. This is the
|
| 79 |
+
equivalent of the Python statement ``del o[i]``.
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
.. c:function:: int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v)
|
| 83 |
+
|
| 84 |
+
Assign the sequence object *v* to the slice in sequence object *o* from *i1* to
|
| 85 |
+
*i2*. This is the equivalent of the Python statement ``o[i1:i2] = v``.
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
.. c:function:: int PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)
|
| 89 |
+
|
| 90 |
+
Delete the slice in sequence object *o* from *i1* to *i2*. Returns ``-1`` on
|
| 91 |
+
failure. This is the equivalent of the Python statement ``del o[i1:i2]``.
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
.. c:function:: Py_ssize_t PySequence_Count(PyObject *o, PyObject *value)
|
| 95 |
+
|
| 96 |
+
Return the number of occurrences of *value* in *o*, that is, return the number
|
| 97 |
+
of keys for which ``o[key] == value``. On failure, return ``-1``. This is
|
| 98 |
+
equivalent to the Python expression ``o.count(value)``.
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
.. c:function:: int PySequence_Contains(PyObject *o, PyObject *value)
|
| 102 |
+
|
| 103 |
+
Determine if *o* contains *value*. If an item in *o* is equal to *value*,
|
| 104 |
+
return ``1``, otherwise return ``0``. On error, return ``-1``. This is
|
| 105 |
+
equivalent to the Python expression ``value in o``.
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
.. c:function:: Py_ssize_t PySequence_Index(PyObject *o, PyObject *value)
|
| 109 |
+
|
| 110 |
+
Return the first index *i* for which ``o[i] == value``. On error, return
|
| 111 |
+
``-1``. This is equivalent to the Python expression ``o.index(value)``.
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
.. c:function:: PyObject* PySequence_List(PyObject *o)
|
| 115 |
+
|
| 116 |
+
Return a list object with the same contents as the sequence or iterable *o*,
|
| 117 |
+
or ``NULL`` on failure. The returned list is guaranteed to be new. This is
|
| 118 |
+
equivalent to the Python expression ``list(o)``.
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
.. c:function:: PyObject* PySequence_Tuple(PyObject *o)
|
| 122 |
+
|
| 123 |
+
.. index:: builtin: tuple
|
| 124 |
+
|
| 125 |
+
Return a tuple object with the same contents as the sequence or iterable *o*,
|
| 126 |
+
or ``NULL`` on failure. If *o* is a tuple, a new reference will be returned,
|
| 127 |
+
otherwise a tuple will be constructed with the appropriate contents. This is
|
| 128 |
+
equivalent to the Python expression ``tuple(o)``.
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
.. c:function:: PyObject* PySequence_Fast(PyObject *o, const char *m)
|
| 132 |
+
|
| 133 |
+
Return the sequence or iterable *o* as an object usable by the other
|
| 134 |
+
``PySequence_Fast*`` family of functions. If the object is not a sequence or
|
| 135 |
+
iterable, raises :exc:`TypeError` with *m* as the message text. Returns
|
| 136 |
+
``NULL`` on failure.
|
| 137 |
+
|
| 138 |
+
The ``PySequence_Fast*`` functions are thus named because they assume
|
| 139 |
+
*o* is a :c:type:`PyTupleObject` or a :c:type:`PyListObject` and access
|
| 140 |
+
the data fields of *o* directly.
|
| 141 |
+
|
| 142 |
+
As a CPython implementation detail, if *o* is already a sequence or list, it
|
| 143 |
+
will be returned.
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
.. c:function:: Py_ssize_t PySequence_Fast_GET_SIZE(PyObject *o)
|
| 147 |
+
|
| 148 |
+
Returns the length of *o*, assuming that *o* was returned by
|
| 149 |
+
:c:func:`PySequence_Fast` and that *o* is not ``NULL``. The size can also be
|
| 150 |
+
gotten by calling :c:func:`PySequence_Size` on *o*, but
|
| 151 |
+
:c:func:`PySequence_Fast_GET_SIZE` is faster because it can assume *o* is a
|
| 152 |
+
list or tuple.
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
.. c:function:: PyObject* PySequence_Fast_GET_ITEM(PyObject *o, Py_ssize_t i)
|
| 156 |
+
|
| 157 |
+
Return the *i*\ th element of *o*, assuming that *o* was returned by
|
| 158 |
+
:c:func:`PySequence_Fast`, *o* is not ``NULL``, and that *i* is within bounds.
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
.. c:function:: PyObject** PySequence_Fast_ITEMS(PyObject *o)
|
| 162 |
+
|
| 163 |
+
Return the underlying array of PyObject pointers. Assumes that *o* was returned
|
| 164 |
+
by :c:func:`PySequence_Fast` and *o* is not ``NULL``.
|
| 165 |
+
|
| 166 |
+
Note, if a list gets resized, the reallocation may relocate the items array.
|
| 167 |
+
So, only use the underlying array pointer in contexts where the sequence
|
| 168 |
+
cannot change.
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
.. c:function:: PyObject* PySequence_ITEM(PyObject *o, Py_ssize_t i)
|
| 172 |
+
|
| 173 |
+
Return the *i*\ th element of *o* or ``NULL`` on failure. Faster form of
|
| 174 |
+
:c:func:`PySequence_GetItem` but without checking that
|
| 175 |
+
:c:func:`PySequence_Check` on *o* is true and without adjustment for negative
|
| 176 |
+
indices.
|
cpython_2/environment/repo/Doc/c-api/set.rst
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _setobjects:
|
| 4 |
+
|
| 5 |
+
Set Objects
|
| 6 |
+
-----------
|
| 7 |
+
|
| 8 |
+
.. sectionauthor:: Raymond D. Hettinger <python@rcn.com>
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
.. index::
|
| 12 |
+
object: set
|
| 13 |
+
object: frozenset
|
| 14 |
+
|
| 15 |
+
This section details the public API for :class:`set` and :class:`frozenset`
|
| 16 |
+
objects. Any functionality not listed below is best accessed using the either
|
| 17 |
+
the abstract object protocol (including :c:func:`PyObject_CallMethod`,
|
| 18 |
+
:c:func:`PyObject_RichCompareBool`, :c:func:`PyObject_Hash`,
|
| 19 |
+
:c:func:`PyObject_Repr`, :c:func:`PyObject_IsTrue`, :c:func:`PyObject_Print`, and
|
| 20 |
+
:c:func:`PyObject_GetIter`) or the abstract number protocol (including
|
| 21 |
+
:c:func:`PyNumber_And`, :c:func:`PyNumber_Subtract`, :c:func:`PyNumber_Or`,
|
| 22 |
+
:c:func:`PyNumber_Xor`, :c:func:`PyNumber_InPlaceAnd`,
|
| 23 |
+
:c:func:`PyNumber_InPlaceSubtract`, :c:func:`PyNumber_InPlaceOr`, and
|
| 24 |
+
:c:func:`PyNumber_InPlaceXor`).
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
.. c:type:: PySetObject
|
| 28 |
+
|
| 29 |
+
This subtype of :c:type:`PyObject` is used to hold the internal data for both
|
| 30 |
+
:class:`set` and :class:`frozenset` objects. It is like a :c:type:`PyDictObject`
|
| 31 |
+
in that it is a fixed size for small sets (much like tuple storage) and will
|
| 32 |
+
point to a separate, variable sized block of memory for medium and large sized
|
| 33 |
+
sets (much like list storage). None of the fields of this structure should be
|
| 34 |
+
considered public and are subject to change. All access should be done through
|
| 35 |
+
the documented API rather than by manipulating the values in the structure.
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
.. c:var:: PyTypeObject PySet_Type
|
| 39 |
+
|
| 40 |
+
This is an instance of :c:type:`PyTypeObject` representing the Python
|
| 41 |
+
:class:`set` type.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
.. c:var:: PyTypeObject PyFrozenSet_Type
|
| 45 |
+
|
| 46 |
+
This is an instance of :c:type:`PyTypeObject` representing the Python
|
| 47 |
+
:class:`frozenset` type.
|
| 48 |
+
|
| 49 |
+
The following type check macros work on pointers to any Python object. Likewise,
|
| 50 |
+
the constructor functions work with any iterable Python object.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
.. c:function:: int PySet_Check(PyObject *p)
|
| 54 |
+
|
| 55 |
+
Return true if *p* is a :class:`set` object or an instance of a subtype.
|
| 56 |
+
|
| 57 |
+
.. c:function:: int PyFrozenSet_Check(PyObject *p)
|
| 58 |
+
|
| 59 |
+
Return true if *p* is a :class:`frozenset` object or an instance of a
|
| 60 |
+
subtype.
|
| 61 |
+
|
| 62 |
+
.. c:function:: int PyAnySet_Check(PyObject *p)
|
| 63 |
+
|
| 64 |
+
Return true if *p* is a :class:`set` object, a :class:`frozenset` object, or an
|
| 65 |
+
instance of a subtype.
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
.. c:function:: int PyAnySet_CheckExact(PyObject *p)
|
| 69 |
+
|
| 70 |
+
Return true if *p* is a :class:`set` object or a :class:`frozenset` object but
|
| 71 |
+
not an instance of a subtype.
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
.. c:function:: int PyFrozenSet_CheckExact(PyObject *p)
|
| 75 |
+
|
| 76 |
+
Return true if *p* is a :class:`frozenset` object but not an instance of a
|
| 77 |
+
subtype.
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
.. c:function:: PyObject* PySet_New(PyObject *iterable)
|
| 81 |
+
|
| 82 |
+
Return a new :class:`set` containing objects returned by the *iterable*. The
|
| 83 |
+
*iterable* may be ``NULL`` to create a new empty set. Return the new set on
|
| 84 |
+
success or ``NULL`` on failure. Raise :exc:`TypeError` if *iterable* is not
|
| 85 |
+
actually iterable. The constructor is also useful for copying a set
|
| 86 |
+
(``c=set(s)``).
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
.. c:function:: PyObject* PyFrozenSet_New(PyObject *iterable)
|
| 90 |
+
|
| 91 |
+
Return a new :class:`frozenset` containing objects returned by the *iterable*.
|
| 92 |
+
The *iterable* may be ``NULL`` to create a new empty frozenset. Return the new
|
| 93 |
+
set on success or ``NULL`` on failure. Raise :exc:`TypeError` if *iterable* is
|
| 94 |
+
not actually iterable.
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
The following functions and macros are available for instances of :class:`set`
|
| 98 |
+
or :class:`frozenset` or instances of their subtypes.
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
.. c:function:: Py_ssize_t PySet_Size(PyObject *anyset)
|
| 102 |
+
|
| 103 |
+
.. index:: builtin: len
|
| 104 |
+
|
| 105 |
+
Return the length of a :class:`set` or :class:`frozenset` object. Equivalent to
|
| 106 |
+
``len(anyset)``. Raises a :exc:`PyExc_SystemError` if *anyset* is not a
|
| 107 |
+
:class:`set`, :class:`frozenset`, or an instance of a subtype.
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
.. c:function:: Py_ssize_t PySet_GET_SIZE(PyObject *anyset)
|
| 111 |
+
|
| 112 |
+
Macro form of :c:func:`PySet_Size` without error checking.
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
.. c:function:: int PySet_Contains(PyObject *anyset, PyObject *key)
|
| 116 |
+
|
| 117 |
+
Return ``1`` if found, ``0`` if not found, and ``-1`` if an error is encountered. Unlike
|
| 118 |
+
the Python :meth:`__contains__` method, this function does not automatically
|
| 119 |
+
convert unhashable sets into temporary frozensets. Raise a :exc:`TypeError` if
|
| 120 |
+
the *key* is unhashable. Raise :exc:`PyExc_SystemError` if *anyset* is not a
|
| 121 |
+
:class:`set`, :class:`frozenset`, or an instance of a subtype.
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
.. c:function:: int PySet_Add(PyObject *set, PyObject *key)
|
| 125 |
+
|
| 126 |
+
Add *key* to a :class:`set` instance. Also works with :class:`frozenset`
|
| 127 |
+
instances (like :c:func:`PyTuple_SetItem` it can be used to fill-in the values
|
| 128 |
+
of brand new frozensets before they are exposed to other code). Return ``0`` on
|
| 129 |
+
success or ``-1`` on failure. Raise a :exc:`TypeError` if the *key* is
|
| 130 |
+
unhashable. Raise a :exc:`MemoryError` if there is no room to grow. Raise a
|
| 131 |
+
:exc:`SystemError` if *set* is not an instance of :class:`set` or its
|
| 132 |
+
subtype.
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
The following functions are available for instances of :class:`set` or its
|
| 136 |
+
subtypes but not for instances of :class:`frozenset` or its subtypes.
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
.. c:function:: int PySet_Discard(PyObject *set, PyObject *key)
|
| 140 |
+
|
| 141 |
+
Return ``1`` if found and removed, ``0`` if not found (no action taken), and ``-1`` if an
|
| 142 |
+
error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a
|
| 143 |
+
:exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard`
|
| 144 |
+
method, this function does not automatically convert unhashable sets into
|
| 145 |
+
temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is not an
|
| 146 |
+
instance of :class:`set` or its subtype.
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
.. c:function:: PyObject* PySet_Pop(PyObject *set)
|
| 150 |
+
|
| 151 |
+
Return a new reference to an arbitrary object in the *set*, and removes the
|
| 152 |
+
object from the *set*. Return ``NULL`` on failure. Raise :exc:`KeyError` if the
|
| 153 |
+
set is empty. Raise a :exc:`SystemError` if *set* is not an instance of
|
| 154 |
+
:class:`set` or its subtype.
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
.. c:function:: int PySet_Clear(PyObject *set)
|
| 158 |
+
|
| 159 |
+
Empty an existing set of all elements.
|
cpython_2/environment/repo/Doc/c-api/slice.rst
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _slice-objects:
|
| 4 |
+
|
| 5 |
+
Slice Objects
|
| 6 |
+
-------------
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
.. c:var:: PyTypeObject PySlice_Type
|
| 10 |
+
|
| 11 |
+
The type object for slice objects. This is the same as :class:`slice` in the
|
| 12 |
+
Python layer.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
.. c:function:: int PySlice_Check(PyObject *ob)
|
| 16 |
+
|
| 17 |
+
Return true if *ob* is a slice object; *ob* must not be ``NULL``.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
.. c:function:: PyObject* PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
|
| 21 |
+
|
| 22 |
+
Return a new slice object with the given values. The *start*, *stop*, and
|
| 23 |
+
*step* parameters are used as the values of the slice object attributes of
|
| 24 |
+
the same names. Any of the values may be ``NULL``, in which case the
|
| 25 |
+
``None`` will be used for the corresponding attribute. Return ``NULL`` if
|
| 26 |
+
the new object could not be allocated.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
.. c:function:: int PySlice_GetIndices(PyObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
|
| 30 |
+
|
| 31 |
+
Retrieve the start, stop and step indices from the slice object *slice*,
|
| 32 |
+
assuming a sequence of length *length*. Treats indices greater than
|
| 33 |
+
*length* as errors.
|
| 34 |
+
|
| 35 |
+
Returns ``0`` on success and ``-1`` on error with no exception set (unless one of
|
| 36 |
+
the indices was not :const:`None` and failed to be converted to an integer,
|
| 37 |
+
in which case ``-1`` is returned with an exception set).
|
| 38 |
+
|
| 39 |
+
You probably do not want to use this function.
|
| 40 |
+
|
| 41 |
+
.. versionchanged:: 3.2
|
| 42 |
+
The parameter type for the *slice* parameter was ``PySliceObject*``
|
| 43 |
+
before.
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
.. c:function:: int PySlice_GetIndicesEx(PyObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength)
|
| 47 |
+
|
| 48 |
+
Usable replacement for :c:func:`PySlice_GetIndices`. Retrieve the start,
|
| 49 |
+
stop, and step indices from the slice object *slice* assuming a sequence of
|
| 50 |
+
length *length*, and store the length of the slice in *slicelength*. Out
|
| 51 |
+
of bounds indices are clipped in a manner consistent with the handling of
|
| 52 |
+
normal slices.
|
| 53 |
+
|
| 54 |
+
Returns ``0`` on success and ``-1`` on error with exception set.
|
| 55 |
+
|
| 56 |
+
.. note::
|
| 57 |
+
This function is considered not safe for resizable sequences.
|
| 58 |
+
Its invocation should be replaced by a combination of
|
| 59 |
+
:c:func:`PySlice_Unpack` and :c:func:`PySlice_AdjustIndices` where ::
|
| 60 |
+
|
| 61 |
+
if (PySlice_GetIndicesEx(slice, length, &start, &stop, &step, &slicelength) < 0) {
|
| 62 |
+
// return error
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
is replaced by ::
|
| 66 |
+
|
| 67 |
+
if (PySlice_Unpack(slice, &start, &stop, &step) < 0) {
|
| 68 |
+
// return error
|
| 69 |
+
}
|
| 70 |
+
slicelength = PySlice_AdjustIndices(length, &start, &stop, step);
|
| 71 |
+
|
| 72 |
+
.. versionchanged:: 3.2
|
| 73 |
+
The parameter type for the *slice* parameter was ``PySliceObject*``
|
| 74 |
+
before.
|
| 75 |
+
|
| 76 |
+
.. versionchanged:: 3.6.1
|
| 77 |
+
If ``Py_LIMITED_API`` is not set or set to the value between ``0x03050400``
|
| 78 |
+
and ``0x03060000`` (not including) or ``0x03060100`` or higher
|
| 79 |
+
:c:func:`!PySlice_GetIndicesEx` is implemented as a macro using
|
| 80 |
+
:c:func:`!PySlice_Unpack` and :c:func:`!PySlice_AdjustIndices`.
|
| 81 |
+
Arguments *start*, *stop* and *step* are evaluated more than once.
|
| 82 |
+
|
| 83 |
+
.. deprecated:: 3.6.1
|
| 84 |
+
If ``Py_LIMITED_API`` is set to the value less than ``0x03050400`` or
|
| 85 |
+
between ``0x03060000`` and ``0x03060100`` (not including)
|
| 86 |
+
:c:func:`!PySlice_GetIndicesEx` is a deprecated function.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
.. c:function:: int PySlice_Unpack(PyObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
|
| 90 |
+
|
| 91 |
+
Extract the start, stop and step data members from a slice object as
|
| 92 |
+
C integers. Silently reduce values larger than ``PY_SSIZE_T_MAX`` to
|
| 93 |
+
``PY_SSIZE_T_MAX``, silently boost the start and stop values less than
|
| 94 |
+
``PY_SSIZE_T_MIN`` to ``PY_SSIZE_T_MIN``, and silently boost the step
|
| 95 |
+
values less than ``-PY_SSIZE_T_MAX`` to ``-PY_SSIZE_T_MAX``.
|
| 96 |
+
|
| 97 |
+
Return ``-1`` on error, ``0`` on success.
|
| 98 |
+
|
| 99 |
+
.. versionadded:: 3.6.1
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
.. c:function:: Py_ssize_t PySlice_AdjustIndices(Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t step)
|
| 103 |
+
|
| 104 |
+
Adjust start/end slice indices assuming a sequence of the specified length.
|
| 105 |
+
Out of bounds indices are clipped in a manner consistent with the handling
|
| 106 |
+
of normal slices.
|
| 107 |
+
|
| 108 |
+
Return the length of the slice. Always successful. Doesn't call Python
|
| 109 |
+
code.
|
| 110 |
+
|
| 111 |
+
.. versionadded:: 3.6.1
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
Ellipsis Object
|
| 115 |
+
---------------
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
.. c:var:: PyObject *Py_Ellipsis
|
| 119 |
+
|
| 120 |
+
The Python ``Ellipsis`` object. This object has no methods. It needs to be
|
| 121 |
+
treated just like any other object with respect to reference counts. Like
|
| 122 |
+
:c:data:`Py_None` it is a singleton object.
|
cpython_2/environment/repo/Doc/c-api/stable.rst
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _stable:
|
| 4 |
+
|
| 5 |
+
***********************************
|
| 6 |
+
Stable Application Binary Interface
|
| 7 |
+
***********************************
|
| 8 |
+
|
| 9 |
+
Traditionally, the C API of Python will change with every release. Most changes
|
| 10 |
+
will be source-compatible, typically by only adding API, rather than changing
|
| 11 |
+
existing API or removing API (although some interfaces do get removed after
|
| 12 |
+
being deprecated first).
|
| 13 |
+
|
| 14 |
+
Unfortunately, the API compatibility does not extend to binary compatibility
|
| 15 |
+
(the ABI). The reason is primarily the evolution of struct definitions, where
|
| 16 |
+
addition of a new field, or changing the type of a field, might not break the
|
| 17 |
+
API, but can break the ABI. As a consequence, extension modules need to be
|
| 18 |
+
recompiled for every Python release (although an exception is possible on Unix
|
| 19 |
+
when none of the affected interfaces are used). In addition, on Windows,
|
| 20 |
+
extension modules link with a specific pythonXY.dll and need to be recompiled to
|
| 21 |
+
link with a newer one.
|
| 22 |
+
|
| 23 |
+
Since Python 3.2, a subset of the API has been declared to guarantee a stable
|
| 24 |
+
ABI. Extension modules wishing to use this API (called "limited API") need to
|
| 25 |
+
define ``Py_LIMITED_API``. A number of interpreter details then become hidden
|
| 26 |
+
from the extension module; in return, a module is built that works on any 3.x
|
| 27 |
+
version (x>=2) without recompilation.
|
| 28 |
+
|
| 29 |
+
In some cases, the stable ABI needs to be extended with new functions.
|
| 30 |
+
Extension modules wishing to use these new APIs need to set ``Py_LIMITED_API``
|
| 31 |
+
to the ``PY_VERSION_HEX`` value (see :ref:`apiabiversion`) of the minimum Python
|
| 32 |
+
version they want to support (e.g. ``0x03030000`` for Python 3.3). Such modules
|
| 33 |
+
will work on all subsequent Python releases, but fail to load (because of
|
| 34 |
+
missing symbols) on the older releases.
|
| 35 |
+
|
| 36 |
+
As of Python 3.2, the set of functions available to the limited API is
|
| 37 |
+
documented in :pep:`384`. In the C API documentation, API elements that are not
|
| 38 |
+
part of the limited API are marked as "Not part of the limited API."
|
cpython_2/environment/repo/Doc/c-api/structures.rst
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _common-structs:
|
| 4 |
+
|
| 5 |
+
Common Object Structures
|
| 6 |
+
========================
|
| 7 |
+
|
| 8 |
+
There are a large number of structures which are used in the definition of
|
| 9 |
+
object types for Python. This section describes these structures and how they
|
| 10 |
+
are used.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Base object types and macros
|
| 14 |
+
----------------------------
|
| 15 |
+
|
| 16 |
+
All Python objects ultimately share a small number of fields at the beginning
|
| 17 |
+
of the object's representation in memory. These are represented by the
|
| 18 |
+
:c:type:`PyObject` and :c:type:`PyVarObject` types, which are defined, in turn,
|
| 19 |
+
by the expansions of some macros also used, whether directly or indirectly, in
|
| 20 |
+
the definition of all other Python objects.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
.. c:type:: PyObject
|
| 24 |
+
|
| 25 |
+
All object types are extensions of this type. This is a type which
|
| 26 |
+
contains the information Python needs to treat a pointer to an object as an
|
| 27 |
+
object. In a normal "release" build, it contains only the object's
|
| 28 |
+
reference count and a pointer to the corresponding type object.
|
| 29 |
+
Nothing is actually declared to be a :c:type:`PyObject`, but every pointer
|
| 30 |
+
to a Python object can be cast to a :c:type:`PyObject*`. Access to the
|
| 31 |
+
members must be done by using the macros :c:macro:`Py_REFCNT` and
|
| 32 |
+
:c:macro:`Py_TYPE`.
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
.. c:type:: PyVarObject
|
| 36 |
+
|
| 37 |
+
This is an extension of :c:type:`PyObject` that adds the :attr:`ob_size`
|
| 38 |
+
field. This is only used for objects that have some notion of *length*.
|
| 39 |
+
This type does not often appear in the Python/C API.
|
| 40 |
+
Access to the members must be done by using the macros
|
| 41 |
+
:c:macro:`Py_REFCNT`, :c:macro:`Py_TYPE`, and :c:macro:`Py_SIZE`.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
.. c:macro:: PyObject_HEAD
|
| 45 |
+
|
| 46 |
+
This is a macro used when declaring new types which represent objects
|
| 47 |
+
without a varying length. The PyObject_HEAD macro expands to::
|
| 48 |
+
|
| 49 |
+
PyObject ob_base;
|
| 50 |
+
|
| 51 |
+
See documentation of :c:type:`PyObject` above.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
.. c:macro:: PyObject_VAR_HEAD
|
| 55 |
+
|
| 56 |
+
This is a macro used when declaring new types which represent objects
|
| 57 |
+
with a length that varies from instance to instance.
|
| 58 |
+
The PyObject_VAR_HEAD macro expands to::
|
| 59 |
+
|
| 60 |
+
PyVarObject ob_base;
|
| 61 |
+
|
| 62 |
+
See documentation of :c:type:`PyVarObject` above.
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
.. c:macro:: Py_TYPE(o)
|
| 66 |
+
|
| 67 |
+
This macro is used to access the :attr:`ob_type` member of a Python object.
|
| 68 |
+
It expands to::
|
| 69 |
+
|
| 70 |
+
(((PyObject*)(o))->ob_type)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
.. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type)
|
| 74 |
+
|
| 75 |
+
Return non-zero if the object *o* type is *type*. Return zero otherwise.
|
| 76 |
+
Equivalent to: ``Py_TYPE(o) == type``.
|
| 77 |
+
|
| 78 |
+
.. versionadded:: 3.9
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
.. c:function:: void Py_SET_TYPE(PyObject *o, PyTypeObject *type)
|
| 82 |
+
|
| 83 |
+
Set the object *o* type to *type*.
|
| 84 |
+
|
| 85 |
+
.. versionadded:: 3.9
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
.. c:macro:: Py_REFCNT(o)
|
| 89 |
+
|
| 90 |
+
This macro is used to access the :attr:`ob_refcnt` member of a Python
|
| 91 |
+
object.
|
| 92 |
+
It expands to::
|
| 93 |
+
|
| 94 |
+
(((PyObject*)(o))->ob_refcnt)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
.. c:function:: void Py_SET_REFCNT(PyObject *o, Py_ssize_t refcnt)
|
| 98 |
+
|
| 99 |
+
Set the object *o* reference counter to *refcnt*.
|
| 100 |
+
|
| 101 |
+
.. versionadded:: 3.9
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
.. c:macro:: Py_SIZE(o)
|
| 105 |
+
|
| 106 |
+
This macro is used to access the :attr:`ob_size` member of a Python object.
|
| 107 |
+
It expands to::
|
| 108 |
+
|
| 109 |
+
(((PyVarObject*)(o))->ob_size)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
.. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size)
|
| 113 |
+
|
| 114 |
+
Set the object *o* size to *size*.
|
| 115 |
+
|
| 116 |
+
.. versionadded:: 3.9
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
.. c:macro:: PyObject_HEAD_INIT(type)
|
| 120 |
+
|
| 121 |
+
This is a macro which expands to initialization values for a new
|
| 122 |
+
:c:type:`PyObject` type. This macro expands to::
|
| 123 |
+
|
| 124 |
+
_PyObject_EXTRA_INIT
|
| 125 |
+
1, type,
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
.. c:macro:: PyVarObject_HEAD_INIT(type, size)
|
| 129 |
+
|
| 130 |
+
This is a macro which expands to initialization values for a new
|
| 131 |
+
:c:type:`PyVarObject` type, including the :attr:`ob_size` field.
|
| 132 |
+
This macro expands to::
|
| 133 |
+
|
| 134 |
+
_PyObject_EXTRA_INIT
|
| 135 |
+
1, type, size,
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
Implementing functions and methods
|
| 139 |
+
----------------------------------
|
| 140 |
+
|
| 141 |
+
.. c:type:: PyCFunction
|
| 142 |
+
|
| 143 |
+
Type of the functions used to implement most Python callables in C.
|
| 144 |
+
Functions of this type take two :c:type:`PyObject\*` parameters and return
|
| 145 |
+
one such value. If the return value is ``NULL``, an exception shall have
|
| 146 |
+
been set. If not ``NULL``, the return value is interpreted as the return
|
| 147 |
+
value of the function as exposed in Python. The function must return a new
|
| 148 |
+
reference.
|
| 149 |
+
|
| 150 |
+
The function signature is::
|
| 151 |
+
|
| 152 |
+
PyObject *PyCFunction(PyObject *self,
|
| 153 |
+
PyObject *args);
|
| 154 |
+
|
| 155 |
+
.. c:type:: PyCFunctionWithKeywords
|
| 156 |
+
|
| 157 |
+
Type of the functions used to implement Python callables in C
|
| 158 |
+
with signature :const:`METH_VARARGS | METH_KEYWORDS`.
|
| 159 |
+
The function signature is::
|
| 160 |
+
|
| 161 |
+
PyObject *PyCFunctionWithKeywords(PyObject *self,
|
| 162 |
+
PyObject *args,
|
| 163 |
+
PyObject *kwargs);
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
.. c:type:: _PyCFunctionFast
|
| 167 |
+
|
| 168 |
+
Type of the functions used to implement Python callables in C
|
| 169 |
+
with signature :const:`METH_FASTCALL`.
|
| 170 |
+
The function signature is::
|
| 171 |
+
|
| 172 |
+
PyObject *_PyCFunctionFast(PyObject *self,
|
| 173 |
+
PyObject *const *args,
|
| 174 |
+
Py_ssize_t nargs);
|
| 175 |
+
|
| 176 |
+
.. c:type:: _PyCFunctionFastWithKeywords
|
| 177 |
+
|
| 178 |
+
Type of the functions used to implement Python callables in C
|
| 179 |
+
with signature :const:`METH_FASTCALL | METH_KEYWORDS`.
|
| 180 |
+
The function signature is::
|
| 181 |
+
|
| 182 |
+
PyObject *_PyCFunctionFastWithKeywords(PyObject *self,
|
| 183 |
+
PyObject *const *args,
|
| 184 |
+
Py_ssize_t nargs,
|
| 185 |
+
PyObject *kwnames);
|
| 186 |
+
|
| 187 |
+
.. c:type:: PyCMethod
|
| 188 |
+
|
| 189 |
+
Type of the functions used to implement Python callables in C
|
| 190 |
+
with signature :const:`METH_METHOD | METH_FASTCALL | METH_KEYWORDS`.
|
| 191 |
+
The function signature is::
|
| 192 |
+
|
| 193 |
+
PyObject *PyCMethod(PyObject *self,
|
| 194 |
+
PyTypeObject *defining_class,
|
| 195 |
+
PyObject *const *args,
|
| 196 |
+
Py_ssize_t nargs,
|
| 197 |
+
PyObject *kwnames)
|
| 198 |
+
|
| 199 |
+
.. versionadded:: 3.9
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
.. c:type:: PyMethodDef
|
| 203 |
+
|
| 204 |
+
Structure used to describe a method of an extension type. This structure has
|
| 205 |
+
four fields:
|
| 206 |
+
|
| 207 |
+
+------------------+---------------+-------------------------------+
|
| 208 |
+
| Field | C Type | Meaning |
|
| 209 |
+
+==================+===============+===============================+
|
| 210 |
+
| :attr:`ml_name` | const char \* | name of the method |
|
| 211 |
+
+------------------+---------------+-------------------------------+
|
| 212 |
+
| :attr:`ml_meth` | PyCFunction | pointer to the C |
|
| 213 |
+
| | | implementation |
|
| 214 |
+
+------------------+---------------+-------------------------------+
|
| 215 |
+
| :attr:`ml_flags` | int | flag bits indicating how the |
|
| 216 |
+
| | | call should be constructed |
|
| 217 |
+
+------------------+---------------+-------------------------------+
|
| 218 |
+
| :attr:`ml_doc` | const char \* | points to the contents of the |
|
| 219 |
+
| | | docstring |
|
| 220 |
+
+------------------+---------------+-------------------------------+
|
| 221 |
+
|
| 222 |
+
The :attr:`ml_meth` is a C function pointer. The functions may be of different
|
| 223 |
+
types, but they always return :c:type:`PyObject\*`. If the function is not of
|
| 224 |
+
the :c:type:`PyCFunction`, the compiler will require a cast in the method table.
|
| 225 |
+
Even though :c:type:`PyCFunction` defines the first parameter as
|
| 226 |
+
:c:type:`PyObject\*`, it is common that the method implementation uses the
|
| 227 |
+
specific C type of the *self* object.
|
| 228 |
+
|
| 229 |
+
The :attr:`ml_flags` field is a bitfield which can include the following flags.
|
| 230 |
+
The individual flags indicate either a calling convention or a binding
|
| 231 |
+
convention.
|
| 232 |
+
|
| 233 |
+
There are these calling conventions:
|
| 234 |
+
|
| 235 |
+
.. data:: METH_VARARGS
|
| 236 |
+
|
| 237 |
+
This is the typical calling convention, where the methods have the type
|
| 238 |
+
:c:type:`PyCFunction`. The function expects two :c:type:`PyObject\*` values.
|
| 239 |
+
The first one is the *self* object for methods; for module functions, it is
|
| 240 |
+
the module object. The second parameter (often called *args*) is a tuple
|
| 241 |
+
object representing all arguments. This parameter is typically processed
|
| 242 |
+
using :c:func:`PyArg_ParseTuple` or :c:func:`PyArg_UnpackTuple`.
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
.. data:: METH_VARARGS | METH_KEYWORDS
|
| 246 |
+
|
| 247 |
+
Methods with these flags must be of type :c:type:`PyCFunctionWithKeywords`.
|
| 248 |
+
The function expects three parameters: *self*, *args*, *kwargs* where
|
| 249 |
+
*kwargs* is a dictionary of all the keyword arguments or possibly ``NULL``
|
| 250 |
+
if there are no keyword arguments. The parameters are typically processed
|
| 251 |
+
using :c:func:`PyArg_ParseTupleAndKeywords`.
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
.. data:: METH_FASTCALL
|
| 255 |
+
|
| 256 |
+
Fast calling convention supporting only positional arguments.
|
| 257 |
+
The methods have the type :c:type:`_PyCFunctionFast`.
|
| 258 |
+
The first parameter is *self*, the second parameter is a C array
|
| 259 |
+
of :c:type:`PyObject\*` values indicating the arguments and the third
|
| 260 |
+
parameter is the number of arguments (the length of the array).
|
| 261 |
+
|
| 262 |
+
This is not part of the :ref:`limited API <stable>`.
|
| 263 |
+
|
| 264 |
+
.. versionadded:: 3.7
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
.. data:: METH_FASTCALL | METH_KEYWORDS
|
| 268 |
+
|
| 269 |
+
Extension of :const:`METH_FASTCALL` supporting also keyword arguments,
|
| 270 |
+
with methods of type :c:type:`_PyCFunctionFastWithKeywords`.
|
| 271 |
+
Keyword arguments are passed the same way as in the
|
| 272 |
+
:ref:`vectorcall protocol <vectorcall>`:
|
| 273 |
+
there is an additional fourth :c:type:`PyObject\*` parameter
|
| 274 |
+
which is a tuple representing the names of the keyword arguments
|
| 275 |
+
(which are guaranteed to be strings)
|
| 276 |
+
or possibly ``NULL`` if there are no keywords. The values of the keyword
|
| 277 |
+
arguments are stored in the *args* array, after the positional arguments.
|
| 278 |
+
|
| 279 |
+
This is not part of the :ref:`limited API <stable>`.
|
| 280 |
+
|
| 281 |
+
.. versionadded:: 3.7
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
.. data:: METH_METHOD | METH_FASTCALL | METH_KEYWORDS
|
| 285 |
+
|
| 286 |
+
Extension of :const:`METH_FASTCALL | METH_KEYWORDS` supporting the *defining
|
| 287 |
+
class*, that is, the class that contains the method in question.
|
| 288 |
+
The defining class might be a superclass of ``Py_TYPE(self)``.
|
| 289 |
+
|
| 290 |
+
The method needs to be of type :c:type:`PyCMethod`, the same as for
|
| 291 |
+
``METH_FASTCALL | METH_KEYWORDS`` with ``defining_class`` argument added after
|
| 292 |
+
``self``.
|
| 293 |
+
|
| 294 |
+
.. versionadded:: 3.9
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
.. data:: METH_NOARGS
|
| 298 |
+
|
| 299 |
+
Methods without parameters don't need to check whether arguments are given if
|
| 300 |
+
they are listed with the :const:`METH_NOARGS` flag. They need to be of type
|
| 301 |
+
:c:type:`PyCFunction`. The first parameter is typically named *self* and will
|
| 302 |
+
hold a reference to the module or object instance. In all cases the second
|
| 303 |
+
parameter will be ``NULL``.
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
.. data:: METH_O
|
| 307 |
+
|
| 308 |
+
Methods with a single object argument can be listed with the :const:`METH_O`
|
| 309 |
+
flag, instead of invoking :c:func:`PyArg_ParseTuple` with a ``"O"`` argument.
|
| 310 |
+
They have the type :c:type:`PyCFunction`, with the *self* parameter, and a
|
| 311 |
+
:c:type:`PyObject\*` parameter representing the single argument.
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
These two constants are not used to indicate the calling convention but the
|
| 315 |
+
binding when use with methods of classes. These may not be used for functions
|
| 316 |
+
defined for modules. At most one of these flags may be set for any given
|
| 317 |
+
method.
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
.. data:: METH_CLASS
|
| 321 |
+
|
| 322 |
+
.. index:: builtin: classmethod
|
| 323 |
+
|
| 324 |
+
The method will be passed the type object as the first parameter rather
|
| 325 |
+
than an instance of the type. This is used to create *class methods*,
|
| 326 |
+
similar to what is created when using the :func:`classmethod` built-in
|
| 327 |
+
function.
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
.. data:: METH_STATIC
|
| 331 |
+
|
| 332 |
+
.. index:: builtin: staticmethod
|
| 333 |
+
|
| 334 |
+
The method will be passed ``NULL`` as the first parameter rather than an
|
| 335 |
+
instance of the type. This is used to create *static methods*, similar to
|
| 336 |
+
what is created when using the :func:`staticmethod` built-in function.
|
| 337 |
+
|
| 338 |
+
One other constant controls whether a method is loaded in place of another
|
| 339 |
+
definition with the same method name.
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
.. data:: METH_COEXIST
|
| 343 |
+
|
| 344 |
+
The method will be loaded in place of existing definitions. Without
|
| 345 |
+
*METH_COEXIST*, the default is to skip repeated definitions. Since slot
|
| 346 |
+
wrappers are loaded before the method table, the existence of a
|
| 347 |
+
*sq_contains* slot, for example, would generate a wrapped method named
|
| 348 |
+
:meth:`__contains__` and preclude the loading of a corresponding
|
| 349 |
+
PyCFunction with the same name. With the flag defined, the PyCFunction
|
| 350 |
+
will be loaded in place of the wrapper object and will co-exist with the
|
| 351 |
+
slot. This is helpful because calls to PyCFunctions are optimized more
|
| 352 |
+
than wrapper object calls.
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
Accessing attributes of extension types
|
| 356 |
+
---------------------------------------
|
| 357 |
+
|
| 358 |
+
.. c:type:: PyMemberDef
|
| 359 |
+
|
| 360 |
+
Structure which describes an attribute of a type which corresponds to a C
|
| 361 |
+
struct member. Its fields are:
|
| 362 |
+
|
| 363 |
+
+------------------+---------------+-------------------------------+
|
| 364 |
+
| Field | C Type | Meaning |
|
| 365 |
+
+==================+===============+===============================+
|
| 366 |
+
| :attr:`name` | const char \* | name of the member |
|
| 367 |
+
+------------------+---------------+-------------------------------+
|
| 368 |
+
| :attr:`!type` | int | the type of the member in the |
|
| 369 |
+
| | | C struct |
|
| 370 |
+
+------------------+---------------+-------------------------------+
|
| 371 |
+
| :attr:`offset` | Py_ssize_t | the offset in bytes that the |
|
| 372 |
+
| | | member is located on the |
|
| 373 |
+
| | | type's object struct |
|
| 374 |
+
+------------------+---------------+-------------------------------+
|
| 375 |
+
| :attr:`flags` | int | flag bits indicating if the |
|
| 376 |
+
| | | field should be read-only or |
|
| 377 |
+
| | | writable |
|
| 378 |
+
+------------------+---------------+-------------------------------+
|
| 379 |
+
| :attr:`doc` | const char \* | points to the contents of the |
|
| 380 |
+
| | | docstring |
|
| 381 |
+
+------------------+---------------+-------------------------------+
|
| 382 |
+
|
| 383 |
+
:attr:`!type` can be one of many ``T_`` macros corresponding to various C
|
| 384 |
+
types. When the member is accessed in Python, it will be converted to the
|
| 385 |
+
equivalent Python type.
|
| 386 |
+
|
| 387 |
+
=============== ==================
|
| 388 |
+
Macro name C type
|
| 389 |
+
=============== ==================
|
| 390 |
+
T_SHORT short
|
| 391 |
+
T_INT int
|
| 392 |
+
T_LONG long
|
| 393 |
+
T_FLOAT float
|
| 394 |
+
T_DOUBLE double
|
| 395 |
+
T_STRING const char \*
|
| 396 |
+
T_OBJECT PyObject \*
|
| 397 |
+
T_OBJECT_EX PyObject \*
|
| 398 |
+
T_CHAR char
|
| 399 |
+
T_BYTE char
|
| 400 |
+
T_UBYTE unsigned char
|
| 401 |
+
T_UINT unsigned int
|
| 402 |
+
T_USHORT unsigned short
|
| 403 |
+
T_ULONG unsigned long
|
| 404 |
+
T_BOOL char
|
| 405 |
+
T_LONGLONG long long
|
| 406 |
+
T_ULONGLONG unsigned long long
|
| 407 |
+
T_PYSSIZET Py_ssize_t
|
| 408 |
+
=============== ==================
|
| 409 |
+
|
| 410 |
+
:c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX` differ in that
|
| 411 |
+
:c:macro:`T_OBJECT` returns ``None`` if the member is ``NULL`` and
|
| 412 |
+
:c:macro:`T_OBJECT_EX` raises an :exc:`AttributeError`. Try to use
|
| 413 |
+
:c:macro:`T_OBJECT_EX` over :c:macro:`T_OBJECT` because :c:macro:`T_OBJECT_EX`
|
| 414 |
+
handles use of the :keyword:`del` statement on that attribute more correctly
|
| 415 |
+
than :c:macro:`T_OBJECT`.
|
| 416 |
+
|
| 417 |
+
:attr:`flags` can be ``0`` for write and read access or :c:macro:`READONLY` for
|
| 418 |
+
read-only access. Using :c:macro:`T_STRING` for :attr:`type` implies
|
| 419 |
+
:c:macro:`READONLY`. :c:macro:`T_STRING` data is interpreted as UTF-8.
|
| 420 |
+
Only :c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX`
|
| 421 |
+
members can be deleted. (They are set to ``NULL``).
|
| 422 |
+
|
| 423 |
+
.. _pymemberdef-offsets:
|
| 424 |
+
|
| 425 |
+
Heap allocated types (created using :c:func:`PyType_FromSpec` or similar),
|
| 426 |
+
``PyMemberDef`` may contain definitions for the special members
|
| 427 |
+
``__dictoffset__``, ``__weaklistoffset__`` and ``__vectorcalloffset__``,
|
| 428 |
+
corresponding to
|
| 429 |
+
:c:member:`~PyTypeObject.tp_dictoffset`,
|
| 430 |
+
:c:member:`~PyTypeObject.tp_weaklistoffset` and
|
| 431 |
+
:c:member:`~PyTypeObject.tp_vectorcall_offset` in type objects.
|
| 432 |
+
These must be defined with ``T_PYSSIZET`` and ``READONLY``, for example::
|
| 433 |
+
|
| 434 |
+
static PyMemberDef spam_type_members[] = {
|
| 435 |
+
{"__dictoffset__", T_PYSSIZET, offsetof(Spam_object, dict), READONLY},
|
| 436 |
+
{NULL} /* Sentinel */
|
| 437 |
+
};
|
| 438 |
+
|
| 439 |
+
.. c:type:: PyGetSetDef
|
| 440 |
+
|
| 441 |
+
Structure to define property-like access for a type. See also description of
|
| 442 |
+
the :c:member:`PyTypeObject.tp_getset` slot.
|
| 443 |
+
|
| 444 |
+
+-------------+------------------+-----------------------------------+
|
| 445 |
+
| Field | C Type | Meaning |
|
| 446 |
+
+=============+==================+===================================+
|
| 447 |
+
| name | const char \* | attribute name |
|
| 448 |
+
+-------------+------------------+-----------------------------------+
|
| 449 |
+
| get | getter | C Function to get the attribute |
|
| 450 |
+
+-------------+------------------+-----------------------------------+
|
| 451 |
+
| set | setter | optional C function to set or |
|
| 452 |
+
| | | delete the attribute, if omitted |
|
| 453 |
+
| | | the attribute is readonly |
|
| 454 |
+
+-------------+------------------+-----------------------------------+
|
| 455 |
+
| doc | const char \* | optional docstring |
|
| 456 |
+
+-------------+------------------+-----------------------------------+
|
| 457 |
+
| closure | void \* | optional function pointer, |
|
| 458 |
+
| | | providing additional data for |
|
| 459 |
+
| | | getter and setter |
|
| 460 |
+
+-------------+------------------+-----------------------------------+
|
| 461 |
+
|
| 462 |
+
The ``get`` function takes one :c:type:`PyObject\*` parameter (the
|
| 463 |
+
instance) and a function pointer (the associated ``closure``)::
|
| 464 |
+
|
| 465 |
+
typedef PyObject *(*getter)(PyObject *, void *);
|
| 466 |
+
|
| 467 |
+
It should return a new reference on success or ``NULL`` with a set exception
|
| 468 |
+
on failure.
|
| 469 |
+
|
| 470 |
+
``set`` functions take two :c:type:`PyObject\*` parameters (the instance and
|
| 471 |
+
the value to be set) and a function pointer (the associated ``closure``)::
|
| 472 |
+
|
| 473 |
+
typedef int (*setter)(PyObject *, PyObject *, void *);
|
| 474 |
+
|
| 475 |
+
In case the attribute should be deleted the second parameter is ``NULL``.
|
| 476 |
+
Should return ``0`` on success or ``-1`` with a set exception on failure.
|
cpython_2/environment/repo/Doc/c-api/sys.rst
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _os:
|
| 4 |
+
|
| 5 |
+
Operating System Utilities
|
| 6 |
+
==========================
|
| 7 |
+
|
| 8 |
+
.. c:function:: PyObject* PyOS_FSPath(PyObject *path)
|
| 9 |
+
|
| 10 |
+
Return the file system representation for *path*. If the object is a
|
| 11 |
+
:class:`str` or :class:`bytes` object, then its reference count is
|
| 12 |
+
incremented. If the object implements the :class:`os.PathLike` interface,
|
| 13 |
+
then :meth:`~os.PathLike.__fspath__` is returned as long as it is a
|
| 14 |
+
:class:`str` or :class:`bytes` object. Otherwise :exc:`TypeError` is raised
|
| 15 |
+
and ``NULL`` is returned.
|
| 16 |
+
|
| 17 |
+
.. versionadded:: 3.6
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
.. c:function:: int Py_FdIsInteractive(FILE *fp, const char *filename)
|
| 21 |
+
|
| 22 |
+
Return true (nonzero) if the standard I/O file *fp* with name *filename* is
|
| 23 |
+
deemed interactive. This is the case for files for which ``isatty(fileno(fp))``
|
| 24 |
+
is true. If the global flag :c:data:`Py_InteractiveFlag` is true, this function
|
| 25 |
+
also returns true if the *filename* pointer is ``NULL`` or if the name is equal to
|
| 26 |
+
one of the strings ``'<stdin>'`` or ``'???'``.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
.. c:function:: void PyOS_BeforeFork()
|
| 30 |
+
|
| 31 |
+
Function to prepare some internal state before a process fork. This
|
| 32 |
+
should be called before calling :c:func:`fork` or any similar function
|
| 33 |
+
that clones the current process.
|
| 34 |
+
Only available on systems where :c:func:`fork` is defined.
|
| 35 |
+
|
| 36 |
+
.. warning::
|
| 37 |
+
The C :c:func:`fork` call should only be made from the
|
| 38 |
+
:ref:`"main" thread <fork-and-threads>` (of the
|
| 39 |
+
:ref:`"main" interpreter <sub-interpreter-support>`). The same is
|
| 40 |
+
true for ``PyOS_BeforeFork()``.
|
| 41 |
+
|
| 42 |
+
.. versionadded:: 3.7
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
.. c:function:: void PyOS_AfterFork_Parent()
|
| 46 |
+
|
| 47 |
+
Function to update some internal state after a process fork. This
|
| 48 |
+
should be called from the parent process after calling :c:func:`fork`
|
| 49 |
+
or any similar function that clones the current process, regardless
|
| 50 |
+
of whether process cloning was successful.
|
| 51 |
+
Only available on systems where :c:func:`fork` is defined.
|
| 52 |
+
|
| 53 |
+
.. warning::
|
| 54 |
+
The C :c:func:`fork` call should only be made from the
|
| 55 |
+
:ref:`"main" thread <fork-and-threads>` (of the
|
| 56 |
+
:ref:`"main" interpreter <sub-interpreter-support>`). The same is
|
| 57 |
+
true for ``PyOS_AfterFork_Parent()``.
|
| 58 |
+
|
| 59 |
+
.. versionadded:: 3.7
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
.. c:function:: void PyOS_AfterFork_Child()
|
| 63 |
+
|
| 64 |
+
Function to update internal interpreter state after a process fork.
|
| 65 |
+
This must be called from the child process after calling :c:func:`fork`,
|
| 66 |
+
or any similar function that clones the current process, if there is
|
| 67 |
+
any chance the process will call back into the Python interpreter.
|
| 68 |
+
Only available on systems where :c:func:`fork` is defined.
|
| 69 |
+
|
| 70 |
+
.. warning::
|
| 71 |
+
The C :c:func:`fork` call should only be made from the
|
| 72 |
+
:ref:`"main" thread <fork-and-threads>` (of the
|
| 73 |
+
:ref:`"main" interpreter <sub-interpreter-support>`). The same is
|
| 74 |
+
true for ``PyOS_AfterFork_Child()``.
|
| 75 |
+
|
| 76 |
+
.. versionadded:: 3.7
|
| 77 |
+
|
| 78 |
+
.. seealso::
|
| 79 |
+
:func:`os.register_at_fork` allows registering custom Python functions
|
| 80 |
+
to be called by :c:func:`PyOS_BeforeFork()`,
|
| 81 |
+
:c:func:`PyOS_AfterFork_Parent` and :c:func:`PyOS_AfterFork_Child`.
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
.. c:function:: void PyOS_AfterFork()
|
| 85 |
+
|
| 86 |
+
Function to update some internal state after a process fork; this should be
|
| 87 |
+
called in the new process if the Python interpreter will continue to be used.
|
| 88 |
+
If a new executable is loaded into the new process, this function does not need
|
| 89 |
+
to be called.
|
| 90 |
+
|
| 91 |
+
.. deprecated:: 3.7
|
| 92 |
+
This function is superseded by :c:func:`PyOS_AfterFork_Child()`.
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
.. c:function:: int PyOS_CheckStack()
|
| 96 |
+
|
| 97 |
+
Return true when the interpreter runs out of stack space. This is a reliable
|
| 98 |
+
check, but is only available when :const:`USE_STACKCHECK` is defined (currently
|
| 99 |
+
on Windows using the Microsoft Visual C++ compiler). :const:`USE_STACKCHECK`
|
| 100 |
+
will be defined automatically; you should never change the definition in your
|
| 101 |
+
own code.
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
.. c:function:: PyOS_sighandler_t PyOS_getsig(int i)
|
| 105 |
+
|
| 106 |
+
Return the current signal handler for signal *i*. This is a thin wrapper around
|
| 107 |
+
either :c:func:`sigaction` or :c:func:`signal`. Do not call those functions
|
| 108 |
+
directly! :c:type:`PyOS_sighandler_t` is a typedef alias for :c:type:`void
|
| 109 |
+
(\*)(int)`.
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
.. c:function:: PyOS_sighandler_t PyOS_setsig(int i, PyOS_sighandler_t h)
|
| 113 |
+
|
| 114 |
+
Set the signal handler for signal *i* to be *h*; return the old signal handler.
|
| 115 |
+
This is a thin wrapper around either :c:func:`sigaction` or :c:func:`signal`. Do
|
| 116 |
+
not call those functions directly! :c:type:`PyOS_sighandler_t` is a typedef
|
| 117 |
+
alias for :c:type:`void (\*)(int)`.
|
| 118 |
+
|
| 119 |
+
.. c:function:: wchar_t* Py_DecodeLocale(const char* arg, size_t *size)
|
| 120 |
+
|
| 121 |
+
Decode a byte string from the locale encoding with the :ref:`surrogateescape
|
| 122 |
+
error handler <surrogateescape>`: undecodable bytes are decoded as
|
| 123 |
+
characters in range U+DC80..U+DCFF. If a byte sequence can be decoded as a
|
| 124 |
+
surrogate character, escape the bytes using the surrogateescape error
|
| 125 |
+
handler instead of decoding them.
|
| 126 |
+
|
| 127 |
+
Encoding, highest priority to lowest priority:
|
| 128 |
+
|
| 129 |
+
* ``UTF-8`` on macOS, Android, and VxWorks;
|
| 130 |
+
* ``UTF-8`` on Windows if :c:data:`Py_LegacyWindowsFSEncodingFlag` is zero;
|
| 131 |
+
* ``UTF-8`` if the Python UTF-8 mode is enabled;
|
| 132 |
+
* ``ASCII`` if the ``LC_CTYPE`` locale is ``"C"``,
|
| 133 |
+
``nl_langinfo(CODESET)`` returns the ``ASCII`` encoding (or an alias),
|
| 134 |
+
and :c:func:`mbstowcs` and :c:func:`wcstombs` functions uses the
|
| 135 |
+
``ISO-8859-1`` encoding.
|
| 136 |
+
* the current locale encoding.
|
| 137 |
+
|
| 138 |
+
Return a pointer to a newly allocated wide character string, use
|
| 139 |
+
:c:func:`PyMem_RawFree` to free the memory. If size is not ``NULL``, write
|
| 140 |
+
the number of wide characters excluding the null character into ``*size``
|
| 141 |
+
|
| 142 |
+
Return ``NULL`` on decoding error or memory allocation error. If *size* is
|
| 143 |
+
not ``NULL``, ``*size`` is set to ``(size_t)-1`` on memory error or set to
|
| 144 |
+
``(size_t)-2`` on decoding error.
|
| 145 |
+
|
| 146 |
+
Decoding errors should never happen, unless there is a bug in the C
|
| 147 |
+
library.
|
| 148 |
+
|
| 149 |
+
Use the :c:func:`Py_EncodeLocale` function to encode the character string
|
| 150 |
+
back to a byte string.
|
| 151 |
+
|
| 152 |
+
.. seealso::
|
| 153 |
+
|
| 154 |
+
The :c:func:`PyUnicode_DecodeFSDefaultAndSize` and
|
| 155 |
+
:c:func:`PyUnicode_DecodeLocaleAndSize` functions.
|
| 156 |
+
|
| 157 |
+
.. versionadded:: 3.5
|
| 158 |
+
|
| 159 |
+
.. versionchanged:: 3.7
|
| 160 |
+
The function now uses the UTF-8 encoding in the UTF-8 mode.
|
| 161 |
+
|
| 162 |
+
.. versionchanged:: 3.8
|
| 163 |
+
The function now uses the UTF-8 encoding on Windows if
|
| 164 |
+
:c:data:`Py_LegacyWindowsFSEncodingFlag` is zero;
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
.. c:function:: char* Py_EncodeLocale(const wchar_t *text, size_t *error_pos)
|
| 168 |
+
|
| 169 |
+
Encode a wide character string to the locale encoding with the
|
| 170 |
+
:ref:`surrogateescape error handler <surrogateescape>`: surrogate characters
|
| 171 |
+
in the range U+DC80..U+DCFF are converted to bytes 0x80..0xFF.
|
| 172 |
+
|
| 173 |
+
Encoding, highest priority to lowest priority:
|
| 174 |
+
|
| 175 |
+
* ``UTF-8`` on macOS, Android, and VxWorks;
|
| 176 |
+
* ``UTF-8`` on Windows if :c:data:`Py_LegacyWindowsFSEncodingFlag` is zero;
|
| 177 |
+
* ``UTF-8`` if the Python UTF-8 mode is enabled;
|
| 178 |
+
* ``ASCII`` if the ``LC_CTYPE`` locale is ``"C"``,
|
| 179 |
+
``nl_langinfo(CODESET)`` returns the ``ASCII`` encoding (or an alias),
|
| 180 |
+
and :c:func:`mbstowcs` and :c:func:`wcstombs` functions uses the
|
| 181 |
+
``ISO-8859-1`` encoding.
|
| 182 |
+
* the current locale encoding.
|
| 183 |
+
|
| 184 |
+
The function uses the UTF-8 encoding in the Python UTF-8 mode.
|
| 185 |
+
|
| 186 |
+
Return a pointer to a newly allocated byte string, use :c:func:`PyMem_Free`
|
| 187 |
+
to free the memory. Return ``NULL`` on encoding error or memory allocation
|
| 188 |
+
error
|
| 189 |
+
|
| 190 |
+
If error_pos is not ``NULL``, ``*error_pos`` is set to ``(size_t)-1`` on
|
| 191 |
+
success, or set to the index of the invalid character on encoding error.
|
| 192 |
+
|
| 193 |
+
Use the :c:func:`Py_DecodeLocale` function to decode the bytes string back
|
| 194 |
+
to a wide character string.
|
| 195 |
+
|
| 196 |
+
.. seealso::
|
| 197 |
+
|
| 198 |
+
The :c:func:`PyUnicode_EncodeFSDefault` and
|
| 199 |
+
:c:func:`PyUnicode_EncodeLocale` functions.
|
| 200 |
+
|
| 201 |
+
.. versionadded:: 3.5
|
| 202 |
+
|
| 203 |
+
.. versionchanged:: 3.7
|
| 204 |
+
The function now uses the UTF-8 encoding in the UTF-8 mode.
|
| 205 |
+
|
| 206 |
+
.. versionchanged:: 3.8
|
| 207 |
+
The function now uses the UTF-8 encoding on Windows if
|
| 208 |
+
:c:data:`Py_LegacyWindowsFSEncodingFlag` is zero;
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
.. _systemfunctions:
|
| 212 |
+
|
| 213 |
+
System Functions
|
| 214 |
+
================
|
| 215 |
+
|
| 216 |
+
These are utility functions that make functionality from the :mod:`sys` module
|
| 217 |
+
accessible to C code. They all work with the current interpreter thread's
|
| 218 |
+
:mod:`sys` module's dict, which is contained in the internal thread state structure.
|
| 219 |
+
|
| 220 |
+
.. c:function:: PyObject *PySys_GetObject(const char *name)
|
| 221 |
+
|
| 222 |
+
Return the object *name* from the :mod:`sys` module or ``NULL`` if it does
|
| 223 |
+
not exist, without setting an exception.
|
| 224 |
+
|
| 225 |
+
.. c:function:: int PySys_SetObject(const char *name, PyObject *v)
|
| 226 |
+
|
| 227 |
+
Set *name* in the :mod:`sys` module to *v* unless *v* is ``NULL``, in which
|
| 228 |
+
case *name* is deleted from the sys module. Returns ``0`` on success, ``-1``
|
| 229 |
+
on error.
|
| 230 |
+
|
| 231 |
+
.. c:function:: void PySys_ResetWarnOptions()
|
| 232 |
+
|
| 233 |
+
Reset :data:`sys.warnoptions` to an empty list. This function may be
|
| 234 |
+
called prior to :c:func:`Py_Initialize`.
|
| 235 |
+
|
| 236 |
+
.. c:function:: void PySys_AddWarnOption(const wchar_t *s)
|
| 237 |
+
|
| 238 |
+
Append *s* to :data:`sys.warnoptions`. This function must be called prior
|
| 239 |
+
to :c:func:`Py_Initialize` in order to affect the warnings filter list.
|
| 240 |
+
|
| 241 |
+
.. c:function:: void PySys_AddWarnOptionUnicode(PyObject *unicode)
|
| 242 |
+
|
| 243 |
+
Append *unicode* to :data:`sys.warnoptions`.
|
| 244 |
+
|
| 245 |
+
Note: this function is not currently usable from outside the CPython
|
| 246 |
+
implementation, as it must be called prior to the implicit import of
|
| 247 |
+
:mod:`warnings` in :c:func:`Py_Initialize` to be effective, but can't be
|
| 248 |
+
called until enough of the runtime has been initialized to permit the
|
| 249 |
+
creation of Unicode objects.
|
| 250 |
+
|
| 251 |
+
.. c:function:: void PySys_SetPath(const wchar_t *path)
|
| 252 |
+
|
| 253 |
+
Set :data:`sys.path` to a list object of paths found in *path* which should
|
| 254 |
+
be a list of paths separated with the platform's search path delimiter
|
| 255 |
+
(``:`` on Unix, ``;`` on Windows).
|
| 256 |
+
|
| 257 |
+
.. c:function:: void PySys_WriteStdout(const char *format, ...)
|
| 258 |
+
|
| 259 |
+
Write the output string described by *format* to :data:`sys.stdout`. No
|
| 260 |
+
exceptions are raised, even if truncation occurs (see below).
|
| 261 |
+
|
| 262 |
+
*format* should limit the total size of the formatted output string to
|
| 263 |
+
1000 bytes or less -- after 1000 bytes, the output string is truncated.
|
| 264 |
+
In particular, this means that no unrestricted "%s" formats should occur;
|
| 265 |
+
these should be limited using "%.<N>s" where <N> is a decimal number
|
| 266 |
+
calculated so that <N> plus the maximum size of other formatted text does not
|
| 267 |
+
exceed 1000 bytes. Also watch out for "%f", which can print hundreds of
|
| 268 |
+
digits for very large numbers.
|
| 269 |
+
|
| 270 |
+
If a problem occurs, or :data:`sys.stdout` is unset, the formatted message
|
| 271 |
+
is written to the real (C level) *stdout*.
|
| 272 |
+
|
| 273 |
+
.. c:function:: void PySys_WriteStderr(const char *format, ...)
|
| 274 |
+
|
| 275 |
+
As :c:func:`PySys_WriteStdout`, but write to :data:`sys.stderr` or *stderr*
|
| 276 |
+
instead.
|
| 277 |
+
|
| 278 |
+
.. c:function:: void PySys_FormatStdout(const char *format, ...)
|
| 279 |
+
|
| 280 |
+
Function similar to PySys_WriteStdout() but format the message using
|
| 281 |
+
:c:func:`PyUnicode_FromFormatV` and don't truncate the message to an
|
| 282 |
+
arbitrary length.
|
| 283 |
+
|
| 284 |
+
.. versionadded:: 3.2
|
| 285 |
+
|
| 286 |
+
.. c:function:: void PySys_FormatStderr(const char *format, ...)
|
| 287 |
+
|
| 288 |
+
As :c:func:`PySys_FormatStdout`, but write to :data:`sys.stderr` or *stderr*
|
| 289 |
+
instead.
|
| 290 |
+
|
| 291 |
+
.. versionadded:: 3.2
|
| 292 |
+
|
| 293 |
+
.. c:function:: void PySys_AddXOption(const wchar_t *s)
|
| 294 |
+
|
| 295 |
+
Parse *s* as a set of :option:`-X` options and add them to the current
|
| 296 |
+
options mapping as returned by :c:func:`PySys_GetXOptions`. This function
|
| 297 |
+
may be called prior to :c:func:`Py_Initialize`.
|
| 298 |
+
|
| 299 |
+
.. versionadded:: 3.2
|
| 300 |
+
|
| 301 |
+
.. c:function:: PyObject *PySys_GetXOptions()
|
| 302 |
+
|
| 303 |
+
Return the current dictionary of :option:`-X` options, similarly to
|
| 304 |
+
:data:`sys._xoptions`. On error, ``NULL`` is returned and an exception is
|
| 305 |
+
set.
|
| 306 |
+
|
| 307 |
+
.. versionadded:: 3.2
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
.. c:function:: int PySys_Audit(const char *event, const char *format, ...)
|
| 311 |
+
|
| 312 |
+
Raise an auditing event with any active hooks. Return zero for success
|
| 313 |
+
and non-zero with an exception set on failure.
|
| 314 |
+
|
| 315 |
+
If any hooks have been added, *format* and other arguments will be used
|
| 316 |
+
to construct a tuple to pass. Apart from ``N``, the same format characters
|
| 317 |
+
as used in :c:func:`Py_BuildValue` are available. If the built value is not
|
| 318 |
+
a tuple, it will be added into a single-element tuple. (The ``N`` format
|
| 319 |
+
option consumes a reference, but since there is no way to know whether
|
| 320 |
+
arguments to this function will be consumed, using it may cause reference
|
| 321 |
+
leaks.)
|
| 322 |
+
|
| 323 |
+
Note that ``#`` format characters should always be treated as
|
| 324 |
+
``Py_ssize_t``, regardless of whether ``PY_SSIZE_T_CLEAN`` was defined.
|
| 325 |
+
|
| 326 |
+
:func:`sys.audit` performs the same function from Python code.
|
| 327 |
+
|
| 328 |
+
.. versionadded:: 3.8
|
| 329 |
+
|
| 330 |
+
.. versionchanged:: 3.8.2
|
| 331 |
+
|
| 332 |
+
Require ``Py_ssize_t`` for ``#`` format characters. Previously, an
|
| 333 |
+
unavoidable deprecation warning was raised.
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
.. c:function:: int PySys_AddAuditHook(Py_AuditHookFunction hook, void *userData)
|
| 337 |
+
|
| 338 |
+
Append the callable *hook* to the list of active auditing hooks.
|
| 339 |
+
Return zero for success
|
| 340 |
+
and non-zero on failure. If the runtime has been initialized, also set an
|
| 341 |
+
error on failure. Hooks added through this API are called for all
|
| 342 |
+
interpreters created by the runtime.
|
| 343 |
+
|
| 344 |
+
The *userData* pointer is passed into the hook function. Since hook
|
| 345 |
+
functions may be called from different runtimes, this pointer should not
|
| 346 |
+
refer directly to Python state.
|
| 347 |
+
|
| 348 |
+
This function is safe to call before :c:func:`Py_Initialize`. When called
|
| 349 |
+
after runtime initialization, existing audit hooks are notified and may
|
| 350 |
+
silently abort the operation by raising an error subclassed from
|
| 351 |
+
:class:`Exception` (other errors will not be silenced).
|
| 352 |
+
|
| 353 |
+
The hook function is of type :c:type:`int (*)(const char *event, PyObject
|
| 354 |
+
*args, void *userData)`, where *args* is guaranteed to be a
|
| 355 |
+
:c:type:`PyTupleObject`. The hook function is always called with the GIL
|
| 356 |
+
held by the Python interpreter that raised the event.
|
| 357 |
+
|
| 358 |
+
See :pep:`578` for a detailed description of auditing. Functions in the
|
| 359 |
+
runtime and standard library that raise events are listed in the
|
| 360 |
+
:ref:`audit events table <audit-events>`.
|
| 361 |
+
Details are in each function's documentation.
|
| 362 |
+
|
| 363 |
+
.. audit-event:: sys.addaudithook "" c.PySys_AddAuditHook
|
| 364 |
+
|
| 365 |
+
If the interpreter is initialized, this function raises a auditing event
|
| 366 |
+
``sys.addaudithook`` with no arguments. If any existing hooks raise an
|
| 367 |
+
exception derived from :class:`Exception`, the new hook will not be
|
| 368 |
+
added and the exception is cleared. As a result, callers cannot assume
|
| 369 |
+
that their hook has been added unless they control all existing hooks.
|
| 370 |
+
|
| 371 |
+
.. versionadded:: 3.8
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
.. _processcontrol:
|
| 375 |
+
|
| 376 |
+
Process Control
|
| 377 |
+
===============
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
.. c:function:: void Py_FatalError(const char *message)
|
| 381 |
+
|
| 382 |
+
.. index:: single: abort()
|
| 383 |
+
|
| 384 |
+
Print a fatal error message and kill the process. No cleanup is performed.
|
| 385 |
+
This function should only be invoked when a condition is detected that would
|
| 386 |
+
make it dangerous to continue using the Python interpreter; e.g., when the
|
| 387 |
+
object administration appears to be corrupted. On Unix, the standard C library
|
| 388 |
+
function :c:func:`abort` is called which will attempt to produce a :file:`core`
|
| 389 |
+
file.
|
| 390 |
+
|
| 391 |
+
The ``Py_FatalError()`` function is replaced with a macro which logs
|
| 392 |
+
automatically the name of the current function, unless the
|
| 393 |
+
``Py_LIMITED_API`` macro is defined.
|
| 394 |
+
|
| 395 |
+
.. versionchanged:: 3.9
|
| 396 |
+
Log the function name automatically.
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
.. c:function:: void Py_Exit(int status)
|
| 400 |
+
|
| 401 |
+
.. index::
|
| 402 |
+
single: Py_FinalizeEx()
|
| 403 |
+
single: exit()
|
| 404 |
+
|
| 405 |
+
Exit the current process. This calls :c:func:`Py_FinalizeEx` and then calls the
|
| 406 |
+
standard C library function ``exit(status)``. If :c:func:`Py_FinalizeEx`
|
| 407 |
+
indicates an error, the exit status is set to 120.
|
| 408 |
+
|
| 409 |
+
.. versionchanged:: 3.6
|
| 410 |
+
Errors from finalization no longer ignored.
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
.. c:function:: int Py_AtExit(void (*func) ())
|
| 414 |
+
|
| 415 |
+
.. index::
|
| 416 |
+
single: Py_FinalizeEx()
|
| 417 |
+
single: cleanup functions
|
| 418 |
+
|
| 419 |
+
Register a cleanup function to be called by :c:func:`Py_FinalizeEx`. The cleanup
|
| 420 |
+
function will be called with no arguments and should return no value. At most
|
| 421 |
+
32 cleanup functions can be registered. When the registration is successful,
|
| 422 |
+
:c:func:`Py_AtExit` returns ``0``; on failure, it returns ``-1``. The cleanup
|
| 423 |
+
function registered last is called first. Each cleanup function will be called
|
| 424 |
+
at most once. Since Python's internal finalization will have completed before
|
| 425 |
+
the cleanup function, no Python APIs should be called by *func*.
|
cpython_2/environment/repo/Doc/c-api/tuple.rst
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _tupleobjects:
|
| 4 |
+
|
| 5 |
+
Tuple Objects
|
| 6 |
+
-------------
|
| 7 |
+
|
| 8 |
+
.. index:: object: tuple
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
.. c:type:: PyTupleObject
|
| 12 |
+
|
| 13 |
+
This subtype of :c:type:`PyObject` represents a Python tuple object.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
.. c:var:: PyTypeObject PyTuple_Type
|
| 17 |
+
|
| 18 |
+
This instance of :c:type:`PyTypeObject` represents the Python tuple type; it
|
| 19 |
+
is the same object as :class:`tuple` in the Python layer.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
.. c:function:: int PyTuple_Check(PyObject *p)
|
| 23 |
+
|
| 24 |
+
Return true if *p* is a tuple object or an instance of a subtype of the tuple
|
| 25 |
+
type.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
.. c:function:: int PyTuple_CheckExact(PyObject *p)
|
| 29 |
+
|
| 30 |
+
Return true if *p* is a tuple object, but not an instance of a subtype of the
|
| 31 |
+
tuple type.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
.. c:function:: PyObject* PyTuple_New(Py_ssize_t len)
|
| 35 |
+
|
| 36 |
+
Return a new tuple object of size *len*, or ``NULL`` on failure.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
.. c:function:: PyObject* PyTuple_Pack(Py_ssize_t n, ...)
|
| 40 |
+
|
| 41 |
+
Return a new tuple object of size *n*, or ``NULL`` on failure. The tuple values
|
| 42 |
+
are initialized to the subsequent *n* C arguments pointing to Python objects.
|
| 43 |
+
``PyTuple_Pack(2, a, b)`` is equivalent to ``Py_BuildValue("(OO)", a, b)``.
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
.. c:function:: Py_ssize_t PyTuple_Size(PyObject *p)
|
| 47 |
+
|
| 48 |
+
Take a pointer to a tuple object, and return the size of that tuple.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
.. c:function:: Py_ssize_t PyTuple_GET_SIZE(PyObject *p)
|
| 52 |
+
|
| 53 |
+
Return the size of the tuple *p*, which must be non-``NULL`` and point to a tuple;
|
| 54 |
+
no error checking is performed.
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
.. c:function:: PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos)
|
| 58 |
+
|
| 59 |
+
Return the object at position *pos* in the tuple pointed to by *p*. If *pos* is
|
| 60 |
+
out of bounds, return ``NULL`` and set an :exc:`IndexError` exception.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
.. c:function:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)
|
| 64 |
+
|
| 65 |
+
Like :c:func:`PyTuple_GetItem`, but does no checking of its arguments.
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
.. c:function:: PyObject* PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)
|
| 69 |
+
|
| 70 |
+
Return the slice of the tuple pointed to by *p* between *low* and *high*,
|
| 71 |
+
or ``NULL`` on failure. This is the equivalent of the Python expression
|
| 72 |
+
``p[low:high]``. Indexing from the end of the list is not supported.
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
.. c:function:: int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
|
| 76 |
+
|
| 77 |
+
Insert a reference to object *o* at position *pos* of the tuple pointed to by
|
| 78 |
+
*p*. Return ``0`` on success. If *pos* is out of bounds, return ``-1``
|
| 79 |
+
and set an :exc:`IndexError` exception.
|
| 80 |
+
|
| 81 |
+
.. note::
|
| 82 |
+
|
| 83 |
+
This function "steals" a reference to *o* and discards a reference to
|
| 84 |
+
an item already in the tuple at the affected position.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
.. c:function:: void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o)
|
| 88 |
+
|
| 89 |
+
Like :c:func:`PyTuple_SetItem`, but does no error checking, and should *only* be
|
| 90 |
+
used to fill in brand new tuples.
|
| 91 |
+
|
| 92 |
+
.. note::
|
| 93 |
+
|
| 94 |
+
This macro "steals" a reference to *o*, and, unlike
|
| 95 |
+
:c:func:`PyTuple_SetItem`, does *not* discard a reference to any item that
|
| 96 |
+
is being replaced; any reference in the tuple at position *pos* will be
|
| 97 |
+
leaked.
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
.. c:function:: int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)
|
| 101 |
+
|
| 102 |
+
Can be used to resize a tuple. *newsize* will be the new length of the tuple.
|
| 103 |
+
Because tuples are *supposed* to be immutable, this should only be used if there
|
| 104 |
+
is only one reference to the object. Do *not* use this if the tuple may already
|
| 105 |
+
be known to some other part of the code. The tuple will always grow or shrink
|
| 106 |
+
at the end. Think of this as destroying the old tuple and creating a new one,
|
| 107 |
+
only more efficiently. Returns ``0`` on success. Client code should never
|
| 108 |
+
assume that the resulting value of ``*p`` will be the same as before calling
|
| 109 |
+
this function. If the object referenced by ``*p`` is replaced, the original
|
| 110 |
+
``*p`` is destroyed. On failure, returns ``-1`` and sets ``*p`` to ``NULL``, and
|
| 111 |
+
raises :exc:`MemoryError` or :exc:`SystemError`.
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
Struct Sequence Objects
|
| 115 |
+
-----------------------
|
| 116 |
+
|
| 117 |
+
Struct sequence objects are the C equivalent of :func:`~collections.namedtuple`
|
| 118 |
+
objects, i.e. a sequence whose items can also be accessed through attributes.
|
| 119 |
+
To create a struct sequence, you first have to create a specific struct sequence
|
| 120 |
+
type.
|
| 121 |
+
|
| 122 |
+
.. c:function:: PyTypeObject* PyStructSequence_NewType(PyStructSequence_Desc *desc)
|
| 123 |
+
|
| 124 |
+
Create a new struct sequence type from the data in *desc*, described below. Instances
|
| 125 |
+
of the resulting type can be created with :c:func:`PyStructSequence_New`.
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
.. c:function:: void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
|
| 129 |
+
|
| 130 |
+
Initializes a struct sequence type *type* from *desc* in place.
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
.. c:function:: int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
|
| 134 |
+
|
| 135 |
+
The same as ``PyStructSequence_InitType``, but returns ``0`` on success and ``-1`` on
|
| 136 |
+
failure.
|
| 137 |
+
|
| 138 |
+
.. versionadded:: 3.4
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
.. c:type:: PyStructSequence_Desc
|
| 142 |
+
|
| 143 |
+
Contains the meta information of a struct sequence type to create.
|
| 144 |
+
|
| 145 |
+
+-------------------+------------------------------+--------------------------------------+
|
| 146 |
+
| Field | C Type | Meaning |
|
| 147 |
+
+===================+==============================+======================================+
|
| 148 |
+
| ``name`` | ``const char *`` | name of the struct sequence type |
|
| 149 |
+
+-------------------+------------------------------+--------------------------------------+
|
| 150 |
+
| ``doc`` | ``const char *`` | pointer to docstring for the type |
|
| 151 |
+
| | | or ``NULL`` to omit |
|
| 152 |
+
+-------------------+------------------------------+--------------------------------------+
|
| 153 |
+
| ``fields`` | ``PyStructSequence_Field *`` | pointer to ``NULL``-terminated array |
|
| 154 |
+
| | | with field names of the new type |
|
| 155 |
+
+-------------------+------------------------------+--------------------------------------+
|
| 156 |
+
| ``n_in_sequence`` | ``int`` | number of fields visible to the |
|
| 157 |
+
| | | Python side (if used as tuple) |
|
| 158 |
+
+-------------------+------------------------------+--------------------------------------+
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
.. c:type:: PyStructSequence_Field
|
| 162 |
+
|
| 163 |
+
Describes a field of a struct sequence. As a struct sequence is modeled as a
|
| 164 |
+
tuple, all fields are typed as :c:type:`PyObject\*`. The index in the
|
| 165 |
+
:attr:`fields` array of the :c:type:`PyStructSequence_Desc` determines which
|
| 166 |
+
field of the struct sequence is described.
|
| 167 |
+
|
| 168 |
+
+-----------+------------------+-----------------------------------------+
|
| 169 |
+
| Field | C Type | Meaning |
|
| 170 |
+
+===========+==================+=========================================+
|
| 171 |
+
| ``name`` | ``const char *`` | name for the field or ``NULL`` to end |
|
| 172 |
+
| | | the list of named fields, set to |
|
| 173 |
+
| | | :c:data:`PyStructSequence_UnnamedField` |
|
| 174 |
+
| | | to leave unnamed |
|
| 175 |
+
+-----------+------------------+-----------------------------------------+
|
| 176 |
+
| ``doc`` | ``const char *`` | field docstring or ``NULL`` to omit |
|
| 177 |
+
+-----------+------------------+-----------------------------------------+
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
.. c:var:: const char * const PyStructSequence_UnnamedField
|
| 181 |
+
|
| 182 |
+
Special value for a field name to leave it unnamed.
|
| 183 |
+
|
| 184 |
+
.. versionchanged:: 3.9
|
| 185 |
+
The type was changed from ``char *``.
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
.. c:function:: PyObject* PyStructSequence_New(PyTypeObject *type)
|
| 189 |
+
|
| 190 |
+
Creates an instance of *type*, which must have been created with
|
| 191 |
+
:c:func:`PyStructSequence_NewType`.
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
.. c:function:: PyObject* PyStructSequence_GetItem(PyObject *p, Py_ssize_t pos)
|
| 195 |
+
|
| 196 |
+
Return the object at position *pos* in the struct sequence pointed to by *p*.
|
| 197 |
+
No bounds checking is performed.
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
.. c:function:: PyObject* PyStructSequence_GET_ITEM(PyObject *p, Py_ssize_t pos)
|
| 201 |
+
|
| 202 |
+
Macro equivalent of :c:func:`PyStructSequence_GetItem`.
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
.. c:function:: void PyStructSequence_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
|
| 206 |
+
|
| 207 |
+
Sets the field at index *pos* of the struct sequence *p* to value *o*. Like
|
| 208 |
+
:c:func:`PyTuple_SET_ITEM`, this should only be used to fill in brand new
|
| 209 |
+
instances.
|
| 210 |
+
|
| 211 |
+
.. note::
|
| 212 |
+
|
| 213 |
+
This function "steals" a reference to *o*.
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
.. c:function:: void PyStructSequence_SET_ITEM(PyObject *p, Py_ssize_t *pos, PyObject *o)
|
| 217 |
+
|
| 218 |
+
Macro equivalent of :c:func:`PyStructSequence_SetItem`.
|
| 219 |
+
|
| 220 |
+
.. note::
|
| 221 |
+
|
| 222 |
+
This function "steals" a reference to *o*.
|
cpython_2/environment/repo/Doc/c-api/type.rst
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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typeobjects:
|
| 4 |
+
|
| 5 |
+
Type Objects
|
| 6 |
+
------------
|
| 7 |
+
|
| 8 |
+
.. index:: object: type
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
.. c:type:: PyTypeObject
|
| 12 |
+
|
| 13 |
+
The C structure of the objects used to describe built-in types.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
.. c:var:: PyObject* PyType_Type
|
| 17 |
+
|
| 18 |
+
This is the type object for type objects; it is the same object as
|
| 19 |
+
:class:`type` in the Python layer.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
.. c:function:: int PyType_Check(PyObject *o)
|
| 23 |
+
|
| 24 |
+
Return non-zero if the object *o* is a type object, including instances of
|
| 25 |
+
types derived from the standard type object. Return 0 in all other cases.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
.. c:function:: int PyType_CheckExact(PyObject *o)
|
| 29 |
+
|
| 30 |
+
Return non-zero if the object *o* is a type object, but not a subtype of the
|
| 31 |
+
standard type object. Return 0 in all other cases.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
.. c:function:: unsigned int PyType_ClearCache()
|
| 35 |
+
|
| 36 |
+
Clear the internal lookup cache. Return the current version tag.
|
| 37 |
+
|
| 38 |
+
.. c:function:: unsigned long PyType_GetFlags(PyTypeObject* type)
|
| 39 |
+
|
| 40 |
+
Return the :c:member:`~PyTypeObject.tp_flags` member of *type*. This function is primarily
|
| 41 |
+
meant for use with `Py_LIMITED_API`; the individual flag bits are
|
| 42 |
+
guaranteed to be stable across Python releases, but access to
|
| 43 |
+
:c:member:`~PyTypeObject.tp_flags` itself is not part of the limited API.
|
| 44 |
+
|
| 45 |
+
.. versionadded:: 3.2
|
| 46 |
+
|
| 47 |
+
.. versionchanged:: 3.4
|
| 48 |
+
The return type is now ``unsigned long`` rather than ``long``.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
.. c:function:: void PyType_Modified(PyTypeObject *type)
|
| 52 |
+
|
| 53 |
+
Invalidate the internal lookup cache for the type and all of its
|
| 54 |
+
subtypes. This function must be called after any manual
|
| 55 |
+
modification of the attributes or base classes of the type.
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
.. c:function:: int PyType_HasFeature(PyTypeObject *o, int feature)
|
| 59 |
+
|
| 60 |
+
Return non-zero if the type object *o* sets the feature *feature*.
|
| 61 |
+
Type features are denoted by single bit flags.
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
.. c:function:: int PyType_IS_GC(PyTypeObject *o)
|
| 65 |
+
|
| 66 |
+
Return true if the type object includes support for the cycle detector; this
|
| 67 |
+
tests the type flag :const:`Py_TPFLAGS_HAVE_GC`.
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
.. c:function:: int PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b)
|
| 71 |
+
|
| 72 |
+
Return true if *a* is a subtype of *b*.
|
| 73 |
+
|
| 74 |
+
This function only checks for actual subtypes, which means that
|
| 75 |
+
:meth:`~class.__subclasscheck__` is not called on *b*. Call
|
| 76 |
+
:c:func:`PyObject_IsSubclass` to do the same check that :func:`issubclass`
|
| 77 |
+
would do.
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
.. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
|
| 81 |
+
|
| 82 |
+
Generic handler for the :c:member:`~PyTypeObject.tp_alloc` slot of a type object. Use
|
| 83 |
+
Python's default memory allocation mechanism to allocate a new instance and
|
| 84 |
+
initialize all its contents to ``NULL``.
|
| 85 |
+
|
| 86 |
+
.. c:function:: PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
| 87 |
+
|
| 88 |
+
Generic handler for the :c:member:`~PyTypeObject.tp_new` slot of a type object. Create a
|
| 89 |
+
new instance using the type's :c:member:`~PyTypeObject.tp_alloc` slot.
|
| 90 |
+
|
| 91 |
+
.. c:function:: int PyType_Ready(PyTypeObject *type)
|
| 92 |
+
|
| 93 |
+
Finalize a type object. This should be called on all type objects to finish
|
| 94 |
+
their initialization. This function is responsible for adding inherited slots
|
| 95 |
+
from a type's base class. Return ``0`` on success, or return ``-1`` and sets an
|
| 96 |
+
exception on error.
|
| 97 |
+
|
| 98 |
+
.. c:function:: void* PyType_GetSlot(PyTypeObject *type, int slot)
|
| 99 |
+
|
| 100 |
+
Return the function pointer stored in the given slot. If the
|
| 101 |
+
result is ``NULL``, this indicates that either the slot is ``NULL``,
|
| 102 |
+
or that the function was called with invalid parameters.
|
| 103 |
+
Callers will typically cast the result pointer into the appropriate
|
| 104 |
+
function type.
|
| 105 |
+
|
| 106 |
+
See :c:member:`PyType_Slot.slot` for possible values of the *slot* argument.
|
| 107 |
+
|
| 108 |
+
An exception is raised if *type* is not a heap type.
|
| 109 |
+
|
| 110 |
+
.. versionadded:: 3.4
|
| 111 |
+
|
| 112 |
+
.. c:function:: PyObject* PyType_GetModule(PyTypeObject *type)
|
| 113 |
+
|
| 114 |
+
Return the module object associated with the given type when the type was
|
| 115 |
+
created using :c:func:`PyType_FromModuleAndSpec`.
|
| 116 |
+
|
| 117 |
+
If no module is associated with the given type, sets :py:class:`TypeError`
|
| 118 |
+
and returns ``NULL``.
|
| 119 |
+
|
| 120 |
+
.. versionadded:: 3.9
|
| 121 |
+
|
| 122 |
+
.. c:function:: void* PyType_GetModuleState(PyTypeObject *type)
|
| 123 |
+
|
| 124 |
+
Return the state of the module object associated with the given type.
|
| 125 |
+
This is a shortcut for calling :c:func:`PyModule_GetState()` on the result
|
| 126 |
+
of :c:func:`PyType_GetModule`.
|
| 127 |
+
|
| 128 |
+
If no module is associated with the given type, sets :py:class:`TypeError`
|
| 129 |
+
and returns ``NULL``.
|
| 130 |
+
|
| 131 |
+
If the *type* has an associated module but its state is ``NULL``,
|
| 132 |
+
returns ``NULL`` without setting an exception.
|
| 133 |
+
|
| 134 |
+
.. versionadded:: 3.9
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
Creating Heap-Allocated Types
|
| 138 |
+
.............................
|
| 139 |
+
|
| 140 |
+
The following functions and structs are used to create
|
| 141 |
+
:ref:`heap types <heap-types>`.
|
| 142 |
+
|
| 143 |
+
.. c:function:: PyObject* PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
|
| 144 |
+
|
| 145 |
+
Creates and returns a heap type object from the *spec*
|
| 146 |
+
(:const:`Py_TPFLAGS_HEAPTYPE`).
|
| 147 |
+
|
| 148 |
+
If *bases* is a tuple, the created heap type contains all types contained
|
| 149 |
+
in it as base types.
|
| 150 |
+
|
| 151 |
+
If *bases* is ``NULL``, the *Py_tp_base* slot is used instead.
|
| 152 |
+
If that also is ``NULL``, the new type derives from :class:`object`.
|
| 153 |
+
|
| 154 |
+
The *module* must be a module object or ``NULL``.
|
| 155 |
+
If not ``NULL``, the module is associated with the new type and can later be
|
| 156 |
+
retreived with :c:func:`PyType_GetModule`.
|
| 157 |
+
|
| 158 |
+
This function calls :c:func:`PyType_Ready` on the new type.
|
| 159 |
+
|
| 160 |
+
.. versionadded:: 3.9
|
| 161 |
+
|
| 162 |
+
.. c:function:: PyObject* PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
|
| 163 |
+
|
| 164 |
+
Equivalent to ``PyType_FromModuleAndSpec(NULL, spec, bases)``.
|
| 165 |
+
|
| 166 |
+
.. versionadded:: 3.3
|
| 167 |
+
|
| 168 |
+
.. c:function:: PyObject* PyType_FromSpec(PyType_Spec *spec)
|
| 169 |
+
|
| 170 |
+
Equivalent to ``PyType_FromSpecWithBases(spec, NULL)``.
|
| 171 |
+
|
| 172 |
+
.. c:type:: PyType_Spec
|
| 173 |
+
|
| 174 |
+
Structure defining a type's behavior.
|
| 175 |
+
|
| 176 |
+
.. c:member:: const char* PyType_Spec.name
|
| 177 |
+
|
| 178 |
+
Name of the type, used to set :c:member:`PyTypeObject.tp_name`.
|
| 179 |
+
|
| 180 |
+
.. c:member:: int PyType_Spec.basicsize
|
| 181 |
+
.. c:member:: int PyType_Spec.itemsize
|
| 182 |
+
|
| 183 |
+
Size of the instance in bytes, used to set
|
| 184 |
+
:c:member:`PyTypeObject.tp_basicsize` and
|
| 185 |
+
:c:member:`PyTypeObject.tp_itemsize`.
|
| 186 |
+
|
| 187 |
+
.. c:member:: int PyType_Spec.flags
|
| 188 |
+
|
| 189 |
+
Type flags, used to set :c:member:`PyTypeObject.tp_flags`.
|
| 190 |
+
|
| 191 |
+
If the ``Py_TPFLAGS_HEAPTYPE`` flag is not set,
|
| 192 |
+
:c:func:`PyType_FromSpecWithBases` sets it automatically.
|
| 193 |
+
|
| 194 |
+
.. c:member:: PyType_Slot *PyType_Spec.slots
|
| 195 |
+
|
| 196 |
+
Array of :c:type:`PyType_Slot` structures.
|
| 197 |
+
Terminated by the special slot value ``{0, NULL}``.
|
| 198 |
+
|
| 199 |
+
.. c:type:: PyType_Slot
|
| 200 |
+
|
| 201 |
+
Structure defining optional functionality of a type, containing a slot ID
|
| 202 |
+
and a value pointer.
|
| 203 |
+
|
| 204 |
+
.. c:member:: int PyType_Slot.slot
|
| 205 |
+
|
| 206 |
+
A slot ID.
|
| 207 |
+
|
| 208 |
+
Slot IDs are named like the field names of the structures
|
| 209 |
+
:c:type:`PyTypeObject`, :c:type:`PyNumberMethods`,
|
| 210 |
+
:c:type:`PySequenceMethods`, :c:type:`PyMappingMethods` and
|
| 211 |
+
:c:type:`PyAsyncMethods` with an added ``Py_`` prefix.
|
| 212 |
+
For example, use:
|
| 213 |
+
|
| 214 |
+
* ``Py_tp_dealloc`` to set :c:member:`PyTypeObject.tp_dealloc`
|
| 215 |
+
* ``Py_nb_add`` to set :c:member:`PyNumberMethods.nb_add`
|
| 216 |
+
* ``Py_sq_length`` to set :c:member:`PySequenceMethods.sq_length`
|
| 217 |
+
|
| 218 |
+
The following fields cannot be set using :c:type:`PyType_Spec` and :c:type:`PyType_Slot`:
|
| 219 |
+
|
| 220 |
+
* :c:member:`~PyTypeObject.tp_dict`
|
| 221 |
+
* :c:member:`~PyTypeObject.tp_mro`
|
| 222 |
+
* :c:member:`~PyTypeObject.tp_cache`
|
| 223 |
+
* :c:member:`~PyTypeObject.tp_subclasses`
|
| 224 |
+
* :c:member:`~PyTypeObject.tp_weaklist`
|
| 225 |
+
* :c:member:`~PyTypeObject.tp_vectorcall`
|
| 226 |
+
* :c:member:`~PyTypeObject.tp_weaklistoffset`
|
| 227 |
+
(see :ref:`PyMemberDef <pymemberdef-offsets>`)
|
| 228 |
+
* :c:member:`~PyTypeObject.tp_dictoffset`
|
| 229 |
+
(see :ref:`PyMemberDef <pymemberdef-offsets>`)
|
| 230 |
+
* :c:member:`~PyTypeObject.tp_vectorcall_offset`
|
| 231 |
+
(see :ref:`PyMemberDef <pymemberdef-offsets>`)
|
| 232 |
+
* :c:member:`~PyBufferProcs.bf_getbuffer`
|
| 233 |
+
* :c:member:`~PyBufferProcs.bf_releasebuffer`
|
| 234 |
+
|
| 235 |
+
Setting :c:data:`Py_tp_bases` may be problematic on some platforms.
|
| 236 |
+
To avoid issues, use the *bases* argument of
|
| 237 |
+
:py:func:`PyType_FromSpecWithBases` instead.
|
| 238 |
+
|
| 239 |
+
.. c:member:: void *PyType_Slot.pfunc
|
| 240 |
+
|
| 241 |
+
The desired value of the slot. In most cases, this is a pointer
|
| 242 |
+
to a function.
|
| 243 |
+
|
| 244 |
+
May not be ``NULL``.
|
cpython_2/environment/repo/Doc/c-api/typeobj.rst
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpython_2/environment/repo/Doc/c-api/unicode.rst
ADDED
|
@@ -0,0 +1,1731 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ecs
|
| 6 |
+
--------------------------
|
| 7 |
+
|
| 8 |
+
.. sectionauthor:: Marc-André Lemburg <mal@lemburg.com>
|
| 9 |
+
.. sectionauthor:: Georg Brandl <georg@python.org>
|
| 10 |
+
|
| 11 |
+
Unicode Objects
|
| 12 |
+
^^^^^^^^^^^^^^^
|
| 13 |
+
|
| 14 |
+
Since the implementation of :pep:`393` in Python 3.3, Unicode objects internally
|
| 15 |
+
use a variety of representations, in order to allow handling the complete range
|
| 16 |
+
of Unicode characters while staying memory efficient. There are special cases
|
| 17 |
+
for strings where all code points are below 128, 256, or 65536; otherwise, code
|
| 18 |
+
points must be below 1114112 (which is the full Unicode range).
|
| 19 |
+
|
| 20 |
+
:c:type:`Py_UNICODE*` and UTF-8 representations are created on demand and cached
|
| 21 |
+
in the Unicode object. The :c:type:`Py_UNICODE*` representation is deprecated
|
| 22 |
+
and inefficient; it should be avoided in performance- or memory-sensitive
|
| 23 |
+
situations.
|
| 24 |
+
|
| 25 |
+
Due to the transition between the old APIs and the new APIs, Unicode objects
|
| 26 |
+
can internally be in two states depending on how they were created:
|
| 27 |
+
|
| 28 |
+
* "canonical" Unicode objects are all objects created by a non-deprecated
|
| 29 |
+
Unicode API. They use the most efficient representation allowed by the
|
| 30 |
+
implementation.
|
| 31 |
+
|
| 32 |
+
* "legacy" Unicode objects have been created through one of the deprecated
|
| 33 |
+
APIs (typically :c:func:`PyUnicode_FromUnicode`) and only bear the
|
| 34 |
+
:c:type:`Py_UNICODE*` representation; you will have to call
|
| 35 |
+
:c:func:`PyUnicode_READY` on them before calling any other API.
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Unicode Type
|
| 39 |
+
""""""""""""
|
| 40 |
+
|
| 41 |
+
These are the basic Unicode object types used for the Unicode implementation in
|
| 42 |
+
Python:
|
| 43 |
+
|
| 44 |
+
.. c:type:: Py_UCS4
|
| 45 |
+
Py_UCS2
|
| 46 |
+
Py_UCS1
|
| 47 |
+
|
| 48 |
+
These types are typedefs for unsigned integer types wide enough to contain
|
| 49 |
+
characters of 32 bits, 16 bits and 8 bits, respectively. When dealing with
|
| 50 |
+
single Unicode characters, use :c:type:`Py_UCS4`.
|
| 51 |
+
|
| 52 |
+
.. versionadded:: 3.3
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
.. c:type:: Py_UNICODE
|
| 56 |
+
|
| 57 |
+
This is a typedef of :c:type:`wchar_t`, which is a 16-bit type or 32-bit type
|
| 58 |
+
depending on the platform.
|
| 59 |
+
|
| 60 |
+
.. versionchanged:: 3.3
|
| 61 |
+
In previous versions, this was a 16-bit type or a 32-bit type depending on
|
| 62 |
+
whether you selected a "narrow" or "wide" Unicode version of Python at
|
| 63 |
+
build time.
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
.. c:type:: PyASCIIObject
|
| 67 |
+
PyCompactUnicodeObject
|
| 68 |
+
PyUnicodeObject
|
| 69 |
+
|
| 70 |
+
These subtypes of :c:type:`PyObject` represent a Python Unicode object. In
|
| 71 |
+
almost all cases, they shouldn't be used directly, since all API functions
|
| 72 |
+
that deal with Unicode objects take and return :c:type:`PyObject` pointers.
|
| 73 |
+
|
| 74 |
+
.. versionadded:: 3.3
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
.. c:var:: PyTypeObject PyUnicode_Type
|
| 78 |
+
|
| 79 |
+
This instance of :c:type:`PyTypeObject` represents the Python Unicode type. It
|
| 80 |
+
is exposed to Python code as ``str``.
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
The following APIs are really C macros and can be used to do fast checks and to
|
| 84 |
+
access internal read-only data of Unicode objects:
|
| 85 |
+
|
| 86 |
+
.. c:function:: int PyUnicode_Check(PyObject *o)
|
| 87 |
+
|
| 88 |
+
Return true if the object *o* is a Unicode object or an instance of a Unicode
|
| 89 |
+
subtype.
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
.. c:function:: int PyUnicode_CheckExact(PyObject *o)
|
| 93 |
+
|
| 94 |
+
Return true if the object *o* is a Unicode object, but not an instance of a
|
| 95 |
+
subtype.
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
.. c:function:: int PyUnicode_READY(PyObject *o)
|
| 99 |
+
|
| 100 |
+
Ensure the string object *o* is in the "canonical" representation. This is
|
| 101 |
+
required before using any of the access macros described below.
|
| 102 |
+
|
| 103 |
+
.. XXX expand on when it is not required
|
| 104 |
+
|
| 105 |
+
Returns ``0`` on success and ``-1`` with an exception set on failure, which in
|
| 106 |
+
particular happens if memory allocation fails.
|
| 107 |
+
|
| 108 |
+
.. versionadded:: 3.3
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
.. c:function:: Py_ssize_t PyUnicode_GET_LENGTH(PyObject *o)
|
| 112 |
+
|
| 113 |
+
Return the length of the Unicode string, in code points. *o* has to be a
|
| 114 |
+
Unicode object in the "canonical" representation (not checked).
|
| 115 |
+
|
| 116 |
+
.. versionadded:: 3.3
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
.. c:function:: Py_UCS1* PyUnicode_1BYTE_DATA(PyObject *o)
|
| 120 |
+
Py_UCS2* PyUnicode_2BYTE_DATA(PyObject *o)
|
| 121 |
+
Py_UCS4* PyUnicode_4BYTE_DATA(PyObject *o)
|
| 122 |
+
|
| 123 |
+
Return a pointer to the canonical representation cast to UCS1, UCS2 or UCS4
|
| 124 |
+
integer types for direct character access. No checks are performed if the
|
| 125 |
+
canonical representation has the correct character size; use
|
| 126 |
+
:c:func:`PyUnicode_KIND` to select the right macro. Make sure
|
| 127 |
+
:c:func:`PyUnicode_READY` has been called before accessing this.
|
| 128 |
+
|
| 129 |
+
.. versionadded:: 3.3
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
.. c:macro:: PyUnicode_WCHAR_KIND
|
| 133 |
+
PyUnicode_1BYTE_KIND
|
| 134 |
+
PyUnicode_2BYTE_KIND
|
| 135 |
+
PyUnicode_4BYTE_KIND
|
| 136 |
+
|
| 137 |
+
Return values of the :c:func:`PyUnicode_KIND` macro.
|
| 138 |
+
|
| 139 |
+
.. versionadded:: 3.3
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
.. c:function:: int PyUnicode_KIND(PyObject *o)
|
| 143 |
+
|
| 144 |
+
Return one of the PyUnicode kind constants (see above) that indicate how many
|
| 145 |
+
bytes per character this Unicode object uses to store its data. *o* has to
|
| 146 |
+
be a Unicode object in the "canonical" representation (not checked).
|
| 147 |
+
|
| 148 |
+
.. XXX document "0" return value?
|
| 149 |
+
|
| 150 |
+
.. versionadded:: 3.3
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
.. c:function:: void* PyUnicode_DATA(PyObject *o)
|
| 154 |
+
|
| 155 |
+
Return a void pointer to the raw Unicode buffer. *o* has to be a Unicode
|
| 156 |
+
object in the "canonical" representation (not checked).
|
| 157 |
+
|
| 158 |
+
.. versionadded:: 3.3
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
.. c:function:: void PyUnicode_WRITE(int kind, void *data, Py_ssize_t index, \
|
| 162 |
+
Py_UCS4 value)
|
| 163 |
+
|
| 164 |
+
Write into a canonical representation *data* (as obtained with
|
| 165 |
+
:c:func:`PyUnicode_DATA`). This macro does not do any sanity checks and is
|
| 166 |
+
intended for usage in loops. The caller should cache the *kind* value and
|
| 167 |
+
*data* pointer as obtained from other macro calls. *index* is the index in
|
| 168 |
+
the string (starts at 0) and *value* is the new code point value which should
|
| 169 |
+
be written to that location.
|
| 170 |
+
|
| 171 |
+
.. versionadded:: 3.3
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
.. c:function:: Py_UCS4 PyUnicode_READ(int kind, void *data, Py_ssize_t index)
|
| 175 |
+
|
| 176 |
+
Read a code point from a canonical representation *data* (as obtained with
|
| 177 |
+
:c:func:`PyUnicode_DATA`). No checks or ready calls are performed.
|
| 178 |
+
|
| 179 |
+
.. versionadded:: 3.3
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
.. c:function:: Py_UCS4 PyUnicode_READ_CHAR(PyObject *o, Py_ssize_t index)
|
| 183 |
+
|
| 184 |
+
Read a character from a Unicode object *o*, which must be in the "canonical"
|
| 185 |
+
representation. This is less efficient than :c:func:`PyUnicode_READ` if you
|
| 186 |
+
do multiple consecutive reads.
|
| 187 |
+
|
| 188 |
+
.. versionadded:: 3.3
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
.. c:function:: PyUnicode_MAX_CHAR_VALUE(PyObject *o)
|
| 192 |
+
|
| 193 |
+
Return the maximum code point that is suitable for creating another string
|
| 194 |
+
based on *o*, which must be in the "canonical" representation. This is
|
| 195 |
+
always an approximation but more efficient than iterating over the string.
|
| 196 |
+
|
| 197 |
+
.. versionadded:: 3.3
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
.. c:function:: Py_ssize_t PyUnicode_GET_SIZE(PyObject *o)
|
| 201 |
+
|
| 202 |
+
Return the size of the deprecated :c:type:`Py_UNICODE` representation, in
|
| 203 |
+
code units (this includes surrogate pairs as 2 units). *o* has to be a
|
| 204 |
+
Unicode object (not checked).
|
| 205 |
+
|
| 206 |
+
.. deprecated-removed:: 3.3 4.0
|
| 207 |
+
Part of the old-style Unicode API, please migrate to using
|
| 208 |
+
:c:func:`PyUnicode_GET_LENGTH`.
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
.. c:function:: Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *o)
|
| 212 |
+
|
| 213 |
+
Return the size of the deprecated :c:type:`Py_UNICODE` representation in
|
| 214 |
+
bytes. *o* has to be a Unicode object (not checked).
|
| 215 |
+
|
| 216 |
+
.. deprecated-removed:: 3.3 4.0
|
| 217 |
+
Part of the old-style Unicode API, please migrate to using
|
| 218 |
+
:c:func:`PyUnicode_GET_LENGTH`.
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
.. c:function:: Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *o)
|
| 222 |
+
const char* PyUnicode_AS_DATA(PyObject *o)
|
| 223 |
+
|
| 224 |
+
Return a pointer to a :c:type:`Py_UNICODE` representation of the object. The
|
| 225 |
+
returned buffer is always terminated with an extra null code point. It
|
| 226 |
+
may also contain embedded null code points, which would cause the string
|
| 227 |
+
to be truncated when used in most C functions. The ``AS_DATA`` form
|
| 228 |
+
casts the pointer to :c:type:`const char *`. The *o* argument has to be
|
| 229 |
+
a Unicode object (not checked).
|
| 230 |
+
|
| 231 |
+
.. versionchanged:: 3.3
|
| 232 |
+
This macro is now inefficient -- because in many cases the
|
| 233 |
+
:c:type:`Py_UNICODE` representation does not exist and needs to be created
|
| 234 |
+
-- and can fail (return ``NULL`` with an exception set). Try to port the
|
| 235 |
+
code to use the new :c:func:`PyUnicode_nBYTE_DATA` macros or use
|
| 236 |
+
:c:func:`PyUnicode_WRITE` or :c:func:`PyUnicode_READ`.
|
| 237 |
+
|
| 238 |
+
.. deprecated-removed:: 3.3 4.0
|
| 239 |
+
Part of the old-style Unicode API, please migrate to using the
|
| 240 |
+
:c:func:`PyUnicode_nBYTE_DATA` family of macros.
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
.. c:function:: int PyUnicode_IsIdentifier(PyObject *o)
|
| 244 |
+
|
| 245 |
+
Return ``1`` if the string is a valid identifier according to the language
|
| 246 |
+
definition, section :ref:`identifiers`. Return ``0`` otherwise.
|
| 247 |
+
|
| 248 |
+
.. versionchanged:: 3.9
|
| 249 |
+
The function does not call :c:func:`Py_FatalError` anymore if the string
|
| 250 |
+
is not ready.
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
Unicode Character Properties
|
| 254 |
+
""""""""""""""""""""""""""""
|
| 255 |
+
|
| 256 |
+
Unicode provides many different character properties. The most often needed ones
|
| 257 |
+
are available through these macros which are mapped to C functions depending on
|
| 258 |
+
the Python configuration.
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
.. c:function:: int Py_UNICODE_ISSPACE(Py_UNICODE ch)
|
| 262 |
+
|
| 263 |
+
Return ``1`` or ``0`` depending on whether *ch* is a whitespace character.
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
.. c:function:: int Py_UNICODE_ISLOWER(Py_UNICODE ch)
|
| 267 |
+
|
| 268 |
+
Return ``1`` or ``0`` depending on whether *ch* is a lowercase character.
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
.. c:function:: int Py_UNICODE_ISUPPER(Py_UNICODE ch)
|
| 272 |
+
|
| 273 |
+
Return ``1`` or ``0`` depending on whether *ch* is an uppercase character.
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
.. c:function:: int Py_UNICODE_ISTITLE(Py_UNICODE ch)
|
| 277 |
+
|
| 278 |
+
Return ``1`` or ``0`` depending on whether *ch* is a titlecase character.
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
.. c:function:: int Py_UNICODE_ISLINEBREAK(Py_UNICODE ch)
|
| 282 |
+
|
| 283 |
+
Return ``1`` or ``0`` depending on whether *ch* is a linebreak character.
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
.. c:function:: int Py_UNICODE_ISDECIMAL(Py_UNICODE ch)
|
| 287 |
+
|
| 288 |
+
Return ``1`` or ``0`` depending on whether *ch* is a decimal character.
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
.. c:function:: int Py_UNICODE_ISDIGIT(Py_UNICODE ch)
|
| 292 |
+
|
| 293 |
+
Return ``1`` or ``0`` depending on whether *ch* is a digit character.
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
.. c:function:: int Py_UNICODE_ISNUMERIC(Py_UNICODE ch)
|
| 297 |
+
|
| 298 |
+
Return ``1`` or ``0`` depending on whether *ch* is a numeric character.
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
.. c:function:: int Py_UNICODE_ISALPHA(Py_UNICODE ch)
|
| 302 |
+
|
| 303 |
+
Return ``1`` or ``0`` depending on whether *ch* is an alphabetic character.
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
.. c:function:: int Py_UNICODE_ISALNUM(Py_UNICODE ch)
|
| 307 |
+
|
| 308 |
+
Return ``1`` or ``0`` depending on whether *ch* is an alphanumeric character.
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
.. c:function:: int Py_UNICODE_ISPRINTABLE(Py_UNICODE ch)
|
| 312 |
+
|
| 313 |
+
Return ``1`` or ``0`` depending on whether *ch* is a printable character.
|
| 314 |
+
Nonprintable characters are those characters defined in the Unicode character
|
| 315 |
+
database as "Other" or "Separator", excepting the ASCII space (0x20) which is
|
| 316 |
+
considered printable. (Note that printable characters in this context are
|
| 317 |
+
those which should not be escaped when :func:`repr` is invoked on a string.
|
| 318 |
+
It has no bearing on the handling of strings written to :data:`sys.stdout` or
|
| 319 |
+
:data:`sys.stderr`.)
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
These APIs can be used for fast direct character conversions:
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
.. c:function:: Py_UNICODE Py_UNICODE_TOLOWER(Py_UNICODE ch)
|
| 326 |
+
|
| 327 |
+
Return the character *ch* converted to lower case.
|
| 328 |
+
|
| 329 |
+
.. deprecated:: 3.3
|
| 330 |
+
This function uses simple case mappings.
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
.. c:function:: Py_UNICODE Py_UNICODE_TOUPPER(Py_UNICODE ch)
|
| 334 |
+
|
| 335 |
+
Return the character *ch* converted to upper case.
|
| 336 |
+
|
| 337 |
+
.. deprecated:: 3.3
|
| 338 |
+
This function uses simple case mappings.
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
.. c:function:: Py_UNICODE Py_UNICODE_TOTITLE(Py_UNICODE ch)
|
| 342 |
+
|
| 343 |
+
Return the character *ch* converted to title case.
|
| 344 |
+
|
| 345 |
+
.. deprecated:: 3.3
|
| 346 |
+
This function uses simple case mappings.
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
.. c:function:: int Py_UNICODE_TODECIMAL(Py_UNICODE ch)
|
| 350 |
+
|
| 351 |
+
Return the character *ch* converted to a decimal positive integer. Return
|
| 352 |
+
``-1`` if this is not possible. This macro does not raise exceptions.
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
.. c:function:: int Py_UNICODE_TODIGIT(Py_UNICODE ch)
|
| 356 |
+
|
| 357 |
+
Return the character *ch* converted to a single digit integer. Return ``-1`` if
|
| 358 |
+
this is not possible. This macro does not raise exceptions.
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
.. c:function:: double Py_UNICODE_TONUMERIC(Py_UNICODE ch)
|
| 362 |
+
|
| 363 |
+
Return the character *ch* converted to a double. Return ``-1.0`` if this is not
|
| 364 |
+
possible. This macro does not raise exceptions.
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
These APIs can be used to work with surrogates:
|
| 368 |
+
|
| 369 |
+
.. c:macro:: Py_UNICODE_IS_SURROGATE(ch)
|
| 370 |
+
|
| 371 |
+
Check if *ch* is a surrogate (``0xD800 <= ch <= 0xDFFF``).
|
| 372 |
+
|
| 373 |
+
.. c:macro:: Py_UNICODE_IS_HIGH_SURROGATE(ch)
|
| 374 |
+
|
| 375 |
+
Check if *ch* is a high surrogate (``0xD800 <= ch <= 0xDBFF``).
|
| 376 |
+
|
| 377 |
+
.. c:macro:: Py_UNICODE_IS_LOW_SURROGATE(ch)
|
| 378 |
+
|
| 379 |
+
Check if *ch* is a low surrogate (``0xDC00 <= ch <= 0xDFFF``).
|
| 380 |
+
|
| 381 |
+
.. c:macro:: Py_UNICODE_JOIN_SURROGATES(high, low)
|
| 382 |
+
|
| 383 |
+
Join two surrogate characters and return a single Py_UCS4 value.
|
| 384 |
+
*high* and *low* are respectively the leading and trailing surrogates in a
|
| 385 |
+
surrogate pair.
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
Creating and accessing Unicode strings
|
| 389 |
+
""""""""""""""""""""""""""""""""""""""
|
| 390 |
+
|
| 391 |
+
To create Unicode objects and access their basic sequence properties, use these
|
| 392 |
+
APIs:
|
| 393 |
+
|
| 394 |
+
.. c:function:: PyObject* PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar)
|
| 395 |
+
|
| 396 |
+
Create a new Unicode object. *maxchar* should be the true maximum code point
|
| 397 |
+
to be placed in the string. As an approximation, it can be rounded up to the
|
| 398 |
+
nearest value in the sequence 127, 255, 65535, 1114111.
|
| 399 |
+
|
| 400 |
+
This is the recommended way to allocate a new Unicode object. Objects
|
| 401 |
+
created using this function are not resizable.
|
| 402 |
+
|
| 403 |
+
.. versionadded:: 3.3
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
.. c:function:: PyObject* PyUnicode_FromKindAndData(int kind, const void *buffer, \
|
| 407 |
+
Py_ssize_t size)
|
| 408 |
+
|
| 409 |
+
Create a new Unicode object with the given *kind* (possible values are
|
| 410 |
+
:c:macro:`PyUnicode_1BYTE_KIND` etc., as returned by
|
| 411 |
+
:c:func:`PyUnicode_KIND`). The *buffer* must point to an array of *size*
|
| 412 |
+
units of 1, 2 or 4 bytes per character, as given by the kind.
|
| 413 |
+
|
| 414 |
+
.. versionadded:: 3.3
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
.. c:function:: PyObject* PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size)
|
| 418 |
+
|
| 419 |
+
Create a Unicode object from the char buffer *u*. The bytes will be
|
| 420 |
+
interpreted as being UTF-8 encoded. The buffer is copied into the new
|
| 421 |
+
object. If the buffer is not ``NULL``, the return value might be a shared
|
| 422 |
+
object, i.e. modification of the data is not allowed.
|
| 423 |
+
|
| 424 |
+
If *u* is ``NULL``, this function behaves like :c:func:`PyUnicode_FromUnicode`
|
| 425 |
+
with the buffer set to ``NULL``. This usage is deprecated in favor of
|
| 426 |
+
:c:func:`PyUnicode_New`.
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
.. c:function:: PyObject *PyUnicode_FromString(const char *u)
|
| 430 |
+
|
| 431 |
+
Create a Unicode object from a UTF-8 encoded null-terminated char buffer
|
| 432 |
+
*u*.
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
.. c:function:: PyObject* PyUnicode_FromFormat(const char *format, ...)
|
| 436 |
+
|
| 437 |
+
Take a C :c:func:`printf`\ -style *format* string and a variable number of
|
| 438 |
+
arguments, calculate the size of the resulting Python Unicode string and return
|
| 439 |
+
a string with the values formatted into it. The variable arguments must be C
|
| 440 |
+
types and must correspond exactly to the format characters in the *format*
|
| 441 |
+
ASCII-encoded string. The following format characters are allowed:
|
| 442 |
+
|
| 443 |
+
.. % This should be exactly the same as the table in PyErr_Format.
|
| 444 |
+
.. % The descriptions for %zd and %zu are wrong, but the truth is complicated
|
| 445 |
+
.. % because not all compilers support the %z width modifier -- we fake it
|
| 446 |
+
.. % when necessary via interpolating PY_FORMAT_SIZE_T.
|
| 447 |
+
.. % Similar comments apply to the %ll width modifier and
|
| 448 |
+
|
| 449 |
+
.. tabularcolumns:: |l|l|L|
|
| 450 |
+
|
| 451 |
+
+-------------------+---------------------+----------------------------------+
|
| 452 |
+
| Format Characters | Type | Comment |
|
| 453 |
+
+===================+=====================+==================================+
|
| 454 |
+
| :attr:`%%` | *n/a* | The literal % character. |
|
| 455 |
+
+-------------------+---------------------+----------------------------------+
|
| 456 |
+
| :attr:`%c` | int | A single character, |
|
| 457 |
+
| | | represented as a C int. |
|
| 458 |
+
+-------------------+---------------------+----------------------------------+
|
| 459 |
+
| :attr:`%d` | int | Equivalent to |
|
| 460 |
+
| | | ``printf("%d")``. [1]_ |
|
| 461 |
+
+-------------------+---------------------+----------------------------------+
|
| 462 |
+
| :attr:`%u` | unsigned int | Equivalent to |
|
| 463 |
+
| | | ``printf("%u")``. [1]_ |
|
| 464 |
+
+-------------------+---------------------+----------------------------------+
|
| 465 |
+
| :attr:`%ld` | long | Equivalent to |
|
| 466 |
+
| | | ``printf("%ld")``. [1]_ |
|
| 467 |
+
+-------------------+---------------------+----------------------------------+
|
| 468 |
+
| :attr:`%li` | long | Equivalent to |
|
| 469 |
+
| | | ``printf("%li")``. [1]_ |
|
| 470 |
+
+-------------------+---------------------+----------------------------------+
|
| 471 |
+
| :attr:`%lu` | unsigned long | Equivalent to |
|
| 472 |
+
| | | ``printf("%lu")``. [1]_ |
|
| 473 |
+
+-------------------+---------------------+----------------------------------+
|
| 474 |
+
| :attr:`%lld` | long long | Equivalent to |
|
| 475 |
+
| | | ``printf("%lld")``. [1]_ |
|
| 476 |
+
+-------------------+---------------------+----------------------------------+
|
| 477 |
+
| :attr:`%lli` | long long | Equivalent to |
|
| 478 |
+
| | | ``printf("%lli")``. [1]_ |
|
| 479 |
+
+-------------------+---------------------+----------------------------------+
|
| 480 |
+
| :attr:`%llu` | unsigned long long | Equivalent to |
|
| 481 |
+
| | | ``printf("%llu")``. [1]_ |
|
| 482 |
+
+-------------------+---------------------+----------------------------------+
|
| 483 |
+
| :attr:`%zd` | Py_ssize_t | Equivalent to |
|
| 484 |
+
| | | ``printf("%zd")``. [1]_ |
|
| 485 |
+
+-------------------+---------------------+----------------------------------+
|
| 486 |
+
| :attr:`%zi` | Py_ssize_t | Equivalent to |
|
| 487 |
+
| | | ``printf("%zi")``. [1]_ |
|
| 488 |
+
+-------------------+---------------------+----------------------------------+
|
| 489 |
+
| :attr:`%zu` | size_t | Equivalent to |
|
| 490 |
+
| | | ``printf("%zu")``. [1]_ |
|
| 491 |
+
+-------------------+---------------------+----------------------------------+
|
| 492 |
+
| :attr:`%i` | int | Equivalent to |
|
| 493 |
+
| | | ``printf("%i")``. [1]_ |
|
| 494 |
+
+-------------------+---------------------+----------------------------------+
|
| 495 |
+
| :attr:`%x` | int | Equivalent to |
|
| 496 |
+
| | | ``printf("%x")``. [1]_ |
|
| 497 |
+
+-------------------+---------------------+----------------------------------+
|
| 498 |
+
| :attr:`%s` | const char\* | A null-terminated C character |
|
| 499 |
+
| | | array. |
|
| 500 |
+
+-------------------+---------------------+----------------------------------+
|
| 501 |
+
| :attr:`%p` | const void\* | The hex representation of a C |
|
| 502 |
+
| | | pointer. Mostly equivalent to |
|
| 503 |
+
| | | ``printf("%p")`` except that |
|
| 504 |
+
| | | it is guaranteed to start with |
|
| 505 |
+
| | | the literal ``0x`` regardless |
|
| 506 |
+
| | | of what the platform's |
|
| 507 |
+
| | | ``printf`` yields. |
|
| 508 |
+
+-------------------+---------------------+----------------------------------+
|
| 509 |
+
| :attr:`%A` | PyObject\* | The result of calling |
|
| 510 |
+
| | | :func:`ascii`. |
|
| 511 |
+
+-------------------+---------------------+----------------------------------+
|
| 512 |
+
| :attr:`%U` | PyObject\* | A Unicode object. |
|
| 513 |
+
+-------------------+---------------------+----------------------------------+
|
| 514 |
+
| :attr:`%V` | PyObject\*, | A Unicode object (which may be |
|
| 515 |
+
| | const char\* | ``NULL``) and a null-terminated |
|
| 516 |
+
| | | C character array as a second |
|
| 517 |
+
| | | parameter (which will be used, |
|
| 518 |
+
| | | if the first parameter is |
|
| 519 |
+
| | | ``NULL``). |
|
| 520 |
+
+-------------------+---------------------+----------------------------------+
|
| 521 |
+
| :attr:`%S` | PyObject\* | The result of calling |
|
| 522 |
+
| | | :c:func:`PyObject_Str`. |
|
| 523 |
+
+-------------------+---------------------+----------------------------------+
|
| 524 |
+
| :attr:`%R` | PyObject\* | The result of calling |
|
| 525 |
+
| | | :c:func:`PyObject_Repr`. |
|
| 526 |
+
+-------------------+---------------------+----------------------------------+
|
| 527 |
+
|
| 528 |
+
An unrecognized format character causes all the rest of the format string to be
|
| 529 |
+
copied as-is to the result string, and any extra arguments discarded.
|
| 530 |
+
|
| 531 |
+
.. note::
|
| 532 |
+
The width formatter unit is number of characters rather than bytes.
|
| 533 |
+
The precision formatter unit is number of bytes for ``"%s"`` and
|
| 534 |
+
``"%V"`` (if the ``PyObject*`` argument is ``NULL``), and a number of
|
| 535 |
+
characters for ``"%A"``, ``"%U"``, ``"%S"``, ``"%R"`` and ``"%V"``
|
| 536 |
+
(if the ``PyObject*`` argument is not ``NULL``).
|
| 537 |
+
|
| 538 |
+
.. [1] For integer specifiers (d, u, ld, li, lu, lld, lli, llu, zd, zi,
|
| 539 |
+
zu, i, x): the 0-conversion flag has effect even when a precision is given.
|
| 540 |
+
|
| 541 |
+
.. versionchanged:: 3.2
|
| 542 |
+
Support for ``"%lld"`` and ``"%llu"`` added.
|
| 543 |
+
|
| 544 |
+
.. versionchanged:: 3.3
|
| 545 |
+
Support for ``"%li"``, ``"%lli"`` and ``"%zi"`` added.
|
| 546 |
+
|
| 547 |
+
.. versionchanged:: 3.4
|
| 548 |
+
Support width and precision formatter for ``"%s"``, ``"%A"``, ``"%U"``,
|
| 549 |
+
``"%V"``, ``"%S"``, ``"%R"`` added.
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
.. c:function:: PyObject* PyUnicode_FromFormatV(const char *format, va_list vargs)
|
| 553 |
+
|
| 554 |
+
Identical to :c:func:`PyUnicode_FromFormat` except that it takes exactly two
|
| 555 |
+
arguments.
|
| 556 |
+
|
| 557 |
+
|
| 558 |
+
.. c:function:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, \
|
| 559 |
+
const char *encoding, const char *errors)
|
| 560 |
+
|
| 561 |
+
Decode an encoded object *obj* to a Unicode object.
|
| 562 |
+
|
| 563 |
+
:class:`bytes`, :class:`bytearray` and other
|
| 564 |
+
:term:`bytes-like objects <bytes-like object>`
|
| 565 |
+
are decoded according to the given *encoding* and using the error handling
|
| 566 |
+
defined by *errors*. Both can be ``NULL`` to have the interface use the default
|
| 567 |
+
values (see :ref:`builtincodecs` for details).
|
| 568 |
+
|
| 569 |
+
All other objects, including Unicode objects, cause a :exc:`TypeError` to be
|
| 570 |
+
set.
|
| 571 |
+
|
| 572 |
+
The API returns ``NULL`` if there was an error. The caller is responsible for
|
| 573 |
+
decref'ing the returned objects.
|
| 574 |
+
|
| 575 |
+
|
| 576 |
+
.. c:function:: Py_ssize_t PyUnicode_GetLength(PyObject *unicode)
|
| 577 |
+
|
| 578 |
+
Return the length of the Unicode object, in code points.
|
| 579 |
+
|
| 580 |
+
.. versionadded:: 3.3
|
| 581 |
+
|
| 582 |
+
|
| 583 |
+
.. c:function:: Py_ssize_t PyUnicode_CopyCharacters(PyObject *to, \
|
| 584 |
+
Py_ssize_t to_start, \
|
| 585 |
+
PyObject *from, \
|
| 586 |
+
Py_ssize_t from_start, \
|
| 587 |
+
Py_ssize_t how_many)
|
| 588 |
+
|
| 589 |
+
Copy characters from one Unicode object into another. This function performs
|
| 590 |
+
character conversion when necessary and falls back to :c:func:`memcpy` if
|
| 591 |
+
possible. Returns ``-1`` and sets an exception on error, otherwise returns
|
| 592 |
+
the number of copied characters.
|
| 593 |
+
|
| 594 |
+
.. versionadded:: 3.3
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
.. c:function:: Py_ssize_t PyUnicode_Fill(PyObject *unicode, Py_ssize_t start, \
|
| 598 |
+
Py_ssize_t length, Py_UCS4 fill_char)
|
| 599 |
+
|
| 600 |
+
Fill a string with a character: write *fill_char* into
|
| 601 |
+
``unicode[start:start+length]``.
|
| 602 |
+
|
| 603 |
+
Fail if *fill_char* is bigger than the string maximum character, or if the
|
| 604 |
+
string has more than 1 reference.
|
| 605 |
+
|
| 606 |
+
Return the number of written character, or return ``-1`` and raise an
|
| 607 |
+
exception on error.
|
| 608 |
+
|
| 609 |
+
.. versionadded:: 3.3
|
| 610 |
+
|
| 611 |
+
|
| 612 |
+
.. c:function:: int PyUnicode_WriteChar(PyObject *unicode, Py_ssize_t index, \
|
| 613 |
+
Py_UCS4 character)
|
| 614 |
+
|
| 615 |
+
Write a character to a string. The string must have been created through
|
| 616 |
+
:c:func:`PyUnicode_New`. Since Unicode strings are supposed to be immutable,
|
| 617 |
+
the string must not be shared, or have been hashed yet.
|
| 618 |
+
|
| 619 |
+
This function checks that *unicode* is a Unicode object, that the index is
|
| 620 |
+
not out of bounds, and that the object can be modified safely (i.e. that it
|
| 621 |
+
its reference count is one).
|
| 622 |
+
|
| 623 |
+
.. versionadded:: 3.3
|
| 624 |
+
|
| 625 |
+
|
| 626 |
+
.. c:function:: Py_UCS4 PyUnicode_ReadChar(PyObject *unicode, Py_ssize_t index)
|
| 627 |
+
|
| 628 |
+
Read a character from a string. This function checks that *unicode* is a
|
| 629 |
+
Unicode object and the index is not out of bounds, in contrast to the macro
|
| 630 |
+
version :c:func:`PyUnicode_READ_CHAR`.
|
| 631 |
+
|
| 632 |
+
.. versionadded:: 3.3
|
| 633 |
+
|
| 634 |
+
|
| 635 |
+
.. c:function:: PyObject* PyUnicode_Substring(PyObject *str, Py_ssize_t start, \
|
| 636 |
+
Py_ssize_t end)
|
| 637 |
+
|
| 638 |
+
Return a substring of *str*, from character index *start* (included) to
|
| 639 |
+
character index *end* (excluded). Negative indices are not supported.
|
| 640 |
+
|
| 641 |
+
.. versionadded:: 3.3
|
| 642 |
+
|
| 643 |
+
|
| 644 |
+
.. c:function:: Py_UCS4* PyUnicode_AsUCS4(PyObject *u, Py_UCS4 *buffer, \
|
| 645 |
+
Py_ssize_t buflen, int copy_null)
|
| 646 |
+
|
| 647 |
+
Copy the string *u* into a UCS4 buffer, including a null character, if
|
| 648 |
+
*copy_null* is set. Returns ``NULL`` and sets an exception on error (in
|
| 649 |
+
particular, a :exc:`SystemError` if *buflen* is smaller than the length of
|
| 650 |
+
*u*). *buffer* is returned on success.
|
| 651 |
+
|
| 652 |
+
.. versionadded:: 3.3
|
| 653 |
+
|
| 654 |
+
|
| 655 |
+
.. c:function:: Py_UCS4* PyUnicode_AsUCS4Copy(PyObject *u)
|
| 656 |
+
|
| 657 |
+
Copy the string *u* into a new UCS4 buffer that is allocated using
|
| 658 |
+
:c:func:`PyMem_Malloc`. If this fails, ``NULL`` is returned with a
|
| 659 |
+
:exc:`MemoryError` set. The returned buffer always has an extra
|
| 660 |
+
null code point appended.
|
| 661 |
+
|
| 662 |
+
.. versionadded:: 3.3
|
| 663 |
+
|
| 664 |
+
|
| 665 |
+
Deprecated Py_UNICODE APIs
|
| 666 |
+
""""""""""""""""""""""""""
|
| 667 |
+
|
| 668 |
+
.. deprecated-removed:: 3.3 4.0
|
| 669 |
+
|
| 670 |
+
These API functions are deprecated with the implementation of :pep:`393`.
|
| 671 |
+
Extension modules can continue using them, as they will not be removed in Python
|
| 672 |
+
3.x, but need to be aware that their use can now cause performance and memory hits.
|
| 673 |
+
|
| 674 |
+
|
| 675 |
+
.. c:function:: PyObject* PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
|
| 676 |
+
|
| 677 |
+
Create a Unicode object from the Py_UNICODE buffer *u* of the given size. *u*
|
| 678 |
+
may be ``NULL`` which causes the contents to be undefined. It is the user's
|
| 679 |
+
responsibility to fill in the needed data. The buffer is copied into the new
|
| 680 |
+
object.
|
| 681 |
+
|
| 682 |
+
If the buffer is not ``NULL``, the return value might be a shared object.
|
| 683 |
+
Therefore, modification of the resulting Unicode object is only allowed when
|
| 684 |
+
*u* is ``NULL``.
|
| 685 |
+
|
| 686 |
+
If the buffer is ``NULL``, :c:func:`PyUnicode_READY` must be called once the
|
| 687 |
+
string content has been filled before using any of the access macros such as
|
| 688 |
+
:c:func:`PyUnicode_KIND`.
|
| 689 |
+
|
| 690 |
+
Please migrate to using :c:func:`PyUnicode_FromKindAndData`,
|
| 691 |
+
:c:func:`PyUnicode_FromWideChar` or :c:func:`PyUnicode_New`.
|
| 692 |
+
|
| 693 |
+
|
| 694 |
+
.. c:function:: Py_UNICODE* PyUnicode_AsUnicode(PyObject *unicode)
|
| 695 |
+
|
| 696 |
+
Return a read-only pointer to the Unicode object's internal
|
| 697 |
+
:c:type:`Py_UNICODE` buffer, or ``NULL`` on error. This will create the
|
| 698 |
+
:c:type:`Py_UNICODE*` representation of the object if it is not yet
|
| 699 |
+
available. The buffer is always terminated with an extra null code point.
|
| 700 |
+
Note that the resulting :c:type:`Py_UNICODE` string may also contain
|
| 701 |
+
embedded null code points, which would cause the string to be truncated when
|
| 702 |
+
used in most C functions.
|
| 703 |
+
|
| 704 |
+
Please migrate to using :c:func:`PyUnicode_AsUCS4`,
|
| 705 |
+
:c:func:`PyUnicode_AsWideChar`, :c:func:`PyUnicode_ReadChar` or similar new
|
| 706 |
+
APIs.
|
| 707 |
+
|
| 708 |
+
|
| 709 |
+
.. c:function:: PyObject* PyUnicode_TransformDecimalToASCII(Py_UNICODE *s, Py_ssize_t size)
|
| 710 |
+
|
| 711 |
+
Create a Unicode object by replacing all decimal digits in
|
| 712 |
+
:c:type:`Py_UNICODE` buffer of the given *size* by ASCII digits 0--9
|
| 713 |
+
according to their decimal value. Return ``NULL`` if an exception occurs.
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
.. c:function:: Py_UNICODE* PyUnicode_AsUnicodeAndSize(PyObject *unicode, Py_ssize_t *size)
|
| 717 |
+
|
| 718 |
+
Like :c:func:`PyUnicode_AsUnicode`, but also saves the :c:func:`Py_UNICODE`
|
| 719 |
+
array length (excluding the extra null terminator) in *size*.
|
| 720 |
+
Note that the resulting :c:type:`Py_UNICODE*` string
|
| 721 |
+
may contain embedded null code points, which would cause the string to be
|
| 722 |
+
truncated when used in most C functions.
|
| 723 |
+
|
| 724 |
+
.. versionadded:: 3.3
|
| 725 |
+
|
| 726 |
+
|
| 727 |
+
.. c:function:: Py_UNICODE* PyUnicode_AsUnicodeCopy(PyObject *unicode)
|
| 728 |
+
|
| 729 |
+
Create a copy of a Unicode string ending with a null code point. Return ``NULL``
|
| 730 |
+
and raise a :exc:`MemoryError` exception on memory allocation failure,
|
| 731 |
+
otherwise return a new allocated buffer (use :c:func:`PyMem_Free` to free
|
| 732 |
+
the buffer). Note that the resulting :c:type:`Py_UNICODE*` string may
|
| 733 |
+
contain embedded null code points, which would cause the string to be
|
| 734 |
+
truncated when used in most C functions.
|
| 735 |
+
|
| 736 |
+
.. versionadded:: 3.2
|
| 737 |
+
|
| 738 |
+
Please migrate to using :c:func:`PyUnicode_AsUCS4Copy` or similar new APIs.
|
| 739 |
+
|
| 740 |
+
|
| 741 |
+
.. c:function:: Py_ssize_t PyUnicode_GetSize(PyObject *unicode)
|
| 742 |
+
|
| 743 |
+
Return the size of the deprecated :c:type:`Py_UNICODE` representation, in
|
| 744 |
+
code units (this includes surrogate pairs as 2 units).
|
| 745 |
+
|
| 746 |
+
Please migrate to using :c:func:`PyUnicode_GetLength`.
|
| 747 |
+
|
| 748 |
+
|
| 749 |
+
.. c:function:: PyObject* PyUnicode_FromObject(PyObject *obj)
|
| 750 |
+
|
| 751 |
+
Copy an instance of a Unicode subtype to a new true Unicode object if
|
| 752 |
+
necessary. If *obj* is already a true Unicode object (not a subtype),
|
| 753 |
+
return the reference with incremented refcount.
|
| 754 |
+
|
| 755 |
+
Objects other than Unicode or its subtypes will cause a :exc:`TypeError`.
|
| 756 |
+
|
| 757 |
+
|
| 758 |
+
Locale Encoding
|
| 759 |
+
"""""""""""""""
|
| 760 |
+
|
| 761 |
+
The current locale encoding can be used to decode text from the operating
|
| 762 |
+
system.
|
| 763 |
+
|
| 764 |
+
.. c:function:: PyObject* PyUnicode_DecodeLocaleAndSize(const char *str, \
|
| 765 |
+
Py_ssize_t len, \
|
| 766 |
+
const char *errors)
|
| 767 |
+
|
| 768 |
+
Decode a string from UTF-8 on Android and VxWorks, or from the current
|
| 769 |
+
locale encoding on other platforms. The supported
|
| 770 |
+
error handlers are ``"strict"`` and ``"surrogateescape"``
|
| 771 |
+
(:pep:`383`). The decoder uses ``"strict"`` error handler if
|
| 772 |
+
*errors* is ``NULL``. *str* must end with a null character but
|
| 773 |
+
cannot contain embedded null characters.
|
| 774 |
+
|
| 775 |
+
Use :c:func:`PyUnicode_DecodeFSDefaultAndSize` to decode a string from
|
| 776 |
+
:c:data:`Py_FileSystemDefaultEncoding` (the locale encoding read at
|
| 777 |
+
Python startup).
|
| 778 |
+
|
| 779 |
+
This function ignores the Python UTF-8 mode.
|
| 780 |
+
|
| 781 |
+
.. seealso::
|
| 782 |
+
|
| 783 |
+
The :c:func:`Py_DecodeLocale` function.
|
| 784 |
+
|
| 785 |
+
.. versionadded:: 3.3
|
| 786 |
+
|
| 787 |
+
.. versionchanged:: 3.7
|
| 788 |
+
The function now also uses the current locale encoding for the
|
| 789 |
+
``surrogateescape`` error handler, except on Android. Previously, :c:func:`Py_DecodeLocale`
|
| 790 |
+
was used for the ``surrogateescape``, and the current locale encoding was
|
| 791 |
+
used for ``strict``.
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
.. c:function:: PyObject* PyUnicode_DecodeLocale(const char *str, const char *errors)
|
| 795 |
+
|
| 796 |
+
Similar to :c:func:`PyUnicode_DecodeLocaleAndSize`, but compute the string
|
| 797 |
+
length using :c:func:`strlen`.
|
| 798 |
+
|
| 799 |
+
.. versionadded:: 3.3
|
| 800 |
+
|
| 801 |
+
|
| 802 |
+
.. c:function:: PyObject* PyUnicode_EncodeLocale(PyObject *unicode, const char *errors)
|
| 803 |
+
|
| 804 |
+
Encode a Unicode object to UTF-8 on Android and VxWorks, or to the current
|
| 805 |
+
locale encoding on other platforms. The
|
| 806 |
+
supported error handlers are ``"strict"`` and ``"surrogateescape"``
|
| 807 |
+
(:pep:`383`). The encoder uses ``"strict"`` error handler if
|
| 808 |
+
*errors* is ``NULL``. Return a :class:`bytes` object. *unicode* cannot
|
| 809 |
+
contain embedded null characters.
|
| 810 |
+
|
| 811 |
+
Use :c:func:`PyUnicode_EncodeFSDefault` to encode a string to
|
| 812 |
+
:c:data:`Py_FileSystemDefaultEncoding` (the locale encoding read at
|
| 813 |
+
Python startup).
|
| 814 |
+
|
| 815 |
+
This function ignores the Python UTF-8 mode.
|
| 816 |
+
|
| 817 |
+
.. seealso::
|
| 818 |
+
|
| 819 |
+
The :c:func:`Py_EncodeLocale` function.
|
| 820 |
+
|
| 821 |
+
.. versionadded:: 3.3
|
| 822 |
+
|
| 823 |
+
.. versionchanged:: 3.7
|
| 824 |
+
The function now also uses the current locale encoding for the
|
| 825 |
+
``surrogateescape`` error handler, except on Android. Previously,
|
| 826 |
+
:c:func:`Py_EncodeLocale`
|
| 827 |
+
was used for the ``surrogateescape``, and the current locale encoding was
|
| 828 |
+
used for ``strict``.
|
| 829 |
+
|
| 830 |
+
|
| 831 |
+
File System Encoding
|
| 832 |
+
""""""""""""""""""""
|
| 833 |
+
|
| 834 |
+
To encode and decode file names and other environment strings,
|
| 835 |
+
:c:data:`Py_FileSystemDefaultEncoding` should be used as the encoding, and
|
| 836 |
+
:c:data:`Py_FileSystemDefaultEncodeErrors` should be used as the error handler
|
| 837 |
+
(:pep:`383` and :pep:`529`). To encode file names to :class:`bytes` during
|
| 838 |
+
argument parsing, the ``"O&"`` converter should be used, passing
|
| 839 |
+
:c:func:`PyUnicode_FSConverter` as the conversion function:
|
| 840 |
+
|
| 841 |
+
.. c:function:: int PyUnicode_FSConverter(PyObject* obj, void* result)
|
| 842 |
+
|
| 843 |
+
ParseTuple converter: encode :class:`str` objects -- obtained directly or
|
| 844 |
+
through the :class:`os.PathLike` interface -- to :class:`bytes` using
|
| 845 |
+
:c:func:`PyUnicode_EncodeFSDefault`; :class:`bytes` objects are output as-is.
|
| 846 |
+
*result* must be a :c:type:`PyBytesObject*` which must be released when it is
|
| 847 |
+
no longer used.
|
| 848 |
+
|
| 849 |
+
.. versionadded:: 3.1
|
| 850 |
+
|
| 851 |
+
.. versionchanged:: 3.6
|
| 852 |
+
Accepts a :term:`path-like object`.
|
| 853 |
+
|
| 854 |
+
To decode file names to :class:`str` during argument parsing, the ``"O&"``
|
| 855 |
+
converter should be used, passing :c:func:`PyUnicode_FSDecoder` as the
|
| 856 |
+
conversion function:
|
| 857 |
+
|
| 858 |
+
.. c:function:: int PyUnicode_FSDecoder(PyObject* obj, void* result)
|
| 859 |
+
|
| 860 |
+
ParseTuple converter: decode :class:`bytes` objects -- obtained either
|
| 861 |
+
directly or indirectly through the :class:`os.PathLike` interface -- to
|
| 862 |
+
:class:`str` using :c:func:`PyUnicode_DecodeFSDefaultAndSize`; :class:`str`
|
| 863 |
+
objects are output as-is. *result* must be a :c:type:`PyUnicodeObject*` which
|
| 864 |
+
must be released when it is no longer used.
|
| 865 |
+
|
| 866 |
+
.. versionadded:: 3.2
|
| 867 |
+
|
| 868 |
+
.. versionchanged:: 3.6
|
| 869 |
+
Accepts a :term:`path-like object`.
|
| 870 |
+
|
| 871 |
+
|
| 872 |
+
.. c:function:: PyObject* PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
|
| 873 |
+
|
| 874 |
+
Decode a string using :c:data:`Py_FileSystemDefaultEncoding` and the
|
| 875 |
+
:c:data:`Py_FileSystemDefaultEncodeErrors` error handler.
|
| 876 |
+
|
| 877 |
+
If :c:data:`Py_FileSystemDefaultEncoding` is not set, fall back to the
|
| 878 |
+
locale encoding.
|
| 879 |
+
|
| 880 |
+
:c:data:`Py_FileSystemDefaultEncoding` is initialized at startup from the
|
| 881 |
+
locale encoding and cannot be modified later. If you need to decode a string
|
| 882 |
+
from the current locale encoding, use
|
| 883 |
+
:c:func:`PyUnicode_DecodeLocaleAndSize`.
|
| 884 |
+
|
| 885 |
+
.. seealso::
|
| 886 |
+
|
| 887 |
+
The :c:func:`Py_DecodeLocale` function.
|
| 888 |
+
|
| 889 |
+
.. versionchanged:: 3.6
|
| 890 |
+
Use :c:data:`Py_FileSystemDefaultEncodeErrors` error handler.
|
| 891 |
+
|
| 892 |
+
|
| 893 |
+
.. c:function:: PyObject* PyUnicode_DecodeFSDefault(const char *s)
|
| 894 |
+
|
| 895 |
+
Decode a null-terminated string using :c:data:`Py_FileSystemDefaultEncoding`
|
| 896 |
+
and the :c:data:`Py_FileSystemDefaultEncodeErrors` error handler.
|
| 897 |
+
|
| 898 |
+
If :c:data:`Py_FileSystemDefaultEncoding` is not set, fall back to the
|
| 899 |
+
locale encoding.
|
| 900 |
+
|
| 901 |
+
Use :c:func:`PyUnicode_DecodeFSDefaultAndSize` if you know the string length.
|
| 902 |
+
|
| 903 |
+
.. versionchanged:: 3.6
|
| 904 |
+
Use :c:data:`Py_FileSystemDefaultEncodeErrors` error handler.
|
| 905 |
+
|
| 906 |
+
|
| 907 |
+
.. c:function:: PyObject* PyUnicode_EncodeFSDefault(PyObject *unicode)
|
| 908 |
+
|
| 909 |
+
Encode a Unicode object to :c:data:`Py_FileSystemDefaultEncoding` with the
|
| 910 |
+
:c:data:`Py_FileSystemDefaultEncodeErrors` error handler, and return
|
| 911 |
+
:class:`bytes`. Note that the resulting :class:`bytes` object may contain
|
| 912 |
+
null bytes.
|
| 913 |
+
|
| 914 |
+
If :c:data:`Py_FileSystemDefaultEncoding` is not set, fall back to the
|
| 915 |
+
locale encoding.
|
| 916 |
+
|
| 917 |
+
:c:data:`Py_FileSystemDefaultEncoding` is initialized at startup from the
|
| 918 |
+
locale encoding and cannot be modified later. If you need to encode a string
|
| 919 |
+
to the current locale encoding, use :c:func:`PyUnicode_EncodeLocale`.
|
| 920 |
+
|
| 921 |
+
.. seealso::
|
| 922 |
+
|
| 923 |
+
The :c:func:`Py_EncodeLocale` function.
|
| 924 |
+
|
| 925 |
+
.. versionadded:: 3.2
|
| 926 |
+
|
| 927 |
+
.. versionchanged:: 3.6
|
| 928 |
+
Use :c:data:`Py_FileSystemDefaultEncodeErrors` error handler.
|
| 929 |
+
|
| 930 |
+
wchar_t Support
|
| 931 |
+
"""""""""""""""
|
| 932 |
+
|
| 933 |
+
:c:type:`wchar_t` support for platforms which support it:
|
| 934 |
+
|
| 935 |
+
.. c:function:: PyObject* PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size)
|
| 936 |
+
|
| 937 |
+
Create a Unicode object from the :c:type:`wchar_t` buffer *w* of the given *size*.
|
| 938 |
+
Passing ``-1`` as the *size* indicates that the function must itself compute the length,
|
| 939 |
+
using wcslen.
|
| 940 |
+
Return ``NULL`` on failure.
|
| 941 |
+
|
| 942 |
+
|
| 943 |
+
.. c:function:: Py_ssize_t PyUnicode_AsWideChar(PyObject *unicode, wchar_t *w, Py_ssize_t size)
|
| 944 |
+
|
| 945 |
+
Copy the Unicode object contents into the :c:type:`wchar_t` buffer *w*. At most
|
| 946 |
+
*size* :c:type:`wchar_t` characters are copied (excluding a possibly trailing
|
| 947 |
+
null termination character). Return the number of :c:type:`wchar_t` characters
|
| 948 |
+
copied or ``-1`` in case of an error. Note that the resulting :c:type:`wchar_t*`
|
| 949 |
+
string may or may not be null-terminated. It is the responsibility of the caller
|
| 950 |
+
to make sure that the :c:type:`wchar_t*` string is null-terminated in case this is
|
| 951 |
+
required by the application. Also, note that the :c:type:`wchar_t*` string
|
| 952 |
+
might contain null characters, which would cause the string to be truncated
|
| 953 |
+
when used with most C functions.
|
| 954 |
+
|
| 955 |
+
|
| 956 |
+
.. c:function:: wchar_t* PyUnicode_AsWideCharString(PyObject *unicode, Py_ssize_t *size)
|
| 957 |
+
|
| 958 |
+
Convert the Unicode object to a wide character string. The output string
|
| 959 |
+
always ends with a null character. If *size* is not ``NULL``, write the number
|
| 960 |
+
of wide characters (excluding the trailing null termination character) into
|
| 961 |
+
*\*size*. Note that the resulting :c:type:`wchar_t` string might contain
|
| 962 |
+
null characters, which would cause the string to be truncated when used with
|
| 963 |
+
most C functions. If *size* is ``NULL`` and the :c:type:`wchar_t*` string
|
| 964 |
+
contains null characters a :exc:`ValueError` is raised.
|
| 965 |
+
|
| 966 |
+
Returns a buffer allocated by :c:func:`PyMem_Alloc` (use
|
| 967 |
+
:c:func:`PyMem_Free` to free it) on success. On error, returns ``NULL``
|
| 968 |
+
and *\*size* is undefined. Raises a :exc:`MemoryError` if memory allocation
|
| 969 |
+
is failed.
|
| 970 |
+
|
| 971 |
+
.. versionadded:: 3.2
|
| 972 |
+
|
| 973 |
+
.. versionchanged:: 3.7
|
| 974 |
+
Raises a :exc:`ValueError` if *size* is ``NULL`` and the :c:type:`wchar_t*`
|
| 975 |
+
string contains null characters.
|
| 976 |
+
|
| 977 |
+
|
| 978 |
+
.. _builtincodecs:
|
| 979 |
+
|
| 980 |
+
Built-in Codecs
|
| 981 |
+
^^^^^^^^^^^^^^^
|
| 982 |
+
|
| 983 |
+
Python provides a set of built-in codecs which are written in C for speed. All of
|
| 984 |
+
these codecs are directly usable via the following functions.
|
| 985 |
+
|
| 986 |
+
Many of the following APIs take two arguments encoding and errors, and they
|
| 987 |
+
have the same semantics as the ones of the built-in :func:`str` string object
|
| 988 |
+
constructor.
|
| 989 |
+
|
| 990 |
+
Setting encoding to ``NULL`` causes the default encoding to be used
|
| 991 |
+
which is UTF-8. The file system calls should use
|
| 992 |
+
:c:func:`PyUnicode_FSConverter` for encoding file names. This uses the
|
| 993 |
+
variable :c:data:`Py_FileSystemDefaultEncoding` internally. This
|
| 994 |
+
variable should be treated as read-only: on some systems, it will be a
|
| 995 |
+
pointer to a static string, on others, it will change at run-time
|
| 996 |
+
(such as when the application invokes setlocale).
|
| 997 |
+
|
| 998 |
+
Error handling is set by errors which may also be set to ``NULL`` meaning to use
|
| 999 |
+
the default handling defined for the codec. Default error handling for all
|
| 1000 |
+
built-in codecs is "strict" (:exc:`ValueError` is raised).
|
| 1001 |
+
|
| 1002 |
+
The codecs all use a similar interface. Only deviation from the following
|
| 1003 |
+
generic ones are documented for simplicity.
|
| 1004 |
+
|
| 1005 |
+
|
| 1006 |
+
Generic Codecs
|
| 1007 |
+
""""""""""""""
|
| 1008 |
+
|
| 1009 |
+
These are the generic codec APIs:
|
| 1010 |
+
|
| 1011 |
+
|
| 1012 |
+
.. c:function:: PyObject* PyUnicode_Decode(const char *s, Py_ssize_t size, \
|
| 1013 |
+
const char *encoding, const char *errors)
|
| 1014 |
+
|
| 1015 |
+
Create a Unicode object by decoding *size* bytes of the encoded string *s*.
|
| 1016 |
+
*encoding* and *errors* have the same meaning as the parameters of the same name
|
| 1017 |
+
in the :func:`str` built-in function. The codec to be used is looked up
|
| 1018 |
+
using the Python codec registry. Return ``NULL`` if an exception was raised by
|
| 1019 |
+
the codec.
|
| 1020 |
+
|
| 1021 |
+
|
| 1022 |
+
.. c:function:: PyObject* PyUnicode_AsEncodedString(PyObject *unicode, \
|
| 1023 |
+
const char *encoding, const char *errors)
|
| 1024 |
+
|
| 1025 |
+
Encode a Unicode object and return the result as Python bytes object.
|
| 1026 |
+
*encoding* and *errors* have the same meaning as the parameters of the same
|
| 1027 |
+
name in the Unicode :meth:`~str.encode` method. The codec to be used is looked up
|
| 1028 |
+
using the Python codec registry. Return ``NULL`` if an exception was raised by
|
| 1029 |
+
the codec.
|
| 1030 |
+
|
| 1031 |
+
|
| 1032 |
+
.. c:function:: PyObject* PyUnicode_Encode(const Py_UNICODE *s, Py_ssize_t size, \
|
| 1033 |
+
const char *encoding, const char *errors)
|
| 1034 |
+
|
| 1035 |
+
Encode the :c:type:`Py_UNICODE` buffer *s* of the given *size* and return a Python
|
| 1036 |
+
bytes object. *encoding* and *errors* have the same meaning as the
|
| 1037 |
+
parameters of the same name in the Unicode :meth:`~str.encode` method. The codec
|
| 1038 |
+
to be used is looked up using the Python codec registry. Return ``NULL`` if an
|
| 1039 |
+
exception was raised by the codec.
|
| 1040 |
+
|
| 1041 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1042 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1043 |
+
:c:func:`PyUnicode_AsEncodedString`.
|
| 1044 |
+
|
| 1045 |
+
|
| 1046 |
+
UTF-8 Codecs
|
| 1047 |
+
""""""""""""
|
| 1048 |
+
|
| 1049 |
+
These are the UTF-8 codec APIs:
|
| 1050 |
+
|
| 1051 |
+
|
| 1052 |
+
.. c:function:: PyObject* PyUnicode_DecodeUTF8(const char *s, Py_ssize_t size, const char *errors)
|
| 1053 |
+
|
| 1054 |
+
Create a Unicode object by decoding *size* bytes of the UTF-8 encoded string
|
| 1055 |
+
*s*. Return ``NULL`` if an exception was raised by the codec.
|
| 1056 |
+
|
| 1057 |
+
|
| 1058 |
+
.. c:function:: PyObject* PyUnicode_DecodeUTF8Stateful(const char *s, Py_ssize_t size, \
|
| 1059 |
+
const char *errors, Py_ssize_t *consumed)
|
| 1060 |
+
|
| 1061 |
+
If *consumed* is ``NULL``, behave like :c:func:`PyUnicode_DecodeUTF8`. If
|
| 1062 |
+
*consumed* is not ``NULL``, trailing incomplete UTF-8 byte sequences will not be
|
| 1063 |
+
treated as an error. Those bytes will not be decoded and the number of bytes
|
| 1064 |
+
that have been decoded will be stored in *consumed*.
|
| 1065 |
+
|
| 1066 |
+
|
| 1067 |
+
.. c:function:: PyObject* PyUnicode_AsUTF8String(PyObject *unicode)
|
| 1068 |
+
|
| 1069 |
+
Encode a Unicode object using UTF-8 and return the result as Python bytes
|
| 1070 |
+
object. Error handling is "strict". Return ``NULL`` if an exception was
|
| 1071 |
+
raised by the codec.
|
| 1072 |
+
|
| 1073 |
+
|
| 1074 |
+
.. c:function:: const char* PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *size)
|
| 1075 |
+
|
| 1076 |
+
Return a pointer to the UTF-8 encoding of the Unicode object, and
|
| 1077 |
+
store the size of the encoded representation (in bytes) in *size*. The
|
| 1078 |
+
*size* argument can be ``NULL``; in this case no size will be stored. The
|
| 1079 |
+
returned buffer always has an extra null byte appended (not included in
|
| 1080 |
+
*size*), regardless of whether there are any other null code points.
|
| 1081 |
+
|
| 1082 |
+
In the case of an error, ``NULL`` is returned with an exception set and no
|
| 1083 |
+
*size* is stored.
|
| 1084 |
+
|
| 1085 |
+
This caches the UTF-8 representation of the string in the Unicode object, and
|
| 1086 |
+
subsequent calls will return a pointer to the same buffer. The caller is not
|
| 1087 |
+
responsible for deallocating the buffer.
|
| 1088 |
+
|
| 1089 |
+
.. versionadded:: 3.3
|
| 1090 |
+
|
| 1091 |
+
.. versionchanged:: 3.7
|
| 1092 |
+
The return type is now ``const char *`` rather of ``char *``.
|
| 1093 |
+
|
| 1094 |
+
|
| 1095 |
+
.. c:function:: const char* PyUnicode_AsUTF8(PyObject *unicode)
|
| 1096 |
+
|
| 1097 |
+
As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size.
|
| 1098 |
+
|
| 1099 |
+
.. versionadded:: 3.3
|
| 1100 |
+
|
| 1101 |
+
.. versionchanged:: 3.7
|
| 1102 |
+
The return type is now ``const char *`` rather of ``char *``.
|
| 1103 |
+
|
| 1104 |
+
|
| 1105 |
+
.. c:function:: PyObject* PyUnicode_EncodeUTF8(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
|
| 1106 |
+
|
| 1107 |
+
Encode the :c:type:`Py_UNICODE` buffer *s* of the given *size* using UTF-8 and
|
| 1108 |
+
return a Python bytes object. Return ``NULL`` if an exception was raised by
|
| 1109 |
+
the codec.
|
| 1110 |
+
|
| 1111 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1112 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1113 |
+
:c:func:`PyUnicode_AsUTF8String`, :c:func:`PyUnicode_AsUTF8AndSize` or
|
| 1114 |
+
:c:func:`PyUnicode_AsEncodedString`.
|
| 1115 |
+
|
| 1116 |
+
|
| 1117 |
+
UTF-32 Codecs
|
| 1118 |
+
"""""""""""""
|
| 1119 |
+
|
| 1120 |
+
These are the UTF-32 codec APIs:
|
| 1121 |
+
|
| 1122 |
+
|
| 1123 |
+
.. c:function:: PyObject* PyUnicode_DecodeUTF32(const char *s, Py_ssize_t size, \
|
| 1124 |
+
const char *errors, int *byteorder)
|
| 1125 |
+
|
| 1126 |
+
Decode *size* bytes from a UTF-32 encoded buffer string and return the
|
| 1127 |
+
corresponding Unicode object. *errors* (if non-``NULL``) defines the error
|
| 1128 |
+
handling. It defaults to "strict".
|
| 1129 |
+
|
| 1130 |
+
If *byteorder* is non-``NULL``, the decoder starts decoding using the given byte
|
| 1131 |
+
order::
|
| 1132 |
+
|
| 1133 |
+
*byteorder == -1: little endian
|
| 1134 |
+
*byteorder == 0: native order
|
| 1135 |
+
*byteorder == 1: big endian
|
| 1136 |
+
|
| 1137 |
+
If ``*byteorder`` is zero, and the first four bytes of the input data are a
|
| 1138 |
+
byte order mark (BOM), the decoder switches to this byte order and the BOM is
|
| 1139 |
+
not copied into the resulting Unicode string. If ``*byteorder`` is ``-1`` or
|
| 1140 |
+
``1``, any byte order mark is copied to the output.
|
| 1141 |
+
|
| 1142 |
+
After completion, *\*byteorder* is set to the current byte order at the end
|
| 1143 |
+
of input data.
|
| 1144 |
+
|
| 1145 |
+
If *byteorder* is ``NULL``, the codec starts in native order mode.
|
| 1146 |
+
|
| 1147 |
+
Return ``NULL`` if an exception was raised by the codec.
|
| 1148 |
+
|
| 1149 |
+
|
| 1150 |
+
.. c:function:: PyObject* PyUnicode_DecodeUTF32Stateful(const char *s, Py_ssize_t size, \
|
| 1151 |
+
const char *errors, int *byteorder, Py_ssize_t *consumed)
|
| 1152 |
+
|
| 1153 |
+
If *consumed* is ``NULL``, behave like :c:func:`PyUnicode_DecodeUTF32`. If
|
| 1154 |
+
*consumed* is not ``NULL``, :c:func:`PyUnicode_DecodeUTF32Stateful` will not treat
|
| 1155 |
+
trailing incomplete UTF-32 byte sequences (such as a number of bytes not divisible
|
| 1156 |
+
by four) as an error. Those bytes will not be decoded and the number of bytes
|
| 1157 |
+
that have been decoded will be stored in *consumed*.
|
| 1158 |
+
|
| 1159 |
+
|
| 1160 |
+
.. c:function:: PyObject* PyUnicode_AsUTF32String(PyObject *unicode)
|
| 1161 |
+
|
| 1162 |
+
Return a Python byte string using the UTF-32 encoding in native byte
|
| 1163 |
+
order. The string always starts with a BOM mark. Error handling is "strict".
|
| 1164 |
+
Return ``NULL`` if an exception was raised by the codec.
|
| 1165 |
+
|
| 1166 |
+
|
| 1167 |
+
.. c:function:: PyObject* PyUnicode_EncodeUTF32(const Py_UNICODE *s, Py_ssize_t size, \
|
| 1168 |
+
const char *errors, int byteorder)
|
| 1169 |
+
|
| 1170 |
+
Return a Python bytes object holding the UTF-32 encoded value of the Unicode
|
| 1171 |
+
data in *s*. Output is written according to the following byte order::
|
| 1172 |
+
|
| 1173 |
+
byteorder == -1: little endian
|
| 1174 |
+
byteorder == 0: native byte order (writes a BOM mark)
|
| 1175 |
+
byteorder == 1: big endian
|
| 1176 |
+
|
| 1177 |
+
If byteorder is ``0``, the output string will always start with the Unicode BOM
|
| 1178 |
+
mark (U+FEFF). In the other two modes, no BOM mark is prepended.
|
| 1179 |
+
|
| 1180 |
+
If ``Py_UNICODE_WIDE`` is not defined, surrogate pairs will be output
|
| 1181 |
+
as a single code point.
|
| 1182 |
+
|
| 1183 |
+
Return ``NULL`` if an exception was raised by the codec.
|
| 1184 |
+
|
| 1185 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1186 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1187 |
+
:c:func:`PyUnicode_AsUTF32String` or :c:func:`PyUnicode_AsEncodedString`.
|
| 1188 |
+
|
| 1189 |
+
|
| 1190 |
+
UTF-16 Codecs
|
| 1191 |
+
"""""""""""""
|
| 1192 |
+
|
| 1193 |
+
These are the UTF-16 codec APIs:
|
| 1194 |
+
|
| 1195 |
+
|
| 1196 |
+
.. c:function:: PyObject* PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, \
|
| 1197 |
+
const char *errors, int *byteorder)
|
| 1198 |
+
|
| 1199 |
+
Decode *size* bytes from a UTF-16 encoded buffer string and return the
|
| 1200 |
+
corresponding Unicode object. *errors* (if non-``NULL``) defines the error
|
| 1201 |
+
handling. It defaults to "strict".
|
| 1202 |
+
|
| 1203 |
+
If *byteorder* is non-``NULL``, the decoder starts decoding using the given byte
|
| 1204 |
+
order::
|
| 1205 |
+
|
| 1206 |
+
*byteorder == -1: little endian
|
| 1207 |
+
*byteorder == 0: native order
|
| 1208 |
+
*byteorder == 1: big endian
|
| 1209 |
+
|
| 1210 |
+
If ``*byteorder`` is zero, and the first two bytes of the input data are a
|
| 1211 |
+
byte order mark (BOM), the decoder switches to this byte order and the BOM is
|
| 1212 |
+
not copied into the resulting Unicode string. If ``*byteorder`` is ``-1`` or
|
| 1213 |
+
``1``, any byte order mark is copied to the output (where it will result in
|
| 1214 |
+
either a ``\ufeff`` or a ``\ufffe`` character).
|
| 1215 |
+
|
| 1216 |
+
After completion, *\*byteorder* is set to the current byte order at the end
|
| 1217 |
+
of input data.
|
| 1218 |
+
|
| 1219 |
+
If *byteorder* is ``NULL``, the codec starts in native order mode.
|
| 1220 |
+
|
| 1221 |
+
Return ``NULL`` if an exception was raised by the codec.
|
| 1222 |
+
|
| 1223 |
+
|
| 1224 |
+
.. c:function:: PyObject* PyUnicode_DecodeUTF16Stateful(const char *s, Py_ssize_t size, \
|
| 1225 |
+
const char *errors, int *byteorder, Py_ssize_t *consumed)
|
| 1226 |
+
|
| 1227 |
+
If *consumed* is ``NULL``, behave like :c:func:`PyUnicode_DecodeUTF16`. If
|
| 1228 |
+
*consumed* is not ``NULL``, :c:func:`PyUnicode_DecodeUTF16Stateful` will not treat
|
| 1229 |
+
trailing incomplete UTF-16 byte sequences (such as an odd number of bytes or a
|
| 1230 |
+
split surrogate pair) as an error. Those bytes will not be decoded and the
|
| 1231 |
+
number of bytes that have been decoded will be stored in *consumed*.
|
| 1232 |
+
|
| 1233 |
+
|
| 1234 |
+
.. c:function:: PyObject* PyUnicode_AsUTF16String(PyObject *unicode)
|
| 1235 |
+
|
| 1236 |
+
Return a Python byte string using the UTF-16 encoding in native byte
|
| 1237 |
+
order. The string always starts with a BOM mark. Error handling is "strict".
|
| 1238 |
+
Return ``NULL`` if an exception was raised by the codec.
|
| 1239 |
+
|
| 1240 |
+
|
| 1241 |
+
.. c:function:: PyObject* PyUnicode_EncodeUTF16(const Py_UNICODE *s, Py_ssize_t size, \
|
| 1242 |
+
const char *errors, int byteorder)
|
| 1243 |
+
|
| 1244 |
+
Return a Python bytes object holding the UTF-16 encoded value of the Unicode
|
| 1245 |
+
data in *s*. Output is written according to the following byte order::
|
| 1246 |
+
|
| 1247 |
+
byteorder == -1: little endian
|
| 1248 |
+
byteorder == 0: native byte order (writes a BOM mark)
|
| 1249 |
+
byteorder == 1: big endian
|
| 1250 |
+
|
| 1251 |
+
If byteorder is ``0``, the output string will always start with the Unicode BOM
|
| 1252 |
+
mark (U+FEFF). In the other two modes, no BOM mark is prepended.
|
| 1253 |
+
|
| 1254 |
+
If ``Py_UNICODE_WIDE`` is defined, a single :c:type:`Py_UNICODE` value may get
|
| 1255 |
+
represented as a surrogate pair. If it is not defined, each :c:type:`Py_UNICODE`
|
| 1256 |
+
values is interpreted as a UCS-2 character.
|
| 1257 |
+
|
| 1258 |
+
Return ``NULL`` if an exception was raised by the codec.
|
| 1259 |
+
|
| 1260 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1261 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1262 |
+
:c:func:`PyUnicode_AsUTF16String` or :c:func:`PyUnicode_AsEncodedString`.
|
| 1263 |
+
|
| 1264 |
+
|
| 1265 |
+
UTF-7 Codecs
|
| 1266 |
+
""""""""""""
|
| 1267 |
+
|
| 1268 |
+
These are the UTF-7 codec APIs:
|
| 1269 |
+
|
| 1270 |
+
|
| 1271 |
+
.. c:function:: PyObject* PyUnicode_DecodeUTF7(const char *s, Py_ssize_t size, const char *errors)
|
| 1272 |
+
|
| 1273 |
+
Create a Unicode object by decoding *size* bytes of the UTF-7 encoded string
|
| 1274 |
+
*s*. Return ``NULL`` if an exception was raised by the codec.
|
| 1275 |
+
|
| 1276 |
+
|
| 1277 |
+
.. c:function:: PyObject* PyUnicode_DecodeUTF7Stateful(const char *s, Py_ssize_t size, \
|
| 1278 |
+
const char *errors, Py_ssize_t *consumed)
|
| 1279 |
+
|
| 1280 |
+
If *consumed* is ``NULL``, behave like :c:func:`PyUnicode_DecodeUTF7`. If
|
| 1281 |
+
*consumed* is not ``NULL``, trailing incomplete UTF-7 base-64 sections will not
|
| 1282 |
+
be treated as an error. Those bytes will not be decoded and the number of
|
| 1283 |
+
bytes that have been decoded will be stored in *consumed*.
|
| 1284 |
+
|
| 1285 |
+
|
| 1286 |
+
.. c:function:: PyObject* PyUnicode_EncodeUTF7(const Py_UNICODE *s, Py_ssize_t size, \
|
| 1287 |
+
int base64SetO, int base64WhiteSpace, const char *errors)
|
| 1288 |
+
|
| 1289 |
+
Encode the :c:type:`Py_UNICODE` buffer of the given size using UTF-7 and
|
| 1290 |
+
return a Python bytes object. Return ``NULL`` if an exception was raised by
|
| 1291 |
+
the codec.
|
| 1292 |
+
|
| 1293 |
+
If *base64SetO* is nonzero, "Set O" (punctuation that has no otherwise
|
| 1294 |
+
special meaning) will be encoded in base-64. If *base64WhiteSpace* is
|
| 1295 |
+
nonzero, whitespace will be encoded in base-64. Both are set to zero for the
|
| 1296 |
+
Python "utf-7" codec.
|
| 1297 |
+
|
| 1298 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1299 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1300 |
+
:c:func:`PyUnicode_AsEncodedString`.
|
| 1301 |
+
|
| 1302 |
+
|
| 1303 |
+
Unicode-Escape Codecs
|
| 1304 |
+
"""""""""""""""""""""
|
| 1305 |
+
|
| 1306 |
+
These are the "Unicode Escape" codec APIs:
|
| 1307 |
+
|
| 1308 |
+
|
| 1309 |
+
.. c:function:: PyObject* PyUnicode_DecodeUnicodeEscape(const char *s, \
|
| 1310 |
+
Py_ssize_t size, const char *errors)
|
| 1311 |
+
|
| 1312 |
+
Create a Unicode object by decoding *size* bytes of the Unicode-Escape encoded
|
| 1313 |
+
string *s*. Return ``NULL`` if an exception was raised by the codec.
|
| 1314 |
+
|
| 1315 |
+
|
| 1316 |
+
.. c:function:: PyObject* PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
|
| 1317 |
+
|
| 1318 |
+
Encode a Unicode object using Unicode-Escape and return the result as a
|
| 1319 |
+
bytes object. Error handling is "strict". Return ``NULL`` if an exception was
|
| 1320 |
+
raised by the codec.
|
| 1321 |
+
|
| 1322 |
+
|
| 1323 |
+
.. c:function:: PyObject* PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s, Py_ssize_t size)
|
| 1324 |
+
|
| 1325 |
+
Encode the :c:type:`Py_UNICODE` buffer of the given *size* using Unicode-Escape and
|
| 1326 |
+
return a bytes object. Return ``NULL`` if an exception was raised by the codec.
|
| 1327 |
+
|
| 1328 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1329 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1330 |
+
:c:func:`PyUnicode_AsUnicodeEscapeString`.
|
| 1331 |
+
|
| 1332 |
+
|
| 1333 |
+
Raw-Unicode-Escape Codecs
|
| 1334 |
+
"""""""""""""""""""""""""
|
| 1335 |
+
|
| 1336 |
+
These are the "Raw Unicode Escape" codec APIs:
|
| 1337 |
+
|
| 1338 |
+
|
| 1339 |
+
.. c:function:: PyObject* PyUnicode_DecodeRawUnicodeEscape(const char *s, \
|
| 1340 |
+
Py_ssize_t size, const char *errors)
|
| 1341 |
+
|
| 1342 |
+
Create a Unicode object by decoding *size* bytes of the Raw-Unicode-Escape
|
| 1343 |
+
encoded string *s*. Return ``NULL`` if an exception was raised by the codec.
|
| 1344 |
+
|
| 1345 |
+
|
| 1346 |
+
.. c:function:: PyObject* PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
|
| 1347 |
+
|
| 1348 |
+
Encode a Unicode object using Raw-Unicode-Escape and return the result as
|
| 1349 |
+
a bytes object. Error handling is "strict". Return ``NULL`` if an exception
|
| 1350 |
+
was raised by the codec.
|
| 1351 |
+
|
| 1352 |
+
|
| 1353 |
+
.. c:function:: PyObject* PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s, \
|
| 1354 |
+
Py_ssize_t size)
|
| 1355 |
+
|
| 1356 |
+
Encode the :c:type:`Py_UNICODE` buffer of the given *size* using Raw-Unicode-Escape
|
| 1357 |
+
and return a bytes object. Return ``NULL`` if an exception was raised by the codec.
|
| 1358 |
+
|
| 1359 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1360 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1361 |
+
:c:func:`PyUnicode_AsRawUnicodeEscapeString` or
|
| 1362 |
+
:c:func:`PyUnicode_AsEncodedString`.
|
| 1363 |
+
|
| 1364 |
+
|
| 1365 |
+
Latin-1 Codecs
|
| 1366 |
+
""""""""""""""
|
| 1367 |
+
|
| 1368 |
+
These are the Latin-1 codec APIs: Latin-1 corresponds to the first 256 Unicode
|
| 1369 |
+
ordinals and only these are accepted by the codecs during encoding.
|
| 1370 |
+
|
| 1371 |
+
|
| 1372 |
+
.. c:function:: PyObject* PyUnicode_DecodeLatin1(const char *s, Py_ssize_t size, const char *errors)
|
| 1373 |
+
|
| 1374 |
+
Create a Unicode object by decoding *size* bytes of the Latin-1 encoded string
|
| 1375 |
+
*s*. Return ``NULL`` if an exception was raised by the codec.
|
| 1376 |
+
|
| 1377 |
+
|
| 1378 |
+
.. c:function:: PyObject* PyUnicode_AsLatin1String(PyObject *unicode)
|
| 1379 |
+
|
| 1380 |
+
Encode a Unicode object using Latin-1 and return the result as Python bytes
|
| 1381 |
+
object. Error handling is "strict". Return ``NULL`` if an exception was
|
| 1382 |
+
raised by the codec.
|
| 1383 |
+
|
| 1384 |
+
|
| 1385 |
+
.. c:function:: PyObject* PyUnicode_EncodeLatin1(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
|
| 1386 |
+
|
| 1387 |
+
Encode the :c:type:`Py_UNICODE` buffer of the given *size* using Latin-1 and
|
| 1388 |
+
return a Python bytes object. Return ``NULL`` if an exception was raised by
|
| 1389 |
+
the codec.
|
| 1390 |
+
|
| 1391 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1392 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1393 |
+
:c:func:`PyUnicode_AsLatin1String` or
|
| 1394 |
+
:c:func:`PyUnicode_AsEncodedString`.
|
| 1395 |
+
|
| 1396 |
+
|
| 1397 |
+
ASCII Codecs
|
| 1398 |
+
""""""""""""
|
| 1399 |
+
|
| 1400 |
+
These are the ASCII codec APIs. Only 7-bit ASCII data is accepted. All other
|
| 1401 |
+
codes generate errors.
|
| 1402 |
+
|
| 1403 |
+
|
| 1404 |
+
.. c:function:: PyObject* PyUnicode_DecodeASCII(const char *s, Py_ssize_t size, const char *errors)
|
| 1405 |
+
|
| 1406 |
+
Create a Unicode object by decoding *size* bytes of the ASCII encoded string
|
| 1407 |
+
*s*. Return ``NULL`` if an exception was raised by the codec.
|
| 1408 |
+
|
| 1409 |
+
|
| 1410 |
+
.. c:function:: PyObject* PyUnicode_AsASCIIString(PyObject *unicode)
|
| 1411 |
+
|
| 1412 |
+
Encode a Unicode object using ASCII and return the result as Python bytes
|
| 1413 |
+
object. Error handling is "strict". Return ``NULL`` if an exception was
|
| 1414 |
+
raised by the codec.
|
| 1415 |
+
|
| 1416 |
+
|
| 1417 |
+
.. c:function:: PyObject* PyUnicode_EncodeASCII(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
|
| 1418 |
+
|
| 1419 |
+
Encode the :c:type:`Py_UNICODE` buffer of the given *size* using ASCII and
|
| 1420 |
+
return a Python bytes object. Return ``NULL`` if an exception was raised by
|
| 1421 |
+
the codec.
|
| 1422 |
+
|
| 1423 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1424 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1425 |
+
:c:func:`PyUnicode_AsASCIIString` or
|
| 1426 |
+
:c:func:`PyUnicode_AsEncodedString`.
|
| 1427 |
+
|
| 1428 |
+
|
| 1429 |
+
Character Map Codecs
|
| 1430 |
+
""""""""""""""""""""
|
| 1431 |
+
|
| 1432 |
+
This codec is special in that it can be used to implement many different codecs
|
| 1433 |
+
(and this is in fact what was done to obtain most of the standard codecs
|
| 1434 |
+
included in the :mod:`encodings` package). The codec uses mapping to encode and
|
| 1435 |
+
decode characters. The mapping objects provided must support the
|
| 1436 |
+
:meth:`__getitem__` mapping interface; dictionaries and sequences work well.
|
| 1437 |
+
|
| 1438 |
+
These are the mapping codec APIs:
|
| 1439 |
+
|
| 1440 |
+
.. c:function:: PyObject* PyUnicode_DecodeCharmap(const char *data, Py_ssize_t size, \
|
| 1441 |
+
PyObject *mapping, const char *errors)
|
| 1442 |
+
|
| 1443 |
+
Create a Unicode object by decoding *size* bytes of the encoded string *s*
|
| 1444 |
+
using the given *mapping* object. Return ``NULL`` if an exception was raised
|
| 1445 |
+
by the codec.
|
| 1446 |
+
|
| 1447 |
+
If *mapping* is ``NULL``, Latin-1 decoding will be applied. Else
|
| 1448 |
+
*mapping* must map bytes ordinals (integers in the range from 0 to 255)
|
| 1449 |
+
to Unicode strings, integers (which are then interpreted as Unicode
|
| 1450 |
+
ordinals) or ``None``. Unmapped data bytes -- ones which cause a
|
| 1451 |
+
:exc:`LookupError`, as well as ones which get mapped to ``None``,
|
| 1452 |
+
``0xFFFE`` or ``'\ufffe'``, are treated as undefined mappings and cause
|
| 1453 |
+
an error.
|
| 1454 |
+
|
| 1455 |
+
|
| 1456 |
+
.. c:function:: PyObject* PyUnicode_AsCharmapString(PyObject *unicode, PyObject *mapping)
|
| 1457 |
+
|
| 1458 |
+
Encode a Unicode object using the given *mapping* object and return the
|
| 1459 |
+
result as a bytes object. Error handling is "strict". Return ``NULL`` if an
|
| 1460 |
+
exception was raised by the codec.
|
| 1461 |
+
|
| 1462 |
+
The *mapping* object must map Unicode ordinal integers to bytes objects,
|
| 1463 |
+
integers in the range from 0 to 255 or ``None``. Unmapped character
|
| 1464 |
+
ordinals (ones which cause a :exc:`LookupError`) as well as mapped to
|
| 1465 |
+
``None`` are treated as "undefined mapping" and cause an error.
|
| 1466 |
+
|
| 1467 |
+
|
| 1468 |
+
.. c:function:: PyObject* PyUnicode_EncodeCharmap(const Py_UNICODE *s, Py_ssize_t size, \
|
| 1469 |
+
PyObject *mapping, const char *errors)
|
| 1470 |
+
|
| 1471 |
+
Encode the :c:type:`Py_UNICODE` buffer of the given *size* using the given
|
| 1472 |
+
*mapping* object and return the result as a bytes object. Return ``NULL`` if
|
| 1473 |
+
an exception was raised by the codec.
|
| 1474 |
+
|
| 1475 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1476 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1477 |
+
:c:func:`PyUnicode_AsCharmapString` or
|
| 1478 |
+
:c:func:`PyUnicode_AsEncodedString`.
|
| 1479 |
+
|
| 1480 |
+
|
| 1481 |
+
The following codec API is special in that maps Unicode to Unicode.
|
| 1482 |
+
|
| 1483 |
+
.. c:function:: PyObject* PyUnicode_Translate(PyObject *unicode, \
|
| 1484 |
+
PyObject *mapping, const char *errors)
|
| 1485 |
+
|
| 1486 |
+
Translate a Unicode object using the given *mapping* object and return the
|
| 1487 |
+
resulting Unicode object. Return ``NULL`` if an exception was raised by the
|
| 1488 |
+
codec.
|
| 1489 |
+
|
| 1490 |
+
The *mapping* object must map Unicode ordinal integers to Unicode strings,
|
| 1491 |
+
integers (which are then interpreted as Unicode ordinals) or ``None``
|
| 1492 |
+
(causing deletion of the character). Unmapped character ordinals (ones
|
| 1493 |
+
which cause a :exc:`LookupError`) are left untouched and are copied as-is.
|
| 1494 |
+
|
| 1495 |
+
|
| 1496 |
+
.. c:function:: PyObject* PyUnicode_TranslateCharmap(const Py_UNICODE *s, Py_ssize_t size, \
|
| 1497 |
+
PyObject *mapping, const char *errors)
|
| 1498 |
+
|
| 1499 |
+
Translate a :c:type:`Py_UNICODE` buffer of the given *size* by applying a
|
| 1500 |
+
character *mapping* table to it and return the resulting Unicode object.
|
| 1501 |
+
Return ``NULL`` when an exception was raised by the codec.
|
| 1502 |
+
|
| 1503 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1504 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1505 |
+
:c:func:`PyUnicode_Translate`. or :ref:`generic codec based API
|
| 1506 |
+
<codec-registry>`
|
| 1507 |
+
|
| 1508 |
+
|
| 1509 |
+
MBCS codecs for Windows
|
| 1510 |
+
"""""""""""""""""""""""
|
| 1511 |
+
|
| 1512 |
+
These are the MBCS codec APIs. They are currently only available on Windows and
|
| 1513 |
+
use the Win32 MBCS converters to implement the conversions. Note that MBCS (or
|
| 1514 |
+
DBCS) is a class of encodings, not just one. The target encoding is defined by
|
| 1515 |
+
the user settings on the machine running the codec.
|
| 1516 |
+
|
| 1517 |
+
.. c:function:: PyObject* PyUnicode_DecodeMBCS(const char *s, Py_ssize_t size, const char *errors)
|
| 1518 |
+
|
| 1519 |
+
Create a Unicode object by decoding *size* bytes of the MBCS encoded string *s*.
|
| 1520 |
+
Return ``NULL`` if an exception was raised by the codec.
|
| 1521 |
+
|
| 1522 |
+
|
| 1523 |
+
.. c:function:: PyObject* PyUnicode_DecodeMBCSStateful(const char *s, Py_ssize_t size, \
|
| 1524 |
+
const char *errors, Py_ssize_t *consumed)
|
| 1525 |
+
|
| 1526 |
+
If *consumed* is ``NULL``, behave like :c:func:`PyUnicode_DecodeMBCS`. If
|
| 1527 |
+
*consumed* is not ``NULL``, :c:func:`PyUnicode_DecodeMBCSStateful` will not decode
|
| 1528 |
+
trailing lead byte and the number of bytes that have been decoded will be stored
|
| 1529 |
+
in *consumed*.
|
| 1530 |
+
|
| 1531 |
+
|
| 1532 |
+
.. c:function:: PyObject* PyUnicode_AsMBCSString(PyObject *unicode)
|
| 1533 |
+
|
| 1534 |
+
Encode a Unicode object using MBCS and return the result as Python bytes
|
| 1535 |
+
object. Error handling is "strict". Return ``NULL`` if an exception was
|
| 1536 |
+
raised by the codec.
|
| 1537 |
+
|
| 1538 |
+
|
| 1539 |
+
.. c:function:: PyObject* PyUnicode_EncodeCodePage(int code_page, PyObject *unicode, const char *errors)
|
| 1540 |
+
|
| 1541 |
+
Encode the Unicode object using the specified code page and return a Python
|
| 1542 |
+
bytes object. Return ``NULL`` if an exception was raised by the codec. Use
|
| 1543 |
+
:c:data:`CP_ACP` code page to get the MBCS encoder.
|
| 1544 |
+
|
| 1545 |
+
.. versionadded:: 3.3
|
| 1546 |
+
|
| 1547 |
+
|
| 1548 |
+
.. c:function:: PyObject* PyUnicode_EncodeMBCS(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
|
| 1549 |
+
|
| 1550 |
+
Encode the :c:type:`Py_UNICODE` buffer of the given *size* using MBCS and return
|
| 1551 |
+
a Python bytes object. Return ``NULL`` if an exception was raised by the
|
| 1552 |
+
codec.
|
| 1553 |
+
|
| 1554 |
+
.. deprecated-removed:: 3.3 4.0
|
| 1555 |
+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
|
| 1556 |
+
:c:func:`PyUnicode_AsMBCSString`, :c:func:`PyUnicode_EncodeCodePage` or
|
| 1557 |
+
:c:func:`PyUnicode_AsEncodedString`.
|
| 1558 |
+
|
| 1559 |
+
|
| 1560 |
+
Methods & Slots
|
| 1561 |
+
"""""""""""""""
|
| 1562 |
+
|
| 1563 |
+
|
| 1564 |
+
.. _unicodemethodsandslots:
|
| 1565 |
+
|
| 1566 |
+
Methods and Slot Functions
|
| 1567 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 1568 |
+
|
| 1569 |
+
The following APIs are capable of handling Unicode objects and strings on input
|
| 1570 |
+
(we refer to them as strings in the descriptions) and return Unicode objects or
|
| 1571 |
+
integers as appropriate.
|
| 1572 |
+
|
| 1573 |
+
They all return ``NULL`` or ``-1`` if an exception occurs.
|
| 1574 |
+
|
| 1575 |
+
|
| 1576 |
+
.. c:function:: PyObject* PyUnicode_Concat(PyObject *left, PyObject *right)
|
| 1577 |
+
|
| 1578 |
+
Concat two strings giving a new Unicode string.
|
| 1579 |
+
|
| 1580 |
+
|
| 1581 |
+
.. c:function:: PyObject* PyUnicode_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit)
|
| 1582 |
+
|
| 1583 |
+
Split a string giving a list of Unicode strings. If *sep* is ``NULL``, splitting
|
| 1584 |
+
will be done at all whitespace substrings. Otherwise, splits occur at the given
|
| 1585 |
+
separator. At most *maxsplit* splits will be done. If negative, no limit is
|
| 1586 |
+
set. Separators are not included in the resulting list.
|
| 1587 |
+
|
| 1588 |
+
|
| 1589 |
+
.. c:function:: PyObject* PyUnicode_Splitlines(PyObject *s, int keepend)
|
| 1590 |
+
|
| 1591 |
+
Split a Unicode string at line breaks, returning a list of Unicode strings.
|
| 1592 |
+
CRLF is considered to be one line break. If *keepend* is ``0``, the Line break
|
| 1593 |
+
characters are not included in the resulting strings.
|
| 1594 |
+
|
| 1595 |
+
|
| 1596 |
+
.. c:function:: PyObject* PyUnicode_Translate(PyObject *str, PyObject *table, \
|
| 1597 |
+
const char *errors)
|
| 1598 |
+
|
| 1599 |
+
Translate a string by applying a character mapping table to it and return the
|
| 1600 |
+
resulting Unicode object.
|
| 1601 |
+
|
| 1602 |
+
The mapping table must map Unicode ordinal integers to Unicode ordinal integers
|
| 1603 |
+
or ``None`` (causing deletion of the character).
|
| 1604 |
+
|
| 1605 |
+
Mapping tables need only provide the :meth:`__getitem__` interface; dictionaries
|
| 1606 |
+
and sequences work well. Unmapped character ordinals (ones which cause a
|
| 1607 |
+
:exc:`LookupError`) are left untouched and are copied as-is.
|
| 1608 |
+
|
| 1609 |
+
*errors* has the usual meaning for codecs. It may be ``NULL`` which indicates to
|
| 1610 |
+
use the default error handling.
|
| 1611 |
+
|
| 1612 |
+
|
| 1613 |
+
.. c:function:: PyObject* PyUnicode_Join(PyObject *separator, PyObject *seq)
|
| 1614 |
+
|
| 1615 |
+
Join a sequence of strings using the given *separator* and return the resulting
|
| 1616 |
+
Unicode string.
|
| 1617 |
+
|
| 1618 |
+
|
| 1619 |
+
.. c:function:: Py_ssize_t PyUnicode_Tailmatch(PyObject *str, PyObject *substr, \
|
| 1620 |
+
Py_ssize_t start, Py_ssize_t end, int direction)
|
| 1621 |
+
|
| 1622 |
+
Return ``1`` if *substr* matches ``str[start:end]`` at the given tail end
|
| 1623 |
+
(*direction* == ``-1`` means to do a prefix match, *direction* == ``1`` a suffix match),
|
| 1624 |
+
``0`` otherwise. Return ``-1`` if an error occurred.
|
| 1625 |
+
|
| 1626 |
+
|
| 1627 |
+
.. c:function:: Py_ssize_t PyUnicode_Find(PyObject *str, PyObject *substr, \
|
| 1628 |
+
Py_ssize_t start, Py_ssize_t end, int direction)
|
| 1629 |
+
|
| 1630 |
+
Return the first position of *substr* in ``str[start:end]`` using the given
|
| 1631 |
+
*direction* (*direction* == ``1`` means to do a forward search, *direction* == ``-1`` a
|
| 1632 |
+
backward search). The return value is the index of the first match; a value of
|
| 1633 |
+
``-1`` indicates that no match was found, and ``-2`` indicates that an error
|
| 1634 |
+
occurred and an exception has been set.
|
| 1635 |
+
|
| 1636 |
+
|
| 1637 |
+
.. c:function:: Py_ssize_t PyUnicode_FindChar(PyObject *str, Py_UCS4 ch, \
|
| 1638 |
+
Py_ssize_t start, Py_ssize_t end, int direction)
|
| 1639 |
+
|
| 1640 |
+
Return the first position of the character *ch* in ``str[start:end]`` using
|
| 1641 |
+
the given *direction* (*direction* == ``1`` means to do a forward search,
|
| 1642 |
+
*direction* == ``-1`` a backward search). The return value is the index of the
|
| 1643 |
+
first match; a value of ``-1`` indicates that no match was found, and ``-2``
|
| 1644 |
+
indicates that an error occurred and an exception has been set.
|
| 1645 |
+
|
| 1646 |
+
.. versionadded:: 3.3
|
| 1647 |
+
|
| 1648 |
+
.. versionchanged:: 3.7
|
| 1649 |
+
*start* and *end* are now adjusted to behave like ``str[start:end]``.
|
| 1650 |
+
|
| 1651 |
+
|
| 1652 |
+
.. c:function:: Py_ssize_t PyUnicode_Count(PyObject *str, PyObject *substr, \
|
| 1653 |
+
Py_ssize_t start, Py_ssize_t end)
|
| 1654 |
+
|
| 1655 |
+
Return the number of non-overlapping occurrences of *substr* in
|
| 1656 |
+
``str[start:end]``. Return ``-1`` if an error occurred.
|
| 1657 |
+
|
| 1658 |
+
|
| 1659 |
+
.. c:function:: PyObject* PyUnicode_Replace(PyObject *str, PyObject *substr, \
|
| 1660 |
+
PyObject *replstr, Py_ssize_t maxcount)
|
| 1661 |
+
|
| 1662 |
+
Replace at most *maxcount* occurrences of *substr* in *str* with *replstr* and
|
| 1663 |
+
return the resulting Unicode object. *maxcount* == ``-1`` means replace all
|
| 1664 |
+
occurrences.
|
| 1665 |
+
|
| 1666 |
+
|
| 1667 |
+
.. c:function:: int PyUnicode_Compare(PyObject *left, PyObject *right)
|
| 1668 |
+
|
| 1669 |
+
Compare two strings and return ``-1``, ``0``, ``1`` for less than, equal, and greater than,
|
| 1670 |
+
respectively.
|
| 1671 |
+
|
| 1672 |
+
This function returns ``-1`` upon failure, so one should call
|
| 1673 |
+
:c:func:`PyErr_Occurred` to check for errors.
|
| 1674 |
+
|
| 1675 |
+
|
| 1676 |
+
.. c:function:: int PyUnicode_CompareWithASCIIString(PyObject *uni, const char *string)
|
| 1677 |
+
|
| 1678 |
+
Compare a Unicode object, *uni*, with *string* and return ``-1``, ``0``, ``1`` for less
|
| 1679 |
+
than, equal, and greater than, respectively. It is best to pass only
|
| 1680 |
+
ASCII-encoded strings, but the function interprets the input string as
|
| 1681 |
+
ISO-8859-1 if it contains non-ASCII characters.
|
| 1682 |
+
|
| 1683 |
+
This function does not raise exceptions.
|
| 1684 |
+
|
| 1685 |
+
|
| 1686 |
+
.. c:function:: PyObject* PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
|
| 1687 |
+
|
| 1688 |
+
Rich compare two Unicode strings and return one of the following:
|
| 1689 |
+
|
| 1690 |
+
* ``NULL`` in case an exception was raised
|
| 1691 |
+
* :const:`Py_True` or :const:`Py_False` for successful comparisons
|
| 1692 |
+
* :const:`Py_NotImplemented` in case the type combination is unknown
|
| 1693 |
+
|
| 1694 |
+
Possible values for *op* are :const:`Py_GT`, :const:`Py_GE`, :const:`Py_EQ`,
|
| 1695 |
+
:const:`Py_NE`, :const:`Py_LT`, and :const:`Py_LE`.
|
| 1696 |
+
|
| 1697 |
+
|
| 1698 |
+
.. c:function:: PyObject* PyUnicode_Format(PyObject *format, PyObject *args)
|
| 1699 |
+
|
| 1700 |
+
Return a new string object from *format* and *args*; this is analogous to
|
| 1701 |
+
``format % args``.
|
| 1702 |
+
|
| 1703 |
+
|
| 1704 |
+
.. c:function:: int PyUnicode_Contains(PyObject *container, PyObject *element)
|
| 1705 |
+
|
| 1706 |
+
Check whether *element* is contained in *container* and return true or false
|
| 1707 |
+
accordingly.
|
| 1708 |
+
|
| 1709 |
+
*element* has to coerce to a one element Unicode string. ``-1`` is returned
|
| 1710 |
+
if there was an error.
|
| 1711 |
+
|
| 1712 |
+
|
| 1713 |
+
.. c:function:: void PyUnicode_InternInPlace(PyObject **string)
|
| 1714 |
+
|
| 1715 |
+
Intern the argument *\*string* in place. The argument must be the address of a
|
| 1716 |
+
pointer variable pointing to a Python Unicode string object. If there is an
|
| 1717 |
+
existing interned string that is the same as *\*string*, it sets *\*string* to
|
| 1718 |
+
it (decrementing the reference count of the old string object and incrementing
|
| 1719 |
+
the reference count of the interned string object), otherwise it leaves
|
| 1720 |
+
*\*string* alone and interns it (incrementing its reference count).
|
| 1721 |
+
(Clarification: even though there is a lot of talk about reference counts, think
|
| 1722 |
+
of this function as reference-count-neutral; you own the object after the call
|
| 1723 |
+
if and only if you owned it before the call.)
|
| 1724 |
+
|
| 1725 |
+
|
| 1726 |
+
.. c:function:: PyObject* PyUnicode_InternFromString(const char *v)
|
| 1727 |
+
|
| 1728 |
+
A combination of :c:func:`PyUnicode_FromString` and
|
| 1729 |
+
:c:func:`PyUnicode_InternInPlace`, returning either a new Unicode string
|
| 1730 |
+
object that has been interned, or a new ("owned") reference to an earlier
|
| 1731 |
+
interned string object with the same value.
|
cpython_2/environment/repo/Doc/c-api/utilities.rst
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _utilities:
|
| 4 |
+
|
| 5 |
+
*********
|
| 6 |
+
Utilities
|
| 7 |
+
*********
|
| 8 |
+
|
| 9 |
+
The functions in this chapter perform various utility tasks, ranging from
|
| 10 |
+
helping C code be more portable across platforms, using Python modules from C,
|
| 11 |
+
and parsing function arguments and constructing Python values from C values.
|
| 12 |
+
|
| 13 |
+
.. toctree::
|
| 14 |
+
|
| 15 |
+
sys.rst
|
| 16 |
+
import.rst
|
| 17 |
+
marshal.rst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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
.. _veryhigh:
|
| 5 |
+
|
| 6 |
+
*************************
|
| 7 |
+
The Very High Level Layer
|
| 8 |
+
*************************
|
| 9 |
+
|
| 10 |
+
The functions in this chapter will let you execute Python source code given in a
|
| 11 |
+
file or a buffer, but they will not let you interact in a more detailed way with
|
| 12 |
+
the interpreter.
|
| 13 |
+
|
| 14 |
+
Several of these functions accept a start symbol from the grammar as a
|
| 15 |
+
parameter. The available start symbols are :const:`Py_eval_input`,
|
| 16 |
+
:const:`Py_file_input`, and :const:`Py_single_input`. These are described
|
| 17 |
+
following the functions which accept them as parameters.
|
| 18 |
+
|
| 19 |
+
Note also that several of these functions take :c:type:`FILE\*` parameters. One
|
| 20 |
+
particular issue which needs to be handled carefully is that the :c:type:`FILE`
|
| 21 |
+
structure for different C libraries can be different and incompatible. Under
|
| 22 |
+
Windows (at least), it is possible for dynamically linked extensions to actually
|
| 23 |
+
use different libraries, so care should be taken that :c:type:`FILE\*` parameters
|
| 24 |
+
are only passed to these functions if it is certain that they were created by
|
| 25 |
+
the same library that the Python runtime is using.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
.. c:function:: int Py_Main(int argc, wchar_t **argv)
|
| 29 |
+
|
| 30 |
+
The main program for the standard interpreter. This is made available for
|
| 31 |
+
programs which embed Python. The *argc* and *argv* parameters should be
|
| 32 |
+
prepared exactly as those which are passed to a C program's :c:func:`main`
|
| 33 |
+
function (converted to wchar_t according to the user's locale). It is
|
| 34 |
+
important to note that the argument list may be modified (but the contents of
|
| 35 |
+
the strings pointed to by the argument list are not). The return value will
|
| 36 |
+
be ``0`` if the interpreter exits normally (i.e., without an exception),
|
| 37 |
+
``1`` if the interpreter exits due to an exception, or ``2`` if the parameter
|
| 38 |
+
list does not represent a valid Python command line.
|
| 39 |
+
|
| 40 |
+
Note that if an otherwise unhandled :exc:`SystemExit` is raised, this
|
| 41 |
+
function will not return ``1``, but exit the process, as long as
|
| 42 |
+
``Py_InspectFlag`` is not set.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
.. c:function:: int Py_BytesMain(int argc, char **argv)
|
| 46 |
+
|
| 47 |
+
Similar to :c:func:`Py_Main` but *argv* is an array of bytes strings.
|
| 48 |
+
|
| 49 |
+
.. versionadded:: 3.8
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
.. c:function:: int PyRun_AnyFile(FILE *fp, const char *filename)
|
| 53 |
+
|
| 54 |
+
This is a simplified interface to :c:func:`PyRun_AnyFileExFlags` below, leaving
|
| 55 |
+
*closeit* set to ``0`` and *flags* set to ``NULL``.
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
.. c:function:: int PyRun_AnyFileFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)
|
| 59 |
+
|
| 60 |
+
This is a simplified interface to :c:func:`PyRun_AnyFileExFlags` below, leaving
|
| 61 |
+
the *closeit* argument set to ``0``.
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
.. c:function:: int PyRun_AnyFileEx(FILE *fp, const char *filename, int closeit)
|
| 65 |
+
|
| 66 |
+
This is a simplified interface to :c:func:`PyRun_AnyFileExFlags` below, leaving
|
| 67 |
+
the *flags* argument set to ``NULL``.
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
.. c:function:: int PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags)
|
| 71 |
+
|
| 72 |
+
If *fp* refers to a file associated with an interactive device (console or
|
| 73 |
+
terminal input or Unix pseudo-terminal), return the value of
|
| 74 |
+
:c:func:`PyRun_InteractiveLoop`, otherwise return the result of
|
| 75 |
+
:c:func:`PyRun_SimpleFile`. *filename* is decoded from the filesystem
|
| 76 |
+
encoding (:func:`sys.getfilesystemencoding`). If *filename* is ``NULL``, this
|
| 77 |
+
function uses ``"???"`` as the filename.
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
.. c:function:: int PyRun_SimpleString(const char *command)
|
| 81 |
+
|
| 82 |
+
This is a simplified interface to :c:func:`PyRun_SimpleStringFlags` below,
|
| 83 |
+
leaving the :c:type:`PyCompilerFlags`\* argument set to ``NULL``.
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
.. c:function:: int PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags)
|
| 87 |
+
|
| 88 |
+
Executes the Python source code from *command* in the :mod:`__main__` module
|
| 89 |
+
according to the *flags* argument. If :mod:`__main__` does not already exist, it
|
| 90 |
+
is created. Returns ``0`` on success or ``-1`` if an exception was raised. If
|
| 91 |
+
there was an error, there is no way to get the exception information. For the
|
| 92 |
+
meaning of *flags*, see below.
|
| 93 |
+
|
| 94 |
+
Note that if an otherwise unhandled :exc:`SystemExit` is raised, this
|
| 95 |
+
function will not return ``-1``, but exit the process, as long as
|
| 96 |
+
``Py_InspectFlag`` is not set.
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
.. c:function:: int PyRun_SimpleFile(FILE *fp, const char *filename)
|
| 100 |
+
|
| 101 |
+
This is a simplified interface to :c:func:`PyRun_SimpleFileExFlags` below,
|
| 102 |
+
leaving *closeit* set to ``0`` and *flags* set to ``NULL``.
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
.. c:function:: int PyRun_SimpleFileEx(FILE *fp, const char *filename, int closeit)
|
| 106 |
+
|
| 107 |
+
This is a simplified interface to :c:func:`PyRun_SimpleFileExFlags` below,
|
| 108 |
+
leaving *flags* set to ``NULL``.
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
.. c:function:: int PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags)
|
| 112 |
+
|
| 113 |
+
Similar to :c:func:`PyRun_SimpleStringFlags`, but the Python source code is read
|
| 114 |
+
from *fp* instead of an in-memory string. *filename* should be the name of
|
| 115 |
+
the file, it is decoded from the filesystem encoding
|
| 116 |
+
(:func:`sys.getfilesystemencoding`). If *closeit* is true, the file is
|
| 117 |
+
closed before PyRun_SimpleFileExFlags returns.
|
| 118 |
+
|
| 119 |
+
.. note::
|
| 120 |
+
On Windows, *fp* should be opened as binary mode (e.g. ``fopen(filename, "rb")``).
|
| 121 |
+
Otherwise, Python may not handle script file with LF line ending correctly.
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
.. c:function:: int PyRun_InteractiveOne(FILE *fp, const char *filename)
|
| 125 |
+
|
| 126 |
+
This is a simplified interface to :c:func:`PyRun_InteractiveOneFlags` below,
|
| 127 |
+
leaving *flags* set to ``NULL``.
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
.. c:function:: int PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)
|
| 131 |
+
|
| 132 |
+
Read and execute a single statement from a file associated with an
|
| 133 |
+
interactive device according to the *flags* argument. The user will be
|
| 134 |
+
prompted using ``sys.ps1`` and ``sys.ps2``. *filename* is decoded from the
|
| 135 |
+
filesystem encoding (:func:`sys.getfilesystemencoding`).
|
| 136 |
+
|
| 137 |
+
Returns ``0`` when the input was
|
| 138 |
+
executed successfully, ``-1`` if there was an exception, or an error code
|
| 139 |
+
from the :file:`errcode.h` include file distributed as part of Python if
|
| 140 |
+
there was a parse error. (Note that :file:`errcode.h` is not included by
|
| 141 |
+
:file:`Python.h`, so must be included specifically if needed.)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
.. c:function:: int PyRun_InteractiveLoop(FILE *fp, const char *filename)
|
| 145 |
+
|
| 146 |
+
This is a simplified interface to :c:func:`PyRun_InteractiveLoopFlags` below,
|
| 147 |
+
leaving *flags* set to ``NULL``.
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
.. c:function:: int PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)
|
| 151 |
+
|
| 152 |
+
Read and execute statements from a file associated with an interactive device
|
| 153 |
+
until EOF is reached. The user will be prompted using ``sys.ps1`` and
|
| 154 |
+
``sys.ps2``. *filename* is decoded from the filesystem encoding
|
| 155 |
+
(:func:`sys.getfilesystemencoding`). Returns ``0`` at EOF or a negative
|
| 156 |
+
number upon failure.
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
.. c:var:: int (*PyOS_InputHook)(void)
|
| 160 |
+
|
| 161 |
+
Can be set to point to a function with the prototype
|
| 162 |
+
``int func(void)``. The function will be called when Python's
|
| 163 |
+
interpreter prompt is about to become idle and wait for user input
|
| 164 |
+
from the terminal. The return value is ignored. Overriding this
|
| 165 |
+
hook can be used to integrate the interpreter's prompt with other
|
| 166 |
+
event loops, as done in the :file:`Modules/_tkinter.c` in the
|
| 167 |
+
Python source code.
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
.. c:var:: char* (*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *)
|
| 171 |
+
|
| 172 |
+
Can be set to point to a function with the prototype
|
| 173 |
+
``char *func(FILE *stdin, FILE *stdout, char *prompt)``,
|
| 174 |
+
overriding the default function used to read a single line of input
|
| 175 |
+
at the interpreter's prompt. The function is expected to output
|
| 176 |
+
the string *prompt* if it's not ``NULL``, and then read a line of
|
| 177 |
+
input from the provided standard input file, returning the
|
| 178 |
+
resulting string. For example, The :mod:`readline` module sets
|
| 179 |
+
this hook to provide line-editing and tab-completion features.
|
| 180 |
+
|
| 181 |
+
The result must be a string allocated by :c:func:`PyMem_RawMalloc` or
|
| 182 |
+
:c:func:`PyMem_RawRealloc`, or ``NULL`` if an error occurred.
|
| 183 |
+
|
| 184 |
+
.. versionchanged:: 3.4
|
| 185 |
+
The result must be allocated by :c:func:`PyMem_RawMalloc` or
|
| 186 |
+
:c:func:`PyMem_RawRealloc`, instead of being allocated by
|
| 187 |
+
:c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`.
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
.. c:function:: struct _node* PyParser_SimpleParseString(const char *str, int start)
|
| 191 |
+
|
| 192 |
+
This is a simplified interface to
|
| 193 |
+
:c:func:`PyParser_SimpleParseStringFlagsFilename` below, leaving *filename* set
|
| 194 |
+
to ``NULL`` and *flags* set to ``0``.
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
.. c:function:: struct _node* PyParser_SimpleParseStringFlags( const char *str, int start, int flags)
|
| 198 |
+
|
| 199 |
+
This is a simplified interface to
|
| 200 |
+
:c:func:`PyParser_SimpleParseStringFlagsFilename` below, leaving *filename* set
|
| 201 |
+
to ``NULL``.
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
.. c:function:: struct _node* PyParser_SimpleParseStringFlagsFilename( const char *str, const char *filename, int start, int flags)
|
| 205 |
+
|
| 206 |
+
Parse Python source code from *str* using the start token *start* according to
|
| 207 |
+
the *flags* argument. The result can be used to create a code object which can
|
| 208 |
+
be evaluated efficiently. This is useful if a code fragment must be evaluated
|
| 209 |
+
many times. *filename* is decoded from the filesystem encoding
|
| 210 |
+
(:func:`sys.getfilesystemencoding`).
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
.. c:function:: struct _node* PyParser_SimpleParseFile(FILE *fp, const char *filename, int start)
|
| 214 |
+
|
| 215 |
+
This is a simplified interface to :c:func:`PyParser_SimpleParseFileFlags` below,
|
| 216 |
+
leaving *flags* set to ``0``.
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
.. c:function:: struct _node* PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags)
|
| 220 |
+
|
| 221 |
+
Similar to :c:func:`PyParser_SimpleParseStringFlagsFilename`, but the Python
|
| 222 |
+
source code is read from *fp* instead of an in-memory string.
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
.. c:function:: PyObject* PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals)
|
| 226 |
+
|
| 227 |
+
This is a simplified interface to :c:func:`PyRun_StringFlags` below, leaving
|
| 228 |
+
*flags* set to ``NULL``.
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
.. c:function:: PyObject* PyRun_StringFlags(const char *str, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags)
|
| 232 |
+
|
| 233 |
+
Execute Python source code from *str* in the context specified by the
|
| 234 |
+
objects *globals* and *locals* with the compiler flags specified by
|
| 235 |
+
*flags*. *globals* must be a dictionary; *locals* can be any object
|
| 236 |
+
that implements the mapping protocol. The parameter *start* specifies
|
| 237 |
+
the start token that should be used to parse the source code.
|
| 238 |
+
|
| 239 |
+
Returns the result of executing the code as a Python object, or ``NULL`` if an
|
| 240 |
+
exception was raised.
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
.. c:function:: PyObject* PyRun_File(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals)
|
| 244 |
+
|
| 245 |
+
This is a simplified interface to :c:func:`PyRun_FileExFlags` below, leaving
|
| 246 |
+
*closeit* set to ``0`` and *flags* set to ``NULL``.
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
.. c:function:: PyObject* PyRun_FileEx(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit)
|
| 250 |
+
|
| 251 |
+
This is a simplified interface to :c:func:`PyRun_FileExFlags` below, leaving
|
| 252 |
+
*flags* set to ``NULL``.
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
.. c:function:: PyObject* PyRun_FileFlags(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags)
|
| 256 |
+
|
| 257 |
+
This is a simplified interface to :c:func:`PyRun_FileExFlags` below, leaving
|
| 258 |
+
*closeit* set to ``0``.
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
.. c:function:: PyObject* PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit, PyCompilerFlags *flags)
|
| 262 |
+
|
| 263 |
+
Similar to :c:func:`PyRun_StringFlags`, but the Python source code is read from
|
| 264 |
+
*fp* instead of an in-memory string. *filename* should be the name of the file,
|
| 265 |
+
it is decoded from the filesystem encoding (:func:`sys.getfilesystemencoding`).
|
| 266 |
+
If *closeit* is true, the file is closed before :c:func:`PyRun_FileExFlags`
|
| 267 |
+
returns.
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
.. c:function:: PyObject* Py_CompileString(const char *str, const char *filename, int start)
|
| 271 |
+
|
| 272 |
+
This is a simplified interface to :c:func:`Py_CompileStringFlags` below, leaving
|
| 273 |
+
*flags* set to ``NULL``.
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
.. c:function:: PyObject* Py_CompileStringFlags(const char *str, const char *filename, int start, PyCompilerFlags *flags)
|
| 277 |
+
|
| 278 |
+
This is a simplified interface to :c:func:`Py_CompileStringExFlags` below, with
|
| 279 |
+
*optimize* set to ``-1``.
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
.. c:function:: PyObject* Py_CompileStringObject(const char *str, PyObject *filename, int start, PyCompilerFlags *flags, int optimize)
|
| 283 |
+
|
| 284 |
+
Parse and compile the Python source code in *str*, returning the resulting code
|
| 285 |
+
object. The start token is given by *start*; this can be used to constrain the
|
| 286 |
+
code which can be compiled and should be :const:`Py_eval_input`,
|
| 287 |
+
:const:`Py_file_input`, or :const:`Py_single_input`. The filename specified by
|
| 288 |
+
*filename* is used to construct the code object and may appear in tracebacks or
|
| 289 |
+
:exc:`SyntaxError` exception messages. This returns ``NULL`` if the code
|
| 290 |
+
cannot be parsed or compiled.
|
| 291 |
+
|
| 292 |
+
The integer *optimize* specifies the optimization level of the compiler; a
|
| 293 |
+
value of ``-1`` selects the optimization level of the interpreter as given by
|
| 294 |
+
:option:`-O` options. Explicit levels are ``0`` (no optimization;
|
| 295 |
+
``__debug__`` is true), ``1`` (asserts are removed, ``__debug__`` is false)
|
| 296 |
+
or ``2`` (docstrings are removed too).
|
| 297 |
+
|
| 298 |
+
.. versionadded:: 3.4
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
.. c:function:: PyObject* Py_CompileStringExFlags(const char *str, const char *filename, int start, PyCompilerFlags *flags, int optimize)
|
| 302 |
+
|
| 303 |
+
Like :c:func:`Py_CompileStringObject`, but *filename* is a byte string
|
| 304 |
+
decoded from the filesystem encoding (:func:`os.fsdecode`).
|
| 305 |
+
|
| 306 |
+
.. versionadded:: 3.2
|
| 307 |
+
|
| 308 |
+
.. c:function:: PyObject* PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals)
|
| 309 |
+
|
| 310 |
+
This is a simplified interface to :c:func:`PyEval_EvalCodeEx`, with just
|
| 311 |
+
the code object, and global and local variables. The other arguments are
|
| 312 |
+
set to ``NULL``.
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
.. c:function:: PyObject* PyEval_EvalCodeEx(PyObject *co, PyObject *globals, PyObject *locals, PyObject *const *args, int argcount, PyObject *const *kws, int kwcount, PyObject *const *defs, int defcount, PyObject *kwdefs, PyObject *closure)
|
| 316 |
+
|
| 317 |
+
Evaluate a precompiled code object, given a particular environment for its
|
| 318 |
+
evaluation. This environment consists of a dictionary of global variables,
|
| 319 |
+
a mapping object of local variables, arrays of arguments, keywords and
|
| 320 |
+
defaults, a dictionary of default values for :ref:`keyword-only
|
| 321 |
+
<keyword-only_parameter>` arguments and a closure tuple of cells.
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
.. c:type:: PyFrameObject
|
| 325 |
+
|
| 326 |
+
The C structure of the objects used to describe frame objects. The
|
| 327 |
+
fields of this type are subject to change at any time.
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
.. c:function:: PyObject* PyEval_EvalFrame(PyFrameObject *f)
|
| 331 |
+
|
| 332 |
+
Evaluate an execution frame. This is a simplified interface to
|
| 333 |
+
:c:func:`PyEval_EvalFrameEx`, for backward compatibility.
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
.. c:function:: PyObject* PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
| 337 |
+
|
| 338 |
+
This is the main, unvarnished function of Python interpretation. The code
|
| 339 |
+
object associated with the execution frame *f* is executed, interpreting
|
| 340 |
+
bytecode and executing calls as needed. The additional *throwflag*
|
| 341 |
+
parameter can mostly be ignored - if true, then it causes an exception
|
| 342 |
+
to immediately be thrown; this is used for the :meth:`~generator.throw`
|
| 343 |
+
methods of generator objects.
|
| 344 |
+
|
| 345 |
+
.. versionchanged:: 3.4
|
| 346 |
+
This function now includes a debug assertion to help ensure that it
|
| 347 |
+
does not silently discard an active exception.
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
.. c:function:: int PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
|
| 351 |
+
|
| 352 |
+
This function changes the flags of the current evaluation frame, and returns
|
| 353 |
+
true on success, false on failure.
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
.. c:var:: int Py_eval_input
|
| 357 |
+
|
| 358 |
+
.. index:: single: Py_CompileString()
|
| 359 |
+
|
| 360 |
+
The start symbol from the Python grammar for isolated expressions; for use with
|
| 361 |
+
:c:func:`Py_CompileString`.
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
.. c:var:: int Py_file_input
|
| 365 |
+
|
| 366 |
+
.. index:: single: Py_CompileString()
|
| 367 |
+
|
| 368 |
+
The start symbol from the Python grammar for sequences of statements as read
|
| 369 |
+
from a file or other source; for use with :c:func:`Py_CompileString`. This is
|
| 370 |
+
the symbol to use when compiling arbitrarily long Python source code.
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
.. c:var:: int Py_single_input
|
| 374 |
+
|
| 375 |
+
.. index:: single: Py_CompileString()
|
| 376 |
+
|
| 377 |
+
The start symbol from the Python grammar for a single statement; for use with
|
| 378 |
+
:c:func:`Py_CompileString`. This is the symbol used for the interactive
|
| 379 |
+
interpreter loop.
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
.. c:type:: struct PyCompilerFlags
|
| 383 |
+
|
| 384 |
+
This is the structure used to hold compiler flags. In cases where code is only
|
| 385 |
+
being compiled, it is passed as ``int flags``, and in cases where code is being
|
| 386 |
+
executed, it is passed as ``PyCompilerFlags *flags``. In this case, ``from
|
| 387 |
+
__future__ import`` can modify *flags*.
|
| 388 |
+
|
| 389 |
+
Whenever ``PyCompilerFlags *flags`` is ``NULL``, :attr:`cf_flags` is treated as
|
| 390 |
+
equal to ``0``, and any modification due to ``from __future__ import`` is
|
| 391 |
+
discarded.
|
| 392 |
+
|
| 393 |
+
.. c:member:: int cf_flags
|
| 394 |
+
|
| 395 |
+
Compiler flags.
|
| 396 |
+
|
| 397 |
+
.. c:member:: int cf_feature_version
|
| 398 |
+
|
| 399 |
+
*cf_feature_version* is the minor Python version. It should be
|
| 400 |
+
initialized to ``PY_MINOR_VERSION``.
|
| 401 |
+
|
| 402 |
+
The field is ignored by default, it is used if and only if
|
| 403 |
+
``PyCF_ONLY_AST`` flag is set in *cf_flags*.
|
| 404 |
+
|
| 405 |
+
.. versionchanged:: 3.8
|
| 406 |
+
Added *cf_feature_version* field.
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
.. c:var:: int CO_FUTURE_DIVISION
|
| 410 |
+
|
| 411 |
+
This bit can be set in *flags* to cause division operator ``/`` to be
|
| 412 |
+
interpreted as "true division" according to :pep:`238`.
|
cpython_2/environment/repo/Doc/c-api/weakref.rst
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. highlight:: c
|
| 2 |
+
|
| 3 |
+
.. _weakrefobjects:
|
| 4 |
+
|
| 5 |
+
Weak Reference Objects
|
| 6 |
+
----------------------
|
| 7 |
+
|
| 8 |
+
Python supports *weak references* as first-class objects. There are two
|
| 9 |
+
specific object types which directly implement weak references. The first is a
|
| 10 |
+
simple reference object, and the second acts as a proxy for the original object
|
| 11 |
+
as much as it can.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
.. c:function:: int PyWeakref_Check(ob)
|
| 15 |
+
|
| 16 |
+
Return true if *ob* is either a reference or proxy object.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
.. c:function:: int PyWeakref_CheckRef(ob)
|
| 20 |
+
|
| 21 |
+
Return true if *ob* is a reference object.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
.. c:function:: int PyWeakref_CheckProxy(ob)
|
| 25 |
+
|
| 26 |
+
Return true if *ob* is a proxy object.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
.. c:function:: PyObject* PyWeakref_NewRef(PyObject *ob, PyObject *callback)
|
| 30 |
+
|
| 31 |
+
Return a weak reference object for the object *ob*. This will always return
|
| 32 |
+
a new reference, but is not guaranteed to create a new object; an existing
|
| 33 |
+
reference object may be returned. The second parameter, *callback*, can be a
|
| 34 |
+
callable object that receives notification when *ob* is garbage collected; it
|
| 35 |
+
should accept a single parameter, which will be the weak reference object
|
| 36 |
+
itself. *callback* may also be ``None`` or ``NULL``. If *ob* is not a
|
| 37 |
+
weakly-referencable object, or if *callback* is not callable, ``None``, or
|
| 38 |
+
``NULL``, this will return ``NULL`` and raise :exc:`TypeError`.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
.. c:function:: PyObject* PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
|
| 42 |
+
|
| 43 |
+
Return a weak reference proxy object for the object *ob*. This will always
|
| 44 |
+
return a new reference, but is not guaranteed to create a new object; an
|
| 45 |
+
existing proxy object may be returned. The second parameter, *callback*, can
|
| 46 |
+
be a callable object that receives notification when *ob* is garbage
|
| 47 |
+
collected; it should accept a single parameter, which will be the weak
|
| 48 |
+
reference object itself. *callback* may also be ``None`` or ``NULL``. If *ob*
|
| 49 |
+
is not a weakly-referencable object, or if *callback* is not callable,
|
| 50 |
+
``None``, or ``NULL``, this will return ``NULL`` and raise :exc:`TypeError`.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
.. c:function:: PyObject* PyWeakref_GetObject(PyObject *ref)
|
| 54 |
+
|
| 55 |
+
Return the referenced object from a weak reference, *ref*. If the referent is
|
| 56 |
+
no longer live, returns :const:`Py_None`.
|
| 57 |
+
|
| 58 |
+
.. note::
|
| 59 |
+
|
| 60 |
+
This function returns a **borrowed reference** to the referenced object.
|
| 61 |
+
This means that you should always call :c:func:`Py_INCREF` on the object
|
| 62 |
+
except if you know that it cannot be destroyed while you are still
|
| 63 |
+
using it.
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
.. c:function:: PyObject* PyWeakref_GET_OBJECT(PyObject *ref)
|
| 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# Python documentation build configuration file
|
| 3 |
+
#
|
| 4 |
+
# This file is execfile()d with the current directory set to its containing dir.
|
| 5 |
+
#
|
| 6 |
+
# The contents of this file are pickled, so don't put values in the namespace
|
| 7 |
+
# that aren't pickleable (module imports are okay, they're removed automatically).
|
| 8 |
+
|
| 9 |
+
import sys, os, time
|
| 10 |
+
sys.path.append(os.path.abspath('tools/extensions'))
|
| 11 |
+
sys.path.append(os.path.abspath('includes'))
|
| 12 |
+
|
| 13 |
+
# General configuration
|
| 14 |
+
# ---------------------
|
| 15 |
+
|
| 16 |
+
extensions = ['sphinx.ext.coverage', 'sphinx.ext.doctest',
|
| 17 |
+
'pyspecific', 'c_annotations', 'escape4chm',
|
| 18 |
+
'asdl_highlight']
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
doctest_global_setup = '''
|
| 22 |
+
try:
|
| 23 |
+
import _tkinter
|
| 24 |
+
except ImportError:
|
| 25 |
+
_tkinter = None
|
| 26 |
+
'''
|
| 27 |
+
|
| 28 |
+
manpages_url = 'https://manpages.debian.org/{path}'
|
| 29 |
+
|
| 30 |
+
# General substitutions.
|
| 31 |
+
project = 'Python'
|
| 32 |
+
copyright = '2001-%s, Python Software Foundation' % time.strftime('%Y')
|
| 33 |
+
|
| 34 |
+
# We look for the Include/patchlevel.h file in the current Python source tree
|
| 35 |
+
# and replace the values accordingly.
|
| 36 |
+
import patchlevel
|
| 37 |
+
version, release = patchlevel.get_version_info()
|
| 38 |
+
|
| 39 |
+
# There are two options for replacing |today|: either, you set today to some
|
| 40 |
+
# non-false value, then it is used:
|
| 41 |
+
today = ''
|
| 42 |
+
# Else, today_fmt is used as the format for a strftime call.
|
| 43 |
+
today_fmt = '%B %d, %Y'
|
| 44 |
+
|
| 45 |
+
# By default, highlight as Python 3.
|
| 46 |
+
highlight_language = 'python3'
|
| 47 |
+
|
| 48 |
+
# Minimum version of sphinx required
|
| 49 |
+
needs_sphinx = '1.8'
|
| 50 |
+
|
| 51 |
+
# Ignore any .rst files in the venv/ directory.
|
| 52 |
+
exclude_patterns = ['venv/*', 'README.rst']
|
| 53 |
+
venvdir = os.getenv('VENVDIR')
|
| 54 |
+
if venvdir is not None:
|
| 55 |
+
exclude_patterns.append(venvdir + '/*')
|
| 56 |
+
|
| 57 |
+
# Disable Docutils smartquotes for several translations
|
| 58 |
+
smartquotes_excludes = {
|
| 59 |
+
'languages': ['ja', 'fr', 'zh_TW', 'zh_CN'], 'builders': ['man', 'text'],
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
# Avoid a warning with Sphinx >= 2.0
|
| 63 |
+
master_doc = 'contents'
|
| 64 |
+
|
| 65 |
+
# Options for HTML output
|
| 66 |
+
# -----------------------
|
| 67 |
+
|
| 68 |
+
# Use our custom theme.
|
| 69 |
+
html_theme = 'python_docs_theme'
|
| 70 |
+
html_theme_path = ['tools']
|
| 71 |
+
html_theme_options = {
|
| 72 |
+
'collapsiblesidebar': True,
|
| 73 |
+
'issues_url': 'https://docs.python.org/3/bugs.html',
|
| 74 |
+
'root_include_title': False # We use the version switcher instead.
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
# Short title used e.g. for <title> HTML tags.
|
| 78 |
+
html_short_title = '%s Documentation' % release
|
| 79 |
+
|
| 80 |
+
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
| 81 |
+
# using the given strftime format.
|
| 82 |
+
html_last_updated_fmt = '%b %d, %Y'
|
| 83 |
+
|
| 84 |
+
# Path to find HTML templates.
|
| 85 |
+
templates_path = ['tools/templates']
|
| 86 |
+
|
| 87 |
+
# Custom sidebar templates, filenames relative to this file.
|
| 88 |
+
html_sidebars = {
|
| 89 |
+
# Defaults taken from http://www.sphinx-doc.org/en/stable/config.html#confval-html_sidebars
|
| 90 |
+
# Removes the quick search block
|
| 91 |
+
'**': ['localtoc.html', 'relations.html', 'customsourcelink.html'],
|
| 92 |
+
'index': ['indexsidebar.html'],
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
# Additional templates that should be rendered to pages.
|
| 96 |
+
html_additional_pages = {
|
| 97 |
+
'download': 'download.html',
|
| 98 |
+
'index': 'indexcontent.html',
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
# Output an OpenSearch description file.
|
| 102 |
+
html_use_opensearch = 'https://docs.python.org/' + version
|
| 103 |
+
|
| 104 |
+
# Additional static files.
|
| 105 |
+
html_static_path = ['tools/static']
|
| 106 |
+
|
| 107 |
+
# Output file base name for HTML help builder.
|
| 108 |
+
htmlhelp_basename = 'python' + release.replace('.', '')
|
| 109 |
+
|
| 110 |
+
# Split the index
|
| 111 |
+
html_split_index = True
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
# Options for LaTeX output
|
| 115 |
+
# ------------------------
|
| 116 |
+
|
| 117 |
+
latex_engine = 'xelatex'
|
| 118 |
+
|
| 119 |
+
# Get LaTeX to handle Unicode correctly
|
| 120 |
+
latex_elements = {
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
# Additional stuff for the LaTeX preamble.
|
| 124 |
+
latex_elements['preamble'] = r'''
|
| 125 |
+
\authoraddress{
|
| 126 |
+
\sphinxstrong{Python Software Foundation}\\
|
| 127 |
+
Email: \sphinxemail{docs@python.org}
|
| 128 |
+
}
|
| 129 |
+
\let\Verbatim=\OriginalVerbatim
|
| 130 |
+
\let\endVerbatim=\endOriginalVerbatim
|
| 131 |
+
\setcounter{tocdepth}{2}
|
| 132 |
+
'''
|
| 133 |
+
|
| 134 |
+
# The paper size ('letter' or 'a4').
|
| 135 |
+
latex_elements['papersize'] = 'a4'
|
| 136 |
+
|
| 137 |
+
# The font size ('10pt', '11pt' or '12pt').
|
| 138 |
+
latex_elements['pointsize'] = '10pt'
|
| 139 |
+
|
| 140 |
+
# Grouping the document tree into LaTeX files. List of tuples
|
| 141 |
+
# (source start file, target name, title, author, document class [howto/manual]).
|
| 142 |
+
_stdauthor = r'Guido van Rossum\\and the Python development team'
|
| 143 |
+
latex_documents = [
|
| 144 |
+
('c-api/index', 'c-api.tex',
|
| 145 |
+
'The Python/C API', _stdauthor, 'manual'),
|
| 146 |
+
('distributing/index', 'distributing.tex',
|
| 147 |
+
'Distributing Python Modules', _stdauthor, 'manual'),
|
| 148 |
+
('extending/index', 'extending.tex',
|
| 149 |
+
'Extending and Embedding Python', _stdauthor, 'manual'),
|
| 150 |
+
('installing/index', 'installing.tex',
|
| 151 |
+
'Installing Python Modules', _stdauthor, 'manual'),
|
| 152 |
+
('library/index', 'library.tex',
|
| 153 |
+
'The Python Library Reference', _stdauthor, 'manual'),
|
| 154 |
+
('reference/index', 'reference.tex',
|
| 155 |
+
'The Python Language Reference', _stdauthor, 'manual'),
|
| 156 |
+
('tutorial/index', 'tutorial.tex',
|
| 157 |
+
'Python Tutorial', _stdauthor, 'manual'),
|
| 158 |
+
('using/index', 'using.tex',
|
| 159 |
+
'Python Setup and Usage', _stdauthor, 'manual'),
|
| 160 |
+
('faq/index', 'faq.tex',
|
| 161 |
+
'Python Frequently Asked Questions', _stdauthor, 'manual'),
|
| 162 |
+
('whatsnew/' + version, 'whatsnew.tex',
|
| 163 |
+
'What\'s New in Python', 'A. M. Kuchling', 'howto'),
|
| 164 |
+
]
|
| 165 |
+
# Collect all HOWTOs individually
|
| 166 |
+
latex_documents.extend(('howto/' + fn[:-4], 'howto-' + fn[:-4] + '.tex',
|
| 167 |
+
'', _stdauthor, 'howto')
|
| 168 |
+
for fn in os.listdir('howto')
|
| 169 |
+
if fn.endswith('.rst') and fn != 'index.rst')
|
| 170 |
+
|
| 171 |
+
# Documents to append as an appendix to all manuals.
|
| 172 |
+
latex_appendices = ['glossary', 'about', 'license', 'copyright']
|
| 173 |
+
|
| 174 |
+
# Options for Epub output
|
| 175 |
+
# -----------------------
|
| 176 |
+
|
| 177 |
+
epub_author = 'Python Documentation Authors'
|
| 178 |
+
epub_publisher = 'Python Software Foundation'
|
| 179 |
+
|
| 180 |
+
# Options for the coverage checker
|
| 181 |
+
# --------------------------------
|
| 182 |
+
|
| 183 |
+
# The coverage checker will ignore all modules/functions/classes whose names
|
| 184 |
+
# match any of the following regexes (using re.match).
|
| 185 |
+
coverage_ignore_modules = [
|
| 186 |
+
r'[T|t][k|K]',
|
| 187 |
+
r'Tix',
|
| 188 |
+
r'distutils.*',
|
| 189 |
+
]
|
| 190 |
+
|
| 191 |
+
coverage_ignore_functions = [
|
| 192 |
+
'test($|_)',
|
| 193 |
+
]
|
| 194 |
+
|
| 195 |
+
coverage_ignore_classes = [
|
| 196 |
+
]
|
| 197 |
+
|
| 198 |
+
# Glob patterns for C source files for C API coverage, relative to this directory.
|
| 199 |
+
coverage_c_path = [
|
| 200 |
+
'../Include/*.h',
|
| 201 |
+
]
|
| 202 |
+
|
| 203 |
+
# Regexes to find C items in the source files.
|
| 204 |
+
coverage_c_regexes = {
|
| 205 |
+
'cfunction': (r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)'),
|
| 206 |
+
'data': (r'^PyAPI_DATA\(.*\)\s+([^_][\w_]+)'),
|
| 207 |
+
'macro': (r'^#define ([^_][\w_]+)\(.*\)[\s|\\]'),
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
# The coverage checker will ignore all C items whose names match these regexes
|
| 211 |
+
# (using re.match) -- the keys must be the same as in coverage_c_regexes.
|
| 212 |
+
coverage_ignore_c_items = {
|
| 213 |
+
# 'cfunction': [...]
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
# Options for the link checker
|
| 218 |
+
# ----------------------------
|
| 219 |
+
|
| 220 |
+
# Ignore certain URLs.
|
| 221 |
+
linkcheck_ignore = [r'https://bugs.python.org/(issue)?\d+',
|
| 222 |
+
# Ignore PEPs for now, they all have permanent redirects.
|
| 223 |
+
r'http://www.python.org/dev/peps/pep-\d+']
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
# Options for extensions
|
| 227 |
+
# ----------------------
|
| 228 |
+
|
| 229 |
+
# Relative filename of the reference count data file.
|
| 230 |
+
refcount_file = 'data/refcounts.dat'
|
cpython_2/environment/repo/Doc/contents.rst
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 2 |
+
Python Documentation contents
|
| 3 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 4 |
+
|
| 5 |
+
.. toctree::
|
| 6 |
+
|
| 7 |
+
whatsnew/index.rst
|
| 8 |
+
tutorial/index.rst
|
| 9 |
+
using/index.rst
|
| 10 |
+
reference/index.rst
|
| 11 |
+
library/index.rst
|
| 12 |
+
extending/index.rst
|
| 13 |
+
c-api/index.rst
|
| 14 |
+
distributing/index.rst
|
| 15 |
+
installing/index.rst
|
| 16 |
+
howto/index.rst
|
| 17 |
+
faq/index.rst
|
| 18 |
+
glossary.rst
|
| 19 |
+
|
| 20 |
+
about.rst
|
| 21 |
+
bugs.rst
|
| 22 |
+
copyright.rst
|
| 23 |
+
license.rst
|
| 24 |
+
|
| 25 |
+
.. to include legacy packaging docs in build
|
| 26 |
+
|
| 27 |
+
.. toctree::
|
| 28 |
+
:hidden:
|
| 29 |
+
|
| 30 |
+
distutils/index.rst
|
| 31 |
+
install/index.rst
|
cpython_2/environment/repo/Doc/copyright.rst
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*********
|
| 2 |
+
Copyright
|
| 3 |
+
*********
|
| 4 |
+
|
| 5 |
+
Python and this documentation is:
|
| 6 |
+
|
| 7 |
+
Copyright © 2001-2020 Python Software Foundation. All rights reserved.
|
| 8 |
+
|
| 9 |
+
Copyright © 2000 BeOpen.com. All rights reserved.
|
| 10 |
+
|
| 11 |
+
Copyright © 1995-2000 Corporation for National Research Initiatives. All rights
|
| 12 |
+
reserved.
|
| 13 |
+
|
| 14 |
+
Copyright © 1991-1995 Stichting Mathematisch Centrum. All rights reserved.
|
| 15 |
+
|
| 16 |
+
-------
|
| 17 |
+
|
| 18 |
+
See :ref:`history-and-license` for complete license and permissions information.
|
| 19 |
+
|
cpython_2/environment/repo/Doc/data/refcounts.dat
ADDED
|
@@ -0,0 +1,3085 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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':' [comment]
|
| 5 |
+
# If the param name slot is empty, that line corresponds to the function's
|
| 6 |
+
# return value, otherwise it's the type of the named parameter.
|
| 7 |
+
|
| 8 |
+
# The first line of a function block gives type/refcount information for the
|
| 9 |
+
# function's return value. Successive lines with the same function name
|
| 10 |
+
# correspond to the function's parameter list and appear in the order the
|
| 11 |
+
# parameters appear in the function's prototype.
|
| 12 |
+
|
| 13 |
+
# For readability, each function's lines are surrounded by a blank line.
|
| 14 |
+
# The blocks are sorted alphabetically by function name.
|
| 15 |
+
|
| 16 |
+
# Refcount behavior is given for all PyObject* types: 0 (no change), +1
|
| 17 |
+
# (increment) and -1 (decrement). A blank refcount field indicates the
|
| 18 |
+
# parameter or function value is not a PyObject* and is therefore not
|
| 19 |
+
# subject to reference counting. A special case for the value "null"
|
| 20 |
+
# (without quotes) is used for functions which return a PyObject* type but
|
| 21 |
+
# always return NULL. This is used by some of the PyErr_*() functions, in
|
| 22 |
+
# particular.
|
| 23 |
+
|
| 24 |
+
# XXX NOTE: the 0/+1/-1 refcount information for arguments is
|
| 25 |
+
# confusing! Much more useful would be to indicate whether the
|
| 26 |
+
# function "steals" a reference to the argument or not. Take for
|
| 27 |
+
# example PyList_SetItem(list, i, item). This lists as a 0 change for
|
| 28 |
+
# both the list and the item arguments. However, in fact it steals a
|
| 29 |
+
# reference to the item argument!
|
| 30 |
+
|
| 31 |
+
# The parameter names are as they appear in the API manual, not the source
|
| 32 |
+
# code.
|
| 33 |
+
|
| 34 |
+
PyAnySet_Check:int:::
|
| 35 |
+
PyAnySet_Check:PyObject*:p:0:
|
| 36 |
+
|
| 37 |
+
PyAnySet_CheckExact:int:::
|
| 38 |
+
PyAnySet_CheckExact:PyObject*:p:0:
|
| 39 |
+
|
| 40 |
+
PyBool_Check:int:::
|
| 41 |
+
PyBool_Check:PyObject*:o:0:
|
| 42 |
+
|
| 43 |
+
PyBool_FromLong:PyObject*::+1:
|
| 44 |
+
PyBool_FromLong:long:v::
|
| 45 |
+
|
| 46 |
+
PyBuffer_FillContiguousStrides:void:::
|
| 47 |
+
PyBuffer_FillContiguousStrides:int:ndims::
|
| 48 |
+
PyBuffer_FillContiguousStrides:Py_ssize_t*:shape::
|
| 49 |
+
PyBuffer_FillContiguousStrides:Py_ssize_t*:strides::
|
| 50 |
+
PyBuffer_FillContiguousStrides:int:itemsize::
|
| 51 |
+
PyBuffer_FillContiguousStrides:char:order::
|
| 52 |
+
|
| 53 |
+
PyBuffer_FillInfo:int:::
|
| 54 |
+
PyBuffer_FillInfo:Py_buffer*:view::
|
| 55 |
+
PyBuffer_FillInfo:PyObject*:exporter:0:
|
| 56 |
+
PyBuffer_FillInfo:void*:buf::
|
| 57 |
+
PyBuffer_FillInfo:Py_ssize_t:len::
|
| 58 |
+
PyBuffer_FillInfo:int:readonly::
|
| 59 |
+
PyBuffer_FillInfo:int:flags::
|
| 60 |
+
|
| 61 |
+
PyBuffer_IsContiguous:int:::
|
| 62 |
+
PyBuffer_IsContiguous:Py_buffer*:view::
|
| 63 |
+
PyBuffer_IsContiguous:char:order::
|
| 64 |
+
|
| 65 |
+
PyBuffer_Release:void:::
|
| 66 |
+
PyBuffer_Release:Py_buffer*:view::
|
| 67 |
+
|
| 68 |
+
PyBuffer_ToContiguous:int:::
|
| 69 |
+
PyBuffer_ToContiguous:void*:buf::
|
| 70 |
+
PyBuffer_ToContiguous:Py_buffer*:src::
|
| 71 |
+
PyBuffer_ToContiguous:Py_ssize_t:len::
|
| 72 |
+
PyBuffer_ToContiguous:char:order::
|
| 73 |
+
|
| 74 |
+
PyByteArray_AS_STRING:char*:::
|
| 75 |
+
PyByteArray_AS_STRING:PyObject*:bytearray:0:
|
| 76 |
+
|
| 77 |
+
PyByteArray_AsString:char*:::
|
| 78 |
+
PyByteArray_AsString:PyObject*:bytearray:0:
|
| 79 |
+
|
| 80 |
+
PyByteArray_Check:int:::
|
| 81 |
+
PyByteArray_Check:PyObject*:o:0:
|
| 82 |
+
|
| 83 |
+
PyByteArray_CheckExact:int:::
|
| 84 |
+
PyByteArray_CheckExact:PyObject*:o:0:
|
| 85 |
+
|
| 86 |
+
PyByteArray_Concat:PyObject*::+1:
|
| 87 |
+
PyByteArray_Concat:PyObject*:a:0:
|
| 88 |
+
PyByteArray_Concat:PyObject*:b:0:
|
| 89 |
+
|
| 90 |
+
PyByteArray_FromObject:PyObject*::+1:
|
| 91 |
+
PyByteArray_FromObject:PyObject*:o:0:
|
| 92 |
+
|
| 93 |
+
PyByteArray_FromStringAndSize:PyObject*::+1:
|
| 94 |
+
PyByteArray_FromStringAndSize:const char*:string::
|
| 95 |
+
PyByteArray_FromStringAndSize:Py_ssize_t:len::
|
| 96 |
+
|
| 97 |
+
PyByteArray_GET_SIZE:Py_ssize_t:::
|
| 98 |
+
PyByteArray_GET_SIZE:PyObject*:bytearray:0:
|
| 99 |
+
|
| 100 |
+
PyByteArray_Resize:int:::
|
| 101 |
+
PyByteArray_Resize:PyObject*:bytearray:0:
|
| 102 |
+
PyByteArray_Resize:Py_ssize_t:len::
|
| 103 |
+
|
| 104 |
+
PyByteArray_Size:Py_ssize_t:::
|
| 105 |
+
PyByteArray_Size:PyObject*:bytearray:0:
|
| 106 |
+
|
| 107 |
+
PyBytes_AS_STRING:char*:::
|
| 108 |
+
PyBytes_AS_STRING:PyObject*:string:0:
|
| 109 |
+
|
| 110 |
+
PyBytes_AsString:char*:::
|
| 111 |
+
PyBytes_AsString:PyObject*:o:0:
|
| 112 |
+
|
| 113 |
+
PyBytes_AsStringAndSize:int:::
|
| 114 |
+
PyBytes_AsStringAndSize:PyObject*:obj:0:
|
| 115 |
+
PyBytes_AsStringAndSize:char**:buffer::
|
| 116 |
+
PyBytes_AsStringAndSize:Py_ssize_t*:length::
|
| 117 |
+
|
| 118 |
+
PyBytes_Check:int:::
|
| 119 |
+
PyBytes_Check:PyObject*:o:0:
|
| 120 |
+
|
| 121 |
+
PyBytes_CheckExact:int:::
|
| 122 |
+
PyBytes_CheckExact:PyObject*:o:0:
|
| 123 |
+
|
| 124 |
+
PyBytes_Concat:void:::
|
| 125 |
+
PyBytes_Concat:PyObject**:bytes:0:
|
| 126 |
+
PyBytes_Concat:PyObject*:newpart:0:
|
| 127 |
+
|
| 128 |
+
PyBytes_ConcatAndDel:void:::
|
| 129 |
+
PyBytes_ConcatAndDel:PyObject**:bytes:0:
|
| 130 |
+
PyBytes_ConcatAndDel:PyObject*:newpart:-1:
|
| 131 |
+
|
| 132 |
+
PyBytes_FromString:PyObject*::+1:
|
| 133 |
+
PyBytes_FromString:const char*:v::
|
| 134 |
+
|
| 135 |
+
PyBytes_FromStringAndSize:PyObject*::+1:
|
| 136 |
+
PyBytes_FromStringAndSize:const char*:v::
|
| 137 |
+
PyBytes_FromStringAndSize:Py_ssize_t:len::
|
| 138 |
+
|
| 139 |
+
PyBytes_FromFormat:PyObject*::+1:
|
| 140 |
+
PyBytes_FromFormat:const char*:format::
|
| 141 |
+
PyBytes_FromFormat::...::
|
| 142 |
+
|
| 143 |
+
PyBytes_FromFormatV:PyObject*::+1:
|
| 144 |
+
PyBytes_FromFormatV:const char*:format::
|
| 145 |
+
PyBytes_FromFormatV:va_list:vargs::
|
| 146 |
+
|
| 147 |
+
PyBytes_FromObject:PyObject*::+1:
|
| 148 |
+
PyBytes_FromObject:PyObject*:o:0:
|
| 149 |
+
|
| 150 |
+
PyBytes_GET_SIZE:Py_ssize_t:::
|
| 151 |
+
PyBytes_GET_SIZE:PyObject*:o:0:
|
| 152 |
+
|
| 153 |
+
PyBytes_Size:Py_ssize_t:::
|
| 154 |
+
PyBytes_Size:PyObject*:o:0:
|
| 155 |
+
|
| 156 |
+
PyCapsule_CheckExact:int:::
|
| 157 |
+
PyCapsule_CheckExact:PyObject*:p:0:
|
| 158 |
+
|
| 159 |
+
PyCapsule_GetContext:void *:::
|
| 160 |
+
PyCapsule_GetContext:PyObject*:self:0:
|
| 161 |
+
|
| 162 |
+
PyCapsule_GetDestructor:void (*)(PyObject *):::
|
| 163 |
+
PyCapsule_GetDestructor:PyObject*:self:0:
|
| 164 |
+
|
| 165 |
+
PyCapsule_GetName:const char *:::
|
| 166 |
+
PyCapsule_GetName:PyObject*:self:0:
|
| 167 |
+
|
| 168 |
+
PyCapsule_GetPointer:void*:::
|
| 169 |
+
PyCapsule_GetPointer:PyObject*:self:0:
|
| 170 |
+
PyCapsule_GetPointer:const char *:name::
|
| 171 |
+
|
| 172 |
+
PyCapsule_Import:void *:::
|
| 173 |
+
PyCapsule_Import:const char *:name::
|
| 174 |
+
PyCapsule_Import:int:no_block::
|
| 175 |
+
|
| 176 |
+
PyCapsule_IsValid:int:::
|
| 177 |
+
PyCapsule_IsValid:PyObject*:capsule:0:
|
| 178 |
+
PyCapsule_IsValid:const char*:name::
|
| 179 |
+
|
| 180 |
+
PyCapsule_New:PyObject*::+1:
|
| 181 |
+
PyCapsule_New:void*:pointer::
|
| 182 |
+
PyCapsule_New:const char *:name::
|
| 183 |
+
PyCapsule_New::void (* destructor)(PyObject* )::
|
| 184 |
+
|
| 185 |
+
PyCapsule_SetContext:int:::
|
| 186 |
+
PyCapsule_SetContext:PyObject*:self:0:
|
| 187 |
+
PyCapsule_SetContext:void *:context::
|
| 188 |
+
|
| 189 |
+
PyCapsule_SetDestructor:int:::
|
| 190 |
+
PyCapsule_SetDestructor:PyObject*:self:0:
|
| 191 |
+
PyCapsule_SetDestructor:void (*)(PyObject *):destructor::
|
| 192 |
+
|
| 193 |
+
PyCapsule_SetName:int:::
|
| 194 |
+
PyCapsule_SetName:PyObject*:self:0:
|
| 195 |
+
PyCapsule_SetName:const char *:name::
|
| 196 |
+
|
| 197 |
+
PyCapsule_SetPointer:int:::
|
| 198 |
+
PyCapsule_SetPointer:PyObject*:self:0:
|
| 199 |
+
PyCapsule_SetPointer:void*:pointer::
|
| 200 |
+
|
| 201 |
+
PyCell_Check:int:::
|
| 202 |
+
PyCell_Check::ob::
|
| 203 |
+
|
| 204 |
+
PyCell_New:PyObject*::+1:
|
| 205 |
+
PyCell_New:PyObject*:ob:0:
|
| 206 |
+
|
| 207 |
+
PyCell_GET:PyObject*::0:
|
| 208 |
+
PyCell_GET:PyObject*:ob:0:
|
| 209 |
+
|
| 210 |
+
PyCell_Get:PyObject*::+1:
|
| 211 |
+
PyCell_Get:PyObject*:cell:0:
|
| 212 |
+
|
| 213 |
+
PyCell_SET:void:::
|
| 214 |
+
PyCell_SET:PyObject*:cell:0:
|
| 215 |
+
PyCell_SET:PyObject*:value:0:
|
| 216 |
+
|
| 217 |
+
PyCell_Set:int:::
|
| 218 |
+
PyCell_Set:PyObject*:cell:0:
|
| 219 |
+
PyCell_Set:PyObject*:value:0:
|
| 220 |
+
|
| 221 |
+
PyCallIter_Check:int:::
|
| 222 |
+
PyCallIter_Check::op::
|
| 223 |
+
|
| 224 |
+
PyCallIter_New:PyObject*::+1:
|
| 225 |
+
PyCallIter_New:PyObject*:callable:+1:
|
| 226 |
+
PyCallIter_New:PyObject*:sentinel:+1:
|
| 227 |
+
|
| 228 |
+
PyCallable_Check:int:::
|
| 229 |
+
PyCallable_Check:PyObject*:o:0:
|
| 230 |
+
|
| 231 |
+
PyCode_Check:int:::
|
| 232 |
+
PyCode_Check:PyObject*:co:0:
|
| 233 |
+
|
| 234 |
+
PyCode_GetNumFree:int:::
|
| 235 |
+
PyCode_GetNumFree:PyCodeObject*:co:0:
|
| 236 |
+
|
| 237 |
+
PyCode_NewWithPosOnlyArgs:PyCodeObject*::+1:
|
| 238 |
+
PyCode_NewWithPosOnlyArgs:int:argcount::
|
| 239 |
+
PyCode_NewWithPosOnlyArgs:int:posonlyargcount::
|
| 240 |
+
PyCode_NewWithPosOnlyArgs:int:kwonlyargcount::
|
| 241 |
+
PyCode_NewWithPosOnlyArgs:int:nlocals::
|
| 242 |
+
PyCode_NewWithPosOnlyArgs:int:stacksize::
|
| 243 |
+
PyCode_NewWithPosOnlyArgs:int:flags::
|
| 244 |
+
PyCode_NewWithPosOnlyArgs:PyObject*:code:0:
|
| 245 |
+
PyCode_NewWithPosOnlyArgs:PyObject*:consts:0:
|
| 246 |
+
PyCode_NewWithPosOnlyArgs:PyObject*:names:0:
|
| 247 |
+
PyCode_NewWithPosOnlyArgs:PyObject*:varnames:0:
|
| 248 |
+
PyCode_NewWithPosOnlyArgs:PyObject*:freevars:0:
|
| 249 |
+
PyCode_NewWithPosOnlyArgs:PyObject*:cellvars:0:
|
| 250 |
+
PyCode_NewWithPosOnlyArgs:PyObject*:filename:0:
|
| 251 |
+
PyCode_NewWithPosOnlyArgs:PyObject*:name:0:
|
| 252 |
+
PyCode_NewWithPosOnlyArgs:int:firstlineno::
|
| 253 |
+
PyCode_NewWithPosOnlyArgs:PyObject*:lnotab:0:
|
| 254 |
+
|
| 255 |
+
PyCode_New:PyCodeObject*::+1:
|
| 256 |
+
PyCode_New:int:argcount::
|
| 257 |
+
PyCode_New:int:kwonlyargcount::
|
| 258 |
+
PyCode_New:int:nlocals::
|
| 259 |
+
PyCode_New:int:stacksize::
|
| 260 |
+
PyCode_New:int:flags::
|
| 261 |
+
PyCode_New:PyObject*:code:0:
|
| 262 |
+
PyCode_New:PyObject*:consts:0:
|
| 263 |
+
PyCode_New:PyObject*:names:0:
|
| 264 |
+
PyCode_New:PyObject*:varnames:0:
|
| 265 |
+
PyCode_New:PyObject*:freevars:0:
|
| 266 |
+
PyCode_New:PyObject*:cellvars:0:
|
| 267 |
+
PyCode_New:PyObject*:filename:0:
|
| 268 |
+
PyCode_New:PyObject*:name:0:
|
| 269 |
+
PyCode_New:int:firstlineno::
|
| 270 |
+
PyCode_New:PyObject*:lnotab:0:
|
| 271 |
+
|
| 272 |
+
PyCode_NewEmpty:PyCodeObject*::+1:
|
| 273 |
+
PyCode_NewEmpty:const char*:filename::
|
| 274 |
+
PyCode_NewEmpty:const char*:funcname::
|
| 275 |
+
PyCode_NewEmpty:int:firstlineno::
|
| 276 |
+
|
| 277 |
+
PyCodec_Register:int:::
|
| 278 |
+
PyCodec_Register:PyObject*:search_function:+1:
|
| 279 |
+
|
| 280 |
+
PyCodec_KnownEncoding:int:::
|
| 281 |
+
PyCodec_KnownEncoding:const char*:encoding::
|
| 282 |
+
|
| 283 |
+
PyCodec_Encode:PyObject*::+1:
|
| 284 |
+
PyCodec_Encode:PyObject*:object:0:
|
| 285 |
+
PyCodec_Encode:const char*:encoding::
|
| 286 |
+
PyCodec_Encode:const char*:errors::
|
| 287 |
+
|
| 288 |
+
PyCodec_Decode:PyObject*::+1:
|
| 289 |
+
PyCodec_Decode:PyObject*:object:0:
|
| 290 |
+
PyCodec_Decode:const char*:encoding::
|
| 291 |
+
PyCodec_Decode:const char*:errors::
|
| 292 |
+
|
| 293 |
+
PyCodec_Encoder:PyObject*::+1:
|
| 294 |
+
PyCodec_Encoder:const char*:encoding::
|
| 295 |
+
|
| 296 |
+
PyCodec_Decoder:PyObject*::+1:
|
| 297 |
+
PyCodec_Decoder:const char*:encoding::
|
| 298 |
+
|
| 299 |
+
PyCodec_IncrementalEncoder:PyObject*::+1:
|
| 300 |
+
PyCodec_IncrementalEncoder:const char*:encoding::
|
| 301 |
+
PyCodec_IncrementalEncoder:const char*:errors::
|
| 302 |
+
|
| 303 |
+
PyCodec_IncrementalDecoder:PyObject*::+1:
|
| 304 |
+
PyCodec_IncrementalDecoder:const char*:encoding::
|
| 305 |
+
PyCodec_IncrementalDecoder:const char*:errors::
|
| 306 |
+
|
| 307 |
+
PyCodec_StreamReader:PyObject*::+1:
|
| 308 |
+
PyCodec_StreamReader:const char*:encoding::
|
| 309 |
+
PyCodec_StreamReader:PyObject*:stream:0:
|
| 310 |
+
PyCodec_StreamReader:const char*:errors::
|
| 311 |
+
|
| 312 |
+
PyCodec_StreamWriter:PyObject*::+1:
|
| 313 |
+
PyCodec_StreamWriter:const char*:encoding::
|
| 314 |
+
PyCodec_StreamWriter:PyObject*:stream:0:
|
| 315 |
+
PyCodec_StreamWriter:const char*:errors::
|
| 316 |
+
|
| 317 |
+
PyCodec_RegisterError:int:::
|
| 318 |
+
PyCodec_RegisterError:const char*:name::
|
| 319 |
+
PyCodec_RegisterError:PyObject*:error:+1:
|
| 320 |
+
|
| 321 |
+
PyCodec_LookupError:PyObject*::+1:
|
| 322 |
+
PyCodec_LookupError:const char*:name::
|
| 323 |
+
|
| 324 |
+
PyCodec_StrictErrors:PyObject*::null:
|
| 325 |
+
PyCodec_StrictErrors:PyObject*:exc:0:
|
| 326 |
+
|
| 327 |
+
PyCodec_IgnoreErrors:PyObject*::+1:
|
| 328 |
+
PyCodec_IgnoreErrors:PyObject*:exc:0:
|
| 329 |
+
|
| 330 |
+
PyCodec_ReplaceErrors:PyObject*::+1:
|
| 331 |
+
PyCodec_ReplaceErrors:PyObject*:exc:0:
|
| 332 |
+
|
| 333 |
+
PyCodec_XMLCharRefReplaceErrors:PyObject*::+1:
|
| 334 |
+
PyCodec_XMLCharRefReplaceErrors:PyObject*:exc:0:
|
| 335 |
+
|
| 336 |
+
PyCodec_BackslashReplaceErrors:PyObject*::+1:
|
| 337 |
+
PyCodec_BackslashReplaceErrors:PyObject*:exc:0:
|
| 338 |
+
|
| 339 |
+
PyCodec_NameReplaceErrors:PyObject*::+1:
|
| 340 |
+
PyCodec_NameReplaceErrors:PyObject*:exc:0:
|
| 341 |
+
|
| 342 |
+
PyComplex_AsCComplex:Py_complex:::
|
| 343 |
+
PyComplex_AsCComplex:PyObject*:op:0:
|
| 344 |
+
|
| 345 |
+
PyComplex_Check:int:::
|
| 346 |
+
PyComplex_Check:PyObject*:p:0:
|
| 347 |
+
|
| 348 |
+
PyComplex_CheckExact:int:::
|
| 349 |
+
PyComplex_CheckExact:PyObject*:p:0:
|
| 350 |
+
|
| 351 |
+
PyComplex_FromCComplex:PyObject*::+1:
|
| 352 |
+
PyComplex_FromCComplex::Py_complex v::
|
| 353 |
+
|
| 354 |
+
PyComplex_FromDoubles:PyObject*::+1:
|
| 355 |
+
PyComplex_FromDoubles::double real::
|
| 356 |
+
PyComplex_FromDoubles::double imag::
|
| 357 |
+
|
| 358 |
+
PyComplex_ImagAsDouble:double:::
|
| 359 |
+
PyComplex_ImagAsDouble:PyObject*:op:0:
|
| 360 |
+
|
| 361 |
+
PyComplex_RealAsDouble:double:::
|
| 362 |
+
PyComplex_RealAsDouble:PyObject*:op:0:
|
| 363 |
+
|
| 364 |
+
PyContext_CheckExact:int:::
|
| 365 |
+
PyContext_CheckExact:PyObject*:o:0:
|
| 366 |
+
|
| 367 |
+
PyContext_ClearFreeList:int:::
|
| 368 |
+
|
| 369 |
+
PyContext_Copy:PyObject*::+1:
|
| 370 |
+
PyContext_Copy:PyObject*:ctx:0:
|
| 371 |
+
|
| 372 |
+
PyContext_CopyCurrent:PyObject*::+1:
|
| 373 |
+
|
| 374 |
+
PyContext_Enter:int:::
|
| 375 |
+
PyContext_Enter:PyObject*:ctx:+1:
|
| 376 |
+
|
| 377 |
+
PyContext_Exit:int:::
|
| 378 |
+
PyContext_Exit:PyObject*:ctx:-1:
|
| 379 |
+
|
| 380 |
+
PyContext_New:PyObject*::+1:
|
| 381 |
+
|
| 382 |
+
PyContextToken_CheckExact:int:::
|
| 383 |
+
PyContextToken_CheckExact:PyObject*:o:0:
|
| 384 |
+
|
| 385 |
+
PyContextVar_CheckExact:int:::
|
| 386 |
+
PyContextVar_CheckExact:PyObject*:o:0:
|
| 387 |
+
|
| 388 |
+
PyContextVar_Get:int:::
|
| 389 |
+
PyContextVar_Get:PyObject*:var:0:
|
| 390 |
+
PyContextVar_Get:PyObject*:default_value:0:
|
| 391 |
+
PyContextVar_Get:PyObject**:value:+1:???
|
| 392 |
+
|
| 393 |
+
PyContextVar_New:PyObject*::+1:
|
| 394 |
+
PyContextVar_New:const char*:name::
|
| 395 |
+
PyContextVar_New:PyObject*:def:+1:
|
| 396 |
+
|
| 397 |
+
PyContextVar_Set:PyObject*::+1:
|
| 398 |
+
PyContextVar_Set:PyObject*:var:0:
|
| 399 |
+
PyContextVar_Set:PyObject*:value:+1:
|
| 400 |
+
|
| 401 |
+
PyContextVar_Reset:int:::
|
| 402 |
+
PyContextVar_Reset:PyObject*:var:0:
|
| 403 |
+
PyContextVar_Reset:PyObject*:token:-1:
|
| 404 |
+
|
| 405 |
+
PyDate_Check:int:::
|
| 406 |
+
PyDate_Check:PyObject*:ob:0:
|
| 407 |
+
|
| 408 |
+
PyDate_CheckExact:int:::
|
| 409 |
+
PyDate_CheckExact:PyObject*:ob:0:
|
| 410 |
+
|
| 411 |
+
PyDate_FromDate:PyObject*::+1:
|
| 412 |
+
PyDate_FromDate:int:year::
|
| 413 |
+
PyDate_FromDate:int:month::
|
| 414 |
+
PyDate_FromDate:int:day::
|
| 415 |
+
|
| 416 |
+
PyDate_FromTimestamp:PyObject*::+1:
|
| 417 |
+
PyDate_FromTimestamp:PyObject*:args:0:
|
| 418 |
+
|
| 419 |
+
PyDateTime_Check:int:::
|
| 420 |
+
PyDateTime_Check:PyObject*:ob:0:
|
| 421 |
+
|
| 422 |
+
PyDateTime_CheckExact:int:::
|
| 423 |
+
PyDateTime_CheckExact:PyObject*:ob:0:
|
| 424 |
+
|
| 425 |
+
PyDateTime_FromDateAndTime:PyObject*::+1:
|
| 426 |
+
PyDateTime_FromDateAndTime:int:year::
|
| 427 |
+
PyDateTime_FromDateAndTime:int:month::
|
| 428 |
+
PyDateTime_FromDateAndTime:int:day::
|
| 429 |
+
PyDateTime_FromDateAndTime:int:hour::
|
| 430 |
+
PyDateTime_FromDateAndTime:int:minute::
|
| 431 |
+
PyDateTime_FromDateAndTime:int:second::
|
| 432 |
+
PyDateTime_FromDateAndTime:int:usecond::
|
| 433 |
+
|
| 434 |
+
PyDateTime_FromDateAndTimeAndFold:PyObject*::+1:
|
| 435 |
+
PyDateTime_FromDateAndTimeAndFold:int:year::
|
| 436 |
+
PyDateTime_FromDateAndTimeAndFold:int:month::
|
| 437 |
+
PyDateTime_FromDateAndTimeAndFold:int:day::
|
| 438 |
+
PyDateTime_FromDateAndTimeAndFold:int:hour::
|
| 439 |
+
PyDateTime_FromDateAndTimeAndFold:int:minute::
|
| 440 |
+
PyDateTime_FromDateAndTimeAndFold:int:second::
|
| 441 |
+
PyDateTime_FromDateAndTimeAndFold:int:usecond::
|
| 442 |
+
PyDateTime_FromDateAndTimeAndFold:int:fold::
|
| 443 |
+
|
| 444 |
+
PyDateTime_FromTimestamp:PyObject*::+1:
|
| 445 |
+
PyDateTime_FromTimestamp:PyObject*:args:0:
|
| 446 |
+
|
| 447 |
+
PyDelta_Check:int:::
|
| 448 |
+
PyDelta_Check:PyObject*:ob:0:
|
| 449 |
+
|
| 450 |
+
PyDelta_CheckExact:int:::
|
| 451 |
+
PyDelta_CheckExact:PyObject*:ob:0:
|
| 452 |
+
|
| 453 |
+
PyDelta_FromDSU:PyObject*::+1:
|
| 454 |
+
PyDelta_FromDSU:int:days::
|
| 455 |
+
PyDelta_FromDSU:int:seconds::
|
| 456 |
+
PyDelta_FromDSU:int:useconds::
|
| 457 |
+
|
| 458 |
+
PyTimeZone_FromOffset:PyObject*::+1:
|
| 459 |
+
PyTimeZone_FromOffset:PyObject*:offset:+1:Reference count not increased if offset is +00:00
|
| 460 |
+
|
| 461 |
+
PyTimeZone_FromOffsetAndName:PyObject*::+1:
|
| 462 |
+
PyTimeZone_FromOffsetAndName:PyObject*:offset:+1:Reference count not increased if offset is +00:00 and name == NULL
|
| 463 |
+
PyTimeZone_FromOffsetAndName:PyObject*:name:+1:
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
PyDescr_IsData:int:::
|
| 467 |
+
PyDescr_IsData:PyObject*:descr:0:
|
| 468 |
+
|
| 469 |
+
PyDescr_NewClassMethod:PyObject*::+1:
|
| 470 |
+
PyDescr_NewClassMethod:PyTypeObject*:type:+1:
|
| 471 |
+
PyDescr_NewClassMethod:PyMethodDef*:method::
|
| 472 |
+
|
| 473 |
+
PyDescr_NewGetSet:PyObject*::+1:
|
| 474 |
+
PyDescr_NewGetSet:PyTypeObject*:type:+1:
|
| 475 |
+
PyDescr_NewGetSet:PyGetSetDef*:getset::
|
| 476 |
+
|
| 477 |
+
PyDescr_NewMember:PyObject*::+1:
|
| 478 |
+
PyDescr_NewMember:PyTypeObject*:type:+1:
|
| 479 |
+
PyDescr_NewMember:PyMemberDef*:member::
|
| 480 |
+
|
| 481 |
+
PyDescr_NewMethod:PyObject*::+1:
|
| 482 |
+
PyDescr_NewMethod:PyTypeObject*:type:+1:
|
| 483 |
+
PyDescr_NewMethod:PyMethodDef*:meth::
|
| 484 |
+
|
| 485 |
+
PyDescr_NewWrapper:PyObject*::+1:
|
| 486 |
+
PyDescr_NewWrapper:PyTypeObject*:type:+1:
|
| 487 |
+
PyDescr_NewWrapper:struct wrapperbase*:base::
|
| 488 |
+
PyDescr_NewWrapper:void*:wrapped::
|
| 489 |
+
|
| 490 |
+
PyDict_Check:int:::
|
| 491 |
+
PyDict_Check:PyObject*:p:0:
|
| 492 |
+
|
| 493 |
+
PyDict_CheckExact:int:::
|
| 494 |
+
PyDict_CheckExact:PyObject*:p:0:
|
| 495 |
+
|
| 496 |
+
PyDict_Clear:void:::
|
| 497 |
+
PyDict_Clear:PyObject*:p:0:
|
| 498 |
+
|
| 499 |
+
PyDict_Contains:int:::
|
| 500 |
+
PyDict_Contains:PyObject*:p:0:
|
| 501 |
+
PyDict_Contains:PyObject*:key:0:
|
| 502 |
+
|
| 503 |
+
PyDict_DelItem:int:::
|
| 504 |
+
PyDict_DelItem:PyObject*:p:0:
|
| 505 |
+
PyDict_DelItem:PyObject*:key:0:
|
| 506 |
+
|
| 507 |
+
PyDict_DelItemString:int:::
|
| 508 |
+
PyDict_DelItemString:PyObject*:p:0:
|
| 509 |
+
PyDict_DelItemString:const char*:key::
|
| 510 |
+
|
| 511 |
+
PyDict_GetItem:PyObject*::0:
|
| 512 |
+
PyDict_GetItem:PyObject*:p:0:
|
| 513 |
+
PyDict_GetItem:PyObject*:key:0:
|
| 514 |
+
|
| 515 |
+
PyDict_GetItemWithError:PyObject*::0:0
|
| 516 |
+
PyDict_GetItemWithError:PyObject*:p:0:
|
| 517 |
+
PyDict_GetItemWithError:PyObject*:key:0:
|
| 518 |
+
|
| 519 |
+
PyDict_GetItemString:PyObject*::0:
|
| 520 |
+
PyDict_GetItemString:PyObject*:p:0:
|
| 521 |
+
PyDict_GetItemString:const char*:key::
|
| 522 |
+
|
| 523 |
+
PyDict_SetDefault:PyObject*::0:
|
| 524 |
+
PyDict_SetDefault:PyObject*:p:0:
|
| 525 |
+
PyDict_SetDefault:PyObject*:key:0:conditionally +1 if inserted into the dict
|
| 526 |
+
PyDict_SetDefault:PyObject*:default:0:conditionally +1 if inserted into the dict
|
| 527 |
+
|
| 528 |
+
PyDict_Items:PyObject*::+1:
|
| 529 |
+
PyDict_Items:PyObject*:p:0:
|
| 530 |
+
|
| 531 |
+
PyDict_Keys:PyObject*::+1:
|
| 532 |
+
PyDict_Keys:PyObject*:p:0:
|
| 533 |
+
|
| 534 |
+
PyDict_New:PyObject*::+1:
|
| 535 |
+
|
| 536 |
+
PyDict_Copy:PyObject*::+1:
|
| 537 |
+
PyDict_Copy:PyObject*:p:0:
|
| 538 |
+
|
| 539 |
+
PyDict_Merge:int:::
|
| 540 |
+
PyDict_Merge:PyObject*:a:0:
|
| 541 |
+
PyDict_Merge:PyObject*:b:0:
|
| 542 |
+
PyDict_Merge:int:override::
|
| 543 |
+
|
| 544 |
+
PyDict_MergeFromSeq2:int:::
|
| 545 |
+
PyDict_MergeFromSeq2:PyObject*:a:0:
|
| 546 |
+
PyDict_MergeFromSeq2:PyObject*:seq2:0:
|
| 547 |
+
PyDict_MergeFromSeq2:int:override::
|
| 548 |
+
|
| 549 |
+
PyDict_Next:int:::
|
| 550 |
+
PyDict_Next:PyObject*:p:0:
|
| 551 |
+
PyDict_Next:Py_ssize_t:ppos::
|
| 552 |
+
PyDict_Next:PyObject**:pkey:0:
|
| 553 |
+
PyDict_Next:PyObject**:pvalue:0:
|
| 554 |
+
|
| 555 |
+
PyDict_SetItem:int:::
|
| 556 |
+
PyDict_SetItem:PyObject*:p:0:
|
| 557 |
+
PyDict_SetItem:PyObject*:key:+1:
|
| 558 |
+
PyDict_SetItem:PyObject*:val:+1:
|
| 559 |
+
|
| 560 |
+
PyDict_SetItemString:int:::
|
| 561 |
+
PyDict_SetItemString:PyObject*:p:0:
|
| 562 |
+
PyDict_SetItemString:const char*:key::
|
| 563 |
+
PyDict_SetItemString:PyObject*:val:+1:
|
| 564 |
+
|
| 565 |
+
PyDict_Size:Py_ssize_t:::
|
| 566 |
+
PyDict_Size:PyObject*:p:0:
|
| 567 |
+
|
| 568 |
+
PyDict_Update:int:::
|
| 569 |
+
PyDict_Update:PyObject*:a:0:
|
| 570 |
+
PyDict_Update:PyObject*:b:0:
|
| 571 |
+
|
| 572 |
+
PyDict_Values:PyObject*::+1:
|
| 573 |
+
PyDict_Values:PyObject*:p:0:
|
| 574 |
+
|
| 575 |
+
PyDictProxy_New:PyObject*::+1:
|
| 576 |
+
PyDictProxy_New:PyObject*:dict:0:
|
| 577 |
+
|
| 578 |
+
PyErr_BadArgument:int:::
|
| 579 |
+
|
| 580 |
+
PyErr_BadInternalCall:void:::
|
| 581 |
+
|
| 582 |
+
PyErr_CheckSignals:int:::
|
| 583 |
+
|
| 584 |
+
PyErr_Clear:void:::
|
| 585 |
+
|
| 586 |
+
PyErr_ExceptionMatches:int:::
|
| 587 |
+
PyErr_ExceptionMatches:PyObject*:exc:0:
|
| 588 |
+
|
| 589 |
+
PyErr_Fetch:void:::
|
| 590 |
+
PyErr_Fetch:PyObject**:ptype:0:
|
| 591 |
+
PyErr_Fetch:PyObject**:pvalue:0:
|
| 592 |
+
PyErr_Fetch:PyObject**:ptraceback:0:
|
| 593 |
+
|
| 594 |
+
PyErr_Format:PyObject*::null:
|
| 595 |
+
PyErr_Format:PyObject*:exception:+1:
|
| 596 |
+
PyErr_Format:const char*:format::
|
| 597 |
+
PyErr_Format::...::
|
| 598 |
+
|
| 599 |
+
PyErr_FormatV:PyObject*::null:
|
| 600 |
+
PyErr_FormatV:PyObject*:exception:+1:
|
| 601 |
+
PyErr_FormatV:const char*:format::
|
| 602 |
+
PyErr_FormatV:va_list:vargs::
|
| 603 |
+
|
| 604 |
+
PyErr_GetExcInfo:void:::
|
| 605 |
+
PyErr_GetExcInfo:PyObject**:ptype:+1:
|
| 606 |
+
PyErr_GetExcInfo:PyObject**:pvalue:+1:
|
| 607 |
+
PyErr_GetExcInfo:PyObject**:ptraceback:+1:
|
| 608 |
+
|
| 609 |
+
PyErr_GivenExceptionMatches:int:::
|
| 610 |
+
PyErr_GivenExceptionMatches:PyObject*:given:0:
|
| 611 |
+
PyErr_GivenExceptionMatches:PyObject*:exc:0:
|
| 612 |
+
|
| 613 |
+
PyErr_NewException:PyObject*::+1:
|
| 614 |
+
PyErr_NewException:const char*:name::
|
| 615 |
+
PyErr_NewException:PyObject*:base:0:
|
| 616 |
+
PyErr_NewException:PyObject*:dict:0:
|
| 617 |
+
|
| 618 |
+
PyErr_NewExceptionWithDoc:PyObject*::+1:
|
| 619 |
+
PyErr_NewExceptionWithDoc:const char*:name::
|
| 620 |
+
PyErr_NewExceptionWithDoc:const char*:doc::
|
| 621 |
+
PyErr_NewExceptionWithDoc:PyObject*:base:0:
|
| 622 |
+
PyErr_NewExceptionWithDoc:PyObject*:dict:0:
|
| 623 |
+
|
| 624 |
+
PyErr_NoMemory:PyObject*::null:
|
| 625 |
+
|
| 626 |
+
PyErr_NormalizeException:void:::
|
| 627 |
+
PyErr_NormalizeException:PyObject**:exc::???
|
| 628 |
+
PyErr_NormalizeException:PyObject**:val::???
|
| 629 |
+
PyErr_NormalizeException:PyObject**:tb::???
|
| 630 |
+
|
| 631 |
+
PyErr_Occurred:PyObject*::0:
|
| 632 |
+
|
| 633 |
+
PyErr_Print:void:::
|
| 634 |
+
|
| 635 |
+
PyErr_PrintEx:void:::
|
| 636 |
+
PyErr_PrintEx:int:set_sys_last_vars::
|
| 637 |
+
|
| 638 |
+
PyErr_ResourceWarning:int:::
|
| 639 |
+
PyErr_ResourceWarning:PyObject*:source:0:
|
| 640 |
+
PyErr_ResourceWarning:Py_ssize_t:stack_level::
|
| 641 |
+
PyErr_ResourceWarning:const char*:format::
|
| 642 |
+
PyErr_ResourceWarning::...::
|
| 643 |
+
|
| 644 |
+
PyErr_Restore:void:::
|
| 645 |
+
PyErr_Restore:PyObject*:type:-1:
|
| 646 |
+
PyErr_Restore:PyObject*:value:-1:
|
| 647 |
+
PyErr_Restore:PyObject*:traceback:-1:
|
| 648 |
+
|
| 649 |
+
PyErr_SetExcFromWindowsErr:PyObject*::null:
|
| 650 |
+
PyErr_SetExcFromWindowsErr:PyObject*:type:+1:
|
| 651 |
+
PyErr_SetExcFromWindowsErr:int:ierr::
|
| 652 |
+
|
| 653 |
+
PyErr_SetExcFromWindowsErrWithFilename:PyObject*::null:
|
| 654 |
+
PyErr_SetExcFromWindowsErrWithFilename:PyObject*:type:+1:
|
| 655 |
+
PyErr_SetExcFromWindowsErrWithFilename:int:ierr::
|
| 656 |
+
PyErr_SetExcFromWindowsErrWithFilename:const char*:filename::
|
| 657 |
+
|
| 658 |
+
PyErr_SetExcFromWindowsErrWithFilenameObject:PyObject*::null:
|
| 659 |
+
PyErr_SetExcFromWindowsErrWithFilenameObject:PyObject*:type:+1:
|
| 660 |
+
PyErr_SetExcFromWindowsErrWithFilenameObject:int:ierr::
|
| 661 |
+
PyErr_SetExcFromWindowsErrWithFilenameObject:PyObject*:filename:+1:
|
| 662 |
+
|
| 663 |
+
PyErr_SetExcFromWindowsErrWithFilenameObjects:PyObject*::null:
|
| 664 |
+
PyErr_SetExcFromWindowsErrWithFilenameObjects:PyObject*:type:+1:
|
| 665 |
+
PyErr_SetExcFromWindowsErrWithFilenameObjects:int:ierr::
|
| 666 |
+
PyErr_SetExcFromWindowsErrWithFilenameObjects:PyObject*:filename:+1:
|
| 667 |
+
PyErr_SetExcFromWindowsErrWithFilenameObjects:PyObject*:filename2:+1:
|
| 668 |
+
|
| 669 |
+
PyErr_SetExcInfo:void:::
|
| 670 |
+
PyErr_SetExcInfo:PyObject*:type:0:
|
| 671 |
+
PyErr_SetExcInfo:PyObject*:value:0:
|
| 672 |
+
PyErr_SetExcInfo:PyObject*:traceback:0:
|
| 673 |
+
|
| 674 |
+
PyErr_SetFromErrno:PyObject*::null:
|
| 675 |
+
PyErr_SetFromErrno:PyObject*:type:+1:
|
| 676 |
+
|
| 677 |
+
PyErr_SetFromErrnoWithFilename:PyObject*::null:
|
| 678 |
+
PyErr_SetFromErrnoWithFilename:PyObject*:type:+1:
|
| 679 |
+
PyErr_SetFromErrnoWithFilename:const char*:filename::
|
| 680 |
+
|
| 681 |
+
PyErr_SetFromErrnoWithFilenameObject:PyObject*::null:
|
| 682 |
+
PyErr_SetFromErrnoWithFilenameObject:PyObject*:type:+1:
|
| 683 |
+
PyErr_SetFromErrnoWithFilenameObject:PyObject*:filenameObject:+1:
|
| 684 |
+
|
| 685 |
+
PyErr_SetFromErrnoWithFilenameObjects:PyObject*::null:
|
| 686 |
+
PyErr_SetFromErrnoWithFilenameObjects:PyObject*:type:+1:
|
| 687 |
+
PyErr_SetFromErrnoWithFilenameObjects:PyObject*:filenameObject:+1:
|
| 688 |
+
PyErr_SetFromErrnoWithFilenameObjects:PyObject*:filenameObject2:+1:
|
| 689 |
+
|
| 690 |
+
PyErr_SetFromWindowsErr:PyObject*::null:
|
| 691 |
+
PyErr_SetFromWindowsErr:int:ierr::
|
| 692 |
+
|
| 693 |
+
PyErr_SetFromWindowsErrWithFilename:PyObject*::null:
|
| 694 |
+
PyErr_SetFromWindowsErrWithFilename:int:ierr::
|
| 695 |
+
PyErr_SetFromWindowsErrWithFilename:const char*:filename::
|
| 696 |
+
|
| 697 |
+
PyErr_SetImportError:PyObject*::null:
|
| 698 |
+
PyErr_SetImportError:PyObject*:msg:+1:
|
| 699 |
+
PyErr_SetImportError:PyObject*:name:+1:
|
| 700 |
+
PyErr_SetImportError:PyObject*:path:+1:
|
| 701 |
+
|
| 702 |
+
PyErr_SetImportErrorSubclass:PyObject*::null:
|
| 703 |
+
PyErr_SetImportErrorSubclass:PyObject*:msg:+1:
|
| 704 |
+
PyErr_SetImportErrorSubclass:PyObject*:name:+1:
|
| 705 |
+
PyErr_SetImportErrorSubclass:PyObject*:path:+1:
|
| 706 |
+
|
| 707 |
+
PyErr_SetInterrupt:void:::
|
| 708 |
+
|
| 709 |
+
PyErr_SetNone:void:::
|
| 710 |
+
PyErr_SetNone:PyObject*:type:+1:
|
| 711 |
+
|
| 712 |
+
PyErr_SetObject:void:::
|
| 713 |
+
PyErr_SetObject:PyObject*:type:+1:
|
| 714 |
+
PyErr_SetObject:PyObject*:value:+1:
|
| 715 |
+
|
| 716 |
+
PyErr_SetString:void:::
|
| 717 |
+
PyErr_SetString:PyObject*:type:+1:
|
| 718 |
+
PyErr_SetString:const char*:message::
|
| 719 |
+
|
| 720 |
+
PyErr_SyntaxLocation:void:::
|
| 721 |
+
PyErr_SyntaxLocation:const char*:filename::
|
| 722 |
+
PyErr_SyntaxLocation:int:lineno::
|
| 723 |
+
|
| 724 |
+
PyErr_SyntaxLocationEx:void:::
|
| 725 |
+
PyErr_SyntaxLocationEx:const char*:filename::
|
| 726 |
+
PyErr_SyntaxLocationEx:int:lineno::
|
| 727 |
+
PyErr_SyntaxLocationEx:int:col_offset::
|
| 728 |
+
|
| 729 |
+
PyErr_SyntaxLocationObject:void:::
|
| 730 |
+
PyErr_SyntaxLocationObject:PyObject*:filename:+1:
|
| 731 |
+
PyErr_SyntaxLocationObject:int:lineno::
|
| 732 |
+
PyErr_SyntaxLocationObject:int:col_offset::
|
| 733 |
+
|
| 734 |
+
PyErr_WarnEx:int:::
|
| 735 |
+
PyErr_WarnEx:PyObject*:category:0:
|
| 736 |
+
PyErr_WarnEx:const char*:message::
|
| 737 |
+
PyErr_WarnEx:Py_ssize_t:stack_level::
|
| 738 |
+
|
| 739 |
+
PyErr_WarnExplicit:int:::
|
| 740 |
+
PyErr_WarnExplicit:PyObject*:category:0:
|
| 741 |
+
PyErr_WarnExplicit:const char*:message::
|
| 742 |
+
PyErr_WarnExplicit:const char*:filename::
|
| 743 |
+
PyErr_WarnExplicit:int:lineno::
|
| 744 |
+
PyErr_WarnExplicit:const char*:module::
|
| 745 |
+
PyErr_WarnExplicit:PyObject*:registry:0:
|
| 746 |
+
|
| 747 |
+
PyErr_WarnExplicitObject:int:::
|
| 748 |
+
PyErr_WarnExplicitObject:PyObject*:category:0:
|
| 749 |
+
PyErr_WarnExplicitObject:PyObject*:message:0:
|
| 750 |
+
PyErr_WarnExplicitObject:PyObject*:filename:0:
|
| 751 |
+
PyErr_WarnExplicitObject:int:lineno::
|
| 752 |
+
PyErr_WarnExplicitObject:PyObject*:module:0:
|
| 753 |
+
PyErr_WarnExplicitObject:PyObject*:registry:0:
|
| 754 |
+
|
| 755 |
+
PyErr_WarnFormat:int:::
|
| 756 |
+
PyErr_WarnFormat:PyObject*:category:0:
|
| 757 |
+
PyErr_WarnFormat:Py_ssize_t:stack_level::
|
| 758 |
+
PyErr_WarnFormat:const char*:format::
|
| 759 |
+
PyErr_WarnFormat::...::
|
| 760 |
+
|
| 761 |
+
PyErr_WriteUnraisable:void:::
|
| 762 |
+
PyErr_WriteUnraisable:PyObject*:obj:0:
|
| 763 |
+
|
| 764 |
+
PyEval_AcquireLock:void:::
|
| 765 |
+
|
| 766 |
+
PyEval_AcquireThread:void:::
|
| 767 |
+
PyEval_AcquireThread:PyThreadState*:tstate::
|
| 768 |
+
|
| 769 |
+
PyEval_GetBuiltins:PyObject*::0:
|
| 770 |
+
|
| 771 |
+
PyEval_GetLocals:PyObject*::0:
|
| 772 |
+
|
| 773 |
+
PyEval_GetGlobals:PyObject*::0:
|
| 774 |
+
|
| 775 |
+
PyEval_GetFrame:PyObject*::0:
|
| 776 |
+
|
| 777 |
+
PyEval_GetFuncDesc:const char*:::
|
| 778 |
+
PyEval_GetFuncDesc:PyObject*:func:0:
|
| 779 |
+
|
| 780 |
+
PyEval_GetFuncName:const char*:::
|
| 781 |
+
PyEval_GetFuncName:PyObject*:func:0:
|
| 782 |
+
|
| 783 |
+
PyEval_InitThreads:void:::
|
| 784 |
+
|
| 785 |
+
PyEval_ReleaseLock:void:::
|
| 786 |
+
|
| 787 |
+
PyEval_ReleaseThread:void:::
|
| 788 |
+
PyEval_ReleaseThread:PyThreadState*:tstate::
|
| 789 |
+
|
| 790 |
+
PyEval_RestoreThread:void:::
|
| 791 |
+
PyEval_RestoreThread:PyThreadState*:tstate::
|
| 792 |
+
|
| 793 |
+
PyEval_SaveThread:PyThreadState*:::
|
| 794 |
+
|
| 795 |
+
PyEval_SetProfile:void:::
|
| 796 |
+
PyEval_SetProfile:Py_tracefunc:func::
|
| 797 |
+
PyEval_SetProfile:PyObject*:obj:+1:
|
| 798 |
+
|
| 799 |
+
PyEval_SetTrace:void:::
|
| 800 |
+
PyEval_SetTrace:Py_tracefunc:func::
|
| 801 |
+
PyEval_SetTrace:PyObject*:obj:+1:
|
| 802 |
+
|
| 803 |
+
PyEval_EvalCode:PyObject*::+1:
|
| 804 |
+
PyEval_EvalCode:PyObject*:co:0:
|
| 805 |
+
PyEval_EvalCode:PyObject*:globals:0:
|
| 806 |
+
PyEval_EvalCode:PyObject*:locals:0:
|
| 807 |
+
|
| 808 |
+
PyEval_EvalCodeEx:PyObject*::+1:
|
| 809 |
+
PyEval_EvalCodeEx:PyObject*:co:0:
|
| 810 |
+
PyEval_EvalCodeEx:PyObject*:globals:0:
|
| 811 |
+
PyEval_EvalCodeEx:PyObject*:locals:0:
|
| 812 |
+
PyEval_EvalCodeEx:PyObject*const*:args::
|
| 813 |
+
PyEval_EvalCodeEx:int:argcount::
|
| 814 |
+
PyEval_EvalCodeEx:PyObject*const*:kws::
|
| 815 |
+
PyEval_EvalCodeEx:int:kwcount::
|
| 816 |
+
PyEval_EvalCodeEx:PyObject*const*:defs::
|
| 817 |
+
PyEval_EvalCodeEx:int:defcount::
|
| 818 |
+
PyEval_EvalCodeEx:PyObject*:kwdefs:0:
|
| 819 |
+
PyEval_EvalCodeEx:PyObject*:closure:0:
|
| 820 |
+
|
| 821 |
+
PyEval_EvalFrame:PyObject*::+1:
|
| 822 |
+
PyEval_EvalFrame:PyFrameObject*:f:0:
|
| 823 |
+
|
| 824 |
+
PyEval_EvalFrameEx:PyObject*::+1:
|
| 825 |
+
PyEval_EvalFrameEx:PyFrameObject*:f:0:
|
| 826 |
+
PyEval_EvalFrameEx:int:throwflag::
|
| 827 |
+
|
| 828 |
+
PyEval_MergeCompilerFlags:int:::
|
| 829 |
+
PyEval_MergeCompilerFlags:PyCompilerFlags*:cf::
|
| 830 |
+
|
| 831 |
+
PyException_GetCause:PyObject*::+1:
|
| 832 |
+
PyException_GetCause:PyObject*:ex:0:
|
| 833 |
+
|
| 834 |
+
PyException_GetContext:PyObject*::+1:
|
| 835 |
+
PyException_GetContext:PyObject*:ex:0:
|
| 836 |
+
|
| 837 |
+
PyException_GetTraceback:PyObject*::+1:
|
| 838 |
+
PyException_GetTraceback:PyObject*:ex:0:
|
| 839 |
+
|
| 840 |
+
PyException_SetCause:void:::
|
| 841 |
+
PyException_SetCause:PyObject*:ex:0:
|
| 842 |
+
PyException_SetCause:PyObject*:cause:+1:
|
| 843 |
+
|
| 844 |
+
PyException_SetContext:void:::
|
| 845 |
+
PyException_SetContext:PyObject*:ex:0:
|
| 846 |
+
PyException_SetContext:PyObject*:ctx:+1:
|
| 847 |
+
|
| 848 |
+
PyException_SetTraceback:int:::
|
| 849 |
+
PyException_SetTraceback:PyObject*:ex:0:
|
| 850 |
+
PyException_SetTraceback:PyObject*:tb:+1:
|
| 851 |
+
|
| 852 |
+
PyFile_FromFd:PyObject*::+1:
|
| 853 |
+
PyFile_FromFd:int:fd::
|
| 854 |
+
PyFile_FromFd:const char*:name::
|
| 855 |
+
PyFile_FromFd:const char*:mode::
|
| 856 |
+
PyFile_FromFd:int:buffering::
|
| 857 |
+
PyFile_FromFd:const char*:encoding::
|
| 858 |
+
PyFile_FromFd:const char*:errors::
|
| 859 |
+
PyFile_FromFd:const char*:newline::
|
| 860 |
+
PyFile_FromFd:int:closefd::
|
| 861 |
+
|
| 862 |
+
PyFile_GetLine:PyObject*::+1:
|
| 863 |
+
PyFile_GetLine:PyObject*:p:0:
|
| 864 |
+
PyFile_GetLine:int:n::
|
| 865 |
+
|
| 866 |
+
PyFile_WriteObject:int:::
|
| 867 |
+
PyFile_WriteObject:PyObject*:obj:0:
|
| 868 |
+
PyFile_WriteObject:PyObject*:p:0:
|
| 869 |
+
PyFile_WriteObject:int:flags::
|
| 870 |
+
|
| 871 |
+
PyFile_WriteString:int:::
|
| 872 |
+
PyFile_WriteString:const char*:s::
|
| 873 |
+
PyFile_WriteString:PyObject*:p:0:
|
| 874 |
+
PyFile_WriteString:int:flags::
|
| 875 |
+
|
| 876 |
+
PyFloat_AS_DOUBLE:double:::
|
| 877 |
+
PyFloat_AS_DOUBLE:PyObject*:pyfloat:0:
|
| 878 |
+
|
| 879 |
+
PyFloat_AsDouble:double:::
|
| 880 |
+
PyFloat_AsDouble:PyObject*:pyfloat:0:
|
| 881 |
+
|
| 882 |
+
PyFloat_Check:int:::
|
| 883 |
+
PyFloat_Check:PyObject*:p:0:
|
| 884 |
+
|
| 885 |
+
PyFloat_CheckExact:int:::
|
| 886 |
+
PyFloat_CheckExact:PyObject*:p:0:
|
| 887 |
+
|
| 888 |
+
PyFloat_FromDouble:PyObject*::+1:
|
| 889 |
+
PyFloat_FromDouble:double:v::
|
| 890 |
+
|
| 891 |
+
PyFloat_FromString:PyObject*::+1:
|
| 892 |
+
PyFloat_FromString:PyObject*:str:0:
|
| 893 |
+
|
| 894 |
+
PyFloat_GetInfo:PyObject*::+1:
|
| 895 |
+
PyFloat_GetInfo::void::
|
| 896 |
+
|
| 897 |
+
PyFrozenSet_Check:int:::
|
| 898 |
+
PyFrozenSet_Check:PyObject*:p:0:
|
| 899 |
+
|
| 900 |
+
PyFrozenSet_CheckExact:int:::
|
| 901 |
+
PyFrozenSet_CheckExact:PyObject*:p:0:
|
| 902 |
+
|
| 903 |
+
PyFrozenSet_New:PyObject*::+1:
|
| 904 |
+
PyFrozenSet_New:PyObject*:iterable:0:
|
| 905 |
+
|
| 906 |
+
PyFunction_Check:int:::
|
| 907 |
+
PyFunction_Check:PyObject*:o:0:
|
| 908 |
+
|
| 909 |
+
PyFunction_GetAnnotations:PyObject*::0:
|
| 910 |
+
PyFunction_GetAnnotations:PyObject*:op:0:
|
| 911 |
+
|
| 912 |
+
PyFunction_GetClosure:PyObject*::0:
|
| 913 |
+
PyFunction_GetClosure:PyObject*:op:0:
|
| 914 |
+
|
| 915 |
+
PyFunction_GetCode:PyObject*::0:
|
| 916 |
+
PyFunction_GetCode:PyObject*:op:0:
|
| 917 |
+
|
| 918 |
+
PyFunction_GetDefaults:PyObject*::0:
|
| 919 |
+
PyFunction_GetDefaults:PyObject*:op:0:
|
| 920 |
+
|
| 921 |
+
PyFunction_GetGlobals:PyObject*::0:
|
| 922 |
+
PyFunction_GetGlobals:PyObject*:op:0:
|
| 923 |
+
|
| 924 |
+
PyFunction_GetModule:PyObject*::0:
|
| 925 |
+
PyFunction_GetModule:PyObject*:op:0:
|
| 926 |
+
|
| 927 |
+
PyFunction_New:PyObject*::+1:
|
| 928 |
+
PyFunction_New:PyObject*:code:+1:
|
| 929 |
+
PyFunction_New:PyObject*:globals:+1:
|
| 930 |
+
|
| 931 |
+
PyFunction_NewWithQualName:PyObject*::+1:
|
| 932 |
+
PyFunction_NewWithQualName:PyObject*:code:+1:
|
| 933 |
+
PyFunction_NewWithQualName:PyObject*:globals:+1:
|
| 934 |
+
PyFunction_NewWithQualName:PyObject*:qualname:+1:
|
| 935 |
+
|
| 936 |
+
PyFunction_SetAnnotations:int:::
|
| 937 |
+
PyFunction_SetAnnotations:PyObject*:op:0:
|
| 938 |
+
PyFunction_SetAnnotations:PyObject*:annotations:+1:
|
| 939 |
+
|
| 940 |
+
PyFunction_SetClosure:int:::
|
| 941 |
+
PyFunction_SetClosure:PyObject*:op:0:
|
| 942 |
+
PyFunction_SetClosure:PyObject*:closure:+1:
|
| 943 |
+
|
| 944 |
+
PyFunction_SetDefaults:int:::
|
| 945 |
+
PyFunction_SetDefaults:PyObject*:op:0:
|
| 946 |
+
PyFunction_SetDefaults:PyObject*:defaults:+1:
|
| 947 |
+
|
| 948 |
+
PyGen_Check:int:::
|
| 949 |
+
PyGen_Check:PyObject*:ob:0:
|
| 950 |
+
|
| 951 |
+
PyGen_CheckExact:int:::
|
| 952 |
+
PyGen_CheckExact:PyObject*:ob:0:
|
| 953 |
+
|
| 954 |
+
PyGen_New:PyObject*::+1:
|
| 955 |
+
PyGen_New:PyFrameObject*:frame:0:
|
| 956 |
+
|
| 957 |
+
PyGen_NewWithQualName:PyObject*::+1:
|
| 958 |
+
PyGen_NewWithQualName:PyFrameObject*:frame:0:
|
| 959 |
+
PyGen_NewWithQualName:PyObject*:name:0:
|
| 960 |
+
PyGen_NewWithQualName:PyObject*:qualname:0:
|
| 961 |
+
|
| 962 |
+
PyCoro_CheckExact:int:::
|
| 963 |
+
PyCoro_CheckExact:PyObject*:ob:0:
|
| 964 |
+
|
| 965 |
+
PyCoro_New:PyObject*::+1:
|
| 966 |
+
PyCoro_New:PyFrameObject*:frame:0:
|
| 967 |
+
PyCoro_New:PyObject*:name:0:
|
| 968 |
+
PyCoro_New:PyObject*:qualname:0:
|
| 969 |
+
|
| 970 |
+
PyImport_AddModule:PyObject*::0:reference borrowed from sys.modules
|
| 971 |
+
PyImport_AddModule:const char*:name::
|
| 972 |
+
|
| 973 |
+
PyImport_AddModuleObject:PyObject*::0:reference borrowed from sys.modules
|
| 974 |
+
PyImport_AddModuleObject:PyObject*:name:0:
|
| 975 |
+
|
| 976 |
+
PyImport_Cleanup:void:::
|
| 977 |
+
|
| 978 |
+
PyImport_ExecCodeModule:PyObject*::+1:
|
| 979 |
+
PyImport_ExecCodeModule:const char*:name::
|
| 980 |
+
PyImport_ExecCodeModule:PyObject*:co:0:
|
| 981 |
+
|
| 982 |
+
PyImport_ExecCodeModuleEx:PyObject*::+1:
|
| 983 |
+
PyImport_ExecCodeModuleEx:const char*:name::
|
| 984 |
+
PyImport_ExecCodeModuleEx:PyObject*:co:0:
|
| 985 |
+
PyImport_ExecCodeModuleEx:const char*:pathname::
|
| 986 |
+
|
| 987 |
+
PyImport_ExecCodeModuleObject:PyObject*::+1:
|
| 988 |
+
PyImport_ExecCodeModuleObject:const char*:name::
|
| 989 |
+
PyImport_ExecCodeModuleObject:PyObject*:co:0:
|
| 990 |
+
PyImport_ExecCodeModuleObject:PyObject*:pathname:0:
|
| 991 |
+
PyImport_ExecCodeModuleObject:PyObject*:cpathname:0:
|
| 992 |
+
|
| 993 |
+
PyImport_ExecCodeModuleWithPathnames:PyObject*::+1:
|
| 994 |
+
PyImport_ExecCodeModuleWithPathnames:const char*:name::
|
| 995 |
+
PyImport_ExecCodeModuleWithPathnames:PyObject*:co:0:
|
| 996 |
+
PyImport_ExecCodeModuleWithPathnames:const char*:pathname::
|
| 997 |
+
PyImport_ExecCodeModuleWithPathnames:const char*:cpathname::
|
| 998 |
+
|
| 999 |
+
PyImport_GetImporter:PyObject*::+1:
|
| 1000 |
+
PyImport_GetImporter:PyObject*:path:0:
|
| 1001 |
+
|
| 1002 |
+
PyImport_GetMagicNumber:long:::
|
| 1003 |
+
|
| 1004 |
+
PyImport_GetModule:PyObject*::+1:
|
| 1005 |
+
PyImport_GetModule:PyObject*:name:0:
|
| 1006 |
+
|
| 1007 |
+
PyImport_GetModuleDict:PyObject*::0:
|
| 1008 |
+
|
| 1009 |
+
PyImport_Import:PyObject*::+1:
|
| 1010 |
+
PyImport_Import:PyObject*:name:0:
|
| 1011 |
+
|
| 1012 |
+
PyImport_ImportFrozenModule:int:::
|
| 1013 |
+
PyImport_ImportFrozenModule:const char*:::
|
| 1014 |
+
|
| 1015 |
+
PyImport_ImportFrozenModuleObject:int:::
|
| 1016 |
+
PyImport_ImportFrozenModuleObject:PyObject*::+1:
|
| 1017 |
+
|
| 1018 |
+
PyImport_ImportModule:PyObject*::+1:
|
| 1019 |
+
PyImport_ImportModule:const char*:name::
|
| 1020 |
+
|
| 1021 |
+
PyImport_ImportModuleEx:PyObject*::+1:
|
| 1022 |
+
PyImport_ImportModuleEx:const char*:name::
|
| 1023 |
+
PyImport_ImportModuleEx:PyObject*:globals:0:???
|
| 1024 |
+
PyImport_ImportModuleEx:PyObject*:locals:0:???
|
| 1025 |
+
PyImport_ImportModuleEx:PyObject*:fromlist:0:???
|
| 1026 |
+
|
| 1027 |
+
PyImport_ImportModuleLevel:PyObject*::+1:
|
| 1028 |
+
PyImport_ImportModuleLevel:const char*:name::
|
| 1029 |
+
PyImport_ImportModuleLevel:PyObject*:globals:0:???
|
| 1030 |
+
PyImport_ImportModuleLevel:PyObject*:locals:0:???
|
| 1031 |
+
PyImport_ImportModuleLevel:PyObject*:fromlist:0:???
|
| 1032 |
+
PyImport_ImportModuleLevel:int:level::
|
| 1033 |
+
|
| 1034 |
+
PyImport_ImportModuleLevelObject:PyObject*::+1:
|
| 1035 |
+
PyImport_ImportModuleLevelObject:PyObject*:name:0:
|
| 1036 |
+
PyImport_ImportModuleLevelObject:PyObject*:globals:0:???
|
| 1037 |
+
PyImport_ImportModuleLevelObject:PyObject*:locals:0:???
|
| 1038 |
+
PyImport_ImportModuleLevelObject:PyObject*:fromlist:0:???
|
| 1039 |
+
PyImport_ImportModuleLevelObject:int:level::
|
| 1040 |
+
|
| 1041 |
+
PyImport_ImportModuleNoBlock:PyObject*::+1:
|
| 1042 |
+
PyImport_ImportModuleNoBlock:const char*:name::
|
| 1043 |
+
|
| 1044 |
+
PyImport_ReloadModule:PyObject*::+1:
|
| 1045 |
+
PyImport_ReloadModule:PyObject*:m:0:
|
| 1046 |
+
|
| 1047 |
+
PyIndex_Check:int:::
|
| 1048 |
+
PyIndex_Check:PyObject*:o:0:
|
| 1049 |
+
|
| 1050 |
+
PyInstanceMethod_Check:int:::
|
| 1051 |
+
PyInstanceMethod_Check:PyObject*:o:0:
|
| 1052 |
+
|
| 1053 |
+
PyInstanceMethod_Function:PyObject*::0:
|
| 1054 |
+
PyInstanceMethod_Function:PyObject*:im:0:
|
| 1055 |
+
|
| 1056 |
+
PyInstanceMethod_GET_FUNCTION:PyObject*::0:
|
| 1057 |
+
PyInstanceMethod_GET_FUNCTION:PyObject*:im:0:
|
| 1058 |
+
|
| 1059 |
+
PyInstanceMethod_New:PyObject*::+1:
|
| 1060 |
+
PyInstanceMethod_New:PyObject*:func:0:
|
| 1061 |
+
|
| 1062 |
+
PyInterpreterState_Clear:void:::
|
| 1063 |
+
PyInterpreterState_Clear:PyInterpreterState*:interp::
|
| 1064 |
+
|
| 1065 |
+
PyInterpreterState_Delete:void:::
|
| 1066 |
+
PyInterpreterState_Delete:PyInterpreterState*:interp::
|
| 1067 |
+
|
| 1068 |
+
PyInterpreterState_GetID:int64_t:::
|
| 1069 |
+
PyInterpreterState_GetID:PyInterpreterState*:interp::
|
| 1070 |
+
|
| 1071 |
+
PyInterpreterState_New:PyInterpreterState*:::
|
| 1072 |
+
|
| 1073 |
+
PyIter_Check:int:::
|
| 1074 |
+
PyIter_Check:PyObject*:o:0:
|
| 1075 |
+
|
| 1076 |
+
PyIter_Next:PyObject*::+1:
|
| 1077 |
+
PyIter_Next:PyObject*:o:0:
|
| 1078 |
+
|
| 1079 |
+
PyList_Append:int:::
|
| 1080 |
+
PyList_Append:PyObject*:list:0:
|
| 1081 |
+
PyList_Append:PyObject*:item:+1:
|
| 1082 |
+
|
| 1083 |
+
PyList_AsTuple:PyObject*::+1:
|
| 1084 |
+
PyList_AsTuple:PyObject*:list:0:
|
| 1085 |
+
|
| 1086 |
+
PyList_Check:int:::
|
| 1087 |
+
PyList_Check:PyObject*:p:0:
|
| 1088 |
+
|
| 1089 |
+
PyList_CheckExact:int:::
|
| 1090 |
+
PyList_CheckExact:PyObject*:p:0:
|
| 1091 |
+
|
| 1092 |
+
PyList_GET_ITEM:PyObject*::0:
|
| 1093 |
+
PyList_GET_ITEM:PyObject*:list:0:
|
| 1094 |
+
PyList_GET_ITEM:Py_ssize_t:i::
|
| 1095 |
+
|
| 1096 |
+
PyList_GET_SIZE:Py_ssize_t:::
|
| 1097 |
+
PyList_GET_SIZE:PyObject*:list:0:
|
| 1098 |
+
|
| 1099 |
+
PyList_GetItem:PyObject*::0:
|
| 1100 |
+
PyList_GetItem:PyObject*:list:0:
|
| 1101 |
+
PyList_GetItem:Py_ssize_t:index::
|
| 1102 |
+
|
| 1103 |
+
PyList_GetSlice:PyObject*::+1:
|
| 1104 |
+
PyList_GetSlice:PyObject*:list:0:
|
| 1105 |
+
PyList_GetSlice:Py_ssize_t:low::
|
| 1106 |
+
PyList_GetSlice:Py_ssize_t:high::
|
| 1107 |
+
|
| 1108 |
+
PyList_Insert:int:::
|
| 1109 |
+
PyList_Insert:PyObject*:list:0:
|
| 1110 |
+
PyList_Insert:Py_ssize_t:index::
|
| 1111 |
+
PyList_Insert:PyObject*:item:+1:
|
| 1112 |
+
|
| 1113 |
+
PyList_New:PyObject*::+1:
|
| 1114 |
+
PyList_New:Py_ssize_t:len::
|
| 1115 |
+
|
| 1116 |
+
PyList_Reverse:int:::
|
| 1117 |
+
PyList_Reverse:PyObject*:list:0:
|
| 1118 |
+
|
| 1119 |
+
PyList_SET_ITEM:void:::
|
| 1120 |
+
PyList_SET_ITEM:PyObject*:list:0:
|
| 1121 |
+
PyList_SET_ITEM:Py_ssize_t:i::
|
| 1122 |
+
PyList_SET_ITEM:PyObject*:o:0:
|
| 1123 |
+
|
| 1124 |
+
PyList_SetItem:int:::
|
| 1125 |
+
PyList_SetItem:PyObject*:list:0:
|
| 1126 |
+
PyList_SetItem:Py_ssize_t:index::
|
| 1127 |
+
PyList_SetItem:PyObject*:item:0:
|
| 1128 |
+
|
| 1129 |
+
PyList_SetSlice:int:::
|
| 1130 |
+
PyList_SetSlice:PyObject*:list:0:
|
| 1131 |
+
PyList_SetSlice:Py_ssize_t:low::
|
| 1132 |
+
PyList_SetSlice:Py_ssize_t:high::
|
| 1133 |
+
PyList_SetSlice:PyObject*:itemlist:0:but increfs its elements?
|
| 1134 |
+
|
| 1135 |
+
PyList_Size:Py_ssize_t:::
|
| 1136 |
+
PyList_Size:PyObject*:list:0:
|
| 1137 |
+
|
| 1138 |
+
PyList_Sort:int:::
|
| 1139 |
+
PyList_Sort:PyObject*:list:0:
|
| 1140 |
+
|
| 1141 |
+
PyLong_AsDouble:double:::
|
| 1142 |
+
PyLong_AsDouble:PyObject*:pylong:0:
|
| 1143 |
+
|
| 1144 |
+
PyLong_AsLong:long:::
|
| 1145 |
+
PyLong_AsLong:PyObject*:pylong:0:
|
| 1146 |
+
|
| 1147 |
+
PyLong_AsLongAndOverflow:long:::
|
| 1148 |
+
PyLong_AsLongAndOverflow:PyObject*:obj:0:
|
| 1149 |
+
PyLong_AsLongAndOverflow:int*:overflow::
|
| 1150 |
+
|
| 1151 |
+
PyLong_AsLongLong:long long:::
|
| 1152 |
+
PyLong_AsLongLong:PyObject*:obj:0:
|
| 1153 |
+
|
| 1154 |
+
PyLong_AsLongLongAndOverflow:long long:::
|
| 1155 |
+
PyLong_AsLongLongAndOverflow:PyObject*:obj:0:
|
| 1156 |
+
PyLong_AsLongLongAndOverflow:int*:overflow::
|
| 1157 |
+
|
| 1158 |
+
PyLong_AsSize_t:size_t:::
|
| 1159 |
+
PyLong_AsSize_t:PyObject*:pylong:0:
|
| 1160 |
+
|
| 1161 |
+
PyLong_AsSsize_t:Py_ssize_t:::
|
| 1162 |
+
PyLong_AsSsize_t:PyObject*:pylong:0:
|
| 1163 |
+
|
| 1164 |
+
PyLong_AsUnsignedLong:unsigned long:::
|
| 1165 |
+
PyLong_AsUnsignedLong:PyObject*:pylong:0:
|
| 1166 |
+
|
| 1167 |
+
PyLong_AsUnsignedLongLong:unsigned long long:::
|
| 1168 |
+
PyLong_AsUnsignedLongLong:PyObject*:pylong:0:
|
| 1169 |
+
|
| 1170 |
+
PyLong_AsUnsignedLongMask:unsigned long:::
|
| 1171 |
+
PyLong_AsUnsignedLongMask:PyObject*:obj:0:
|
| 1172 |
+
|
| 1173 |
+
PyLong_AsUnsignedLongLongMask:unsigned long long:::
|
| 1174 |
+
PyLong_AsUnsignedLongLongMask:PyObject*:obj:0:
|
| 1175 |
+
|
| 1176 |
+
PyLong_AsVoidPtr:void*:::
|
| 1177 |
+
PyLong_AsVoidPtr:PyObject*:pylong:0:
|
| 1178 |
+
|
| 1179 |
+
PyLong_Check:int:::
|
| 1180 |
+
PyLong_Check:PyObject*:p:0:
|
| 1181 |
+
|
| 1182 |
+
PyLong_CheckExact:int:::
|
| 1183 |
+
PyLong_CheckExact:PyObject*:p:0:
|
| 1184 |
+
|
| 1185 |
+
PyLong_FromDouble:PyObject*::+1:
|
| 1186 |
+
PyLong_FromDouble:double:v::
|
| 1187 |
+
|
| 1188 |
+
PyLong_FromLong:PyObject*::+1:
|
| 1189 |
+
PyLong_FromLong:long:v::
|
| 1190 |
+
|
| 1191 |
+
PyLong_FromLongLong:PyObject*::+1:
|
| 1192 |
+
PyLong_FromLongLong:long long:v::
|
| 1193 |
+
|
| 1194 |
+
PyLong_FromUnsignedLongLong:PyObject*::+1:
|
| 1195 |
+
PyLong_FromUnsignedLongLong:unsigned long long:v::
|
| 1196 |
+
|
| 1197 |
+
PyLong_FromSize_t:PyObject*::+1:
|
| 1198 |
+
PyLong_FromSize_t:size_t:v::
|
| 1199 |
+
|
| 1200 |
+
PyLong_FromSsize_t:PyObject*::+1:
|
| 1201 |
+
PyLong_FromSsize_t:Py_ssize_t:v::
|
| 1202 |
+
|
| 1203 |
+
PyLong_FromString:PyObject*::+1:
|
| 1204 |
+
PyLong_FromString:const char*:str::
|
| 1205 |
+
PyLong_FromString:char**:pend::
|
| 1206 |
+
PyLong_FromString:int:base::
|
| 1207 |
+
|
| 1208 |
+
PyLong_FromUnicode:PyObject*::+1:
|
| 1209 |
+
PyLong_FromUnicode:Py_UNICODE*:u::
|
| 1210 |
+
PyLong_FromUnicode:Py_ssize_t:length::
|
| 1211 |
+
PyLong_FromUnicode:int:base::
|
| 1212 |
+
|
| 1213 |
+
PyLong_FromUnicodeObject:PyObject*::+1:
|
| 1214 |
+
PyLong_FromUnicodeObject:PyObject*:u:0:
|
| 1215 |
+
PyLong_FromUnicodeObject:int:base::
|
| 1216 |
+
|
| 1217 |
+
PyLong_FromUnsignedLong:PyObject*::+1:
|
| 1218 |
+
PyLong_FromUnsignedLong:unsignedlong:v::
|
| 1219 |
+
|
| 1220 |
+
PyLong_FromVoidPtr:PyObject*::+1:
|
| 1221 |
+
PyLong_FromVoidPtr:void*:p::
|
| 1222 |
+
|
| 1223 |
+
PyMapping_Check:int:::
|
| 1224 |
+
PyMapping_Check:PyObject*:o:0:
|
| 1225 |
+
|
| 1226 |
+
PyMapping_DelItem:int:::
|
| 1227 |
+
PyMapping_DelItem:PyObject*:o:0:
|
| 1228 |
+
PyMapping_DelItem:PyObject*:key:0:
|
| 1229 |
+
|
| 1230 |
+
PyMapping_DelItemString:int:::
|
| 1231 |
+
PyMapping_DelItemString:PyObject*:o:0:
|
| 1232 |
+
PyMapping_DelItemString:const char*:key::
|
| 1233 |
+
|
| 1234 |
+
PyMapping_GetItemString:PyObject*::+1:
|
| 1235 |
+
PyMapping_GetItemString:PyObject*:o:0:
|
| 1236 |
+
PyMapping_GetItemString:const char*:key::
|
| 1237 |
+
|
| 1238 |
+
PyMapping_HasKey:int:::
|
| 1239 |
+
PyMapping_HasKey:PyObject*:o:0:
|
| 1240 |
+
PyMapping_HasKey:PyObject*:key::
|
| 1241 |
+
|
| 1242 |
+
PyMapping_HasKeyString:int:::
|
| 1243 |
+
PyMapping_HasKeyString:PyObject*:o:0:
|
| 1244 |
+
PyMapping_HasKeyString:const char*:key::
|
| 1245 |
+
|
| 1246 |
+
PyMapping_Items:PyObject*::+1:
|
| 1247 |
+
PyMapping_Items:PyObject*:o:0:
|
| 1248 |
+
|
| 1249 |
+
PyMapping_Keys:PyObject*::+1:
|
| 1250 |
+
PyMapping_Keys:PyObject*:o:0:
|
| 1251 |
+
|
| 1252 |
+
PyMapping_Length:Py_ssize_t:::
|
| 1253 |
+
PyMapping_Length:PyObject*:o:0:
|
| 1254 |
+
|
| 1255 |
+
PyMapping_SetItemString:int:::
|
| 1256 |
+
PyMapping_SetItemString:PyObject*:o:0:
|
| 1257 |
+
PyMapping_SetItemString:const char*:key::
|
| 1258 |
+
PyMapping_SetItemString:PyObject*:v:+1:
|
| 1259 |
+
|
| 1260 |
+
PyMapping_Size:Py_ssize_t:::
|
| 1261 |
+
PyMapping_Size:PyObject*:o:0:
|
| 1262 |
+
|
| 1263 |
+
PyMapping_Values:PyObject*::+1:
|
| 1264 |
+
PyMapping_Values:PyObject*:o:0:
|
| 1265 |
+
|
| 1266 |
+
PyMarshal_ReadLastObjectFromFile:PyObject*::+1:
|
| 1267 |
+
PyMarshal_ReadLastObjectFromFile:FILE*:file::
|
| 1268 |
+
|
| 1269 |
+
PyMarshal_ReadObjectFromFile:PyObject*::+1:
|
| 1270 |
+
PyMarshal_ReadObjectFromFile:FILE*:file::
|
| 1271 |
+
|
| 1272 |
+
PyMarshal_ReadObjectFromString:PyObject*::+1:
|
| 1273 |
+
PyMarshal_ReadObjectFromString:const char*:string::
|
| 1274 |
+
PyMarshal_ReadObjectFromString:Py_ssize_t:len::
|
| 1275 |
+
|
| 1276 |
+
PyMarshal_WriteObjectToString:PyObject*::+1:
|
| 1277 |
+
PyMarshal_WriteObjectToString:PyObject*:value:0:
|
| 1278 |
+
PyMarshal_WriteObjectToString:int:version::
|
| 1279 |
+
|
| 1280 |
+
PyMemoryView_Check:int:::
|
| 1281 |
+
PyMemoryView_Check:PyObject*:obj:0:
|
| 1282 |
+
|
| 1283 |
+
PyMemoryView_FromBuffer:PyObject*::+1:
|
| 1284 |
+
PyMemoryView_FromBuffer:Py_buffer*:view::
|
| 1285 |
+
|
| 1286 |
+
PyMemoryView_FromMemory:PyObject*::+1:
|
| 1287 |
+
PyMemoryView_FromMemory:char*:mem::
|
| 1288 |
+
PyMemoryView_FromMemory:Py_ssize_t:size::
|
| 1289 |
+
PyMemoryView_FromMemory:int:flags::
|
| 1290 |
+
|
| 1291 |
+
PyMemoryView_FromObject:PyObject*::+1:
|
| 1292 |
+
PyMemoryView_FromObject:PyObject*:obj:0:
|
| 1293 |
+
|
| 1294 |
+
PyMemoryView_GET_BASE:Py_buffer*:::
|
| 1295 |
+
PyMemoryView_GET_BASE:PyObject*:mview:0:
|
| 1296 |
+
|
| 1297 |
+
PyMemoryView_GET_BUFFER:Py_buffer*:::
|
| 1298 |
+
PyMemoryView_GET_BUFFER:PyObject*:mview:0:
|
| 1299 |
+
|
| 1300 |
+
PyMemoryView_GetContiguous:PyObject*::+1:
|
| 1301 |
+
PyMemoryView_GetContiguous:PyObject*:obj:0:
|
| 1302 |
+
PyMemoryView_GetContiguous:int:buffertype::
|
| 1303 |
+
PyMemoryView_GetContiguous:char:order::
|
| 1304 |
+
|
| 1305 |
+
PyMethod_Check:int:::
|
| 1306 |
+
PyMethod_Check:PyObject*:o:0:
|
| 1307 |
+
|
| 1308 |
+
PyMethod_Function:PyObject*::0:
|
| 1309 |
+
PyMethod_Function:PyObject*:im:0:
|
| 1310 |
+
|
| 1311 |
+
PyMethod_GET_FUNCTION:PyObject*::0:
|
| 1312 |
+
PyMethod_GET_FUNCTION:PyObject*:im:0:
|
| 1313 |
+
|
| 1314 |
+
PyMethod_GET_SELF:PyObject*::0:
|
| 1315 |
+
PyMethod_GET_SELF:PyObject*:im:0:
|
| 1316 |
+
|
| 1317 |
+
PyMethod_New:PyObject*::+1:
|
| 1318 |
+
PyMethod_New:PyObject*:func:0:
|
| 1319 |
+
PyMethod_New:PyObject*:self:0:
|
| 1320 |
+
PyMethod_New:PyObject*:class:0:
|
| 1321 |
+
|
| 1322 |
+
PyMethod_Self:PyObject*::0:
|
| 1323 |
+
PyMethod_Self:PyObject*:im:0:
|
| 1324 |
+
|
| 1325 |
+
PyModule_AddFunctions:int:::
|
| 1326 |
+
PyModule_AddFunctions:PyObject*:module:0:
|
| 1327 |
+
PyModule_AddFunctions:PyMethodDef*:functions::
|
| 1328 |
+
|
| 1329 |
+
PyModule_AddIntConstant:int:::
|
| 1330 |
+
PyModule_AddIntConstant:PyObject*:module:0:
|
| 1331 |
+
PyModule_AddIntConstant:const char*:name::
|
| 1332 |
+
PyModule_AddIntConstant:long:value::
|
| 1333 |
+
|
| 1334 |
+
PyModule_AddIntMacro:int:::
|
| 1335 |
+
PyModule_AddIntMacro:PyObject*:module:0:
|
| 1336 |
+
PyModule_AddIntMacro::macro::
|
| 1337 |
+
|
| 1338 |
+
PyModule_AddObject:int:::
|
| 1339 |
+
PyModule_AddObject:PyObject*:module:0:
|
| 1340 |
+
PyModule_AddObject:const char*:name::
|
| 1341 |
+
PyModule_AddObject:PyObject*:value:+1:
|
| 1342 |
+
|
| 1343 |
+
PyModule_AddStringConstant:int:::
|
| 1344 |
+
PyModule_AddStringConstant:PyObject*:module:0:
|
| 1345 |
+
PyModule_AddStringConstant:const char*:name::
|
| 1346 |
+
PyModule_AddStringConstant:const char*:value::
|
| 1347 |
+
|
| 1348 |
+
PyModule_AddStringMacro:int:::
|
| 1349 |
+
PyModule_AddStringMacro:PyObject*:module:0:
|
| 1350 |
+
PyModule_AddStringMacro::macro::
|
| 1351 |
+
|
| 1352 |
+
PyModule_Check:int:::
|
| 1353 |
+
PyModule_Check:PyObject*:p:0:
|
| 1354 |
+
|
| 1355 |
+
PyModule_CheckExact:int:::
|
| 1356 |
+
PyModule_CheckExact:PyObject*:p:0:
|
| 1357 |
+
|
| 1358 |
+
PyModule_Create:PyObject*::+1:
|
| 1359 |
+
PyModule_Create:PyModuleDef*:def::
|
| 1360 |
+
|
| 1361 |
+
PyModule_Create2:PyObject*::+1:
|
| 1362 |
+
PyModule_Create2:PyModuleDef*:def::
|
| 1363 |
+
PyModule_Create2:int:module_api_version::
|
| 1364 |
+
|
| 1365 |
+
PyModule_ExecDef:int:::
|
| 1366 |
+
PyModule_ExecDef:PyObject*:module:0:
|
| 1367 |
+
PyModule_ExecDef:PyModuleDef*:def::
|
| 1368 |
+
|
| 1369 |
+
PyModule_FromDefAndSpec:PyObject*::+1:
|
| 1370 |
+
PyModule_FromDefAndSpec:PyModuleDef*:def::
|
| 1371 |
+
PyModule_FromDefAndSpec:PyObject*:spec:0:
|
| 1372 |
+
|
| 1373 |
+
PyModule_FromDefAndSpec2:PyObject*::+1:
|
| 1374 |
+
PyModule_FromDefAndSpec2:PyModuleDef*:def::
|
| 1375 |
+
PyModule_FromDefAndSpec2:PyObject*:spec:0:
|
| 1376 |
+
PyModule_FromDefAndSpec2:int:module_api_version::
|
| 1377 |
+
|
| 1378 |
+
PyModule_GetDef:PyModuleDef*::0:
|
| 1379 |
+
PyModule_GetDef:PyObject*:module:0:
|
| 1380 |
+
|
| 1381 |
+
PyModule_GetDict:PyObject*::0:
|
| 1382 |
+
PyModule_GetDict:PyObject*:module:0:
|
| 1383 |
+
|
| 1384 |
+
PyModule_GetFilename:const char*:::
|
| 1385 |
+
PyModule_GetFilename:PyObject*:module:0:
|
| 1386 |
+
|
| 1387 |
+
PyModule_GetFilenameObject:PyObject*::+1:
|
| 1388 |
+
PyModule_GetFilenameObject:PyObject*:module:0:
|
| 1389 |
+
|
| 1390 |
+
PyModule_GetName:const char*:::
|
| 1391 |
+
PyModule_GetName:PyObject*:module:0:
|
| 1392 |
+
|
| 1393 |
+
PyModule_GetNameObject:PyObject*::+1:
|
| 1394 |
+
PyModule_GetNameObject:PyObject*:module:0:
|
| 1395 |
+
|
| 1396 |
+
PyModule_GetState:void*:::
|
| 1397 |
+
PyModule_GetState:PyObject*:module:0:
|
| 1398 |
+
|
| 1399 |
+
PyModule_New:PyObject*::+1:
|
| 1400 |
+
PyModule_New::char* name::
|
| 1401 |
+
|
| 1402 |
+
PyModule_NewObject:PyObject*::+1:
|
| 1403 |
+
PyModule_NewObject:PyObject*:name:+1:
|
| 1404 |
+
|
| 1405 |
+
PyModule_SetDocString:int:::
|
| 1406 |
+
PyModule_SetDocString:PyObject*:module:0:
|
| 1407 |
+
PyModule_SetDocString:const char*:docstring::
|
| 1408 |
+
|
| 1409 |
+
PyModuleDef_Init:PyObject*::0:
|
| 1410 |
+
PyModuleDef_Init:PyModuleDef*:def:0:
|
| 1411 |
+
|
| 1412 |
+
PyNumber_Absolute:PyObject*::+1:
|
| 1413 |
+
PyNumber_Absolute:PyObject*:o:0:
|
| 1414 |
+
|
| 1415 |
+
PyNumber_Add:PyObject*::+1:
|
| 1416 |
+
PyNumber_Add:PyObject*:o1:0:
|
| 1417 |
+
PyNumber_Add:PyObject*:o2:0:
|
| 1418 |
+
|
| 1419 |
+
PyNumber_And:PyObject*::+1:
|
| 1420 |
+
PyNumber_And:PyObject*:o1:0:
|
| 1421 |
+
PyNumber_And:PyObject*:o2:0:
|
| 1422 |
+
|
| 1423 |
+
PyNumber_AsSsize_t:Py_ssize_t:::
|
| 1424 |
+
PyNumber_AsSsize_t:PyObject*:o:0:
|
| 1425 |
+
PyNumber_AsSsize_t:PyObject*:exc:0:
|
| 1426 |
+
|
| 1427 |
+
PyNumber_Check:int:::
|
| 1428 |
+
PyNumber_Check:PyObject*:o:0:
|
| 1429 |
+
|
| 1430 |
+
PyNumber_Divmod:PyObject*::+1:
|
| 1431 |
+
PyNumber_Divmod:PyObject*:o1:0:
|
| 1432 |
+
PyNumber_Divmod:PyObject*:o2:0:
|
| 1433 |
+
|
| 1434 |
+
PyNumber_Float:PyObject*::+1:
|
| 1435 |
+
PyNumber_Float:PyObject*:o:0:
|
| 1436 |
+
|
| 1437 |
+
PyNumber_FloorDivide:PyObject*::+1:
|
| 1438 |
+
PyNumber_FloorDivide:PyObject*:v:0:
|
| 1439 |
+
PyNumber_FloorDivide:PyObject*:w:0:
|
| 1440 |
+
|
| 1441 |
+
PyNumber_Index:PyObject*::+1:
|
| 1442 |
+
PyNumber_Index:PyObject*:o:0:
|
| 1443 |
+
|
| 1444 |
+
PyNumber_InPlaceAdd:PyObject*::+1:
|
| 1445 |
+
PyNumber_InPlaceAdd:PyObject*:v:0:
|
| 1446 |
+
PyNumber_InPlaceAdd:PyObject*:w:0:
|
| 1447 |
+
|
| 1448 |
+
PyNumber_InPlaceAnd:PyObject*::+1:
|
| 1449 |
+
PyNumber_InPlaceAnd:PyObject*:v:0:
|
| 1450 |
+
PyNumber_InPlaceAnd:PyObject*:w:0:
|
| 1451 |
+
|
| 1452 |
+
PyNumber_InPlaceFloorDivide:PyObject*::+1:
|
| 1453 |
+
PyNumber_InPlaceFloorDivide:PyObject*:v:0:
|
| 1454 |
+
PyNumber_InPlaceFloorDivide:PyObject*:w:0:
|
| 1455 |
+
|
| 1456 |
+
PyNumber_InPlaceLshift:PyObject*::+1:
|
| 1457 |
+
PyNumber_InPlaceLshift:PyObject*:v:0:
|
| 1458 |
+
PyNumber_InPlaceLshift:PyObject*:w:0:
|
| 1459 |
+
|
| 1460 |
+
PyNumber_InPlaceMatrixMultiply:PyObject*::+1:
|
| 1461 |
+
PyNumber_InPlaceMatrixMultiply:PyObject*:o1:0:
|
| 1462 |
+
PyNumber_InPlaceMatrixMultiply:PyObject*:o2:0:
|
| 1463 |
+
|
| 1464 |
+
PyNumber_InPlaceMultiply:PyObject*::+1:
|
| 1465 |
+
PyNumber_InPlaceMultiply:PyObject*:v:0:
|
| 1466 |
+
PyNumber_InPlaceMultiply:PyObject*:w:0:
|
| 1467 |
+
|
| 1468 |
+
PyNumber_InPlaceOr:PyObject*::+1:
|
| 1469 |
+
PyNumber_InPlaceOr:PyObject*:v:0:
|
| 1470 |
+
PyNumber_InPlaceOr:PyObject*:w:0:
|
| 1471 |
+
|
| 1472 |
+
PyNumber_InPlacePower:PyObject*::+1:
|
| 1473 |
+
PyNumber_InPlacePower:PyObject*:v:0:
|
| 1474 |
+
PyNumber_InPlacePower:PyObject*:w:0:
|
| 1475 |
+
PyNumber_InPlacePower:PyObject*:z:0:
|
| 1476 |
+
|
| 1477 |
+
PyNumber_InPlaceRemainder:PyObject*::+1:
|
| 1478 |
+
PyNumber_InPlaceRemainder:PyObject*:v:0:
|
| 1479 |
+
PyNumber_InPlaceRemainder:PyObject*:w:0:
|
| 1480 |
+
|
| 1481 |
+
PyNumber_InPlaceRshift:PyObject*::+1:
|
| 1482 |
+
PyNumber_InPlaceRshift:PyObject*:v:0:
|
| 1483 |
+
PyNumber_InPlaceRshift:PyObject*:w:0:
|
| 1484 |
+
|
| 1485 |
+
PyNumber_InPlaceSubtract:PyObject*::+1:
|
| 1486 |
+
PyNumber_InPlaceSubtract:PyObject*:v:0:
|
| 1487 |
+
PyNumber_InPlaceSubtract:PyObject*:w:0:
|
| 1488 |
+
|
| 1489 |
+
PyNumber_InPlaceTrueDivide:PyObject*::+1:
|
| 1490 |
+
PyNumber_InPlaceTrueDivide:PyObject*:v:0:
|
| 1491 |
+
PyNumber_InPlaceTrueDivide:PyObject*:w:0:
|
| 1492 |
+
|
| 1493 |
+
PyNumber_InPlaceXor:PyObject*::+1:
|
| 1494 |
+
PyNumber_InPlaceXor:PyObject*:v:0:
|
| 1495 |
+
PyNumber_InPlaceXor:PyObject*:w:0:
|
| 1496 |
+
|
| 1497 |
+
PyNumber_Invert:PyObject*::+1:
|
| 1498 |
+
PyNumber_Invert:PyObject*:o:0:
|
| 1499 |
+
|
| 1500 |
+
PyNumber_Long:PyObject*::+1:
|
| 1501 |
+
PyNumber_Long:PyObject*:o:0:
|
| 1502 |
+
|
| 1503 |
+
PyNumber_Lshift:PyObject*::+1:
|
| 1504 |
+
PyNumber_Lshift:PyObject*:o1:0:
|
| 1505 |
+
PyNumber_Lshift:PyObject*:o2:0:
|
| 1506 |
+
|
| 1507 |
+
PyNumber_MatrixMultiply:PyObject*::+1:
|
| 1508 |
+
PyNumber_MatrixMultiply:PyObject*:o1:0:
|
| 1509 |
+
PyNumber_MatrixMultiply:PyObject*:o2:0:
|
| 1510 |
+
|
| 1511 |
+
PyNumber_Multiply:PyObject*::+1:
|
| 1512 |
+
PyNumber_Multiply:PyObject*:o1:0:
|
| 1513 |
+
PyNumber_Multiply:PyObject*:o2:0:
|
| 1514 |
+
|
| 1515 |
+
PyNumber_Negative:PyObject*::+1:
|
| 1516 |
+
PyNumber_Negative:PyObject*:o:0:
|
| 1517 |
+
|
| 1518 |
+
PyNumber_Or:PyObject*::+1:
|
| 1519 |
+
PyNumber_Or:PyObject*:o1:0:
|
| 1520 |
+
PyNumber_Or:PyObject*:o2:0:
|
| 1521 |
+
|
| 1522 |
+
PyNumber_Positive:PyObject*::+1:
|
| 1523 |
+
PyNumber_Positive:PyObject*:o:0:
|
| 1524 |
+
|
| 1525 |
+
PyNumber_Power:PyObject*::+1:
|
| 1526 |
+
PyNumber_Power:PyObject*:o1:0:
|
| 1527 |
+
PyNumber_Power:PyObject*:o2:0:
|
| 1528 |
+
PyNumber_Power:PyObject*:o3:0:
|
| 1529 |
+
|
| 1530 |
+
PyNumber_Remainder:PyObject*::+1:
|
| 1531 |
+
PyNumber_Remainder:PyObject*:o1:0:
|
| 1532 |
+
PyNumber_Remainder:PyObject*:o2:0:
|
| 1533 |
+
|
| 1534 |
+
PyNumber_Rshift:PyObject*::+1:
|
| 1535 |
+
PyNumber_Rshift:PyObject*:o1:0:
|
| 1536 |
+
PyNumber_Rshift:PyObject*:o2:0:
|
| 1537 |
+
|
| 1538 |
+
PyNumber_Subtract:PyObject*::+1:
|
| 1539 |
+
PyNumber_Subtract:PyObject*:o1:0:
|
| 1540 |
+
PyNumber_Subtract:PyObject*:o2:0:
|
| 1541 |
+
|
| 1542 |
+
PyNumber_ToBase:PyObject*::+1:
|
| 1543 |
+
PyNumber_ToBase:PyObject*:n:0:
|
| 1544 |
+
PyNumber_ToBase:int:base::
|
| 1545 |
+
|
| 1546 |
+
PyNumber_TrueDivide:PyObject*::+1:
|
| 1547 |
+
PyNumber_TrueDivide:PyObject*:v:0:
|
| 1548 |
+
PyNumber_TrueDivide:PyObject*:w:0:
|
| 1549 |
+
|
| 1550 |
+
PyNumber_Xor:PyObject*::+1:
|
| 1551 |
+
PyNumber_Xor:PyObject*:o1:0:
|
| 1552 |
+
PyNumber_Xor:PyObject*:o2:0:
|
| 1553 |
+
|
| 1554 |
+
PyObject_AsFileDescriptor:int:::
|
| 1555 |
+
PyObject_AsFileDescriptor:PyObject*:o:0:
|
| 1556 |
+
|
| 1557 |
+
PyOS_AfterFork:void:::
|
| 1558 |
+
|
| 1559 |
+
PyOS_AfterFork_Child:void:::
|
| 1560 |
+
|
| 1561 |
+
PyOS_AfterFork_Parent:void:::
|
| 1562 |
+
|
| 1563 |
+
PyOS_BeforeFork:void:::
|
| 1564 |
+
|
| 1565 |
+
PyOS_FSPath:PyObject*::+1:
|
| 1566 |
+
PyOS_FSPath:PyObject*:path:0:
|
| 1567 |
+
|
| 1568 |
+
PyObject_ASCII:PyObject*::+1:
|
| 1569 |
+
PyObject_ASCII:PyObject*:o:0:
|
| 1570 |
+
|
| 1571 |
+
PyObject_AsCharBuffer:int:::
|
| 1572 |
+
PyObject_AsCharBuffer:PyObject*:obj:0:
|
| 1573 |
+
PyObject_AsCharBuffer:const char**:buffer::
|
| 1574 |
+
PyObject_AsCharBuffer:Py_ssize_t*:buffer_len::
|
| 1575 |
+
|
| 1576 |
+
PyObject_AsReadBuffer:int:::
|
| 1577 |
+
PyObject_AsReadBuffer:PyObject*:obj:0:
|
| 1578 |
+
PyObject_AsReadBuffer:const void**:buffer::
|
| 1579 |
+
PyObject_AsReadBuffer:Py_ssize_t*:buffer_len::
|
| 1580 |
+
|
| 1581 |
+
PyObject_AsWriteBuffer:int:::
|
| 1582 |
+
PyObject_AsWriteBuffer:PyObject*:obj:0:
|
| 1583 |
+
PyObject_AsWriteBuffer:void**:buffer::
|
| 1584 |
+
PyObject_AsWriteBuffer:Py_ssize_t*:buffer_len::
|
| 1585 |
+
|
| 1586 |
+
PyObject_Bytes:PyObject*::+1:
|
| 1587 |
+
PyObject_Bytes:PyObject*:o:0:
|
| 1588 |
+
|
| 1589 |
+
PyObject_Call:PyObject*::+1:
|
| 1590 |
+
PyObject_Call:PyObject*:callable_object:0:
|
| 1591 |
+
PyObject_Call:PyObject*:args:0:
|
| 1592 |
+
PyObject_Call:PyObject*:kw:0:
|
| 1593 |
+
|
| 1594 |
+
PyObject_CallFunction:PyObject*::+1:
|
| 1595 |
+
PyObject_CallFunction:PyObject*:callable_object:0:
|
| 1596 |
+
PyObject_CallFunction:const char*:format::
|
| 1597 |
+
PyObject_CallFunction::...::
|
| 1598 |
+
|
| 1599 |
+
PyObject_CallFunctionObjArgs:PyObject*::+1:
|
| 1600 |
+
PyObject_CallFunctionObjArgs:PyObject*:callable:0:
|
| 1601 |
+
PyObject_CallFunctionObjArgs::...::
|
| 1602 |
+
|
| 1603 |
+
PyObject_CallMethod:PyObject*::+1:
|
| 1604 |
+
PyObject_CallMethod:PyObject*:o:0:
|
| 1605 |
+
PyObject_CallMethod:const char*:m::
|
| 1606 |
+
PyObject_CallMethod:const char*:format::
|
| 1607 |
+
PyObject_CallMethod::...::
|
| 1608 |
+
|
| 1609 |
+
PyObject_CallMethodObjArgs:PyObject*::+1:
|
| 1610 |
+
PyObject_CallMethodObjArgs:PyObject*:o:0:
|
| 1611 |
+
PyObject_CallMethodObjArgs:PyObject*:name:0:
|
| 1612 |
+
PyObject_CallMethodObjArgs::...::
|
| 1613 |
+
|
| 1614 |
+
PyObject_CallObject:PyObject*::+1:
|
| 1615 |
+
PyObject_CallObject:PyObject*:callable_object:0:
|
| 1616 |
+
PyObject_CallObject:PyObject*:args:0:
|
| 1617 |
+
|
| 1618 |
+
PyObject_CheckBuffer:int:::
|
| 1619 |
+
PyObject_CheckBuffer:PyObject*:obj:0:
|
| 1620 |
+
|
| 1621 |
+
PyObject_CheckReadBuffer:int:::
|
| 1622 |
+
PyObject_CheckReadBuffer:PyObject*:o:0:
|
| 1623 |
+
|
| 1624 |
+
PyObject_DelAttr:int:::
|
| 1625 |
+
PyObject_DelAttr:PyObject*:o:0:
|
| 1626 |
+
PyObject_DelAttr:PyObject*:attr_name:0:
|
| 1627 |
+
|
| 1628 |
+
PyObject_DelAttrString:int:::
|
| 1629 |
+
PyObject_DelAttrString:PyObject*:o:0:
|
| 1630 |
+
PyObject_DelAttrString:const char*:attr_name::
|
| 1631 |
+
|
| 1632 |
+
PyObject_DelItem:int:::
|
| 1633 |
+
PyObject_DelItem:PyObject*:o:0:
|
| 1634 |
+
PyObject_DelItem:PyObject*:key:0:
|
| 1635 |
+
|
| 1636 |
+
PyObject_Dir:PyObject*::+1:
|
| 1637 |
+
PyObject_Dir:PyObject*:o:0:
|
| 1638 |
+
|
| 1639 |
+
PyObject_GC_Del:void:::
|
| 1640 |
+
PyObject_GC_Del:void*:op::
|
| 1641 |
+
|
| 1642 |
+
PyObject_GC_New:TYPE*::+1:
|
| 1643 |
+
PyObject_GC_New::TYPE::
|
| 1644 |
+
PyObject_GC_New:PyTypeObject*:type:0:
|
| 1645 |
+
|
| 1646 |
+
PyObject_GC_NewVar:TYPE*::+1:
|
| 1647 |
+
PyObject_GC_NewVar::TYPE::
|
| 1648 |
+
PyObject_GC_NewVar:PyTypeObject*:type:0:
|
| 1649 |
+
PyObject_GC_NewVar:Py_ssize_t:size::
|
| 1650 |
+
|
| 1651 |
+
PyObject_GC_Resize:TYPE*::0:
|
| 1652 |
+
PyObject_GC_Resize::TYPE::
|
| 1653 |
+
PyObject_GC_Resize:PyVarObject*:op:0:
|
| 1654 |
+
PyObject_GC_Resize:Py_ssize_t:newsize::
|
| 1655 |
+
|
| 1656 |
+
PyObject_GC_Track:void:::
|
| 1657 |
+
PyObject_GC_Track:PyObject*:op:0:
|
| 1658 |
+
|
| 1659 |
+
PyObject_GC_UnTrack:void:::
|
| 1660 |
+
PyObject_GC_UnTrack:void*:op::
|
| 1661 |
+
|
| 1662 |
+
PyObject_GenericGetAttr:PyObject*::+1:
|
| 1663 |
+
PyObject_GenericGetAttr:PyObject*:o:0:
|
| 1664 |
+
PyObject_GenericGetAttr:PyObject*:name:0:
|
| 1665 |
+
|
| 1666 |
+
PyObject_GenericGetDict:PyObject*::+1:
|
| 1667 |
+
PyObject_GenericGetDict:PyObject*:o:0:
|
| 1668 |
+
PyObject_GenericGetDict:void*:context::
|
| 1669 |
+
|
| 1670 |
+
PyObject_GenericSetAttr:int:::
|
| 1671 |
+
PyObject_GenericSetAttr:PyObject*:o:0:
|
| 1672 |
+
PyObject_GenericSetAttr:PyObject*:name:0:
|
| 1673 |
+
PyObject_GenericSetAttr:PyObject*:value:+1:
|
| 1674 |
+
|
| 1675 |
+
PyObject_GenericSetDict:int:::
|
| 1676 |
+
PyObject_GenericSetDict:PyObject*:o:0:
|
| 1677 |
+
PyObject_GenericSetDict:PyObject*:value:+1:
|
| 1678 |
+
PyObject_GenericSetDict:void*:context::
|
| 1679 |
+
|
| 1680 |
+
PyObject_GetAttr:PyObject*::+1:
|
| 1681 |
+
PyObject_GetAttr:PyObject*:o:0:
|
| 1682 |
+
PyObject_GetAttr:PyObject*:attr_name:0:
|
| 1683 |
+
|
| 1684 |
+
PyObject_GetAttrString:PyObject*::+1:
|
| 1685 |
+
PyObject_GetAttrString:PyObject*:o:0:
|
| 1686 |
+
PyObject_GetAttrString:const char*:attr_name::
|
| 1687 |
+
|
| 1688 |
+
PyObject_GetBuffer:int:::
|
| 1689 |
+
PyObject_GetBuffer:PyObject*:exporter:0:
|
| 1690 |
+
PyObject_GetBuffer:Py_buffer*:view::
|
| 1691 |
+
PyObject_GetBuffer:int:flags::
|
| 1692 |
+
|
| 1693 |
+
PyObject_GetItem:PyObject*::+1:
|
| 1694 |
+
PyObject_GetItem:PyObject*:o:0:
|
| 1695 |
+
PyObject_GetItem:PyObject*:key:0:
|
| 1696 |
+
|
| 1697 |
+
PyObject_GetIter:PyObject*::+1:
|
| 1698 |
+
PyObject_GetIter:PyObject*:o:0:
|
| 1699 |
+
|
| 1700 |
+
PyObject_HasAttr:int:::
|
| 1701 |
+
PyObject_HasAttr:PyObject*:o:0:
|
| 1702 |
+
PyObject_HasAttr:PyObject*:attr_name:0:
|
| 1703 |
+
|
| 1704 |
+
PyObject_HasAttrString:int:::
|
| 1705 |
+
PyObject_HasAttrString:PyObject*:o:0:
|
| 1706 |
+
PyObject_HasAttrString:const char*:attr_name::
|
| 1707 |
+
|
| 1708 |
+
PyObject_Hash:int:::
|
| 1709 |
+
PyObject_Hash:PyObject*:o:0:
|
| 1710 |
+
|
| 1711 |
+
PyObject_HashNotImplemented:Py_hash_t:::
|
| 1712 |
+
PyObject_HashNotImplemented:PyObject*:o:0:
|
| 1713 |
+
|
| 1714 |
+
PyObject_IsInstance:int:::
|
| 1715 |
+
PyObject_IsInstance:PyObject*:inst:0:
|
| 1716 |
+
PyObject_IsInstance:PyObject*:cls:0:
|
| 1717 |
+
|
| 1718 |
+
PyObject_IsSubclass:int:::
|
| 1719 |
+
PyObject_IsSubclass:PyObject*:derived:0:
|
| 1720 |
+
PyObject_IsSubclass:PyObject*:cls:0:
|
| 1721 |
+
|
| 1722 |
+
PyObject_IsTrue:int:::
|
| 1723 |
+
PyObject_IsTrue:PyObject*:o:0:
|
| 1724 |
+
|
| 1725 |
+
PyObject_Init:PyObject*::0:
|
| 1726 |
+
PyObject_Init:PyObject*:op:0:
|
| 1727 |
+
PyObject_Init:PyTypeObject*:type:0:
|
| 1728 |
+
|
| 1729 |
+
PyObject_InitVar:PyVarObject*::0:
|
| 1730 |
+
PyObject_InitVar:PyVarObject*:op:0:
|
| 1731 |
+
|
| 1732 |
+
PyObject_Length:Py_ssize_t:::
|
| 1733 |
+
PyObject_Length:PyObject*:o:0:
|
| 1734 |
+
|
| 1735 |
+
PyObject_LengthHint:Py_ssize_t:::
|
| 1736 |
+
PyObject_LengthHint:PyObject*:o:0:
|
| 1737 |
+
PyObject_LengthHint:Py_ssize_t:default::
|
| 1738 |
+
|
| 1739 |
+
PyObject_NEW:PyObject*::+1:
|
| 1740 |
+
PyObject_NEW::TYPE::
|
| 1741 |
+
PyObject_NEW:PyTypeObject*:type:0:
|
| 1742 |
+
|
| 1743 |
+
PyObject_New:PyObject*::+1:
|
| 1744 |
+
PyObject_New::TYPE::
|
| 1745 |
+
PyObject_New:PyTypeObject*:type:0:
|
| 1746 |
+
|
| 1747 |
+
PyObject_NEW_VAR:PyObject*::+1:
|
| 1748 |
+
PyObject_NEW_VAR::TYPE::
|
| 1749 |
+
PyObject_NEW_VAR:PyTypeObject*:type:0:
|
| 1750 |
+
PyObject_NEW_VAR:Py_ssize_t:size::
|
| 1751 |
+
|
| 1752 |
+
PyObject_NewVar:PyObject*::+1:
|
| 1753 |
+
PyObject_NewVar::TYPE::
|
| 1754 |
+
PyObject_NewVar:PyTypeObject*:type:0:
|
| 1755 |
+
PyObject_NewVar:Py_ssize_t:size::
|
| 1756 |
+
|
| 1757 |
+
PyObject_Not:int:::
|
| 1758 |
+
PyObject_Not:PyObject*:o:0:
|
| 1759 |
+
|
| 1760 |
+
PyObject_Print:int:::
|
| 1761 |
+
PyObject_Print:PyObject*:o:0:
|
| 1762 |
+
PyObject_Print:FILE*:fp::
|
| 1763 |
+
PyObject_Print:int:flags::
|
| 1764 |
+
|
| 1765 |
+
PyObject_Repr:PyObject*::+1:
|
| 1766 |
+
PyObject_Repr:PyObject*:o:0:
|
| 1767 |
+
|
| 1768 |
+
PyObject_RichCompare:PyObject*::+1:
|
| 1769 |
+
PyObject_RichCompare:PyObject*:o1:0:
|
| 1770 |
+
PyObject_RichCompare:PyObject*:o2:0:
|
| 1771 |
+
PyObject_RichCompare:int:opid::
|
| 1772 |
+
|
| 1773 |
+
PyObject_RichCompareBool:int:::
|
| 1774 |
+
PyObject_RichCompareBool:PyObject*:o1:0:
|
| 1775 |
+
PyObject_RichCompareBool:PyObject*:o2:0:
|
| 1776 |
+
PyObject_RichCompareBool:int:opid::
|
| 1777 |
+
|
| 1778 |
+
PyObject_SetAttr:int:::
|
| 1779 |
+
PyObject_SetAttr:PyObject*:o:0:
|
| 1780 |
+
PyObject_SetAttr:PyObject*:attr_name:0:
|
| 1781 |
+
PyObject_SetAttr:PyObject*:v:+1:
|
| 1782 |
+
|
| 1783 |
+
PyObject_SetAttrString:int:::
|
| 1784 |
+
PyObject_SetAttrString:PyObject*:o:0:
|
| 1785 |
+
PyObject_SetAttrString:const char*:attr_name::
|
| 1786 |
+
PyObject_SetAttrString:PyObject*:v:+1:
|
| 1787 |
+
|
| 1788 |
+
PyObject_SetItem:int:::
|
| 1789 |
+
PyObject_SetItem:PyObject*:o:0:
|
| 1790 |
+
PyObject_SetItem:PyObject*:key:0:
|
| 1791 |
+
PyObject_SetItem:PyObject*:v:+1:
|
| 1792 |
+
|
| 1793 |
+
PyObject_Size:Py_ssize_t:::
|
| 1794 |
+
PyObject_Size:PyObject*:o:0:
|
| 1795 |
+
|
| 1796 |
+
PyObject_Str:PyObject*::+1:
|
| 1797 |
+
PyObject_Str:PyObject*:o:0:
|
| 1798 |
+
|
| 1799 |
+
PyObject_Type:PyObject*::+1:
|
| 1800 |
+
PyObject_Type:PyObject*:o:0:
|
| 1801 |
+
|
| 1802 |
+
PyObject_TypeCheck:int:::
|
| 1803 |
+
PyObject_TypeCheck:PyObject*:o:0:
|
| 1804 |
+
PyObject_TypeCheck:PyTypeObject*:type:0:
|
| 1805 |
+
|
| 1806 |
+
PyParser_SimpleParseFile:struct _node*:::
|
| 1807 |
+
PyParser_SimpleParseFile:FILE*:fp::
|
| 1808 |
+
PyParser_SimpleParseFile:const char*:filename::
|
| 1809 |
+
PyParser_SimpleParseFile:int:start::
|
| 1810 |
+
|
| 1811 |
+
PyParser_SimpleParseFileFlags:struct _node*:::
|
| 1812 |
+
PyParser_SimpleParseFileFlags:FILE*:fp::
|
| 1813 |
+
PyParser_SimpleParseFileFlags:const char*:filename::
|
| 1814 |
+
PyParser_SimpleParseFileFlags:int:start::
|
| 1815 |
+
PyParser_SimpleParseFileFlags:int:flags::
|
| 1816 |
+
|
| 1817 |
+
PyParser_SimpleParseString:struct _node*:::
|
| 1818 |
+
PyParser_SimpleParseString:const char*:str::
|
| 1819 |
+
PyParser_SimpleParseString:int:start::
|
| 1820 |
+
|
| 1821 |
+
PyParser_SimpleParseStringFlags:struct _node*:::
|
| 1822 |
+
PyParser_SimpleParseStringFlags:const char*:str::
|
| 1823 |
+
PyParser_SimpleParseStringFlags:int:start::
|
| 1824 |
+
PyParser_SimpleParseStringFlags:int:flags::
|
| 1825 |
+
|
| 1826 |
+
PyParser_SimpleParseStringFlagsFilename:struct _node*:::
|
| 1827 |
+
PyParser_SimpleParseStringFlagsFilename:const char*:str::
|
| 1828 |
+
PyParser_SimpleParseStringFlagsFilename:const char*:filename::
|
| 1829 |
+
PyParser_SimpleParseStringFlagsFilename:int:start::
|
| 1830 |
+
PyParser_SimpleParseStringFlagsFilename:int:flags::
|
| 1831 |
+
|
| 1832 |
+
PyRun_AnyFile:int:::
|
| 1833 |
+
PyRun_AnyFile:FILE*:fp::
|
| 1834 |
+
PyRun_AnyFile:const char*:filename::
|
| 1835 |
+
|
| 1836 |
+
PyRun_AnyFileFlags:int:::
|
| 1837 |
+
PyRun_AnyFileFlags:FILE*:fp::
|
| 1838 |
+
PyRun_AnyFileFlags:const char*:filename::
|
| 1839 |
+
PyRun_AnyFileFlags:PyCompilerFlags*:flags::
|
| 1840 |
+
|
| 1841 |
+
PyRun_AnyFileEx:int:::
|
| 1842 |
+
PyRun_AnyFileEx:FILE*:fp::
|
| 1843 |
+
PyRun_AnyFileEx:const char*:filename::
|
| 1844 |
+
PyRun_AnyFileEx:int:closeit::
|
| 1845 |
+
|
| 1846 |
+
PyRun_AnyFileExFlags:int:::
|
| 1847 |
+
PyRun_AnyFileExFlags:FILE*:fp::
|
| 1848 |
+
PyRun_AnyFileExFlags:const char*:filename::
|
| 1849 |
+
PyRun_AnyFileExFlags:int:closeit::
|
| 1850 |
+
PyRun_AnyFileExFlags:PyCompilerFlags*:flags::
|
| 1851 |
+
|
| 1852 |
+
PyRun_File:PyObject*::+1:??? -- same as eval_code2()
|
| 1853 |
+
PyRun_File:FILE*:fp::
|
| 1854 |
+
PyRun_File:const char*:filename::
|
| 1855 |
+
PyRun_File:int:start::
|
| 1856 |
+
PyRun_File:PyObject*:globals:0:
|
| 1857 |
+
PyRun_File:PyObject*:locals:0:
|
| 1858 |
+
|
| 1859 |
+
PyRun_FileEx:PyObject*::+1:??? -- same as eval_code2()
|
| 1860 |
+
PyRun_FileEx:FILE*:fp::
|
| 1861 |
+
PyRun_FileEx:const char*:filename::
|
| 1862 |
+
PyRun_FileEx:int:start::
|
| 1863 |
+
PyRun_FileEx:PyObject*:globals:0:
|
| 1864 |
+
PyRun_FileEx:PyObject*:locals:0:
|
| 1865 |
+
PyRun_FileEx:int:closeit::
|
| 1866 |
+
|
| 1867 |
+
PyRun_FileFlags:PyObject*::+1:??? -- same as eval_code2()
|
| 1868 |
+
PyRun_FileFlags:FILE*:fp::
|
| 1869 |
+
PyRun_FileFlags:const char*:filename::
|
| 1870 |
+
PyRun_FileFlags:int:start::
|
| 1871 |
+
PyRun_FileFlags:PyObject*:globals:0:
|
| 1872 |
+
PyRun_FileFlags:PyObject*:locals:0:
|
| 1873 |
+
PyRun_FileFlags:PyCompilerFlags*:flags::
|
| 1874 |
+
|
| 1875 |
+
PyRun_FileExFlags:PyObject*::+1:??? -- same as eval_code2()
|
| 1876 |
+
PyRun_FileExFlags:FILE*:fp::
|
| 1877 |
+
PyRun_FileExFlags:const char*:filename::
|
| 1878 |
+
PyRun_FileExFlags:int:start::
|
| 1879 |
+
PyRun_FileExFlags:PyObject*:globals:0:
|
| 1880 |
+
PyRun_FileExFlags:PyObject*:locals:0:
|
| 1881 |
+
PyRun_FileExFlags:int:closeit::
|
| 1882 |
+
PyRun_FileExFlags:PyCompilerFlags*:flags::
|
| 1883 |
+
|
| 1884 |
+
PyRun_InteractiveLoop:int:::
|
| 1885 |
+
PyRun_InteractiveLoop:FILE*:fp::
|
| 1886 |
+
PyRun_InteractiveLoop:const char*:filename::
|
| 1887 |
+
|
| 1888 |
+
PyRun_InteractiveLoopFlags:int:::
|
| 1889 |
+
PyRun_InteractiveLoopFlags:FILE*:fp::
|
| 1890 |
+
PyRun_InteractiveLoopFlags:const char*:filename::
|
| 1891 |
+
PyRun_InteractiveLoopFlags:PyCompilerFlags*:flags::
|
| 1892 |
+
|
| 1893 |
+
PyRun_InteractiveOne:int:::
|
| 1894 |
+
PyRun_InteractiveOne:FILE*:fp::
|
| 1895 |
+
PyRun_InteractiveOne:const char*:filename::
|
| 1896 |
+
|
| 1897 |
+
PyRun_InteractiveOneFlags:int:::
|
| 1898 |
+
PyRun_InteractiveOneFlags:FILE*:fp::
|
| 1899 |
+
PyRun_InteractiveOneFlags:const char*:filename::
|
| 1900 |
+
PyRun_InteractiveOneFlags:PyCompilerFlags*:flags::
|
| 1901 |
+
|
| 1902 |
+
PyRun_SimpleFile:int:::
|
| 1903 |
+
PyRun_SimpleFile:FILE*:fp::
|
| 1904 |
+
PyRun_SimpleFile:const char*:filename::
|
| 1905 |
+
|
| 1906 |
+
PyRun_SimpleFileEx:int:::
|
| 1907 |
+
PyRun_SimpleFileEx:FILE*:fp::
|
| 1908 |
+
PyRun_SimpleFileEx:const char*:filename::
|
| 1909 |
+
PyRun_SimpleFileEx:int:closeit::
|
| 1910 |
+
|
| 1911 |
+
PyRun_SimpleFileExFlags:int:::
|
| 1912 |
+
PyRun_SimpleFileExFlags:FILE*:fp::
|
| 1913 |
+
PyRun_SimpleFileExFlags:const char*:filename::
|
| 1914 |
+
PyRun_SimpleFileExFlags:int:closeit::
|
| 1915 |
+
PyRun_SimpleFileExFlags:PyCompilerFlags*:flags::
|
| 1916 |
+
|
| 1917 |
+
PyRun_SimpleString:int:::
|
| 1918 |
+
PyRun_SimpleString:const char*:command::
|
| 1919 |
+
|
| 1920 |
+
PyRun_SimpleStringFlags:int:::
|
| 1921 |
+
PyRun_SimpleStringFlags:const char*:command::
|
| 1922 |
+
PyRun_SimpleStringFlags:PyCompilerFlags*:flags::
|
| 1923 |
+
|
| 1924 |
+
PyRun_String:PyObject*::+1:??? -- same as eval_code2()
|
| 1925 |
+
PyRun_String:const char*:str::
|
| 1926 |
+
PyRun_String:int:start::
|
| 1927 |
+
PyRun_String:PyObject*:globals:0:
|
| 1928 |
+
PyRun_String:PyObject*:locals:0:
|
| 1929 |
+
|
| 1930 |
+
PyRun_StringFlags:PyObject*::+1:??? -- same as eval_code2()
|
| 1931 |
+
PyRun_StringFlags:const char*:str::
|
| 1932 |
+
PyRun_StringFlags:int:start::
|
| 1933 |
+
PyRun_StringFlags:PyObject*:globals:0:
|
| 1934 |
+
PyRun_StringFlags:PyObject*:locals:0:
|
| 1935 |
+
PyRun_StringFlags:PyCompilerFlags*:flags::
|
| 1936 |
+
|
| 1937 |
+
PySeqIter_Check:int:::
|
| 1938 |
+
PySeqIter_Check::op::
|
| 1939 |
+
|
| 1940 |
+
PySeqIter_New:PyObject*::+1:
|
| 1941 |
+
PySeqIter_New:PyObject*:seq::
|
| 1942 |
+
|
| 1943 |
+
PySequence_Check:int:::
|
| 1944 |
+
PySequence_Check:PyObject*:o:0:
|
| 1945 |
+
|
| 1946 |
+
PySequence_Concat:PyObject*::+1:
|
| 1947 |
+
PySequence_Concat:PyObject*:o1:0:
|
| 1948 |
+
PySequence_Concat:PyObject*:o2:0:
|
| 1949 |
+
|
| 1950 |
+
PySequence_Contains:int:::
|
| 1951 |
+
PySequence_Contains:PyObject*:o:0:
|
| 1952 |
+
PySequence_Contains:PyObject*:value:0:
|
| 1953 |
+
|
| 1954 |
+
PySequence_Count:Py_ssize_t:::
|
| 1955 |
+
PySequence_Count:PyObject*:o:0:
|
| 1956 |
+
PySequence_Count:PyObject*:value:0:
|
| 1957 |
+
|
| 1958 |
+
PySequence_DelItem:int:::
|
| 1959 |
+
PySequence_DelItem:PyObject*:o:0:
|
| 1960 |
+
PySequence_DelItem:Py_ssize_t:i::
|
| 1961 |
+
|
| 1962 |
+
PySequence_DelSlice:int:::
|
| 1963 |
+
PySequence_DelSlice:PyObject*:o:0:
|
| 1964 |
+
PySequence_DelSlice:Py_ssize_t:i1::
|
| 1965 |
+
PySequence_DelSlice:Py_ssize_t:i2::
|
| 1966 |
+
|
| 1967 |
+
PySequence_Fast:PyObject*::+1:
|
| 1968 |
+
PySequence_Fast:PyObject*:v:0:
|
| 1969 |
+
PySequence_Fast:const char*:m::
|
| 1970 |
+
|
| 1971 |
+
PySequence_Fast_GET_ITEM:PyObject*::0:
|
| 1972 |
+
PySequence_Fast_GET_ITEM:PyObject*:o:0:
|
| 1973 |
+
PySequence_Fast_GET_ITEM:Py_ssize_t:i::
|
| 1974 |
+
|
| 1975 |
+
PySequence_Fast_GET_SIZE:Py_ssize_t:::
|
| 1976 |
+
PySequence_Fast_GET_SIZE:PyObject*:o:0:
|
| 1977 |
+
|
| 1978 |
+
PySequence_Fast_ITEMS:PyObject**:::
|
| 1979 |
+
PySequence_Fast_ITEMS:PyObject*:o:0:
|
| 1980 |
+
|
| 1981 |
+
PySequence_GetItem:PyObject*::+1:
|
| 1982 |
+
PySequence_GetItem:PyObject*:o:0:
|
| 1983 |
+
PySequence_GetItem:Py_ssize_t:i::
|
| 1984 |
+
|
| 1985 |
+
PySequence_GetSlice:PyObject*::+1:
|
| 1986 |
+
PySequence_GetSlice:PyObject*:o:0:
|
| 1987 |
+
PySequence_GetSlice:Py_ssize_t:i1::
|
| 1988 |
+
PySequence_GetSlice:Py_ssize_t:i2::
|
| 1989 |
+
|
| 1990 |
+
PySequence_In:int:::
|
| 1991 |
+
PySequence_In:PyObject*:o:0:
|
| 1992 |
+
PySequence_In:PyObject*:value:0:
|
| 1993 |
+
|
| 1994 |
+
PySequence_Index:Py_ssize_t:::
|
| 1995 |
+
PySequence_Index:PyObject*:o:0:
|
| 1996 |
+
PySequence_Index:PyObject*:value:0:
|
| 1997 |
+
|
| 1998 |
+
PySequence_InPlaceConcat:PyObject*::+1:
|
| 1999 |
+
PySequence_InPlaceConcat:PyObject*:s:0:
|
| 2000 |
+
PySequence_InPlaceConcat:PyObject*:o:0:
|
| 2001 |
+
|
| 2002 |
+
PySequence_InPlaceRepeat:PyObject*::+1:
|
| 2003 |
+
PySequence_InPlaceRepeat:PyObject*:s:0:
|
| 2004 |
+
PySequence_InPlaceRepeat:PyObject*:o:0:
|
| 2005 |
+
|
| 2006 |
+
PySequence_ITEM:PyObject*::+1:
|
| 2007 |
+
PySequence_ITEM:PyObject*:o:0:
|
| 2008 |
+
PySequence_ITEM:Py_ssize_t:i::
|
| 2009 |
+
|
| 2010 |
+
PySequence_Repeat:PyObject*::+1:
|
| 2011 |
+
PySequence_Repeat:PyObject*:o:0:
|
| 2012 |
+
PySequence_Repeat:Py_ssize_t:count::
|
| 2013 |
+
|
| 2014 |
+
PySequence_SetItem:int:::
|
| 2015 |
+
PySequence_SetItem:PyObject*:o:0:
|
| 2016 |
+
PySequence_SetItem:Py_ssize_t:i::
|
| 2017 |
+
PySequence_SetItem:PyObject*:v:+1:
|
| 2018 |
+
|
| 2019 |
+
PySequence_SetSlice:int:::
|
| 2020 |
+
PySequence_SetSlice:PyObject*:o:0:
|
| 2021 |
+
PySequence_SetSlice:Py_ssize_t:i1::
|
| 2022 |
+
PySequence_SetSlice:Py_ssize_t:i2::
|
| 2023 |
+
PySequence_SetSlice:PyObject*:v:0:
|
| 2024 |
+
|
| 2025 |
+
PySequence_Size:Py_ssize_t:::
|
| 2026 |
+
PySequence_Size:PyObject*:o:0:
|
| 2027 |
+
|
| 2028 |
+
PySequence_List:PyObject*::+1:
|
| 2029 |
+
PySequence_List:PyObject*:o:0:
|
| 2030 |
+
|
| 2031 |
+
PySequence_Tuple:PyObject*::+1:
|
| 2032 |
+
PySequence_Tuple:PyObject*:o:0:
|
| 2033 |
+
|
| 2034 |
+
PySet_Add:int:::
|
| 2035 |
+
PySet_Add:PyObject*:set:0:
|
| 2036 |
+
PySet_Add:PyObject*:key:+1:
|
| 2037 |
+
|
| 2038 |
+
PySet_Check:int:::
|
| 2039 |
+
PySet_Check:PyObject*:p:0:
|
| 2040 |
+
|
| 2041 |
+
PySet_Clear:int:::
|
| 2042 |
+
PySet_Clear:PyObject*:set:0:
|
| 2043 |
+
|
| 2044 |
+
PySet_Contains:int:::
|
| 2045 |
+
PySet_Contains:PyObject*:anyset:0:
|
| 2046 |
+
PySet_Contains:PyObject*:key:0:
|
| 2047 |
+
|
| 2048 |
+
PySet_Discard:int:::
|
| 2049 |
+
PySet_Discard:PyObject*:set:0:
|
| 2050 |
+
PySet_Discard:PyObject*:key:-1:no effect if key not found
|
| 2051 |
+
|
| 2052 |
+
PySet_GET_SIZE:Py_ssize_t:::
|
| 2053 |
+
PySet_GET_SIZE:PyObject*:anyset:0:
|
| 2054 |
+
|
| 2055 |
+
PySet_New:PyObject*::+1:
|
| 2056 |
+
PySet_New:PyObject*:iterable:0:
|
| 2057 |
+
|
| 2058 |
+
PySet_Pop:PyObject*::+1:or returns NULL and raises KeyError if set is empty
|
| 2059 |
+
PySet_Pop:PyObject*:set:0:
|
| 2060 |
+
|
| 2061 |
+
PySet_Size:Py_ssize_t:::
|
| 2062 |
+
PySet_Size:PyObject*:anyset:0:
|
| 2063 |
+
|
| 2064 |
+
PySignal_SetWakeupFd:int:::
|
| 2065 |
+
PySignal_SetWakeupFd:int:fd::
|
| 2066 |
+
|
| 2067 |
+
PySlice_AdjustIndices:Py_ssize_t:::
|
| 2068 |
+
PySlice_AdjustIndices:Py_ssize_t:length::
|
| 2069 |
+
PySlice_AdjustIndices:Py_ssize_t*:start::
|
| 2070 |
+
PySlice_AdjustIndices:Py_ssize_t*:stop::
|
| 2071 |
+
PySlice_AdjustIndices:Py_ssize_t*:step::
|
| 2072 |
+
|
| 2073 |
+
PySlice_Check:int:::
|
| 2074 |
+
PySlice_Check:PyObject*:ob:0:
|
| 2075 |
+
|
| 2076 |
+
PySlice_GetIndices:int:::
|
| 2077 |
+
PySlice_GetIndices:PyObject*:slice:0:
|
| 2078 |
+
PySlice_GetIndices:Py_ssize_t:length::
|
| 2079 |
+
PySlice_GetIndices:Py_ssize_t*:start::
|
| 2080 |
+
PySlice_GetIndices:Py_ssize_t*:stop::
|
| 2081 |
+
PySlice_GetIndices:Py_ssize_t*:step::
|
| 2082 |
+
|
| 2083 |
+
PySlice_GetIndicesEx:int:::
|
| 2084 |
+
PySlice_GetIndicesEx:PyObject*:slice:0:
|
| 2085 |
+
PySlice_GetIndicesEx:Py_ssize_t:length::
|
| 2086 |
+
PySlice_GetIndicesEx:Py_ssize_t*:start::
|
| 2087 |
+
PySlice_GetIndicesEx:Py_ssize_t*:stop::
|
| 2088 |
+
PySlice_GetIndicesEx:Py_ssize_t*:step::
|
| 2089 |
+
PySlice_GetIndicesEx:Py_ssize_t*:slicelength::
|
| 2090 |
+
|
| 2091 |
+
PySlice_New:PyObject*::+1:
|
| 2092 |
+
PySlice_New:PyObject*:start:0:
|
| 2093 |
+
PySlice_New:PyObject*:stop:0:
|
| 2094 |
+
PySlice_New:PyObject*:step:0:
|
| 2095 |
+
|
| 2096 |
+
PySlice_Unpack:int:::
|
| 2097 |
+
PySlice_Unpack:PyObject*:slice:0:
|
| 2098 |
+
PySlice_Unpack:Py_ssize_t*:start::
|
| 2099 |
+
PySlice_Unpack:Py_ssize_t*:stop::
|
| 2100 |
+
PySlice_Unpack:Py_ssize_t*:step::
|
| 2101 |
+
|
| 2102 |
+
PyState_AddModule:int:::
|
| 2103 |
+
PyState_AddModule:PyObject*:module:+1:
|
| 2104 |
+
PyState_AddModule:PyModuleDef*:def::
|
| 2105 |
+
|
| 2106 |
+
PyState_FindModule:PyObject*::0:
|
| 2107 |
+
PyState_FindModule:PyModuleDef*:def::
|
| 2108 |
+
|
| 2109 |
+
PyState_RemoveModule:int:::
|
| 2110 |
+
PyState_RemoveModule:PyModuleDef*:def::
|
| 2111 |
+
|
| 2112 |
+
PyStructSequence_GET_ITEM:PyObject*::0:
|
| 2113 |
+
PyStructSequence_GET_ITEM:PyObject*:p:0:
|
| 2114 |
+
PyStructSequence_GET_ITEM:Py_ssize_t:pos::
|
| 2115 |
+
|
| 2116 |
+
PyStructSequence_GetItem:PyObject*::0:
|
| 2117 |
+
PyStructSequence_GetItem:PyObject*:p:0:
|
| 2118 |
+
PyStructSequence_GetItem:Py_ssize_t:pos::
|
| 2119 |
+
|
| 2120 |
+
PyStructSequence_InitType:void:::
|
| 2121 |
+
PyStructSequence_InitType:PyTypeObject*:type:+1:
|
| 2122 |
+
PyStructSequence_InitType:PyStructSequence_Desc*:desc::
|
| 2123 |
+
|
| 2124 |
+
PyStructSequence_InitType2:int:::
|
| 2125 |
+
PyStructSequence_InitType2:PyTypeObject*:type:+1:
|
| 2126 |
+
PyStructSequence_InitType2:PyStructSequence_Desc*:desc::
|
| 2127 |
+
|
| 2128 |
+
PyStructSequence_New:PyObject*::+1:
|
| 2129 |
+
PyStructSequence_New:PyTypeObject*:type:0:
|
| 2130 |
+
|
| 2131 |
+
PyStructSequence_NewType:PyTypeObject*::+1:
|
| 2132 |
+
PyStructSequence_NewType:PyStructSequence_Desc*:desc::
|
| 2133 |
+
|
| 2134 |
+
PyStructSequence_SET_ITEM:void:::
|
| 2135 |
+
PyStructSequence_SET_ITEM:PyObject*:p:0:
|
| 2136 |
+
PyStructSequence_SET_ITEM:Py_ssize_t*:pos::
|
| 2137 |
+
PyStructSequence_SET_ITEM:PyObject*:o:0:
|
| 2138 |
+
|
| 2139 |
+
PyStructSequence_SetItem:void:::
|
| 2140 |
+
PyStructSequence_SetItem:PyObject*:p:0:
|
| 2141 |
+
PyStructSequence_SetItem:Py_ssize_t:pos::
|
| 2142 |
+
PyStructSequence_SetItem:PyObject*:o:0:
|
| 2143 |
+
|
| 2144 |
+
PySys_AddWarnOption:void:::
|
| 2145 |
+
PySys_AddWarnOption:const wchar_t*:s::
|
| 2146 |
+
|
| 2147 |
+
PySys_AddWarnOptionUnicode:void:::
|
| 2148 |
+
PySys_AddWarnOptionUnicode:PyObject*:unicode:0:
|
| 2149 |
+
|
| 2150 |
+
PySys_AddXOption:void:::
|
| 2151 |
+
PySys_AddXOption:const wchar_t*:s::
|
| 2152 |
+
|
| 2153 |
+
PySys_FormatStderr:void:::
|
| 2154 |
+
PySys_FormatStderr:const char*:format::
|
| 2155 |
+
PySys_FormatStderr::...::
|
| 2156 |
+
|
| 2157 |
+
PySys_FormatStdout:void:::
|
| 2158 |
+
PySys_FormatStdout:const char*:format::
|
| 2159 |
+
PySys_FormatStdout::...::
|
| 2160 |
+
|
| 2161 |
+
PySys_GetObject:PyObject*::0:
|
| 2162 |
+
PySys_GetObject:const char*:name::
|
| 2163 |
+
|
| 2164 |
+
PySys_GetXOptions:PyObject*::0:
|
| 2165 |
+
|
| 2166 |
+
PySys_SetArgv:void:::
|
| 2167 |
+
PySys_SetArgv:int:argc::
|
| 2168 |
+
PySys_SetArgv:wchar_t**:argv::
|
| 2169 |
+
|
| 2170 |
+
PySys_SetArgvEx:void:::
|
| 2171 |
+
PySys_SetArgvEx:int:argc::
|
| 2172 |
+
PySys_SetArgvEx:wchar_t**:argv::
|
| 2173 |
+
PySys_SetArgvEx:int:updatepath::
|
| 2174 |
+
|
| 2175 |
+
PySys_SetObject:int:::
|
| 2176 |
+
PySys_SetObject:const char*:name::
|
| 2177 |
+
PySys_SetObject:PyObject*:v:+1:
|
| 2178 |
+
|
| 2179 |
+
PySys_ResetWarnOptions:void:::
|
| 2180 |
+
|
| 2181 |
+
PySys_WriteStdout:void:::
|
| 2182 |
+
PySys_WriteStdout:const char*:format::
|
| 2183 |
+
PySys_WriteStdout::...::
|
| 2184 |
+
|
| 2185 |
+
PySys_WriteStderr:void:::
|
| 2186 |
+
PySys_WriteStderr:const char*:format::
|
| 2187 |
+
PySys_WriteStderr::...::
|
| 2188 |
+
|
| 2189 |
+
PyThreadState_Clear:void:::
|
| 2190 |
+
PyThreadState_Clear:PyThreadState*:tstate::
|
| 2191 |
+
|
| 2192 |
+
PyThreadState_Delete:void:::
|
| 2193 |
+
PyThreadState_Delete:PyThreadState*:tstate::
|
| 2194 |
+
|
| 2195 |
+
PyThreadState_Get:PyThreadState*:::
|
| 2196 |
+
|
| 2197 |
+
PyThreadState_GetDict:PyObject*::0:
|
| 2198 |
+
|
| 2199 |
+
PyThreadState_New:PyThreadState*:::
|
| 2200 |
+
PyThreadState_New:PyInterpreterState*:interp::
|
| 2201 |
+
|
| 2202 |
+
PyThreadState_SetAsyncExc:int:::
|
| 2203 |
+
PyThreadState_SetAsyncExc:unsigned long:id::
|
| 2204 |
+
PyThreadState_SetAsyncExc:PyObject*:exc:+1:
|
| 2205 |
+
|
| 2206 |
+
PyThreadState_Swap:PyThreadState*:::
|
| 2207 |
+
PyThreadState_Swap:PyThreadState*:tstate::
|
| 2208 |
+
|
| 2209 |
+
PyThread_tss_alloc:Py_tss_t*:::
|
| 2210 |
+
|
| 2211 |
+
PyThread_tss_create:int:::
|
| 2212 |
+
PyThread_tss_create:Py_tss_t*:key::
|
| 2213 |
+
|
| 2214 |
+
PyThread_tss_delete:void:::
|
| 2215 |
+
PyThread_tss_delete:Py_tss_t*:key::
|
| 2216 |
+
|
| 2217 |
+
PyThread_tss_free:void:::
|
| 2218 |
+
PyThread_tss_free:Py_tss_t*:key::
|
| 2219 |
+
|
| 2220 |
+
PyThread_tss_get:void*:::
|
| 2221 |
+
PyThread_tss_get:Py_tss_t*:key::
|
| 2222 |
+
|
| 2223 |
+
PyThread_tss_is_created:int:::
|
| 2224 |
+
PyThread_tss_is_created:Py_tss_t*:key::
|
| 2225 |
+
|
| 2226 |
+
PyThread_tss_set:int:::
|
| 2227 |
+
PyThread_tss_set:Py_tss_t*:key::
|
| 2228 |
+
PyThread_tss_set:void*:value::
|
| 2229 |
+
|
| 2230 |
+
PyTime_Check:int:::
|
| 2231 |
+
PyTime_Check:PyObject*:ob:0:
|
| 2232 |
+
|
| 2233 |
+
PyTime_CheckExact:int:::
|
| 2234 |
+
PyTime_CheckExact:PyObject*:ob:0:
|
| 2235 |
+
|
| 2236 |
+
PyTime_FromTime:PyObject*::+1:
|
| 2237 |
+
PyTime_FromTime:int:hour::
|
| 2238 |
+
PyTime_FromTime:int:minute::
|
| 2239 |
+
PyTime_FromTime:int:second::
|
| 2240 |
+
PyTime_FromTime:int:usecond::
|
| 2241 |
+
|
| 2242 |
+
PyTime_FromTimeAndFold:PyObject*::+1:
|
| 2243 |
+
PyTime_FromTimeAndFold:int:hour::
|
| 2244 |
+
PyTime_FromTimeAndFold:int:minute::
|
| 2245 |
+
PyTime_FromTimeAndFold:int:second::
|
| 2246 |
+
PyTime_FromTimeAndFold:int:usecond::
|
| 2247 |
+
PyTime_FromTimeAndFold:int:fold::
|
| 2248 |
+
|
| 2249 |
+
PyTraceMalloc_Track:int:::
|
| 2250 |
+
PyTraceMalloc_Track:unsigned int:domain::
|
| 2251 |
+
PyTraceMalloc_Track:uintptr_t:ptr::
|
| 2252 |
+
PyTraceMalloc_Track:size_t:size::
|
| 2253 |
+
|
| 2254 |
+
PyTraceMalloc_Untrack:int:::
|
| 2255 |
+
PyTraceMalloc_Untrack:unsigned int:domain::
|
| 2256 |
+
PyTraceMalloc_Untrack:uintptr_t:ptr::
|
| 2257 |
+
|
| 2258 |
+
PyTuple_Check:int:::
|
| 2259 |
+
PyTuple_Check:PyObject*:p:0:
|
| 2260 |
+
|
| 2261 |
+
PyTuple_CheckExact:int:::
|
| 2262 |
+
PyTuple_CheckExact:PyObject*:p:0:
|
| 2263 |
+
|
| 2264 |
+
PyTuple_GET_ITEM:PyObject*::0:
|
| 2265 |
+
PyTuple_GET_ITEM:PyObject*:p:0:
|
| 2266 |
+
PyTuple_GET_ITEM:Py_ssize_t:pos::
|
| 2267 |
+
|
| 2268 |
+
PyTuple_GetItem:PyObject*::0:
|
| 2269 |
+
PyTuple_GetItem:PyObject*:p:0:
|
| 2270 |
+
PyTuple_GetItem:Py_ssize_t:pos::
|
| 2271 |
+
|
| 2272 |
+
PyTuple_GET_SIZE:Py_ssize_t:::
|
| 2273 |
+
PyTuple_GET_SIZE:PyObject*:p:0:
|
| 2274 |
+
|
| 2275 |
+
PyTuple_GetSlice:PyObject*::+1:
|
| 2276 |
+
PyTuple_GetSlice:PyObject*:p:0:
|
| 2277 |
+
PyTuple_GetSlice:Py_ssize_t:low::
|
| 2278 |
+
PyTuple_GetSlice:Py_ssize_t:high::
|
| 2279 |
+
|
| 2280 |
+
PyTuple_New:PyObject*::+1:
|
| 2281 |
+
PyTuple_New:Py_ssize_t:len::
|
| 2282 |
+
|
| 2283 |
+
PyTuple_Pack:PyObject*::+1:
|
| 2284 |
+
PyTuple_Pack:Py_ssize_t:len::
|
| 2285 |
+
PyTuple_Pack:PyObject*:...:0:
|
| 2286 |
+
|
| 2287 |
+
PyTuple_SET_ITEM:void:::
|
| 2288 |
+
PyTuple_SET_ITEM:PyObject*:p:0:
|
| 2289 |
+
PyTuple_SET_ITEM:Py_ssize_t:pos::
|
| 2290 |
+
PyTuple_SET_ITEM:PyObject*:o:0:
|
| 2291 |
+
|
| 2292 |
+
PyTuple_SetItem:int:::
|
| 2293 |
+
PyTuple_SetItem:PyObject*:p:0:
|
| 2294 |
+
PyTuple_SetItem:Py_ssize_t:pos::
|
| 2295 |
+
PyTuple_SetItem:PyObject*:o:0:
|
| 2296 |
+
|
| 2297 |
+
PyTuple_Size:Py_ssize_t:::
|
| 2298 |
+
PyTuple_Size:PyObject*:p:0:
|
| 2299 |
+
|
| 2300 |
+
PyType_Check:int:::
|
| 2301 |
+
PyType_Check:PyObject*:o:0:
|
| 2302 |
+
|
| 2303 |
+
PyType_CheckExact:int:::
|
| 2304 |
+
PyType_CheckExact:PyObject*:o:0:
|
| 2305 |
+
|
| 2306 |
+
PyType_FromSpec:PyObject*::+1:
|
| 2307 |
+
PyType_FromSpec:PyType_Spec*:spec::
|
| 2308 |
+
|
| 2309 |
+
PyType_FromSpecWithBases:PyObject*::+1:
|
| 2310 |
+
PyType_FromSpecWithBases:PyType_Spec*:spec::
|
| 2311 |
+
PyType_FromSpecWithBases:PyObject*:bases:0:
|
| 2312 |
+
|
| 2313 |
+
PyType_GenericAlloc:PyObject*::+1:
|
| 2314 |
+
PyType_GenericAlloc:PyObject*:type:0:
|
| 2315 |
+
PyType_GenericAlloc:Py_ssize_t:nitems::
|
| 2316 |
+
|
| 2317 |
+
PyType_GenericNew:PyObject*::+1:
|
| 2318 |
+
PyType_GenericNew:PyObject*:type:0:
|
| 2319 |
+
PyType_GenericNew:PyObject*:args:0:
|
| 2320 |
+
PyType_GenericNew:PyObject*:kwds:0:
|
| 2321 |
+
|
| 2322 |
+
PyType_GetFlags:unsigned long:::
|
| 2323 |
+
PyType_GetFlags:PyTypeObject*:type:0:
|
| 2324 |
+
|
| 2325 |
+
PyType_GetSlot:void*:::
|
| 2326 |
+
PyType_GetSlot:PyTypeObject*:type:0:
|
| 2327 |
+
PyType_GetSlot:int:slot::
|
| 2328 |
+
|
| 2329 |
+
PyType_HasFeature:int:::
|
| 2330 |
+
PyType_HasFeature:PyTypeObject*:o:0:
|
| 2331 |
+
PyType_HasFeature:int:feature::
|
| 2332 |
+
|
| 2333 |
+
PyType_IS_GC:int:::
|
| 2334 |
+
PyType_IS_GC:PyTypeObject*:o:0:
|
| 2335 |
+
|
| 2336 |
+
PyType_IsSubtype:int:::
|
| 2337 |
+
PyType_IsSubtype:PyTypeObject*:a:0:
|
| 2338 |
+
PyType_IsSubtype:PyTypeObject*:b:0:
|
| 2339 |
+
|
| 2340 |
+
PyType_Modified:void:::
|
| 2341 |
+
PyType_Modified:PyTypeObject*:type:0:
|
| 2342 |
+
|
| 2343 |
+
PyType_Ready:int:::
|
| 2344 |
+
PyType_Ready:PyTypeObject*:type:0:
|
| 2345 |
+
|
| 2346 |
+
PyUnicode_1BYTE_DATA:Py_UCS1*:::
|
| 2347 |
+
PyUnicode_1BYTE_DATA:PyObject*:o:0:
|
| 2348 |
+
|
| 2349 |
+
PyUnicode_Check:int:::
|
| 2350 |
+
PyUnicode_Check:PyObject*:o:0:
|
| 2351 |
+
|
| 2352 |
+
PyUnicode_CheckExact:int:::
|
| 2353 |
+
PyUnicode_CheckExact:PyObject*:o:0:
|
| 2354 |
+
|
| 2355 |
+
PyUnicode_DATA:void*:::
|
| 2356 |
+
PyUnicode_DATA:PyObject*:o:0:
|
| 2357 |
+
|
| 2358 |
+
PyUnicode_GET_LENGTH:Py_ssize_t:::
|
| 2359 |
+
PyUnicode_GET_LENGTH:PyObject*:o:0:
|
| 2360 |
+
|
| 2361 |
+
PyUnicode_GET_SIZE:Py_ssize_t:::
|
| 2362 |
+
PyUnicode_GET_SIZE:PyObject*:o:0:
|
| 2363 |
+
|
| 2364 |
+
PyUnicode_GET_DATA_SIZE:Py_ssize_t:::
|
| 2365 |
+
PyUnicode_GET_DATA_SIZE:PyObject*:o:0:
|
| 2366 |
+
|
| 2367 |
+
PyUnicode_KIND:int:::
|
| 2368 |
+
PyUnicode_KIND:PyObject*:o:0:
|
| 2369 |
+
|
| 2370 |
+
PyUnicode_MAX_CHAR_VALUE::::
|
| 2371 |
+
PyUnicode_MAX_CHAR_VALUE:PyObject*:o:0:
|
| 2372 |
+
|
| 2373 |
+
PyUnicode_AS_UNICODE:Py_UNICODE*:::
|
| 2374 |
+
PyUnicode_AS_UNICODE:PyObject*:o:0:
|
| 2375 |
+
|
| 2376 |
+
PyUnicode_AS_DATA:const char*:::
|
| 2377 |
+
PyUnicode_AS_DATA:PyObject*:o:0:
|
| 2378 |
+
|
| 2379 |
+
Py_UNICODE_ISALNUM:int:::
|
| 2380 |
+
Py_UNICODE_ISALNUM:Py_UNICODE:ch::
|
| 2381 |
+
|
| 2382 |
+
Py_UNICODE_ISALPHA:int:::
|
| 2383 |
+
Py_UNICODE_ISALPHA:Py_UNICODE:ch::
|
| 2384 |
+
|
| 2385 |
+
Py_UNICODE_ISSPACE:int:::
|
| 2386 |
+
Py_UNICODE_ISSPACE:Py_UNICODE:ch::
|
| 2387 |
+
|
| 2388 |
+
Py_UNICODE_ISLOWER:int:::
|
| 2389 |
+
Py_UNICODE_ISLOWER:Py_UNICODE:ch::
|
| 2390 |
+
|
| 2391 |
+
Py_UNICODE_ISUPPER:int:::
|
| 2392 |
+
Py_UNICODE_ISUPPER:Py_UNICODE:ch::
|
| 2393 |
+
|
| 2394 |
+
Py_UNICODE_ISTITLE:int:::
|
| 2395 |
+
Py_UNICODE_ISTITLE:Py_UNICODE:ch::
|
| 2396 |
+
|
| 2397 |
+
Py_UNICODE_ISLINEBREAK:int:::
|
| 2398 |
+
Py_UNICODE_ISLINEBREAK:Py_UNICODE:ch::
|
| 2399 |
+
|
| 2400 |
+
Py_UNICODE_ISDECIMAL:int:::
|
| 2401 |
+
Py_UNICODE_ISDECIMAL:Py_UNICODE:ch::
|
| 2402 |
+
|
| 2403 |
+
Py_UNICODE_ISDIGIT:int:::
|
| 2404 |
+
Py_UNICODE_ISDIGIT:Py_UNICODE:ch::
|
| 2405 |
+
|
| 2406 |
+
Py_UNICODE_ISNUMERIC:int:::
|
| 2407 |
+
Py_UNICODE_ISNUMERIC:Py_UNICODE:ch::
|
| 2408 |
+
|
| 2409 |
+
Py_UNICODE_ISPRINTABLE:int:::
|
| 2410 |
+
Py_UNICODE_ISPRINTABLE:Py_UNICODE:ch::
|
| 2411 |
+
|
| 2412 |
+
Py_UNICODE_TOLOWER:Py_UNICODE:::
|
| 2413 |
+
Py_UNICODE_TOLOWER:Py_UNICODE:ch::
|
| 2414 |
+
|
| 2415 |
+
Py_UNICODE_TOUPPER:Py_UNICODE:::
|
| 2416 |
+
Py_UNICODE_TOUPPER:Py_UNICODE:ch::
|
| 2417 |
+
|
| 2418 |
+
Py_UNICODE_TOTITLE:Py_UNICODE:::
|
| 2419 |
+
Py_UNICODE_TOTITLE:Py_UNICODE:ch::
|
| 2420 |
+
|
| 2421 |
+
Py_UNICODE_TODECIMAL:int:::
|
| 2422 |
+
Py_UNICODE_TODECIMAL:Py_UNICODE:ch::
|
| 2423 |
+
|
| 2424 |
+
Py_UNICODE_TODIGIT:int:::
|
| 2425 |
+
Py_UNICODE_TODIGIT:Py_UNICODE:ch::
|
| 2426 |
+
|
| 2427 |
+
Py_UNICODE_TONUMERIC:double:::
|
| 2428 |
+
Py_UNICODE_TONUMERIC:Py_UNICODE:ch::
|
| 2429 |
+
|
| 2430 |
+
PyUnicode_FromUnicode:PyObject*::+1:
|
| 2431 |
+
PyUnicode_FromUnicode:const Py_UNICODE*:u::
|
| 2432 |
+
PyUnicode_FromUnicode:Py_ssize_t:size::
|
| 2433 |
+
|
| 2434 |
+
PyUnicode_AsUnicode:Py_UNICODE*:::
|
| 2435 |
+
PyUnicode_AsUnicode:PyObject*:unicode:0:
|
| 2436 |
+
|
| 2437 |
+
PyUnicode_TransformDecimalToASCII:PyObject*::+1:
|
| 2438 |
+
PyUnicode_TransformDecimalToASCII:Py_UNICODE*:s::
|
| 2439 |
+
PyUnicode_TransformDecimalToASCII:Py_ssize_t:size::
|
| 2440 |
+
|
| 2441 |
+
PyUnicode_AsUnicodeAndSize:Py_UNICODE*:::
|
| 2442 |
+
PyUnicode_AsUnicodeAndSize:PyObject*:unicode:0:
|
| 2443 |
+
PyUnicode_AsUnicodeAndSize:Py_ssize_t*:size::
|
| 2444 |
+
|
| 2445 |
+
PyUnicode_AsUnicodeCopy:Py_UNICODE*:::
|
| 2446 |
+
PyUnicode_AsUnicodeCopy:PyObject*:unicode:0:
|
| 2447 |
+
|
| 2448 |
+
PyUnicode_GetSize:Py_ssize_t:::
|
| 2449 |
+
PyUnicode_GetSize:PyObject*:unicode:0:
|
| 2450 |
+
|
| 2451 |
+
PyUnicode_FromObject:PyObject*::+1:
|
| 2452 |
+
PyUnicode_FromObject:PyObject*:obj:0:
|
| 2453 |
+
|
| 2454 |
+
PyUnicode_FromEncodedObject:PyObject*::+1:
|
| 2455 |
+
PyUnicode_FromEncodedObject:PyObject*:obj:0:
|
| 2456 |
+
PyUnicode_FromEncodedObject:const char*:encoding::
|
| 2457 |
+
PyUnicode_FromEncodedObject:const char*:errors::
|
| 2458 |
+
|
| 2459 |
+
PyUnicode_FromWideChar:PyObject*::+1:
|
| 2460 |
+
PyUnicode_FromWideChar:const wchar_t*:w::
|
| 2461 |
+
PyUnicode_FromWideChar:Py_ssize_t:size::
|
| 2462 |
+
|
| 2463 |
+
PyUnicode_AsWideChar:Py_ssize_t:::
|
| 2464 |
+
PyUnicode_AsWideChar:PyObject*:*unicode:0:
|
| 2465 |
+
PyUnicode_AsWideChar:wchar_t*:w::
|
| 2466 |
+
PyUnicode_AsWideChar:Py_ssize_t:size::
|
| 2467 |
+
|
| 2468 |
+
PyUnicode_AsWideCharString:wchar_t*:::
|
| 2469 |
+
PyUnicode_AsWideCharString:PyObject*:unicode:0:
|
| 2470 |
+
PyUnicode_AsWideCharString:Py_ssize_t*:size::
|
| 2471 |
+
|
| 2472 |
+
PyUnicode_Decode:PyObject*::+1:
|
| 2473 |
+
PyUnicode_Decode:const char*:s::
|
| 2474 |
+
PyUnicode_Decode:Py_ssize_t:size::
|
| 2475 |
+
PyUnicode_Decode:const char*:encoding::
|
| 2476 |
+
PyUnicode_Decode:const char*:errors::
|
| 2477 |
+
|
| 2478 |
+
PyUnicode_DecodeUTF16Stateful:PyObject*::+1:
|
| 2479 |
+
PyUnicode_DecodeUTF16Stateful:const char*:s::
|
| 2480 |
+
PyUnicode_DecodeUTF16Stateful:Py_ssize_t:size::
|
| 2481 |
+
PyUnicode_DecodeUTF16Stateful:const char*:errors::
|
| 2482 |
+
PyUnicode_DecodeUTF16Stateful:int*:byteorder::
|
| 2483 |
+
PyUnicode_DecodeUTF16Stateful:Py_ssize_t*:consumed::
|
| 2484 |
+
|
| 2485 |
+
PyUnicode_DecodeUTF8Stateful:PyObject*::+1:
|
| 2486 |
+
PyUnicode_DecodeUTF8Stateful:const char*:s::
|
| 2487 |
+
PyUnicode_DecodeUTF8Stateful:Py_ssize_t:size::
|
| 2488 |
+
PyUnicode_DecodeUTF8Stateful:const char*:errors::
|
| 2489 |
+
PyUnicode_DecodeUTF8Stateful:Py_ssize_t*:consumed::
|
| 2490 |
+
|
| 2491 |
+
PyUnicode_Encode:PyObject*::+1:
|
| 2492 |
+
PyUnicode_Encode:const Py_UNICODE*:s::
|
| 2493 |
+
PyUnicode_Encode:Py_ssize_t:size::
|
| 2494 |
+
PyUnicode_Encode:const char*:encoding::
|
| 2495 |
+
PyUnicode_Encode:const char*:errors::
|
| 2496 |
+
|
| 2497 |
+
PyUnicode_AsEncodedString:PyObject*::+1:
|
| 2498 |
+
PyUnicode_AsEncodedString:PyObject*:unicode:0:
|
| 2499 |
+
PyUnicode_AsEncodedString:const char*:encoding::
|
| 2500 |
+
PyUnicode_AsEncodedString:const char*:errors::
|
| 2501 |
+
|
| 2502 |
+
PyUnicode_DecodeUTF7:PyObject*::+1:
|
| 2503 |
+
PyUnicode_DecodeUTF7:const char*:s::
|
| 2504 |
+
PyUnicode_DecodeUTF7:Py_ssize_t:size::
|
| 2505 |
+
PyUnicode_DecodeUTF7:const char*:errors::
|
| 2506 |
+
|
| 2507 |
+
PyUnicode_DecodeUTF7Stateful:PyObject*::+1:
|
| 2508 |
+
PyUnicode_DecodeUTF7Stateful:const char*:s::
|
| 2509 |
+
PyUnicode_DecodeUTF7Stateful:Py_ssize_t:size::
|
| 2510 |
+
PyUnicode_DecodeUTF7Stateful:const char*:errors::
|
| 2511 |
+
PyUnicode_DecodeUTF7Stateful:Py_ssize_t*:consumed::
|
| 2512 |
+
|
| 2513 |
+
PyUnicode_EncodeUTF7:PyObject*::+1:
|
| 2514 |
+
PyUnicode_EncodeUTF7:const Py_UNICODE*:s::
|
| 2515 |
+
PyUnicode_EncodeUTF7:Py_ssize_t:size::
|
| 2516 |
+
PyUnicode_EncodeUTF7:int:base64SetO::
|
| 2517 |
+
PyUnicode_EncodeUTF7:int:base64WhiteSpace::
|
| 2518 |
+
PyUnicode_EncodeUTF7:const char*:errors::
|
| 2519 |
+
|
| 2520 |
+
PyUnicode_DecodeUTF8:PyObject*::+1:
|
| 2521 |
+
PyUnicode_DecodeUTF8:const char*:s::
|
| 2522 |
+
PyUnicode_DecodeUTF8:Py_ssize_t:size::
|
| 2523 |
+
PyUnicode_DecodeUTF8:const char*:errors::
|
| 2524 |
+
|
| 2525 |
+
PyUnicode_EncodeUTF8:PyObject*::+1:
|
| 2526 |
+
PyUnicode_EncodeUTF8:const Py_UNICODE*:s::
|
| 2527 |
+
PyUnicode_EncodeUTF8:Py_ssize_t:size::
|
| 2528 |
+
PyUnicode_EncodeUTF8:const char*:errors::
|
| 2529 |
+
|
| 2530 |
+
PyUnicode_AsUTF8String:PyObject*::+1:
|
| 2531 |
+
PyUnicode_AsUTF8String:PyObject*:unicode:0:
|
| 2532 |
+
|
| 2533 |
+
PyUnicode_AsUTF8AndSize:const char*:::
|
| 2534 |
+
PyUnicode_AsUTF8AndSize:PyObject*:unicode:0:
|
| 2535 |
+
PyUnicode_AsUTF8AndSize:Py_ssize_t*:size:0:
|
| 2536 |
+
|
| 2537 |
+
PyUnicode_AsUTF8:const char*:::
|
| 2538 |
+
PyUnicode_AsUTF8:PyObject*:unicode:0:
|
| 2539 |
+
|
| 2540 |
+
PyUnicode_DecodeUTF16:PyObject*::+1:
|
| 2541 |
+
PyUnicode_DecodeUTF16:const char*:s::
|
| 2542 |
+
PyUnicode_DecodeUTF16:Py_ssize_t:size::
|
| 2543 |
+
PyUnicode_DecodeUTF16:const char*:errors::
|
| 2544 |
+
PyUnicode_DecodeUTF16:int*:byteorder::
|
| 2545 |
+
|
| 2546 |
+
PyUnicode_EncodeUTF16:PyObject*::+1:
|
| 2547 |
+
PyUnicode_EncodeUTF16:const Py_UNICODE*:s::
|
| 2548 |
+
PyUnicode_EncodeUTF16:Py_ssize_t:size::
|
| 2549 |
+
PyUnicode_EncodeUTF16:const char*:errors::
|
| 2550 |
+
PyUnicode_EncodeUTF16:int:byteorder::
|
| 2551 |
+
|
| 2552 |
+
PyUnicode_AsUTF16String:PyObject*::+1:
|
| 2553 |
+
PyUnicode_AsUTF16String:PyObject*:unicode:0:
|
| 2554 |
+
|
| 2555 |
+
PyUnicode_DecodeUTF32:PyObject*::+1:
|
| 2556 |
+
PyUnicode_DecodeUTF32:const char*:s::
|
| 2557 |
+
PyUnicode_DecodeUTF32:Py_ssize_t:size::
|
| 2558 |
+
PyUnicode_DecodeUTF32:const char*:errors::
|
| 2559 |
+
PyUnicode_DecodeUTF32:int*:byteorder::
|
| 2560 |
+
|
| 2561 |
+
PyUnicode_DecodeUTF32Stateful:PyObject*::+1:
|
| 2562 |
+
PyUnicode_DecodeUTF32Stateful:const char*:s::
|
| 2563 |
+
PyUnicode_DecodeUTF32Stateful:Py_ssize_t:size::
|
| 2564 |
+
PyUnicode_DecodeUTF32Stateful:const char*:errors::
|
| 2565 |
+
PyUnicode_DecodeUTF32Stateful:int*:byteorder::
|
| 2566 |
+
PyUnicode_DecodeUTF32Stateful:Py_ssize_t*:consumed::
|
| 2567 |
+
|
| 2568 |
+
PyUnicode_AsUTF32String:PyObject*::+1:
|
| 2569 |
+
PyUnicode_AsUTF32String:PyObject*:unicode:0:
|
| 2570 |
+
|
| 2571 |
+
PyUnicode_EncodeUTF32:PyObject*::+1:
|
| 2572 |
+
PyUnicode_EncodeUTF32:const Py_UNICODE*:s::
|
| 2573 |
+
PyUnicode_EncodeUTF32:Py_ssize_t:size::
|
| 2574 |
+
PyUnicode_EncodeUTF32:const char*:errors::
|
| 2575 |
+
PyUnicode_EncodeUTF32:int:byteorder::
|
| 2576 |
+
|
| 2577 |
+
PyUnicode_DecodeUnicodeEscape:PyObject*::+1:
|
| 2578 |
+
PyUnicode_DecodeUnicodeEscape:const char*:s::
|
| 2579 |
+
PyUnicode_DecodeUnicodeEscape:Py_ssize_t:size::
|
| 2580 |
+
PyUnicode_DecodeUnicodeEscape:const char*:errors::
|
| 2581 |
+
|
| 2582 |
+
PyUnicode_EncodeUnicodeEscape:PyObject*::+1:
|
| 2583 |
+
PyUnicode_EncodeUnicodeEscape:const Py_UNICODE*:s::
|
| 2584 |
+
PyUnicode_EncodeUnicodeEscape:Py_ssize_t:size::
|
| 2585 |
+
|
| 2586 |
+
PyUnicode_AsUnicodeEscapeString:PyObject*::+1:
|
| 2587 |
+
PyUnicode_AsUnicodeEscapeString:PyObject*:unicode:0:
|
| 2588 |
+
|
| 2589 |
+
PyUnicode_DecodeRawUnicodeEscape:PyObject*::+1:
|
| 2590 |
+
PyUnicode_DecodeRawUnicodeEscape:const char*:s::
|
| 2591 |
+
PyUnicode_DecodeRawUnicodeEscape:Py_ssize_t:size::
|
| 2592 |
+
PyUnicode_DecodeRawUnicodeEscape:const char*:errors::
|
| 2593 |
+
|
| 2594 |
+
PyUnicode_EncodeRawUnicodeEscape:PyObject*::+1:
|
| 2595 |
+
PyUnicode_EncodeRawUnicodeEscape:const Py_UNICODE*:s::
|
| 2596 |
+
PyUnicode_EncodeRawUnicodeEscape:Py_ssize_t:size::
|
| 2597 |
+
|
| 2598 |
+
PyUnicode_AsRawUnicodeEscapeString:PyObject*::+1:
|
| 2599 |
+
PyUnicode_AsRawUnicodeEscapeString:PyObject*:unicode:0:
|
| 2600 |
+
|
| 2601 |
+
PyUnicode_DecodeLatin1:PyObject*::+1:
|
| 2602 |
+
PyUnicode_DecodeLatin1:const char*:s::
|
| 2603 |
+
PyUnicode_DecodeLatin1:Py_ssize_t:size::
|
| 2604 |
+
PyUnicode_DecodeLatin1:const char*:errors::
|
| 2605 |
+
|
| 2606 |
+
PyUnicode_EncodeLatin1:PyObject*::+1:
|
| 2607 |
+
PyUnicode_EncodeLatin1:const Py_UNICODE*:s::
|
| 2608 |
+
PyUnicode_EncodeLatin1:Py_ssize_t:size::
|
| 2609 |
+
PyUnicode_EncodeLatin1:const char*:errors::
|
| 2610 |
+
|
| 2611 |
+
PyUnicode_AsLatin1String:PyObject*::+1:
|
| 2612 |
+
PyUnicode_AsLatin1String:PyObject*:unicode:0:
|
| 2613 |
+
|
| 2614 |
+
PyUnicode_DecodeASCII:PyObject*::+1:
|
| 2615 |
+
PyUnicode_DecodeASCII:const char*:s::
|
| 2616 |
+
PyUnicode_DecodeASCII:Py_ssize_t:size::
|
| 2617 |
+
PyUnicode_DecodeASCII:const char*:errors::
|
| 2618 |
+
|
| 2619 |
+
PyUnicode_EncodeASCII:PyObject*::+1:
|
| 2620 |
+
PyUnicode_EncodeASCII:const Py_UNICODE*:s::
|
| 2621 |
+
PyUnicode_EncodeASCII:Py_ssize_t:size::
|
| 2622 |
+
PyUnicode_EncodeASCII:const char*:errors::
|
| 2623 |
+
|
| 2624 |
+
PyUnicode_AsASCIIString:PyObject*::+1:
|
| 2625 |
+
PyUnicode_AsASCIIString:PyObject*:unicode:0:
|
| 2626 |
+
|
| 2627 |
+
PyUnicode_DecodeCharmap:PyObject*::+1:
|
| 2628 |
+
PyUnicode_DecodeCharmap:const char*:s::
|
| 2629 |
+
PyUnicode_DecodeCharmap:Py_ssize_t:size::
|
| 2630 |
+
PyUnicode_DecodeCharmap:PyObject*:mapping:0:
|
| 2631 |
+
PyUnicode_DecodeCharmap:const char*:errors::
|
| 2632 |
+
|
| 2633 |
+
PyUnicode_EncodeCharmap:PyObject*::+1:
|
| 2634 |
+
PyUnicode_EncodeCharmap:const Py_UNICODE*:s::
|
| 2635 |
+
PyUnicode_EncodeCharmap:Py_ssize_t:size::
|
| 2636 |
+
PyUnicode_EncodeCharmap:PyObject*:mapping:0:
|
| 2637 |
+
PyUnicode_EncodeCharmap:const char*:errors::
|
| 2638 |
+
|
| 2639 |
+
PyUnicode_AsCharmapString:PyObject*::+1:
|
| 2640 |
+
PyUnicode_AsCharmapString:PyObject*:unicode:0:
|
| 2641 |
+
PyUnicode_AsCharmapString:PyObject*:mapping:0:
|
| 2642 |
+
|
| 2643 |
+
PyUnicode_TranslateCharmap:PyObject*::+1:
|
| 2644 |
+
PyUnicode_TranslateCharmap:const Py_UNICODE*:s::
|
| 2645 |
+
PyUnicode_TranslateCharmap:Py_ssize_t:size::
|
| 2646 |
+
PyUnicode_TranslateCharmap:PyObject*:mapping:0:
|
| 2647 |
+
PyUnicode_TranslateCharmap:const char*:errors::
|
| 2648 |
+
|
| 2649 |
+
PyUnicode_DecodeMBCS:PyObject*::+1:
|
| 2650 |
+
PyUnicode_DecodeMBCS:const char*:s::
|
| 2651 |
+
PyUnicode_DecodeMBCS:Py_ssize_t:size::
|
| 2652 |
+
PyUnicode_DecodeMBCS:const char*:errors::
|
| 2653 |
+
|
| 2654 |
+
PyUnicode_DecodeMBCSStateful:PyObject*::+1:
|
| 2655 |
+
PyUnicode_DecodeMBCSStateful:const char*:s::
|
| 2656 |
+
PyUnicode_DecodeMBCSStateful:Py_ssize_t:size::
|
| 2657 |
+
PyUnicode_DecodeMBCSStateful:const char*:errors::
|
| 2658 |
+
PyUnicode_DecodeMBCSStateful:Py_ssize_t*:consumed::
|
| 2659 |
+
|
| 2660 |
+
PyUnicode_EncodeCodePage:PyObject*::+1:
|
| 2661 |
+
PyUnicode_EncodeCodePage:int:code_page::
|
| 2662 |
+
PyUnicode_EncodeCodePage:PyObject*:unicode:0:
|
| 2663 |
+
PyUnicode_EncodeCodePage:const char*:errors::
|
| 2664 |
+
|
| 2665 |
+
PyUnicode_EncodeMBCS:PyObject*::+1:
|
| 2666 |
+
PyUnicode_EncodeMBCS:const Py_UNICODE*:s::
|
| 2667 |
+
PyUnicode_EncodeMBCS:Py_ssize_t:size::
|
| 2668 |
+
PyUnicode_EncodeMBCS:const char*:errors::
|
| 2669 |
+
|
| 2670 |
+
PyUnicode_AsMBCSString:PyObject*::+1:
|
| 2671 |
+
PyUnicode_AsMBCSString:PyObject*:unicode:0:
|
| 2672 |
+
|
| 2673 |
+
PyUnicode_Concat:PyObject*::+1:
|
| 2674 |
+
PyUnicode_Concat:PyObject*:left:0:
|
| 2675 |
+
PyUnicode_Concat:PyObject*:right:0:
|
| 2676 |
+
|
| 2677 |
+
PyUnicode_Split:PyObject*::+1:
|
| 2678 |
+
PyUnicode_Split:PyObject*:left:0:
|
| 2679 |
+
PyUnicode_Split:PyObject*:right:0:
|
| 2680 |
+
PyUnicode_Split:Py_ssize_t:maxsplit::
|
| 2681 |
+
|
| 2682 |
+
PyUnicode_Splitlines:PyObject*::+1:
|
| 2683 |
+
PyUnicode_Splitlines:PyObject*:s:0:
|
| 2684 |
+
PyUnicode_Splitlines:int:keepend::
|
| 2685 |
+
|
| 2686 |
+
PyUnicode_Translate:PyObject*::+1:
|
| 2687 |
+
PyUnicode_Translate:PyObject*:str:0:
|
| 2688 |
+
PyUnicode_Translate:PyObject*:table:0:
|
| 2689 |
+
PyUnicode_Translate:const char*:errors::
|
| 2690 |
+
|
| 2691 |
+
PyUnicode_Join:PyObject*::+1:
|
| 2692 |
+
PyUnicode_Join:PyObject*:separator:0:
|
| 2693 |
+
PyUnicode_Join:PyObject*:seq:0:
|
| 2694 |
+
|
| 2695 |
+
PyUnicode_Tailmatch:Py_ssize_t:::
|
| 2696 |
+
PyUnicode_Tailmatch:PyObject*:str:0:
|
| 2697 |
+
PyUnicode_Tailmatch:PyObject*:substr:0:
|
| 2698 |
+
PyUnicode_Tailmatch:Py_ssize_t:start::
|
| 2699 |
+
PyUnicode_Tailmatch:Py_ssize_t:end::
|
| 2700 |
+
PyUnicode_Tailmatch:int:direction::
|
| 2701 |
+
|
| 2702 |
+
PyUnicode_Find:Py_ssize_t:::
|
| 2703 |
+
PyUnicode_Find:PyObject*:str:0:
|
| 2704 |
+
PyUnicode_Find:PyObject*:substr:0:
|
| 2705 |
+
PyUnicode_Find:Py_ssize_t:start::
|
| 2706 |
+
PyUnicode_Find:Py_ssize_t:end::
|
| 2707 |
+
PyUnicode_Find:int:direction::
|
| 2708 |
+
|
| 2709 |
+
PyUnicode_FindChar:Py_ssize_t:::
|
| 2710 |
+
PyUnicode_FindChar:PyObject*:str:0:
|
| 2711 |
+
PyUnicode_FindChar:Py_UCS4:ch::
|
| 2712 |
+
PyUnicode_FindChar:Py_ssize_t:start::
|
| 2713 |
+
PyUnicode_FindChar:Py_ssize_t:end::
|
| 2714 |
+
PyUnicode_FindChar:int:direction::
|
| 2715 |
+
|
| 2716 |
+
PyUnicode_Count:Py_ssize_t:::
|
| 2717 |
+
PyUnicode_Count:PyObject*:str:0:
|
| 2718 |
+
PyUnicode_Count:PyObject*:substr:0:
|
| 2719 |
+
PyUnicode_Count:Py_ssize_t:start::
|
| 2720 |
+
PyUnicode_Count:Py_ssize_t:end::
|
| 2721 |
+
|
| 2722 |
+
PyUnicode_Replace:PyObject*::+1:
|
| 2723 |
+
PyUnicode_Replace:PyObject*:str:0:
|
| 2724 |
+
PyUnicode_Replace:PyObject*:substr:0:
|
| 2725 |
+
PyUnicode_Replace:PyObject*:replstr:0:
|
| 2726 |
+
PyUnicode_Replace:Py_ssize_t:maxcount::
|
| 2727 |
+
|
| 2728 |
+
PyUnicode_Compare:int:::
|
| 2729 |
+
PyUnicode_Compare:PyObject*:left:0:
|
| 2730 |
+
PyUnicode_Compare:PyObject*:right:0:
|
| 2731 |
+
|
| 2732 |
+
PyUnicode_CompareWithASCIIString:int:::
|
| 2733 |
+
PyUnicode_CompareWithASCIIString:PyObject*:uni:0:
|
| 2734 |
+
PyUnicode_CompareWithASCIIString:const char*:string::
|
| 2735 |
+
|
| 2736 |
+
PyUnicode_RichCompare:PyObject*::+1:
|
| 2737 |
+
PyUnicode_RichCompare:PyObject*:left:0:
|
| 2738 |
+
PyUnicode_RichCompare:PyObject*:right:0:
|
| 2739 |
+
PyUnicode_RichCompare:int:op::
|
| 2740 |
+
|
| 2741 |
+
PyUnicode_Format:PyObject*::+1:
|
| 2742 |
+
PyUnicode_Format:PyObject*:format:0:
|
| 2743 |
+
PyUnicode_Format:PyObject*:args:0:
|
| 2744 |
+
|
| 2745 |
+
PyUnicode_Contains:int:::
|
| 2746 |
+
PyUnicode_Contains:PyObject*:container:0:
|
| 2747 |
+
PyUnicode_Contains:PyObject*:element:0:
|
| 2748 |
+
|
| 2749 |
+
PyUnicode_InternInPlace:void:::
|
| 2750 |
+
PyUnicode_InternInPlace:PyObject**:string:+1:
|
| 2751 |
+
|
| 2752 |
+
PyUnicode_InternFromString:PyObject*::+1:
|
| 2753 |
+
PyUnicode_InternFromString:const char*:v::
|
| 2754 |
+
|
| 2755 |
+
PyUnicode_New:PyObject*::+1:
|
| 2756 |
+
PyUnicode_New:Py_ssize_t:size::
|
| 2757 |
+
PyUnicode_New:Py_UCS4:maxchar::
|
| 2758 |
+
|
| 2759 |
+
PyUnicode_FromKindAndData:PyObject*::+1:
|
| 2760 |
+
PyUnicode_FromKindAndData:int:kind::
|
| 2761 |
+
PyUnicode_FromKindAndData:const void*:buffer::
|
| 2762 |
+
PyUnicode_FromKindAndData:Py_ssize_t:size::
|
| 2763 |
+
|
| 2764 |
+
PyUnicode_FromStringAndSize:PyObject*::+1:
|
| 2765 |
+
PyUnicode_FromStringAndSize:const char*:u::
|
| 2766 |
+
PyUnicode_FromStringAndSize:Py_ssize_t:size::
|
| 2767 |
+
|
| 2768 |
+
PyUnicode_FromString:PyObject*::+1:
|
| 2769 |
+
PyUnicode_FromString:const char*:u::
|
| 2770 |
+
|
| 2771 |
+
PyUnicode_FromFormat:PyObject*::+1:
|
| 2772 |
+
PyUnicode_FromFormat:const char*:format::
|
| 2773 |
+
PyUnicode_FromFormat::...::
|
| 2774 |
+
|
| 2775 |
+
PyUnicode_FromFormatV:PyObject*::+1:
|
| 2776 |
+
PyUnicode_FromFormatV:const char*:format::
|
| 2777 |
+
PyUnicode_FromFormatV:va_list:args::
|
| 2778 |
+
|
| 2779 |
+
PyUnicode_GetLength:Py_ssize_t:::
|
| 2780 |
+
PyUnicode_GetLength:PyObject*:unicode:0:
|
| 2781 |
+
|
| 2782 |
+
PyUnicode_CopyCharacters:Py_ssize_t:::
|
| 2783 |
+
PyUnicode_CopyCharacters:PyObject*:to:0:
|
| 2784 |
+
PyUnicode_CopyCharacters:Py_ssize_t:to_start::
|
| 2785 |
+
PyUnicode_CopyCharacters:PyObject*:from:0:
|
| 2786 |
+
PyUnicode_CopyCharacters:Py_ssize_t:from_start::
|
| 2787 |
+
PyUnicode_CopyCharacters:Py_ssize_t:how_many::
|
| 2788 |
+
|
| 2789 |
+
PyUnicode_Fill:Py_ssize_t:::
|
| 2790 |
+
PyUnicode_Fill:PyObject*:unicode:0:
|
| 2791 |
+
PyUnicode_Fill:Py_ssize_t:start::
|
| 2792 |
+
PyUnicode_Fill:Py_ssize_t:length::
|
| 2793 |
+
PyUnicode_Fill:Py_UCS4:fill_char::
|
| 2794 |
+
|
| 2795 |
+
PyUnicode_READ:Py_UCS4:::
|
| 2796 |
+
PyUnicode_READ:int:kind::
|
| 2797 |
+
PyUnicode_READ:void*:data::
|
| 2798 |
+
PyUnicode_READ:Py_ssize_t:index::
|
| 2799 |
+
|
| 2800 |
+
PyUnicode_READ_CHAR:Py_UCS4:::
|
| 2801 |
+
PyUnicode_READ_CHAR:PyObject*:o:0:
|
| 2802 |
+
PyUnicode_READ_CHAR:Py_ssize_t:index::
|
| 2803 |
+
|
| 2804 |
+
PyUnicode_ReadChar:Py_UCS4:::
|
| 2805 |
+
PyUnicode_ReadChar:PyObject*:unicode:0:
|
| 2806 |
+
PyUnicode_ReadChar:Py_ssize_t:index::
|
| 2807 |
+
|
| 2808 |
+
PyUnicode_WRITE:void:::
|
| 2809 |
+
PyUnicode_WRITE:int:kind::
|
| 2810 |
+
PyUnicode_WRITE:void*:data::
|
| 2811 |
+
PyUnicode_WRITE:Py_ssize_t:index::
|
| 2812 |
+
PyUnicode_WRITE:Py_UCS4:value::
|
| 2813 |
+
|
| 2814 |
+
PyUnicode_WriteChar:int:::
|
| 2815 |
+
PyUnicode_WriteChar:PyObject*:unicode:0:
|
| 2816 |
+
PyUnicode_WriteChar:Py_ssize_t:index::
|
| 2817 |
+
PyUnicode_WriteChar:Py_UCS4:character::
|
| 2818 |
+
|
| 2819 |
+
PyUnicode_READY:int:::
|
| 2820 |
+
PyUnicode_READY:PyObject*:o:0:
|
| 2821 |
+
|
| 2822 |
+
PyUnicode_Substring:PyObject*::+1:
|
| 2823 |
+
PyUnicode_Substring:PyObject*:str:0:
|
| 2824 |
+
PyUnicode_Substring:Py_ssize_t:start::
|
| 2825 |
+
PyUnicode_Substring:Py_ssize_t:end::
|
| 2826 |
+
|
| 2827 |
+
PyUnicode_AsUCS4:Py_UCS4*:::
|
| 2828 |
+
PyUnicode_AsUCS4:PyObject*:u:0:
|
| 2829 |
+
PyUnicode_AsUCS4:Py_UCS4*:buffer::
|
| 2830 |
+
PyUnicode_AsUCS4:Py_ssize_t:buflen::
|
| 2831 |
+
PyUnicode_AsUCS4:int:copy_null::
|
| 2832 |
+
|
| 2833 |
+
PyUnicode_AsUCS4Copy:Py_UCS4*:::
|
| 2834 |
+
PyUnicode_AsUCS4Copy:PyObject*:u:0:
|
| 2835 |
+
|
| 2836 |
+
PyUnicode_DecodeLocaleAndSize:PyObject*::+1:
|
| 2837 |
+
PyUnicode_DecodeLocaleAndSize:const char*:str::
|
| 2838 |
+
PyUnicode_DecodeLocaleAndSize:Py_ssize_t:len::
|
| 2839 |
+
PyUnicode_DecodeLocaleAndSize:const char*:errors::
|
| 2840 |
+
|
| 2841 |
+
PyUnicode_DecodeLocale:PyObject*::+1:
|
| 2842 |
+
PyUnicode_DecodeLocale:const char*:str::
|
| 2843 |
+
PyUnicode_DecodeLocale:const char*:errors::
|
| 2844 |
+
|
| 2845 |
+
PyUnicode_EncodeLocale:PyObject*::+1:
|
| 2846 |
+
PyUnicode_EncodeLocale:PyObject*:unicode:0:
|
| 2847 |
+
PyUnicode_EncodeLocale:const char*:errors::
|
| 2848 |
+
|
| 2849 |
+
PyUnicode_FSConverter:int:::
|
| 2850 |
+
PyUnicode_FSConverter:PyObject*:obj:0:
|
| 2851 |
+
PyUnicode_FSConverter:void*:result::
|
| 2852 |
+
|
| 2853 |
+
PyUnicode_FSDecoder:int:::
|
| 2854 |
+
PyUnicode_FSDecoder:PyObject*:obj:0:
|
| 2855 |
+
PyUnicode_FSDecoder:void*:result::
|
| 2856 |
+
|
| 2857 |
+
PyUnicode_DecodeFSDefaultAndSize:PyObject*::+1:
|
| 2858 |
+
PyUnicode_DecodeFSDefaultAndSize:const char*:s::
|
| 2859 |
+
PyUnicode_DecodeFSDefaultAndSize:Py_ssize_t:size::
|
| 2860 |
+
|
| 2861 |
+
PyUnicode_DecodeFSDefault:PyObject*::+1:
|
| 2862 |
+
PyUnicode_DecodeFSDefault:const char*:s::
|
| 2863 |
+
|
| 2864 |
+
PyUnicode_EncodeFSDefault:PyObject*::+1:
|
| 2865 |
+
PyUnicode_EncodeFSDefault:PyObject*:unicode:0:
|
| 2866 |
+
|
| 2867 |
+
PyUnicodeDecodeError_Create:PyObject*::+1:
|
| 2868 |
+
PyUnicodeDecodeError_Create:const char*:encoding::
|
| 2869 |
+
PyUnicodeDecodeError_Create:const char*:object::
|
| 2870 |
+
PyUnicodeDecodeError_Create:Py_ssize_t:length::
|
| 2871 |
+
PyUnicodeDecodeError_Create:Py_ssize_t:start::
|
| 2872 |
+
PyUnicodeDecodeError_Create:Py_ssize_t:end::
|
| 2873 |
+
PyUnicodeDecodeError_Create:const char*:reason::
|
| 2874 |
+
|
| 2875 |
+
PyUnicodeDecodeError_GetEncoding:PyObject*::+1:
|
| 2876 |
+
PyUnicodeDecodeError_GetEncoding:PyObject*:exc:0:
|
| 2877 |
+
|
| 2878 |
+
PyUnicodeDecodeError_GetEnd:Py_ssize_t:::
|
| 2879 |
+
PyUnicodeDecodeError_GetEnd:PyObject*:exc:0:
|
| 2880 |
+
PyUnicodeDecodeError_GetEnd:Py_ssize_t*:end::
|
| 2881 |
+
|
| 2882 |
+
PyUnicodeDecodeError_GetObject:PyObject*::+1:
|
| 2883 |
+
PyUnicodeDecodeError_GetObject:PyObject*:exc:0:
|
| 2884 |
+
|
| 2885 |
+
PyUnicodeDecodeError_GetReason:PyObject*::+1:
|
| 2886 |
+
PyUnicodeDecodeError_GetReason:PyObject*:exc:0:
|
| 2887 |
+
|
| 2888 |
+
PyUnicodeDecodeError_GetStart:Py_ssize_t:::
|
| 2889 |
+
PyUnicodeDecodeError_GetStart:PyObject*:exc:0:
|
| 2890 |
+
PyUnicodeDecodeError_GetStart:Py_ssize_t*:start::
|
| 2891 |
+
|
| 2892 |
+
PyUnicodeDecodeError_SetEnd:int:::
|
| 2893 |
+
PyUnicodeDecodeError_SetEnd:PyObject*:exc:0:
|
| 2894 |
+
PyUnicodeDecodeError_SetEnd:Py_ssize_t:end::
|
| 2895 |
+
|
| 2896 |
+
PyUnicodeDecodeError_SetReason:int:::
|
| 2897 |
+
PyUnicodeDecodeError_SetReason:PyObject*:exc:0:
|
| 2898 |
+
PyUnicodeDecodeError_SetReason:const char*:reason::
|
| 2899 |
+
|
| 2900 |
+
PyUnicodeDecodeError_SetStart:int:::
|
| 2901 |
+
PyUnicodeDecodeError_SetStart:PyObject*:exc:0:
|
| 2902 |
+
PyUnicodeDecodeError_SetStart:Py_ssize_t:start::
|
| 2903 |
+
|
| 2904 |
+
PyUnicodeEncodeError_Create:PyObject*::+1:
|
| 2905 |
+
PyUnicodeEncodeError_Create:const char*:encoding::
|
| 2906 |
+
PyUnicodeEncodeError_Create:const Py_UNICODE*:object::
|
| 2907 |
+
PyUnicodeEncodeError_Create:Py_ssize_t:length::
|
| 2908 |
+
PyUnicodeEncodeError_Create:Py_ssize_t:start::
|
| 2909 |
+
PyUnicodeEncodeError_Create:Py_ssize_t:end::
|
| 2910 |
+
PyUnicodeEncodeError_Create:const char*:reason::
|
| 2911 |
+
|
| 2912 |
+
PyUnicodeTranslateError_Create:PyObject*::+1:
|
| 2913 |
+
PyUnicodeTranslateError_Create:const Py_UNICODE*:object::
|
| 2914 |
+
PyUnicodeTranslateError_Create:Py_ssize_t:length::
|
| 2915 |
+
PyUnicodeTranslateError_Create:Py_ssize_t:start::
|
| 2916 |
+
PyUnicodeTranslateError_Create:Py_ssize_t:end::
|
| 2917 |
+
PyUnicodeTranslateError_Create:const char*:reason::
|
| 2918 |
+
|
| 2919 |
+
PyWeakref_Check:int:::
|
| 2920 |
+
PyWeakref_Check:PyObject*:ob::
|
| 2921 |
+
|
| 2922 |
+
PyWeakref_CheckProxy:int:::
|
| 2923 |
+
PyWeakref_CheckProxy:PyObject*:ob::
|
| 2924 |
+
|
| 2925 |
+
PyWeakref_CheckRef:int:::
|
| 2926 |
+
PyWeakref_CheckRef:PyObject*:ob::
|
| 2927 |
+
|
| 2928 |
+
PyWeakref_GET_OBJECT:PyObject*::0:
|
| 2929 |
+
PyWeakref_GET_OBJECT:PyObject*:ref:0:
|
| 2930 |
+
|
| 2931 |
+
PyWeakref_GetObject:PyObject*::0:
|
| 2932 |
+
PyWeakref_GetObject:PyObject*:ref:0:
|
| 2933 |
+
|
| 2934 |
+
PyWeakref_NewProxy:PyObject*::+1:
|
| 2935 |
+
PyWeakref_NewProxy:PyObject*:ob:0:
|
| 2936 |
+
PyWeakref_NewProxy:PyObject*:callback:0:
|
| 2937 |
+
|
| 2938 |
+
PyWeakref_NewRef:PyObject*::+1:
|
| 2939 |
+
PyWeakref_NewRef:PyObject*:ob:0:
|
| 2940 |
+
PyWeakref_NewRef:PyObject*:callback:0:
|
| 2941 |
+
|
| 2942 |
+
PyWrapper_New:PyObject*::+1:
|
| 2943 |
+
PyWrapper_New:PyObject*:d:0:
|
| 2944 |
+
PyWrapper_New:PyObject*:self:0:
|
| 2945 |
+
|
| 2946 |
+
Py_AtExit:int:::
|
| 2947 |
+
Py_AtExit:void (*)():func::
|
| 2948 |
+
|
| 2949 |
+
Py_BuildValue:PyObject*::+1:
|
| 2950 |
+
Py_BuildValue:const char*:format::
|
| 2951 |
+
Py_BuildValue::...::
|
| 2952 |
+
|
| 2953 |
+
Py_VaBuildValue:PyObject*::+1:
|
| 2954 |
+
Py_VaBuildValue:const char*:format::
|
| 2955 |
+
Py_VaBuildValue:va_list:vargs::
|
| 2956 |
+
|
| 2957 |
+
Py_CLEAR:void:::
|
| 2958 |
+
Py_CLEAR:PyObject*:o:-1:
|
| 2959 |
+
|
| 2960 |
+
Py_CompileString:PyObject*::+1:
|
| 2961 |
+
Py_CompileString:const char*:str::
|
| 2962 |
+
Py_CompileString:const char*:filename::
|
| 2963 |
+
Py_CompileString:int:start::
|
| 2964 |
+
|
| 2965 |
+
Py_CompileStringExFlags:PyObject*::+1:
|
| 2966 |
+
Py_CompileStringExFlags:const char*:str::
|
| 2967 |
+
Py_CompileStringExFlags:const char*:filename::
|
| 2968 |
+
Py_CompileStringExFlags:int:start::
|
| 2969 |
+
Py_CompileStringExFlags:PyCompilerFlags*:flags::
|
| 2970 |
+
Py_CompileStringExFlags:int:optimize::
|
| 2971 |
+
|
| 2972 |
+
Py_CompileStringFlags:PyObject*::+1:
|
| 2973 |
+
Py_CompileStringFlags:const char*:str::
|
| 2974 |
+
Py_CompileStringFlags:const char*:filename::
|
| 2975 |
+
Py_CompileStringFlags:int:start::
|
| 2976 |
+
Py_CompileStringFlags:PyCompilerFlags*:flags::
|
| 2977 |
+
|
| 2978 |
+
Py_CompileStringObject:PyObject*::+1:
|
| 2979 |
+
Py_CompileStringObject:const char*:str::
|
| 2980 |
+
Py_CompileStringObject:PyObject*:filename:0:
|
| 2981 |
+
Py_CompileStringObject:int:start::
|
| 2982 |
+
Py_CompileStringObject:PyCompilerFlags*:flags::
|
| 2983 |
+
Py_CompileStringObject:int:optimize::
|
| 2984 |
+
|
| 2985 |
+
Py_DECREF:void:::
|
| 2986 |
+
Py_DECREF:PyObject*:o:-1:
|
| 2987 |
+
|
| 2988 |
+
Py_EndInterpreter:void:::
|
| 2989 |
+
Py_EndInterpreter:PyThreadState*:tstate::
|
| 2990 |
+
|
| 2991 |
+
Py_Exit:void:::
|
| 2992 |
+
Py_Exit:int:status::
|
| 2993 |
+
|
| 2994 |
+
Py_FatalError:void:::
|
| 2995 |
+
Py_FatalError:const char*:message::
|
| 2996 |
+
|
| 2997 |
+
Py_FdIsInteractive:int:::
|
| 2998 |
+
Py_FdIsInteractive:FILE*:fp::
|
| 2999 |
+
Py_FdIsInteractive:const char*:filename::
|
| 3000 |
+
|
| 3001 |
+
Py_Finalize:void:::
|
| 3002 |
+
|
| 3003 |
+
Py_GetBuildInfo:const char*:::
|
| 3004 |
+
|
| 3005 |
+
Py_GetCompiler:const char*:::
|
| 3006 |
+
|
| 3007 |
+
Py_GetCopyright:const char*:::
|
| 3008 |
+
|
| 3009 |
+
Py_GetExecPrefix:wchar_t*:::
|
| 3010 |
+
|
| 3011 |
+
Py_GetPath:wchar_t*:::
|
| 3012 |
+
|
| 3013 |
+
Py_GetPlatform:const char*:::
|
| 3014 |
+
|
| 3015 |
+
Py_GetPrefix:wchar_t*:::
|
| 3016 |
+
|
| 3017 |
+
Py_GetProgramFullPath:wchar_t*:::
|
| 3018 |
+
|
| 3019 |
+
Py_GetProgramName:wchar_t*:::
|
| 3020 |
+
|
| 3021 |
+
Py_GetVersion:const char*:::
|
| 3022 |
+
|
| 3023 |
+
Py_INCREF:void:::
|
| 3024 |
+
Py_INCREF:PyObject*:o:+1:
|
| 3025 |
+
|
| 3026 |
+
Py_Initialize:void:::
|
| 3027 |
+
|
| 3028 |
+
Py_IsInitialized:int:::
|
| 3029 |
+
|
| 3030 |
+
Py_NewInterpreter:PyThreadState*:::
|
| 3031 |
+
|
| 3032 |
+
Py_ReprEnter:int:::
|
| 3033 |
+
Py_ReprEnter:PyObject*:object:+1:
|
| 3034 |
+
|
| 3035 |
+
Py_ReprLeave:void:::
|
| 3036 |
+
Py_ReprLeave:PyObject*:object:-1:
|
| 3037 |
+
|
| 3038 |
+
Py_SetProgramName:void:::
|
| 3039 |
+
Py_SetProgramName:const wchar_t*:name::
|
| 3040 |
+
|
| 3041 |
+
Py_XDECREF:void:::
|
| 3042 |
+
Py_XDECREF:PyObject*:o:-1:if o is not NULL
|
| 3043 |
+
|
| 3044 |
+
Py_XINCREF:void:::
|
| 3045 |
+
Py_XINCREF:PyObject*:o:+1:if o is not NULL
|
| 3046 |
+
|
| 3047 |
+
_PyImport_Fini:void:::
|
| 3048 |
+
|
| 3049 |
+
_PyObject_New:PyObject*::+1:
|
| 3050 |
+
_PyObject_New:PyTypeObject*:type:0:
|
| 3051 |
+
|
| 3052 |
+
_PyObject_NewVar:PyVarObject*::+1:
|
| 3053 |
+
_PyObject_NewVar:PyTypeObject*:type:0:
|
| 3054 |
+
_PyObject_NewVar:Py_ssize_t:size::
|
| 3055 |
+
|
| 3056 |
+
_PyBytes_Resize:int:::
|
| 3057 |
+
_PyBytes_Resize:PyObject**:bytes:0:
|
| 3058 |
+
_PyBytes_Resize:Py_ssize_t:newsize::
|
| 3059 |
+
|
| 3060 |
+
_PyTuple_Resize:int:::
|
| 3061 |
+
_PyTuple_Resize:PyObject**:p:0:
|
| 3062 |
+
_PyTuple_Resize:Py_ssize_t:new::
|
| 3063 |
+
|
| 3064 |
+
_Py_c_diff:Py_complex:::
|
| 3065 |
+
_Py_c_diff:Py_complex:left::
|
| 3066 |
+
_Py_c_diff:Py_complex:right::
|
| 3067 |
+
|
| 3068 |
+
_Py_c_neg:Py_complex:::
|
| 3069 |
+
_Py_c_neg:Py_complex:complex::
|
| 3070 |
+
|
| 3071 |
+
_Py_c_pow:Py_complex:::
|
| 3072 |
+
_Py_c_pow:Py_complex:num::
|
| 3073 |
+
_Py_c_pow:Py_complex:exp::
|
| 3074 |
+
|
| 3075 |
+
_Py_c_prod:Py_complex:::
|
| 3076 |
+
_Py_c_prod:Py_complex:left::
|
| 3077 |
+
_Py_c_prod:Py_complex:right::
|
| 3078 |
+
|
| 3079 |
+
_Py_c_quot:Py_complex:::
|
| 3080 |
+
_Py_c_quot:Py_complex:dividend::
|
| 3081 |
+
_Py_c_quot:Py_complex:divisor::
|
| 3082 |
+
|
| 3083 |
+
_Py_c_sum:Py_complex:::
|
| 3084 |
+
_Py_c_sum:Py_complex:left::
|
| 3085 |
+
_Py_c_sum:Py_complex:right::
|
cpython_2/environment/repo/Doc/distributing/index.rst
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. _distributing-index:
|
| 2 |
+
|
| 3 |
+
###############################
|
| 4 |
+
Distributing Python Modules
|
| 5 |
+
###############################
|
| 6 |
+
|
| 7 |
+
:Email: distutils-sig@python.org
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
As a popular open source development project, Python has an active
|
| 11 |
+
supporting community of contributors and users that also make their software
|
| 12 |
+
available for other Python developers to use under open source license terms.
|
| 13 |
+
|
| 14 |
+
This allows Python users to share and collaborate effectively, benefiting
|
| 15 |
+
from the solutions others have already created to common (and sometimes
|
| 16 |
+
even rare!) problems, as well as potentially contributing their own
|
| 17 |
+
solutions to the common pool.
|
| 18 |
+
|
| 19 |
+
This guide covers the distribution part of the process. For a guide to
|
| 20 |
+
installing other Python projects, refer to the
|
| 21 |
+
:ref:`installation guide <installing-index>`.
|
| 22 |
+
|
| 23 |
+
.. note::
|
| 24 |
+
|
| 25 |
+
For corporate and other institutional users, be aware that many
|
| 26 |
+
organisations have their own policies around using and contributing to
|
| 27 |
+
open source software. Please take such policies into account when making
|
| 28 |
+
use of the distribution and installation tools provided with Python.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Key terms
|
| 32 |
+
=========
|
| 33 |
+
|
| 34 |
+
* the `Python Packaging Index <https://pypi.org>`__ is a public
|
| 35 |
+
repository of open source licensed packages made available for use by
|
| 36 |
+
other Python users
|
| 37 |
+
* the `Python Packaging Authority
|
| 38 |
+
<https://www.pypa.io/>`__ are the group of
|
| 39 |
+
developers and documentation authors responsible for the maintenance and
|
| 40 |
+
evolution of the standard packaging tools and the associated metadata and
|
| 41 |
+
file format standards. They maintain a variety of tools, documentation
|
| 42 |
+
and issue trackers on both `GitHub <https://github.com/pypa>`__ and
|
| 43 |
+
`Bitbucket <https://bitbucket.org/pypa/>`__.
|
| 44 |
+
* :mod:`distutils` is the original build and distribution system first added
|
| 45 |
+
to the Python standard library in 1998. While direct use of :mod:`distutils`
|
| 46 |
+
is being phased out, it still laid the foundation for the current packaging
|
| 47 |
+
and distribution infrastructure, and it not only remains part of the
|
| 48 |
+
standard library, but its name lives on in other ways (such as the name
|
| 49 |
+
of the mailing list used to coordinate Python packaging standards
|
| 50 |
+
development).
|
| 51 |
+
* `setuptools`_ is a (largely) drop-in replacement for :mod:`distutils` first
|
| 52 |
+
published in 2004. Its most notable addition over the unmodified
|
| 53 |
+
:mod:`distutils` tools was the ability to declare dependencies on other
|
| 54 |
+
packages. It is currently recommended as a more regularly updated
|
| 55 |
+
alternative to :mod:`distutils` that offers consistent support for more
|
| 56 |
+
recent packaging standards across a wide range of Python versions.
|
| 57 |
+
* `wheel`_ (in this context) is a project that adds the ``bdist_wheel``
|
| 58 |
+
command to :mod:`distutils`/`setuptools`_. This produces a cross platform
|
| 59 |
+
binary packaging format (called "wheels" or "wheel files" and defined in
|
| 60 |
+
:pep:`427`) that allows Python libraries, even those including binary
|
| 61 |
+
extensions, to be installed on a system without needing to be built
|
| 62 |
+
locally.
|
| 63 |
+
|
| 64 |
+
.. _setuptools: https://setuptools.readthedocs.io/en/latest/
|
| 65 |
+
.. _wheel: https://wheel.readthedocs.io/
|
| 66 |
+
|
| 67 |
+
Open source licensing and collaboration
|
| 68 |
+
=======================================
|
| 69 |
+
|
| 70 |
+
In most parts of the world, software is automatically covered by copyright.
|
| 71 |
+
This means that other developers require explicit permission to copy, use,
|
| 72 |
+
modify and redistribute the software.
|
| 73 |
+
|
| 74 |
+
Open source licensing is a way of explicitly granting such permission in a
|
| 75 |
+
relatively consistent way, allowing developers to share and collaborate
|
| 76 |
+
efficiently by making common solutions to various problems freely available.
|
| 77 |
+
This leaves many developers free to spend more time focusing on the problems
|
| 78 |
+
that are relatively unique to their specific situation.
|
| 79 |
+
|
| 80 |
+
The distribution tools provided with Python are designed to make it
|
| 81 |
+
reasonably straightforward for developers to make their own contributions
|
| 82 |
+
back to that common pool of software if they choose to do so.
|
| 83 |
+
|
| 84 |
+
The same distribution tools can also be used to distribute software within
|
| 85 |
+
an organisation, regardless of whether that software is published as open
|
| 86 |
+
source software or not.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
Installing the tools
|
| 90 |
+
====================
|
| 91 |
+
|
| 92 |
+
The standard library does not include build tools that support modern
|
| 93 |
+
Python packaging standards, as the core development team has found that it
|
| 94 |
+
is important to have standard tools that work consistently, even on older
|
| 95 |
+
versions of Python.
|
| 96 |
+
|
| 97 |
+
The currently recommended build and distribution tools can be installed
|
| 98 |
+
by invoking the ``pip`` module at the command line::
|
| 99 |
+
|
| 100 |
+
python -m pip install setuptools wheel twine
|
| 101 |
+
|
| 102 |
+
.. note::
|
| 103 |
+
|
| 104 |
+
For POSIX users (including Mac OS X and Linux users), these instructions
|
| 105 |
+
assume the use of a :term:`virtual environment`.
|
| 106 |
+
|
| 107 |
+
For Windows users, these instructions assume that the option to
|
| 108 |
+
adjust the system PATH environment variable was selected when installing
|
| 109 |
+
Python.
|
| 110 |
+
|
| 111 |
+
The Python Packaging User Guide includes more details on the `currently
|
| 112 |
+
recommended tools`_.
|
| 113 |
+
|
| 114 |
+
.. _currently recommended tools: https://packaging.python.org/guides/tool-recommendations/#packaging-tool-recommendations
|
| 115 |
+
|
| 116 |
+
.. index::
|
| 117 |
+
single: Python Package Index (PyPI)
|
| 118 |
+
single: PyPI; (see Python Package Index (PyPI))
|
| 119 |
+
|
| 120 |
+
.. _publishing-python-packages:
|
| 121 |
+
|
| 122 |
+
Reading the Python Packaging User Guide
|
| 123 |
+
=======================================
|
| 124 |
+
|
| 125 |
+
The Python Packaging User Guide covers the various key steps and elements
|
| 126 |
+
involved in creating and publishing a project:
|
| 127 |
+
|
| 128 |
+
* `Project structure`_
|
| 129 |
+
* `Building and packaging the project`_
|
| 130 |
+
* `Uploading the project to the Python Packaging Index`_
|
| 131 |
+
|
| 132 |
+
.. _Project structure: \
|
| 133 |
+
https://packaging.python.org/tutorials/distributing-packages/
|
| 134 |
+
.. _Building and packaging the project: \
|
| 135 |
+
https://packaging.python.org/tutorials/distributing-packages/#packaging-your-project
|
| 136 |
+
.. _Uploading the project to the Python Packaging Index: \
|
| 137 |
+
https://packaging.python.org/tutorials/distributing-packages/#uploading-your-project-to-pypi
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
How do I...?
|
| 141 |
+
============
|
| 142 |
+
|
| 143 |
+
These are quick answers or links for some common tasks.
|
| 144 |
+
|
| 145 |
+
... choose a name for my project?
|
| 146 |
+
---------------------------------
|
| 147 |
+
|
| 148 |
+
This isn't an easy topic, but here are a few tips:
|
| 149 |
+
|
| 150 |
+
* check the Python Packaging Index to see if the name is already in use
|
| 151 |
+
* check popular hosting sites like GitHub, Bitbucket, etc to see if there
|
| 152 |
+
is already a project with that name
|
| 153 |
+
* check what comes up in a web search for the name you're considering
|
| 154 |
+
* avoid particularly common words, especially ones with multiple meanings,
|
| 155 |
+
as they can make it difficult for users to find your software when
|
| 156 |
+
searching for it
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
... create and distribute binary extensions?
|
| 160 |
+
--------------------------------------------
|
| 161 |
+
|
| 162 |
+
This is actually quite a complex topic, with a variety of alternatives
|
| 163 |
+
available depending on exactly what you're aiming to achieve. See the
|
| 164 |
+
Python Packaging User Guide for more information and recommendations.
|
| 165 |
+
|
| 166 |
+
.. seealso::
|
| 167 |
+
|
| 168 |
+
`Python Packaging User Guide: Binary Extensions
|
| 169 |
+
<https://packaging.python.org/guides/packaging-binary-extensions/>`__
|
| 170 |
+
|
| 171 |
+
.. other topics:
|
| 172 |
+
|
| 173 |
+
Once the Development & Deployment part of PPUG is fleshed out, some of
|
| 174 |
+
those sections should be linked from new questions here (most notably,
|
| 175 |
+
we should have a question about avoiding depending on PyPI that links to
|
| 176 |
+
https://packaging.python.org/en/latest/mirrors/)
|
cpython_2/environment/repo/Doc/distutils/_setuptools_disclaimer.rst
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. note::
|
| 2 |
+
|
| 3 |
+
This document is being retained solely until the ``setuptools`` documentation
|
| 4 |
+
at https://setuptools.readthedocs.io/en/latest/setuptools.html
|
| 5 |
+
independently covers all of the relevant information currently included here.
|
cpython_2/environment/repo/Doc/distutils/apiref.rst
ADDED
|
@@ -0,0 +1,2070 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. _api-reference:
|
| 2 |
+
|
| 3 |
+
*************
|
| 4 |
+
API Reference
|
| 5 |
+
*************
|
| 6 |
+
|
| 7 |
+
.. seealso::
|
| 8 |
+
|
| 9 |
+
`New and changed setup.py arguments in setuptools`_
|
| 10 |
+
The ``setuptools`` project adds new capabilities to the ``setup`` function
|
| 11 |
+
and other APIs, makes the API consistent across different Python versions,
|
| 12 |
+
and is hence recommended over using ``distutils`` directly.
|
| 13 |
+
|
| 14 |
+
.. _New and changed setup.py arguments in setuptools: https://setuptools.readthedocs.io/en/latest/setuptools.html#new-and-changed-setup-keywords
|
| 15 |
+
|
| 16 |
+
.. include:: ./_setuptools_disclaimer.rst
|
| 17 |
+
|
| 18 |
+
:mod:`distutils.core` --- Core Distutils functionality
|
| 19 |
+
======================================================
|
| 20 |
+
|
| 21 |
+
.. module:: distutils.core
|
| 22 |
+
:synopsis: The core Distutils functionality
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
The :mod:`distutils.core` module is the only module that needs to be installed
|
| 26 |
+
to use the Distutils. It provides the :func:`setup` (which is called from the
|
| 27 |
+
setup script). Indirectly provides the :class:`distutils.dist.Distribution` and
|
| 28 |
+
:class:`distutils.cmd.Command` class.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
.. function:: setup(arguments)
|
| 32 |
+
|
| 33 |
+
The basic do-everything function that does most everything you could ever ask
|
| 34 |
+
for from a Distutils method.
|
| 35 |
+
|
| 36 |
+
The setup function takes a large number of arguments. These are laid out in the
|
| 37 |
+
following table.
|
| 38 |
+
|
| 39 |
+
.. tabularcolumns:: |l|L|L|
|
| 40 |
+
|
| 41 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 42 |
+
| argument name | value | type |
|
| 43 |
+
+====================+================================+=============================================================+
|
| 44 |
+
| *name* | The name of the package | a string |
|
| 45 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 46 |
+
| *version* | The version number of the | a string |
|
| 47 |
+
| | package; see | |
|
| 48 |
+
| | :mod:`distutils.version` | |
|
| 49 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 50 |
+
| *description* | A single line describing the | a string |
|
| 51 |
+
| | package | |
|
| 52 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 53 |
+
| *long_description* | Longer description of the | a string |
|
| 54 |
+
| | package | |
|
| 55 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 56 |
+
| *author* | The name of the package author | a string |
|
| 57 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 58 |
+
| *author_email* | The email address of the | a string |
|
| 59 |
+
| | package author | |
|
| 60 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 61 |
+
| *maintainer* | The name of the current | a string |
|
| 62 |
+
| | maintainer, if different from | |
|
| 63 |
+
| | the author. Note that if | |
|
| 64 |
+
| | the maintainer is provided, | |
|
| 65 |
+
| | distutils will use it as the | |
|
| 66 |
+
| | author in :file:`PKG-INFO` | |
|
| 67 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 68 |
+
| *maintainer_email* | The email address of the | a string |
|
| 69 |
+
| | current maintainer, if | |
|
| 70 |
+
| | different from the author | |
|
| 71 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 72 |
+
| *url* | A URL for the package | a string |
|
| 73 |
+
| | (homepage) | |
|
| 74 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 75 |
+
| *download_url* | A URL to download the package | a string |
|
| 76 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 77 |
+
| *packages* | A list of Python packages that | a list of strings |
|
| 78 |
+
| | distutils will manipulate | |
|
| 79 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 80 |
+
| *py_modules* | A list of Python modules that | a list of strings |
|
| 81 |
+
| | distutils will manipulate | |
|
| 82 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 83 |
+
| *scripts* | A list of standalone script | a list of strings |
|
| 84 |
+
| | files to be built and | |
|
| 85 |
+
| | installed | |
|
| 86 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 87 |
+
| *ext_modules* | A list of Python extensions to | a list of instances of |
|
| 88 |
+
| | be built | :class:`distutils.core.Extension` |
|
| 89 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 90 |
+
| *classifiers* | A list of categories for the | a list of strings; valid classifiers are listed on `PyPI |
|
| 91 |
+
| | package | <https://pypi.org/classifiers>`_. |
|
| 92 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 93 |
+
| *distclass* | the :class:`Distribution` | a subclass of |
|
| 94 |
+
| | class to use | :class:`distutils.core.Distribution` |
|
| 95 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 96 |
+
| *script_name* | The name of the setup.py | a string |
|
| 97 |
+
| | script - defaults to | |
|
| 98 |
+
| | ``sys.argv[0]`` | |
|
| 99 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 100 |
+
| *script_args* | Arguments to supply to the | a list of strings |
|
| 101 |
+
| | setup script | |
|
| 102 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 103 |
+
| *options* | default options for the setup | a dictionary |
|
| 104 |
+
| | script | |
|
| 105 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 106 |
+
| *license* | The license for the package | a string |
|
| 107 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 108 |
+
| *keywords* | Descriptive meta-data, see | a list of strings or a comma-separated string |
|
| 109 |
+
| | :pep:`314` | |
|
| 110 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 111 |
+
| *platforms* | | a list of strings or a comma-separated string |
|
| 112 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 113 |
+
| *cmdclass* | A mapping of command names to | a dictionary |
|
| 114 |
+
| | :class:`Command` subclasses | |
|
| 115 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 116 |
+
| *data_files* | A list of data files to | a list |
|
| 117 |
+
| | install | |
|
| 118 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 119 |
+
| *package_dir* | A mapping of package to | a dictionary |
|
| 120 |
+
| | directory names | |
|
| 121 |
+
+--------------------+--------------------------------+-------------------------------------------------------------+
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
.. function:: run_setup(script_name[, script_args=None, stop_after='run'])
|
| 126 |
+
|
| 127 |
+
Run a setup script in a somewhat controlled environment, and return the
|
| 128 |
+
:class:`distutils.dist.Distribution` instance that drives things. This is
|
| 129 |
+
useful if you need to find out the distribution meta-data (passed as keyword
|
| 130 |
+
args from *script* to :func:`setup`), or the contents of the config files or
|
| 131 |
+
command-line.
|
| 132 |
+
|
| 133 |
+
*script_name* is a file that will be read and run with :func:`exec`. ``sys.argv[0]``
|
| 134 |
+
will be replaced with *script* for the duration of the call. *script_args* is a
|
| 135 |
+
list of strings; if supplied, ``sys.argv[1:]`` will be replaced by *script_args*
|
| 136 |
+
for the duration of the call.
|
| 137 |
+
|
| 138 |
+
*stop_after* tells :func:`setup` when to stop processing; possible values:
|
| 139 |
+
|
| 140 |
+
.. tabularcolumns:: |l|L|
|
| 141 |
+
|
| 142 |
+
+---------------+---------------------------------------------+
|
| 143 |
+
| value | description |
|
| 144 |
+
+===============+=============================================+
|
| 145 |
+
| *init* | Stop after the :class:`Distribution` |
|
| 146 |
+
| | instance has been created and populated |
|
| 147 |
+
| | with the keyword arguments to :func:`setup` |
|
| 148 |
+
+---------------+---------------------------------------------+
|
| 149 |
+
| *config* | Stop after config files have been parsed |
|
| 150 |
+
| | (and their data stored in the |
|
| 151 |
+
| | :class:`Distribution` instance) |
|
| 152 |
+
+---------------+---------------------------------------------+
|
| 153 |
+
| *commandline* | Stop after the command-line |
|
| 154 |
+
| | (``sys.argv[1:]`` or *script_args*) have |
|
| 155 |
+
| | been parsed (and the data stored in the |
|
| 156 |
+
| | :class:`Distribution` instance.) |
|
| 157 |
+
+---------------+---------------------------------------------+
|
| 158 |
+
| *run* | Stop after all commands have been run (the |
|
| 159 |
+
| | same as if :func:`setup` had been called |
|
| 160 |
+
| | in the usual way). This is the default |
|
| 161 |
+
| | value. |
|
| 162 |
+
+---------------+---------------------------------------------+
|
| 163 |
+
|
| 164 |
+
In addition, the :mod:`distutils.core` module exposed a number of classes that
|
| 165 |
+
live elsewhere.
|
| 166 |
+
|
| 167 |
+
* :class:`~distutils.extension.Extension` from :mod:`distutils.extension`
|
| 168 |
+
|
| 169 |
+
* :class:`~distutils.cmd.Command` from :mod:`distutils.cmd`
|
| 170 |
+
|
| 171 |
+
* :class:`~distutils.dist.Distribution` from :mod:`distutils.dist`
|
| 172 |
+
|
| 173 |
+
A short description of each of these follows, but see the relevant module for
|
| 174 |
+
the full reference.
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
.. class:: Extension
|
| 178 |
+
|
| 179 |
+
The Extension class describes a single C or C++ extension module in a setup
|
| 180 |
+
script. It accepts the following keyword arguments in its constructor:
|
| 181 |
+
|
| 182 |
+
.. tabularcolumns:: |l|L|l|
|
| 183 |
+
|
| 184 |
+
+------------------------+--------------------------------+---------------------------+
|
| 185 |
+
| argument name | value | type |
|
| 186 |
+
+========================+================================+===========================+
|
| 187 |
+
| *name* | the full name of the | a string |
|
| 188 |
+
| | extension, including any | |
|
| 189 |
+
| | packages --- ie. *not* a | |
|
| 190 |
+
| | filename or pathname, but | |
|
| 191 |
+
| | Python dotted name | |
|
| 192 |
+
+------------------------+--------------------------------+---------------------------+
|
| 193 |
+
| *sources* | list of source filenames, | a list of strings |
|
| 194 |
+
| | relative to the distribution | |
|
| 195 |
+
| | root (where the setup script | |
|
| 196 |
+
| | lives), in Unix form | |
|
| 197 |
+
| | (slash-separated) for | |
|
| 198 |
+
| | portability. | |
|
| 199 |
+
| | Source files may be C, C++, | |
|
| 200 |
+
| | SWIG (.i), platform-specific | |
|
| 201 |
+
| | resource files, or whatever | |
|
| 202 |
+
| | else is recognized by the | |
|
| 203 |
+
| | :command:`build_ext` command | |
|
| 204 |
+
| | as source for a Python | |
|
| 205 |
+
| | extension. | |
|
| 206 |
+
+------------------------+--------------------------------+---------------------------+
|
| 207 |
+
| *include_dirs* | list of directories to search | a list of strings |
|
| 208 |
+
| | for C/C++ header files (in | |
|
| 209 |
+
| | Unix form for portability) | |
|
| 210 |
+
+------------------------+--------------------------------+---------------------------+
|
| 211 |
+
| *define_macros* | list of macros to define; each | a list of tuples |
|
| 212 |
+
| | macro is defined using a | |
|
| 213 |
+
| | 2-tuple ``(name, value)``, | |
|
| 214 |
+
| | where *value* is | |
|
| 215 |
+
| | either the string to define it | |
|
| 216 |
+
| | to or ``None`` to define it | |
|
| 217 |
+
| | without a particular value | |
|
| 218 |
+
| | (equivalent of ``#define FOO`` | |
|
| 219 |
+
| | in source or :option:`!-DFOO` | |
|
| 220 |
+
| | on Unix C compiler command | |
|
| 221 |
+
| | line) | |
|
| 222 |
+
+------------------------+--------------------------------+---------------------------+
|
| 223 |
+
| *undef_macros* | list of macros to undefine | a list of strings |
|
| 224 |
+
| | explicitly | |
|
| 225 |
+
+------------------------+--------------------------------+---------------------------+
|
| 226 |
+
| *library_dirs* | list of directories to search | a list of strings |
|
| 227 |
+
| | for C/C++ libraries at link | |
|
| 228 |
+
| | time | |
|
| 229 |
+
+------------------------+--------------------------------+---------------------------+
|
| 230 |
+
| *libraries* | list of library names (not | a list of strings |
|
| 231 |
+
| | filenames or paths) to link | |
|
| 232 |
+
| | against | |
|
| 233 |
+
+------------------------+--------------------------------+---------------------------+
|
| 234 |
+
| *runtime_library_dirs* | list of directories to search | a list of strings |
|
| 235 |
+
| | for C/C++ libraries at run | |
|
| 236 |
+
| | time (for shared extensions, | |
|
| 237 |
+
| | this is when the extension is | |
|
| 238 |
+
| | loaded) | |
|
| 239 |
+
+------------------------+--------------------------------+---------------------------+
|
| 240 |
+
| *extra_objects* | list of extra files to link | a list of strings |
|
| 241 |
+
| | with (eg. object files not | |
|
| 242 |
+
| | implied by 'sources', static | |
|
| 243 |
+
| | library that must be | |
|
| 244 |
+
| | explicitly specified, binary | |
|
| 245 |
+
| | resource files, etc.) | |
|
| 246 |
+
+------------------------+--------------------------------+---------------------------+
|
| 247 |
+
| *extra_compile_args* | any extra platform- and | a list of strings |
|
| 248 |
+
| | compiler-specific information | |
|
| 249 |
+
| | to use when compiling the | |
|
| 250 |
+
| | source files in 'sources'. For | |
|
| 251 |
+
| | platforms and compilers where | |
|
| 252 |
+
| | a command line makes sense, | |
|
| 253 |
+
| | this is typically a list of | |
|
| 254 |
+
| | command-line arguments, but | |
|
| 255 |
+
| | for other platforms it could | |
|
| 256 |
+
| | be anything. | |
|
| 257 |
+
+------------------------+--------------------------------+---------------------------+
|
| 258 |
+
| *extra_link_args* | any extra platform- and | a list of strings |
|
| 259 |
+
| | compiler-specific information | |
|
| 260 |
+
| | to use when linking object | |
|
| 261 |
+
| | files together to create the | |
|
| 262 |
+
| | extension (or to create a new | |
|
| 263 |
+
| | static Python interpreter). | |
|
| 264 |
+
| | Similar interpretation as for | |
|
| 265 |
+
| | 'extra_compile_args'. | |
|
| 266 |
+
+------------------------+--------------------------------+---------------------------+
|
| 267 |
+
| *export_symbols* | list of symbols to be exported | a list of strings |
|
| 268 |
+
| | from a shared extension. Not | |
|
| 269 |
+
| | used on all platforms, and not | |
|
| 270 |
+
| | generally necessary for Python | |
|
| 271 |
+
| | extensions, which typically | |
|
| 272 |
+
| | export exactly one symbol: | |
|
| 273 |
+
| | ``init`` + extension_name. | |
|
| 274 |
+
+------------------------+--------------------------------+---------------------------+
|
| 275 |
+
| *depends* | list of files that the | a list of strings |
|
| 276 |
+
| | extension depends on | |
|
| 277 |
+
+------------------------+--------------------------------+---------------------------+
|
| 278 |
+
| *language* | extension language (i.e. | a string |
|
| 279 |
+
| | ``'c'``, ``'c++'``, | |
|
| 280 |
+
| | ``'objc'``). Will be detected | |
|
| 281 |
+
| | from the source extensions if | |
|
| 282 |
+
| | not provided. | |
|
| 283 |
+
+------------------------+--------------------------------+---------------------------+
|
| 284 |
+
| *optional* | specifies that a build failure | a boolean |
|
| 285 |
+
| | in the extension should not | |
|
| 286 |
+
| | abort the build process, but | |
|
| 287 |
+
| | simply skip the extension. | |
|
| 288 |
+
+------------------------+--------------------------------+---------------------------+
|
| 289 |
+
|
| 290 |
+
.. versionchanged:: 3.8
|
| 291 |
+
|
| 292 |
+
On Unix, C extensions are no longer linked to libpython except on
|
| 293 |
+
Android and Cygwin.
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
.. class:: Distribution
|
| 297 |
+
|
| 298 |
+
A :class:`Distribution` describes how to build, install and package up a Python
|
| 299 |
+
software package.
|
| 300 |
+
|
| 301 |
+
See the :func:`setup` function for a list of keyword arguments accepted by the
|
| 302 |
+
Distribution constructor. :func:`setup` creates a Distribution instance.
|
| 303 |
+
|
| 304 |
+
.. versionchanged:: 3.7
|
| 305 |
+
:class:`~distutils.core.Distribution` now warns if ``classifiers``,
|
| 306 |
+
``keywords`` and ``platforms`` fields are not specified as a list or
|
| 307 |
+
a string.
|
| 308 |
+
|
| 309 |
+
.. class:: Command
|
| 310 |
+
|
| 311 |
+
A :class:`Command` class (or rather, an instance of one of its subclasses)
|
| 312 |
+
implement a single distutils command.
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
:mod:`distutils.ccompiler` --- CCompiler base class
|
| 316 |
+
===================================================
|
| 317 |
+
|
| 318 |
+
.. module:: distutils.ccompiler
|
| 319 |
+
:synopsis: Abstract CCompiler class
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
This module provides the abstract base class for the :class:`CCompiler`
|
| 323 |
+
classes. A :class:`CCompiler` instance can be used for all the compile and
|
| 324 |
+
link steps needed to build a single project. Methods are provided to set
|
| 325 |
+
options for the compiler --- macro definitions, include directories, link path,
|
| 326 |
+
libraries and the like.
|
| 327 |
+
|
| 328 |
+
This module provides the following functions.
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
.. function:: gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries)
|
| 332 |
+
|
| 333 |
+
Generate linker options for searching library directories and linking with
|
| 334 |
+
specific libraries. *libraries* and *library_dirs* are, respectively, lists of
|
| 335 |
+
library names (not filenames!) and search directories. Returns a list of
|
| 336 |
+
command-line options suitable for use with some compiler (depending on the two
|
| 337 |
+
format strings passed in).
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
.. function:: gen_preprocess_options(macros, include_dirs)
|
| 341 |
+
|
| 342 |
+
Generate C pre-processor options (:option:`!-D`, :option:`!-U`, :option:`!-I`) as
|
| 343 |
+
used by at least two types of compilers: the typical Unix compiler and Visual
|
| 344 |
+
C++. *macros* is the usual thing, a list of 1- or 2-tuples, where ``(name,)``
|
| 345 |
+
means undefine (:option:`!-U`) macro *name*, and ``(name, value)`` means define
|
| 346 |
+
(:option:`!-D`) macro *name* to *value*. *include_dirs* is just a list of
|
| 347 |
+
directory names to be added to the header file search path (:option:`!-I`).
|
| 348 |
+
Returns a list of command-line options suitable for either Unix compilers or
|
| 349 |
+
Visual C++.
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
.. function:: get_default_compiler(osname, platform)
|
| 353 |
+
|
| 354 |
+
Determine the default compiler to use for the given platform.
|
| 355 |
+
|
| 356 |
+
*osname* should be one of the standard Python OS names (i.e. the ones returned
|
| 357 |
+
by ``os.name``) and *platform* the common value returned by ``sys.platform`` for
|
| 358 |
+
the platform in question.
|
| 359 |
+
|
| 360 |
+
The default values are ``os.name`` and ``sys.platform`` in case the parameters
|
| 361 |
+
are not given.
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
.. function:: new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0)
|
| 365 |
+
|
| 366 |
+
Factory function to generate an instance of some CCompiler subclass for the
|
| 367 |
+
supplied platform/compiler combination. *plat* defaults to ``os.name`` (eg.
|
| 368 |
+
``'posix'``, ``'nt'``), and *compiler* defaults to the default compiler for
|
| 369 |
+
that platform. Currently only ``'posix'`` and ``'nt'`` are supported, and the
|
| 370 |
+
default compilers are "traditional Unix interface" (:class:`UnixCCompiler`
|
| 371 |
+
class) and Visual C++ (:class:`MSVCCompiler` class). Note that it's perfectly
|
| 372 |
+
possible to ask for a Unix compiler object under Windows, and a Microsoft
|
| 373 |
+
compiler object under Unix---if you supply a value for *compiler*, *plat* is
|
| 374 |
+
ignored.
|
| 375 |
+
|
| 376 |
+
.. % Is the posix/nt only thing still true? Mac OS X seems to work, and
|
| 377 |
+
.. % returns a UnixCCompiler instance. How to document this... hmm.
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
.. function:: show_compilers()
|
| 381 |
+
|
| 382 |
+
Print list of available compilers (used by the :option:`!--help-compiler` options
|
| 383 |
+
to :command:`build`, :command:`build_ext`, :command:`build_clib`).
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
.. class:: CCompiler([verbose=0, dry_run=0, force=0])
|
| 387 |
+
|
| 388 |
+
The abstract base class :class:`CCompiler` defines the interface that must be
|
| 389 |
+
implemented by real compiler classes. The class also has some utility methods
|
| 390 |
+
used by several compiler classes.
|
| 391 |
+
|
| 392 |
+
The basic idea behind a compiler abstraction class is that each instance can be
|
| 393 |
+
used for all the compile/link steps in building a single project. Thus,
|
| 394 |
+
attributes common to all of those compile and link steps --- include
|
| 395 |
+
directories, macros to define, libraries to link against, etc. --- are
|
| 396 |
+
attributes of the compiler instance. To allow for variability in how individual
|
| 397 |
+
files are treated, most of those attributes may be varied on a per-compilation
|
| 398 |
+
or per-link basis.
|
| 399 |
+
|
| 400 |
+
The constructor for each subclass creates an instance of the Compiler object.
|
| 401 |
+
Flags are *verbose* (show verbose output), *dry_run* (don't actually execute the
|
| 402 |
+
steps) and *force* (rebuild everything, regardless of dependencies). All of
|
| 403 |
+
these flags default to ``0`` (off). Note that you probably don't want to
|
| 404 |
+
instantiate :class:`CCompiler` or one of its subclasses directly - use the
|
| 405 |
+
:func:`distutils.CCompiler.new_compiler` factory function instead.
|
| 406 |
+
|
| 407 |
+
The following methods allow you to manually alter compiler options for the
|
| 408 |
+
instance of the Compiler class.
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
.. method:: CCompiler.add_include_dir(dir)
|
| 412 |
+
|
| 413 |
+
Add *dir* to the list of directories that will be searched for header files.
|
| 414 |
+
The compiler is instructed to search directories in the order in which they are
|
| 415 |
+
supplied by successive calls to :meth:`add_include_dir`.
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
.. method:: CCompiler.set_include_dirs(dirs)
|
| 419 |
+
|
| 420 |
+
Set the list of directories that will be searched to *dirs* (a list of strings).
|
| 421 |
+
Overrides any preceding calls to :meth:`add_include_dir`; subsequent calls to
|
| 422 |
+
:meth:`add_include_dir` add to the list passed to :meth:`set_include_dirs`.
|
| 423 |
+
This does not affect any list of standard include directories that the compiler
|
| 424 |
+
may search by default.
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
.. method:: CCompiler.add_library(libname)
|
| 428 |
+
|
| 429 |
+
Add *libname* to the list of libraries that will be included in all links driven
|
| 430 |
+
by this compiler object. Note that *libname* should \*not\* be the name of a
|
| 431 |
+
file containing a library, but the name of the library itself: the actual
|
| 432 |
+
filename will be inferred by the linker, the compiler, or the compiler class
|
| 433 |
+
(depending on the platform).
|
| 434 |
+
|
| 435 |
+
The linker will be instructed to link against libraries in the order they were
|
| 436 |
+
supplied to :meth:`add_library` and/or :meth:`set_libraries`. It is perfectly
|
| 437 |
+
valid to duplicate library names; the linker will be instructed to link against
|
| 438 |
+
libraries as many times as they are mentioned.
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
.. method:: CCompiler.set_libraries(libnames)
|
| 442 |
+
|
| 443 |
+
Set the list of libraries to be included in all links driven by this compiler
|
| 444 |
+
object to *libnames* (a list of strings). This does not affect any standard
|
| 445 |
+
system libraries that the linker may include by default.
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
.. method:: CCompiler.add_library_dir(dir)
|
| 449 |
+
|
| 450 |
+
Add *dir* to the list of directories that will be searched for libraries
|
| 451 |
+
specified to :meth:`add_library` and :meth:`set_libraries`. The linker will be
|
| 452 |
+
instructed to search for libraries in the order they are supplied to
|
| 453 |
+
:meth:`add_library_dir` and/or :meth:`set_library_dirs`.
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
.. method:: CCompiler.set_library_dirs(dirs)
|
| 457 |
+
|
| 458 |
+
Set the list of library search directories to *dirs* (a list of strings). This
|
| 459 |
+
does not affect any standard library search path that the linker may search by
|
| 460 |
+
default.
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
.. method:: CCompiler.add_runtime_library_dir(dir)
|
| 464 |
+
|
| 465 |
+
Add *dir* to the list of directories that will be searched for shared libraries
|
| 466 |
+
at runtime.
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
.. method:: CCompiler.set_runtime_library_dirs(dirs)
|
| 470 |
+
|
| 471 |
+
Set the list of directories to search for shared libraries at runtime to *dirs*
|
| 472 |
+
(a list of strings). This does not affect any standard search path that the
|
| 473 |
+
runtime linker may search by default.
|
| 474 |
+
|
| 475 |
+
|
| 476 |
+
.. method:: CCompiler.define_macro(name[, value=None])
|
| 477 |
+
|
| 478 |
+
Define a preprocessor macro for all compilations driven by this compiler object.
|
| 479 |
+
The optional parameter *value* should be a string; if it is not supplied, then
|
| 480 |
+
the macro will be defined without an explicit value and the exact outcome
|
| 481 |
+
depends on the compiler used.
|
| 482 |
+
|
| 483 |
+
.. XXX true? does ANSI say anything about this?
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
.. method:: CCompiler.undefine_macro(name)
|
| 487 |
+
|
| 488 |
+
Undefine a preprocessor macro for all compilations driven by this compiler
|
| 489 |
+
object. If the same macro is defined by :meth:`define_macro` and
|
| 490 |
+
undefined by :meth:`undefine_macro` the last call takes precedence
|
| 491 |
+
(including multiple redefinitions or undefinitions). If the macro is
|
| 492 |
+
redefined/undefined on a per-compilation basis (ie. in the call to
|
| 493 |
+
:meth:`compile`), then that takes precedence.
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
.. method:: CCompiler.add_link_object(object)
|
| 497 |
+
|
| 498 |
+
Add *object* to the list of object files (or analogues, such as explicitly named
|
| 499 |
+
library files or the output of "resource compilers") to be included in every
|
| 500 |
+
link driven by this compiler object.
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
.. method:: CCompiler.set_link_objects(objects)
|
| 504 |
+
|
| 505 |
+
Set the list of object files (or analogues) to be included in every link to
|
| 506 |
+
*objects*. This does not affect any standard object files that the linker may
|
| 507 |
+
include by default (such as system libraries).
|
| 508 |
+
|
| 509 |
+
The following methods implement methods for autodetection of compiler options,
|
| 510 |
+
providing some functionality similar to GNU :program:`autoconf`.
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
.. method:: CCompiler.detect_language(sources)
|
| 514 |
+
|
| 515 |
+
Detect the language of a given file, or list of files. Uses the instance
|
| 516 |
+
attributes :attr:`language_map` (a dictionary), and :attr:`language_order` (a
|
| 517 |
+
list) to do the job.
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
.. method:: CCompiler.find_library_file(dirs, lib[, debug=0])
|
| 521 |
+
|
| 522 |
+
Search the specified list of directories for a static or shared library file
|
| 523 |
+
*lib* and return the full path to that file. If *debug* is true, look for a
|
| 524 |
+
debugging version (if that makes sense on the current platform). Return
|
| 525 |
+
``None`` if *lib* wasn't found in any of the specified directories.
|
| 526 |
+
|
| 527 |
+
|
| 528 |
+
.. method:: CCompiler.has_function(funcname [, includes=None, include_dirs=None, libraries=None, library_dirs=None])
|
| 529 |
+
|
| 530 |
+
Return a boolean indicating whether *funcname* is supported on the current
|
| 531 |
+
platform. The optional arguments can be used to augment the compilation
|
| 532 |
+
environment by providing additional include files and paths and libraries and
|
| 533 |
+
paths.
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
.. method:: CCompiler.library_dir_option(dir)
|
| 537 |
+
|
| 538 |
+
Return the compiler option to add *dir* to the list of directories searched for
|
| 539 |
+
libraries.
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
.. method:: CCompiler.library_option(lib)
|
| 543 |
+
|
| 544 |
+
Return the compiler option to add *lib* to the list of libraries linked into the
|
| 545 |
+
shared library or executable.
|
| 546 |
+
|
| 547 |
+
|
| 548 |
+
.. method:: CCompiler.runtime_library_dir_option(dir)
|
| 549 |
+
|
| 550 |
+
Return the compiler option to add *dir* to the list of directories searched for
|
| 551 |
+
runtime libraries.
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
.. method:: CCompiler.set_executables(**args)
|
| 555 |
+
|
| 556 |
+
Define the executables (and options for them) that will be run to perform the
|
| 557 |
+
various stages of compilation. The exact set of executables that may be
|
| 558 |
+
specified here depends on the compiler class (via the 'executables' class
|
| 559 |
+
attribute), but most will have:
|
| 560 |
+
|
| 561 |
+
+--------------+------------------------------------------+
|
| 562 |
+
| attribute | description |
|
| 563 |
+
+==============+==========================================+
|
| 564 |
+
| *compiler* | the C/C++ compiler |
|
| 565 |
+
+--------------+------------------------------------------+
|
| 566 |
+
| *linker_so* | linker used to create shared objects and |
|
| 567 |
+
| | libraries |
|
| 568 |
+
+--------------+------------------------------------------+
|
| 569 |
+
| *linker_exe* | linker used to create binary executables |
|
| 570 |
+
+--------------+------------------------------------------+
|
| 571 |
+
| *archiver* | static library creator |
|
| 572 |
+
+--------------+------------------------------------------+
|
| 573 |
+
|
| 574 |
+
On platforms with a command-line (Unix, DOS/Windows), each of these is a string
|
| 575 |
+
that will be split into executable name and (optional) list of arguments.
|
| 576 |
+
(Splitting the string is done similarly to how Unix shells operate: words are
|
| 577 |
+
delimited by spaces, but quotes and backslashes can override this. See
|
| 578 |
+
:func:`distutils.util.split_quoted`.)
|
| 579 |
+
|
| 580 |
+
The following methods invoke stages in the build process.
|
| 581 |
+
|
| 582 |
+
|
| 583 |
+
.. method:: CCompiler.compile(sources[, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None])
|
| 584 |
+
|
| 585 |
+
Compile one or more source files. Generates object files (e.g. transforms a
|
| 586 |
+
:file:`.c` file to a :file:`.o` file.)
|
| 587 |
+
|
| 588 |
+
*sources* must be a list of filenames, most likely C/C++ files, but in reality
|
| 589 |
+
anything that can be handled by a particular compiler and compiler class (eg.
|
| 590 |
+
:class:`MSVCCompiler` can handle resource files in *sources*). Return a list of
|
| 591 |
+
object filenames, one per source filename in *sources*. Depending on the
|
| 592 |
+
implementation, not all source files will necessarily be compiled, but all
|
| 593 |
+
corresponding object filenames will be returned.
|
| 594 |
+
|
| 595 |
+
If *output_dir* is given, object files will be put under it, while retaining
|
| 596 |
+
their original path component. That is, :file:`foo/bar.c` normally compiles to
|
| 597 |
+
:file:`foo/bar.o` (for a Unix implementation); if *output_dir* is *build*, then
|
| 598 |
+
it would compile to :file:`build/foo/bar.o`.
|
| 599 |
+
|
| 600 |
+
*macros*, if given, must be a list of macro definitions. A macro definition is
|
| 601 |
+
either a ``(name, value)`` 2-tuple or a ``(name,)`` 1-tuple. The former defines
|
| 602 |
+
a macro; if the value is ``None``, the macro is defined without an explicit
|
| 603 |
+
value. The 1-tuple case undefines a macro. Later
|
| 604 |
+
definitions/redefinitions/undefinitions take precedence.
|
| 605 |
+
|
| 606 |
+
*include_dirs*, if given, must be a list of strings, the directories to add to
|
| 607 |
+
the default include file search path for this compilation only.
|
| 608 |
+
|
| 609 |
+
*debug* is a boolean; if true, the compiler will be instructed to output debug
|
| 610 |
+
symbols in (or alongside) the object file(s).
|
| 611 |
+
|
| 612 |
+
*extra_preargs* and *extra_postargs* are implementation-dependent. On platforms
|
| 613 |
+
that have the notion of a command-line (e.g. Unix, DOS/Windows), they are most
|
| 614 |
+
likely lists of strings: extra command-line arguments to prepend/append to the
|
| 615 |
+
compiler command line. On other platforms, consult the implementation class
|
| 616 |
+
documentation. In any event, they are intended as an escape hatch for those
|
| 617 |
+
occasions when the abstract compiler framework doesn't cut the mustard.
|
| 618 |
+
|
| 619 |
+
*depends*, if given, is a list of filenames that all targets depend on. If a
|
| 620 |
+
source file is older than any file in depends, then the source file will be
|
| 621 |
+
recompiled. This supports dependency tracking, but only at a coarse
|
| 622 |
+
granularity.
|
| 623 |
+
|
| 624 |
+
Raises :exc:`CompileError` on failure.
|
| 625 |
+
|
| 626 |
+
|
| 627 |
+
.. method:: CCompiler.create_static_lib(objects, output_libname[, output_dir=None, debug=0, target_lang=None])
|
| 628 |
+
|
| 629 |
+
Link a bunch of stuff together to create a static library file. The "bunch of
|
| 630 |
+
stuff" consists of the list of object files supplied as *objects*, the extra
|
| 631 |
+
object files supplied to :meth:`add_link_object` and/or
|
| 632 |
+
:meth:`set_link_objects`, the libraries supplied to :meth:`add_library` and/or
|
| 633 |
+
:meth:`set_libraries`, and the libraries supplied as *libraries* (if any).
|
| 634 |
+
|
| 635 |
+
*output_libname* should be a library name, not a filename; the filename will be
|
| 636 |
+
inferred from the library name. *output_dir* is the directory where the library
|
| 637 |
+
file will be put.
|
| 638 |
+
|
| 639 |
+
.. XXX defaults to what?
|
| 640 |
+
|
| 641 |
+
*debug* is a boolean; if true, debugging information will be included in the
|
| 642 |
+
library (note that on most platforms, it is the compile step where this matters:
|
| 643 |
+
the *debug* flag is included here just for consistency).
|
| 644 |
+
|
| 645 |
+
*target_lang* is the target language for which the given objects are being
|
| 646 |
+
compiled. This allows specific linkage time treatment of certain languages.
|
| 647 |
+
|
| 648 |
+
Raises :exc:`LibError` on failure.
|
| 649 |
+
|
| 650 |
+
|
| 651 |
+
.. method:: CCompiler.link(target_desc, objects, output_filename[, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None])
|
| 652 |
+
|
| 653 |
+
Link a bunch of stuff together to create an executable or shared library file.
|
| 654 |
+
|
| 655 |
+
The "bunch of stuff" consists of the list of object files supplied as *objects*.
|
| 656 |
+
*output_filename* should be a filename. If *output_dir* is supplied,
|
| 657 |
+
*output_filename* is relative to it (i.e. *output_filename* can provide
|
| 658 |
+
directory components if needed).
|
| 659 |
+
|
| 660 |
+
*libraries* is a list of libraries to link against. These are library names,
|
| 661 |
+
not filenames, since they're translated into filenames in a platform-specific
|
| 662 |
+
way (eg. *foo* becomes :file:`libfoo.a` on Unix and :file:`foo.lib` on
|
| 663 |
+
DOS/Windows). However, they can include a directory component, which means the
|
| 664 |
+
linker will look in that specific directory rather than searching all the normal
|
| 665 |
+
locations.
|
| 666 |
+
|
| 667 |
+
*library_dirs*, if supplied, should be a list of directories to search for
|
| 668 |
+
libraries that were specified as bare library names (ie. no directory
|
| 669 |
+
component). These are on top of the system default and those supplied to
|
| 670 |
+
:meth:`add_library_dir` and/or :meth:`set_library_dirs`. *runtime_library_dirs*
|
| 671 |
+
is a list of directories that will be embedded into the shared library and used
|
| 672 |
+
to search for other shared libraries that \*it\* depends on at run-time. (This
|
| 673 |
+
may only be relevant on Unix.)
|
| 674 |
+
|
| 675 |
+
*export_symbols* is a list of symbols that the shared library will export.
|
| 676 |
+
(This appears to be relevant only on Windows.)
|
| 677 |
+
|
| 678 |
+
*debug* is as for :meth:`compile` and :meth:`create_static_lib`, with the
|
| 679 |
+
slight distinction that it actually matters on most platforms (as opposed to
|
| 680 |
+
:meth:`create_static_lib`, which includes a *debug* flag mostly for form's
|
| 681 |
+
sake).
|
| 682 |
+
|
| 683 |
+
*extra_preargs* and *extra_postargs* are as for :meth:`compile` (except of
|
| 684 |
+
course that they supply command-line arguments for the particular linker being
|
| 685 |
+
used).
|
| 686 |
+
|
| 687 |
+
*target_lang* is the target language for which the given objects are being
|
| 688 |
+
compiled. This allows specific linkage time treatment of certain languages.
|
| 689 |
+
|
| 690 |
+
Raises :exc:`LinkError` on failure.
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
.. method:: CCompiler.link_executable(objects, output_progname[, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, target_lang=None])
|
| 694 |
+
|
| 695 |
+
Link an executable. *output_progname* is the name of the file executable, while
|
| 696 |
+
*objects* are a list of object filenames to link in. Other arguments are as for
|
| 697 |
+
the :meth:`link` method.
|
| 698 |
+
|
| 699 |
+
|
| 700 |
+
.. method:: CCompiler.link_shared_lib(objects, output_libname[, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None])
|
| 701 |
+
|
| 702 |
+
Link a shared library. *output_libname* is the name of the output library,
|
| 703 |
+
while *objects* is a list of object filenames to link in. Other arguments are
|
| 704 |
+
as for the :meth:`link` method.
|
| 705 |
+
|
| 706 |
+
|
| 707 |
+
.. method:: CCompiler.link_shared_object(objects, output_filename[, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None])
|
| 708 |
+
|
| 709 |
+
Link a shared object. *output_filename* is the name of the shared object that
|
| 710 |
+
will be created, while *objects* is a list of object filenames to link in.
|
| 711 |
+
Other arguments are as for the :meth:`link` method.
|
| 712 |
+
|
| 713 |
+
|
| 714 |
+
.. method:: CCompiler.preprocess(source[, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None])
|
| 715 |
+
|
| 716 |
+
Preprocess a single C/C++ source file, named in *source*. Output will be written
|
| 717 |
+
to file named *output_file*, or *stdout* if *output_file* not supplied.
|
| 718 |
+
*macros* is a list of macro definitions as for :meth:`compile`, which will
|
| 719 |
+
augment the macros set with :meth:`define_macro` and :meth:`undefine_macro`.
|
| 720 |
+
*include_dirs* is a list of directory names that will be added to the default
|
| 721 |
+
list, in the same way as :meth:`add_include_dir`.
|
| 722 |
+
|
| 723 |
+
Raises :exc:`PreprocessError` on failure.
|
| 724 |
+
|
| 725 |
+
The following utility methods are defined by the :class:`CCompiler` class, for
|
| 726 |
+
use by the various concrete subclasses.
|
| 727 |
+
|
| 728 |
+
|
| 729 |
+
.. method:: CCompiler.executable_filename(basename[, strip_dir=0, output_dir=''])
|
| 730 |
+
|
| 731 |
+
Returns the filename of the executable for the given *basename*. Typically for
|
| 732 |
+
non-Windows platforms this is the same as the basename, while Windows will get
|
| 733 |
+
a :file:`.exe` added.
|
| 734 |
+
|
| 735 |
+
|
| 736 |
+
.. method:: CCompiler.library_filename(libname[, lib_type='static', strip_dir=0, output_dir=''])
|
| 737 |
+
|
| 738 |
+
Returns the filename for the given library name on the current platform. On Unix
|
| 739 |
+
a library with *lib_type* of ``'static'`` will typically be of the form
|
| 740 |
+
:file:`liblibname.a`, while a *lib_type* of ``'dynamic'`` will be of the form
|
| 741 |
+
:file:`liblibname.so`.
|
| 742 |
+
|
| 743 |
+
|
| 744 |
+
.. method:: CCompiler.object_filenames(source_filenames[, strip_dir=0, output_dir=''])
|
| 745 |
+
|
| 746 |
+
Returns the name of the object files for the given source files.
|
| 747 |
+
*source_filenames* should be a list of filenames.
|
| 748 |
+
|
| 749 |
+
|
| 750 |
+
.. method:: CCompiler.shared_object_filename(basename[, strip_dir=0, output_dir=''])
|
| 751 |
+
|
| 752 |
+
Returns the name of a shared object file for the given file name *basename*.
|
| 753 |
+
|
| 754 |
+
|
| 755 |
+
.. method:: CCompiler.execute(func, args[, msg=None, level=1])
|
| 756 |
+
|
| 757 |
+
Invokes :func:`distutils.util.execute`. This method invokes a Python function
|
| 758 |
+
*func* with the given arguments *args*, after logging and taking into account
|
| 759 |
+
the *dry_run* flag.
|
| 760 |
+
|
| 761 |
+
|
| 762 |
+
.. method:: CCompiler.spawn(cmd)
|
| 763 |
+
|
| 764 |
+
Invokes :func:`distutils.util.spawn`. This invokes an external process to run
|
| 765 |
+
the given command.
|
| 766 |
+
|
| 767 |
+
|
| 768 |
+
.. method:: CCompiler.mkpath(name[, mode=511])
|
| 769 |
+
|
| 770 |
+
Invokes :func:`distutils.dir_util.mkpath`. This creates a directory and any
|
| 771 |
+
missing ancestor directories.
|
| 772 |
+
|
| 773 |
+
|
| 774 |
+
.. method:: CCompiler.move_file(src, dst)
|
| 775 |
+
|
| 776 |
+
Invokes :meth:`distutils.file_util.move_file`. Renames *src* to *dst*.
|
| 777 |
+
|
| 778 |
+
|
| 779 |
+
.. method:: CCompiler.announce(msg[, level=1])
|
| 780 |
+
|
| 781 |
+
Write a message using :func:`distutils.log.debug`.
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
.. method:: CCompiler.warn(msg)
|
| 785 |
+
|
| 786 |
+
Write a warning message *msg* to standard error.
|
| 787 |
+
|
| 788 |
+
|
| 789 |
+
.. method:: CCompiler.debug_print(msg)
|
| 790 |
+
|
| 791 |
+
If the *debug* flag is set on this :class:`CCompiler` instance, print *msg* to
|
| 792 |
+
standard output, otherwise do nothing.
|
| 793 |
+
|
| 794 |
+
.. % \subsection{Compiler-specific modules}
|
| 795 |
+
.. %
|
| 796 |
+
.. % The following modules implement concrete subclasses of the abstract
|
| 797 |
+
.. % \class{CCompiler} class. They should not be instantiated directly, but should
|
| 798 |
+
.. % be created using \function{distutils.ccompiler.new_compiler()} factory
|
| 799 |
+
.. % function.
|
| 800 |
+
|
| 801 |
+
|
| 802 |
+
:mod:`distutils.unixccompiler` --- Unix C Compiler
|
| 803 |
+
==================================================
|
| 804 |
+
|
| 805 |
+
.. module:: distutils.unixccompiler
|
| 806 |
+
:synopsis: UNIX C Compiler
|
| 807 |
+
|
| 808 |
+
|
| 809 |
+
This module provides the :class:`UnixCCompiler` class, a subclass of
|
| 810 |
+
:class:`CCompiler` that handles the typical Unix-style command-line C compiler:
|
| 811 |
+
|
| 812 |
+
* macros defined with :option:`!-Dname[=value]`
|
| 813 |
+
|
| 814 |
+
* macros undefined with :option:`!-Uname`
|
| 815 |
+
|
| 816 |
+
* include search directories specified with :option:`!-Idir`
|
| 817 |
+
|
| 818 |
+
* libraries specified with :option:`!-llib`
|
| 819 |
+
|
| 820 |
+
* library search directories specified with :option:`!-Ldir`
|
| 821 |
+
|
| 822 |
+
* compile handled by :program:`cc` (or similar) executable with :option:`!-c`
|
| 823 |
+
option: compiles :file:`.c` to :file:`.o`
|
| 824 |
+
|
| 825 |
+
* link static library handled by :program:`ar` command (possibly with
|
| 826 |
+
:program:`ranlib`)
|
| 827 |
+
|
| 828 |
+
* link shared library handled by :program:`cc` :option:`!-shared`
|
| 829 |
+
|
| 830 |
+
|
| 831 |
+
:mod:`distutils.msvccompiler` --- Microsoft Compiler
|
| 832 |
+
====================================================
|
| 833 |
+
|
| 834 |
+
.. module:: distutils.msvccompiler
|
| 835 |
+
:synopsis: Microsoft Compiler
|
| 836 |
+
|
| 837 |
+
.. XXX: This is *waaaaay* out of date!
|
| 838 |
+
|
| 839 |
+
This module provides :class:`MSVCCompiler`, an implementation of the abstract
|
| 840 |
+
:class:`CCompiler` class for Microsoft Visual Studio. Typically, extension
|
| 841 |
+
modules need to be compiled with the same compiler that was used to compile
|
| 842 |
+
Python. For Python 2.3 and earlier, the compiler was Visual Studio 6. For Python
|
| 843 |
+
2.4 and 2.5, the compiler is Visual Studio .NET 2003.
|
| 844 |
+
|
| 845 |
+
:class:`MSVCCompiler` will normally choose the right compiler, linker etc. on
|
| 846 |
+
its own. To override this choice, the environment variables *DISTUTILS_USE_SDK*
|
| 847 |
+
and *MSSdk* must be both set. *MSSdk* indicates that the current environment has
|
| 848 |
+
been setup by the SDK's ``SetEnv.Cmd`` script, or that the environment variables
|
| 849 |
+
had been registered when the SDK was installed; *DISTUTILS_USE_SDK* indicates
|
| 850 |
+
that the distutils user has made an explicit choice to override the compiler
|
| 851 |
+
selection by :class:`MSVCCompiler`.
|
| 852 |
+
|
| 853 |
+
|
| 854 |
+
:mod:`distutils.bcppcompiler` --- Borland Compiler
|
| 855 |
+
==================================================
|
| 856 |
+
|
| 857 |
+
.. module:: distutils.bcppcompiler
|
| 858 |
+
|
| 859 |
+
|
| 860 |
+
This module provides :class:`BorlandCCompiler`, a subclass of the abstract
|
| 861 |
+
:class:`CCompiler` class for the Borland C++ compiler.
|
| 862 |
+
|
| 863 |
+
|
| 864 |
+
:mod:`distutils.cygwincompiler` --- Cygwin Compiler
|
| 865 |
+
===================================================
|
| 866 |
+
|
| 867 |
+
.. module:: distutils.cygwinccompiler
|
| 868 |
+
|
| 869 |
+
|
| 870 |
+
This module provides the :class:`CygwinCCompiler` class, a subclass of
|
| 871 |
+
:class:`UnixCCompiler` that handles the Cygwin port of the GNU C compiler to
|
| 872 |
+
Windows. It also contains the Mingw32CCompiler class which handles the mingw32
|
| 873 |
+
port of GCC (same as cygwin in no-cygwin mode).
|
| 874 |
+
|
| 875 |
+
|
| 876 |
+
:mod:`distutils.archive_util` --- Archiving utilities
|
| 877 |
+
======================================================
|
| 878 |
+
|
| 879 |
+
.. module:: distutils.archive_util
|
| 880 |
+
:synopsis: Utility functions for creating archive files (tarballs, zip files, ...)
|
| 881 |
+
|
| 882 |
+
|
| 883 |
+
This module provides a few functions for creating archive files, such as
|
| 884 |
+
tarballs or zipfiles.
|
| 885 |
+
|
| 886 |
+
|
| 887 |
+
.. function:: make_archive(base_name, format[, root_dir=None, base_dir=None, verbose=0, dry_run=0])
|
| 888 |
+
|
| 889 |
+
Create an archive file (eg. ``zip`` or ``tar``). *base_name* is the name of
|
| 890 |
+
the file to create, minus any format-specific extension; *format* is the
|
| 891 |
+
archive format: one of ``zip``, ``tar``, ``gztar``, ``bztar``, ``xztar``, or
|
| 892 |
+
``ztar``. *root_dir* is a directory that will be the root directory of the
|
| 893 |
+
archive; ie. we typically ``chdir`` into *root_dir* before creating the
|
| 894 |
+
archive. *base_dir* is the directory where we start archiving from; ie.
|
| 895 |
+
*base_dir* will be the common prefix of all files and directories in the
|
| 896 |
+
archive. *root_dir* and *base_dir* both default to the current directory.
|
| 897 |
+
Returns the name of the archive file.
|
| 898 |
+
|
| 899 |
+
.. versionchanged:: 3.5
|
| 900 |
+
Added support for the ``xztar`` format.
|
| 901 |
+
|
| 902 |
+
|
| 903 |
+
.. function:: make_tarball(base_name, base_dir[, compress='gzip', verbose=0, dry_run=0])
|
| 904 |
+
|
| 905 |
+
'Create an (optional compressed) archive as a tar file from all files in and
|
| 906 |
+
under *base_dir*. *compress* must be ``'gzip'`` (the default),
|
| 907 |
+
``'bzip2'``, ``'xz'``, ``'compress'``, or ``None``. For the ``'compress'``
|
| 908 |
+
method the compression utility named by :program:`compress` must be on the
|
| 909 |
+
default program search path, so this is probably Unix-specific. The output
|
| 910 |
+
tar file will be named :file:`base_dir.tar`, possibly plus the appropriate
|
| 911 |
+
compression extension (``.gz``, ``.bz2``, ``.xz`` or ``.Z``). Return the
|
| 912 |
+
output filename.
|
| 913 |
+
|
| 914 |
+
.. versionchanged:: 3.5
|
| 915 |
+
Added support for the ``xz`` compression.
|
| 916 |
+
|
| 917 |
+
|
| 918 |
+
.. function:: make_zipfile(base_name, base_dir[, verbose=0, dry_run=0])
|
| 919 |
+
|
| 920 |
+
Create a zip file from all files in and under *base_dir*. The output zip file
|
| 921 |
+
will be named *base_name* + :file:`.zip`. Uses either the :mod:`zipfile` Python
|
| 922 |
+
module (if available) or the InfoZIP :file:`zip` utility (if installed and
|
| 923 |
+
found on the default search path). If neither tool is available, raises
|
| 924 |
+
:exc:`DistutilsExecError`. Returns the name of the output zip file.
|
| 925 |
+
|
| 926 |
+
|
| 927 |
+
:mod:`distutils.dep_util` --- Dependency checking
|
| 928 |
+
=================================================
|
| 929 |
+
|
| 930 |
+
.. module:: distutils.dep_util
|
| 931 |
+
:synopsis: Utility functions for simple dependency checking
|
| 932 |
+
|
| 933 |
+
|
| 934 |
+
This module provides functions for performing simple, timestamp-based
|
| 935 |
+
dependency of files and groups of files; also, functions based entirely on such
|
| 936 |
+
timestamp dependency analysis.
|
| 937 |
+
|
| 938 |
+
|
| 939 |
+
.. function:: newer(source, target)
|
| 940 |
+
|
| 941 |
+
Return true if *source* exists and is more recently modified than *target*, or
|
| 942 |
+
if *source* exists and *target* doesn't. Return false if both exist and *target*
|
| 943 |
+
is the same age or newer than *source*. Raise :exc:`DistutilsFileError` if
|
| 944 |
+
*source* does not exist.
|
| 945 |
+
|
| 946 |
+
|
| 947 |
+
.. function:: newer_pairwise(sources, targets)
|
| 948 |
+
|
| 949 |
+
Walk two filename lists in parallel, testing if each source is newer than its
|
| 950 |
+
corresponding target. Return a pair of lists (*sources*, *targets*) where
|
| 951 |
+
source is newer than target, according to the semantics of :func:`newer`.
|
| 952 |
+
|
| 953 |
+
.. % % equivalent to a listcomp...
|
| 954 |
+
|
| 955 |
+
|
| 956 |
+
.. function:: newer_group(sources, target[, missing='error'])
|
| 957 |
+
|
| 958 |
+
Return true if *target* is out-of-date with respect to any file listed in
|
| 959 |
+
*sources*. In other words, if *target* exists and is newer than every file in
|
| 960 |
+
*sources*, return false; otherwise return true. *missing* controls what we do
|
| 961 |
+
when a source file is missing; the default (``'error'``) is to blow up with an
|
| 962 |
+
:exc:`OSError` from inside :func:`os.stat`; if it is ``'ignore'``, we silently
|
| 963 |
+
drop any missing source files; if it is ``'newer'``, any missing source files
|
| 964 |
+
make us assume that *target* is out-of-date (this is handy in "dry-run" mode:
|
| 965 |
+
it'll make you pretend to carry out commands that wouldn't work because inputs
|
| 966 |
+
are missing, but that doesn't matter because you're not actually going to run
|
| 967 |
+
the commands).
|
| 968 |
+
|
| 969 |
+
|
| 970 |
+
:mod:`distutils.dir_util` --- Directory tree operations
|
| 971 |
+
=======================================================
|
| 972 |
+
|
| 973 |
+
.. module:: distutils.dir_util
|
| 974 |
+
:synopsis: Utility functions for operating on directories and directory trees
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
This module provides functions for operating on directories and trees of
|
| 978 |
+
directories.
|
| 979 |
+
|
| 980 |
+
|
| 981 |
+
.. function:: mkpath(name[, mode=0o777, verbose=0, dry_run=0])
|
| 982 |
+
|
| 983 |
+
Create a directory and any missing ancestor directories. If the directory
|
| 984 |
+
already exists (or if *name* is the empty string, which means the current
|
| 985 |
+
directory, which of course exists), then do nothing. Raise
|
| 986 |
+
:exc:`DistutilsFileError` if unable to create some directory along the way (eg.
|
| 987 |
+
some sub-path exists, but is a file rather than a directory). If *verbose* is
|
| 988 |
+
true, print a one-line summary of each mkdir to stdout. Return the list of
|
| 989 |
+
directories actually created.
|
| 990 |
+
|
| 991 |
+
|
| 992 |
+
.. function:: create_tree(base_dir, files[, mode=0o777, verbose=0, dry_run=0])
|
| 993 |
+
|
| 994 |
+
Create all the empty directories under *base_dir* needed to put *files* there.
|
| 995 |
+
*base_dir* is just the name of a directory which doesn't necessarily exist
|
| 996 |
+
yet; *files* is a list of filenames to be interpreted relative to *base_dir*.
|
| 997 |
+
*base_dir* + the directory portion of every file in *files* will be created if
|
| 998 |
+
it doesn't already exist. *mode*, *verbose* and *dry_run* flags are as for
|
| 999 |
+
:func:`mkpath`.
|
| 1000 |
+
|
| 1001 |
+
|
| 1002 |
+
.. function:: copy_tree(src, dst[, preserve_mode=1, preserve_times=1, preserve_symlinks=0, update=0, verbose=0, dry_run=0])
|
| 1003 |
+
|
| 1004 |
+
Copy an entire directory tree *src* to a new location *dst*. Both *src* and
|
| 1005 |
+
*dst* must be directory names. If *src* is not a directory, raise
|
| 1006 |
+
:exc:`DistutilsFileError`. If *dst* does not exist, it is created with
|
| 1007 |
+
:func:`mkpath`. The end result of the copy is that every file in *src* is
|
| 1008 |
+
copied to *dst*, and directories under *src* are recursively copied to *dst*.
|
| 1009 |
+
Return the list of files that were copied or might have been copied, using their
|
| 1010 |
+
output name. The return value is unaffected by *update* or *dry_run*: it is
|
| 1011 |
+
simply the list of all files under *src*, with the names changed to be under
|
| 1012 |
+
*dst*.
|
| 1013 |
+
|
| 1014 |
+
*preserve_mode* and *preserve_times* are the same as for
|
| 1015 |
+
:func:`distutils.file_util.copy_file`; note that they only apply to
|
| 1016 |
+
regular files, not to
|
| 1017 |
+
directories. If *preserve_symlinks* is true, symlinks will be copied as
|
| 1018 |
+
symlinks (on platforms that support them!); otherwise (the default), the
|
| 1019 |
+
destination of the symlink will be copied. *update* and *verbose* are the same
|
| 1020 |
+
as for :func:`copy_file`.
|
| 1021 |
+
|
| 1022 |
+
Files in *src* that begin with :file:`.nfs` are skipped (more information on
|
| 1023 |
+
these files is available in answer D2 of the `NFS FAQ page
|
| 1024 |
+
<http://nfs.sourceforge.net/#section_d>`_).
|
| 1025 |
+
|
| 1026 |
+
.. versionchanged:: 3.3.1
|
| 1027 |
+
NFS files are ignored.
|
| 1028 |
+
|
| 1029 |
+
.. function:: remove_tree(directory[, verbose=0, dry_run=0])
|
| 1030 |
+
|
| 1031 |
+
Recursively remove *directory* and all files and directories underneath it. Any
|
| 1032 |
+
errors are ignored (apart from being reported to ``sys.stdout`` if *verbose* is
|
| 1033 |
+
true).
|
| 1034 |
+
|
| 1035 |
+
|
| 1036 |
+
:mod:`distutils.file_util` --- Single file operations
|
| 1037 |
+
=====================================================
|
| 1038 |
+
|
| 1039 |
+
.. module:: distutils.file_util
|
| 1040 |
+
:synopsis: Utility functions for operating on single files
|
| 1041 |
+
|
| 1042 |
+
|
| 1043 |
+
This module contains some utility functions for operating on individual files.
|
| 1044 |
+
|
| 1045 |
+
|
| 1046 |
+
.. function:: copy_file(src, dst[, preserve_mode=1, preserve_times=1, update=0, link=None, verbose=0, dry_run=0])
|
| 1047 |
+
|
| 1048 |
+
Copy file *src* to *dst*. If *dst* is a directory, then *src* is copied there
|
| 1049 |
+
with the same name; otherwise, it must be a filename. (If the file exists, it
|
| 1050 |
+
will be ruthlessly clobbered.) If *preserve_mode* is true (the default), the
|
| 1051 |
+
file's mode (type and permission bits, or whatever is analogous on the
|
| 1052 |
+
current platform) is copied. If *preserve_times* is true (the default), the
|
| 1053 |
+
last-modified and last-access times are copied as well. If *update* is true,
|
| 1054 |
+
*src* will only be copied if *dst* does not exist, or if *dst* does exist but
|
| 1055 |
+
is older than *src*.
|
| 1056 |
+
|
| 1057 |
+
*link* allows you to make hard links (using :func:`os.link`) or symbolic links
|
| 1058 |
+
(using :func:`os.symlink`) instead of copying: set it to ``'hard'`` or
|
| 1059 |
+
``'sym'``; if it is ``None`` (the default), files are copied. Don't set *link*
|
| 1060 |
+
on systems that don't support it: :func:`copy_file` doesn't check if hard or
|
| 1061 |
+
symbolic linking is available. It uses :func:`_copy_file_contents` to copy file
|
| 1062 |
+
contents.
|
| 1063 |
+
|
| 1064 |
+
Return a tuple ``(dest_name, copied)``: *dest_name* is the actual name of the
|
| 1065 |
+
output file, and *copied* is true if the file was copied (or would have been
|
| 1066 |
+
copied, if *dry_run* true).
|
| 1067 |
+
|
| 1068 |
+
.. % XXX if the destination file already exists, we clobber it if
|
| 1069 |
+
.. % copying, but blow up if linking. Hmmm. And I don't know what
|
| 1070 |
+
.. % macostools.copyfile() does. Should definitely be consistent, and
|
| 1071 |
+
.. % should probably blow up if destination exists and we would be
|
| 1072 |
+
.. % changing it (ie. it's not already a hard/soft link to src OR
|
| 1073 |
+
.. % (not update) and (src newer than dst)).
|
| 1074 |
+
|
| 1075 |
+
|
| 1076 |
+
.. function:: move_file(src, dst[, verbose, dry_run])
|
| 1077 |
+
|
| 1078 |
+
Move file *src* to *dst*. If *dst* is a directory, the file will be moved into
|
| 1079 |
+
it with the same name; otherwise, *src* is just renamed to *dst*. Returns the
|
| 1080 |
+
new full name of the file.
|
| 1081 |
+
|
| 1082 |
+
.. warning::
|
| 1083 |
+
|
| 1084 |
+
Handles cross-device moves on Unix using :func:`copy_file`. What about
|
| 1085 |
+
other systems?
|
| 1086 |
+
|
| 1087 |
+
|
| 1088 |
+
.. function:: write_file(filename, contents)
|
| 1089 |
+
|
| 1090 |
+
Create a file called *filename* and write *contents* (a sequence of strings
|
| 1091 |
+
without line terminators) to it.
|
| 1092 |
+
|
| 1093 |
+
|
| 1094 |
+
:mod:`distutils.util` --- Miscellaneous other utility functions
|
| 1095 |
+
===============================================================
|
| 1096 |
+
|
| 1097 |
+
.. module:: distutils.util
|
| 1098 |
+
:synopsis: Miscellaneous other utility functions
|
| 1099 |
+
|
| 1100 |
+
|
| 1101 |
+
This module contains other assorted bits and pieces that don't fit into any
|
| 1102 |
+
other utility module.
|
| 1103 |
+
|
| 1104 |
+
|
| 1105 |
+
.. function:: get_platform()
|
| 1106 |
+
|
| 1107 |
+
Return a string that identifies the current platform. This is used mainly to
|
| 1108 |
+
distinguish platform-specific build directories and platform-specific built
|
| 1109 |
+
distributions. Typically includes the OS name and version and the
|
| 1110 |
+
architecture (as supplied by 'os.uname()'), although the exact information
|
| 1111 |
+
included depends on the OS; e.g., on Linux, the kernel version isn't
|
| 1112 |
+
particularly important.
|
| 1113 |
+
|
| 1114 |
+
Examples of returned values:
|
| 1115 |
+
|
| 1116 |
+
* ``linux-i586``
|
| 1117 |
+
* ``linux-alpha``
|
| 1118 |
+
* ``solaris-2.6-sun4u``
|
| 1119 |
+
|
| 1120 |
+
For non-POSIX platforms, currently just returns ``sys.platform``.
|
| 1121 |
+
|
| 1122 |
+
For Mac OS X systems the OS version reflects the minimal version on which
|
| 1123 |
+
binaries will run (that is, the value of ``MACOSX_DEPLOYMENT_TARGET``
|
| 1124 |
+
during the build of Python), not the OS version of the current system.
|
| 1125 |
+
|
| 1126 |
+
For universal binary builds on Mac OS X the architecture value reflects
|
| 1127 |
+
the universal binary status instead of the architecture of the current
|
| 1128 |
+
processor. For 32-bit universal binaries the architecture is ``fat``,
|
| 1129 |
+
for 64-bit universal binaries the architecture is ``fat64``, and
|
| 1130 |
+
for 4-way universal binaries the architecture is ``universal``. Starting
|
| 1131 |
+
from Python 2.7 and Python 3.2 the architecture ``fat3`` is used for
|
| 1132 |
+
a 3-way universal build (ppc, i386, x86_64) and ``intel`` is used for
|
| 1133 |
+
a universal build with the i386 and x86_64 architectures
|
| 1134 |
+
|
| 1135 |
+
Examples of returned values on Mac OS X:
|
| 1136 |
+
|
| 1137 |
+
* ``macosx-10.3-ppc``
|
| 1138 |
+
|
| 1139 |
+
* ``macosx-10.3-fat``
|
| 1140 |
+
|
| 1141 |
+
* ``macosx-10.5-universal``
|
| 1142 |
+
|
| 1143 |
+
* ``macosx-10.6-intel``
|
| 1144 |
+
|
| 1145 |
+
For AIX, Python 3.9 and later return a string starting with "aix", followed
|
| 1146 |
+
by additional fields (separated by ``'-'``) that represent the combined
|
| 1147 |
+
values of AIX Version, Release and Technology Level (first field), Build Date
|
| 1148 |
+
(second field), and bit-size (third field). Python 3.8 and earlier returned
|
| 1149 |
+
only a single additional field with the AIX Version and Release.
|
| 1150 |
+
|
| 1151 |
+
Examples of returned values on AIX:
|
| 1152 |
+
|
| 1153 |
+
* ``aix-5307-0747-32`` # 32-bit build on AIX ``oslevel -s``: 5300-07-00-0000
|
| 1154 |
+
|
| 1155 |
+
* ``aix-7105-1731-64`` # 64-bit build on AIX ``oslevel -s``: 7100-05-01-1731
|
| 1156 |
+
|
| 1157 |
+
* ``aix-7.2`` # Legacy form reported in Python 3.8 and earlier
|
| 1158 |
+
|
| 1159 |
+
.. versionchanged:: 3.9
|
| 1160 |
+
The AIX platform string format now also includes the technology level,
|
| 1161 |
+
build date, and ABI bit-size.
|
| 1162 |
+
|
| 1163 |
+
|
| 1164 |
+
.. function:: convert_path(pathname)
|
| 1165 |
+
|
| 1166 |
+
Return 'pathname' as a name that will work on the native filesystem, i.e. split
|
| 1167 |
+
it on '/' and put it back together again using the current directory separator.
|
| 1168 |
+
Needed because filenames in the setup script are always supplied in Unix style,
|
| 1169 |
+
and have to be converted to the local convention before we can actually use them
|
| 1170 |
+
in the filesystem. Raises :exc:`ValueError` on non-Unix-ish systems if
|
| 1171 |
+
*pathname* either starts or ends with a slash.
|
| 1172 |
+
|
| 1173 |
+
|
| 1174 |
+
.. function:: change_root(new_root, pathname)
|
| 1175 |
+
|
| 1176 |
+
Return *pathname* with *new_root* prepended. If *pathname* is relative, this is
|
| 1177 |
+
equivalent to ``os.path.join(new_root,pathname)`` Otherwise, it requires making
|
| 1178 |
+
*pathname* relative and then joining the two, which is tricky on DOS/Windows.
|
| 1179 |
+
|
| 1180 |
+
|
| 1181 |
+
.. function:: check_environ()
|
| 1182 |
+
|
| 1183 |
+
Ensure that 'os.environ' has all the environment variables we guarantee that
|
| 1184 |
+
users can use in config files, command-line options, etc. Currently this
|
| 1185 |
+
includes:
|
| 1186 |
+
|
| 1187 |
+
* :envvar:`HOME` - user's home directory (Unix only)
|
| 1188 |
+
* :envvar:`PLAT` - description of the current platform, including hardware and
|
| 1189 |
+
OS (see :func:`get_platform`)
|
| 1190 |
+
|
| 1191 |
+
|
| 1192 |
+
.. function:: subst_vars(s, local_vars)
|
| 1193 |
+
|
| 1194 |
+
Perform shell/Perl-style variable substitution on *s*. Every occurrence of
|
| 1195 |
+
``$`` followed by a name is considered a variable, and variable is substituted
|
| 1196 |
+
by the value found in the *local_vars* dictionary, or in ``os.environ`` if it's
|
| 1197 |
+
not in *local_vars*. *os.environ* is first checked/augmented to guarantee that
|
| 1198 |
+
it contains certain values: see :func:`check_environ`. Raise :exc:`ValueError`
|
| 1199 |
+
for any variables not found in either *local_vars* or ``os.environ``.
|
| 1200 |
+
|
| 1201 |
+
Note that this is not a fully-fledged string interpolation function. A valid
|
| 1202 |
+
``$variable`` can consist only of upper and lower case letters, numbers and an
|
| 1203 |
+
underscore. No { } or ( ) style quoting is available.
|
| 1204 |
+
|
| 1205 |
+
|
| 1206 |
+
.. function:: split_quoted(s)
|
| 1207 |
+
|
| 1208 |
+
Split a string up according to Unix shell-like rules for quotes and backslashes.
|
| 1209 |
+
In short: words are delimited by spaces, as long as those spaces are not escaped
|
| 1210 |
+
by a backslash, or inside a quoted string. Single and double quotes are
|
| 1211 |
+
equivalent, and the quote characters can be backslash-escaped. The backslash is
|
| 1212 |
+
stripped from any two-character escape sequence, leaving only the escaped
|
| 1213 |
+
character. The quote characters are stripped from any quoted string. Returns a
|
| 1214 |
+
list of words.
|
| 1215 |
+
|
| 1216 |
+
.. % Should probably be moved into the standard library.
|
| 1217 |
+
|
| 1218 |
+
|
| 1219 |
+
.. function:: execute(func, args[, msg=None, verbose=0, dry_run=0])
|
| 1220 |
+
|
| 1221 |
+
Perform some action that affects the outside world (for instance, writing to the
|
| 1222 |
+
filesystem). Such actions are special because they are disabled by the
|
| 1223 |
+
*dry_run* flag. This method takes care of all that bureaucracy for you; all
|
| 1224 |
+
you have to do is supply the function to call and an argument tuple for it (to
|
| 1225 |
+
embody the "external action" being performed), and an optional message to print.
|
| 1226 |
+
|
| 1227 |
+
|
| 1228 |
+
.. function:: strtobool(val)
|
| 1229 |
+
|
| 1230 |
+
Convert a string representation of truth to true (1) or false (0).
|
| 1231 |
+
|
| 1232 |
+
True values are ``y``, ``yes``, ``t``, ``true``, ``on`` and ``1``; false values
|
| 1233 |
+
are ``n``, ``no``, ``f``, ``false``, ``off`` and ``0``. Raises
|
| 1234 |
+
:exc:`ValueError` if *val* is anything else.
|
| 1235 |
+
|
| 1236 |
+
|
| 1237 |
+
.. function:: byte_compile(py_files[, optimize=0, force=0, prefix=None, base_dir=None, verbose=1, dry_run=0, direct=None])
|
| 1238 |
+
|
| 1239 |
+
Byte-compile a collection of Python source files to :file:`.pyc` files in a
|
| 1240 |
+
:file:`__pycache__` subdirectory (see :pep:`3147` and :pep:`488`).
|
| 1241 |
+
*py_files* is a list of files to compile; any files that don't end in
|
| 1242 |
+
:file:`.py` are silently skipped. *optimize* must be one of the following:
|
| 1243 |
+
|
| 1244 |
+
* ``0`` - don't optimize
|
| 1245 |
+
* ``1`` - normal optimization (like ``python -O``)
|
| 1246 |
+
* ``2`` - extra optimization (like ``python -OO``)
|
| 1247 |
+
|
| 1248 |
+
If *force* is true, all files are recompiled regardless of timestamps.
|
| 1249 |
+
|
| 1250 |
+
The source filename encoded in each :term:`bytecode` file defaults to the filenames
|
| 1251 |
+
listed in *py_files*; you can modify these with *prefix* and *basedir*.
|
| 1252 |
+
*prefix* is a string that will be stripped off of each source filename, and
|
| 1253 |
+
*base_dir* is a directory name that will be prepended (after *prefix* is
|
| 1254 |
+
stripped). You can supply either or both (or neither) of *prefix* and
|
| 1255 |
+
*base_dir*, as you wish.
|
| 1256 |
+
|
| 1257 |
+
If *dry_run* is true, doesn't actually do anything that would affect the
|
| 1258 |
+
filesystem.
|
| 1259 |
+
|
| 1260 |
+
Byte-compilation is either done directly in this interpreter process with the
|
| 1261 |
+
standard :mod:`py_compile` module, or indirectly by writing a temporary script
|
| 1262 |
+
and executing it. Normally, you should let :func:`byte_compile` figure out to
|
| 1263 |
+
use direct compilation or not (see the source for details). The *direct* flag
|
| 1264 |
+
is used by the script generated in indirect mode; unless you know what you're
|
| 1265 |
+
doing, leave it set to ``None``.
|
| 1266 |
+
|
| 1267 |
+
.. versionchanged:: 3.2.3
|
| 1268 |
+
Create ``.pyc`` files with an :func:`import magic tag
|
| 1269 |
+
<imp.get_tag>` in their name, in a :file:`__pycache__` subdirectory
|
| 1270 |
+
instead of files without tag in the current directory.
|
| 1271 |
+
|
| 1272 |
+
.. versionchanged:: 3.5
|
| 1273 |
+
Create ``.pyc`` files according to :pep:`488`.
|
| 1274 |
+
|
| 1275 |
+
|
| 1276 |
+
.. function:: rfc822_escape(header)
|
| 1277 |
+
|
| 1278 |
+
Return a version of *header* escaped for inclusion in an :rfc:`822` header, by
|
| 1279 |
+
ensuring there are 8 spaces space after each newline. Note that it does no other
|
| 1280 |
+
modification of the string.
|
| 1281 |
+
|
| 1282 |
+
.. % this _can_ be replaced
|
| 1283 |
+
|
| 1284 |
+
.. % \subsection{Distutils objects}
|
| 1285 |
+
|
| 1286 |
+
|
| 1287 |
+
:mod:`distutils.dist` --- The Distribution class
|
| 1288 |
+
================================================
|
| 1289 |
+
|
| 1290 |
+
.. module:: distutils.dist
|
| 1291 |
+
:synopsis: Provides the Distribution class, which represents the module distribution being
|
| 1292 |
+
built/installed/distributed
|
| 1293 |
+
|
| 1294 |
+
|
| 1295 |
+
This module provides the :class:`~distutils.core.Distribution` class, which
|
| 1296 |
+
represents the module distribution being built/installed/distributed.
|
| 1297 |
+
|
| 1298 |
+
|
| 1299 |
+
:mod:`distutils.extension` --- The Extension class
|
| 1300 |
+
==================================================
|
| 1301 |
+
|
| 1302 |
+
.. module:: distutils.extension
|
| 1303 |
+
:synopsis: Provides the Extension class, used to describe C/C++ extension modules in setup
|
| 1304 |
+
scripts
|
| 1305 |
+
|
| 1306 |
+
|
| 1307 |
+
This module provides the :class:`Extension` class, used to describe C/C++
|
| 1308 |
+
extension modules in setup scripts.
|
| 1309 |
+
|
| 1310 |
+
.. % \subsection{Ungrouped modules}
|
| 1311 |
+
.. % The following haven't been moved into a more appropriate section yet.
|
| 1312 |
+
|
| 1313 |
+
|
| 1314 |
+
:mod:`distutils.debug` --- Distutils debug mode
|
| 1315 |
+
===============================================
|
| 1316 |
+
|
| 1317 |
+
.. module:: distutils.debug
|
| 1318 |
+
:synopsis: Provides the debug flag for distutils
|
| 1319 |
+
|
| 1320 |
+
|
| 1321 |
+
This module provides the DEBUG flag.
|
| 1322 |
+
|
| 1323 |
+
|
| 1324 |
+
:mod:`distutils.errors` --- Distutils exceptions
|
| 1325 |
+
================================================
|
| 1326 |
+
|
| 1327 |
+
.. module:: distutils.errors
|
| 1328 |
+
:synopsis: Provides standard distutils exceptions
|
| 1329 |
+
|
| 1330 |
+
|
| 1331 |
+
Provides exceptions used by the Distutils modules. Note that Distutils modules
|
| 1332 |
+
may raise standard exceptions; in particular, SystemExit is usually raised for
|
| 1333 |
+
errors that are obviously the end-user's fault (eg. bad command-line arguments).
|
| 1334 |
+
|
| 1335 |
+
This module is safe to use in ``from ... import *`` mode; it only exports
|
| 1336 |
+
symbols whose names start with ``Distutils`` and end with ``Error``.
|
| 1337 |
+
|
| 1338 |
+
|
| 1339 |
+
:mod:`distutils.fancy_getopt` --- Wrapper around the standard getopt module
|
| 1340 |
+
===========================================================================
|
| 1341 |
+
|
| 1342 |
+
.. module:: distutils.fancy_getopt
|
| 1343 |
+
:synopsis: Additional getopt functionality
|
| 1344 |
+
|
| 1345 |
+
|
| 1346 |
+
This module provides a wrapper around the standard :mod:`getopt` module that
|
| 1347 |
+
provides the following additional features:
|
| 1348 |
+
|
| 1349 |
+
* short and long options are tied together
|
| 1350 |
+
|
| 1351 |
+
* options have help strings, so :func:`fancy_getopt` could potentially create a
|
| 1352 |
+
complete usage summary
|
| 1353 |
+
|
| 1354 |
+
* options set attributes of a passed-in object
|
| 1355 |
+
|
| 1356 |
+
* boolean options can have "negative aliases" --- eg. if :option:`!--quiet` is
|
| 1357 |
+
the "negative alias" of :option:`!--verbose`, then :option:`!--quiet` on the
|
| 1358 |
+
command line sets *verbose* to false.
|
| 1359 |
+
|
| 1360 |
+
.. function:: fancy_getopt(options, negative_opt, object, args)
|
| 1361 |
+
|
| 1362 |
+
Wrapper function. *options* is a list of ``(long_option, short_option,
|
| 1363 |
+
help_string)`` 3-tuples as described in the constructor for
|
| 1364 |
+
:class:`FancyGetopt`. *negative_opt* should be a dictionary mapping option names
|
| 1365 |
+
to option names, both the key and value should be in the *options* list.
|
| 1366 |
+
*object* is an object which will be used to store values (see the :meth:`getopt`
|
| 1367 |
+
method of the :class:`FancyGetopt` class). *args* is the argument list. Will use
|
| 1368 |
+
``sys.argv[1:]`` if you pass ``None`` as *args*.
|
| 1369 |
+
|
| 1370 |
+
|
| 1371 |
+
.. function:: wrap_text(text, width)
|
| 1372 |
+
|
| 1373 |
+
Wraps *text* to less than *width* wide.
|
| 1374 |
+
|
| 1375 |
+
|
| 1376 |
+
.. class:: FancyGetopt([option_table=None])
|
| 1377 |
+
|
| 1378 |
+
The option_table is a list of 3-tuples: ``(long_option, short_option,
|
| 1379 |
+
help_string)``
|
| 1380 |
+
|
| 1381 |
+
If an option takes an argument, its *long_option* should have ``'='`` appended;
|
| 1382 |
+
*short_option* should just be a single character, no ``':'`` in any case.
|
| 1383 |
+
*short_option* should be ``None`` if a *long_option* doesn't have a
|
| 1384 |
+
corresponding *short_option*. All option tuples must have long options.
|
| 1385 |
+
|
| 1386 |
+
The :class:`FancyGetopt` class provides the following methods:
|
| 1387 |
+
|
| 1388 |
+
|
| 1389 |
+
.. method:: FancyGetopt.getopt([args=None, object=None])
|
| 1390 |
+
|
| 1391 |
+
Parse command-line options in args. Store as attributes on *object*.
|
| 1392 |
+
|
| 1393 |
+
If *args* is ``None`` or not supplied, uses ``sys.argv[1:]``. If *object* is
|
| 1394 |
+
``None`` or not supplied, creates a new :class:`OptionDummy` instance, stores
|
| 1395 |
+
option values there, and returns a tuple ``(args, object)``. If *object* is
|
| 1396 |
+
supplied, it is modified in place and :func:`getopt` just returns *args*; in
|
| 1397 |
+
both cases, the returned *args* is a modified copy of the passed-in *args* list,
|
| 1398 |
+
which is left untouched.
|
| 1399 |
+
|
| 1400 |
+
.. % and args returned are?
|
| 1401 |
+
|
| 1402 |
+
|
| 1403 |
+
.. method:: FancyGetopt.get_option_order()
|
| 1404 |
+
|
| 1405 |
+
Returns the list of ``(option, value)`` tuples processed by the previous run of
|
| 1406 |
+
:meth:`getopt` Raises :exc:`RuntimeError` if :meth:`getopt` hasn't been called
|
| 1407 |
+
yet.
|
| 1408 |
+
|
| 1409 |
+
|
| 1410 |
+
.. method:: FancyGetopt.generate_help([header=None])
|
| 1411 |
+
|
| 1412 |
+
Generate help text (a list of strings, one per suggested line of output) from
|
| 1413 |
+
the option table for this :class:`FancyGetopt` object.
|
| 1414 |
+
|
| 1415 |
+
If supplied, prints the supplied *header* at the top of the help.
|
| 1416 |
+
|
| 1417 |
+
|
| 1418 |
+
:mod:`distutils.filelist` --- The FileList class
|
| 1419 |
+
================================================
|
| 1420 |
+
|
| 1421 |
+
.. module:: distutils.filelist
|
| 1422 |
+
:synopsis: The FileList class, used for poking about the file system and
|
| 1423 |
+
building lists of files.
|
| 1424 |
+
|
| 1425 |
+
|
| 1426 |
+
This module provides the :class:`FileList` class, used for poking about the
|
| 1427 |
+
filesystem and building lists of files.
|
| 1428 |
+
|
| 1429 |
+
|
| 1430 |
+
:mod:`distutils.log` --- Simple :pep:`282`-style logging
|
| 1431 |
+
========================================================
|
| 1432 |
+
|
| 1433 |
+
.. module:: distutils.log
|
| 1434 |
+
:synopsis: A simple logging mechanism, :pep:`282`-style
|
| 1435 |
+
|
| 1436 |
+
|
| 1437 |
+
:mod:`distutils.spawn` --- Spawn a sub-process
|
| 1438 |
+
==============================================
|
| 1439 |
+
|
| 1440 |
+
.. module:: distutils.spawn
|
| 1441 |
+
:synopsis: Provides the spawn() function
|
| 1442 |
+
|
| 1443 |
+
|
| 1444 |
+
This module provides the :func:`spawn` function, a front-end to various
|
| 1445 |
+
platform-specific functions for launching another program in a sub-process.
|
| 1446 |
+
Also provides :func:`find_executable` to search the path for a given executable
|
| 1447 |
+
name.
|
| 1448 |
+
|
| 1449 |
+
|
| 1450 |
+
:mod:`distutils.sysconfig` --- System configuration information
|
| 1451 |
+
===============================================================
|
| 1452 |
+
|
| 1453 |
+
.. module:: distutils.sysconfig
|
| 1454 |
+
:synopsis: Low-level access to configuration information of the Python interpreter.
|
| 1455 |
+
.. moduleauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
|
| 1456 |
+
.. moduleauthor:: Greg Ward <gward@python.net>
|
| 1457 |
+
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
|
| 1458 |
+
|
| 1459 |
+
|
| 1460 |
+
The :mod:`distutils.sysconfig` module provides access to Python's low-level
|
| 1461 |
+
configuration information. The specific configuration variables available
|
| 1462 |
+
depend heavily on the platform and configuration. The specific variables depend
|
| 1463 |
+
on the build process for the specific version of Python being run; the variables
|
| 1464 |
+
are those found in the :file:`Makefile` and configuration header that are
|
| 1465 |
+
installed with Python on Unix systems. The configuration header is called
|
| 1466 |
+
:file:`pyconfig.h` for Python versions starting with 2.2, and :file:`config.h`
|
| 1467 |
+
for earlier versions of Python.
|
| 1468 |
+
|
| 1469 |
+
Some additional functions are provided which perform some useful manipulations
|
| 1470 |
+
for other parts of the :mod:`distutils` package.
|
| 1471 |
+
|
| 1472 |
+
|
| 1473 |
+
.. data:: PREFIX
|
| 1474 |
+
|
| 1475 |
+
The result of ``os.path.normpath(sys.prefix)``.
|
| 1476 |
+
|
| 1477 |
+
|
| 1478 |
+
.. data:: EXEC_PREFIX
|
| 1479 |
+
|
| 1480 |
+
The result of ``os.path.normpath(sys.exec_prefix)``.
|
| 1481 |
+
|
| 1482 |
+
|
| 1483 |
+
.. function:: get_config_var(name)
|
| 1484 |
+
|
| 1485 |
+
Return the value of a single variable. This is equivalent to
|
| 1486 |
+
``get_config_vars().get(name)``.
|
| 1487 |
+
|
| 1488 |
+
|
| 1489 |
+
.. function:: get_config_vars(...)
|
| 1490 |
+
|
| 1491 |
+
Return a set of variable definitions. If there are no arguments, this returns a
|
| 1492 |
+
dictionary mapping names of configuration variables to values. If arguments are
|
| 1493 |
+
provided, they should be strings, and the return value will be a sequence giving
|
| 1494 |
+
the associated values. If a given name does not have a corresponding value,
|
| 1495 |
+
``None`` will be included for that variable.
|
| 1496 |
+
|
| 1497 |
+
|
| 1498 |
+
.. function:: get_config_h_filename()
|
| 1499 |
+
|
| 1500 |
+
Return the full path name of the configuration header. For Unix, this will be
|
| 1501 |
+
the header generated by the :program:`configure` script; for other platforms the
|
| 1502 |
+
header will have been supplied directly by the Python source distribution. The
|
| 1503 |
+
file is a platform-specific text file.
|
| 1504 |
+
|
| 1505 |
+
|
| 1506 |
+
.. function:: get_makefile_filename()
|
| 1507 |
+
|
| 1508 |
+
Return the full path name of the :file:`Makefile` used to build Python. For
|
| 1509 |
+
Unix, this will be a file generated by the :program:`configure` script; the
|
| 1510 |
+
meaning for other platforms will vary. The file is a platform-specific text
|
| 1511 |
+
file, if it exists. This function is only useful on POSIX platforms.
|
| 1512 |
+
|
| 1513 |
+
|
| 1514 |
+
.. function:: get_python_inc([plat_specific[, prefix]])
|
| 1515 |
+
|
| 1516 |
+
Return the directory for either the general or platform-dependent C include
|
| 1517 |
+
files. If *plat_specific* is true, the platform-dependent include directory is
|
| 1518 |
+
returned; if false or omitted, the platform-independent directory is returned.
|
| 1519 |
+
If *prefix* is given, it is used as either the prefix instead of
|
| 1520 |
+
:const:`PREFIX`, or as the exec-prefix instead of :const:`EXEC_PREFIX` if
|
| 1521 |
+
*plat_specific* is true.
|
| 1522 |
+
|
| 1523 |
+
|
| 1524 |
+
.. function:: get_python_lib([plat_specific[, standard_lib[, prefix]]])
|
| 1525 |
+
|
| 1526 |
+
Return the directory for either the general or platform-dependent library
|
| 1527 |
+
installation. If *plat_specific* is true, the platform-dependent include
|
| 1528 |
+
directory is returned; if false or omitted, the platform-independent directory
|
| 1529 |
+
is returned. If *prefix* is given, it is used as either the prefix instead of
|
| 1530 |
+
:const:`PREFIX`, or as the exec-prefix instead of :const:`EXEC_PREFIX` if
|
| 1531 |
+
*plat_specific* is true. If *standard_lib* is true, the directory for the
|
| 1532 |
+
standard library is returned rather than the directory for the installation of
|
| 1533 |
+
third-party extensions.
|
| 1534 |
+
|
| 1535 |
+
The following function is only intended for use within the :mod:`distutils`
|
| 1536 |
+
package.
|
| 1537 |
+
|
| 1538 |
+
|
| 1539 |
+
.. function:: customize_compiler(compiler)
|
| 1540 |
+
|
| 1541 |
+
Do any platform-specific customization of a
|
| 1542 |
+
:class:`distutils.ccompiler.CCompiler` instance.
|
| 1543 |
+
|
| 1544 |
+
This function is only needed on Unix at this time, but should be called
|
| 1545 |
+
consistently to support forward-compatibility. It inserts the information that
|
| 1546 |
+
varies across Unix flavors and is stored in Python's :file:`Makefile`. This
|
| 1547 |
+
information includes the selected compiler, compiler and linker options, and the
|
| 1548 |
+
extension used by the linker for shared objects.
|
| 1549 |
+
|
| 1550 |
+
This function is even more special-purpose, and should only be used from
|
| 1551 |
+
Python's own build procedures.
|
| 1552 |
+
|
| 1553 |
+
|
| 1554 |
+
.. function:: set_python_build()
|
| 1555 |
+
|
| 1556 |
+
Inform the :mod:`distutils.sysconfig` module that it is being used as part of
|
| 1557 |
+
the build process for Python. This changes a lot of relative locations for
|
| 1558 |
+
files, allowing them to be located in the build area rather than in an installed
|
| 1559 |
+
Python.
|
| 1560 |
+
|
| 1561 |
+
|
| 1562 |
+
:mod:`distutils.text_file` --- The TextFile class
|
| 1563 |
+
=================================================
|
| 1564 |
+
|
| 1565 |
+
.. module:: distutils.text_file
|
| 1566 |
+
:synopsis: Provides the TextFile class, a simple interface to text files
|
| 1567 |
+
|
| 1568 |
+
|
| 1569 |
+
This module provides the :class:`TextFile` class, which gives an interface to
|
| 1570 |
+
text files that (optionally) takes care of stripping comments, ignoring blank
|
| 1571 |
+
lines, and joining lines with backslashes.
|
| 1572 |
+
|
| 1573 |
+
|
| 1574 |
+
.. class:: TextFile([filename=None, file=None, **options])
|
| 1575 |
+
|
| 1576 |
+
This class provides a file-like object that takes care of all the things you
|
| 1577 |
+
commonly want to do when processing a text file that has some line-by-line
|
| 1578 |
+
syntax: strip comments (as long as ``#`` is your comment character), skip blank
|
| 1579 |
+
lines, join adjacent lines by escaping the newline (ie. backslash at end of
|
| 1580 |
+
line), strip leading and/or trailing whitespace. All of these are optional and
|
| 1581 |
+
independently controllable.
|
| 1582 |
+
|
| 1583 |
+
The class provides a :meth:`warn` method so you can generate warning messages
|
| 1584 |
+
that report physical line number, even if the logical line in question spans
|
| 1585 |
+
multiple physical lines. Also provides :meth:`unreadline` for implementing
|
| 1586 |
+
line-at-a-time lookahead.
|
| 1587 |
+
|
| 1588 |
+
:class:`TextFile` instances are create with either *filename*, *file*, or both.
|
| 1589 |
+
:exc:`RuntimeError` is raised if both are ``None``. *filename* should be a
|
| 1590 |
+
string, and *file* a file object (or something that provides :meth:`readline`
|
| 1591 |
+
and :meth:`close` methods). It is recommended that you supply at least
|
| 1592 |
+
*filename*, so that :class:`TextFile` can include it in warning messages. If
|
| 1593 |
+
*file* is not supplied, :class:`TextFile` creates its own using the
|
| 1594 |
+
:func:`open` built-in function.
|
| 1595 |
+
|
| 1596 |
+
The options are all boolean, and affect the values returned by :meth:`readline`
|
| 1597 |
+
|
| 1598 |
+
.. tabularcolumns:: |l|L|l|
|
| 1599 |
+
|
| 1600 |
+
+------------------+--------------------------------+---------+
|
| 1601 |
+
| option name | description | default |
|
| 1602 |
+
+==================+================================+=========+
|
| 1603 |
+
| *strip_comments* | strip from ``'#'`` to | true |
|
| 1604 |
+
| | end-of-line, as well as any | |
|
| 1605 |
+
| | whitespace leading up to the | |
|
| 1606 |
+
| | ``'#'``\ ---unless it is | |
|
| 1607 |
+
| | escaped by a backslash | |
|
| 1608 |
+
+------------------+--------------------------------+---------+
|
| 1609 |
+
| *lstrip_ws* | strip leading whitespace from | false |
|
| 1610 |
+
| | each line before returning it | |
|
| 1611 |
+
+------------------+--------------------------------+---------+
|
| 1612 |
+
| *rstrip_ws* | strip trailing whitespace | true |
|
| 1613 |
+
| | (including line terminator!) | |
|
| 1614 |
+
| | from each line before | |
|
| 1615 |
+
| | returning it. | |
|
| 1616 |
+
+------------------+--------------------------------+---------+
|
| 1617 |
+
| *skip_blanks* | skip lines that are empty | true |
|
| 1618 |
+
| | \*after\* stripping comments | |
|
| 1619 |
+
| | and whitespace. (If both | |
|
| 1620 |
+
| | lstrip_ws and rstrip_ws are | |
|
| 1621 |
+
| | false, then some lines may | |
|
| 1622 |
+
| | consist of solely whitespace: | |
|
| 1623 |
+
| | these will \*not\* be skipped, | |
|
| 1624 |
+
| | even if *skip_blanks* is | |
|
| 1625 |
+
| | true.) | |
|
| 1626 |
+
+------------------+--------------------------------+---------+
|
| 1627 |
+
| *join_lines* | if a backslash is the last | false |
|
| 1628 |
+
| | non-newline character on a | |
|
| 1629 |
+
| | line after stripping comments | |
|
| 1630 |
+
| | and whitespace, join the | |
|
| 1631 |
+
| | following line to it to form | |
|
| 1632 |
+
| | one logical line; if N | |
|
| 1633 |
+
| | consecutive lines end with a | |
|
| 1634 |
+
| | backslash, then N+1 physical | |
|
| 1635 |
+
| | lines will be joined to form | |
|
| 1636 |
+
| | one logical line. | |
|
| 1637 |
+
+------------------+--------------------------------+---------+
|
| 1638 |
+
| *collapse_join* | strip leading whitespace from | false |
|
| 1639 |
+
| | lines that are joined to their | |
|
| 1640 |
+
| | predecessor; only matters if | |
|
| 1641 |
+
| | ``(join_lines and not | |
|
| 1642 |
+
| | lstrip_ws)`` | |
|
| 1643 |
+
+------------------+--------------------------------+---------+
|
| 1644 |
+
|
| 1645 |
+
Note that since *rstrip_ws* can strip the trailing newline, the semantics of
|
| 1646 |
+
:meth:`readline` must differ from those of the built-in file object's
|
| 1647 |
+
:meth:`readline` method! In particular, :meth:`readline` returns ``None`` for
|
| 1648 |
+
end-of-file: an empty string might just be a blank line (or an all-whitespace
|
| 1649 |
+
line), if *rstrip_ws* is true but *skip_blanks* is not.
|
| 1650 |
+
|
| 1651 |
+
|
| 1652 |
+
.. method:: TextFile.open(filename)
|
| 1653 |
+
|
| 1654 |
+
Open a new file *filename*. This overrides any *file* or *filename*
|
| 1655 |
+
constructor arguments.
|
| 1656 |
+
|
| 1657 |
+
|
| 1658 |
+
.. method:: TextFile.close()
|
| 1659 |
+
|
| 1660 |
+
Close the current file and forget everything we know about it (including the
|
| 1661 |
+
filename and the current line number).
|
| 1662 |
+
|
| 1663 |
+
|
| 1664 |
+
.. method:: TextFile.warn(msg[,line=None])
|
| 1665 |
+
|
| 1666 |
+
Print (to stderr) a warning message tied to the current logical line in the
|
| 1667 |
+
current file. If the current logical line in the file spans multiple physical
|
| 1668 |
+
lines, the warning refers to the whole range, such as ``"lines 3-5"``. If
|
| 1669 |
+
*line* is supplied, it overrides the current line number; it may be a list or
|
| 1670 |
+
tuple to indicate a range of physical lines, or an integer for a single
|
| 1671 |
+
physical line.
|
| 1672 |
+
|
| 1673 |
+
|
| 1674 |
+
.. method:: TextFile.readline()
|
| 1675 |
+
|
| 1676 |
+
Read and return a single logical line from the current file (or from an internal
|
| 1677 |
+
buffer if lines have previously been "unread" with :meth:`unreadline`). If the
|
| 1678 |
+
*join_lines* option is true, this may involve reading multiple physical lines
|
| 1679 |
+
concatenated into a single string. Updates the current line number, so calling
|
| 1680 |
+
:meth:`warn` after :meth:`readline` emits a warning about the physical line(s)
|
| 1681 |
+
just read. Returns ``None`` on end-of-file, since the empty string can occur
|
| 1682 |
+
if *rstrip_ws* is true but *strip_blanks* is not.
|
| 1683 |
+
|
| 1684 |
+
|
| 1685 |
+
.. method:: TextFile.readlines()
|
| 1686 |
+
|
| 1687 |
+
Read and return the list of all logical lines remaining in the current file.
|
| 1688 |
+
This updates the current line number to the last line of the file.
|
| 1689 |
+
|
| 1690 |
+
|
| 1691 |
+
.. method:: TextFile.unreadline(line)
|
| 1692 |
+
|
| 1693 |
+
Push *line* (a string) onto an internal buffer that will be checked by future
|
| 1694 |
+
:meth:`readline` calls. Handy for implementing a parser with line-at-a-time
|
| 1695 |
+
lookahead. Note that lines that are "unread" with :meth:`unreadline` are not
|
| 1696 |
+
subsequently re-cleansed (whitespace stripped, or whatever) when read with
|
| 1697 |
+
:meth:`readline`. If multiple calls are made to :meth:`unreadline` before a call
|
| 1698 |
+
to :meth:`readline`, the lines will be returned most in most recent first order.
|
| 1699 |
+
|
| 1700 |
+
|
| 1701 |
+
:mod:`distutils.version` --- Version number classes
|
| 1702 |
+
===================================================
|
| 1703 |
+
|
| 1704 |
+
.. module:: distutils.version
|
| 1705 |
+
:synopsis: Implements classes that represent module version numbers.
|
| 1706 |
+
|
| 1707 |
+
|
| 1708 |
+
.. % todo
|
| 1709 |
+
.. % \section{Distutils Commands}
|
| 1710 |
+
.. %
|
| 1711 |
+
.. % This part of Distutils implements the various Distutils commands, such
|
| 1712 |
+
.. % as \code{build}, \code{install} \&c. Each command is implemented as a
|
| 1713 |
+
.. % separate module, with the command name as the name of the module.
|
| 1714 |
+
|
| 1715 |
+
|
| 1716 |
+
:mod:`distutils.cmd` --- Abstract base class for Distutils commands
|
| 1717 |
+
===================================================================
|
| 1718 |
+
|
| 1719 |
+
.. module:: distutils.cmd
|
| 1720 |
+
:synopsis: Provides the abstract base class :class:`~distutils.cmd.Command`. This class
|
| 1721 |
+
is subclassed by the modules in the distutils.command subpackage.
|
| 1722 |
+
|
| 1723 |
+
|
| 1724 |
+
This module supplies the abstract base class :class:`Command`.
|
| 1725 |
+
|
| 1726 |
+
|
| 1727 |
+
.. class:: Command(dist)
|
| 1728 |
+
|
| 1729 |
+
Abstract base class for defining command classes, the "worker bees" of the
|
| 1730 |
+
Distutils. A useful analogy for command classes is to think of them as
|
| 1731 |
+
subroutines with local variables called *options*. The options are declared
|
| 1732 |
+
in :meth:`initialize_options` and defined (given their final values) in
|
| 1733 |
+
:meth:`finalize_options`, both of which must be defined by every command
|
| 1734 |
+
class. The distinction between the two is necessary because option values
|
| 1735 |
+
might come from the outside world (command line, config file, ...), and any
|
| 1736 |
+
options dependent on other options must be computed after these outside
|
| 1737 |
+
influences have been processed --- hence :meth:`finalize_options`. The body
|
| 1738 |
+
of the subroutine, where it does all its work based on the values of its
|
| 1739 |
+
options, is the :meth:`run` method, which must also be implemented by every
|
| 1740 |
+
command class.
|
| 1741 |
+
|
| 1742 |
+
The class constructor takes a single argument *dist*, a
|
| 1743 |
+
:class:`~distutils.core.Distribution` instance.
|
| 1744 |
+
|
| 1745 |
+
|
| 1746 |
+
Creating a new Distutils command
|
| 1747 |
+
================================
|
| 1748 |
+
|
| 1749 |
+
This section outlines the steps to create a new Distutils command.
|
| 1750 |
+
|
| 1751 |
+
A new command lives in a module in the :mod:`distutils.command` package. There
|
| 1752 |
+
is a sample template in that directory called :file:`command_template`. Copy
|
| 1753 |
+
this file to a new module with the same name as the new command you're
|
| 1754 |
+
implementing. This module should implement a class with the same name as the
|
| 1755 |
+
module (and the command). So, for instance, to create the command
|
| 1756 |
+
``peel_banana`` (so that users can run ``setup.py peel_banana``), you'd copy
|
| 1757 |
+
:file:`command_template` to :file:`distutils/command/peel_banana.py`, then edit
|
| 1758 |
+
it so that it's implementing the class :class:`peel_banana`, a subclass of
|
| 1759 |
+
:class:`distutils.cmd.Command`.
|
| 1760 |
+
|
| 1761 |
+
Subclasses of :class:`Command` must define the following methods.
|
| 1762 |
+
|
| 1763 |
+
.. method:: Command.initialize_options()
|
| 1764 |
+
|
| 1765 |
+
Set default values for all the options that this command supports. Note that
|
| 1766 |
+
these defaults may be overridden by other commands, by the setup script, by
|
| 1767 |
+
config files, or by the command-line. Thus, this is not the place to code
|
| 1768 |
+
dependencies between options; generally, :meth:`initialize_options`
|
| 1769 |
+
implementations are just a bunch of ``self.foo = None`` assignments.
|
| 1770 |
+
|
| 1771 |
+
|
| 1772 |
+
.. method:: Command.finalize_options()
|
| 1773 |
+
|
| 1774 |
+
Set final values for all the options that this command supports. This is
|
| 1775 |
+
always called as late as possible, ie. after any option assignments from the
|
| 1776 |
+
command-line or from other commands have been done. Thus, this is the place
|
| 1777 |
+
to code option dependencies: if *foo* depends on *bar*, then it is safe to
|
| 1778 |
+
set *foo* from *bar* as long as *foo* still has the same value it was
|
| 1779 |
+
assigned in :meth:`initialize_options`.
|
| 1780 |
+
|
| 1781 |
+
|
| 1782 |
+
.. method:: Command.run()
|
| 1783 |
+
|
| 1784 |
+
A command's raison d'etre: carry out the action it exists to perform, controlled
|
| 1785 |
+
by the options initialized in :meth:`initialize_options`, customized by other
|
| 1786 |
+
commands, the setup script, the command-line, and config files, and finalized in
|
| 1787 |
+
:meth:`finalize_options`. All terminal output and filesystem interaction should
|
| 1788 |
+
be done by :meth:`run`.
|
| 1789 |
+
|
| 1790 |
+
|
| 1791 |
+
.. attribute:: Command.sub_commands
|
| 1792 |
+
|
| 1793 |
+
*sub_commands* formalizes the notion of a "family" of commands,
|
| 1794 |
+
e.g. ``install`` as the parent with sub-commands ``install_lib``,
|
| 1795 |
+
``install_headers``, etc. The parent of a family of commands defines
|
| 1796 |
+
*sub_commands* as a class attribute; it's a list of 2-tuples ``(command_name,
|
| 1797 |
+
predicate)``, with *command_name* a string and *predicate* a function, a
|
| 1798 |
+
string or ``None``. *predicate* is a method of the parent command that
|
| 1799 |
+
determines whether the corresponding command is applicable in the current
|
| 1800 |
+
situation. (E.g. ``install_headers`` is only applicable if we have any C
|
| 1801 |
+
header files to install.) If *predicate* is ``None``, that command is always
|
| 1802 |
+
applicable.
|
| 1803 |
+
|
| 1804 |
+
*sub_commands* is usually defined at the *end* of a class, because
|
| 1805 |
+
predicates can be methods of the class, so they must already have been
|
| 1806 |
+
defined. The canonical example is the :command:`install` command.
|
| 1807 |
+
|
| 1808 |
+
|
| 1809 |
+
:mod:`distutils.command` --- Individual Distutils commands
|
| 1810 |
+
==========================================================
|
| 1811 |
+
|
| 1812 |
+
.. module:: distutils.command
|
| 1813 |
+
:synopsis: Contains one module for each standard Distutils command.
|
| 1814 |
+
|
| 1815 |
+
|
| 1816 |
+
.. % \subsubsection{Individual Distutils commands}
|
| 1817 |
+
.. % todo
|
| 1818 |
+
|
| 1819 |
+
|
| 1820 |
+
:mod:`distutils.command.bdist` --- Build a binary installer
|
| 1821 |
+
===========================================================
|
| 1822 |
+
|
| 1823 |
+
.. module:: distutils.command.bdist
|
| 1824 |
+
:synopsis: Build a binary installer for a package
|
| 1825 |
+
|
| 1826 |
+
|
| 1827 |
+
.. % todo
|
| 1828 |
+
|
| 1829 |
+
|
| 1830 |
+
:mod:`distutils.command.bdist_packager` --- Abstract base class for packagers
|
| 1831 |
+
=============================================================================
|
| 1832 |
+
|
| 1833 |
+
.. module:: distutils.command.bdist_packager
|
| 1834 |
+
:synopsis: Abstract base class for packagers
|
| 1835 |
+
|
| 1836 |
+
|
| 1837 |
+
.. % todo
|
| 1838 |
+
|
| 1839 |
+
|
| 1840 |
+
:mod:`distutils.command.bdist_dumb` --- Build a "dumb" installer
|
| 1841 |
+
================================================================
|
| 1842 |
+
|
| 1843 |
+
.. module:: distutils.command.bdist_dumb
|
| 1844 |
+
:synopsis: Build a "dumb" installer - a simple archive of files
|
| 1845 |
+
|
| 1846 |
+
|
| 1847 |
+
.. % todo
|
| 1848 |
+
|
| 1849 |
+
|
| 1850 |
+
:mod:`distutils.command.bdist_msi` --- Build a Microsoft Installer binary package
|
| 1851 |
+
=================================================================================
|
| 1852 |
+
|
| 1853 |
+
.. module:: distutils.command.bdist_msi
|
| 1854 |
+
:synopsis: Build a binary distribution as a Windows MSI file
|
| 1855 |
+
|
| 1856 |
+
.. class:: bdist_msi
|
| 1857 |
+
|
| 1858 |
+
.. deprecated:: 3.9
|
| 1859 |
+
Use bdist_wheel (wheel packages) instead.
|
| 1860 |
+
|
| 1861 |
+
Builds a `Windows Installer`_ (.msi) binary package.
|
| 1862 |
+
|
| 1863 |
+
.. _Windows Installer: https://msdn.microsoft.com/en-us/library/cc185688(VS.85).aspx
|
| 1864 |
+
|
| 1865 |
+
In most cases, the ``bdist_msi`` installer is a better choice than the
|
| 1866 |
+
``bdist_wininst`` installer, because it provides better support for
|
| 1867 |
+
Win64 platforms, allows administrators to perform non-interactive
|
| 1868 |
+
installations, and allows installation through group policies.
|
| 1869 |
+
|
| 1870 |
+
|
| 1871 |
+
:mod:`distutils.command.bdist_rpm` --- Build a binary distribution as a Redhat RPM and SRPM
|
| 1872 |
+
===========================================================================================
|
| 1873 |
+
|
| 1874 |
+
.. module:: distutils.command.bdist_rpm
|
| 1875 |
+
:synopsis: Build a binary distribution as a Redhat RPM and SRPM
|
| 1876 |
+
|
| 1877 |
+
|
| 1878 |
+
.. % todo
|
| 1879 |
+
|
| 1880 |
+
|
| 1881 |
+
:mod:`distutils.command.bdist_wininst` --- Build a Windows installer
|
| 1882 |
+
====================================================================
|
| 1883 |
+
|
| 1884 |
+
.. module:: distutils.command.bdist_wininst
|
| 1885 |
+
:synopsis: Build a Windows installer
|
| 1886 |
+
|
| 1887 |
+
.. deprecated:: 3.8
|
| 1888 |
+
Use bdist_wheel (wheel packages) instead.
|
| 1889 |
+
|
| 1890 |
+
|
| 1891 |
+
.. % todo
|
| 1892 |
+
|
| 1893 |
+
|
| 1894 |
+
:mod:`distutils.command.sdist` --- Build a source distribution
|
| 1895 |
+
==============================================================
|
| 1896 |
+
|
| 1897 |
+
.. module:: distutils.command.sdist
|
| 1898 |
+
:synopsis: Build a source distribution
|
| 1899 |
+
|
| 1900 |
+
|
| 1901 |
+
.. % todo
|
| 1902 |
+
|
| 1903 |
+
|
| 1904 |
+
:mod:`distutils.command.build` --- Build all files of a package
|
| 1905 |
+
===============================================================
|
| 1906 |
+
|
| 1907 |
+
.. module:: distutils.command.build
|
| 1908 |
+
:synopsis: Build all files of a package
|
| 1909 |
+
|
| 1910 |
+
|
| 1911 |
+
.. % todo
|
| 1912 |
+
|
| 1913 |
+
|
| 1914 |
+
:mod:`distutils.command.build_clib` --- Build any C libraries in a package
|
| 1915 |
+
==========================================================================
|
| 1916 |
+
|
| 1917 |
+
.. module:: distutils.command.build_clib
|
| 1918 |
+
:synopsis: Build any C libraries in a package
|
| 1919 |
+
|
| 1920 |
+
|
| 1921 |
+
.. % todo
|
| 1922 |
+
|
| 1923 |
+
|
| 1924 |
+
:mod:`distutils.command.build_ext` --- Build any extensions in a package
|
| 1925 |
+
========================================================================
|
| 1926 |
+
|
| 1927 |
+
.. module:: distutils.command.build_ext
|
| 1928 |
+
:synopsis: Build any extensions in a package
|
| 1929 |
+
|
| 1930 |
+
|
| 1931 |
+
.. % todo
|
| 1932 |
+
|
| 1933 |
+
|
| 1934 |
+
:mod:`distutils.command.build_py` --- Build the .py/.pyc files of a package
|
| 1935 |
+
===========================================================================
|
| 1936 |
+
|
| 1937 |
+
.. module:: distutils.command.build_py
|
| 1938 |
+
:synopsis: Build the .py/.pyc files of a package
|
| 1939 |
+
|
| 1940 |
+
|
| 1941 |
+
.. class:: build_py
|
| 1942 |
+
|
| 1943 |
+
.. class:: build_py_2to3
|
| 1944 |
+
|
| 1945 |
+
Alternative implementation of build_py which also runs the
|
| 1946 |
+
2to3 conversion library on each .py file that is going to be
|
| 1947 |
+
installed. To use this in a setup.py file for a distribution
|
| 1948 |
+
that is designed to run with both Python 2.x and 3.x, add::
|
| 1949 |
+
|
| 1950 |
+
try:
|
| 1951 |
+
from distutils.command.build_py import build_py_2to3 as build_py
|
| 1952 |
+
except ImportError:
|
| 1953 |
+
from distutils.command.build_py import build_py
|
| 1954 |
+
|
| 1955 |
+
to your setup.py, and later::
|
| 1956 |
+
|
| 1957 |
+
cmdclass = {'build_py': build_py}
|
| 1958 |
+
|
| 1959 |
+
to the invocation of setup().
|
| 1960 |
+
|
| 1961 |
+
|
| 1962 |
+
:mod:`distutils.command.build_scripts` --- Build the scripts of a package
|
| 1963 |
+
=========================================================================
|
| 1964 |
+
|
| 1965 |
+
.. module:: distutils.command.build_scripts
|
| 1966 |
+
:synopsis: Build the scripts of a package
|
| 1967 |
+
|
| 1968 |
+
|
| 1969 |
+
.. % todo
|
| 1970 |
+
|
| 1971 |
+
|
| 1972 |
+
:mod:`distutils.command.clean` --- Clean a package build area
|
| 1973 |
+
=============================================================
|
| 1974 |
+
|
| 1975 |
+
.. module:: distutils.command.clean
|
| 1976 |
+
:synopsis: Clean a package build area
|
| 1977 |
+
|
| 1978 |
+
This command removes the temporary files created by :command:`build`
|
| 1979 |
+
and its subcommands, like intermediary compiled object files. With
|
| 1980 |
+
the ``--all`` option, the complete build directory will be removed.
|
| 1981 |
+
|
| 1982 |
+
Extension modules built :ref:`in place <distutils-build-ext-inplace>`
|
| 1983 |
+
will not be cleaned, as they are not in the build directory.
|
| 1984 |
+
|
| 1985 |
+
|
| 1986 |
+
:mod:`distutils.command.config` --- Perform package configuration
|
| 1987 |
+
=================================================================
|
| 1988 |
+
|
| 1989 |
+
.. module:: distutils.command.config
|
| 1990 |
+
:synopsis: Perform package configuration
|
| 1991 |
+
|
| 1992 |
+
|
| 1993 |
+
.. % todo
|
| 1994 |
+
|
| 1995 |
+
|
| 1996 |
+
:mod:`distutils.command.install` --- Install a package
|
| 1997 |
+
======================================================
|
| 1998 |
+
|
| 1999 |
+
.. module:: distutils.command.install
|
| 2000 |
+
:synopsis: Install a package
|
| 2001 |
+
|
| 2002 |
+
|
| 2003 |
+
.. % todo
|
| 2004 |
+
|
| 2005 |
+
|
| 2006 |
+
:mod:`distutils.command.install_data` --- Install data files from a package
|
| 2007 |
+
===========================================================================
|
| 2008 |
+
|
| 2009 |
+
.. module:: distutils.command.install_data
|
| 2010 |
+
:synopsis: Install data files from a package
|
| 2011 |
+
|
| 2012 |
+
|
| 2013 |
+
.. % todo
|
| 2014 |
+
|
| 2015 |
+
|
| 2016 |
+
:mod:`distutils.command.install_headers` --- Install C/C++ header files from a package
|
| 2017 |
+
======================================================================================
|
| 2018 |
+
|
| 2019 |
+
.. module:: distutils.command.install_headers
|
| 2020 |
+
:synopsis: Install C/C++ header files from a package
|
| 2021 |
+
|
| 2022 |
+
|
| 2023 |
+
.. % todo
|
| 2024 |
+
|
| 2025 |
+
|
| 2026 |
+
:mod:`distutils.command.install_lib` --- Install library files from a package
|
| 2027 |
+
=============================================================================
|
| 2028 |
+
|
| 2029 |
+
.. module:: distutils.command.install_lib
|
| 2030 |
+
:synopsis: Install library files from a package
|
| 2031 |
+
|
| 2032 |
+
|
| 2033 |
+
.. % todo
|
| 2034 |
+
|
| 2035 |
+
|
| 2036 |
+
:mod:`distutils.command.install_scripts` --- Install script files from a package
|
| 2037 |
+
================================================================================
|
| 2038 |
+
|
| 2039 |
+
.. module:: distutils.command.install_scripts
|
| 2040 |
+
:synopsis: Install script files from a package
|
| 2041 |
+
|
| 2042 |
+
|
| 2043 |
+
.. % todo
|
| 2044 |
+
|
| 2045 |
+
|
| 2046 |
+
:mod:`distutils.command.register` --- Register a module with the Python Package Index
|
| 2047 |
+
=====================================================================================
|
| 2048 |
+
|
| 2049 |
+
.. module:: distutils.command.register
|
| 2050 |
+
:synopsis: Register a module with the Python Package Index
|
| 2051 |
+
|
| 2052 |
+
|
| 2053 |
+
The ``register`` command registers the package with the Python Package Index.
|
| 2054 |
+
This is described in more detail in :pep:`301`.
|
| 2055 |
+
|
| 2056 |
+
.. % todo
|
| 2057 |
+
|
| 2058 |
+
|
| 2059 |
+
:mod:`distutils.command.check` --- Check the meta-data of a package
|
| 2060 |
+
===================================================================
|
| 2061 |
+
|
| 2062 |
+
.. module:: distutils.command.check
|
| 2063 |
+
:synopsis: Check the meta-data of a package
|
| 2064 |
+
|
| 2065 |
+
|
| 2066 |
+
The ``check`` command performs some tests on the meta-data of a package.
|
| 2067 |
+
For example, it verifies that all required meta-data are provided as
|
| 2068 |
+
the arguments passed to the :func:`set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uptools_disclaimer.rst
|
| 8 |
+
|
| 9 |
+
A "built distribution" is what you're probably used to thinking of either as a
|
| 10 |
+
"binary package" or an "installer" (depending on your background). It's not
|
| 11 |
+
necessarily binary, though, because it might contain only Python source code
|
| 12 |
+
and/or byte-code; and we don't call it a package, because that word is already
|
| 13 |
+
spoken for in Python. (And "installer" is a term specific to the world of
|
| 14 |
+
mainstream desktop systems.)
|
| 15 |
+
|
| 16 |
+
A built distribution is how you make life as easy as possible for installers of
|
| 17 |
+
your module distribution: for users of RPM-based Linux systems, it's a binary
|
| 18 |
+
RPM; for Windows users, it's an executable installer; for Debian-based Linux
|
| 19 |
+
users, it's a Debian package; and so forth. Obviously, no one person will be
|
| 20 |
+
able to create built distributions for every platform under the sun, so the
|
| 21 |
+
Distutils are designed to enable module developers to concentrate on their
|
| 22 |
+
specialty---writing code and creating source distributions---while an
|
| 23 |
+
intermediary species called *packagers* springs up to turn source distributions
|
| 24 |
+
into built distributions for as many platforms as there are packagers.
|
| 25 |
+
|
| 26 |
+
Of course, the module developer could be their own packager; or the packager could
|
| 27 |
+
be a volunteer "out there" somewhere who has access to a platform which the
|
| 28 |
+
original developer does not; or it could be software periodically grabbing new
|
| 29 |
+
source distributions and turning them into built distributions for as many
|
| 30 |
+
platforms as the software has access to. Regardless of who they are, a packager
|
| 31 |
+
uses the setup script and the :command:`bdist` command family to generate built
|
| 32 |
+
distributions.
|
| 33 |
+
|
| 34 |
+
As a simple example, if I run the following command in the Distutils source
|
| 35 |
+
tree::
|
| 36 |
+
|
| 37 |
+
python setup.py bdist
|
| 38 |
+
|
| 39 |
+
then the Distutils builds my module distribution (the Distutils itself in this
|
| 40 |
+
case), does a "fake" installation (also in the :file:`build` directory), and
|
| 41 |
+
creates the default type of built distribution for my platform. The default
|
| 42 |
+
format for built distributions is a "dumb" tar file on Unix, and a simple
|
| 43 |
+
executable installer on Windows. (That tar file is considered "dumb" because it
|
| 44 |
+
has to be unpacked in a specific location to work.)
|
| 45 |
+
|
| 46 |
+
Thus, the above command on a Unix system creates
|
| 47 |
+
:file:`Distutils-1.0.{plat}.tar.gz`; unpacking this tarball from the right place
|
| 48 |
+
installs the Distutils just as though you had downloaded the source distribution
|
| 49 |
+
and run ``python setup.py install``. (The "right place" is either the root of
|
| 50 |
+
the filesystem or Python's :file:`{prefix}` directory, depending on the options
|
| 51 |
+
given to the :command:`bdist_dumb` command; the default is to make dumb
|
| 52 |
+
distributions relative to :file:`{prefix}`.)
|
| 53 |
+
|
| 54 |
+
Obviously, for pure Python distributions, this isn't any simpler than just
|
| 55 |
+
running ``python setup.py install``\ ---but for non-pure distributions, which
|
| 56 |
+
include extensions that would need to be compiled, it can mean the difference
|
| 57 |
+
between someone being able to use your extensions or not. And creating "smart"
|
| 58 |
+
built distributions, such as an RPM package or an executable installer for
|
| 59 |
+
Windows, is far more convenient for users even if your distribution doesn't
|
| 60 |
+
include any extensions.
|
| 61 |
+
|
| 62 |
+
The :command:`bdist` command has a :option:`!--formats` option, similar to the
|
| 63 |
+
:command:`sdist` command, which you can use to select the types of built
|
| 64 |
+
distribution to generate: for example, ::
|
| 65 |
+
|
| 66 |
+
python setup.py bdist --format=zip
|
| 67 |
+
|
| 68 |
+
would, when run on a Unix system, create
|
| 69 |
+
:file:`Distutils-1.0.{plat}.zip`\ ---again, this archive would be unpacked
|
| 70 |
+
from the root directory to install the Distutils.
|
| 71 |
+
|
| 72 |
+
The available formats for built distributions are:
|
| 73 |
+
|
| 74 |
+
+-------------+------------------------------+---------+
|
| 75 |
+
| Format | Description | Notes |
|
| 76 |
+
+=============+==============================+=========+
|
| 77 |
+
| ``gztar`` | gzipped tar file | \(1) |
|
| 78 |
+
| | (:file:`.tar.gz`) | |
|
| 79 |
+
+-------------+------------------------------+---------+
|
| 80 |
+
| ``bztar`` | bzipped tar file | |
|
| 81 |
+
| | (:file:`.tar.bz2`) | |
|
| 82 |
+
+-------------+------------------------------+---------+
|
| 83 |
+
| ``xztar`` | xzipped tar file | |
|
| 84 |
+
| | (:file:`.tar.xz`) | |
|
| 85 |
+
+-------------+------------------------------+---------+
|
| 86 |
+
| ``ztar`` | compressed tar file | \(3) |
|
| 87 |
+
| | (:file:`.tar.Z`) | |
|
| 88 |
+
+-------------+------------------------------+---------+
|
| 89 |
+
| ``tar`` | tar file (:file:`.tar`) | |
|
| 90 |
+
+-------------+------------------------------+---------+
|
| 91 |
+
| ``zip`` | zip file (:file:`.zip`) | (2),(4) |
|
| 92 |
+
+-------------+------------------------------+---------+
|
| 93 |
+
| ``rpm`` | RPM | \(5) |
|
| 94 |
+
+-------------+------------------------------+---------+
|
| 95 |
+
| ``pkgtool`` | Solaris :program:`pkgtool` | |
|
| 96 |
+
+-------------+------------------------------+---------+
|
| 97 |
+
| ``sdux`` | HP-UX :program:`swinstall` | |
|
| 98 |
+
+-------------+------------------------------+---------+
|
| 99 |
+
| ``wininst`` | self-extracting ZIP file for | \(4) |
|
| 100 |
+
| | Windows | |
|
| 101 |
+
+-------------+------------------------------+---------+
|
| 102 |
+
| ``msi`` | Microsoft Installer. | |
|
| 103 |
+
+-------------+------------------------------+---------+
|
| 104 |
+
|
| 105 |
+
.. versionchanged:: 3.5
|
| 106 |
+
Added support for the ``xztar`` format.
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
Notes:
|
| 110 |
+
|
| 111 |
+
(1)
|
| 112 |
+
default on Unix
|
| 113 |
+
|
| 114 |
+
(2)
|
| 115 |
+
default on Windows
|
| 116 |
+
|
| 117 |
+
(3)
|
| 118 |
+
requires external :program:`compress` utility.
|
| 119 |
+
|
| 120 |
+
(4)
|
| 121 |
+
requires either external :program:`zip` utility or :mod:`zipfile` module (part
|
| 122 |
+
of the standard Python library since Python 1.6)
|
| 123 |
+
|
| 124 |
+
(5)
|
| 125 |
+
requires external :program:`rpm` utility, version 3.0.4 or better (use ``rpm
|
| 126 |
+
--version`` to find out which version you have)
|
| 127 |
+
|
| 128 |
+
You don't have to use the :command:`bdist` command with the :option:`!--formats`
|
| 129 |
+
option; you can also use the command that directly implements the format you're
|
| 130 |
+
interested in. Some of these :command:`bdist` "sub-commands" actually generate
|
| 131 |
+
several similar formats; for instance, the :command:`bdist_dumb` command
|
| 132 |
+
generates all the "dumb" archive formats (``tar``, ``gztar``, ``bztar``,
|
| 133 |
+
``xztar``, ``ztar``, and ``zip``), and :command:`bdist_rpm` generates both
|
| 134 |
+
binary and source RPMs. The :command:`bdist` sub-commands, and the formats
|
| 135 |
+
generated by each, are:
|
| 136 |
+
|
| 137 |
+
+--------------------------+-------------------------------------+
|
| 138 |
+
| Command | Formats |
|
| 139 |
+
+==========================+=====================================+
|
| 140 |
+
| :command:`bdist_dumb` | tar, gztar, bztar, xztar, ztar, zip |
|
| 141 |
+
+--------------------------+-------------------------------------+
|
| 142 |
+
| :command:`bdist_rpm` | rpm, srpm |
|
| 143 |
+
+--------------------------+-------------------------------------+
|
| 144 |
+
| :command:`bdist_wininst` | wininst |
|
| 145 |
+
+--------------------------+-------------------------------------+
|
| 146 |
+
| :command:`bdist_msi` | msi |
|
| 147 |
+
+--------------------------+-------------------------------------+
|
| 148 |
+
|
| 149 |
+
.. note::
|
| 150 |
+
bdist_wininst is deprecated since Python 3.8.
|
| 151 |
+
|
| 152 |
+
.. note::
|
| 153 |
+
bdist_msi is deprecated since Python 3.9.
|
| 154 |
+
|
| 155 |
+
The following sections give details on the individual :command:`bdist_\*`
|
| 156 |
+
commands.
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
.. .. _creating-dumb:
|
| 160 |
+
|
| 161 |
+
.. Creating dumb built distributions
|
| 162 |
+
.. =================================
|
| 163 |
+
|
| 164 |
+
.. XXX Need to document absolute vs. prefix-relative packages here, but first
|
| 165 |
+
I have to implement it!
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
.. _creating-rpms:
|
| 169 |
+
|
| 170 |
+
Creating RPM packages
|
| 171 |
+
=====================
|
| 172 |
+
|
| 173 |
+
The RPM format is used by many popular Linux distributions, including Red Hat,
|
| 174 |
+
SuSE, and Mandrake. If one of these (or any of the other RPM-based Linux
|
| 175 |
+
distributions) is your usual environment, creating RPM packages for other users
|
| 176 |
+
of that same distribution is trivial. Depending on the complexity of your module
|
| 177 |
+
distribution and differences between Linux distributions, you may also be able
|
| 178 |
+
to create RPMs that work on different RPM-based distributions.
|
| 179 |
+
|
| 180 |
+
The usual way to create an RPM of your module distribution is to run the
|
| 181 |
+
:command:`bdist_rpm` command::
|
| 182 |
+
|
| 183 |
+
python setup.py bdist_rpm
|
| 184 |
+
|
| 185 |
+
or the :command:`bdist` command with the :option:`!--format` option::
|
| 186 |
+
|
| 187 |
+
python setup.py bdist --formats=rpm
|
| 188 |
+
|
| 189 |
+
The former allows you to specify RPM-specific options; the latter allows you to
|
| 190 |
+
easily specify multiple formats in one run. If you need to do both, you can
|
| 191 |
+
explicitly specify multiple :command:`bdist_\*` commands and their options::
|
| 192 |
+
|
| 193 |
+
python setup.py bdist_rpm --packager="John Doe <jdoe@example.org>" \
|
| 194 |
+
bdist_wininst --target-version="2.0"
|
| 195 |
+
|
| 196 |
+
Creating RPM packages is driven by a :file:`.spec` file, much as using the
|
| 197 |
+
Distutils is driven by the setup script. To make your life easier, the
|
| 198 |
+
:command:`bdist_rpm` command normally creates a :file:`.spec` file based on the
|
| 199 |
+
information you supply in the setup script, on the command line, and in any
|
| 200 |
+
Distutils configuration files. Various options and sections in the
|
| 201 |
+
:file:`.spec` file are derived from options in the setup script as follows:
|
| 202 |
+
|
| 203 |
+
+------------------------------------------+----------------------------------------------+
|
| 204 |
+
| RPM :file:`.spec` file option or section | Distutils setup script option |
|
| 205 |
+
+==========================================+==============================================+
|
| 206 |
+
| Name | ``name`` |
|
| 207 |
+
+------------------------------------------+----------------------------------------------+
|
| 208 |
+
| Summary (in preamble) | ``description`` |
|
| 209 |
+
+------------------------------------------+----------------------------------------------+
|
| 210 |
+
| Version | ``version`` |
|
| 211 |
+
+------------------------------------------+----------------------------------------------+
|
| 212 |
+
| Vendor | ``author`` and ``author_email``, |
|
| 213 |
+
| | or --- & ``maintainer`` and |
|
| 214 |
+
| | ``maintainer_email`` |
|
| 215 |
+
+------------------------------------------+----------------------------------------------+
|
| 216 |
+
| Copyright | ``license`` |
|
| 217 |
+
+------------------------------------------+----------------------------------------------+
|
| 218 |
+
| Url | ``url`` |
|
| 219 |
+
+------------------------------------------+----------------------------------------------+
|
| 220 |
+
| %description (section) | ``long_description`` |
|
| 221 |
+
+------------------------------------------+----------------------------------------------+
|
| 222 |
+
|
| 223 |
+
Additionally, there are many options in :file:`.spec` files that don't have
|
| 224 |
+
corresponding options in the setup script. Most of these are handled through
|
| 225 |
+
options to the :command:`bdist_rpm` command as follows:
|
| 226 |
+
|
| 227 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 228 |
+
| RPM :file:`.spec` file option | :command:`bdist_rpm` option | default value |
|
| 229 |
+
| or section | | |
|
| 230 |
+
+===============================+=============================+=========================+
|
| 231 |
+
| Release | ``release`` | "1" |
|
| 232 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 233 |
+
| Group | ``group`` | "Development/Libraries" |
|
| 234 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 235 |
+
| Vendor | ``vendor`` | (see above) |
|
| 236 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 237 |
+
| Packager | ``packager`` | (none) |
|
| 238 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 239 |
+
| Provides | ``provides`` | (none) |
|
| 240 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 241 |
+
| Requires | ``requires`` | (none) |
|
| 242 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 243 |
+
| Conflicts | ``conflicts`` | (none) |
|
| 244 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 245 |
+
| Obsoletes | ``obsoletes`` | (none) |
|
| 246 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 247 |
+
| Distribution | ``distribution_name`` | (none) |
|
| 248 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 249 |
+
| BuildRequires | ``build_requires`` | (none) |
|
| 250 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 251 |
+
| Icon | ``icon`` | (none) |
|
| 252 |
+
+-------------------------------+-----------------------------+-------------------------+
|
| 253 |
+
|
| 254 |
+
Obviously, supplying even a few of these options on the command-line would be
|
| 255 |
+
tedious and error-prone, so it's usually best to put them in the setup
|
| 256 |
+
configuration file, :file:`setup.cfg`\ ---see section :ref:`setup-config`. If
|
| 257 |
+
you distribute or package many Python module distributions, you might want to
|
| 258 |
+
put options that apply to all of them in your personal Distutils configuration
|
| 259 |
+
file (:file:`~/.pydistutils.cfg`). If you want to temporarily disable
|
| 260 |
+
this file, you can pass the :option:`!--no-user-cfg` option to :file:`setup.py`.
|
| 261 |
+
|
| 262 |
+
There are three steps to building a binary RPM package, all of which are
|
| 263 |
+
handled automatically by the Distutils:
|
| 264 |
+
|
| 265 |
+
#. create a :file:`.spec` file, which describes the package (analogous to the
|
| 266 |
+
Distutils setup script; in fact, much of the information in the setup script
|
| 267 |
+
winds up in the :file:`.spec` file)
|
| 268 |
+
|
| 269 |
+
#. create the source RPM
|
| 270 |
+
|
| 271 |
+
#. create the "binary" RPM (which may or may not contain binary code, depending
|
| 272 |
+
on whether your module distribution contains Python extensions)
|
| 273 |
+
|
| 274 |
+
Normally, RPM bundles the last two steps together; when you use the Distutils,
|
| 275 |
+
all three steps are typically bundled together.
|
| 276 |
+
|
| 277 |
+
If you wish, you can separate these three steps. You can use the
|
| 278 |
+
:option:`!--spec-only` option to make :command:`bdist_rpm` just create the
|
| 279 |
+
:file:`.spec` file and exit; in this case, the :file:`.spec` file will be
|
| 280 |
+
written to the "distribution directory"---normally :file:`dist/`, but
|
| 281 |
+
customizable with the :option:`!--dist-dir` option. (Normally, the :file:`.spec`
|
| 282 |
+
file winds up deep in the "build tree," in a temporary directory created by
|
| 283 |
+
:command:`bdist_rpm`.)
|
| 284 |
+
|
| 285 |
+
.. % \XXX{this isn't implemented yet---is it needed?!}
|
| 286 |
+
.. % You can also specify a custom \file{.spec} file with the
|
| 287 |
+
.. % \longprogramopt{spec-file} option; used in conjunction with
|
| 288 |
+
.. % \longprogramopt{spec-only}, this gives you an opportunity to customize
|
| 289 |
+
.. % the \file{.spec} file manually:
|
| 290 |
+
.. %
|
| 291 |
+
.. % \ begin{verbatim}
|
| 292 |
+
.. % > python setup.py bdist_rpm --spec-only
|
| 293 |
+
.. % # ...edit dist/FooBar-1.0.spec
|
| 294 |
+
.. % > python setup.py bdist_rpm --spec-file=dist/FooBar-1.0.spec
|
| 295 |
+
.. % \ end{verbatim}
|
| 296 |
+
.. %
|
| 297 |
+
.. % (Although a better way to do this is probably to override the standard
|
| 298 |
+
.. % \command{bdist\_rpm} command with one that writes whatever else you want
|
| 299 |
+
.. % to the \file{.spec} file.)
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
.. _creating-wininst:
|
| 303 |
+
|
| 304 |
+
Creating Windows Installers
|
| 305 |
+
===========================
|
| 306 |
+
|
| 307 |
+
.. warning::
|
| 308 |
+
bdist_wininst is deprecated since Python 3.8.
|
| 309 |
+
|
| 310 |
+
.. warning::
|
| 311 |
+
bdist_msi is deprecated since Python 3.9.
|
| 312 |
+
|
| 313 |
+
Executable installers are the natural format for binary distributions on
|
| 314 |
+
Windows. They display a nice graphical user interface, display some information
|
| 315 |
+
about the module distribution to be installed taken from the metadata in the
|
| 316 |
+
setup script, let the user select a few options, and start or cancel the
|
| 317 |
+
installation.
|
| 318 |
+
|
| 319 |
+
Since the metadata is taken from the setup script, creating Windows installers
|
| 320 |
+
is usually as easy as running::
|
| 321 |
+
|
| 322 |
+
python setup.py bdist_wininst
|
| 323 |
+
|
| 324 |
+
or the :command:`bdist` command with the :option:`!--formats` option::
|
| 325 |
+
|
| 326 |
+
python setup.py bdist --formats=wininst
|
| 327 |
+
|
| 328 |
+
If you have a pure module distribution (only containing pure Python modules and
|
| 329 |
+
packages), the resulting installer will be version independent and have a name
|
| 330 |
+
like :file:`foo-1.0.win32.exe`. Note that creating ``wininst`` binary
|
| 331 |
+
distributions in only supported on Windows systems.
|
| 332 |
+
|
| 333 |
+
If you have a non-pure distribution, the extensions can only be created on a
|
| 334 |
+
Windows platform, and will be Python version dependent. The installer filename
|
| 335 |
+
will reflect this and now has the form :file:`foo-1.0.win32-py2.0.exe`. You
|
| 336 |
+
have to create a separate installer for every Python version you want to
|
| 337 |
+
support.
|
| 338 |
+
|
| 339 |
+
The installer will try to compile pure modules into :term:`bytecode` after installation
|
| 340 |
+
on the target system in normal and optimizing mode. If you don't want this to
|
| 341 |
+
happen for some reason, you can run the :command:`bdist_wininst` command with
|
| 342 |
+
the :option:`!--no-target-compile` and/or the :option:`!--no-target-optimize`
|
| 343 |
+
option.
|
| 344 |
+
|
| 345 |
+
By default the installer will display the cool "Python Powered" logo when it is
|
| 346 |
+
run, but you can also supply your own 152x261 bitmap which must be a Windows
|
| 347 |
+
:file:`.bmp` file with the :option:`!--bitmap` option.
|
| 348 |
+
|
| 349 |
+
The installer will also display a large title on the desktop background window
|
| 350 |
+
when it is run, which is constructed from the name of your distribution and the
|
| 351 |
+
version number. This can be changed to another text by using the
|
| 352 |
+
:option:`!--title` option.
|
| 353 |
+
|
| 354 |
+
The installer file will be written to the "distribution directory" --- normally
|
| 355 |
+
:file:`dist/`, but customizable with the :option:`!--dist-dir` option.
|
| 356 |
+
|
| 357 |
+
.. _cross-compile-windows:
|
| 358 |
+
|
| 359 |
+
Cross-compiling on Windows
|
| 360 |
+
==========================
|
| 361 |
+
|
| 362 |
+
Starting with Python 2.6, distutils is capable of cross-compiling between
|
| 363 |
+
Windows platforms. In practice, this means that with the correct tools
|
| 364 |
+
installed, you can use a 32bit version of Windows to create 64bit extensions
|
| 365 |
+
and vice-versa.
|
| 366 |
+
|
| 367 |
+
To build for an alternate platform, specify the :option:`!--plat-name` option
|
| 368 |
+
to the build command. Valid values are currently 'win32', and 'win-amd64'.
|
| 369 |
+
For example, on a 32bit version of Windows, you could execute::
|
| 370 |
+
|
| 371 |
+
python setup.py build --plat-name=win-amd64
|
| 372 |
+
|
| 373 |
+
to build a 64bit version of your extension. The Windows Installers also
|
| 374 |
+
support this option, so the command::
|
| 375 |
+
|
| 376 |
+
python setup.py build --plat-name=win-amd64 bdist_wininst
|
| 377 |
+
|
| 378 |
+
would create a 64bit installation executable on your 32bit version of Windows.
|
| 379 |
+
|
| 380 |
+
To cross-compile, you must download the Python source code and cross-compile
|
| 381 |
+
Python itself for the platform you are targeting - it is not possible from a
|
| 382 |
+
binary installation of Python (as the .lib etc file for other platforms are
|
| 383 |
+
not included.) In practice, this means the user of a 32 bit operating
|
| 384 |
+
system will need to use Visual Studio 2008 to open the
|
| 385 |
+
:file:`PCbuild/PCbuild.sln` solution in the Python source tree and build the
|
| 386 |
+
"x64" configuration of the 'pythoncore' project before cross-compiling
|
| 387 |
+
extensions is possible.
|
| 388 |
+
|
| 389 |
+
Note that by default, Visual Studio 2008 does not install 64bit compilers or
|
| 390 |
+
tools. You may need to reexecute the Visual Studio setup process and select
|
| 391 |
+
these tools (using Control Panel->[Add/Remove] Programs is a convenient way to
|
| 392 |
+
check or modify your existing install.)
|
| 393 |
+
|
| 394 |
+
.. _postinstallation-script:
|
| 395 |
+
|
| 396 |
+
The Postinstallation script
|
| 397 |
+
---------------------------
|
| 398 |
+
|
| 399 |
+
Starting with Python 2.3, a postinstallation script can be specified with the
|
| 400 |
+
:option:`!--install-script` option. The basename of the script must be
|
| 401 |
+
specified, and the script filename must also be listed in the scripts argument
|
| 402 |
+
to the setup function.
|
| 403 |
+
|
| 404 |
+
This script will be run at installation time on the target system after all the
|
| 405 |
+
files have been copied, with ``argv[1]`` set to :option:`!-install`, and again at
|
| 406 |
+
uninstallation time before the files are removed with ``argv[1]`` set to
|
| 407 |
+
:option:`!-remove`.
|
| 408 |
+
|
| 409 |
+
The installation script runs embedded in the windows installer, every output
|
| 410 |
+
(``sys.stdout``, ``sys.stderr``) is redirected into a buffer and will be
|
| 411 |
+
displayed in the GUI after the script has finished.
|
| 412 |
+
|
| 413 |
+
Some functions especially useful in this context are available as additional
|
| 414 |
+
built-in functions in the installation script.
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
.. function:: directory_created(path)
|
| 418 |
+
file_created(path)
|
| 419 |
+
|
| 420 |
+
These functions should be called when a directory or file is created by the
|
| 421 |
+
postinstall script at installation time. It will register *path* with the
|
| 422 |
+
uninstaller, so that it will be removed when the distribution is uninstalled.
|
| 423 |
+
To be safe, directories are only removed if they are empty.
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
.. function:: get_special_folder_path(csidl_string)
|
| 427 |
+
|
| 428 |
+
This function can be used to retrieve special folder locations on Windows like
|
| 429 |
+
the Start Menu or the Desktop. It returns the full path to the folder.
|
| 430 |
+
*csidl_string* must be one of the following strings::
|
| 431 |
+
|
| 432 |
+
"CSIDL_APPDATA"
|
| 433 |
+
|
| 434 |
+
"CSIDL_COMMON_STARTMENU"
|
| 435 |
+
"CSIDL_STARTMENU"
|
| 436 |
+
|
| 437 |
+
"CSIDL_COMMON_DESKTOPDIRECTORY"
|
| 438 |
+
"CSIDL_DESKTOPDIRECTORY"
|
| 439 |
+
|
| 440 |
+
"CSIDL_COMMON_STARTUP"
|
| 441 |
+
"CSIDL_STARTUP"
|
| 442 |
+
|
| 443 |
+
"CSIDL_COMMON_PROGRAMS"
|
| 444 |
+
"CSIDL_PROGRAMS"
|
| 445 |
+
|
| 446 |
+
"CSIDL_FONTS"
|
| 447 |
+
|
| 448 |
+
If the folder cannot be retrieved, :exc:`OSError` is raised.
|
| 449 |
+
|
| 450 |
+
Which folders are available depends on the exact Windows version, and probably
|
| 451 |
+
also the configuration. For details refer to Microsoft's documentation of the
|
| 452 |
+
:c:func:`SHGetSpecialFolderPath` function.
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
.. function:: create_shortcut(target, description, filename[, arguments[, workdir[, iconpath[, iconindex]]]])
|
| 456 |
+
|
| 457 |
+
This function creates a shortcut. *target* is the path to the program to be
|
| 458 |
+
started by the shortcut. *description* is the description of the shortcut.
|
| 459 |
+
*filename* is the title of the shortcut that the user will see. *arguments*
|
| 460 |
+
specifies the command line arguments, if any. *workdir* is the working directory
|
| 461 |
+
for the program. *iconpath* is the file containing the icon for the shortcut,
|
| 462 |
+
and *iconindex* is the index of the icon in the file *iconpath*. Again, for
|
| 463 |
+
details consult the Microsoft documentation for the :class:`IShellLink`
|
| 464 |
+
interface.
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
Vista User Access Control (UAC)
|
| 468 |
+
===============================
|
| 469 |
+
|
| 470 |
+
Starting with Python 2.6, bdist_wininst supports a :option:`!--user-access-control`
|
| 471 |
+
option. The default is 'none' (meaning no UAC handling is done), and other
|
| 472 |
+
valid values are 'auto' (meaning prompt for UAC elevation if Python was
|
| 473 |
+
installed for all users) and 'force' (meaning always prompt for elevation).
|
| 474 |
+
|
| 475 |
+
.. note::
|
| 476 |
+
bdist_wininst is deprecated since Python 3.8.
|
| 477 |
+
|
| 478 |
+
.. note::
|
| 479 |
+
bdist_msi is deprecated since Python 3.9.
|
cpython_2/environment/repo/Doc/distutils/commandref.rst
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. _reference:
|
| 2 |
+
|
| 3 |
+
*****************
|
| 4 |
+
Command Reference
|
| 5 |
+
*****************
|
| 6 |
+
|
| 7 |
+
.. include:: ./_setuptools_disclaimer.rst
|
| 8 |
+
|
| 9 |
+
.. % \section{Building modules: the \protect\command{build} command family}
|
| 10 |
+
.. % \label{build-cmds}
|
| 11 |
+
.. % \subsubsection{\protect\command{build}}
|
| 12 |
+
.. % \label{build-cmd}
|
| 13 |
+
.. % \subsubsection{\protect\command{build\_py}}
|
| 14 |
+
.. % \label{build-py-cmd}
|
| 15 |
+
.. % \subsubsection{\protect\command{build\_ext}}
|
| 16 |
+
.. % \label{build-ext-cmd}
|
| 17 |
+
.. % \subsubsection{\protect\command{build\_clib}}
|
| 18 |
+
.. % \label{build-clib-cmd}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
.. _install-cmd:
|
| 22 |
+
|
| 23 |
+
Installing modules: the :command:`install` command family
|
| 24 |
+
=========================================================
|
| 25 |
+
|
| 26 |
+
The install command ensures that the build commands have been run and then runs
|
| 27 |
+
the subcommands :command:`install_lib`, :command:`install_data` and
|
| 28 |
+
:command:`install_scripts`.
|
| 29 |
+
|
| 30 |
+
.. % \subsubsection{\protect\command{install\_lib}}
|
| 31 |
+
.. % \label{install-lib-cmd}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
.. _install-data-cmd:
|
| 35 |
+
|
| 36 |
+
:command:`install_data`
|
| 37 |
+
-----------------------
|
| 38 |
+
|
| 39 |
+
This command installs all data files provided with the distribution.
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
.. _install-scripts-cmd:
|
| 43 |
+
|
| 44 |
+
:command:`install_scripts`
|
| 45 |
+
--------------------------
|
| 46 |
+
|
| 47 |
+
This command installs all (Python) scripts in the distribution.
|
| 48 |
+
|
| 49 |
+
.. % \subsection{Cleaning up: the \protect\command{clean} command}
|
| 50 |
+
.. % \label{clean-cmd}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
.. _sdist-cmd:
|
| 54 |
+
|
| 55 |
+
Creating a source distribution: the :command:`sdist` command
|
| 56 |
+
============================================================
|
| 57 |
+
|
| 58 |
+
.. XXX fragment moved down from above: needs context!
|
| 59 |
+
|
| 60 |
+
The manifest template commands are:
|
| 61 |
+
|
| 62 |
+
+-------------------------------------------+-----------------------------------------------+
|
| 63 |
+
| Command | Description |
|
| 64 |
+
+===========================================+===============================================+
|
| 65 |
+
| :command:`include pat1 pat2 ...` | include all files matching any of the listed |
|
| 66 |
+
| | patterns |
|
| 67 |
+
+-------------------------------------------+-----------------------------------------------+
|
| 68 |
+
| :command:`exclude pat1 pat2 ...` | exclude all files matching any of the listed |
|
| 69 |
+
| | patterns |
|
| 70 |
+
+-------------------------------------------+-----------------------------------------------+
|
| 71 |
+
| :command:`recursive-include dir pat1 pat2 | include all files under *dir* matching any of |
|
| 72 |
+
| ...` | the listed patterns |
|
| 73 |
+
+-------------------------------------------+-----------------------------------------------+
|
| 74 |
+
| :command:`recursive-exclude dir pat1 pat2 | exclude all files under *dir* matching any of |
|
| 75 |
+
| ...` | the listed patterns |
|
| 76 |
+
+-------------------------------------------+-----------------------------------------------+
|
| 77 |
+
| :command:`global-include pat1 pat2 ...` | include all files anywhere in the source tree |
|
| 78 |
+
| | matching --- & any of the listed patterns |
|
| 79 |
+
+-------------------------------------------+-----------------------------------------------+
|
| 80 |
+
| :command:`global-exclude pat1 pat2 ...` | exclude all files anywhere in the source tree |
|
| 81 |
+
| | matching --- & any of the listed patterns |
|
| 82 |
+
+-------------------------------------------+-----------------------------------------------+
|
| 83 |
+
| :command:`prune dir` | exclude all files under *dir* |
|
| 84 |
+
+-------------------------------------------+-----------------------------------------------+
|
| 85 |
+
| :command:`graft dir` | include all files under *dir* |
|
| 86 |
+
+-------------------------------------------+-----------------------------------------------+
|
| 87 |
+
|
| 88 |
+
The patterns here are Unix-style "glob" patterns: ``*`` matches any sequence of
|
| 89 |
+
regular filename characters, ``?`` matches any single regular filename
|
| 90 |
+
character, and ``[range]`` matches any of the characters in *range* (e.g.,
|
| 91 |
+
``a-z``, ``a-zA-Z``, ``a-f0-9_.``). The definition of "regular filename
|
| 92 |
+
character" is platform-specific: on Unix it is anything except slash; on Windows
|
| 93 |
+
anything except backslash or colon.
|
| 94 |
+
|
| 95 |
+
.. XXX Windows support not there yet
|
| 96 |
+
|
| 97 |
+
.. % \section{Creating a built distribution: the
|
| 98 |
+
.. % \protect\command{bdist} command family}
|
| 99 |
+
.. % \label{bdist-cmds}
|
| 100 |
+
|
| 101 |
+
.. % \subsection{\protect\command{bdist}}
|
| 102 |
+
.. % \subsection{\protect\command{bdist\_dumb}}
|
| 103 |
+
.. % \subsection{\protect\command{bdist\_rpm}}
|
| 104 |
+
.. % \subsection{\protect\command{bdist\_wininst}}
|
| 105 |
+
|
| 106 |
+
|
cpython_2/environment/repo/Doc/distutils/configfile.rst
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. _setup-config:
|
| 2 |
+
|
| 3 |
+
************************************
|
| 4 |
+
Writing the Setup Configuration File
|
| 5 |
+
************************************
|
| 6 |
+
|
| 7 |
+
.. include:: ./_setuptools_disclaimer.rst
|
| 8 |
+
|
| 9 |
+
Often, it's not possible to write down everything needed to build a distribution
|
| 10 |
+
*a priori*: you may need to get some information from the user, or from the
|
| 11 |
+
user's system, in order to proceed. As long as that information is fairly
|
| 12 |
+
simple---a list of directories to search for C header files or libraries, for
|
| 13 |
+
example---then providing a configuration file, :file:`setup.cfg`, for users to
|
| 14 |
+
edit is a cheap and easy way to solicit it. Configuration files also let you
|
| 15 |
+
provide default values for any command option, which the installer can then
|
| 16 |
+
override either on the command-line or by editing the config file.
|
| 17 |
+
|
| 18 |
+
The setup configuration file is a useful middle-ground between the setup
|
| 19 |
+
script---which, ideally, would be opaque to installers [#]_---and the command-line to
|
| 20 |
+
the setup script, which is outside of your control and entirely up to the
|
| 21 |
+
installer. In fact, :file:`setup.cfg` (and any other Distutils configuration
|
| 22 |
+
files present on the target system) are processed after the contents of the
|
| 23 |
+
setup script, but before the command-line. This has several useful
|
| 24 |
+
consequences:
|
| 25 |
+
|
| 26 |
+
.. % (If you have more advanced needs, such as determining which extensions
|
| 27 |
+
.. % to build based on what capabilities are present on the target system,
|
| 28 |
+
.. % then you need the Distutils ``auto-configuration'' facility. This
|
| 29 |
+
.. % started to appear in Distutils 0.9 but, as of this writing, isn't mature
|
| 30 |
+
.. % or stable enough yet for real-world use.)
|
| 31 |
+
|
| 32 |
+
* installers can override some of what you put in :file:`setup.py` by editing
|
| 33 |
+
:file:`setup.cfg`
|
| 34 |
+
|
| 35 |
+
* you can provide non-standard defaults for options that are not easily set in
|
| 36 |
+
:file:`setup.py`
|
| 37 |
+
|
| 38 |
+
* installers can override anything in :file:`setup.cfg` using the command-line
|
| 39 |
+
options to :file:`setup.py`
|
| 40 |
+
|
| 41 |
+
The basic syntax of the configuration file is simple:
|
| 42 |
+
|
| 43 |
+
.. code-block:: ini
|
| 44 |
+
|
| 45 |
+
[command]
|
| 46 |
+
option=value
|
| 47 |
+
...
|
| 48 |
+
|
| 49 |
+
where *command* is one of the Distutils commands (e.g. :command:`build_py`,
|
| 50 |
+
:command:`install`), and *option* is one of the options that command supports.
|
| 51 |
+
Any number of options can be supplied for each command, and any number of
|
| 52 |
+
command sections can be included in the file. Blank lines are ignored, as are
|
| 53 |
+
comments, which run from a ``'#'`` character until the end of the line. Long
|
| 54 |
+
option values can be split across multiple lines simply by indenting the
|
| 55 |
+
continuation lines.
|
| 56 |
+
|
| 57 |
+
You can find out the list of options supported by a particular command with the
|
| 58 |
+
universal :option:`!--help` option, e.g.
|
| 59 |
+
|
| 60 |
+
.. code-block:: shell-session
|
| 61 |
+
|
| 62 |
+
$ python setup.py --help build_ext
|
| 63 |
+
[...]
|
| 64 |
+
Options for 'build_ext' command:
|
| 65 |
+
--build-lib (-b) directory for compiled extension modules
|
| 66 |
+
--build-temp (-t) directory for temporary files (build by-products)
|
| 67 |
+
--inplace (-i) ignore build-lib and put compiled extensions into the
|
| 68 |
+
source directory alongside your pure Python modules
|
| 69 |
+
--include-dirs (-I) list of directories to search for header files
|
| 70 |
+
--define (-D) C preprocessor macros to define
|
| 71 |
+
--undef (-U) C preprocessor macros to undefine
|
| 72 |
+
--swig-opts list of SWIG command line options
|
| 73 |
+
[...]
|
| 74 |
+
|
| 75 |
+
Note that an option spelled :option:`!--foo-bar` on the command-line is spelled
|
| 76 |
+
``foo_bar`` in configuration files.
|
| 77 |
+
|
| 78 |
+
.. _distutils-build-ext-inplace:
|
| 79 |
+
|
| 80 |
+
For example, say you want your extensions to be built "in-place"---that is, you
|
| 81 |
+
have an extension :mod:`pkg.ext`, and you want the compiled extension file
|
| 82 |
+
(:file:`ext.so` on Unix, say) to be put in the same source directory as your
|
| 83 |
+
pure Python modules :mod:`pkg.mod1` and :mod:`pkg.mod2`. You can always use the
|
| 84 |
+
:option:`!--inplace` option on the command-line to ensure this:
|
| 85 |
+
|
| 86 |
+
.. code-block:: sh
|
| 87 |
+
|
| 88 |
+
python setup.py build_ext --inplace
|
| 89 |
+
|
| 90 |
+
But this requires that you always specify the :command:`build_ext` command
|
| 91 |
+
explicitly, and remember to provide :option:`!--inplace`. An easier way is to
|
| 92 |
+
"set and forget" this option, by encoding it in :file:`setup.cfg`, the
|
| 93 |
+
configuration file for this distribution:
|
| 94 |
+
|
| 95 |
+
.. code-block:: ini
|
| 96 |
+
|
| 97 |
+
[build_ext]
|
| 98 |
+
inplace=1
|
| 99 |
+
|
| 100 |
+
This will affect all builds of this module distribution, whether or not you
|
| 101 |
+
explicitly specify :command:`build_ext`. If you include :file:`setup.cfg` in
|
| 102 |
+
your source distribution, it will also affect end-user builds---which is
|
| 103 |
+
probably a bad idea for this option, since always building extensions in-place
|
| 104 |
+
would break installation of the module distribution. In certain peculiar cases,
|
| 105 |
+
though, modules are built right in their installation directory, so this is
|
| 106 |
+
conceivably a useful ability. (Distributing extensions that expect to be built
|
| 107 |
+
in their installation directory is almost always a bad idea, though.)
|
| 108 |
+
|
| 109 |
+
Another example: certain commands take a lot of options that don't change from
|
| 110 |
+
run to run; for example, :command:`bdist_rpm` needs to know everything required
|
| 111 |
+
to generate a "spec" file for creating an RPM distribution. Some of this
|
| 112 |
+
information comes from the setup script, and some is automatically generated by
|
| 113 |
+
the Distutils (such as the list of files installed). But some of it has to be
|
| 114 |
+
supplied as options to :command:`bdist_rpm`, which would be very tedious to do
|
| 115 |
+
on the command-line for every run. Hence, here is a snippet from the Distutils'
|
| 116 |
+
own :file:`setup.cfg`:
|
| 117 |
+
|
| 118 |
+
.. code-block:: ini
|
| 119 |
+
|
| 120 |
+
[bdist_rpm]
|
| 121 |
+
release = 1
|
| 122 |
+
packager = Greg Ward <gward@python.net>
|
| 123 |
+
doc_files = CHANGES.txt
|
| 124 |
+
README.txt
|
| 125 |
+
USAGE.txt
|
| 126 |
+
doc/
|
| 127 |
+
examples/
|
| 128 |
+
|
| 129 |
+
Note that the ``doc_files`` option is simply a whitespace-separated string
|
| 130 |
+
split across multiple lines for readability.
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
.. seealso::
|
| 134 |
+
|
| 135 |
+
:ref:`inst-config-syntax` in "Installing Python Modules"
|
| 136 |
+
More information on the configuration files is available in the manual for
|
| 137 |
+
system administrators.
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
.. rubric:: Footnotes
|
| 141 |
+
|
| 142 |
+
.. [#] This ideal probably won't be achieved until auto-configuration is fully
|
| 143 |
+
supported by the Distutils.
|
| 144 |
+
|
cpython_2/environment/repo/Doc/distutils/examples.rst
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ter provides a number of basic examples to help get started with
|
| 10 |
+
distutils. Additional information about using distutils can be found in the
|
| 11 |
+
Distutils Cookbook.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
.. seealso::
|
| 15 |
+
|
| 16 |
+
`Distutils Cookbook <https://wiki.python.org/moin/Distutils/Cookbook>`_
|
| 17 |
+
Collection of recipes showing how to achieve more control over distutils.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
.. _pure-mod:
|
| 21 |
+
|
| 22 |
+
Pure Python distribution (by module)
|
| 23 |
+
====================================
|
| 24 |
+
|
| 25 |
+
If you're just distributing a couple of modules, especially if they don't live
|
| 26 |
+
in a particular package, you can specify them individually using the
|
| 27 |
+
``py_modules`` option in the setup script.
|
| 28 |
+
|
| 29 |
+
In the simplest case, you'll have two files to worry about: a setup script and
|
| 30 |
+
the single module you're distributing, :file:`foo.py` in this example::
|
| 31 |
+
|
| 32 |
+
<root>/
|
| 33 |
+
setup.py
|
| 34 |
+
foo.py
|
| 35 |
+
|
| 36 |
+
(In all diagrams in this section, *<root>* will refer to the distribution root
|
| 37 |
+
directory.) A minimal setup script to describe this situation would be::
|
| 38 |
+
|
| 39 |
+
from distutils.core import setup
|
| 40 |
+
setup(name='foo',
|
| 41 |
+
version='1.0',
|
| 42 |
+
py_modules=['foo'],
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
Note that the name of the distribution is specified independently with the
|
| 46 |
+
``name`` option, and there's no rule that says it has to be the same as
|
| 47 |
+
the name of the sole module in the distribution (although that's probably a good
|
| 48 |
+
convention to follow). However, the distribution name is used to generate
|
| 49 |
+
filenames, so you should stick to letters, digits, underscores, and hyphens.
|
| 50 |
+
|
| 51 |
+
Since ``py_modules`` is a list, you can of course specify multiple
|
| 52 |
+
modules, eg. if you're distributing modules :mod:`foo` and :mod:`bar`, your
|
| 53 |
+
setup might look like this::
|
| 54 |
+
|
| 55 |
+
<root>/
|
| 56 |
+
setup.py
|
| 57 |
+
foo.py
|
| 58 |
+
bar.py
|
| 59 |
+
|
| 60 |
+
and the setup script might be ::
|
| 61 |
+
|
| 62 |
+
from distutils.core import setup
|
| 63 |
+
setup(name='foobar',
|
| 64 |
+
version='1.0',
|
| 65 |
+
py_modules=['foo', 'bar'],
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
You can put module source files into another directory, but if you have enough
|
| 69 |
+
modules to do that, it's probably easier to specify modules by package rather
|
| 70 |
+
than listing them individually.
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
.. _pure-pkg:
|
| 74 |
+
|
| 75 |
+
Pure Python distribution (by package)
|
| 76 |
+
=====================================
|
| 77 |
+
|
| 78 |
+
If you have more than a couple of modules to distribute, especially if they are
|
| 79 |
+
in multiple packages, it's probably easier to specify whole packages rather than
|
| 80 |
+
individual modules. This works even if your modules are not in a package; you
|
| 81 |
+
can just tell the Distutils to process modules from the root package, and that
|
| 82 |
+
works the same as any other package (except that you don't have to have an
|
| 83 |
+
:file:`__init__.py` file).
|
| 84 |
+
|
| 85 |
+
The setup script from the last example could also be written as ::
|
| 86 |
+
|
| 87 |
+
from distutils.core import setup
|
| 88 |
+
setup(name='foobar',
|
| 89 |
+
version='1.0',
|
| 90 |
+
packages=[''],
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
(The empty string stands for the root package.)
|
| 94 |
+
|
| 95 |
+
If those two files are moved into a subdirectory, but remain in the root
|
| 96 |
+
package, e.g.::
|
| 97 |
+
|
| 98 |
+
<root>/
|
| 99 |
+
setup.py
|
| 100 |
+
src/ foo.py
|
| 101 |
+
bar.py
|
| 102 |
+
|
| 103 |
+
then you would still specify the root package, but you have to tell the
|
| 104 |
+
Distutils where source files in the root package live::
|
| 105 |
+
|
| 106 |
+
from distutils.core import setup
|
| 107 |
+
setup(name='foobar',
|
| 108 |
+
version='1.0',
|
| 109 |
+
package_dir={'': 'src'},
|
| 110 |
+
packages=[''],
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
More typically, though, you will want to distribute multiple modules in the same
|
| 114 |
+
package (or in sub-packages). For example, if the :mod:`foo` and :mod:`bar`
|
| 115 |
+
modules belong in package :mod:`foobar`, one way to layout your source tree is
|
| 116 |
+
::
|
| 117 |
+
|
| 118 |
+
<root>/
|
| 119 |
+
setup.py
|
| 120 |
+
foobar/
|
| 121 |
+
__init__.py
|
| 122 |
+
foo.py
|
| 123 |
+
bar.py
|
| 124 |
+
|
| 125 |
+
This is in fact the default layout expected by the Distutils, and the one that
|
| 126 |
+
requires the least work to describe in your setup script::
|
| 127 |
+
|
| 128 |
+
from distutils.core import setup
|
| 129 |
+
setup(name='foobar',
|
| 130 |
+
version='1.0',
|
| 131 |
+
packages=['foobar'],
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
If you want to put modules in directories not named for their package, then you
|
| 135 |
+
need to use the ``package_dir`` option again. For example, if the
|
| 136 |
+
:file:`src` directory holds modules in the :mod:`foobar` package::
|
| 137 |
+
|
| 138 |
+
<root>/
|
| 139 |
+
setup.py
|
| 140 |
+
src/
|
| 141 |
+
__init__.py
|
| 142 |
+
foo.py
|
| 143 |
+
bar.py
|
| 144 |
+
|
| 145 |
+
an appropriate setup script would be ::
|
| 146 |
+
|
| 147 |
+
from distutils.core import setup
|
| 148 |
+
setup(name='foobar',
|
| 149 |
+
version='1.0',
|
| 150 |
+
package_dir={'foobar': 'src'},
|
| 151 |
+
packages=['foobar'],
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
Or, you might put modules from your main package right in the distribution
|
| 155 |
+
root::
|
| 156 |
+
|
| 157 |
+
<root>/
|
| 158 |
+
setup.py
|
| 159 |
+
__init__.py
|
| 160 |
+
foo.py
|
| 161 |
+
bar.py
|
| 162 |
+
|
| 163 |
+
in which case your setup script would be ::
|
| 164 |
+
|
| 165 |
+
from distutils.core import setup
|
| 166 |
+
setup(name='foobar',
|
| 167 |
+
version='1.0',
|
| 168 |
+
package_dir={'foobar': ''},
|
| 169 |
+
packages=['foobar'],
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
(The empty string also stands for the current directory.)
|
| 173 |
+
|
| 174 |
+
If you have sub-packages, they must be explicitly listed in ``packages``,
|
| 175 |
+
but any entries in ``package_dir`` automatically extend to sub-packages.
|
| 176 |
+
(In other words, the Distutils does *not* scan your source tree, trying to
|
| 177 |
+
figure out which directories correspond to Python packages by looking for
|
| 178 |
+
:file:`__init__.py` files.) Thus, if the default layout grows a sub-package::
|
| 179 |
+
|
| 180 |
+
<root>/
|
| 181 |
+
setup.py
|
| 182 |
+
foobar/
|
| 183 |
+
__init__.py
|
| 184 |
+
foo.py
|
| 185 |
+
bar.py
|
| 186 |
+
subfoo/
|
| 187 |
+
__init__.py
|
| 188 |
+
blah.py
|
| 189 |
+
|
| 190 |
+
then the corresponding setup script would be ::
|
| 191 |
+
|
| 192 |
+
from distutils.core import setup
|
| 193 |
+
setup(name='foobar',
|
| 194 |
+
version='1.0',
|
| 195 |
+
packages=['foobar', 'foobar.subfoo'],
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
.. _single-ext:
|
| 200 |
+
|
| 201 |
+
Single extension module
|
| 202 |
+
=======================
|
| 203 |
+
|
| 204 |
+
Extension modules are specified using the ``ext_modules`` option.
|
| 205 |
+
``package_dir`` has no effect on where extension source files are found;
|
| 206 |
+
it only affects the source for pure Python modules. The simplest case, a
|
| 207 |
+
single extension module in a single C source file, is::
|
| 208 |
+
|
| 209 |
+
<root>/
|
| 210 |
+
setup.py
|
| 211 |
+
foo.c
|
| 212 |
+
|
| 213 |
+
If the :mod:`foo` extension belongs in the root package, the setup script for
|
| 214 |
+
this could be ::
|
| 215 |
+
|
| 216 |
+
from distutils.core import setup
|
| 217 |
+
from distutils.extension import Extension
|
| 218 |
+
setup(name='foobar',
|
| 219 |
+
version='1.0',
|
| 220 |
+
ext_modules=[Extension('foo', ['foo.c'])],
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
If the extension actually belongs in a package, say :mod:`foopkg`, then
|
| 224 |
+
|
| 225 |
+
With exactly the same source tree layout, this extension can be put in the
|
| 226 |
+
:mod:`foopkg` package simply by changing the name of the extension::
|
| 227 |
+
|
| 228 |
+
from distutils.core import setup
|
| 229 |
+
from distutils.extension import Extension
|
| 230 |
+
setup(name='foobar',
|
| 231 |
+
version='1.0',
|
| 232 |
+
ext_modules=[Extension('foopkg.foo', ['foo.c'])],
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
Checking a package
|
| 236 |
+
==================
|
| 237 |
+
|
| 238 |
+
The ``check`` command allows you to verify if your package meta-data
|
| 239 |
+
meet the minimum requirements to build a distribution.
|
| 240 |
+
|
| 241 |
+
To run it, just call it using your :file:`setup.py` script. If something is
|
| 242 |
+
missing, ``check`` will display a warning.
|
| 243 |
+
|
| 244 |
+
Let's take an example with a simple script::
|
| 245 |
+
|
| 246 |
+
from distutils.core import setup
|
| 247 |
+
|
| 248 |
+
setup(name='foobar')
|
| 249 |
+
|
| 250 |
+
Running the ``check`` command will display some warnings:
|
| 251 |
+
|
| 252 |
+
.. code-block:: shell-session
|
| 253 |
+
|
| 254 |
+
$ python setup.py check
|
| 255 |
+
running check
|
| 256 |
+
warning: check: missing required meta-data: version, url
|
| 257 |
+
warning: check: missing meta-data: either (author and author_email) or
|
| 258 |
+
(maintainer and maintainer_email) should be supplied
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
If you use the reStructuredText syntax in the ``long_description`` field and
|
| 262 |
+
`docutils`_ is installed you can check if the syntax is fine with the
|
| 263 |
+
``check`` command, using the ``restructuredtext`` option.
|
| 264 |
+
|
| 265 |
+
For example, if the :file:`setup.py` script is changed like this::
|
| 266 |
+
|
| 267 |
+
from distutils.core import setup
|
| 268 |
+
|
| 269 |
+
desc = """\
|
| 270 |
+
My description
|
| 271 |
+
==============
|
| 272 |
+
|
| 273 |
+
This is the description of the ``foobar`` package.
|
| 274 |
+
"""
|
| 275 |
+
|
| 276 |
+
setup(name='foobar', version='1', author='tarek',
|
| 277 |
+
author_email='tarek@ziade.org',
|
| 278 |
+
url='http://example.com', long_description=desc)
|
| 279 |
+
|
| 280 |
+
Where the long description is broken, ``check`` will be able to detect it
|
| 281 |
+
by using the :mod:`docutils` parser:
|
| 282 |
+
|
| 283 |
+
.. code-block:: shell-session
|
| 284 |
+
|
| 285 |
+
$ python setup.py check --restructuredtext
|
| 286 |
+
running check
|
| 287 |
+
warning: check: Title underline too short. (line 2)
|
| 288 |
+
warning: check: Could not finish the parsing.
|
| 289 |
+
|
| 290 |
+
Reading the metadata
|
| 291 |
+
=====================
|
| 292 |
+
|
| 293 |
+
The :func:`distutils.core.setup` function provides a command-line interface
|
| 294 |
+
that allows you to query the metadata fields of a project through the
|
| 295 |
+
``setup.py`` script of a given project:
|
| 296 |
+
|
| 297 |
+
.. code-block:: shell-session
|
| 298 |
+
|
| 299 |
+
$ python setup.py --name
|
| 300 |
+
distribute
|
| 301 |
+
|
| 302 |
+
This call reads the ``name`` metadata by running the
|
| 303 |
+
:func:`distutils.core.setup` function. Although, when a source or binary
|
| 304 |
+
distribution is created with Distutils, the metadata fields are written
|
| 305 |
+
in a static file called :file:`PKG-INFO`. When a Distutils-based project is
|
| 306 |
+
installed in Python, the :file:`PKG-INFO` file is copied alongside the modules
|
| 307 |
+
and packages of the distribution under :file:`NAME-VERSION-pyX.X.egg-info`,
|
| 308 |
+
where ``NAME`` is the name of the project, ``VERSION`` its version as defined
|
| 309 |
+
in the Metadata, and ``pyX.X`` the major and minor version of Python like
|
| 310 |
+
``2.7`` or ``3.2``.
|
| 311 |
+
|
| 312 |
+
You can read back this static file, by using the
|
| 313 |
+
:class:`distutils.dist.DistributionMetadata` class and its
|
| 314 |
+
:func:`read_pkg_file` method::
|
| 315 |
+
|
| 316 |
+
>>> from distutils.dist import DistributionMetadata
|
| 317 |
+
>>> metadata = DistributionMetadata()
|
| 318 |
+
>>> metadata.read_pkg_file(open('distribute-0.6.8-py2.7.egg-info'))
|
| 319 |
+
>>> metadata.name
|
| 320 |
+
'distribute'
|
| 321 |
+
>>> metadata.version
|
| 322 |
+
'0.6.8'
|
| 323 |
+
>>> metadata.description
|
| 324 |
+
'Easily download, build, install, upgrade, and uninstall Python packages'
|
| 325 |
+
|
| 326 |
+
Notice that the class can also be instantiated with a metadata file path to
|
| 327 |
+
loads its values::
|
| 328 |
+
|
| 329 |
+
>>> pkg_info_path = 'distribute-0.6.8-py2.7.egg-info'
|
| 330 |
+
>>> DistributionMetadata(pkg_info_path).name
|
| 331 |
+
'distribute'
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
.. % \section{Multiple extension modules}
|
| 335 |
+
.. % \label{multiple-ext}
|
| 336 |
+
|
| 337 |
+
.. % \section{Putting it all together}
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
.. _docutils: http://docutils.sourceforge.net
|