Improve fd reallocation safety
Improve fd reallocation safety

The algorithm should now always be able to swap the files associated to
the original stdio file descriptors correctly.

pymad/cpymad,pymad/jpymad,pymad/jpymad,pymad/jpymad,pymad/cpymad