Skip to content

Commit cd14a4a

Browse files
committed
fix NullReferenceException when using null on a argument list.
1 parent 5f21a85 commit cd14a4a

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/runtime/classderived.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ public static void InvokeCtor(IPythonDerivedType obj, string origCtorName, Objec
786786
PyObject[] pyargs = new PyObject[args.Length];
787787
for (int i = 0; i < args.Length; ++i)
788788
{
789-
pyargs[i] = new PyObject(Converter.ToPython(args[i], args[i].GetType()));
789+
pyargs[i] = new PyObject(Converter.ToPython(args[i], args[i]?.GetType()));
790790
disposeList.Add(pyargs[i]);
791791
}
792792

src/runtime/converter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ internal static IntPtr ToPython(Object value, Type type)
228228
{
229229
foreach (object o in (IEnumerable)value)
230230
{
231-
using (var p = new PyObject(ToPython(o, o.GetType())))
231+
using (var p = new PyObject(ToPython(o, o?.GetType())))
232232
resultlist.Append(p);
233233
}
234234
Runtime.Incref(resultlist.Handle);
@@ -962,7 +962,7 @@ public static class ConverterExtension
962962
{
963963
public static PyObject ToPython(this object o)
964964
{
965-
return new PyObject(Converter.ToPython(o, o.GetType()));
965+
return new PyObject(Converter.ToPython(o, o?.GetType()));
966966
}
967967
}
968968
}

src/runtime/pyobject.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ private void GetArgs(object[] inargs, out PyTuple args, out PyDict kwargs)
972972
}
973973
else
974974
{
975-
ptr = Converter.ToPython(inargs[i], inargs[i].GetType());
975+
ptr = Converter.ToPython(inargs[i], inargs[i]?.GetType());
976976
}
977977
if (Runtime.PyTuple_SetItem(argtuple, i, ptr) < 0)
978978
throw new PythonException();

src/runtime/pythonengine.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ public static KeywordArguments kw(params object[] kv)
487487
if (kv[i + 1] is PyObject)
488488
value = ((PyObject)kv[i + 1]).Handle;
489489
else
490-
value = Converter.ToPython(kv[i + 1], kv[i + 1].GetType());
490+
value = Converter.ToPython(kv[i + 1], kv[i + 1]?.GetType());
491491
if (Runtime.PyDict_SetItemString(dict.Handle, (string)kv[i], value) != 0)
492492
throw new ArgumentException(string.Format("Cannot add key '{0}' to dictionary.", (string)kv[i]));
493493
if (!(kv[i + 1] is PyObject))

0 commit comments

Comments
 (0)