Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 2 | /* Map C struct members to Python object attributes */ |
| 3 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 4 | #include "Python.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 5 | |
| 6 | #include "structmember.h" |
| 7 | |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 8 | PyObject * |
Tim Peters | c3d12ac | 2005-12-24 06:03:06 +0000 | [diff] [blame] | 9 | PyMember_GetOne(const char *addr, PyMemberDef *l) |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 10 | { |
| 11 | PyObject *v; |
Guido van Rossum | a8add0e | 2007-05-14 22:03:55 +0000 | [diff] [blame] | 12 | |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 13 | addr += l->offset; |
| 14 | switch (l->type) { |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 15 | case T_BOOL: |
| 16 | v = PyBool_FromLong(*(char*)addr); |
| 17 | break; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 18 | case T_BYTE: |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 19 | v = PyLong_FromLong(*(char*)addr); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 20 | break; |
| 21 | case T_UBYTE: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 22 | v = PyLong_FromUnsignedLong(*(unsigned char*)addr); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 23 | break; |
| 24 | case T_SHORT: |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 25 | v = PyLong_FromLong(*(short*)addr); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 26 | break; |
| 27 | case T_USHORT: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 28 | v = PyLong_FromUnsignedLong(*(unsigned short*)addr); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 29 | break; |
| 30 | case T_INT: |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 31 | v = PyLong_FromLong(*(int*)addr); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 32 | break; |
| 33 | case T_UINT: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 34 | v = PyLong_FromUnsignedLong(*(unsigned int*)addr); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 35 | break; |
| 36 | case T_LONG: |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 37 | v = PyLong_FromLong(*(long*)addr); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 38 | break; |
| 39 | case T_ULONG: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 40 | v = PyLong_FromUnsignedLong(*(unsigned long*)addr); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 41 | break; |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 42 | case T_PYSSIZET: |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 43 | v = PyLong_FromSsize_t(*(Py_ssize_t*)addr); |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 44 | break; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 45 | case T_FLOAT: |
| 46 | v = PyFloat_FromDouble((double)*(float*)addr); |
| 47 | break; |
| 48 | case T_DOUBLE: |
| 49 | v = PyFloat_FromDouble(*(double*)addr); |
| 50 | break; |
| 51 | case T_STRING: |
| 52 | if (*(char**)addr == NULL) { |
| 53 | Py_INCREF(Py_None); |
| 54 | v = Py_None; |
| 55 | } |
| 56 | else |
Guido van Rossum | 21431e8 | 2007-10-19 21:48:41 +0000 | [diff] [blame] | 57 | v = PyUnicode_FromString(*(char**)addr); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 58 | break; |
| 59 | case T_STRING_INPLACE: |
Guido van Rossum | 21431e8 | 2007-10-19 21:48:41 +0000 | [diff] [blame] | 60 | v = PyUnicode_FromString((char*)addr); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 61 | break; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 62 | case T_CHAR: |
Guido van Rossum | 21431e8 | 2007-10-19 21:48:41 +0000 | [diff] [blame] | 63 | v = PyUnicode_FromStringAndSize((char*)addr, 1); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 64 | break; |
| 65 | case T_OBJECT: |
| 66 | v = *(PyObject **)addr; |
| 67 | if (v == NULL) |
| 68 | v = Py_None; |
| 69 | Py_INCREF(v); |
| 70 | break; |
Guido van Rossum | 6b70599 | 2001-12-04 16:23:42 +0000 | [diff] [blame] | 71 | case T_OBJECT_EX: |
| 72 | v = *(PyObject **)addr; |
| 73 | if (v == NULL) |
| 74 | PyErr_SetString(PyExc_AttributeError, l->name); |
| 75 | Py_XINCREF(v); |
| 76 | break; |
Martin v. Löwis | 96d743e | 2005-03-03 23:00:26 +0000 | [diff] [blame] | 77 | #ifdef HAVE_LONG_LONG |
| 78 | case T_LONGLONG: |
| 79 | v = PyLong_FromLongLong(*(PY_LONG_LONG *)addr); |
| 80 | break; |
| 81 | case T_ULONGLONG: |
| 82 | v = PyLong_FromUnsignedLongLong(*(unsigned PY_LONG_LONG *)addr); |
| 83 | break; |
| 84 | #endif /* HAVE_LONG_LONG */ |
Guido van Rossum | 50e9fb9 | 2006-08-17 05:42:55 +0000 | [diff] [blame] | 85 | case T_NONE: |
| 86 | v = Py_None; |
| 87 | Py_INCREF(v); |
| 88 | break; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 89 | default: |
| 90 | PyErr_SetString(PyExc_SystemError, "bad memberdescr type"); |
| 91 | v = NULL; |
| 92 | } |
| 93 | return v; |
| 94 | } |
| 95 | |
Skip Montanaro | 46fc337 | 2007-08-12 11:44:53 +0000 | [diff] [blame] | 96 | #define WARN(msg) \ |
| 97 | do { \ |
| 98 | if (PyErr_WarnEx(PyExc_RuntimeWarning, msg, 1) < 0) \ |
| 99 | return -1; \ |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 100 | } while (0) |
| 101 | |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 102 | int |
| 103 | PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) |
| 104 | { |
| 105 | PyObject *oldv; |
| 106 | |
Jack Jansen | eddc144 | 2003-11-20 01:44:59 +0000 | [diff] [blame] | 107 | if ((l->flags & READONLY) || l->type == T_STRING) |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 108 | { |
Collin Winter | 42dae6a | 2007-03-28 21:44:53 +0000 | [diff] [blame] | 109 | PyErr_SetString(PyExc_AttributeError, "readonly attribute"); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 110 | return -1; |
| 111 | } |
Guido van Rossum | 6b70599 | 2001-12-04 16:23:42 +0000 | [diff] [blame] | 112 | if (v == NULL && l->type != T_OBJECT_EX && l->type != T_OBJECT) { |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 113 | PyErr_SetString(PyExc_TypeError, |
| 114 | "can't delete numeric/char attribute"); |
| 115 | return -1; |
| 116 | } |
| 117 | addr += l->offset; |
| 118 | switch (l->type) { |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 119 | case T_BOOL:{ |
| 120 | if (!PyBool_Check(v)) { |
| 121 | PyErr_SetString(PyExc_TypeError, |
| 122 | "attribute value type must be bool"); |
| 123 | return -1; |
| 124 | } |
| 125 | if (v == Py_True) |
| 126 | *(char*)addr = (char) 1; |
| 127 | else |
| 128 | *(char*)addr = (char) 0; |
| 129 | break; |
| 130 | } |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 131 | case T_BYTE:{ |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 132 | long long_val = PyLong_AsLong(v); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 133 | if ((long_val == -1) && PyErr_Occurred()) |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 134 | return -1; |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 135 | *(char*)addr = (char)long_val; |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 136 | /* XXX: For compatibility, only warn about truncations |
| 137 | for now. */ |
| 138 | if ((long_val > CHAR_MAX) || (long_val < CHAR_MIN)) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 139 | WARN("Truncation of value to char"); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 140 | break; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 141 | } |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 142 | case T_UBYTE:{ |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 143 | long long_val = PyLong_AsLong(v); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 144 | if ((long_val == -1) && PyErr_Occurred()) |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 145 | return -1; |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 146 | *(unsigned char*)addr = (unsigned char)long_val; |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 147 | if ((long_val > UCHAR_MAX) || (long_val < 0)) |
| 148 | WARN("Truncation of value to unsigned char"); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 149 | break; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 150 | } |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 151 | case T_SHORT:{ |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 152 | long long_val = PyLong_AsLong(v); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 153 | if ((long_val == -1) && PyErr_Occurred()) |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 154 | return -1; |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 155 | *(short*)addr = (short)long_val; |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 156 | if ((long_val > SHRT_MAX) || (long_val < SHRT_MIN)) |
| 157 | WARN("Truncation of value to short"); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 158 | break; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 159 | } |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 160 | case T_USHORT:{ |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 161 | long long_val = PyLong_AsLong(v); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 162 | if ((long_val == -1) && PyErr_Occurred()) |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 163 | return -1; |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 164 | *(unsigned short*)addr = (unsigned short)long_val; |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 165 | if ((long_val > USHRT_MAX) || (long_val < 0)) |
| 166 | WARN("Truncation of value to unsigned short"); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 167 | break; |
| 168 | } |
| 169 | case T_INT:{ |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 170 | long long_val = PyLong_AsLong(v); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 171 | if ((long_val == -1) && PyErr_Occurred()) |
| 172 | return -1; |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 173 | *(int *)addr = (int)long_val; |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 174 | if ((long_val > INT_MAX) || (long_val < INT_MIN)) |
| 175 | WARN("Truncation of value to int"); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 176 | break; |
| 177 | } |
| 178 | case T_UINT:{ |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 179 | unsigned long ulong_val = PyLong_AsUnsignedLong(v); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 180 | if ((ulong_val == (unsigned int)-1) && PyErr_Occurred()) { |
| 181 | /* XXX: For compatibility, accept negative int values |
| 182 | as well. */ |
| 183 | PyErr_Clear(); |
| 184 | ulong_val = PyLong_AsLong(v); |
| 185 | if ((ulong_val == (unsigned int)-1) && PyErr_Occurred()) |
| 186 | return -1; |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 187 | *(unsigned int *)addr = (unsigned int)ulong_val; |
| 188 | WARN("Writing negative value into unsigned field"); |
| 189 | } else |
| 190 | *(unsigned int *)addr = (unsigned int)ulong_val; |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 191 | if (ulong_val > UINT_MAX) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 192 | WARN("Truncation of value to unsigned int"); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 193 | break; |
| 194 | } |
| 195 | case T_LONG:{ |
| 196 | *(long*)addr = PyLong_AsLong(v); |
| 197 | if ((*(long*)addr == -1) && PyErr_Occurred()) |
| 198 | return -1; |
| 199 | break; |
| 200 | } |
| 201 | case T_ULONG:{ |
| 202 | *(unsigned long*)addr = PyLong_AsUnsignedLong(v); |
| 203 | if ((*(unsigned long*)addr == (unsigned long)-1) |
| 204 | && PyErr_Occurred()) { |
| 205 | /* XXX: For compatibility, accept negative int values |
| 206 | as well. */ |
| 207 | PyErr_Clear(); |
| 208 | *(unsigned long*)addr = PyLong_AsLong(v); |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 209 | if ((*(unsigned long*)addr == (unsigned int)-1) |
| 210 | && PyErr_Occurred()) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 211 | return -1; |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 212 | WARN("Writing negative value into unsigned field"); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 213 | } |
| 214 | break; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 215 | } |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 216 | case T_PYSSIZET:{ |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 217 | *(Py_ssize_t*)addr = PyLong_AsSsize_t(v); |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 218 | if ((*(Py_ssize_t*)addr == (Py_ssize_t)-1) |
| 219 | && PyErr_Occurred()) |
| 220 | return -1; |
| 221 | break; |
| 222 | } |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 223 | case T_FLOAT:{ |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 224 | double double_val = PyFloat_AsDouble(v); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 225 | if ((double_val == -1) && PyErr_Occurred()) |
| 226 | return -1; |
| 227 | *(float*)addr = (float)double_val; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 228 | break; |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 229 | } |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 230 | case T_DOUBLE: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 231 | *(double*)addr = PyFloat_AsDouble(v); |
| 232 | if ((*(double*)addr == -1) && PyErr_Occurred()) |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 233 | return -1; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 234 | break; |
| 235 | case T_OBJECT: |
Guido van Rossum | 6b70599 | 2001-12-04 16:23:42 +0000 | [diff] [blame] | 236 | case T_OBJECT_EX: |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 237 | Py_XINCREF(v); |
| 238 | oldv = *(PyObject **)addr; |
| 239 | *(PyObject **)addr = v; |
| 240 | Py_XDECREF(oldv); |
| 241 | break; |
Alexandre Vassalotti | a85998a | 2008-05-03 18:24:43 +0000 | [diff] [blame] | 242 | case T_CHAR: { |
| 243 | char *string; |
| 244 | Py_ssize_t len; |
| 245 | |
| 246 | if (!PyUnicode_Check(v)) { |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 247 | PyErr_BadArgument(); |
| 248 | return -1; |
| 249 | } |
Alexandre Vassalotti | a85998a | 2008-05-03 18:24:43 +0000 | [diff] [blame] | 250 | string = PyUnicode_AsStringAndSize(v, &len); |
| 251 | if (len != 1) { |
| 252 | PyErr_BadArgument(); |
| 253 | return -1; |
| 254 | } |
| 255 | *(char*)addr = string[0]; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 256 | break; |
Alexandre Vassalotti | a85998a | 2008-05-03 18:24:43 +0000 | [diff] [blame] | 257 | } |
Martin v. Löwis | 96d743e | 2005-03-03 23:00:26 +0000 | [diff] [blame] | 258 | #ifdef HAVE_LONG_LONG |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 259 | case T_LONGLONG:{ |
| 260 | PY_LONG_LONG value; |
| 261 | *(PY_LONG_LONG*)addr = value = PyLong_AsLongLong(v); |
| 262 | if ((value == -1) && PyErr_Occurred()) |
Martin v. Löwis | 96d743e | 2005-03-03 23:00:26 +0000 | [diff] [blame] | 263 | return -1; |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 264 | break; |
| 265 | } |
| 266 | case T_ULONGLONG:{ |
| 267 | unsigned PY_LONG_LONG value; |
| 268 | /* ??? PyLong_AsLongLong accepts an int, but PyLong_AsUnsignedLongLong |
| 269 | doesn't ??? */ |
| 270 | if (PyLong_Check(v)) |
| 271 | *(unsigned PY_LONG_LONG*)addr = value = PyLong_AsUnsignedLongLong(v); |
| 272 | else |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 273 | *(unsigned PY_LONG_LONG*)addr = value = PyLong_AsLong(v); |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 274 | if ((value == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred()) |
| 275 | return -1; |
| 276 | break; |
| 277 | } |
Martin v. Löwis | 96d743e | 2005-03-03 23:00:26 +0000 | [diff] [blame] | 278 | #endif /* HAVE_LONG_LONG */ |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 279 | default: |
Jeremy Hylton | 26633f4 | 2001-10-16 16:51:56 +0000 | [diff] [blame] | 280 | PyErr_Format(PyExc_SystemError, |
| 281 | "bad memberdescr type for %s", l->name); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 282 | return -1; |
| 283 | } |
| 284 | return 0; |
| 285 | } |