Consolidate invalid callback check

Use the same function to check for invalid callbacks as for method
XSUBs.

Ultimately, we need a mechanism to disable the autogeneration of XSUBs
and callbacks separately. For now, it seems safer to keep callbacks for
excluded methods.


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

Branch: refs/heads/master
Commit: a6568feb34244510b95e3eb03668b1baa4b46b6a
Parents: 2ba718b
Author: Nick Wellnhofer <[email protected]>
Authored: Thu Jul 31 14:15:34 2014 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Mon Sep 1 13:30:04 2014 +0200

----------------------------------------------------------------------
 compiler/src/CFCPerlMethod.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a6568feb/compiler/src/CFCPerlMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c
index 5efca7b..0dd7a98 100644
--- a/compiler/src/CFCPerlMethod.c
+++ b/compiler/src/CFCPerlMethod.c
@@ -442,18 +442,18 @@ S_xsub_def_positional_args(CFCPerlMethod *self) {
 
 char*
 CFCPerlMethod_callback_def(CFCMethod *method) {
+    // Return a callback wrapper that throws an error if there are no
+    // bindings for a method.
+    if (!CFCPerlMethod_can_be_bound(method)) {
+        return S_invalid_callback_def(method);
+    }
+
     CFCType *return_type = CFCMethod_get_return_type(method);
     char *start = S_callback_start(method);
     char *callback_def = NULL;
     char *refcount_mods = S_callback_refcount_mods(method);
 
-    if (!start) {
-        // Can't map vars, because there's at least one type in the argument
-        // list we don't yet support.  Return a callback wrapper that throws
-        // an error error.
-        callback_def = S_invalid_callback_def(method);
-    }
-    else if (CFCType_is_void(return_type)) {
+    if (CFCType_is_void(return_type)) {
         callback_def = S_void_callback_def(method, start, refcount_mods);
     }
     else if (CFCType_is_object(return_type)) {
@@ -571,9 +571,9 @@ S_callback_start(CFCMethod *method) {
                                  name, ");\n", NULL);
         }
         else {
-            // Can't map variable type.  Signal to caller.
-            FREEMEM(params);
-            return NULL;
+            // Can't map variable type.
+            const char *type_str = CFCType_to_c(type);
+            CFCUtil_die("Can't map type '%s' to Perl", type_str);
         }
     }
 

Reply via email to