1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-20 10:40:19 +02:00

Merge branch 'stable-2.0'

Conflicts:
	libguile/read.c
	test-suite/tests/web-response.test
This commit is contained in:
Mark H Weaver 2014-01-21 03:57:04 -05:00
commit ba578eb044
12 changed files with 120 additions and 38 deletions

1
THANKS
View file

@ -168,6 +168,7 @@ For fixes or providing information which led to a fix:
Rainer Tammer Rainer Tammer
Samuel Thibault Samuel Thibault
Richard Todd Richard Todd
Sree Harsha Totakura
Tom Tromey Tom Tromey
Issac Trotts Issac Trotts
Greg Troxel Greg Troxel

View file

@ -1,7 +1,7 @@
@c -*-texinfo-*- @c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual. @c This is part of the GNU Guile Reference Manual.
@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2009, 2010, 2011, 2012, 2013 @c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2009, 2010, 2011,
@c Free Software Foundation, Inc. @c 2012, 2013, 2014 Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions. @c See the file guile.texi for copying conditions.
@node Macros @node Macros
@ -393,7 +393,7 @@ templates. For example:
When writing macros that generate macro definitions, it is convenient to When writing macros that generate macro definitions, it is convenient to
use a different ellipsis identifier at each level. Guile allows the use a different ellipsis identifier at each level. Guile allows the
desired ellipsis identifier to be specified as the first operand to desired ellipsis identifier to be specified as the first operand to
@code{syntax-rules}, as per R7RS. For example: @code{syntax-rules}, as specified by SRFI-46 and R7RS. For example:
@example @example
(define-syntax define-quotation-macros (define-syntax define-quotation-macros

View file

@ -71,24 +71,23 @@ Here is @file{simple-guile.c}, source code for a @code{main} and an
interpreter. interpreter.
@example @example
/* simple-guile.c --- how to start up the Guile /* simple-guile.c --- Start Guile from C. */
interpreter from C code. */
/* Get declarations for all the scm_ functions. */
#include <libguile.h> #include <libguile.h>
static void static void
inner_main (void *closure, int argc, char **argv) inner_main (void *closure, int argc, char **argv)
@{ @{
/* module initializations would go here */ /* preparation */
scm_shell (argc, argv); scm_shell (argc, argv);
/* after exit */
@} @}
int int
main (int argc, char **argv) main (int argc, char **argv)
@{ @{
scm_boot_guile (argc, argv, inner_main, 0); scm_boot_guile (argc, argv, inner_main, 0);
return 0; /* never reached */ return 0; /* never reached, see inner_main */
@} @}
@end example @end example
@ -97,7 +96,9 @@ Guile, passing it @code{inner_main}. Once @code{scm_boot_guile} is
ready, it invokes @code{inner_main}, which calls @code{scm_shell} to ready, it invokes @code{inner_main}, which calls @code{scm_shell} to
process the command-line arguments in the usual way. process the command-line arguments in the usual way.
Here is a Makefile which you can use to compile the above program. It @subsection Building the Example with Make
Here is a Makefile which you can use to compile the example program. It
uses @code{pkg-config} to learn about the necessary compiler and uses @code{pkg-config} to learn about the necessary compiler and
linker flags. linker flags.
@example @example
@ -117,8 +118,10 @@ simple-guile.o: simple-guile.c
$@{CC@} -c $@{CFLAGS@} simple-guile.c $@{CC@} -c $@{CFLAGS@} simple-guile.c
@end example @end example
@subsection Building the Example with Autoconf
If you are using the GNU Autoconf package to make your application more If you are using the GNU Autoconf package to make your application more
portable, Autoconf will settle many of the details in the Makefile above portable, Autoconf will settle many of the details in the Makefile
automatically, making it much simpler and more portable; we recommend automatically, making it much simpler and more portable; we recommend
using Autoconf with Guile. Here is a @file{configure.ac} file for using Autoconf with Guile. Here is a @file{configure.ac} file for
@code{simple-guile} that uses the standard @code{PKG_CHECK_MODULES} @code{simple-guile} that uses the standard @code{PKG_CHECK_MODULES}

View file

@ -48,12 +48,14 @@ get the relevant SRFI documents from the SRFI home page
* SRFI-41:: Streams. * SRFI-41:: Streams.
* SRFI-42:: Eager comprehensions * SRFI-42:: Eager comprehensions
* SRFI-45:: Primitives for expressing iterative lazy algorithms * SRFI-45:: Primitives for expressing iterative lazy algorithms
* SRFI-46:: Basic syntax-rules Extensions.
* SRFI-55:: Requiring Features. * SRFI-55:: Requiring Features.
* SRFI-60:: Integers as bits. * SRFI-60:: Integers as bits.
* SRFI-61:: A more general `cond' clause * SRFI-61:: A more general `cond' clause
* SRFI-62:: S-expression comments. * SRFI-62:: S-expression comments.
* SRFI-67:: Compare procedures * SRFI-67:: Compare procedures
* SRFI-69:: Basic hash tables. * SRFI-69:: Basic hash tables.
* SRFI-87:: => in case clauses.
* SRFI-88:: Keyword objects. * SRFI-88:: Keyword objects.
* SRFI-98:: Accessing environment variables. * SRFI-98:: Accessing environment variables.
* SRFI-105:: Curly-infix expressions. * SRFI-105:: Curly-infix expressions.
@ -154,9 +156,11 @@ srfi-16
srfi-23 srfi-23
srfi-30 srfi-30
srfi-39 srfi-39
srfi-46
srfi-55 srfi-55
srfi-61 srfi-61
srfi-62 srfi-62
srfi-87
srfi-105 srfi-105
@end example @end example
@ -4649,6 +4653,15 @@ apply @code{force} to arguments of deconstructors (e.g., @code{car},
wrap procedure bodies with @code{(lazy ...)}. wrap procedure bodies with @code{(lazy ...)}.
@end itemize @end itemize
@node SRFI-46
@subsection SRFI-46 Basic syntax-rules Extensions
@cindex SRFI-46
Guile's core @code{syntax-rules} supports the extensions specified by
SRFI-46/R7RS. Tail patterns have been supported since at least Guile
2.0, and custom ellipsis identifiers have been supported since Guile
2.0.10. @xref{Syntax Rules}.
@node SRFI-55 @node SRFI-55
@subsection SRFI-55 - Requiring Features @subsection SRFI-55 - Requiring Features
@cindex SRFI-55 @cindex SRFI-55
@ -5033,6 +5046,14 @@ Answer a hash value appropriate for equality predicate @code{equal?},
@code{hash} is a backwards-compatible replacement for Guile's built-in @code{hash} is a backwards-compatible replacement for Guile's built-in
@code{hash}. @code{hash}.
@node SRFI-87
@subsection SRFI-87 => in case clauses
@cindex SRFI-87
Starting from version 2.0.6, Guile's core @code{case} syntax supports
@code{=>} in clauses, as specified by SRFI-87/R7RS.
@xref{Conditionals}.
@node SRFI-88 @node SRFI-88
@subsection SRFI-88 Keyword Objects @subsection SRFI-88 Keyword Objects
@cindex SRFI-88 @cindex SRFI-88

View file

@ -334,9 +334,11 @@ cbip_fill_input (SCM port)
if (c_port->read_pos >= c_port->read_end) if (c_port->read_pos >= c_port->read_end)
{ {
/* Invoke the user's `read!' procedure. */ /* Invoke the user's `read!' procedure. */
unsigned c_octets; size_t c_octets, c_requested;
SCM bv, read_proc, octets; SCM bv, read_proc, octets;
c_requested = c_port->read_buf_size;
/* Use the bytevector associated with PORT as the buffer passed to the /* Use the bytevector associated with PORT as the buffer passed to the
`read!' procedure, thereby avoiding additional allocations. */ `read!' procedure, thereby avoiding additional allocations. */
bv = SCM_CBIP_BYTEVECTOR (port); bv = SCM_CBIP_BYTEVECTOR (port);
@ -350,8 +352,10 @@ cbip_fill_input (SCM port)
== SCM_BYTEVECTOR_LENGTH (bv)); == SCM_BYTEVECTOR_LENGTH (bv));
octets = scm_call_3 (read_proc, bv, SCM_INUM0, octets = scm_call_3 (read_proc, bv, SCM_INUM0,
SCM_I_MAKINUM (CBIP_BUFFER_SIZE)); scm_from_size_t (c_requested));
c_octets = scm_to_uint (octets); c_octets = scm_to_size_t (octets);
if (SCM_UNLIKELY (c_octets > c_requested))
scm_out_of_range (FUNC_NAME, octets);
c_port->read_pos = (unsigned char *) SCM_BYTEVECTOR_CONTENTS (bv); c_port->read_pos = (unsigned char *) SCM_BYTEVECTOR_CONTENTS (bv);
c_port->read_end = (unsigned char *) c_port->read_pos + c_octets; c_port->read_end = (unsigned char *) c_port->read_pos + c_octets;

View file

@ -2022,8 +2022,6 @@ scm_get_hash_procedure (int c)
} }
} }
#define SCM_ENCODING_SEARCH_SIZE (500)
static int static int
is_encoding_char (char c) is_encoding_char (char c)
{ {
@ -2033,9 +2031,20 @@ is_encoding_char (char c)
return strchr ("_-.:/,+=()", c) != NULL; return strchr ("_-.:/,+=()", c) != NULL;
} }
/* Search the first few hundred characters of a file for an Emacs-like coding /* Maximum size of an encoding name. This is a bit more than the
declaration. Returns either NULL or a string whose storage has been longest name listed at
allocated with `scm_gc_malloc ()'. */ <http://www.iana.org/assignments/character-sets> ("ISO-2022-JP-2", 13
characters.) */
#define ENCODING_NAME_MAX_SIZE 20
/* Number of bytes at the beginning or end of a file that are scanned
for a "coding:" declaration. */
#define SCM_ENCODING_SEARCH_SIZE (500 + ENCODING_NAME_MAX_SIZE)
/* Search the SCM_ENCODING_SEARCH_SIZE bytes of a file for an Emacs-like
coding declaration. Returns either NULL or a string whose storage
has been allocated with `scm_gc_malloc'. */
char * char *
scm_i_scan_for_encoding (SCM port) scm_i_scan_for_encoding (SCM port)
{ {
@ -2094,7 +2103,7 @@ scm_i_scan_for_encoding (SCM port)
if ((pos = strstr(pos, "coding")) == NULL) if ((pos = strstr(pos, "coding")) == NULL)
return NULL; return NULL;
pos += strlen("coding"); pos += strlen ("coding");
if (pos - header >= SCM_ENCODING_SEARCH_SIZE || if (pos - header >= SCM_ENCODING_SEARCH_SIZE ||
(*pos == ':' || *pos == '=')) (*pos == ':' || *pos == '='))
{ {
@ -2108,6 +2117,13 @@ scm_i_scan_for_encoding (SCM port)
(*pos == ' ' || *pos == '\t')) (*pos == ' ' || *pos == '\t'))
pos ++; pos ++;
if (pos - header >= SCM_ENCODING_SEARCH_SIZE - ENCODING_NAME_MAX_SIZE)
/* We found the "coding:" string, but there is probably not enough
room to store an encoding name in its entirety, so ignore it.
This makes sure we do not end up returning a truncated encoding
name. */
return NULL;
/* grab the next token */ /* grab the next token */
encoding_start = pos; encoding_start = pos;
i = 0; i = 0;

View file

@ -4218,9 +4218,11 @@ when none is available, reading FILE-NAME with READER."
srfi-23 ;; `error` procedure srfi-23 ;; `error` procedure
srfi-30 ;; nested multi-line comments srfi-30 ;; nested multi-line comments
srfi-39 ;; parameterize srfi-39 ;; parameterize
srfi-46 ;; basic syntax-rules extensions
srfi-55 ;; require-extension srfi-55 ;; require-extension
srfi-61 ;; general cond clause srfi-61 ;; general cond clause
srfi-62 ;; s-expression comments srfi-62 ;; s-expression comments
srfi-87 ;; => in case clauses
srfi-105 ;; curly infix expressions srfi-105 ;; curly infix expressions
)) ))

View file

@ -1,6 +1,6 @@
;;; HTTP response objects ;;; HTTP response objects
;; Copyright (C) 2010, 2011, 2012, 2013 Free Software Foundation, Inc. ;; Copyright (C) 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
;; This library is free software; you can redistribute it and/or ;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public ;; modify it under the terms of the GNU Lesser General Public
@ -246,16 +246,21 @@ closes PORT, unless KEEP-ALIVE? is true."
bytes-read len)) bytes-read len))
(define (read! bv start count) (define (read! bv start count)
(let ((ret (get-bytevector-n! port bv start count))) ;; Read at most LEN bytes in total. HTTP/1.1 doesn't say what to do
(if (eof-object? ret) ;; when a server provides more than the Content-Length, but it seems
(if (= bytes-read len) ;; wise to just stop reading at LEN.
0 (let ((count (min count (- len bytes-read))))
(fail)) (let loop ((ret (get-bytevector-n! port bv start count)))
(begin (cond ((eof-object? ret)
(set! bytes-read (+ bytes-read ret)) (if (= bytes-read len)
(if (> bytes-read len) 0 ; EOF
(fail) (fail)))
ret))))) ((and (zero? ret) (> count 0))
;; Do not return zero since zero means EOF, so try again.
(loop (get-bytevector-n! port bv start count)))
(else
(set! bytes-read (+ bytes-read ret))
ret)))))
(define close (define close
(and (not keep-alive?) (and (not keep-alive?)

View file

@ -1,6 +1,6 @@
;;;; coding.test --- test suite for coding declarations. -*- mode: scheme -*- ;;;; coding.test --- test suite for coding declarations. -*- mode: scheme -*-
;;;; ;;;;
;;;; Copyright (C) 2011, 2013 Free Software Foundation, Inc. ;;;; Copyright (C) 2011, 2013, 2014 Free Software Foundation, Inc.
;;;; ;;;;
;;;; This library is free software; you can redistribute it and/or ;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public ;;;; modify it under the terms of the GNU Lesser General Public
@ -101,4 +101,10 @@
(pass-if-equal "second line, whitespace, nl" (pass-if-equal "second line, whitespace, nl"
"ISO-8859-1" "ISO-8859-1"
(scan-coding "\n; coding: iso-8859-1 \n"))) (scan-coding "\n; coding: iso-8859-1 \n"))
(pass-if-equal "http://bugs.gnu.org/16463"
;; On Guile <= 2.0.9, this would return "ISO-8".
"ISO-8859-1"
(scan-coding (string-append (make-string 485 #\space)
"; coding: ISO-8859-1"))))

View file

@ -411,6 +411,15 @@
(not (or (port-has-port-position? port) (not (or (port-has-port-position? port)
(port-has-set-port-position!? port))))) (port-has-set-port-position!? port)))))
(pass-if-exception "custom binary input port 'read!' returns too much"
exception:out-of-range
;; In Guile <= 2.0.9 this would segfault.
(let* ((read! (lambda (bv start count)
(+ count 4242)))
(port (make-custom-binary-input-port "the port" read!
#f #f #f)))
(get-bytevector-all port)))
(pass-if-equal "custom binary input port supports `port-position', \ (pass-if-equal "custom binary input port supports `port-position', \
not `set-port-position!'" not `set-port-position!'"
42 42

View file

@ -1,7 +1,7 @@
;;;; syntax.test --- test suite for Guile's syntactic forms -*- scheme -*- ;;;; syntax.test --- test suite for Guile's syntactic forms -*- scheme -*-
;;;; ;;;;
;;;; Copyright (C) 2001, 2003, 2004, 2005, 2006, 2009, 2010, ;;;; Copyright (C) 2001, 2003, 2004, 2005, 2006, 2009, 2010,
;;;; 2011, 2012, 2013 Free Software Foundation, Inc. ;;;; 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
;;;; ;;;;
;;;; This library is free software; you can redistribute it and/or ;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public ;;;; modify it under the terms of the GNU Lesser General Public
@ -1275,7 +1275,20 @@
'((((x y) …) ...) '((((x y) …) ...)
(((x y) ...) …))))))) (((x y) ...) …)))))))
(define-syntax bar (foo x y z)) (define-syntax bar (foo x y z))
(bar a b c)))) (bar a b c)))
;; This test is given in SRFI-46.
(pass-if-equal "custom ellipsis is handled hygienically"
'((1) 2 (3) (4))
(let-syntax
((f (syntax-rules ()
((f ?e)
(let-syntax
((g (syntax-rules --- ()
((g (??x ?e) (??y ---))
'((??x) ?e (??y) ---)))))
(g (1 2) (3 4)))))))
(f ---))))
(with-test-prefix "syntax-error" (with-test-prefix "syntax-error"

View file

@ -1,6 +1,6 @@
;;;; web-response.test --- HTTP responses -*- mode: scheme; coding: utf-8; -*- ;;;; web-response.test --- HTTP responses -*- mode: scheme; coding: utf-8; -*-
;;;; ;;;;
;;;; Copyright (C) 2010, 2011, 2012, 2013 Free Software Foundation, Inc. ;;;; Copyright (C) 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
;;;; ;;;;
;;;; This library is free software; you can redistribute it and/or ;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public ;;;; modify it under the terms of the GNU Lesser General Public
@ -39,7 +39,9 @@ Content-Encoding: gzip\r
Content-Length: 36\r Content-Length: 36\r
Content-Type: text/html; charset=utf-8\r Content-Type: text/html; charset=utf-8\r
\r \r
abcdefghijklmnopqrstuvwxyz0123456789") abcdefghijklmnopqrstuvwxyz0123456789
-> Here is trailing garbage that should be ignored because it is
beyond Content-Length.")
(define example-2 (define example-2
"HTTP/1.1 200 OK\r "HTTP/1.1 200 OK\r