diff --git a/PC/python_nt.rc b/PC/python_nt.rc index 83174359524..a4e4849dfbc 100644 --- a/PC/python_nt.rc +++ b/PC/python_nt.rc @@ -19,9 +19,29 @@ #endif /* Nothing below this should need to be changed except for copyright - * notices and company name. + * notices, company name, and FIELD3. Unfortunately, all attempts + * to get the resource compiler to do arithmetic in macros have + * failed miserably -- it gives syntax errors, ignores operators, + * or does stuff that's simply bizarre. */ + +/* This is what we'd like FIELD3 to be: + * + * #define FIELD3 (PY_MICRO_VERSION*1000 + PY_RELEASE_LEVEL*10 + PY_RELEASE_SERIAL) + * + * but that neither gives an error nor comes anywhere close to working. The + * following comment and #define are output from PCbuild\field3.py: + * + * For 2.3a0, + * PY_MICRO_VERSION = 0 + * PY_RELEASE_LEVEL = 'alpha' = 0xa + * PY_RELEASE_SERIAL = 1 + * + * and 0*1000 + 10*10 + 1 = 101 + */ +#define FIELD3 101 + /* e.g., 2.1a2 * PY_VERSION comes from patchevel.h */ @@ -37,7 +57,6 @@ #if PY_RELEASE_SERIAL > 9 # error "PY_RELEASE_SERIAL > 9" #endif -#define FIELD3 (PY_MICRO_VERSION*1000 + PY_RELEASE_LEVEL*10 + PY_RELEASE_SERIAL) #define PYVERSION64 PY_MAJOR_VERSION, PY_MINOR_VERSION, FIELD3, PYTHON_API_VERSION // String Tables diff --git a/PCbuild/field3.py b/PCbuild/field3.py new file mode 100644 index 00000000000..47f24ca3cb4 --- /dev/null +++ b/PCbuild/field3.py @@ -0,0 +1,35 @@ +# An absurd workaround for the lack of arithmetic in MS's resource compiler. +# After building Python, run this, then paste the output into the appropriate +# part of PC\python_nt.rc. +# Example output: +# +# * For 2.3a0, +# * PY_MICRO_VERSION = 0 +# * PY_RELEASE_LEVEL = 'alpha' = 0xA +# * PY_RELEASE_SERIAL = 1 +# * +# * and 0*1000 + 10*10 + 1 = 101. +# */ +# #define FIELD3 101 + +import sys + +major, minor, micro, level, serial = sys.version_info +levelnum = {'alpha': 0xA, + 'beta': 0xB, + 'candidate': 0xC, + 'final': 0xF, + }[level] +string = sys.version.split()[0] # like '2.3a0' + +print " * For %s," % string +print " * PY_MICRO_VERSION = %d" % micro +print " * PY_RELEASE_LEVEL = %r = %s" % (level, hex(levelnum)) +print " * PY_RELEASE_SERIAL = %d" % serial +print " *" + +field3 = micro * 1000 + levelnum * 10 + serial + +print " * and %d*1000 + %d*10 + %d = %d" % (micro, levelnum, serial, field3) +print " */" +print "#define FIELD3", field3