[issue9041] raised exception is misleading
Pauli Rikula added the comment: Could we overcome these issues by some kind of exception inheritance? On Tue, Aug 30, 2011 at 5:28 PM, Meador Inge wrote: > > Meador Inge added the comment: > > That is a good question. While it is true that errors other than > 'PyExc_OverflowError', will be mapped onto a 'TypeError' I don't think that > is a bad thing. Any errors that come out of 'PyFloat_AsDouble' should be > handled on a case-by-case basis and not blindly passed back out the call > chain. Otherwise, we may end up passing back errors (which are who knows > what) that make sense for a caller of 'PyFloat_AsDouble', but not for callers > of 'g_set'. > > Also, the interface would become variable, meaning that whenever > 'PyFloat_AsDouble' introduces new exceptions, then this code would too, which > would lead to a somewhat unpredictable interface for callers of 'g_set'. > > -- > > ___ > Python tracker > <http://bugs.python.org/issue9041> > ___ -- ___ Python tracker <http://bugs.python.org/issue9041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9030] ctypes variable limits
Pauli Rikula added the comment: This enchantment overlaps with sys -module's sys.float_info (new in 2.6) and sys.long_info (new in 2.7). -- ___ Python tracker <http://bugs.python.org/issue9030> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9030] ctypes variable limits
Changes by Pauli Rikula : -- assignee: theller components: ctypes nosy: kumma, theller priority: normal severity: normal status: open title: ctypes variable limits ___ Python tracker <http://bugs.python.org/issue9030> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9030] ctypes variable limits
New submission from Pauli Rikula : ctypes should have nice interface from which one could get maximum and minimum values etc information about numeric's data types. for integers this is quite trivial, but at least long double is a bit trickier one. -- type: -> feature request ___ Python tracker <http://bugs.python.org/issue9030> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9041] raised exception is misleading
New submission from Pauli Rikula : Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes >>> ctypes.c_double(-10L) c_double(-10.0) >>> ctypes.c_double(-1615850303565550365035743834433497598022205133485774201606517271376232756943394544659860070576145673184435898046094900974705977957524546054754407619322414156031543868365049804587509887519482605339802881919203378413839610932130987808091904716923808523529082292601815252144378794577053290430377619956196519276104705135157728700572895265282173598410898686661027635767561787024437943425698063864148353509329232637353185879916662535762857046055803126344827252193638068450635075403914139728774215976701177253424872306256754071372279583622974579667610358402093946751697566057918099861246342266493808947395028086687786041L) Traceback (most recent call last): File "", line 1, in TypeError: float expected instead of long instance .. vs: >>> float(-1615850303565550365035743834433497598022205133485774201606517271376232756943394544659860070576145673184435898046094900974705977957524546054754407619322414156031543868365049804587509887519482605339802881919203378413839610932130987808091904716923808523529082292601815252144378794577053290430377619956196519276104705135157728700572895265282173598410898686661027635767561787024437943425698063864148353509329232637353185879916662535762857046055803126344827252193638068450635075403914139728774215976701177253424872306256754071372279583622974579667610358402093946751697566057918099861246342266493808947395028086687786041L) Traceback (most recent call last): File "", line 1, in OverflowError: long int too large to convert to float -- assignee: theller components: ctypes messages: 108265 nosy: kumma, theller priority: normal severity: normal status: open title: raised exception is misleading type: behavior versions: Python 2.6 ___ Python tracker <http://bugs.python.org/issue9041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9041] raised exception is misleading
Pauli Rikula added the comment: I'm a newbie what it comes to Python's C-sources, so please do not take me too seriously. I fetched the sources 'svn checkout http://svn.python.org/projects/python/branches/release26-maint ' studied the issue, and my best guess is that Modules/_ctypes/cfield.c 's funktion d_set is called, when converting something to ctypes.c_double Please check, that this is what happens :) If so, Objects/longobject.c's function double PyLong_AsDouble(PyObject *vv) sets the overflow exception, but d_set overwrites it, like you can see: static PyObject * d_set(void *ptr, PyObject *value, Py_ssize_t size) { double x; x = PyFloat_AsDouble(value); if (x == -1 && PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, " float expected instead of %s instance", value->ob_type->tp_name); return NULL; } memcpy(ptr, &x, sizeof(double)); _RET(value); } Perhaps something like: if (PyErr_ExceptionMatches(PyExc_OverflowError)){ return NULL; } just after the line: 'f (x == -1 && PyErr_Occurred()) {' could fix this? But like I said, I'm an newbie, this was actually my first look into Python/C API and I have not tested this fix in any way whatsoever -- ___ Python tracker <http://bugs.python.org/issue9041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9041] raised exception is misleading
Pauli Rikula added the comment: If d_set makes the conversion, py3k does the same thing: http://svn.python.org/projects/python/branches/py3k/Modules/_ctypes/cfield.c It has a function d_set_sw, which might have same issues as well. The same function can be found from 2.6 too: http://svn.python.org/projects/python/branches/release26-maint/Modules/_ctypes/cfield.c -- ___ Python tracker <http://bugs.python.org/issue9041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com