1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
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
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. */
48 PyObject
*x_attr
; /* Attributes dictionary */
51 staticforward PyTypeObject Xxtype
;
53 #define is_xxobject(v) ((v)->ob_type == &Xxtype)
60 xp
= PyObject_NEW(xxobject
, &Xxtype
);
73 Py_XDECREF(xp
->x_attr
);
82 if (!PyArg_NoArgs(args
))
88 static PyMethodDef xx_methods
[] = {
89 {"demo", (PyCFunction
)xx_demo
},
90 {NULL
, NULL
} /* sentinel */
98 if (xp
->x_attr
!= NULL
) {
99 PyObject
*v
= PyDict_GetItemString(xp
->x_attr
, name
);
105 return Py_FindMethod(xx_methods
, (PyObject
*)xp
, name
);
109 xx_setattr(xp
, name
, v
)
114 if (xp
->x_attr
== NULL
) {
115 xp
->x_attr
= PyDict_New();
116 if (xp
->x_attr
== NULL
)
120 int rv
= PyDict_DelItemString(xp
->x_attr
, name
);
122 PyErr_SetString(PyExc_AttributeError
,
123 "delete non-existing xx attribute");
127 return PyDict_SetItemString(xp
->x_attr
, name
, v
);
130 static PyTypeObject Xxtype
= {
131 PyObject_HEAD_INIT(&PyType_Type
)
134 sizeof(xxobject
), /*tp_basicsize*/
137 (destructor
)xx_dealloc
, /*tp_dealloc*/
139 (getattrfunc
)xx_getattr
, /*tp_getattr*/
140 (setattrfunc
)xx_setattr
, /*tp_setattr*/
144 0, /*tp_as_sequence*/