1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 04:10:18 +02:00
Commit graph

6845 commits

Author SHA1 Message Date
Ludovic Courtès
ceed7709be Slightly optimize `gensym'.
* libguile/symbols.c (default_gensym_prefix): New variable.
  (scm_gensym): Use it.  Use `scm_from_latin1_stringn' instead of
  `scm_from_locale_stringn'.
  (scm_init_symbols): Initialize DEFAULT_GENSYM_PREFIX.
2011-03-06 23:05:00 +01:00
Ludovic Courtès
d8f1c2162c Simply grow string port buffers geometrically.
* libguile/strports.c (SCM_WRITE_BLOCK): Remove.
  (st_flush): Multiply `pt->write_buf_size' by 2.
  (st_seek): Likewise when TARGET == PT->write_buf_size.
2011-03-06 23:05:00 +01:00
Ludovic Courtès
0b2c2ba353 Let `scm_mkstrport' allocate buffers on the caller's behalf.
* libguile/strports.c (INITIAL_BUFFER_SIZE): New macro.
  (scm_mkstrport): If STR is false, allocate a bytevector on the
  caller's behalf.
  (scm_object_to_string, scm_call_with_output_string,
  scm_open_output_string): Pass SCM_BOOL_F as the STR argument of
  `scm_mkstrport'.

* libguile/backtrace.c (scm_display_application,
  display_backtrace_body): Likewise.

* libguile/gdbint.c (scm_init_gdbint): Likewise.

* libguile/print.c (scm_simple_format): Likewise.
2011-03-06 23:05:00 +01:00
Ludovic Courtès
691fcf66c0 Use a bytevector as the backing buffer of string ports.
* libguile/strports.c (st_resize_port): Adjust to deal with OLD_STREAM
  and NEW_STREAM as bytevectors.
  (scm_mkstrport): Store a bytevector in the port's stream rather than a
  string.
2011-03-06 23:05:00 +01:00
Andy Wingo
b6b84131cd remove obsolete comments
* libguile/eval.c (scm_nconc2last):
* libguile/strports.c (scm_c_read_string): Remove some obsolete
  comments.
2011-03-05 21:48:47 +01:00
BT Templeton
fd029c35de guile-snarf: allow multiple init actions on one line
* libguile/guile-snarf.in (modern_snarf): Allow programs to specify
  multiple initialization actions on a single line. This makes it
  possible for C programs to define multiple subrs with a single macro
  invocation.

* test-suite/standalone/test-guile-snarf: Enable more tests.
2011-03-04 11:34:24 +01:00
Andy Wingo
d900843c72 fix encoding scanning for non-seekable ports
* libguile/read.c (scm_i_scan_for_encoding): If possible, just use the
  read buffer for the encoding scan, and avoid seeking.  Fixes
  `(open-input-file "/dev/urandom")', because /dev/urandom can't be
  seeked backwards.
2011-03-03 12:57:46 +01:00
Ludovic Courtès
9c3fa20a56 Remove extra comma after `SCM_ARRAY_ELEMENT_TYPE_LAST'.
* libguile/array-handle.h (scm_t_array_element_type): Remove extra comma
  after last element.  Reported by David Fang <fang@csl.cornell.edu>.
  Indent.
2011-03-03 00:13:30 +01:00
Ludovic Courtès
58b1db5f24 Have `read' update line/column numbers when reading SCSH block comments.
* libguile/read.c (scm_read_scsh_block_comment): Use `scm_getc' instead
  of `scm_get_byte_or_eof'.

* test-suite/tests/reader.test ("read-options")["position of SCSH block
  comment"]: New test.
2011-02-28 23:33:47 +01:00
Andy Wingo
ac012a27a2 update port-filename docs
* doc/ref/api-io.texi (File Ports):
* libguile/ports.c (scm_port_filename): Fix docs to match
  implementation.
2011-02-28 20:54:03 +01:00
Andy Wingo
6800f86d63 make-weak-key-hash-table vacuuming
* libguile/hashtab.c (scm_make_weak_key_hash_table): Whoops, fix the
  case I actually cared about.
2011-02-25 10:48:35 +01:00
Ludovic Courtès
914c4300b2 Make `locale-digit-grouping' more robust.
* libguile/i18n.c (scm_nl_langinfo)[GROUPING]: Consider negative numbers
  like `CHAR_MAX'.  Reported by David Fang <fang@csl.cornell.edu>.
  Fix suggested by Bruno Haible <bruno@clisp.org>.
2011-02-24 23:17:06 +01:00
Andy Wingo
62c290e977 weak hash tables vacuum stale entries after a gc
* libguile/hashtab.c (scm_c_register_weak_gc_callback): New private
  helper, arranges for a C function to be called with a SCM as an
  argument, as long as the argument is reachable by GC.
  (scm_make_weak_key_hash_table)
  (scm_make_weak_value_hash_table)
  (scm_make_doubly_weak_hash_table): Register a weak GC callback to
  vacuum_weak_hash_table.
2011-02-24 17:01:38 +01:00
Andy Wingo
ec7f624d65 re-enable the after-gc-hook
* libguile/gc.c (scm_gc): No need to take a mutex here.  Don't run the
  hook, the hook will run itself.
  (scm_c_register_gc_callback): New private helper, registers a callback
  the next time GC happens.
  (system_gc_callback): Guile's internal callback that runs
  scm_after_gc_c_hook, which itself queues a call to the after-gc-hook.
  (scm_storage_prehistory): Queue up a call to system_gc_callback.
2011-02-24 16:30:08 +01:00
Andy Wingo
574b7be0ba pointerless backing buffers for string ports
* libguile/strports.c (scm_mkstrport): String port string buffer
  allocated atomically.
2011-02-24 13:12:58 +01:00
Andy Wingo
b2548e2344 errno saving in display_string
* libguile/print.c (display_string): Fix a case in which perhaps `errno'
  could have been stompled.
2011-02-24 13:10:16 +01:00
Andy Wingo
40d2a0076a GC dead links in weak hash tables before a possible rehash
* libguile/hashtab.c (vacuum_weak_hash_table): New helper, goes through
  the entirety of a weak hash table, vacuuming dead entries.
  (scm_hash_fn_create_handle_x): If when adding to a weak hash table, we
  would trigger a rehash, vacuum the table first.  The weak_bucket_assoc
  would have only caught dead entries within one bucket.

  Without this patch, the following code leaks:

  (let lp ()
    (call-with-output-string
      (lambda (port)
        (display "foo" port)))
    (lp))
2011-02-23 11:59:38 +01:00
Mark H Weaver
85bdb6ac9c Portability fix for new log and log10
* libguile/numbers.c: Define M_LN2 if it's not already defined.
  Fix error in comment.
2011-02-22 21:04:08 -05:00
Andy Wingo
3e05fc0466 fix a couple leaks in ports.c. thanks valgrind!
* libguile/ports.c (scm_i_remove_port): Fix a case in which ports
  explictly closed via close-port would leak their iconv_t data.
  (scm_set_port_encoding_x): scm_i_set_port_encoding_x strdups its
  argument, so we need to free the locale encoding of the incoming str.
2011-02-18 19:28:37 +01:00
Mark H Weaver
a5f6b751be Improvements to log' and log10'
* libguile/numbers.c (log_of_shifted_double, log_of_exact_integer,
  log_of_exact_integer_with_size, log_of_fraction): New internal static
  functions used by scm_log and scm_log10.

  (scm_log, scm_log10): Robustly handle large integers, large and small
  fractions, and fractions close to 1.  Previously, computing logarithms
  of fractions close to 1 yielded grossly inaccurate results, and the
  other cases yielded infinities even though the answer could easily fit
  in a double.  (log -0.0) now returns -inf.0+<PI>i, where previously it
  returned -inf.0.  (log 0) now throws a numerical overflow exception,
  where previously it returned -inf.0.  (log 0.0) still returns -inf.0.
  Analogous changes made to `log10'.

* test-suite/tests/numbers.test (log, log10): Add tests.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2011-02-16 00:40:35 +01:00
Mark H Weaver
c15fe4999a Use trunc in scm_i_inexact_truncate_divide
* libguile/numbers.c (scm_i_inexact_truncate_divide): Use trunc instead
  of floor and ceil.  Important for consistency with
  scm_truncate_quotient and scm_truncate_remainder.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2011-02-15 14:31:40 +01:00
Ludovic Courtès
bb5b36d069 Fix compilation of `c-tokenize.c' in a cross-compile setup.
* libguile/Makefile.am (c-tokenize.$(OBJEXT)): When cross-compiling,
  don't include any CPPFLAGS since we could end up seeing Gnulib's
  replacements, e.g., `rpl_malloc', which we can't use.
2011-02-15 12:15:02 +01:00
Ludovic Courtès
cae0945c83 Use all the LDFLAGS from Gnulib.
* libguile/Makefile.am (version_info): New variable.
  (libguile_@GUILE_EFFECTIVE_VERSION@_la_LIBADD): Remove
  `$(LTLIBUNISTRING) $(LTLIBICONV) $(LTLIBINTL)'.
  (libguile_@GUILE_EFFECTIVE_VERSION@_la_LDFLAGS): Add all the flags
  from Gnulib, one per line as in the `gnulib-tool' output, including
  those above.
2011-02-15 12:07:49 +01:00
Mark H Weaver
c251ab631e Use trunc instead of scm_c_truncate
* libguile/numbers.c (scm_c_truncate, scm_truncate_number,
  scm_i_inexact_truncate_quotient, scm_i_inexact_truncate_remainder):
  Use trunc directly, now that we have its gnulib module.
2011-02-15 09:20:35 +01:00
Andy Wingo
7017846b2b tweak to internal scm_i_extract_values_2
* libguile/values.c (scm_i_extract_values_2): Make nvalues check more
  robust.
2011-02-14 20:39:31 +01:00
Mark H Weaver
5093e51839 Make SCM_NUMP and SCM_NUMBERP more extensible
* libguile/numbers.h (SCM_NUMP, SCM_NUMBERP): Mask out more bits in the
  cell type field when doing the comparison, in order to accept future
  numeric types that have not yet been implemented.  This should allow
  us to add more core numeric types without breaking ABI compatibility.
  As a bonus, these macros are now more efficient.
2011-02-14 20:32:54 +01:00
Mark H Weaver
f135fc3eda Slight optimization for scm_equal_p
* libguile/eq.c (scm_equal_p): Move SCM_STRUCTP check within the default
  case of the SCM_TYP7 switch statement, for optimization.
2011-02-14 20:32:01 +01:00
Mark H Weaver
a8da6d9338 Reduce code size of division operators
* libguile/numbers.c (scm_quotient): Reimplement in terms of
  scm_truncate_quotient.

  (scm_remainder): Reimplement in terms of scm_truncate_remainder.

  (scm_modulo): Reimplement in terms of scm_floor_remainder.

  (scm_euclidean_quotient, scm_euclidean_remainder,
  scm_euclidean_divide): Reimplement in terms of floor and ceiling.
  Make them non-extensible, because there is no need; they will work
  with any objects that implement the floor and ceiling division
  operators, and that can be tested using `negative?'.
2011-02-14 20:31:25 +01:00
Mark H Weaver
8b56bcec44 Optimize truncate, round, floor, and ceiling
* libguile/numbers.c (scm_c_truncate): Use ceil (x) instead of
  -floor (-x).

  (scm_truncate_number): Implement directly instead of by checking the
  sign and using scm_floor or scm_ceiling.  Use scm_truncate_quotient
  for fractions.  Make extensible, so that new number types implemented
  in GOOPS will be able to do the job more efficiently, since it is
  often easier to implement truncate than floor or ceiling.

  (scm_round_number): Optimize fractions case by using
  scm_round_quotient.  Make extensible, so that new number types
  implemented in GOOPS will be able to do the job efficiently.

  (scm_floor, scm_ceiling): Optimize fractions case by using
  scm_floor_quotient and scm_ceiling_quotient, respectively.

* test-suite/tests/numbers.test: Add test cases.
2011-02-14 20:31:14 +01:00
Mark H Weaver
8f9da3406b Add four new sets of fast quotient and remainder operators
* libguile/numbers.c (scm_floor_divide, scm_floor_quotient,
  scm_floor_remainder, scm_ceiling_divide, scm_ceiling_quotient,
  scm_ceiling_remainder, scm_truncate_divide, scm_truncate_quotient,
  scm_truncate_remainder, scm_round_divide, scm_round_quotient,
  scm_round_remainder): New extensible procedures `floor/',
  `floor-quotient', `floor-remainder', `ceiling/', `ceiling-quotient',
  `ceiling-remainder', `truncate/', `truncate-quotient',
  `truncate-remainder', `round/', `round-quotient', and
  `round-remainder'.

* libguile/numbers.h: Add function prototypes.

* test-suite/tests/numbers.test: Add tests.

* doc/ref/api-data.texi (Arithmetic): Add documentation.

* NEWS: Add NEWS entry.
2011-02-14 20:30:53 +01:00
Mark H Weaver
03ddd15bae Optimize division operators handling of fractions
* libguile/numbers.c: (scm_euclidean_quotient, scm_euclidean_remainder,
  scm_euclidean_divide, scm_centered_quotient, scm_centered_remainder,
  scm_centered_divide): Optimize case where both arguments are exact and
  at least one is a fraction, by reducing to a subproblem involving only
  integers, and then adjusting the resulting remainder as needed.
2011-02-14 20:30:49 +01:00
Mark H Weaver
5fbf680be9 Make divide functions return values via (SCM *) output arguments
* libguile/numbers.c (scm_euclidean_divide, scm_centered_divide): Change
  API to return two values via output arguments of type (SCM *), instead
  of packing into a values object.

  (scm_i_euclidean_divide, scm_i_centered_divide): New internal wrappers
  that call the above functions and pack the result into a values
  object.

* libguile/numbers.h: Change prototypes to reflect new API.

* doc/ref/api-data.h (Arithmetic): Update manual.
2011-02-14 20:30:30 +01:00
Mark H Weaver
a85c1f93f0 Added internal C function to extract from values object
* libguile/values.c (scm_i_extract_values_2): New internal function
  that extracts two values from a values object.

* libguile/values.h: Added prototype.
2011-02-14 20:29:54 +01:00
Ian Price
ca65967360 fix fencepost error in vector-move-left! and -right!
* libguile/vectors.c (scm_vector_move_right_x, scm_vector_move_left_x):
  Fix edge case.
2011-02-14 20:19:15 +01:00
Ludovic Courtès
533d8212af Pass all the flags when building `gen-scmconfig' in a cross-compile setup.
* libguile/Makefile.am (gen-scmconfig.$(OBJEXT)): When cross-compiling,
  pass all the CPPFLAGS and CFLAGS.
2011-02-14 13:48:08 +01:00
Noah Lavine
482d311b39 Set sockaddr_in.sin_len field when it exists.
* configure.ac: Detect when struct sockaddr_in has a sin_len field.
  Remove obsolete comment.
* libguile/socket.c (scm_to_sockaddr, scm_fill_sockaddr): Set the
  sin_len field in our struct sockaddr_in when it exists.
2011-02-13 22:08:44 +01:00
Andy Wingo
e8ab529d57 bump objcode version to 2.0; introduce minor-version compatibility
* libguile/_scm.h (SCM_OBJCODE_MAJOR_VERSION): Bump to 2.
  (SCM_OBJCODE_MINOR_VERSION): Reset to 0.
  (SCM_OBJCODE_MACHINE_VERSION_STRING, SCM_OBJCODE_COOKIE): Reorder so
  the minor version is the last byte.

* libguile/objcodes.c (make_objcode_by_mmap): Accept objcodes whose
  minor version is less than SCM_OBJCODE_MINOR_VERSION, not just equal
  to.
2011-02-13 22:02:01 +01:00
Noah Lavine
333a81ccba zero newly allocated sockaddrs
* libguile/socket.c (scm_to_sockaddr, scm_fill_sockaddr): Zero the
  sockaddrs, so we do not pass uninitialized memory to the kernel.
2011-02-13 21:04:00 +01:00
Ludovic Courtès
5a79300f85 Add %auto-compilation-options', used by compile-file' when auto-compiling.
* module/ice-9/boot-9.scm (%auto-compilation-options): New variable.
  (load-in-vicinity): Honor it.

* libguile/load.c (kw_opts, sym_compile_file,
  sym_auto_compilation_options): New variables.
  (do_try_auto_compile): Honor %AUTO-COMPILATION-OPTIONS.

* module/system/repl/common.scm (repl-default-options): Have
  `compile-options' default to %AUTO-COMPILATION-OPTIONS.
2011-02-13 19:18:02 +01:00
Andy Wingo
eb7a16a9f8 primitive-load defaults to utf-8, not latin-1
* libguile/load.c (scm_primitive_load): Default to utf-8.
2011-02-13 18:19:00 +01:00
Andy Wingo
6f06e8d35f autocompile -> auto-compile
* NEWS:
* check-guile.in:
* doc/guile.1:
* doc/ref/scheme-scripts.texi:
* libguile/init.c:
* libguile/load.c:
* libguile/load.h:
* libguile/script.c:
* module/Makefile.am:
* module/ice-9/boot-9.scm:
* module/scripts/compile.scm:
* module/system/base/compile.scm:
* test-suite/Makefile.am:
* test-suite/tests/popen.test: Change "autocompile" to "auto-compile" or
  "auto_compile", as appropriate, in variable names, function names,
  command line arguments, and the documentation.
2011-02-13 15:06:11 +01:00
Andy Wingo
6c51a40ace read-enable 'positions by default
* libguile/read.c (scm_read_opts): Default "positions" to #t.  The
  compiler was already turning it on anyway, and this allows
  primitive-load without --auto-compile to also propagate source
  information through the expander, for better errors and to let macros
  know their source.

* module/language/scheme/spec.scm: No need to enable positions here
  now.
2011-02-13 15:06:11 +01:00
Andy Wingo
d7265e376d use scm_c_make_struct in scm_values
* libguile/values.c (scm_values): Micro-optimization.
2011-02-13 15:06:11 +01:00
Ludovic Courtès
be90d0b6f9 Add `scm_t_subr' typedef (fix bug #23681).
* libguile/__scm.h (scm_t_subr): New typedef.

* libguile/deprecated.h (scm_make_gsubr, scm_make_gsubr_with_generic,
  scm_call_catching_errors): Use it.

* libguile/gsubr.h (scm_c_make_gsubr, scm_c_define_gsubr,
  scm_c_define_gsubr_with_generic): Likewise.

* libguile/smob.h (scm_smob_descriptor)[apply]: Likewise.
  (scm_set_smob_apply): Likewise.

* libguile/snarf.h (SCM_FUNC_CAST_ARBITRARY_ARGS): Likewise.
2011-02-13 14:50:05 +01:00
Ludovic Courtès
10b9343f04 Change `scm_ramapc' prototype to avoid empty declarators (bug #23681).
* libguile/array-map.h (scm_ramapc): Change `cproc' to `void *' instead
  of using empty declarators.

* libguile/array-map.c (scm_ramapc): Adjust accordingly.
2011-02-13 14:47:33 +01:00
Ludovic Courtès
b339459e94 Fix prototype of `scm_the_vm'.
* libguile/vm.h (scm_the_vm): Use `(void)' instead of `()'.
2011-02-13 14:45:47 +01:00
Mark H Weaver
4a46bc2a5f Fixes and improvements to number-theoretic division operators
* libguile/numbers.c (scm_euclidean_quotient, scm_euclidean_divide,
  scm_centered_quotient, scm_centered_divide): Fix bug in inum/inum
  case, where (quotient most-negative-fixnum -1) would not be converted
  to a bignum.

  (scm_euclidean_quotient): Be more anal-retentive about calling
  scm_remember_upto_here_1 after mpz_sgn, (even though mpz_sgn is
  documented as being implemented as a macro and certainly won't
  do any allocation).  It's better to be safe than sorry here.

  (scm_euclidean_quotient, scm_centered_quotient): In the bignum/inum
  case, check if the divisor is 1, since this will allow us to avoid
  allocating a new bignum.

  (scm_euclidean_divide, scm_centered_quotient, scm_centered_divide):
  When computing the intermediate truncated quotient (xx / yy) and
  remainder, use (xx % yy) instead of (xx - qq * yy), on the theory that
  the compiler is more likely to handle this case intelligently and
  maybe combine the operations.

  (scm_euclidean_divide): In the bignum/inum case, we know that the
  remainder will fit in an fixnum, so don't bother allocating a bignum
  for it.

  (scm_euclidean_quotient, scm_euclidean_remainder,
  scm_euclidean_divide, scm_centered_quotient, scm_centered_remainder,
  scm_centered_divide): Minor stylistic changes.

* test-suite/tests/numbers.test: Rework testing framework for
  number-theoretic division operators to be more efficient and
  comprehensive in its testing of code paths and problem cases.
2011-02-12 13:00:43 +01:00
Mark H Weaver
bc3d34f587 Add comment about handling of exactness specifiers
* libguile/numbers.c: Add discussion on the handling of exactness
  specifiers to the comment above the string-to-number conversion
  functions.
2011-02-12 13:00:43 +01:00
Mark H Weaver
18104cac0b Fix extensibility of 1-argument atan
* libguile/numbers.c (scm_atan): Call SCM_WTA_DISPATCH_1 instead of
  SCM_WTA_DISPATCH_2 if the second argument is unbound.  Arguably,
  SCM_WTA_DISPATCH_* should handle that case gracefully, but currently
  it doesn't.
2011-02-12 13:00:43 +01:00
Mark H Weaver
1ce7279a06 Fix mistake in comment in tags.h
* libguile/tags.h: Fix comment in discussion of data representation.
  tc3-code #0b110 indicates a small integer and #0b100 indicates a
  non-integer immediate.  Previously, these were reversed.
2011-02-12 13:00:43 +01:00