annotate Python/structmember.c @ 13255:916fb024ce94 legacy-trunk

Change copyright notice.
author Guido van Rossum <guido@python.org>
date Fri, 30 Jun 2000 23:50:40 +0000
parents ff31f2501742
children 87ee82e5c56d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
1 /***********************************************************
2062
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2023
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2023
diff changeset
3 The Netherlands.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
4
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
5 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
6
13255
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 8398
diff changeset
7 Copyright (c) 2000, BeOpen.com.
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 8398
diff changeset
8 Copyright (c) 1995-2000, Corporation for National Research Initiatives.
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 8398
diff changeset
9 Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 8398
diff changeset
10 All rights reserved.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
11
13255
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 8398
diff changeset
12 See the file "Misc/COPYRIGHT" for information on usage and
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 8398
diff changeset
13 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
14
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
15 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
16
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 /* Map C struct members to Python object attributes */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
19 #include "Python.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 #include "structmember.h"
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
23 static PyObject *
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
24 listmembers(mlist)
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
25 struct memberlist *mlist;
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
26 {
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
27 int i, n;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
28 PyObject *v;
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
29 for (n = 0; mlist[n].name != NULL; n++)
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
30 ;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
31 v = PyList_New(n);
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
32 if (v != NULL) {
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
33 for (i = 0; i < n; i++)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
34 PyList_SetItem(v, i,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
35 PyString_FromString(mlist[i].name));
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
36 if (PyErr_Occurred()) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
37 Py_DECREF(v);
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
38 v = NULL;
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
39 }
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
40 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
41 PyList_Sort(v);
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
42 }
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
43 }
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
44 return v;
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
45 }
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
46
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
47 PyObject *
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
48 PyMember_Get(addr, mlist, name)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 char *addr;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 struct memberlist *mlist;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 char *name;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 struct memberlist *l;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
54
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
55 if (strcmp(name, "__members__") == 0)
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
56 return listmembers(mlist);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 for (l = mlist; l->name != NULL; l++) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 if (strcmp(l->name, name) == 0) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
59 PyObject *v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 addr += l->offset;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 switch (l->type) {
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
62 case T_BYTE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
63 v = PyInt_FromLong((long)
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
64 (((*(char*)addr & 0xff)
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
65 ^ 0x80) - 0x80));
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
66 break;
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
67 case T_UBYTE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
68 v = PyInt_FromLong((long) *(char*)addr & 0xff);
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
69 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 case T_SHORT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
71 v = PyInt_FromLong((long) *(short*)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
73 case T_USHORT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
74 v = PyInt_FromLong((long)
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
75 *(unsigned short*)addr);
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
76 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 case T_INT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
78 v = PyInt_FromLong((long) *(int*)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
80 case T_UINT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
81 v = PyInt_FromLong((long)
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
82 *(unsigned int*)addr);
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
83 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 case T_LONG:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
85 v = PyInt_FromLong(*(long*)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
87 case T_ULONG:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
88 v = PyLong_FromDouble((double)
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
89 *(unsigned long*)addr);
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
90 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 case T_FLOAT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
92 v = PyFloat_FromDouble((double)*(float*)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 case T_DOUBLE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
95 v = PyFloat_FromDouble(*(double*)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 case T_STRING:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 if (*(char**)addr == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
99 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
100 v = Py_None;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 else
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
103 v = PyString_FromString(*(char**)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 break;
2023
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
105 case T_STRING_INPLACE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
106 v = PyString_FromString((char*)addr);
2023
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
107 break;
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
108 #ifdef macintosh
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
109 case T_PSTRING:
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
110 if (*(char**)addr == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
111 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
112 v = Py_None;
2023
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
113 }
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
114 else
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
115 v = PyString_FromStringAndSize(
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
116 (*(char**)addr)+1,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
117 **(unsigned char**)addr);
2023
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
118 break;
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
119 case T_PSTRING_INPLACE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
120 v = PyString_FromStringAndSize(
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
121 ((char*)addr)+1,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
122 *(unsigned char*)addr);
2023
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
123 break;
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
124 #endif /* macintosh */
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
125 case T_CHAR:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
126 v = PyString_FromStringAndSize((char*)addr, 1);
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
127 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 case T_OBJECT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
129 v = *(PyObject **)addr;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 if (v == NULL)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
131 v = Py_None;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
132 Py_INCREF(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
135 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
136 "bad memberlist type");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 v = NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 return v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
143 PyErr_SetString(PyExc_AttributeError, name);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
146
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 int
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
148 PyMember_Set(addr, mlist, name, v)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 char *addr;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 struct memberlist *mlist;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 char *name;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
152 PyObject *v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 struct memberlist *l;
8398
ff31f2501742 Trivial little change: when setting a member to an object, hold the
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
155 PyObject *oldv;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 for (l = mlist; l->name != NULL; l++) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 if (strcmp(l->name, name) == 0) {
2023
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
159 #ifdef macintosh
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
160 if (l->readonly || l->type == T_STRING ||
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
161 l->type == T_PSTRING)
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
162 {
2023
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
163 #else
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
164 if (l->readonly || l->type == T_STRING ) {
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
165 #endif /* macintosh */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
166 PyErr_SetString(PyExc_TypeError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
167 "readonly attribute");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 }
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
170 if (v == NULL && l->type != T_OBJECT) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
171 PyErr_SetString(PyExc_TypeError,
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
172 "can't delete numeric/char attribute");
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
173 return -1;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
174 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 addr += l->offset;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 switch (l->type) {
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
177 case T_BYTE:
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
178 case T_UBYTE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
179 if (!PyInt_Check(v)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
180 PyErr_BadArgument();
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
181 return -1;
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
182 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
183 *(char*)addr = (char) PyInt_AsLong(v);
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
184 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 case T_SHORT:
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
186 case T_USHORT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
187 if (!PyInt_Check(v)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
188 PyErr_BadArgument();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
191 *(short*)addr = (short) PyInt_AsLong(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
193 case T_UINT:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 case T_INT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
195 if (!PyInt_Check(v)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
196 PyErr_BadArgument();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
199 *(int*)addr = (int) PyInt_AsLong(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 case T_LONG:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
202 if (!PyInt_Check(v)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
203 PyErr_BadArgument();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
206 *(long*)addr = PyInt_AsLong(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
208 case T_ULONG:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
209 if (PyInt_Check(v))
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
210 *(long*)addr = PyInt_AsLong(v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
211 else if (PyLong_Check(v))
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
212 *(long*)addr = PyLong_AsLong(v);
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
213 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
214 PyErr_BadArgument();
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
215 return -1;
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
216 }
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
217 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 case T_FLOAT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
219 if (PyInt_Check(v))
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
220 *(float*)addr =
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
221 (float) PyInt_AsLong(v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
222 else if (PyFloat_Check(v))
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
223 *(float*)addr =
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
224 (float) PyFloat_AsDouble(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
226 PyErr_BadArgument();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 case T_DOUBLE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
231 if (PyInt_Check(v))
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
232 *(double*)addr =
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
233 (double) PyInt_AsLong(v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
234 else if (PyFloat_Check(v))
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
235 *(double*)addr = PyFloat_AsDouble(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
237 PyErr_BadArgument();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 case T_OBJECT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
242 Py_XINCREF(v);
8398
ff31f2501742 Trivial little change: when setting a member to an object, hold the
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
243 oldv = *(PyObject **)addr;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
244 *(PyObject **)addr = v;
8398
ff31f2501742 Trivial little change: when setting a member to an object, hold the
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
245 Py_XDECREF(oldv);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
247 case T_CHAR:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
248 if (PyString_Check(v) &&
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
249 PyString_Size(v) == 1) {
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
250 *(char*)addr =
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
251 PyString_AsString(v)[0];
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
252 }
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
253 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
254 PyErr_BadArgument();
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
255 return -1;
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
256 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
258 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
259 "bad memberlist type");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 return 0;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
265
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
266 PyErr_SetString(PyExc_AttributeError, name);
95
a5bf7d5959ce Return -1 for errors.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
267 return -1;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 }