Skip to content

Instantly share code, notes, and snippets.

@cebtenzzre
Last active February 20, 2022 23:00
Show Gist options
  • Save cebtenzzre/a64f942dd22f443fc564066cf30cebeb to your computer and use it in GitHub Desktop.
Save cebtenzzre/a64f942dd22f443fc564066cf30cebeb to your computer and use it in GitHub Desktop.
From a86739d8c46ce2b041836cb70173830fde7976dc Mon Sep 17 00:00:00 2001
From: Cebtenzzre <cebtenzzre@gmail.com>
Date: Sun, 20 Feb 2022 14:50:59 -0500
Subject: [PATCH] Duplicate output file debugging
---
lib/formats.c | 12 +++++++++++-
lib/formats.h | 7 ++++++-
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/lib/formats.c b/lib/formats.c
index 5dbc43f9..ecc344d8 100644
--- a/lib/formats.c
+++ b/lib/formats.c
@@ -78,6 +78,8 @@ RmFmtTable *rm_fmt_open(RmSession *session) {
self->config = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
(GDestroyNotify)g_hash_table_unref);
+ self->seen_files = g_hash_table_new(NULL, NULL);
+
self->handler_order = g_queue_new();
self->session = session;
@@ -452,6 +454,7 @@ void rm_fmt_close(RmFmtTable *self) {
g_hash_table_unref(self->path_to_handler);
g_hash_table_unref(self->config);
g_hash_table_unref(self->handler_set);
+ g_hash_table_unref(self->seen_files);
g_queue_free(self->handler_order);
g_rec_mutex_clear(&self->state_mtx);
@@ -462,7 +465,14 @@ void rm_fmt_close(RmFmtTable *self) {
g_slice_free(RmFmtTable, self);
}
-void rm_fmt_write(RmFile *result, RmFmtTable *self) {
+void _rm_fmt_write(RmFile *result, RmFmtTable *self, char *loc) {
+ char *prevloc = g_hash_table_lookup(self->seen_files, result);
+ if (prevloc) {
+ fprintf(stderr, "dupped output file: %s and %s\n", prevloc, loc);
+ abort();
+ }
+ g_hash_table_insert(self->seen_files, result, loc);
+
bool direct = !(self->session->cfg->cache_file_structs);
if(direct) {
diff --git a/lib/formats.h b/lib/formats.h
index 0842e8ae..7657bccc 100644
--- a/lib/formats.h
+++ b/lib/formats.h
@@ -56,6 +56,7 @@ typedef struct RmFmtTable {
GHashTable *handler_to_file;
GHashTable *handler_set;
GHashTable *config;
+ GHashTable *seen_files;
GQueue *handler_order;
GRecMutex state_mtx;
RmSession *session;
@@ -181,7 +182,11 @@ bool rm_fmt_add(RmFmtTable *self, const char *handler_name, const char *path);
* implementation of the handler - it might also do just nothing.
* @note argument order is to enable calling via g_queue_foreach()
*/
-void rm_fmt_write(RmFile *result, RmFmtTable *self);
+void _rm_fmt_write(RmFile *result, RmFmtTable *self, char *loc);
+
+#define STR_(x) #x
+#define STR(x) STR_(x)
+#define rm_fmt_write(result, self) _rm_fmt_write(result, self, __FILE__ ":" STR(__LINE__))
/**
* @brief Change the state of rmlint.
--
2.35.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment