-
-
Notifications
You must be signed in to change notification settings - Fork 568
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
OverflowErrors in TripleDictEraser #14254
Comments
comment:2
There is a comment
Could it be that this is relevant here? Is it really safe to do
? Yes, we need to care about the sign. But we also have
(hence, the modulus is Py_ssize_t, and the result will be translated into Py_ssize_t, too) I am afraid I have no 32 bit machine to test. |
comment:3
PS: Note the discussion that we had on #715 on that matter. Is there a reason why we use ssize_t and not size_t? |
comment:4
Any idea on how to debug this? The problem is that currently we have no idea where this exception is generated. |
comment:5
Google seems to tell me that one should use size_t and not ssize_t here anyway. Not sure though. Nils, do you think it could help to consistently replace ssize_t and Py_ssize_t by size_t? |
comment:6
Replying to @jdemeyer:
Sage's debug version? |
comment:7
Replying to @simon-king-jena:
This line might be problematic if there is no guarantee that the components of |
comment:8
Replying to @simon-king-jena:
Would it really give more information about where the exception is generated? |
comment:9
Replying to @jdemeyer:
I thought that this is the point of a debug version? Is there an environment variable similar to MALLOC_CHECK_ that makes the program segfault on an overflow error, so that one could then analyse the problem using gdb? |
comment:10
How many bytes is Py_ssize_t using? On 32-bit machines, is Py_ssize_t perhaps using more bytes than size_t? Then, the problem could be here:
While h1, h2, and h3 should be fine (they are obtained from a pointer and are thus using 32 bit), I could imagine that Python tries to be clever and uses more byte (long versus int) for h, if 13h2 or 503h3 happen to be larger than the greatest number representable by 32 bit. If this is the case, then the line
(when the "long" Py_ssize_t h is converted down to 32 bit of size_t) could overflow, isn't it? Caveat: I am not an expert for the subtleties of Py_ssize_t on 32 versus 64 bit... |
comment:11
Replying to @simon-king-jena:
No, that cannot be the problem, arithmetic on pure C types (like here) doesn't use Python at all. |
comment:12
I found the following on PEP 353:
Note that we actually do want a conversion from and to <void*>. So, shouldn't we actually use Py_intptr_t, not Py_ssize_t? |
comment:13
Does Py_intptr_t even exist in Sage? I did a grep for it, to no avail. |
comment:14
Replying to @simon-king-jena:
That's all true but it wouldn't solve this error. |
comment:15
Replying to @jdemeyer:
Well, you didn't tell yet were exactly the error is located. Lacking more information, my guess was that an overflow could occur on systems where |
comment:16
Replying to @simon-king-jena:
If I would know that, fixing the error would probably be trivial. |
comment:17
I see it also all over the place when building the docs:
|
comment:18
Can you test |
comment:19
Replying to @simon-king-jena:
This is a typical 32-bit system where the types |
comment:20
Besides, even if |
comment:21
I am debugging building the docs, as I can reliably get the failure this way. |
comment:22
The error happens in the last line here:
|
comment:23
Replying to @jdemeyer:
Interesting. So, this would probably mean that the actual error occurs when storing the key. Let's see what is done there... Just out of curiosity: Does the same problem also occur with #14159 and dependencies? |
comment:24
Aha! We have
Hence, the three items of the key originally were size_t. But they are assigned to Py_ssize_t. |
comment:25
I can't find this code, where is it? |
comment:26
Replying to @simon-king-jena:
Indeed. And So the question is: where does this tuple come from? |
comment:27
In sage/categories/homset.py:
|
comment:28
Replying to @jdemeyer:
There are (as much as I know) only the two places that I mentioned (by the way, #14159 would change it). Is |
comment:29
Replying to @simon-king-jena:
Bingo! That's the problem indeed. |
comment:30
Replying to @jdemeyer:
OK. Then it is solved in #14159, I suppose. |
comment:32
Replying to @jdemeyer:
No, I wouldn't mind (rebasing #14159 should be easy enough). But how can one change the id() thingy in sage/categories/homset.py? After all, it is a Python file, hence, one can not just do |
comment:33
Replying to @simon-king-jena:
You can't, but you could write a small function to do just this in |
Author: Jeroen Demeyer |
comment:34
Attachment: 14254_signed_id.patch.gz |
Dependencies: #13387 |
comment:36
The patch looks fine to me, and it applies cleanly after #13387. Now I wonder what the patchbots have to tell. Problem: I have no 32-bit machine available. Will the machines on which you first noticed the problem report here, in the hopefully green) blob? |
comment:37
Replying to @simon-king-jena:
I don't think so. In any case, the machine in question managed to build the documentation without errors, so that's a good sign. I'm running tests now, but it's a slow machine so I'll report back tomorrow. Regardless, I think you can review the patch without access to a 32-bit system and assume that I have done my duty in testing the patch. |
comment:38
Replying to @simon-king-jena:
Good work guys! That line made me feel uncomfortable when I was reviewing it, because it was reaching into implementation details of |
comment:39
OK, I believe Jeroen when he says that building the documentation on his 32-bit systems works with the patch, while it reproducibly failed without the patch. I think the solution makes sense: id(X) returns a positive number, and this may very well be beyond what a signed number type of the same size (such as Py_ssize_t) can take. The patchbot gives a green blob, too. Hence, I hope it is safe to give this a positive review (but I think #14159 will be better, on the long run). |
Reviewer: SimonKing |
Changed reviewer from SimonKing to Simon King |
Merged: sage-5.8.rc0 |
With the new doctesting framework (#12415), I sometimes see errors like
on 32-bit systems.
These appear randomly non-reproducibly in doctests.
Depends on #13387
CC: @simon-king-jena @nbruin
Component: coercion
Author: Jeroen Demeyer
Reviewer: Simon King
Merged: sage-5.8.rc0
Issue created by migration from https://trac.sagemath.org/ticket/14254
The text was updated successfully, but these errors were encountered: