Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent indent: properly store parser state in debug ...
details: https://anonhg.NetBSD.org/src/rev/ea91eb018f5a
branches: trunk
changeset: 376597:ea91eb018f5a
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 23 20:43:21 2023 +0000
description:
indent: properly store parser state in debug mode
The stacks in the parser state are allocated now and need to be copied
individually.
The test whether two paren stacks are equal was broken since 2023-06-14
14:11:28.
diffstat:
usr.bin/indent/debug.c | 11 ++++++-----
usr.bin/indent/indent.c | 8 ++++----
usr.bin/indent/indent.h | 6 +++++-
3 files changed, 15 insertions(+), 10 deletions(-)
diffs (106 lines):
diff -r 6a8089f00b96 -r ea91eb018f5a usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c Fri Jun 23 20:37:02 2023 +0000
+++ b/usr.bin/indent/debug.c Fri Jun 23 20:43:21 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.67 2023/06/17 22:28:49 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.68 2023/06/23 20:43:21 rillig Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.67 2023/06/17 22:28:49 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.68 2023/06/23 20:43:21 rillig Exp $");
#include <stdarg.h>
#include <string.h>
@@ -263,8 +263,8 @@ paren_stack_equal(const struct paren_sta
for (size_t i = 0, n = a->len; i < n; i++)
if (a->item[i].indent != b->item[i].indent
|| a->item[i].cast != b->item[i].cast)
- return true;
- return false;
+ return false;
+ return true;
}
static void
@@ -375,7 +375,8 @@ debug_parser_state(void)
state.heading = NULL;
debug_blank_line();
- state.prev_ps = ps;
+ parser_state_free(&state.prev_ps);
+ parser_state_back_up(&state.prev_ps);
state.ps_first = false;
}
diff -r 6a8089f00b96 -r ea91eb018f5a usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Fri Jun 23 20:37:02 2023 +0000
+++ b/usr.bin/indent/indent.c Fri Jun 23 20:43:21 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.381 2023/06/18 07:10:24 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.382 2023/06/23 20:43:21 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.381 2023/06/18 07:10:24 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.382 2023/06/23 20:43:21 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -464,7 +464,7 @@ dup_mem(const void *src, size_t size)
#define copy_array(dst, src, len) \
memcpy((dst), (src), sizeof((dst)[0]) * (len))
-static void
+static_unless_debug void
parser_state_back_up(struct parser_state *dst)
{
*dst = ps;
@@ -496,7 +496,7 @@ parser_state_restore(const struct parser
copy_array(ps.psyms.ind_level, src->psyms.ind_level, src->psyms.len);
}
-static void
+static_unless_debug void
parser_state_free(struct parser_state *pst)
{
free(pst->paren.item);
diff -r 6a8089f00b96 -r ea91eb018f5a usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Fri Jun 23 20:37:02 2023 +0000
+++ b/usr.bin/indent/indent.h Fri Jun 23 20:43:21 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.202 2023/06/16 23:51:32 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.203 2023/06/23 20:43:21 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -442,10 +442,13 @@ void debug_parser_state(void);
void debug_psyms_stack(const char *);
void debug_print_buf(const char *, const struct buffer *);
void debug_buffers(void);
+void parser_state_back_up(struct parser_state *);
+void parser_state_free(struct parser_state *);
extern const char *const lsym_name[];
extern const char *const psym_name[];
extern const char *const paren_level_cast_name[];
extern const char *const line_kind_name[];
+#define static_unless_debug /* nothing */
#else
#define debug_noop() do { } while (false)
#define debug_printf(fmt, ...) debug_noop()
@@ -456,6 +459,7 @@ extern const char *const line_kind_name[
#define debug_psyms_stack(situation) debug_noop()
#define debug_print_buf(name, buf) debug_noop()
#define debug_buffers() debug_noop()
+#define static_unless_debug static
#endif
void register_typename(const char *);
Home |
Main Index |
Thread Index |
Old Index