Virgil Dupras avatar Virgil Dupras committed 549d56b

Fixed a bug where pyref arguments were over-decref'ed and made instances created through ObjP_classInstanceWithRef non-retaining.

Comments (0)

Files changed (3)

     TypeSpec(object, 'id', 'ObjP_obj_o2p(%s)', 'ObjP_obj_p2o(%s)'),
     TypeSpec(list, 'NSArray *', 'ObjP_list_o2p(%s)', 'ObjP_list_p2o(%s)'),
     TypeSpec(dict, 'NSDictionary *', 'ObjP_dict_o2p(%s)', 'ObjP_dict_p2o(%s)'),
-    TypeSpec(pyref, 'PyObject *', '%s', '%s'),
+    TypeSpec(pyref, 'PyObject *', 'ObjP_pyref_o2p(%s)', '%s'),
 PYTYPE2SPEC = {ts.pytype: ts for ts in TYPE_SPECS}
 PyObject* ObjP_list_o2p(NSArray *list);
 NSDictionary* ObjP_dict_p2o(PyObject *pDict);
 PyObject* ObjP_dict_o2p(NSDictionary *dict);
+PyObject* ObjP_pyref_o2p(PyObject *pyref);
 #import "ObjP.h"
+/* Returns the python class `className` in `inModule`.
+   If inModule is nil, look for class in __main__.
 PyObject* ObjP_findPythonClass(NSString *className, NSString *inModule)
     PyObject *pModule, *pClass;
     return pClass;
+/* Return a class `className` instantiated with `ref` as a reference objc class.
+   `ref` will *not* be retained by the python class.
 PyObject* ObjP_classInstanceWithRef(NSString *className, NSString *inModule, id ref)
     PyObject *pClass, *pRefCapsule, *pResult;
     pRefCapsule = PyCapsule_New(ref, NULL, NULL);
-    pResult = PyObject_CallFunctionObjArgs(pClass, pRefCapsule, NULL);
+    pResult = PyObject_CallFunctionObjArgs(pClass, pRefCapsule, Py_False, NULL);
     return pResult;
+/* We can use pyref as is, but in all other o2p code, we expect to have to decref the result,
+   so in pyrefs case, we have to incref our pyref before returning it.
+PyObject* ObjP_pyref_o2p(PyObject *pyref)
+    Py_INCREF(pyref);
+    return pyref;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.