Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 6610ad9 | 1995-01-04 19:07:38 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 25 | /* Type object implementation */ |
| 26 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 27 | #include "allobjects.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 28 | |
| 29 | /* Type object implementation */ |
| 30 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 31 | static object * |
Guido van Rossum | 29ca26e | 1995-01-07 11:58:15 +0000 | [diff] [blame] | 32 | type_getattr(t, name) |
| 33 | typeobject *t; |
| 34 | char *name; |
| 35 | { |
| 36 | if (strcmp(name, "__name__") == 0) |
| 37 | return newstringobject(t->tp_name); |
| 38 | if (strcmp(name, "__doc__") == 0) { |
| 39 | char *doc = t->tp_doc; |
| 40 | if (doc != NULL) |
| 41 | return newstringobject(doc); |
| 42 | INCREF(None); |
| 43 | return None; |
| 44 | } |
| 45 | if (strcmp(name, "__members__") == 0) |
| 46 | return mkvalue("[ss]", "__doc__", "__name__"); |
| 47 | err_setstr(AttributeError, name); |
| 48 | return NULL; |
| 49 | } |
| 50 | |
| 51 | static object * |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 52 | type_repr(v) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 53 | typeobject *v; |
| 54 | { |
| 55 | char buf[100]; |
| 56 | sprintf(buf, "<type '%.80s'>", v->tp_name); |
| 57 | return newstringobject(buf); |
| 58 | } |
| 59 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 60 | typeobject Typetype = { |
| 61 | OB_HEAD_INIT(&Typetype) |
| 62 | 0, /* Number of items for varobject */ |
| 63 | "type", /* Name of this type */ |
| 64 | sizeof(typeobject), /* Basic object size */ |
| 65 | 0, /* Item size for varobject */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 66 | 0, /*tp_dealloc*/ |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 67 | 0, /*tp_print*/ |
Guido van Rossum | 29ca26e | 1995-01-07 11:58:15 +0000 | [diff] [blame] | 68 | (getattrfunc)type_getattr, /*tp_getattr*/ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 69 | 0, /*tp_setattr*/ |
| 70 | 0, /*tp_compare*/ |
Guido van Rossum | 29ca26e | 1995-01-07 11:58:15 +0000 | [diff] [blame] | 71 | (reprfunc)type_repr, /*tp_repr*/ |
| 72 | 0, /*tp_as_number*/ |
| 73 | 0, /*tp_as_sequence*/ |
| 74 | 0, /*tp_as_mapping*/ |
| 75 | 0, /*tp_hash*/ |
| 76 | 0, /*tp_call*/ |
| 77 | 0, /*tp_str*/ |
| 78 | 0, /*tp_xxx1*/ |
| 79 | 0, /*tp_xxx2*/ |
| 80 | 0, /*tp_xxx3*/ |
| 81 | 0, /*tp_xxx4*/ |
| 82 | "Define the behaviour of a particular type of object.", |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 83 | }; |