projects
/
pspp
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
44c7a15
)
message: Intern file names in msg_location to make them cheaper to copy.
author
Ben Pfaff
<blp@cs.stanford.edu>
Thu, 25 Nov 2021 01:00:57 +0000
(17:00 -0800)
committer
Ben Pfaff
<blp@cs.stanford.edu>
Tue, 30 Nov 2021 14:55:06 +0000
(06:55 -0800)
src/language/control/define.c
patch
|
blob
|
history
src/language/data-io/data-parser.c
patch
|
blob
|
history
src/language/data-io/matrix-data.c
patch
|
blob
|
history
src/language/lexer/lexer.c
patch
|
blob
|
history
src/language/stats/matrix.c
patch
|
blob
|
history
src/libpspp/intern.c
patch
|
blob
|
history
src/libpspp/intern.h
patch
|
blob
|
history
src/libpspp/message.c
patch
|
blob
|
history
src/libpspp/message.h
patch
|
blob
|
history
diff --git
a/src/language/control/define.c
b/src/language/control/define.c
index 4c12ac24935badc7cf8c9b2408a2065cb8996d46..f33e885925a807b67071d1832b2de8442f3c7845 100644
(file)
--- a/
src/language/control/define.c
+++ b/
src/language/control/define.c
@@
-23,6
+23,7
@@
#include "language/lexer/macro.h"
#include "language/lexer/scan.h"
#include "language/lexer/token.h"
#include "language/lexer/macro.h"
#include "language/lexer/scan.h"
#include "language/lexer/token.h"
+#include "libpspp/intern.h"
#include "libpspp/message.h"
#include "gl/xalloc.h"
#include "libpspp/message.h"
#include "gl/xalloc.h"
@@
-113,7
+114,7
@@
cmd_define (struct lexer *lexer, struct dataset *ds UNUSED)
.location = xmalloc (sizeof *m->location),
};
*m->location = (struct msg_location) {
.location = xmalloc (sizeof *m->location),
};
*m->location = (struct msg_location) {
- .file_name =
xstrdup
_if_nonnull (lex_get_file_name (lexer)),
+ .file_name =
intern_new
_if_nonnull (lex_get_file_name (lexer)),
.first_line = lex_get_first_line_number (lexer, 0),
};
lex_get (lexer);
.first_line = lex_get_first_line_number (lexer, 0),
};
lex_get (lexer);
diff --git
a/src/language/data-io/data-parser.c
b/src/language/data-io/data-parser.c
index 03c6dbbb0ea36a421a956498f2fb4470c14771a3..09af7542bb5750510f402b6ce3ee90bb6e833c01 100644
(file)
--- a/
src/language/data-io/data-parser.c
+++ b/
src/language/data-io/data-parser.c
@@
-29,6
+29,7
@@
#include "data/file-handle-def.h"
#include "data/settings.h"
#include "language/data-io/data-reader.h"
#include "data/file-handle-def.h"
#include "data/settings.h"
#include "language/data-io/data-reader.h"
+#include "libpspp/intern.h"
#include "libpspp/message.h"
#include "libpspp/str.h"
#include "output/pivot-table.h"
#include "libpspp/message.h"
#include "libpspp/str.h"
#include "output/pivot-table.h"
@@
-498,7
+499,7
@@
parse_error (const struct dfm_reader *reader, const struct field *field,
int line_number = dfm_get_line_number (reader);
struct msg_location *location = xmalloc (sizeof *location);
*location = (struct msg_location) {
int line_number = dfm_get_line_number (reader);
struct msg_location *location = xmalloc (sizeof *location);
*location = (struct msg_location) {
- .file_name =
xstrdup
(dfm_get_file_name (reader)),
+ .file_name =
intern_new
(dfm_get_file_name (reader)),
.first_line = line_number,
.last_line = line_number + 1,
.first_column = first_column,
.first_line = line_number,
.last_line = line_number + 1,
.first_column = first_column,
diff --git
a/src/language/data-io/matrix-data.c
b/src/language/data-io/matrix-data.c
index bffdd92cb7f463d0183181196b9e920f7e1a2fe9..31d6b710b0ba68a54402d33e50e559b9f581bf2e 100644
(file)
--- a/
src/language/data-io/matrix-data.c
+++ b/
src/language/data-io/matrix-data.c
@@
-39,6
+39,7
@@
#include "language/lexer/variable-parser.h"
#include "libpspp/assertion.h"
#include "libpspp/i18n.h"
#include "language/lexer/variable-parser.h"
#include "libpspp/assertion.h"
#include "libpspp/i18n.h"
+#include "libpspp/intern.h"
#include "libpspp/message.h"
#include "libpspp/str.h"
#include "libpspp/message.h"
#include "libpspp/str.h"
@@
-253,7
+254,7
@@
parse_msg (struct dfm_reader *reader, const struct substring *token,
int line_number = dfm_get_line_number (reader);
struct msg_location *location = xmalloc (sizeof *location);
*location = (struct msg_location) {
int line_number = dfm_get_line_number (reader);
struct msg_location *location = xmalloc (sizeof *location);
*location = (struct msg_location) {
- .file_name =
xstrdup
(dfm_get_file_name (reader)),
+ .file_name =
intern_new
(dfm_get_file_name (reader)),
.first_line = line_number,
.last_line = line_number + 1,
.first_column = first_column,
.first_line = line_number,
.last_line = line_number + 1,
.first_column = first_column,
diff --git
a/src/language/lexer/lexer.c
b/src/language/lexer/lexer.c
index 9fa1823b5fdab6cb1aeab50eea2c490f5441e5c0..df3a77de94fb11ac90d196c560f32de27922848d 100644
(file)
--- a/
src/language/lexer/lexer.c
+++ b/
src/language/lexer/lexer.c
@@
-38,6
+38,7
@@
#include "libpspp/cast.h"
#include "libpspp/deque.h"
#include "libpspp/i18n.h"
#include "libpspp/cast.h"
#include "libpspp/deque.h"
#include "libpspp/i18n.h"
+#include "libpspp/intern.h"
#include "libpspp/ll.h"
#include "libpspp/message.h"
#include "libpspp/misc.h"
#include "libpspp/ll.h"
#include "libpspp/message.h"
#include "libpspp/misc.h"
@@
-1248,7
+1249,7
@@
lex_token_location (const struct lex_source *src,
const struct lex_token *t1)
{
return (struct msg_location) {
const struct lex_token *t1)
{
return (struct msg_location) {
- .file_name =
src->reader->file_name
,
+ .file_name =
intern_new_if_nonnull (src->reader->file_name)
,
.first_line = t0->first_line,
.last_line = lex_token_get_last_line_number (src, t1),
.first_column = lex_token_get_first_column (src, t0),
.first_line = t0->first_line,
.last_line = lex_token_get_last_line_number (src, t1),
.first_column = lex_token_get_first_column (src, t0),
@@
-1364,7
+1365,7
@@
lex_get_lines (const struct lexer *lexer, int n0, int n1)
{
struct msg_location *loc = xmalloc (sizeof *loc);
*loc = (struct msg_location) {
{
struct msg_location *loc = xmalloc (sizeof *loc);
*loc = (struct msg_location) {
- .file_name =
xstrdup
_if_nonnull (lex_get_file_name (lexer)),
+ .file_name =
intern_new
_if_nonnull (lex_get_file_name (lexer)),
.first_line = lex_get_first_line_number (lexer, n0),
.last_line = lex_get_last_line_number (lexer, n1),
};
.first_line = lex_get_first_line_number (lexer, n0),
.last_line = lex_get_last_line_number (lexer, n1),
};
diff --git
a/src/language/stats/matrix.c
b/src/language/stats/matrix.c
index 473cec585a29c77bb27f7d0b1f782774407ef7bd..ff3c792e7ee882c615850a01d20b7261f0fd283b 100644
(file)
--- a/
src/language/stats/matrix.c
+++ b/
src/language/stats/matrix.c
@@
-49,6
+49,7
@@
#include "libpspp/compiler.h"
#include "libpspp/hmap.h"
#include "libpspp/i18n.h"
#include "libpspp/compiler.h"
#include "libpspp/hmap.h"
#include "libpspp/i18n.h"
+#include "libpspp/intern.h"
#include "libpspp/misc.h"
#include "libpspp/str.h"
#include "libpspp/string-array.h"
#include "libpspp/misc.h"
#include "libpspp/str.h"
#include "libpspp/string-array.h"
@@
-6156,7
+6157,7
@@
parse_error (const struct dfm_reader *reader, enum fmt_type format,
int line_number = dfm_get_line_number (reader);
struct msg_location *location = xmalloc (sizeof *location);
*location = (struct msg_location) {
int line_number = dfm_get_line_number (reader);
struct msg_location *location = xmalloc (sizeof *location);
*location = (struct msg_location) {
- .file_name =
xstrdup
(dfm_get_file_name (reader)),
+ .file_name =
intern_new
(dfm_get_file_name (reader)),
.first_line = line_number,
.last_line = line_number + 1,
.first_column = first_column,
.first_line = line_number,
.last_line = line_number + 1,
.first_column = first_column,
diff --git
a/src/libpspp/intern.c
b/src/libpspp/intern.c
index fc31acf0b439fec19c339296abe3e5fe8f5ce314..b8eb5198b4d9ac902ef2ce67c2fd1c994b5f0de2 100644
(file)
--- a/
src/libpspp/intern.c
+++ b/
src/libpspp/intern.c
@@
-77,6
+77,13
@@
intern_new (const char *s)
return is->string;
}
return is->string;
}
+const char *
+intern_new_if_nonnull (const char *s)
+{
+ return s ? intern_new (s) : NULL;
+}
+
+
static struct interned_string *
interned_string_from_string (const char *s_)
{
static struct interned_string *
interned_string_from_string (const char *s_)
{
@@
-96,17
+103,26
@@
intern_ref (const char *s)
return s;
}
return s;
}
+const char *
+intern_ref_if_nonnull (const char *s)
+{
+ return s ? intern_ref (s) : NULL;
+}
+
/* Decreases the reference count on S, which must be an interned string
returned by intern_new(). If the reference count reaches 0, frees the
interned string. */
void
intern_unref (const char *s)
{
/* Decreases the reference count on S, which must be an interned string
returned by intern_new(). If the reference count reaches 0, frees the
interned string. */
void
intern_unref (const char *s)
{
- struct interned_string *is = interned_string_from_string (s);
- if (--is->ref_cnt == 0)
+ if (s)
{
{
- hmap_delete (&interns, &is->node);
- free (is);
+ struct interned_string *is = interned_string_from_string (s);
+ if (--is->ref_cnt == 0)
+ {
+ hmap_delete (&interns, &is->node);
+ free (is);
+ }
}
}
}
}
diff --git
a/src/libpspp/intern.h
b/src/libpspp/intern.h
index 2f07a9ef77808b17f19e85adc2ffc9dc8d024262..2192c66d8c650afa058a2b8bc0be896da2a2c2be 100644
(file)
--- a/
src/libpspp/intern.h
+++ b/
src/libpspp/intern.h
@@
-34,7
+34,9
@@
#include <stddef.h>
const char *intern_new (const char *);
#include <stddef.h>
const char *intern_new (const char *);
+const char *intern_new_if_nonnull (const char *);
const char *intern_ref (const char *);
const char *intern_ref (const char *);
+const char *intern_ref_if_nonnull (const char *);
void intern_unref (const char *);
size_t intern_strlen (const char *);
void intern_unref (const char *);
size_t intern_strlen (const char *);
diff --git
a/src/libpspp/message.c
b/src/libpspp/message.c
index 41a1da17502ea5e18386cdecb5c0d99df2c3afae..faeb83a449d3e3058507e163d9bd7049192ea917 100644
(file)
--- a/
src/libpspp/message.c
+++ b/
src/libpspp/message.c
@@
-27,6
+27,7
@@
#include <unistd.h>
#include "libpspp/cast.h"
#include <unistd.h>
#include "libpspp/cast.h"
+#include "libpspp/intern.h"
#include "libpspp/str.h"
#include "libpspp/version.h"
#include "data/settings.h"
#include "libpspp/str.h"
#include "libpspp/version.h"
#include "data/settings.h"
@@
-108,7
+109,7
@@
msg_set_handler (void (*handler) (const struct msg *, void *aux), void *aux)
void
msg_location_uninit (struct msg_location *loc)
{
void
msg_location_uninit (struct msg_location *loc)
{
-
free
(loc->file_name);
+
intern_unref
(loc->file_name);
}
void
}
void
@@
-129,7
+130,7
@@
msg_location_dup (const struct msg_location *src)
struct msg_location *dst = xmalloc (sizeof *dst);
*dst = (struct msg_location) {
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,
.first_line = src->first_line,
.last_line = src->last_line,
.first_column = src->first_column,
diff --git
a/src/libpspp/message.h
b/src/libpspp/message.h
index 6cfbde7c5019ba2740a01c80bde5266edc7b06fc..a99b0818e3438fd6514be202a46c3d6e0f6f8185 100644
(file)
--- a/
src/libpspp/message.h
+++ b/
src/libpspp/message.h
@@
-74,7
+74,7
@@
msg_class_from_category_and_severity (enum msg_category category,
struct msg_location
{
struct msg_location
{
- c
har *file_name; /* Name of file containing error
, or NULL. */
+ c
onst char *file_name; /* Interned file name
, or NULL. */
int first_line; /* 1-based line number, or 0 if none. */
int last_line; /* 1-based exclusive last line (0=none). */
int first_column; /* 1-based first column, or 0 if none. */
int first_line; /* 1-based line number, or 0 if none. */
int last_line; /* 1-based exclusive last line (0=none). */
int first_column; /* 1-based first column, or 0 if none. */