Skip to content

Commit aaafea8

Browse files
committed
fixed crash in MethodBinder.Bind when MethodInfo to invoke is passed explicitly
1 parent 7f894fa commit aaafea8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/runtime/methodbinder.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Concurrent;
4+
using System.Collections.Generic;
45
using System.Diagnostics;
56
using System.Linq;
67
using System.Reflection;
@@ -169,16 +170,16 @@ internal MethodBase[] GetMethods()
169170
// I'm sure this could be made more efficient.
170171
list.Sort(new MethodSorter());
171172
methods = (MethodBase[])list.ToArray(typeof(MethodBase));
172-
pyArgumentConverter = this.GetArgumentConverter();
173+
pyArgumentConverter = GetArgumentConverter(this.methods);
173174
init = true;
174175
}
175176
return methods;
176177
}
177178

178-
IPyArgumentConverter GetArgumentConverter() {
179+
static IPyArgumentConverter GetArgumentConverter(IEnumerable<MethodBase> methods) {
179180
IPyArgumentConverter converter = null;
180181
Type converterType = null;
181-
foreach (MethodBase method in this.methods)
182+
foreach (MethodBase method in methods)
182183
{
183184
PyArgConverterAttribute attribute = TryGetArgConverter(method.DeclaringType);
184185
if (converterType == null)
@@ -344,14 +345,17 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
344345

345346
var pynargs = (int)Runtime.PyTuple_Size(args);
346347
var isGeneric = false;
348+
IPyArgumentConverter argumentConverter;
347349
if (info != null)
348350
{
349351
_methods = new MethodBase[1];
350352
_methods.SetValue(info, 0);
353+
argumentConverter = GetArgumentConverter(_methods);
351354
}
352355
else
353356
{
354357
_methods = GetMethods();
358+
argumentConverter = this.pyArgumentConverter;
355359
}
356360

357361
// TODO: Clean up
@@ -370,7 +374,8 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
370374
continue;
371375
}
372376
var outs = 0;
373-
var margs = this.TryConvertArguments(pi, paramsArray, args, pynargs, kwargDict, defaultArgList,
377+
var margs = TryConvertArguments(pi, paramsArray, argumentConverter,
378+
args, pynargs, kwargDict, defaultArgList,
374379
needsResolution: _methods.Length > 1,
375380
outs: out outs);
376381

@@ -426,7 +431,8 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
426431
/// <param name="needsResolution"><c>true</c>, if overloading resolution is required</param>
427432
/// <param name="outs">Returns number of output parameters</param>
428433
/// <returns>An array of .NET arguments, that can be passed to a method.</returns>
429-
object[] TryConvertArguments(ParameterInfo[] pi, bool paramsArray,
434+
static object[] TryConvertArguments(ParameterInfo[] pi, bool paramsArray,
435+
IPyArgumentConverter argumentConverter,
430436
IntPtr args, int pyArgCount,
431437
Dictionary<string, IntPtr> kwargDict,
432438
ArrayList defaultArgList,
@@ -467,7 +473,7 @@ object[] TryConvertArguments(ParameterInfo[] pi, bool paramsArray,
467473
}
468474

469475
bool isOut;
470-
if (!this.pyArgumentConverter.TryConvertArgument(
476+
if (!argumentConverter.TryConvertArgument(
471477
op, parameter.ParameterType, needsResolution,
472478
out margs[paramIndex], out isOut))
473479
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy