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

Commit04b77d9

Browse files
committed
extracted TryConvertArguments from MethodBinder.Bind
1 parent0bb5a45 commit04b77d9

File tree

1 file changed

+67
-53
lines changed

1 file changed

+67
-53
lines changed

‎src/runtime/methodbinder.cs

Lines changed: 67 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
280280
// loop to find match, return invoker w/ or /wo error
281281
MethodBase[]_methods=null;
282282
varpynargs=(int)Runtime.PyTuple_Size(args);
283-
objectarg;
284283
varisGeneric=false;
285284
if(info!=null)
286285
{
@@ -301,59 +300,15 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
301300
}
302301
ParameterInfo[]pi=mi.GetParameters();
303302
ArrayListdefaultArgList;
304-
intarrayStart;
303+
boolparamsArray;
305304

306-
if(!MatchesArgumentCount(pynargs,pi,outarrayStart,outdefaultArgList)){
305+
if(!MatchesArgumentCount(pynargs,pi,outparamsArray,outdefaultArgList)){
307306
continue;
308307
}
309308
varouts=0;
310-
varmargs=newobject[pi.Length];
311-
312-
for(intparamIndex=0;paramIndex<pi.Length;paramIndex++)
313-
{
314-
if(paramIndex>=pynargs)
315-
{
316-
if(defaultArgList!=null)
317-
{
318-
margs[paramIndex]=defaultArgList[paramIndex-pynargs];
319-
}
320-
321-
continue;
322-
}
323-
324-
IntPtrop=(arrayStart==paramIndex)
325-
// map remaining Python arguments to a tuple since
326-
// the managed function accepts it - hopefully :]
327-
?Runtime.PyTuple_GetSlice(args,arrayStart,pynargs)
328-
:Runtime.PyTuple_GetItem(args,paramIndex);
329-
330-
varparameter=pi[paramIndex];
331-
332-
varclrtype=TryComputeClrArgumentType(parameter.ParameterType,op,needsResolution:_methods.Length>1);
333-
if(clrtype==null){
334-
margs=null;
335-
break;
336-
}
337-
338-
if(parameter.IsOut||clrtype.IsByRef)
339-
{
340-
outs++;
341-
}
342-
343-
if(!Converter.ToManaged(op,clrtype,outarg,false))
344-
{
345-
Exceptions.Clear();
346-
margs=null;
347-
break;
348-
}
349-
if(arrayStart==paramIndex)
350-
{
351-
// GetSlice() creates a new reference but GetItem()
352-
// returns only a borrow reference.
353-
Runtime.XDecref(op);
354-
}
355-
margs[paramIndex]=arg;
356-
}
309+
varmargs=TryConvertArguments(pi,paramsArray,args,pynargs,defaultArgList,
310+
needsResolution:_methods.Length>1,
311+
outs:outouts);
357312

358313
if(margs==null)
359314
{
@@ -394,6 +349,65 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
394349
returnnull;
395350
}
396351

352+
staticobject[]TryConvertArguments(ParameterInfo[]pi,boolparamsArray,
353+
IntPtrargs,intpyArgCount,
354+
ArrayListdefaultArgList,
355+
boolneedsResolution,
356+
outintouts)
357+
{
358+
outs=0;
359+
varmargs=newobject[pi.Length];
360+
intarrayStart=paramsArray?pi.Length-1:-1;
361+
362+
for(intparamIndex=0;paramIndex<pi.Length;paramIndex++)
363+
{
364+
if(paramIndex>=pyArgCount)
365+
{
366+
if(defaultArgList!=null)
367+
{
368+
margs[paramIndex]=defaultArgList[paramIndex-pyArgCount];
369+
}
370+
371+
continue;
372+
}
373+
374+
IntPtrop=(arrayStart==paramIndex)
375+
// map remaining Python arguments to a tuple since
376+
// the managed function accepts it - hopefully :]
377+
?Runtime.PyTuple_GetSlice(args,arrayStart,pyArgCount)
378+
:Runtime.PyTuple_GetItem(args,paramIndex);
379+
380+
varparameter=pi[paramIndex];
381+
382+
varclrtype=TryComputeClrArgumentType(parameter.ParameterType,op,needsResolution:needsResolution);
383+
if(clrtype==null)
384+
{
385+
returnnull;
386+
}
387+
388+
if(parameter.IsOut||clrtype.IsByRef)
389+
{
390+
outs++;
391+
}
392+
393+
objectarg;
394+
if(!Converter.ToManaged(op,clrtype,outarg,false))
395+
{
396+
Exceptions.Clear();
397+
returnnull;
398+
}
399+
if(arrayStart==paramIndex)
400+
{
401+
// GetSlice() creates a new reference but GetItem()
402+
// returns only a borrow reference.
403+
Runtime.XDecref(op);
404+
}
405+
margs[paramIndex]=arg;
406+
}
407+
408+
returnmargs;
409+
}
410+
397411
staticTypeTryComputeClrArgumentType(TypeparameterType,IntPtrargument,boolneedsResolution)
398412
{
399413
// this logic below handles cases when multiple overloading methods
@@ -465,12 +479,12 @@ static Type TryComputeClrArgumentType(Type parameterType, IntPtr argument, bool
465479
}
466480

467481
staticboolMatchesArgumentCount(intargumentCount,ParameterInfo[]parameters,
468-
outintparamsArrayStart,
482+
outboolparamsArray,
469483
outArrayListdefaultArgList)
470484
{
471485
defaultArgList=null;
472486
varmatch=false;
473-
paramsArrayStart=-1;
487+
paramsArray=false;
474488

475489
if(argumentCount==parameters.Length)
476490
{
@@ -491,7 +505,7 @@ static bool MatchesArgumentCount(int argumentCount, ParameterInfo[] parameters,
491505
{
492506
// This is a `foo(params object[] bar)` style method
493507
match=true;
494-
paramsArrayStart=parameters.Length-1;
508+
paramsArray=true;
495509
}
496510

497511
returnmatch;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp