[New-bugs-announce] [issue21490] Add Py_ABS and Py_STINGIFY macros

STINNER Victor report at bugs.python.org
Tue May 13 09:58:42 CEST 2014

New submission from STINNER Victor:

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.
	("[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.

files: abs_stringify.patch
keywords: patch
messages: 218409
nosy: haypo
priority: normal
severity: normal
status: open
title: Add Py_ABS and Py_STINGIFY macros
versions: Python 3.5
Added file: http://bugs.python.org/file35238/abs_stringify.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list