summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/kpathsea')
-rw-r--r--Build/source/texk/kpathsea/ChangeLog15
-rw-r--r--Build/source/texk/kpathsea/cnf.c8
-rw-r--r--Build/source/texk/kpathsea/cnf.h4
-rw-r--r--Build/source/texk/kpathsea/db.c8
-rw-r--r--Build/source/texk/kpathsea/dir.c4
-rw-r--r--Build/source/texk/kpathsea/fontmap.c4
-rw-r--r--Build/source/texk/kpathsea/hash.c19
-rw-r--r--Build/source/texk/kpathsea/hash.h12
-rw-r--r--Build/source/texk/kpathsea/kpathsea.c4
-rw-r--r--Build/source/texk/kpathsea/rm-suffix.c6
-rw-r--r--Build/source/texk/kpathsea/str-list.c20
-rw-r--r--Build/source/texk/kpathsea/str-list.h32
12 files changed, 90 insertions, 46 deletions
diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog
index 15414d79e41..94d592e45d6 100644
--- a/Build/source/texk/kpathsea/ChangeLog
+++ b/Build/source/texk/kpathsea/ChangeLog
@@ -1,3 +1,18 @@
+2012-12-11 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ Resolve some const related problems.
+ * str-list.[ch]: Add cstr_list_type and cstr_list_add() for
+ const strings. Define [c]str_list_init() as static inline.
+ * kpathsea.c: Move definition of KPATHSEA_CAN_FREE from here ...
+ * hash.h: ... to here.
+ * hash.[ch]: Define hash_free() only if KPATHSEA_CAN_FREE!=0.
+ (hash_lookup): Change return type 'string*' => 'const_string*'.
+ * cnf.[ch] (kpathsea_cnf_get, kpse_cnf_get):
+ Change return type 'string*' => 'const_string*'.
+ * dir.c (kpathsea_dir_links): Adapt.
+ * rm-suffix.c (remove_suffix): Adapt.
+ * db.c, fontmap.c: Remove casts 'string*' => 'const_string*'.
+
2012-12-10 Peter Breitenlohner <peb@mppmu.mpg.de>
* mingw32.c: Remove look_for_cmd().
diff --git a/Build/source/texk/kpathsea/cnf.c b/Build/source/texk/kpathsea/cnf.c
index 1f9dc744c88..fe0f49df2c2 100644
--- a/Build/source/texk/kpathsea/cnf.c
+++ b/Build/source/texk/kpathsea/cnf.c
@@ -224,11 +224,11 @@ read_all_cnf (kpathsea kpse)
/* Read the cnf files on the first call. Return the first value in the
returned list -- this will be from the last-read cnf file. */
-string
+const_string
kpathsea_cnf_get (kpathsea kpse, const_string name)
{
- string ret, ctry;
- string *ret_list;
+ string ctry;
+ const_string ret, *ret_list;
/* When we expand the compile-time value for DEFAULT_TEXMFCNF,
we end up needing the value for TETEXDIR and other variables,
@@ -273,7 +273,7 @@ kpathsea_cnf_get (kpathsea kpse, const_string name)
}
#if defined(KPSE_COMPAT_API)
-string
+const_string
kpse_cnf_get (const_string name)
{
return kpathsea_cnf_get(kpse_def, name);
diff --git a/Build/source/texk/kpathsea/cnf.h b/Build/source/texk/kpathsea/cnf.h
index 4d653f4197e..dce41e2787b 100644
--- a/Build/source/texk/kpathsea/cnf.h
+++ b/Build/source/texk/kpathsea/cnf.h
@@ -26,10 +26,10 @@
On the first call, also read all the `texmf.cnf' files in the
path for kpse_cnf_format (and initialize the path). */
-extern KPSEDLL string kpathsea_cnf_get (kpathsea kpse, const_string name);
+extern KPSEDLL const_string kpathsea_cnf_get (kpathsea kpse, const_string name);
#if defined(KPSE_COMPAT_API)
-extern KPSEDLL string kpse_cnf_get (const_string var);
+extern KPSEDLL const_string kpse_cnf_get (const_string var);
#endif
#endif /* not KPATHSEA_CNF_H */
diff --git a/Build/source/texk/kpathsea/db.c b/Build/source/texk/kpathsea/db.c
index 76f7763d790..843a1a27b8f 100644
--- a/Build/source/texk/kpathsea/db.c
+++ b/Build/source/texk/kpathsea/db.c
@@ -435,7 +435,7 @@ str_list_type *
kpathsea_db_search (kpathsea kpse, const_string name,
const_string orig_path_elt, boolean all)
{
- string *db_dirs, *orig_dirs;
+ const_string *db_dirs, *orig_dirs;
const_string last_slash, path_elt;
string temp_str = NULL;
boolean done;
@@ -480,7 +480,7 @@ kpathsea_db_search (kpathsea kpse, const_string name,
/* If we have aliases for this name, use them. */
if (kpse->alias_db.buckets)
- aliases = (const_string *) hash_lookup (kpse->alias_db, name);
+ aliases = hash_lookup (kpse->alias_db, name);
else
aliases = NULL;
@@ -586,7 +586,7 @@ str_list_type *
kpathsea_db_search_list (kpathsea kpse, const_string* names,
const_string path_elt, boolean all)
{
- string *db_dirs, *orig_dirs;
+ const_string *db_dirs, *orig_dirs;
const_string last_slash, name, path;
string temp_str = NULL;
boolean done;
@@ -645,7 +645,7 @@ kpathsea_db_search_list (kpathsea kpse, const_string* names,
/* If we have aliases for this name, use them. */
if (kpse->alias_db.buckets)
- aliases = (const_string *) hash_lookup (kpse->alias_db, name);
+ aliases = hash_lookup (kpse->alias_db, name);
else
aliases = NULL;
diff --git a/Build/source/texk/kpathsea/dir.c b/Build/source/texk/kpathsea/dir.c
index 23d0c7dbc7c..f2b4eaf3fb1 100644
--- a/Build/source/texk/kpathsea/dir.c
+++ b/Build/source/texk/kpathsea/dir.c
@@ -1,6 +1,6 @@
/* dir.c: directory operations.
- Copyright 1992, 1993, 1994, 1995, 2008, 2009, 2010, 2011 Karl Berry.
+ Copyright 1992, 1993, 1994, 1995, 2008-2012 Karl Berry.
Copyright 2000, 2002, 2005 Olaf Weber.
This library is free software; you can redistribute it and/or
@@ -78,7 +78,7 @@ dir_p (string fn)
int
kpathsea_dir_links (kpathsea kpse, const_string fn, long nlinks)
{
- string *hash_ret;
+ const_string *hash_ret;
if (kpse->link_table.size == 0)
kpse->link_table = hash_create (457);
diff --git a/Build/source/texk/kpathsea/fontmap.c b/Build/source/texk/kpathsea/fontmap.c
index e878104188d..e1b40aef34e 100644
--- a/Build/source/texk/kpathsea/fontmap.c
+++ b/Build/source/texk/kpathsea/fontmap.c
@@ -177,14 +177,14 @@ kpathsea_fontmap_lookup (kpathsea kpse, const_string key)
read_all_maps (kpse);
}
- ret = (const_string *) hash_lookup (kpse->map, key);
+ ret = hash_lookup (kpse->map, key);
if (!ret) {
/* OK, the original KEY didn't work. Let's check for the KEY without
an extension -- perhaps they gave foobar.tfm, but the mapping only
defines `foobar'. */
if (suffix) {
string base_key = remove_suffix (key);
- ret = (const_string *) hash_lookup (kpse->map, base_key);
+ ret = hash_lookup (kpse->map, base_key);
free (base_key);
}
}
diff --git a/Build/source/texk/kpathsea/hash.c b/Build/source/texk/kpathsea/hash.c
index 8232eae5ac4..f1d81dbd3a6 100644
--- a/Build/source/texk/kpathsea/hash.c
+++ b/Build/source/texk/kpathsea/hash.c
@@ -1,6 +1,6 @@
/* hash.c: hash table operations.
- Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2005, 2008
+ Copyright 1994-2000, 2002, 2005, 2008, 2012
Karl Berry & Olaf Weber.
This library is free software; you can redistribute it and/or
@@ -158,23 +158,22 @@ hash_remove (hash_table_type *table, const_string key,
/* Look up KEY in TABLE, and return NULL-terminated list of all matching
values (not copies), in insertion order. If none, return NULL. */
-string *
+const_string *
hash_lookup (hash_table_type table, const_string key)
{
hash_element_type *p;
- str_list_type ret;
+ cstr_list_type ret;
unsigned n = hash (table, key);
- ret = str_list_init ();
+ ret = cstr_list_init ();
/* Look at everything in this bucket. */
for (p = table.buckets[n]; p != NULL; p = p->next)
if (FILESTRCASEEQ (key, p->key))
- /* Cast because the general str_list_type shouldn't force const data. */
- str_list_add (&ret, (string) p->value);
+ cstr_list_add (&ret, p->value);
/* If we found anything, mark end of list with null. */
if (STR_LIST (ret))
- str_list_add (&ret, NULL);
+ cstr_list_add (&ret, NULL);
#ifdef KPSE_DEBUG
#if defined (KPSE_COMPAT_API)
@@ -187,7 +186,7 @@ hash_lookup (hash_table_type table, const_string key)
fputs (" (nil)\n", stderr);
else
{
- string *r;
+ const_string *r;
for (r = STR_LIST (ret); *r; r++)
{
putc (' ', stderr);
@@ -207,6 +206,7 @@ hash_lookup (hash_table_type table, const_string key)
return STR_LIST (ret);
}
+#ifdef KPSE_DEBUG
/* We only print nonempty buckets, to decrease output volume. */
void
@@ -246,7 +246,9 @@ hash_print (hash_table_type table, boolean summary_only)
total_elements,
total_buckets ? total_elements / (double) total_buckets : 0.0);
}
+#endif
+#if KPATHSEA_CAN_FREE
void
hash_free (hash_table_type table)
{
@@ -260,3 +262,4 @@ hash_free (hash_table_type table)
p = q;
}
}
+#endif
diff --git a/Build/source/texk/kpathsea/hash.h b/Build/source/texk/kpathsea/hash.h
index 27294eaddf6..d382201d2a4 100644
--- a/Build/source/texk/kpathsea/hash.h
+++ b/Build/source/texk/kpathsea/hash.h
@@ -1,6 +1,6 @@
/* hash.h: declarations for a hash table.
- Copyright 1994, 1995, 2008, 2010, 2011 Karl Berry.
+ Copyright 1994, 1995, 2008, 2010-2012 Karl Berry.
Copyright 1999, 2005 Olaf Weber.
This library is free software; you can redistribute it and/or
@@ -22,6 +22,12 @@
#include <kpathsea/c-proto.h>
#include <kpathsea/types.h>
+/*
+ * The code freeing strings and hash tables is enabled/disabled
+ * by KPATHSEA_CAN_FREE.
+ */
+/* At the moment can not free */
+#define KPATHSEA_CAN_FREE 0
/* A single (key,value) pair. */
typedef struct hash_element_struct
@@ -65,15 +71,17 @@ extern KPSEDLL void hash_remove (hash_table_type *table, const_string key,
/* Look up KEY in TABLE, and return NULL-terminated list of all matching
values (not copies), in insertion order. If none, return NULL. */
-extern KPSEDLL string *hash_lookup (hash_table_type table, const_string key);
+extern KPSEDLL const_string *hash_lookup (hash_table_type table, const_string key);
#ifdef MAKE_KPSE_DLL /* libkpathsea internal only */
/* Print TABLE to stderr. */
extern void hash_print (hash_table_type table, boolean summary_only);
+#if KPATHSEA_CAN_FREE
/* Drop the TABLE */
extern void hash_free (hash_table_type table);
+#endif
#endif /* MAKE_KPSE_DLL */
diff --git a/Build/source/texk/kpathsea/kpathsea.c b/Build/source/texk/kpathsea/kpathsea.c
index 1fb0fa27524..b7bf6964ac2 100644
--- a/Build/source/texk/kpathsea/kpathsea.c
+++ b/Build/source/texk/kpathsea/kpathsea.c
@@ -1,6 +1,6 @@
/* kpathsea.c: creating and freeing library instances
- Copyright 2009 Taco Hoekwater.
+ Copyright 2009, 2012 Taco Hoekwater.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -21,8 +21,6 @@
* The code freeing the strings used in this struct is enabled/disabled
* by KPATHSEA_CAN_FREE.
*/
-/* At the moment can not free */
-#define KPATHSEA_CAN_FREE 0
#include <kpathsea/config.h>
diff --git a/Build/source/texk/kpathsea/rm-suffix.c b/Build/source/texk/kpathsea/rm-suffix.c
index 49a100da3ee..289847de455 100644
--- a/Build/source/texk/kpathsea/rm-suffix.c
+++ b/Build/source/texk/kpathsea/rm-suffix.c
@@ -1,6 +1,6 @@
/* rm-suffix.c: remove any suffix.
- Copyright 2008, 2011 Karl Berry.
+ Copyright 2008, 2011, 2012 Karl Berry.
Copyright 1992, 1993, 1995 Free Software Foundation, Inc.
Modified for kpathsea by Karl Berry.
@@ -20,8 +20,6 @@
#include <kpathsea/config.h>
-/* Generic const warning -- see readable.c. */
-
string
remove_suffix (const_string s)
{
@@ -37,7 +35,7 @@ remove_suffix (const_string s)
ret[suffix - s] = 0;
}
else
- ret = (string) s;
+ ret = xstrdup (s);
return ret;
}
diff --git a/Build/source/texk/kpathsea/str-list.c b/Build/source/texk/kpathsea/str-list.c
index d4dcf86c5bf..750ccd916ad 100644
--- a/Build/source/texk/kpathsea/str-list.c
+++ b/Build/source/texk/kpathsea/str-list.c
@@ -1,6 +1,6 @@
/* str-list.c: define routines for string lists.
- Copyright 1993, 2008 Karl Berry.
+ Copyright 1993, 2008, 2012 Karl Berry.
Copyright 2001, 2005 Olaf Weber.
This library is free software; you can redistribute it and/or
@@ -24,23 +24,19 @@
/* See the .h file for comments. */
-str_list_type
-str_list_init (void)
+void
+str_list_add (str_list_type *l, string s)
{
- str_list_type ret;
-
- STR_LIST_LENGTH (ret) = 0;
- STR_LIST (ret) = NULL;
-
- return ret;
+ STR_LIST_LENGTH (*l)++;
+ XRETALLOC (STR_LIST (*l), STR_LIST_LENGTH (*l), string);
+ STR_LIST_LAST_ELT (*l) = s;
}
-
void
-str_list_add (str_list_type *l, string s)
+cstr_list_add (cstr_list_type *l, const_string s)
{
STR_LIST_LENGTH (*l)++;
- XRETALLOC (STR_LIST (*l), STR_LIST_LENGTH (*l), string);
+ XRETALLOC (STR_LIST (*l), STR_LIST_LENGTH (*l), const_string);
STR_LIST_LAST_ELT (*l) = s;
}
diff --git a/Build/source/texk/kpathsea/str-list.h b/Build/source/texk/kpathsea/str-list.h
index cf33c726508..6be7b39ee45 100644
--- a/Build/source/texk/kpathsea/str-list.h
+++ b/Build/source/texk/kpathsea/str-list.h
@@ -1,6 +1,6 @@
/* str-list.h: declarations for string lists.
- Copyright 1993, 1994, 2007, 2008, 2010 Karl Berry.
+ Copyright 1993, 1994, 2007, 2008, 2010, 2012 Karl Berry.
Copyright 1999, 2005 Olaf Weber.
This library is free software; you can redistribute it and/or
@@ -24,13 +24,19 @@
/* Lists of strings; used for, e.g., directory lists. */
-
typedef struct
{
unsigned length;
string *list;
} str_list_type;
+/* Lists of const strings; used for, e.g., hash tables. */
+typedef struct
+{
+ unsigned length;
+ const_string *list;
+} cstr_list_type;
+
#define STR_LIST_LENGTH(l) ((l).length)
#define STR_LIST(l) ((l).list)
#define STR_LIST_ELT(l, n) STR_LIST (l)[n]
@@ -39,7 +45,26 @@ typedef struct
#ifdef MAKE_KPSE_DLL /* libkpathsea internal only */
/* Return a new, empty, list. */
-extern str_list_type str_list_init (void);
+static inline str_list_type
+str_list_init (void)
+{
+ str_list_type ret;
+
+ STR_LIST_LENGTH (ret) = 0;
+ STR_LIST (ret) = NULL;
+
+ return ret;
+}
+static inline cstr_list_type
+cstr_list_init (void)
+{
+ cstr_list_type ret;
+
+ STR_LIST_LENGTH (ret) = 0;
+ STR_LIST (ret) = NULL;
+
+ return ret;
+}
#endif /* MAKE_KPSE_DLL */
@@ -47,6 +72,7 @@ extern str_list_type str_list_init (void);
deallocate S; we don't copy it. Also up to the caller to terminate
the list with a null entry. */
extern KPSEDLL void str_list_add (str_list_type *l, string s);
+extern KPSEDLL void cstr_list_add (cstr_list_type *l, const_string s);
#ifdef MAKE_KPSE_DLL /* libkpathsea internal only */