Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 1 | \documentstyle[twoside,11pt,myformat]{report} |
| 2 | |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 3 | \title{Python-C API Reference} |
| 4 | |
| 5 | \input{boilerplate} |
| 6 | |
| 7 | \makeindex % tell \index to actually write the .idx file |
| 8 | |
| 9 | |
| 10 | \begin{document} |
| 11 | |
| 12 | \pagenumbering{roman} |
| 13 | |
| 14 | \maketitle |
| 15 | |
| 16 | \input{copyright} |
| 17 | |
| 18 | \begin{abstract} |
| 19 | |
| 20 | \noindent |
| 21 | This manual documents the API used by C (or C++) programmers who want |
| 22 | to write extension modules or embed Python. It is a companion to |
| 23 | ``Extending and Embedding the Python Interpreter'', which describes |
| 24 | the general principles of extension writing but does not document the |
| 25 | API functions in detail. |
| 26 | |
| 27 | \end{abstract} |
| 28 | |
| 29 | \pagebreak |
| 30 | |
| 31 | { |
| 32 | \parskip = 0mm |
| 33 | \tableofcontents |
| 34 | } |
| 35 | |
| 36 | \pagebreak |
| 37 | |
| 38 | \pagenumbering{arabic} |
| 39 | |
| 40 | |
| 41 | \chapter{Introduction} |
| 42 | |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 43 | The Application Programmer's Interface to Python gives C and C++ |
| 44 | programmers access to the Python interpreter at a variety of levels. |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 45 | There are two fundamentally different reasons for using the Python/C |
| 46 | API. (The API is equally usable from C++, but for brevity it is |
| 47 | generally referred to as the Python/C API.) The first reason is to |
| 48 | write ``extension modules'' for specific purposes; these are C modules |
| 49 | that extend the Python interpreter. This is probably the most common |
| 50 | use. The second reason is to use Python as a component in a larger |
| 51 | application; this technique is generally referred to as ``embedding'' |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 52 | Python in an application. |
| 53 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 54 | Writing an extension module is a relatively well-understood process, |
| 55 | where a ``cookbook'' approach works well. There are several tools |
| 56 | that automate the process to some extent. While people have embedded |
| 57 | Python in other applications since its early existence, the process of |
| 58 | embedding Python is less straightforward that writing an extension. |
| 59 | Python 1.5 introduces a number of new API functions as well as some |
| 60 | changes to the build process that make embedding much simpler. |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 61 | This manual describes the 1.5 state of affair (as of Python 1.5a3). |
| 62 | % XXX Eventually, take the historical notes out |
| 63 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 64 | Many API functions are useful independent of whether you're embedding |
| 65 | or extending Python; moreover, most applications that embed Python |
| 66 | will need to provide a custom extension as well, so it's probably a |
| 67 | good idea to become familiar with writing an extension before |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 68 | attempting to embed Python in a real application. |
| 69 | |
| 70 | \section{Objects, Types and Reference Counts} |
| 71 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 72 | Most Python/C API functions have one or more arguments as well as a |
| 73 | return value of type \code{PyObject *}. This type is a pointer |
| 74 | (obviously!) to an opaque data type representing an arbitrary Python |
| 75 | object. Since all Python object types are treated the same way by the |
| 76 | Python language in most situations (e.g., assignments, scope rules, |
| 77 | and argument passing), it is only fitting that they should be |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 78 | represented by a single C type. All Python objects live on the heap: |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 79 | you never declare an automatic or static variable of type |
| 80 | \code{PyObject}, only pointer variables of type \code{PyObject *} can |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 81 | be declared. |
| 82 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 83 | All Python objects (even Python integers) have a ``type'' and a |
| 84 | ``reference count''. An object's type determines what kind of object |
| 85 | it is (e.g., an integer, a list, or a user-defined function; there are |
| 86 | many more as explained in the Python Language Reference Manual). For |
| 87 | each of the well-known types there is a macro to check whether an |
| 88 | object is of that type; for instance, \code{PyList_Check(a)} is true |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 89 | iff the object pointed to by \code{a} is a Python list. |
| 90 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 91 | The reference count is important only because today's computers have a |
| 92 | finite (and often severly limited) memory size; it counts how many |
| 93 | different places there are that have a reference to an object. Such a |
| 94 | place could be another object, or a global (or static) C variable, or |
| 95 | a local variable in some C function. When an object's reference count |
| 96 | becomes zero, the object is deallocated. If it contains references to |
| 97 | other objects, their reference count is decremented. Those other |
| 98 | objects may be deallocated in turn, if this decrement makes their |
| 99 | reference count become zero, and so on. (There's an obvious problem |
| 100 | with objects that reference each other here; for now, the solution is |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 101 | ``don't do that''.) |
| 102 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 103 | Reference counts are always manipulated explicitly. The normal way is |
| 104 | to use the macro \code{Py_INCREF(a)} to increment an object's |
| 105 | reference count by one, and \code{Py_DECREF(a)} to decrement it by |
| 106 | one. The latter macro is considerably more complex than the former, |
| 107 | since it must check whether the reference count becomes zero and then |
| 108 | cause the object's deallocator, which is a function pointer contained |
| 109 | in the object's type structure. The type-specific deallocator takes |
| 110 | care of decrementing the reference counts for other objects contained |
| 111 | in the object, and so on, if this is a compound object type such as a |
| 112 | list. There's no chance that the reference count can overflow; at |
| 113 | least as many bits are used to hold the reference count as there are |
| 114 | distinct memory locations in virtual memory (assuming |
| 115 | \code{sizeof(long) >= sizeof(char *)}). Thus, the reference count |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 116 | increment is a simple operation. |
| 117 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 118 | It is not necessary to increment an object's reference count for every |
| 119 | local variable that contains a pointer to an object. In theory, the |
| 120 | oject's reference count goes up by one when the variable is made to |
| 121 | point to it and it goes down by one when the variable goes out of |
| 122 | scope. However, these two cancel each other out, so at the end the |
| 123 | reference count hasn't changed. The only real reason to use the |
| 124 | reference count is to prevent the object from being deallocated as |
| 125 | long as our variable is pointing to it. If we know that there is at |
| 126 | least one other reference to the object that lives at least as long as |
| 127 | our variable, there is no need to increment the reference count |
| 128 | temporarily. An important situation where this arises is in objects |
| 129 | that are passed as arguments to C functions in an extension module |
| 130 | that are called from Python; the call mechanism guarantees to hold a |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 131 | reference to every argument for the duration of the call. |
| 132 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 133 | However, a common pitfall is to extract an object from a list and |
| 134 | holding on to it for a while without incrementing its reference count. |
| 135 | Some other operation might conceivably remove the object from the |
| 136 | list, decrementing its reference count and possible deallocating it. |
| 137 | The real danger is that innocent-looking operations may invoke |
| 138 | arbitrary Python code which could do this; there is a code path which |
| 139 | allows control to flow back to the user from a \code{Py_DECREF()}, so |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 140 | almost any operation is potentially dangerous. |
| 141 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 142 | A safe approach is to always use the generic operations (functions |
| 143 | whose name begins with \code{PyObject_}, \code{PyNumber_}, |
| 144 | \code{PySequence_} or \code{PyMapping_}). These operations always |
| 145 | increment the reference count of the object they return. This leaves |
| 146 | the caller with the responsibility to call \code{Py_DECREF()} when |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 147 | they are done with the result; this soon becomes second nature. |
| 148 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 149 | There are very few other data types that play a significant role in |
| 150 | the Python/C API; most are all simple C types such as \code{int}, |
| 151 | \code{long}, \code{double} and \code{char *}. A few structure types |
| 152 | are used to describe static tables used to list the functions exported |
| 153 | by a module or the data attributes of a new object type. These will |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 154 | be discussed together with the functions that use them. |
| 155 | |
| 156 | \section{Exceptions} |
| 157 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 158 | The Python programmer only needs to deal with exceptions if specific |
| 159 | error handling is required; unhandled exceptions are automatically |
| 160 | propagated to the caller, then to the caller's caller, and so on, till |
| 161 | they reach the top-level interpreter, where they are reported to the |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 162 | user accompanied by a stack trace. |
| 163 | |
| 164 | For C programmers, however, error checking always has to be explicit. |
| 165 | % XXX add more stuff here |
| 166 | |
| 167 | \section{Embedding Python} |
| 168 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 169 | The one important task that only embedders of the Python interpreter |
| 170 | have to worry about is the initialization (and possibly the |
| 171 | finalization) of the Python interpreter. Most functionality of the |
| 172 | interpreter can only be used after the interpreter has been |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 173 | initialized. |
| 174 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 175 | The basic initialization function is \code{Py_Initialize()}. This |
| 176 | initializes the table of loaded modules, and creates the fundamental |
| 177 | modules \code{__builtin__}, \code{__main__} and \code{sys}. It also |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 178 | initializes the module search path (\code{sys.path}). |
| 179 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 180 | \code{Py_Initialize()} does not set the ``script argument list'' |
| 181 | (\code{sys.argv}). If this variable is needed by Python code that |
| 182 | will be executed later, it must be set explicitly with a call to |
| 183 | \code{PySys_SetArgv(\var{argc}, \var{argv})} subsequent to the call |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 184 | to \code{Py_Initialize()}. |
| 185 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 186 | On Unix, \code{Py_Initialize()} calculates the module search path |
| 187 | based upon its best guess for the location of the standard Python |
| 188 | interpreter executable, assuming that the Python library is found in a |
| 189 | fixed location relative to the Python interpreter executable. In |
| 190 | particular, it looks for a directory named \code{lib/python1.5} |
| 191 | (replacing \code{1.5} with the current interpreter version) relative |
| 192 | to the parent directory where the executable named \code{python} is |
| 193 | found on the shell command search path (the environment variable |
| 194 | \code{$PATH}). For instance, if the Python executable is found in |
| 195 | \code{/usr/local/bin/python}, it will assume that the libraries are in |
| 196 | \code{/usr/local/lib/python1.5}. In fact, this also the ``fallback'' |
| 197 | location, used when no executable file named \code{python} is found |
| 198 | along \code{\$PATH}. The user can change this behavior by setting the |
| 199 | environment variable \code{\$PYTHONHOME}, and can insert additional |
| 200 | directories in front of the standard path by setting |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 201 | \code{\$PYTHONPATH}. |
| 202 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 203 | The embedding application can steer the search by calling |
| 204 | \code{Py_SetProgramName(\var{file})} \emph{before} calling |
| 205 | \code{Py_Initialize()}. Note that \code[$PYTHONHOME} still overrides |
| 206 | this and \code{\$PYTHONPATH} is still inserted in front of the |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 207 | standard path. |
| 208 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 209 | Sometimes, it is desirable to ``uninitialize'' Python. For instance, |
| 210 | the application may want to start over (make another call to |
| 211 | \code{Py_Initialize()}) or the application is simply done with its |
| 212 | use of Python and wants to free all memory allocated by Python. This |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 213 | can be accomplished by calling \code{Py_Finalize()}. |
| 214 | % XXX More... |
| 215 | |
| 216 | \section{Embedding Python in Threaded Applications} |
| 217 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 226 | |
| 227 | \chapter{Old Introduction} |
| 228 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 229 | (XXX This is the old introduction, mostly by Jim Fulton -- should be |
| 230 | rewritten.) |
| 231 | |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 232 | From the viewpoint of of C access to Python services, we have: |
| 233 | |
| 234 | \begin{enumerate} |
| 235 | |
| 236 | \item "Very high level layer": two or three functions that let you |
| 237 | exec or eval arbitrary Python code given as a string in a module whose |
| 238 | name is given, passing C values in and getting C values out using |
| 239 | mkvalue/getargs style format strings. This does not require the user |
| 240 | to declare any variables of type \code{PyObject *}. This should be |
| 241 | enough to write a simple application that gets Python code from the |
| 242 | user, execs it, and returns the output or errors. |
| 243 | |
| 244 | \item "Abstract objects layer": which is the subject of this chapter. |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 245 | It has many functions operating on objects, and lets you do many |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 246 | things from C that you can also write in Python, without going through |
| 247 | the Python parser. |
| 248 | |
| 249 | \item "Concrete objects layer": This is the public type-dependent |
| 250 | interface provided by the standard built-in types, such as floats, |
| 251 | strings, and lists. This interface exists and is currently documented |
| 252 | by the collection of include files provides with the Python |
| 253 | distributions. |
| 254 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 255 | \end{enumerate} |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 256 | |
| 257 | From the point of view of Python accessing services provided by C |
| 258 | modules: |
| 259 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 260 | \begin{enumerate} |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 261 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 262 | \item[4.] "Python module interface": this interface consist of the basic |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 263 | routines used to define modules and their members. Most of the |
| 264 | current extensions-writing guide deals with this interface. |
| 265 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 266 | \item[5.] "Built-in object interface": this is the interface that a new |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 267 | built-in type must provide and the mechanisms and rules that a |
| 268 | developer of a new built-in type must use and follow. |
| 269 | |
| 270 | \end{enumerate} |
| 271 | |
| 272 | The Python C API provides four groups of operations on objects, |
| 273 | corresponding to the same operations in the Python language: object, |
| 274 | numeric, sequence, and mapping. Each protocol consists of a |
| 275 | collection of related operations. If an operation that is not |
| 276 | provided by a particular type is invoked, then the standard exception |
| 277 | \code{TypeError} is raised with a operation name as an argument. |
| 278 | |
| 279 | In addition, for convenience this interface defines a set of |
| 280 | constructors for building objects of built-in types. This is needed |
| 281 | so new objects can be returned from C functions that otherwise treat |
| 282 | objects generically. |
| 283 | |
| 284 | \section{Reference Counting} |
| 285 | |
| 286 | For most of the functions in the Python-C API, if a function retains a |
| 287 | reference to a Python object passed as an argument, then the function |
| 288 | will increase the reference count of the object. It is unnecessary |
| 289 | for the caller to increase the reference count of an argument in |
| 290 | anticipation of the object's retention. |
| 291 | |
| 292 | Usually, Python objects returned from functions should be treated as |
| 293 | new objects. Functions that return objects assume that the caller |
| 294 | will retain a reference and the reference count of the object has |
| 295 | already been incremented to account for this fact. A caller that does |
| 296 | not retain a reference to an object that is returned from a function |
| 297 | must decrement the reference count of the object (using |
| 298 | \code{Py_DECREF()}) to prevent memory leaks. |
| 299 | |
| 300 | Exceptions to these rules will be noted with the individual functions. |
| 301 | |
| 302 | \section{Include Files} |
| 303 | |
| 304 | All function, type and macro definitions needed to use the Python-C |
| 305 | API are included in your code by the following line: |
| 306 | |
| 307 | \code{\#include "Python.h"} |
| 308 | |
| 309 | This implies inclusion of the following standard header files: |
| 310 | stdio.h, string.h, errno.h, and stdlib.h (if available). |
| 311 | |
| 312 | All user visible names defined by Python.h (except those defined by |
| 313 | the included standard headers) have one of the prefixes \code{Py} or |
| 314 | \code{_Py}. Names beginning with \code{_Py} are for internal use |
| 315 | only. |
| 316 | |
| 317 | |
| 318 | \chapter{Initialization and Shutdown of an Embedded Python Interpreter} |
| 319 | |
| 320 | When embedding the Python interpreter in a C or C++ program, the |
| 321 | interpreter must be initialized. |
| 322 | |
| 323 | \begin{cfuncdesc}{void}{PyInitialize}{} |
| 324 | This function initializes the interpreter. It must be called before |
| 325 | any interaction with the interpreter takes place. If it is called |
| 326 | more than once, the second and further calls have no effect. |
| 327 | |
| 328 | The function performs the following tasks: create an environment in |
| 329 | which modules can be imported and Python code can be executed; |
| 330 | initialize the \code{__builtin__} module; initialize the \code{sys} |
| 331 | module; initialize \code{sys.path}; initialize signal handling; and |
| 332 | create the empty \code{__main__} module. |
| 333 | |
| 334 | In the current system, there is no way to undo all these |
| 335 | initializations or to create additional interpreter environments. |
| 336 | \end{cfuncdesc} |
| 337 | |
| 338 | \begin{cfuncdesc}{int}{Py_AtExit}{void (*func) ()} |
| 339 | Register a cleanup function to be called when Python exits. The |
| 340 | cleanup function will be called with no arguments and should return no |
| 341 | value. At most 32 cleanup functions can be registered. When the |
| 342 | registration is successful, \code{Py_AtExit} returns 0; on failure, it |
| 343 | returns -1. Each cleanup function will be called t most once. The |
| 344 | cleanup function registered last is called first. |
| 345 | \end{cfuncdesc} |
| 346 | |
| 347 | \begin{cfuncdesc}{void}{Py_Exit}{int status} |
| 348 | Exit the current process. This calls \code{Py_Cleanup()} (see next |
| 349 | item) and performs additional cleanup (under some circumstances it |
| 350 | will attempt to delete all modules), and then calls the standard C |
| 351 | library function \code{exit(status)}. |
| 352 | \end{cfuncdesc} |
| 353 | |
| 354 | \begin{cfuncdesc}{void}{Py_Cleanup}{} |
| 355 | Perform some of the cleanup that \code{Py_Exit} performs, but don't |
| 356 | exit the process. In particular, this invokes the user's |
| 357 | \code{sys.exitfunc} function (if defined at all), and it invokes the |
| 358 | cleanup functions registered with \code{Py_AtExit()}, in reverse order |
| 359 | of their registration. |
| 360 | \end{cfuncdesc} |
| 361 | |
| 362 | \begin{cfuncdesc}{void}{Py_FatalError}{char *message} |
| 363 | Print a fatal error message and die. No cleanup is performed. This |
| 364 | function should only be invoked when a condition is detected that |
| 365 | would make it dangerous to continue using the Python interpreter; |
| 366 | e.g., when the object administration appears to be corrupted. |
| 367 | \end{cfuncdesc} |
| 368 | |
| 369 | \begin{cfuncdesc}{void}{PyImport_Init}{} |
| 370 | Initialize the module table. For internal use only. |
| 371 | \end{cfuncdesc} |
| 372 | |
| 373 | \begin{cfuncdesc}{void}{PyImport_Cleanup}{} |
| 374 | Empty the module table. For internal use only. |
| 375 | \end{cfuncdesc} |
| 376 | |
| 377 | \begin{cfuncdesc}{void}{PyBuiltin_Init}{} |
| 378 | Initialize the \code{__builtin__} module. For internal use only. |
| 379 | \end{cfuncdesc} |
| 380 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 381 | XXX Other init functions: PyEval_InitThreads, PyOS_InitInterrupts, |
| 382 | PyMarshal_Init, PySys_Init. |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 383 | |
| 384 | \chapter{Reference Counting} |
| 385 | |
| 386 | The functions in this chapter are used for managing reference counts |
| 387 | of Python objects. |
| 388 | |
| 389 | \begin{cfuncdesc}{void}{Py_INCREF}{PyObject *o} |
| 390 | Increment the reference count for object \code{o}. The object must |
| 391 | not be \NULL{}; if you aren't sure that it isn't \NULL{}, use |
| 392 | \code{Py_XINCREF()}. |
| 393 | \end{cfuncdesc} |
| 394 | |
| 395 | \begin{cfuncdesc}{void}{Py_XINCREF}{PyObject *o} |
| 396 | Increment the reference count for object \code{o}. The object may be |
| 397 | \NULL{}, in which case the function has no effect. |
| 398 | \end{cfuncdesc} |
| 399 | |
| 400 | \begin{cfuncdesc}{void}{Py_DECREF}{PyObject *o} |
| 401 | Decrement the reference count for object \code{o}. The object must |
| 402 | not be \NULL{}; if you aren't sure that it isn't \NULL{}, use |
| 403 | \code{Py_XDECREF()}. If the reference count reaches zero, the object's |
| 404 | type's deallocation function (which must not be \NULL{}) is invoked. |
| 405 | |
| 406 | \strong{Warning:} The deallocation function can cause arbitrary Python |
| 407 | code to be invoked (e.g. when a class instance with a \code{__del__()} |
| 408 | method is deallocated). While exceptions in such code are not |
| 409 | propagated, the executed code has free access to all Python global |
| 410 | variables. This means that any object that is reachable from a global |
| 411 | variable should be in a consistent state before \code{Py_DECREF()} is |
| 412 | invoked. For example, code to delete an object from a list should |
| 413 | copy a reference to the deleted object in a temporary variable, update |
| 414 | the list data structure, and then call \code{Py_DECREF()} for the |
| 415 | temporary variable. |
| 416 | \end{cfuncdesc} |
| 417 | |
| 418 | \begin{cfuncdesc}{void}{Py_XDECREF}{PyObject *o} |
| 419 | Decrement the reference count for object \code{o}.The object may be |
| 420 | \NULL{}, in which case the function has no effect; otherwise the |
| 421 | effect is the same as for \code{Py_DECREF()}, and the same warning |
| 422 | applies. |
| 423 | \end{cfuncdesc} |
| 424 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 425 | The following functions are only for internal use: |
| 426 | \code{_Py_Dealloc}, \code{_Py_ForgetReference}, \code{_Py_NewReference}, |
| 427 | as well as the global variable \code{_Py_RefTotal}. |
| 428 | |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 429 | |
| 430 | \chapter{Exception Handling} |
| 431 | |
| 432 | The functions in this chapter will let you handle and raise Python |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 433 | exceptions. It is important to understand some of the basics of |
| 434 | Python exception handling. It works somewhat like the Unix |
| 435 | \code{errno} variable: there is a global indicator (per thread) of the |
| 436 | last error that occurred. Most functions don't clear this on success, |
| 437 | but will set it to indicate the cause of the error on failure. Most |
| 438 | functions also return an error indicator, usually \NULL{} if they are |
| 439 | supposed to return a pointer, or -1 if they return an integer |
| 440 | (exception: the \code{PyArg_Parse*()} functions return 1 for success and |
| 441 | 0 for failure). When a function must fail because of some function it |
| 442 | called failed, it generally doesn't set the error indicator; the |
| 443 | function it called already set it. |
| 444 | |
| 445 | The error indicator consists of three Python objects corresponding to |
| 446 | the Python variables \code{sys.exc_type}, \code{sys.exc_value} and |
| 447 | \code{sys.exc_traceback}. API functions exist to interact with the |
| 448 | error indicator in various ways. There is a separate error indicator |
| 449 | for each thread. |
| 450 | |
| 451 | % XXX Order of these should be more thoughtful. |
| 452 | % Either alphabetical or some kind of structure. |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 453 | |
| 454 | \begin{cfuncdesc}{void}{PyErr_Print}{} |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 455 | Print a standard traceback to \code{sys.stderr} and clear the error |
| 456 | indicator. Call this function only when the error indicator is set. |
| 457 | (Otherwise it will cause a fatal error!) |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 458 | \end{cfuncdesc} |
| 459 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 460 | \begin{cfuncdesc}{PyObject *}{PyErr_Occurred}{} |
| 461 | Test whether the error indicator is set. If set, return the exception |
| 462 | \code{type} (the first argument to the last call to one of the |
| 463 | \code{PyErr_Set*()} functions or to \code{PyErr_Restore()}). If not |
| 464 | set, return \NULL{}. You do not own a reference to the return value, |
| 465 | so you do not need to \code{Py_DECREF()} it. |
| 466 | \end{cfuncdesc} |
| 467 | |
| 468 | \begin{cfuncdesc}{void}{PyErr_Clear}{} |
| 469 | Clear the error indicator. If the error indicator is not set, there |
| 470 | is no effect. |
| 471 | \end{cfuncdesc} |
| 472 | |
| 473 | \begin{cfuncdesc}{void}{PyErr_Fetch}{PyObject **ptype, PyObject **pvalue, PyObject **ptraceback} |
| 474 | Retrieve the error indicator into three variables whose addresses are |
| 475 | passed. If the error indicator is not set, set all three variables to |
| 476 | \NULL{}. If it is set, it will be cleared and you own a reference to |
| 477 | each object retrieved. The value and traceback object may be \NULL{} |
| 478 | even when the type object is not. \strong{Note:} this function is |
| 479 | normally only used by code that needs to handle exceptions or by code |
| 480 | that needs to save and restore the error indicator temporarily. |
| 481 | \end{cfuncdesc} |
| 482 | |
| 483 | \begin{cfuncdesc}{void}{PyErr_Restore}{PyObject *type, PyObject *value, PyObject *traceback} |
| 484 | Set the error indicator from the three objects. If the error |
| 485 | indicator is already set, it is cleared first. If the objects are |
| 486 | \NULL{}, the error indicator is cleared. Do not pass a \NULL{} type |
| 487 | and non-\NULL{} value or traceback. The exception type should be a |
| 488 | string or class; if it is a class, the value should be an instance of |
| 489 | that class. Do not pass an invalid exception type or value. |
| 490 | (Violating these rules will cause subtle problems later.) This call |
| 491 | takes away a reference to each object, i.e. you must own a reference |
| 492 | to each object before the call and after the call you no longer own |
| 493 | these references. (If you don't understand this, don't use this |
| 494 | function. I warned you.) \strong{Note:} this function is normally |
| 495 | only used by code that needs to save and restore the error indicator |
| 496 | temporarily. |
| 497 | \end{cfuncdesc} |
| 498 | |
| 499 | \begin{cfuncdesc}{void}{PyErr_SetString}{PyObject *type, char *message} |
| 500 | This is the most common way to set the error indicator. The first |
| 501 | argument specifies the exception type; it is normally one of the |
| 502 | standard exceptions, e.g. \code{PyExc_RuntimeError}. You need not |
| 503 | increment its reference count. The second argument is an error |
| 504 | message; it is converted to a string object. |
| 505 | \end{cfuncdesc} |
| 506 | |
| 507 | \begin{cfuncdesc}{void}{PyErr_SetObject}{PyObject *type, PyObject *value} |
| 508 | This function is similar to \code{PyErr_SetString()} but lets you |
| 509 | specify an arbitrary Python object for the ``value'' of the exception. |
| 510 | You need not increment its reference count. |
| 511 | \end{cfuncdesc} |
| 512 | |
| 513 | \begin{cfuncdesc}{void}{PyErr_SetNone}{PyObject *type} |
| 514 | This is a shorthand for \code{PyErr_SetString(\var{type}, Py_None}. |
| 515 | \end{cfuncdesc} |
| 516 | |
| 517 | \begin{cfuncdesc}{int}{PyErr_BadArgument}{} |
| 518 | This is a shorthand for \code{PyErr_SetString(PyExc_TypeError, |
| 519 | \var{message})}, where \var{message} indicates that a built-in operation |
| 520 | was invoked with an illegal argument. It is mostly for internal use. |
| 521 | \end{cfuncdesc} |
| 522 | |
| 523 | \begin{cfuncdesc}{PyObject *}{PyErr_NoMemory}{} |
| 524 | This is a shorthand for \code{PyErr_SetNone(PyExc_MemoryError)}; it |
| 525 | returns \NULL{} so an object allocation function can write |
| 526 | \code{return PyErr_NoMemory();} when it runs out of memory. |
| 527 | \end{cfuncdesc} |
| 528 | |
| 529 | \begin{cfuncdesc}{PyObject *}{PyErr_SetFromErrno}{PyObject *type} |
| 530 | This is a convenience function to raise an exception when a C library |
| 531 | function has returned an error and set the C variable \code{errno}. |
| 532 | It constructs a tuple object whose first item is the integer |
| 533 | \code{errno} value and whose second item is the corresponding error |
| 534 | message (gotten from \code{strerror()}), and then calls |
| 535 | \code{PyErr_SetObject(\var{type}, \var{object})}. On \UNIX{}, when |
| 536 | the \code{errno} value is \code{EINTR}, indicating an interrupted |
| 537 | system call, this calls \code{PyErr_CheckSignals()}, and if that set |
| 538 | the error indicator, leaves it set to that. The function always |
| 539 | returns \NULL{}, so a wrapper function around a system call can write |
| 540 | \code{return PyErr_NoMemory();} when the system call returns an error. |
| 541 | \end{cfuncdesc} |
| 542 | |
| 543 | \begin{cfuncdesc}{void}{PyErr_BadInternalCall}{} |
| 544 | This is a shorthand for \code{PyErr_SetString(PyExc_TypeError, |
| 545 | \var{message})}, where \var{message} indicates that an internal |
| 546 | operation (e.g. a Python-C API function) was invoked with an illegal |
| 547 | argument. It is mostly for internal use. |
| 548 | \end{cfuncdesc} |
| 549 | |
| 550 | \begin{cfuncdesc}{int}{PyErr_CheckSignals}{} |
| 551 | This function interacts with Python's signal handling. It checks |
| 552 | whether a signal has been sent to the processes and if so, invokes the |
| 553 | corresponding signal handler. If the \code{signal} module is |
| 554 | supported, this can invoke a signal handler written in Python. In all |
| 555 | cases, the default effect for \code{SIGINT} is to raise the |
| 556 | \code{KeyboadInterrupt} exception. If an exception is raised the |
| 557 | error indicator is set and the function returns 1; otherwise the |
| 558 | function returns 0. The error indicator may or may not be cleared if |
| 559 | it was previously set. |
| 560 | \end{cfuncdesc} |
| 561 | |
| 562 | \begin{cfuncdesc}{void}{PyErr_SetInterrupt}{} |
| 563 | This function is obsolete (XXX or platform dependent?). It simulates |
| 564 | the effect of a \code{SIGINT} signal arriving -- the next time |
| 565 | \code{PyErr_CheckSignals()} is called, \code{KeyboadInterrupt} will be |
| 566 | raised. |
| 567 | \end{cfuncdesc} |
| 568 | |
| 569 | \section{Standard Exceptions} |
| 570 | |
| 571 | All standard Python exceptions are available as global variables whose |
| 572 | names are \code{PyExc_} followed by the Python exception name. |
| 573 | These have the type \code{PyObject *}; they are all string objects. |
| 574 | For completion, here are all the variables: |
| 575 | \code{PyExc_AccessError}, |
| 576 | \code{PyExc_AssertionError}, |
| 577 | \code{PyExc_AttributeError}, |
| 578 | \code{PyExc_EOFError}, |
| 579 | \code{PyExc_FloatingPointError}, |
| 580 | \code{PyExc_IOError}, |
| 581 | \code{PyExc_ImportError}, |
| 582 | \code{PyExc_IndexError}, |
| 583 | \code{PyExc_KeyError}, |
| 584 | \code{PyExc_KeyboardInterrupt}, |
| 585 | \code{PyExc_MemoryError}, |
| 586 | \code{PyExc_NameError}, |
| 587 | \code{PyExc_OverflowError}, |
| 588 | \code{PyExc_RuntimeError}, |
| 589 | \code{PyExc_SyntaxError}, |
| 590 | \code{PyExc_SystemError}, |
| 591 | \code{PyExc_SystemExit}, |
| 592 | \code{PyExc_TypeError}, |
| 593 | \code{PyExc_ValueError}, |
| 594 | \code{PyExc_ZeroDivisionError}. |
| 595 | |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 596 | |
| 597 | \chapter{Utilities} |
| 598 | |
| 599 | The functions in this chapter perform various utility tasks, such as |
| 600 | parsing function arguments and constructing Python values from C |
| 601 | values. |
| 602 | |
| 603 | \begin{cfuncdesc}{int}{Py_FdIsInteractive}{FILE *fp, char *filename} |
| 604 | Return true (nonzero) if the standard I/O file \code{fp} with name |
| 605 | \code{filename} is deemed interactive. This is the case for files for |
| 606 | which \code{isatty(fileno(fp))} is true. If the global flag |
| 607 | \code{Py_InteractiveFlag} is true, this function also returns true if |
| 608 | the \code{name} pointer is \NULL{} or if the name is equal to one of |
| 609 | the strings \code{"<stdin>"} or \code{"???"}. |
| 610 | \end{cfuncdesc} |
| 611 | |
| 612 | \begin{cfuncdesc}{long}{PyOS_GetLastModificationTime}{char *filename} |
| 613 | Return the time of last modification of the file \code{filename}. |
| 614 | The result is encoded in the same way as the timestamp returned by |
| 615 | the standard C library function \code{time()}. |
| 616 | \end{cfuncdesc} |
| 617 | |
| 618 | |
| 619 | \chapter{Debugging} |
| 620 | |
| 621 | XXX Explain Py_DEBUG, Py_TRACE_REFS, Py_REF_DEBUG. |
| 622 | |
| 623 | |
| 624 | \chapter{The Very High Level Layer} |
| 625 | |
| 626 | The functions in this chapter will let you execute Python source code |
| 627 | given in a file or a buffer, but they will not let you interact in a |
| 628 | more detailed way with the interpreter. |
| 629 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 630 | \begin{cfuncdesc}{int}{PyRun_AnyFile}{FILE *, char *} |
| 631 | \end{cfuncdesc} |
| 632 | |
| 633 | \begin{cfuncdesc}{int}{PyRun_SimpleString}{char *} |
| 634 | \end{cfuncdesc} |
| 635 | |
| 636 | \begin{cfuncdesc}{int}{PyRun_SimpleFile}{FILE *, char *} |
| 637 | \end{cfuncdesc} |
| 638 | |
| 639 | \begin{cfuncdesc}{int}{PyRun_InteractiveOne}{FILE *, char *} |
| 640 | \end{cfuncdesc} |
| 641 | |
| 642 | \begin{cfuncdesc}{int}{PyRun_InteractiveLoop}{FILE *, char *} |
| 643 | \end{cfuncdesc} |
| 644 | |
| 645 | \begin{cfuncdesc}{struct _node *}{PyParser_SimpleParseString}{char *, int} |
| 646 | \end{cfuncdesc} |
| 647 | |
| 648 | \begin{cfuncdesc}{struct _node *}{PyParser_SimpleParseFile}{FILE *, char *, int} |
| 649 | \end{cfuncdesc} |
| 650 | |
| 651 | \begin{cfuncdesc}{}{PyObject *PyRun}{ROTO((char *, int, PyObject *, PyObject *} |
| 652 | \end{cfuncdesc} |
| 653 | |
| 654 | \begin{cfuncdesc}{}{PyObject *PyRun}{ROTO((FILE *, char *, int, PyObject *, PyObject *} |
| 655 | \end{cfuncdesc} |
| 656 | |
| 657 | \begin{cfuncdesc}{}{PyObject *Py}{ROTO((char *, char *, int} |
| 658 | \end{cfuncdesc} |
| 659 | |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 660 | |
| 661 | \chapter{Abstract Objects Layer} |
| 662 | |
| 663 | The functions in this chapter interact with Python objects regardless |
| 664 | of their type, or with wide classes of object types (e.g. all |
| 665 | numerical types, or all sequence types). When used on object types |
| 666 | for which they do not apply, they will flag a Python exception. |
| 667 | |
| 668 | \section{Object Protocol} |
| 669 | |
| 670 | \begin{cfuncdesc}{int}{PyObject_Print}{PyObject *o, FILE *fp, int flags} |
| 671 | Print an object \code{o}, on file \code{fp}. Returns -1 on error |
| 672 | The flags argument is used to enable certain printing |
| 673 | options. The only option currently supported is \code{Py_Print_RAW}. |
| 674 | \end{cfuncdesc} |
| 675 | |
| 676 | \begin{cfuncdesc}{int}{PyObject_HasAttrString}{PyObject *o, char *attr_name} |
| 677 | Returns 1 if o has the attribute attr_name, and 0 otherwise. |
| 678 | This is equivalent to the Python expression: |
| 679 | \code{hasattr(o,attr_name)}. |
| 680 | This function always succeeds. |
| 681 | \end{cfuncdesc} |
| 682 | |
| 683 | \begin{cfuncdesc}{PyObject*}{PyObject_GetAttrString}{PyObject *o, char *attr_name} |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 684 | Retrieve an attributed named attr_name from object o. |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 685 | Returns the attribute value on success, or \NULL{} on failure. |
| 686 | This is the equivalent of the Python expression: \code{o.attr_name}. |
| 687 | \end{cfuncdesc} |
| 688 | |
| 689 | |
| 690 | \begin{cfuncdesc}{int}{PyObject_HasAttr}{PyObject *o, PyObject *attr_name} |
| 691 | Returns 1 if o has the attribute attr_name, and 0 otherwise. |
| 692 | This is equivalent to the Python expression: |
| 693 | \code{hasattr(o,attr_name)}. |
| 694 | This function always succeeds. |
| 695 | \end{cfuncdesc} |
| 696 | |
| 697 | |
| 698 | \begin{cfuncdesc}{PyObject*}{PyObject_GetAttr}{PyObject *o, PyObject *attr_name} |
| 699 | Retrieve an attributed named attr_name form object o. |
| 700 | Returns the attribute value on success, or \NULL{} on failure. |
| 701 | This is the equivalent of the Python expression: o.attr_name. |
| 702 | \end{cfuncdesc} |
| 703 | |
| 704 | |
| 705 | \begin{cfuncdesc}{int}{PyObject_SetAttrString}{PyObject *o, char *attr_name, PyObject *v} |
| 706 | Set the value of the attribute named \code{attr_name}, for object \code{o}, |
| 707 | to the value \code{v}. Returns -1 on failure. This is |
| 708 | the equivalent of the Python statement: \code{o.attr_name=v}. |
| 709 | \end{cfuncdesc} |
| 710 | |
| 711 | |
| 712 | \begin{cfuncdesc}{int}{PyObject_SetAttr}{PyObject *o, PyObject *attr_name, PyObject *v} |
| 713 | Set the value of the attribute named \code{attr_name}, for |
| 714 | object \code{o}, |
| 715 | to the value \code{v}. Returns -1 on failure. This is |
| 716 | the equivalent of the Python statement: \code{o.attr_name=v}. |
| 717 | \end{cfuncdesc} |
| 718 | |
| 719 | |
| 720 | \begin{cfuncdesc}{int}{PyObject_DelAttrString}{PyObject *o, char *attr_name} |
| 721 | Delete attribute named \code{attr_name}, for object \code{o}. Returns -1 on |
| 722 | failure. This is the equivalent of the Python |
| 723 | statement: \code{del o.attr_name}. |
| 724 | \end{cfuncdesc} |
| 725 | |
| 726 | |
| 727 | \begin{cfuncdesc}{int}{PyObject_DelAttr}{PyObject *o, PyObject *attr_name} |
| 728 | Delete attribute named \code{attr_name}, for object \code{o}. Returns -1 on |
| 729 | failure. This is the equivalent of the Python |
| 730 | statement: \code{del o.attr_name}. |
| 731 | \end{cfuncdesc} |
| 732 | |
| 733 | |
| 734 | \begin{cfuncdesc}{int}{PyObject_Cmp}{PyObject *o1, PyObject *o2, int *result} |
| 735 | Compare the values of \code{o1} and \code{o2} using a routine provided by |
| 736 | \code{o1}, if one exists, otherwise with a routine provided by \code{o2}. |
| 737 | The result of the comparison is returned in \code{result}. Returns |
| 738 | -1 on failure. This is the equivalent of the Python |
| 739 | statement: \code{result=cmp(o1,o2)}. |
| 740 | \end{cfuncdesc} |
| 741 | |
| 742 | |
| 743 | \begin{cfuncdesc}{int}{PyObject_Compare}{PyObject *o1, PyObject *o2} |
| 744 | Compare the values of \code{o1} and \code{o2} using a routine provided by |
| 745 | \code{o1}, if one exists, otherwise with a routine provided by \code{o2}. |
| 746 | Returns the result of the comparison on success. On error, |
| 747 | the value returned is undefined. This is equivalent to the |
| 748 | Python expression: \code{cmp(o1,o2)}. |
| 749 | \end{cfuncdesc} |
| 750 | |
| 751 | |
| 752 | \begin{cfuncdesc}{PyObject*}{PyObject_Repr}{PyObject *o} |
| 753 | Compute the string representation of object, \code{o}. Returns the |
| 754 | string representation on success, \NULL{} on failure. This is |
| 755 | the equivalent of the Python expression: \code{repr(o)}. |
| 756 | Called by the \code{repr()} built-in function and by reverse quotes. |
| 757 | \end{cfuncdesc} |
| 758 | |
| 759 | |
| 760 | \begin{cfuncdesc}{PyObject*}{PyObject_Str}{PyObject *o} |
| 761 | Compute the string representation of object, \code{o}. Returns the |
| 762 | string representation on success, \NULL{} on failure. This is |
| 763 | the equivalent of the Python expression: \code{str(o)}. |
| 764 | Called by the \code{str()} built-in function and by the \code{print} |
| 765 | statement. |
| 766 | \end{cfuncdesc} |
| 767 | |
| 768 | |
| 769 | \begin{cfuncdesc}{int}{PyCallable_Check}{PyObject *o} |
| 770 | Determine if the object \code{o}, is callable. Return 1 if the |
| 771 | object is callable and 0 otherwise. |
| 772 | This function always succeeds. |
| 773 | \end{cfuncdesc} |
| 774 | |
| 775 | |
| 776 | \begin{cfuncdesc}{PyObject*}{PyObject_CallObject}{PyObject *callable_object, PyObject *args} |
| 777 | Call a callable Python object \code{callable_object}, with |
| 778 | arguments given by the tuple \code{args}. If no arguments are |
| 779 | needed, then args may be \NULL{}. Returns the result of the |
| 780 | call on success, or \NULL{} on failure. This is the equivalent |
| 781 | of the Python expression: \code{apply(o, args)}. |
| 782 | \end{cfuncdesc} |
| 783 | |
| 784 | \begin{cfuncdesc}{PyObject*}{PyObject_CallFunction}{PyObject *callable_object, char *format, ...} |
| 785 | Call a callable Python object \code{callable_object}, with a |
| 786 | variable number of C arguments. The C arguments are described |
| 787 | using a mkvalue-style format string. The format may be \NULL{}, |
| 788 | indicating that no arguments are provided. Returns the |
| 789 | result of the call on success, or \NULL{} on failure. This is |
| 790 | the equivalent of the Python expression: \code{apply(o,args)}. |
| 791 | \end{cfuncdesc} |
| 792 | |
| 793 | |
| 794 | \begin{cfuncdesc}{PyObject*}{PyObject_CallMethod}{PyObject *o, char *m, char *format, ...} |
| 795 | Call the method named \code{m} of object \code{o} with a variable number of |
| 796 | C arguments. The C arguments are described by a mkvalue |
| 797 | format string. The format may be \NULL{}, indicating that no |
| 798 | arguments are provided. Returns the result of the call on |
| 799 | success, or \NULL{} on failure. This is the equivalent of the |
| 800 | Python expression: \code{o.method(args)}. |
| 801 | Note that Special method names, such as "\code{__add__}", |
| 802 | "\code{__getitem__}", and so on are not supported. The specific |
| 803 | abstract-object routines for these must be used. |
| 804 | \end{cfuncdesc} |
| 805 | |
| 806 | |
| 807 | \begin{cfuncdesc}{int}{PyObject_Hash}{PyObject *o} |
| 808 | Compute and return the hash value of an object \code{o}. On |
| 809 | failure, return -1. This is the equivalent of the Python |
| 810 | expression: \code{hash(o)}. |
| 811 | \end{cfuncdesc} |
| 812 | |
| 813 | |
| 814 | \begin{cfuncdesc}{int}{PyObject_IsTrue}{PyObject *o} |
| 815 | Returns 1 if the object \code{o} is considered to be true, and |
| 816 | 0 otherwise. This is equivalent to the Python expression: |
| 817 | \code{not not o}. |
| 818 | This function always succeeds. |
| 819 | \end{cfuncdesc} |
| 820 | |
| 821 | |
| 822 | \begin{cfuncdesc}{PyObject*}{PyObject_Type}{PyObject *o} |
| 823 | On success, returns a type object corresponding to the object |
| 824 | type of object \code{o}. On failure, returns \NULL{}. This is |
| 825 | equivalent to the Python expression: \code{type(o)}. |
| 826 | \end{cfuncdesc} |
| 827 | |
| 828 | \begin{cfuncdesc}{int}{PyObject_Length}{PyObject *o} |
| 829 | Return the length of object \code{o}. If the object \code{o} provides |
| 830 | both sequence and mapping protocols, the sequence length is |
| 831 | returned. On error, -1 is returned. This is the equivalent |
| 832 | to the Python expression: \code{len(o)}. |
| 833 | \end{cfuncdesc} |
| 834 | |
| 835 | |
| 836 | \begin{cfuncdesc}{PyObject*}{PyObject_GetItem}{PyObject *o, PyObject *key} |
| 837 | Return element of \code{o} corresponding to the object \code{key} or \NULL{} |
| 838 | on failure. This is the equivalent of the Python expression: |
| 839 | \code{o[key]}. |
| 840 | \end{cfuncdesc} |
| 841 | |
| 842 | |
| 843 | \begin{cfuncdesc}{int}{PyObject_SetItem}{PyObject *o, PyObject *key, PyObject *v} |
| 844 | Map the object \code{key} to the value \code{v}. |
| 845 | Returns -1 on failure. This is the equivalent |
| 846 | of the Python statement: \code{o[key]=v}. |
| 847 | \end{cfuncdesc} |
| 848 | |
| 849 | |
| 850 | \begin{cfuncdesc}{int}{PyObject_DelItem}{PyObject *o, PyObject *key, PyObject *v} |
| 851 | Delete the mapping for \code{key} from \code{*o}. Returns -1 |
| 852 | on failure. |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 853 | This is the equivalent of the Python statement: \code{del o[key]}. |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 854 | \end{cfuncdesc} |
| 855 | |
| 856 | |
| 857 | \section{Number Protocol} |
| 858 | |
| 859 | \begin{cfuncdesc}{int}{PyNumber_Check}{PyObject *o} |
| 860 | Returns 1 if the object \code{o} provides numeric protocols, and |
| 861 | false otherwise. |
| 862 | This function always succeeds. |
| 863 | \end{cfuncdesc} |
| 864 | |
| 865 | |
| 866 | \begin{cfuncdesc}{PyObject*}{PyNumber_Add}{PyObject *o1, PyObject *o2} |
| 867 | Returns the result of adding \code{o1} and \code{o2}, or null on failure. |
| 868 | This is the equivalent of the Python expression: \code{o1+o2}. |
| 869 | \end{cfuncdesc} |
| 870 | |
| 871 | |
| 872 | \begin{cfuncdesc}{PyObject*}{PyNumber_Subtract}{PyObject *o1, PyObject *o2} |
| 873 | Returns the result of subtracting \code{o2} from \code{o1}, or null on |
| 874 | failure. This is the equivalent of the Python expression: |
| 875 | \code{o1-o2}. |
| 876 | \end{cfuncdesc} |
| 877 | |
| 878 | |
| 879 | \begin{cfuncdesc}{PyObject*}{PyNumber_Multiply}{PyObject *o1, PyObject *o2} |
| 880 | Returns the result of multiplying \code{o1} and \code{o2}, or null on |
| 881 | failure. This is the equivalent of the Python expression: |
| 882 | \code{o1*o2}. |
| 883 | \end{cfuncdesc} |
| 884 | |
| 885 | |
| 886 | \begin{cfuncdesc}{PyObject*}{PyNumber_Divide}{PyObject *o1, PyObject *o2} |
| 887 | Returns the result of dividing \code{o1} by \code{o2}, or null on failure. |
| 888 | This is the equivalent of the Python expression: \code{o1/o2}. |
| 889 | \end{cfuncdesc} |
| 890 | |
| 891 | |
| 892 | \begin{cfuncdesc}{PyObject*}{PyNumber_Remainder}{PyObject *o1, PyObject *o2} |
| 893 | Returns the remainder of dividing \code{o1} by \code{o2}, or null on |
| 894 | failure. This is the equivalent of the Python expression: |
| 895 | \code{o1\%o2}. |
| 896 | \end{cfuncdesc} |
| 897 | |
| 898 | |
| 899 | \begin{cfuncdesc}{PyObject*}{PyNumber_Divmod}{PyObject *o1, PyObject *o2} |
| 900 | See the built-in function divmod. Returns \NULL{} on failure. |
| 901 | This is the equivalent of the Python expression: |
| 902 | \code{divmod(o1,o2)}. |
| 903 | \end{cfuncdesc} |
| 904 | |
| 905 | |
| 906 | \begin{cfuncdesc}{PyObject*}{PyNumber_Power}{PyObject *o1, PyObject *o2, PyObject *o3} |
| 907 | See the built-in function pow. Returns \NULL{} on failure. |
| 908 | This is the equivalent of the Python expression: |
| 909 | \code{pow(o1,o2,o3)}, where \code{o3} is optional. |
| 910 | \end{cfuncdesc} |
| 911 | |
| 912 | |
| 913 | \begin{cfuncdesc}{PyObject*}{PyNumber_Negative}{PyObject *o} |
| 914 | Returns the negation of \code{o} on success, or null on failure. |
| 915 | This is the equivalent of the Python expression: \code{-o}. |
| 916 | \end{cfuncdesc} |
| 917 | |
| 918 | |
| 919 | \begin{cfuncdesc}{PyObject*}{PyNumber_Positive}{PyObject *o} |
| 920 | Returns \code{o} on success, or \NULL{} on failure. |
| 921 | This is the equivalent of the Python expression: \code{+o}. |
| 922 | \end{cfuncdesc} |
| 923 | |
| 924 | |
| 925 | \begin{cfuncdesc}{PyObject*}{PyNumber_Absolute}{PyObject *o} |
| 926 | Returns the absolute value of \code{o}, or null on failure. This is |
| 927 | the equivalent of the Python expression: \code{abs(o)}. |
| 928 | \end{cfuncdesc} |
| 929 | |
| 930 | |
| 931 | \begin{cfuncdesc}{PyObject*}{PyNumber_Invert}{PyObject *o} |
| 932 | Returns the bitwise negation of \code{o} on success, or \NULL{} on |
| 933 | failure. This is the equivalent of the Python expression: |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 934 | \code{\~o}. |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 935 | \end{cfuncdesc} |
| 936 | |
| 937 | |
| 938 | \begin{cfuncdesc}{PyObject*}{PyNumber_Lshift}{PyObject *o1, PyObject *o2} |
| 939 | Returns the result of left shifting \code{o1} by \code{o2} on success, or |
| 940 | \NULL{} on failure. This is the equivalent of the Python |
| 941 | expression: \code{o1 << o2}. |
| 942 | \end{cfuncdesc} |
| 943 | |
| 944 | |
| 945 | \begin{cfuncdesc}{PyObject*}{PyNumber_Rshift}{PyObject *o1, PyObject *o2} |
| 946 | Returns the result of right shifting \code{o1} by \code{o2} on success, or |
| 947 | \NULL{} on failure. This is the equivalent of the Python |
| 948 | expression: \code{o1 >> o2}. |
| 949 | \end{cfuncdesc} |
| 950 | |
| 951 | |
| 952 | \begin{cfuncdesc}{PyObject*}{PyNumber_And}{PyObject *o1, PyObject *o2} |
| 953 | Returns the result of "anding" \code{o2} and \code{o2} on success and \NULL{} |
| 954 | on failure. This is the equivalent of the Python |
| 955 | expression: \code{o1 and o2}. |
| 956 | \end{cfuncdesc} |
| 957 | |
| 958 | |
| 959 | \begin{cfuncdesc}{PyObject*}{PyNumber_Xor}{PyObject *o1, PyObject *o2} |
| 960 | Returns the bitwise exclusive or of \code{o1} by \code{o2} on success, or |
| 961 | \NULL{} on failure. This is the equivalent of the Python |
| 962 | expression: \code{o1\^{ }o2}. |
| 963 | \end{cfuncdesc} |
| 964 | |
| 965 | \begin{cfuncdesc}{PyObject*}{PyNumber_Or}{PyObject *o1, PyObject *o2} |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 966 | Returns the result of \code{o1} and \code{o2} on success, or \NULL{} on |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 967 | failure. This is the equivalent of the Python expression: |
| 968 | \code{o1 or o2}. |
| 969 | \end{cfuncdesc} |
| 970 | |
| 971 | |
| 972 | \begin{cfuncdesc}{PyObject*}{PyNumber_Coerce}{PyObject *o1, PyObject *o2} |
| 973 | This function takes the addresses of two variables of type |
| 974 | \code{PyObject*}. |
| 975 | |
| 976 | If the objects pointed to by \code{*p1} and \code{*p2} have the same type, |
| 977 | increment their reference count and return 0 (success). |
| 978 | If the objects can be converted to a common numeric type, |
| 979 | replace \code{*p1} and \code{*p2} by their converted value (with 'new' |
| 980 | reference counts), and return 0. |
| 981 | If no conversion is possible, or if some other error occurs, |
| 982 | return -1 (failure) and don't increment the reference counts. |
| 983 | The call \code{PyNumber_Coerce(\&o1, \&o2)} is equivalent to the Python |
| 984 | statement \code{o1, o2 = coerce(o1, o2)}. |
| 985 | \end{cfuncdesc} |
| 986 | |
| 987 | |
| 988 | \begin{cfuncdesc}{PyObject*}{PyNumber_Int}{PyObject *o} |
| 989 | Returns the \code{o} converted to an integer object on success, or |
| 990 | \NULL{} on failure. This is the equivalent of the Python |
| 991 | expression: \code{int(o)}. |
| 992 | \end{cfuncdesc} |
| 993 | |
| 994 | |
| 995 | \begin{cfuncdesc}{PyObject*}{PyNumber_Long}{PyObject *o} |
| 996 | Returns the \code{o} converted to a long integer object on success, |
| 997 | or \NULL{} on failure. This is the equivalent of the Python |
| 998 | expression: \code{long(o)}. |
| 999 | \end{cfuncdesc} |
| 1000 | |
| 1001 | |
| 1002 | \begin{cfuncdesc}{PyObject*}{PyNumber_Float}{PyObject *o} |
| 1003 | Returns the \code{o} converted to a float object on success, or \NULL{} |
| 1004 | on failure. This is the equivalent of the Python expression: |
| 1005 | \code{float(o)}. |
| 1006 | \end{cfuncdesc} |
| 1007 | |
| 1008 | |
| 1009 | \section{Sequence protocol} |
| 1010 | |
| 1011 | \begin{cfuncdesc}{int}{PySequence_Check}{PyObject *o} |
| 1012 | Return 1 if the object provides sequence protocol, and 0 |
| 1013 | otherwise. |
| 1014 | This function always succeeds. |
| 1015 | \end{cfuncdesc} |
| 1016 | |
| 1017 | |
| 1018 | \begin{cfuncdesc}{PyObject*}{PySequence_Concat}{PyObject *o1, PyObject *o2} |
| 1019 | Return the concatination of \code{o1} and \code{o2} on success, and \NULL{} on |
| 1020 | failure. This is the equivalent of the Python |
| 1021 | expression: \code{o1+o2}. |
| 1022 | \end{cfuncdesc} |
| 1023 | |
| 1024 | |
| 1025 | \begin{cfuncdesc}{PyObject*}{PySequence_Repeat}{PyObject *o, int count} |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 1026 | Return the result of repeating sequence object \code{o} \code{count} times, |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 1027 | or \NULL{} on failure. This is the equivalent of the Python |
| 1028 | expression: \code{o*count}. |
| 1029 | \end{cfuncdesc} |
| 1030 | |
| 1031 | |
| 1032 | \begin{cfuncdesc}{PyObject*}{PySequence_GetItem}{PyObject *o, int i} |
| 1033 | Return the ith element of \code{o}, or \NULL{} on failure. This is the |
| 1034 | equivalent of the Python expression: \code{o[i]}. |
| 1035 | \end{cfuncdesc} |
| 1036 | |
| 1037 | |
| 1038 | \begin{cfuncdesc}{PyObject*}{PySequence_GetSlice}{PyObject *o, int i1, int i2} |
| 1039 | Return the slice of sequence object \code{o} between \code{i1} and \code{i2}, or |
| 1040 | \NULL{} on failure. This is the equivalent of the Python |
| 1041 | expression, \code{o[i1:i2]}. |
| 1042 | \end{cfuncdesc} |
| 1043 | |
| 1044 | |
| 1045 | \begin{cfuncdesc}{int}{PySequence_SetItem}{PyObject *o, int i, PyObject *v} |
| 1046 | Assign object \code{v} to the \code{i}th element of \code{o}. |
| 1047 | Returns -1 on failure. This is the equivalent of the Python |
| 1048 | statement, \code{o[i]=v}. |
| 1049 | \end{cfuncdesc} |
| 1050 | |
| 1051 | \begin{cfuncdesc}{int}{PySequence_DelItem}{PyObject *o, int i} |
| 1052 | Delete the \code{i}th element of object \code{v}. Returns |
| 1053 | -1 on failure. This is the equivalent of the Python |
| 1054 | statement: \code{del o[i]}. |
| 1055 | \end{cfuncdesc} |
| 1056 | |
| 1057 | \begin{cfuncdesc}{int}{PySequence_SetSlice}{PyObject *o, int i1, int i2, PyObject *v} |
| 1058 | Assign the sequence object \code{v} to the slice in sequence |
| 1059 | object \code{o} from \code{i1} to \code{i2}. This is the equivalent of the Python |
| 1060 | statement, \code{o[i1:i2]=v}. |
| 1061 | \end{cfuncdesc} |
| 1062 | |
| 1063 | \begin{cfuncdesc}{int}{PySequence_DelSlice}{PyObject *o, int i1, int i2} |
| 1064 | Delete the slice in sequence object, \code{o}, from \code{i1} to \code{i2}. |
| 1065 | Returns -1 on failure. This is the equivalent of the Python |
| 1066 | statement: \code{del o[i1:i2]}. |
| 1067 | \end{cfuncdesc} |
| 1068 | |
| 1069 | \begin{cfuncdesc}{PyObject*}{PySequence_Tuple}{PyObject *o} |
| 1070 | Returns the \code{o} as a tuple on success, and \NULL{} on failure. |
| 1071 | This is equivalent to the Python expression: \code{tuple(o)}. |
| 1072 | \end{cfuncdesc} |
| 1073 | |
| 1074 | \begin{cfuncdesc}{int}{PySequence_Count}{PyObject *o, PyObject *value} |
| 1075 | Return the number of occurrences of \code{value} on \code{o}, that is, |
| 1076 | return the number of keys for which \code{o[key]==value}. On |
| 1077 | failure, return -1. This is equivalent to the Python |
| 1078 | expression: \code{o.count(value)}. |
| 1079 | \end{cfuncdesc} |
| 1080 | |
| 1081 | \begin{cfuncdesc}{int}{PySequence_In}{PyObject *o, PyObject *value} |
| 1082 | Determine if \code{o} contains \code{value}. If an item in \code{o} is equal to |
| 1083 | \code{value}, return 1, otherwise return 0. On error, return -1. This |
| 1084 | is equivalent to the Python expression: \code{value in o}. |
| 1085 | \end{cfuncdesc} |
| 1086 | |
| 1087 | \begin{cfuncdesc}{int}{PySequence_Index}{PyObject *o, PyObject *value} |
Guido van Rossum | 59a6135 | 1997-08-14 20:34:33 +0000 | [diff] [blame] | 1088 | Return the first index for which \code{o[i]==value}. On error, |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 1089 | return -1. This is equivalent to the Python |
| 1090 | expression: \code{o.index(value)}. |
| 1091 | \end{cfuncdesc} |
| 1092 | |
| 1093 | \section{Mapping protocol} |
| 1094 | |
| 1095 | \begin{cfuncdesc}{int}{PyMapping_Check}{PyObject *o} |
| 1096 | Return 1 if the object provides mapping protocol, and 0 |
| 1097 | otherwise. |
| 1098 | This function always succeeds. |
| 1099 | \end{cfuncdesc} |
| 1100 | |
| 1101 | |
| 1102 | \begin{cfuncdesc}{int}{PyMapping_Length}{PyObject *o} |
| 1103 | Returns the number of keys in object \code{o} on success, and -1 on |
| 1104 | failure. For objects that do not provide sequence protocol, |
| 1105 | this is equivalent to the Python expression: \code{len(o)}. |
| 1106 | \end{cfuncdesc} |
| 1107 | |
| 1108 | |
| 1109 | \begin{cfuncdesc}{int}{PyMapping_DelItemString}{PyObject *o, char *key} |
| 1110 | Remove the mapping for object \code{key} from the object \code{o}. |
| 1111 | Return -1 on failure. This is equivalent to |
| 1112 | the Python statement: \code{del o[key]}. |
| 1113 | \end{cfuncdesc} |
| 1114 | |
| 1115 | |
| 1116 | \begin{cfuncdesc}{int}{PyMapping_DelItem}{PyObject *o, PyObject *key} |
| 1117 | Remove the mapping for object \code{key} from the object \code{o}. |
| 1118 | Return -1 on failure. This is equivalent to |
| 1119 | the Python statement: \code{del o[key]}. |
| 1120 | \end{cfuncdesc} |
| 1121 | |
| 1122 | |
| 1123 | \begin{cfuncdesc}{int}{PyMapping_HasKeyString}{PyObject *o, char *key} |
| 1124 | On success, return 1 if the mapping object has the key \code{key} |
| 1125 | and 0 otherwise. This is equivalent to the Python expression: |
| 1126 | \code{o.has_key(key)}. |
| 1127 | This function always succeeds. |
| 1128 | \end{cfuncdesc} |
| 1129 | |
| 1130 | |
| 1131 | \begin{cfuncdesc}{int}{PyMapping_HasKey}{PyObject *o, PyObject *key} |
| 1132 | Return 1 if the mapping object has the key \code{key} |
| 1133 | and 0 otherwise. This is equivalent to the Python expression: |
| 1134 | \code{o.has_key(key)}. |
| 1135 | This function always succeeds. |
| 1136 | \end{cfuncdesc} |
| 1137 | |
| 1138 | |
| 1139 | \begin{cfuncdesc}{PyObject*}{PyMapping_Keys}{PyObject *o} |
| 1140 | On success, return a list of the keys in object \code{o}. On |
| 1141 | failure, return \NULL{}. This is equivalent to the Python |
| 1142 | expression: \code{o.keys()}. |
| 1143 | \end{cfuncdesc} |
| 1144 | |
| 1145 | |
| 1146 | \begin{cfuncdesc}{PyObject*}{PyMapping_Values}{PyObject *o} |
| 1147 | On success, return a list of the values in object \code{o}. On |
| 1148 | failure, return \NULL{}. This is equivalent to the Python |
| 1149 | expression: \code{o.values()}. |
| 1150 | \end{cfuncdesc} |
| 1151 | |
| 1152 | |
| 1153 | \begin{cfuncdesc}{PyObject*}{PyMapping_Items}{PyObject *o} |
| 1154 | On success, return a list of the items in object \code{o}, where |
| 1155 | each item is a tuple containing a key-value pair. On |
| 1156 | failure, return \NULL{}. This is equivalent to the Python |
| 1157 | expression: \code{o.items()}. |
| 1158 | \end{cfuncdesc} |
| 1159 | |
| 1160 | \begin{cfuncdesc}{int}{PyMapping_Clear}{PyObject *o} |
| 1161 | Make object \code{o} empty. Returns 1 on success and 0 on failure. |
| 1162 | This is equivalent to the Python statement: |
| 1163 | \code{for key in o.keys(): del o[key]} |
| 1164 | \end{cfuncdesc} |
| 1165 | |
| 1166 | |
| 1167 | \begin{cfuncdesc}{PyObject*}{PyMapping_GetItemString}{PyObject *o, char *key} |
| 1168 | Return element of \code{o} corresponding to the object \code{key} or \NULL{} |
| 1169 | on failure. This is the equivalent of the Python expression: |
| 1170 | \code{o[key]}. |
| 1171 | \end{cfuncdesc} |
| 1172 | |
| 1173 | \begin{cfuncdesc}{PyObject*}{PyMapping_SetItemString}{PyObject *o, char *key, PyObject *v} |
| 1174 | Map the object \code{key} to the value \code{v} in object \code{o}. Returns |
| 1175 | -1 on failure. This is the equivalent of the Python |
| 1176 | statement: \code{o[key]=v}. |
| 1177 | \end{cfuncdesc} |
| 1178 | |
| 1179 | |
| 1180 | \section{Constructors} |
| 1181 | |
| 1182 | \begin{cfuncdesc}{PyObject*}{PyFile_FromString}{char *file_name, char *mode} |
| 1183 | On success, returns a new file object that is opened on the |
| 1184 | file given by \code{file_name}, with a file mode given by \code{mode}, |
| 1185 | where \code{mode} has the same semantics as the standard C routine, |
| 1186 | fopen. On failure, return -1. |
| 1187 | \end{cfuncdesc} |
| 1188 | |
| 1189 | \begin{cfuncdesc}{PyObject*}{PyFile_FromFile}{FILE *fp, char *file_name, char *mode, int close_on_del} |
| 1190 | Return a new file object for an already opened standard C |
| 1191 | file pointer, \code{fp}. A file name, \code{file_name}, and open mode, |
| 1192 | \code{mode}, must be provided as well as a flag, \code{close_on_del}, that |
| 1193 | indicates whether the file is to be closed when the file |
| 1194 | object is destroyed. On failure, return -1. |
| 1195 | \end{cfuncdesc} |
| 1196 | |
| 1197 | \begin{cfuncdesc}{PyObject*}{PyFloat_FromDouble}{double v} |
| 1198 | Returns a new float object with the value \code{v} on success, and |
| 1199 | \NULL{} on failure. |
| 1200 | \end{cfuncdesc} |
| 1201 | |
| 1202 | \begin{cfuncdesc}{PyObject*}{PyInt_FromLong}{long v} |
| 1203 | Returns a new int object with the value \code{v} on success, and |
| 1204 | \NULL{} on failure. |
| 1205 | \end{cfuncdesc} |
| 1206 | |
| 1207 | \begin{cfuncdesc}{PyObject*}{PyList_New}{int l} |
| 1208 | Returns a new list of length \code{l} on success, and \NULL{} on |
| 1209 | failure. |
| 1210 | \end{cfuncdesc} |
| 1211 | |
| 1212 | \begin{cfuncdesc}{PyObject*}{PyLong_FromLong}{long v} |
| 1213 | Returns a new long object with the value \code{v} on success, and |
| 1214 | \NULL{} on failure. |
| 1215 | \end{cfuncdesc} |
| 1216 | |
| 1217 | \begin{cfuncdesc}{PyObject*}{PyLong_FromDouble}{double v} |
| 1218 | Returns a new long object with the value \code{v} on success, and |
| 1219 | \NULL{} on failure. |
| 1220 | \end{cfuncdesc} |
| 1221 | |
| 1222 | \begin{cfuncdesc}{PyObject*}{PyDict_New}{} |
| 1223 | Returns a new empty dictionary on success, and \NULL{} on |
| 1224 | failure. |
| 1225 | \end{cfuncdesc} |
| 1226 | |
| 1227 | \begin{cfuncdesc}{PyObject*}{PyString_FromString}{char *v} |
| 1228 | Returns a new string object with the value \code{v} on success, and |
| 1229 | \NULL{} on failure. |
| 1230 | \end{cfuncdesc} |
| 1231 | |
| 1232 | \begin{cfuncdesc}{PyObject*}{PyString_FromStringAndSize}{char *v, int l} |
| 1233 | Returns a new string object with the value \code{v} and length \code{l} |
| 1234 | on success, and \NULL{} on failure. |
| 1235 | \end{cfuncdesc} |
| 1236 | |
| 1237 | \begin{cfuncdesc}{PyObject*}{PyTuple_New}{int l} |
| 1238 | Returns a new tuple of length \code{l} on success, and \NULL{} on |
| 1239 | failure. |
| 1240 | \end{cfuncdesc} |
| 1241 | |
| 1242 | |
| 1243 | \chapter{Concrete Objects Layer} |
| 1244 | |
| 1245 | The functions in this chapter are specific to certain Python object |
| 1246 | types. Passing them an object of the wrong type is not a good idea; |
| 1247 | if you receive an object from a Python program and you are not sure |
| 1248 | that it has the right type, you must perform a type check first; |
| 1249 | e.g. to check that an object is a dictionary, use |
| 1250 | \code{PyDict_Check()}. |
| 1251 | |
| 1252 | |
| 1253 | \chapter{Defining New Object Types} |
| 1254 | |
| 1255 | \begin{cfuncdesc}{PyObject *}{_PyObject_New}{PyTypeObject *type} |
| 1256 | \end{cfuncdesc} |
| 1257 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 1258 | \begin{cfuncdesc}{PyObject *}{_PyObject_NewVar}{PyTypeObject *type, int size} |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 1259 | \end{cfuncdesc} |
| 1260 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 1261 | \begin{cfuncdesc}{TYPE}{_PyObject_NEW}{TYPE, PyTypeObject *} |
| 1262 | \end{cfuncdesc} |
| 1263 | |
| 1264 | \begin{cfuncdesc}{TYPE}{_PyObject_NEW_VAR}{TYPE, PyTypeObject *, int size} |
| 1265 | \end{cfuncdesc} |
| 1266 | |
Guido van Rossum | 4a944d7 | 1997-08-14 20:35:38 +0000 | [diff] [blame] | 1267 | \chapter{Initialization, Finalization, and Threads} |
| 1268 | |
| 1269 | % XXX Check argument/return type of all these |
| 1270 | |
| 1271 | \begin{cfuncdesc}{void}{Py_Initialize}{} |
| 1272 | Initialize the Python interpreter. In an application embedding |
| 1273 | Python, this should be called before using any other Python/C API |
| 1274 | functions; with the exception of \code{Py_SetProgramName()}, |
| 1275 | \code{PyEval_InitThreads()}, \code{PyEval_ReleaseLock()}, and |
| 1276 | \code{PyEval_AcquireLock()}. This initializes the table of loaded |
| 1277 | modules (\code{sys.modules}), and creates the fundamental modules |
| 1278 | \code{__builtin__}, \code{__main__} and \code{sys}. It also |
| 1279 | initializes the module search path (\code{sys.path}). It does not set |
| 1280 | \code{sys.argv}; use \code{PySys_SetArgv()} for that. It is a fatal |
| 1281 | error to call it for a second time without calling |
| 1282 | \code{Py_Finalize()} first. There is no return value; it is a fatal |
| 1283 | error if the initialization fails. |
| 1284 | \end{cfuncdesc} |
| 1285 | |
| 1286 | \begin{cfuncdesc}{void}{Py_Finalize}{} |
| 1287 | Undo all initializations made by \code{Py_Initialize()} and subsequent |
| 1288 | use of Python/C API functions, and destroy all sub-interpreters (see |
| 1289 | \code{Py_NewInterpreter()} below) that were created and not yet |
| 1290 | destroyed since the last call to \code{Py_Initialize()}. Ideally, |
| 1291 | this frees all memory allocated by the Python interpreter. It is a |
| 1292 | fatal error to call it for a second time without calling |
| 1293 | \code{Py_Initialize()} again first. There is no return value; errors |
| 1294 | during finalization are ignored. |
| 1295 | |
| 1296 | This function is provided for a number of reasons. An embedding |
| 1297 | application might want to restart Python without having to restart the |
| 1298 | application itself. An application that has loaded the Python |
| 1299 | interpreter from a dynamically loadable library (or DLL) might want to |
| 1300 | free all memory allocated by Python before unloading the DLL. During a |
| 1301 | hunt for memory leaks in an application a developer might want to free |
| 1302 | all memory allocated by Python before exiting from the application. |
| 1303 | |
| 1304 | \emph{Bugs and caveats:} The destruction of modules and objects in |
| 1305 | modules is done in random order; this may cause destructors |
| 1306 | (\code{__del__} methods) to fail when they depend on other objects |
| 1307 | (even functions) or modules. Dynamically loaded extension modules |
| 1308 | loaded by Python are not unloaded. Small amounts of memory allocated |
| 1309 | by the Python interpreter may not be freed (if you find a leak, please |
| 1310 | report it). Memory tied up in circular references between objects is |
| 1311 | not freed. Some memory allocated by extension modules may not be |
| 1312 | freed. Some extension may not work properly if their initialization |
| 1313 | routine is called more than once; this can happen if an applcation |
| 1314 | calls \code{Py_Initialize()} and \code{Py_Finalize()} more than once. |
| 1315 | \end{cfuncdesc} |
| 1316 | |
| 1317 | \begin{cfuncdesc}{PyThreadState *}{Py_NewInterpreter}{} |
| 1318 | Create a new sub-interpreter. This is an (almost) totally separate |
| 1319 | environment for the execution of Python code. In particular, the new |
| 1320 | interpreter has separate, independent versions of all imported |
| 1321 | modules, including the fundamental modules \code{__builtin__}, |
| 1322 | \code{__main__} and \code{sys}. The table of loaded modules |
| 1323 | (\code{sys.modules}) and the module search path (\code{sys.path}) are |
| 1324 | also separate. The new environment has no \code{sys.argv} variable. |
| 1325 | It has new standard I/O stream file objects \code{sys.stdin}, |
| 1326 | \code{sys.stdout} and \code{sys.stderr} (however these refer to the |
| 1327 | same underlying \code{FILE} structures in the C library). |
| 1328 | |
| 1329 | The return value points to the first thread state created in the new |
| 1330 | sub-interpreter. This thread state is made the current thread state. |
| 1331 | Note that no actual thread is created; see the discussion of thread |
| 1332 | states below. If creation of the new interpreter is unsuccessful, |
| 1333 | \code{NULL} is returned; no exception is set since the exception state |
| 1334 | is stored in the current thread state and there may not be a current |
| 1335 | thread state. (Like all other Python/C API functions, the global |
| 1336 | interpreter lock must be held before calling this function and is |
| 1337 | still held when it returns; however, unlike most other Python/C API |
| 1338 | functions, there needn't be a current thread state on entry.) |
| 1339 | |
| 1340 | Extension modules are shared between (sub-)interpreters as follows: |
| 1341 | the first time a particular extension is imported, it is initialized |
| 1342 | normally, and a (shallow) copy of its module's dictionary is |
| 1343 | squirreled away. When the same extension is imported by another |
| 1344 | (sub-)interpreter, a new module is initialized and filled with the |
| 1345 | contents of this copy; the extension's \code{init} function is not |
| 1346 | called. Note that this is different from what happens when as |
| 1347 | extension is imported after the interpreter has been completely |
| 1348 | re-initialized by calling \code{Py_Finalize()} and |
| 1349 | \code{Py_Initialize()}; in that case, the extension's \code{init} |
| 1350 | function \emph{is} called again. |
| 1351 | |
| 1352 | \emph{Bugs and caveats:} Because sub-interpreters (and the main |
| 1353 | interpreter) are part of the same process, the insulation between them |
| 1354 | isn't perfect -- for example, using low-level file operations like |
| 1355 | \code{os.close()} they can (accidentally or maliciously) affect each |
| 1356 | other's open files. Because of the way extensions are shared between |
| 1357 | (sub-)interpreters, some extensions may not work properly; this is |
| 1358 | especially likely when the extension makes use of (static) global |
| 1359 | variables, or when the extension manipulates its module's dictionary |
| 1360 | after its initialization. It is possible to insert objects created in |
| 1361 | one sub-interpreter into a namespace of another sub-interpreter; this |
| 1362 | should be done with great care to avoid sharing user-defined |
| 1363 | functions, methods, instances or classes between sub-interpreters, |
| 1364 | since import operations executed by such objects may affect the |
| 1365 | wrong (sub-)interpreter's dictionary of loaded modules. (XXX This is |
| 1366 | a hard-to-fix bug that will be addressed in a future release.) |
| 1367 | \end{cfuncdesc} |
| 1368 | |
| 1369 | \begin{cfuncdesc}{void}{Py_EndInterpreter}{PyThreadState *tstate} |
| 1370 | Destroy the (sub-)interpreter represented by the given thread state. |
| 1371 | The given thread state must be the current thread state. See the |
| 1372 | discussion of thread states below. When the call returns, the current |
| 1373 | thread state is \code{NULL}. All thread states associated with this |
| 1374 | interpreted are destroyed. (The global interpreter lock must be held |
| 1375 | before calling this function and is still held when it returns.) |
| 1376 | \code{Py_Finalize()} will destroy all sub-interpreters that haven't |
| 1377 | been explicitly destroyed at that point. |
| 1378 | \end{cfuncdesc} |
| 1379 | |
| 1380 | \begin{cfuncdesc}{void}{Py_SetProgramName}{char *name} |
| 1381 | This function should be called before \code{Py_Initialize()} is called |
| 1382 | for the first time, if it is called at all. It tells the interpreter |
| 1383 | the value of the \code{argv[0]} argument to the \code{main()} function |
| 1384 | of the program. This is used by \code{Py_GetPath()} and some other |
| 1385 | functions below to find the Python run-time libraries relative to the |
| 1386 | interpreter executable. The default value is \code{"python"}. The |
| 1387 | argument should point to a zero-terminated character string in static |
| 1388 | storage whose contents will not change for the duration of the |
| 1389 | program's execution. No code in the Python interpreter will change |
| 1390 | the contents of this storage. |
| 1391 | \end{cfuncdesc} |
| 1392 | |
| 1393 | \begin{cfuncdesc}{char *}{Py_GetProgramName}{} |
| 1394 | Return the program name set with \code{Py_SetProgramName()}, or the |
| 1395 | default. The returned string points into static storage; the caller |
| 1396 | should not modify its value. |
| 1397 | \end{cfuncdesc} |
| 1398 | |
| 1399 | \begin{cfuncdesc}{char *}{Py_GetPrefix}{} |
| 1400 | Return the ``prefix'' for installed platform-independent files. This |
| 1401 | is derived through a number of complicated rules from the program name |
| 1402 | set with \code{Py_SetProgramName()} and some environment variables; |
| 1403 | for example, if the program name is \code{"/usr/local/bin/python"}, |
| 1404 | the prefix is \code{"/usr/local"}. The returned string points into |
| 1405 | static storage; the caller should not modify its value. This |
| 1406 | corresponds to the \code{prefix} variable in the top-level |
| 1407 | \code{Makefile} and the \code{--prefix} argument to the |
| 1408 | \code{configure} script at build time. The value is available to |
| 1409 | Python code as \code{sys.prefix}. It is only useful on Unix. See |
| 1410 | also the next function. |
| 1411 | \end{cfuncdesc} |
| 1412 | |
| 1413 | \begin{cfuncdesc}{char *}{Py_GetExecPrefix}{} |
| 1414 | Return the ``exec-prefix'' for installed platform-\emph{de}pendent |
| 1415 | files. This is derived through a number of complicated rules from the |
| 1416 | program name set with \code{Py_SetProgramName()} and some environment |
| 1417 | variables; for example, if the program name is |
| 1418 | \code{"/usr/local/bin/python"}, the exec-prefix is |
| 1419 | \code{"/usr/local"}. The returned string points into static storage; |
| 1420 | the caller should not modify its value. This corresponds to the |
| 1421 | \code{exec_prefix} variable in the top-level \code{Makefile} and the |
| 1422 | \code{--exec_prefix} argument to the \code{configure} script at build |
| 1423 | time. The value is available to Python code as |
| 1424 | \code{sys.exec_prefix}. It is only useful on Unix. |
| 1425 | |
| 1426 | Background: The exec-prefix differs from the prefix when platform |
| 1427 | dependent files (such as executables and shared libraries) are |
| 1428 | installed in a different directory tree. In a typical installation, |
| 1429 | platform dependent files may be installed in the |
| 1430 | \code{"/usr/local/plat"} subtree while platform independent may be |
| 1431 | installed in \code{"/usr/local"}. |
| 1432 | |
| 1433 | Generally speaking, a platform is a combination of hardware and |
| 1434 | software families, e.g. Sparc machines running the Solaris 2.x |
| 1435 | operating system are considered the same platform, but Intel machines |
| 1436 | running Solaris 2.x are another platform, and Intel machines running |
| 1437 | Linux are yet another platform. Different major revisions of the same |
| 1438 | operating system generally also form different platforms. Non-Unix |
| 1439 | operating systems are a different story; the installation strategies |
| 1440 | on those systems are so different that the prefix and exec-prefix are |
| 1441 | meaningless, and set to the empty string. Note that compiled Python |
| 1442 | bytecode files are platform independent (but not independent from the |
| 1443 | Python version by which they were compiled!). |
| 1444 | |
| 1445 | System administrators will know how to configure the \code{mount} or |
| 1446 | \code{automount} programs to share \code{"/usr/local"} between platforms |
| 1447 | while having \code{"/usr/local/plat"} be a different filesystem for each |
| 1448 | platform. |
| 1449 | \end{cfuncdesc} |
| 1450 | |
| 1451 | \begin{cfuncdesc}{char *}{Py_GetProgramFullPath}{} |
| 1452 | Return the full program name of the Python executable; this is |
| 1453 | computed as a side-effect of deriving the default module search path |
| 1454 | from the program name (set by \code{Py_SetProgramName() above). The |
| 1455 | returned string points into static storage; the caller should not |
| 1456 | modify its value. The value is available to Python code as |
| 1457 | \code{sys.executable}. % XXX is that the right sys.name? |
| 1458 | \end{cfuncdesc} |
| 1459 | |
| 1460 | \begin{cfuncdesc}{char *}{Py_GetPath}{} |
| 1461 | Return the default module search path; this is computed from the |
| 1462 | program name (set by \code{Py_SetProgramName() above) and some |
| 1463 | environment variables. The returned string consists of a series of |
| 1464 | directory names separated by a platform dependent delimiter character. |
| 1465 | The delimiter character is \code{':'} on Unix, \code{';'} on |
| 1466 | DOS/Windows, and \code{'\n'} (the ASCII newline character) on |
| 1467 | Macintosh. The returned string points into static storage; the caller |
| 1468 | should not modify its value. The value is available to Python code |
| 1469 | as the list \code{sys.path}, which may be modified to change the |
| 1470 | future search path for loaded modules. |
| 1471 | |
| 1472 | % XXX should give the exact rules |
| 1473 | \end{cfuncdesc} |
| 1474 | |
| 1475 | \begin{cfuncdesc}{const char *}{Py_GetVersion}{} |
| 1476 | Return the version of this Python interpreter. This is a string that |
| 1477 | looks something like |
| 1478 | |
| 1479 | \code{"1.5a3 (#67, Aug 1 1997, 22:34:28) [GCC 2.7.2.2]"}. |
| 1480 | |
| 1481 | The first word (up to the first space character) is the current Python |
| 1482 | version; the first three characters are the major and minor version |
| 1483 | separated by a period. The returned string points into static storage; |
| 1484 | the caller should not modify its value. The value is available to |
| 1485 | Python code as the list \code{sys.version}. |
| 1486 | \end{cfuncdesc} |
| 1487 | |
| 1488 | \begin{cfuncdesc}{const char *}{Py_GetPlatform}{} |
| 1489 | Return the platform identifier for the current platform. On Unix, |
| 1490 | this is formed from the ``official'' name of the operating system, |
| 1491 | converted to lower case, followed by the major revision number; e.g., |
| 1492 | for Solaris 2.x, which is also known as SunOS 5.x, the value is |
| 1493 | \code{"sunos5"}. On Macintosh, it is \code{"mac"}. On Windows, it |
| 1494 | is \code{"win"}. The returned string points into static storage; |
| 1495 | the caller should not modify its value. The value is available to |
| 1496 | Python code as \code{sys.platform}. |
| 1497 | \end{cfuncdesc} |
| 1498 | |
| 1499 | \begin{cfuncdesc}{const char *}{Py_GetCopyright}{} |
| 1500 | Return the official copyright string for the current Python version, |
| 1501 | for example |
| 1502 | |
| 1503 | \code{"Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam"} |
| 1504 | |
| 1505 | The returned string points into static storage; the caller should not |
| 1506 | modify its value. The value is available to Python code as the list |
| 1507 | \code{sys.copyright}. |
| 1508 | \end{cfuncdesc} |
| 1509 | |
| 1510 | \begin{cfuncdesc}{const char *}{Py_GetCompiler}{} |
| 1511 | Return an indication of the compiler used to build the current Python |
| 1512 | version, in square brackets, for example |
| 1513 | |
| 1514 | \code{"[GCC 2.7.2.2]"} |
| 1515 | |
| 1516 | The returned string points into static storage; the caller should not |
| 1517 | modify its value. The value is available to Python code as part of |
| 1518 | the variable \code{sys.version}. |
| 1519 | \end{cfuncdesc} |
| 1520 | |
| 1521 | \begin{cfuncdesc}{const char *}{Py_GetBuildInfo}{} |
| 1522 | Return information about the sequence number and build date and time |
| 1523 | of the current Python interpreter instance, for example |
| 1524 | |
| 1525 | \code{"#67, Aug 1 1997, 22:34:28"} |
| 1526 | |
| 1527 | The returned string points into static storage; the caller should not |
| 1528 | modify its value. The value is available to Python code as part of |
| 1529 | the variable \code{sys.version}. |
| 1530 | \end{cfuncdesc} |
| 1531 | |
| 1532 | \begin{cfuncdesc}{int}{PySys_SetArgv}{int argc, char **argv} |
| 1533 | % XXX |
| 1534 | \end{cfuncdesc} |
| 1535 | |
| 1536 | % XXX Other PySys thingies (doesn't really belong in this chapter) |
| 1537 | |
| 1538 | \section{Thread State and the Global Interpreter Lock} |
| 1539 | |
| 1540 | \begin{cfuncdesc}{void}{PyEval_AcquireLock}{} |
| 1541 | \end{cfuncdesc} |
| 1542 | |
| 1543 | \begin{cfuncdesc}{void}{PyEval_ReleaseLock}{} |
| 1544 | \end{cfuncdesc} |
| 1545 | |
| 1546 | \begin{cfuncdesc}{void}{PyEval_AcquireThread}{PyThreadState *tstate} |
| 1547 | \end{cfuncdesc} |
| 1548 | |
| 1549 | \begin{cfuncdesc}{void}{PyEval_ReleaseThread}{PyThreadState *tstate} |
| 1550 | \end{cfuncdesc} |
| 1551 | |
| 1552 | \begin{cfuncdesc}{void}{PyEval_RestoreThread}{PyThreadState *tstate} |
| 1553 | \end{cfuncdesc} |
| 1554 | |
| 1555 | \begin{cfuncdesc}{PyThreadState *}{PyEval_SaveThread}{} |
| 1556 | \end{cfuncdesc} |
| 1557 | |
| 1558 | % XXX These aren't really C functions! |
| 1559 | \begin{cfuncdesc}{Py_BEGIN_ALLOW_THREADS}{} |
| 1560 | \end{cfuncdesc} |
| 1561 | |
| 1562 | \begin{cfuncdesc}{Py_BEGIN_END_THREADS}{} |
| 1563 | \end{cfuncdesc} |
| 1564 | |
| 1565 | \begin{cfuncdesc}{Py_BEGIN_XXX_THREADS}{} |
| 1566 | \end{cfuncdesc} |
| 1567 | |
| 1568 | |
Guido van Rossum | ae110af | 1997-05-22 20:11:52 +0000 | [diff] [blame] | 1569 | XXX To be done: |
| 1570 | |
| 1571 | PyObject, PyVarObject |
| 1572 | |
| 1573 | PyObject_HEAD, PyObject_HEAD_INIT, PyObject_VAR_HEAD |
| 1574 | |
| 1575 | Typedefs: |
| 1576 | unaryfunc, binaryfunc, ternaryfunc, inquiry, coercion, intargfunc, |
| 1577 | intintargfunc, intobjargproc, intintobjargproc, objobjargproc, |
| 1578 | getreadbufferproc, getwritebufferproc, getsegcountproc, |
| 1579 | destructor, printfunc, getattrfunc, getattrofunc, setattrfunc, |
| 1580 | setattrofunc, cmpfunc, reprfunc, hashfunc |
| 1581 | |
| 1582 | PyNumberMethods |
| 1583 | |
| 1584 | PySequenceMethods |
| 1585 | |
| 1586 | PyMappingMethods |
| 1587 | |
| 1588 | PyBufferProcs |
| 1589 | |
| 1590 | PyTypeObject |
| 1591 | |
| 1592 | DL_IMPORT |
| 1593 | |
| 1594 | PyType_Type |
| 1595 | |
| 1596 | Py*_Check |
| 1597 | |
| 1598 | Py_None, _Py_NoneStruct |
| 1599 | |
| 1600 | _PyObject_New, _PyObject_NewVar |
| 1601 | |
| 1602 | PyObject_NEW, PyObject_NEW_VAR |
| 1603 | |
| 1604 | |
| 1605 | \chapter{Specific Data Types} |
| 1606 | |
| 1607 | This chapter describes the functions that deal with specific types of |
| 1608 | Python objects. It is structured like the ``family tree'' of Python |
| 1609 | object types. |
| 1610 | |
| 1611 | |
| 1612 | \section{Fundamental Objects} |
| 1613 | |
| 1614 | This section describes Python type objects and the singleton object |
| 1615 | \code{None}. |
| 1616 | |
| 1617 | |
| 1618 | \subsection{Type Objects} |
| 1619 | |
| 1620 | \begin{ctypedesc}{PyTypeObject} |
| 1621 | |
| 1622 | \end{ctypedesc} |
| 1623 | |
| 1624 | \begin{cvardesc}{PyObject *}{PyType_Type} |
| 1625 | |
| 1626 | \end{cvardesc} |
| 1627 | |
| 1628 | |
| 1629 | \subsection{The None Object} |
| 1630 | |
| 1631 | \begin{cvardesc}{PyObject *}{Py_None} |
| 1632 | macro |
| 1633 | \end{cvardesc} |
| 1634 | |
| 1635 | |
| 1636 | \section{Sequence Objects} |
| 1637 | |
| 1638 | Generic operations on sequence objects were discussed in the previous |
| 1639 | chapter; this section deals with the specific kinds of sequence |
| 1640 | objects that are intrinsuc to the Python language. |
| 1641 | |
| 1642 | |
| 1643 | \subsection{String Objects} |
| 1644 | |
| 1645 | \begin{ctypedesc}{PyStringObject} |
| 1646 | This subtype of \code{PyObject} represents a Python string object. |
| 1647 | \end{ctypedesc} |
| 1648 | |
| 1649 | \begin{cvardesc}{PyTypeObject}{PyString_Type} |
| 1650 | This instance of \code{PyTypeObject} represents the Python string type. |
| 1651 | \end{cvardesc} |
| 1652 | |
| 1653 | \begin{cfuncdesc}{int}{PyString_Check}{PyObject *o} |
| 1654 | |
| 1655 | \end{cfuncdesc} |
| 1656 | |
| 1657 | \begin{cfuncdesc}{PyObject *}{PyString_FromStringAndSize}{const char *, int} |
| 1658 | |
| 1659 | \end{cfuncdesc} |
| 1660 | |
| 1661 | \begin{cfuncdesc}{PyObject *}{PyString_FromString}{const char *} |
| 1662 | |
| 1663 | \end{cfuncdesc} |
| 1664 | |
| 1665 | \begin{cfuncdesc}{int}{PyString_Size}{PyObject *} |
| 1666 | |
| 1667 | \end{cfuncdesc} |
| 1668 | |
| 1669 | \begin{cfuncdesc}{char *}{PyString_AsString}{PyObject *} |
| 1670 | |
| 1671 | \end{cfuncdesc} |
| 1672 | |
| 1673 | \begin{cfuncdesc}{void}{PyString_Concat}{PyObject **, PyObject *} |
| 1674 | |
| 1675 | \end{cfuncdesc} |
| 1676 | |
| 1677 | \begin{cfuncdesc}{void}{PyString_ConcatAndDel}{PyObject **, PyObject *} |
| 1678 | |
| 1679 | \end{cfuncdesc} |
| 1680 | |
| 1681 | \begin{cfuncdesc}{int}{_PyString_Resize}{PyObject **, int} |
| 1682 | |
| 1683 | \end{cfuncdesc} |
| 1684 | |
| 1685 | \begin{cfuncdesc}{PyObject *}{PyString_Format}{PyObject *, PyObject *} |
| 1686 | |
| 1687 | \end{cfuncdesc} |
| 1688 | |
| 1689 | \begin{cfuncdesc}{void}{PyString_InternInPlace}{PyObject **} |
| 1690 | |
| 1691 | \end{cfuncdesc} |
| 1692 | |
| 1693 | \begin{cfuncdesc}{PyObject *}{PyString_InternFromString}{const char *} |
| 1694 | |
| 1695 | \end{cfuncdesc} |
| 1696 | |
| 1697 | \begin{cfuncdesc}{char *}{PyString_AS_STRING}{PyStringObject *} |
| 1698 | |
| 1699 | \end{cfuncdesc} |
| 1700 | |
| 1701 | \begin{cfuncdesc}{int}{PyString_GET_SIZE}{PyStringObject *} |
| 1702 | |
| 1703 | \end{cfuncdesc} |
| 1704 | |
| 1705 | |
| 1706 | \subsection{Tuple Objects} |
| 1707 | |
| 1708 | \begin{ctypedesc}{PyTupleObject} |
| 1709 | This subtype of \code{PyObject} represents a Python tuple object. |
| 1710 | \end{ctypedesc} |
| 1711 | |
| 1712 | \begin{cvardesc}{PyTypeObject}{PyTuple_Type} |
| 1713 | This instance of \code{PyTypeObject} represents the Python tuple type. |
| 1714 | \end{cvardesc} |
| 1715 | |
| 1716 | \begin{cfuncdesc}{int}{PyTuple_Check}{PyObject *p} |
| 1717 | Return true if the argument is a tuple object. |
| 1718 | \end{cfuncdesc} |
| 1719 | |
| 1720 | \begin{cfuncdesc}{PyTupleObject *}{PyTuple_New}{int s} |
| 1721 | Return a new tuple object of size \code{s} |
| 1722 | \end{cfuncdesc} |
| 1723 | |
| 1724 | \begin{cfuncdesc}{int}{PyTuple_Size}{PyTupleObject *p} |
| 1725 | akes a pointer to a tuple object, and returns the size |
| 1726 | of that tuple. |
| 1727 | \end{cfuncdesc} |
| 1728 | |
| 1729 | \begin{cfuncdesc}{PyObject *}{PyTuple_GetItem}{PyTupleObject *p, int pos} |
| 1730 | returns the object at position \code{pos} in the tuple pointed |
| 1731 | to by \code{p}. |
| 1732 | \end{cfuncdesc} |
| 1733 | |
| 1734 | \begin{cfuncdesc}{PyObject *}{PyTuple_GET_ITEM}{PyTupleObject *p, int pos} |
| 1735 | does the same, but does no checking of it's |
| 1736 | arguments. |
| 1737 | \end{cfuncdesc} |
| 1738 | |
| 1739 | \begin{cfuncdesc}{PyTupleObject *}{PyTuple_GetSlice}{PyTupleObject *p, |
| 1740 | int low, |
| 1741 | int high} |
| 1742 | takes a slice of the tuple pointed to by \code{p} from |
| 1743 | \code{low} to \code{high} and returns it as a new tuple. |
| 1744 | \end{cfuncdesc} |
| 1745 | |
| 1746 | \begin{cfuncdesc}{int}{PyTuple_SetItem}{PyTupleObject *p, |
| 1747 | int pos, |
| 1748 | PyObject *o} |
| 1749 | inserts a reference to object \code{o} at position \code{pos} of |
| 1750 | the tuple pointed to by \code{p}. It returns 0 on success. |
| 1751 | \end{cfuncdesc} |
| 1752 | |
| 1753 | \begin{cfuncdesc}{void}{PyTuple_SET_ITEM}{PyTupleObject *p, |
| 1754 | int pos, |
| 1755 | PyObject *o} |
| 1756 | |
| 1757 | does the same, but does no error checking, and |
| 1758 | should \emph{only} be used to fill in brand new tuples. |
| 1759 | \end{cfuncdesc} |
| 1760 | |
| 1761 | \begin{cfuncdesc}{PyTupleObject *}{_PyTuple_Resize}{PyTupleObject *p, |
| 1762 | int new, |
| 1763 | int last_is_sticky} |
| 1764 | can be used to resize a tuple. Because tuples are |
| 1765 | \emph{supposed} to be immutable, this should only be used if there is only |
| 1766 | one module referencing the object. Do \emph{not} use this if the tuple may |
| 1767 | already be known to some other part of the code. \code{last_is_sticky} is |
| 1768 | a flag - if set, the tuple will grow or shrink at the front, otherwise |
| 1769 | it will grow or shrink at the end. Think of this as destroying the old |
| 1770 | tuple and creating a new one, only more efficiently. |
| 1771 | \end{cfuncdesc} |
| 1772 | |
| 1773 | |
| 1774 | \subsection{List Objects} |
| 1775 | |
| 1776 | \begin{ctypedesc}{PyListObject} |
| 1777 | This subtype of \code{PyObject} represents a Python list object. |
| 1778 | \end{ctypedesc} |
| 1779 | |
| 1780 | \begin{cvardesc}{PyTypeObject}{PyList_Type} |
| 1781 | This instance of \code{PyTypeObject} represents the Python list type. |
| 1782 | \end{cvardesc} |
| 1783 | |
| 1784 | \begin{cfuncdesc}{int}{PyList_Check}{PyObject *p} |
| 1785 | returns true if it's argument is a \code{PyListObject} |
| 1786 | \end{cfuncdesc} |
| 1787 | |
| 1788 | \begin{cfuncdesc}{PyObject *}{PyList_New}{int size} |
| 1789 | |
| 1790 | \end{cfuncdesc} |
| 1791 | |
| 1792 | \begin{cfuncdesc}{int}{PyList_Size}{PyObject *} |
| 1793 | |
| 1794 | \end{cfuncdesc} |
| 1795 | |
| 1796 | \begin{cfuncdesc}{PyObject *}{PyList_GetItem}{PyObject *, int} |
| 1797 | |
| 1798 | \end{cfuncdesc} |
| 1799 | |
| 1800 | \begin{cfuncdesc}{int}{PyList_SetItem}{PyObject *, int, PyObject *} |
| 1801 | |
| 1802 | \end{cfuncdesc} |
| 1803 | |
| 1804 | \begin{cfuncdesc}{int}{PyList_Insert}{PyObject *, int, PyObject *} |
| 1805 | |
| 1806 | \end{cfuncdesc} |
| 1807 | |
| 1808 | \begin{cfuncdesc}{int}{PyList_Append}{PyObject *, PyObject *} |
| 1809 | |
| 1810 | \end{cfuncdesc} |
| 1811 | |
| 1812 | \begin{cfuncdesc}{PyObject *}{PyList_GetSlice}{PyObject *, int, int} |
| 1813 | |
| 1814 | \end{cfuncdesc} |
| 1815 | |
| 1816 | \begin{cfuncdesc}{int}{PyList_SetSlice}{PyObject *, int, int, PyObject *} |
| 1817 | |
| 1818 | \end{cfuncdesc} |
| 1819 | |
| 1820 | \begin{cfuncdesc}{int}{PyList_Sort}{PyObject *} |
| 1821 | |
| 1822 | \end{cfuncdesc} |
| 1823 | |
| 1824 | \begin{cfuncdesc}{int}{PyList_Reverse}{PyObject *} |
| 1825 | |
| 1826 | \end{cfuncdesc} |
| 1827 | |
| 1828 | \begin{cfuncdesc}{PyObject *}{PyList_AsTuple}{PyObject *} |
| 1829 | |
| 1830 | \end{cfuncdesc} |
| 1831 | |
| 1832 | \begin{cfuncdesc}{PyObject *}{PyList_GET_ITEM}{PyObject *list, int i} |
| 1833 | |
| 1834 | \end{cfuncdesc} |
| 1835 | |
| 1836 | \begin{cfuncdesc}{int}{PyList_GET_SIZE}{PyObject *list} |
| 1837 | |
| 1838 | \end{cfuncdesc} |
| 1839 | |
| 1840 | |
| 1841 | \section{Mapping Objects} |
| 1842 | |
| 1843 | \subsection{Dictionary Objects} |
| 1844 | |
| 1845 | \begin{ctypedesc}{PyDictObject} |
| 1846 | This subtype of \code{PyObject} represents a Python dictionary object. |
| 1847 | \end{ctypedesc} |
| 1848 | |
| 1849 | \begin{cvardesc}{PyTypeObject}{PyDict_Type} |
| 1850 | This instance of \code{PyTypeObject} represents the Python dictionary type. |
| 1851 | \end{cvardesc} |
| 1852 | |
| 1853 | \begin{cfuncdesc}{int}{PyDict_Check}{PyObject *p} |
| 1854 | returns true if it's argument is a PyDictObject |
| 1855 | \end{cfuncdesc} |
| 1856 | |
| 1857 | \begin{cfuncdesc}{PyDictObject *}{PyDict_New}{} |
| 1858 | returns a new empty dictionary. |
| 1859 | \end{cfuncdesc} |
| 1860 | |
| 1861 | \begin{cfuncdesc}{void}{PyDict_Clear}{PyDictObject *p} |
| 1862 | empties an existing dictionary and deletes it. |
| 1863 | \end{cfuncdesc} |
| 1864 | |
| 1865 | \begin{cfuncdesc}{int}{PyDict_SetItem}{PyDictObject *p, |
| 1866 | PyObject *key, |
| 1867 | PyObject *val} |
| 1868 | inserts \code{value} into the dictionary with a key of |
| 1869 | \code{key}. Both \code{key} and \code{value} should be PyObjects, and \code{key} should |
| 1870 | be hashable. |
| 1871 | \end{cfuncdesc} |
| 1872 | |
| 1873 | \begin{cfuncdesc}{int}{PyDict_SetItemString}{PyDictObject *p, |
| 1874 | char *key, |
| 1875 | PyObject *val} |
| 1876 | inserts \code{value} into the dictionary using \code{key} |
| 1877 | as a key. \code{key} should be a char * |
| 1878 | \end{cfuncdesc} |
| 1879 | |
| 1880 | \begin{cfuncdesc}{int}{PyDict_DelItem}{PyDictObject *p, PyObject *key} |
| 1881 | removes the entry in dictionary \code{p} with key \code{key}. |
| 1882 | \code{key} is a PyObject. |
| 1883 | \end{cfuncdesc} |
| 1884 | |
| 1885 | \begin{cfuncdesc}{int}{PyDict_DelItemString}{PyDictObject *p, char *key} |
| 1886 | removes the entry in dictionary \code{p} which has a key |
| 1887 | specified by the \code{char *}\code{key}. |
| 1888 | \end{cfuncdesc} |
| 1889 | |
| 1890 | \begin{cfuncdesc}{PyObject *}{PyDict_GetItem}{PyDictObject *p, PyObject *key} |
| 1891 | returns the object from dictionary \code{p} which has a key |
| 1892 | \code{key}. |
| 1893 | \end{cfuncdesc} |
| 1894 | |
| 1895 | \begin{cfuncdesc}{PyObject *}{PyDict_GetItemString}{PyDictObject *p, char *key} |
| 1896 | does the same, but \code{key} is specified as a |
| 1897 | \code{char *}, rather than a \code{PyObject *}. |
| 1898 | \end{cfuncdesc} |
| 1899 | |
| 1900 | \begin{cfuncdesc}{PyListObject *}{PyDict_Items}{PyDictObject *p} |
| 1901 | returns a PyListObject containing all the items |
| 1902 | from the dictionary, as in the mapping method \code{items()} (see the Reference |
| 1903 | Guide) |
| 1904 | \end{cfuncdesc} |
| 1905 | |
| 1906 | \begin{cfuncdesc}{PyListObject *}{PyDict_Keys}{PyDictObject *p} |
| 1907 | returns a PyListObject containing all the keys |
| 1908 | from the dictionary, as in the mapping method \code{keys()} (see the Reference Guide) |
| 1909 | \end{cfuncdesc} |
| 1910 | |
| 1911 | \begin{cfuncdesc}{PyListObject *}{PyDict_Values}{PyDictObject *p} |
| 1912 | returns a PyListObject containing all the values |
| 1913 | from the dictionary, as in the mapping method \code{values()} (see the Reference Guide) |
| 1914 | \end{cfuncdesc} |
| 1915 | |
| 1916 | \begin{cfuncdesc}{int}{PyDict_Size}{PyDictObject *p} |
| 1917 | returns the number of items in the dictionary. |
| 1918 | \end{cfuncdesc} |
| 1919 | |
| 1920 | \begin{cfuncdesc}{int}{PyDict_Next}{PyDictObject *p, |
| 1921 | int ppos, |
| 1922 | PyObject **pkey, |
| 1923 | PyObject **pvalue} |
| 1924 | |
| 1925 | \end{cfuncdesc} |
| 1926 | |
| 1927 | |
| 1928 | \section{Numeric Objects} |
| 1929 | |
| 1930 | \subsection{Plain Integer Objects} |
| 1931 | |
| 1932 | \begin{ctypedesc}{PyIntObject} |
| 1933 | This subtype of \code{PyObject} represents a Python integer object. |
| 1934 | \end{ctypedesc} |
| 1935 | |
| 1936 | \begin{cvardesc}{PyTypeObject}{PyInt_Type} |
| 1937 | This instance of \code{PyTypeObject} represents the Python plain |
| 1938 | integer type. |
| 1939 | \end{cvardesc} |
| 1940 | |
| 1941 | \begin{cfuncdesc}{int}{PyInt_Check}{PyObject *} |
| 1942 | |
| 1943 | \end{cfuncdesc} |
| 1944 | |
| 1945 | \begin{cfuncdesc}{PyIntObject *}{PyInt_FromLong}{long ival} |
| 1946 | creates a new integer object with a value of \code{ival}. |
| 1947 | |
| 1948 | The current implementation keeps an array of integer objects for all |
| 1949 | integers between -1 and 100, when you create an int in that range you |
| 1950 | actually just get back a reference to the existing object. So it should |
| 1951 | be possible to change the value of 1. I suspect the behaviour of python |
| 1952 | in this case is undefined. :-) |
| 1953 | \end{cfuncdesc} |
| 1954 | |
| 1955 | \begin{cfuncdesc}{long}{PyInt_AS_LONG}{PyIntObject *io} |
| 1956 | returns the value of the object \code{io}. |
| 1957 | \end{cfuncdesc} |
| 1958 | |
| 1959 | \begin{cfuncdesc}{long}{PyInt_AsLong}{PyObject *io} |
| 1960 | will first attempt to cast the object to a PyIntObject, if |
| 1961 | it is not already one, and the return it's value. |
| 1962 | \end{cfuncdesc} |
| 1963 | |
| 1964 | \begin{cfuncdesc}{long}{PyInt_GetMax}{} |
| 1965 | returns the systems idea of the largest int it can handle |
| 1966 | (LONG_MAX, as defined in the system header files) |
| 1967 | \end{cfuncdesc} |
| 1968 | |
| 1969 | |
| 1970 | \subsection{Long Integer Objects} |
| 1971 | |
| 1972 | \begin{ctypedesc}{PyLongObject} |
| 1973 | This subtype of \code{PyObject} represents a Python long integer object. |
| 1974 | \end{ctypedesc} |
| 1975 | |
| 1976 | \begin{cvardesc}{PyTypeObject}{PyLong_Type} |
| 1977 | This instance of \code{PyTypeObject} represents the Python long integer type. |
| 1978 | \end{cvardesc} |
| 1979 | |
| 1980 | \begin{cfuncdesc}{int}{PyLong_Check}{PyObject *p} |
| 1981 | returns true if it's argument is a \code{PyLongObject} |
| 1982 | \end{cfuncdesc} |
| 1983 | |
| 1984 | \begin{cfuncdesc}{PyObject *}{PyLong_FromLong}{long} |
| 1985 | |
| 1986 | \end{cfuncdesc} |
| 1987 | |
| 1988 | \begin{cfuncdesc}{PyObject *}{PyLong_FromUnsignedLong}{unsigned long} |
| 1989 | |
| 1990 | \end{cfuncdesc} |
| 1991 | |
| 1992 | \begin{cfuncdesc}{PyObject *}{PyLong_FromDouble}{double} |
| 1993 | |
| 1994 | \end{cfuncdesc} |
| 1995 | |
| 1996 | \begin{cfuncdesc}{long}{PyLong_AsLong}{PyObject *} |
| 1997 | |
| 1998 | \end{cfuncdesc} |
| 1999 | |
| 2000 | \begin{cfuncdesc}{unsigned long}{PyLong_AsUnsignedLong}{PyObject } |
| 2001 | |
| 2002 | \end{cfuncdesc} |
| 2003 | |
| 2004 | \begin{cfuncdesc}{double}{PyLong_AsDouble}{PyObject *} |
| 2005 | |
| 2006 | \end{cfuncdesc} |
| 2007 | |
| 2008 | \begin{cfuncdesc}{PyObject *}{*PyLong_FromString}{char *, char **, int} |
| 2009 | |
| 2010 | \end{cfuncdesc} |
| 2011 | |
| 2012 | |
| 2013 | \subsection{Floating Point Objects} |
| 2014 | |
| 2015 | \begin{ctypedesc}{PyFloatObject} |
| 2016 | This subtype of \code{PyObject} represents a Python floating point object. |
| 2017 | \end{ctypedesc} |
| 2018 | |
| 2019 | \begin{cvardesc}{PyTypeObject}{PyFloat_Type} |
| 2020 | This instance of \code{PyTypeObject} represents the Python floating |
| 2021 | point type. |
| 2022 | \end{cvardesc} |
| 2023 | |
| 2024 | \begin{cfuncdesc}{int}{PyFloat_Check}{PyObject *p} |
| 2025 | returns true if it's argument is a \code{PyFloatObject} |
| 2026 | \end{cfuncdesc} |
| 2027 | |
| 2028 | \begin{cfuncdesc}{PyObject *}{PyFloat_FromDouble}{double} |
| 2029 | |
| 2030 | \end{cfuncdesc} |
| 2031 | |
| 2032 | \begin{cfuncdesc}{double}{PyFloat_AsDouble}{PyObject *} |
| 2033 | |
| 2034 | \end{cfuncdesc} |
| 2035 | |
| 2036 | \begin{cfuncdesc}{double}{PyFloat_AS_DOUBLE}{PyFloatObject *} |
| 2037 | |
| 2038 | \end{cfuncdesc} |
| 2039 | |
| 2040 | |
| 2041 | \subsection{Complex Number Objects} |
| 2042 | |
| 2043 | \begin{ctypedesc}{Py_complex} |
| 2044 | typedef struct { |
| 2045 | double real; |
| 2046 | double imag; |
| 2047 | } |
| 2048 | \end{ctypedesc} |
| 2049 | |
| 2050 | \begin{ctypedesc}{PyComplexObject} |
| 2051 | This subtype of \code{PyObject} represents a Python complex number object. |
| 2052 | \end{ctypedesc} |
| 2053 | |
| 2054 | \begin{cvardesc}{PyTypeObject}{PyComplex_Type} |
| 2055 | This instance of \code{PyTypeObject} represents the Python complex |
| 2056 | number type. |
| 2057 | \end{cvardesc} |
| 2058 | |
| 2059 | \begin{cfuncdesc}{int}{PyComplex_Check}{PyObject *p} |
| 2060 | returns true if it's argument is a \code{PyComplexObject} |
| 2061 | \end{cfuncdesc} |
| 2062 | |
| 2063 | \begin{cfuncdesc}{Py_complex}{_Py_c_sum}{Py_complex, Py_complex} |
| 2064 | |
| 2065 | \end{cfuncdesc} |
| 2066 | |
| 2067 | \begin{cfuncdesc}{Py_complex}{_Py_c_diff}{Py_complex, Py_complex} |
| 2068 | |
| 2069 | \end{cfuncdesc} |
| 2070 | |
| 2071 | \begin{cfuncdesc}{Py_complex}{_Py_c_neg}{Py_complex} |
| 2072 | |
| 2073 | \end{cfuncdesc} |
| 2074 | |
| 2075 | \begin{cfuncdesc}{Py_complex}{_Py_c_prod}{Py_complex, Py_complex} |
| 2076 | |
| 2077 | \end{cfuncdesc} |
| 2078 | |
| 2079 | \begin{cfuncdesc}{Py_complex}{_Py_c_quot}{Py_complex, Py_complex} |
| 2080 | |
| 2081 | \end{cfuncdesc} |
| 2082 | |
| 2083 | \begin{cfuncdesc}{Py_complex}{_Py_c_pow}{Py_complex, Py_complex} |
| 2084 | |
| 2085 | \end{cfuncdesc} |
| 2086 | |
| 2087 | \begin{cfuncdesc}{PyObject *}{PyComplex_FromCComplex}{Py_complex} |
| 2088 | |
| 2089 | \end{cfuncdesc} |
| 2090 | |
| 2091 | \begin{cfuncdesc}{PyObject *}{PyComplex_FromDoubles}{double real, double imag} |
| 2092 | |
| 2093 | \end{cfuncdesc} |
| 2094 | |
| 2095 | \begin{cfuncdesc}{double}{PyComplex_RealAsDouble}{PyObject *op} |
| 2096 | |
| 2097 | \end{cfuncdesc} |
| 2098 | |
| 2099 | \begin{cfuncdesc}{double}{PyComplex_ImagAsDouble}{PyObject *op} |
| 2100 | |
| 2101 | \end{cfuncdesc} |
| 2102 | |
| 2103 | \begin{cfuncdesc}{Py_complex}{PyComplex_AsCComplex}{PyObject *op} |
| 2104 | |
| 2105 | \end{cfuncdesc} |
| 2106 | |
| 2107 | |
| 2108 | |
| 2109 | \section{Other Objects} |
| 2110 | |
| 2111 | \subsection{File Objects} |
| 2112 | |
| 2113 | \begin{ctypedesc}{PyFileObject} |
| 2114 | This subtype of \code{PyObject} represents a Python file object. |
| 2115 | \end{ctypedesc} |
| 2116 | |
| 2117 | \begin{cvardesc}{PyTypeObject}{PyFile_Type} |
| 2118 | This instance of \code{PyTypeObject} represents the Python file type. |
| 2119 | \end{cvardesc} |
| 2120 | |
| 2121 | \begin{cfuncdesc}{int}{PyFile_Check}{PyObject *p} |
| 2122 | returns true if it's argument is a \code{PyFileObject} |
| 2123 | \end{cfuncdesc} |
| 2124 | |
| 2125 | \begin{cfuncdesc}{PyObject *}{PyFile_FromString}{char *name, char *mode} |
| 2126 | creates a new PyFileObject pointing to the file |
| 2127 | specified in \code{name} with the mode specified in \code{mode} |
| 2128 | \end{cfuncdesc} |
| 2129 | |
| 2130 | \begin{cfuncdesc}{PyObject *}{PyFile_FromFile}{FILE *fp, |
| 2131 | char *name, char *mode, int (*close}) |
| 2132 | creates a new PyFileObject from the already-open \code{fp}. |
| 2133 | The function \code{close} will be called when the file should be closed. |
| 2134 | \end{cfuncdesc} |
| 2135 | |
| 2136 | \begin{cfuncdesc}{FILE *}{PyFile_AsFile}{PyFileObject *p} |
| 2137 | returns the file object associated with \code{p} as a \code{FILE *} |
| 2138 | \end{cfuncdesc} |
| 2139 | |
| 2140 | \begin{cfuncdesc}{PyStringObject *}{PyFile_GetLine}{PyObject *p, int n} |
| 2141 | undocumented as yet |
| 2142 | \end{cfuncdesc} |
| 2143 | |
| 2144 | \begin{cfuncdesc}{PyStringObject *}{PyFile_Name}{PyObject *p} |
| 2145 | returns the name of the file specified by \code{p} as a |
| 2146 | PyStringObject |
| 2147 | \end{cfuncdesc} |
| 2148 | |
| 2149 | \begin{cfuncdesc}{void}{PyFile_SetBufSize}{PyFileObject *p, int n} |
| 2150 | on systems with \code{setvbuf} only |
| 2151 | \end{cfuncdesc} |
| 2152 | |
| 2153 | \begin{cfuncdesc}{int}{PyFile_SoftSpace}{PyFileObject *p, int newflag} |
| 2154 | same as the file object method \code{softspace} |
| 2155 | \end{cfuncdesc} |
| 2156 | |
| 2157 | \begin{cfuncdesc}{int}{PyFile_WriteObject}{PyObject *obj, PyFileObject *p} |
| 2158 | writes object \code{obj} to file object \code{p} |
| 2159 | \end{cfuncdesc} |
| 2160 | |
| 2161 | \begin{cfuncdesc}{int}{PyFile_WriteString}{char *s, PyFileObject *p} |
| 2162 | writes string \code{s} to file object \code{p} |
| 2163 | \end{cfuncdesc} |
| 2164 | |
| 2165 | |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 2166 | \input{api.ind} % Index -- must be last |
| 2167 | |
| 2168 | \end{document} |