gap-packages / io

GAP package IO to do input and output
https://gap-packages.github.io/io/
Other
14 stars 14 forks source link

Properly close all open files on exit #121

Closed zickgraf closed 10 months ago

zickgraf commented 11 months ago

The old logic iterated over a list while modifying this list, effectively skipping every second open file.

To avoid such errors in my own code, I have added an error to my GAP which triggers if I remove elements from a list while iterating over it: https://github.com/zickgraf/gap/commit/f8d4c3548275eef87bacb5c105ac230348cf4b01. Would this be a welcome change for GAP?

ChrisJefferson commented 11 months ago

This looks good to me, and I certainly can't think of any bugs this could introduce. It's obviously hard to add a test for, but looks correct. Good catch!

ChrisJefferson commented 11 months ago

With regards the error, I personally would be tempted to instead add this as an "InfoWarning", at level 1. This means if anyone does have code which is relying on this behaviour (honestly, I'm not positive how they would be), it will at least still run. However, I imagine in most cases where people write such code it is an error.

zickgraf commented 10 months ago

With regards the error, I personally would be tempted to instead add this as an "InfoWarning", at level 1.

(How) could I use "InfoWarning" from C code?

fingolfin commented 10 months ago

(How) could I use "InfoWarning" from C code?

I guess one could import InfoWarning from the library "as usual", and then use the kernel helper InfoCheckLevel to check the level, and use that to wrap a Pr call.