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/12 18:37:13 UTC

[4/7] lucy-clownfish git commit: Helper to allocate objects on the stack

Helper to allocate objects on the stack

This adds a global variable lookup and an indirection to the creation
of stack strings. But it would make stack allocation of other objects
like Blobs more straight-forward.


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

Branch: refs/heads/master
Commit: a149e4ea7f882248559b2bd39cb99c47965d69f7
Parents: 8316e7c
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat May 9 20:57:33 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue May 12 18:34:59 2015 +0200

----------------------------------------------------------------------
 compiler/src/CFCPerlSub.c                        |  2 +-
 compiler/src/CFCPerlTypeMap.c                    |  4 ++--
 runtime/core/Clownfish/Class.cfh                 |  6 ++++++
 runtime/core/Clownfish/String.c                  |  5 -----
 runtime/core/Clownfish/String.cfh                | 11 +++--------
 runtime/perl/buildlib/Clownfish/Build/Binding.pm |  2 +-
 runtime/perl/xs/XSBind.h                         |  6 +++---
 7 files changed, 16 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a149e4ea/compiler/src/CFCPerlSub.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlSub.c b/compiler/src/CFCPerlSub.c
index 35f7939..d531044 100644
--- a/compiler/src/CFCPerlSub.c
+++ b/compiler/src/CFCPerlSub.c
@@ -154,7 +154,7 @@ S_allot_params_arg(CFCType *type, const char *label, int required) {
             use_sv_buffer = true;
         }
         const char *allocation = use_sv_buffer
-                                 ? "alloca(cfish_SStr_size())"
+                                 ? "CFISH_ALLOCA_OBJ(CFISH_STACKSTRING)"
                                  : "NULL";
         const char pattern[] = "ALLOT_OBJ(&arg_%s, \"%s\", %u, %s, %s, %s)";
         char *arg = CFCUtil_sprintf(pattern, label, label, label_len,

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a149e4ea/compiler/src/CFCPerlTypeMap.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlTypeMap.c b/compiler/src/CFCPerlTypeMap.c
index a2b682e..349d79f 100644
--- a/compiler/src/CFCPerlTypeMap.c
+++ b/compiler/src/CFCPerlTypeMap.c
@@ -47,7 +47,7 @@ CFCPerlTypeMap_from_perl(CFCType *type, const char *xs_var) {
            ) {
             // Share buffers rather than copy between Perl scalars and
             // Clownfish string types.
-            allocation = "alloca(cfish_SStr_size())";
+            allocation = "CFISH_ALLOCA_OBJ(CFISH_STACKSTRING)";
         }
         else {
             allocation = "NULL";
@@ -266,7 +266,7 @@ CFCPerlTypeMap_write_xs_typemap(CFCHierarchy *hierarchy) {
         if (strcmp(full_struct_sym, "cfish_String") == 0) {
             // Share buffers rather than copy between Perl scalars and
             // Clownfish string types.
-            allocation = "alloca(cfish_SStr_size())";
+            allocation = "CFISH_ALLOCA_OBJ(CFISH_STACKSTRING)";
         }
         else {
             allocation = "NULL";

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a149e4ea/runtime/core/Clownfish/Class.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Class.cfh b/runtime/core/Clownfish/Class.cfh
index ff4e623..94c89a5 100644
--- a/runtime/core/Clownfish/Class.cfh
+++ b/runtime/core/Clownfish/Class.cfh
@@ -142,4 +142,10 @@ final class Clownfish::Class inherits Clownfish::Obj {
     Destroy(Class *self);
 }
 
+__C__
+
+#define CFISH_ALLOCA_OBJ(class) \
+    cfish_alloca(CFISH_Class_Get_Obj_Alloc_Size(class))
+
+__END_C__
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a149e4ea/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.c b/runtime/core/Clownfish/String.c
index 8764c1d..25237c7 100644
--- a/runtime/core/Clownfish/String.c
+++ b/runtime/core/Clownfish/String.c
@@ -533,11 +533,6 @@ SStr_wrap(void *allocation, String *source) {
     return SStr_wrap_utf8(allocation, source->ptr, source->size);
 }
 
-size_t
-SStr_size() {
-    return sizeof(StackString);
-}
-
 void
 SStr_Destroy_IMP(StackString *self) {
     THROW(ERR, "Can't destroy a StackString ('%o')", self);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a149e4ea/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.cfh b/runtime/core/Clownfish/String.cfh
index bf2ce7f..f9a21f5 100644
--- a/runtime/core/Clownfish/String.cfh
+++ b/runtime/core/Clownfish/String.cfh
@@ -281,11 +281,6 @@ class Clownfish::StackString nickname SStr
     inert incremented StackString*
     wrap_utf8(void *allocation, const char *utf8, size_t size);
 
-    /** Return the size for a StackString struct.
-     */
-    inert size_t
-    size();
-
     /** Throws an error.
      */
     public void
@@ -401,13 +396,13 @@ class Clownfish::StringIterator nickname StrIter
 __C__
 
 #define CFISH_SSTR_BLANK() \
-   cfish_SStr_wrap_utf8(cfish_alloca(cfish_SStr_size()), "", 0)
+   cfish_SStr_wrap_utf8(CFISH_ALLOCA_OBJ(CFISH_STACKSTRING), "", 0)
 
 #define CFISH_SSTR_WRAP(source) \
-    cfish_SStr_wrap(cfish_alloca(cfish_SStr_size()), source)
+    cfish_SStr_wrap(CFISH_ALLOCA_OBJ(CFISH_STACKSTRING), source)
 
 #define CFISH_SSTR_WRAP_UTF8(ptr, size) \
-    cfish_SStr_wrap_utf8(cfish_alloca(cfish_SStr_size()), ptr, size)
+    cfish_SStr_wrap_utf8(CFISH_ALLOCA_OBJ(CFISH_STACKSTRING), ptr, size)
 
 #define CFISH_STRITER_DONE  -1
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a149e4ea/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 4e0ef0b..8783afb 100644
--- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -609,7 +609,7 @@ CODE:
     bool args_ok
         = XSBind_allot_params(aTHX_ &(ST(0)), 1, items,
                               ALLOT_OBJ(&class_name, "class_name", 10, true,
-                                        CFISH_STRING, alloca(cfish_SStr_size())),
+                                        CFISH_STRING, CFISH_ALLOCA_OBJ(CFISH_STACKSTRING)),
                               ALLOT_OBJ(&parent, "parent", 6, false,
                                         CFISH_CLASS, NULL),
                               NULL);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a149e4ea/runtime/perl/xs/XSBind.h
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.h b/runtime/perl/xs/XSBind.h
index 4b48167..bba6ae4 100644
--- a/runtime/perl/xs/XSBind.h
+++ b/runtime/perl/xs/XSBind.h
@@ -162,8 +162,8 @@ cfish_XSBind_enable_overload(pTHX_ void *pobj);
  * a NULL-terminated series of ALLOT_ macros.
  *
  *     cfish_XSBind_allot_params(stack, start, num_stack_elems,
- *          ALLOT_OBJ(&field, "field", 5, CFISH_STRING, true, alloca(cfish_SStr_size()),
- *          ALLOT_OBJ(&term, "term", 4, CFISH_STRING, true, alloca(cfish_SStr_size()),
+ *          ALLOT_OBJ(&field, "field", 5, CFISH_STRING, true, CFISH_ALLOCA_OBJ(CFISH_STACKSTRING),
+ *          ALLOT_OBJ(&term, "term", 4, CFISH_STRING, true, CFISH_ALLOCA_OBJ(CFISH_STACKSTRING),
  *          NULL);
  *
  * The following ALLOT_ macros are available for primitive types:
@@ -202,7 +202,7 @@ cfish_XSBind_enable_overload(pTHX_ void *pobj);
  * The "klass" argument must be the Class corresponding to the class of the
  * desired object.  The "allocation" argument must be a blob of memory
  * allocated on the stack sufficient to hold a StackString.  (Use
- * cfish_SStr_size() to find the allocation size.)
+ * CFISH_ALLOCA_OBJ to allocate the object.)
  *
  * To extract a Perl scalar, use the following ALLOT_ macro:
  *