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
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
Fixed comment and removed \r from added source
  • Loading branch information
rmadsen-ks committed Dec 5, 2016
commit 335cd37c54a2837e677ed8e1a671300b2231ce2b
28 changes: 14 additions & 14 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ 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;
if(value is PyObject)
{
IntPtr handle = ((PyObject)value).Handle;
Runtime.XIncref(handle);
return handle;
}
IntPtr result = IntPtr.Zero;

Expand Down Expand Up @@ -271,15 +271,15 @@ internal static bool ToManaged(IntPtr value, Type type,
internal static bool ToManagedValue(IntPtr value, Type obType,
out Object result, bool setError)
{
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.
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
10 changes: 10 additions & 0 deletions src/runtime/pyobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ protected virtual void Dispose(bool disposing)
}
}

public long RefCount
{
get
{
if(!disposed)
return Runtime.Refcount(obj);
return -1;
}
}

public void Dispose()
{
Dispose(true);
Expand Down
28 changes: 14 additions & 14 deletions src/testing/callbacktest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public string Call_simpleDefaultArg_WithEmptyArgs(string moduleName)
return module.simpleDefaultArg();
}
}
}
//==========================================================================
// Tests calling from Python into C# and back into Python using a PyObject.
// SelfCallbackTest should be inherited from a Python class.
// Used in test_class.py / testCallback
//==========================================================================
public class SelfCallbackTest
{
public void Callback(Runtime.PyObject self)
{
using (Runtime.Py.GIL())
((dynamic)self).PyCallback(self);
}
}

//==========================================================================
// Tests calling from Python into C# and back into Python using a PyObject.
// SelfCallbackTest should be inherited by a Python class.
// Used in test_class.py / testCallback
//==========================================================================
public class SelfCallbackTest
{
public void Callback(Runtime.PyObject self)
{
using (Runtime.Py.GIL())
((dynamic)self).PyCallback(self);
}
}
}