| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1 | #ifndef Py_ABSTRACTOBJECT_H | 
|  | 2 | #define Py_ABSTRACTOBJECT_H | 
|  | 3 | #ifdef __cplusplus | 
|  | 4 | extern "C" { | 
|  | 5 | #endif | 
|  | 6 |  | 
|  | 7 | /*********************************************************** | 
|  | 8 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, | 
|  | 9 | The Netherlands. | 
|  | 10 |  | 
|  | 11 | All Rights Reserved | 
|  | 12 |  | 
| Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame^] | 13 | Permission to use, copy, modify, and distribute this software and its | 
|  | 14 | documentation for any purpose and without fee is hereby granted, | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 15 | provided that the above copyright notice appear in all copies and that | 
| Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame^] | 16 | both that copyright notice and this permission notice appear in | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 17 | supporting documentation, and that the names of Stichting Mathematisch | 
| Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame^] | 18 | Centrum or CWI or Corporation for National Research Initiatives or | 
|  | 19 | CNRI not be used in advertising or publicity pertaining to | 
|  | 20 | distribution of the software without specific, written prior | 
|  | 21 | permission. | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 22 |  | 
| Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame^] | 23 | While CWI is the initial source for this software, a modified version | 
|  | 24 | is made available by the Corporation for National Research Initiatives | 
|  | 25 | (CNRI) at the Internet address ftp://ftp.python.org. | 
|  | 26 |  | 
|  | 27 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH | 
|  | 28 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF | 
|  | 29 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH | 
|  | 30 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL | 
|  | 31 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | 
|  | 32 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | 
|  | 33 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | 
|  | 34 | PERFORMANCE OF THIS SOFTWARE. | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 35 |  | 
|  | 36 | ******************************************************************/ | 
|  | 37 |  | 
|  | 38 | /* Abstract Object Interface (many thanks to Jim Fulton) */ | 
|  | 39 |  | 
|  | 40 | /* | 
|  | 41 | PROPOSAL: A Generic Python Object Interface for Python C Modules | 
|  | 42 |  | 
|  | 43 | Problem | 
|  | 44 |  | 
|  | 45 | Python modules written in C that must access Python objects must do | 
|  | 46 | so through routines whose interfaces are described by a set of | 
|  | 47 | include files.  Unfortunately, these routines vary according to the | 
|  | 48 | object accessed.  To use these routines, the C programmer must check | 
|  | 49 | the type of the object being used and must call a routine based on | 
|  | 50 | the object type.  For example, to access an element of a sequence, | 
|  | 51 | the programmer must determine whether the sequence is a list or a | 
|  | 52 | tuple: | 
|  | 53 |  | 
|  | 54 | if(is_tupleobject(o)) | 
|  | 55 | e=gettupleitem(o,i) | 
|  | 56 | else if(is_listitem(o)) | 
|  | 57 | e=getlistitem(o,i) | 
|  | 58 |  | 
|  | 59 | If the programmer wants to get an item from another type of object | 
|  | 60 | that provides sequence behavior, there is no clear way to do it | 
|  | 61 | correctly. | 
|  | 62 |  | 
|  | 63 | The persistent programmer may peruse object.h and find that the | 
|  | 64 | _typeobject structure provides a means of invoking up to (currently | 
|  | 65 | about) 41 special operators.  So, for example, a routine can get an | 
|  | 66 | item from any object that provides sequence behavior. However, to | 
|  | 67 | use this mechanism, the programmer must make their code dependent on | 
|  | 68 | the current Python implementation. | 
|  | 69 |  | 
|  | 70 | Also, certain semantics, especially memory management semantics, may | 
|  | 71 | differ by the type of object being used.  Unfortunately, these | 
|  | 72 | semantics are not clearly described in the current include files. | 
|  | 73 | An abstract interface providing more consistent semantics is needed. | 
|  | 74 |  | 
|  | 75 | Proposal | 
|  | 76 |  | 
|  | 77 | I propose the creation of a standard interface (with an associated | 
|  | 78 | library of routines and/or macros) for generically obtaining the | 
|  | 79 | services of Python objects.  This proposal can be viewed as one | 
|  | 80 | components of a Python C interface consisting of several components. | 
|  | 81 |  | 
|  | 82 | From the viewpoint of of C access to Python services, we have (as | 
|  | 83 | suggested by Guido in off-line discussions): | 
|  | 84 |  | 
|  | 85 | - "Very high level layer": two or three functions that let you exec or | 
|  | 86 | eval arbitrary Python code given as a string in a module whose name is | 
|  | 87 | given, passing C values in and getting C values out using | 
|  | 88 | mkvalue/getargs style format strings.  This does not require the user | 
|  | 89 | to declare any variables of type "PyObject *".  This should be enough | 
|  | 90 | to write a simple application that gets Python code from the user, | 
|  | 91 | execs it, and returns the output or errors.  (Error handling must also | 
|  | 92 | be part of this API.) | 
|  | 93 |  | 
|  | 94 | - "Abstract objects layer": which is the subject of this proposal. | 
|  | 95 | It has many functions operating on objects, and lest you do many | 
|  | 96 | things from C that you can also write in Python, without going | 
|  | 97 | through the Python parser. | 
|  | 98 |  | 
|  | 99 | - "Concrete objects layer": This is the public type-dependent | 
|  | 100 | interface provided by the standard built-in types, such as floats, | 
|  | 101 | strings, and lists.  This interface exists and is currently | 
|  | 102 | documented by the collection of include files provides with the | 
|  | 103 | Python distributions. | 
|  | 104 |  | 
|  | 105 | From the point of view of Python accessing services provided by C | 
|  | 106 | modules: | 
|  | 107 |  | 
|  | 108 | - "Python module interface": this interface consist of the basic | 
|  | 109 | routines used to define modules and their members.  Most of the | 
|  | 110 | current extensions-writing guide deals with this interface. | 
|  | 111 |  | 
|  | 112 | - "Built-in object interface": this is the interface that a new | 
|  | 113 | built-in type must provide and the mechanisms and rules that a | 
|  | 114 | developer of a new built-in type must use and follow. | 
|  | 115 |  | 
|  | 116 | This proposal is a "first-cut" that is intended to spur | 
|  | 117 | discussion. See especially the lists of notes. | 
|  | 118 |  | 
|  | 119 | The Python C object interface will provide four protocols: object, | 
|  | 120 | numeric, sequence, and mapping.  Each protocol consists of a | 
|  | 121 | collection of related operations.  If an operation that is not | 
|  | 122 | provided by a particular type is invoked, then a standard exception, | 
|  | 123 | NotImplementedError is raised with a operation name as an argument. | 
|  | 124 | In addition, for convenience this interface defines a set of | 
|  | 125 | constructors for building objects of built-in types.  This is needed | 
|  | 126 | so new objects can be returned from C functions that otherwise treat | 
|  | 127 | objects generically. | 
|  | 128 |  | 
|  | 129 | Memory Management | 
|  | 130 |  | 
|  | 131 | For all of the functions described in this proposal, if a function | 
|  | 132 | retains a reference to a Python object passed as an argument, then the | 
|  | 133 | function will increase the reference count of the object.  It is | 
|  | 134 | unnecessary for the caller to increase the reference count of an | 
|  | 135 | argument in anticipation of the object's retention. | 
|  | 136 |  | 
|  | 137 | All Python objects returned from functions should be treated as new | 
|  | 138 | objects.  Functions that return objects assume that the caller will | 
|  | 139 | retain a reference and the reference count of the object has already | 
|  | 140 | been incremented to account for this fact.  A caller that does not | 
|  | 141 | retain a reference to an object that is returned from a function | 
|  | 142 | must decrement the reference count of the object (using | 
|  | 143 | DECREF(object)) to prevent memory leaks. | 
|  | 144 |  | 
|  | 145 | Note that the behavior mentioned here is different from the current | 
|  | 146 | behavior for some objects (e.g. lists and tuples) when certain | 
|  | 147 | type-specific routines are called directly (e.g. setlistitem).  The | 
|  | 148 | proposed abstraction layer will provide a consistent memory | 
|  | 149 | management interface, correcting for inconsistent behavior for some | 
|  | 150 | built-in types. | 
|  | 151 |  | 
|  | 152 | Protocols | 
|  | 153 |  | 
|  | 154 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ | 
|  | 155 |  | 
|  | 156 | /*  Object Protocol: */ | 
|  | 157 |  | 
|  | 158 | /* Implemented elsewhere: | 
|  | 159 |  | 
|  | 160 | int PyObject_Print(PyObject *o, FILE *fp, int flags); | 
|  | 161 |  | 
|  | 162 | Print an object, o, on file, fp.  Returns -1 on | 
|  | 163 | error.  The flags argument is used to enable certain printing | 
|  | 164 | options. The only option currently supported is Py_Print_RAW. | 
|  | 165 |  | 
|  | 166 | (What should be said about Py_Print_RAW?) | 
|  | 167 |  | 
|  | 168 | */ | 
|  | 169 |  | 
|  | 170 | /* Implemented elsewhere: | 
|  | 171 |  | 
|  | 172 | int PyObject_HasAttrString(PyObject *o, char *attr_name); | 
|  | 173 |  | 
|  | 174 | Returns 1 if o has the attribute attr_name, and 0 otherwise. | 
|  | 175 | This is equivalent to the Python expression: | 
|  | 176 | hasattr(o,attr_name). | 
|  | 177 |  | 
|  | 178 | This function always succeeds. | 
|  | 179 |  | 
|  | 180 | */ | 
|  | 181 |  | 
|  | 182 | /* Implemented elsewhere: | 
|  | 183 |  | 
|  | 184 | PyObject* PyObject_GetAttrString(PyObject *o, char *attr_name); | 
|  | 185 |  | 
|  | 186 | Retrieve an attributed named attr_name form object o. | 
|  | 187 | Returns the attribute value on success, or NULL on failure. | 
|  | 188 | This is the equivalent of the Python expression: o.attr_name. | 
|  | 189 |  | 
|  | 190 | */ | 
|  | 191 |  | 
|  | 192 | /* Implemented elsewhere: | 
|  | 193 |  | 
|  | 194 | int PyObject_HasAttr(PyObject *o, PyObject *attr_name); | 
|  | 195 |  | 
|  | 196 | Returns 1 if o has the attribute attr_name, and 0 otherwise. | 
|  | 197 | This is equivalent to the Python expression: | 
|  | 198 | hasattr(o,attr_name). | 
|  | 199 |  | 
|  | 200 | This function always succeeds. | 
|  | 201 |  | 
|  | 202 | */ | 
|  | 203 |  | 
|  | 204 | /* Implemented elsewhere: | 
|  | 205 |  | 
|  | 206 | PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); | 
|  | 207 |  | 
|  | 208 | Retrieve an attributed named attr_name form object o. | 
|  | 209 | Returns the attribute value on success, or NULL on failure. | 
|  | 210 | This is the equivalent of the Python expression: o.attr_name. | 
|  | 211 |  | 
|  | 212 | */ | 
|  | 213 |  | 
|  | 214 |  | 
|  | 215 | /* Implemented elsewhere: | 
|  | 216 |  | 
|  | 217 | int PyObject_SetAttrString(PyObject *o, char *attr_name, PyObject *v); | 
|  | 218 |  | 
|  | 219 | Set the value of the attribute named attr_name, for object o, | 
|  | 220 | to the value, v. Returns -1 on failure.  This is | 
|  | 221 | the equivalent of the Python statement: o.attr_name=v. | 
|  | 222 |  | 
|  | 223 | */ | 
|  | 224 |  | 
|  | 225 | /* Implemented elsewhere: | 
|  | 226 |  | 
|  | 227 | int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); | 
|  | 228 |  | 
|  | 229 | Set the value of the attribute named attr_name, for object o, | 
|  | 230 | to the value, v. Returns -1 on failure.  This is | 
|  | 231 | the equivalent of the Python statement: o.attr_name=v. | 
|  | 232 |  | 
|  | 233 | */ | 
|  | 234 |  | 
|  | 235 | /* implemented as a macro: | 
|  | 236 |  | 
|  | 237 | int PyObject_DelAttrString(PyObject *o, char *attr_name); | 
|  | 238 |  | 
|  | 239 | Delete attribute named attr_name, for object o. Returns | 
|  | 240 | -1 on failure.  This is the equivalent of the Python | 
|  | 241 | statement: del o.attr_name. | 
|  | 242 |  | 
|  | 243 | */ | 
|  | 244 | #define  PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A),NULL) | 
|  | 245 |  | 
|  | 246 | /* implemented as a macro: | 
|  | 247 |  | 
|  | 248 | int PyObject_DelAttr(PyObject *o, PyObject *attr_name); | 
|  | 249 |  | 
|  | 250 | Delete attribute named attr_name, for object o. Returns -1 | 
|  | 251 | on failure.  This is the equivalent of the Python | 
|  | 252 | statement: del o.attr_name. | 
|  | 253 |  | 
|  | 254 | */ | 
|  | 255 | #define  PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL) | 
|  | 256 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 257 | int PyObject_Cmp Py_PROTO((PyObject *o1, PyObject *o2, int *result)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 258 |  | 
|  | 259 | /* | 
|  | 260 | Compare the values of o1 and o2 using a routine provided by | 
|  | 261 | o1, if one exists, otherwise with a routine provided by o2. | 
|  | 262 | The result of the comparison is returned in result.  Returns | 
|  | 263 | -1 on failure.  This is the equivalent of the Python | 
|  | 264 | statement: result=cmp(o1,o2). | 
|  | 265 |  | 
|  | 266 | */ | 
|  | 267 |  | 
|  | 268 | /* Implemented elsewhere: | 
|  | 269 |  | 
|  | 270 | int PyObject_Compare(PyObject *o1, PyObject *o2); | 
|  | 271 |  | 
|  | 272 | Compare the values of o1 and o2 using a routine provided by | 
|  | 273 | o1, if one exists, otherwise with a routine provided by o2. | 
|  | 274 | Returns the result of the comparison on success.  On error, | 
|  | 275 | the value returned is undefined. This is equivalent to the | 
|  | 276 | Python expression: cmp(o1,o2). | 
|  | 277 |  | 
|  | 278 | */ | 
|  | 279 |  | 
|  | 280 | /* Implemented elsewhere: | 
|  | 281 |  | 
|  | 282 | PyObject *PyObject_Repr(PyObject *o); | 
|  | 283 |  | 
|  | 284 | Compute the string representation of object, o.  Returns the | 
|  | 285 | string representation on success, NULL on failure.  This is | 
|  | 286 | the equivalent of the Python expression: repr(o). | 
|  | 287 |  | 
|  | 288 | Called by the repr() built-in function and by reverse quotes. | 
|  | 289 |  | 
|  | 290 | */ | 
|  | 291 |  | 
|  | 292 | /* Implemented elsewhere: | 
|  | 293 |  | 
|  | 294 | PyObject *PyObject_Str(PyObject *o); | 
|  | 295 |  | 
|  | 296 | Compute the string representation of object, o.  Returns the | 
|  | 297 | string representation on success, NULL on failure.  This is | 
|  | 298 | the equivalent of the Python expression: str(o).) | 
|  | 299 |  | 
|  | 300 | Called by the str() built-in function and by the print | 
|  | 301 | statement. | 
|  | 302 |  | 
|  | 303 | */ | 
|  | 304 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 305 | int PyCallable_Check Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 306 |  | 
|  | 307 | /* | 
|  | 308 | Determine if the object, o, is callable.  Return 1 if the | 
|  | 309 | object is callable and 0 otherwise. | 
|  | 310 |  | 
|  | 311 | This function always succeeds. | 
|  | 312 |  | 
|  | 313 | */ | 
|  | 314 |  | 
|  | 315 |  | 
|  | 316 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 317 | PyObject *PyObject_CallObject Py_PROTO((PyObject *callable_object, | 
|  | 318 | PyObject *args)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 319 |  | 
|  | 320 | /* | 
|  | 321 |  | 
|  | 322 | Call a callable Python object, callable_object, with | 
|  | 323 | arguments given by the tuple, args.  If no arguments are | 
|  | 324 | needed, then args may be NULL.  Returns the result of the | 
|  | 325 | call on success, or NULL on failure.  This is the equivalent | 
|  | 326 | of the Python expression: apply(o,args). | 
|  | 327 |  | 
|  | 328 | */ | 
|  | 329 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 330 | PyObject *PyObject_CallFunction Py_PROTO((PyObject *callable_object, | 
|  | 331 | char *format, ...)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 332 |  | 
|  | 333 | /* | 
|  | 334 | Call a callable Python object, callable_object, with a | 
|  | 335 | variable number of C arguments. The C arguments are described | 
|  | 336 | using a mkvalue-style format string. The format may be NULL, | 
|  | 337 | indicating that no arguments are provided.  Returns the | 
|  | 338 | result of the call on success, or NULL on failure.  This is | 
|  | 339 | the equivalent of the Python expression: apply(o,args). | 
|  | 340 |  | 
|  | 341 | */ | 
|  | 342 |  | 
|  | 343 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 344 | PyObject *PyObject_CallMethod Py_PROTO((PyObject *o, char *m, | 
|  | 345 | char *format, ...)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 346 |  | 
|  | 347 | /* | 
|  | 348 | Call the method named m of object o with a variable number of | 
|  | 349 | C arguments.  The C arguments are described by a mkvalue | 
|  | 350 | format string.  The format may be NULL, indicating that no | 
|  | 351 | arguments are provided. Returns the result of the call on | 
|  | 352 | success, or NULL on failure.  This is the equivalent of the | 
|  | 353 | Python expression: o.method(args). | 
|  | 354 |  | 
|  | 355 | Note that Special method names, such as "__add__", | 
|  | 356 | "__getitem__", and so on are not supported. The specific | 
|  | 357 | abstract-object routines for these must be used. | 
|  | 358 |  | 
|  | 359 | */ | 
|  | 360 |  | 
|  | 361 |  | 
|  | 362 | /* Implemented elsewhere: | 
|  | 363 |  | 
|  | 364 | long PyObject_Hash(PyObject *o); | 
|  | 365 |  | 
|  | 366 | Compute and return the hash, hash_value, of an object, o.  On | 
|  | 367 | failure, return -1.  This is the equivalent of the Python | 
|  | 368 | expression: hash(o). | 
|  | 369 |  | 
|  | 370 | */ | 
|  | 371 |  | 
|  | 372 |  | 
|  | 373 | /* Implemented elsewhere: | 
|  | 374 |  | 
|  | 375 | int PyObject_IsTrue(PyObject *o); | 
|  | 376 |  | 
|  | 377 | Returns 1 if the object, o, is considered to be true, and | 
|  | 378 | 0 otherwise. This is equivalent to the Python expression: | 
|  | 379 | not not o | 
|  | 380 |  | 
|  | 381 | This function always succeeds. | 
|  | 382 |  | 
|  | 383 | */ | 
|  | 384 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 385 | PyObject *PyObject_Type Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 386 |  | 
|  | 387 | /* | 
|  | 388 | On success, returns a type object corresponding to the object | 
|  | 389 | type of object o. On failure, returns NULL.  This is | 
|  | 390 | equivalent to the Python expression: type(o). | 
|  | 391 | */ | 
|  | 392 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 393 | int PyObject_Length Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 394 |  | 
|  | 395 | /* | 
|  | 396 | Return the length of object o.  If the object, o, provides | 
|  | 397 | both sequence and mapping protocols, the sequence length is | 
|  | 398 | returned. On error, -1 is returned.  This is the equivalent | 
|  | 399 | to the Python expression: len(o). | 
|  | 400 |  | 
|  | 401 | */ | 
|  | 402 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 403 | PyObject *PyObject_GetItem Py_PROTO((PyObject *o, PyObject *key)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 404 |  | 
|  | 405 | /* | 
|  | 406 | Return element of o corresponding to the object, key, or NULL | 
|  | 407 | on failure. This is the equivalent of the Python expression: | 
|  | 408 | o[key]. | 
|  | 409 |  | 
|  | 410 | */ | 
|  | 411 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 412 | int PyObject_SetItem Py_PROTO((PyObject *o, PyObject *key, PyObject *v)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 413 |  | 
|  | 414 | /* | 
|  | 415 | Map the object, key, to the value, v.  Returns | 
|  | 416 | -1 on failure.  This is the equivalent of the Python | 
|  | 417 | statement: o[key]=v. | 
|  | 418 | */ | 
|  | 419 |  | 
| Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 420 | int PyObject_DelItem Py_PROTO((PyObject *o, PyObject *key)); | 
|  | 421 |  | 
|  | 422 | /* | 
|  | 423 | Delete the mapping for key from *o.  Returns -1 on failure. | 
|  | 424 | This is the equivalent of the Python statement: del o[key]. | 
|  | 425 | */ | 
|  | 426 |  | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 427 |  | 
|  | 428 | /*  Number Protocol:*/ | 
|  | 429 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 430 | int PyNumber_Check Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 431 |  | 
|  | 432 | /* | 
|  | 433 | Returns 1 if the object, o, provides numeric protocols, and | 
|  | 434 | false otherwise. | 
|  | 435 |  | 
|  | 436 | This function always succeeds. | 
|  | 437 |  | 
|  | 438 | */ | 
|  | 439 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 440 | PyObject *PyNumber_Add Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 441 |  | 
|  | 442 | /* | 
|  | 443 | Returns the result of adding o1 and o2, or null on failure. | 
|  | 444 | This is the equivalent of the Python expression: o1+o2. | 
|  | 445 |  | 
|  | 446 |  | 
|  | 447 | */ | 
|  | 448 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 449 | PyObject *PyNumber_Subtract Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 450 |  | 
|  | 451 | /* | 
|  | 452 | Returns the result of subtracting o2 from o1, or null on | 
|  | 453 | failure.  This is the equivalent of the Python expression: | 
|  | 454 | o1-o2. | 
|  | 455 |  | 
|  | 456 | */ | 
|  | 457 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 458 | PyObject *PyNumber_Multiply Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 459 |  | 
|  | 460 | /* | 
|  | 461 | Returns the result of multiplying o1 and o2, or null on | 
|  | 462 | failure.  This is the equivalent of the Python expression: | 
|  | 463 | o1*o2. | 
|  | 464 |  | 
|  | 465 |  | 
|  | 466 | */ | 
|  | 467 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 468 | PyObject *PyNumber_Divide Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 469 |  | 
|  | 470 | /* | 
|  | 471 | Returns the result of dividing o1 by o2, or null on failure. | 
|  | 472 | This is the equivalent of the Python expression: o1/o2. | 
|  | 473 |  | 
|  | 474 |  | 
|  | 475 | */ | 
|  | 476 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 477 | PyObject *PyNumber_Remainder Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 478 |  | 
|  | 479 | /* | 
|  | 480 | Returns the remainder of dividing o1 by o2, or null on | 
|  | 481 | failure.  This is the equivalent of the Python expression: | 
|  | 482 | o1%o2. | 
|  | 483 |  | 
|  | 484 |  | 
|  | 485 | */ | 
|  | 486 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 487 | PyObject *PyNumber_Divmod Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 488 |  | 
|  | 489 | /* | 
|  | 490 | See the built-in function divmod.  Returns NULL on failure. | 
|  | 491 | This is the equivalent of the Python expression: | 
|  | 492 | divmod(o1,o2). | 
|  | 493 |  | 
|  | 494 |  | 
|  | 495 | */ | 
|  | 496 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 497 | PyObject *PyNumber_Power Py_PROTO((PyObject *o1, PyObject *o2, PyObject *o3)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 498 |  | 
|  | 499 | /* | 
|  | 500 | See the built-in function pow.  Returns NULL on failure. | 
|  | 501 | This is the equivalent of the Python expression: | 
|  | 502 | pow(o1,o2,o3), where o3 is optional. | 
|  | 503 |  | 
|  | 504 | */ | 
|  | 505 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 506 | PyObject *PyNumber_Negative Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 507 |  | 
|  | 508 | /* | 
|  | 509 | Returns the negation of o on success, or null on failure. | 
|  | 510 | This is the equivalent of the Python expression: -o. | 
|  | 511 |  | 
|  | 512 | */ | 
|  | 513 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 514 | PyObject *PyNumber_Positive Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 515 |  | 
|  | 516 | /* | 
|  | 517 | Returns the (what?) of o on success, or NULL on failure. | 
|  | 518 | This is the equivalent of the Python expression: +o. | 
|  | 519 |  | 
|  | 520 | */ | 
|  | 521 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 522 | PyObject *PyNumber_Absolute Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 523 |  | 
|  | 524 | /* | 
|  | 525 | Returns the absolute value of o, or null on failure.  This is | 
|  | 526 | the equivalent of the Python expression: abs(o). | 
|  | 527 |  | 
|  | 528 | */ | 
|  | 529 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 530 | PyObject *PyNumber_Invert Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 531 |  | 
|  | 532 | /* | 
|  | 533 | Returns the bitwise negation of o on success, or NULL on | 
|  | 534 | failure.  This is the equivalent of the Python expression: | 
|  | 535 | ~o. | 
|  | 536 |  | 
|  | 537 |  | 
|  | 538 | */ | 
|  | 539 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 540 | PyObject *PyNumber_Lshift Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 541 |  | 
|  | 542 | /* | 
|  | 543 | Returns the result of left shifting o1 by o2 on success, or | 
|  | 544 | NULL on failure.  This is the equivalent of the Python | 
|  | 545 | expression: o1 << o2. | 
|  | 546 |  | 
|  | 547 |  | 
|  | 548 | */ | 
|  | 549 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 550 | PyObject *PyNumber_Rshift Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 551 |  | 
|  | 552 | /* | 
|  | 553 | Returns the result of right shifting o1 by o2 on success, or | 
|  | 554 | NULL on failure.  This is the equivalent of the Python | 
|  | 555 | expression: o1 >> o2. | 
|  | 556 |  | 
|  | 557 | */ | 
|  | 558 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 559 | PyObject *PyNumber_And Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 560 |  | 
|  | 561 | /* | 
|  | 562 | Returns the result of "anding" o2 and o2 on success and NULL | 
|  | 563 | on failure. This is the equivalent of the Python | 
|  | 564 | expression: o1 and o2. | 
|  | 565 |  | 
|  | 566 |  | 
|  | 567 | */ | 
|  | 568 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 569 | PyObject *PyNumber_Xor Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 570 |  | 
|  | 571 | /* | 
|  | 572 | Returns the bitwise exclusive or of o1 by o2 on success, or | 
|  | 573 | NULL on failure.  This is the equivalent of the Python | 
|  | 574 | expression: o1^o2. | 
|  | 575 |  | 
|  | 576 |  | 
|  | 577 | */ | 
|  | 578 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 579 | PyObject *PyNumber_Or Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 580 |  | 
|  | 581 | /* | 
|  | 582 | Returns the result or o1 and o2 on success, or NULL on | 
|  | 583 | failure.  This is the equivalent of the Python expression: | 
|  | 584 | o1 or o2. | 
|  | 585 |  | 
|  | 586 | */ | 
|  | 587 |  | 
|  | 588 | /* Implemented elsewhere: | 
|  | 589 |  | 
| Guido van Rossum | ed227f0 | 1996-09-06 13:40:53 +0000 | [diff] [blame] | 590 | int PyNumber_Coerce(PyObject **p1, PyObject **p2); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 591 |  | 
| Guido van Rossum | ed227f0 | 1996-09-06 13:40:53 +0000 | [diff] [blame] | 592 | This function takes the addresses of two variables of type | 
|  | 593 | PyObject*. | 
|  | 594 |  | 
|  | 595 | If the objects pointed to by *p1 and *p2 have the same type, | 
|  | 596 | increment their reference count and return 0 (success). | 
|  | 597 | If the objects can be converted to a common numeric type, | 
|  | 598 | replace *p1 and *p2 by their converted value (with 'new' | 
|  | 599 | reference counts), and return 0. | 
|  | 600 | If no conversion is possible, or if some other error occurs, | 
|  | 601 | return -1 (failure) and don't increment the reference counts. | 
|  | 602 | The call PyNumber_Coerce(&o1, &o2) is equivalent to the Python | 
|  | 603 | statement o1, o2 = coerce(o1, o2). | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 604 |  | 
|  | 605 | */ | 
|  | 606 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 607 | PyObject *PyNumber_Int Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 608 |  | 
|  | 609 | /* | 
|  | 610 | Returns the o converted to an integer object on success, or | 
|  | 611 | NULL on failure.  This is the equivalent of the Python | 
|  | 612 | expression: int(o). | 
|  | 613 |  | 
|  | 614 | */ | 
|  | 615 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 616 | PyObject *PyNumber_Long Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 617 |  | 
|  | 618 | /* | 
|  | 619 | Returns the o converted to a long integer object on success, | 
|  | 620 | or NULL on failure.  This is the equivalent of the Python | 
|  | 621 | expression: long(o). | 
|  | 622 |  | 
|  | 623 | */ | 
|  | 624 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 625 | PyObject *PyNumber_Float Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 626 |  | 
|  | 627 | /* | 
|  | 628 | Returns the o converted to a float object on success, or NULL | 
|  | 629 | on failure.  This is the equivalent of the Python expression: | 
|  | 630 | float(o). | 
|  | 631 | */ | 
|  | 632 |  | 
|  | 633 |  | 
|  | 634 | /*  Sequence protocol:*/ | 
|  | 635 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 636 | int PySequence_Check Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 637 |  | 
|  | 638 | /* | 
|  | 639 | Return 1 if the object provides sequence protocol, and zero | 
|  | 640 | otherwise. | 
|  | 641 |  | 
|  | 642 | This function always succeeds. | 
|  | 643 |  | 
|  | 644 | */ | 
|  | 645 |  | 
| Guido van Rossum | 578cedd | 1996-08-08 18:43:10 +0000 | [diff] [blame] | 646 | int PySequence_Length Py_PROTO((PyObject *o)); | 
| Guido van Rossum | 4f4ce68 | 1996-07-21 02:22:56 +0000 | [diff] [blame] | 647 |  | 
|  | 648 | /* | 
|  | 649 | Return the length of sequence object o, or -1 on failure. | 
|  | 650 |  | 
|  | 651 | */ | 
|  | 652 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 653 | PyObject *PySequence_Concat Py_PROTO((PyObject *o1, PyObject *o2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 654 |  | 
|  | 655 | /* | 
|  | 656 | Return the concatination of o1 and o2 on success, and NULL on | 
|  | 657 | failure.   This is the equivalent of the Python | 
|  | 658 | expression: o1+o2. | 
|  | 659 |  | 
|  | 660 | */ | 
|  | 661 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 662 | PyObject *PySequence_Repeat Py_PROTO((PyObject *o, int count)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 663 |  | 
|  | 664 | /* | 
|  | 665 | Return the result of repeating sequence object o count times, | 
|  | 666 | or NULL on failure.  This is the equivalent of the Python | 
|  | 667 | expression: o1*count. | 
|  | 668 |  | 
|  | 669 | */ | 
|  | 670 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 671 | PyObject *PySequence_GetItem Py_PROTO((PyObject *o, int i)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 672 |  | 
|  | 673 | /* | 
|  | 674 | Return the ith element of o, or NULL on failure. This is the | 
|  | 675 | equivalent of the Python expression: o[i]. | 
|  | 676 |  | 
|  | 677 | */ | 
|  | 678 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 679 | PyObject *PySequence_GetSlice Py_PROTO((PyObject *o, int i1, int i2)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 680 |  | 
|  | 681 | /* | 
|  | 682 | Return the slice of sequence object o between i1 and i2, or | 
|  | 683 | NULL on failure. This is the equivalent of the Python | 
|  | 684 | expression: o[i1:i2]. | 
|  | 685 |  | 
|  | 686 | */ | 
|  | 687 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 688 | int PySequence_SetItem Py_PROTO((PyObject *o, int i, PyObject *v)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 689 |  | 
|  | 690 | /* | 
|  | 691 | Assign object v to the ith element of o.  Returns | 
|  | 692 | -1 on failure.  This is the equivalent of the Python | 
|  | 693 | statement: o[i]=v. | 
|  | 694 |  | 
|  | 695 | */ | 
|  | 696 |  | 
| Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 697 | int PySequence_DelItem Py_PROTO((PyObject *o, int i)); | 
|  | 698 |  | 
|  | 699 | /* | 
|  | 700 | Delete the ith element of object v.  Returns | 
|  | 701 | -1 on failure.  This is the equivalent of the Python | 
|  | 702 | statement: del o[i]. | 
|  | 703 | */ | 
|  | 704 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 705 | int PySequence_SetSlice Py_PROTO((PyObject *o, int i1, int i2, PyObject *v)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 706 |  | 
|  | 707 | /* | 
|  | 708 | Assign the sequence object, v, to the slice in sequence | 
|  | 709 | object, o, from i1 to i2.  Returns -1 on failure. This is the | 
|  | 710 | equivalent of the Python statement: o[i1:i2]=v. | 
|  | 711 | */ | 
|  | 712 |  | 
| Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 713 | int PySequence_DelSlice Py_PROTO((PyObject *o, int i1, int i2)); | 
|  | 714 |  | 
|  | 715 | /* | 
|  | 716 | Delete the slice in sequence object, o, from i1 to i2. | 
|  | 717 | Returns -1 on failure. This is the equivalent of the Python | 
|  | 718 | statement: del o[i1:i2]. | 
|  | 719 | */ | 
|  | 720 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 721 | PyObject *PySequence_Tuple Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 722 |  | 
|  | 723 | /* | 
|  | 724 | Returns the o as a tuple on success, and NULL on failure. | 
|  | 725 | This is equivalent to the Python expression: tuple(o) | 
|  | 726 | */ | 
|  | 727 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 728 | int PySequence_Count Py_PROTO((PyObject *o, PyObject *value)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 729 |  | 
|  | 730 | /* | 
|  | 731 | Return the number of occurrences on value on o, that is, | 
|  | 732 | return the number of keys for which o[key]==value.  On | 
|  | 733 | failure, return -1.  This is equivalent to the Python | 
|  | 734 | expression: o.count(value). | 
|  | 735 | */ | 
|  | 736 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 737 | int PySequence_In Py_PROTO((PyObject *o, PyObject *value)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 738 |  | 
|  | 739 | /* | 
|  | 740 | Determine if o contains value.  If an item in o is equal to | 
|  | 741 | X, return 1, otherwise return 0.  On error, return -1.  This | 
|  | 742 | is equivalent to the Python expression: value in o. | 
|  | 743 | */ | 
|  | 744 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 745 | int PySequence_Index Py_PROTO((PyObject *o, PyObject *value)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 746 |  | 
|  | 747 | /* | 
|  | 748 | Return the first index for which o[i]=value.  On error, | 
|  | 749 | return -1.    This is equivalent to the Python | 
|  | 750 | expression: o.index(value). | 
|  | 751 | */ | 
|  | 752 |  | 
|  | 753 | /*  Mapping protocol:*/ | 
|  | 754 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 755 | int PyMapping_Check Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 756 |  | 
|  | 757 | /* | 
|  | 758 | Return 1 if the object provides mapping protocol, and zero | 
|  | 759 | otherwise. | 
|  | 760 |  | 
|  | 761 | This function always succeeds. | 
|  | 762 | */ | 
|  | 763 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 764 | int PyMapping_Length Py_PROTO((PyObject *o)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 765 |  | 
|  | 766 | /* | 
|  | 767 | Returns the number of keys in object o on success, and -1 on | 
|  | 768 | failure.  For objects that do not provide sequence protocol, | 
|  | 769 | this is equivalent to the Python expression: len(o). | 
|  | 770 | */ | 
|  | 771 |  | 
| Guido van Rossum | a25e5e9 | 1996-09-06 13:48:38 +0000 | [diff] [blame] | 772 | /* implemented as a macro: | 
|  | 773 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 774 | int PyMapping_DelItemString Py_PROTO((PyObject *o, char *key)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 775 |  | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 776 | Remove the mapping for object, key, from the object *o. | 
|  | 777 | Returns -1 on failure.  This is equivalent to | 
|  | 778 | the Python statement: del o[key]. | 
|  | 779 | */ | 
| Guido van Rossum | a25e5e9 | 1996-09-06 13:48:38 +0000 | [diff] [blame] | 780 | #define PyMapping_DelItemString(O,K) PyDict_DelItemString((O),(K)) | 
|  | 781 |  | 
|  | 782 | /* implemented as a macro: | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 783 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 784 | int PyMapping_DelItem Py_PROTO((PyObject *o, PyObject *key)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 785 |  | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 786 | Remove the mapping for object, key, from the object *o. | 
|  | 787 | Returns -1 on failure.  This is equivalent to | 
|  | 788 | the Python statement: del o[key]. | 
|  | 789 | */ | 
| Guido van Rossum | a25e5e9 | 1996-09-06 13:48:38 +0000 | [diff] [blame] | 790 | #define PyMapping_DelItem(O,K) PyDict_DelItem((O),(K)) | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 791 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 792 | int PyMapping_HasKeyString Py_PROTO((PyObject *o, char *key)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 793 |  | 
|  | 794 | /* | 
|  | 795 | On success, return 1 if the mapping object has the key, key, | 
|  | 796 | and 0 otherwise.  This is equivalent to the Python expression: | 
|  | 797 | o.has_key(key). | 
|  | 798 |  | 
|  | 799 | This function always succeeds. | 
|  | 800 | */ | 
|  | 801 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 802 | int PyMapping_HasKey Py_PROTO((PyObject *o, PyObject *key)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 803 |  | 
|  | 804 | /* | 
|  | 805 | Return 1 if the mapping object has the key, key, | 
|  | 806 | and 0 otherwise.  This is equivalent to the Python expression: | 
|  | 807 | o.has_key(key). | 
|  | 808 |  | 
|  | 809 | This function always succeeds. | 
|  | 810 |  | 
|  | 811 | */ | 
|  | 812 |  | 
|  | 813 | /* Implemented as macro: | 
|  | 814 |  | 
|  | 815 | PyObject *PyMapping_Keys(PyObject *o); | 
|  | 816 |  | 
|  | 817 | On success, return a list of the keys in object o.  On | 
|  | 818 | failure, return NULL. This is equivalent to the Python | 
|  | 819 | expression: o.keys(). | 
|  | 820 | */ | 
|  | 821 | #define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL) | 
|  | 822 |  | 
|  | 823 | /* Implemented as macro: | 
|  | 824 |  | 
|  | 825 | PyObject *PyMapping_Values(PyObject *o); | 
|  | 826 |  | 
|  | 827 | On success, return a list of the values in object o.  On | 
|  | 828 | failure, return NULL. This is equivalent to the Python | 
|  | 829 | expression: o.values(). | 
|  | 830 | */ | 
|  | 831 | #define PyMapping_Values(O) PyObject_CallMethod(O,"values",NULL) | 
|  | 832 |  | 
|  | 833 | /* Implemented as macro: | 
|  | 834 |  | 
|  | 835 | PyObject *PyMapping_Items(PyObject *o); | 
|  | 836 |  | 
|  | 837 | On success, return a list of the items in object o, where | 
|  | 838 | each item is a tuple containing a key-value pair.  On | 
|  | 839 | failure, return NULL. This is equivalent to the Python | 
|  | 840 | expression: o.items(). | 
|  | 841 |  | 
|  | 842 | */ | 
|  | 843 | #define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL) | 
|  | 844 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 845 | PyObject *PyMapping_GetItemString Py_PROTO((PyObject *o, char *key)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 846 |  | 
|  | 847 | /* | 
|  | 848 | Return element of o corresponding to the object, key, or NULL | 
|  | 849 | on failure. This is the equivalent of the Python expression: | 
|  | 850 | o[key]. | 
|  | 851 | */ | 
|  | 852 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 853 | int PyMapping_SetItemString Py_PROTO((PyObject *o, char *key, | 
|  | 854 | PyObject *value)); | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 855 |  | 
|  | 856 | /* | 
|  | 857 | Map the object, key, to the value, v.  Returns | 
|  | 858 | -1 on failure.  This is the equivalent of the Python | 
|  | 859 | statement: o[key]=v. | 
|  | 860 | */ | 
|  | 861 |  | 
|  | 862 |  | 
| Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 863 | #ifdef __cplusplus | 
|  | 864 | } | 
|  | 865 | #endif | 
| Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 866 | #endif /* Py_ABSTRACTOBJECT_H */ |