[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.3-162-g1ceec
From: |
Mark H Weaver |
Subject: |
[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.3-162-g1ceeca0 |
Date: |
Wed, 18 Jan 2012 23:03:42 +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 "GNU Guile".
http://git.savannah.gnu.org/cgit/guile.git/commit/?id=1ceeca0a76809248aa974685756e0f05c7f64200
The branch, stable-2.0 has been updated
via 1ceeca0a76809248aa974685756e0f05c7f64200 (commit)
from f0007cade095c5a2878ebbb8ea8c9b40810e4509 (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 -----------------------------------------------------------------
commit 1ceeca0a76809248aa974685756e0f05c7f64200
Author: Mark H Weaver <address@hidden>
Date: Wed Jan 18 17:52:43 2012 -0500
Add `scm_c_value_ref' to allow access to multiple returned values from C
Based on a patch by Julian Graham <address@hidden>
* libguile/values.c, libguile/values.h (scm_c_value_ref): New function.
* doc/ref/api-control.texi (Multiple Values): Add documentation.
* test-suite/standalone/test-scm-values.c: New test program.
* test-suite/standalone/Makefile.am: Add test-scm-values test.
-----------------------------------------------------------------------
Summary of changes:
doc/ref/api-control.texi | 7 +++
libguile/values.c | 25 +++++++++
libguile/values.h | 1 +
test-suite/standalone/Makefile.am | 7 +++
.../standalone/{test-list.c => test-scm-values.c} | 52 +++++++++++---------
5 files changed, 68 insertions(+), 24 deletions(-)
copy test-suite/standalone/{test-list.c => test-scm-values.c} (50%)
diff --git a/doc/ref/api-control.texi b/doc/ref/api-control.texi
index c1502b0..5596778 100644
--- a/doc/ref/api-control.texi
+++ b/doc/ref/api-control.texi
@@ -785,6 +785,13 @@ the current implementation that object shares structure
with
@var{args}, so @var{args} should not be modified subsequently.
@end deffn
address@hidden {C Function} scm_c_value_ref (values, idx)
+Returns the value at the position specified by @var{idx} in
address@hidden Note that @var{values} will ordinarily be a
+multiple-values object, but it need not be. Any other object
+represents a single value (itself), and is handled appropriately.
address@hidden deffn
+
@rnindex call-with-values
@deffn {Scheme Procedure} call-with-values producer consumer
Calls its @var{producer} argument with no values and a
diff --git a/libguile/values.c b/libguile/values.c
index ab77731..9c9e5ff 100644
--- a/libguile/values.c
+++ b/libguile/values.c
@@ -67,6 +67,31 @@ print_values (SCM obj, SCM pwps)
return SCM_UNSPECIFIED;
}
+SCM
+scm_c_value_ref (SCM obj, size_t idx)
+{
+ if (SCM_LIKELY (SCM_VALUESP (obj)))
+ {
+ SCM values = scm_struct_ref (obj, SCM_INUM0);
+ size_t i = idx;
+ while (SCM_LIKELY (scm_is_pair (values)))
+ {
+ if (i == 0)
+ return SCM_CAR (values);
+ values = SCM_CDR (values);
+ i--;
+ }
+ }
+ else if (idx == 0)
+ return obj;
+
+ scm_error (scm_out_of_range_key,
+ "scm_c_value_ref",
+ "Too few values in ~S to access index ~S",
+ scm_list_2 (obj, scm_from_unsigned_integer (idx)),
+ scm_list_1 (scm_from_unsigned_integer (idx)));
+}
+
SCM_DEFINE (scm_values, "values", 0, 0, 1,
(SCM args),
"Delivers all of its arguments to its continuation. Except for\n"
diff --git a/libguile/values.h b/libguile/values.h
index 65ad8a1..5f79855 100644
--- a/libguile/values.h
+++ b/libguile/values.h
@@ -33,6 +33,7 @@ SCM_API SCM scm_values_vtable;
SCM_INTERNAL void scm_i_extract_values_2 (SCM obj, SCM *p1, SCM *p2);
SCM_API SCM scm_values (SCM args);
+SCM_API SCM scm_c_value_ref (SCM values, size_t idx);
SCM_INTERNAL void scm_init_values (void);
#endif /* SCM_VALUES_H */
diff --git a/test-suite/standalone/Makefile.am
b/test-suite/standalone/Makefile.am
index 08d249c..d8cfafa 100644
--- a/test-suite/standalone/Makefile.am
+++ b/test-suite/standalone/Makefile.am
@@ -189,6 +189,13 @@ test_scm_to_latin1_string_LDADD = $(LIBGUILE_LDADD)
check_PROGRAMS += test-scm-to-latin1-string
TESTS += test-scm-to-latin1-string
+# test-scm-values
+test_scm_values_SOURCES = test-scm-values.c
+test_scm_values_CFLAGS = ${test_cflags}
+test_scm_values_LDADD = $(LIBGUILE_LDADD)
+check_PROGRAMS += test-scm-values
+TESTS += test-scm-values
+
if HAVE_SHARED_LIBRARIES
# test-extensions
diff --git a/test-suite/standalone/test-list.c
b/test-suite/standalone/test-scm-values.c
similarity index 50%
copy from test-suite/standalone/test-list.c
copy to test-suite/standalone/test-scm-values.c
index b51a2a1..ece62da 100644
--- a/test-suite/standalone/test-list.c
+++ b/test-suite/standalone/test-scm-values.c
@@ -1,6 +1,4 @@
-/* test-list.c - exercise libguile/list.c functions */
-
-/* Copyright (C) 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -22,39 +20,45 @@
# include <config.h>
#endif
+#include <assert.h>
#include <libguile.h>
-
#include <stdlib.h>
-#include <stdio.h>
#include <string.h>
-/* pretty trivial, but ensure this entrypoint exists, since it was
- documented in Guile 1.6 and earlier */
static void
-test_scm_list (void)
+test_scm_c_value_ref_on_multiple_values ()
{
- {
- if (! scm_is_eq (SCM_EOL, scm_list (SCM_EOL)))
- {
- fprintf (stderr, "fail: scm_list SCM_EOL\n");
- exit (EXIT_FAILURE);
- }
- }
+ SCM values = scm_values (scm_list_3 (scm_from_latin1_string ("foo"),
+ scm_from_latin1_string ("bar"),
+ scm_from_latin1_string ("baz")));
+
+ char *foo = scm_to_latin1_string (scm_c_value_ref (values, 0));
+ char *bar = scm_to_latin1_string (scm_c_value_ref (values, 1));
+ char *baz = scm_to_latin1_string (scm_c_value_ref (values, 2));
+
+ assert (strcmp (foo, "foo") == 0);
+ assert (strcmp (bar, "bar") == 0);
+ assert (strcmp (baz, "baz") == 0);
- {
- SCM lst = scm_list_2 (scm_from_int (1), scm_from_int (2));
- if (! scm_is_true (scm_equal_p (lst, scm_list (lst))))
- {
- fprintf (stderr, "fail: scm_list '(1 2)\n");
- exit (EXIT_FAILURE);
- }
- }
+ free (foo);
+ free (bar);
+ free (baz);
+}
+
+static void
+test_scm_c_value_ref_on_a_single_value ()
+{
+ SCM value = scm_from_latin1_string ("foo");
+ char *foo = scm_to_latin1_string (scm_c_value_ref (value, 0));
+ assert (strcmp (foo, "foo") == 0);
+ free (foo);
}
static void
tests (void *data, int argc, char **argv)
{
- test_scm_list ();
+ test_scm_c_value_ref_on_multiple_values ();
+ test_scm_c_value_ref_on_a_single_value ();
}
int
hooks/post-receive
--
GNU Guile
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.3-162-g1ceeca0,
Mark H Weaver <=