[CRIU] [PATCH] crit-images: Don't overwrite 'pb' with local var

Radostin Stoyanov rstoyanov1 at gmail.com
Tue Oct 9 10:50:35 MSK 2018


On 09/10/2018 00:14, Andrei Vagin wrote:
> On Wed, Oct 03, 2018 at 08:57:21PM +0100, Radostin Stoyanov wrote:
>> Rename the local variables 'pb' to 'pbuff' to avoid conflict with the
>> imported 'pb' module.
>>
>> Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
>> ---
>>  lib/py/images/images.py | 74 ++++++++++++++++++++---------------------
>>  1 file changed, 37 insertions(+), 37 deletions(-)
>>
>> diff --git a/lib/py/images/images.py b/lib/py/images/images.py
>> index 217105fa..40fb74d3 100644
>> --- a/lib/py/images/images.py
>> +++ b/lib/py/images/images.py
>> @@ -91,13 +91,13 @@ class entry_handler:
>>  			entry = {}
>>  
>>  			# Read payload
>> -			pb = self.payload()
>> +			pbuff = self.payload()
>>  			buf = f.read(4)
>>  			if buf == b'':
>>  				break
>>  			size, = struct.unpack('i', buf)
>> -			pb.ParseFromString(f.read(size))
>> -			entry = pb2dict.pb2dict(pb, pretty)
>> +			pbuff.ParseFromString(f.read(size))
>> +			entry = pb2dict.pb2dict(pbuff, pretty)
>>  
>>  			# Read extra
>>  			if self.extra_handler:
>> @@ -112,10 +112,10 @@ class entry_handler:
>>  							num /= 1024.0
>>  						return "%.1fYB" % num
>>  
>> -					pl_size = self.extra_handler.skip(f, pb)
>> +					pl_size = self.extra_handler.skip(f, pbuff)
>>  					entry['extra'] = '... <%s>' % human_readable(pl_size)
>>  				else:
>> -					entry['extra'] = self.extra_handler.load(f, pb)
>> +					entry['extra'] = self.extra_handler.load(f, pbuff)
>>  
>>  			entries.append(entry)
>>  
>> @@ -138,16 +138,16 @@ class entry_handler:
>>  			extra = entry.pop('extra', None)
>>  
>>  			# Write payload
>> -			pb = self.payload()
>> -			pb2dict.dict2pb(entry, pb)
>> -			pb_str = pb.SerializeToString()
>> +			pbuff = self.payload()
>> +			pb2dict.dict2pb(entry, pbuff)
>> +			pb_str = pbuff.SerializeToString()
>>  			size = len(pb_str)
>>  			f.write(struct.pack('i', size))
>>  			f.write(pb_str)
>>  
>>  			# Write extra
>>  			if self.extra_handler and extra:
>> -				self.extra_handler.dump(extra, f, pb)
>> +				self.extra_handler.dump(extra, f, pbuff)
>>  
>>  	def dumps(self, entries):
>>  		"""
>> @@ -312,7 +312,7 @@ class sk_queues_extra_handler:
>>  		data = f.read(size)
>>  		return base64.encodebytes(data)
>>  
>> -	def dump(self, extra, f, pb):
>> +	def dump(self, extra, f, _unused):
>>  		data = base64.decodebytes(extra)
>>  		f.write(data)
>>  
>> @@ -322,31 +322,31 @@ class sk_queues_extra_handler:
>>  
>>  
>>  class tcp_stream_extra_handler:
>> -	def load(self, f, pb):
>> +	def load(self, f, pbuff):
>>  		d = {}
>>  
>> -		inq	= f.read(pb.inq_len)
>> -		outq	= f.read(pb.outq_len)
>> +		inq	= f.read(pbuff.inq_len)
>> +		outq	= f.read(pbuff.outq_len)
>>  
>>  		d['inq']	= base64.encodebytes(inq)
>>  		d['outq']	= base64.encodebytes(outq)
>>  
>>  		return d
>>  
>> -	def dump(self, extra, f, pb):
>> +	def dump(self, extra, f, _unused):
>>  		inq	= base64.decodebytes(extra['inq'])
>>  		outq	= base64.decodebytes(extra['outq'])
>>  
>>  		f.write(inq)
>>  		f.write(outq)
>>  
>> -	def skip(self, f, pb):
>> +	def skip(self, f, pbuff):
>>  		f.seek(0, os.SEEK_END)
>> -		return pb.inq_len + pb.outq_len
>> +		return pbuff.inq_len + pbuff.outq_len
>>  
>>  class ipc_sem_set_handler:
>> -	def load(self, f, pb):
>> -		entry = pb2dict.pb2dict(pb)
>> +	def load(self, f, pbuff):
>> +		entry = pb2dict.pb2dict(pbuff)
>>  		size = sizeof_u16 * entry['nsems']
>>  		rounded = round_up(size, sizeof_u64)
>>  		s = array.array('H')
>> @@ -356,8 +356,8 @@ class ipc_sem_set_handler:
>>  		f.seek(rounded - size, 1)
>>  		return s.tolist()
>>  
>> -	def dump(self, extra, f, pb):
>> -		entry = pb2dict.pb2dict(pb)
>> +	def dump(self, extra, f, pbuff):
>> +		entry = pb2dict.pb2dict(pbuff)
>>  		size = sizeof_u16 * entry['nsems']
>>  		rounded = round_up(size, sizeof_u64)
>>  		s = array.array('H')
>> @@ -369,22 +369,22 @@ class ipc_sem_set_handler:
>>  		f.write(s.tostring())
>>  		f.write('\0' * (rounded - size))
>>  
>> -	def skip(self, f, pb):
>> -		entry = pb2dict.pb2dict(pb)
>> +	def skip(self, f, pbuff):
>> +		entry = pb2dict.pb2dict(pbuff)
>>  		size = sizeof_u16 * entry['nsems']
>>  		f.seek(round_up(size, sizeof_u64), os.SEEK_CUR)
>>  		return size
>>  
>>  class ipc_msg_queue_handler:
>> -	def load(self, f, pb):
>> -		entry = pb2dict.pb2dict(pb)
>> +	def load(self, f, pbuff):
>> +		entry = pb2dict.pb2dict(pbuff)
>>  		messages = []
>>  		for x in range (0, entry['qnum']):
>>  			buf = f.read(4)
>>  			if buf == '':
>>  				break
>>  			size, = struct.unpack('i', buf)
>> -			msg = pb.ipc_msg()
>> +			msg = pbuff.ipc_msg()
> pb.ipc_msg ?
Yes, you are right! Sorry about that.

Radostin


More information about the CRIU mailing list