annotate Python/structmember.c @ 54129:77cfef596d33

Merged revisions 72698-72699 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r72698 | hirokazu.yamamoto | 2009-05-17 11:52:09 +0900 | 1 line Issue #3527: Removed Py_WIN_WIDE_FILENAMES which is not used any more. ........ r72699 | hirokazu.yamamoto | 2009-05-17 11:58:36 +0900 | 1 line Added NEWS for r72698. ........
author Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
date Sun, 17 May 2009 04:21:53 +0000
parents 85b67fb5672b
children 46f4b7b5b4dd
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
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
8 PyObject *
36114
e9a10f74cf88 const poisoning, spreading to fix new const warnings
Tim Peters <tim.peters@gmail.com>
parents: 34677
diff changeset
9 PyMember_GetOne(const char *addr, PyMemberDef *l)
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
10 {
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
11 PyObject *v;
41715
f60c877d52c8 Merged revisions 55270-55324 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41317
diff changeset
12
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
13 addr += l->offset;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
14 switch (l->type) {
44885
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
15 case T_BOOL:
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
16 v = PyBool_FromLong(*(char*)addr);
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
17 break;
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
18 case T_BYTE:
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
19 v = PyLong_FromLong(*(char*)addr);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
20 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
21 case T_UBYTE:
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
22 v = PyLong_FromUnsignedLong(*(unsigned char*)addr);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
23 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
24 case T_SHORT:
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
25 v = PyLong_FromLong(*(short*)addr);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
26 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
27 case T_USHORT:
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
28 v = PyLong_FromUnsignedLong(*(unsigned short*)addr);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
29 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
30 case T_INT:
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
31 v = PyLong_FromLong(*(int*)addr);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
32 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
33 case T_UINT:
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
34 v = PyLong_FromUnsignedLong(*(unsigned int*)addr);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
35 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
36 case T_LONG:
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
37 v = PyLong_FromLong(*(long*)addr);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
38 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
39 case T_ULONG:
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
40 v = PyLong_FromUnsignedLong(*(unsigned long*)addr);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
41 break;
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
42 case T_PYSSIZET:
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
43 v = PyLong_FromSsize_t(*(Py_ssize_t*)addr);
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
44 break;
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
45 case T_FLOAT:
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
46 v = PyFloat_FromDouble((double)*(float*)addr);
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
47 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
48 case T_DOUBLE:
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
49 v = PyFloat_FromDouble(*(double*)addr);
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
50 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
51 case T_STRING:
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
52 if (*(char**)addr == NULL) {
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
53 Py_INCREF(Py_None);
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
54 v = Py_None;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
55 }
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
56 else
43603
dd03aa741f56 This is the uncontroversial half of patch 1263 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents: 42560
diff changeset
57 v = PyUnicode_FromString(*(char**)addr);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
58 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
59 case T_STRING_INPLACE:
43603
dd03aa741f56 This is the uncontroversial half of patch 1263 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents: 42560
diff changeset
60 v = PyUnicode_FromString((char*)addr);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
61 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
62 case T_CHAR:
43603
dd03aa741f56 This is the uncontroversial half of patch 1263 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents: 42560
diff changeset
63 v = PyUnicode_FromStringAndSize((char*)addr, 1);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
64 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
65 case T_OBJECT:
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
66 v = *(PyObject **)addr;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
67 if (v == NULL)
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
68 v = Py_None;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
69 Py_INCREF(v);
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
70 break;
21187
ef6f692c76e2 Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents: 20456
diff changeset
71 case T_OBJECT_EX:
ef6f692c76e2 Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents: 20456
diff changeset
72 v = *(PyObject **)addr;
ef6f692c76e2 Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents: 20456
diff changeset
73 if (v == NULL)
ef6f692c76e2 Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents: 20456
diff changeset
74 PyErr_SetString(PyExc_AttributeError, l->name);
ef6f692c76e2 Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents: 20456
diff changeset
75 Py_XINCREF(v);
ef6f692c76e2 Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents: 20456
diff changeset
76 break;
34677
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
77 #ifdef HAVE_LONG_LONG
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
78 case T_LONGLONG:
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
79 v = PyLong_FromLongLong(*(PY_LONG_LONG *)addr);
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
80 break;
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
81 case T_ULONGLONG:
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
82 v = PyLong_FromUnsignedLongLong(*(unsigned PY_LONG_LONG *)addr);
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
83 break;
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
84 #endif /* HAVE_LONG_LONG */
39536
8f5b9982beba Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
85 case T_NONE:
8f5b9982beba Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
86 v = Py_None;
8f5b9982beba Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
87 Py_INCREF(v);
8f5b9982beba Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
88 break;
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
89 default:
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
90 PyErr_SetString(PyExc_SystemError, "bad memberdescr type");
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
91 v = NULL;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
92 }
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
93 return v;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
94 }
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
95
42560
0fcc18aba385 PyErr_Warn is deprecated in 2.5 - goes away for 3.0
Skip Montanaro <skip@pobox.com>
parents: 42537
diff changeset
96 #define WARN(msg) \
0fcc18aba385 PyErr_Warn is deprecated in 2.5 - goes away for 3.0
Skip Montanaro <skip@pobox.com>
parents: 42537
diff changeset
97 do { \
0fcc18aba385 PyErr_Warn is deprecated in 2.5 - goes away for 3.0
Skip Montanaro <skip@pobox.com>
parents: 42537
diff changeset
98 if (PyErr_WarnEx(PyExc_RuntimeWarning, msg, 1) < 0) \
0fcc18aba385 PyErr_Warn is deprecated in 2.5 - goes away for 3.0
Skip Montanaro <skip@pobox.com>
parents: 42537
diff changeset
99 return -1; \
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
100 } while (0)
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
101
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
102 int
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
103 PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
104 {
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
105 PyObject *oldv;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
106
30979
86fdf8fe7f17 Getting rid of all the code inside #ifdef macintosh too.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21187
diff changeset
107 if ((l->flags & READONLY) || l->type == T_STRING)
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
108 {
41317
b897b77a004f Make readonly members defined in C throw an AttributeError on modification. This brings them into sync with Python-level attributes. Fixes bug #1687163.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
109 PyErr_SetString(PyExc_AttributeError, "readonly attribute");
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
110 return -1;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
111 }
21187
ef6f692c76e2 Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents: 20456
diff changeset
112 if (v == NULL && l->type != T_OBJECT_EX && l->type != T_OBJECT) {
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
113 PyErr_SetString(PyExc_TypeError,
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
114 "can't delete numeric/char attribute");
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
115 return -1;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
116 }
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
117 addr += l->offset;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
118 switch (l->type) {
44885
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
119 case T_BOOL:{
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
120 if (!PyBool_Check(v)) {
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
121 PyErr_SetString(PyExc_TypeError,
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
122 "attribute value type must be bool");
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
123 return -1;
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
124 }
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
125 if (v == Py_True)
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
126 *(char*)addr = (char) 1;
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
127 else
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
128 *(char*)addr = (char) 0;
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
129 break;
fefaa0e66fdd Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
130 }
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
131 case T_BYTE:{
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
132 long long_val = PyLong_AsLong(v);
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
133 if ((long_val == -1) && PyErr_Occurred())
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
134 return -1;
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
135 *(char*)addr = (char)long_val;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
136 /* XXX: For compatibility, only warn about truncations
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
137 for now. */
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
138 if ((long_val > CHAR_MAX) || (long_val < CHAR_MIN))
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
139 WARN("Truncation of value to char");
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
140 break;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
141 }
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
142 case T_UBYTE:{
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
143 long long_val = PyLong_AsLong(v);
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
144 if ((long_val == -1) && PyErr_Occurred())
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
145 return -1;
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
146 *(unsigned char*)addr = (unsigned char)long_val;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
147 if ((long_val > UCHAR_MAX) || (long_val < 0))
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
148 WARN("Truncation of value to unsigned char");
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
149 break;
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
150 }
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
151 case T_SHORT:{
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
152 long long_val = PyLong_AsLong(v);
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
153 if ((long_val == -1) && PyErr_Occurred())
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
154 return -1;
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
155 *(short*)addr = (short)long_val;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
156 if ((long_val > SHRT_MAX) || (long_val < SHRT_MIN))
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
157 WARN("Truncation of value to short");
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
158 break;
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
159 }
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
160 case T_USHORT:{
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
161 long long_val = PyLong_AsLong(v);
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
162 if ((long_val == -1) && PyErr_Occurred())
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
163 return -1;
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
164 *(unsigned short*)addr = (unsigned short)long_val;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
165 if ((long_val > USHRT_MAX) || (long_val < 0))
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
166 WARN("Truncation of value to unsigned short");
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
167 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
168 }
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
169 case T_INT:{
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
170 long long_val = PyLong_AsLong(v);
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
171 if ((long_val == -1) && PyErr_Occurred())
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
172 return -1;
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
173 *(int *)addr = (int)long_val;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
174 if ((long_val > INT_MAX) || (long_val < INT_MIN))
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
175 WARN("Truncation of value to int");
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
176 break;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
177 }
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
178 case T_UINT:{
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
179 unsigned long ulong_val = PyLong_AsUnsignedLong(v);
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
180 if ((ulong_val == (unsigned int)-1) && PyErr_Occurred()) {
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
181 /* XXX: For compatibility, accept negative int values
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
182 as well. */
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
183 PyErr_Clear();
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
184 ulong_val = PyLong_AsLong(v);
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
185 if ((ulong_val == (unsigned int)-1) && PyErr_Occurred())
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
186 return -1;
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
187 *(unsigned int *)addr = (unsigned int)ulong_val;
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
188 WARN("Writing negative value into unsigned field");
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
189 } else
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
190 *(unsigned int *)addr = (unsigned int)ulong_val;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
191 if (ulong_val > UINT_MAX)
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
192 WARN("Truncation of value to unsigned int");
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
193 break;
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
194 }
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
195 case T_LONG:{
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
196 *(long*)addr = PyLong_AsLong(v);
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
197 if ((*(long*)addr == -1) && PyErr_Occurred())
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
198 return -1;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
199 break;
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
200 }
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
201 case T_ULONG:{
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
202 *(unsigned long*)addr = PyLong_AsUnsignedLong(v);
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
203 if ((*(unsigned long*)addr == (unsigned long)-1)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
204 && PyErr_Occurred()) {
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
205 /* XXX: For compatibility, accept negative int values
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
206 as well. */
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
207 PyErr_Clear();
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
208 *(unsigned long*)addr = PyLong_AsLong(v);
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
209 if ((*(unsigned long*)addr == (unsigned int)-1)
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
210 && PyErr_Occurred())
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
211 return -1;
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
212 WARN("Writing negative value into unsigned field");
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
213 }
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
214 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
215 }
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
216 case T_PYSSIZET:{
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
217 *(Py_ssize_t*)addr = PyLong_AsSsize_t(v);
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
218 if ((*(Py_ssize_t*)addr == (Py_ssize_t)-1)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
219 && PyErr_Occurred())
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
220 return -1;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
221 break;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
222 }
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
223 case T_FLOAT:{
42466
3fc3cedc49ca Merged revisions 56753-56781 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42110
diff changeset
224 double double_val = PyFloat_AsDouble(v);
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
225 if ((double_val == -1) && PyErr_Occurred())
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
226 return -1;
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
227 *(float*)addr = (float)double_val;
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
228 break;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
229 }
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
230 case T_DOUBLE:
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
231 *(double*)addr = PyFloat_AsDouble(v);
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
232 if ((*(double*)addr == -1) && PyErr_Occurred())
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
233 return -1;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
234 break;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
235 case T_OBJECT:
21187
ef6f692c76e2 Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents: 20456
diff changeset
236 case T_OBJECT_EX:
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
237 Py_XINCREF(v);
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
238 oldv = *(PyObject **)addr;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
239 *(PyObject **)addr = v;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
240 Py_XDECREF(oldv);
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
241 break;
46644
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
242 case T_CHAR: {
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
243 char *string;
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
244 Py_ssize_t len;
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
245
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
246 if (!PyUnicode_Check(v)) {
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
247 PyErr_BadArgument();
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
248 return -1;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
249 }
48660
85b67fb5672b Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents: 46644
diff changeset
250 string = _PyUnicode_AsStringAndSize(v, &len);
46644
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
251 if (len != 1) {
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
252 PyErr_BadArgument();
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
253 return -1;
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
254 }
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
255 *(char*)addr = string[0];
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
256 break;
46644
ea594306ea85 Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 44885
diff changeset
257 }
34677
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
258 #ifdef HAVE_LONG_LONG
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
259 case T_LONGLONG:{
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
260 PY_LONG_LONG value;
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
261 *(PY_LONG_LONG*)addr = value = PyLong_AsLongLong(v);
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
262 if ((value == -1) && PyErr_Occurred())
34677
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
263 return -1;
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
264 break;
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
265 }
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
266 case T_ULONGLONG:{
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
267 unsigned PY_LONG_LONG value;
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
268 /* ??? PyLong_AsLongLong accepts an int, but PyLong_AsUnsignedLongLong
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
269 doesn't ??? */
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
270 if (PyLong_Check(v))
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
271 *(unsigned PY_LONG_LONG*)addr = value = PyLong_AsUnsignedLongLong(v);
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
272 else
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43603
diff changeset
273 *(unsigned PY_LONG_LONG*)addr = value = PyLong_AsLong(v);
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
274 if ((value == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
275 return -1;
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
276 break;
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41715
diff changeset
277 }
34677
e9ffad6d8822 Patch #1115086: support PY_LONGLONG in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 30979
diff changeset
278 #endif /* HAVE_LONG_LONG */
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
279 default:
20456
bff6c2d76f33 Put descr name in "bad memberdescr type" error message.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20012
diff changeset
280 PyErr_Format(PyExc_SystemError,
bff6c2d76f33 Put descr name in "bad memberdescr type" error message.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20012
diff changeset
281 "bad memberdescr type for %s", l->name);
20012
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
282 return -1;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
283 }
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
284 return 0;
3faabf54b8b8 Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents: 19942
diff changeset
285 }