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