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
respond to PR review
  • Loading branch information
koubaa committed Sep 18, 2020
commit 945db38af4b5f53f4a454283c77d0500ab378e91
2 changes: 1 addition & 1 deletion src/runtime/pyansistring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public PyAnsiString(IntPtr ptr) : base(ptr)

private static IntPtr FromObject(PyObject o)
{
if (!IsStringType(o))
if (o == null || !IsStringType(o))
{
throw new ArgumentException("object is not a string");
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pydict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public PyDict() : base(Runtime.PyDict_New())
/// </remarks>
public PyDict(PyObject o) : base(o.obj)
{
Runtime.XIncref(o.obj);
if (!IsDictType(o))
{
throw new ArgumentException("object is not a dict");
}
Runtime.XIncref(o.obj);
}


Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pyfloat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public PyFloat(double value) : base(FromDouble(value))

private static IntPtr FromObject(PyObject o)
{
if (!IsFloatType(o))
if (o == null || !IsFloatType(o))
{
throw new ArgumentException("object is not a float");
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pyint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public PyInt(PyObject o) : base(FromObject(o))

private static IntPtr FromObject(PyObject o)
{
if (!IsIntType(o))
if (o == null || !IsIntType(o))
{
throw new ArgumentException("object is not an int");
}
Expand Down
23 changes: 20 additions & 3 deletions src/runtime/pyiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public PyIter(IntPtr ptr) : base(ptr)

private static IntPtr FromObject(PyObject iterable)
{
if (iterable == null)
{
throw new NullReferenceException();
Comment thread
koubaa marked this conversation as resolved.
Outdated
}
IntPtr val = Runtime.PyObject_GetIter(iterable.obj);
if (val == IntPtr.Zero)
{
Expand All @@ -35,14 +39,27 @@ private static IntPtr FromObject(PyObject iterable)
return val;
}


/// <summary>
/// PyIter Constructor
/// PyIter factory function.
/// </summary>
/// <remarks>
/// Creates a Python iterator from an iterable. Like doing "iter(iterable)" in python.
/// Create a new PyIter from a given iterable. Like doing "iter(iterable)" in python.
/// </remarks>
public PyIter(PyObject iterable) : base(FromObject(iterable))
/// <param name="iterable"></param>
/// <returns></returns>
public static PyIter GetIter(PyObject iterable)
{
if (iterable == null)
{
throw new NullReferenceException();
}
IntPtr val = Runtime.PyObject_GetIter(iterable.obj);
if (val == IntPtr.Zero)
{
throw new PythonException();
}
return new PyIter(val);
}

protected override void Dispose(bool disposing)
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/pylist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal PyList(BorrowedReference reference) : base(reference) { }

private static IntPtr FromObject(PyObject o)
{
if (!IsListType(o))
if (o == null || !IsListType(o))
{
throw new ArgumentException("object is not a list");
}
Expand Down Expand Up @@ -76,6 +76,7 @@ private static IntPtr FromArray(PyObject[] items)
int r = Runtime.PyList_SetItem(val, i, ptr);
if (r < 0)
{
Runtime.Py_DecRef(val);
throw new PythonException();
}
Comment thread
koubaa marked this conversation as resolved.
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pylong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public PyLong(PyObject o) : base(FromObject(o))

private static IntPtr FromObject(PyObject o)
{
if (!IsLongType(o))
if (o == null || !IsLongType(o))
{
throw new ArgumentException("object is not a long");
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pyobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public PyObject GetIterator()
/// </remarks>
public IEnumerator GetEnumerator()
{
return new PyIter(this);
return PyIter.GetIter(this);
}


Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pystring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PyString(IntPtr ptr) : base(ptr)

private static IntPtr FromObject(PyObject o)
{
if (!IsStringType(o))
if (o == null || !IsStringType(o))
{
throw new ArgumentException("object is not a string");
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pytuple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal PyTuple(BorrowedReference reference) : base(reference) { }

private static IntPtr FromObject(PyObject o)
{
if (!IsTupleType(o))
if (o == null || !IsTupleType(o))
{
throw new ArgumentException("object is not a tuple");
}
Expand Down