Unfortunately I have discovered that there is significant difference between uint_converter in Modules/zlibmodule.c and proposed _PyLong_UnsignedInt_Converter. And there are tests in Lib/test/test_zlib.py which fail when _PyLong_UnsignedInt_Converter is used instead of uint_converter. uint_converter raises ValueError for negative integers, and _PyLong_UnsignedInt_Converter raises OverflowError.
Possible solutions:
1. Change tests. I don't like this, ValueError looks reasonable for these cases.
2. Continue to use uint_converter in Modules/zlibmodule.c. Then new converters become less useful.
3. Raise ValueError in new converters for negative integers. ValueError looks reasonable in many cases.
4. Raise ValueError in PyLong_AsUnsignedLong etc for negative integers.
Here is a patch which incorporates Larry's suggestions and implements option #3. |