annotate Python/structmember.c @ 19600:1cece743a708 legacy-trunk

Removed some unreachable break statements to silence SGI compiler.
author Sjoerd Mullender <sjoerd@acm.org>
date Thu, 30 Aug 2001 14:05:20 +0000
parents 7b3476c1382e
children 8522b022f80a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
1
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Map C struct members to Python object attributes */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 #include "structmember.h"
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 struct memberlist *l;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 for (l = mlist; l->name != NULL; l++) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 addr += l->offset;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 case T_STRING:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 v = NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 return v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
127
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
133
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 for (l = mlist; l->name != NULL; l++) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 addr += l->offset;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 return 0;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a5bf7d5959ce Return -1 for errors.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
245 return -1;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 }