8000 Fixed #296 Converter support for PyObject by rmadsen-ks · Pull Request #297 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Fixed #296 Converter support for PyObject #297

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 7 commits into from
Dec 16, 2016
Merged
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
Next Next commit
Fixed #296
  • Loading branch information
rmadsen-ks committed Nov 29, 2016
commit 7d132c9af495401497fdee0c3b39dfceaae7e9ea
17 changes: 15 additions & 2 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ internal static IntPtr ToPython<T>(T value)

internal static IntPtr ToPython(Object value, Type type)
{
if(value is PyObject)
{
IntPtr handle = ((PyObject)value).Handle;
Runtime.XIncref(handle);
return handle;
}
IntPtr result = IntPtr.Zero;

// Null always converts to None in Python.
Expand Down Expand Up @@ -265,8 +271,15 @@ internal static bool ToManaged(IntPtr value, Type type,
internal static bool ToManagedValue(IntPtr value, Type obType,
out Object result, bool setError)
{
// Common case: if the Python value is a wrapped managed object
// instance, just return the wrapped object.
if (obType == typeof(PyObject))
{
Runtime.XIncref(value); // PyObject() assumes ownership
result = new PyObject(value);
return true;
}

// Common case: if the Python value is a wrapped managed object
// instance, just return the wrapped object.
ManagedType mt = ManagedType.GetManagedObject(value);
result = null;

Expand Down
0