You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/05/30 13:27:48 UTC

[09/12] lucy-clownfish git commit: Implement Str_To_Host

Implement Str_To_Host


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

Branch: refs/heads/master
Commit: 4afe9a6bcc3c8a0c74c7a042bea582d5db80fe58
Parents: 40d863c
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri May 29 14:43:16 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri May 29 17:53:26 2015 +0200

----------------------------------------------------------------------
 compiler/src/CFCPerlMethod.c                    |  9 ++----
 runtime/core/Clownfish/String.cfh               |  3 ++
 .../perl/buildlib/Clownfish/Build/Binding.pm    |  9 +-----
 runtime/perl/xs/XSBind.c                        | 31 ++++++++------------
 runtime/perl/xs/XSBind.h                        |  6 ----
 5 files changed, 19 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4afe9a6b/compiler/src/CFCPerlMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c
index ca5f34e..afe34c0 100644
--- a/compiler/src/CFCPerlMethod.c
+++ b/compiler/src/CFCPerlMethod.c
@@ -500,13 +500,8 @@ S_callback_start(CFCMethod *method) {
                                  num_buf, ");\n", NULL);
         }
 
-        if (CFCType_is_string_type(type)) {
-            // Convert Clownfish string type to UTF-8 Perl string scalars.
-            params = CFCUtil_cat(params, "    mPUSHs(XSBind_str_to_sv(",
-                                 "aTHX_ (cfish_String*)", name, "));\n", NULL);
-        }
-        else if (CFCType_is_object(type)) {
-            // Wrap other Clownfish object types in Perl objects.
+        if (CFCType_is_object(type)) {
+            // Wrap Clownfish object types in Perl objects.
             params = CFCUtil_cat(params, "    mPUSHs(XSBind_cfish_to_perl(",
                                  "aTHX_ (cfish_Obj*)", name, "));\n", NULL);
         }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4afe9a6b/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.cfh b/runtime/core/Clownfish/String.cfh
index 17418b9..932f36b 100644
--- a/runtime/core/Clownfish/String.cfh
+++ b/runtime/core/Clownfish/String.cfh
@@ -120,6 +120,9 @@ final class Clownfish::String nickname Str
     inert bool
     less_than(const void *va, const void *vb);
 
+    void*
+    To_Host(String *self);
+
     /** Return the concatenation of the String and `other`.
      */
     incremented String*

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4afe9a6b/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 8097d6b..309f7e8 100644
--- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -226,13 +226,6 @@ _clone(self)
 CODE:
     RETVAL = CFISH_OBJ_TO_SV_NOINC(CFISH_Str_Clone_IMP(self));
 OUTPUT: RETVAL
-
-SV*
-to_perl(self)
-    cfish_String *self;
-CODE:
-    RETVAL = XSBind_str_to_sv(aTHX_ self);
-OUTPUT: RETVAL
 END_XS_CODE
 
     my $binding = Clownfish::CFC::Binding::Perl::Class->new(
@@ -496,7 +489,7 @@ get_class_name(self)
     cfish_Obj *self
 CODE:
     cfish_String *class_name = cfish_Obj_get_class_name(self);
-    RETVAL = cfish_XSBind_str_to_sv(aTHX_ class_name);
+    RETVAL = (SV*)CFISH_Str_To_Host(class_name);
 OUTPUT: RETVAL
 
 bool

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4afe9a6b/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index f1a9c21..630febf 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -141,9 +141,6 @@ XSBind_cfish_to_perl(pTHX_ cfish_Obj *obj) {
     if (obj == NULL) {
         return newSV(0);
     }
-    else if (cfish_Obj_is_a(obj, CFISH_STRING)) {
-        return XSBind_str_to_sv(aTHX_ (cfish_String*)obj);
-    }
     else {
         return (SV*)CFISH_Obj_To_Host(obj);
     }
@@ -203,18 +200,6 @@ XSBind_perl_to_cfish(pTHX_ SV *sv) {
     return retval;
 }
 
-SV*
-XSBind_str_to_sv(pTHX_ cfish_String *str) {
-    if (!str) {
-        return newSV(0);
-    }
-    else {
-        SV *sv = newSVpvn(CFISH_Str_Get_Ptr8(str), CFISH_Str_Get_Size(str));
-        SvUTF8_on(sv);
-        return sv;
-    }
-}
-
 static cfish_Hash*
 S_perl_hash_to_cfish_hash(pTHX_ HV *phash) {
     uint32_t    num_keys = hv_iterinit(phash);
@@ -743,7 +728,7 @@ cfish_Class_fresh_host_methods(cfish_String *class_name) {
     SAVETMPS;
     EXTEND(SP, 1);
     PUSHMARK(SP);
-    mPUSHs(XSBind_str_to_sv(aTHX_ class_name));
+    mPUSHs((SV*)CFISH_Str_To_Host(class_name));
     PUTBACK;
     call_pv("Clownfish::Class::_fresh_host_methods", G_SCALAR);
     SPAGAIN;
@@ -762,7 +747,7 @@ cfish_Class_find_parent_class(cfish_String *class_name) {
     SAVETMPS;
     EXTEND(SP, 1);
     PUSHMARK(SP);
-    mPUSHs(XSBind_str_to_sv(aTHX_ class_name));
+    mPUSHs((SV*)CFISH_Str_To_Host(class_name));
     PUTBACK;
     call_pv("Clownfish::Class::_find_parent_class", G_SCALAR);
     SPAGAIN;
@@ -897,7 +882,7 @@ cfish_Err_throw_mess(cfish_Class *klass, cfish_String *message) {
 void
 cfish_Err_warn_mess(cfish_String *message) {
     dTHX;
-    SV *error_sv = XSBind_str_to_sv(aTHX_ message);
+    SV *error_sv = (SV*)CFISH_Str_To_Host(message);
     CFISH_DECREF(message);
     warn("%s", SvPV_nolen(error_sv));
     SvREFCNT_dec(error_sv);
@@ -949,6 +934,16 @@ cfish_Err_trap(CFISH_Err_Attempt_t routine, void *context) {
     return error;
 }
 
+/**************************** Clownfish::String *****************************/
+
+void*
+CFISH_Str_To_Host_IMP(cfish_String *self) {
+    dTHX;
+    SV *sv = newSVpvn(CFISH_Str_Get_Ptr8(self), CFISH_Str_Get_Size(self));
+    SvUTF8_on(sv);
+    return sv;
+}
+
 /***************************** Clownfish::Blob ******************************/
 
 void*

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4afe9a6b/runtime/perl/xs/XSBind.h
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.h b/runtime/perl/xs/XSBind.h
index 711adab..f895854 100644
--- a/runtime/perl/xs/XSBind.h
+++ b/runtime/perl/xs/XSBind.h
@@ -131,11 +131,6 @@ cfish_XSBind_cfish_to_perl(pTHX_ cfish_Obj *obj);
 CFISH_VISIBLE cfish_Obj*
 cfish_XSBind_perl_to_cfish(pTHX_ SV *sv);
 
-/** Convert a String into a new UTF-8 string SV.
- */
-CFISH_VISIBLE SV*
-cfish_XSBind_str_to_sv(pTHX_ cfish_String *str);
-
 /** Perl-specific wrapper for Err#trap.  The "routine" must be either a
  * subroutine reference or the name of a subroutine.
  */
@@ -308,7 +303,6 @@ cfish_XSBind_allot_params(pTHX_ SV** stack, int32_t start,
 #define XSBind_cfish_obj_to_sv_noinc   cfish_XSBind_cfish_obj_to_sv_noinc
 #define XSBind_cfish_to_perl           cfish_XSBind_cfish_to_perl
 #define XSBind_perl_to_cfish           cfish_XSBind_perl_to_cfish
-#define XSBind_str_to_sv               cfish_XSBind_str_to_sv
 #define XSBind_trap                    cfish_XSBind_trap
 #define XSBind_allot_params            cfish_XSBind_allot_params
 #define ALLOT_I8                       XSBIND_ALLOT_I8