annotate Tools/modulator/Templates/object_structure @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents cd9d86ecc175
children 847425d5bca8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2713
cd9d86ecc175 Templates converted to new naming conventions (thanks to Chak Tan)
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
1
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Code to access structure members by accessing attributes */
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #include "structmember.h"
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 #define OFF(x) offsetof(XXXXobject, x)
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 static struct memberlist $abbrev$_memberlist[] = {
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 /* XXXX Add lines like { "foo", T_INT, OFF(foo), RO } */
2713
cd9d86ecc175 Templates converted to new naming conventions (thanks to Chak Tan)
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
10
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 {NULL} /* Sentinel */
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 };
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
2713
cd9d86ecc175 Templates converted to new naming conventions (thanks to Chak Tan)
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
14 static PyObject *
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 $abbrev$_getattr(self, name)
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 $abbrev$object *self;
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 char *name;
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 {
2713
cd9d86ecc175 Templates converted to new naming conventions (thanks to Chak Tan)
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
19 PyObject *rv;
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 /* XXXX Add your own getattr code here */
2713
cd9d86ecc175 Templates converted to new naming conventions (thanks to Chak Tan)
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
22 rv = PyMember_Get((char *)/*XXXX*/0, $abbrev$_memberlist, name);
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 if (rv)
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 return rv;
2713
cd9d86ecc175 Templates converted to new naming conventions (thanks to Chak Tan)
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
25 PyErr_Clear();
cd9d86ecc175 Templates converted to new naming conventions (thanks to Chak Tan)
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
26 return Py_FindMethod($abbrev$_methods, (PyObject *)self, name);
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 }
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 static int
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 $abbrev$_setattr(self, name, v)
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 $abbrev$object *self;
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 char *name;
2713
cd9d86ecc175 Templates converted to new naming conventions (thanks to Chak Tan)
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
34 PyObject *v;
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 {
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 /* XXXX Add your own setattr code here */
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 if ( v == NULL ) {
2713
cd9d86ecc175 Templates converted to new naming conventions (thanks to Chak Tan)
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
38 PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 return -1;
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 }
2713
cd9d86ecc175 Templates converted to new naming conventions (thanks to Chak Tan)
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
41 return PyMember_Set((char *)/*XXXX*/0, $abbrev$_memberlist, name, v);
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 }