From c36b5dab05d7c5a7f95641379d3e12ac3dd6a861 Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Sun, 23 Sep 2018 15:31:54 +0100 Subject: [PATCH] python: Replace xrange with range In Py2 `range` returns a list and `xrange` creates a sequence object that evaluates lazily. In Py3 `range` is equivalent to `xrange` in Py2. Signed-off-by: Radostin Stoyanov Signed-off-by: Andrei Vagin --- coredump/criu_coredump/coredump.py | 2 +- test/exhaustive/pipe.py | 10 +++++----- test/others/mounts/mounts.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/coredump/criu_coredump/coredump.py b/coredump/criu_coredump/coredump.py index df055dcb2..963e8c61b 100644 --- a/coredump/criu_coredump/coredump.py +++ b/coredump/criu_coredump/coredump.py @@ -625,7 +625,7 @@ class coredump_generator: off = 0# in pages for m in pagemap[1:]: found = False - for i in xrange(m["nr_pages"]): + for i in range(m["nr_pages"]): if m["vaddr"] + i*PAGESIZE == page_no*PAGESIZE: found = True break diff --git a/test/exhaustive/pipe.py b/test/exhaustive/pipe.py index b4453129a..17e065800 100755 --- a/test/exhaustive/pipe.py +++ b/test/exhaustive/pipe.py @@ -19,13 +19,13 @@ def mix(nr_tasks, nr_pipes): # First -- make a full set of combinations for a single pipe. max_idx = 1 << nr_tasks - pipe_mix = [[(r, w)] for r in xrange(0, max_idx) for w in xrange(0, max_idx)] + pipe_mix = [[(r, w)] for r in range(0, max_idx) for w in range(0, max_idx)] # Now, for every pipe throw another one into the game making # all possible combinations of what was seen before with the # newbie. pipes_mix = pipe_mix - for t in xrange(1, nr_pipes): + for t in range(1, nr_pipes): pipes_mix = [ o + n for o in pipes_mix for n in pipe_mix ] return pipes_mix @@ -38,7 +38,7 @@ def make_pipes(task_nr, nr_pipes, pipes, comb, status_pipe): # We need to make sure that pipes have their # ends according to comb for task_nr - for i in xrange(0, nr_pipes): + for i in range(0, nr_pipes): # Read end if not (comb[i][0] & (1 << task_nr)): os.close(pipes[i][0]) @@ -137,13 +137,13 @@ def make_comb(comb, opts, status_pipe): print('\tMake pipes') # 1st -- make needed pipes pipes = [] - for p in xrange(0, opts.pipes): + for p in range(0, opts.pipes): pipes.append(os.pipe()) # Fork the kids that'll make pipes kc_pipe = os.pipe() kids = [] - for t in xrange(0, opts.tasks): + for t in range(0, opts.tasks): pid = os.fork() if pid == 0: os.close(status_pipe) diff --git a/test/others/mounts/mounts.py b/test/others/mounts/mounts.py index 474feed41..dc65ba45c 100755 --- a/test/others/mounts/mounts.py +++ b/test/others/mounts/mounts.py @@ -23,7 +23,7 @@ root = tempfile.mkdtemp(prefix = "root.mount", dir = "/tmp") mount(None, root, 1, 0, 0) mounts = [root] -for i in xrange(10): +for i in range(10): dstdir = random.choice(mounts) dst = tempfile.mkdtemp(prefix = "mount", dir = dstdir) src = random.choice(mounts + [None])