From: Eli Bendersky Date: Sun, 31 Mar 2013 21:19:21 +0000 (-0700) Subject: Fix some Python 3 goofs and make sure the tests execute with the correct X-Git-Tag: v0.21~12 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ccdb5543cdc1446874d68ad1693e3776beb74386;p=pyelftools.git Fix some Python 3 goofs and make sure the tests execute with the correct version of Python (the same the runners themselves were executed with). --- diff --git a/README.rst b/README.rst index 68a9e81..07bd671 100644 --- a/README.rst +++ b/README.rst @@ -28,6 +28,10 @@ install from source, as usual:: > python setup.py install +Since **pyelftools** is a work in progress, it's recommended to get the ``tip`` +tag ("trunk") from *Downloads* or just clone the Mercurial repository, to get +the latest code. + How to use it? -------------- diff --git a/elftools/common/utils.py b/elftools/common/utils.py index 2daed04..7bd1d5b 100644 --- a/elftools/common/utils.py +++ b/elftools/common/utils.py @@ -41,6 +41,8 @@ def parse_cstring_from_stream(stream, stream_pos=None): If stream_pos is provided, the stream is seeked to this position before the parsing is done. Otherwise, the current position of the stream is used. + Note: a bytes object is returned here, because this is what's read from + the binary file. """ if stream_pos is not None: stream.seek(stream_pos) diff --git a/scripts/readelf.py b/scripts/readelf.py index c1ed3fc..69ad480 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -300,13 +300,13 @@ class ReadElf(object): padding = 20 + (8 if self.elffile.elfclass == 32 else 0) for tag in section.iter_tags(): if tag.entry.d_tag == 'DT_NEEDED': - parsed = 'Shared library: [%s]' % tag.needed + parsed = 'Shared library: [%s]' % bytes2str(tag.needed) elif tag.entry.d_tag == 'DT_RPATH': - parsed = 'Library rpath: [%s]' % tag.rpath + parsed = 'Library rpath: [%s]' % bytes2str(tag.rpath) elif tag.entry.d_tag == 'DT_RUNPATH': - parsed = 'Library runpath: [%s]' % tag.runpath + parsed = 'Library runpath: [%s]' % bytes2str(tag.runpath) elif tag.entry.d_tag == 'DT_SONAME': - parsed = 'Library soname: [%s]' % tag.soname + parsed = 'Library soname: [%s]' % bytes2str(tag.soname) elif (tag.entry.d_tag.endswith('SZ') or tag.entry.d_tag.endswith('ENT')): parsed = '%i (bytes)' % tag['d_val'] @@ -618,7 +618,7 @@ class ReadElf(object): if dir_index > 0: dir = lineprogram['include_directory'][dir_index - 1] else: - dir = '.' + dir = b'.' cu_filename = '%s/%s' % (bytes2str(dir), cu_filename) self._emitline('CU: %s:' % cu_filename) diff --git a/test/run_readelf_tests.py b/test/run_readelf_tests.py index 933788b..25a97c9 100755 --- a/test/run_readelf_tests.py +++ b/test/run_readelf_tests.py @@ -168,6 +168,7 @@ def main(): if options.verbose: testlog.info('Running in verbose mode') + testlog.info('Python executable = %s' % sys.executable) testlog.info('readelf path = %s' % READELF_PATH) testlog.info('Given list of files: %s' % args) diff --git a/test/utils.py b/test/utils.py index 0ee0ebf..dc6784d 100644 --- a/test/utils.py +++ b/test/utils.py @@ -6,7 +6,7 @@ # Eli Bendersky (eliben@gmail.com) # This code is in the public domain #------------------------------------------------------------------------------- -import os, subprocess, tempfile +import os, sys, subprocess, tempfile from elftools.common.py3compat import bytes2str @@ -17,7 +17,7 @@ def run_exe(exe_path, args): """ popen_cmd = [exe_path] + args if os.path.splitext(exe_path)[1] == '.py': - popen_cmd.insert(0, 'python') + popen_cmd.insert(0, sys.executable) proc = subprocess.Popen(popen_cmd, stdout=subprocess.PIPE) proc_stdout = proc.communicate()[0] return proc.returncode, bytes2str(proc_stdout)