annotate Include/intobject.h @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents 5158e4789459
children aa8d59823add
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Integer object interface */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 /*
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
5 PyIntObject represents a (long) integer. This is an immutable object;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 an integer cannot change its value after creation.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 There are functions to create new integer objects, to test an object
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 for integer-ness, and to get the integer value. The latter functions
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
10 returns -1 and sets errno to EBADF if the object is not an PyIntObject.
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 None of the functions should be applied to nil objects.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
13 The type PyIntObject is (unfortunately) exposed here so we can declare
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
14 _Py_TrueStruct and _Py_ZeroStruct below; don't use this.
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
17 #ifndef Py_INTOBJECT_H
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
18 #define Py_INTOBJECT_H
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
19 #ifdef __cplusplus
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
20 extern "C" {
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
21 #endif
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
22
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 typedef struct {
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
24 PyObject_HEAD
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
25 long ob_ival;
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
26 } PyIntObject;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
2436
fa98dda07877 make the type a parameter of the DL_IMPORT macro, for Borland C
Guido van Rossum <guido@python.org>
parents: 2129
diff changeset
28 extern DL_IMPORT(PyTypeObject) PyInt_Type;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
19550
19d271f297dc Make the PyXXX_Check() macros for the numeric types inheritance-aware.
Guido van Rossum <guido@python.org>
parents: 19343
diff changeset
30 #define PyInt_Check(op) PyObject_TypeCheck(op, &PyInt_Type)
19837
5158e4789459 SF bug #460020: bug or feature: unicode() and subclasses.
Tim Peters <tim.peters@gmail.com>
parents: 19550
diff changeset
31 #define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
33 extern DL_IMPORT(PyObject *) PyInt_FromString(char*, char**, int);
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
34 #ifdef Py_USING_UNICODE
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
35 extern DL_IMPORT(PyObject *) PyInt_FromUnicode(Py_UNICODE*, int, int);
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
36 #endif
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
37 extern DL_IMPORT(PyObject *) PyInt_FromLong(long);
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
38 extern DL_IMPORT(long) PyInt_AsLong(PyObject *);
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
39 extern DL_IMPORT(long) PyInt_GetMax(void);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 /*
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 False and True are special intobjects used by Boolean expressions.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 All values of type Boolean must point to either of these; but in
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 contexts where integers are required they are integers (valued 0 and 1).
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 Hope these macros don't conflict with other people's.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
48 Don't forget to apply Py_INCREF() when returning True or False!!!
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
2436
fa98dda07877 make the type a parameter of the DL_IMPORT macro, for Borland C
Guido van Rossum <guido@python.org>
parents: 2129
diff changeset
51 extern DL_IMPORT(PyIntObject) _Py_ZeroStruct, _Py_TrueStruct; /* Don't use these directly */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
53 #define Py_False ((PyObject *) &_Py_ZeroStruct)
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
54 #define Py_True ((PyObject *) &_Py_TrueStruct)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 /* Macro, trading safety for speed */
5918
780b68df4560 Add cast to PyInt_AS_LONG macro, as suggested by Marc Lemburg.
Guido van Rossum <guido@python.org>
parents: 5861
diff changeset
57 #define PyInt_AS_LONG(op) (((PyIntObject *)(op))->ob_ival)
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
58
9623
fa8f9fe0a33d Add prototypes for PyOS_strto[u]l -- Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
59 /* These aren't really part of the Int object, but they're handy; the protos
fa8f9fe0a33d Add prototypes for PyOS_strto[u]l -- Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
60 * are necessary for systems that need the magic of DL_IMPORT and that want
fa8f9fe0a33d Add prototypes for PyOS_strto[u]l -- Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
61 * to have stropmodule as a dynamically loaded module instead of building it
fa8f9fe0a33d Add prototypes for PyOS_strto[u]l -- Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
62 * into the main Python shared library/DLL. Guido thinks I'm weird for
fa8f9fe0a33d Add prototypes for PyOS_strto[u]l -- Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
63 * building it this way. :-) [cjh]
fa8f9fe0a33d Add prototypes for PyOS_strto[u]l -- Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
64 */
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
65 extern DL_IMPORT(unsigned long) PyOS_strtoul(char *, char **, int);
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
66 extern DL_IMPORT(long) PyOS_strtol(char *, char **, int);
9623
fa8f9fe0a33d Add prototypes for PyOS_strto[u]l -- Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
67
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
68 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
69 }
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
70 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
71 #endif /* !Py_INTOBJECT_H */