[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-21 Thread Mark Dickinson
Mark Dickinson added the comment: I fixed up py3k to be in sync with trunk, and added your tests (slightly expanded) to py3k in r76971. Thanks! -- resolution: -> accepted status: open -> closed ___ Python tracker

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-21 Thread Mark Dickinson
Mark Dickinson added the comment: Perfect---thank you! Applied to trunk in r76963. I tweaked the main comment and docstring, wrapped a long line, and replaced two instances of '*overflow = Py_SIZE(v) > 0 ? 1 : -1' with simply '*overflow = sign'. I also expanded the test a bit to check for

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-20 Thread Case Van Horsen
Case Van Horsen added the comment: I uploaded a new consolidated diff that includes the original patch with (hopefully) correct whitespace, some tests, and doc updates. The test just verifies that overflow is set/cleared properly. Proper conversions to long are already tested in test_capi. Let

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-20 Thread Case Van Horsen
Case Van Horsen added the comment: I will work on documentation and test case patches. Per comments on python-dev, there doesn't appear to be interest in distributing forward compatibility files. I will update the bug report with a slightly revised version of py3intcompat.c and just leave it at

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-20 Thread Mark Dickinson
Mark Dickinson added the comment: The longobject.diff patch looks fine, modulo some whitespace nits. (Older C source files use width-8 tabs for indentation.) Are you interested in adding documentation and tests (the latter in the test_capi module)? One thing about the patch struck me as odd

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-19 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks for the patches! I'll look at the 2.7 PyLong_AsLongAndOverflow patch, and (assuming it looks good) apply it. For the py3intcompat.c, it would be good to have some sort of consensus about this; perhaps it should be discussed on python-dev. One proble

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-17 Thread Case Van Horsen
Case Van Horsen added the comment: Uploaded a new version of py3intcompat.c. It should be save to include with any version of Python, included 2.7 with PyLong_AsLongAndOverflow added. The file includes basic documentation on use. -- Added file: http://bugs.python.org/file15588/py3intco

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-17 Thread Case Van Horsen
Case Van Horsen added the comment: I uploaded a patch to add PyLong_AsLongAndOverflow. It was made against the 2.7a1 source. "make test", gmpy's test suite, and mpmath's test suite all pass. Let me know if there is anything else I can do. -- keywords: +patch Added file: http://bugs.pyt

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-17 Thread Case Van Horsen
Case Van Horsen added the comment: I don't want it to be a 2.7-only feature. I'm trying to maintain compatibility with 2.4 and later for gmpy. I would be in favor with adding it to 2.7 as long as we could still provide a standalone version for earlier releases of Python. I hadn't realized th

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-17 Thread Mark Dickinson
Mark Dickinson added the comment: > I'm specifically not in favor of adding it to the Python 2.7 API. Out of curiosity, why not? It seems like a reasonable addition to me. I'd continue to call it simply PyLong_AsLongAndOverflow, though. I note that in 2.x, PyLong_AsLong accepts both ints and

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-17 Thread Case Van Horsen
Case Van Horsen added the comment: Attached py3intcompat.c -- Added file: http://bugs.python.org/file15579/py3intcompat.c ___ Python tracker ___ _

[issue7528] Provide PyLong_AsLongAndOverflow compatibility to Python 2.x

2009-12-17 Thread Case Van Horsen
New submission from Case Van Horsen : When I ported gmpy to Python 3.x, I began to use PyLong_AsLongAndOverflow frequently. I found the code to slightly faster and cleaner than using PyLong_AsLong and checking for overflow. I had several code fragments that looked like: #if PY_MAJOR_VERSION == 2