blob: 183abd06efd1449defae459fd47592b4a8d1cb81 [file] [log] [blame]
Guido van Rossum0011d931996-08-22 23:18:55 +00001\newcommand{\NULL}{\code{NULL}}
2
3\chapter{Extension Reference}
Guido van Rossum267e80d1996-08-09 21:01:07 +00004
Guido van Rossumb54f4de1996-11-06 15:47:58 +00005\section{Introduction}
6
Guido van Rossum267e80d1996-08-09 21:01:07 +00007From the viewpoint of of C access to Python services, we have:
8
9\begin{enumerate}
10 \item "Very high level layer": two or three functions that let you exec or
11 eval arbitrary Python code given as a string in a module whose name is
12 given, passing C values in and getting C values out using
13 mkvalue/getargs style format strings. This does not require the user
14 to declare any variables of type "PyObject *". This should be enough
15 to write a simple application that gets Python code from the user,
16 execs it, and returns the output or errors.
17
Guido van Rossumb54f4de1996-11-06 15:47:58 +000018 \item "Abstract objects layer": which is the subject of this chapter.
Guido van Rossum267e80d1996-08-09 21:01:07 +000019 It has many functions operating on objects, and lest you do many
20 things from C that you can also write in Python, without going
21 through the Python parser.
22
23 \item "Concrete objects layer": This is the public type-dependent
24 interface provided by the standard built-in types, such as floats,
25 strings, and lists. This interface exists and is currently
26 documented by the collection of include files provides with the
27 Python distributions.
28
29 From the point of view of Python accessing services provided by C
30 modules:
31
32 \item "Python module interface": this interface consist of the basic
33 routines used to define modules and their members. Most of the
34 current extensions-writing guide deals with this interface.
35
36 \item "Built-in object interface": this is the interface that a new
37 built-in type must provide and the mechanisms and rules that a
38 developer of a new built-in type must use and follow.
39\end{enumerate}
40
41 The Python C object interface provides four protocols: object,
42 numeric, sequence, and mapping. Each protocol consists of a
43 collection of related operations. If an operation that is not
44 provided by a particular type is invoked, then a standard exception,
45 NotImplementedError is raised with a operation name as an argument.
46 In addition, for convenience this interface defines a set of
47 constructors for building objects of built-in types. This is needed
48 so new objects can be returned from C functions that otherwise treat
49 objects generically.
50
Guido van Rossumb54f4de1996-11-06 15:47:58 +000051\subsection{Memory Management}
52
53 For all of the functions described in this chapter, if a function
54 retains a reference to a Python object passed as an argument, then the
55 function will increase the reference count of the object. It is
56 unnecessary for the caller to increase the reference count of an
57 argument in anticipation of the object's retention.
58
59 All Python objects returned from functions should be treated as new
60 objects. Functions that return objects assume that the caller will
61 retain a reference and the reference count of the object has already
62 been incremented to account for this fact. A caller that does not
63 retain a reference to an object that is returned from a function
64 must decrement the reference count of the object (using
65 DECREF(object)) to prevent memory leaks.
66
67
Guido van Rossum0011d931996-08-22 23:18:55 +000068\section{Object Protocol}
69
70 \begin{cfuncdesc}{int}{PyObject_Print}{PyObject *o, FILE *fp, int flags}
Guido van Rossum267e80d1996-08-09 21:01:07 +000071 Print an object \code{o}, on file \code{fp}. Returns -1 on error
72 The flags argument is used to enable certain printing
73 options. The only option currently supported is \code{Py_Print_RAW}.
Guido van Rossum0011d931996-08-22 23:18:55 +000074 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000075
Guido van Rossum0011d931996-08-22 23:18:55 +000076 \begin{cfuncdesc}{int}{PyObject_HasAttrString}{PyObject *o, char *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +000077 Returns 1 if o has the attribute attr_name, and 0 otherwise.
Guido van Rossum0011d931996-08-22 23:18:55 +000078 This is equivalent to the Python expression:
Guido van Rossum267e80d1996-08-09 21:01:07 +000079 \code{hasattr(o,attr_name)}.
80 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +000081 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000082
Guido van Rossum0011d931996-08-22 23:18:55 +000083 \begin{cfuncdesc}{PyObject*}{PyObject_AttrString}{PyObject *o, char *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +000084 Retrieve an attributed named attr_name form object o.
Guido van Rossum0011d931996-08-22 23:18:55 +000085 Returns the attribute value on success, or {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +000086 This is the equivalent of the Python expression: \code{o.attr_name}.
Guido van Rossum0011d931996-08-22 23:18:55 +000087 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000088
89
Guido van Rossum0011d931996-08-22 23:18:55 +000090 \begin{cfuncdesc}{int}{PyObject_HasAttr}{PyObject *o, PyObject *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +000091 Returns 1 if o has the attribute attr_name, and 0 otherwise.
92 This is equivalent to the Python expression:
93 \code{hasattr(o,attr_name)}.
94 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +000095 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000096
97
Guido van Rossum0011d931996-08-22 23:18:55 +000098 \begin{cfuncdesc}{PyObject*}{PyObject_GetAttr}{PyObject *o, PyObject *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +000099 Retrieve an attributed named attr_name form object o.
Guido van Rossum0011d931996-08-22 23:18:55 +0000100 Returns the attribute value on success, or {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +0000101 This is the equivalent of the Python expression: o.attr_name.
Guido van Rossum0011d931996-08-22 23:18:55 +0000102 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000103
104
Guido van Rossum0011d931996-08-22 23:18:55 +0000105 \begin{cfuncdesc}{int}{PyObject_SetAttrString}{PyObject *o, char *attr_name, PyObject *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000106 Set the value of the attribute named \code{attr_name}, for object \code{o},
107 to the value \code{v}. Returns -1 on failure. This is
108 the equivalent of the Python statement: \code{o.attr_name=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000109 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000110
111
Guido van Rossum0011d931996-08-22 23:18:55 +0000112 \begin{cfuncdesc}{int}{PyObject_SetAttr}{PyObject *o, PyObject *attr_name, PyObject *v}
113 Set the value of the attribute named \code{attr_name}, for
114 object \code{o},
Guido van Rossum267e80d1996-08-09 21:01:07 +0000115 to the value \code{v}. Returns -1 on failure. This is
116 the equivalent of the Python statement: \code{o.attr_name=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000117 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000118
119
Guido van Rossum0011d931996-08-22 23:18:55 +0000120 \begin{cfuncdesc}{int}{PyObject_DelAttrString}{PyObject *o, char *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000121 Delete attribute named \code{attr_name}, for object \code{o}. Returns -1 on
122 failure. This is the equivalent of the Python
123 statement: \code{del o.attr_name}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000124 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000125
126
Guido van Rossum0011d931996-08-22 23:18:55 +0000127 \begin{cfuncdesc}{int}{PyObject_DelAttr}{PyObject *o, PyObject *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000128 Delete attribute named \code{attr_name}, for object \code{o}. Returns -1 on
129 failure. This is the equivalent of the Python
130 statement: \code{del o.attr_name}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000131 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000132
133
Guido van Rossum0011d931996-08-22 23:18:55 +0000134 \begin{cfuncdesc}{int}{PyObject_Cmp}{PyObject *o1, PyObject *o2, int *result}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000135 Compare the values of \code{o1} and \code{o2} using a routine provided by
136 \code{o1}, if one exists, otherwise with a routine provided by \code{o2}.
137 The result of the comparison is returned in \code{result}. Returns
138 -1 on failure. This is the equivalent of the Python
139 statement: \code{result=cmp(o1,o2)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000140 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000141
142
Guido van Rossum0011d931996-08-22 23:18:55 +0000143 \begin{cfuncdesc}{int}{PyObject_Compare}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000144 Compare the values of \code{o1} and \code{o2} using a routine provided by
145 \code{o1}, if one exists, otherwise with a routine provided by \code{o2}.
146 Returns the result of the comparison on success. On error,
147 the value returned is undefined. This is equivalent to the
148 Python expression: \code{cmp(o1,o2)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000149 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000150
151
Guido van Rossum0011d931996-08-22 23:18:55 +0000152 \begin{cfuncdesc}{PyObject*}{PyObject_Repr}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000153 Compute the string representation of object, \code{o}. Returns the
Guido van Rossum0011d931996-08-22 23:18:55 +0000154 string representation on success, {\NULL} on failure. This is
Guido van Rossum267e80d1996-08-09 21:01:07 +0000155 the equivalent of the Python expression: \code{repr(o)}.
156 Called by the \code{repr()} built-in function and by reverse quotes.
Guido van Rossum0011d931996-08-22 23:18:55 +0000157 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000158
159
Guido van Rossum0011d931996-08-22 23:18:55 +0000160 \begin{cfuncdesc}{PyObject*}{PyObject_Str}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000161 Compute the string representation of object, \code{o}. Returns the
Guido van Rossum0011d931996-08-22 23:18:55 +0000162 string representation on success, {\NULL} on failure. This is
Guido van Rossum267e80d1996-08-09 21:01:07 +0000163 the equivalent of the Python expression: \code{str(o)}.
164 Called by the \code{str()} built-in function and by the \code{print}
165 statement.
Guido van Rossum0011d931996-08-22 23:18:55 +0000166 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000167
168
Guido van Rossum0011d931996-08-22 23:18:55 +0000169 \begin{cfuncdesc}{int}{PyCallable_Check}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000170 Determine if the object \code{o}, is callable. Return 1 if the
171 object is callable and 0 otherwise.
172 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000173 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000174
175
Guido van Rossum0011d931996-08-22 23:18:55 +0000176 \begin{cfuncdesc}{PyObject*}{PyObject_CallObject}{PyObject *callable_object, PyObject *args}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000177 Call a callable Python object \code{callable_object}, with
178 arguments given by the tuple \code{args}. If no arguments are
Guido van Rossum0011d931996-08-22 23:18:55 +0000179 needed, then args may be {\NULL}. Returns the result of the
180 call on success, or {\NULL} on failure. This is the equivalent
181 of the Python expression: \code{apply(o, args)}.
182 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000183
Guido van Rossum0011d931996-08-22 23:18:55 +0000184 \begin{cfuncdesc}{PyObject*}{PyObject_CallFunction}{PyObject *callable_object, char *format, ...}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000185 Call a callable Python object \code{callable_object}, with a
186 variable number of C arguments. The C arguments are described
Guido van Rossum0011d931996-08-22 23:18:55 +0000187 using a mkvalue-style format string. The format may be {\NULL},
Guido van Rossum267e80d1996-08-09 21:01:07 +0000188 indicating that no arguments are provided. Returns the
Guido van Rossum0011d931996-08-22 23:18:55 +0000189 result of the call on success, or {\NULL} on failure. This is
Guido van Rossum267e80d1996-08-09 21:01:07 +0000190 the equivalent of the Python expression: \code{apply(o,args)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000191 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000192
193
Guido van Rossum0011d931996-08-22 23:18:55 +0000194 \begin{cfuncdesc}{PyObject*}{PyObject_CallMethod}{PyObject *o, char *m, char *format, ...}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000195 Call the method named \code{m} of object \code{o} with a variable number of
196 C arguments. The C arguments are described by a mkvalue
Guido van Rossum0011d931996-08-22 23:18:55 +0000197 format string. The format may be {\NULL}, indicating that no
Guido van Rossum267e80d1996-08-09 21:01:07 +0000198 arguments are provided. Returns the result of the call on
Guido van Rossum0011d931996-08-22 23:18:55 +0000199 success, or {\NULL} on failure. This is the equivalent of the
Guido van Rossum267e80d1996-08-09 21:01:07 +0000200 Python expression: \code{o.method(args)}.
201 Note that Special method names, such as "\code{__add__}",
202 "\code{__getitem__}", and so on are not supported. The specific
203 abstract-object routines for these must be used.
Guido van Rossum0011d931996-08-22 23:18:55 +0000204 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000205
206
Guido van Rossum0011d931996-08-22 23:18:55 +0000207 \begin{cfuncdesc}{int}{PyObject_Hash}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000208 Compute and return the hash value of an object \code{o}. On
209 failure, return -1. This is the equivalent of the Python
210 expression: \code{hash(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000211 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000212
213
Guido van Rossum0011d931996-08-22 23:18:55 +0000214 \begin{cfuncdesc}{int}{PyObject_IsTrue}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000215 Returns 1 if the object \code{o} is considered to be true, and
216 0 otherwise. This is equivalent to the Python expression:
217 \code{not not o}.
218 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000219 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000220
221
Guido van Rossum0011d931996-08-22 23:18:55 +0000222 \begin{cfuncdesc}{PyObject*}{PyObject_Type}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000223 On success, returns a type object corresponding to the object
Guido van Rossum0011d931996-08-22 23:18:55 +0000224 type of object \code{o}. On failure, returns {\NULL}. This is
Guido van Rossum267e80d1996-08-09 21:01:07 +0000225 equivalent to the Python expression: \code{type(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000226 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000227
Guido van Rossum0011d931996-08-22 23:18:55 +0000228 \begin{cfuncdesc}{int}{PyObject_Length}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000229 Return the length of object \code{o}. If the object \code{o} provides
230 both sequence and mapping protocols, the sequence length is
231 returned. On error, -1 is returned. This is the equivalent
232 to the Python expression: \code{len(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000233 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000234
235
Guido van Rossum0011d931996-08-22 23:18:55 +0000236 \begin{cfuncdesc}{PyObject*}{PyObject_GetItem}{PyObject *o, PyObject *key}
237 Return element of \code{o} corresponding to the object \code{key} or {\NULL}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000238 on failure. This is the equivalent of the Python expression:
239 \code{o[key]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000240 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000241
242
Guido van Rossum0011d931996-08-22 23:18:55 +0000243 \begin{cfuncdesc}{int}{PyObject_SetItem}{PyObject *o, PyObject *key, PyObject *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000244 Map the object \code{key} to the value \code{v}.
245 Returns -1 on failure. This is the equivalent
246 of the Python statement: \code{o[key]=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000247 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000248
249
Guido van Rossum0011d931996-08-22 23:18:55 +0000250 \begin{cfuncdesc}{int}{PyObject_DelItem}{PyObject *o, PyObject *key, PyObject *v}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000251 Delete the mapping for \code{key} from \code{*o}. Returns -1
252 on failure.
253 This is the equivalent of the Python statement: del o[key].
Guido van Rossum0011d931996-08-22 23:18:55 +0000254 \end{cfuncdesc}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000255
256
Guido van Rossum0011d931996-08-22 23:18:55 +0000257\section{Number Protocol}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000258
Guido van Rossum0011d931996-08-22 23:18:55 +0000259 \begin{cfuncdesc}{int}{PyNumber_Check}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000260 Returns 1 if the object \code{o} provides numeric protocols, and
261 false otherwise.
262 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000263 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000264
265
Guido van Rossum0011d931996-08-22 23:18:55 +0000266 \begin{cfuncdesc}{PyObject*}{PyNumber_Add}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000267 Returns the result of adding \code{o1} and \code{o2}, or null on failure.
268 This is the equivalent of the Python expression: \code{o1+o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000269 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000270
271
Guido van Rossum0011d931996-08-22 23:18:55 +0000272 \begin{cfuncdesc}{PyObject*}{PyNumber_Subtract}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000273 Returns the result of subtracting \code{o2} from \code{o1}, or null on
274 failure. This is the equivalent of the Python expression:
275 \code{o1-o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000276 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000277
278
Guido van Rossum0011d931996-08-22 23:18:55 +0000279 \begin{cfuncdesc}{PyObject*}{PyNumber_Multiply}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000280 Returns the result of multiplying \code{o1} and \code{o2}, or null on
281 failure. This is the equivalent of the Python expression:
282 \code{o1*o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000283 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000284
285
Guido van Rossum0011d931996-08-22 23:18:55 +0000286 \begin{cfuncdesc}{PyObject*}{PyNumber_Divide}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000287 Returns the result of dividing \code{o1} by \code{o2}, or null on failure.
288 This is the equivalent of the Python expression: \code{o1/o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000289 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000290
291
Guido van Rossum0011d931996-08-22 23:18:55 +0000292 \begin{cfuncdesc}{PyObject*}{PyNumber_Remainder}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000293 Returns the remainder of dividing \code{o1} by \code{o2}, or null on
294 failure. This is the equivalent of the Python expression:
295 \code{o1\%o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000296 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000297
298
Guido van Rossum0011d931996-08-22 23:18:55 +0000299 \begin{cfuncdesc}{PyObject*}{PyNumber_Divmod}{PyObject *o1, PyObject *o2}
300 See the built-in function divmod. Returns {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +0000301 This is the equivalent of the Python expression:
302 \code{divmod(o1,o2)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000303 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000304
305
Guido van Rossum0011d931996-08-22 23:18:55 +0000306 \begin{cfuncdesc}{PyObject*}{PyNumber_Power}{PyObject *o1, PyObject *o2, PyObject *o3}
307 See the built-in function pow. Returns {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +0000308 This is the equivalent of the Python expression:
309 \code{pow(o1,o2,o3)}, where \code{o3} is optional.
Guido van Rossum0011d931996-08-22 23:18:55 +0000310 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000311
312
Guido van Rossum0011d931996-08-22 23:18:55 +0000313 \begin{cfuncdesc}{PyObject*}{PyNumber_Negative}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000314 Returns the negation of \code{o} on success, or null on failure.
315 This is the equivalent of the Python expression: \code{-o}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000316 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000317
318
Guido van Rossum0011d931996-08-22 23:18:55 +0000319 \begin{cfuncdesc}{PyObject*}{PyNumber_Positive}{PyObject *o}
320 Returns \code{o} on success, or {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +0000321 This is the equivalent of the Python expression: \code{+o}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000322 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000323
324
Guido van Rossum0011d931996-08-22 23:18:55 +0000325 \begin{cfuncdesc}{PyObject*}{PyNumber_Absolute}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000326 Returns the absolute value of \code{o}, or null on failure. This is
327 the equivalent of the Python expression: \code{abs(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000328 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000329
330
Guido van Rossum0011d931996-08-22 23:18:55 +0000331 \begin{cfuncdesc}{PyObject*}{PyNumber_Invert}{PyObject *o}
332 Returns the bitwise negation of \code{o} on success, or {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000333 failure. This is the equivalent of the Python expression:
334 \code{~o}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000335 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000336
337
Guido van Rossum0011d931996-08-22 23:18:55 +0000338 \begin{cfuncdesc}{PyObject*}{PyNumber_Lshift}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000339 Returns the result of left shifting \code{o1} by \code{o2} on success, or
Guido van Rossum0011d931996-08-22 23:18:55 +0000340 {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000341 expression: \code{o1 << o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000342 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000343
344
Guido van Rossum0011d931996-08-22 23:18:55 +0000345 \begin{cfuncdesc}{PyObject*}{PyNumber_Rshift}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000346 Returns the result of right shifting \code{o1} by \code{o2} on success, or
Guido van Rossum0011d931996-08-22 23:18:55 +0000347 {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000348 expression: \code{o1 >> o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000349 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000350
351
Guido van Rossum0011d931996-08-22 23:18:55 +0000352 \begin{cfuncdesc}{PyObject*}{PyNumber_And}{PyObject *o1, PyObject *o2}
353 Returns the result of "anding" \code{o2} and \code{o2} on success and {\NULL}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000354 on failure. This is the equivalent of the Python
355 expression: \code{o1 and o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000356 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000357
358
Guido van Rossum0011d931996-08-22 23:18:55 +0000359 \begin{cfuncdesc}{PyObject*}{PyNumber_Xor}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000360 Returns the bitwise exclusive or of \code{o1} by \code{o2} on success, or
Guido van Rossum0011d931996-08-22 23:18:55 +0000361 {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000362 expression: \code{o1\^{ }o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000363 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000364
Guido van Rossum0011d931996-08-22 23:18:55 +0000365 \begin{cfuncdesc}{PyObject*}{PyNumber_Or}{PyObject *o1, PyObject *o2}
366 Returns the result or \code{o1} and \code{o2} on success, or {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000367 failure. This is the equivalent of the Python expression:
368 \code{o1 or o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000369 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000370
371
Guido van Rossum0011d931996-08-22 23:18:55 +0000372 \begin{cfuncdesc}{PyObject*}{PyNumber_Coerce}{PyObject *o1, PyObject *o2}
Guido van Rossumc05797d1996-09-10 17:36:17 +0000373 This function takes the addresses of two variables of type
374 \code{PyObject*}.
375
376 If the objects pointed to by \code{*p1} and \code{*p2} have the same type,
377 increment their reference count and return 0 (success).
378 If the objects can be converted to a common numeric type,
379 replace \code{*p1} and \code{*p2} by their converted value (with 'new'
380 reference counts), and return 0.
381 If no conversion is possible, or if some other error occurs,
382 return -1 (failure) and don't increment the reference counts.
Guido van Rossume86cbc41996-09-27 17:28:03 +0000383 The call \code{PyNumber_Coerce(\&o1, \&o2)} is equivalent to the Python
Guido van Rossumc05797d1996-09-10 17:36:17 +0000384 statement \code{o1, o2 = coerce(o1, o2)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000385 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000386
387
Guido van Rossum0011d931996-08-22 23:18:55 +0000388 \begin{cfuncdesc}{PyObject*}{PyNumber_Int}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000389 Returns the \code{o} converted to an integer object on success, or
Guido van Rossum0011d931996-08-22 23:18:55 +0000390 {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000391 expression: \code{int(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000392 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000393
394
Guido van Rossum0011d931996-08-22 23:18:55 +0000395 \begin{cfuncdesc}{PyObject*}{PyNumber_Long}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000396 Returns the \code{o} converted to a long integer object on success,
Guido van Rossum0011d931996-08-22 23:18:55 +0000397 or {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000398 expression: \code{long(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000399 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000400
401
Guido van Rossum0011d931996-08-22 23:18:55 +0000402 \begin{cfuncdesc}{PyObject*}{PyNumber_Float}{PyObject *o}
403 Returns the \code{o} converted to a float object on success, or {\NULL}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000404 on failure. This is the equivalent of the Python expression:
405 \code{float(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000406 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000407
408
Guido van Rossum0011d931996-08-22 23:18:55 +0000409\section{Sequence protocol}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000410
Guido van Rossum0011d931996-08-22 23:18:55 +0000411 \begin{cfuncdesc}{int}{PySequence_Check}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000412 Return 1 if the object provides sequence protocol, and 0
413 otherwise.
414 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000415 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000416
417
Guido van Rossum0011d931996-08-22 23:18:55 +0000418 \begin{cfuncdesc}{PyObject*}{PySequence_Concat}{PyObject *o1, PyObject *o2}
419 Return the concatination of \code{o1} and \code{o2} on success, and {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000420 failure. This is the equivalent of the Python
421 expression: \code{o1+o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000422 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000423
424
Guido van Rossum0011d931996-08-22 23:18:55 +0000425 \begin{cfuncdesc}{PyObject*}{PySequence_Repeat}{PyObject *o, int count}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000426 Return the result of repeating sequence object \code{o} count times,
Guido van Rossum0011d931996-08-22 23:18:55 +0000427 or {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000428 expression: \code{o*count}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000429 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000430
431
Guido van Rossum0011d931996-08-22 23:18:55 +0000432 \begin{cfuncdesc}{PyObject*}{PySequence_GetItem}{PyObject *o, int i}
433 Return the ith element of \code{o}, or {\NULL} on failure. This is the
Guido van Rossum267e80d1996-08-09 21:01:07 +0000434 equivalent of the Python expression: \code{o[i]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000435 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000436
437
Guido van Rossum0011d931996-08-22 23:18:55 +0000438 \begin{cfuncdesc}{PyObject*}{PySequence_GetSlice}{PyObject *o, int i1, int i2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000439 Return the slice of sequence object \code{o} between \code{i1} and \code{i2}, or
Guido van Rossum0011d931996-08-22 23:18:55 +0000440 {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000441 expression, \code{o[i1:i2]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000442 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000443
444
Guido van Rossum0011d931996-08-22 23:18:55 +0000445 \begin{cfuncdesc}{int}{PySequence_SetItem}{PyObject *o, int i, PyObject *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000446 Assign object \code{v} to the \code{i}th element of \code{o}.
447Returns -1 on failure. This is the equivalent of the Python
448 statement, \code{o[i]=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000449 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000450
Guido van Rossum0011d931996-08-22 23:18:55 +0000451 \begin{cfuncdesc}{int}{PySequence_DelItem}{PyObject *o, int i}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000452 Delete the \code{i}th element of object \code{v}. Returns
453 -1 on failure. This is the equivalent of the Python
454 statement: \code{del o[i]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000455 \end{cfuncdesc}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000456
Guido van Rossum0011d931996-08-22 23:18:55 +0000457 \begin{cfuncdesc}{int}{PySequence_SetSlice}{PyObject *o, int i1, int i2, PyObject *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000458 Assign the sequence object \code{v} to the slice in sequence
459 object \code{o} from \code{i1} to \code{i2}. This is the equivalent of the Python
460 statement, \code{o[i1:i2]=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000461 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000462
Guido van Rossum0011d931996-08-22 23:18:55 +0000463 \begin{cfuncdesc}{int}{PySequence_DelSlice}{PyObject *o, int i1, int i2}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000464 Delete the slice in sequence object, \code{o}, from \code{i1} to \code{i2}.
465 Returns -1 on failure. This is the equivalent of the Python
466 statement: \code{del o[i1:i2]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000467 \end{cfuncdesc}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000468
Guido van Rossum0011d931996-08-22 23:18:55 +0000469 \begin{cfuncdesc}{PyObject*}{PySequence_Tuple}{PyObject *o}
470 Returns the \code{o} as a tuple on success, and {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +0000471 This is equivalent to the Python expression: \code{tuple(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000472 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000473
Guido van Rossum0011d931996-08-22 23:18:55 +0000474 \begin{cfuncdesc}{int}{PySequence_Count}{PyObject *o, PyObject *value}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000475 Return the number of occurrences of \code{value} on \code{o}, that is,
476 return the number of keys for which \code{o[key]==value}. On
477 failure, return -1. This is equivalent to the Python
478 expression: \code{o.count(value)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000479 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000480
Guido van Rossum0011d931996-08-22 23:18:55 +0000481 \begin{cfuncdesc}{int}{PySequence_In}{PyObject *o, PyObject *value}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000482 Determine if \code{o} contains \code{value}. If an item in \code{o} is equal to
483 \code{value}, return 1, otherwise return 0. On error, return -1. This
484 is equivalent to the Python expression: \code{value in o}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000485 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000486
Guido van Rossum0011d931996-08-22 23:18:55 +0000487 \begin{cfuncdesc}{int}{PySequence_Index}{PyObject *o, PyObject *value}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000488 Return the first index for which \code{o[i]=value}. On error,
489 return -1. This is equivalent to the Python
490 expression: \code{o.index(value)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000491 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000492
Guido van Rossum0011d931996-08-22 23:18:55 +0000493\section{Mapping protocol}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000494
Guido van Rossum0011d931996-08-22 23:18:55 +0000495 \begin{cfuncdesc}{int}{PyMapping_Check}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000496 Return 1 if the object provides mapping protocol, and 0
497 otherwise.
498 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000499 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000500
501
Guido van Rossum0011d931996-08-22 23:18:55 +0000502 \begin{cfuncdesc}{int}{PyMapping_Length}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000503 Returns the number of keys in object \code{o} on success, and -1 on
504 failure. For objects that do not provide sequence protocol,
505 this is equivalent to the Python expression: \code{len(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000506 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000507
508
Guido van Rossum0011d931996-08-22 23:18:55 +0000509 \begin{cfuncdesc}{int}{PyMapping_DelItemString}{PyObject *o, char *key}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000510 Remove the mapping for object \code{key} from the object \code{o}.
511 Return -1 on failure. This is equivalent to
512 the Python statement: \code{del o[key]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000513 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000514
515
Guido van Rossum0011d931996-08-22 23:18:55 +0000516 \begin{cfuncdesc}{int}{PyMapping_DelItem}{PyObject *o, PyObject *key}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000517 Remove the mapping for object \code{key} from the object \code{o}.
518 Return -1 on failure. This is equivalent to
519 the Python statement: \code{del o[key]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000520 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000521
522
Guido van Rossum0011d931996-08-22 23:18:55 +0000523 \begin{cfuncdesc}{int}{PyMapping_HasKeyString}{PyObject *o, char *key}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000524 On success, return 1 if the mapping object has the key \code{key}
525 and 0 otherwise. This is equivalent to the Python expression:
526 \code{o.has_key(key)}.
527 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000528 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000529
530
Guido van Rossum0011d931996-08-22 23:18:55 +0000531 \begin{cfuncdesc}{int}{PyMapping_HasKey}{PyObject *o, PyObject *key}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000532 Return 1 if the mapping object has the key \code{key}
533 and 0 otherwise. This is equivalent to the Python expression:
534 \code{o.has_key(key)}.
535 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000536 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000537
538
Guido van Rossum0011d931996-08-22 23:18:55 +0000539 \begin{cfuncdesc}{PyObject*}{PyMapping_Keys}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000540 On success, return a list of the keys in object \code{o}. On
Guido van Rossum0011d931996-08-22 23:18:55 +0000541 failure, return {\NULL}. This is equivalent to the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000542 expression: \code{o.keys()}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000543 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000544
545
Guido van Rossum0011d931996-08-22 23:18:55 +0000546 \begin{cfuncdesc}{PyObject*}{PyMapping_Values}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000547 On success, return a list of the values in object \code{o}. On
Guido van Rossum0011d931996-08-22 23:18:55 +0000548 failure, return {\NULL}. This is equivalent to the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000549 expression: \code{o.values()}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000550 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000551
552
Guido van Rossum0011d931996-08-22 23:18:55 +0000553 \begin{cfuncdesc}{PyObject*}{PyMapping_Items}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000554 On success, return a list of the items in object \code{o}, where
555 each item is a tuple containing a key-value pair. On
Guido van Rossum0011d931996-08-22 23:18:55 +0000556 failure, return {\NULL}. This is equivalent to the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000557 expression: \code{o.items()}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000558 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000559
Guido van Rossum0011d931996-08-22 23:18:55 +0000560 \begin{cfuncdesc}{int}{PyMapping_Clear}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000561 Make object \code{o} empty. Returns 1 on success and 0 on failure.
562 This is equivalent to the Python statement:
563 \code{for key in o.keys(): del o[key]}
Guido van Rossum0011d931996-08-22 23:18:55 +0000564 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000565
566
Guido van Rossum0011d931996-08-22 23:18:55 +0000567 \begin{cfuncdesc}{PyObject*}{PyMapping_GetItemString}{PyObject *o, char *key}
568 Return element of \code{o} corresponding to the object \code{key} or {\NULL}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000569 on failure. This is the equivalent of the Python expression:
570 \code{o[key]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000571 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000572
Guido van Rossum0011d931996-08-22 23:18:55 +0000573 \begin{cfuncdesc}{PyObject*}{PyMapping_SetItemString}{PyObject *o, char *key, PyObject *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000574 Map the object \code{key} to the value \code{v} in object \code{o}. Returns
575 -1 on failure. This is the equivalent of the Python
576 statement: \code{o[key]=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000577 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000578
579
Guido van Rossum0011d931996-08-22 23:18:55 +0000580\section{Constructors}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000581
Guido van Rossum0011d931996-08-22 23:18:55 +0000582 \begin{cfuncdesc}{PyObject*}{PyFile_FromString}{char *file_name, char *mode}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000583 On success, returns a new file object that is opened on the
584 file given by \code{file_name}, with a file mode given by \code{mode},
585 where \code{mode} has the same semantics as the standard C routine,
586 fopen. On failure, return -1.
Guido van Rossum0011d931996-08-22 23:18:55 +0000587 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000588
Guido van Rossum0011d931996-08-22 23:18:55 +0000589 \begin{cfuncdesc}{PyObject*}{PyFile_FromFile}{FILE *fp, char *file_name, char *mode, int close_on_del}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000590 Return a new file object for an already opened standard C
591 file pointer, \code{fp}. A file name, \code{file_name}, and open mode,
592 \code{mode}, must be provided as well as a flag, \code{close_on_del}, that
593 indicates whether the file is to be closed when the file
594 object is destroyed. On failure, return -1.
Guido van Rossum0011d931996-08-22 23:18:55 +0000595 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000596
Guido van Rossum0011d931996-08-22 23:18:55 +0000597 \begin{cfuncdesc}{PyObject*}{PyFloat_FromDouble}{double v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000598 Returns a new float object with the value \code{v} on success, and
Guido van Rossum0011d931996-08-22 23:18:55 +0000599 {\NULL} on failure.
600 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000601
Guido van Rossum0011d931996-08-22 23:18:55 +0000602 \begin{cfuncdesc}{PyObject*}{PyInt_FromLong}{long v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000603 Returns a new int object with the value \code{v} on success, and
Guido van Rossum0011d931996-08-22 23:18:55 +0000604 {\NULL} on failure.
605 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000606
Guido van Rossum0011d931996-08-22 23:18:55 +0000607 \begin{cfuncdesc}{PyObject*}{PyList_New}{int l}
608 Returns a new list of length \code{l} on success, and {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000609 failure.
Guido van Rossum0011d931996-08-22 23:18:55 +0000610 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000611
Guido van Rossum0011d931996-08-22 23:18:55 +0000612 \begin{cfuncdesc}{PyObject*}{PyLong_FromLong}{long v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000613 Returns a new long object with the value \code{v} on success, and
Guido van Rossum0011d931996-08-22 23:18:55 +0000614 {\NULL} on failure.
615 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000616
Guido van Rossum0011d931996-08-22 23:18:55 +0000617 \begin{cfuncdesc}{PyObject*}{PyLong_FromDouble}{double v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000618 Returns a new long object with the value \code{v} on success, and
Guido van Rossum0011d931996-08-22 23:18:55 +0000619 {\NULL} on failure.
620 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000621
Guido van Rossum0011d931996-08-22 23:18:55 +0000622 \begin{cfuncdesc}{PyObject*}{PyDict_New}{}
623 Returns a new empty dictionary on success, and {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000624 failure.
Guido van Rossum0011d931996-08-22 23:18:55 +0000625 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000626
Guido van Rossum0011d931996-08-22 23:18:55 +0000627 \begin{cfuncdesc}{PyObject*}{PyString_FromString}{char *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000628 Returns a new string object with the value \code{v} on success, and
Guido van Rossum0011d931996-08-22 23:18:55 +0000629 {\NULL} on failure.
630 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000631
Guido van Rossum0011d931996-08-22 23:18:55 +0000632 \begin{cfuncdesc}{PyObject*}{PyString_FromStringAndSize}{char *v, int l}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000633 Returns a new string object with the value \code{v} and length \code{l}
Guido van Rossum0011d931996-08-22 23:18:55 +0000634 on success, and {\NULL} on failure.
635 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000636
Guido van Rossum0011d931996-08-22 23:18:55 +0000637 \begin{cfuncdesc}{PyObject*}{PyTuple_New}{int l}
638 Returns a new tuple of length \code{l} on success, and {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000639 failure.
Guido van Rossum0011d931996-08-22 23:18:55 +0000640 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000641