* [PATCH v1] tools: use integer division in convert-legacy-stream
@ 2021-06-18 9:31 Olaf Hering
2021-06-18 9:42 ` Andrew Cooper
0 siblings, 1 reply; 4+ messages in thread
From: Olaf Hering @ 2021-06-18 9:31 UTC (permalink / raw)
To: xen-devel
Cc: Olaf Hering, Marek Marczykowski-Górecki, Ian Jackson, Wei Liu
A single slash gives a float, a double slash gives an int.
bitmap = unpack_exact("Q" * ((max_id/64) + 1))
TypeError: can't multiply sequence by non-int of type 'float'
This is broken for unknown reasons since 4.14.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
tools/python/scripts/convert-legacy-stream | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/python/scripts/convert-legacy-stream b/tools/python/scripts/convert-legacy-stream
index ca93a93848..a04c6e4165 100755
--- a/tools/python/scripts/convert-legacy-stream
+++ b/tools/python/scripts/convert-legacy-stream
@@ -163,7 +163,7 @@ def write_libxc_hvm_params(params):
raise RuntimeError("Expected even length list of hvm parameters")
write_record(libxc.REC_TYPE_hvm_params,
- pack(libxc.HVM_PARAMS_FORMAT, len(params) / 2, 0),
+ pack(libxc.HVM_PARAMS_FORMAT, len(params) // 2, 0),
pack("Q" * len(params), *params))
def write_libxc_static_data_end():
@@ -264,8 +264,8 @@ def read_pv_extended_info(vm):
(so_far - total_length, ))
def read_pv_p2m_frames(vm):
- fpp = 4096 / vm.width
- p2m_frame_len = (vm.p2m_size - 1) / fpp + 1
+ fpp = 4096 // vm.width
+ p2m_frame_len = (vm.p2m_size - 1) // fpp + 1
info("P2M frames: fpp %d, p2m_frame_len %d" % (fpp, p2m_frame_len))
write_libxc_pv_p2m_frames(vm, unpack_ulongs(p2m_frame_len))
@@ -405,7 +405,7 @@ def read_chunks(vm):
(max_id, legacy.MAX_VCPU_ID))
vm.max_vcpu_id = max_id
- bitmap = unpack_exact("Q" * ((max_id/64) + 1))
+ bitmap = unpack_exact("Q" * ((max_id//64) + 1))
for idx, word in enumerate(bitmap):
bit_idx = 0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1] tools: use integer division in convert-legacy-stream
2021-06-18 9:31 [PATCH v1] tools: use integer division in convert-legacy-stream Olaf Hering
@ 2021-06-18 9:42 ` Andrew Cooper
2021-06-18 9:54 ` Olaf Hering
2021-06-18 15:33 ` Olaf Hering
0 siblings, 2 replies; 4+ messages in thread
From: Andrew Cooper @ 2021-06-18 9:42 UTC (permalink / raw)
To: Olaf Hering, xen-devel
Cc: Marek Marczykowski-Górecki, Ian Jackson, Wei Liu
On 18/06/2021 10:31, Olaf Hering wrote:
> A single slash gives a float, a double slash gives an int.
>
> bitmap = unpack_exact("Q" * ((max_id/64) + 1))
> TypeError: can't multiply sequence by non-int of type 'float'
>
> This is broken for unknown reasons since 4.14.
:(
This is a Py2 vs Py3 difference.
To not break Py2.7, we need "from __future__ import division" at the top
of the script, but I doubt this is the only script impacted.
>
> Signed-off-by: Olaf Hering <olaf@aepfle.de>
> ---
> tools/python/scripts/convert-legacy-stream | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
>
> diff --git a/tools/python/scripts/convert-legacy-stream b/tools/python/scripts/convert-legacy-stream
> index ca93a93848..a04c6e4165 100755
> --- a/tools/python/scripts/convert-legacy-stream
> +++ b/tools/python/scripts/convert-legacy-stream
> @@ -163,7 +163,7 @@ def write_libxc_hvm_params(params):
> raise RuntimeError("Expected even length list of hvm parameters")
>
> write_record(libxc.REC_TYPE_hvm_params,
> - pack(libxc.HVM_PARAMS_FORMAT, len(params) / 2, 0),
> + pack(libxc.HVM_PARAMS_FORMAT, len(params) // 2, 0),
> pack("Q" * len(params), *params))
>
> def write_libxc_static_data_end():
> @@ -264,8 +264,8 @@ def read_pv_extended_info(vm):
> (so_far - total_length, ))
>
> def read_pv_p2m_frames(vm):
> - fpp = 4096 / vm.width
> - p2m_frame_len = (vm.p2m_size - 1) / fpp + 1
> + fpp = 4096 // vm.width
> + p2m_frame_len = (vm.p2m_size - 1) // fpp + 1
>
> info("P2M frames: fpp %d, p2m_frame_len %d" % (fpp, p2m_frame_len))
> write_libxc_pv_p2m_frames(vm, unpack_ulongs(p2m_frame_len))
> @@ -405,7 +405,7 @@ def read_chunks(vm):
> (max_id, legacy.MAX_VCPU_ID))
>
> vm.max_vcpu_id = max_id
> - bitmap = unpack_exact("Q" * ((max_id/64) + 1))
> + bitmap = unpack_exact("Q" * ((max_id//64) + 1))
While you're changing this, could we make it (max_id // 64) to fix the
style (which I clearly messed up first time around).
~Andrew
>
> for idx, word in enumerate(bitmap):
> bit_idx = 0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] tools: use integer division in convert-legacy-stream
2021-06-18 9:42 ` Andrew Cooper
@ 2021-06-18 9:54 ` Olaf Hering
2021-06-18 15:33 ` Olaf Hering
1 sibling, 0 replies; 4+ messages in thread
From: Olaf Hering @ 2021-06-18 9:54 UTC (permalink / raw)
To: Andrew Cooper
Cc: xen-devel, Marek Marczykowski-Górecki, Ian Jackson, Wei Liu
[-- Attachment #1: Type: text/plain, Size: 329 bytes --]
Am Fri, 18 Jun 2021 10:42:58 +0100
schrieb Andrew Cooper <andrew.cooper3@citrix.com>:
> This is a Py2 vs Py3 difference.
Indeed, my build wrapper changes every 'env python' to 'python3.4' in 4.14+ builds.
That explains why it happens to work with my 4.13 builds, which changes every 'env python' to 'python2.7'.
Olaf
[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] tools: use integer division in convert-legacy-stream
2021-06-18 9:42 ` Andrew Cooper
2021-06-18 9:54 ` Olaf Hering
@ 2021-06-18 15:33 ` Olaf Hering
1 sibling, 0 replies; 4+ messages in thread
From: Olaf Hering @ 2021-06-18 15:33 UTC (permalink / raw)
To: Andrew Cooper
Cc: xen-devel, Marek Marczykowski-Górecki, Ian Jackson, Wei Liu
[-- Attachment #1: Type: text/plain, Size: 409 bytes --]
Am Fri, 18 Jun 2021 10:42:58 +0100
schrieb Andrew Cooper <andrew.cooper3@citrix.com>:
> This is a Py2 vs Py3 difference.
This script is not ready for python 3.
At a first glance it is the usual type confusion.
It seems the type 'bytearray' exists in both variants.
Perhaps stream_read() should return such an object, instead of either 'str' or 'bytes'.
I'm sure there are more pitfalls.
Olaf
[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-18 15:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 9:31 [PATCH v1] tools: use integer division in convert-legacy-stream Olaf Hering
2021-06-18 9:42 ` Andrew Cooper
2021-06-18 9:54 ` Olaf Hering
2021-06-18 15:33 ` Olaf Hering
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).