[CRIU] [PATCH 4/4] python: Replace xrange with range

Radostin Stoyanov rstoyanov1 at gmail.com
Sun Sep 23 17:31:54 MSK 2018


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 <rstoyanov1 at gmail.com>
---
 coredump/criu_coredump/coredump.py |  2 +-
 scripts/criu-ns                    |  2 +-
 test/exhaustive/pipe.py            | 10 +++++-----
 test/others/mounts/mounts.py       |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/coredump/criu_coredump/coredump.py b/coredump/criu_coredump/coredump.py
index df055dcb..963e8c61 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/scripts/criu-ns b/scripts/criu-ns
index e7ebbf0c..0910f2a3 100755
--- a/scripts/criu-ns
+++ b/scripts/criu-ns
@@ -124,7 +124,7 @@ def wrap_restore():
 
 
 def get_varg(args):
-	for i in xrange(1, len(sys.argv)):
+	for i in range(1, len(sys.argv)):
 		if not sys.argv[i] in args:
 			continue
 
diff --git a/test/exhaustive/pipe.py b/test/exhaustive/pipe.py
index b4453129..17e06580 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 474feed4..dc65ba45 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])
-- 
2.17.1



More information about the CRIU mailing list