1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00
Commit graph

3553 commits

Author SHA1 Message Date
Andy Wingo
ce934bcd43 Add allow-legacy-syntax-objects? parameter
* module/ice-9/psyntax.scm (syntax?): Only recognize legacy syntax
  objects if the new allow-legacy-syntax-objects? parameter is true.
* module/ice-9/boot-9.scm (allow-legacy-syntax-objects?): New
  parameter.
* doc/ref/api-macros.texi (Syntax Transformer Helpers): Document the
  horrible situation with legacy syntax objects.
* NEWS: Add entry.
2017-03-28 21:27:11 +02:00
Andy Wingo
a42bfae65f Psyntax generates new syntax objects
* module/ice-9/psyntax.scm (make-syntax-object): Change to make
  new-style syntax objects.
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/ice-9/compile-psyntax.scm (squeeze-syntax-object): Change to be
  functional.
  (squeeze-constant): Likewise.
  (squeeze-tree-il): Likewise.
  (translate-literal-syntax-objects): New pass.  The compiler can embed
  literal syntax objects into compiled objects, but syntax can no longer
  be read/written; otherwise users could forge syntax objects.  So for
  the bootstrap phase, rewrite literal constants to calls to
  make-syntax.
2017-03-28 19:23:13 +02:00
Andy Wingo
eb84c2f2da Beginnings of psyntax switch to new syntax objects
* module/ice-9/psyntax.scm: Baby steps towards support of a new
  representation of syntax objects.
* module/ice-9/psyntax-pp.scm: Regenerate.
2017-03-28 19:23:13 +02:00
Andy Wingo
64c5cc58fc Add disjoint syntax object type
* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (DOT_X_FILES, DOT_DOC_FILES, noinst_HEADERS): Add syntax.c and
  syntax.h.
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (class_syntax, scm_class_of, scm_goops_early_init):
* libguile/init.c (scm_init_guile):
* libguile/print.c (iprin1):
* libguile/tags.h (scm_tc7_syntax):
* module/oop/goops.scm (<syntax>):
* module/system/base/types.scm (%tc7-syntax, cell->object):
* module/system/vm/disassembler.scm (code-annotation): Wire up the new
  data type.
* libguile/syntax.c:
* libguile/syntax.h: New files.
* module/ice-9/boot-9.scm: Move new definitions to (system syntax
  internal).
* module/system/syntax.scm (print-syntax): New helper.
* module/system/vm/assembler.scm (statically-allocatable?)
  (intern-constant, link-data): Arrange to be able to write syntax
  objects into images.
* module/language/cps/types.scm (&syntax): New type.  Remove
  &hash-table; it was never detected, an internal binding, and we need
  the bit to avoid going into bignum territory.
2017-03-28 19:23:13 +02:00
Andy Wingo
6ba3f35f26 Plumbing changes to rename "syntax-module"
* module/ice-9/psyntax.scm (%syntax-module): Rename from syntax-module
  in order to make room for a new syntax-module primitive binding.
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/ice-9/boot-9.scm: Push syntax bindings into an internal
  module.
* module/system/syntax.scm: New file.
* module/Makefile.am (SOURCES): Add system/syntax.scm.
2017-03-28 19:23:13 +02:00
Mike Gran
5d2aa5f1ad i18n: add international sign positions to %locale-dump
* module/ice-9/i18n.scm (%locale-dump): modified
2017-03-20 22:35:49 -07:00
Mike Gran
c818684252 i18n: add debugging helper procedure for locales
* module/ice-9/i18n.scm (%locale-dump): new procedure
2017-03-20 20:20:29 -07:00
Mike Gran
7e218d35ac i18n: rename locale-monetary-digit-grouping to locale-monetary-grouping
* module/ice-9/i18n.scm (locale-monetary-digit-grouping): renamed to locale-monetary grouping
  (monetary-amount->locale-string): use renamed procedure
* test-suite/tests/i18n.test (%french-locale): add LC_MONETARY
  (%french-utf8-locale): add LC_MONETARY
  ("nl-langinfo et al."): tests for locale-monetary-grouping
2017-03-20 07:29:47 -07:00
Ludovic Courtès
aa86fcb7d9 web: Avoid deprecated '_IOFBF'.
* module/web/client.scm (open-socket-for-uri): Use 'block instead of
_IOFBF.
2017-03-17 23:37:57 +01:00
Ludovic Courtès
011669af3b web: Remove export of nonexistent 'open-connection-for-uri'.
* module/web/client.scm: Don't export 'open-connection-for-uri', which
doesn't exist.
2017-03-17 23:35:24 +01:00
Andy Wingo
db19853b06 Update --version and REPL copyright years
* module/ice-9/command-line.scm (version-etc):
* module/system/repl/common.scm (*version*): Update release year.
2017-03-15 09:12:55 +01:00
Andy Wingo
0543ec96b2 Nonlocal prompt returns cause all effects
* module/language/cps/effects-analysis.scm (expression-effects): Prompts
  cause &all-effects.  I tried to limit this change to CSE but it was
  actually LICM that was borked, so better to be conservative
* test-suite/tests/control.test ("escape-only continuations"): Add
  test.
2017-03-13 22:20:16 +01:00
Andy Wingo
c525aa6d95 VM support for string-set!; slimmer read-string
* doc/ref/vm.texi (Inlined Scheme Instructions): Add string-set!.
* libguile/vm-engine.c (string-set!): New opcode.
* module/ice-9/rdelim.scm (read-string): Reimplement in terms of a
  geometrically growing list of strings, to reduce total heap usage when
  reading big files.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  string-set! support.
* module/language/cps/types.scm (string-set!): Update for &u64 index.
* module/language/tree-il/compile-cps.scm (convert): Unbox index to
  string-set!.
* module/system/vm/assembler.scm (system): Export string-set!.
2017-03-09 17:24:06 +01:00
Daniel Llorens
7de77bf7d8 Fix bug in comparison between real and complex
This bug was introduced by 35a9059250.

* module/language/cps/specialize-numbers.scm (specialize-operations):
  Check that both operands are real as a condition for
  specialize-f64-comparison.
* test-suite/tests/numbers.test: Add test.
2017-03-09 15:17:35 +01:00
Andy Wingo
7cdfaaada9 Remove contification restriction in case-lambda
* module/language/cps/compile-bytecode.scm (compile-function): Check for
  fallthrough after $kclause too; possible to need to jump if clause
  tails are contified.
* module/language/cps/contification.scm (compute-contification-candidates):
  Enable inter-clause contification.
2017-03-09 14:47:42 +01:00
Andy Wingo
6d9335ad46 All clauses of function have same nlocals
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/slot-allocation.scm ($allocation)
  (lookup-nlocals, compute-frame-size, allocate-slots): Adapt to
  have one frame size per function, for all clauses.
2017-03-09 14:25:37 +01:00
Andy Wingo
f7909b9516 Adapt gcprof to preemptive interrupts
* module/statprof.scm (gcprof): Remove handle-interrupts trampoline from
  captured stacks.
2017-03-09 10:48:02 +01:00
Andy Wingo
e7d3414079 Adapt statprof to new preemptive interrupts
* module/statprof.scm (profile-signal-handler): Cut an additional stack
  frame, corresponding to the handle-interrupts trampoline added
  recently.
2017-03-09 10:44:09 +01:00
Ludovic Courtès
bfa3883592 statprof: 'with-statprof' honors #:display-style.
* module/statprof.scm (with-statprof): Pass #:display-style to 'statprof'.
2017-03-09 10:33:11 +01:00
Andy Wingo
c62f0b0256 64KB segment alignment
* module/system/vm/linker.scm (*lcm-page-size*): Rename
  from *page-size*, change to 64 KB.
* libguile/loader.c (load_thunk_from_memory): Only require page size
  alignment, knowing that although Guile might emit ELF with 64k
  alignment, it only really needs page alignment.
2017-03-08 22:49:24 +01:00
Mark H Weaver
84a740d86a psyntax: Generate identifiers in a deterministic fashion.
Fixes <http://bugs.gnu.org/20272>.

* module/ice-9/boot-9.scm (module-generate-unique-id!)
(module-gensym): New procedures.
(module): Add 'next-unique-id' field.
(the-root-module): Inherit 'next-unique-id' value from early stub.
(make-module, make-autoload-interface): Adjust calls to
module-constructor.
* module/ice-9/psyntax.scm (gen-label, new-mark): Generate unique
identifiers from the module name and the per-module unique-id.
(build-lexical-var, generate-temporaries): Use
'module-gensym' instead of 'gensym'.
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/language/tree-il/fix-letrec.scm (fix-letrec!): Use
'module-gensym' instead of 'gensym'.
* module/system/base/syntax.scm (define-record): Likewise.
(transform-record): Likewise.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2017-03-07 20:48:40 +01:00
Ludovic Courtès
de5cf50aba i18n: 'number->locale-string' guesses the minimum number of decimals.
This feature was removed by 4aead68cdb.

* module/ice-9/i18n.scm (number-decimal-string): Rewrite the case where
DIGIT-COUNT is not an integer.
(number->locale-string): Always pass FRACTION-DIGITS to
'number-decimal-string'.
* test-suite/tests/format.test ("~h localized number")["1234.5"]
["padding", "padchar"]: Remove decimal specifier.
* test-suite/tests/i18n.test ("number->locale-string")
["fraction",
* test-suite/tests/i18n.test ("format ~h")["12 345,678"]: Remove decimal
specifier.  Remove one decimal.
* doc/ref/api-i18n.texi (Number Input and Output): Update
'number->locale-string' doc to mention the number of decimals.
2017-03-01 21:16:49 +01:00
Ludovic Courtès
4c7d1a64fa i18n: Fix corner cases for monetary and number string conversions.
Fixes <http://bugs.gnu.org/24990>.
Reported by Martin Michel <dev@famic.de>.

* module/ice-9/i18n.scm (integer->string, number-decimal-string): New
procedures.
(monetary-amount->locale-string): Use them instead of 'number->string'
followed by 'string-split'.
(number->locale-string): Likewise.
* test-suite/tests/i18n.test ("number->locale-string")["fraction"]: Add
second argument to 'number->locale-string'.
["fraction, 1 digit"]: Round up.
["fraction, 10 digits", "trailing zeros", "negative integer"]: New
tests.
* test-suite/tests/i18n.test ("format ~h"): Pass the number of decimals
for ~h.
("monetary-amount->locale-string")["French"]: Always expect two decimals
after the comma.
["one cent", "very little money"]: New tests.
* test-suite/tests/format.test ("~h localized number")["1234.5"]:
Specify the number of decimals explicitly.
["padding"]: Expect zero decimals.
["padchar"]: Ask for one decimal.
["decimals", "locale"]: Adjust rounding.
2017-03-01 21:16:25 +01:00
Ludovic Courtès
19d274c680 i18n: Do not represent zero as "-0".
Partly fixes <http://bugs.gnu.org/24990>.
Reported by Martin Michel <dev@famic.de>.

* module/ice-9/i18n.scm (monetary-amount->locale-string): Don't negate
AMOUNT when it's zero.
(number->locale-string): Likewise.
* test-suite/tests/i18n.test ("number->locale-string")["positive inexact
zero, 1 digit"]: New test.
("monetary-amount->locale-string")["positive inexact zero"]: New test.
2017-03-01 21:04:42 +01:00
John Paul Adrian Glaubitz
92222727f8 Recognize sh3 as compilation targets
* module/system/base/target.scm (cpu-endianness, triplet-pointer-size):
  Add case for "sh3".

Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2017-03-01 21:04:31 +01:00
Ludovic Courtès
4d3a14924f scandir: Avoid 'stat' calls on each entry.
* module/ice-9/ftw.scm (scandir): Rewrite in terms of 'readdir'.
2017-03-01 20:40:26 +01:00
Mark H Weaver
402162cfcf REPL Server: Guard against HTTP inter-protocol exploitation attacks.
Reported by Christopher Allan Webber <cwebber@dustycloud.org>
Co-authored-by: Ludovic Courtès <ludo@gnu.org>

This commit adds protection to Guile's REPL servers against HTTP
inter-protocol exploitation attacks, a scenario whereby an attacker can,
via an HTML page, cause a web browser to send data to TCP servers
listening on a loopback interface or private network.  See
<https://en.wikipedia.org/wiki/Inter-protocol_exploitation> and
<https://www.jochentopf.com/hfpa/hfpa.pdf>, The HTML Form Protocol
Attack (2001) by Tochen Topf <jochen@remote.org>.

Here we add a procedure to 'before-read-hook' that looks for a possible
HTTP request-line in the first line of input from the client socket.  If
present, the socket is drained and closed, and a loud warning is written
to stderr (POSIX file descriptor 2).

* module/system/repl/server.scm: Add 'maybe-check-for-http-request'
to 'before-read-hook' when this module is loaded.
(with-temporary-port-encoding, with-saved-port-line+column)
(drain-input-and-close, permissive-http-request-line?)
(check-for-http-request, guard-against-http-request)
(maybe-check-for-http-request): New procedures.
(serve-client): Use 'guard-against-http-request'.
* module/system/repl/coop-server.scm (start-repl-client): Use
'guard-against-http-request'.
* doc/ref/guile-invoke.texi (Command-line Options): In the description
of the --listen option, make the security warning more prominent.
Mention the new protection added here.  Recommend using UNIX domain
sockets for REPL servers.  "a path to" => "the file name of".
2017-03-01 20:13:13 +01:00
Mark H Weaver
b56b944920 http: Do not use 'eq?' to compare characters in parse-request-uri.
* module/web/http.scm (parse-request-uri): Use 'eqv?' to compare
characters.
2017-03-01 19:50:37 +01:00
Ludovic Courtès
7a32add5dc texinfo: Remove unnecessary (oop goops) dependency.
* module/texinfo/string-utils.scm: Remove #:use-module (oop goops).
2017-03-01 19:28:04 +01:00
Andy Wingo
0cd60c3f26 Cosmetic REPL server improvements
* module/system/repl/server.scm (run-server*): Cosmetic improvements.
2017-03-01 17:23:29 +01:00
Andy Wingo
374b88580c Fix trap frame matching
* module/system/vm/traps.scm (program-last-ip): Actually return an
  absolute IP.  Fixes traps!
2017-03-01 16:06:53 +01:00
Andy Wingo
77cfd7e4bf Fix class slot allocation since GOOPS rewrite
* module/oop/goops.scm (%compute-layout): Fix class slot layout.
  Before, a #:class that was an argument to #:allocation was getting
  interpreted as a keyword with a value.
* test-suite/tests/goops.test ("#:class slot allocation"): Add test.
2017-03-01 15:37:05 +01:00
Andy Wingo
e13cd5c77c Flush when getting string from r6rs string output port
* module/rnrs/io/ports.scm (open-string-output-port): Calling the
  get-string proc should flush the buffer and reset the file position.
* test-suite/tests/r6rs-ports.test ("8.2.10 Output ports"): Add tests.
  Thanks to Freja Nordsiek for the report.
2017-03-01 14:26:11 +01:00
Wilfred Hughes
67b8b6fb06 Favor docstrings for describing the purpose of functions.
* module/ice-9/boot-9.scm: Where functions have docstring-style
  comments, make them proper docstrings.
2017-03-01 10:09:38 +01:00
Andy Wingo
68f13adaaf Better errors for odd-length keyword args
* libguile/vm-engine.c (bind-kwargs):
* libguile/vm.c (vm_error_kwargs_missing_value):
* libguile/eval.c (error_missing_value)
  (prepare_boot_closure_env_for_apply): Adapt to mirror VM behavior.
* libguile/keywords.c (scm_c_bind_keyword_arguments): Likewise.
* module/ice-9/eval.scm (primitive-eval): Update to error on (foo #:kw)
  with a "Keyword argument has no value" instead of the horrible "odd
  argument list length".  Also adapts to the expected args format for
  the keyword-argument-error exception printer in all cases.  Matches
  1.8 optargs behavior also.
* test-suite/standalone/test-scm-c-bind-keyword-arguments.c (test_missing_value):
  (missing_value_error_handler): Update test.
* test-suite/tests/optargs.test: Add tests.
2017-02-28 22:01:20 +01:00
Andy Wingo
631e9901d8 Declare module exports before loading imports
* module/ice-9/boot-9.scm (define-module*): Process module imports after
  module exports.  Allows for an additional kind of circular module
  imports (see https://bugs.gnu.org/15540).
* test-suite/tests/modules.test ("circular imports"): Add test.
2017-02-28 11:49:15 +01:00
Andy Wingo
9e28a12121 Revert "futures: Limit the number of nested futures on the same stack."
This reverts commit 8a177d316c, though
keeping the additional tests.  (Guile 2.2 doesn't have a fixed stack
limit).
2017-02-28 10:45:21 +01:00
Andy Wingo
f261eaf03a Fix guild compile --to=cps / --from=cps
* module/language/cps/spec.scm (read-cps, write-cps): Fix CPS
  serialization and parsing, so that "guild compile" works with --to=cps
  and --from=cps.
2017-02-23 11:37:44 +01:00
Andy Wingo
23278d07de Fix kfun parse-cps bug
* module/language/cps.scm (parse-cps): Fix bug parsing kfun.
2017-02-23 11:37:06 +01:00
Andy Wingo
c7fb87cd6e Fix multi-arity dispatch in GOOPS
* module/oop/goops.scm (multiple-arity-dispatcher): Fix dispatch for
  max-arity+1 when a generic is already in multiple-arity dispatch.
  Fixes #24454.
* test-suite/tests/goops.test ("dispatch"): Add test.
2017-02-22 23:10:46 +01:00
Andy Wingo
4dcc97288d Fix compute-frame-sizes for case-lambda jumps
* module/system/vm/frame.scm (compute-frame-sizes): Fix for jumps to the
  next arity.
2017-02-22 22:22:27 +01:00
Andy Wingo
d0811644f6 Fix flonum/complex type inference.
* module/language/cps/types.scm (define-binary-result!): Arithmetic
  where one argument is a flonum may produce a complex.
* test-suite/tests/compiler.test: Add test.
2017-02-19 12:11:07 +01:00
Andy Wingo
d0934df1f2 Stringbufs immutable by default
* libguile/snarf.h (SCM_IMMUTABLE_STRINGBUF): Remove shared flag.
  Stringbufs are immutable by default.
* libguile/strings.c: Rewrite blurb.  Change to have stringbufs be
  immutable by default and mutable only when marked as such.  Going
  mutable means making a private copy.
  (STRINGBUF_MUTABLE, STRINGBUF_F_MUTABLE): New definitions.
  (SET_STRINGBUF_SHARED): Remove.
  (scm_i_print_stringbuf): Simplify to just alias the stringbuf as-is.
  (substring_with_immutable_stringbuf): New helper.
  (scm_i_substring, scm_i_substring_read_only, scm_i_substring_copy):
  use new helper.
  (scm_i_string_ensure_mutable_x): New helper.
  (scm_i_substring_shared): Use scm_i_string_ensure_mutable_x.
  (stringbuf_write_mutex): Remove; yaaaaaaaay.
  (scm_i_string_start_writing): Use scm_i_string_ensure_mutable_x.  No
  more mutex.
  (scm_i_string_stop_writing): Now a no-op.
  (scm_i_make_symbol): Use substring/copy.
  (scm_sys_string_dump, scm_sys_symbol_dump): Update.
* libguile/strings.h (SCM_I_STRINGBUF_F_SHARED): Remove.
  (SCM_I_STRINGBUF_F_MUTABLE): Add.
* module/system/vm/assembler.scm (link-data): Don't add shared flag any
  more.  Existing compiled flags are harmless tho.
* test-suite/tests/strings.test ("string internals"): Update.
2017-02-16 13:11:29 +01:00
Andy Wingo
6e0965104c Add accept4 support
* doc/ref/posix.texi (Network Sockets and Communication): Add
  documentation.
* libguile/socket.c (scm_accept4): New function, replaces accept
  implementation.
  (scm_accept): Call scm_accept4.
  (scm_init_socket): Define SOCK_CLOEXEC and SOCK_NONBLOCK.
* libguile/socket.h: Add private scm_accept4 decl.
* module/ice-9/suspendable-ports.scm (accept): Update.
2017-02-15 22:10:25 +01:00
Andy Wingo
710ebfddc6 Web server and client use suspendable ports
* module/web/request.scm (write-request):
* module/web/response.scm (write-response): Use put-string instead of
  display.
2017-02-08 15:16:25 +01:00
Andy Wingo
8a4774dec8 Prevent TOCTTOU bugs in suspendable ports
* module/ice-9/suspendable-ports.scm: Prevent TOCTTOU bugs by
  additionally returning the buffer and offset when we compute an
  amount-buffered.
2017-02-08 15:09:14 +01:00
Andy Wingo
ecdff904cb Remove remaining "display" uses in (web http)
* module/web/http.scm (header-writer): Default to calling put-string.
  (put-list): Rename from write-list, take the port first, and call the
  put-item function with port then value.  Adapt all callers.
  (write-date): Rename display-digits to put-digits.
  (put-challenge): Rename from write-challenge, adapt arguments to put
  convention, and adapt callers.
  (declare-symbol-list-header!): Use put-symbol.
  (declare-integer-header!): Use put-non-negative-integer.o
  (declare-entity-tag-list-header!): Use put-entity-tag-list.
  ("If-Range", "Etag"): Adapt to put-entity-tag.
  (make-chunked-output-port): Use put-char.
2017-02-08 15:09:14 +01:00
Andy Wingo
96b994b6f8 Beginnings of suspendable HTTP
* module/web/http.scm: Use put-string and other routines from (ice-9
  textual-ports) in preference to `display'.  The goal is for these
  operations to be suspendable.
2017-02-08 15:09:14 +01:00
Andy Wingo
8c50060ae9 Modernize (web http) a bit
* module/web/http.scm: Modernize the Guile Scheme by using more match,
  when, unless, and non-tail conversion.  No functional change, with the
  exception of fixing a bug in write-key-value-list for symbols like
  100-continue that shouldn't print as #{100-continue}#.
* test-suite/tests/web-http.test (pass-if-only-parse):
  (pass-if-reparse, pass-if-parse): Arrange to also serialize and
  reparse values from pass-if-parse.  Apply to all existing tests except
  fragments where we don't expect fragments to be written out.
2017-02-08 15:09:14 +01:00
Daniel Llorens
93cbaef134 Fix rank 0 arrays and nested arrays in truncated-print
* module/ice-9/pretty-print.scm (print): In the array case, pass
  #:inner? along to (print-sequence), unless we're at the last dimension
  of the array.
  Special case for 0-rank arrays, which cannot be empty and have no
  length.
* test-suite/tests/print.test: Test some of the cases fixed by this
  patch.
2017-02-07 15:56:40 +01:00