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

Skip to content

Commit 48deae1

Browse files
committed
some horrible preprocessing tricks to automatically update the tag
1 parent dd5be06 commit 48deae1

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

Python/import.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,24 @@ typedef unsigned short mode_t;
110110
TAG and PYC_TAG_UNICODE must change for each major Python release. The magic
111111
number will take care of any bytecode changes that occur during development.
112112
*/
113+
#define QUOTE(arg) #arg
114+
#define STRIFY(name) QUOTE(name)
115+
#define MAJOR STRIFY(PY_MAJOR_VERSION)
116+
#define MINOR STRIFY(PY_MINOR_VERSION)
113117
#define MAGIC (3180 | ((long)'\r'<<16) | ((long)'\n'<<24))
114-
#define TAG "cpython-32"
118+
#define TAG "cpython-" MAJOR MINOR;
115119
#define CACHEDIR "__pycache__"
116120
static const Py_UNICODE CACHEDIR_UNICODE[] = {
117121
'_', '_', 'p', 'y', 'c', 'a', 'c', 'h', 'e', '_', '_', '\0'};
118122
/* Current magic word and string tag as globals. */
119123
static long pyc_magic = MAGIC;
120124
static const char *pyc_tag = TAG;
121125
static const Py_UNICODE PYC_TAG_UNICODE[] = {
122-
'c', 'p', 'y', 't', 'h', 'o', 'n', '-', '3', '2', '\0'};
126+
'c', 'p', 'y', 't', 'h', 'o', 'n', '-', PY_MAJOR_VERSION + 48, PY_MINOR_VERSION + 48, '\0'};
127+
#undef QUOTE
128+
#undef STRIFY
129+
#undef MAJOR
130+
#undef MINOR
123131

124132
/* See _PyImport_FixupExtensionObject() below */
125133
static PyObject *extensions = NULL;

0 commit comments

Comments
 (0)