Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd87584b

Browse files
committed
Fix Primitive Conversion to Int
1 parented6ab18 commitd87584b

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

‎src/runtime/converter.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,12 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
688688
caseTypeCode.Int32:
689689
{
690690
// Python3 always use PyLong API
691-
nintnum=Runtime.PyLong_AsSignedSize_t(value);
691+
op=Runtime.PyNumber_Long(value);
692+
if(op==IntPtr.Zero&&Exceptions.ErrorOccurred())
693+
{
694+
gotoconvert_error;
695+
}
696+
nintnum=Runtime.PyLong_AsSignedSize_t(op);
692697
if(num==-1&&Exceptions.ErrorOccurred())
693698
{
694699
gotoconvert_error;
@@ -796,7 +801,12 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
796801

797802
caseTypeCode.Int16:
798803
{
799-
nintnum=Runtime.PyLong_AsSignedSize_t(value);
804+
op=Runtime.PyNumber_Long(value);
805+
if(op==IntPtr.Zero&&Exceptions.ErrorOccurred())
806+
{
807+
gotoconvert_error;
808+
}
809+
nintnum=Runtime.PyLong_AsSignedSize_t(op);
800810
if(num==-1&&Exceptions.ErrorOccurred())
801811
{
802812
gotoconvert_error;
@@ -827,7 +837,12 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
827837
}
828838
else
829839
{
830-
nintnum=Runtime.PyLong_AsSignedSize_t(value);
840+
op=Runtime.PyNumber_Long(value);
841+
if(op==IntPtr.Zero&&Exceptions.ErrorOccurred())
842+
{
843+
gotoconvert_error;
844+
}
845+
nintnum=Runtime.PyLong_AsSignedSize_t(op);
831846
if(num==-1&&Exceptions.ErrorOccurred())
832847
{
833848
gotoconvert_error;
@@ -839,7 +854,12 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
839854

840855
caseTypeCode.UInt16:
841856
{
842-
nintnum=Runtime.PyLong_AsSignedSize_t(value);
857+
op=Runtime.PyNumber_Long(value);
858+
if(op==IntPtr.Zero&&Exceptions.ErrorOccurred())
859+
{
860+
gotoconvert_error;
861+
}
862+
nintnum=Runtime.PyLong_AsSignedSize_t(op);
843863
if(num==-1&&Exceptions.ErrorOccurred())
844864
{
845865
gotoconvert_error;
@@ -854,7 +874,12 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
854874

855875
caseTypeCode.UInt32:
856876
{
857-
nuintnum=Runtime.PyLong_AsUnsignedSize_t(value);
877+
op=Runtime.PyNumber_Long(value);
878+
if(op==IntPtr.Zero&&Exceptions.ErrorOccurred())
879+
{
880+
gotoconvert_error;
881+
}
882+
nuintnum=Runtime.PyLong_AsUnsignedSize_t(op);
858883
if(num==unchecked((nuint)(-1))&&Exceptions.ErrorOccurred())
859884
{
860885
gotoconvert_error;
@@ -869,7 +894,12 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
869894

870895
caseTypeCode.UInt64:
871896
{
872-
ulongnum=Runtime.PyLong_AsUnsignedLongLong(value);
897+
op=Runtime.PyNumber_Long(value);
898+
if(op==IntPtr.Zero&&Exceptions.ErrorOccurred())
899+
{
900+
gotoconvert_error;
901+
}
902+
ulongnum=Runtime.PyLong_AsUnsignedLongLong(op);
873903
if(num==ulong.MaxValue&&Exceptions.ErrorOccurred())
874904
{
875905
gotoconvert_error;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp