Don't reference removed files in Makefile
[python/dscho.git] / Objects / xxobject.c
blobbb8a5f677f900f5178fb3492fed7bf5cb98b1d13
1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
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.
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.
23 ******************************************************************/
25 /* Use this file as a template to start implementing a new object type.
26 If your objects will be called foobar, start by copying this file to
27 foobarobject.c, changing all occurrences of xx to foobar and all
28 occurrences of Xx by Foobar. You will probably want to delete all
29 references to 'x_attr' and add your own types of attributes
30 instead. Maybe you want to name your local variables other than
31 'xp'. If your object type is needed in other files, you'll have to
32 create a file "foobarobject.h"; see intobject.h for an example. */
35 /* Xx objects */
37 #include "Python.h"
39 typedef struct {
40 PyObject_HEAD
41 PyObject *x_attr; /* Attributes dictionary */
42 } xxobject;
44 staticforward PyTypeObject Xxtype;
46 #define is_xxobject(v) ((v)->ob_type == &Xxtype)
48 static xxobject *
49 newxxobject(arg)
50 PyObject *arg;
52 xxobject *xp;
53 xp = PyObject_NEW(xxobject, &Xxtype);
54 if (xp == NULL)
55 return NULL;
56 xp->x_attr = NULL;
57 return xp;
60 /* Xx methods */
62 static void
63 xx_dealloc(xp)
64 xxobject *xp;
66 Py_XDECREF(xp->x_attr);
67 PyMem_DEL(xp);
70 static PyObject *
71 xx_demo(self, args)
72 xxobject *self;
73 PyObject *args;
75 if (!PyArg_NoArgs(args))
76 return NULL;
77 Py_INCREF(Py_None);
78 return Py_None;
81 static Py_MethodDef xx_methods[] = {
82 {"demo", (PyCFunction)xx_demo},
83 {NULL, NULL} /* sentinel */
86 static PyObject *
87 xx_getattr(xp, name)
88 xxobject *xp;
89 char *name;
91 if (xp->x_attr != NULL) {
92 PyObject *v = PyDict_GetItemString(xp->x_attr, name);
93 if (v != NULL) {
94 Py_INCREF(v);
95 return v;
98 return Py_FindMethod(xx_methods, (PyObject *)xp, name);
101 static int
102 xx_setattr(xp, name, v)
103 xxobject *xp;
104 char *name;
105 PyObject *v;
107 if (xp->x_attr == NULL) {
108 xp->x_attr = PyDict_New();
109 if (xp->x_attr == NULL)
110 return -1;
112 if (v == NULL) {
113 int rv = PyDict_DelItemString(xp->x_attr, name);
114 if (rv < 0)
115 PyErr_SetString(PyExc_AttributeError,
116 "delete non-existing xx attribute");
117 return rv;
119 else
120 return PyDict_SetItemString(xp->x_attr, name, v);
123 static PyTypeObject Xxtype = {
124 PyObject_HEAD_INIT(&PyType_Type)
125 0, /*ob_size*/
126 "xx", /*tp_name*/
127 sizeof(xxobject), /*tp_basicsize*/
128 0, /*tp_itemsize*/
129 /* methods */
130 (destructor)xx_dealloc, /*tp_dealloc*/
131 0, /*tp_print*/
132 (getattrfunc)xx_getattr, /*tp_getattr*/
133 (setattrfunc)xx_setattr, /*tp_setattr*/
134 0, /*tp_compare*/
135 0, /*tp_repr*/
136 0, /*tp_as_number*/
137 0, /*tp_as_sequence*/
138 0, /*tp_as_mapping*/
139 0, /*tp_hash*/