Mercurial > cpython-lru_cache-weakref
diff Python/structmember.c @ 44863:eb4b50f739f6 legacy-trunk
Patch #1720595: add T_BOOL to the range of structmember types.
Patch by Angelo Mottola, reviewed by MvL, tests by me.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 21 Jan 2008 21:23:15 +0000 |
| parents | a8dd8874ff2d |
| children | 4fe192d48960 |
line wrap: on
line diff
--- a/Python/structmember.c Mon Jan 21 21:19:07 2008 +0000 +++ b/Python/structmember.c Mon Jan 21 21:23:15 2008 +0000 @@ -61,6 +61,9 @@ } addr += l->offset; switch (l->type) { + case T_BOOL: + v = PyBool_FromLong(*(char*)addr); + break; case T_BYTE: v = PyInt_FromLong(*(char*)addr); break; @@ -183,6 +186,18 @@ } addr += l->offset; switch (l->type) { + case T_BOOL:{ + if (!PyBool_Check(v)) { + PyErr_SetString(PyExc_TypeError, + "attribute value type must be bool"); + return -1; + } + if (v == Py_True) + *(char*)addr = (char) 1; + else + *(char*)addr = (char) 0; + break; + } case T_BYTE:{ long long_val = PyInt_AsLong(v); if ((long_val == -1) && PyErr_Occurred())
