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/03/01 04:03:17 UTC

[09/22] lucy-clownfish git commit: Incref `decremented` args in Py glue.

Incref `decremented` args in Py glue.

For args that are specified as `decremented` in the Clownfish method
signature, add an INCREF in the glue code.


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

Branch: refs/heads/master
Commit: a9daf3cf7bb82ee5c9f51a83b5f3d166fb35de6d
Parents: 4cdfb56
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Feb 2 15:44:10 2016 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Feb 24 15:32:30 2016 -0800

----------------------------------------------------------------------
 compiler/src/CFCPyMethod.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a9daf3cf/compiler/src/CFCPyMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPyMethod.c b/compiler/src/CFCPyMethod.c
index 8d6adfb..5464dbb 100644
--- a/compiler/src/CFCPyMethod.c
+++ b/compiler/src/CFCPyMethod.c
@@ -427,18 +427,43 @@ S_meth_top(CFCMethod *method) {
     }
 }
 
+static char*
+S_gen_arg_increfs(CFCParamList *param_list, int first_tick) {
+    CFCVariable **vars = CFCParamList_get_variables(param_list);
+    int num_vars = CFCParamList_num_vars(param_list);
+    char *content = CFCUtil_strdup("");
+    for (int i = first_tick;i < num_vars; i++) {
+        CFCType *type = CFCVariable_get_type(vars[i]);
+        if (CFCType_decremented(type)) {
+            const char *name = CFCVariable_get_name(vars[i]);
+            const char *specifier = CFCType_get_specifier(type);
+            char pattern[] =
+                "    %s_ARG = (%s*)CFISH_INCREF(%s_ARG);\n";
+            char *incref = CFCUtil_sprintf(pattern, name, specifier, name);
+            content = CFCUtil_cat(content, incref, NULL);
+            FREEMEM(incref);
+        }
+    }
+    return content;
+}
+
 char*
 CFCPyMethod_wrapper(CFCMethod *method, CFCClass *invoker) {
+    CFCParamList *param_list  = CFCMethod_get_param_list(method);
     char *meth_sym   = CFCMethod_full_method_sym(method, invoker);
     char *meth_top   = S_meth_top(method);
+    char *increfs    = S_gen_arg_increfs(param_list, 1);
 
     char pattern[] =
         "static PyObject*\n"
         "S_%s%s"
+        "%s" // increfs
         "    Py_RETURN_NONE;\n"
         "}\n"
         ;
-    char *wrapper = CFCUtil_sprintf(pattern, meth_sym, meth_top);
+    char *wrapper = CFCUtil_sprintf(pattern, meth_sym, meth_top,
+                                    increfs);
+    FREEMEM(increfs);
     FREEMEM(meth_sym);
     FREEMEM(meth_top);