Unhelpful error message
Thomas Nyberg
tomuxiong at gmx.com
Tue Jun 6 15:01:21 EDT 2017
On 06/06/2017 11:46 AM, Jon Ribbens wrote:
> On 2017-06-06, Thomas Nyberg <tomuxiong at gmx.com> wrote:
>> My changes feel a bit hacky. I wanted to just drop a straight repr() in,
>> but I didn't want to change the code too much since I assume the string
>> formatting is already there for a reason (e.g. "%.200s").
>
> Just change the '%.200s' to '%.200R' and it should work. The '.200'
> isn't necessary to avoid buffer-overflow or anything, but an error
> message of unlimited length is probably a good thing to avoid anyway ;-)
>
That causes a segfault for me. I.e. if I use this patch:
---------------------
$ git diff master
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 64d0c52..c62db6b 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -357,7 +357,7 @@ PyOS_string_to_double(const char *s,
else if (fail_pos == s)
PyErr_Format(PyExc_ValueError,
"could not convert string to float: "
- "%.200s", s);
+ "%.200R", s);
else if (errno == ERANGE && fabs(x) >= 1.0 && overflow_exception)
PyErr_Format(overflow_exception,
"value too large to convert to float: "
---------------------
Is it because the string object `s` is a const char* string and not a
python string and hence the raw R isn't working right?
Regardless, I think that the logic should probably be handled above this
function (i.e. as I posted in my other reply to you).
In any case, thanks for the help!
Cheers,
Thomas
More information about the Python-list
mailing list