New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix exceptions on encoding list or dict elements and non-overflow errors on int handling getting silenced #505
Fix exceptions on encoding list or dict elements and non-overflow errors on int handling getting silenced #505
Conversation
Codecov Report
@@ Coverage Diff @@
## main #505 +/- ##
==========================================
+ Coverage 88.79% 88.88% +0.09%
==========================================
Files 6 6
Lines 1695 1709 +14
==========================================
+ Hits 1505 1519 +14
Misses 190 190
Continue to review full report at Codecov.
|
…ors on int handling getting silenced Fixes ultrajson#273
59cd7d6
to
80e1aee
Compare
This is also relevant to #402. What might have been happening there was that the error was getting ignored and it kept appending commas until it ran out of buffer (cf. my comments on #504). While the segfault is no longer possible as far as I can tell (didn't track back where it was fixed though), this causes the first |
I realised earlier that this was missing some cleanup on returning from
There's an extra space on the third and fourth line because This further led me to discover that |
An overflow error sounds sensible to me anyway. |
@bwoodsend Just to be clear, I meant that those functions could in principle set another exception, and the previous code would've ignored them at least in certain scenarios since it only handled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Wouldn't it be a bit nicer like this instead?
if (exc && PyErr_ExceptionMatches(PyExc_OverflowError))
{
PyErr_Clear();
pc->PyTypeToJSON = PyLongToUINT64;
tc->type = JT_ULONG;
GET_TC(tc)->unsignedLongValue = PyLong_AsUnsignedLongLong(obj);
exc = PyErr_Occurred();
}
if (exc)
{
PRINTMARK();
goto INVALID;
}
@RouquinBlanc Good point! Yes, that would be cleaner. Since this has already been merged, could you make a separate PR for that? Or would you prefer if I did it? |
Done! |
Fixes #273
I have no idea how to make
PyLong_As*
raise an exception other thanOverflowError
for testing that part, but it should be possible in theory (e.g. running out of memory at that exact moment, I guess?).