From 374314612121a0952f301ff85a1cf31cae12c886 Mon Sep 17 00:00:00 2001 From: anthony cantor Date: Thu, 5 Sep 2013 17:29:25 -0600 Subject: [PATCH] only convert input bytes if they are a string and we are in python 3 in python 2 'str' and 'bytes' are the same. if input bytes are not a string or bytes, then raise a TypeError. --- llvm/mc/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/mc/__init__.py b/llvm/mc/__init__.py index 58dd4b2..3e13242 100644 --- a/llvm/mc/__init__.py +++ b/llvm/mc/__init__.py @@ -194,11 +194,10 @@ class Disassembler(object): llvm.mc.Instr ''' - if not isinstance(bs, bytes): - if sys.version_info.major < 3: - bs = bytes(bs) - else: - bs = bytes(map(lambda c: ord(c), bs)) + if isinstance(bs, str) and sys.version_info.major >= 3: + bs = bytes(map(lambda c: ord(c), bs)) + elif not isinstance(bs, bytes): + raise TypeError("expected bs to be either 'str' or 'bytes' but got %s" % type(bs)) code = api.llvm.StringRefMemoryObject.new(bs, base_addr) idx = 0