Mercurial > cpython-lru_cache-weakref
annotate Modules/xxmodule.c @ 3720:b341def4eef8 legacy-trunk
Ignore latex intermediate products.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 26 Jun 1996 19:30:01 +0000 |
| parents | dab34cbf8d7f |
| children | d19338fd38eb |
| rev | line source |
|---|---|
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1915
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1915
diff
changeset
|
3 The Netherlands. |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 All Rights Reserved |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 Centrum or CWI not be used in advertising or publicity pertaining to |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 distribution of the software without specific, written prior permission. |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 ******************************************************************/ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
25 /* Use this file as a template to start implementing a module that |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
26 also declares objects types. All occurrences of 'xxo' should be changed |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
27 to something reasonable for your objects. After that, all other |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
28 occurrences of 'xx' should be changed to something reasonable for your |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
29 module. If your module is named foo your sourcefile should be named |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
30 foomodule.c. |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
31 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
32 You will probably want to delete all references to 'x_attr' and add |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
33 your own types of attributes instead. Maybe you want to name your |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
34 local variables other than 'self'. If your object type is needed in |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
35 other files, you'll have to create a file "foobarobject.h"; see |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
36 intobject.h for an example. */ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
37 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
38 /* Xxo objects */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 #include "allobjects.h" |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
41 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
42 static object *ErrorObject; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
43 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
44 typedef struct { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
45 OB_HEAD |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
46 object *x_attr; /* Attributes dictionary */ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
47 } xxoobject; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
48 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
49 staticforward typeobject Xxotype; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
50 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
51 #define is_xxoobject(v) ((v)->ob_type == &Xxotype) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
52 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
53 static xxoobject * |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
54 newxxoobject(arg) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
55 object *arg; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
56 { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
57 xxoobject *self; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
58 self = NEWOBJ(xxoobject, &Xxotype); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
59 if (self == NULL) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
60 return NULL; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
61 self->x_attr = NULL; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
62 return self; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
63 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
64 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
65 /* Xxo methods */ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
66 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
67 static void |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
68 xxo_dealloc(self) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
69 xxoobject *self; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
70 { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
71 XDECREF(self->x_attr); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
72 DEL(self); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
73 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
74 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
75 static object * |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
76 xxo_demo(self, args) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
77 xxoobject *self; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
78 object *args; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
79 { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
80 if (!getnoarg(args)) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
81 return NULL; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
82 INCREF(None); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
83 return None; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
84 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
85 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
86 static struct methodlist xxo_methods[] = { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
87 {"demo", (method)xxo_demo}, |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
88 {NULL, NULL} /* sentinel */ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
89 }; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
91 static object * |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
92 xxo_getattr(self, name) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
93 xxoobject *self; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
94 char *name; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
95 { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
96 if (self->x_attr != NULL) { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
97 object *v = dictlookup(self->x_attr, name); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
98 if (v != NULL) { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
99 INCREF(v); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
100 return v; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
101 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
102 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
103 return findmethod(xxo_methods, (object *)self, name); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
104 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
105 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
106 static int |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
107 xxo_setattr(self, name, v) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
108 xxoobject *self; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
109 char *name; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
110 object *v; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
111 { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
112 if (self->x_attr == NULL) { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
113 self->x_attr = newdictobject(); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
114 if (self->x_attr == NULL) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
115 return -1; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
116 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
117 if (v == NULL) { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
118 int rv = dictremove(self->x_attr, name); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
119 if (rv < 0) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
120 err_setstr(AttributeError, |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
121 "delete non-existing xxo attribute"); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
122 return rv; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
123 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
124 else |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
125 return dictinsert(self->x_attr, name, v); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
126 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
127 |
|
2377
dab34cbf8d7f
changes for CFM-68K mac
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
128 staticforward typeobject Xxotype = { |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
129 OB_HEAD_INIT(&Typetype) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
130 0, /*ob_size*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
131 "xxo", /*tp_name*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
132 sizeof(xxoobject), /*tp_basicsize*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
133 0, /*tp_itemsize*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
134 /* methods */ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
135 (destructor)xxo_dealloc, /*tp_dealloc*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
136 0, /*tp_print*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
137 (getattrfunc)xxo_getattr, /*tp_getattr*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
138 (setattrfunc)xxo_setattr, /*tp_setattr*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
139 0, /*tp_compare*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
140 0, /*tp_repr*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
141 0, /*tp_as_number*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
142 0, /*tp_as_sequence*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
143 0, /*tp_as_mapping*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
144 0, /*tp_hash*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
145 }; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
146 /* --------------------------------------------------------------------- */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 /* Function of two integers returning integer */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 static object * |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 xx_foo(self, args) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 object *self; /* Not used */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 object *args; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 long i, j; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 long res; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 if (!getargs(args, "(ll)", &i, &j)) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 return NULL; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 res = i+j; /* XXX Do something here */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 return newintobject(res); |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
164 /* Function of no arguments returning new xxo object */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 static object * |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
167 xx_new(self, args) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 object *self; /* Not used */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 object *args; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 int i, j; |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
172 xxoobject *rv; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
173 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 if (!getnoarg(args)) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 return NULL; |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
176 rv = newxxoobject(args); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
177 if ( rv == NULL ) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
178 return NULL; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
179 return (object *)rv; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 /* List of functions defined in the module */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 static struct methodlist xx_methods[] = { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 {"foo", xx_foo}, |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
187 {"new", xx_new}, |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 {NULL, NULL} /* sentinel */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 /* Initialization function for the module (*must* be called initxx) */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 void |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 initxx() |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 { |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
197 object *m, *d; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 /* Create the module and add the functions */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 m = initmodule("xx", xx_methods); |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 /* Add some symbolic constants to the module */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 d = getmoduledict(m); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
204 ErrorObject = newstringobject("xx.error"); |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
205 dictinsert(d, "error", ErrorObject); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 /* Check for errors */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 if (err_occurred()) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 fatal("can't initialize module xx"); |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 } |
