Little_Sheep_Yawn's blog

By Little_Sheep_Yawn, history, 6 months ago, In English

In recent competitions, I came across this type of RUNTIME ERROR. Here's the thing:

I wrote a program like this:

def main():
    k = 15
    m = 3
    
    for a in range(k + 1):
        for b in range(k + 1):
            for c in range(min(m, k) + 1):
                for d in range(min(m, k) + 1):
                    continue
    return

t = 1
for _ in range(t):
    main() 

But in Atcoder, it showed something like this: (Sorry that the picture isn't clear enough)

It really bothered me and I wonder if anyone could be so kind as to help me with this issue.

(p.s. The RUNTIME ERROR doesn't show in Codeforces, so I'm really confused)

Here are some codes that don't show RUNTIME ERROR:

Code 1:

k = 15
m = 3

for a in range(k + 1):
    for b in range(k + 1):
        for c in range(min(m, k) + 1):
            for d in range(min(m, k) + 1):
                pass

Code 2:

def main():
    k = 15
    m = 3
    
    for a in range(k + 1):
        for b in range(k + 1):
            for c in range(min(m, k) + 1):
                for d in range(min(m, k) + 1):
                    print(d)
    return

t = 1
for _ in range(t):
    main()
  • Vote: I like it
  • +45
  • Vote: I do not like it

»
6 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I would also be very grateful if anyone could help me propose an issue to Pypy through this website: https://foss.heptapod.net/pypy/pypy/-/issues. (according to this: https://www.pypy.org/contact.html) (I couldn't get access to the issue tracker)

  • »
    »
    6 months ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    Did you try reproducing this error locally? Pinging our resident Python expert pajenegod as he might be interested and able to help, since he's quite active there (sorry for the ping if this is not the case).

    • »
      »
      »
      6 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks a lot! In my computer, this program also terminated with abnormally and there wasn't any error messages printed. But some of my friends didn't see that and the program worked out just fine.

      So I think it might have something to do with what kind of system you run the program on.

»
6 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I can reproduce this with PyPy 7.3.13 on Linux. The program triggers a segmentation fault.

I've posted the program on their issue tracker.

»
6 months ago, # |
Rev. 3   Vote: I like it +26 Vote: I do not like it

I'm also able to reproduce this segfault locally on my Windows computer. Even something as simple as this segfaults

def f():
    m = 3
    for a in range(100):
        for b in range(m + 1):
            for c in range(m + 1):
                pass
f() 

It is impressive how such a simple piece of Python code can cause a segfault. Probably it is triggering some bug in PyPy's JIT.