You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Fix marshal bug in handling complex numbers
This commit is contained in:
20
pytest/test_marsh.py
Normal file
20
pytest/test_marsh.py
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os.path
|
||||
from uncompyle6.load import load_module
|
||||
|
||||
def get_srcdir():
|
||||
filename = os.path.normcase(os.path.dirname(os.path.abspath(__file__)))
|
||||
return os.path.realpath(filename)
|
||||
|
||||
srcdir = get_srcdir()
|
||||
|
||||
def test_load_module():
|
||||
"""Tests uncompile6.load.load_module"""
|
||||
# We deliberately pick a bytecode that we aren't likely to be running against
|
||||
mod_file = os.path.join(get_srcdir(), '..', 'test', 'bytecode_2.5',
|
||||
'02_complex.pyc')
|
||||
|
||||
version, timestamp, magic_int, co = load_module(mod_file)
|
||||
assert version == 2.5, "Should have picked up Python version properly"
|
||||
assert co.co_consts == (5j, None), "Code should have a complex constant"
|
BIN
test/bytecode_2.5/02_complex.pyc
Normal file
BIN
test/bytecode_2.5/02_complex.pyc
Normal file
Binary file not shown.
4
test/simple_source/expression/02_complex.py
Normal file
4
test/simple_source/expression/02_complex.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# From python2.7/json/tests/test_recursion.py
|
||||
# Tests our Python marshal load_code_internal handles reading complex numbers,
|
||||
# marshal type 'x'
|
||||
x = 5j
|
@@ -161,6 +161,7 @@ def load_code_internal(fp, magic_int, bytes_for_s=False,
|
||||
return code
|
||||
marshalType = chr(b1)
|
||||
|
||||
# print(marshalType) # debug
|
||||
if marshalType == '0':
|
||||
# Null
|
||||
return None
|
||||
@@ -192,8 +193,9 @@ def load_code_internal(fp, magic_int, bytes_for_s=False,
|
||||
raise KeyError(marshalType)
|
||||
elif marshalType == 'y':
|
||||
# binary complex
|
||||
raise KeyError(marshalType)
|
||||
return None
|
||||
real = unpack('d', fp.read(8))[0]
|
||||
imag = unpack('d', fp.read(8))[0]
|
||||
return complex(real, imag)
|
||||
elif marshalType == 'l':
|
||||
# long
|
||||
n = unpack('i', fp.read(4))[0]
|
||||
|
Reference in New Issue
Block a user