Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1 | /* Integer object interface */ |
| 2 | |
| 3 | /* |
| 4 | 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12 |
| 5 | |
| 6 | intobject represents a (long) integer. This is an immutable object; |
| 7 | an integer cannot change its value after creation. |
| 8 | |
| 9 | There are functions to create new integer objects, to test an object |
| 10 | for integer-ness, and to get the integer value. The latter functions |
| 11 | returns -1 and sets errno to EBADF if the object is not an intobject. |
| 12 | None of the functions should be applied to nil objects. |
| 13 | |
| 14 | The type intobject is (unfortunately) exposed bere so we can declare |
| 15 | TrueObject and FalseObject below; don't use this. |
| 16 | */ |
| 17 | |
| 18 | typedef struct { |
| 19 | OB_HEAD |
| 20 | long ob_ival; |
| 21 | } intobject; |
| 22 | |
| 23 | extern typeobject Inttype; |
| 24 | |
| 25 | #define is_intobject(op) ((op)->ob_type == &Inttype) |
| 26 | |
| 27 | extern object *newintobject PROTO((long)); |
| 28 | extern long getintvalue PROTO((object *)); |
| 29 | |
| 30 | |
| 31 | /* |
| 32 | 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12 |
| 33 | |
| 34 | False and True are special intobjects used by Boolean expressions. |
| 35 | All values of type Boolean must point to either of these; but in |
| 36 | contexts where integers are required they are integers (valued 0 and 1). |
| 37 | Hope these macros don't conflict with other people's. |
| 38 | |
| 39 | Don't forget to apply INCREF() when returning True or False!!! |
| 40 | */ |
| 41 | |
| 42 | extern intobject FalseObject, TrueObject; /* Don't use these directly */ |
| 43 | |
| 44 | #define False ((object *) &FalseObject) |
| 45 | #define True ((object *) &TrueObject) |
| 46 | |
| 47 | /* Macro, trading safety for speed */ |
| 48 | #define GETINTVALUE(op) ((op)->ob_ival) |