This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add Py_ABS and Py_STRINGIFY macros
Type: Stage:
Components: Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: python-dev, vstinner
Priority: normal Keywords: patch

Created on 2014-05-13 07:58 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
abs_stringify.patch vstinner, 2014-05-13 07:58 review
Messages (2)
msg218409 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-05-13 07:58
Attached patches replaces duplicated C macros with two new shared macros: Py_ABS(x) and Py_STRINGIFY(x).

I didn't touch PC/pyconfig.h because it uses 3 macros to stringify instead of just 2 and I don't know why:
---
/* We want COMPILER to expand to a string containing _MSC_VER's *value*.
 * This is horridly tricky, because the stringization operator only works
 * on macro arguments, and doesn't evaluate macros passed *as* arguments.
 * Attempts simpler than the following appear doomed to produce "_MSC_VER"
 * literally in the string.
 */
#define _Py_PASTE_VERSION(SUFFIX) \
	("[MSC v." _Py_STRINGIZE(_MSC_VER) " " SUFFIX "]")
/* e.g., this produces, after compile-time string catenation,
 * 	("[MSC v.1200 32 bit (Intel)]")
 *
 * _Py_STRINGIZE(_MSC_VER) expands to
 * _Py_STRINGIZE1((_MSC_VER)) expands to
 * _Py_STRINGIZE2(_MSC_VER) but as this call is the result of token-pasting
 *      it's scanned again for macros and so further expands to (under MSVC 6)
 * _Py_STRINGIZE2(1200) which then expands to
 * "1200"
 */
#define _Py_STRINGIZE(X) _Py_STRINGIZE1((X))
#define _Py_STRINGIZE1(X) _Py_STRINGIZE2 ## X
#define _Py_STRINGIZE2(X) #X
---

Maybe it's time to drop these old macros (only required for MSVC 6?) and use Py_STRINGIFY? I will try with Visual Studio 2010.
msg218548 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-05-14 15:30
New changeset 849efd365ab4 by Victor Stinner in branch 'default':
Issue #21490: Add new C macros: Py_ABS() and Py_STRINGIFY()
http://hg.python.org/cpython/rev/849efd365ab4
History
Date User Action Args
2022-04-11 14:58:03adminsetgithub: 65689
2014-05-14 15:31:25vstinnersetstatus: open -> closed
resolution: fixed
2014-05-14 15:30:50python-devsetnosy: + python-dev
messages: + msg218548
2014-05-13 08:52:06serhiy.storchakasettitle: Add Py_ABS and Py_STINGIFY macros -> Add Py_ABS and Py_STRINGIFY macros
2014-05-13 07:58:41vstinnercreate