Mercurial > cpython-lru_cache-weakref
annotate Python/structmember.c @ 4503:65d2d8e67da3 legacy-trunk
New permission notice, includes CNRI.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 25 Oct 1996 14:44:06 +0000 |
| parents | d0d0a69b5ca3 |
| children | 5af766a1b531 |
| rev | line source |
|---|---|
| 145 | 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 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 145 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 145 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
15 permission. |
| 145 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 145 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 86 | 32 /* Map C struct members to Python object attributes */ |
| 33 | |
| 34 #include "allobjects.h" | |
| 35 | |
| 36 #include "structmember.h" | |
| 37 | |
|
398
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
38 static object * |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
39 listmembers(mlist) |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
40 struct memberlist *mlist; |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
41 { |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
42 int i, n; |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
43 object *v; |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
44 for (n = 0; mlist[n].name != NULL; n++) |
|
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 v = newlistobject(n); |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
47 if (v != NULL) { |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
48 for (i = 0; i < n; i++) |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
49 setlistitem(v, i, newstringobject(mlist[i].name)); |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
50 if (err_occurred()) { |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
51 DECREF(v); |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
52 v = NULL; |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
53 } |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
54 else { |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
55 sortlist(v); |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
56 } |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
57 } |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
58 return v; |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
59 } |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
60 |
| 86 | 61 object * |
| 62 getmember(addr, mlist, name) | |
| 63 char *addr; | |
| 64 struct memberlist *mlist; | |
| 65 char *name; | |
| 66 { | |
| 67 struct memberlist *l; | |
| 68 | |
|
398
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
69 if (strcmp(name, "__members__") == 0) |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
70 return listmembers(mlist); |
| 86 | 71 for (l = mlist; l->name != NULL; l++) { |
| 72 if (strcmp(l->name, name) == 0) { | |
| 73 object *v; | |
| 74 addr += l->offset; | |
| 75 switch (l->type) { | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
76 case T_BYTE: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
77 v = newintobject((long) |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
78 (((*(char*)addr & 0xff) |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
79 ^ 0x80) - 0x80)); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
80 break; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
81 case T_UBYTE: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
82 v = newintobject((long) *(char*)addr & 0xff); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
83 break; |
| 86 | 84 case T_SHORT: |
| 85 v = newintobject((long) *(short*)addr); | |
| 86 break; | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
87 case T_USHORT: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
88 v = newintobject((long) |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
89 *(unsigned short*)addr); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
90 break; |
| 86 | 91 case T_INT: |
| 92 v = newintobject((long) *(int*)addr); | |
| 93 break; | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
94 case T_UINT: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
95 v = newintobject((long) *(unsigned int*)addr); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
96 break; |
| 86 | 97 case T_LONG: |
| 98 v = newintobject(*(long*)addr); | |
| 99 break; | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
100 case T_ULONG: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
101 v = dnewlongobject((double) |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
102 *(unsigned long*)addr); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
103 break; |
| 86 | 104 case T_FLOAT: |
| 105 v = newfloatobject((double)*(float*)addr); | |
| 106 break; | |
| 107 case T_DOUBLE: | |
| 108 v = newfloatobject(*(double*)addr); | |
| 109 break; | |
| 110 case T_STRING: | |
| 111 if (*(char**)addr == NULL) { | |
| 112 INCREF(None); | |
| 113 v = None; | |
| 114 } | |
| 115 else | |
| 116 v = newstringobject(*(char**)addr); | |
| 117 break; | |
|
2023
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
118 case T_STRING_INPLACE: |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
119 v = newstringobject((char*)addr); |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
120 break; |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
121 #ifdef macintosh |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
122 case T_PSTRING: |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
123 if (*(char**)addr == NULL) { |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
124 INCREF(None); |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
125 v = None; |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
126 } |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
127 else |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
128 v = newsizedstringobject((*(char**)addr)+1, |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
129 **(unsigned char**)addr); |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
130 break; |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
131 case T_PSTRING_INPLACE: |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
132 v = newsizedstringobject(((char*)addr)+1, |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
133 *(unsigned char*)addr); |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
134 break; |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
135 #endif /* macintosh */ |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
136 case T_CHAR: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
137 v = newsizedstringobject((char*)addr, 1); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
138 break; |
| 86 | 139 case T_OBJECT: |
| 140 v = *(object **)addr; | |
| 141 if (v == NULL) | |
| 142 v = None; | |
| 143 INCREF(v); | |
| 144 break; | |
| 145 default: | |
| 146 err_setstr(SystemError, "bad memberlist type"); | |
| 147 v = NULL; | |
| 148 } | |
| 149 return v; | |
| 150 } | |
| 151 } | |
| 152 | |
| 475 | 153 err_setstr(AttributeError, name); |
| 86 | 154 return NULL; |
| 155 } | |
| 156 | |
| 157 int | |
| 158 setmember(addr, mlist, name, v) | |
| 159 char *addr; | |
| 160 struct memberlist *mlist; | |
| 161 char *name; | |
| 162 object *v; | |
| 163 { | |
| 164 struct memberlist *l; | |
| 165 | |
| 166 for (l = mlist; l->name != NULL; l++) { | |
| 167 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
|
168 #ifdef macintosh |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
169 if (l->readonly || l->type == T_STRING || l->type == T_PSTRING) { |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
170 #else |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
171 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
|
172 #endif /* macintosh */ |
| 475 | 173 err_setstr(TypeError, "readonly attribute"); |
| 86 | 174 return -1; |
| 175 } | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
176 if (v == NULL && l->type != T_OBJECT) { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
177 err_setstr(TypeError, |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
178 "can't delete numeric/char attribute"); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
179 return -1; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
180 } |
| 86 | 181 addr += l->offset; |
| 182 switch (l->type) { | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
183 case T_BYTE: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
184 case T_UBYTE: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
185 if (!is_intobject(v)) { |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
186 err_badarg(); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
187 return -1; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
188 } |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
189 *(char*)addr = getintvalue(v); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
190 break; |
| 86 | 191 case T_SHORT: |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
192 case T_USHORT: |
| 86 | 193 if (!is_intobject(v)) { |
| 194 err_badarg(); | |
| 195 return -1; | |
| 196 } | |
| 197 *(short*)addr = getintvalue(v); | |
| 198 break; | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
199 case T_UINT: |
| 86 | 200 case T_INT: |
| 201 if (!is_intobject(v)) { | |
| 202 err_badarg(); | |
| 203 return -1; | |
| 204 } | |
| 205 *(int*)addr = getintvalue(v); | |
| 206 break; | |
| 207 case T_LONG: | |
| 208 if (!is_intobject(v)) { | |
| 209 err_badarg(); | |
| 210 return -1; | |
| 211 } | |
| 212 *(long*)addr = getintvalue(v); | |
| 213 break; | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
214 case T_ULONG: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
215 if (is_intobject(v)) |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
216 *(long*)addr = getintvalue(v); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
217 else if (is_longobject(v)) |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
218 *(long*)addr = getlongvalue(v); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
219 else { |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
220 err_badarg(); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
221 return -1; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
222 } |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
223 break; |
| 86 | 224 case T_FLOAT: |
| 225 if (is_intobject(v)) | |
| 226 *(float*)addr = getintvalue(v); | |
| 227 else if (is_floatobject(v)) | |
| 228 *(float*)addr = getfloatvalue(v); | |
| 229 else { | |
| 230 err_badarg(); | |
| 231 return -1; | |
| 232 } | |
| 233 break; | |
| 234 case T_DOUBLE: | |
| 235 if (is_intobject(v)) | |
| 236 *(double*)addr = getintvalue(v); | |
| 237 else if (is_floatobject(v)) | |
| 238 *(double*)addr = getfloatvalue(v); | |
| 239 else { | |
| 240 err_badarg(); | |
| 241 return -1; | |
| 242 } | |
| 243 break; | |
| 244 case T_OBJECT: | |
| 245 XDECREF(*(object **)addr); | |
| 246 XINCREF(v); | |
| 247 *(object **)addr = v; | |
| 248 break; | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
249 case T_CHAR: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
250 if (is_stringobject(v) && |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
251 getstringsize(v) == 1) { |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
252 *(char*)addr = |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
253 getstringvalue(v)[0]; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
254 } |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
255 else { |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
256 err_badarg(); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
257 return -1; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
258 } |
| 86 | 259 default: |
| 260 err_setstr(SystemError, "bad memberlist type"); | |
| 261 return -1; | |
| 262 } | |
| 263 return 0; | |
| 264 } | |
| 265 } | |
| 266 | |
| 475 | 267 err_setstr(AttributeError, name); |
| 95 | 268 return -1; |
| 86 | 269 } |
