summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-06-15 17:17:14 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2017-06-15 17:27:35 +0300
commit75b1c55e4db1c0b90e898b1375f1489e72719127 (patch)
tree0d1b2513b6887013fb468ad65cd7e8fd56ddfff3
parent74e285e77d204d15ef2dedd40483003c3d5746a7 (diff)
downloadmailutils-75b1c55e4db1c0b90e898b1375f1489e72719127.tar.gz
mailutils-75b1c55e4db1c0b90e898b1375f1489e72719127.tar.bz2
Fix id reference counting
* include/mailutils/locus.h: Add copyleft. (mu_ident_stat): New proto. * include/mailutils/types.hin (mu_locus_DEPRECATED): Update commit. Include link to the wiki article. * include/mailutils/yyloc.h: Add copyleft. * libmailutils/locus/ident.c (mu_ident_stat): New function. * libmailutils/locus/locus.c (mu_locus_point_init) (mu_locus_point_copy): Don't touch destination unless setting mu_file member succeeds. (mu_locus_range_copy): deinitialize dest before assignment. * libmailutils/stream/logstream.c (_log_write): Use mu_locus_range_copy to save locus. (mu_ioctl_logstream_get_locus_deprecated) (mu_ioctl_logstream_set_locus_deprecated): Include link to the wiki article. * libmailutils/tests/linetrack.c (main): Destroy tracker before exiting. * libmailutils/tests/logstr.c: Make it possible to run selected tests.
-rw-r--r--include/mailutils/locus.h21
-rw-r--r--include/mailutils/types.hin6
-rw-r--r--include/mailutils/yyloc.h23
-rw-r--r--libmailutils/locus/ident.c39
-rw-r--r--libmailutils/locus/locus.c31
-rw-r--r--libmailutils/stream/logstream.c10
-rw-r--r--libmailutils/tests/linetrack.c1
-rw-r--r--libmailutils/tests/logstr.c27
8 files changed, 136 insertions, 22 deletions
diff --git a/include/mailutils/locus.h b/include/mailutils/locus.h
index 50efc53fb..1f94c69e4 100644
--- a/include/mailutils/locus.h
+++ b/include/mailutils/locus.h
@@ -1 +1,18 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2017 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
#ifndef _MAILUTILS_LOCUS_H
@@ -36,2 +53,3 @@ int mu_ident_ref (char const *name, char const **refname);
int mu_ident_deref (char const *);
+void mu_ident_stat (mu_stream_t str);
@@ -62,5 +80,2 @@ mu_locus_point_same_line (struct mu_locus_point const *a,
-void mu_lrange_debug (struct mu_locus_range const *loc,
- char const *fmt, ...);
-
int mu_linetrack_create (mu_linetrack_t *ret,
diff --git a/include/mailutils/types.hin b/include/mailutils/types.hin
index 5c15c6253..e1a9ac46a 100644
--- a/include/mailutils/types.hin
+++ b/include/mailutils/types.hin
@@ -157,3 +157,7 @@ typedef unsigned int mu_debug_level_t;
This definition is provided for backward compatibility. Authors are
- urged to switch to the new API as soon as their time permits. */
+ urged to switch to the new API as soon as their time permits.
+
+ Please see http://mailutils.org/wiki/Source_location_API#Deprecated_interface
+ for detailed guidelines.
+*/
struct mu_locus_DEPRECATED
diff --git a/include/mailutils/yyloc.h b/include/mailutils/yyloc.h
index 40e395ee2..951ccf0a6 100644
--- a/include/mailutils/yyloc.h
+++ b/include/mailutils/yyloc.h
@@ -1 +1,21 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2017 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _MAILUTILS_YYLOC_H
+#define _MAILUTILS_YYLOC_H
+
void mu_file_print_locus_point (FILE *,
@@ -20,2 +40,3 @@ void mu_file_print_locus_range (FILE *,
} while (0)
+
#define YY_LOCATION_PRINT(File, Loc) \
@@ -23,3 +44,3 @@ void mu_file_print_locus_range (FILE *,
-
+#endif
diff --git a/libmailutils/locus/ident.c b/libmailutils/locus/ident.c
index 029a12f61..cb7591ea8 100644
--- a/libmailutils/locus/ident.c
+++ b/libmailutils/locus/ident.c
@@ -25,2 +25,5 @@
#include <mailutils/list.h>
+#include <mailutils/io.h>
+#include <mailutils/stream.h>
+#include <mailutils/iterator.h>
@@ -113,3 +116,37 @@ mu_ident_deref (char const *name)
-
+void
+mu_ident_stat (mu_stream_t str)
+{
+ size_t count, i;
+ mu_iterator_t itr;
+
+ mu_stream_printf (str, "BEGIN IDENT STAT\n");
+
+ mu_assoc_count (nametab, &count);
+ mu_stream_printf (str, "N=%zu\n", count);
+
+ if (count > 0)
+ {
+ int rc = mu_assoc_get_iterator (nametab, &itr);
+ if (rc)
+ mu_stream_printf (str, "mu_assoc_get_iterator: %s\n",
+ mu_strerror (rc));
+ else
+ {
+ i = 0;
+ for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+ mu_iterator_next (itr), i)
+ {
+ const char *key;
+ struct mu_ident_ref *ref;
+
+ mu_iterator_current_kv (itr,
+ (const void **)&key, (void **)&ref);
+ mu_stream_printf (str, "%04zu: %s: %zu\n", i, key, ref->count);
+ }
+ }
+ mu_iterator_destroy (&itr);
+ }
+ mu_stream_printf (str, "END IDENT STAT\n");
+}
diff --git a/libmailutils/locus/locus.c b/libmailutils/locus/locus.c
index 8183294c8..49648fdc5 100644
--- a/libmailutils/locus/locus.c
+++ b/libmailutils/locus/locus.c
@@ -22,2 +22,3 @@
#include <mailutils/error.h>
+#include <mailutils/errno.h>
@@ -40,5 +41,9 @@ mu_locus_point_init (struct mu_locus_point *pt, const char *filename)
{
- pt->mu_line = 0;
- pt->mu_col = 0;
- return mu_locus_point_set_file (pt, filename);
+ int rc = mu_locus_point_set_file (pt, filename);
+ if (rc == 0)
+ {
+ pt->mu_line = 0;
+ pt->mu_col = 0;
+ }
+ return rc;
}
@@ -56,5 +61,9 @@ mu_locus_point_copy (struct mu_locus_point *dest,
{
- dest->mu_col = src->mu_col;
- dest->mu_line = src->mu_line;
- return mu_locus_point_set_file (dest, src->mu_file);
+ int rc = mu_locus_point_set_file (dest, src->mu_file);
+ if (rc == 0)
+ {
+ dest->mu_col = src->mu_col;
+ dest->mu_line = src->mu_line;
+ }
+ return rc;
}
@@ -67,3 +76,6 @@ mu_locus_range_copy (struct mu_locus_range *dest,
struct mu_locus_range tmp = MU_LOCUS_RANGE_INITIALIZER;
-
+
+ if (!dest)
+ return MU_ERR_OUT_PTR_NULL;
+
rc = mu_locus_point_copy (&tmp.beg, &src->beg);
@@ -75,3 +87,6 @@ mu_locus_range_copy (struct mu_locus_range *dest,
else
- *dest = tmp;
+ {
+ mu_locus_range_deinit (dest);
+ *dest = tmp;
+ }
}
diff --git a/libmailutils/stream/logstream.c b/libmailutils/stream/logstream.c
index e79b27514..1cc2b4b08 100644
--- a/libmailutils/stream/logstream.c
+++ b/libmailutils/stream/logstream.c
@@ -260,7 +260,3 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size,
if (save_locus)
- {
- sp->locrange = loc;
- mu_ident_ref (sp->locrange.beg.mu_file, &sp->locrange.beg.mu_file);
- mu_ident_ref (sp->locrange.end.mu_file, &sp->locrange.end.mu_file);
- }
+ mu_locus_range_copy (&sp->locrange, &loc);
@@ -651,2 +647,4 @@ mu_log_stream_create (mu_stream_t *pstr, mu_stream_t transport)
+static char wiki_url[] = "http://mailutils.org/wiki/Source_location_API#Deprecated_interface";
+
int
@@ -658,2 +656,3 @@ mu_ioctl_logstream_get_locus_deprecated (void)
mu_error (_("the program uses MU_IOCTL_LOGSTREAM_GET_LOCUS, which is deprecated"));
+ mu_error (_("please see %s, for detailed guidelines"), wiki_url);
warned = 1;
@@ -670,2 +669,3 @@ mu_ioctl_logstream_set_locus_deprecated (void)
mu_error (_("program uses MU_IOCTL_LOGSTREAM_SET_LOCUS, which is deprecated"));
+ mu_error (_("please see %s, for detailed guidelines"), wiki_url);
warned = 1;
diff --git a/libmailutils/tests/linetrack.c b/libmailutils/tests/linetrack.c
index 3ca5ceb4f..c99440e1f 100644
--- a/libmailutils/tests/linetrack.c
+++ b/libmailutils/tests/linetrack.c
@@ -61,2 +61,3 @@ main (int argc, char **argv)
}
+ mu_linetrack_destroy (&trk);
return 0;
diff --git a/libmailutils/tests/logstr.c b/libmailutils/tests/logstr.c
index 638f9b8a7..269a6137f 100644
--- a/libmailutils/tests/logstr.c
+++ b/libmailutils/tests/logstr.c
@@ -631,2 +631,3 @@ struct testcase
void (*handler) (mu_stream_t);
+ int enabled;
};
@@ -691,2 +692,3 @@ main (int argc, char **argv)
int i;
+ int ena = 0;
@@ -695,2 +697,18 @@ main (int argc, char **argv)
+ if (argc > 1)
+ {
+ ena = 1;
+ for (i = 1; i < argc; i++)
+ {
+ char *p;
+ int n = strtol (argv[i], &p, 10);
+ if (! (*p == 0 && n >= 0) )
+ {
+ mu_error ("erroneous argument %s\n", argv[i]);
+ return 1;
+ }
+ testcases[n].enabled = ena;
+ }
+ }
+
log = create_log ();
@@ -699,5 +717,8 @@ main (int argc, char **argv)
{
- mu_stream_printf (log, "%02d. %s\n", i, tp->id);
- tp->handler (log);
- log_reset (log);
+ if (tp->enabled == ena)
+ {
+ mu_stream_printf (log, "%02d. %s\n", i, tp->id);
+ tp->handler (log);
+ log_reset (log);
+ }
}

Return to:

Send suggestions and report system problems to the System administrator.