annotate Objects/typeobject.c @ 18816:50004bed4e65 legacy-trunk

Oh, ok, so plainpager is probably marginally better.
author Fred Drake <fdrake@acm.org>
date Mon, 23 Jul 2001 19:48:10 +0000
parents 62472656807e
children 09df3254b49d
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: 86
diff changeset
1
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Type object implementation */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
4 #include "Python.h"
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 /* Type object implementation */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
8 static PyObject *
13458
7908ec855665 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
9 type_getattr(PyTypeObject *t, char *name)
2080
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
10 {
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
11 if (strcmp(name, "__name__") == 0)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
12 return PyString_FromString(t->tp_name);
2080
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
13 if (strcmp(name, "__doc__") == 0) {
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
14 char *doc = t->tp_doc;
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
15 if (doc != NULL)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
16 return PyString_FromString(doc);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
17 Py_INCREF(Py_None);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
18 return Py_None;
2080
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
19 }
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
20 if (strcmp(name, "__members__") == 0)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
21 return Py_BuildValue("[ss]", "__doc__", "__name__");
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
22 PyErr_SetString(PyExc_AttributeError, name);
2080
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
23 return NULL;
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
24 }
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
25
18063
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
26 static int
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
27 type_compare(PyObject *v, PyObject *w)
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
28 {
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
29 /* This is called with type objects only. So we
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
30 can just compare the addresses. */
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
31 Py_uintptr_t vv = (Py_uintptr_t)v;
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
32 Py_uintptr_t ww = (Py_uintptr_t)w;
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
33 return (vv < ww) ? -1 : (vv > ww) ? 1 : 0;
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
34 }
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
35
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
36 static PyObject *
13458
7908ec855665 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
37 type_repr(PyTypeObject *v)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 char buf[100];
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 sprintf(buf, "<type '%.80s'>", v->tp_name);
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
41 return PyString_FromString(buf);
6
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
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
44 PyTypeObject PyType_Type = {
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
45 PyObject_HEAD_INIT(&PyType_Type)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 0, /* Number of items for varobject */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 "type", /* Name of this type */
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
48 sizeof(PyTypeObject), /* Basic object size */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 0, /* Item size for varobject */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
50 0, /*tp_dealloc*/
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
51 0, /*tp_print*/
2080
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
52 (getattrfunc)type_getattr, /*tp_getattr*/
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
53 0, /*tp_setattr*/
18063
bbac2a6a5d16 Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
54 type_compare, /*tp_compare*/
2080
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
55 (reprfunc)type_repr, /*tp_repr*/
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
56 0, /*tp_as_number*/
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
57 0, /*tp_as_sequence*/
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
58 0, /*tp_as_mapping*/
18068
62472656807e Added a missing cast to the hashfunc initializer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18063
diff changeset
59 (hashfunc)_Py_HashPointer, /*tp_hash*/
2080
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
60 0, /*tp_call*/
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
61 0, /*tp_str*/
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
62 0, /*tp_xxx1*/
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
63 0, /*tp_xxx2*/
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
64 0, /*tp_xxx3*/
c21cc7b3ce28 added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents: 2059
diff changeset
65 0, /*tp_xxx4*/
5671
d66304963ca7 American spelling in doc string.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
66 "Define the behavior of a particular type of object.",
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 };