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 2015/10/06 03:46:07 UTC

[1/2] lucy-clownfish git commit: Nil-check nullable retvals from Go.

Repository: lucy-clownfish
Updated Branches:
  refs/heads/master bc67c0695 -> 6dc5deb06


Nil-check nullable retvals from Go.

Type assertions in Go for interfaces fail on nil, so switch to checking
for nil then returning nil for nullable method return values.  Only
perform the type assertion when non-nil, which is guaranteed to succeed
unless there is a bug in the method implementation.


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

Branch: refs/heads/master
Commit: 17fdbba7b1d53df6f84556d70d32dfd1c88144bd
Parents: bc67c06
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Oct 5 18:41:45 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Oct 5 18:41:45 2015 -0700

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


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/17fdbba7/compiler/src/CFCGoFunc.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoFunc.c b/compiler/src/CFCGoFunc.c
index 1d94f04..83b6775 100644
--- a/compiler/src/CFCGoFunc.c
+++ b/compiler/src/CFCGoFunc.c
@@ -312,10 +312,28 @@ CFCGoFunc_return_statement(CFCParcel *parcel, CFCType *return_type,
             char *go_type_name = CFCGoTypeMap_go_type_name(return_type, parcel);
             char *pattern;
             if (CFCType_incremented(return_type)) {
-                pattern = "\treturn %sWRAPAny(unsafe.Pointer(retvalCF)).(%s)\n";
+                if (CFCType_nullable(return_type)) {
+                    pattern =
+                        "\tretvalGO := %sWRAPAny(unsafe.Pointer(retvalCF))\n"
+                        "\tif retvalGO == nil { return nil }\n"
+                        "\treturn retvalGO.(%s)\n"
+                        ;
+                }
+                else {
+                    pattern = "\treturn %sWRAPAny(unsafe.Pointer(retvalCF)).(%s)\n";
+                }
             }
             else {
-                pattern = "\treturn %sWRAPAny(unsafe.Pointer(C.cfish_inc_refcount(unsafe.Pointer(retvalCF)))).(%s)\n";
+                if (CFCType_nullable(return_type)) {
+                    pattern =
+                        "\tretvalGO := %sWRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(retvalCF))))\n"
+                        "\tif retvalGO == nil { return nil }\n"
+                        "\treturn retvalGO.(%s)\n"
+                        ;
+                }
+                else {
+                    pattern = "\treturn %sWRAPAny(unsafe.Pointer(C.cfish_inc_refcount(unsafe.Pointer(retvalCF)))).(%s)\n";
+                }
             }
             statement = CFCUtil_sprintf(pattern, clownfish_dot, go_type_name);
             FREEMEM(go_type_name);


[2/2] lucy-clownfish git commit: Merge branch 'CLOWNFISH-59-go-nullable-retvals'

Posted by ma...@apache.org.
Merge branch 'CLOWNFISH-59-go-nullable-retvals'

Fix nil-checking of `nullable` return values in Go 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/6dc5deb0
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/6dc5deb0
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/6dc5deb0

Branch: refs/heads/master
Commit: 6dc5deb06a2922ae253976f34d702795564bb121
Parents: bc67c06 17fdbba
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Oct 5 18:44:36 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Oct 5 18:44:36 2015 -0700

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