The patch implements gc.compact_freelists() which calls PyInt and PyFloat_CompactFreeList(). I've moved the code from the _Fini methods to the _CompactFreeList() methods. The patch also moves the clear type cache function to gc.clear_type_cache().
I think sys is appropriate for clearing the cache. Lib/test/regrtest.py still has a reference to gc rather than sys. Why do the CompactFreeList APIs return an int that is always 0? Seems like they should return a real value or be void. I'm not sure why you changed the functions to keep a block_list_length. I doubt this API would be requested very often. Seems like it would be better to just calculate when necessary (or perhaps not even add the APIs). The only issue I have with the patch is the casting in the printf calls. These can lose information. On Win64, long is 32-bits, but size_t is 64-bits. See PY_FORMAT_SIZE_T in Include/pyport.h for how to handle this.
I don't know what the purpose of this feature is nor who the target users are. Trying to micro-manage the interpreter's resource allocation from Python code is certainly a losing battle, and does not warrant relying on implementation-specific APIs. Moreover, these days gc.collect() implicitly collects the freelists. I therefore recommend rejecting this patch.