Mercurial > cpython-lru_cache-weakref
annotate Doc/api/api.tex @ 8029:95142c8a09c8 legacy-trunk
Typo: (and often severly limited) -- severely
Typo: (but not to the tuple or list into which the item it put!) -- is put
Thanks, AMK!
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Mon, 13 Apr 1998 00:53:42 +0000 |
| parents | 3b91affa333e |
| children | 5aacdd097941 |
| rev | line source |
|---|---|
|
7527
26a8771a4cfd
Convert LaTeX support to create a new class of documents. HTML generation
Fred Drake <fdrake@acm.org>
parents:
7493
diff
changeset
|
1 \documentclass{manual} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
3 \title{Python/C API Reference Manual} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 \input{boilerplate} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 \makeindex % tell \index to actually write the .idx file |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 \begin{document} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 \maketitle |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 \input{copyright} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 \begin{abstract} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 \noindent |
| 7308 | 19 This manual documents the API used by \C{} (or \Cpp{}) programmers who |
| 20 want to write extension modules or embed Python. It is a companion to | |
| 21 \emph{Extending and Embedding the Python Interpreter}, which describes | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 the general principles of extension writing but does not document the |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 API functions in detail. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
25 \strong{Warning:} The current version of this document is incomplete. |
|
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
26 I hope that it is nevertheless useful. I will continue to work on it, |
|
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
27 and release new versions from time to time, independent from Python |
|
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
28 source code releases. |
|
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
29 |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 \end{abstract} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
|
7092
8a55643e667f
Removed \mytableofcontents; just use \tableofcontents.
Fred Drake <fdrake@acm.org>
parents:
7081
diff
changeset
|
32 \tableofcontents |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
34 % XXX Consider moving all this back to ext.tex and giving api.tex |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
35 % XXX a *really* short intro only. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 \chapter{Introduction} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
38 \label{intro} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
| 7081 | 40 The Application Programmer's Interface to Python gives \C{} and \Cpp{} |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
41 programmers access to the Python interpreter at a variety of levels. |
| 7081 | 42 The API is equally usable from \Cpp{}, but for brevity it is generally |
| 43 referred to as the Python/\C{} API. There are two fundamentally | |
| 7308 | 44 different reasons for using the Python/\C{} API. The first reason is |
| 45 to write \emph{extension modules} for specific purposes; these are | |
| 46 \C{} modules that extend the Python interpreter. This is probably the | |
| 47 most common use. The second reason is to use Python as a component in | |
| 48 a larger application; this technique is generally referred to as | |
| 49 \dfn{embedding} Python in an application. | |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
50 |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
51 Writing an extension module is a relatively well-understood process, |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
52 where a ``cookbook'' approach works well. There are several tools |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
53 that automate the process to some extent. While people have embedded |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
54 Python in other applications since its early existence, the process of |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
55 embedding Python is less straightforward that writing an extension. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
56 Python 1.5 introduces a number of new API functions as well as some |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
57 changes to the build process that make embedding much simpler. |
| 7782 | 58 This manual describes the \version\ state of affairs. |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
59 % XXX Eventually, take the historical notes out |
|
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
60 |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
61 Many API functions are useful independent of whether you're embedding |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
62 or extending Python; moreover, most applications that embed Python |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
63 will need to provide a custom extension as well, so it's probably a |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
64 good idea to become familiar with writing an extension before |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
65 attempting to embed Python in a real application. |
|
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
66 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
67 \section{Include Files} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
68 \label{includes} |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
69 |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
70 All function, type and macro definitions needed to use the Python/C |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
71 API are included in your code by the following line: |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
72 |
| 7308 | 73 \begin{verbatim} |
| 74 #include "Python.h" | |
| 75 \end{verbatim} | |
| 76 | |
| 77 This implies inclusion of the following standard headers: | |
| 78 \code{<stdio.h>}, \code{<string.h>}, \code{<errno.h>}, and | |
| 79 \code{<stdlib.h>} (if available). | |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
80 |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
81 All user visible names defined by Python.h (except those defined by |
| 7308 | 82 the included standard headers) have one of the prefixes \samp{Py} or |
| 83 \samp{_Py}. Names beginning with \samp{_Py} are for internal use | |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
84 only. Structure member names do not have a reserved prefix. |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
85 |
| 7308 | 86 \strong{Important:} user code should never define names that begin |
| 87 with \samp{Py} or \samp{_Py}. This confuses the reader, and | |
| 88 jeopardizes the portability of the user code to future Python | |
| 89 versions, which may define additional names beginning with one of | |
| 90 these prefixes. | |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
91 |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
92 \section{Objects, Types and Reference Counts} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
93 \label{objects} |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
94 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
95 Most Python/C API functions have one or more arguments as well as a |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
96 return value of type \code{PyObject *}. This type is a pointer |
| 7308 | 97 to an opaque data type representing an arbitrary Python |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
98 object. Since all Python object types are treated the same way by the |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
99 Python language in most situations (e.g., assignments, scope rules, |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
100 and argument passing), it is only fitting that they should be |
| 7081 | 101 represented by a single \C{} type. All Python objects live on the heap: |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
102 you never declare an automatic or static variable of type |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
103 \code{PyObject}, only pointer variables of type \code{PyObject *} can |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
104 be declared. |
|
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
105 |
| 7308 | 106 All Python objects (even Python integers) have a \dfn{type} and a |
| 107 \dfn{reference count}. An object's type determines what kind of object | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
108 it is (e.g., an integer, a list, or a user-defined function; there are |
| 7308 | 109 many more as explained in the \emph{Python Reference Manual}). For |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
110 each of the well-known types there is a macro to check whether an |
| 7308 | 111 object is of that type; for instance, \samp{PyList_Check(\var{a})} is |
| 112 true iff the object pointed to by \var{a} is a Python list. | |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
113 |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
114 \subsection{Reference Counts} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
115 \label{refcounts} |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
116 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
117 The reference count is important because today's computers have a |
|
8029
95142c8a09c8
Typo: (and often severly limited) -- severely
Fred Drake <fdrake@acm.org>
parents:
8021
diff
changeset
|
118 finite (and often severely limited) memory size; it counts how many |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
119 different places there are that have a reference to an object. Such a |
| 7081 | 120 place could be another object, or a global (or static) \C{} variable, or |
| 121 a local variable in some \C{} function. When an object's reference count | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
122 becomes zero, the object is deallocated. If it contains references to |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
123 other objects, their reference count is decremented. Those other |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
124 objects may be deallocated in turn, if this decrement makes their |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
125 reference count become zero, and so on. (There's an obvious problem |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
126 with objects that reference each other here; for now, the solution is |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
127 ``don't do that''.) |
|
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
128 |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
129 Reference counts are always manipulated explicitly. The normal way is |
| 7308 | 130 to use the macro \cfunction{Py_INCREF()} to increment an object's |
| 131 reference count by one, and \cfunction{Py_DECREF()} to decrement it by | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
132 one. The decref macro is considerably more complex than the incref one, |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
133 since it must check whether the reference count becomes zero and then |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
134 cause the object's deallocator, which is a function pointer contained |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
135 in the object's type structure. The type-specific deallocator takes |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
136 care of decrementing the reference counts for other objects contained |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
137 in the object, and so on, if this is a compound object type such as a |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
138 list. There's no chance that the reference count can overflow; at |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
139 least as many bits are used to hold the reference count as there are |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
140 distinct memory locations in virtual memory (assuming |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
141 \code{sizeof(long) >= sizeof(char *)}). Thus, the reference count |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
142 increment is a simple operation. |
|
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
143 |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
144 It is not necessary to increment an object's reference count for every |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
145 local variable that contains a pointer to an object. In theory, the |
| 7308 | 146 object's reference count goes up by one when the variable is made to |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
147 point to it and it goes down by one when the variable goes out of |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
148 scope. However, these two cancel each other out, so at the end the |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
149 reference count hasn't changed. The only real reason to use the |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
150 reference count is to prevent the object from being deallocated as |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
151 long as our variable is pointing to it. If we know that there is at |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
152 least one other reference to the object that lives at least as long as |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
153 our variable, there is no need to increment the reference count |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
154 temporarily. An important situation where this arises is in objects |
| 7081 | 155 that are passed as arguments to \C{} functions in an extension module |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
156 that are called from Python; the call mechanism guarantees to hold a |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
157 reference to every argument for the duration of the call. |
|
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
158 |
| 7308 | 159 However, a common pitfall is to extract an object from a list and |
| 160 hold on to it for a while without incrementing its reference count. | |
| 161 Some other operation might conceivably remove the object from the | |
| 162 list, decrementing its reference count and possible deallocating it. | |
| 163 The real danger is that innocent-looking operations may invoke | |
| 164 arbitrary Python code which could do this; there is a code path which | |
| 165 allows control to flow back to the user from a \cfunction{Py_DECREF()}, | |
| 166 so almost any operation is potentially dangerous. | |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
167 |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
168 A safe approach is to always use the generic operations (functions |
| 7308 | 169 whose name begins with \samp{PyObject_}, \samp{PyNumber_}, |
| 170 \samp{PySequence_} or \samp{PyMapping_}). These operations always | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
171 increment the reference count of the object they return. This leaves |
| 7308 | 172 the caller with the responsibility to call \cfunction{Py_DECREF()} |
| 173 when they are done with the result; this soon becomes second nature. | |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
174 |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
175 \subsubsection{Reference Count Details} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
176 \label{refcountDetails} |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
177 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
178 The reference count behavior of functions in the Python/C API is best |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
179 expelained in terms of \emph{ownership of references}. Note that we |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
180 talk of owning references, never of owning objects; objects are always |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
181 shared! When a function owns a reference, it has to dispose of it |
| 7308 | 182 properly --- either by passing ownership on (usually to its caller) or |
| 183 by calling \cfunction{Py_DECREF()} or \cfunction{Py_XDECREF()}. When | |
| 184 a function passes ownership of a reference on to its caller, the | |
| 185 caller is said to receive a \emph{new} reference. When no ownership | |
| 186 is transferred, the caller is said to \emph{borrow} the reference. | |
| 187 Nothing needs to be done for a borrowed reference. | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
188 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
189 Conversely, when calling a function passes it a reference to an |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
190 object, there are two possibilities: the function \emph{steals} a |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
191 reference to the object, or it does not. Few functions steal |
| 7308 | 192 references; the two notable exceptions are |
| 193 \cfunction{PyList_SetItem()} and \cfunction{PyTuple_SetItem()}, which | |
| 194 steal a reference to the item (but not to the tuple or list into which | |
|
8029
95142c8a09c8
Typo: (and often severly limited) -- severely
Fred Drake <fdrake@acm.org>
parents:
8021
diff
changeset
|
195 the item is put!). These functions were designed to steal a reference |
| 7308 | 196 because of a common idiom for populating a tuple or list with newly |
| 197 created objects; for example, the code to create the tuple \code{(1, | |
| 198 2, "three")} could look like this (forgetting about error handling for | |
| 199 the moment; a better way to code this is shown below anyway): | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
200 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
201 \begin{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
202 PyObject *t; |
| 7782 | 203 |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
204 t = PyTuple_New(3); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
205 PyTuple_SetItem(t, 0, PyInt_FromLong(1L)); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
206 PyTuple_SetItem(t, 1, PyInt_FromLong(2L)); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
207 PyTuple_SetItem(t, 2, PyString_FromString("three")); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
208 \end{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
209 |
| 7308 | 210 Incidentally, \cfunction{PyTuple_SetItem()} is the \emph{only} way to |
| 211 set tuple items; \cfunction{PySequence_SetItem()} and | |
| 212 \cfunction{PyObject_SetItem()} refuse to do this since tuples are an | |
| 213 immutable data type. You should only use | |
| 214 \cfunction{PyTuple_SetItem()} for tuples that you are creating | |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
215 yourself. |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
216 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
217 Equivalent code for populating a list can be written using |
| 7308 | 218 \cfunction{PyList_New()} and \cfunction{PyList_SetItem()}. Such code |
| 219 can also use \cfunction{PySequence_SetItem()}; this illustrates the | |
| 220 difference between the two (the extra \cfunction{Py_DECREF()} calls): | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
221 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
222 \begin{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
223 PyObject *l, *x; |
| 7782 | 224 |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
225 l = PyList_New(3); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
226 x = PyInt_FromLong(1L); |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
227 PySequence_SetItem(l, 0, x); Py_DECREF(x); |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
228 x = PyInt_FromLong(2L); |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
229 PySequence_SetItem(l, 1, x); Py_DECREF(x); |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
230 x = PyString_FromString("three"); |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
231 PySequence_SetItem(l, 2, x); Py_DECREF(x); |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
232 \end{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
233 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
234 You might find it strange that the ``recommended'' approach takes more |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
235 code. However, in practice, you will rarely use these ways of |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
236 creating and populating a tuple or list. There's a generic function, |
| 7308 | 237 \cfunction{Py_BuildValue()}, that can create most common objects from |
| 238 \C{} values, directed by a \dfn{format string}. For example, the | |
| 239 above two blocks of code could be replaced by the following (which | |
| 240 also takes care of the error checking): | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
241 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
242 \begin{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
243 PyObject *t, *l; |
| 7782 | 244 |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
245 t = Py_BuildValue("(iis)", 1, 2, "three"); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
246 l = Py_BuildValue("[iis]", 1, 2, "three"); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
247 \end{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
248 |
| 7308 | 249 It is much more common to use \cfunction{PyObject_SetItem()} and |
| 250 friends with items whose references you are only borrowing, like | |
| 251 arguments that were passed in to the function you are writing. In | |
| 252 that case, their behaviour regarding reference counts is much saner, | |
| 253 since you don't have to increment a reference count so you can give a | |
| 254 reference away (``have it be stolen''). For example, this function | |
| 255 sets all items of a list (actually, any mutable sequence) to a given | |
| 256 item: | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
257 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
258 \begin{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
259 int set_all(PyObject *target, PyObject *item) |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
260 { |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
261 int i, n; |
| 7782 | 262 |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
263 n = PyObject_Length(target); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
264 if (n < 0) |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
265 return -1; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
266 for (i = 0; i < n; i++) { |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
267 if (PyObject_SetItem(target, i, item) < 0) |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
268 return -1; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
269 } |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
270 return 0; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
271 } |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
272 \end{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
273 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
274 The situation is slightly different for function return values. |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
275 While passing a reference to most functions does not change your |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
276 ownership responsibilities for that reference, many functions that |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
277 return a referece to an object give you ownership of the reference. |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
278 The reason is simple: in many cases, the returned object is created |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
279 on the fly, and the reference you get is the only reference to the |
| 7308 | 280 object. Therefore, the generic functions that return object |
| 281 references, like \cfunction{PyObject_GetItem()} and | |
| 282 \cfunction{PySequence_GetItem()}, always return a new reference (i.e., | |
| 283 the caller becomes the owner of the reference). | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
284 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
285 It is important to realize that whether you own a reference returned |
| 7308 | 286 by a function depends on which function you call only --- \emph{the |
| 287 plumage} (i.e., the type of the type of the object passed as an | |
| 288 argument to the function) \emph{doesn't enter into it!} Thus, if you | |
| 289 extract an item from a list using \cfunction{PyList_GetItem()}, you | |
| 290 don't own the reference --- but if you obtain the same item from the | |
| 291 same list using \cfunction{PySequence_GetItem()} (which happens to | |
| 292 take exactly the same arguments), you do own a reference to the | |
| 293 returned object. | |
| 294 | |
| 295 Here is an example of how you could write a function that computes the | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
296 sum of the items in a list of integers; once using |
| 7308 | 297 \cfunction{PyList_GetItem()}, once using |
| 298 \cfunction{PySequence_GetItem()}. | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
299 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
300 \begin{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
301 long sum_list(PyObject *list) |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
302 { |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
303 int i, n; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
304 long total = 0; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
305 PyObject *item; |
| 7782 | 306 |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
307 n = PyList_Size(list); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
308 if (n < 0) |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
309 return -1; /* Not a list */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
310 for (i = 0; i < n; i++) { |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
311 item = PyList_GetItem(list, i); /* Can't fail */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
312 if (!PyInt_Check(item)) continue; /* Skip non-integers */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
313 total += PyInt_AsLong(item); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
314 } |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
315 return total; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
316 } |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
317 \end{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
318 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
319 \begin{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
320 long sum_sequence(PyObject *sequence) |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
321 { |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
322 int i, n; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
323 long total = 0; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
324 PyObject *item; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
325 n = PyObject_Size(list); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
326 if (n < 0) |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
327 return -1; /* Has no length */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
328 for (i = 0; i < n; i++) { |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
329 item = PySequence_GetItem(list, i); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
330 if (item == NULL) |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
331 return -1; /* Not a sequence, or other failure */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
332 if (PyInt_Check(item)) |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
333 total += PyInt_AsLong(item); |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
334 Py_DECREF(item); /* Discard reference ownership */ |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
335 } |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
336 return total; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
337 } |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
338 \end{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
339 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
340 \subsection{Types} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
341 \label{types} |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
342 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
343 There are few other data types that play a significant role in |
| 7081 | 344 the Python/C API; most are simple \C{} types such as \code{int}, |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
345 \code{long}, \code{double} and \code{char *}. A few structure types |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
346 are used to describe static tables used to list the functions exported |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
347 by a module or the data attributes of a new object type. These will |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
348 be discussed together with the functions that use them. |
|
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
349 |
|
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
350 \section{Exceptions} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
351 \label{exceptions} |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
352 |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
353 The Python programmer only needs to deal with exceptions if specific |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
354 error handling is required; unhandled exceptions are automatically |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
355 propagated to the caller, then to the caller's caller, and so on, till |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
356 they reach the top-level interpreter, where they are reported to the |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
357 user accompanied by a stack traceback. |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
358 |
| 7081 | 359 For \C{} programmers, however, error checking always has to be explicit. |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
360 All functions in the Python/C API can raise exceptions, unless an |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
361 explicit claim is made otherwise in a function's documentation. In |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
362 general, when a function encounters an error, it sets an exception, |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
363 discards any object references that it owns, and returns an |
| 7308 | 364 error indicator --- usually \NULL{} or \code{-1}. A few functions |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
365 return a Boolean true/false result, with false indicating an error. |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
366 Very few functions return no explicit error indicator or have an |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
367 ambiguous return value, and require explicit testing for errors with |
| 7308 | 368 \cfunction{PyErr_Occurred()}. |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
369 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
370 Exception state is maintained in per-thread storage (this is |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
371 equivalent to using global storage in an unthreaded application). A |
| 7782 | 372 thread can be in one of two states: an exception has occurred, or not. |
| 7308 | 373 The function \cfunction{PyErr_Occurred()} can be used to check for |
| 374 this: it returns a borrowed reference to the exception type object | |
| 375 when an exception has occurred, and \NULL{} otherwise. There are a | |
| 376 number of functions to set the exception state: | |
| 377 \cfunction{PyErr_SetString()} is the most common (though not the most | |
| 378 general) function to set the exception state, and | |
| 379 \cfunction{PyErr_Clear()} clears the exception state. | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
380 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
381 The full exception state consists of three objects (all of which can |
| 7308 | 382 be \NULL{}): the exception type, the corresponding exception |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
383 value, and the traceback. These have the same meanings as the Python |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
384 object \code{sys.exc_type}, \code{sys.exc_value}, |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
385 \code{sys.exc_traceback}; however, they are not the same: the Python |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
386 objects represent the last exception being handled by a Python |
| 7308 | 387 \keyword{try} \ldots\ \keyword{except} statement, while the \C{} level |
| 388 exception state only exists while an exception is being passed on | |
| 389 between \C{} functions until it reaches the Python interpreter, which | |
| 390 takes care of transferring it to \code{sys.exc_type} and friends. | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
391 |
| 7782 | 392 Note that starting with Python 1.5, the preferred, thread-safe way to |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
393 access the exception state from Python code is to call the function |
| 7308 | 394 \function{sys.exc_info()}, which returns the per-thread exception state |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
395 for Python code. Also, the semantics of both ways to access the |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
396 exception state have changed so that a function which catches an |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
397 exception will save and restore its thread's exception state so as to |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
398 preserve the exception state of its caller. This prevents common bugs |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
399 in exception handling code caused by an innocent-looking function |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
400 overwriting the exception being handled; it also reduces the often |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
401 unwanted lifetime extension for objects that are referenced by the |
| 7782 | 402 stack frames in the traceback. |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
403 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
404 As a general principle, a function that calls another function to |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
405 perform some task should check whether the called function raised an |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
406 exception, and if so, pass the exception state on to its caller. It |
| 7308 | 407 should discard any object references that it owns, and returns an |
| 408 error indicator, but it should \emph{not} set another exception --- | |
| 409 that would overwrite the exception that was just raised, and lose | |
| 410 important information about the exact cause of the error. | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
411 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
412 A simple example of detecting exceptions and passing them on is shown |
| 7308 | 413 in the \cfunction{sum_sequence()} example above. It so happens that |
| 414 that example doesn't need to clean up any owned references when it | |
| 415 detects an error. The following example function shows some error | |
| 416 cleanup. First, to remind you why you like Python, we show the | |
| 417 equivalent Python code: | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
418 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
419 \begin{verbatim} |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
420 def incr_item(dict, key): |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
421 try: |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
422 item = dict[key] |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
423 except KeyError: |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
424 item = 0 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
425 return item + 1 |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
426 \end{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
427 |
| 7081 | 428 Here is the corresponding \C{} code, in all its glory: |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
429 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
430 \begin{verbatim} |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
431 int incr_item(PyObject *dict, PyObject *key) |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
432 { |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
433 /* Objects all initialized to NULL for Py_XDECREF */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
434 PyObject *item = NULL, *const_one = NULL, *incremented_item = NULL; |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
435 int rv = -1; /* Return value initialized to -1 (failure) */ |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
436 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
437 item = PyObject_GetItem(dict, key); |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
438 if (item == NULL) { |
| 7782 | 439 /* Handle KeyError only: */ |
| 440 if (!PyErr_ExceptionMatches(PyExc_KeyError)) goto error; | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
441 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
442 /* Clear the error and use zero: */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
443 PyErr_Clear(); |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
444 item = PyInt_FromLong(0L); |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
445 if (item == NULL) goto error; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
446 } |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
447 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
448 const_one = PyInt_FromLong(1L); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
449 if (const_one == NULL) goto error; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
450 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
451 incremented_item = PyNumber_Add(item, const_one); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
452 if (incremented_item == NULL) goto error; |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
453 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
454 if (PyObject_SetItem(dict, key, incremented_item) < 0) goto error; |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
455 rv = 0; /* Success */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
456 /* Continue with cleanup code */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
457 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
458 error: |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
459 /* Cleanup code, shared by success and failure path */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
460 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
461 /* Use Py_XDECREF() to ignore NULL references */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
462 Py_XDECREF(item); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
463 Py_XDECREF(const_one); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
464 Py_XDECREF(incremented_item); |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
465 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
466 return rv; /* -1 for error, 0 for success */ |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
467 } |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
468 \end{verbatim} |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
469 |
|
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
470 This example represents an endorsed use of the \code{goto} statement |
| 7308 | 471 in \C{}! It illustrates the use of |
| 472 \cfunction{PyErr_ExceptionMatches()} and \cfunction{PyErr_Clear()} to | |
| 473 handle specific exceptions, and the use of \cfunction{Py_XDECREF()} to | |
| 474 dispose of owned references that may be \NULL{} (note the \samp{X} in | |
| 475 the name; \cfunction{Py_DECREF()} would crash when confronted with a | |
| 476 \NULL{} reference). It is important that the variables used to hold | |
| 477 owned references are initialized to \NULL{} for this to work; | |
| 478 likewise, the proposed return value is initialized to \code{-1} | |
| 479 (failure) and only set to success after the final call made is | |
| 480 successful. | |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
481 |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
482 |
|
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
483 \section{Embedding Python} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
484 \label{embedding} |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
485 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
486 The one important task that only embedders (as opposed to extension |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
487 writers) of the Python interpreter have to worry about is the |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
488 initialization, and possibly the finalization, of the Python |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
489 interpreter. Most functionality of the interpreter can only be used |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
490 after the interpreter has been initialized. |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
491 |
| 7308 | 492 The basic initialization function is \cfunction{Py_Initialize()}. |
| 493 This initializes the table of loaded modules, and creates the | |
|
7310
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
494 fundamental modules \module{__builtin__}\refbimodindex{__builtin__}, |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
495 \module{__main__}\refbimodindex{__main__} and |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
496 \module{sys}\refbimodindex{sys}. It also initializes the module |
| 7782 | 497 search path (\code{sys.path}).% |
| 498 \indexiii{module}{search}{path} | |
| 7308 | 499 |
| 500 \cfunction{Py_Initialize()} does not set the ``script argument list'' | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
501 (\code{sys.argv}). If this variable is needed by Python code that |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
502 will be executed later, it must be set explicitly with a call to |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
503 \code{PySys_SetArgv(\var{argc}, \var{argv})} subsequent to the call |
| 7308 | 504 to \cfunction{Py_Initialize()}. |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
505 |
| 7081 | 506 On most systems (in particular, on \UNIX{} and Windows, although the |
| 7308 | 507 details are slightly different), \cfunction{Py_Initialize()} |
| 508 calculates the module search path based upon its best guess for the | |
| 509 location of the standard Python interpreter executable, assuming that | |
| 510 the Python library is found in a fixed location relative to the Python | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
511 interpreter executable. In particular, it looks for a directory named |
|
7923
23cc6ac5eba6
Don't assume that \version expands to the 3-character major.minor number; it
Fred Drake <fdrake@acm.org>
parents:
7807
diff
changeset
|
512 \file{lib/python1.5} (replacing \file{1.5} with the current |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
513 interpreter version) relative to the parent directory where the |
| 7308 | 514 executable named \file{python} is found on the shell command search |
| 7782 | 515 path (the environment variable \envvar{PATH}). |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
516 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
517 For instance, if the Python executable is found in |
| 7308 | 518 \file{/usr/local/bin/python}, it will assume that the libraries are in |
|
7923
23cc6ac5eba6
Don't assume that \version expands to the 3-character major.minor number; it
Fred Drake <fdrake@acm.org>
parents:
7807
diff
changeset
|
519 \file{/usr/local/lib/python1.5}. (In fact, this particular path |
| 7308 | 520 is also the ``fallback'' location, used when no executable file named |
| 7782 | 521 \file{python} is found along \envvar{PATH}.) The user can override |
| 522 this behavior by setting the environment variable \envvar{PYTHONHOME}, | |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
523 or insert additional directories in front of the standard path by |
| 7782 | 524 setting \envvar{PYTHONPATH}. |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
525 |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
526 The embedding application can steer the search by calling |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
527 \code{Py_SetProgramName(\var{file})} \emph{before} calling |
| 7782 | 528 \cfunction{Py_Initialize()}. Note that \envvar{PYTHONHOME} still |
| 529 overrides this and \envvar{PYTHONPATH} is still inserted in front of | |
| 7308 | 530 the standard path. An application that requires total control has to |
| 531 provide its own implementation of \cfunction{Py_GetPath()}, | |
| 532 \cfunction{Py_GetPrefix()}, \cfunction{Py_GetExecPrefix()}, | |
| 533 \cfunction{Py_GetProgramFullPath()} (all defined in | |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
534 \file{Modules/getpath.c}). |
|
6040
1a43699108a6
Added new intro sections (incomplete); fixed various typos
Guido van Rossum <guido@python.org>
parents:
5588
diff
changeset
|
535 |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
536 Sometimes, it is desirable to ``uninitialize'' Python. For instance, |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
537 the application may want to start over (make another call to |
| 7308 | 538 \cfunction{Py_Initialize()}) or the application is simply done with its |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
539 use of Python and wants to free all memory allocated by Python. This |
| 7308 | 540 can be accomplished by calling \cfunction{Py_Finalize()}. The function |
| 541 \cfunction{Py_IsInitialized()} returns true iff Python is currently in the | |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
542 initialized state. More information about these functions is given in |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
543 a later chapter. |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
544 |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
545 |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
546 \chapter{The Very High Level Layer} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
547 \label{veryhigh} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
548 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
549 The functions in this chapter will let you execute Python source code |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
550 given in a file or a buffer, but they will not let you interact in a |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
551 more detailed way with the interpreter. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
552 |
| 7782 | 553 \begin{cfuncdesc}{int}{PyRun_AnyFile}{FILE *fp, char *filename} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
554 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
555 |
| 7782 | 556 \begin{cfuncdesc}{int}{PyRun_SimpleString}{char *command} |
| 557 \end{cfuncdesc} | |
| 558 | |
| 559 \begin{cfuncdesc}{int}{PyRun_SimpleFile}{FILE *fp, char *filename} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
560 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
561 |
| 7782 | 562 \begin{cfuncdesc}{int}{PyRun_InteractiveOne}{FILE *fp, char *filename} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
563 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
564 |
| 7782 | 565 \begin{cfuncdesc}{int}{PyRun_InteractiveLoop}{FILE *fp, char *filename} |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
566 \end{cfuncdesc} |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
567 |
| 7782 | 568 \begin{cfuncdesc}{struct _node*}{PyParser_SimpleParseString}{char *str, |
| 569 int start} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
570 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
571 |
| 7782 | 572 \begin{cfuncdesc}{struct _node*}{PyParser_SimpleParseFile}{FILE *fp, |
| 573 char *filename, int start} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
574 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
575 |
| 7782 | 576 \begin{cfuncdesc}{PyObject*}{PyRun_String}{char *str, int start, |
| 577 PyObject *globals, | |
| 578 PyObject *locals} | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
579 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
580 |
| 7782 | 581 \begin{cfuncdesc}{PyObject*}{PyRun_File}{FILE *fp, char *filename, |
| 582 int start, PyObject *globals, | |
| 583 PyObject *locals} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
584 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
585 |
| 7782 | 586 \begin{cfuncdesc}{PyObject*}{Py_CompileString}{char *str, char *filename, |
| 587 int start} | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
588 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
589 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
590 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
591 \chapter{Reference Counting} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
592 \label{countingRefs} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
593 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
594 The macros in this section are used for managing reference counts |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
595 of Python objects. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
596 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
597 \begin{cfuncdesc}{void}{Py_INCREF}{PyObject *o} |
| 7782 | 598 Increment the reference count for object \var{o}. The object must |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
599 not be \NULL{}; if you aren't sure that it isn't \NULL{}, use |
| 7308 | 600 \cfunction{Py_XINCREF()}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
601 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
602 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
603 \begin{cfuncdesc}{void}{Py_XINCREF}{PyObject *o} |
| 7308 | 604 Increment the reference count for object \var{o}. The object may be |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
605 \NULL{}, in which case the macro has no effect. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
606 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
607 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
608 \begin{cfuncdesc}{void}{Py_DECREF}{PyObject *o} |
| 7308 | 609 Decrement the reference count for object \var{o}. The object must |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
610 not be \NULL{}; if you aren't sure that it isn't \NULL{}, use |
| 7308 | 611 \cfunction{Py_XDECREF()}. If the reference count reaches zero, the |
| 612 object's type's deallocation function (which must not be \NULL{}) is | |
| 613 invoked. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
615 \strong{Warning:} The deallocation function can cause arbitrary Python |
| 7308 | 616 code to be invoked (e.g. when a class instance with a \method{__del__()} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 method is deallocated). While exceptions in such code are not |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 propagated, the executed code has free access to all Python global |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 variables. This means that any object that is reachable from a global |
| 7308 | 620 variable should be in a consistent state before \cfunction{Py_DECREF()} is |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
621 invoked. For example, code to delete an object from a list should |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 copy a reference to the deleted object in a temporary variable, update |
| 7308 | 623 the list data structure, and then call \cfunction{Py_DECREF()} for the |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
624 temporary variable. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
625 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
626 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
627 \begin{cfuncdesc}{void}{Py_XDECREF}{PyObject *o} |
| 7308 | 628 Decrement the reference count for object \var{o}. The object may be |
| 629 \NULL{}, in which case the macro has no effect; otherwise the effect | |
| 630 is the same as for \cfunction{Py_DECREF()}, and the same warning | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
631 applies. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
632 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
633 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
634 The following functions or macros are only for internal use: |
| 7308 | 635 \cfunction{_Py_Dealloc()}, \cfunction{_Py_ForgetReference()}, |
| 636 \cfunction{_Py_NewReference()}, as well as the global variable | |
| 637 \code{_Py_RefTotal}. | |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
638 |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
639 XXX Should mention Py_Malloc(), Py_Realloc(), Py_Free(), |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
640 PyMem_Malloc(), PyMem_Realloc(), PyMem_Free(), PyMem_NEW(), |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
641 PyMem_RESIZE(), PyMem_DEL(), PyMem_XDEL(). |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
642 |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
643 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
644 \chapter{Exception Handling} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
645 \label{exceptionHandling} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
646 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
647 The functions in this chapter will let you handle and raise Python |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
648 exceptions. It is important to understand some of the basics of |
| 7081 | 649 Python exception handling. It works somewhat like the \UNIX{} |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
650 \code{errno} variable: there is a global indicator (per thread) of the |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
651 last error that occurred. Most functions don't clear this on success, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
652 but will set it to indicate the cause of the error on failure. Most |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
653 functions also return an error indicator, usually \NULL{} if they are |
| 7308 | 654 supposed to return a pointer, or \code{-1} if they return an integer |
| 655 (exception: the \code{PyArg_Parse*()} functions return \code{1} for | |
| 656 success and \code{0} for failure). When a function must fail because | |
| 657 some function it called failed, it generally doesn't set the error | |
| 658 indicator; the function it called already set it. | |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
659 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
660 The error indicator consists of three Python objects corresponding to |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
661 the Python variables \code{sys.exc_type}, \code{sys.exc_value} and |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
662 \code{sys.exc_traceback}. API functions exist to interact with the |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
663 error indicator in various ways. There is a separate error indicator |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
664 for each thread. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
665 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
666 % XXX Order of these should be more thoughtful. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
667 % Either alphabetical or some kind of structure. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
668 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
669 \begin{cfuncdesc}{void}{PyErr_Print}{} |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
670 Print a standard traceback to \code{sys.stderr} and clear the error |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
671 indicator. Call this function only when the error indicator is set. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
672 (Otherwise it will cause a fatal error!) |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
673 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
674 |
| 7782 | 675 \begin{cfuncdesc}{PyObject*}{PyErr_Occurred}{} |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
676 Test whether the error indicator is set. If set, return the exception |
| 7308 | 677 \emph{type} (the first argument to the last call to one of the |
| 678 \code{PyErr_Set*()} functions or to \cfunction{PyErr_Restore()}). If | |
| 679 not set, return \NULL{}. You do not own a reference to the return | |
| 680 value, so you do not need to \cfunction{Py_DECREF()} it. | |
| 681 \strong{Note:} do not compare the return value to a specific | |
| 682 exception; use \cfunction{PyErr_ExceptionMatches()} instead, shown | |
| 683 below. | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
684 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
685 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
686 \begin{cfuncdesc}{int}{PyErr_ExceptionMatches}{PyObject *exc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
687 Equivalent to |
| 7308 | 688 \samp{PyErr_GivenExceptionMatches(PyErr_Occurred(), \var{exc})}. |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
689 This should only be called when an exception is actually set. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
690 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
691 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
692 \begin{cfuncdesc}{int}{PyErr_GivenExceptionMatches}{PyObject *given, PyObject *exc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
693 Return true if the \var{given} exception matches the exception in |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
694 \var{exc}. If \var{exc} is a class object, this also returns true |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
695 when \var{given} is a subclass. If \var{exc} is a tuple, all |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
696 exceptions in the tuple (and recursively in subtuples) are searched |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
697 for a match. This should only be called when an exception is actually |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
698 set. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
699 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
700 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
701 \begin{cfuncdesc}{void}{PyErr_NormalizeException}{PyObject**exc, PyObject**val, PyObject**tb} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
702 Under certain circumstances, the values returned by |
| 7308 | 703 \cfunction{PyErr_Fetch()} below can be ``unnormalized'', meaning that |
| 704 \code{*\var{exc}} is a class object but \code{*\var{val}} is not an | |
| 705 instance of the same class. This function can be used to instantiate | |
| 706 the class in that case. If the values are already normalized, nothing | |
| 707 happens. | |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
708 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
709 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
710 \begin{cfuncdesc}{void}{PyErr_Clear}{} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
711 Clear the error indicator. If the error indicator is not set, there |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
712 is no effect. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
713 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
714 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
715 \begin{cfuncdesc}{void}{PyErr_Fetch}{PyObject **ptype, PyObject **pvalue, PyObject **ptraceback} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
716 Retrieve the error indicator into three variables whose addresses are |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
717 passed. If the error indicator is not set, set all three variables to |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
718 \NULL{}. If it is set, it will be cleared and you own a reference to |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
719 each object retrieved. The value and traceback object may be \NULL{} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
720 even when the type object is not. \strong{Note:} this function is |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
721 normally only used by code that needs to handle exceptions or by code |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
722 that needs to save and restore the error indicator temporarily. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
723 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
724 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
725 \begin{cfuncdesc}{void}{PyErr_Restore}{PyObject *type, PyObject *value, PyObject *traceback} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
726 Set the error indicator from the three objects. If the error |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
727 indicator is already set, it is cleared first. If the objects are |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
728 \NULL{}, the error indicator is cleared. Do not pass a \NULL{} type |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
729 and non-\NULL{} value or traceback. The exception type should be a |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
730 string or class; if it is a class, the value should be an instance of |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
731 that class. Do not pass an invalid exception type or value. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
732 (Violating these rules will cause subtle problems later.) This call |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
733 takes away a reference to each object, i.e. you must own a reference |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
734 to each object before the call and after the call you no longer own |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
735 these references. (If you don't understand this, don't use this |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
736 function. I warned you.) \strong{Note:} this function is normally |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
737 only used by code that needs to save and restore the error indicator |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
738 temporarily. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
739 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
740 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
741 \begin{cfuncdesc}{void}{PyErr_SetString}{PyObject *type, char *message} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
742 This is the most common way to set the error indicator. The first |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
743 argument specifies the exception type; it is normally one of the |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
744 standard exceptions, e.g. \code{PyExc_RuntimeError}. You need not |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
745 increment its reference count. The second argument is an error |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
746 message; it is converted to a string object. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
747 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
748 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
749 \begin{cfuncdesc}{void}{PyErr_SetObject}{PyObject *type, PyObject *value} |
| 7308 | 750 This function is similar to \cfunction{PyErr_SetString()} but lets you |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
751 specify an arbitrary Python object for the ``value'' of the exception. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
752 You need not increment its reference count. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
753 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
754 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
755 \begin{cfuncdesc}{void}{PyErr_SetNone}{PyObject *type} |
| 7308 | 756 This is a shorthand for \samp{PyErr_SetObject(\var{type}, Py_None)}. |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
757 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
758 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
759 \begin{cfuncdesc}{int}{PyErr_BadArgument}{} |
| 7308 | 760 This is a shorthand for \samp{PyErr_SetString(PyExc_TypeError, |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
761 \var{message})}, where \var{message} indicates that a built-in operation |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
762 was invoked with an illegal argument. It is mostly for internal use. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
763 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
764 |
| 7782 | 765 \begin{cfuncdesc}{PyObject*}{PyErr_NoMemory}{} |
| 7308 | 766 This is a shorthand for \samp{PyErr_SetNone(PyExc_MemoryError)}; it |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
767 returns \NULL{} so an object allocation function can write |
| 7308 | 768 \samp{return PyErr_NoMemory();} when it runs out of memory. |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
769 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
770 |
| 7782 | 771 \begin{cfuncdesc}{PyObject*}{PyErr_SetFromErrno}{PyObject *type} |
| 7081 | 772 This is a convenience function to raise an exception when a \C{} library |
| 773 function has returned an error and set the \C{} variable \code{errno}. | |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
774 It constructs a tuple object whose first item is the integer |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
775 \code{errno} value and whose second item is the corresponding error |
| 7308 | 776 message (gotten from \cfunction{strerror()}), and then calls |
| 777 \samp{PyErr_SetObject(\var{type}, \var{object})}. On \UNIX{}, when | |
| 778 the \code{errno} value is \constant{EINTR}, indicating an interrupted | |
| 779 system call, this calls \cfunction{PyErr_CheckSignals()}, and if that set | |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
780 the error indicator, leaves it set to that. The function always |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
781 returns \NULL{}, so a wrapper function around a system call can write |
| 7308 | 782 \samp{return PyErr_SetFromErrno();} when the system call returns an |
| 783 error. | |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
784 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
785 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
786 \begin{cfuncdesc}{void}{PyErr_BadInternalCall}{} |
| 7308 | 787 This is a shorthand for \samp{PyErr_SetString(PyExc_TypeError, |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
788 \var{message})}, where \var{message} indicates that an internal |
|
6084
0aa62cbed9f8
Consistently change Python-C API to Python/C API; added lots of new
Guido van Rossum <guido@python.org>
parents:
6074
diff
changeset
|
789 operation (e.g. a Python/C API function) was invoked with an illegal |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
790 argument. It is mostly for internal use. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
791 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
792 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
793 \begin{cfuncdesc}{int}{PyErr_CheckSignals}{} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
794 This function interacts with Python's signal handling. It checks |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
795 whether a signal has been sent to the processes and if so, invokes the |
|
7310
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
796 corresponding signal handler. If the |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
797 \module{signal}\refbimodindex{signal} module is supported, this can |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
798 invoke a signal handler written in Python. In all cases, the default |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
799 effect for \constant{SIGINT} is to raise the |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
800 \exception{KeyboadInterrupt} exception. If an exception is raised the |
| 7308 | 801 error indicator is set and the function returns \code{1}; otherwise |
| 802 the function returns \code{0}. The error indicator may or may not be | |
| 803 cleared if it was previously set. | |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
804 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
805 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
806 \begin{cfuncdesc}{void}{PyErr_SetInterrupt}{} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
807 This function is obsolete (XXX or platform dependent?). It simulates |
| 7308 | 808 the effect of a \constant{SIGINT} signal arriving --- the next time |
| 809 \cfunction{PyErr_CheckSignals()} is called, | |
| 810 \exception{KeyboadInterrupt} will be raised. | |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
811 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
812 |
| 7782 | 813 \begin{cfuncdesc}{PyObject*}{PyErr_NewException}{char *name, |
| 814 PyObject *base, | |
| 815 PyObject *dict} | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
816 This utility function creates and returns a new exception object. The |
| 7081 | 817 \var{name} argument must be the name of the new exception, a \C{} string |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
818 of the form \code{module.class}. The \var{base} and \var{dict} |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
819 arguments are normally \NULL{}. Normally, this creates a class |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
820 object derived from the root for all exceptions, the built-in name |
| 7308 | 821 \exception{Exception} (accessible in \C{} as \code{PyExc_Exception}). |
| 822 In this case the \code{__module__} attribute of the new class is set to the | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
823 first part (up to the last dot) of the \var{name} argument, and the |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
824 class name is set to the last part (after the last dot). When the |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
825 user has specified the \code{-X} command line option to use string |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
826 exceptions, for backward compatibility, or when the \var{base} |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
827 argument is not a class object (and not \NULL{}), a string object |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
828 created from the entire \var{name} argument is returned. The |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
829 \var{base} argument can be used to specify an alternate base class. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
830 The \var{dict} argument can be used to specify a dictionary of class |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
831 variables and methods. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
832 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
833 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
834 |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
835 \section{Standard Exceptions} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
836 \label{standardExceptions} |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
837 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
838 All standard Python exceptions are available as global variables whose |
| 7308 | 839 names are \samp{PyExc_} followed by the Python exception name. |
| 840 These have the type \code{PyObject *}; they are all either class | |
| 841 objects or string objects, depending on the use of the \code{-X} | |
| 842 option to the interpreter. For completeness, here are all the | |
|
7314
d23bb969e63a
Removed various "(New in 1.5a?!)" constructs. Other notes pertaining to
Fred Drake <fdrake@acm.org>
parents:
7310
diff
changeset
|
843 variables: |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
844 \code{PyExc_Exception}, |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
845 \code{PyExc_StandardError}, |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
846 \code{PyExc_ArithmeticError}, |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
847 \code{PyExc_LookupError}, |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
848 \code{PyExc_AssertionError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
849 \code{PyExc_AttributeError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
850 \code{PyExc_EOFError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
851 \code{PyExc_FloatingPointError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
852 \code{PyExc_IOError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
853 \code{PyExc_ImportError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
854 \code{PyExc_IndexError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
855 \code{PyExc_KeyError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
856 \code{PyExc_KeyboardInterrupt}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
857 \code{PyExc_MemoryError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
858 \code{PyExc_NameError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
859 \code{PyExc_OverflowError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
860 \code{PyExc_RuntimeError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
861 \code{PyExc_SyntaxError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
862 \code{PyExc_SystemError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
863 \code{PyExc_SystemExit}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
864 \code{PyExc_TypeError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
865 \code{PyExc_ValueError}, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
866 \code{PyExc_ZeroDivisionError}. |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
867 |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
868 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
869 \chapter{Utilities} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
870 \label{utilities} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
871 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
872 The functions in this chapter perform various utility tasks, such as |
| 7081 | 873 parsing function arguments and constructing Python values from \C{} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
874 values. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
875 |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
876 \section{OS Utilities} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
877 \label{os} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
878 |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
879 \begin{cfuncdesc}{int}{Py_FdIsInteractive}{FILE *fp, char *filename} |
| 7308 | 880 Return true (nonzero) if the standard I/O file \var{fp} with name |
| 881 \var{filename} is deemed interactive. This is the case for files for | |
| 882 which \samp{isatty(fileno(\var{fp}))} is true. If the global flag | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
883 \code{Py_InteractiveFlag} is true, this function also returns true if |
| 7308 | 884 the \var{name} pointer is \NULL{} or if the name is equal to one of |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
885 the strings \code{"<stdin>"} or \code{"???"}. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
886 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
887 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
888 \begin{cfuncdesc}{long}{PyOS_GetLastModificationTime}{char *filename} |
| 7308 | 889 Return the time of last modification of the file \var{filename}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
890 The result is encoded in the same way as the timestamp returned by |
| 7308 | 891 the standard \C{} library function \cfunction{time()}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
892 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
893 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
894 |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
895 \section{Process Control} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
896 \label{processControl} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
897 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
898 \begin{cfuncdesc}{void}{Py_FatalError}{char *message} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
899 Print a fatal error message and kill the process. No cleanup is |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
900 performed. This function should only be invoked when a condition is |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
901 detected that would make it dangerous to continue using the Python |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
902 interpreter; e.g., when the object administration appears to be |
| 7308 | 903 corrupted. On \UNIX{}, the standard \C{} library function |
| 904 \cfunction{abort()} is called which will attempt to produce a | |
| 905 \file{core} file. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
906 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
907 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
908 \begin{cfuncdesc}{void}{Py_Exit}{int status} |
| 7308 | 909 Exit the current process. This calls \cfunction{Py_Finalize()} and |
| 910 then calls the standard \C{} library function | |
| 911 \code{exit(\var{status})}. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
912 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
913 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
914 \begin{cfuncdesc}{int}{Py_AtExit}{void (*func) ()} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
915 Register a cleanup function to be called by \cfunction{Py_Finalize()}. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
916 The cleanup function will be called with no arguments and should |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
917 return no value. At most 32 cleanup functions can be registered. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
918 When the registration is successful, \cfunction{Py_AtExit()} returns |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
919 \code{0}; on failure, it returns \code{-1}. The cleanup function |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
920 registered last is called first. Each cleanup function will be called |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
921 at most once. Since Python's internal finallization will have |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
922 completed before the cleanup function, no Python APIs should be called |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
923 by \var{func}. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
924 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
925 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
926 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
927 \section{Importing Modules} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
928 \label{importing} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
929 |
| 7782 | 930 \begin{cfuncdesc}{PyObject*}{PyImport_ImportModule}{char *name} |
| 7308 | 931 This is a simplified interface to \cfunction{PyImport_ImportModuleEx()} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
932 below, leaving the \var{globals} and \var{locals} arguments set to |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
933 \NULL{}. When the \var{name} argument contains a dot (i.e., when |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
934 it specifies a submodule of a package), the \var{fromlist} argument is |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
935 set to the list \code{['*']} so that the return value is the named |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
936 module rather than the top-level package containing it as would |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
937 otherwise be the case. (Unfortunately, this has an additional side |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
938 effect when \var{name} in fact specifies a subpackage instead of a |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
939 submodule: the submodules specified in the package's \code{__all__} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
940 variable are loaded.) Return a new reference to the imported module, |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
941 or \NULL{} with an exception set on failure (the module may still |
| 7782 | 942 be created in this case --- examine \code{sys.modules} to find out). |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
943 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
944 |
| 7782 | 945 \begin{cfuncdesc}{PyObject*}{PyImport_ImportModuleEx}{char *name, PyObject *globals, PyObject *locals, PyObject *fromlist} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
946 Import a module. This is best described by referring to the built-in |
|
7309
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
947 Python function \function{__import__()}\bifuncindex{__import__}, as |
|
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
948 the standard \function{__import__()} function calls this function |
|
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
949 directly. |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
950 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
951 The return value is a new reference to the imported module or |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
952 top-level package, or \NULL{} with an exception set on failure |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
953 (the module may still be created in this case). Like for |
| 7308 | 954 \function{__import__()}, the return value when a submodule of a |
| 955 package was requested is normally the top-level package, unless a | |
| 956 non-empty \var{fromlist} was given. | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
957 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
958 |
| 7782 | 959 \begin{cfuncdesc}{PyObject*}{PyImport_Import}{PyObject *name} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
960 This is a higher-level interface that calls the current ``import hook |
| 7308 | 961 function''. It invokes the \function{__import__()} function from the |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
962 \code{__builtins__} of the current globals. This means that the |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
963 import is done using whatever import hooks are installed in the |
|
7310
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
964 current environment, e.g. by \module{rexec}\refstmodindex{rexec} or |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
965 \module{ihooks}\refstmodindex{ihooks}. |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
966 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
967 |
| 7782 | 968 \begin{cfuncdesc}{PyObject*}{PyImport_ReloadModule}{PyObject *m} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
969 Reload a module. This is best described by referring to the built-in |
|
7309
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
970 Python function \function{reload()}\bifuncindex{reload}, as the standard |
| 7308 | 971 \function{reload()} function calls this function directly. Return a |
| 972 new reference to the reloaded module, or \NULL{} with an exception set | |
| 973 on failure (the module still exists in this case). | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
974 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
975 |
| 7782 | 976 \begin{cfuncdesc}{PyObject*}{PyImport_AddModule}{char *name} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
977 Return the module object corresponding to a module name. The |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
978 \var{name} argument may be of the form \code{package.module}). First |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
979 check the modules dictionary if there's one there, and if not, create |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
980 a new one and insert in in the modules dictionary. Because the former |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
981 action is most common, this does not return a new reference, and you |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
982 do not own the returned reference. Return \NULL{} with an |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
983 exception set on failure. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
984 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
985 |
| 7782 | 986 \begin{cfuncdesc}{PyObject*}{PyImport_ExecCodeModule}{char *name, PyObject *co} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
987 Given a module name (possibly of the form \code{package.module}) and a |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
988 code object read from a Python bytecode file or obtained from the |
|
7309
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
989 built-in function \function{compile()}\bifuncindex{compile}, load the |
|
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
990 module. Return a new reference to the module object, or \NULL{} with |
|
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
991 an exception set if an error occurred (the module may still be created |
|
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
992 in this case). (This function would reload the module if it was |
|
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
993 already imported.) |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
994 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
995 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
996 \begin{cfuncdesc}{long}{PyImport_GetMagicNumber}{} |
| 7308 | 997 Return the magic number for Python bytecode files (a.k.a. \file{.pyc} |
| 998 and \file{.pyo} files). The magic number should be present in the | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
999 first four bytes of the bytecode file, in little-endian byte order. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1000 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1001 |
| 7782 | 1002 \begin{cfuncdesc}{PyObject*}{PyImport_GetModuleDict}{} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1003 Return the dictionary used for the module administration |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1004 (a.k.a. \code{sys.modules}). Note that this is a per-interpreter |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1005 variable. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1006 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1007 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1008 \begin{cfuncdesc}{void}{_PyImport_Init}{} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1009 Initialize the import mechanism. For internal use only. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1010 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1011 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1012 \begin{cfuncdesc}{void}{PyImport_Cleanup}{} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1013 Empty the module table. For internal use only. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1014 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1015 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1016 \begin{cfuncdesc}{void}{_PyImport_Fini}{} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1017 Finalize the import mechanism. For internal use only. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1018 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1019 |
| 7782 | 1020 \begin{cfuncdesc}{PyObject*}{_PyImport_FindExtension}{char *, char *} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1021 For internal use only. |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
1022 \end{cfuncdesc} |
|
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
1023 |
| 7782 | 1024 \begin{cfuncdesc}{PyObject*}{_PyImport_FixupExtension}{char *, char *} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1025 For internal use only. |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
1026 \end{cfuncdesc} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1027 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1028 \begin{cfuncdesc}{int}{PyImport_ImportFrozenModule}{char *} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1029 Load a frozen module. Return \code{1} for success, \code{0} if the |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1030 module is not found, and \code{-1} with an exception set if the |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1031 initialization failed. To access the imported module on a successful |
| 7308 | 1032 load, use \cfunction{PyImport_ImportModule()}. |
| 1033 (Note the misnomer --- this function would reload the module if it was | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1034 already imported.) |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1035 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1036 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1037 \begin{ctypedesc}{struct _frozen} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1038 This is the structure type definition for frozen module descriptors, |
| 7782 | 1039 as generated by the \program{freeze}\index{freeze utility} utility |
| 1040 (see \file{Tools/freeze/} in the Python source distribution). Its | |
| 1041 definition is: | |
| 1042 | |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
1043 \begin{verbatim} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1044 struct _frozen { |
| 6480 | 1045 char *name; |
| 1046 unsigned char *code; | |
| 1047 int size; | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1048 }; |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
1049 \end{verbatim} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1050 \end{ctypedesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1051 |
| 7782 | 1052 \begin{cvardesc}{struct _frozen*}{PyImport_FrozenModules} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1053 This pointer is initialized to point to an array of \code{struct |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
1054 _frozen} records, terminated by one whose members are all \NULL{} |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1055 or zero. When a frozen module is imported, it is searched in this |
| 7782 | 1056 table. Third-party code could play tricks with this to provide a |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1057 dynamically created collection of frozen modules. |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1058 \end{cvardesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1059 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
1060 |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1061 \chapter{Abstract Objects Layer} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1062 \label{abstract} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1063 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1064 The functions in this chapter interact with Python objects regardless |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1065 of their type, or with wide classes of object types (e.g. all |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1066 numerical types, or all sequence types). When used on object types |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1067 for which they do not apply, they will flag a Python exception. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1068 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1069 \section{Object Protocol} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1070 \label{object} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1071 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1072 \begin{cfuncdesc}{int}{PyObject_Print}{PyObject *o, FILE *fp, int flags} |
| 7308 | 1073 Print an object \var{o}, on file \var{fp}. Returns \code{-1} on error |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1074 The flags argument is used to enable certain printing |
| 7308 | 1075 options. The only option currently supported is |
| 1076 \constant{Py_Print_RAW}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1077 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1078 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1079 \begin{cfuncdesc}{int}{PyObject_HasAttrString}{PyObject *o, char *attr_name} |
| 7308 | 1080 Returns \code{1} if \var{o} has the attribute \var{attr_name}, and |
| 1081 \code{0} otherwise. This is equivalent to the Python expression | |
| 1082 \samp{hasattr(\var{o}, \var{attr_name})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1083 This function always succeeds. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1084 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1085 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1086 \begin{cfuncdesc}{PyObject*}{PyObject_GetAttrString}{PyObject *o, char *attr_name} |
| 7308 | 1087 Retrieve an attribute named \var{attr_name} from object \var{o}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1088 Returns the attribute value on success, or \NULL{} on failure. |
| 7308 | 1089 This is the equivalent of the Python expression |
| 1090 \samp{\var{o}.\var{attr_name}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1091 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1092 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1093 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1094 \begin{cfuncdesc}{int}{PyObject_HasAttr}{PyObject *o, PyObject *attr_name} |
| 7308 | 1095 Returns \code{1} if \var{o} has the attribute \var{attr_name}, and |
| 1096 \code{0} otherwise. This is equivalent to the Python expression | |
| 1097 \samp{hasattr(\var{o}, \var{attr_name})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1098 This function always succeeds. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1099 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1100 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1101 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1102 \begin{cfuncdesc}{PyObject*}{PyObject_GetAttr}{PyObject *o, PyObject *attr_name} |
| 7308 | 1103 Retrieve an attribute named \var{attr_name} from object \var{o}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1104 Returns the attribute value on success, or \NULL{} on failure. |
| 7308 | 1105 This is the equivalent of the Python expression |
| 1106 \samp{\var{o}.\var{attr_name}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1107 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1108 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1109 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1110 \begin{cfuncdesc}{int}{PyObject_SetAttrString}{PyObject *o, char *attr_name, PyObject *v} |
| 7308 | 1111 Set the value of the attribute named \var{attr_name}, for object |
| 1112 \var{o}, to the value \var{v}. Returns \code{-1} on failure. This is | |
| 1113 the equivalent of the Python statement \samp{\var{o}.\var{attr_name} = | |
| 1114 \var{v}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1115 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1116 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1117 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1118 \begin{cfuncdesc}{int}{PyObject_SetAttr}{PyObject *o, PyObject *attr_name, PyObject *v} |
| 7308 | 1119 Set the value of the attribute named \var{attr_name}, for |
| 1120 object \var{o}, | |
| 1121 to the value \var{v}. Returns \code{-1} on failure. This is | |
| 1122 the equivalent of the Python statement \samp{\var{o}.\var{attr_name} = | |
| 1123 \var{v}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1124 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1125 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1126 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1127 \begin{cfuncdesc}{int}{PyObject_DelAttrString}{PyObject *o, char *attr_name} |
| 7308 | 1128 Delete attribute named \var{attr_name}, for object \var{o}. Returns |
| 1129 \code{-1} on failure. This is the equivalent of the Python | |
| 1130 statement: \samp{del \var{o}.\var{attr_name}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1131 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1132 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1133 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1134 \begin{cfuncdesc}{int}{PyObject_DelAttr}{PyObject *o, PyObject *attr_name} |
| 7308 | 1135 Delete attribute named \var{attr_name}, for object \var{o}. Returns |
| 1136 \code{-1} on failure. This is the equivalent of the Python | |
| 1137 statement \samp{del \var{o}.\var{attr_name}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1138 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1139 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1140 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1141 \begin{cfuncdesc}{int}{PyObject_Cmp}{PyObject *o1, PyObject *o2, int *result} |
| 7308 | 1142 Compare the values of \var{o1} and \var{o2} using a routine provided |
| 1143 by \var{o1}, if one exists, otherwise with a routine provided by | |
| 1144 \var{o2}. The result of the comparison is returned in \var{result}. | |
| 1145 Returns \code{-1} on failure. This is the equivalent of the Python | |
| 1146 statement \samp{\var{result} = cmp(\var{o1}, \var{o2})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1147 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1148 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1149 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1150 \begin{cfuncdesc}{int}{PyObject_Compare}{PyObject *o1, PyObject *o2} |
| 7308 | 1151 Compare the values of \var{o1} and \var{o2} using a routine provided |
| 1152 by \var{o1}, if one exists, otherwise with a routine provided by | |
| 1153 \var{o2}. Returns the result of the comparison on success. On error, | |
| 1154 the value returned is undefined; use \cfunction{PyErr_Occurred()} to | |
| 1155 detect an error. This is equivalent to the | |
| 1156 Python expression \samp{cmp(\var{o1}, \var{o2})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1157 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1158 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1159 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1160 \begin{cfuncdesc}{PyObject*}{PyObject_Repr}{PyObject *o} |
| 7308 | 1161 Compute the string representation of object, \var{o}. Returns the |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1162 string representation on success, \NULL{} on failure. This is |
| 7308 | 1163 the equivalent of the Python expression \samp{repr(\var{o})}. |
| 1164 Called by the \function{repr()}\bifuncindex{repr} built-in function | |
| 1165 and by reverse quotes. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1166 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1167 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1168 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1169 \begin{cfuncdesc}{PyObject*}{PyObject_Str}{PyObject *o} |
| 7308 | 1170 Compute the string representation of object \var{o}. Returns the |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1171 string representation on success, \NULL{} on failure. This is |
| 7308 | 1172 the equivalent of the Python expression \samp{str(\var{o})}. |
| 1173 Called by the \function{str()}\bifuncindex{str} built-in function and | |
| 1174 by the \keyword{print} statement. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1175 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1176 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1177 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1178 \begin{cfuncdesc}{int}{PyCallable_Check}{PyObject *o} |
| 7308 | 1179 Determine if the object \var{o}, is callable. Return \code{1} if the |
| 1180 object is callable and \code{0} otherwise. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1181 This function always succeeds. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1182 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1183 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1184 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1185 \begin{cfuncdesc}{PyObject*}{PyObject_CallObject}{PyObject *callable_object, PyObject *args} |
| 7308 | 1186 Call a callable Python object \var{callable_object}, with |
| 1187 arguments given by the tuple \var{args}. If no arguments are | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1188 needed, then args may be \NULL{}. Returns the result of the |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1189 call on success, or \NULL{} on failure. This is the equivalent |
| 7308 | 1190 of the Python expression \samp{apply(\var{o}, \var{args})}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1191 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1192 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1193 \begin{cfuncdesc}{PyObject*}{PyObject_CallFunction}{PyObject *callable_object, char *format, ...} |
| 7308 | 1194 Call a callable Python object \var{callable_object}, with a |
| 7081 | 1195 variable number of \C{} arguments. The \C{} arguments are described |
| 7308 | 1196 using a \cfunction{Py_BuildValue()} style format string. The format may |
| 1197 be \NULL{}, indicating that no arguments are provided. Returns the | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1198 result of the call on success, or \NULL{} on failure. This is |
| 7308 | 1199 the equivalent of the Python expression \samp{apply(\var{o}, |
| 1200 \var{args})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1201 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1202 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1203 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1204 \begin{cfuncdesc}{PyObject*}{PyObject_CallMethod}{PyObject *o, char *m, char *format, ...} |
| 7308 | 1205 Call the method named \var{m} of object \var{o} with a variable number |
| 1206 of C arguments. The \C{} arguments are described by a | |
| 1207 \cfunction{Py_BuildValue()} format string. The format may be \NULL{}, | |
| 1208 indicating that no arguments are provided. Returns the result of the | |
| 1209 call on success, or \NULL{} on failure. This is the equivalent of the | |
| 1210 Python expression \samp{\var{o}.\var{method}(\var{args})}. | |
| 1211 Note that Special method names, such as \method{__add__()}, | |
| 1212 \method{__getitem__()}, and so on are not supported. The specific | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1213 abstract-object routines for these must be used. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1214 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1215 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1216 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1217 \begin{cfuncdesc}{int}{PyObject_Hash}{PyObject *o} |
| 7308 | 1218 Compute and return the hash value of an object \var{o}. On |
| 1219 failure, return \code{-1}. This is the equivalent of the Python | |
| 1220 expression \samp{hash(\var{o})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1221 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1222 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1223 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1224 \begin{cfuncdesc}{int}{PyObject_IsTrue}{PyObject *o} |
| 7308 | 1225 Returns \code{1} if the object \var{o} is considered to be true, and |
| 1226 \code{0} otherwise. This is equivalent to the Python expression | |
| 1227 \samp{not not \var{o}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1228 This function always succeeds. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1229 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1230 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1231 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1232 \begin{cfuncdesc}{PyObject*}{PyObject_Type}{PyObject *o} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1233 On success, returns a type object corresponding to the object |
| 7308 | 1234 type of object \var{o}. On failure, returns \NULL{}. This is |
| 1235 equivalent to the Python expression \samp{type(\var{o})}. | |
|
7309
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
1236 \bifuncindex{type} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1237 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1238 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1239 \begin{cfuncdesc}{int}{PyObject_Length}{PyObject *o} |
| 7308 | 1240 Return the length of object \var{o}. If the object \var{o} provides |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1241 both sequence and mapping protocols, the sequence length is |
| 7308 | 1242 returned. On error, \code{-1} is returned. This is the equivalent |
| 1243 to the Python expression \samp{len(\var{o})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1244 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1245 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1246 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1247 \begin{cfuncdesc}{PyObject*}{PyObject_GetItem}{PyObject *o, PyObject *key} |
| 7308 | 1248 Return element of \var{o} corresponding to the object \var{key} or |
| 1249 \NULL{} on failure. This is the equivalent of the Python expression | |
| 1250 \samp{\var{o}[\var{key}]}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1251 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1252 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1253 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1254 \begin{cfuncdesc}{int}{PyObject_SetItem}{PyObject *o, PyObject *key, PyObject *v} |
| 7308 | 1255 Map the object \var{key} to the value \var{v}. |
| 1256 Returns \code{-1} on failure. This is the equivalent | |
| 1257 of the Python statement \samp{\var{o}[\var{key}] = \var{v}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1258 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1259 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1260 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1261 \begin{cfuncdesc}{int}{PyObject_DelItem}{PyObject *o, PyObject *key, PyObject *v} |
| 7308 | 1262 Delete the mapping for \var{key} from \var{o}. Returns \code{-1} on |
| 1263 failure. This is the equivalent of the Python statement \samp{del | |
| 1264 \var{o}[\var{key}]}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1265 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1266 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1267 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1268 \section{Number Protocol} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1269 \label{number} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1270 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1271 \begin{cfuncdesc}{int}{PyNumber_Check}{PyObject *o} |
| 7308 | 1272 Returns \code{1} if the object \var{o} provides numeric protocols, and |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1273 false otherwise. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1274 This function always succeeds. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1275 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1276 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1277 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1278 \begin{cfuncdesc}{PyObject*}{PyNumber_Add}{PyObject *o1, PyObject *o2} |
| 7308 | 1279 Returns the result of adding \var{o1} and \var{o2}, or \NULL{} on |
| 1280 failure. This is the equivalent of the Python expression | |
| 1281 \samp{\var{o1} + \var{o2}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1282 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1283 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1284 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1285 \begin{cfuncdesc}{PyObject*}{PyNumber_Subtract}{PyObject *o1, PyObject *o2} |
| 7308 | 1286 Returns the result of subtracting \var{o2} from \var{o1}, or \NULL{} |
| 1287 on failure. This is the equivalent of the Python expression | |
| 1288 \samp{\var{o1} - \var{o2}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1289 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1290 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1291 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1292 \begin{cfuncdesc}{PyObject*}{PyNumber_Multiply}{PyObject *o1, PyObject *o2} |
| 7308 | 1293 Returns the result of multiplying \var{o1} and \var{o2}, or \NULL{} on |
| 1294 failure. This is the equivalent of the Python expression | |
| 1295 \samp{\var{o1} * \var{o2}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1296 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1297 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1298 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1299 \begin{cfuncdesc}{PyObject*}{PyNumber_Divide}{PyObject *o1, PyObject *o2} |
| 7308 | 1300 Returns the result of dividing \var{o1} by \var{o2}, or \NULL{} on |
| 1301 failure. | |
| 1302 This is the equivalent of the Python expression \samp{\var{o1} / | |
| 1303 \var{o2}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1304 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1305 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1306 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1307 \begin{cfuncdesc}{PyObject*}{PyNumber_Remainder}{PyObject *o1, PyObject *o2} |
| 7308 | 1308 Returns the remainder of dividing \var{o1} by \var{o2}, or \NULL{} on |
| 1309 failure. This is the equivalent of the Python expression | |
| 1310 \samp{\var{o1} \% \var{o2}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1311 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1312 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1313 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1314 \begin{cfuncdesc}{PyObject*}{PyNumber_Divmod}{PyObject *o1, PyObject *o2} |
|
7309
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
1315 See the built-in function \function{divmod()}\bifuncindex{divmod}. |
|
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
1316 Returns \NULL{} on failure. This is the equivalent of the Python |
|
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
1317 expression \samp{divmod(\var{o1}, \var{o2})}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1318 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1319 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1320 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1321 \begin{cfuncdesc}{PyObject*}{PyNumber_Power}{PyObject *o1, PyObject *o2, PyObject *o3} |
|
7309
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
1322 See the built-in function \function{pow()}\bifuncindex{pow}. Returns |
|
d7266372dd37
Added index enties for the Python built-in functions, where appropriate.
Fred Drake <fdrake@acm.org>
parents:
7308
diff
changeset
|
1323 \NULL{} on failure. This is the equivalent of the Python expression |
| 7308 | 1324 \samp{pow(\var{o1}, \var{o2}, \var{o3})}, where \var{o3} is optional. |
| 1325 If \var{o3} is to be ignored, pass \code{Py_None} in its place. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1326 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1327 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1328 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1329 \begin{cfuncdesc}{PyObject*}{PyNumber_Negative}{PyObject *o} |
| 7308 | 1330 Returns the negation of \var{o} on success, or \NULL{} on failure. |
| 1331 This is the equivalent of the Python expression \samp{-\var{o}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1332 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1333 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1334 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1335 \begin{cfuncdesc}{PyObject*}{PyNumber_Positive}{PyObject *o} |
| 7308 | 1336 Returns \var{o} on success, or \NULL{} on failure. |
| 1337 This is the equivalent of the Python expression \samp{+\var{o}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1338 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1339 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1340 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1341 \begin{cfuncdesc}{PyObject*}{PyNumber_Absolute}{PyObject *o} |
| 7308 | 1342 Returns the absolute value of \var{o}, or \NULL{} on failure. This is |
| 1343 the equivalent of the Python expression \samp{abs(\var{o})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1344 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1345 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1346 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1347 \begin{cfuncdesc}{PyObject*}{PyNumber_Invert}{PyObject *o} |
| 7308 | 1348 Returns the bitwise negation of \var{o} on success, or \NULL{} on |
| 1349 failure. This is the equivalent of the Python expression | |
| 1350 \samp{\~\var{o}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1351 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1352 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1353 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1354 \begin{cfuncdesc}{PyObject*}{PyNumber_Lshift}{PyObject *o1, PyObject *o2} |
| 7308 | 1355 Returns the result of left shifting \var{o1} by \var{o2} on success, |
| 1356 or \NULL{} on failure. This is the equivalent of the Python | |
| 1357 expression \samp{\var{o1} << \var{o2}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1358 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1359 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1360 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1361 \begin{cfuncdesc}{PyObject*}{PyNumber_Rshift}{PyObject *o1, PyObject *o2} |
| 7308 | 1362 Returns the result of right shifting \var{o1} by \var{o2} on success, |
| 1363 or \NULL{} on failure. This is the equivalent of the Python | |
| 1364 expression \samp{\var{o1} >> \var{o2}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1365 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1366 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1367 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1368 \begin{cfuncdesc}{PyObject*}{PyNumber_And}{PyObject *o1, PyObject *o2} |
| 7308 | 1369 Returns the result of ``anding'' \var{o2} and \var{o2} on success and |
| 1370 \NULL{} on failure. This is the equivalent of the Python | |
| 1371 expression \samp{\var{o1} and \var{o2}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1372 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1373 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1374 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1375 \begin{cfuncdesc}{PyObject*}{PyNumber_Xor}{PyObject *o1, PyObject *o2} |
| 7308 | 1376 Returns the bitwise exclusive or of \var{o1} by \var{o2} on success, |
| 1377 or \NULL{} on failure. This is the equivalent of the Python | |
| 1378 expression \samp{\var{o1} \^{ }\var{o2}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1379 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1380 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1381 \begin{cfuncdesc}{PyObject*}{PyNumber_Or}{PyObject *o1, PyObject *o2} |
| 7308 | 1382 Returns the result of \var{o1} and \var{o2} on success, or \NULL{} on |
| 1383 failure. This is the equivalent of the Python expression | |
| 1384 \samp{\var{o1} or \var{o2}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1385 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1386 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1387 |
| 7308 | 1388 \begin{cfuncdesc}{PyObject*}{PyNumber_Coerce}{PyObject **p1, PyObject **p2} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1389 This function takes the addresses of two variables of type |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1390 \code{PyObject*}. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1391 |
| 7308 | 1392 If the objects pointed to by \code{*\var{p1}} and \code{*\var{p2}} |
| 1393 have the same type, increment their reference count and return | |
| 1394 \code{0} (success). If the objects can be converted to a common | |
| 1395 numeric type, replace \code{*p1} and \code{*p2} by their converted | |
| 1396 value (with 'new' reference counts), and return \code{0}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1397 If no conversion is possible, or if some other error occurs, |
| 7308 | 1398 return \code{-1} (failure) and don't increment the reference counts. |
| 1399 The call \code{PyNumber_Coerce(\&o1, \&o2)} is equivalent to the | |
| 1400 Python statement \samp{\var{o1}, \var{o2} = coerce(\var{o1}, | |
| 1401 \var{o2})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1402 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1403 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1404 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1405 \begin{cfuncdesc}{PyObject*}{PyNumber_Int}{PyObject *o} |
| 7308 | 1406 Returns the \var{o} converted to an integer object on success, or |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1407 \NULL{} on failure. This is the equivalent of the Python |
| 7308 | 1408 expression \samp{int(\var{o})}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1409 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1410 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1411 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1412 \begin{cfuncdesc}{PyObject*}{PyNumber_Long}{PyObject *o} |
| 7308 | 1413 Returns the \var{o} converted to a long integer object on success, |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1414 or \NULL{} on failure. This is the equivalent of the Python |
| 7308 | 1415 expression \samp{long(\var{o})}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1416 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1417 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1418 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1419 \begin{cfuncdesc}{PyObject*}{PyNumber_Float}{PyObject *o} |
| 7308 | 1420 Returns the \var{o} converted to a float object on success, or \NULL{} |
| 1421 on failure. This is the equivalent of the Python expression | |
| 1422 \samp{float(\var{o})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1423 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1424 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1425 |
|
7268
a2f4c944cb87
For sections describing the "Foo Protocol", consistently use the capitalized
Fred Drake <fdrake@acm.org>
parents:
7267
diff
changeset
|
1426 \section{Sequence Protocol} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1427 \label{sequence} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1428 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1429 \begin{cfuncdesc}{int}{PySequence_Check}{PyObject *o} |
| 7308 | 1430 Return \code{1} if the object provides sequence protocol, and \code{0} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1431 otherwise. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1432 This function always succeeds. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1433 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1434 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1435 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1436 \begin{cfuncdesc}{PyObject*}{PySequence_Concat}{PyObject *o1, PyObject *o2} |
| 7308 | 1437 Return the concatenation of \var{o1} and \var{o2} on success, and \NULL{} on |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1438 failure. This is the equivalent of the Python |
| 7308 | 1439 expression \samp{\var{o1} + \var{o2}}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1440 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1441 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1442 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1443 \begin{cfuncdesc}{PyObject*}{PySequence_Repeat}{PyObject *o, int count} |
| 7308 | 1444 Return the result of repeating sequence object \var{o} \var{count} |
| 1445 times, or \NULL{} on failure. This is the equivalent of the Python | |
| 1446 expression \samp{\var{o} * \var{count}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1447 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1448 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1449 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1450 \begin{cfuncdesc}{PyObject*}{PySequence_GetItem}{PyObject *o, int i} |
| 7308 | 1451 Return the \var{i}th element of \var{o}, or \NULL{} on failure. This |
| 1452 is the equivalent of the Python expression \samp{\var{o}[\var{i}]}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1453 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1454 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1455 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1456 \begin{cfuncdesc}{PyObject*}{PySequence_GetSlice}{PyObject *o, int i1, int i2} |
| 7308 | 1457 Return the slice of sequence object \var{o} between \var{i1} and |
| 1458 \var{i2}, or \NULL{} on failure. This is the equivalent of the Python | |
| 1459 expression \samp{\var{o}[\var{i1}:\var{i2}]}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1460 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1461 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1462 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1463 \begin{cfuncdesc}{int}{PySequence_SetItem}{PyObject *o, int i, PyObject *v} |
| 7308 | 1464 Assign object \var{v} to the \var{i}th element of \var{o}. |
| 1465 Returns \code{-1} on failure. This is the equivalent of the Python | |
| 1466 statement \samp{\var{o}[\var{i}] = \var{v}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1467 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1468 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1469 \begin{cfuncdesc}{int}{PySequence_DelItem}{PyObject *o, int i} |
| 7308 | 1470 Delete the \var{i}th element of object \var{v}. Returns |
| 1471 \code{-1} on failure. This is the equivalent of the Python | |
| 1472 statement \samp{del \var{o}[\var{i}]}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1473 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1474 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1475 \begin{cfuncdesc}{int}{PySequence_SetSlice}{PyObject *o, int i1, int i2, PyObject *v} |
| 7308 | 1476 Assign the sequence object \var{v} to the slice in sequence |
| 1477 object \var{o} from \var{i1} to \var{i2}. This is the equivalent of | |
| 1478 the Python statement \samp{\var{o}[\var{i1}:\var{i2}] = \var{v}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1479 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1480 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1481 \begin{cfuncdesc}{int}{PySequence_DelSlice}{PyObject *o, int i1, int i2} |
| 7308 | 1482 Delete the slice in sequence object \var{o} from \var{i1} to \var{i2}. |
| 1483 Returns \code{-1} on failure. This is the equivalent of the Python | |
| 1484 statement \samp{del \var{o}[\var{i1}:\var{i2}]}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1485 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1486 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1487 \begin{cfuncdesc}{PyObject*}{PySequence_Tuple}{PyObject *o} |
| 7308 | 1488 Returns the \var{o} as a tuple on success, and \NULL{} on failure. |
| 1489 This is equivalent to the Python expression \code{tuple(\var{o})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1490 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1491 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1492 \begin{cfuncdesc}{int}{PySequence_Count}{PyObject *o, PyObject *value} |
| 7308 | 1493 Return the number of occurrences of \var{value} in \var{o}, that is, |
| 1494 return the number of keys for which \code{\var{o}[\var{key}] == | |
| 1495 \var{value}}. On failure, return \code{-1}. This is equivalent to | |
| 1496 the Python expression \samp{\var{o}.count(\var{value})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1497 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1498 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1499 \begin{cfuncdesc}{int}{PySequence_In}{PyObject *o, PyObject *value} |
| 7308 | 1500 Determine if \var{o} contains \var{value}. If an item in \var{o} is |
| 1501 equal to \var{value}, return \code{1}, otherwise return \code{0}. On | |
| 1502 error, return \code{-1}. This is equivalent to the Python expression | |
| 1503 \samp{\var{value} in \var{o}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1504 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1505 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1506 \begin{cfuncdesc}{int}{PySequence_Index}{PyObject *o, PyObject *value} |
| 7308 | 1507 Return the first index \var{i} for which \code{\var{o}[\var{i}] == |
| 1508 \var{value}}. On error, return \code{-1}. This is equivalent to | |
| 1509 the Python expression \samp{\var{o}.index(\var{value})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1510 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1511 |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1512 |
|
7268
a2f4c944cb87
For sections describing the "Foo Protocol", consistently use the capitalized
Fred Drake <fdrake@acm.org>
parents:
7267
diff
changeset
|
1513 \section{Mapping Protocol} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1514 \label{mapping} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1515 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1516 \begin{cfuncdesc}{int}{PyMapping_Check}{PyObject *o} |
| 7308 | 1517 Return \code{1} if the object provides mapping protocol, and \code{0} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1518 otherwise. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1519 This function always succeeds. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1520 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1521 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1522 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1523 \begin{cfuncdesc}{int}{PyMapping_Length}{PyObject *o} |
| 7308 | 1524 Returns the number of keys in object \var{o} on success, and \code{-1} |
| 1525 on failure. For objects that do not provide sequence protocol, | |
| 1526 this is equivalent to the Python expression \samp{len(\var{o})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1527 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1528 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1529 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1530 \begin{cfuncdesc}{int}{PyMapping_DelItemString}{PyObject *o, char *key} |
| 7308 | 1531 Remove the mapping for object \var{key} from the object \var{o}. |
| 1532 Return \code{-1} on failure. This is equivalent to | |
| 1533 the Python statement \samp{del \var{o}[\var{key}]}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1534 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1535 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1536 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1537 \begin{cfuncdesc}{int}{PyMapping_DelItem}{PyObject *o, PyObject *key} |
| 7308 | 1538 Remove the mapping for object \var{key} from the object \var{o}. |
| 1539 Return \code{-1} on failure. This is equivalent to | |
| 1540 the Python statement \samp{del \var{o}[\var{key}]}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1541 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1542 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1543 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1544 \begin{cfuncdesc}{int}{PyMapping_HasKeyString}{PyObject *o, char *key} |
| 7308 | 1545 On success, return \code{1} if the mapping object has the key \var{key} |
| 1546 and \code{0} otherwise. This is equivalent to the Python expression | |
| 1547 \samp{\var{o}.has_key(\var{key})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1548 This function always succeeds. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1549 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1550 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1551 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1552 \begin{cfuncdesc}{int}{PyMapping_HasKey}{PyObject *o, PyObject *key} |
| 7308 | 1553 Return \code{1} if the mapping object has the key \var{key} and |
| 1554 \code{0} otherwise. This is equivalent to the Python expression | |
| 1555 \samp{\var{o}.has_key(\var{key})}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1556 This function always succeeds. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1557 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1558 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1559 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1560 \begin{cfuncdesc}{PyObject*}{PyMapping_Keys}{PyObject *o} |
| 7308 | 1561 On success, return a list of the keys in object \var{o}. On |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1562 failure, return \NULL{}. This is equivalent to the Python |
| 7308 | 1563 expression \samp{\var{o}.keys()}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1564 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1565 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1566 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1567 \begin{cfuncdesc}{PyObject*}{PyMapping_Values}{PyObject *o} |
| 7308 | 1568 On success, return a list of the values in object \var{o}. On |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1569 failure, return \NULL{}. This is equivalent to the Python |
| 7308 | 1570 expression \samp{\var{o}.values()}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1571 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1572 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1573 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1574 \begin{cfuncdesc}{PyObject*}{PyMapping_Items}{PyObject *o} |
| 7308 | 1575 On success, return a list of the items in object \var{o}, where |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1576 each item is a tuple containing a key-value pair. On |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1577 failure, return \NULL{}. This is equivalent to the Python |
| 7308 | 1578 expression \samp{\var{o}.items()}. |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1579 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1580 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1581 \begin{cfuncdesc}{int}{PyMapping_Clear}{PyObject *o} |
| 7308 | 1582 Make object \var{o} empty. Returns \code{1} on success and \code{0} |
| 1583 on failure. This is equivalent to the Python statement | |
| 1584 \samp{for key in \var{o}.keys(): del \var{o}[key]}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1585 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1586 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1587 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1588 \begin{cfuncdesc}{PyObject*}{PyMapping_GetItemString}{PyObject *o, char *key} |
| 7308 | 1589 Return element of \var{o} corresponding to the object \var{key} or |
| 1590 \NULL{} on failure. This is the equivalent of the Python expression | |
| 1591 \samp{\var{o}[\var{key}]}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1592 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1593 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1594 \begin{cfuncdesc}{PyObject*}{PyMapping_SetItemString}{PyObject *o, char *key, PyObject *v} |
| 7308 | 1595 Map the object \var{key} to the value \var{v} in object \var{o}. |
| 1596 Returns \code{-1} on failure. This is the equivalent of the Python | |
| 1597 statement \samp{\var{o}[\var{key}] = \var{v}}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1598 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1599 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1600 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1601 \section{Constructors} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1602 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1603 \begin{cfuncdesc}{PyObject*}{PyFile_FromString}{char *file_name, char *mode} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1604 On success, returns a new file object that is opened on the |
| 7308 | 1605 file given by \var{file_name}, with a file mode given by \var{mode}, |
| 1606 where \var{mode} has the same semantics as the standard \C{} routine | |
| 1607 \cfunction{fopen()}. On failure, return \code{-1}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1608 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1609 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1610 \begin{cfuncdesc}{PyObject*}{PyFile_FromFile}{FILE *fp, char *file_name, char *mode, int close_on_del} |
| 7308 | 1611 Return a new file object for an already opened standard \C{} file |
| 1612 pointer, \var{fp}. A file name, \var{file_name}, and open mode, | |
| 1613 \var{mode}, must be provided as well as a flag, \var{close_on_del}, | |
| 1614 that indicates whether the file is to be closed when the file object | |
| 1615 is destroyed. On failure, return \code{-1}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1616 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1617 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1618 \begin{cfuncdesc}{PyObject*}{PyFloat_FromDouble}{double v} |
| 7308 | 1619 Returns a new float object with the value \var{v} on success, and |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1620 \NULL{} on failure. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1621 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1622 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1623 \begin{cfuncdesc}{PyObject*}{PyInt_FromLong}{long v} |
| 7308 | 1624 Returns a new int object with the value \var{v} on success, and |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1625 \NULL{} on failure. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1626 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1627 |
| 7308 | 1628 \begin{cfuncdesc}{PyObject*}{PyList_New}{int len} |
| 1629 Returns a new list of length \var{len} on success, and \NULL{} on | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1630 failure. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1631 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1632 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1633 \begin{cfuncdesc}{PyObject*}{PyLong_FromLong}{long v} |
| 7308 | 1634 Returns a new long object with the value \var{v} on success, and |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1635 \NULL{} on failure. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1636 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1637 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1638 \begin{cfuncdesc}{PyObject*}{PyLong_FromDouble}{double v} |
| 7308 | 1639 Returns a new long object with the value \var{v} on success, and |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1640 \NULL{} on failure. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1641 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1642 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1643 \begin{cfuncdesc}{PyObject*}{PyDict_New}{} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1644 Returns a new empty dictionary on success, and \NULL{} on |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1645 failure. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1646 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1647 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1648 \begin{cfuncdesc}{PyObject*}{PyString_FromString}{char *v} |
| 7308 | 1649 Returns a new string object with the value \var{v} on success, and |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1650 \NULL{} on failure. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1651 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1652 |
| 7308 | 1653 \begin{cfuncdesc}{PyObject*}{PyString_FromStringAndSize}{char *v, int len} |
| 1654 Returns a new string object with the value \var{v} and length | |
| 1655 \var{len} on success, and \NULL{} on failure. If \var{v} is \NULL{}, | |
| 1656 the contents of the string are uninitialized. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1657 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1658 |
| 7308 | 1659 \begin{cfuncdesc}{PyObject*}{PyTuple_New}{int len} |
| 1660 Returns a new tuple of length \var{len} on success, and \NULL{} on | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1661 failure. |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1662 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1663 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1664 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1665 \chapter{Concrete Objects Layer} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1666 \label{concrete} |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1667 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1668 The functions in this chapter are specific to certain Python object |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1669 types. Passing them an object of the wrong type is not a good idea; |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1670 if you receive an object from a Python program and you are not sure |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1671 that it has the right type, you must perform a type check first; |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1672 e.g. to check that an object is a dictionary, use |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1673 \cfunction{PyDict_Check()}. The chapter is structured like the |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1674 ``family tree'' of Python object types. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1675 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1676 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1677 \section{Fundamental Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1678 \label{fundamental} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1679 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1680 This section describes Python type objects and the singleton object |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1681 \code{None}. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1682 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1683 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1684 \subsection{Type Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1685 \label{typeObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1686 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1687 \begin{ctypedesc}{PyTypeObject} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1688 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1689 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1690 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1691 \begin{cvardesc}{PyObject *}{PyType_Type} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1692 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1693 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1694 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1695 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1696 \subsection{The None Object} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1697 \label{noneObject} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1698 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1699 \begin{cvardesc}{PyObject *}{Py_None} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1700 XXX macro |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1701 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1702 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1703 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1704 \section{Sequence Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1705 \label{sequenceObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1706 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1707 Generic operations on sequence objects were discussed in the previous |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1708 chapter; this section deals with the specific kinds of sequence |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1709 objects that are intrinsic to the Python language. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1710 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1711 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1712 \subsection{String Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1713 \label{stringObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1714 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1715 \begin{ctypedesc}{PyStringObject} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1716 This subtype of \code{PyObject} represents a Python string object. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1717 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1718 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1719 \begin{cvardesc}{PyTypeObject}{PyString_Type} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1720 This instance of \code{PyTypeObject} represents the Python string type. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1721 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1722 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1723 \begin{cfuncdesc}{int}{PyString_Check}{PyObject *o} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1724 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1725 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1726 |
| 7782 | 1727 \begin{cfuncdesc}{PyObject*}{PyString_FromStringAndSize}{const char *v, |
| 1728 int len} | |
| 1729 \end{cfuncdesc} | |
| 1730 | |
| 1731 \begin{cfuncdesc}{PyObject*}{PyString_FromString}{const char *v} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1732 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1733 |
| 7782 | 1734 \begin{cfuncdesc}{int}{PyString_Size}{PyObject *string} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1735 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1736 |
| 7782 | 1737 \begin{cfuncdesc}{char*}{PyString_AsString}{PyObject *string} |
| 1738 \end{cfuncdesc} | |
| 1739 | |
| 1740 \begin{cfuncdesc}{void}{PyString_Concat}{PyObject **string, | |
| 1741 PyObject *newpart} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1742 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1743 |
| 7782 | 1744 \begin{cfuncdesc}{void}{PyString_ConcatAndDel}{PyObject **string, |
| 1745 PyObject *newpart} | |
| 1746 \end{cfuncdesc} | |
| 1747 | |
| 1748 \begin{cfuncdesc}{int}{_PyString_Resize}{PyObject **string, int newsize} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1749 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1750 |
| 7782 | 1751 \begin{cfuncdesc}{PyObject*}{PyString_Format}{PyObject *format, |
| 1752 PyObject *args} | |
| 1753 \end{cfuncdesc} | |
| 1754 | |
| 1755 \begin{cfuncdesc}{void}{PyString_InternInPlace}{PyObject **string} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1756 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1757 |
| 7782 | 1758 \begin{cfuncdesc}{PyObject*}{PyString_InternFromString}{const char *v} |
| 1759 \end{cfuncdesc} | |
| 1760 | |
| 1761 \begin{cfuncdesc}{char*}{PyString_AS_STRING}{PyObject *string} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1762 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1763 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1764 |
| 7782 | 1765 \begin{cfuncdesc}{int}{PyString_GET_SIZE}{PyObject *string} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1766 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1767 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1768 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1769 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1770 \subsection{Tuple Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1771 \label{tupleObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1772 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1773 \begin{ctypedesc}{PyTupleObject} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1774 This subtype of \code{PyObject} represents a Python tuple object. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1775 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1776 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1777 \begin{cvardesc}{PyTypeObject}{PyTuple_Type} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1778 This instance of \code{PyTypeObject} represents the Python tuple type. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1779 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1780 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1781 \begin{cfuncdesc}{int}{PyTuple_Check}{PyObject *p} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1782 Return true if the argument is a tuple object. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1783 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1784 |
| 7782 | 1785 \begin{cfuncdesc}{PyObject*}{PyTuple_New}{int s} |
| 7308 | 1786 Return a new tuple object of size \var{s}. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1787 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1788 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1789 \begin{cfuncdesc}{int}{PyTuple_Size}{PyTupleObject *p} |
| 7308 | 1790 Takes a pointer to a tuple object, and returns the size |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1791 of that tuple. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1792 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1793 |
| 7782 | 1794 \begin{cfuncdesc}{PyObject*}{PyTuple_GetItem}{PyTupleObject *p, int pos} |
| 7308 | 1795 Returns the object at position \var{pos} in the tuple pointed |
| 1796 to by \var{p}. If \var{pos} is out of bounds, returns \NULL{} and | |
| 1797 raises an \exception{IndexError} exception. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1798 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1799 |
| 7782 | 1800 \begin{cfuncdesc}{PyObject*}{PyTuple_GET_ITEM}{PyTupleObject *p, int pos} |
| 7308 | 1801 Does the same, but does no checking of its arguments. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1802 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1803 |
| 7782 | 1804 \begin{cfuncdesc}{PyObject*}{PyTuple_GetSlice}{PyTupleObject *p, |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1805 int low, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1806 int high} |
| 7308 | 1807 Takes a slice of the tuple pointed to by \var{p} from |
| 1808 \var{low} to \var{high} and returns it as a new tuple. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1809 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1810 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1811 \begin{cfuncdesc}{int}{PyTuple_SetItem}{PyTupleObject *p, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1812 int pos, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1813 PyObject *o} |
| 7308 | 1814 Inserts a reference to object \var{o} at position \var{pos} of |
| 1815 the tuple pointed to by \var{p}. It returns \code{0} on success. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1816 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1817 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1818 \begin{cfuncdesc}{void}{PyTuple_SET_ITEM}{PyTupleObject *p, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1819 int pos, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1820 PyObject *o} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1821 |
| 7308 | 1822 Does the same, but does no error checking, and |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1823 should \emph{only} be used to fill in brand new tuples. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1824 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1825 |
| 7782 | 1826 \begin{cfuncdesc}{int}{_PyTuple_Resize}{PyTupleObject *p, |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1827 int new, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1828 int last_is_sticky} |
| 7308 | 1829 Can be used to resize a tuple. Because tuples are |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1830 \emph{supposed} to be immutable, this should only be used if there is only |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1831 one module referencing the object. Do \emph{not} use this if the tuple may |
| 7308 | 1832 already be known to some other part of the code. \var{last_is_sticky} is |
| 1833 a flag --- if set, the tuple will grow or shrink at the front, otherwise | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1834 it will grow or shrink at the end. Think of this as destroying the old |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1835 tuple and creating a new one, only more efficiently. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1836 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1837 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1838 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1839 \subsection{List Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1840 \label{listObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1841 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1842 \begin{ctypedesc}{PyListObject} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1843 This subtype of \code{PyObject} represents a Python list object. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1844 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1845 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1846 \begin{cvardesc}{PyTypeObject}{PyList_Type} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1847 This instance of \code{PyTypeObject} represents the Python list type. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1848 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1849 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1850 \begin{cfuncdesc}{int}{PyList_Check}{PyObject *p} |
| 7308 | 1851 Returns true if its argument is a \code{PyListObject}. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1852 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1853 |
| 7782 | 1854 \begin{cfuncdesc}{PyObject*}{PyList_New}{int size} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1855 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1856 |
| 7782 | 1857 \begin{cfuncdesc}{int}{PyList_Size}{PyObject *list} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1858 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1859 |
| 7782 | 1860 \begin{cfuncdesc}{PyObject*}{PyList_GetItem}{PyObject *list, int index} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1861 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1862 |
| 7782 | 1863 \begin{cfuncdesc}{int}{PyList_SetItem}{PyObject *list, int index, |
| 1864 PyObject *item} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1865 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1866 |
| 7782 | 1867 \begin{cfuncdesc}{int}{PyList_Insert}{PyObject *list, int index, |
| 1868 PyObject *index} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1869 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1870 |
| 7782 | 1871 \begin{cfuncdesc}{int}{PyList_Append}{PyObject *list, PyObject *item} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1872 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1873 |
| 7782 | 1874 \begin{cfuncdesc}{PyObject*}{PyList_GetSlice}{PyObject *list, |
| 1875 int low, int high} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1876 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1877 |
| 7782 | 1878 \begin{cfuncdesc}{int}{PyList_SetSlice}{PyObject *list, |
| 1879 int low, int high, | |
| 1880 PyObject *itemlist} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1881 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1882 |
| 7782 | 1883 \begin{cfuncdesc}{int}{PyList_Sort}{PyObject *list} |
| 1884 \end{cfuncdesc} | |
| 1885 | |
| 1886 \begin{cfuncdesc}{int}{PyList_Reverse}{PyObject *list} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1887 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1888 |
| 7782 | 1889 \begin{cfuncdesc}{PyObject*}{PyList_AsTuple}{PyObject *list} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1890 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1891 |
| 7782 | 1892 \begin{cfuncdesc}{PyObject*}{PyList_GET_ITEM}{PyObject *list, int i} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1893 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1894 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1895 \begin{cfuncdesc}{int}{PyList_GET_SIZE}{PyObject *list} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1896 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1897 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1898 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1899 \section{Mapping Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1900 \label{mapObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1901 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1902 \subsection{Dictionary Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1903 \label{dictObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1904 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1905 \begin{ctypedesc}{PyDictObject} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1906 This subtype of \code{PyObject} represents a Python dictionary object. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1907 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1908 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1909 \begin{cvardesc}{PyTypeObject}{PyDict_Type} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1910 This instance of \code{PyTypeObject} represents the Python dictionary type. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1911 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1912 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1913 \begin{cfuncdesc}{int}{PyDict_Check}{PyObject *p} |
| 7308 | 1914 Returns true if its argument is a \code{PyDictObject}. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1915 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1916 |
| 7782 | 1917 \begin{cfuncdesc}{PyObject*}{PyDict_New}{} |
| 7308 | 1918 Returns a new empty dictionary. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1919 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1920 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1921 \begin{cfuncdesc}{void}{PyDict_Clear}{PyDictObject *p} |
| 7308 | 1922 Empties an existing dictionary of all key/value pairs. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1923 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1924 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1925 \begin{cfuncdesc}{int}{PyDict_SetItem}{PyDictObject *p, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1926 PyObject *key, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1927 PyObject *val} |
| 7308 | 1928 Inserts \var{value} into the dictionary with a key of \var{key}. Both |
| 1929 \var{key} and \var{value} should be PyObjects, and \var{key} should be | |
| 1930 hashable. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1931 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1932 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1933 \begin{cfuncdesc}{int}{PyDict_SetItemString}{PyDictObject *p, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1934 char *key, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1935 PyObject *val} |
| 7308 | 1936 Inserts \var{value} into the dictionary using \var{key} |
| 1937 as a key. \var{key} should be a \code{char *}. The key object is | |
| 1938 created using \code{PyString_FromString(\var{key})}. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1939 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1940 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1941 \begin{cfuncdesc}{int}{PyDict_DelItem}{PyDictObject *p, PyObject *key} |
| 7308 | 1942 Removes the entry in dictionary \var{p} with key \var{key}. |
| 1943 \var{key} is a PyObject. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1944 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1945 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1946 \begin{cfuncdesc}{int}{PyDict_DelItemString}{PyDictObject *p, char *key} |
| 7308 | 1947 Removes the entry in dictionary \var{p} which has a key |
| 1948 specified by the \code{char *}\var{key}. | |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1949 \end{cfuncdesc} |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1950 |
| 7782 | 1951 \begin{cfuncdesc}{PyObject*}{PyDict_GetItem}{PyDictObject *p, PyObject *key} |
| 7308 | 1952 Returns the object from dictionary \var{p} which has a key |
| 1953 \var{key}. Returns \NULL{} if the key \var{key} is not present. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1954 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1955 |
| 7782 | 1956 \begin{cfuncdesc}{PyObject*}{PyDict_GetItemString}{PyDictObject *p, char *key} |
| 7308 | 1957 Does the same, but \var{key} is specified as a |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1958 \code{char *}, rather than a \code{PyObject *}. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1959 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1960 |
| 7782 | 1961 \begin{cfuncdesc}{PyObject*}{PyDict_Items}{PyDictObject *p} |
| 7308 | 1962 Returns a \code{PyListObject} containing all the items |
| 1963 from the dictionary, as in the mapping method \method{items()} (see | |
| 1964 the \emph{Python Library Reference}). | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1965 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1966 |
| 7782 | 1967 \begin{cfuncdesc}{PyObject*}{PyDict_Keys}{PyDictObject *p} |
| 7308 | 1968 Returns a \code{PyListObject} containing all the keys |
| 1969 from the dictionary, as in the mapping method \method{keys()} (see the | |
| 1970 \emph{Python Library Reference}). | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1971 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1972 |
| 7782 | 1973 \begin{cfuncdesc}{PyObject*}{PyDict_Values}{PyDictObject *p} |
| 7308 | 1974 Returns a \code{PyListObject} containing all the values |
| 1975 from the dictionary \var{p}, as in the mapping method | |
| 1976 \method{values()} (see the \emph{Python Library Reference}). | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1977 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1978 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1979 \begin{cfuncdesc}{int}{PyDict_Size}{PyDictObject *p} |
| 7308 | 1980 Returns the number of items in the dictionary. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1981 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1982 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1983 \begin{cfuncdesc}{int}{PyDict_Next}{PyDictObject *p, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1984 int ppos, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1985 PyObject **pkey, |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1986 PyObject **pvalue} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1987 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1988 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1989 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1990 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1991 \section{Numeric Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1992 \label{numericObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1993 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1994 \subsection{Plain Integer Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
1995 \label{intObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1996 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1997 \begin{ctypedesc}{PyIntObject} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1998 This subtype of \code{PyObject} represents a Python integer object. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
1999 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2000 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2001 \begin{cvardesc}{PyTypeObject}{PyInt_Type} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2002 This instance of \code{PyTypeObject} represents the Python plain |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2003 integer type. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2004 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2005 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2006 \begin{cfuncdesc}{int}{PyInt_Check}{PyObject *} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2007 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2008 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2009 |
| 7782 | 2010 \begin{cfuncdesc}{PyObject*}{PyInt_FromLong}{long ival} |
| 7308 | 2011 Creates a new integer object with a value of \var{ival}. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2012 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2013 The current implementation keeps an array of integer objects for all |
| 7308 | 2014 integers between \code{-1} and \code{100}, when you create an int in |
| 2015 that range you actually just get back a reference to the existing | |
| 2016 object. So it should be possible to change the value of \code{1}. I | |
|
7807
5d15f4fd6d69
Capitalize "Python" for consistency.
Fred Drake <fdrake@acm.org>
parents:
7782
diff
changeset
|
2017 suspect the behaviour of Python in this case is undefined. :-) |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2018 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2019 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2020 \begin{cfuncdesc}{long}{PyInt_AS_LONG}{PyIntObject *io} |
| 7308 | 2021 Returns the value of the object \var{io}. No error checking is |
| 2022 performed. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2023 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2024 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2025 \begin{cfuncdesc}{long}{PyInt_AsLong}{PyObject *io} |
| 7308 | 2026 Will first attempt to cast the object to a \code{PyIntObject}, if |
| 2027 it is not already one, and then return its value. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2028 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2029 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2030 \begin{cfuncdesc}{long}{PyInt_GetMax}{} |
| 7308 | 2031 Returns the systems idea of the largest integer it can handle |
| 2032 (\constant{LONG_MAX}, as defined in the system header files). | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2033 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2034 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2035 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2036 \subsection{Long Integer Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
2037 \label{longObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2038 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2039 \begin{ctypedesc}{PyLongObject} |
| 7308 | 2040 This subtype of \code{PyObject} represents a Python long integer |
| 2041 object. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2042 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2043 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2044 \begin{cvardesc}{PyTypeObject}{PyLong_Type} |
| 7308 | 2045 This instance of \code{PyTypeObject} represents the Python long |
| 2046 integer type. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2047 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2048 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2049 \begin{cfuncdesc}{int}{PyLong_Check}{PyObject *p} |
| 7308 | 2050 Returns true if its argument is a \code{PyLongObject}. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2051 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2052 |
| 7782 | 2053 \begin{cfuncdesc}{PyObject*}{PyLong_FromLong}{long v} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2054 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2055 |
| 7782 | 2056 \begin{cfuncdesc}{PyObject*}{PyLong_FromUnsignedLong}{unsigned long v} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2057 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2058 |
| 7782 | 2059 \begin{cfuncdesc}{PyObject*}{PyLong_FromDouble}{double v} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2060 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2061 |
| 7782 | 2062 \begin{cfuncdesc}{long}{PyLong_AsLong}{PyObject *pylong} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2063 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2064 |
| 7782 | 2065 \begin{cfuncdesc}{unsigned long}{PyLong_AsUnsignedLong}{PyObject *pylong} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2066 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2067 |
| 7782 | 2068 \begin{cfuncdesc}{double}{PyLong_AsDouble}{PyObject *pylong} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2069 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2070 |
| 7782 | 2071 \begin{cfuncdesc}{PyObject*}{PyLong_FromString}{char *str, char **pend, |
| 2072 int base} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2073 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2074 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2075 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2076 \subsection{Floating Point Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
2077 \label{floatObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2078 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2079 \begin{ctypedesc}{PyFloatObject} |
| 7308 | 2080 This subtype of \code{PyObject} represents a Python floating point |
| 2081 object. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2082 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2083 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2084 \begin{cvardesc}{PyTypeObject}{PyFloat_Type} |
| 7308 | 2085 This instance of \code{PyTypeObject} represents the Python floating |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2086 point type. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2087 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2088 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2089 \begin{cfuncdesc}{int}{PyFloat_Check}{PyObject *p} |
| 7308 | 2090 Returns true if its argument is a \code{PyFloatObject}. |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2091 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2092 |
| 7782 | 2093 \begin{cfuncdesc}{PyObject*}{PyFloat_FromDouble}{double v} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2094 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2095 |
| 7782 | 2096 \begin{cfuncdesc}{double}{PyFloat_AsDouble}{PyObject *pyfloat} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2097 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2098 |
| 7782 | 2099 \begin{cfuncdesc}{double}{PyFloat_AS_DOUBLE}{PyObject *pyfloat} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2100 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2101 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2102 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2103 \subsection{Complex Number Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
2104 \label{complexObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2105 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2106 \begin{ctypedesc}{Py_complex} |
|
7310
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2107 The \C{} structure which corresponds to the value portion of a Python |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2108 complex number object. Most of the functions for dealing with complex |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2109 number objects use structures of this type as input or output values, |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2110 as appropriate. It is defined as: |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2111 |
| 7308 | 2112 \begin{verbatim} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2113 typedef struct { |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2114 double real; |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2115 double imag; |
|
7310
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2116 } Py_complex; |
| 7308 | 2117 \end{verbatim} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2118 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2119 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2120 \begin{ctypedesc}{PyComplexObject} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2121 This subtype of \code{PyObject} represents a Python complex number object. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2122 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2123 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2124 \begin{cvardesc}{PyTypeObject}{PyComplex_Type} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2125 This instance of \code{PyTypeObject} represents the Python complex |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2126 number type. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2127 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2128 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2129 \begin{cfuncdesc}{int}{PyComplex_Check}{PyObject *p} |
| 7308 | 2130 Returns true if its argument is a \code{PyComplexObject}. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2131 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2132 |
| 7782 | 2133 \begin{cfuncdesc}{Py_complex}{_Py_c_sum}{Py_complex left, Py_complex right} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2134 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2135 |
| 7782 | 2136 \begin{cfuncdesc}{Py_complex}{_Py_c_diff}{Py_complex left, Py_complex right} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2137 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2138 |
| 7782 | 2139 \begin{cfuncdesc}{Py_complex}{_Py_c_neg}{Py_complex complex} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2140 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2141 |
| 7782 | 2142 \begin{cfuncdesc}{Py_complex}{_Py_c_prod}{Py_complex left, Py_complex right} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2143 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2144 |
| 7782 | 2145 \begin{cfuncdesc}{Py_complex}{_Py_c_quot}{Py_complex dividend, |
| 2146 Py_complex divisor} | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2147 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2148 |
| 7782 | 2149 \begin{cfuncdesc}{Py_complex}{_Py_c_pow}{Py_complex num, Py_complex exp} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2150 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2151 |
| 7782 | 2152 \begin{cfuncdesc}{PyObject*}{PyComplex_FromCComplex}{Py_complex v} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2153 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2154 |
| 7782 | 2155 \begin{cfuncdesc}{PyObject*}{PyComplex_FromDoubles}{double real, double imag} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2156 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2157 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2158 \begin{cfuncdesc}{double}{PyComplex_RealAsDouble}{PyObject *op} |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2159 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2160 |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2161 \begin{cfuncdesc}{double}{PyComplex_ImagAsDouble}{PyObject *op} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2162 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2163 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2164 \begin{cfuncdesc}{Py_complex}{PyComplex_AsCComplex}{PyObject *op} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2165 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2166 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2167 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2168 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2169 \section{Other Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
2170 \label{otherObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2171 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2172 \subsection{File Objects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
2173 \label{fileObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2174 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2175 \begin{ctypedesc}{PyFileObject} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2176 This subtype of \code{PyObject} represents a Python file object. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2177 \end{ctypedesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2178 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2179 \begin{cvardesc}{PyTypeObject}{PyFile_Type} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2180 This instance of \code{PyTypeObject} represents the Python file type. |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2181 \end{cvardesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2182 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2183 \begin{cfuncdesc}{int}{PyFile_Check}{PyObject *p} |
| 7308 | 2184 Returns true if its argument is a \code{PyFileObject}. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2185 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2186 |
| 7782 | 2187 \begin{cfuncdesc}{PyObject*}{PyFile_FromString}{char *name, char *mode} |
| 7308 | 2188 Creates a new \code{PyFileObject} pointing to the file |
| 2189 specified in \var{name} with the mode specified in \var{mode}. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2190 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2191 |
| 7782 | 2192 \begin{cfuncdesc}{PyObject*}{PyFile_FromFile}{FILE *fp, |
|
7467
0360e3e30a2e
PyFile_FromFile() description: make sure the closing brace for the arguments
Fred Drake <fdrake@acm.org>
parents:
7422
diff
changeset
|
2193 char *name, char *mode, int (*close)} |
| 7308 | 2194 Creates a new \code{PyFileObject} from the already-open \var{fp}. |
| 2195 The function \var{close} will be called when the file should be | |
| 2196 closed. | |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2197 \end{cfuncdesc} |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2198 |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2199 \begin{cfuncdesc}{FILE *}{PyFile_AsFile}{PyFileObject *p} |
| 7308 | 2200 Returns the file object associated with \var{p} as a \code{FILE *}. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2201 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2202 |
| 7782 | 2203 \begin{cfuncdesc}{PyObject*}{PyFile_GetLine}{PyObject *p, int n} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2204 undocumented as yet |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2205 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2206 |
| 7782 | 2207 \begin{cfuncdesc}{PyObject*}{PyFile_Name}{PyObject *p} |
| 7308 | 2208 Returns the name of the file specified by \var{p} as a |
| 2209 \code{PyStringObject}. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2210 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2211 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2212 \begin{cfuncdesc}{void}{PyFile_SetBufSize}{PyFileObject *p, int n} |
| 7308 | 2213 Available on systems with \cfunction{setvbuf()} only. This should |
| 2214 only be called immediately after file object creation. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2215 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2216 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2217 \begin{cfuncdesc}{int}{PyFile_SoftSpace}{PyFileObject *p, int newflag} |
| 7308 | 2218 Sets the \code{softspace} attribute of \var{p} to \var{newflag}. |
| 7782 | 2219 Returns the previous value. This function clears any errors, and will |
| 7308 | 2220 return \code{0} as the previous value if the attribute either does not |
| 2221 exist or if there were errors in retrieving it. There is no way to | |
| 2222 detect errors from this function, but doing so should not be needed. | |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2223 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2224 |
| 7782 | 2225 \begin{cfuncdesc}{int}{PyFile_WriteObject}{PyObject *obj, PyFileObject *p, |
| 2226 int flags} | |
| 7308 | 2227 Writes object \var{obj} to file object \var{p}. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2228 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2229 |
| 7782 | 2230 \begin{cfuncdesc}{int}{PyFile_WriteString}{char *s, PyFileObject *p, |
| 2231 int flags} | |
| 7308 | 2232 Writes string \var{s} to file object \var{p}. |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2233 \end{cfuncdesc} |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2234 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2235 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2236 \subsection{CObjects} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
2237 \label{cObjects} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2238 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2239 XXX |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2240 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2241 |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2242 \chapter{Initialization, Finalization, and Threads} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
2243 \label{initialization} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2244 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2245 \begin{cfuncdesc}{void}{Py_Initialize}{} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2246 Initialize the Python interpreter. In an application embedding |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2247 Python, this should be called before using any other Python/C API |
| 7308 | 2248 functions; with the exception of \cfunction{Py_SetProgramName()}, |
| 2249 \cfunction{PyEval_InitThreads()}, \cfunction{PyEval_ReleaseLock()}, | |
| 2250 and \cfunction{PyEval_AcquireLock()}. This initializes the table of | |
| 2251 loaded modules (\code{sys.modules}), and creates the fundamental | |
|
7310
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2252 modules \module{__builtin__}\refbimodindex{__builtin__}, |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2253 \module{__main__}\refbimodindex{__main__} and |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2254 \module{sys}\refbimodindex{sys}. It also initializes the module |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2255 search path (\code{sys.path}).% |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2256 \indexiii{module}{search}{path} |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2257 It does not set \code{sys.argv}; use \cfunction{PySys_SetArgv()} for |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2258 that. This is a no-op when called for a second time (without calling |
| 7308 | 2259 \cfunction{Py_Finalize()} first). There is no return value; it is a |
| 2260 fatal error if the initialization fails. | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
2261 \end{cfuncdesc} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
2262 |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
2263 \begin{cfuncdesc}{int}{Py_IsInitialized}{} |
|
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
2264 Return true (nonzero) when the Python interpreter has been |
| 7308 | 2265 initialized, false (zero) if not. After \cfunction{Py_Finalize()} is |
| 2266 called, this returns false until \cfunction{Py_Initialize()} is called | |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
2267 again. |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2268 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2269 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2270 \begin{cfuncdesc}{void}{Py_Finalize}{} |
| 7308 | 2271 Undo all initializations made by \cfunction{Py_Initialize()} and |
| 2272 subsequent use of Python/C API functions, and destroy all | |
| 2273 sub-interpreters (see \cfunction{Py_NewInterpreter()} below) that were | |
| 2274 created and not yet destroyed since the last call to | |
| 2275 \cfunction{Py_Initialize()}. Ideally, this frees all memory allocated | |
| 2276 by the Python interpreter. This is a no-op when called for a second | |
| 2277 time (without calling \cfunction{Py_Initialize()} again first). There | |
| 2278 is no return value; errors during finalization are ignored. | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2279 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2280 This function is provided for a number of reasons. An embedding |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2281 application might want to restart Python without having to restart the |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2282 application itself. An application that has loaded the Python |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2283 interpreter from a dynamically loadable library (or DLL) might want to |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2284 free all memory allocated by Python before unloading the DLL. During a |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2285 hunt for memory leaks in an application a developer might want to free |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2286 all memory allocated by Python before exiting from the application. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2287 |
| 7308 | 2288 \strong{Bugs and caveats:} The destruction of modules and objects in |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2289 modules is done in random order; this may cause destructors |
| 7308 | 2290 (\method{__del__()} methods) to fail when they depend on other objects |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2291 (even functions) or modules. Dynamically loaded extension modules |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2292 loaded by Python are not unloaded. Small amounts of memory allocated |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2293 by the Python interpreter may not be freed (if you find a leak, please |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2294 report it). Memory tied up in circular references between objects is |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2295 not freed. Some memory allocated by extension modules may not be |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2296 freed. Some extension may not work properly if their initialization |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2297 routine is called more than once; this can happen if an applcation |
| 7308 | 2298 calls \cfunction{Py_Initialize()} and \cfunction{Py_Finalize()} more |
| 2299 than once. | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2300 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2301 |
| 7782 | 2302 \begin{cfuncdesc}{PyThreadState*}{Py_NewInterpreter}{} |
|
7310
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2303 Create a new sub-interpreter. This is an (almost) totally separate |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2304 environment for the execution of Python code. In particular, the new |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2305 interpreter has separate, independent versions of all imported |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2306 modules, including the fundamental modules |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2307 \module{__builtin__}\refbimodindex{__builtin__}, |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2308 \module{__main__}\refbimodindex{__main__} and |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2309 \module{sys}\refbimodindex{sys}. The table of loaded modules |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2310 (\code{sys.modules}) and the module search path (\code{sys.path}) are |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2311 also separate. The new environment has no \code{sys.argv} variable. |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2312 It has new standard I/O stream file objects \code{sys.stdin}, |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2313 \code{sys.stdout} and \code{sys.stderr} (however these refer to the |
| 7081 | 2314 same underlying \code{FILE} structures in the \C{} library). |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2315 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2316 The return value points to the first thread state created in the new |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2317 sub-interpreter. This thread state is made the current thread state. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2318 Note that no actual thread is created; see the discussion of thread |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2319 states below. If creation of the new interpreter is unsuccessful, |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
2320 \NULL{} is returned; no exception is set since the exception state |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2321 is stored in the current thread state and there may not be a current |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2322 thread state. (Like all other Python/C API functions, the global |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2323 interpreter lock must be held before calling this function and is |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2324 still held when it returns; however, unlike most other Python/C API |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2325 functions, there needn't be a current thread state on entry.) |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2326 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2327 Extension modules are shared between (sub-)interpreters as follows: |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2328 the first time a particular extension is imported, it is initialized |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2329 normally, and a (shallow) copy of its module's dictionary is |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2330 squirreled away. When the same extension is imported by another |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2331 (sub-)interpreter, a new module is initialized and filled with the |
| 7308 | 2332 contents of this copy; the extension's \code{init} function is not |
| 2333 called. Note that this is different from what happens when an | |
| 2334 extension is imported after the interpreter has been completely | |
| 2335 re-initialized by calling \cfunction{Py_Finalize()} and | |
| 2336 \cfunction{Py_Initialize()}; in that case, the extension's \code{init} | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2337 function \emph{is} called again. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2338 |
| 7308 | 2339 \strong{Bugs and caveats:} Because sub-interpreters (and the main |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2340 interpreter) are part of the same process, the insulation between them |
| 7308 | 2341 isn't perfect --- for example, using low-level file operations like |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2342 \code{os.close()} they can (accidentally or maliciously) affect each |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2343 other's open files. Because of the way extensions are shared between |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2344 (sub-)interpreters, some extensions may not work properly; this is |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2345 especially likely when the extension makes use of (static) global |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2346 variables, or when the extension manipulates its module's dictionary |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2347 after its initialization. It is possible to insert objects created in |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2348 one sub-interpreter into a namespace of another sub-interpreter; this |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2349 should be done with great care to avoid sharing user-defined |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2350 functions, methods, instances or classes between sub-interpreters, |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2351 since import operations executed by such objects may affect the |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2352 wrong (sub-)interpreter's dictionary of loaded modules. (XXX This is |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2353 a hard-to-fix bug that will be addressed in a future release.) |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2354 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2355 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2356 \begin{cfuncdesc}{void}{Py_EndInterpreter}{PyThreadState *tstate} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2357 Destroy the (sub-)interpreter represented by the given thread state. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2358 The given thread state must be the current thread state. See the |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2359 discussion of thread states below. When the call returns, the current |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
2360 thread state is \NULL{}. All thread states associated with this |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2361 interpreted are destroyed. (The global interpreter lock must be held |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2362 before calling this function and is still held when it returns.) |
| 7308 | 2363 \cfunction{Py_Finalize()} will destroy all sub-interpreters that haven't |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2364 been explicitly destroyed at that point. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2365 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2366 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2367 \begin{cfuncdesc}{void}{Py_SetProgramName}{char *name} |
| 7308 | 2368 This function should be called before \cfunction{Py_Initialize()} is called |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2369 for the first time, if it is called at all. It tells the interpreter |
| 7308 | 2370 the value of the \code{argv[0]} argument to the \cfunction{main()} function |
| 2371 of the program. This is used by \cfunction{Py_GetPath()} and some other | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2372 functions below to find the Python run-time libraries relative to the |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2373 interpreter executable. The default value is \code{"python"}. The |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2374 argument should point to a zero-terminated character string in static |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2375 storage whose contents will not change for the duration of the |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2376 program's execution. No code in the Python interpreter will change |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2377 the contents of this storage. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2378 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2379 |
| 7782 | 2380 \begin{cfuncdesc}{char*}{Py_GetProgramName}{} |
| 7308 | 2381 Return the program name set with \cfunction{Py_SetProgramName()}, or the |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2382 default. The returned string points into static storage; the caller |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2383 should not modify its value. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2384 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2385 |
| 7782 | 2386 \begin{cfuncdesc}{char*}{Py_GetPrefix}{} |
| 7308 | 2387 Return the \emph{prefix} for installed platform-independent files. This |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2388 is derived through a number of complicated rules from the program name |
| 7308 | 2389 set with \cfunction{Py_SetProgramName()} and some environment variables; |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2390 for example, if the program name is \code{"/usr/local/bin/python"}, |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2391 the prefix is \code{"/usr/local"}. The returned string points into |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2392 static storage; the caller should not modify its value. This |
|
8021
3b91affa333e
In descriptions of Py_GetPrefix() and Py_GetExecPrefix(), make sure the
Fred Drake <fdrake@acm.org>
parents:
7923
diff
changeset
|
2393 corresponds to the \makevar{prefix} variable in the top-level |
|
3b91affa333e
In descriptions of Py_GetPrefix() and Py_GetExecPrefix(), make sure the
Fred Drake <fdrake@acm.org>
parents:
7923
diff
changeset
|
2394 \file{Makefile} and the \code{-}\code{-prefix} argument to the |
| 7308 | 2395 \program{configure} script at build time. The value is available to |
| 7081 | 2396 Python code as \code{sys.prefix}. It is only useful on \UNIX{}. See |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2397 also the next function. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2398 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2399 |
| 7782 | 2400 \begin{cfuncdesc}{char*}{Py_GetExecPrefix}{} |
| 7308 | 2401 Return the \emph{exec-prefix} for installed platform-\emph{de}pendent |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2402 files. This is derived through a number of complicated rules from the |
| 7308 | 2403 program name set with \cfunction{Py_SetProgramName()} and some environment |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2404 variables; for example, if the program name is |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2405 \code{"/usr/local/bin/python"}, the exec-prefix is |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2406 \code{"/usr/local"}. The returned string points into static storage; |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2407 the caller should not modify its value. This corresponds to the |
|
8021
3b91affa333e
In descriptions of Py_GetPrefix() and Py_GetExecPrefix(), make sure the
Fred Drake <fdrake@acm.org>
parents:
7923
diff
changeset
|
2408 \makevar{exec_prefix} variable in the top-level \file{Makefile} and the |
|
3b91affa333e
In descriptions of Py_GetPrefix() and Py_GetExecPrefix(), make sure the
Fred Drake <fdrake@acm.org>
parents:
7923
diff
changeset
|
2409 \code{-}\code{-exec_prefix} argument to the \program{configure} script |
|
3b91affa333e
In descriptions of Py_GetPrefix() and Py_GetExecPrefix(), make sure the
Fred Drake <fdrake@acm.org>
parents:
7923
diff
changeset
|
2410 at build time. The value is available to Python code as |
| 7081 | 2411 \code{sys.exec_prefix}. It is only useful on \UNIX{}. |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2412 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2413 Background: The exec-prefix differs from the prefix when platform |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2414 dependent files (such as executables and shared libraries) are |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2415 installed in a different directory tree. In a typical installation, |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2416 platform dependent files may be installed in the |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2417 \code{"/usr/local/plat"} subtree while platform independent may be |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2418 installed in \code{"/usr/local"}. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2419 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2420 Generally speaking, a platform is a combination of hardware and |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2421 software families, e.g. Sparc machines running the Solaris 2.x |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2422 operating system are considered the same platform, but Intel machines |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2423 running Solaris 2.x are another platform, and Intel machines running |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2424 Linux are yet another platform. Different major revisions of the same |
| 7081 | 2425 operating system generally also form different platforms. Non-\UNIX{} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2426 operating systems are a different story; the installation strategies |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2427 on those systems are so different that the prefix and exec-prefix are |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2428 meaningless, and set to the empty string. Note that compiled Python |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2429 bytecode files are platform independent (but not independent from the |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2430 Python version by which they were compiled!). |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2431 |
| 7308 | 2432 System administrators will know how to configure the \program{mount} or |
| 2433 \program{automount} programs to share \code{"/usr/local"} between platforms | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2434 while having \code{"/usr/local/plat"} be a different filesystem for each |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2435 platform. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2436 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2437 |
| 7782 | 2438 \begin{cfuncdesc}{char*}{Py_GetProgramFullPath}{} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2439 Return the full program name of the Python executable; this is |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2440 computed as a side-effect of deriving the default module search path |
| 7308 | 2441 from the program name (set by \cfunction{Py_SetProgramName()} above). The |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2442 returned string points into static storage; the caller should not |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2443 modify its value. The value is available to Python code as |
|
6382
16cd39805fd5
Checkpoint. Added docs for the new exception handling APIs and for
Guido van Rossum <guido@python.org>
parents:
6126
diff
changeset
|
2444 \code{sys.executable}. |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2445 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2446 |
| 7782 | 2447 \begin{cfuncdesc}{char*}{Py_GetPath}{} |
|
7310
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2448 \indexiii{module}{search}{path} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2449 Return the default module search path; this is computed from the |
| 7308 | 2450 program name (set by \cfunction{Py_SetProgramName()} above) and some |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2451 environment variables. The returned string consists of a series of |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2452 directory names separated by a platform dependent delimiter character. |
| 7271 | 2453 The delimiter character is \code{':'} on \UNIX{}, \code{';'} on |
| 2454 DOS/Windows, and \code{'\\n'} (the \ASCII{} newline character) on | |
| 2455 Macintosh. The returned string points into static storage; the caller | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2456 should not modify its value. The value is available to Python code |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2457 as the list \code{sys.path}, which may be modified to change the |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2458 future search path for loaded modules. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2459 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2460 % XXX should give the exact rules |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2461 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2462 |
| 7782 | 2463 \begin{cfuncdesc}{const char*}{Py_GetVersion}{} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2464 Return the version of this Python interpreter. This is a string that |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2465 looks something like |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2466 |
|
6074
5e5e54a6dba6
Fixes to make it pass latex without complaints.
Guido van Rossum <guido@python.org>
parents:
6041
diff
changeset
|
2467 \begin{verbatim} |
| 7308 | 2468 "1.5 (#67, Dec 31 1997, 22:34:28) [GCC 2.7.2.2]" |
|
6074
5e5e54a6dba6
Fixes to make it pass latex without complaints.
Guido van Rossum <guido@python.org>
parents:
6041
diff
changeset
|
2469 \end{verbatim} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2470 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2471 The first word (up to the first space character) is the current Python |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2472 version; the first three characters are the major and minor version |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2473 separated by a period. The returned string points into static storage; |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2474 the caller should not modify its value. The value is available to |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2475 Python code as the list \code{sys.version}. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2476 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2477 |
| 7782 | 2478 \begin{cfuncdesc}{const char*}{Py_GetPlatform}{} |
| 7081 | 2479 Return the platform identifier for the current platform. On \UNIX{}, |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2480 this is formed from the ``official'' name of the operating system, |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2481 converted to lower case, followed by the major revision number; e.g., |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2482 for Solaris 2.x, which is also known as SunOS 5.x, the value is |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2483 \code{"sunos5"}. On Macintosh, it is \code{"mac"}. On Windows, it |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2484 is \code{"win"}. The returned string points into static storage; |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2485 the caller should not modify its value. The value is available to |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2486 Python code as \code{sys.platform}. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2487 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2488 |
| 7782 | 2489 \begin{cfuncdesc}{const char*}{Py_GetCopyright}{} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2490 Return the official copyright string for the current Python version, |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2491 for example |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2492 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2493 \code{"Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam"} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2494 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2495 The returned string points into static storage; the caller should not |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2496 modify its value. The value is available to Python code as the list |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2497 \code{sys.copyright}. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2498 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2499 |
| 7782 | 2500 \begin{cfuncdesc}{const char*}{Py_GetCompiler}{} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2501 Return an indication of the compiler used to build the current Python |
| 7308 | 2502 version, in square brackets, for example: |
| 2503 | |
| 2504 \begin{verbatim} | |
| 2505 "[GCC 2.7.2.2]" | |
| 2506 \end{verbatim} | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2507 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2508 The returned string points into static storage; the caller should not |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2509 modify its value. The value is available to Python code as part of |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2510 the variable \code{sys.version}. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2511 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2512 |
| 7782 | 2513 \begin{cfuncdesc}{const char*}{Py_GetBuildInfo}{} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2514 Return information about the sequence number and build date and time |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2515 of the current Python interpreter instance, for example |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2516 |
|
6074
5e5e54a6dba6
Fixes to make it pass latex without complaints.
Guido van Rossum <guido@python.org>
parents:
6041
diff
changeset
|
2517 \begin{verbatim} |
|
5e5e54a6dba6
Fixes to make it pass latex without complaints.
Guido van Rossum <guido@python.org>
parents:
6041
diff
changeset
|
2518 "#67, Aug 1 1997, 22:34:28" |
|
5e5e54a6dba6
Fixes to make it pass latex without complaints.
Guido van Rossum <guido@python.org>
parents:
6041
diff
changeset
|
2519 \end{verbatim} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2520 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2521 The returned string points into static storage; the caller should not |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2522 modify its value. The value is available to Python code as part of |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2523 the variable \code{sys.version}. |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2524 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2525 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2526 \begin{cfuncdesc}{int}{PySys_SetArgv}{int argc, char **argv} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2527 % XXX |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2528 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2529 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2530 % XXX Other PySys thingies (doesn't really belong in this chapter) |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2531 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2532 \section{Thread State and the Global Interpreter Lock} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
2533 \label{threads} |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2534 |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2535 The Python interpreter is not fully thread safe. In order to support |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2536 multi-threaded Python programs, there's a global lock that must be |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2537 held by the current thread before it can safely access Python objects. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2538 Without the lock, even the simplest operations could cause problems in |
|
7422
2d508822e7f6
Fixed typo reported by Vladimir Marangozov <Vladimir.Marangozov@imag.fr>.
Fred Drake <fdrake@acm.org>
parents:
7314
diff
changeset
|
2539 a multi-threaded program: for example, when two threads simultaneously |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2540 increment the reference count of the same object, the reference count |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2541 could end up being incremented only once instead of twice. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2542 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2543 Therefore, the rule exists that only the thread that has acquired the |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2544 global interpreter lock may operate on Python objects or call Python/C |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2545 API functions. In order to support multi-threaded Python programs, |
| 7308 | 2546 the interpreter regularly release and reacquires the lock --- by |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2547 default, every ten bytecode instructions (this can be changed with |
| 7308 | 2548 \function{sys.setcheckinterval()}). The lock is also released and |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2549 reacquired around potentially blocking I/O operations like reading or |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2550 writing a file, so that other threads can run while the thread that |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2551 requests the I/O is waiting for the I/O operation to complete. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2552 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2553 The Python interpreter needs to keep some bookkeeping information |
| 7308 | 2554 separate per thread --- for this it uses a data structure called |
| 2555 \code{PyThreadState}. This is new in Python 1.5; in earlier versions, | |
| 2556 such state was stored in global variables, and switching threads could | |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2557 cause problems. In particular, exception handling is now thread safe, |
| 7308 | 2558 when the application uses \function{sys.exc_info()} to access the |
| 2559 exception last raised in the current thread. | |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2560 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2561 There's one global variable left, however: the pointer to the current |
| 7308 | 2562 \code{PyThreadState} structure. While most thread packages have a way |
|
7314
d23bb969e63a
Removed various "(New in 1.5a?!)" constructs. Other notes pertaining to
Fred Drake <fdrake@acm.org>
parents:
7310
diff
changeset
|
2563 to store ``per-thread global data,'' Python's internal platform |
| 7308 | 2564 independent thread abstraction doesn't support this yet. Therefore, |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2565 the current thread state must be manipulated explicitly. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2566 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2567 This is easy enough in most cases. Most code manipulating the global |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2568 interpreter lock has the following simple structure: |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2569 |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
2570 \begin{verbatim} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2571 Save the thread state in a local variable. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2572 Release the interpreter lock. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2573 ...Do some blocking I/O operation... |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2574 Reacquire the interpreter lock. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2575 Restore the thread state from the local variable. |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
2576 \end{verbatim} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2577 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2578 This is so common that a pair of macros exists to simplify it: |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2579 |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
2580 \begin{verbatim} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2581 Py_BEGIN_ALLOW_THREADS |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2582 ...Do some blocking I/O operation... |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2583 Py_END_ALLOW_THREADS |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
2584 \end{verbatim} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2585 |
| 7308 | 2586 The \code{Py_BEGIN_ALLOW_THREADS} macro opens a new block and declares |
| 2587 a hidden local variable; the \code{Py_END_ALLOW_THREADS} macro closes | |
| 2588 the block. Another advantage of using these two macros is that when | |
| 2589 Python is compiled without thread support, they are defined empty, | |
| 2590 thus saving the thread state and lock manipulations. | |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2591 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2592 When thread support is enabled, the block above expands to the |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2593 following code: |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2594 |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
2595 \begin{verbatim} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2596 { |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2597 PyThreadState *_save; |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2598 _save = PyEval_SaveThread(); |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2599 ...Do some blocking I/O operation... |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2600 PyEval_RestoreThread(_save); |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2601 } |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
2602 \end{verbatim} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2603 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2604 Using even lower level primitives, we can get roughly the same effect |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2605 as follows: |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2606 |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
2607 \begin{verbatim} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2608 { |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2609 PyThreadState *_save; |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2610 _save = PyThreadState_Swap(NULL); |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2611 PyEval_ReleaseLock(); |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2612 ...Do some blocking I/O operation... |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2613 PyEval_AcquireLock(); |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2614 PyThreadState_Swap(_save); |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2615 } |
|
6417
4491f84ac223
Change title to {Python/C API Reference Manual}; remove \bcode \ecode
Guido van Rossum <guido@python.org>
parents:
6390
diff
changeset
|
2616 \end{verbatim} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2617 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2618 There are some subtle differences; in particular, |
| 7308 | 2619 \cfunction{PyEval_RestoreThread()} saves and restores the value of the |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2620 global variable \code{errno}, since the lock manipulation does not |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2621 guarantee that \code{errno} is left alone. Also, when thread support |
| 7308 | 2622 is disabled, \cfunction{PyEval_SaveThread()} and |
| 2623 \cfunction{PyEval_RestoreThread()} don't manipulate the lock; in this | |
| 2624 case, \cfunction{PyEval_ReleaseLock()} and | |
| 2625 \cfunction{PyEval_AcquireLock()} are not available. This is done so | |
| 2626 that dynamically loaded extensions compiled with thread support | |
| 2627 enabled can be loaded by an interpreter that was compiled with | |
| 2628 disabled thread support. | |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2629 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2630 The global interpreter lock is used to protect the pointer to the |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2631 current thread state. When releasing the lock and saving the thread |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2632 state, the current thread state pointer must be retrieved before the |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2633 lock is released (since another thread could immediately acquire the |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2634 lock and store its own thread state in the global variable). |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2635 Reversely, when acquiring the lock and restoring the thread state, the |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2636 lock must be acquired before storing the thread state pointer. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2637 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2638 Why am I going on with so much detail about this? Because when |
| 7081 | 2639 threads are created from \C{}, they don't have the global interpreter |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2640 lock, nor is there a thread state data structure for them. Such |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2641 threads must bootstrap themselves into existence, by first creating a |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2642 thread state data structure, then acquiring the lock, and finally |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2643 storing their thread state pointer, before they can start using the |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2644 Python/C API. When they are done, they should reset the thread state |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2645 pointer, release the lock, and finally free their thread state data |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2646 structure. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2647 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2648 When creating a thread data structure, you need to provide an |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2649 interpreter state data structure. The interpreter state data |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2650 structure hold global data that is shared by all threads in an |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2651 interpreter, for example the module administration |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2652 (\code{sys.modules}). Depending on your needs, you can either create |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2653 a new interpreter state data structure, or share the interpreter state |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2654 data structure used by the Python main thread (to access the latter, |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2655 you must obtain the thread state and access its \code{interp} member; |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2656 this must be done by a thread that is created by Python or by the main |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2657 thread after Python is initialized). |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2658 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2659 XXX More? |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2660 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2661 \begin{ctypedesc}{PyInterpreterState} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2662 This data structure represents the state shared by a number of |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2663 cooperating threads. Threads belonging to the same interpreter |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2664 share their module administration and a few other internal items. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2665 There are no public members in this structure. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2666 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2667 Threads belonging to different interpreters initially share nothing, |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2668 except process state like available memory, open file descriptors and |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2669 such. The global interpreter lock is also shared by all threads, |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2670 regardless of to which interpreter they belong. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2671 \end{ctypedesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2672 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2673 \begin{ctypedesc}{PyThreadState} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2674 This data structure represents the state of a single thread. The only |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2675 public data member is \code{PyInterpreterState *interp}, which points |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2676 to this thread's interpreter state. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2677 \end{ctypedesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2678 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2679 \begin{cfuncdesc}{void}{PyEval_InitThreads}{} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2680 Initialize and acquire the global interpreter lock. It should be |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2681 called in the main thread before creating a second thread or engaging |
| 7308 | 2682 in any other thread operations such as |
| 2683 \cfunction{PyEval_ReleaseLock()} or | |
| 2684 \code{PyEval_ReleaseThread(\var{tstate})}. It is not needed before | |
| 2685 calling \cfunction{PyEval_SaveThread()} or | |
| 2686 \cfunction{PyEval_RestoreThread()}. | |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2687 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2688 This is a no-op when called for a second time. It is safe to call |
| 7308 | 2689 this function before calling \cfunction{Py_Initialize()}. |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2690 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2691 When only the main thread exists, no lock operations are needed. This |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2692 is a common situation (most Python programs do not use threads), and |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2693 the lock operations slow the interpreter down a bit. Therefore, the |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2694 lock is not created initially. This situation is equivalent to having |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2695 acquired the lock: when there is only a single thread, all object |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2696 accesses are safe. Therefore, when this function initializes the |
|
7310
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2697 lock, it also acquires it. Before the Python |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2698 \module{thread}\refbimodindex{thread} module creates a new thread, |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2699 knowing that either it has the lock or the lock hasn't been created |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2700 yet, it calls \cfunction{PyEval_InitThreads()}. When this call |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2701 returns, it is guaranteed that the lock has been created and that it |
|
6095a472f574
Place C typedef for Py_complex after brief description, to be more consistent
Fred Drake <fdrake@acm.org>
parents:
7309
diff
changeset
|
2702 has acquired it. |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2703 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2704 It is \strong{not} safe to call this function when it is unknown which |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2705 thread (if any) currently has the global interpreter lock. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2706 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2707 This function is not available when thread support is disabled at |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2708 compile time. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2709 \end{cfuncdesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2710 |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2711 \begin{cfuncdesc}{void}{PyEval_AcquireLock}{} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2712 Acquire the global interpreter lock. The lock must have been created |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2713 earlier. If this thread already has the lock, a deadlock ensues. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2714 This function is not available when thread support is disabled at |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2715 compile time. |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2716 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2717 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2718 \begin{cfuncdesc}{void}{PyEval_ReleaseLock}{} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2719 Release the global interpreter lock. The lock must have been created |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2720 earlier. This function is not available when thread support is |
| 7308 | 2721 disabled at compile time. |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2722 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2723 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2724 \begin{cfuncdesc}{void}{PyEval_AcquireThread}{PyThreadState *tstate} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2725 Acquire the global interpreter lock and then set the current thread |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
2726 state to \var{tstate}, which should not be \NULL{}. The lock must |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2727 have been created earlier. If this thread already has the lock, |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2728 deadlock ensues. This function is not available when thread support |
| 7308 | 2729 is disabled at compile time. |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2730 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2731 |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2732 \begin{cfuncdesc}{void}{PyEval_ReleaseThread}{PyThreadState *tstate} |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
2733 Reset the current thread state to \NULL{} and release the global |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2734 interpreter lock. The lock must have been created earlier and must be |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2735 held by the current thread. The \var{tstate} argument, which must not |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
2736 be \NULL{}, is only used to check that it represents the current |
| 7308 | 2737 thread state --- if it isn't, a fatal error is reported. This |
| 2738 function is not available when thread support is disabled at compile | |
| 2739 time. | |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2740 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2741 |
| 7782 | 2742 \begin{cfuncdesc}{PyThreadState*}{PyEval_SaveThread}{} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2743 Release the interpreter lock (if it has been created and thread |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
2744 support is enabled) and reset the thread state to \NULL{}, |
|
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
2745 returning the previous thread state (which is not \NULL{}). If |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2746 the lock has been created, the current thread must have acquired it. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2747 (This function is available even when thread support is disabled at |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2748 compile time.) |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2749 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2750 |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2751 \begin{cfuncdesc}{void}{PyEval_RestoreThread}{PyThreadState *tstate} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2752 Acquire the interpreter lock (if it has been created and thread |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2753 support is enabled) and set the thread state to \var{tstate}, which |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
2754 must not be \NULL{}. If the lock has been created, the current |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2755 thread must not have acquired it, otherwise deadlock ensues. (This |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2756 function is available even when thread support is disabled at compile |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2757 time.) |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2758 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2759 |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2760 % XXX These aren't really C types, but the ctypedesc macro is the simplest! |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2761 \begin{ctypedesc}{Py_BEGIN_ALLOW_THREADS} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2762 This macro expands to |
| 7308 | 2763 \samp{\{ PyThreadState *_save; _save = PyEval_SaveThread();}. |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2764 Note that it contains an opening brace; it must be matched with a |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2765 following \code{Py_END_ALLOW_THREADS} macro. See above for further |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2766 discussion of this macro. It is a no-op when thread support is |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2767 disabled at compile time. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2768 \end{ctypedesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2769 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2770 \begin{ctypedesc}{Py_END_ALLOW_THREADS} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2771 This macro expands to |
| 7308 | 2772 \samp{PyEval_RestoreThread(_save); \}}. |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2773 Note that it contains a closing brace; it must be matched with an |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2774 earlier \code{Py_BEGIN_ALLOW_THREADS} macro. See above for further |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2775 discussion of this macro. It is a no-op when thread support is |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2776 disabled at compile time. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2777 \end{ctypedesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2778 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2779 \begin{ctypedesc}{Py_BEGIN_BLOCK_THREADS} |
| 7308 | 2780 This macro expands to \samp{PyEval_RestoreThread(_save);} i.e. it |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2781 is equivalent to \code{Py_END_ALLOW_THREADS} without the closing |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2782 brace. It is a no-op when thread support is disabled at compile |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2783 time. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2784 \end{ctypedesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2785 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2786 \begin{ctypedesc}{Py_BEGIN_UNBLOCK_THREADS} |
| 7308 | 2787 This macro expands to \samp{_save = PyEval_SaveThread();} i.e. it is |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2788 equivalent to \code{Py_BEGIN_ALLOW_THREADS} without the opening brace |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2789 and variable declaration. It is a no-op when thread support is |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2790 disabled at compile time. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2791 \end{ctypedesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2792 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2793 All of the following functions are only available when thread support |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2794 is enabled at compile time, and must be called only when the |
|
7314
d23bb969e63a
Removed various "(New in 1.5a?!)" constructs. Other notes pertaining to
Fred Drake <fdrake@acm.org>
parents:
7310
diff
changeset
|
2795 interpreter lock has been created. |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2796 |
| 7782 | 2797 \begin{cfuncdesc}{PyInterpreterState*}{PyInterpreterState_New}{} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2798 Create a new interpreter state object. The interpreter lock must be |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2799 held. |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2800 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2801 |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2802 \begin{cfuncdesc}{void}{PyInterpreterState_Clear}{PyInterpreterState *interp} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2803 Reset all information in an interpreter state object. The interpreter |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2804 lock must be held. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2805 \end{cfuncdesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2806 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2807 \begin{cfuncdesc}{void}{PyInterpreterState_Delete}{PyInterpreterState *interp} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2808 Destroy an interpreter state object. The interpreter lock need not be |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2809 held. The interpreter state must have been reset with a previous |
| 7308 | 2810 call to \cfunction{PyInterpreterState_Clear()}. |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2811 \end{cfuncdesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2812 |
| 7782 | 2813 \begin{cfuncdesc}{PyThreadState*}{PyThreadState_New}{PyInterpreterState *interp} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2814 Create a new thread state object belonging to the given interpreter |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2815 object. The interpreter lock must be held. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2816 \end{cfuncdesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2817 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2818 \begin{cfuncdesc}{void}{PyThreadState_Clear}{PyThreadState *tstate} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2819 Reset all information in a thread state object. The interpreter lock |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2820 must be held. |
|
6041
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2821 \end{cfuncdesc} |
|
a9e1ea80ea3f
Added more stuff on initialization (still rudimentary)
Guido van Rossum <guido@python.org>
parents:
6040
diff
changeset
|
2822 |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2823 \begin{cfuncdesc}{void}{PyThreadState_Delete}{PyThreadState *tstate} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2824 Destroy a thread state object. The interpreter lock need not be |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2825 held. The thread state must have been reset with a previous |
| 7308 | 2826 call to \cfunction{PyThreadState_Clear()}. |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2827 \end{cfuncdesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2828 |
| 7782 | 2829 \begin{cfuncdesc}{PyThreadState*}{PyThreadState_Get}{} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2830 Return the current thread state. The interpreter lock must be held. |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
2831 When the current thread state is \NULL{}, this issues a fatal |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
2832 error (so that the caller needn't check for \NULL{}). |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2833 \end{cfuncdesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2834 |
| 7782 | 2835 \begin{cfuncdesc}{PyThreadState*}{PyThreadState_Swap}{PyThreadState *tstate} |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2836 Swap the current thread state with the thread state given by the |
|
6653
c6c1d133677a
Several changes, e.g. restructuring of the intro to be closer to what
Guido van Rossum <guido@python.org>
parents:
6480
diff
changeset
|
2837 argument \var{tstate}, which may be \NULL{}. The interpreter lock |
|
6390
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2838 must be held. |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2839 \end{cfuncdesc} |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2840 |
|
a2df3c9e5f43
Done with tread state descriptions. Sigh!
Guido van Rossum <guido@python.org>
parents:
6382
diff
changeset
|
2841 |
| 7308 | 2842 \chapter{Defining New Object Types} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
2843 \label{newTypes} |
| 7308 | 2844 |
| 7782 | 2845 \begin{cfuncdesc}{PyObject*}{_PyObject_New}{PyTypeObject *type} |
| 7308 | 2846 \end{cfuncdesc} |
| 2847 | |
| 7782 | 2848 \begin{cfuncdesc}{PyObject*}{_PyObject_NewVar}{PyTypeObject *type, int size} |
| 7308 | 2849 \end{cfuncdesc} |
| 2850 | |
| 2851 \begin{cfuncdesc}{TYPE}{_PyObject_NEW}{TYPE, PyTypeObject *} | |
| 2852 \end{cfuncdesc} | |
| 2853 | |
| 2854 \begin{cfuncdesc}{TYPE}{_PyObject_NEW_VAR}{TYPE, PyTypeObject *, int size} | |
| 2855 \end{cfuncdesc} | |
| 2856 | |
|
5588
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2857 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2858 PyObject, PyVarObject |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2859 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2860 PyObject_HEAD, PyObject_HEAD_INIT, PyObject_VAR_HEAD |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2861 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2862 Typedefs: |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2863 unaryfunc, binaryfunc, ternaryfunc, inquiry, coercion, intargfunc, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2864 intintargfunc, intobjargproc, intintobjargproc, objobjargproc, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2865 getreadbufferproc, getwritebufferproc, getsegcountproc, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2866 destructor, printfunc, getattrfunc, getattrofunc, setattrfunc, |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2867 setattrofunc, cmpfunc, reprfunc, hashfunc |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2868 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2869 PyNumberMethods |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2870 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2871 PySequenceMethods |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2872 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2873 PyMappingMethods |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2874 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2875 PyBufferProcs |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2876 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2877 PyTypeObject |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2878 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2879 DL_IMPORT |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2880 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2881 PyType_Type |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2882 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2883 Py*_Check |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2884 |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2885 Py_None, _Py_NoneStruct |
|
53cdf94b652b
Just another checkin for backup. Nothing substantial yet.
Guido van Rossum <guido@python.org>
parents:
5536
diff
changeset
|
2886 |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2887 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2888 \chapter{Debugging} |
|
7493
6857acbe2e74
Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents:
7467
diff
changeset
|
2889 \label{debugging} |
|
7269
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2890 |
|
682d3e5b267f
Reorganized a bit. No changed content.
Fred Drake <fdrake@acm.org>
parents:
7268
diff
changeset
|
2891 XXX Explain Py_DEBUG, Py_TRACE_REFS, Py_REF_DEBUG. |
|
6991
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
2892 |
|
f349bf0e9322
A whole bunch of typos fixed by Andrew Kuchling.
Guido van Rossum <guido@python.org>
parents:
6653
diff
changeset
|
2893 |
|
7708
4991aaab17bd
Revert the index stuff to work better with LaTeX2HTML.
Fred Drake <fdrake@acm.org>
parents:
7620
diff
changeset
|
2894 \input{api.ind} % Index -- must be last |
|
5536
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2895 |
|
c6f04e965508
Made a start with api.tex, the Python-C API Reference Manual.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2896 \end{document} |
