mirror of https://github.com/python/cpython.git
gh-115172: Fix explicit index extries for the C API (GH-115173)
This commit is contained in:
parent
4a08e7b343
commit
573acb30f2
|
@ -29,7 +29,7 @@ without intermediate copying.
|
||||||
Python provides such a facility at the C level in the form of the :ref:`buffer
|
Python provides such a facility at the C level in the form of the :ref:`buffer
|
||||||
protocol <bufferobjects>`. This protocol has two sides:
|
protocol <bufferobjects>`. This protocol has two sides:
|
||||||
|
|
||||||
.. index:: single: PyBufferProcs
|
.. index:: single: PyBufferProcs (C type)
|
||||||
|
|
||||||
- on the producer side, a type can export a "buffer interface" which allows
|
- on the producer side, a type can export a "buffer interface" which allows
|
||||||
objects of that type to expose information about their underlying buffer.
|
objects of that type to expose information about their underlying buffer.
|
||||||
|
|
|
@ -49,7 +49,7 @@ bound into a function.
|
||||||
.. versionchanged:: 3.11
|
.. versionchanged:: 3.11
|
||||||
Added ``qualname`` and ``exceptiontable`` parameters.
|
Added ``qualname`` and ``exceptiontable`` parameters.
|
||||||
|
|
||||||
.. index:: single: PyCode_New
|
.. index:: single: PyCode_New (C function)
|
||||||
|
|
||||||
.. versionchanged:: 3.12
|
.. versionchanged:: 3.12
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ bound into a function.
|
||||||
Similar to :c:func:`PyUnstable_Code_New`, but with an extra "posonlyargcount" for positional-only arguments.
|
Similar to :c:func:`PyUnstable_Code_New`, but with an extra "posonlyargcount" for positional-only arguments.
|
||||||
The same caveats that apply to ``PyUnstable_Code_New`` also apply to this function.
|
The same caveats that apply to ``PyUnstable_Code_New`` also apply to this function.
|
||||||
|
|
||||||
.. index:: single: PyCode_NewWithPosOnlyArgs
|
.. index:: single: PyCode_NewWithPosOnlyArgs (C function)
|
||||||
|
|
||||||
.. versionadded:: 3.8 as ``PyCode_NewWithPosOnlyArgs``
|
.. versionadded:: 3.8 as ``PyCode_NewWithPosOnlyArgs``
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ may change without deprecation warnings.
|
||||||
*free* will be called on non-``NULL`` data stored under the new index.
|
*free* will be called on non-``NULL`` data stored under the new index.
|
||||||
Use :c:func:`Py_DecRef` when storing :c:type:`PyObject`.
|
Use :c:func:`Py_DecRef` when storing :c:type:`PyObject`.
|
||||||
|
|
||||||
.. index:: single: _PyEval_RequestCodeExtraIndex
|
.. index:: single: _PyEval_RequestCodeExtraIndex (C function)
|
||||||
|
|
||||||
.. versionadded:: 3.6 as ``_PyEval_RequestCodeExtraIndex``
|
.. versionadded:: 3.6 as ``_PyEval_RequestCodeExtraIndex``
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ may change without deprecation warnings.
|
||||||
If no data was set under the index, set *extra* to ``NULL`` and return
|
If no data was set under the index, set *extra* to ``NULL`` and return
|
||||||
0 without setting an exception.
|
0 without setting an exception.
|
||||||
|
|
||||||
.. index:: single: _PyCode_GetExtra
|
.. index:: single: _PyCode_GetExtra (C function)
|
||||||
|
|
||||||
.. versionadded:: 3.6 as ``_PyCode_GetExtra``
|
.. versionadded:: 3.6 as ``_PyCode_GetExtra``
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ may change without deprecation warnings.
|
||||||
Set the extra data stored under the given index to *extra*.
|
Set the extra data stored under the given index to *extra*.
|
||||||
Return 0 on success. Set an exception and return -1 on failure.
|
Return 0 on success. Set an exception and return -1 on failure.
|
||||||
|
|
||||||
.. index:: single: _PyCode_SetExtra
|
.. index:: single: _PyCode_SetExtra (C function)
|
||||||
|
|
||||||
.. versionadded:: 3.6 as ``_PyCode_SetExtra``
|
.. versionadded:: 3.6 as ``_PyCode_SetExtra``
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ For convenience, some of these functions will always return a
|
||||||
|
|
||||||
.. c:function:: PyObject* PyErr_SetFromErrno(PyObject *type)
|
.. c:function:: PyObject* PyErr_SetFromErrno(PyObject *type)
|
||||||
|
|
||||||
.. index:: single: strerror()
|
.. index:: single: strerror (C function)
|
||||||
|
|
||||||
This is a convenience function to raise an exception when a C library function
|
This is a convenience function to raise an exception when a C library function
|
||||||
has returned an error and set the C variable :c:data:`errno`. It constructs a
|
has returned an error and set the C variable :c:data:`errno`. It constructs a
|
||||||
|
@ -635,7 +635,7 @@ Signal Handling
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
pair: module; signal
|
pair: module; signal
|
||||||
single: SIGINT
|
single: SIGINT (C macro)
|
||||||
single: KeyboardInterrupt (built-in exception)
|
single: KeyboardInterrupt (built-in exception)
|
||||||
|
|
||||||
This function interacts with Python's signal handling.
|
This function interacts with Python's signal handling.
|
||||||
|
@ -666,7 +666,7 @@ Signal Handling
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
pair: module; signal
|
pair: module; signal
|
||||||
single: SIGINT
|
single: SIGINT (C macro)
|
||||||
single: KeyboardInterrupt (built-in exception)
|
single: KeyboardInterrupt (built-in exception)
|
||||||
|
|
||||||
Simulate the effect of a :c:macro:`!SIGINT` signal arriving.
|
Simulate the effect of a :c:macro:`!SIGINT` signal arriving.
|
||||||
|
@ -968,59 +968,59 @@ All standard Python exceptions are available as global variables whose names are
|
||||||
the variables:
|
the variables:
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PyExc_BaseException
|
single: PyExc_BaseException (C var)
|
||||||
single: PyExc_Exception
|
single: PyExc_Exception (C var)
|
||||||
single: PyExc_ArithmeticError
|
single: PyExc_ArithmeticError (C var)
|
||||||
single: PyExc_AssertionError
|
single: PyExc_AssertionError (C var)
|
||||||
single: PyExc_AttributeError
|
single: PyExc_AttributeError (C var)
|
||||||
single: PyExc_BlockingIOError
|
single: PyExc_BlockingIOError (C var)
|
||||||
single: PyExc_BrokenPipeError
|
single: PyExc_BrokenPipeError (C var)
|
||||||
single: PyExc_BufferError
|
single: PyExc_BufferError (C var)
|
||||||
single: PyExc_ChildProcessError
|
single: PyExc_ChildProcessError (C var)
|
||||||
single: PyExc_ConnectionAbortedError
|
single: PyExc_ConnectionAbortedError (C var)
|
||||||
single: PyExc_ConnectionError
|
single: PyExc_ConnectionError (C var)
|
||||||
single: PyExc_ConnectionRefusedError
|
single: PyExc_ConnectionRefusedError (C var)
|
||||||
single: PyExc_ConnectionResetError
|
single: PyExc_ConnectionResetError (C var)
|
||||||
single: PyExc_EOFError
|
single: PyExc_EOFError (C var)
|
||||||
single: PyExc_FileExistsError
|
single: PyExc_FileExistsError (C var)
|
||||||
single: PyExc_FileNotFoundError
|
single: PyExc_FileNotFoundError (C var)
|
||||||
single: PyExc_FloatingPointError
|
single: PyExc_FloatingPointError (C var)
|
||||||
single: PyExc_GeneratorExit
|
single: PyExc_GeneratorExit (C var)
|
||||||
single: PyExc_ImportError
|
single: PyExc_ImportError (C var)
|
||||||
single: PyExc_IndentationError
|
single: PyExc_IndentationError (C var)
|
||||||
single: PyExc_IndexError
|
single: PyExc_IndexError (C var)
|
||||||
single: PyExc_InterruptedError
|
single: PyExc_InterruptedError (C var)
|
||||||
single: PyExc_IsADirectoryError
|
single: PyExc_IsADirectoryError (C var)
|
||||||
single: PyExc_KeyError
|
single: PyExc_KeyError (C var)
|
||||||
single: PyExc_KeyboardInterrupt
|
single: PyExc_KeyboardInterrupt (C var)
|
||||||
single: PyExc_LookupError
|
single: PyExc_LookupError (C var)
|
||||||
single: PyExc_MemoryError
|
single: PyExc_MemoryError (C var)
|
||||||
single: PyExc_ModuleNotFoundError
|
single: PyExc_ModuleNotFoundError (C var)
|
||||||
single: PyExc_NameError
|
single: PyExc_NameError (C var)
|
||||||
single: PyExc_NotADirectoryError
|
single: PyExc_NotADirectoryError (C var)
|
||||||
single: PyExc_NotImplementedError
|
single: PyExc_NotImplementedError (C var)
|
||||||
single: PyExc_OSError
|
single: PyExc_OSError (C var)
|
||||||
single: PyExc_OverflowError
|
single: PyExc_OverflowError (C var)
|
||||||
single: PyExc_PermissionError
|
single: PyExc_PermissionError (C var)
|
||||||
single: PyExc_ProcessLookupError
|
single: PyExc_ProcessLookupError (C var)
|
||||||
single: PyExc_RecursionError
|
single: PyExc_RecursionError (C var)
|
||||||
single: PyExc_ReferenceError
|
single: PyExc_ReferenceError (C var)
|
||||||
single: PyExc_RuntimeError
|
single: PyExc_RuntimeError (C var)
|
||||||
single: PyExc_StopAsyncIteration
|
single: PyExc_StopAsyncIteration (C var)
|
||||||
single: PyExc_StopIteration
|
single: PyExc_StopIteration (C var)
|
||||||
single: PyExc_SyntaxError
|
single: PyExc_SyntaxError (C var)
|
||||||
single: PyExc_SystemError
|
single: PyExc_SystemError (C var)
|
||||||
single: PyExc_SystemExit
|
single: PyExc_SystemExit (C var)
|
||||||
single: PyExc_TabError
|
single: PyExc_TabError (C var)
|
||||||
single: PyExc_TimeoutError
|
single: PyExc_TimeoutError (C var)
|
||||||
single: PyExc_TypeError
|
single: PyExc_TypeError (C var)
|
||||||
single: PyExc_UnboundLocalError
|
single: PyExc_UnboundLocalError (C var)
|
||||||
single: PyExc_UnicodeDecodeError
|
single: PyExc_UnicodeDecodeError (C var)
|
||||||
single: PyExc_UnicodeEncodeError
|
single: PyExc_UnicodeEncodeError (C var)
|
||||||
single: PyExc_UnicodeError
|
single: PyExc_UnicodeError (C var)
|
||||||
single: PyExc_UnicodeTranslateError
|
single: PyExc_UnicodeTranslateError (C var)
|
||||||
single: PyExc_ValueError
|
single: PyExc_ValueError (C var)
|
||||||
single: PyExc_ZeroDivisionError
|
single: PyExc_ZeroDivisionError (C var)
|
||||||
|
|
||||||
+-----------------------------------------+---------------------------------+----------+
|
+-----------------------------------------+---------------------------------+----------+
|
||||||
| C Name | Python Name | Notes |
|
| C Name | Python Name | Notes |
|
||||||
|
@ -1151,9 +1151,9 @@ the variables:
|
||||||
These are compatibility aliases to :c:data:`PyExc_OSError`:
|
These are compatibility aliases to :c:data:`PyExc_OSError`:
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PyExc_EnvironmentError
|
single: PyExc_EnvironmentError (C var)
|
||||||
single: PyExc_IOError
|
single: PyExc_IOError (C var)
|
||||||
single: PyExc_WindowsError
|
single: PyExc_WindowsError (C var)
|
||||||
|
|
||||||
+-------------------------------------+----------+
|
+-------------------------------------+----------+
|
||||||
| C Name | Notes |
|
| C Name | Notes |
|
||||||
|
@ -1188,17 +1188,17 @@ names are ``PyExc_`` followed by the Python exception name. These have the type
|
||||||
the variables:
|
the variables:
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PyExc_Warning
|
single: PyExc_Warning (C var)
|
||||||
single: PyExc_BytesWarning
|
single: PyExc_BytesWarning (C var)
|
||||||
single: PyExc_DeprecationWarning
|
single: PyExc_DeprecationWarning (C var)
|
||||||
single: PyExc_FutureWarning
|
single: PyExc_FutureWarning (C var)
|
||||||
single: PyExc_ImportWarning
|
single: PyExc_ImportWarning (C var)
|
||||||
single: PyExc_PendingDeprecationWarning
|
single: PyExc_PendingDeprecationWarning (C var)
|
||||||
single: PyExc_ResourceWarning
|
single: PyExc_ResourceWarning (C var)
|
||||||
single: PyExc_RuntimeWarning
|
single: PyExc_RuntimeWarning (C var)
|
||||||
single: PyExc_SyntaxWarning
|
single: PyExc_SyntaxWarning (C var)
|
||||||
single: PyExc_UnicodeWarning
|
single: PyExc_UnicodeWarning (C var)
|
||||||
single: PyExc_UserWarning
|
single: PyExc_UserWarning (C var)
|
||||||
|
|
||||||
+------------------------------------------+---------------------------------+----------+
|
+------------------------------------------+---------------------------------+----------+
|
||||||
| C Name | Python Name | Notes |
|
| C Name | Python Name | Notes |
|
||||||
|
|
|
@ -96,7 +96,7 @@ the :mod:`io` APIs instead.
|
||||||
|
|
||||||
.. c:function:: int PyFile_WriteObject(PyObject *obj, PyObject *p, int flags)
|
.. c:function:: int PyFile_WriteObject(PyObject *obj, PyObject *p, int flags)
|
||||||
|
|
||||||
.. index:: single: Py_PRINT_RAW
|
.. index:: single: Py_PRINT_RAW (C macro)
|
||||||
|
|
||||||
Write object *obj* to file object *p*. The only supported flag for *flags* is
|
Write object *obj* to file object *p*. The only supported flag for *flags* is
|
||||||
:c:macro:`Py_PRINT_RAW`; if given, the :func:`str` of the object is written
|
:c:macro:`Py_PRINT_RAW`; if given, the :func:`str` of the object is written
|
||||||
|
|
|
@ -332,7 +332,7 @@ Initializing and finalizing the interpreter
|
||||||
pair: module; __main__
|
pair: module; __main__
|
||||||
pair: module; sys
|
pair: module; sys
|
||||||
triple: module; search; path
|
triple: module; search; path
|
||||||
single: Py_FinalizeEx()
|
single: Py_FinalizeEx (C function)
|
||||||
|
|
||||||
Initialize the Python interpreter. In an application embedding Python,
|
Initialize the Python interpreter. In an application embedding Python,
|
||||||
this should be called before using any other Python/C API functions; see
|
this should be called before using any other Python/C API functions; see
|
||||||
|
@ -661,7 +661,7 @@ operations could cause problems in a multi-threaded program: for example, when
|
||||||
two threads simultaneously increment the reference count of the same object, the
|
two threads simultaneously increment the reference count of the same object, the
|
||||||
reference count could end up being incremented only once instead of twice.
|
reference count could end up being incremented only once instead of twice.
|
||||||
|
|
||||||
.. index:: single: setswitchinterval() (in module sys)
|
.. index:: single: setswitchinterval (in module sys)
|
||||||
|
|
||||||
Therefore, the rule exists that only the thread that has acquired the
|
Therefore, the rule exists that only the thread that has acquired the
|
||||||
:term:`GIL` may operate on Python objects or call Python/C API functions.
|
:term:`GIL` may operate on Python objects or call Python/C API functions.
|
||||||
|
@ -671,8 +671,7 @@ released around potentially blocking I/O operations like reading or writing
|
||||||
a file, so that other Python threads can run in the meantime.
|
a file, so that other Python threads can run in the meantime.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PyThreadState
|
single: PyThreadState (C type)
|
||||||
single: PyThreadState
|
|
||||||
|
|
||||||
The Python interpreter keeps some thread-specific bookkeeping information
|
The Python interpreter keeps some thread-specific bookkeeping information
|
||||||
inside a data structure called :c:type:`PyThreadState`. There's also one
|
inside a data structure called :c:type:`PyThreadState`. There's also one
|
||||||
|
@ -698,8 +697,8 @@ This is so common that a pair of macros exists to simplify it::
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: Py_BEGIN_ALLOW_THREADS
|
single: Py_BEGIN_ALLOW_THREADS (C macro)
|
||||||
single: Py_END_ALLOW_THREADS
|
single: Py_END_ALLOW_THREADS (C macro)
|
||||||
|
|
||||||
The :c:macro:`Py_BEGIN_ALLOW_THREADS` macro opens a new block and declares a
|
The :c:macro:`Py_BEGIN_ALLOW_THREADS` macro opens a new block and declares a
|
||||||
hidden local variable; the :c:macro:`Py_END_ALLOW_THREADS` macro closes the
|
hidden local variable; the :c:macro:`Py_END_ALLOW_THREADS` macro closes the
|
||||||
|
@ -714,8 +713,8 @@ The block above expands to the following code::
|
||||||
PyEval_RestoreThread(_save);
|
PyEval_RestoreThread(_save);
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PyEval_RestoreThread()
|
single: PyEval_RestoreThread (C function)
|
||||||
single: PyEval_SaveThread()
|
single: PyEval_SaveThread (C function)
|
||||||
|
|
||||||
Here is how these functions work: the global interpreter lock is used to protect the pointer to the
|
Here is how these functions work: the global interpreter lock is used to protect the pointer to the
|
||||||
current thread state. When releasing the lock and saving the thread state,
|
current thread state. When releasing the lock and saving the thread state,
|
||||||
|
@ -1399,8 +1398,8 @@ function. You can create and destroy them using the following functions:
|
||||||
may be stored internally on the :c:type:`PyInterpreterState`.
|
may be stored internally on the :c:type:`PyInterpreterState`.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: Py_FinalizeEx()
|
single: Py_FinalizeEx (C function)
|
||||||
single: Py_Initialize()
|
single: Py_Initialize (C function)
|
||||||
|
|
||||||
Extension modules are shared between (sub-)interpreters as follows:
|
Extension modules are shared between (sub-)interpreters as follows:
|
||||||
|
|
||||||
|
@ -1428,7 +1427,7 @@ function. You can create and destroy them using the following functions:
|
||||||
As with multi-phase initialization, this means that only C-level static
|
As with multi-phase initialization, this means that only C-level static
|
||||||
and global variables are shared between these modules.
|
and global variables are shared between these modules.
|
||||||
|
|
||||||
.. index:: single: close() (in module os)
|
.. index:: single: close (in module os)
|
||||||
|
|
||||||
|
|
||||||
.. c:function:: PyThreadState* Py_NewInterpreter(void)
|
.. c:function:: PyThreadState* Py_NewInterpreter(void)
|
||||||
|
@ -1451,7 +1450,7 @@ function. You can create and destroy them using the following functions:
|
||||||
|
|
||||||
.. c:function:: void Py_EndInterpreter(PyThreadState *tstate)
|
.. c:function:: void Py_EndInterpreter(PyThreadState *tstate)
|
||||||
|
|
||||||
.. index:: single: Py_FinalizeEx()
|
.. index:: single: Py_FinalizeEx (C function)
|
||||||
|
|
||||||
Destroy the (sub-)interpreter represented by the given thread state.
|
Destroy the (sub-)interpreter represented by the given thread state.
|
||||||
The given thread state must be the current thread state. See the
|
The given thread state must be the current thread state. See the
|
||||||
|
@ -1543,8 +1542,6 @@ pointer and a void pointer argument.
|
||||||
|
|
||||||
.. c:function:: int Py_AddPendingCall(int (*func)(void *), void *arg)
|
.. c:function:: int Py_AddPendingCall(int (*func)(void *), void *arg)
|
||||||
|
|
||||||
.. index:: single: Py_AddPendingCall()
|
|
||||||
|
|
||||||
Schedule a function to be called from the main interpreter thread. On
|
Schedule a function to be called from the main interpreter thread. On
|
||||||
success, ``0`` is returned and *func* is queued for being called in the
|
success, ``0`` is returned and *func* is queued for being called in the
|
||||||
main thread. On failure, ``-1`` is returned without setting any exception.
|
main thread. On failure, ``-1`` is returned without setting any exception.
|
||||||
|
|
|
@ -325,8 +325,8 @@ objects that reference each other here; for now, the solution
|
||||||
is "don't do that.")
|
is "don't do that.")
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: Py_INCREF()
|
single: Py_INCREF (C function)
|
||||||
single: Py_DECREF()
|
single: Py_DECREF (C function)
|
||||||
|
|
||||||
Reference counts are always manipulated explicitly. The normal way is
|
Reference counts are always manipulated explicitly. The normal way is
|
||||||
to use the macro :c:func:`Py_INCREF` to take a new reference to an
|
to use the macro :c:func:`Py_INCREF` to take a new reference to an
|
||||||
|
@ -401,8 +401,8 @@ function, that function assumes that it now owns that reference, and you are not
|
||||||
responsible for it any longer.
|
responsible for it any longer.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PyList_SetItem()
|
single: PyList_SetItem (C function)
|
||||||
single: PyTuple_SetItem()
|
single: PyTuple_SetItem (C function)
|
||||||
|
|
||||||
Few functions steal references; the two notable exceptions are
|
Few functions steal references; the two notable exceptions are
|
||||||
:c:func:`PyList_SetItem` and :c:func:`PyTuple_SetItem`, which steal a reference
|
:c:func:`PyList_SetItem` and :c:func:`PyTuple_SetItem`, which steal a reference
|
||||||
|
@ -491,8 +491,8 @@ using :c:func:`PySequence_GetItem` (which happens to take exactly the same
|
||||||
arguments), you do own a reference to the returned object.
|
arguments), you do own a reference to the returned object.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PyList_GetItem()
|
single: PyList_GetItem (C function)
|
||||||
single: PySequence_GetItem()
|
single: PySequence_GetItem (C function)
|
||||||
|
|
||||||
Here is an example of how you could write a function that computes the sum of
|
Here is an example of how you could write a function that computes the sum of
|
||||||
the items in a list of integers; once using :c:func:`PyList_GetItem`, and once
|
the items in a list of integers; once using :c:func:`PyList_GetItem`, and once
|
||||||
|
@ -587,7 +587,7 @@ caller, then to the caller's caller, and so on, until they reach the top-level
|
||||||
interpreter, where they are reported to the user accompanied by a stack
|
interpreter, where they are reported to the user accompanied by a stack
|
||||||
traceback.
|
traceback.
|
||||||
|
|
||||||
.. index:: single: PyErr_Occurred()
|
.. index:: single: PyErr_Occurred (C function)
|
||||||
|
|
||||||
For C programmers, however, error checking always has to be explicit. All
|
For C programmers, however, error checking always has to be explicit. All
|
||||||
functions in the Python/C API can raise exceptions, unless an explicit claim is
|
functions in the Python/C API can raise exceptions, unless an explicit claim is
|
||||||
|
@ -601,8 +601,8 @@ ambiguous return value, and require explicit testing for errors with
|
||||||
:c:func:`PyErr_Occurred`. These exceptions are always explicitly documented.
|
:c:func:`PyErr_Occurred`. These exceptions are always explicitly documented.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PyErr_SetString()
|
single: PyErr_SetString (C function)
|
||||||
single: PyErr_Clear()
|
single: PyErr_Clear (C function)
|
||||||
|
|
||||||
Exception state is maintained in per-thread storage (this is equivalent to
|
Exception state is maintained in per-thread storage (this is equivalent to
|
||||||
using global storage in an unthreaded application). A thread can be in one of
|
using global storage in an unthreaded application). A thread can be in one of
|
||||||
|
@ -624,7 +624,7 @@ an exception is being passed on between C functions until it reaches the Python
|
||||||
bytecode interpreter's main loop, which takes care of transferring it to
|
bytecode interpreter's main loop, which takes care of transferring it to
|
||||||
``sys.exc_info()`` and friends.
|
``sys.exc_info()`` and friends.
|
||||||
|
|
||||||
.. index:: single: exc_info() (in module sys)
|
.. index:: single: exc_info (in module sys)
|
||||||
|
|
||||||
Note that starting with Python 1.5, the preferred, thread-safe way to access the
|
Note that starting with Python 1.5, the preferred, thread-safe way to access the
|
||||||
exception state from Python code is to call the function :func:`sys.exc_info`,
|
exception state from Python code is to call the function :func:`sys.exc_info`,
|
||||||
|
@ -709,9 +709,9 @@ Here is the corresponding C code, in all its glory::
|
||||||
.. index:: single: incr_item()
|
.. index:: single: incr_item()
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PyErr_ExceptionMatches()
|
single: PyErr_ExceptionMatches (C function)
|
||||||
single: PyErr_Clear()
|
single: PyErr_Clear (C function)
|
||||||
single: Py_XDECREF()
|
single: Py_XDECREF (C function)
|
||||||
|
|
||||||
This example represents an endorsed use of the ``goto`` statement in C!
|
This example represents an endorsed use of the ``goto`` statement in C!
|
||||||
It illustrates the use of :c:func:`PyErr_ExceptionMatches` and
|
It illustrates the use of :c:func:`PyErr_ExceptionMatches` and
|
||||||
|
@ -735,7 +735,7 @@ the finalization, of the Python interpreter. Most functionality of the
|
||||||
interpreter can only be used after the interpreter has been initialized.
|
interpreter can only be used after the interpreter has been initialized.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: Py_Initialize()
|
single: Py_Initialize (C function)
|
||||||
pair: module; builtins
|
pair: module; builtins
|
||||||
pair: module; __main__
|
pair: module; __main__
|
||||||
pair: module; sys
|
pair: module; sys
|
||||||
|
@ -770,10 +770,10 @@ environment variable :envvar:`PYTHONHOME`, or insert additional directories in
|
||||||
front of the standard path by setting :envvar:`PYTHONPATH`.
|
front of the standard path by setting :envvar:`PYTHONPATH`.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: Py_GetPath()
|
single: Py_GetPath (C function)
|
||||||
single: Py_GetPrefix()
|
single: Py_GetPrefix (C function)
|
||||||
single: Py_GetExecPrefix()
|
single: Py_GetExecPrefix (C function)
|
||||||
single: Py_GetProgramFullPath()
|
single: Py_GetProgramFullPath (C function)
|
||||||
|
|
||||||
The embedding application can steer the search by setting
|
The embedding application can steer the search by setting
|
||||||
:c:member:`PyConfig.program_name` *before* calling
|
:c:member:`PyConfig.program_name` *before* calling
|
||||||
|
@ -784,7 +784,7 @@ control has to provide its own implementation of :c:func:`Py_GetPath`,
|
||||||
:c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, and
|
:c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, and
|
||||||
:c:func:`Py_GetProgramFullPath` (all defined in :file:`Modules/getpath.c`).
|
:c:func:`Py_GetProgramFullPath` (all defined in :file:`Modules/getpath.c`).
|
||||||
|
|
||||||
.. index:: single: Py_IsInitialized()
|
.. index:: single: Py_IsInitialized (C function)
|
||||||
|
|
||||||
Sometimes, it is desirable to "uninitialize" Python. For instance, the
|
Sometimes, it is desirable to "uninitialize" Python. For instance, the
|
||||||
application may want to start over (make another call to
|
application may want to start over (make another call to
|
||||||
|
|
|
@ -117,7 +117,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
|
||||||
.. c:function:: long PyLong_AsLong(PyObject *obj)
|
.. c:function:: long PyLong_AsLong(PyObject *obj)
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: LONG_MAX
|
single: LONG_MAX (C macro)
|
||||||
single: OverflowError (built-in exception)
|
single: OverflowError (built-in exception)
|
||||||
|
|
||||||
Return a C :c:expr:`long` representation of *obj*. If *obj* is not an
|
Return a C :c:expr:`long` representation of *obj*. If *obj* is not an
|
||||||
|
@ -210,7 +210,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
|
||||||
.. c:function:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong)
|
.. c:function:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong)
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PY_SSIZE_T_MAX
|
single: PY_SSIZE_T_MAX (C macro)
|
||||||
single: OverflowError (built-in exception)
|
single: OverflowError (built-in exception)
|
||||||
|
|
||||||
Return a C :c:type:`Py_ssize_t` representation of *pylong*. *pylong* must
|
Return a C :c:type:`Py_ssize_t` representation of *pylong*. *pylong* must
|
||||||
|
@ -225,7 +225,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
|
||||||
.. c:function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
|
.. c:function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: ULONG_MAX
|
single: ULONG_MAX (C macro)
|
||||||
single: OverflowError (built-in exception)
|
single: OverflowError (built-in exception)
|
||||||
|
|
||||||
Return a C :c:expr:`unsigned long` representation of *pylong*. *pylong*
|
Return a C :c:expr:`unsigned long` representation of *pylong*. *pylong*
|
||||||
|
@ -241,7 +241,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
|
||||||
.. c:function:: size_t PyLong_AsSize_t(PyObject *pylong)
|
.. c:function:: size_t PyLong_AsSize_t(PyObject *pylong)
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: SIZE_MAX
|
single: SIZE_MAX (C macro)
|
||||||
single: OverflowError (built-in exception)
|
single: OverflowError (built-in exception)
|
||||||
|
|
||||||
Return a C :c:type:`size_t` representation of *pylong*. *pylong* must be
|
Return a C :c:type:`size_t` representation of *pylong*. *pylong* must be
|
||||||
|
|
|
@ -41,10 +41,10 @@ buffers is performed on demand by the Python memory manager through the Python/C
|
||||||
API functions listed in this document.
|
API functions listed in this document.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: malloc()
|
single: malloc (C function)
|
||||||
single: calloc()
|
single: calloc (C function)
|
||||||
single: realloc()
|
single: realloc (C function)
|
||||||
single: free()
|
single: free (C function)
|
||||||
|
|
||||||
To avoid memory corruption, extension writers should never try to operate on
|
To avoid memory corruption, extension writers should never try to operate on
|
||||||
Python objects with the functions exported by the C library: :c:func:`malloc`,
|
Python objects with the functions exported by the C library: :c:func:`malloc`,
|
||||||
|
|
|
@ -561,9 +561,9 @@ The following flags can be used with :c:member:`PyMemberDef.flags`:
|
||||||
:c:member:`PyMemberDef.offset` to the offset from the ``PyObject`` struct.
|
:c:member:`PyMemberDef.offset` to the offset from the ``PyObject`` struct.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: READ_RESTRICTED
|
single: READ_RESTRICTED (C macro)
|
||||||
single: WRITE_RESTRICTED
|
single: WRITE_RESTRICTED (C macro)
|
||||||
single: RESTRICTED
|
single: RESTRICTED (C macro)
|
||||||
|
|
||||||
.. versionchanged:: 3.10
|
.. versionchanged:: 3.10
|
||||||
|
|
||||||
|
@ -574,7 +574,7 @@ The following flags can be used with :c:member:`PyMemberDef.flags`:
|
||||||
:c:macro:`Py_AUDIT_READ`; :c:macro:`!WRITE_RESTRICTED` does nothing.
|
:c:macro:`Py_AUDIT_READ`; :c:macro:`!WRITE_RESTRICTED` does nothing.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: READONLY
|
single: READONLY (C macro)
|
||||||
|
|
||||||
.. versionchanged:: 3.12
|
.. versionchanged:: 3.12
|
||||||
|
|
||||||
|
@ -637,24 +637,24 @@ Macro name C type Python type
|
||||||
Reading a ``NULL`` pointer raises :py:exc:`AttributeError`.
|
Reading a ``NULL`` pointer raises :py:exc:`AttributeError`.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: T_BYTE
|
single: T_BYTE (C macro)
|
||||||
single: T_SHORT
|
single: T_SHORT (C macro)
|
||||||
single: T_INT
|
single: T_INT (C macro)
|
||||||
single: T_LONG
|
single: T_LONG (C macro)
|
||||||
single: T_LONGLONG
|
single: T_LONGLONG (C macro)
|
||||||
single: T_UBYTE
|
single: T_UBYTE (C macro)
|
||||||
single: T_USHORT
|
single: T_USHORT (C macro)
|
||||||
single: T_UINT
|
single: T_UINT (C macro)
|
||||||
single: T_ULONG
|
single: T_ULONG (C macro)
|
||||||
single: T_ULONGULONG
|
single: T_ULONGULONG (C macro)
|
||||||
single: T_PYSSIZET
|
single: T_PYSSIZET (C macro)
|
||||||
single: T_FLOAT
|
single: T_FLOAT (C macro)
|
||||||
single: T_DOUBLE
|
single: T_DOUBLE (C macro)
|
||||||
single: T_BOOL
|
single: T_BOOL (C macro)
|
||||||
single: T_CHAR
|
single: T_CHAR (C macro)
|
||||||
single: T_STRING
|
single: T_STRING (C macro)
|
||||||
single: T_STRING_INPLACE
|
single: T_STRING_INPLACE (C macro)
|
||||||
single: T_OBJECT_EX
|
single: T_OBJECT_EX (C macro)
|
||||||
single: structmember.h
|
single: structmember.h
|
||||||
|
|
||||||
.. versionadded:: 3.12
|
.. versionadded:: 3.12
|
||||||
|
|
|
@ -371,7 +371,7 @@ Process Control
|
||||||
|
|
||||||
.. c:function:: void Py_FatalError(const char *message)
|
.. c:function:: void Py_FatalError(const char *message)
|
||||||
|
|
||||||
.. index:: single: abort()
|
.. index:: single: abort (C function)
|
||||||
|
|
||||||
Print a fatal error message and kill the process. No cleanup is performed.
|
Print a fatal error message and kill the process. No cleanup is performed.
|
||||||
This function should only be invoked when a condition is detected that would
|
This function should only be invoked when a condition is detected that would
|
||||||
|
@ -391,8 +391,8 @@ Process Control
|
||||||
.. c:function:: void Py_Exit(int status)
|
.. c:function:: void Py_Exit(int status)
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: Py_FinalizeEx()
|
single: Py_FinalizeEx (C function)
|
||||||
single: exit()
|
single: exit (C function)
|
||||||
|
|
||||||
Exit the current process. This calls :c:func:`Py_FinalizeEx` and then calls the
|
Exit the current process. This calls :c:func:`Py_FinalizeEx` and then calls the
|
||||||
standard C library function ``exit(status)``. If :c:func:`Py_FinalizeEx`
|
standard C library function ``exit(status)``. If :c:func:`Py_FinalizeEx`
|
||||||
|
@ -405,7 +405,7 @@ Process Control
|
||||||
.. c:function:: int Py_AtExit(void (*func) ())
|
.. c:function:: int Py_AtExit(void (*func) ())
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: Py_FinalizeEx()
|
single: Py_FinalizeEx (C function)
|
||||||
single: cleanup functions
|
single: cleanup functions
|
||||||
|
|
||||||
Register a cleanup function to be called by :c:func:`Py_FinalizeEx`. The cleanup
|
Register a cleanup function to be called by :c:func:`Py_FinalizeEx`. The cleanup
|
||||||
|
|
|
@ -322,7 +322,7 @@ the same library that the Python runtime is using.
|
||||||
|
|
||||||
.. c:var:: int Py_eval_input
|
.. c:var:: int Py_eval_input
|
||||||
|
|
||||||
.. index:: single: Py_CompileString()
|
.. index:: single: Py_CompileString (C function)
|
||||||
|
|
||||||
The start symbol from the Python grammar for isolated expressions; for use with
|
The start symbol from the Python grammar for isolated expressions; for use with
|
||||||
:c:func:`Py_CompileString`.
|
:c:func:`Py_CompileString`.
|
||||||
|
@ -330,7 +330,7 @@ the same library that the Python runtime is using.
|
||||||
|
|
||||||
.. c:var:: int Py_file_input
|
.. c:var:: int Py_file_input
|
||||||
|
|
||||||
.. index:: single: Py_CompileString()
|
.. index:: single: Py_CompileString (C function)
|
||||||
|
|
||||||
The start symbol from the Python grammar for sequences of statements as read
|
The start symbol from the Python grammar for sequences of statements as read
|
||||||
from a file or other source; for use with :c:func:`Py_CompileString`. This is
|
from a file or other source; for use with :c:func:`Py_CompileString`. This is
|
||||||
|
@ -339,7 +339,7 @@ the same library that the Python runtime is using.
|
||||||
|
|
||||||
.. c:var:: int Py_single_input
|
.. c:var:: int Py_single_input
|
||||||
|
|
||||||
.. index:: single: Py_CompileString()
|
.. index:: single: Py_CompileString (C function)
|
||||||
|
|
||||||
The start symbol from the Python grammar for a single statement; for use with
|
The start symbol from the Python grammar for a single statement; for use with
|
||||||
:c:func:`Py_CompileString`. This is the symbol used for the interactive
|
:c:func:`Py_CompileString`. This is the symbol used for the interactive
|
||||||
|
|
|
@ -547,7 +547,7 @@ reference count of an object and are safe in the presence of ``NULL`` pointers
|
||||||
(but note that *temp* will not be ``NULL`` in this context). More info on them
|
(but note that *temp* will not be ``NULL`` in this context). More info on them
|
||||||
in section :ref:`refcounts`.
|
in section :ref:`refcounts`.
|
||||||
|
|
||||||
.. index:: single: PyObject_CallObject()
|
.. index:: single: PyObject_CallObject (C function)
|
||||||
|
|
||||||
Later, when it is time to call the function, you call the C function
|
Later, when it is time to call the function, you call the C function
|
||||||
:c:func:`PyObject_CallObject`. This function has two arguments, both pointers to
|
:c:func:`PyObject_CallObject`. This function has two arguments, both pointers to
|
||||||
|
@ -638,7 +638,7 @@ the above example, we use :c:func:`Py_BuildValue` to construct the dictionary. :
|
||||||
Extracting Parameters in Extension Functions
|
Extracting Parameters in Extension Functions
|
||||||
============================================
|
============================================
|
||||||
|
|
||||||
.. index:: single: PyArg_ParseTuple()
|
.. index:: single: PyArg_ParseTuple (C function)
|
||||||
|
|
||||||
The :c:func:`PyArg_ParseTuple` function is declared as follows::
|
The :c:func:`PyArg_ParseTuple` function is declared as follows::
|
||||||
|
|
||||||
|
@ -730,7 +730,7 @@ Some example calls::
|
||||||
Keyword Parameters for Extension Functions
|
Keyword Parameters for Extension Functions
|
||||||
==========================================
|
==========================================
|
||||||
|
|
||||||
.. index:: single: PyArg_ParseTupleAndKeywords()
|
.. index:: single: PyArg_ParseTupleAndKeywords (C function)
|
||||||
|
|
||||||
The :c:func:`PyArg_ParseTupleAndKeywords` function is declared as follows::
|
The :c:func:`PyArg_ParseTupleAndKeywords` function is declared as follows::
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,8 @@ If your type supports garbage collection, the destructor should call
|
||||||
}
|
}
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: PyErr_Fetch()
|
single: PyErr_Fetch (C function)
|
||||||
single: PyErr_Restore()
|
single: PyErr_Restore (C function)
|
||||||
|
|
||||||
One important requirement of the deallocator function is that it leaves any
|
One important requirement of the deallocator function is that it leaves any
|
||||||
pending exceptions alone. This is important since deallocators are frequently
|
pending exceptions alone. This is important since deallocators are frequently
|
||||||
|
|
|
@ -1597,7 +1597,7 @@ To find out what card the pair consists of, one could use the
|
||||||
Simulating scanf()
|
Simulating scanf()
|
||||||
^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
.. index:: single: scanf()
|
.. index:: single: scanf (C function)
|
||||||
|
|
||||||
Python does not currently have an equivalent to :c:func:`!scanf`. Regular
|
Python does not currently have an equivalent to :c:func:`!scanf`. Regular
|
||||||
expressions are generally more powerful, though also more verbose, than
|
expressions are generally more powerful, though also more verbose, than
|
||||||
|
|
Loading…
Reference in New Issue