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