diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-06-15 17:17:14 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-06-15 17:27:35 +0300 |
commit | 75b1c55e4db1c0b90e898b1375f1489e72719127 (patch) | |
tree | 0d1b2513b6887013fb468ad65cd7e8fd56ddfff3 | |
parent | 74e285e77d204d15ef2dedd40483003c3d5746a7 (diff) | |
download | mailutils-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.h | 21 | ||||
-rw-r--r-- | include/mailutils/types.hin | 6 | ||||
-rw-r--r-- | include/mailutils/yyloc.h | 23 | ||||
-rw-r--r-- | libmailutils/locus/ident.c | 39 | ||||
-rw-r--r-- | libmailutils/locus/locus.c | 31 | ||||
-rw-r--r-- | libmailutils/stream/logstream.c | 10 | ||||
-rw-r--r-- | libmailutils/tests/linetrack.c | 1 | ||||
-rw-r--r-- | libmailutils/tests/logstr.c | 27 |
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,3 +1,20 @@ | |||
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2017 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 3 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General | ||
15 | Public License along with this library. If not, see | ||
16 | <http://www.gnu.org/licenses/>. */ | ||
17 | |||
1 | #ifndef _MAILUTILS_LOCUS_H | 18 | #ifndef _MAILUTILS_LOCUS_H |
2 | #define _MAILUTILS_LOCUS_H | 19 | #define _MAILUTILS_LOCUS_H |
3 | 20 | ||
@@ -34,6 +51,7 @@ struct mu_linetrack_stat | |||
34 | 51 | ||
35 | int mu_ident_ref (char const *name, char const **refname); | 52 | int mu_ident_ref (char const *name, char const **refname); |
36 | int mu_ident_deref (char const *); | 53 | int mu_ident_deref (char const *); |
54 | void mu_ident_stat (mu_stream_t str); | ||
37 | 55 | ||
38 | int mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename); | 56 | int mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename); |
39 | int mu_locus_point_init (struct mu_locus_point *pt, const char *filename); | 57 | int mu_locus_point_init (struct mu_locus_point *pt, const char *filename); |
@@ -60,9 +78,6 @@ mu_locus_point_same_line (struct mu_locus_point const *a, | |||
60 | return mu_locus_point_same_file (a, b) && a->mu_line == b->mu_line; | 78 | return mu_locus_point_same_file (a, b) && a->mu_line == b->mu_line; |
61 | } | 79 | } |
62 | 80 | ||
63 | void mu_lrange_debug (struct mu_locus_range const *loc, | ||
64 | char const *fmt, ...); | ||
65 | |||
66 | int mu_linetrack_create (mu_linetrack_t *ret, | 81 | int mu_linetrack_create (mu_linetrack_t *ret, |
67 | char const *file_name, size_t max_lines); | 82 | char const *file_name, size_t max_lines); |
68 | int mu_linetrack_rebase (mu_linetrack_t trk, struct mu_locus_point const *pt); | 83 | int mu_linetrack_rebase (mu_linetrack_t trk, struct mu_locus_point const *pt); |
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 | |||
@@ -155,7 +155,11 @@ typedef unsigned int mu_debug_level_t; | |||
155 | <mailutils/locus.h>. | 155 | <mailutils/locus.h>. |
156 | 156 | ||
157 | This definition is provided for backward compatibility. Authors are | 157 | This definition is provided for backward compatibility. Authors are |
158 | urged to switch to the new API as soon as their time permits. */ | 158 | urged to switch to the new API as soon as their time permits. |
159 | |||
160 | Please see http://mailutils.org/wiki/Source_location_API#Deprecated_interface | ||
161 | for detailed guidelines. | ||
162 | */ | ||
159 | struct mu_locus_DEPRECATED | 163 | struct mu_locus_DEPRECATED |
160 | { | 164 | { |
161 | char *mu_file; | 165 | char *mu_file; |
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,3 +1,23 @@ | |||
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2017 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 3 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General | ||
15 | Public License along with this library. If not, see | ||
16 | <http://www.gnu.org/licenses/>. */ | ||
17 | |||
18 | #ifndef _MAILUTILS_YYLOC_H | ||
19 | #define _MAILUTILS_YYLOC_H | ||
20 | |||
1 | void mu_file_print_locus_point (FILE *, | 21 | void mu_file_print_locus_point (FILE *, |
2 | struct mu_locus_point const *lpt); | 22 | struct mu_locus_point const *lpt); |
3 | void mu_file_print_locus_range (FILE *, | 23 | void mu_file_print_locus_range (FILE *, |
@@ -18,8 +38,9 @@ void mu_file_print_locus_range (FILE *, | |||
18 | (Current).end = (Current).beg; \ | 38 | (Current).end = (Current).beg; \ |
19 | } \ | 39 | } \ |
20 | } while (0) | 40 | } while (0) |
41 | |||
21 | #define YY_LOCATION_PRINT(File, Loc) \ | 42 | #define YY_LOCATION_PRINT(File, Loc) \ |
22 | mu_file_print_locus_range (File, &(Loc)) | 43 | mu_file_print_locus_range (File, &(Loc)) |
23 | 44 | ||
24 | 45 | #endif | |
25 | 46 | ||
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 | |||
@@ -23,6 +23,9 @@ | |||
23 | #include <mailutils/errno.h> | 23 | #include <mailutils/errno.h> |
24 | #include <mailutils/diag.h> | 24 | #include <mailutils/diag.h> |
25 | #include <mailutils/list.h> | 25 | #include <mailutils/list.h> |
26 | #include <mailutils/io.h> | ||
27 | #include <mailutils/stream.h> | ||
28 | #include <mailutils/iterator.h> | ||
26 | 29 | ||
27 | struct mu_ident_ref | 30 | struct mu_ident_ref |
28 | { | 31 | { |
@@ -111,5 +114,39 @@ mu_ident_deref (char const *name) | |||
111 | return 0; | 114 | return 0; |
112 | } | 115 | } |
113 | 116 | ||
114 | 117 | void | |
118 | mu_ident_stat (mu_stream_t str) | ||
119 | { | ||
120 | size_t count, i; | ||
121 | mu_iterator_t itr; | ||
122 | |||
123 | mu_stream_printf (str, "BEGIN IDENT STAT\n"); | ||
124 | |||
125 | mu_assoc_count (nametab, &count); | ||
126 | mu_stream_printf (str, "N=%zu\n", count); | ||
127 | |||
128 | if (count > 0) | ||
129 | { | ||
130 | int rc = mu_assoc_get_iterator (nametab, &itr); | ||
131 | if (rc) | ||
132 | mu_stream_printf (str, "mu_assoc_get_iterator: %s\n", | ||
133 | mu_strerror (rc)); | ||
134 | else | ||
135 | { | ||
136 | i = 0; | ||
137 | for (mu_iterator_first (itr); !mu_iterator_is_done (itr); | ||
138 | mu_iterator_next (itr), i) | ||
139 | { | ||
140 | const char *key; | ||
141 | struct mu_ident_ref *ref; | ||
142 | |||
143 | mu_iterator_current_kv (itr, | ||
144 | (const void **)&key, (void **)&ref); | ||
145 | mu_stream_printf (str, "%04zu: %s: %zu\n", i, key, ref->count); | ||
146 | } | ||
147 | } | ||
148 | mu_iterator_destroy (&itr); | ||
149 | } | ||
150 | mu_stream_printf (str, "END IDENT STAT\n"); | ||
151 | } | ||
115 | 152 | ||
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 | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <mailutils/types.h> | 20 | #include <mailutils/types.h> |
21 | #include <mailutils/locus.h> | 21 | #include <mailutils/locus.h> |
22 | #include <mailutils/error.h> | 22 | #include <mailutils/error.h> |
23 | #include <mailutils/errno.h> | ||
23 | 24 | ||
24 | int | 25 | int |
25 | mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename) | 26 | mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename) |
@@ -38,9 +39,13 @@ mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename) | |||
38 | int | 39 | int |
39 | mu_locus_point_init (struct mu_locus_point *pt, const char *filename) | 40 | mu_locus_point_init (struct mu_locus_point *pt, const char *filename) |
40 | { | 41 | { |
41 | pt->mu_line = 0; | 42 | int rc = mu_locus_point_set_file (pt, filename); |
42 | pt->mu_col = 0; | 43 | if (rc == 0) |
43 | return mu_locus_point_set_file (pt, filename); | 44 | { |
45 | pt->mu_line = 0; | ||
46 | pt->mu_col = 0; | ||
47 | } | ||
48 | return rc; | ||
44 | } | 49 | } |
45 | 50 | ||
46 | void | 51 | void |
@@ -54,9 +59,13 @@ int | |||
54 | mu_locus_point_copy (struct mu_locus_point *dest, | 59 | mu_locus_point_copy (struct mu_locus_point *dest, |
55 | struct mu_locus_point const *src) | 60 | struct mu_locus_point const *src) |
56 | { | 61 | { |
57 | dest->mu_col = src->mu_col; | 62 | int rc = mu_locus_point_set_file (dest, src->mu_file); |
58 | dest->mu_line = src->mu_line; | 63 | if (rc == 0) |
59 | return mu_locus_point_set_file (dest, src->mu_file); | 64 | { |
65 | dest->mu_col = src->mu_col; | ||
66 | dest->mu_line = src->mu_line; | ||
67 | } | ||
68 | return rc; | ||
60 | } | 69 | } |
61 |