annotate Python/structmember.c @ 13256:87ee82e5c56d legacy-trunk

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