lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [2/2] lucy-clownfish git commit: Factor out code to throw invalid argument error
Date Fri, 27 Nov 2015 13:58:23 GMT
Factor out code to throw invalid argument error

Reduces the size of the stripped 32-bit Lucy binary by about 180 KB.

The size of the simplest XS wrappers (void, no params) is down to
133 bytes on my 32-bit Linux system.


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

Branch: refs/heads/master
Commit: 976199e97634bc129d36d80c584cf3f2a5973e7b
Parents: 3c79eef
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Fri Nov 27 14:29:28 2015 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Fri Nov 27 14:34:04 2015 +0100

----------------------------------------------------------------------
 compiler/src/CFCPerlConstructor.c | 4 +++-
 compiler/src/CFCPerlMethod.c      | 6 ++++--
 runtime/perl/xs/XSBind.c          | 5 +++++
 runtime/perl/xs/XSBind.h          | 6 ++++++
 4 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/976199e9/compiler/src/CFCPerlConstructor.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlConstructor.c b/compiler/src/CFCPerlConstructor.c
index bde723b..68f20e1 100644
--- a/compiler/src/CFCPerlConstructor.c
+++ b/compiler/src/CFCPerlConstructor.c
@@ -150,7 +150,9 @@ CFCPerlConstructor_xsub_def(CFCPerlConstructor *self, CFCClass *klass)
{
         "    %s retval;\n"
         "\n"
         "    CFISH_UNUSED_VAR(cv);\n"
-        "    if (%s) { CFISH_THROW(CFISH_ERR, \"Usage: %%s(class_name, ...)\",  GvNAME(CvGV(cv)));
}\n"
+        "    if (%s) {\n"
+        "        XSBind_invalid_args_error(aTHX_ cv, \"class_name, ...\");\n"
+        "    }\n"
         "    SP -= items;\n"
         "\n"
         "%s" // locate_args

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/976199e9/compiler/src/CFCPerlMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c
index 120c6c4..d549563 100644
--- a/compiler/src/CFCPerlMethod.c
+++ b/compiler/src/CFCPerlMethod.c
@@ -269,7 +269,9 @@ S_xsub_def_labeled_params(CFCPerlMethod *self, CFCClass *klass) {
         "%s"
         "\n"
         "    CFISH_UNUSED_VAR(cv);\n"
-        "    if (items < 1) { CFISH_THROW(CFISH_ERR, \"Usage: %%s(%s, ...)\",  GvNAME(CvGV(cv)));
}\n"
+        "    if (items < 1) {\n"
+        "        XSBind_invalid_args_error(aTHX_ cv, \"%s, ...\");\n"
+        "    }\n"
         "    SP -= items;\n"
         "\n"
         "    /* Locate args on Perl stack. */\n"
@@ -359,7 +361,7 @@ S_xsub_def_positional_args(CFCPerlMethod *self, CFCClass *klass) {
         "    CFISH_UNUSED_VAR(cv);\n"
         "    SP -= items;\n"
         "    if (%s) {\n"
-        "        CFISH_THROW(CFISH_ERR, \"Usage: %%s(%s)\", GvNAME(CvGV(cv)));\n"
+        "        XSBind_invalid_args_error(aTHX_ cv, \"%s\");\n"
         "    }\n"
         "\n"
         "    /* Extract vars from Perl stack. */\n"

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/976199e9/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index 665edf9..6175c46 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -412,6 +412,11 @@ XSBind_arg_to_cfish_nullable(pTHX_ SV *value, const char *label,
     return obj;
 }
 
+void
+XSBind_invalid_args_error(pTHX_ CV *cv, const char *param_list) {
+    THROW(CFISH_ERR, "Usage: %s(%s)", GvNAME(CvGV(cv)), param_list);
+}
+
 /***************************************************************************
  * 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/976199e9/runtime/perl/xs/XSBind.h
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.h b/runtime/perl/xs/XSBind.h
index dc18b19..7c5a9cc 100644
--- a/runtime/perl/xs/XSBind.h
+++ b/runtime/perl/xs/XSBind.h
@@ -197,6 +197,11 @@ CFISH_VISIBLE cfish_Obj*
 cfish_XSBind_arg_to_cfish_nullable(pTHX_ SV *value, const char *label,
                                    cfish_Class *klass, void *allocation);
 
+/** Throw an error because of invalid number of arguments.
+ */
+CFISH_VISIBLE void
+cfish_XSBind_invalid_args_error(pTHX_ CV *cv, const char *param_list);
+
 #define XSBIND_PARAM(key, required) \
     { key, (int16_t)sizeof("" key) - 1, (char)required }
 
@@ -222,6 +227,7 @@ cfish_XSBind_arg_to_cfish_nullable(pTHX_ SV *value, const char *label,
 #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
+#define XSBind_invalid_args_error      cfish_XSBind_invalid_args_error
 
 /* 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