lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject lucy-clownfish git commit: Split XSBind_arg_to_cfish in two
Date Fri, 27 Nov 2015 12:35:58 GMT
Repository: lucy-clownfish
Updated Branches:
  refs/heads/master b51cc4684 -> b8ba6d8c4


Split XSBind_arg_to_cfish in two

Implement XSBind_arg_to_cfish_nullable as separate function.


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

Branch: refs/heads/master
Commit: b8ba6d8c436301996281ad6c41931a75997252a4
Parents: b51cc46
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Fri Nov 27 13:29:02 2015 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Fri Nov 27 13:29:02 2015 +0100

----------------------------------------------------------------------
 compiler/src/CFCPerlTypeMap.c                   |  8 ++++----
 .../perl/buildlib/Clownfish/Build/Binding.pm    |  6 +++---
 runtime/perl/xs/XSBind.c                        | 20 +++++++++++++++++---
 runtime/perl/xs/XSBind.h                        | 13 ++++++++++---
 4 files changed, 34 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8ba6d8c/compiler/src/CFCPerlTypeMap.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlTypeMap.c b/compiler/src/CFCPerlTypeMap.c
index 2ac4985..c975c4f 100644
--- a/compiler/src/CFCPerlTypeMap.c
+++ b/compiler/src/CFCPerlTypeMap.c
@@ -42,7 +42,7 @@ CFCPerlTypeMap_from_perl(CFCType *type, const char *xs_var,
     if (CFCType_is_object(type)) {
         const char *struct_sym   = CFCType_get_specifier(type);
         const char *class_var    = CFCType_get_class_var(type);
-        const char *nullable_str = CFCType_nullable(type) ? "true" : "false";
+        const char *nullable_str = CFCType_nullable(type) ? "_nullable" : "";
         const char *allocation;
         if (strcmp(struct_sym, "cfish_String") == 0
             || strcmp(struct_sym, "cfish_Obj") == 0
@@ -55,9 +55,9 @@ CFCPerlTypeMap_from_perl(CFCType *type, const char *xs_var,
             allocation = "NULL";
         }
         const char pattern[]
-            = "(%s*)XSBind_arg_to_cfish(aTHX_ %s, \"%s\", %s, %s, %s)";
-        result = CFCUtil_sprintf(pattern, struct_sym, xs_var, label,
-                                 nullable_str, class_var, allocation);
+            = "(%s*)XSBind_arg_to_cfish%s(aTHX_ %s, \"%s\", %s, %s)";
+        result = CFCUtil_sprintf(pattern, struct_sym, nullable_str, xs_var,
+                                 label, class_var, allocation);
     }
     else if (CFCType_is_primitive(type)) {
         const char *specifier = CFCType_get_specifier(type);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8ba6d8c/runtime/perl/buildlib/Clownfish/Build/Binding.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
index a50af01..2452b79 100644
--- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -970,11 +970,11 @@ CODE:
     CFISH_UNUSED_VAR(unused_sv);
     XSBind_locate_args(aTHX_ &(ST(0)), 1, items, param_specs, locations, 2);
     class_name = (cfish_String*)XSBind_arg_to_cfish(
-            aTHX_ ST(locations[0]), "class_name", false, CFISH_STRING,
+            aTHX_ ST(locations[0]), "class_name", CFISH_STRING,
             CFISH_ALLOCA_OBJ(CFISH_STRING));
     if (locations[1] < items) {
-        parent = (cfish_Class*)XSBind_arg_to_cfish(
-                aTHX_ ST(locations[1]), "parent", true, CFISH_CLASS, NULL);
+        parent = (cfish_Class*)XSBind_arg_to_cfish_nullable(
+                aTHX_ ST(locations[1]), "parent", CFISH_CLASS, NULL);
     }
     singleton = cfish_Class_singleton(class_name, parent);
     RETVAL = (SV*)CFISH_Class_To_Host(singleton);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8ba6d8c/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index c89f669..665edf9 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -380,8 +380,8 @@ cfish_XSBind_locate_args(pTHX_ SV** stack, int32_t start, int32_t items,
 }
 
 cfish_Obj*
-XSBind_arg_to_cfish(pTHX_ SV *value, const char *label, bool nullable,
-                    cfish_Class *klass, void *allocation) {
+XSBind_arg_to_cfish(pTHX_ SV *value, const char *label, cfish_Class *klass,
+                    void *allocation) {
     cfish_Obj *obj = NULL;
 
     if (!S_maybe_perl_to_cfish(aTHX_ value, klass, false, allocation, &obj)) {
@@ -390,7 +390,7 @@ XSBind_arg_to_cfish(pTHX_ SV *value, const char *label, bool nullable,
         CFISH_UNREACHABLE_RETURN(cfish_Obj*);
     }
 
-    if (!obj && !nullable) {
+    if (!obj) {
         THROW(CFISH_ERR, "'%s' must not be undef", label);
         CFISH_UNREACHABLE_RETURN(cfish_Obj*);
     }
@@ -398,6 +398,20 @@ XSBind_arg_to_cfish(pTHX_ SV *value, const char *label, bool nullable,
     return obj;
 }
 
+cfish_Obj*
+XSBind_arg_to_cfish_nullable(pTHX_ SV *value, const char *label,
+                             cfish_Class *klass, void *allocation) {
+    cfish_Obj *obj = NULL;
+
+    if (!S_maybe_perl_to_cfish(aTHX_ value, klass, false, allocation, &obj)) {
+        THROW(CFISH_ERR, "Invalid value for '%s' - not a %o", label,
+              CFISH_Class_Get_Name(klass));
+        CFISH_UNREACHABLE_RETURN(cfish_Obj*);
+    }
+
+    return obj;
+}
+
 /***************************************************************************
  * The routines below are declared within the Clownfish core but left
  * unimplemented and must be defined for each host language.

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8ba6d8c/runtime/perl/xs/XSBind.h
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.h b/runtime/perl/xs/XSBind.h
index 0927382..dc18b19 100644
--- a/runtime/perl/xs/XSBind.h
+++ b/runtime/perl/xs/XSBind.h
@@ -179,18 +179,24 @@ cfish_XSBind_locate_args(pTHX_ SV** stack, int32_t start, int32_t items,
                          const cfish_XSBind_ParamSpec *specs,
                          int32_t *locations, int32_t num_params);
 
-/** Convert an argument from the Perl stack to a Clownfish object.
+/** Convert an argument from the Perl stack to a Clownfish object. Throws
+ * an error if the SV can't be converted.
  *
  * @param value The SV from the Perl stack.
  * @param label The name of the param.
- * @param nullable Whether undef is allowed for objects.
  * @param klass The class to convert to.
  * @param allocation Stack allocation for Obj and String.
  */
 CFISH_VISIBLE cfish_Obj*
-cfish_XSBind_arg_to_cfish(pTHX_ SV *value, const char *label, bool nullable,
+cfish_XSBind_arg_to_cfish(pTHX_ SV *value, const char *label,
                           cfish_Class *klass, void *allocation);
 
+/** Like XSBind_arg_to_cfish, but allows undef which is converted to NULL.
+ */
+CFISH_VISIBLE cfish_Obj*
+cfish_XSBind_arg_to_cfish_nullable(pTHX_ SV *value, const char *label,
+                                   cfish_Class *klass, void *allocation);
+
 #define XSBIND_PARAM(key, required) \
     { key, (int16_t)sizeof("" key) - 1, (char)required }
 
@@ -215,6 +221,7 @@ cfish_XSBind_arg_to_cfish(pTHX_ SV *value, const char *label, bool nullable,
 #define XSBind_trap                    cfish_XSBind_trap
 #define XSBind_locate_args             cfish_XSBind_locate_args
 #define XSBind_arg_to_cfish            cfish_XSBind_arg_to_cfish
+#define XSBind_arg_to_cfish_nullable   cfish_XSBind_arg_to_cfish_nullable
 
 /* Strip the prefix from some common ClownFish symbols where we know there's
  * no conflict with Perl.  It's a little inconsistent to do this rather than


Mime
View raw message