message: Intern file names in msg_location to make them cheaper to copy.
[pspp] / src / libpspp / message.c
index e3d301efd7ae8ae76a09a83360e1b09ed8f5c671..faeb83a449d3e3058507e163d9bd7049192ea917 100644 (file)
@@ -27,6 +27,7 @@
 #include <unistd.h>
 
 #include "libpspp/cast.h"
+#include "libpspp/intern.h"
 #include "libpspp/str.h"
 #include "libpspp/version.h"
 #include "data/settings.h"
@@ -51,14 +52,12 @@ static int messages_disabled;
 
 
 void
-vmsg (enum msg_class class, const struct msg_location *location,
-      const char *format, va_list args)
+vmsg (enum msg_class class, const char *format, va_list args)
 {
   struct msg *m = xmalloc (sizeof *m);
   *m = (struct msg) {
     .category = msg_class_to_category (class),
     .severity = msg_class_to_severity (class),
-    .location = msg_location_dup (location),
     .text = xvasprintf (format, args),
   };
   msg_emit (m);
@@ -71,21 +70,11 @@ msg (enum msg_class class, const char *format, ...)
 {
   va_list args;
   va_start (args, format);
-  vmsg (class, NULL, format, args);
+  vmsg (class, format, args);
   va_end (args);
 }
 
-/* Outputs error message in CLASS, with text FORMAT, formatted with printf.
-   LOCATION is the reported location for the message. */
-void
-msg_at (enum msg_class class, const struct msg_location *location,
-        const char *format, ...)
-{
-  va_list args;
-  va_start (args, format);
-  vmsg (class, location, format, args);
-  va_end (args);
-}
+
 
 void
 msg_error (int errnum, const char *format, ...)
@@ -120,7 +109,7 @@ msg_set_handler (void (*handler) (const struct msg *, void *aux), void *aux)
 void
 msg_location_uninit (struct msg_location *loc)
 {
-  free (loc->file_name);
+  intern_unref (loc->file_name);
 }
 
 void
@@ -141,7 +130,7 @@ msg_location_dup (const struct msg_location *src)
 
   struct msg_location *dst = xmalloc (sizeof *dst);
   *dst = (struct msg_location) {
-    .file_name = xstrdup_if_nonnull (src->file_name),
+    .file_name = intern_new_if_nonnull (src->file_name),
     .first_line = src->first_line,
     .last_line = src->last_line,
     .first_column = src->first_column,