Skip to content

Commit

Permalink
Fix bytecode compatibility with Python 3.7 beta3
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed Apr 26, 2018
1 parent bf60a58 commit 0c39558
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions PythonBytecode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Python MAGIC Python MAGIC Python MAGIC
1.5 0x0A0D4E99 2.5 0x0A0DF2B3 3.5 0x0A0D0D16
1.6 0x0A0DC4FC 2.6 0x0A0DF2D1 3.5.3 0x0A0D0D17
2.7 0x0A0DF303 3.6 0x0A0D0D33
3.7 0x0A0D0D3F
3.7 0x0A0D0D41


1.0 1.1 1.2 1.3 1.4 1.5 1.6
Expand Down Expand Up @@ -479,7 +479,7 @@ SETUP_FINALLY [X] [X] [X] [X] [X] [X] [X]
LOAD_FAST [X] [X] [X] [X] [X] [X] [X] [X]
STORE_FAST [X] [X] [X] [X] [X] [X] [X] [X]
DELETE_FAST [X] [X] [X] [X] [X] [X] [X] [X]
STORE_ANNOTATION [ ] [ ] [ ] [ ] [ ] [ ] [X] [X]
STORE_ANNOTATION [ ] [ ] [ ] [ ] [ ] [ ] [X] [ ]
<128> [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]
<129> [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]
RAISE_VARARGS [X] [X] [X] [X] [X] [X] [X] [X]
Expand Down
1 change: 0 additions & 1 deletion bytes/python_37.map
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
124 LOAD_FAST_A
125 STORE_FAST_A
126 DELETE_FAST_A
127 STORE_ANNOTATION_A
130 RAISE_VARARGS_A
131 CALL_FUNCTION_A
132 MAKE_FUNCTION_A
Expand Down
17 changes: 14 additions & 3 deletions pyc_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,21 @@ void PycModule::loadFromFile(const char* filename)
fputs("Bad MAGIC!\n", stderr);
return;
}
in.get32(); // Timestamp -- who cares?

if (verCompare(3, 3) >= 0)
in.get32(); // Size parameter added in Python 3.3
int flags = 0;
if (verCompare(3, 7) >= 0)
flags = in.get32();

if (flags & 0x1) {
// Optional checksum added in Python 3.7
in.get32();
in.get32();
} else {
in.get32(); // Timestamp -- who cares?

if (verCompare(3, 3) >= 0)
in.get32(); // Size parameter added in Python 3.3
}

m_code = LoadObject(&in, this).require_cast<PycCode>();
}
Expand Down
2 changes: 1 addition & 1 deletion pyc_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum PycMagic {
MAGIC_3_5 = 0x0A0D0D16,
MAGIC_3_5_3 = 0x0A0D0D17,
MAGIC_3_6 = 0x0A0D0D33,
MAGIC_3_7 = 0x0A0D0D3F,
MAGIC_3_7 = 0x0A0D0D41,
};

#define PYC_VERSION(maj, min) MAGIC_##maj##_##min
Expand Down

0 comments on commit 0c39558

Please sign in to comment.