Skip to content

Another shot at #495 #503

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 10 commits into from
Jun 26, 2017
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
Prev Previous commit
Next Next commit
Trying out __init__
  • Loading branch information
Rickard Holmberg committed Jun 21, 2017
commit 7c9e8810716482e411153b3c36944ede7d16e6e5
17 changes: 3 additions & 14 deletions src/runtime/metatype.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;

namespace Python.Runtime
Expand Down Expand Up @@ -157,23 +157,12 @@ public static IntPtr tp_call(IntPtr tp, IntPtr args, IntPtr kw)
return IntPtr.Zero;
}

IntPtr py__init__ = Runtime.PyString_FromString("__init__");
IntPtr type = Runtime.PyObject_TYPE(obj);
IntPtr init = Runtime._PyType_Lookup(type, py__init__);
Runtime.XDecref(py__init__);
var init = Runtime.PyObject_GetAttrString(obj, "__init__");
Copy link
Member

Choose a reason for hiding this comment

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

You are leaking this reference.

Copy link
Contributor Author

@rickardraysearch rickardraysearch Jun 21, 2017

Choose a reason for hiding this comment

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

Oh. Should be fixed now.

Runtime.PyErr_Clear();

if (init != IntPtr.Zero)
{
IntPtr bound = Runtime.GetBoundArgTuple(obj, args);
if (bound == IntPtr.Zero)
{
Runtime.XDecref(obj);
return IntPtr.Zero;
}

IntPtr result = Runtime.PyObject_Call(init, bound, kw);
Runtime.XDecref(bound);
IntPtr result = Runtime.PyObject_Call(init, args, kw);

if (result == IntPtr.Zero)
{
Expand Down