Mercurial > cpython-lru_cache-weakref
annotate Python/structmember.c @ 19942:8522b022f80a legacy-trunk
Add support for restricting access based on restricted execution mode.
Renamed the 'readonly' field to 'flags' and defined some new flag
bits: READ_RESTRICTED and WRITE_RESTRICTED, as well as a shortcut
RESTRICTED that means both.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 17 Sep 2001 19:28:08 +0000 |
| parents | 7b3476c1382e |
| children | 3faabf54b8b8 |
| 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; |
|
19942
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
41 if ((l->flags & READ_RESTRICTED) && |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
42 PyEval_GetRestricted()) { |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
43 PyErr_SetString(PyExc_RuntimeError, |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
44 "restricted attribute"); |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
45 return NULL; |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
46 } |
| 86 | 47 addr += l->offset; |
| 48 switch (l->type) { | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
49 case T_BYTE: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
50 v = PyInt_FromLong((long) |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
51 (((*(char*)addr & 0xff) |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
52 ^ 0x80) - 0x80)); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
53 break; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
54 case T_UBYTE: |
|
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) *(char*)addr & 0xff); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
56 break; |
| 86 | 57 case T_SHORT: |
|
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) *(short*)addr); |
| 86 | 59 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
60 case T_USHORT: |
|
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) |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
62 *(unsigned short*)addr); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
63 break; |
| 86 | 64 case T_INT: |
|
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) *(int*)addr); |
| 86 | 66 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
67 case T_UINT: |
|
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) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
69 *(unsigned int*)addr); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
70 break; |
| 86 | 71 case T_LONG: |
|
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*)addr); |
| 86 | 73 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
74 case T_ULONG: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
75 v = PyLong_FromDouble((double) |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
76 *(unsigned long*)addr); |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
77 break; |
| 86 | 78 case T_FLOAT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
79 v = PyFloat_FromDouble((double)*(float*)addr); |
| 86 | 80 break; |
| 81 case T_DOUBLE: | |
|
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*)addr); |
| 86 | 83 break; |
| 84 case T_STRING: | |
| 85 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
|
86 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
87 v = Py_None; |
| 86 | 88 } |
| 89 else | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
90 v = PyString_FromString(*(char**)addr); |
| 86 | 91 break; |
|
2023
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
92 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
|
93 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
|
94 break; |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
95 #ifdef macintosh |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
96 case T_PSTRING: |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
97 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
|
98 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
99 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
|
100 } |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
101 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
102 v = PyString_FromStringAndSize( |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
103 (*(char**)addr)+1, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
104 **(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
|
105 break; |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
106 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
|
107 v = PyString_FromStringAndSize( |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
108 ((char*)addr)+1, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
109 *(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
|
110 break; |
|
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
111 #endif /* macintosh */ |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
112 case T_CHAR: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
113 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
|
114 break; |
| 86 | 115 case T_OBJECT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
116 v = *(PyObject **)addr; |
| 86 | 117 if (v == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
118 v = Py_None; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
119 Py_INCREF(v); |
| 86 | 120 break; |
| 121 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
122 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
123 "bad memberlist type"); |
| 86 | 124 v = NULL; |
| 125 } | |
| 126 return v; | |
| 127 } | |
| 128 } | |
| 129 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
130 PyErr_SetString(PyExc_AttributeError, name); |
| 86 | 131 return NULL; |
| 132 } | |
| 133 | |
| 134 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
135 PyMember_Set(char *addr, struct memberlist *mlist, char *name, PyObject *v) |
| 86 | 136 { |
| 137 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
|
138 PyObject *oldv; |
| 86 | 139 |
| 140 for (l = mlist; l->name != NULL; l++) { | |
| 141 if (strcmp(l->name, name) == 0) { | |
|
19942
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
142 if ((l->flags & READONLY) || l->type == T_STRING |
|
2023
3d431a521132
- Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
1848
diff
changeset
|
143 #ifdef macintosh |
|
19942
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
144 || l->type == T_PSTRING |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
145 #endif |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
146 ) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
147 { |
|
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, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
149 "readonly attribute"); |
| 86 | 150 return -1; |
| 151 } | |
|
19942
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
152 if ((l->flags & WRITE_RESTRICTED) && |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
153 PyEval_GetRestricted()) { |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
154 PyErr_SetString(PyExc_RuntimeError, |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
155 "restricted attribute"); |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
156 return -1; |
|
8522b022f80a
Add support for restricting access based on restricted execution mode.
Guido van Rossum <guido@python.org>
parents:
16295
diff
changeset
|
157 } |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
158 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
|
159 PyErr_SetString(PyExc_TypeError, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
160 "can't delete numeric/char attribute"); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
161 return -1; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
162 } |
| 86 | 163 addr += l->offset; |
| 164 switch (l->type) { | |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
165 case T_BYTE: |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
166 case T_UBYTE: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
167 if (!PyInt_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
168 PyErr_BadArgument(); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
169 return -1; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
170 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
171 *(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
|
172 break; |
| 86 | 173 case T_SHORT: |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
174 case T_USHORT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
175 if (!PyInt_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
176 PyErr_BadArgument(); |
| 86 | 177 return -1; |
| 178 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
179 *(short*)addr = (short) PyInt_AsLong(v); |
| 86 | 180 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
181 case T_UINT: |
| 86 | 182 case T_INT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
183 if (!PyInt_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
184 PyErr_BadArgument(); |
| 86 | 185 return -1; |
| 186 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
187 *(int*)addr = (int) PyInt_AsLong(v); |
| 86 | 188 break; |
| 189 case T_LONG: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
190 if (!PyInt_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
191 PyErr_BadArgument(); |
| 86 | 192 return -1; |
| 193 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
194 *(long*)addr = PyInt_AsLong(v); |
| 86 | 195 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
196 case T_ULONG: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
197 if (PyInt_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 = 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 (PyLong_Check(v)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
200 *(long*)addr = PyLong_AsLong(v); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
201 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
202 PyErr_BadArgument(); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
203 return -1; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
204 } |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
205 break; |
| 86 | 206 case T_FLOAT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
207 if (PyInt_Check(v)) |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
208 *(float*)addr = |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
209 (float) PyInt_AsLong(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
210 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
|
211 *(float*)addr = |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
212 (float) 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_DOUBLE: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
219 if (PyInt_Check(v)) |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
220 *(double*)addr = |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
221 (double) PyInt_AsLong(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
222 else if (PyFloat_Check(v)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
223 *(double*)addr = PyFloat_AsDouble(v); |
| 86 | 224 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
225 PyErr_BadArgument(); |
| 86 | 226 return -1; |
| 227 } | |
| 228 break; | |
| 229 case T_OBJECT: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
230 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
|
231 oldv = *(PyObject **)addr; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
232 *(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
|
233 Py_XDECREF(oldv); |
| 86 | 234 break; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
235 case T_CHAR: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
236 if (PyString_Check(v) && |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
237 PyString_Size(v) == 1) { |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
238 *(char*)addr = |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
239 PyString_AsString(v)[0]; |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
240 } |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
241 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
242 PyErr_BadArgument(); |
|
888
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
243 return -1; |
|
dd7dfad404cd
Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
244 } |
|
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
|
245 break; |
| 86 | 246 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
247 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
248 "bad memberlist type"); |
| 86 | 249 return -1; |
| 250 } | |
| 251 return 0; | |
| 252 } | |
| 253 } | |
| 254 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
255 PyErr_SetString(PyExc_AttributeError, name); |
| 95 | 256 return -1; |
| 86 | 257 } |
