Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix issues
  • Loading branch information
koubaa committed Sep 20, 2020
commit 8d74e1c3488244a626c951b56b700f1804d14737
22 changes: 2 additions & 20 deletions src/runtime/pyiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@ public PyIter(IntPtr ptr) : base(ptr)
{
}

private static IntPtr FromObject(PyObject iterable)
{
if (iterable == null)
{
throw new NullReferenceException();
}
IntPtr val = Runtime.PyObject_GetIter(iterable.obj);
if (val == IntPtr.Zero)
{
throw new PythonException();
}
return val;
}


/// <summary>
/// PyIter factory function.
/// </summary>
Expand All @@ -52,13 +37,10 @@ public static PyIter GetIter(PyObject iterable)
{
if (iterable == null)
{
throw new NullReferenceException();
throw new ArgumentNullException();
}
IntPtr val = Runtime.PyObject_GetIter(iterable.obj);
if (val == IntPtr.Zero)
{
throw new PythonException();
}
PythonException.ThrowIfIsNull(val);
return new PyIter(val);
}

Expand Down
3 changes: 2 additions & 1 deletion src/runtime/pythonexception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,11 @@ internal static void ThrowIfIsNull(BorrowedReference reference)
}
}

public static void ThrowIfIsNotZero(int value)
public static void ThrowIfIsNotZero(int value, Action onBeforeThrow = null)
{
if (value != 0)
{
onBeforeThrow?.Invoke();
Comment thread
koubaa marked this conversation as resolved.
Outdated
throw new PythonException();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pytuple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static IntPtr FromArray(PyObject[] items)
IntPtr ptr = items[i].obj;
Runtime.XIncref(ptr);
int res = Runtime.PyTuple_SetItem(val, i, ptr);
PythonException.ThrowIfIsNotZero(res);
PythonException.ThrowIfIsNotZero(res, () => Runtime.Py_DecRef(val));
}
return val;
}
Expand Down