You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2016/02/25 00:07:30 UTC

[03/20] lucy-clownfish git commit: Add wrappers for `To_Host` in Python bindings.

Add wrappers for `To_Host` in Python bindings.

Add NULL-safe wrappers, one of which is refcount neutral.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/2aab6efe
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/2aab6efe
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/2aab6efe

Branch: refs/heads/master
Commit: 2aab6efe2533e6e5b526cd6b408e24443c6d0f61
Parents: 991e4a5
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Jan 25 16:39:02 2016 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Feb 23 18:22:02 2016 -0800

----------------------------------------------------------------------
 runtime/python/cfext/CFBind.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2aab6efe/runtime/python/cfext/CFBind.h
----------------------------------------------------------------------
diff --git a/runtime/python/cfext/CFBind.h b/runtime/python/cfext/CFBind.h
index 85be7af..6637fca 100644
--- a/runtime/python/cfext/CFBind.h
+++ b/runtime/python/cfext/CFBind.h
@@ -23,6 +23,7 @@ extern "C" {
 
 #include "cfish_platform.h"
 #include "Python.h"
+#include "Clownfish/Obj.h"
 
 struct cfish_Class;
 struct cfish_String;
@@ -37,6 +38,34 @@ struct cfish_String;
 void
 CFBind_reraise_pyerr(struct cfish_Class *err_klass, struct cfish_String *mess);
 
+/** Null-safe invocation of Obj_To_Host.
+  */
+static CFISH_INLINE PyObject*
+CFBind_cfish_to_py(struct cfish_Obj *obj) {
+    if (obj != NULL) {
+        return (PyObject*)CFISH_Obj_To_Host(obj);
+    }
+    else {
+        Py_RETURN_NONE;
+    }
+}
+
+/** Perform the same conversion as `CFBind_cfish_to_py`, but ensure that the
+  * result is refcount-neutral, decrementing a refcount from `obj` and passing
+  * it along.
+  */
+static CFISH_INLINE PyObject*
+CFBind_cfish_to_py_zeroref(struct cfish_Obj *obj) {
+    if (obj != NULL) {
+        PyObject *result = (PyObject*)CFISH_Obj_To_Host(obj);
+        CFISH_DECREF(obj);
+        return result;
+    }
+    else {
+        return Py_None;
+    }
+}
+
 /* ParseTuple conversion routines for primitive numeric types.
  *
  * If the value of `input` is out of range for the an integer C type, an