Mercurial > cpython-lru_cache-weakref
annotate Python/structmember.c @ 13973:4e28ca345cfe legacy-trunk
Fix the parent of WindowsError - both the comments in this source file, and the previous exceptions.py have WindowsError as a sub-class of OSError.
| author | Mark Hammond <mhammond@skippinet.com.au> |
|---|---|
| date | Tue, 15 Aug 2000 00:37:32 +0000 |
| parents | f79434ee41fa |
| children | 6f6f965c5e2d |
| rev | line source |
|---|---|
| 145 | 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 | 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 | 9 ******************************************************************/ |
| 10 | |
| 86 | 11 /* Map C struct members to Python object attributes */ |
| 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 | 14 |
| 15 #include "structmember.h" | |
| 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 * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
18 listmembers(struct memberlist *mlist) |
|
398
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
19 { |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
20 int i, n; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
21 PyObject *v; |
|
398
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
22 for (n = 0; mlist[n].name != NULL; n++) |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
23 ; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
24 v = PyList_New(n); |
|
398
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
25 if (v != NULL) { |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
26 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
|
27 PyList_SetItem(v, i, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
28 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
|
29 if (PyErr_Occurred()) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
30 Py_DECREF(v); |
|
398
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
31 v = NULL; |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
32 } |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
33 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
34 PyList_Sort(v); |
|
398
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
35 } |
|
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 return v; |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
38 } |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
39 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
40 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
41 PyMember_Get(char *addr, struct memberlist *mlist, char *name) |
| 86 | 42 { |
| 43 struct memberlist *l; | |
| 44 | |
|
398
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
45 if (strcmp(name, "__members__") == 0) |
|
0ac1357cd898
Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
46 return listmembers(mlist); |
| 86 | 47 for (l = mlist; l->name != NULL; l++) { |
| 48 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
|
49 PyObject *v; |
| 86 | 50 addr += l->offset; |
| 51 switch (l->type) { | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
52 case T_BYTE: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
53 v = PyInt_FromLong((long) |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
54 (((*(char*)addr & 0xff) |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
55 ^ 0x80) - 0x80)); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
56 break; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
57 case T_UBYTE: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
58 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
|
59 break; |
| 86 | 60 case T_SHORT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
61 v = PyInt_FromLong((long) *(short*)addr); |
| 86 | 62 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
63 case T_USHORT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
64 v = PyInt_FromLong((long) |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
65 *(unsigned short*)addr); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
66 break; |
| 86 | 67 case T_INT: |
|
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) *(int*)addr); |
| 86 | 69 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
70 case T_UINT: |
|
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) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
72 *(unsigned int*)addr); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
73 break; |
| 86 | 74 case T_LONG: |
|
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*)addr); |
| 86 | 76 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
77 case T_ULONG: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
78 v = PyLong_FromDouble((double) |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
79 *(unsigned long*)addr); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
80 break; |
| 86 | 81 case T_FLOAT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
82 v = PyFloat_FromDouble((double)*(float*)addr); |
| 86 | 83 break; |
| 84 case T_DOUBLE: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
85 v = PyFloat_FromDouble(*(double*)addr); |
| 86 | 86 break; |
| 87 case T_STRING: | |
| 88 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
|
89 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
90 v = Py_None; |
| 86 | 91 } |
| 92 else | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
93 v = PyString_FromString(*(char**)addr); |
| 86 | 94 break; |
|
2023
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
95 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
|
96 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
|
97 break; |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
98 #ifdef macintosh |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
99 case T_PSTRING: |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
100 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
|
101 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
102 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
|
103 } |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
104 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
105 v = PyString_FromStringAndSize( |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
106 (*(char**)addr)+1, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
107 **(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
|
108 break; |
|
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_INPLACE: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
110 v = PyString_FromStringAndSize( |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
111 ((char*)addr)+1, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
112 *(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
|
113 break; |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
114 #endif /* macintosh */ |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
115 case T_CHAR: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
116 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
|
117 break; |
| 86 | 118 case T_OBJECT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
119 v = *(PyObject **)addr; |
| 86 | 120 if (v == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
121 v = Py_None; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
122 Py_INCREF(v); |
| 86 | 123 break; |
| 124 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
125 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
126 "bad memberlist type"); |
| 86 | 127 v = NULL; |
| 128 } | |
| 129 return v; | |
| 130 } | |
| 131 } | |
| 132 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
133 PyErr_SetString(PyExc_AttributeError, name); |
| 86 | 134 return NULL; |
| 135 } | |
| 136 | |
| 137 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
138 PyMember_Set(char *addr, struct memberlist *mlist, char *name, PyObject *v) |
| 86 | 139 { |
| 140 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
|
141 PyObject *oldv; |
| 86 | 142 |
| 143 for (l = mlist; l->name != NULL; l++) { | |
| 144 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
|
145 #ifdef macintosh |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
146 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
|
147 l->type == T_PSTRING) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
148 { |
|
2023
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
149 #else |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
150 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
|
151 #endif /* macintosh */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
152 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
153 "readonly attribute"); |
| 86 | 154 return -1; |
| 155 } | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
156 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
|
157 PyErr_SetString(PyExc_TypeError, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
158 "can't delete numeric/char attribute"); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
159 return -1; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
160 } |
| 86 | 161 addr += l->offset; |
| 162 switch (l->type) { | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
163 case T_BYTE: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
164 case T_UBYTE: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
165 if (!PyInt_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
166 PyErr_BadArgument(); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
167 return -1; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
168 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
169 *(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
|
170 break; |
| 86 | 171 case T_SHORT: |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
172 case T_USHORT: |
|
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(); |
| 86 | 175 return -1; |
| 176 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
177 *(short*)addr = (short) PyInt_AsLong(v); |
| 86 | 178 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
179 case T_UINT: |
| 86 | 180 case T_INT: |
|
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 | 183 return -1; |
| 184 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
185 *(int*)addr = (int) PyInt_AsLong(v); |
| 86 | 186 break; |
| 187 case T_LONG: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
188 if (!PyInt_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
189 PyErr_BadArgument(); |
| 86 | 190 return -1; |
| 191 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
192 *(long*)addr = PyInt_AsLong(v); |
| 86 | 193 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
194 case T_ULONG: |
|
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 *(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
|
197 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
|
198 *(long*)addr = PyLong_AsLong(v); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
199 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
200 PyErr_BadArgument(); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
201 return -1; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
202 } |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
203 break; |
| 86 | 204 case T_FLOAT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
205 if (PyInt_Check(v)) |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
206 *(float*)addr = |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
207 (float) PyInt_AsLong(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
208 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
|
209 *(float*)addr = |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
210 (float) PyFloat_AsDouble(v); |
| 86 | 211 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
212 PyErr_BadArgument(); |
| 86 | 213 return -1; |
| 214 } | |
| 215 break; | |
| 216 case T_DOUBLE: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
217 if (PyInt_Check(v)) |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
218 *(double*)addr = |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
219 (double) PyInt_AsLong(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
220 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
|
221 *(double*)addr = PyFloat_AsDouble(v); |
| 86 | 222 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
223 PyErr_BadArgument(); |
| 86 | 224 return -1; |
| 225 } | |
| 226 break; | |
| 227 case T_OBJECT: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
228 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
|
229 oldv = *(PyObject **)addr; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
230 *(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
|
231 Py_XDECREF(oldv); |
| 86 | 232 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
233 case T_CHAR: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
234 if (PyString_Check(v) && |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
235 PyString_Size(v) == 1) { |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
236 *(char*)addr = |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
237 PyString_AsString(v)[0]; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
238 } |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
239 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
240 PyErr_BadArgument(); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
241 return -1; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
242 } |
| 86 | 243 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
244 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
245 "bad memberlist type"); |
| 86 | 246 return -1; |
| 247 } | |
| 248 return 0; | |
| 249 } | |
| 250 } | |
| 251 | |
|
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_AttributeError, name); |
| 95 | 253 return -1; |
| 86 | 254 } |
