blob: 60940f567e0f2891fc9334a97e6c94b6c10e032e [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
5From the viewpoint of of C access to Python services, we have:
6
7\begin{enumerate}
8 \item "Very high level layer": two or three functions that let you exec or
9 eval arbitrary Python code given as a string in a module whose name is
10 given, passing C values in and getting C values out using
11 mkvalue/getargs style format strings. This does not require the user
12 to declare any variables of type "PyObject *". This should be enough
13 to write a simple application that gets Python code from the user,
14 execs it, and returns the output or errors.
15
16 \item "Abstract objects layer": which is the subject of this proposal.
17 It has many functions operating on objects, and lest you do many
18 things from C that you can also write in Python, without going
19 through the Python parser.
20
21 \item "Concrete objects layer": This is the public type-dependent
22 interface provided by the standard built-in types, such as floats,
23 strings, and lists. This interface exists and is currently
24 documented by the collection of include files provides with the
25 Python distributions.
26
27 From the point of view of Python accessing services provided by C
28 modules:
29
30 \item "Python module interface": this interface consist of the basic
31 routines used to define modules and their members. Most of the
32 current extensions-writing guide deals with this interface.
33
34 \item "Built-in object interface": this is the interface that a new
35 built-in type must provide and the mechanisms and rules that a
36 developer of a new built-in type must use and follow.
37\end{enumerate}
38
39 The Python C object interface provides four protocols: object,
40 numeric, sequence, and mapping. Each protocol consists of a
41 collection of related operations. If an operation that is not
42 provided by a particular type is invoked, then a standard exception,
43 NotImplementedError is raised with a operation name as an argument.
44 In addition, for convenience this interface defines a set of
45 constructors for building objects of built-in types. This is needed
46 so new objects can be returned from C functions that otherwise treat
47 objects generically.
48
Guido van Rossum0011d931996-08-22 23:18:55 +000049\section{Object Protocol}
50
51 \begin{cfuncdesc}{int}{PyObject_Print}{PyObject *o, FILE *fp, int flags}
Guido van Rossum267e80d1996-08-09 21:01:07 +000052 Print an object \code{o}, on file \code{fp}. Returns -1 on error
53 The flags argument is used to enable certain printing
54 options. The only option currently supported is \code{Py_Print_RAW}.
Guido van Rossum0011d931996-08-22 23:18:55 +000055 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000056
Guido van Rossum0011d931996-08-22 23:18:55 +000057 \begin{cfuncdesc}{int}{PyObject_HasAttrString}{PyObject *o, char *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +000058 Returns 1 if o has the attribute attr_name, and 0 otherwise.
Guido van Rossum0011d931996-08-22 23:18:55 +000059 This is equivalent to the Python expression:
Guido van Rossum267e80d1996-08-09 21:01:07 +000060 \code{hasattr(o,attr_name)}.
61 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +000062 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000063
Guido van Rossum0011d931996-08-22 23:18:55 +000064 \begin{cfuncdesc}{PyObject*}{PyObject_AttrString}{PyObject *o, char *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +000065 Retrieve an attributed named attr_name form object o.
Guido van Rossum0011d931996-08-22 23:18:55 +000066 Returns the attribute value on success, or {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +000067 This is the equivalent of the Python expression: \code{o.attr_name}.
Guido van Rossum0011d931996-08-22 23:18:55 +000068 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000069
70
Guido van Rossum0011d931996-08-22 23:18:55 +000071 \begin{cfuncdesc}{int}{PyObject_HasAttr}{PyObject *o, PyObject *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +000072 Returns 1 if o has the attribute attr_name, and 0 otherwise.
73 This is equivalent to the Python expression:
74 \code{hasattr(o,attr_name)}.
75 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +000076 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000077
78
Guido van Rossum0011d931996-08-22 23:18:55 +000079 \begin{cfuncdesc}{PyObject*}{PyObject_GetAttr}{PyObject *o, PyObject *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +000080 Retrieve an attributed named attr_name form object o.
Guido van Rossum0011d931996-08-22 23:18:55 +000081 Returns the attribute value on success, or {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +000082 This is the equivalent of the Python expression: o.attr_name.
Guido van Rossum0011d931996-08-22 23:18:55 +000083 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000084
85
Guido van Rossum0011d931996-08-22 23:18:55 +000086 \begin{cfuncdesc}{int}{PyObject_SetAttrString}{PyObject *o, char *attr_name, PyObject *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +000087 Set the value of the attribute named \code{attr_name}, for object \code{o},
88 to the value \code{v}. Returns -1 on failure. This is
89 the equivalent of the Python statement: \code{o.attr_name=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +000090 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000091
92
Guido van Rossum0011d931996-08-22 23:18:55 +000093 \begin{cfuncdesc}{int}{PyObject_SetAttr}{PyObject *o, PyObject *attr_name, PyObject *v}
94 Set the value of the attribute named \code{attr_name}, for
95 object \code{o},
Guido van Rossum267e80d1996-08-09 21:01:07 +000096 to the value \code{v}. Returns -1 on failure. This is
97 the equivalent of the Python statement: \code{o.attr_name=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +000098 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +000099
100
Guido van Rossum0011d931996-08-22 23:18:55 +0000101 \begin{cfuncdesc}{int}{PyObject_DelAttrString}{PyObject *o, char *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000102 Delete attribute named \code{attr_name}, for object \code{o}. Returns -1 on
103 failure. This is the equivalent of the Python
104 statement: \code{del o.attr_name}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000105 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000106
107
Guido van Rossum0011d931996-08-22 23:18:55 +0000108 \begin{cfuncdesc}{int}{PyObject_DelAttr}{PyObject *o, PyObject *attr_name}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000109 Delete attribute named \code{attr_name}, for object \code{o}. Returns -1 on
110 failure. This is the equivalent of the Python
111 statement: \code{del o.attr_name}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000112 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000113
114
Guido van Rossum0011d931996-08-22 23:18:55 +0000115 \begin{cfuncdesc}{int}{PyObject_Cmp}{PyObject *o1, PyObject *o2, int *result}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000116 Compare the values of \code{o1} and \code{o2} using a routine provided by
117 \code{o1}, if one exists, otherwise with a routine provided by \code{o2}.
118 The result of the comparison is returned in \code{result}. Returns
119 -1 on failure. This is the equivalent of the Python
120 statement: \code{result=cmp(o1,o2)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000121 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000122
123
Guido van Rossum0011d931996-08-22 23:18:55 +0000124 \begin{cfuncdesc}{int}{PyObject_Compare}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000125 Compare the values of \code{o1} and \code{o2} using a routine provided by
126 \code{o1}, if one exists, otherwise with a routine provided by \code{o2}.
127 Returns the result of the comparison on success. On error,
128 the value returned is undefined. This is equivalent to the
129 Python expression: \code{cmp(o1,o2)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000130 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000131
132
Guido van Rossum0011d931996-08-22 23:18:55 +0000133 \begin{cfuncdesc}{PyObject*}{PyObject_Repr}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000134 Compute the string representation of object, \code{o}. Returns the
Guido van Rossum0011d931996-08-22 23:18:55 +0000135 string representation on success, {\NULL} on failure. This is
Guido van Rossum267e80d1996-08-09 21:01:07 +0000136 the equivalent of the Python expression: \code{repr(o)}.
137 Called by the \code{repr()} built-in function and by reverse quotes.
Guido van Rossum0011d931996-08-22 23:18:55 +0000138 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000139
140
Guido van Rossum0011d931996-08-22 23:18:55 +0000141 \begin{cfuncdesc}{PyObject*}{PyObject_Str}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000142 Compute the string representation of object, \code{o}. Returns the
Guido van Rossum0011d931996-08-22 23:18:55 +0000143 string representation on success, {\NULL} on failure. This is
Guido van Rossum267e80d1996-08-09 21:01:07 +0000144 the equivalent of the Python expression: \code{str(o)}.
145 Called by the \code{str()} built-in function and by the \code{print}
146 statement.
Guido van Rossum0011d931996-08-22 23:18:55 +0000147 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000148
149
Guido van Rossum0011d931996-08-22 23:18:55 +0000150 \begin{cfuncdesc}{int}{PyCallable_Check}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000151 Determine if the object \code{o}, is callable. Return 1 if the
152 object is callable and 0 otherwise.
153 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000154 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000155
156
Guido van Rossum0011d931996-08-22 23:18:55 +0000157 \begin{cfuncdesc}{PyObject*}{PyObject_CallObject}{PyObject *callable_object, PyObject *args}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000158 Call a callable Python object \code{callable_object}, with
159 arguments given by the tuple \code{args}. If no arguments are
Guido van Rossum0011d931996-08-22 23:18:55 +0000160 needed, then args may be {\NULL}. Returns the result of the
161 call on success, or {\NULL} on failure. This is the equivalent
162 of the Python expression: \code{apply(o, args)}.
163 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000164
Guido van Rossum0011d931996-08-22 23:18:55 +0000165 \begin{cfuncdesc}{PyObject*}{PyObject_CallFunction}{PyObject *callable_object, char *format, ...}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000166 Call a callable Python object \code{callable_object}, with a
167 variable number of C arguments. The C arguments are described
Guido van Rossum0011d931996-08-22 23:18:55 +0000168 using a mkvalue-style format string. The format may be {\NULL},
Guido van Rossum267e80d1996-08-09 21:01:07 +0000169 indicating that no arguments are provided. Returns the
Guido van Rossum0011d931996-08-22 23:18:55 +0000170 result of the call on success, or {\NULL} on failure. This is
Guido van Rossum267e80d1996-08-09 21:01:07 +0000171 the equivalent of the Python expression: \code{apply(o,args)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000172 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000173
174
Guido van Rossum0011d931996-08-22 23:18:55 +0000175 \begin{cfuncdesc}{PyObject*}{PyObject_CallMethod}{PyObject *o, char *m, char *format, ...}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000176 Call the method named \code{m} of object \code{o} with a variable number of
177 C arguments. The C arguments are described by a mkvalue
Guido van Rossum0011d931996-08-22 23:18:55 +0000178 format string. The format may be {\NULL}, indicating that no
Guido van Rossum267e80d1996-08-09 21:01:07 +0000179 arguments are provided. Returns the result of the call on
Guido van Rossum0011d931996-08-22 23:18:55 +0000180 success, or {\NULL} on failure. This is the equivalent of the
Guido van Rossum267e80d1996-08-09 21:01:07 +0000181 Python expression: \code{o.method(args)}.
182 Note that Special method names, such as "\code{__add__}",
183 "\code{__getitem__}", and so on are not supported. The specific
184 abstract-object routines for these must be used.
Guido van Rossum0011d931996-08-22 23:18:55 +0000185 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000186
187
Guido van Rossum0011d931996-08-22 23:18:55 +0000188 \begin{cfuncdesc}{int}{PyObject_Hash}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000189 Compute and return the hash value of an object \code{o}. On
190 failure, return -1. This is the equivalent of the Python
191 expression: \code{hash(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000192 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000193
194
Guido van Rossum0011d931996-08-22 23:18:55 +0000195 \begin{cfuncdesc}{int}{PyObject_IsTrue}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000196 Returns 1 if the object \code{o} is considered to be true, and
197 0 otherwise. This is equivalent to the Python expression:
198 \code{not not o}.
199 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000200 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000201
202
Guido van Rossum0011d931996-08-22 23:18:55 +0000203 \begin{cfuncdesc}{PyObject*}{PyObject_Type}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000204 On success, returns a type object corresponding to the object
Guido van Rossum0011d931996-08-22 23:18:55 +0000205 type of object \code{o}. On failure, returns {\NULL}. This is
Guido van Rossum267e80d1996-08-09 21:01:07 +0000206 equivalent to the Python expression: \code{type(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000207 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000208
Guido van Rossum0011d931996-08-22 23:18:55 +0000209 \begin{cfuncdesc}{int}{PyObject_Length}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000210 Return the length of object \code{o}. If the object \code{o} provides
211 both sequence and mapping protocols, the sequence length is
212 returned. On error, -1 is returned. This is the equivalent
213 to the Python expression: \code{len(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000214 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000215
216
Guido van Rossum0011d931996-08-22 23:18:55 +0000217 \begin{cfuncdesc}{PyObject*}{PyObject_GetItem}{PyObject *o, PyObject *key}
218 Return element of \code{o} corresponding to the object \code{key} or {\NULL}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000219 on failure. This is the equivalent of the Python expression:
220 \code{o[key]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000221 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000222
223
Guido van Rossum0011d931996-08-22 23:18:55 +0000224 \begin{cfuncdesc}{int}{PyObject_SetItem}{PyObject *o, PyObject *key, PyObject *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000225 Map the object \code{key} to the value \code{v}.
226 Returns -1 on failure. This is the equivalent
227 of the Python statement: \code{o[key]=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000228 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000229
230
Guido van Rossum0011d931996-08-22 23:18:55 +0000231 \begin{cfuncdesc}{int}{PyObject_DelItem}{PyObject *o, PyObject *key, PyObject *v}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000232 Delete the mapping for \code{key} from \code{*o}. Returns -1
233 on failure.
234 This is the equivalent of the Python statement: del o[key].
Guido van Rossum0011d931996-08-22 23:18:55 +0000235 \end{cfuncdesc}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000236
237
Guido van Rossum0011d931996-08-22 23:18:55 +0000238\section{Number Protocol}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000239
Guido van Rossum0011d931996-08-22 23:18:55 +0000240 \begin{cfuncdesc}{int}{PyNumber_Check}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000241 Returns 1 if the object \code{o} provides numeric protocols, and
242 false otherwise.
243 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000244 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000245
246
Guido van Rossum0011d931996-08-22 23:18:55 +0000247 \begin{cfuncdesc}{PyObject*}{PyNumber_Add}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000248 Returns the result of adding \code{o1} and \code{o2}, or null on failure.
249 This is the equivalent of the Python expression: \code{o1+o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000250 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000251
252
Guido van Rossum0011d931996-08-22 23:18:55 +0000253 \begin{cfuncdesc}{PyObject*}{PyNumber_Subtract}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000254 Returns the result of subtracting \code{o2} from \code{o1}, or null on
255 failure. This is the equivalent of the Python expression:
256 \code{o1-o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000257 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000258
259
Guido van Rossum0011d931996-08-22 23:18:55 +0000260 \begin{cfuncdesc}{PyObject*}{PyNumber_Multiply}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000261 Returns the result of multiplying \code{o1} and \code{o2}, or null on
262 failure. This is the equivalent of the Python expression:
263 \code{o1*o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000264 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000265
266
Guido van Rossum0011d931996-08-22 23:18:55 +0000267 \begin{cfuncdesc}{PyObject*}{PyNumber_Divide}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000268 Returns the result of dividing \code{o1} by \code{o2}, or null on failure.
269 This is the equivalent of the Python expression: \code{o1/o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000270 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000271
272
Guido van Rossum0011d931996-08-22 23:18:55 +0000273 \begin{cfuncdesc}{PyObject*}{PyNumber_Remainder}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000274 Returns the remainder of dividing \code{o1} by \code{o2}, or null on
275 failure. This is the equivalent of the Python expression:
276 \code{o1\%o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000277 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000278
279
Guido van Rossum0011d931996-08-22 23:18:55 +0000280 \begin{cfuncdesc}{PyObject*}{PyNumber_Divmod}{PyObject *o1, PyObject *o2}
281 See the built-in function divmod. Returns {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +0000282 This is the equivalent of the Python expression:
283 \code{divmod(o1,o2)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000284 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000285
286
Guido van Rossum0011d931996-08-22 23:18:55 +0000287 \begin{cfuncdesc}{PyObject*}{PyNumber_Power}{PyObject *o1, PyObject *o2, PyObject *o3}
288 See the built-in function pow. Returns {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +0000289 This is the equivalent of the Python expression:
290 \code{pow(o1,o2,o3)}, where \code{o3} is optional.
Guido van Rossum0011d931996-08-22 23:18:55 +0000291 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000292
293
Guido van Rossum0011d931996-08-22 23:18:55 +0000294 \begin{cfuncdesc}{PyObject*}{PyNumber_Negative}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000295 Returns the negation of \code{o} on success, or null on failure.
296 This is the equivalent of the Python expression: \code{-o}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000297 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000298
299
Guido van Rossum0011d931996-08-22 23:18:55 +0000300 \begin{cfuncdesc}{PyObject*}{PyNumber_Positive}{PyObject *o}
301 Returns \code{o} on success, or {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +0000302 This is the equivalent of the Python expression: \code{+o}.
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_Absolute}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000307 Returns the absolute value of \code{o}, or null on failure. This is
308 the equivalent of the Python expression: \code{abs(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000309 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000310
311
Guido van Rossum0011d931996-08-22 23:18:55 +0000312 \begin{cfuncdesc}{PyObject*}{PyNumber_Invert}{PyObject *o}
313 Returns the bitwise negation of \code{o} on success, or {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000314 failure. This is the equivalent of the Python expression:
315 \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_Lshift}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000320 Returns the result of left shifting \code{o1} by \code{o2} on success, or
Guido van Rossum0011d931996-08-22 23:18:55 +0000321 {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000322 expression: \code{o1 << o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000323 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000324
325
Guido van Rossum0011d931996-08-22 23:18:55 +0000326 \begin{cfuncdesc}{PyObject*}{PyNumber_Rshift}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000327 Returns the result of right shifting \code{o1} by \code{o2} on success, or
Guido van Rossum0011d931996-08-22 23:18:55 +0000328 {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000329 expression: \code{o1 >> o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000330 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000331
332
Guido van Rossum0011d931996-08-22 23:18:55 +0000333 \begin{cfuncdesc}{PyObject*}{PyNumber_And}{PyObject *o1, PyObject *o2}
334 Returns the result of "anding" \code{o2} and \code{o2} on success and {\NULL}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000335 on failure. This is the equivalent of the Python
336 expression: \code{o1 and o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000337 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000338
339
Guido van Rossum0011d931996-08-22 23:18:55 +0000340 \begin{cfuncdesc}{PyObject*}{PyNumber_Xor}{PyObject *o1, PyObject *o2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000341 Returns the bitwise exclusive or of \code{o1} by \code{o2} on success, or
Guido van Rossum0011d931996-08-22 23:18:55 +0000342 {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000343 expression: \code{o1\^{ }o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000344 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000345
Guido van Rossum0011d931996-08-22 23:18:55 +0000346 \begin{cfuncdesc}{PyObject*}{PyNumber_Or}{PyObject *o1, PyObject *o2}
347 Returns the result or \code{o1} and \code{o2} on success, or {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000348 failure. This is the equivalent of the Python expression:
349 \code{o1 or o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000350 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000351
352
Guido van Rossum0011d931996-08-22 23:18:55 +0000353 \begin{cfuncdesc}{PyObject*}{PyNumber_Coerce}{PyObject *o1, PyObject *o2}
Guido van Rossumc05797d1996-09-10 17:36:17 +0000354 This function takes the addresses of two variables of type
355 \code{PyObject*}.
356
357 If the objects pointed to by \code{*p1} and \code{*p2} have the same type,
358 increment their reference count and return 0 (success).
359 If the objects can be converted to a common numeric type,
360 replace \code{*p1} and \code{*p2} by their converted value (with 'new'
361 reference counts), and return 0.
362 If no conversion is possible, or if some other error occurs,
363 return -1 (failure) and don't increment the reference counts.
Guido van Rossume86cbc41996-09-27 17:28:03 +0000364 The call \code{PyNumber_Coerce(\&o1, \&o2)} is equivalent to the Python
Guido van Rossumc05797d1996-09-10 17:36:17 +0000365 statement \code{o1, o2 = coerce(o1, o2)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000366 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000367
368
Guido van Rossum0011d931996-08-22 23:18:55 +0000369 \begin{cfuncdesc}{PyObject*}{PyNumber_Int}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000370 Returns the \code{o} converted to an integer object on success, or
Guido van Rossum0011d931996-08-22 23:18:55 +0000371 {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000372 expression: \code{int(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000373 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000374
375
Guido van Rossum0011d931996-08-22 23:18:55 +0000376 \begin{cfuncdesc}{PyObject*}{PyNumber_Long}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000377 Returns the \code{o} converted to a long integer object on success,
Guido van Rossum0011d931996-08-22 23:18:55 +0000378 or {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000379 expression: \code{long(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000380 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000381
382
Guido van Rossum0011d931996-08-22 23:18:55 +0000383 \begin{cfuncdesc}{PyObject*}{PyNumber_Float}{PyObject *o}
384 Returns the \code{o} converted to a float object on success, or {\NULL}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000385 on failure. This is the equivalent of the Python expression:
386 \code{float(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000387 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000388
389
Guido van Rossum0011d931996-08-22 23:18:55 +0000390\section{Sequence protocol}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000391
Guido van Rossum0011d931996-08-22 23:18:55 +0000392 \begin{cfuncdesc}{int}{PySequence_Check}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000393 Return 1 if the object provides sequence protocol, and 0
394 otherwise.
395 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000396 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000397
398
Guido van Rossum0011d931996-08-22 23:18:55 +0000399 \begin{cfuncdesc}{PyObject*}{PySequence_Concat}{PyObject *o1, PyObject *o2}
400 Return the concatination of \code{o1} and \code{o2} on success, and {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000401 failure. This is the equivalent of the Python
402 expression: \code{o1+o2}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000403 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000404
405
Guido van Rossum0011d931996-08-22 23:18:55 +0000406 \begin{cfuncdesc}{PyObject*}{PySequence_Repeat}{PyObject *o, int count}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000407 Return the result of repeating sequence object \code{o} count times,
Guido van Rossum0011d931996-08-22 23:18:55 +0000408 or {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000409 expression: \code{o*count}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000410 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000411
412
Guido van Rossum0011d931996-08-22 23:18:55 +0000413 \begin{cfuncdesc}{PyObject*}{PySequence_GetItem}{PyObject *o, int i}
414 Return the ith element of \code{o}, or {\NULL} on failure. This is the
Guido van Rossum267e80d1996-08-09 21:01:07 +0000415 equivalent of the Python expression: \code{o[i]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000416 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000417
418
Guido van Rossum0011d931996-08-22 23:18:55 +0000419 \begin{cfuncdesc}{PyObject*}{PySequence_GetSlice}{PyObject *o, int i1, int i2}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000420 Return the slice of sequence object \code{o} between \code{i1} and \code{i2}, or
Guido van Rossum0011d931996-08-22 23:18:55 +0000421 {\NULL} on failure. This is the equivalent of the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000422 expression, \code{o[i1:i2]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000423 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000424
425
Guido van Rossum0011d931996-08-22 23:18:55 +0000426 \begin{cfuncdesc}{int}{PySequence_SetItem}{PyObject *o, int i, PyObject *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000427 Assign object \code{v} to the \code{i}th element of \code{o}.
428Returns -1 on failure. This is the equivalent of the Python
429 statement, \code{o[i]=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000430 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000431
Guido van Rossum0011d931996-08-22 23:18:55 +0000432 \begin{cfuncdesc}{int}{PySequence_DelItem}{PyObject *o, int i}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000433 Delete the \code{i}th element of object \code{v}. Returns
434 -1 on failure. This is the equivalent of the Python
435 statement: \code{del o[i]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000436 \end{cfuncdesc}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000437
Guido van Rossum0011d931996-08-22 23:18:55 +0000438 \begin{cfuncdesc}{int}{PySequence_SetSlice}{PyObject *o, int i1, int i2, PyObject *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000439 Assign the sequence object \code{v} to the slice in sequence
440 object \code{o} from \code{i1} to \code{i2}. This is the equivalent of the Python
441 statement, \code{o[i1:i2]=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000442 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000443
Guido van Rossum0011d931996-08-22 23:18:55 +0000444 \begin{cfuncdesc}{int}{PySequence_DelSlice}{PyObject *o, int i1, int i2}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000445 Delete the slice in sequence object, \code{o}, from \code{i1} to \code{i2}.
446 Returns -1 on failure. This is the equivalent of the Python
447 statement: \code{del o[i1:i2]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000448 \end{cfuncdesc}
Guido van Rossumd0f11de1996-08-21 19:08:12 +0000449
Guido van Rossum0011d931996-08-22 23:18:55 +0000450 \begin{cfuncdesc}{PyObject*}{PySequence_Tuple}{PyObject *o}
451 Returns the \code{o} as a tuple on success, and {\NULL} on failure.
Guido van Rossum267e80d1996-08-09 21:01:07 +0000452 This is equivalent to the Python expression: \code{tuple(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000453 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000454
Guido van Rossum0011d931996-08-22 23:18:55 +0000455 \begin{cfuncdesc}{int}{PySequence_Count}{PyObject *o, PyObject *value}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000456 Return the number of occurrences of \code{value} on \code{o}, that is,
457 return the number of keys for which \code{o[key]==value}. On
458 failure, return -1. This is equivalent to the Python
459 expression: \code{o.count(value)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000460 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000461
Guido van Rossum0011d931996-08-22 23:18:55 +0000462 \begin{cfuncdesc}{int}{PySequence_In}{PyObject *o, PyObject *value}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000463 Determine if \code{o} contains \code{value}. If an item in \code{o} is equal to
464 \code{value}, return 1, otherwise return 0. On error, return -1. This
465 is equivalent to the Python expression: \code{value in o}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000466 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000467
Guido van Rossum0011d931996-08-22 23:18:55 +0000468 \begin{cfuncdesc}{int}{PySequence_Index}{PyObject *o, PyObject *value}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000469 Return the first index for which \code{o[i]=value}. On error,
470 return -1. This is equivalent to the Python
471 expression: \code{o.index(value)}.
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\section{Mapping protocol}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000475
Guido van Rossum0011d931996-08-22 23:18:55 +0000476 \begin{cfuncdesc}{int}{PyMapping_Check}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000477 Return 1 if the object provides mapping protocol, and 0
478 otherwise.
479 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000480 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000481
482
Guido van Rossum0011d931996-08-22 23:18:55 +0000483 \begin{cfuncdesc}{int}{PyMapping_Length}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000484 Returns the number of keys in object \code{o} on success, and -1 on
485 failure. For objects that do not provide sequence protocol,
486 this is equivalent to the Python expression: \code{len(o)}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000487 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000488
489
Guido van Rossum0011d931996-08-22 23:18:55 +0000490 \begin{cfuncdesc}{int}{PyMapping_DelItemString}{PyObject *o, char *key}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000491 Remove the mapping for object \code{key} from the object \code{o}.
492 Return -1 on failure. This is equivalent to
493 the Python statement: \code{del o[key]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000494 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000495
496
Guido van Rossum0011d931996-08-22 23:18:55 +0000497 \begin{cfuncdesc}{int}{PyMapping_DelItem}{PyObject *o, PyObject *key}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000498 Remove the mapping for object \code{key} from the object \code{o}.
499 Return -1 on failure. This is equivalent to
500 the Python statement: \code{del o[key]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000501 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000502
503
Guido van Rossum0011d931996-08-22 23:18:55 +0000504 \begin{cfuncdesc}{int}{PyMapping_HasKeyString}{PyObject *o, char *key}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000505 On success, return 1 if the mapping object has the key \code{key}
506 and 0 otherwise. This is equivalent to the Python expression:
507 \code{o.has_key(key)}.
508 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000509 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000510
511
Guido van Rossum0011d931996-08-22 23:18:55 +0000512 \begin{cfuncdesc}{int}{PyMapping_HasKey}{PyObject *o, PyObject *key}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000513 Return 1 if the mapping object has the key \code{key}
514 and 0 otherwise. This is equivalent to the Python expression:
515 \code{o.has_key(key)}.
516 This function always succeeds.
Guido van Rossum0011d931996-08-22 23:18:55 +0000517 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000518
519
Guido van Rossum0011d931996-08-22 23:18:55 +0000520 \begin{cfuncdesc}{PyObject*}{PyMapping_Keys}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000521 On success, return a list of the keys in object \code{o}. On
Guido van Rossum0011d931996-08-22 23:18:55 +0000522 failure, return {\NULL}. This is equivalent to the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000523 expression: \code{o.keys()}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000524 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000525
526
Guido van Rossum0011d931996-08-22 23:18:55 +0000527 \begin{cfuncdesc}{PyObject*}{PyMapping_Values}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000528 On success, return a list of the values in object \code{o}. On
Guido van Rossum0011d931996-08-22 23:18:55 +0000529 failure, return {\NULL}. This is equivalent to the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000530 expression: \code{o.values()}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000531 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000532
533
Guido van Rossum0011d931996-08-22 23:18:55 +0000534 \begin{cfuncdesc}{PyObject*}{PyMapping_Items}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000535 On success, return a list of the items in object \code{o}, where
536 each item is a tuple containing a key-value pair. On
Guido van Rossum0011d931996-08-22 23:18:55 +0000537 failure, return {\NULL}. This is equivalent to the Python
Guido van Rossum267e80d1996-08-09 21:01:07 +0000538 expression: \code{o.items()}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000539 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000540
Guido van Rossum0011d931996-08-22 23:18:55 +0000541 \begin{cfuncdesc}{int}{PyMapping_Clear}{PyObject *o}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000542 Make object \code{o} empty. Returns 1 on success and 0 on failure.
543 This is equivalent to the Python statement:
544 \code{for key in o.keys(): del o[key]}
Guido van Rossum0011d931996-08-22 23:18:55 +0000545 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000546
547
Guido van Rossum0011d931996-08-22 23:18:55 +0000548 \begin{cfuncdesc}{PyObject*}{PyMapping_GetItemString}{PyObject *o, char *key}
549 Return element of \code{o} corresponding to the object \code{key} or {\NULL}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000550 on failure. This is the equivalent of the Python expression:
551 \code{o[key]}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000552 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000553
Guido van Rossum0011d931996-08-22 23:18:55 +0000554 \begin{cfuncdesc}{PyObject*}{PyMapping_SetItemString}{PyObject *o, char *key, PyObject *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000555 Map the object \code{key} to the value \code{v} in object \code{o}. Returns
556 -1 on failure. This is the equivalent of the Python
557 statement: \code{o[key]=v}.
Guido van Rossum0011d931996-08-22 23:18:55 +0000558 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000559
560
Guido van Rossum0011d931996-08-22 23:18:55 +0000561\section{Constructors}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000562
Guido van Rossum0011d931996-08-22 23:18:55 +0000563 \begin{cfuncdesc}{PyObject*}{PyFile_FromString}{char *file_name, char *mode}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000564 On success, returns a new file object that is opened on the
565 file given by \code{file_name}, with a file mode given by \code{mode},
566 where \code{mode} has the same semantics as the standard C routine,
567 fopen. On failure, return -1.
Guido van Rossum0011d931996-08-22 23:18:55 +0000568 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000569
Guido van Rossum0011d931996-08-22 23:18:55 +0000570 \begin{cfuncdesc}{PyObject*}{PyFile_FromFile}{FILE *fp, char *file_name, char *mode, int close_on_del}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000571 Return a new file object for an already opened standard C
572 file pointer, \code{fp}. A file name, \code{file_name}, and open mode,
573 \code{mode}, must be provided as well as a flag, \code{close_on_del}, that
574 indicates whether the file is to be closed when the file
575 object is destroyed. On failure, return -1.
Guido van Rossum0011d931996-08-22 23:18:55 +0000576 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000577
Guido van Rossum0011d931996-08-22 23:18:55 +0000578 \begin{cfuncdesc}{PyObject*}{PyFloat_FromDouble}{double v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000579 Returns a new float object with the value \code{v} on success, and
Guido van Rossum0011d931996-08-22 23:18:55 +0000580 {\NULL} on failure.
581 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000582
Guido van Rossum0011d931996-08-22 23:18:55 +0000583 \begin{cfuncdesc}{PyObject*}{PyInt_FromLong}{long v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000584 Returns a new int object with the value \code{v} on success, and
Guido van Rossum0011d931996-08-22 23:18:55 +0000585 {\NULL} on failure.
586 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000587
Guido van Rossum0011d931996-08-22 23:18:55 +0000588 \begin{cfuncdesc}{PyObject*}{PyList_New}{int l}
589 Returns a new list of length \code{l} on success, and {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000590 failure.
Guido van Rossum0011d931996-08-22 23:18:55 +0000591 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000592
Guido van Rossum0011d931996-08-22 23:18:55 +0000593 \begin{cfuncdesc}{PyObject*}{PyLong_FromLong}{long v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000594 Returns a new long object with the value \code{v} on success, and
Guido van Rossum0011d931996-08-22 23:18:55 +0000595 {\NULL} on failure.
596 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000597
Guido van Rossum0011d931996-08-22 23:18:55 +0000598 \begin{cfuncdesc}{PyObject*}{PyLong_FromDouble}{double v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000599 Returns a new long object with the value \code{v} on success, and
Guido van Rossum0011d931996-08-22 23:18:55 +0000600 {\NULL} on failure.
601 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000602
Guido van Rossum0011d931996-08-22 23:18:55 +0000603 \begin{cfuncdesc}{PyObject*}{PyDict_New}{}
604 Returns a new empty dictionary on success, and {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000605 failure.
Guido van Rossum0011d931996-08-22 23:18:55 +0000606 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000607
Guido van Rossum0011d931996-08-22 23:18:55 +0000608 \begin{cfuncdesc}{PyObject*}{PyString_FromString}{char *v}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000609 Returns a new string object with the value \code{v} on success, and
Guido van Rossum0011d931996-08-22 23:18:55 +0000610 {\NULL} on failure.
611 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000612
Guido van Rossum0011d931996-08-22 23:18:55 +0000613 \begin{cfuncdesc}{PyObject*}{PyString_FromStringAndSize}{char *v, int l}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000614 Returns a new string object with the value \code{v} and length \code{l}
Guido van Rossum0011d931996-08-22 23:18:55 +0000615 on success, and {\NULL} on failure.
616 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000617
Guido van Rossum0011d931996-08-22 23:18:55 +0000618 \begin{cfuncdesc}{PyObject*}{PyTuple_New}{int l}
619 Returns a new tuple of length \code{l} on success, and {\NULL} on
Guido van Rossum267e80d1996-08-09 21:01:07 +0000620 failure.
Guido van Rossum0011d931996-08-22 23:18:55 +0000621 \end{cfuncdesc}
Guido van Rossum267e80d1996-08-09 21:01:07 +0000622