annotate Python/structmember.c @ 5938:222faeb43d02 legacy-trunk

New rules for deleting modules. Rather than having an elaborate scheme based on object's types, have a simple two-phase scheme based on object's *names*: /* To make the execution order of destructors for global objects a bit more predictable, we first zap all objects whose name starts with a single underscore, before we clear the entire dictionary. We zap them by replacing them with None, rather than deleting them from the dictionary, to avoid rehashing the dictionary (to some extent). */
author Guido van Rossum <guido@python.org>
date Tue, 05 Aug 1997 02:20:51 +0000
parents 5880384d7c71
children ff31f2501742
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 /***********************************************************
2062
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2023
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2023
diff changeset
3 The Netherlands.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
4
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
5 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
8 documentation for any purpose and without fee is hereby granted,
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
9 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
10 both that copyright notice and this permission notice appear in
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
15 permission.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
17 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
18 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
29
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
30 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
31
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* Map C struct members to Python object attributes */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
34 #include "Python.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 #include "structmember.h"
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
38 static PyObject *
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
39 listmembers(mlist)
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
40 struct memberlist *mlist;
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
41 {
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
42 int i, n;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
43 PyObject *v;
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
44 for (n = 0; mlist[n].name != NULL; n++)
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
45 ;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
46 v = PyList_New(n);
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
47 if (v != NULL) {
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
48 for (i = 0; i < n; i++)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
49 PyList_SetItem(v, i,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
50 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
51 if (PyErr_Occurred()) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
52 Py_DECREF(v);
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
53 v = NULL;
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
54 }
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
55 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
56 PyList_Sort(v);
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
57 }
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
58 }
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
59 return v;
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
60 }
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
61
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
62 PyObject *
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
63 PyMember_Get(addr, mlist, name)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 char *addr;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 struct memberlist *mlist;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 char *name;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 struct memberlist *l;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
398
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
70 if (strcmp(name, "__members__") == 0)
0ac1357cd898 Added __members__ secret attribute
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
71 return listmembers(mlist);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 for (l = mlist; l->name != NULL; l++) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 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
74 PyObject *v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 addr += l->offset;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 switch (l->type) {
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
77 case T_BYTE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
78 v = PyInt_FromLong((long)
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
79 (((*(char*)addr & 0xff)
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
80 ^ 0x80) - 0x80));
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
81 break;
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
82 case T_UBYTE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
83 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
84 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 case T_SHORT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
86 v = PyInt_FromLong((long) *(short*)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
88 case T_USHORT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
89 v = PyInt_FromLong((long)
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
90 *(unsigned short*)addr);
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
91 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 case T_INT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
93 v = PyInt_FromLong((long) *(int*)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
95 case T_UINT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
96 v = PyInt_FromLong((long)
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
97 *(unsigned int*)addr);
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
98 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 case T_LONG:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
100 v = PyInt_FromLong(*(long*)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
102 case T_ULONG:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
103 v = PyLong_FromDouble((double)
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
104 *(unsigned long*)addr);
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
105 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 case T_FLOAT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
107 v = PyFloat_FromDouble((double)*(float*)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 case T_DOUBLE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
110 v = PyFloat_FromDouble(*(double*)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 case T_STRING:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 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
114 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
115 v = Py_None;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 else
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
118 v = PyString_FromString(*(char**)addr);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 break;
2023
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
120 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
121 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
122 break;
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
123 #ifdef macintosh
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
124 case T_PSTRING:
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
125 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
126 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
127 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
128 }
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
129 else
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
130 v = PyString_FromStringAndSize(
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
131 (*(char**)addr)+1,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
132 **(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
133 break;
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
134 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
135 v = PyString_FromStringAndSize(
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
136 ((char*)addr)+1,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
137 *(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
138 break;
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
139 #endif /* macintosh */
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
140 case T_CHAR:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
141 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
142 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 case T_OBJECT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
144 v = *(PyObject **)addr;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 if (v == NULL)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
146 v = Py_None;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
147 Py_INCREF(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
150 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
151 "bad memberlist type");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 v = NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 return v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
157
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
158 PyErr_SetString(PyExc_AttributeError, name);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
161
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 int
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
163 PyMember_Set(addr, mlist, name, v)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 char *addr;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 struct memberlist *mlist;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 char *name;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
167 PyObject *v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 struct memberlist *l;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
170
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 for (l = mlist; l->name != NULL; l++) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 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
173 #ifdef macintosh
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
174 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
175 l->type == T_PSTRING)
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
176 {
2023
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
177 #else
3d431a521132 - Added ability to get at strings embedded in the struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 1848
diff changeset
178 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
179 #endif /* macintosh */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
180 PyErr_SetString(PyExc_TypeError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
181 "readonly attribute");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 }
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
184 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
185 PyErr_SetString(PyExc_TypeError,
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
186 "can't delete numeric/char attribute");
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
187 return -1;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
188 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 addr += l->offset;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 switch (l->type) {
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
191 case T_BYTE:
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
192 case T_UBYTE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
193 if (!PyInt_Check(v)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
194 PyErr_BadArgument();
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
195 return -1;
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
196 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
197 *(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
198 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 case T_SHORT:
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
200 case T_USHORT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
201 if (!PyInt_Check(v)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
202 PyErr_BadArgument();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
205 *(short*)addr = (short) PyInt_AsLong(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
207 case T_UINT:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 case T_INT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
209 if (!PyInt_Check(v)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
210 PyErr_BadArgument();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
213 *(int*)addr = (int) PyInt_AsLong(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 case T_LONG:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
216 if (!PyInt_Check(v)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
217 PyErr_BadArgument();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
220 *(long*)addr = PyInt_AsLong(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
222 case T_ULONG:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
223 if (PyInt_Check(v))
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
224 *(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
225 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
226 *(long*)addr = PyLong_AsLong(v);
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
227 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
228 PyErr_BadArgument();
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
229 return -1;
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
230 }
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
231 break;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 case T_FLOAT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
233 if (PyInt_Check(v))
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
234 *(float*)addr =
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
235 (float) PyInt_AsLong(v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
236 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
237 *(float*)addr =
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
238 (float) PyFloat_AsDouble(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
240 PyErr_BadArgument();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 return -1;
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 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 case T_DOUBLE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
245 if (PyInt_Check(v))
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
246 *(double*)addr =
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
247 (double) PyInt_AsLong(v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
248 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
249 *(double*)addr = PyFloat_AsDouble(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
251 PyErr_BadArgument();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 case T_OBJECT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
256 Py_XDECREF(*(PyObject **)addr);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
257 Py_XINCREF(v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
258 *(PyObject **)addr = v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 break;
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
260 case T_CHAR:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
261 if (PyString_Check(v) &&
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
262 PyString_Size(v) == 1) {
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
263 *(char*)addr =
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
264 PyString_AsString(v)[0];
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
265 }
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
266 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
267 PyErr_BadArgument();
888
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
268 return -1;
dd7dfad404cd Added new types to setattr() as well...
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
269 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
271 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
272 "bad memberlist type");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 return 0;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
278
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
279 PyErr_SetString(PyExc_AttributeError, name);
95
a5bf7d5959ce Return -1 for errors.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
280 return -1;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 }