Repository: lucy-clownfish
Updated Branches:
  refs/heads/master a3992dd9d -> 8655f1881


Convert nullable args safely.

Use `GoToClownfish`, which can handle nil values safely, rather than the
lower-level `GoToString` etc. which are not nil-safe.


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

Branch: refs/heads/master
Commit: a121da47ff968f6acc45ab6cf491d01878174193
Parents: 1fc8c00
Author: Marvin Humphrey <[email protected]>
Authored: Mon Aug 3 16:50:49 2015 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Mon Aug 3 16:50:49 2015 -0700

----------------------------------------------------------------------
 compiler/src/CFCGoFunc.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a121da47/compiler/src/CFCGoFunc.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoFunc.c b/compiler/src/CFCGoFunc.c
index 2670034..bb6a261 100644
--- a/compiler/src/CFCGoFunc.c
+++ b/compiler/src/CFCGoFunc.c
@@ -87,17 +87,29 @@ S_prep_start(CFCParcel *parcel, const char *name, CFCClass 
*invoker,
 
         // Convert certain types and defer their destruction until after the
         // Clownfish call returns.
-        char *convertible = NULL;
-        if      (CFCType_cfish_string(type))  { convertible = "String"; }
-        else if (CFCType_cfish_vector(type))  { convertible = "Vector"; }
-        else if (CFCType_cfish_blob(type))    { convertible = "Blob"; }
-        else if (CFCType_cfish_hash(type))    { convertible = "Hash"; }
-        else                                  { continue; }
+        const char *class_var;
+        if (CFCType_cfish_string(type)) {
+            class_var = "CFISH_STRING";
+        }
+        else if (CFCType_cfish_vector(type)) {
+            class_var = "CFISH_VECTOR";
+        }
+        else if (CFCType_cfish_blob(type)) {
+            class_var = "CFISH_BLOB";
+        }
+        else if (CFCType_cfish_hash(type)) {
+            class_var = "CFISH_HASH";
+        }
+        else {
+            continue;
+        }
+        const char *struct_name = CFCType_get_specifier(type);
+        const char *nullable = CFCType_nullable(type) ? "true" : "false";
         char pattern[] =
-            "\t%sCF := (*C.cfish_%s)(%sGoTo%s(%s))\n";
-        char *conversion = CFCUtil_sprintf(pattern, go_name, convertible,
-                                           clownfish_dot, convertible,
-                                           go_name);
+            "\t%sCF := (*C.%s)(%sGoToClownfish(%s, unsafe.Pointer(C.%s), 
%s))\n";
+        char *conversion = CFCUtil_sprintf(pattern, go_name, struct_name,
+                                           clownfish_dot, go_name,
+                                           class_var, nullable);
         converted = CFCUtil_cat(converted, conversion, NULL);
         FREEMEM(conversion);
         if (CFCType_decremented(type)) {

Reply via email to