Fix compile error when compiling with optimize level 4
Fix Python 3 crash on Windows, and fix some Python 3-related compile errors