gawk-diffs
[Top][All Lists]
Advanced

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

[SCM] gawk branch, feature/fix-mpfr-and-pma, created. gawk-4.1.0-4818-gd


From: Arnold Robbins
Subject: [SCM] gawk branch, feature/fix-mpfr-and-pma, created. gawk-4.1.0-4818-gd6ddf6b1
Date: Mon, 1 Aug 2022 15:13:58 -0400 (EDT)

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 "gawk".

The branch, feature/fix-mpfr-and-pma has been created
        at  d6ddf6b1abe98f2d39d758adc82a1fa474832dc0 (commit)

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=d6ddf6b1abe98f2d39d758adc82a1fa474832dc0

commit d6ddf6b1abe98f2d39d758adc82a1fa474832dc0
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Mon Aug 1 22:13:20 2022 +0300

    Fix pma and mpfr to work together.

diff --git a/awk.h b/awk.h
index 84fd714c..bbe817dd 100644
--- a/awk.h
+++ b/awk.h
@@ -1709,6 +1709,9 @@ extern NODE *mpg_node(unsigned int);
 extern const char *mpg_fmt(const char *, ...);
 extern int mpg_strtoui(mpz_ptr, char *, size_t, char **, int);
 extern void mpg_zero(NODE *n);
+extern void *mpfr_mem_alloc(size_t alloc_size);
+extern void *mpfr_mem_realloc(void *ptr, size_t old_size, size_t new_size);
+extern void mpfr_mem_free(void *ptr, size_t size);
 #endif
 /* msg.c */
 extern void gawk_exit(int status);
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index 850e3918..27b669da 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -30031,10 +30031,15 @@ and error information the persistent memory allocator 
will print.
 source code to understand what the different verbosity levels are.
 
 @quotation NOTE
-Persistent memory and the use of MPFR (the @option{-M} option)
-don't mix! If you use @option{-M} then you will get a core dump on the
-second @command{gawk} run.  This may eventually be fixed. But then again,
-it may not.
+If you use MPFR mode (the @option{-M} option) on the first run
+of a program using persistent memory, you @emph{must} continue
+to use it on all subsequent runs.  Similarly, if you don't use @option{-M}
+on the first run, do not use it on any subsequent runs.
+
+Mixing and matching MPFR mode and regular mode with the same
+backing file will lead to strange results and/or core dumps.
+@command{gawk} does not currently detect such a situation and
+may not do so in the future either.
 @end quotation
 
 Here are articles and web links that provide more information about
diff --git a/main.c b/main.c
index ca913844..7f00160b 100644
--- a/main.c
+++ b/main.c
@@ -251,6 +251,9 @@ for PMA */
        if (using_persistent_malloc)
                warning(_("persistent memory is not supported"));
 #endif
+#ifdef HAVE_MPFR
+       mp_set_memory_functions(mpfr_mem_alloc, mpfr_mem_realloc, 
mpfr_mem_free);
+#endif
 
        /* do these checks early */
        if (getenv("TIDYMEM") != NULL)
diff --git a/mpfr.c b/mpfr.c
index 40833124..21bac6cd 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -1963,6 +1963,38 @@ mpfr_unset(NODE *n)
                mpz_clear(n->mpg_i);
 }
 
+/*
+ * Custom memory allocation functions for GMP / MPFR. We need these so that the
+ * persistent memory feature will also work with the -M option.
+ *
+ * These just call malloc/realloc/free; if we are using PMA then those are
+ * redefined as macros to point at the pma functions, so all should "just 
work."
+ */
+
+/* mpfr_mem_alloc --- allocate memory */
+
+void *
+mpfr_mem_alloc(size_t alloc_size)
+{
+       return malloc(alloc_size);
+}
+
+/* mpfr_mem_realloc --- reallocate memory */
+
+void *
+mpfr_mem_realloc(void *ptr, size_t old_size, size_t new_size)
+{
+       return realloc(ptr, new_size);
+}
+
+/* mpfr_mem_free --- free memory */
+
+void
+mpfr_mem_free(void *ptr, size_t size)
+{
+       free(ptr);
+}
+
 #else
 
 void

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


hooks/post-receive
-- 
gawk



reply via email to

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