Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 1 | % cfuncdesc should be called as an \begin{cfuncdesc} ... \end{cfuncdesc} |
| 2 | \newcommand{\cfuncline}[3]{\item[\code{#1 #2(\varvars{#3})}]\ttindex{#2}} |
| 3 | \newcommand{\cfuncdesc}[3]{\fulllineitems\cfuncline{#1}{#2}{#3}} |
| 4 | \let\endcfuncdesc\endfulllineitems |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 5 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 6 | \newcommand{\NULL}{\code{NULL}} |
| 7 | |
| 8 | \chapter{Extension Reference} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 9 | |
| 10 | From the viewpoint of of C access to Python services, we have: |
| 11 | |
| 12 | \begin{enumerate} |
| 13 | \item "Very high level layer": two or three functions that let you exec or |
| 14 | eval arbitrary Python code given as a string in a module whose name is |
| 15 | given, passing C values in and getting C values out using |
| 16 | mkvalue/getargs style format strings. This does not require the user |
| 17 | to declare any variables of type "PyObject *". This should be enough |
| 18 | to write a simple application that gets Python code from the user, |
| 19 | execs it, and returns the output or errors. |
| 20 | |
| 21 | \item "Abstract objects layer": which is the subject of this proposal. |
| 22 | It has many functions operating on objects, and lest you do many |
| 23 | things from C that you can also write in Python, without going |
| 24 | through the Python parser. |
| 25 | |
| 26 | \item "Concrete objects layer": This is the public type-dependent |
| 27 | interface provided by the standard built-in types, such as floats, |
| 28 | strings, and lists. This interface exists and is currently |
| 29 | documented by the collection of include files provides with the |
| 30 | Python distributions. |
| 31 | |
| 32 | From the point of view of Python accessing services provided by C |
| 33 | modules: |
| 34 | |
| 35 | \item "Python module interface": this interface consist of the basic |
| 36 | routines used to define modules and their members. Most of the |
| 37 | current extensions-writing guide deals with this interface. |
| 38 | |
| 39 | \item "Built-in object interface": this is the interface that a new |
| 40 | built-in type must provide and the mechanisms and rules that a |
| 41 | developer of a new built-in type must use and follow. |
| 42 | \end{enumerate} |
| 43 | |
| 44 | The Python C object interface provides four protocols: object, |
| 45 | numeric, sequence, and mapping. Each protocol consists of a |
| 46 | collection of related operations. If an operation that is not |
| 47 | provided by a particular type is invoked, then a standard exception, |
| 48 | NotImplementedError is raised with a operation name as an argument. |
| 49 | In addition, for convenience this interface defines a set of |
| 50 | constructors for building objects of built-in types. This is needed |
| 51 | so new objects can be returned from C functions that otherwise treat |
| 52 | objects generically. |
| 53 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 54 | \section{Object Protocol} |
| 55 | |
| 56 | \begin{cfuncdesc}{int}{PyObject_Print}{PyObject *o, FILE *fp, int flags} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 57 | Print an object \code{o}, on file \code{fp}. Returns -1 on error |
| 58 | The flags argument is used to enable certain printing |
| 59 | options. The only option currently supported is \code{Py_Print_RAW}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 60 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 61 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 62 | \begin{cfuncdesc}{int}{PyObject_HasAttrString}{PyObject *o, char *attr_name} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 63 | Returns 1 if o has the attribute attr_name, and 0 otherwise. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 64 | This is equivalent to the Python expression: |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 65 | \code{hasattr(o,attr_name)}. |
| 66 | This function always succeeds. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 67 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 68 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 69 | \begin{cfuncdesc}{PyObject*}{PyObject_AttrString}{PyObject *o, char *attr_name} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 70 | Retrieve an attributed named attr_name form object o. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 71 | Returns the attribute value on success, or {\NULL} on failure. |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 72 | This is the equivalent of the Python expression: \code{o.attr_name}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 73 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 74 | |
| 75 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 76 | \begin{cfuncdesc}{int}{PyObject_HasAttr}{PyObject *o, PyObject *attr_name} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 77 | Returns 1 if o has the attribute attr_name, and 0 otherwise. |
| 78 | This is equivalent to the Python expression: |
| 79 | \code{hasattr(o,attr_name)}. |
| 80 | This function always succeeds. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 81 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 82 | |
| 83 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 84 | \begin{cfuncdesc}{PyObject*}{PyObject_GetAttr}{PyObject *o, PyObject *attr_name} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 85 | Retrieve an attributed named attr_name form object o. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 86 | Returns the attribute value on success, or {\NULL} on failure. |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 87 | This is the equivalent of the Python expression: o.attr_name. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 88 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 89 | |
| 90 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 91 | \begin{cfuncdesc}{int}{PyObject_SetAttrString}{PyObject *o, char *attr_name, PyObject *v} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 92 | Set the value of the attribute named \code{attr_name}, for object \code{o}, |
| 93 | to the value \code{v}. Returns -1 on failure. This is |
| 94 | the equivalent of the Python statement: \code{o.attr_name=v}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 95 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 96 | |
| 97 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 98 | \begin{cfuncdesc}{int}{PyObject_SetAttr}{PyObject *o, PyObject *attr_name, PyObject *v} |
| 99 | Set the value of the attribute named \code{attr_name}, for |
| 100 | object \code{o}, |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 101 | to the value \code{v}. Returns -1 on failure. This is |
| 102 | the equivalent of the Python statement: \code{o.attr_name=v}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 103 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 104 | |
| 105 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 106 | \begin{cfuncdesc}{int}{PyObject_DelAttrString}{PyObject *o, char *attr_name} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 107 | Delete attribute named \code{attr_name}, for object \code{o}. Returns -1 on |
| 108 | failure. This is the equivalent of the Python |
| 109 | statement: \code{del o.attr_name}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 110 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 111 | |
| 112 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 113 | \begin{cfuncdesc}{int}{PyObject_DelAttr}{PyObject *o, PyObject *attr_name} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 114 | Delete attribute named \code{attr_name}, for object \code{o}. Returns -1 on |
| 115 | failure. This is the equivalent of the Python |
| 116 | statement: \code{del o.attr_name}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 117 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 118 | |
| 119 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 120 | \begin{cfuncdesc}{int}{PyObject_Cmp}{PyObject *o1, PyObject *o2, int *result} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 121 | Compare the values of \code{o1} and \code{o2} using a routine provided by |
| 122 | \code{o1}, if one exists, otherwise with a routine provided by \code{o2}. |
| 123 | The result of the comparison is returned in \code{result}. Returns |
| 124 | -1 on failure. This is the equivalent of the Python |
| 125 | statement: \code{result=cmp(o1,o2)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 126 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 127 | |
| 128 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 129 | \begin{cfuncdesc}{int}{PyObject_Compare}{PyObject *o1, PyObject *o2} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 130 | Compare the values of \code{o1} and \code{o2} using a routine provided by |
| 131 | \code{o1}, if one exists, otherwise with a routine provided by \code{o2}. |
| 132 | Returns the result of the comparison on success. On error, |
| 133 | the value returned is undefined. This is equivalent to the |
| 134 | Python expression: \code{cmp(o1,o2)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 135 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 136 | |
| 137 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 138 | \begin{cfuncdesc}{PyObject*}{PyObject_Repr}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 139 | Compute the string representation of object, \code{o}. Returns the |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 140 | string representation on success, {\NULL} on failure. This is |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 141 | the equivalent of the Python expression: \code{repr(o)}. |
| 142 | Called by the \code{repr()} built-in function and by reverse quotes. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 143 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 144 | |
| 145 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 146 | \begin{cfuncdesc}{PyObject*}{PyObject_Str}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 147 | Compute the string representation of object, \code{o}. Returns the |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 148 | string representation on success, {\NULL} on failure. This is |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 149 | the equivalent of the Python expression: \code{str(o)}. |
| 150 | Called by the \code{str()} built-in function and by the \code{print} |
| 151 | statement. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 152 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 153 | |
| 154 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 155 | \begin{cfuncdesc}{int}{PyCallable_Check}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 156 | Determine if the object \code{o}, is callable. Return 1 if the |
| 157 | object is callable and 0 otherwise. |
| 158 | This function always succeeds. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 159 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 160 | |
| 161 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 162 | \begin{cfuncdesc}{PyObject*}{PyObject_CallObject}{PyObject *callable_object, PyObject *args} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 163 | Call a callable Python object \code{callable_object}, with |
| 164 | arguments given by the tuple \code{args}. If no arguments are |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 165 | needed, then args may be {\NULL}. Returns the result of the |
| 166 | call on success, or {\NULL} on failure. This is the equivalent |
| 167 | of the Python expression: \code{apply(o, args)}. |
| 168 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 169 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 170 | \begin{cfuncdesc}{PyObject*}{PyObject_CallFunction}{PyObject *callable_object, char *format, ...} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 171 | Call a callable Python object \code{callable_object}, with a |
| 172 | variable number of C arguments. The C arguments are described |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 173 | using a mkvalue-style format string. The format may be {\NULL}, |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 174 | indicating that no arguments are provided. Returns the |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 175 | result of the call on success, or {\NULL} on failure. This is |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 176 | the equivalent of the Python expression: \code{apply(o,args)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 177 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 178 | |
| 179 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 180 | \begin{cfuncdesc}{PyObject*}{PyObject_CallMethod}{PyObject *o, char *m, char *format, ...} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 181 | Call the method named \code{m} of object \code{o} with a variable number of |
| 182 | C arguments. The C arguments are described by a mkvalue |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 183 | format string. The format may be {\NULL}, indicating that no |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 184 | arguments are provided. Returns the result of the call on |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 185 | success, or {\NULL} on failure. This is the equivalent of the |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 186 | Python expression: \code{o.method(args)}. |
| 187 | Note that Special method names, such as "\code{__add__}", |
| 188 | "\code{__getitem__}", and so on are not supported. The specific |
| 189 | abstract-object routines for these must be used. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 190 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 191 | |
| 192 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 193 | \begin{cfuncdesc}{int}{PyObject_Hash}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 194 | Compute and return the hash value of an object \code{o}. On |
| 195 | failure, return -1. This is the equivalent of the Python |
| 196 | expression: \code{hash(o)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 197 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 198 | |
| 199 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 200 | \begin{cfuncdesc}{int}{PyObject_IsTrue}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 201 | Returns 1 if the object \code{o} is considered to be true, and |
| 202 | 0 otherwise. This is equivalent to the Python expression: |
| 203 | \code{not not o}. |
| 204 | This function always succeeds. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 205 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 206 | |
| 207 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 208 | \begin{cfuncdesc}{PyObject*}{PyObject_Type}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 209 | On success, returns a type object corresponding to the object |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 210 | type of object \code{o}. On failure, returns {\NULL}. This is |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 211 | equivalent to the Python expression: \code{type(o)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 212 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 213 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 214 | \begin{cfuncdesc}{int}{PyObject_Length}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 215 | Return the length of object \code{o}. If the object \code{o} provides |
| 216 | both sequence and mapping protocols, the sequence length is |
| 217 | returned. On error, -1 is returned. This is the equivalent |
| 218 | to the Python expression: \code{len(o)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 219 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 220 | |
| 221 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 222 | \begin{cfuncdesc}{PyObject*}{PyObject_GetItem}{PyObject *o, PyObject *key} |
| 223 | Return element of \code{o} corresponding to the object \code{key} or {\NULL} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 224 | on failure. This is the equivalent of the Python expression: |
| 225 | \code{o[key]}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 226 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 227 | |
| 228 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 229 | \begin{cfuncdesc}{int}{PyObject_SetItem}{PyObject *o, PyObject *key, PyObject *v} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 230 | Map the object \code{key} to the value \code{v}. |
| 231 | Returns -1 on failure. This is the equivalent |
| 232 | of the Python statement: \code{o[key]=v}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 233 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 234 | |
| 235 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 236 | \begin{cfuncdesc}{int}{PyObject_DelItem}{PyObject *o, PyObject *key, PyObject *v} |
Guido van Rossum | d0f11de | 1996-08-21 19:08:12 +0000 | [diff] [blame] | 237 | Delete the mapping for \code{key} from \code{*o}. Returns -1 |
| 238 | on failure. |
| 239 | This is the equivalent of the Python statement: del o[key]. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 240 | \end{cfuncdesc} |
Guido van Rossum | d0f11de | 1996-08-21 19:08:12 +0000 | [diff] [blame] | 241 | |
| 242 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 243 | \section{Number Protocol} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 244 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 245 | \begin{cfuncdesc}{int}{PyNumber_Check}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 246 | Returns 1 if the object \code{o} provides numeric protocols, and |
| 247 | false otherwise. |
| 248 | This function always succeeds. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 249 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 250 | |
| 251 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 252 | \begin{cfuncdesc}{PyObject*}{PyNumber_Add}{PyObject *o1, PyObject *o2} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 253 | Returns the result of adding \code{o1} and \code{o2}, or null on failure. |
| 254 | This is the equivalent of the Python expression: \code{o1+o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 255 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 256 | |
| 257 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 258 | \begin{cfuncdesc}{PyObject*}{PyNumber_Subtract}{PyObject *o1, PyObject *o2} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 259 | Returns the result of subtracting \code{o2} from \code{o1}, or null on |
| 260 | failure. This is the equivalent of the Python expression: |
| 261 | \code{o1-o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 262 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 263 | |
| 264 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 265 | \begin{cfuncdesc}{PyObject*}{PyNumber_Multiply}{PyObject *o1, PyObject *o2} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 266 | Returns the result of multiplying \code{o1} and \code{o2}, or null on |
| 267 | failure. This is the equivalent of the Python expression: |
| 268 | \code{o1*o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 269 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 270 | |
| 271 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 272 | \begin{cfuncdesc}{PyObject*}{PyNumber_Divide}{PyObject *o1, PyObject *o2} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 273 | Returns the result of dividing \code{o1} by \code{o2}, or null on failure. |
| 274 | This is the equivalent of the Python expression: \code{o1/o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 275 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 276 | |
| 277 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 278 | \begin{cfuncdesc}{PyObject*}{PyNumber_Remainder}{PyObject *o1, PyObject *o2} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 279 | Returns the remainder of dividing \code{o1} by \code{o2}, or null on |
| 280 | failure. This is the equivalent of the Python expression: |
| 281 | \code{o1\%o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 282 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 283 | |
| 284 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 285 | \begin{cfuncdesc}{PyObject*}{PyNumber_Divmod}{PyObject *o1, PyObject *o2} |
| 286 | See the built-in function divmod. Returns {\NULL} on failure. |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 287 | This is the equivalent of the Python expression: |
| 288 | \code{divmod(o1,o2)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 289 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 290 | |
| 291 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 292 | \begin{cfuncdesc}{PyObject*}{PyNumber_Power}{PyObject *o1, PyObject *o2, PyObject *o3} |
| 293 | See the built-in function pow. Returns {\NULL} on failure. |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 294 | This is the equivalent of the Python expression: |
| 295 | \code{pow(o1,o2,o3)}, where \code{o3} is optional. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 296 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 297 | |
| 298 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 299 | \begin{cfuncdesc}{PyObject*}{PyNumber_Negative}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 300 | Returns the negation of \code{o} on success, or null on failure. |
| 301 | This is the equivalent of the Python expression: \code{-o}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 302 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 303 | |
| 304 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 305 | \begin{cfuncdesc}{PyObject*}{PyNumber_Positive}{PyObject *o} |
| 306 | Returns \code{o} on success, or {\NULL} on failure. |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 307 | This is the equivalent of the Python expression: \code{+o}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 308 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 309 | |
| 310 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 311 | \begin{cfuncdesc}{PyObject*}{PyNumber_Absolute}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 312 | Returns the absolute value of \code{o}, or null on failure. This is |
| 313 | the equivalent of the Python expression: \code{abs(o)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 314 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 315 | |
| 316 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 317 | \begin{cfuncdesc}{PyObject*}{PyNumber_Invert}{PyObject *o} |
| 318 | Returns the bitwise negation of \code{o} on success, or {\NULL} on |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 319 | failure. This is the equivalent of the Python expression: |
| 320 | \code{~o}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 321 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 322 | |
| 323 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 324 | \begin{cfuncdesc}{PyObject*}{PyNumber_Lshift}{PyObject *o1, PyObject *o2} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 325 | Returns the result of left shifting \code{o1} by \code{o2} on success, or |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 326 | {\NULL} on failure. This is the equivalent of the Python |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 327 | expression: \code{o1 << o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 328 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 329 | |
| 330 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 331 | \begin{cfuncdesc}{PyObject*}{PyNumber_Rshift}{PyObject *o1, PyObject *o2} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 332 | Returns the result of right shifting \code{o1} by \code{o2} on success, or |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 333 | {\NULL} on failure. This is the equivalent of the Python |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 334 | expression: \code{o1 >> o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 335 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 336 | |
| 337 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 338 | \begin{cfuncdesc}{PyObject*}{PyNumber_And}{PyObject *o1, PyObject *o2} |
| 339 | Returns the result of "anding" \code{o2} and \code{o2} on success and {\NULL} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 340 | on failure. This is the equivalent of the Python |
| 341 | expression: \code{o1 and o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 342 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 343 | |
| 344 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 345 | \begin{cfuncdesc}{PyObject*}{PyNumber_Xor}{PyObject *o1, PyObject *o2} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 346 | Returns the bitwise exclusive or of \code{o1} by \code{o2} on success, or |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 347 | {\NULL} on failure. This is the equivalent of the Python |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 348 | expression: \code{o1\^{ }o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 349 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 350 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 351 | \begin{cfuncdesc}{PyObject*}{PyNumber_Or}{PyObject *o1, PyObject *o2} |
| 352 | Returns the result or \code{o1} and \code{o2} on success, or {\NULL} on |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 353 | failure. This is the equivalent of the Python expression: |
| 354 | \code{o1 or o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 355 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 356 | |
| 357 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 358 | \begin{cfuncdesc}{PyObject*}{PyNumber_Coerce}{PyObject *o1, PyObject *o2} |
Guido van Rossum | c05797d | 1996-09-10 17:36:17 +0000 | [diff] [blame^] | 359 | This function takes the addresses of two variables of type |
| 360 | \code{PyObject*}. |
| 361 | |
| 362 | If the objects pointed to by \code{*p1} and \code{*p2} have the same type, |
| 363 | increment their reference count and return 0 (success). |
| 364 | If the objects can be converted to a common numeric type, |
| 365 | replace \code{*p1} and \code{*p2} by their converted value (with 'new' |
| 366 | reference counts), and return 0. |
| 367 | If no conversion is possible, or if some other error occurs, |
| 368 | return -1 (failure) and don't increment the reference counts. |
| 369 | The call \code{PyNumber_Coerce(&o1, &o2)} is equivalent to the Python |
| 370 | statement \code{o1, o2 = coerce(o1, o2)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 371 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 372 | |
| 373 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 374 | \begin{cfuncdesc}{PyObject*}{PyNumber_Int}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 375 | Returns the \code{o} converted to an integer object on success, or |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 376 | {\NULL} on failure. This is the equivalent of the Python |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 377 | expression: \code{int(o)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 378 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 379 | |
| 380 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 381 | \begin{cfuncdesc}{PyObject*}{PyNumber_Long}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 382 | Returns the \code{o} converted to a long integer object on success, |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 383 | or {\NULL} on failure. This is the equivalent of the Python |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 384 | expression: \code{long(o)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 385 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 386 | |
| 387 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 388 | \begin{cfuncdesc}{PyObject*}{PyNumber_Float}{PyObject *o} |
| 389 | Returns the \code{o} converted to a float object on success, or {\NULL} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 390 | on failure. This is the equivalent of the Python expression: |
| 391 | \code{float(o)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 392 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 393 | |
| 394 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 395 | \section{Sequence protocol} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 396 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 397 | \begin{cfuncdesc}{int}{PySequence_Check}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 398 | Return 1 if the object provides sequence protocol, and 0 |
| 399 | otherwise. |
| 400 | This function always succeeds. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 401 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 402 | |
| 403 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 404 | \begin{cfuncdesc}{PyObject*}{PySequence_Concat}{PyObject *o1, PyObject *o2} |
| 405 | Return the concatination of \code{o1} and \code{o2} on success, and {\NULL} on |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 406 | failure. This is the equivalent of the Python |
| 407 | expression: \code{o1+o2}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 408 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 409 | |
| 410 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 411 | \begin{cfuncdesc}{PyObject*}{PySequence_Repeat}{PyObject *o, int count} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 412 | Return the result of repeating sequence object \code{o} count times, |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 413 | or {\NULL} on failure. This is the equivalent of the Python |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 414 | expression: \code{o*count}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 415 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 416 | |
| 417 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 418 | \begin{cfuncdesc}{PyObject*}{PySequence_GetItem}{PyObject *o, int i} |
| 419 | Return the ith element of \code{o}, or {\NULL} on failure. This is the |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 420 | equivalent of the Python expression: \code{o[i]}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 421 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 422 | |
| 423 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 424 | \begin{cfuncdesc}{PyObject*}{PySequence_GetSlice}{PyObject *o, int i1, int i2} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 425 | Return the slice of sequence object \code{o} between \code{i1} and \code{i2}, or |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 426 | {\NULL} on failure. This is the equivalent of the Python |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 427 | expression, \code{o[i1:i2]}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 428 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 429 | |
| 430 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 431 | \begin{cfuncdesc}{int}{PySequence_SetItem}{PyObject *o, int i, PyObject *v} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 432 | Assign object \code{v} to the \code{i}th element of \code{o}. |
| 433 | Returns -1 on failure. This is the equivalent of the Python |
| 434 | statement, \code{o[i]=v}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 435 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 436 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 437 | \begin{cfuncdesc}{int}{PySequence_DelItem}{PyObject *o, int i} |
Guido van Rossum | d0f11de | 1996-08-21 19:08:12 +0000 | [diff] [blame] | 438 | Delete the \code{i}th element of object \code{v}. Returns |
| 439 | -1 on failure. This is the equivalent of the Python |
| 440 | statement: \code{del o[i]}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 441 | \end{cfuncdesc} |
Guido van Rossum | d0f11de | 1996-08-21 19:08:12 +0000 | [diff] [blame] | 442 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 443 | \begin{cfuncdesc}{int}{PySequence_SetSlice}{PyObject *o, int i1, int i2, PyObject *v} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 444 | Assign the sequence object \code{v} to the slice in sequence |
| 445 | object \code{o} from \code{i1} to \code{i2}. This is the equivalent of the Python |
| 446 | statement, \code{o[i1:i2]=v}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 447 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 448 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 449 | \begin{cfuncdesc}{int}{PySequence_DelSlice}{PyObject *o, int i1, int i2} |
Guido van Rossum | d0f11de | 1996-08-21 19:08:12 +0000 | [diff] [blame] | 450 | Delete the slice in sequence object, \code{o}, from \code{i1} to \code{i2}. |
| 451 | Returns -1 on failure. This is the equivalent of the Python |
| 452 | statement: \code{del o[i1:i2]}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 453 | \end{cfuncdesc} |
Guido van Rossum | d0f11de | 1996-08-21 19:08:12 +0000 | [diff] [blame] | 454 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 455 | \begin{cfuncdesc}{PyObject*}{PySequence_Tuple}{PyObject *o} |
| 456 | Returns the \code{o} as a tuple on success, and {\NULL} on failure. |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 457 | This is equivalent to the Python expression: \code{tuple(o)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 458 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 459 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 460 | \begin{cfuncdesc}{int}{PySequence_Count}{PyObject *o, PyObject *value} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 461 | Return the number of occurrences of \code{value} on \code{o}, that is, |
| 462 | return the number of keys for which \code{o[key]==value}. On |
| 463 | failure, return -1. This is equivalent to the Python |
| 464 | expression: \code{o.count(value)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 465 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 466 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 467 | \begin{cfuncdesc}{int}{PySequence_In}{PyObject *o, PyObject *value} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 468 | Determine if \code{o} contains \code{value}. If an item in \code{o} is equal to |
| 469 | \code{value}, return 1, otherwise return 0. On error, return -1. This |
| 470 | is equivalent to the Python expression: \code{value in o}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 471 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 472 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 473 | \begin{cfuncdesc}{int}{PySequence_Index}{PyObject *o, PyObject *value} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 474 | Return the first index for which \code{o[i]=value}. On error, |
| 475 | return -1. This is equivalent to the Python |
| 476 | expression: \code{o.index(value)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 477 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 478 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 479 | \section{Mapping protocol} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 480 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 481 | \begin{cfuncdesc}{int}{PyMapping_Check}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 482 | Return 1 if the object provides mapping protocol, and 0 |
| 483 | otherwise. |
| 484 | This function always succeeds. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 485 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 486 | |
| 487 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 488 | \begin{cfuncdesc}{int}{PyMapping_Length}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 489 | Returns the number of keys in object \code{o} on success, and -1 on |
| 490 | failure. For objects that do not provide sequence protocol, |
| 491 | this is equivalent to the Python expression: \code{len(o)}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 492 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 493 | |
| 494 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 495 | \begin{cfuncdesc}{int}{PyMapping_DelItemString}{PyObject *o, char *key} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 496 | Remove the mapping for object \code{key} from the object \code{o}. |
| 497 | Return -1 on failure. This is equivalent to |
| 498 | the Python statement: \code{del o[key]}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 499 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 500 | |
| 501 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 502 | \begin{cfuncdesc}{int}{PyMapping_DelItem}{PyObject *o, PyObject *key} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 503 | Remove the mapping for object \code{key} from the object \code{o}. |
| 504 | Return -1 on failure. This is equivalent to |
| 505 | the Python statement: \code{del o[key]}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 506 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 507 | |
| 508 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 509 | \begin{cfuncdesc}{int}{PyMapping_HasKeyString}{PyObject *o, char *key} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 510 | On success, return 1 if the mapping object has the key \code{key} |
| 511 | and 0 otherwise. This is equivalent to the Python expression: |
| 512 | \code{o.has_key(key)}. |
| 513 | This function always succeeds. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 514 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 515 | |
| 516 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 517 | \begin{cfuncdesc}{int}{PyMapping_HasKey}{PyObject *o, PyObject *key} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 518 | Return 1 if the mapping object has the key \code{key} |
| 519 | and 0 otherwise. This is equivalent to the Python expression: |
| 520 | \code{o.has_key(key)}. |
| 521 | This function always succeeds. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 522 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 523 | |
| 524 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 525 | \begin{cfuncdesc}{PyObject*}{PyMapping_Keys}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 526 | On success, return a list of the keys in object \code{o}. On |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 527 | failure, return {\NULL}. This is equivalent to the Python |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 528 | expression: \code{o.keys()}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 529 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 530 | |
| 531 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 532 | \begin{cfuncdesc}{PyObject*}{PyMapping_Values}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 533 | On success, return a list of the values in object \code{o}. On |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 534 | failure, return {\NULL}. This is equivalent to the Python |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 535 | expression: \code{o.values()}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 536 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 537 | |
| 538 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 539 | \begin{cfuncdesc}{PyObject*}{PyMapping_Items}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 540 | On success, return a list of the items in object \code{o}, where |
| 541 | each item is a tuple containing a key-value pair. On |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 542 | failure, return {\NULL}. This is equivalent to the Python |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 543 | expression: \code{o.items()}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 544 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 545 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 546 | \begin{cfuncdesc}{int}{PyMapping_Clear}{PyObject *o} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 547 | Make object \code{o} empty. Returns 1 on success and 0 on failure. |
| 548 | This is equivalent to the Python statement: |
| 549 | \code{for key in o.keys(): del o[key]} |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 550 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 551 | |
| 552 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 553 | \begin{cfuncdesc}{PyObject*}{PyMapping_GetItemString}{PyObject *o, char *key} |
| 554 | Return element of \code{o} corresponding to the object \code{key} or {\NULL} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 555 | on failure. This is the equivalent of the Python expression: |
| 556 | \code{o[key]}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 557 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 558 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 559 | \begin{cfuncdesc}{PyObject*}{PyMapping_SetItemString}{PyObject *o, char *key, PyObject *v} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 560 | Map the object \code{key} to the value \code{v} in object \code{o}. Returns |
| 561 | -1 on failure. This is the equivalent of the Python |
| 562 | statement: \code{o[key]=v}. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 563 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 564 | |
| 565 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 566 | \section{Constructors} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 567 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 568 | \begin{cfuncdesc}{PyObject*}{PyFile_FromString}{char *file_name, char *mode} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 569 | On success, returns a new file object that is opened on the |
| 570 | file given by \code{file_name}, with a file mode given by \code{mode}, |
| 571 | where \code{mode} has the same semantics as the standard C routine, |
| 572 | fopen. On failure, return -1. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 573 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 574 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 575 | \begin{cfuncdesc}{PyObject*}{PyFile_FromFile}{FILE *fp, char *file_name, char *mode, int close_on_del} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 576 | Return a new file object for an already opened standard C |
| 577 | file pointer, \code{fp}. A file name, \code{file_name}, and open mode, |
| 578 | \code{mode}, must be provided as well as a flag, \code{close_on_del}, that |
| 579 | indicates whether the file is to be closed when the file |
| 580 | object is destroyed. On failure, return -1. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 581 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 582 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 583 | \begin{cfuncdesc}{PyObject*}{PyFloat_FromDouble}{double v} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 584 | Returns a new float object with the value \code{v} on success, and |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 585 | {\NULL} on failure. |
| 586 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 587 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 588 | \begin{cfuncdesc}{PyObject*}{PyInt_FromLong}{long v} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 589 | Returns a new int object with the value \code{v} on success, and |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 590 | {\NULL} on failure. |
| 591 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 592 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 593 | \begin{cfuncdesc}{PyObject*}{PyList_New}{int l} |
| 594 | Returns a new list of length \code{l} on success, and {\NULL} on |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 595 | failure. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 596 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 597 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 598 | \begin{cfuncdesc}{PyObject*}{PyLong_FromLong}{long v} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 599 | Returns a new long object with the value \code{v} on success, and |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 600 | {\NULL} on failure. |
| 601 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 602 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 603 | \begin{cfuncdesc}{PyObject*}{PyLong_FromDouble}{double v} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 604 | Returns a new long object with the value \code{v} on success, and |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 605 | {\NULL} on failure. |
| 606 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 607 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 608 | \begin{cfuncdesc}{PyObject*}{PyDict_New}{} |
| 609 | Returns a new empty dictionary on success, and {\NULL} on |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 610 | failure. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 611 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 612 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 613 | \begin{cfuncdesc}{PyObject*}{PyString_FromString}{char *v} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 614 | Returns a new string object with the value \code{v} on success, and |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 615 | {\NULL} on failure. |
| 616 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 617 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 618 | \begin{cfuncdesc}{PyObject*}{PyString_FromStringAndSize}{char *v, int l} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 619 | Returns a new string object with the value \code{v} and length \code{l} |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 620 | on success, and {\NULL} on failure. |
| 621 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 622 | |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 623 | \begin{cfuncdesc}{PyObject*}{PyTuple_New}{int l} |
| 624 | Returns a new tuple of length \code{l} on success, and {\NULL} on |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 625 | failure. |
Guido van Rossum | 0011d93 | 1996-08-22 23:18:55 +0000 | [diff] [blame] | 626 | \end{cfuncdesc} |
Guido van Rossum | 267e80d | 1996-08-09 21:01:07 +0000 | [diff] [blame] | 627 | |