-
Notifications
You must be signed in to change notification settings - Fork 752
implement list codec #1084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement list codec #1084
Changes from 1 commit
b500aa1
f80ae87
765b6a2
98ce49c
b827f5a
224df0e
1600fdc
c43446e
32fa32d
dfc814b
f025cd1
24d78c3
ebcfa30
5cc575d
17c47a7
e8cc3d8
080dbc3
059ab08
432c09e
3043201
57d7779
7fb5915
085c665
bf2d038
07ee9fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,11 @@ public T this[int index] | |
{ | ||
get | ||
{ | ||
IntPtr item = Runtime.PySequence_GetItem(pyObject.Handle, index); | ||
object obj; | ||
var item = Runtime.PyList_GetItem(pyObject.Handle, index); | ||
var pyItem = new PyObject(item); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dispose this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lostmsu again I thought the point of making it IDisposable was that the finalizer would take care of that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap it by using statement is better. If you knew it's no use anymore you should dispose it manually instead of waiting for the auto collection to do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using (var pyItem = new PyObject(item)) { } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @koubaa this still needs a fix. With C# 8+ which we use now, it should just be |
||
|
||
if (!Converter.ToManaged(item, typeof(T), out obj, true)) | ||
{ | ||
Runtime.XDecref(item); | ||
if (!Converter.ToManaged(pyItem.Handle, typeof(T), out object obj, true)) | ||
Runtime.CheckExceptionOccurred(); | ||
} | ||
|
||
return (T)obj; | ||
} | ||
|
@@ -31,10 +28,10 @@ public T this[int index] | |
if (pyItem == IntPtr.Zero) | ||
throw new Exception("failed to set item"); | ||
koubaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var result = Runtime.PySequence_SetItem(pyObject.Handle, index, pyItem); | ||
var result = Runtime.PyList_SetItem(pyObject.Handle, index, pyItem); | ||
Runtime.XDecref(pyItem); | ||
if (result == -1) | ||
throw new Exception("failed to set item"); | ||
Runtime.CheckExceptionOccurred(); | ||
} | ||
} | ||
|
||
|
@@ -46,7 +43,7 @@ public int IndexOf(T item) | |
public void Insert(int index, T item) | ||
{ | ||
if (IsReadOnly) | ||
throw new NotImplementedException(); | ||
throw new InvalidOperationException("Collection is read-only"); | ||
|
||
IntPtr pyItem = Converter.ToPython(item, typeof(T)); | ||
if (pyItem == IntPtr.Zero) | ||
|
@@ -55,7 +52,7 @@ public void Insert(int index, T item) | |
var result = Runtime.PyList_Insert(pyObject.Reference, index, pyItem); | ||
Runtime.XDecref(pyItem); | ||
koubaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (result == -1) | ||
throw new Exception("failed to insert item"); | ||
Runtime.CheckExceptionOccurred(); | ||
} | ||
|
||
public void RemoveAt(int index) | ||
|
Uh oh!
There was an error while loading. Please reload this page.