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

Commit4d1e09a

Browse files
filmorlostmsu
andauthored
fixed ForbidPythonThreadsAttribute being ignored in certain scenarios (#1815)
Co-authored-by: Victor Nova <lost@losttech.software>
1 parenta6e4353 commit4d1e09a

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

‎src/runtime/Types/MethodObject.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal class MethodObject : ExtensionType
2727
internalPyString?doc;
2828
internalMaybeTypetype;
2929

30-
publicMethodObject(MaybeTypetype,stringname,MethodBase[]info,boolallow_threads=MethodBinder.DefaultAllowThreads)
30+
publicMethodObject(MaybeTypetype,stringname,MethodBase[]info,boolallow_threads)
3131
{
3232
this.type=type;
3333
this.name=name;
@@ -45,6 +45,11 @@ public MethodObject(MaybeType type, string name, MethodBase[] info, bool allow_t
4545
binder.allow_threads=allow_threads;
4646
}
4747

48+
publicMethodObject(MaybeTypetype,stringname,MethodBase[]info)
49+
:this(type,name,info,allow_threads:AllowThreads(info))
50+
{
51+
}
52+
4853
publicboolIsInstanceConstructor=>name=="__init__";
4954

5055
publicMethodObjectWithOverloads(MethodBase[]overloads)
@@ -206,5 +211,27 @@ public static NewReference tp_repr(BorrowedReference ob)
206211
varself=(MethodObject)GetManagedObject(ob)!;
207212
returnRuntime.PyString_FromString($"<method '{self.name}'>");
208213
}
214+
215+
staticboolAllowThreads(MethodBase[]methods)
216+
{
217+
boolhasAllowOverload=false,hasForbidOverload=false;
218+
foreach(varmethodinmethods)
219+
{
220+
boolforbidsThreads=method.GetCustomAttribute<ForbidPythonThreadsAttribute>(inherit:false)!=null;
221+
if(forbidsThreads)
222+
{
223+
hasForbidOverload=true;
224+
}
225+
else
226+
{
227+
hasAllowOverload=true;
228+
}
229+
}
230+
231+
if(hasAllowOverload&&hasForbidOverload)
232+
thrownewNotImplementedException("All method overloads currently must either allow or forbid Python threads together");
233+
234+
return!hasForbidOverload;
235+
}
209236
}
210237
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp