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