-
Notifications
You must be signed in to change notification settings - Fork 1k
Chez Scheme: raise catchable exception for expt with huge result #1017
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
base: main
Are you sure you want to change the base?
Conversation
c/alloc.c
Outdated
|
|
||
| d = size_bignum(n); | ||
| if ((uptr)d > (uptr)1 << (ptr_bits > 32 ? 38 : 28)) | ||
| S_error("", "out of memory"); |
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.
Can you say more about what this is doing? I don't understand where the constants come from, but it seems like they should be derived in "cmacro.ss". More generally, raising exceptions in the kernel instead of Scheme also creates problems; I think this would be incompatible with #1013, for example.
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.
The constants are just plausible ones that seemed "big enough".
I will try a different approach that avoids raising exceptions in the kernel.
|
I see that the latest commit moves the practical-limit check to the Scheme side — thanks! — but I'm skeptical of that number. Lets assume that the magic number 40 is given a name in "cmacros.ss": In the context of things like Typed Racket tests, maybe the right thing is to use |
|
A few thoughts:
More generally I'm not sure what the philosophy should be here. My thought was that safe Scheme operations should not trigger aborts, even when they try to allocate large amounts of memory. But maybe that's not the goal and we should be a lot more permissive at the cost of aborts so that if there is enough memory the operation will succeed. |
Raise a catchable exception for
exptwith an integer base and bignum exponent, rather than consuming all memory and aborting. Also add a practical size limit inS_bignumto catch cases where the exponent is a large fixnum (e.g., on 64-bit).This was found in the random testing for Typed Racket, see racket/typed-racket#1494.