Fix some Python 3 goofs and make sure the tests execute with the correct
authorEli Bendersky <eliben@gmail.com>
Sun, 31 Mar 2013 21:19:21 +0000 (14:19 -0700)
committerEli Bendersky <eliben@gmail.com>
Sun, 31 Mar 2013 21:19:21 +0000 (14:19 -0700)
version of Python (the same the runners themselves were executed with).

README.rst
elftools/common/utils.py
scripts/readelf.py
test/run_readelf_tests.py
test/utils.py

index 68a9e8107e415c4e80e5846d471076256764b4eb..07bd671cb72a4914b9662c647424b90358cddcc7 100644 (file)
@@ -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?
 --------------
 
index 2daed04c51cde36a9f0185312d75c5b602f72b4c..7bd1d5b1fef76133809756e1b46c212c702261c9 100644 (file)
@@ -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)
index c1ed3fc8d2146bd1610b7366b64d76436f7b3464..69ad480cc0613a9c31fecbef5f3b53c2dcc4be52 100755 (executable)
@@ -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)
index 933788bb65ec7f33778c30540f2b71f6776c8ef2..25a97c90593f63da53dff0aea9a12756a3fecf17 100755 (executable)
@@ -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)
 
index 0ee0ebf95333417a1187f433eeb9aa902a2ea446..dc6784dc02ef9180b8492076f1756271d1b23898 100644 (file)
@@ -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)