gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gawk-diffs] [SCM] gawk branch, extgawk, updated. 860fe8fd4734fb3e9cc556


From: Arnold Robbins
Subject: [gawk-diffs] [SCM] gawk branch, extgawk, updated. 860fe8fd4734fb3e9cc5568595ce1ac719d71112
Date: Fri, 18 May 2012 11:25:13 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, extgawk has been updated
       via  860fe8fd4734fb3e9cc5568595ce1ac719d71112 (commit)
      from  0f2e51f9b18a1c4e203e0bd0ac3c68db9faa9b6d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=860fe8fd4734fb3e9cc5568595ce1ac719d71112

commit 860fe8fd4734fb3e9cc5568595ce1ac719d71112
Author: Arnold D. Robbins <address@hidden>
Date:   Fri May 18 14:24:51 2012 +0300

    Further ext API progress.

diff --git a/gawkapi.c b/gawkapi.c
index 2eb071c..2a9ad92 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -25,6 +25,19 @@
 
 #include "awk.h"
 
+static const awk_value_t *const node_to_awk_value(NODE *node);
+
+/*
+ * This value is passed back to gawk when an extension function returns.
+ * Having it static is not wonderful, but on the other hand gawk is not
+ * multithreaded and calls to extension functions are not multithreaded.
+ *
+ * Hmm. They should not be recursive either, but since C code cannot call
+ * back into awk code, there should not be a problem. But we should
+ * document how this works.
+ */
+static NODE *ext_ret_val;
+
 /*
  * Get the count'th paramater, zero-based.
  * Returns NULL if count is out of range, or if actual paramater
@@ -34,13 +47,51 @@ static awk_value_t *
 api_get_curfunc_param(awk_ext_id_t id, size_t count,
                        awk_param_type_t wanted)
 {
-       return NULL;    /* for now */
+       NODE *arg;
+
+       arg = (wanted == AWK_PARAM_ARRAY
+                       ? get_array_argument(count, false)
+                       : get_scalar_argument(count, false) );
+       if (arg == NULL)
+               return NULL;
+
+       if (arg->type != Node_var_array) {
+               if (wanted == AWK_PARAM_NUMBER) {
+                       (void) force_number(arg);
+               } else {
+                       (void) force_string(arg);
+               }
+       }
+
+       return (awk_value_t *) node_to_awk_value(arg);
 }
 
 /* Set the return value. Gawk takes ownership of string memory */
 static void
 api_set_return_value(awk_ext_id_t id, const awk_value_t *retval)
 {
+       if (retval == NULL)
+               fatal(_("api_set_return_value: received null retval"));
+
+       ext_ret_val = NULL;
+       getnode(ext_ret_val);
+       if (retval->val_type == AWK_ARRAY) {
+               *ext_ret_val = *((NODE *) retval->array_cookie);
+       } else if (retval->val_type == AWK_UNDEFINED) {
+               /* free node */
+               ext_ret_val = Nnull_string;
+       } else if (retval->val_type == AWK_NUMBER) {
+               ext_ret_val->type = Node_val;
+               ext_ret_val->flags |= NUMBER|NUMCUR;
+               /* FIXME: How to do this?
+               ext_ret_val->numbr = retval->num_value;
+                */
+       } else {
+               ext_ret_val->type = Node_val;
+               ext_ret_val->flags |= STRING|STRCUR;
+               ext_ret_val->stptr = retval->str_value.str;
+               ext_ret_val->stlen = retval->str_value.len;
+       }
 }
 
 /* Functions to print messages */

-----------------------------------------------------------------------

Summary of changes:
 gawkapi.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]