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

Commit1dadc8a

Browse files
committed
extracted TryConvertArgument from MethodBinder.TryConvertArguments
1 parent04b77d9 commit1dadc8a

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

‎src/runtime/methodbinder.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -371,43 +371,57 @@ static object[] TryConvertArguments(ParameterInfo[] pi, bool paramsArray,
371371
continue;
372372
}
373373

374+
varparameter=pi[paramIndex];
374375
IntPtrop=(arrayStart==paramIndex)
375376
// map remaining Python arguments to a tuple since
376377
// the managed function accepts it - hopefully :]
377378
?Runtime.PyTuple_GetSlice(args,arrayStart,pyArgCount)
378379
:Runtime.PyTuple_GetItem(args,paramIndex);
379380

380-
varparameter=pi[paramIndex];
381-
382-
varclrtype=TryComputeClrArgumentType(parameter.ParameterType,op,needsResolution:needsResolution);
383-
if(clrtype==null)
381+
boolisOut;
382+
if(!TryConvertArgument(op,parameter.ParameterType,needsResolution,outmargs[paramIndex],outisOut))
384383
{
385384
returnnull;
386385
}
387386

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-
}
399387
if(arrayStart==paramIndex)
400388
{
389+
// TODO: is this a bug? Should this happen even if the conversion fails?
401390
// GetSlice() creates a new reference but GetItem()
402391
// returns only a borrow reference.
403392
Runtime.XDecref(op);
404393
}
405-
margs[paramIndex]=arg;
394+
395+
if(parameter.IsOut||isOut)
396+
{
397+
outs++;
398+
}
406399
}
407400

408401
returnmargs;
409402
}
410403

404+
staticboolTryConvertArgument(IntPtrop,TypeparameterType,boolneedsResolution,
405+
outobjectarg,outboolisOut)
406+
{
407+
arg=null;
408+
isOut=false;
409+
varclrtype=TryComputeClrArgumentType(parameterType,op,needsResolution:needsResolution);
410+
if(clrtype==null)
411+
{
412+
returnfalse;
413+
}
414+
415+
if(!Converter.ToManaged(op,clrtype,outarg,false))
416+
{
417+
Exceptions.Clear();
418+
returnfalse;
419+
}
420+
421+
isOut=clrtype.IsByRef;
422+
returntrue;
423+
}
424+
411425
staticTypeTryComputeClrArgumentType(TypeparameterType,IntPtrargument,boolneedsResolution)
412426
{
413427
// this logic below handles cases when multiple overloading methods

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp