blob: ffafcd71bdb86dc4982d5b9324c396a12c3a72b5 [file] [log] [blame]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001/* Xx objects */
2
3typedef struct {
4 OB_HEAD
5 object *x_attr; /* Attributes dictionary */
6} xxobject;
7
8extern typeobject Xxtype; /* Really static, forward */
9
10static xxobject *
11newxxobject(arg)
12 object *arg;
13{
14 textobject *xp;
15 xp = NEWOBJ(xxobject, &Xxtype);
16 if (xp == NULL)
17 return NULL;
18 xp->x_attr = NULL;
19 return xp;
20}
21
22/* Xx methods */
23
24static void
25xx_dealloc(xp)
26 xxobject *xp;
27{
28 if (xp->x_attr != NULL)
29 DECREF(xp->x_attr);
30 DEL(xp);
31}
32
33static object *
34xx_demo(self, args)
35 xxobject *self;
36 object *args;
37{
38 if (!getnoarg(args))
39 return NULL;
40 INCREF(None);
41 return None;
42}
43
44static struct methodlist xx_methods[] = {
45 "demo", xx_demo,
46 {NULL, NULL} /* sentinel */
47};
48
49static object *
50xx_getattr(xp, name)
51 xxobject *xp;
52 char *name;
53{
54 if (xp->x_attr != NULL) {
55 object *v = dictlookup(xp->x_attr, name);
56 if (v != NULL) {
57 INCREF(v);
58 return v;
59 }
60 }
61 return findmethod(xx_methods, (object *)xp, name);
62}
63
64static int
65xx_setattr(xp, name, v)
66 xxobject *xp;
67 char *name;
68 object *v;
69{
70 if (xp->x_attr == NULL) {
71 xp->x_attr = newdictobject();
72 if (xp->x_attr == NULL)
73 return errno;
74 }
75 if (v == NULL)
76 return dictremove(xp->x_attr, name);
77 else
78 return dictinsert(xp->x_attr, name, v);
79}
80
81static typeobject Xxtype = {
82 OB_HEAD_INIT(&Typetype)
83 0, /*ob_size*/
84 "xx", /*tp_name*/
85 sizeof(xxobject), /*tp_size*/
86 0, /*tp_itemsize*/
87 /* methods */
88 xx_dealloc, /*tp_dealloc*/
89 0, /*tp_print*/
90 xx_getattr, /*tp_getattr*/
91 xx_setattr, /*tp_setattr*/
92 0, /*tp_compare*/
93 0, /*tp_repr*/
94};