Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c78462f

Browse files
committed
The MS resource compiler simply cannot be convinced to do arithmetic
correctly. So field3.py is a Python program that can. This injects another manual step into the Python release process for Windows; so it goes.
1 parent ce2f663 commit c78462f

2 files changed

Lines changed: 56 additions & 2 deletions

File tree

PC/python_nt.rc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,29 @@
1919
#endif
2020

2121
/* Nothing below this should need to be changed except for copyright
22-
* notices and company name.
22+
* notices, company name, and FIELD3. Unfortunately, all attempts
23+
* to get the resource compiler to do arithmetic in macros have
24+
* failed miserably -- it gives syntax errors, ignores operators,
25+
* or does stuff that's simply bizarre.
2326
*/
2427

28+
29+
/* This is what we'd like FIELD3 to be:
30+
*
31+
* #define FIELD3 (PY_MICRO_VERSION*1000 + PY_RELEASE_LEVEL*10 + PY_RELEASE_SERIAL)
32+
*
33+
* but that neither gives an error nor comes anywhere close to working. The
34+
* following comment and #define are output from PCbuild\field3.py:
35+
*
36+
* For 2.3a0,
37+
* PY_MICRO_VERSION = 0
38+
* PY_RELEASE_LEVEL = 'alpha' = 0xa
39+
* PY_RELEASE_SERIAL = 1
40+
*
41+
* and 0*1000 + 10*10 + 1 = 101
42+
*/
43+
#define FIELD3 101
44+
2545
/* e.g., 2.1a2
2646
* PY_VERSION comes from patchevel.h
2747
*/
@@ -37,7 +57,6 @@
3757
#if PY_RELEASE_SERIAL > 9
3858
# error "PY_RELEASE_SERIAL > 9"
3959
#endif
40-
#define FIELD3 (PY_MICRO_VERSION*1000 + PY_RELEASE_LEVEL*10 + PY_RELEASE_SERIAL)
4160
#define PYVERSION64 PY_MAJOR_VERSION, PY_MINOR_VERSION, FIELD3, PYTHON_API_VERSION
4261

4362
// String Tables

PCbuild/field3.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# An absurd workaround for the lack of arithmetic in MS's resource compiler.
2+
# After building Python, run this, then paste the output into the appropriate
3+
# part of PC\python_nt.rc.
4+
# Example output:
5+
#
6+
# * For 2.3a0,
7+
# * PY_MICRO_VERSION = 0
8+
# * PY_RELEASE_LEVEL = 'alpha' = 0xA
9+
# * PY_RELEASE_SERIAL = 1
10+
# *
11+
# * and 0*1000 + 10*10 + 1 = 101.
12+
# */
13+
# #define FIELD3 101
14+
15+
import sys
16+
17+
major, minor, micro, level, serial = sys.version_info
18+
levelnum = {'alpha': 0xA,
19+
'beta': 0xB,
20+
'candidate': 0xC,
21+
'final': 0xF,
22+
}[level]
23+
string = sys.version.split()[0] # like '2.3a0'
24+
25+
print " * For %s," % string
26+
print " * PY_MICRO_VERSION = %d" % micro
27+
print " * PY_RELEASE_LEVEL = %r = %s" % (level, hex(levelnum))
28+
print " * PY_RELEASE_SERIAL = %d" % serial
29+
print " *"
30+
31+
field3 = micro * 1000 + levelnum * 10 + serial
32+
33+
print " * and %d*1000 + %d*10 + %d = %d" % (micro, levelnum, serial, field3)
34+
print " */"
35+
print "#define FIELD3", field3

0 commit comments

Comments
 (0)