guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] GNU Guile branch, master, updated. v2.1.0-188-gea0582c


From: Andy Wingo
Subject: [Guile-commits] GNU Guile branch, master, updated. v2.1.0-188-gea0582c
Date: Fri, 02 Dec 2011 11:01:40 +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=ea0582c283c29e40f1eb1e85821a9c46bc386121

The branch, master has been updated
       via  ea0582c283c29e40f1eb1e85821a9c46bc386121 (commit)
       via  b57bf2724a254cf73e255b3d2bca0a7dcad6674a (commit)
      from  b2208d2e987759270c712e35c8164394a47a52aa (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 ea0582c283c29e40f1eb1e85821a9c46bc386121
Merge: b2208d2 b57bf27
Author: Andy Wingo <address@hidden>
Date:   Fri Dec 2 12:00:33 2011 +0100

    Merge remote-tracking branch 'origin/stable-2.0'
    
    Conflicts:
        libguile/guile.c
        libguile/numbers.c

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

Summary of changes:
 libguile/guile.c   |    1 +
 libguile/numbers.c |   42 ++++++++++++++++++++++++++++++++++++++++--
 libguile/numbers.h |    3 +++
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/libguile/guile.c b/libguile/guile.c
index 1ed28d5..133afc4 100644
--- a/libguile/guile.c
+++ b/libguile/guile.c
@@ -77,6 +77,7 @@ main (int argc, char **argv)
   if (setlocale (LC_ALL, "") == NULL)
     fprintf (stderr, "guile: warning: failed to install locale\n");
 
+  scm_install_gmp_memory_functions = 1;
   scm_boot_guile (argc, argv, inner_main, 0);
   return 0; /* never reached */
 }
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 54351d6..f15c724 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -114,6 +114,10 @@ typedef scm_t_signed_bits scm_t_inum;
 /* the macro above will not work as is with fractions */
 
 
+/* Default to 1, because as we used to hard-code `free' as the
+   deallocator, we know that overriding these functions with
+   instrumented `malloc' / `free' is OK.  */
+int scm_install_gmp_memory_functions = 1;
 static SCM flo0;
 static SCM exactly_one_half;
 static SCM flo_log10e;
@@ -172,6 +176,7 @@ scm_from_complex_double (complex double z)
 static mpz_t z_negative_one;
 
 
+
 /* Clear the `mpz_t' embedded in bignum PTR.  */
 static void
 finalize_bignum (GC_PTR ptr, GC_PTR data)
@@ -182,6 +187,31 @@ finalize_bignum (GC_PTR ptr, GC_PTR data)
   mpz_clear (SCM_I_BIG_MPZ (bignum));
 }
 
+/* The next three functions (custom_libgmp_*) are passed to
+   mp_set_memory_functions (in GMP) so that memory used by the digits
+   themselves is known to the garbage collector.  This is needed so
+   that GC will be run at appropriate times.  Otherwise, a program which
+   creates many large bignums would malloc a huge amount of memory
+   before the GC runs. */
+static void *
+custom_gmp_malloc (size_t alloc_size)
+{
+  return scm_malloc (alloc_size);
+}
+
+static void *
+custom_gmp_realloc (void *old_ptr, size_t old_size, size_t new_size)
+{
+  return scm_realloc (old_ptr, new_size);
+}
+
+static void
+custom_gmp_free (void *ptr, size_t size)
+{
+  free (ptr);
+}
+
+
 /* Return a new uninitialized bignum.  */
 static inline SCM
 make_bignum (void)
@@ -5359,9 +5389,12 @@ int
 scm_bigprint (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
 {
   char *str = mpz_get_str (NULL, 10, SCM_I_BIG_MPZ (exp));
+  size_t len = strlen (str);
+  void (*freefunc) (void *, size_t);
+  mp_get_memory_functions (NULL, NULL, &freefunc);
   scm_remember_upto_here_1 (exp);
-  scm_lfwrite_unlocked (str, (size_t) strlen (str), port);
-  free (str);
+  scm_lfwrite_unlocked (str, len, port);
+  freefunc (str, len + 1);
   return !0;
 }
 /*** END nums->strs ***/
@@ -9655,6 +9688,11 @@ scm_init_numbers ()
 {
   int i;
 
+  if (scm_install_gmp_memory_functions)
+    mp_set_memory_functions (custom_gmp_malloc,
+                             custom_gmp_realloc,
+                             custom_gmp_free);
+
   mpz_init_set_si (z_negative_one, -1);
 
   /* It may be possible to tune the performance of some algorithms by using
diff --git a/libguile/numbers.h b/libguile/numbers.h
index 96843c1..b7bcfe4 100644
--- a/libguile/numbers.h
+++ b/libguile/numbers.h
@@ -519,6 +519,9 @@ SCM_API double scm_c_angle (SCM z);
 
 SCM_API int scm_is_number (SCM val);
 
+/* If nonzero, tell gmp to use GC_malloc for its allocations.  */
+SCM_API int scm_install_gmp_memory_functions;
+
 SCM_INTERNAL void scm_init_numbers (void);
 
 #endif  /* SCM_NUMBERS_H */


hooks/post-receive
-- 
GNU Guile



reply via email to

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