8000 Codecs: customize set of Py<->C# conversions via PyObjectConversions by lostmsu · Pull Request #1022 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Codecs: customize set of Py<->C# conversions via PyObjectConversions #1022

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

Merged
merged 17 commits into from
Feb 26, 2020
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
corrected reference counting in Codecs
  • Loading branch information
lostmsu committed Feb 21, 2020
commit 50a3822bf49f6e99a0b96a78b89af26fd32e0fcc
6 changes: 4 additions & 2 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ internal static IntPtr ToPython(object value, Type type)
if (Type.GetTypeCode(type) == TypeCode.Object && value.GetType() != typeof(object)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glad this comes before other builtin conversions but ultimately the built-in conversions should probably use this codec system internally.

var encoded = PyObjectConversions.TryEncode(value, type);
if (encoded != null) {
Runtime.XIncref(encoded.Handle);
return encoded.Handle;
result = encoded.Handle;
Runtime.XIncref(result);
encoded.Dispose();
return result;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/converterextensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ internal static bool TryDecode(IntPtr pyHandle, IntPtr pyType, Type targetType,
static Converter.TryConvertFromPythonDelegate GetDecoder(IntPtr sourceType, Type targetType)
{
IPyObjectDecoder decoder;
using (var pyType = new PyObject(sourceType))
using (var pyType = new PyObject(Runtime.SelfIncRef(sourceType)))
{
lock (decoders)
{
Expand Down
0