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

Commit4f689a9

Browse files
committed
Take the GIL when converting enum to int
1 parenta6e4353 commit4f689a9

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

‎src/runtime/Util/OpsHelper.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,20 @@ internal static class EnumOps<T> where T : Enum
8282
{
8383
[ForbidPythonThreads]
8484
#pragma warning disableIDE1006// Naming Styles - must match Python
85-
publicstaticPyInt__int__(Tvalue)
85+
publicstaticPyInt__int__(Tvalue){
8686
#pragma warning restoreIDE1006// Naming Styles
87-
=>typeof(T).GetEnumUnderlyingType()==typeof(UInt64)
88-
?newPyInt(Convert.ToUInt64(value))
89-
:newPyInt(Convert.ToInt64(value));
87+
if(typeof(T).GetEnumUnderlyingType()==typeof(UInt64))
88+
{
89+
varconverted=Convert.ToUInt64(value);
90+
usingvar_=Py.GIL();
91+
returnnewPyInt(converted);
92+
}
93+
else
94+
{
95+
varconverted=Convert.ToInt64(value);
96+
usingvar_=Py.GIL();
97+
returnnewPyInt(converted);
98+
}
99+
}
90100
}
91101
}

‎tests/test_enum.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ def test_ulong_enum():
8787
assertTest.ULongEnum.Two==Test.ULongEnum(2)
8888

8989

90+
deftest_simple_enum_to_int():
91+
fromSystemimportDayOfWeek
92+
assertint(DayOfWeek.Sunday)==0
93+
94+
9095
deftest_long_enum_to_int():
9196
assertint(Test.LongEnum.Max)==9223372036854775807
9297
assertint(Test.LongEnum.Min)==-9223372036854775808
@@ -138,6 +143,7 @@ def test_enum_undefined_value():
138143
# explicitly permit undefined values
139144
Test.FieldTest().EnumField=Test.ShortEnum(20,True)
140145

146+
141147
deftest_enum_conversion():
142148
"""Test enumeration conversion."""
143149
ob=Test.FieldTest()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp