@@ -371,43 +371,57 @@ static object[] TryConvertArguments(ParameterInfo[] pi, bool paramsArray,
371
371
continue ;
372
372
}
373
373
374
+ var parameter = pi [ paramIndex ] ;
374
375
IntPtr op = ( arrayStart == paramIndex )
375
376
// map remaining Python arguments to a tuple since
376
377
// the managed function accepts it - hopefully :]
377
378
? Runtime . PyTuple_GetSlice ( args , arrayStart , pyArgCount )
378
379
: Runtime . PyTuple_GetItem ( args , paramIndex ) ;
379
380
380
- var parameter = pi [ paramIndex ] ;
381
-
382
- var clrtype = TryComputeClrArgumentType ( parameter . ParameterType , op , needsResolution : needsResolution ) ;
383
- if ( clrtype == null )
381
+ bool isOut ;
382
+ if ( ! TryConvertArgument ( op , parameter . ParameterType , needsResolution , out margs [ paramIndex ] , out isOut ) )
384
383
{
385
384
return null ;
386
385
}
387
386
388
- if ( parameter . IsOut || clrtype . IsByRef )
389
- {
390
- outs ++ ;
391
- }
392
-
393
- object arg ;
394
- if ( ! Converter . ToManaged ( op , clrtype , out arg , false ) )
395
- {
396
- Exceptions . Clear ( ) ;
397
- return null ;
398
- }
399
387
if ( arrayStart == paramIndex )
400
388
{
389
+ // TODO: is this a bug? Should this happen even if the conversion fails?
401
390
// GetSlice() creates a new reference but GetItem()
402
391
// returns only a borrow reference.
403
392
Runtime . XDecref ( op ) ;
404
393
}
405
- margs [ paramIndex ] = arg ;
394
+
395
+ if ( parameter . IsOut || isOut )
396
+ {
397
+ outs ++ ;
398
+ }
406
399
}
407
400
408
401
return margs ;
409
402
}
410
403
404
+ static bool TryConvertArgument ( IntPtr op , Type parameterType , bool needsResolution ,
405
+ out object arg , out bool isOut )
406
+ {
407
+ arg = null ;
408
+ isOut = false ;
409
+ var clrtype = TryComputeClrArgumentType ( parameterType , op , needsResolution : needsResolution ) ;
410
+ if ( clrtype == null )
411
+ {
412
+ return false ;
413
+ }
414
+
415
+ if ( ! Converter . ToManaged ( op , clrtype , out arg , false ) )
416
+ {
417
+ Exceptions . Clear ( ) ;
418
+ return false ;
419
+ }
420
+
421
+ isOut = clrtype . IsByRef ;
422
+ return true ;
423
+ }
424
+
411
425
static Type TryComputeClrArgumentType ( Type parameterType , IntPtr argument , bool needsResolution )
412
426
{
413
427
// this logic below handles cases when multiple overloading methods
0 commit comments