Fix an amazing number of typos & malformed sentences reported by Detlef
[python/dscho.git] / Objects / xxobject.c
blobc5b518f7bdde7aca619848a7c8a2554edef3781e
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 or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
15 permission.
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
32 /* Use this file as a template to start implementing a new object type.
33 If your objects will be called foobar, start by copying this file to
34 foobarobject.c, changing all occurrences of xx to foobar and all
35 occurrences of Xx by Foobar. You will probably want to delete all
36 references to 'x_attr' and add your own types of attributes
37 instead. Maybe you want to name your local variables other than
38 'xp'. If your object type is needed in other files, you'll have to
39 create a file "foobarobject.h"; see intobject.h for an example. */
42 /* Xx objects */
44 #include "Python.h"
46 typedef struct {
47 PyObject_HEAD
48 PyObject *x_attr; /* Attributes dictionary */
49 } xxobject;
51 staticforward PyTypeObject Xxtype;
53 #define is_xxobject(v) ((v)->ob_type == &Xxtype)
55 static xxobject *
56 newxxobject(arg)
57 PyObject *arg;
59 xxobject *xp;
60 xp = PyObject_NEW(xxobject, &Xxtype);
61 if (xp == NULL)
62 return NULL;
63 xp->x_attr = NULL;
64 return xp;
67 /* Xx methods */
69 static void
70 xx_dealloc(xp)
71 xxobject *xp;
73 Py_XDECREF(xp->x_attr);
74 PyMem_DEL(xp);
77 static PyObject *
78 xx_demo(self, args)
79 xxobject *self;
80 PyObject *args;
82 if (!PyArg_NoArgs(args))
83 return NULL;
84 Py_INCREF(Py_None);
85 return Py_None;
88 static PyMethodDef xx_methods[] = {
89 {"demo", (PyCFunction)xx_demo},
90 {NULL, NULL} /* sentinel */
93 static PyObject *
94 xx_getattr(xp, name)
95 xxobject *xp;
96 char *name;
98 if (xp->x_attr != NULL) {
99 PyObject *v = PyDict_GetItemString(xp->x_attr, name);
100 if (v != NULL) {
101 Py_INCREF(v);
102 return v;
105 return Py_FindMethod(xx_methods, (PyObject *)xp, name);
108 static int
109 xx_setattr(xp, name, v)
110 xxobject *xp;
111 char *name;
112 PyObject *v;
114 if (xp->x_attr == NULL) {
115 xp->x_attr = PyDict_New();
116 if (xp->x_attr == NULL)
117 return -1;
119 if (v == NULL) {
120 int rv = PyDict_DelItemString(xp->x_attr, name);
121 if (rv < 0)
122 PyErr_SetString(PyExc_AttributeError,
123 "delete non-existing xx attribute");
124 return rv;
126 else
127 return PyDict_SetItemString(xp->x_attr, name, v);
130 static PyTypeObject Xxtype = {
131 PyObject_HEAD_INIT(&PyType_Type)
132 0, /*ob_size*/
133 "xx", /*tp_name*/
134 sizeof(xxobject), /*tp_basicsize*/
135 0, /*tp_itemsize*/
136 /* methods */
137 (destructor)xx_dealloc, /*tp_dealloc*/
138 0, /*tp_print*/
139 (getattrfunc)xx_getattr, /*tp_getattr*/
140 (setattrfunc)xx_setattr, /*tp_setattr*/
141 0, /*tp_compare*/
142 0, /*tp_repr*/
143 0, /*tp_as_number*/
144 0, /*tp_as_sequence*/
145 0, /*tp_as_mapping*/
146 0, /*tp_hash*/