typeobject.c revision c0b618a2ccfb0fc39e07ee96dc09da77fbcce1b1
1/*********************************************************** 2Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, 3The Netherlands. 4 5 All Rights Reserved 6 7Permission to use, copy, modify, and distribute this software and its 8documentation for any purpose and without fee is hereby granted, 9provided that the above copyright notice appear in all copies and that 10both that copyright notice and this permission notice appear in 11supporting documentation, and that the names of Stichting Mathematisch 12Centrum or CWI or Corporation for National Research Initiatives or 13CNRI not be used in advertising or publicity pertaining to 14distribution of the software without specific, written prior 15permission. 16 17While CWI is the initial source for this software, a modified version 18is made available by the Corporation for National Research Initiatives 19(CNRI) at the Internet address ftp://ftp.python.org. 20 21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH 22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF 23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH 24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 28PERFORMANCE OF THIS SOFTWARE. 29 30******************************************************************/ 31 32/* Type object implementation */ 33 34#include "Python.h" 35 36/* Type object implementation */ 37 38static PyObject * 39type_getattr(t, name) 40 PyTypeObject *t; 41 char *name; 42{ 43 if (strcmp(name, "__name__") == 0) 44 return PyString_FromString(t->tp_name); 45 if (strcmp(name, "__doc__") == 0) { 46 char *doc = t->tp_doc; 47 if (doc != NULL) 48 return PyString_FromString(doc); 49 Py_INCREF(Py_None); 50 return Py_None; 51 } 52 if (strcmp(name, "__members__") == 0) 53 return Py_BuildValue("[ss]", "__doc__", "__name__"); 54 PyErr_SetString(PyExc_AttributeError, name); 55 return NULL; 56} 57 58static PyObject * 59type_repr(v) 60 PyTypeObject *v; 61{ 62 char buf[100]; 63 sprintf(buf, "<type '%.80s'>", v->tp_name); 64 return PyString_FromString(buf); 65} 66 67PyTypeObject PyType_Type = { 68 PyObject_HEAD_INIT(&PyType_Type) 69 0, /* Number of items for varobject */ 70 "type", /* Name of this type */ 71 sizeof(PyTypeObject), /* Basic object size */ 72 0, /* Item size for varobject */ 73 0, /*tp_dealloc*/ 74 0, /*tp_print*/ 75 (getattrfunc)type_getattr, /*tp_getattr*/ 76 0, /*tp_setattr*/ 77 0, /*tp_compare*/ 78 (reprfunc)type_repr, /*tp_repr*/ 79 0, /*tp_as_number*/ 80 0, /*tp_as_sequence*/ 81 0, /*tp_as_mapping*/ 82 0, /*tp_hash*/ 83 0, /*tp_call*/ 84 0, /*tp_str*/ 85 0, /*tp_xxx1*/ 86 0, /*tp_xxx2*/ 87 0, /*tp_xxx3*/ 88 0, /*tp_xxx4*/ 89 "Define the behaviour of a particular type of object.", 90}; 91