blob: 956ca89017fcc0ee0024da4a06c206d73e94aeab [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
583 int PyNumber_Coerce(PyObject *o1, PyObject *o2);
584
585 On success, returns a tuple containing o1 and o2 converted to
586 a common numeric type, or None if no conversion is possible.
587 Returns -1 on failure. This is equivalent to the Python
588 expression: coerce(o1,o2).
589
590 */
591
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000592 PyObject *PyNumber_Int Py_PROTO((PyObject *o));
Guido van Rossuma8275371995-07-18 14:07:00 +0000593
594 /*
595 Returns the o converted to an integer object on success, or
596 NULL on failure. This is the equivalent of the Python
597 expression: int(o).
598
599 */
600
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000601 PyObject *PyNumber_Long Py_PROTO((PyObject *o));
Guido van Rossuma8275371995-07-18 14:07:00 +0000602
603 /*
604 Returns the o converted to a long integer object on success,
605 or NULL on failure. This is the equivalent of the Python
606 expression: long(o).
607
608 */
609
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000610 PyObject *PyNumber_Float Py_PROTO((PyObject *o));
Guido van Rossuma8275371995-07-18 14:07:00 +0000611
612 /*
613 Returns the o converted to a float object on success, or NULL
614 on failure. This is the equivalent of the Python expression:
615 float(o).
616 */
617
618
619/* Sequence protocol:*/
620
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000621 int PySequence_Check Py_PROTO((PyObject *o));
Guido van Rossuma8275371995-07-18 14:07:00 +0000622
623 /*
624 Return 1 if the object provides sequence protocol, and zero
625 otherwise.
626
627 This function always succeeds.
628
629 */
630
Guido van Rossum578cedd1996-08-08 18:43:10 +0000631 int PySequence_Length Py_PROTO((PyObject *o));
Guido van Rossum4f4ce681996-07-21 02:22:56 +0000632
633 /*
634 Return the length of sequence object o, or -1 on failure.
635
636 */
637
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000638 PyObject *PySequence_Concat Py_PROTO((PyObject *o1, PyObject *o2));
Guido van Rossuma8275371995-07-18 14:07:00 +0000639
640 /*
641 Return the concatination of o1 and o2 on success, and NULL on
642 failure. This is the equivalent of the Python
643 expression: o1+o2.
644
645 */
646
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000647 PyObject *PySequence_Repeat Py_PROTO((PyObject *o, int count));
Guido van Rossuma8275371995-07-18 14:07:00 +0000648
649 /*
650 Return the result of repeating sequence object o count times,
651 or NULL on failure. This is the equivalent of the Python
652 expression: o1*count.
653
654 */
655
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000656 PyObject *PySequence_GetItem Py_PROTO((PyObject *o, int i));
Guido van Rossuma8275371995-07-18 14:07:00 +0000657
658 /*
659 Return the ith element of o, or NULL on failure. This is the
660 equivalent of the Python expression: o[i].
661
662 */
663
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000664 PyObject *PySequence_GetSlice Py_PROTO((PyObject *o, int i1, int i2));
Guido van Rossuma8275371995-07-18 14:07:00 +0000665
666 /*
667 Return the slice of sequence object o between i1 and i2, or
668 NULL on failure. This is the equivalent of the Python
669 expression: o[i1:i2].
670
671 */
672
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000673 int PySequence_SetItem Py_PROTO((PyObject *o, int i, PyObject *v));
Guido van Rossuma8275371995-07-18 14:07:00 +0000674
675 /*
676 Assign object v to the ith element of o. Returns
677 -1 on failure. This is the equivalent of the Python
678 statement: o[i]=v.
679
680 */
681
Guido van Rossum6cdc6f41996-08-21 17:41:54 +0000682 int PySequence_DelItem Py_PROTO((PyObject *o, int i));
683
684 /*
685 Delete the ith element of object v. Returns
686 -1 on failure. This is the equivalent of the Python
687 statement: del o[i].
688 */
689
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000690 int PySequence_SetSlice Py_PROTO((PyObject *o, int i1, int i2, PyObject *v));
Guido van Rossuma8275371995-07-18 14:07:00 +0000691
692 /*
693 Assign the sequence object, v, to the slice in sequence
694 object, o, from i1 to i2. Returns -1 on failure. This is the
695 equivalent of the Python statement: o[i1:i2]=v.
696 */
697
Guido van Rossum6cdc6f41996-08-21 17:41:54 +0000698 int PySequence_DelSlice Py_PROTO((PyObject *o, int i1, int i2));
699
700 /*
701 Delete the slice in sequence object, o, from i1 to i2.
702 Returns -1 on failure. This is the equivalent of the Python
703 statement: del o[i1:i2].
704 */
705
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000706 PyObject *PySequence_Tuple Py_PROTO((PyObject *o));
Guido van Rossuma8275371995-07-18 14:07:00 +0000707
708 /*
709 Returns the o as a tuple on success, and NULL on failure.
710 This is equivalent to the Python expression: tuple(o)
711 */
712
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000713 int PySequence_Count Py_PROTO((PyObject *o, PyObject *value));
Guido van Rossuma8275371995-07-18 14:07:00 +0000714
715 /*
716 Return the number of occurrences on value on o, that is,
717 return the number of keys for which o[key]==value. On
718 failure, return -1. This is equivalent to the Python
719 expression: o.count(value).
720 */
721
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000722 int PySequence_In Py_PROTO((PyObject *o, PyObject *value));
Guido van Rossuma8275371995-07-18 14:07:00 +0000723
724 /*
725 Determine if o contains value. If an item in o is equal to
726 X, return 1, otherwise return 0. On error, return -1. This
727 is equivalent to the Python expression: value in o.
728 */
729
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000730 int PySequence_Index Py_PROTO((PyObject *o, PyObject *value));
Guido van Rossuma8275371995-07-18 14:07:00 +0000731
732 /*
733 Return the first index for which o[i]=value. On error,
734 return -1. This is equivalent to the Python
735 expression: o.index(value).
736 */
737
738/* Mapping protocol:*/
739
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000740 int PyMapping_Check Py_PROTO((PyObject *o));
Guido van Rossuma8275371995-07-18 14:07:00 +0000741
742 /*
743 Return 1 if the object provides mapping protocol, and zero
744 otherwise.
745
746 This function always succeeds.
747 */
748
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000749 int PyMapping_Length Py_PROTO((PyObject *o));
Guido van Rossuma8275371995-07-18 14:07:00 +0000750
751 /*
752 Returns the number of keys in object o on success, and -1 on
753 failure. For objects that do not provide sequence protocol,
754 this is equivalent to the Python expression: len(o).
755 */
756
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000757 int PyMapping_DelItemString Py_PROTO((PyObject *o, char *key));
Guido van Rossuma8275371995-07-18 14:07:00 +0000758
759 /*
760 Remove the mapping for object, key, from the object *o.
761 Returns -1 on failure. This is equivalent to
762 the Python statement: del o[key].
763 */
764
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000765 int PyMapping_DelItem Py_PROTO((PyObject *o, PyObject *key));
Guido van Rossuma8275371995-07-18 14:07:00 +0000766
767 /*
768 Remove the mapping for object, key, from the object *o.
769 Returns -1 on failure. This is equivalent to
770 the Python statement: del o[key].
771 */
772
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000773 int PyMapping_HasKeyString Py_PROTO((PyObject *o, char *key));
Guido van Rossuma8275371995-07-18 14:07:00 +0000774
775 /*
776 On success, return 1 if the mapping object has the key, key,
777 and 0 otherwise. This is equivalent to the Python expression:
778 o.has_key(key).
779
780 This function always succeeds.
781 */
782
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000783 int PyMapping_HasKey Py_PROTO((PyObject *o, PyObject *key));
Guido van Rossuma8275371995-07-18 14:07:00 +0000784
785 /*
786 Return 1 if the mapping object has the key, key,
787 and 0 otherwise. This is equivalent to the Python expression:
788 o.has_key(key).
789
790 This function always succeeds.
791
792 */
793
794 /* Implemented as macro:
795
796 PyObject *PyMapping_Keys(PyObject *o);
797
798 On success, return a list of the keys in object o. On
799 failure, return NULL. This is equivalent to the Python
800 expression: o.keys().
801 */
802#define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL)
803
804 /* Implemented as macro:
805
806 PyObject *PyMapping_Values(PyObject *o);
807
808 On success, return a list of the values in object o. On
809 failure, return NULL. This is equivalent to the Python
810 expression: o.values().
811 */
812#define PyMapping_Values(O) PyObject_CallMethod(O,"values",NULL)
813
814 /* Implemented as macro:
815
816 PyObject *PyMapping_Items(PyObject *o);
817
818 On success, return a list of the items in object o, where
819 each item is a tuple containing a key-value pair. On
820 failure, return NULL. This is equivalent to the Python
821 expression: o.items().
822
823 */
824#define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL)
825
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000826 PyObject *PyMapping_GetItemString Py_PROTO((PyObject *o, char *key));
Guido van Rossuma8275371995-07-18 14:07:00 +0000827
828 /*
829 Return element of o corresponding to the object, key, or NULL
830 on failure. This is the equivalent of the Python expression:
831 o[key].
832 */
833
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000834 int PyMapping_SetItemString Py_PROTO((PyObject *o, char *key,
835 PyObject *value));
Guido van Rossuma8275371995-07-18 14:07:00 +0000836
837 /*
838 Map the object, key, to the value, v. Returns
839 -1 on failure. This is the equivalent of the Python
840 statement: o[key]=v.
841 */
842
843
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000844#ifdef __cplusplus
845}
846#endif
Guido van Rossuma8275371995-07-18 14:07:00 +0000847#endif /* Py_ABSTRACTOBJECT_H */