From 494a3724724903646b3a10f5bc0deb1f15a97a9c Mon Sep 17 00:00:00 2001 From: Tom Minka <8955276+tminka@users.noreply.github.com> Date: Thu, 21 Jan 2021 16:04:33 +0000 Subject: [PATCH 1/2] Disable implicit conversion from PyFloat to uint64 --- src/runtime/converter.cs | 8 ++------ src/tests/test_conversion.py | 5 ++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/runtime/converter.cs b/src/runtime/converter.cs index aa4ed6a80..d58612f62 100644 --- a/src/runtime/converter.cs +++ b/src/runtime/converter.cs @@ -701,16 +701,12 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo op = value; if (Runtime.PyObject_TYPE(value) != Runtime.PyLongType) { - op = Runtime.PyNumber_Long(value); - if (op == IntPtr.Zero) - { - goto convert_error; - } + goto type_error; } ulong num = Runtime.PyLong_AsUnsignedLongLong(op); if (num == ulong.MaxValue && Exceptions.ErrorOccurred()) { - goto overflow; + goto convert_error; } result = num; return true; diff --git a/src/tests/test_conversion.py b/src/tests/test_conversion.py index 6b152025d..3b290b947 100644 --- a/src/tests/test_conversion.py +++ b/src/tests/test_conversion.py @@ -382,7 +382,10 @@ def test_uint64_conversion(): ob.UInt64Field = System.UInt64(0) assert ob.UInt64Field == 0 - with pytest.raises(ValueError): + with pytest.raises(TypeError): + ConversionTest().UInt64Field = 0.5 + + with pytest.raises(TypeError): ConversionTest().UInt64Field = "spam" with pytest.raises(TypeError): From 7bf5c4d7bc24038547fe78aaf8be20136b346c8d Mon Sep 17 00:00:00 2001 From: Tom Minka <8955276+tminka@users.noreply.github.com> Date: Thu, 21 Jan 2021 20:30:22 +0000 Subject: [PATCH 2/2] Omitted redundant type check --- src/runtime/converter.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/runtime/converter.cs b/src/runtime/converter.cs index d58612f62..62e091d31 100644 --- a/src/runtime/converter.cs +++ b/src/runtime/converter.cs @@ -698,12 +698,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo case TypeCode.UInt64: { - op = value; - if (Runtime.PyObject_TYPE(value) != Runtime.PyLongType) - { - goto type_error; - } - ulong num = Runtime.PyLong_AsUnsignedLongLong(op); + ulong num = Runtime.PyLong_AsUnsignedLongLong(value); if (num == ulong.MaxValue && Exceptions.ErrorOccurred()) { goto convert_error; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy