[augeas-devel] [PATCH] Change struct fields of type (const char *) to (char *)
David Lutterkort
dlutter at redhat.com
Fri Jun 6 18:38:58 UTC 2008
12 files changed, 77 insertions(+), 83 deletions(-)
src/augeas.c | 9 ++++-----
src/get.c | 26 +++++++++++++-------------
src/internal.h | 7 +++----
src/lens.c | 6 +++---
src/lens.h | 4 ++--
src/lexer.l | 1 +
src/parser.y | 22 +++++++++++-----------
src/put.c | 6 +++---
src/regexp.c | 4 ++--
src/syntax.c | 52 +++++++++++++++++++++++++---------------------------
src/syntax.h | 20 +++++++++-----------
src/transform.c | 3 +--
# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1212777529 25200
# Node ID 84ed3d061a2a46d477dd98f400f9b53b7fbbbf4f
# Parent 51525a865e2fe536e7efa764dbbd66b72547488d
Change struct fields of type (const char *) to (char *)
There were many places where struct fields were declared (const char *) but
then used as (char *) - mostly to free them. Remove the 'const' from those
fields.
I would really appreciate if somebody could look over these and make sure I
don't throw away constness in too many places. It seems strange to declare a
field as non-const, even if the string referenced by it is never modified,
and only ever free'd when the enclosing struct is free'd.
diff -r 51525a865e2f -r 84ed3d061a2a src/augeas.c
--- a/src/augeas.c Thu Jun 05 15:31:46 2008 -0700
+++ b/src/augeas.c Fri Jun 06 11:38:49 2008 -0700
@@ -587,7 +587,7 @@
free_path(p);
if (tree->value != NULL) {
- free((char *) tree->value);
+ free(tree->value);
tree->value = NULL;
}
if (value != NULL) {
@@ -645,8 +645,7 @@
return -1;
}
-struct tree *make_tree(const char *label, const char *value,
- struct tree *children) {
+struct tree *make_tree(char *label, char *value, struct tree *children) {
struct tree *tree;
CALLOC(tree, 1);
if (tree == NULL)
@@ -664,8 +663,8 @@
if (tree == NULL)
return;
- free((char *) tree->label);
- free((char *) tree->value);
+ free(tree->label);
+ free(tree->value);
free(tree);
}
diff -r 51525a865e2f -r 84ed3d061a2a src/get.c
--- a/src/get.c Thu Jun 05 15:31:46 2008 -0700
+++ b/src/get.c Fri Jun 06 11:38:49 2008 -0700
@@ -53,8 +53,8 @@
struct split *split;
const char *text;
struct seq *seqs;
- const char *key;
- const char *value; /* GET_STORE leaves a value here */
+ char *key;
+ char *value; /* GET_STORE leaves a value here */
struct lns_error *error;
};
@@ -108,12 +108,12 @@
free_skel(del);
}
} else if (skel->tag == L_DEL) {
- free((char *) skel->text);
+ free(skel->text);
}
free(skel);
}
-static struct dict *make_dict(const char *key,
+static struct dict *make_dict(char *key,
struct skel *skel, struct dict *subdict) {
struct dict *dict;
CALLOC(dict, 1);
@@ -135,7 +135,7 @@
free_dict(del->dict);
free(del);
}
- free((char *) dict->key);
+ free(dict->key);
free(dict);
dict = next;
}
@@ -232,7 +232,7 @@
struct dict *del = e2;
list_append(e1->entry, e2->entry);
e2 = e2->next;
- free((char *) del->key);
+ free(del->key);
free(del);
}
}
@@ -631,8 +631,8 @@
}
static struct tree *get_subtree(struct lens *lens, struct state *state) {
- const char *key = state->key;
- const char *value = state->value;
+ char *key = state->key;
+ char *value = state->value;
struct tree *tree = NULL, *children;
state->key = NULL;
@@ -648,7 +648,7 @@
static struct skel *parse_subtree(struct lens *lens, struct state *state,
struct dict **dict) {
- const char *key = state->key;
+ char *key = state->key;
struct skel *skel;
struct dict *di = NULL;
@@ -726,11 +726,11 @@
free_seqs(state.seqs);
if (state.key != NULL) {
get_error(&state, lens, "get left unused key %s", state.key);
- free((char *) state.key);
+ free(state.key);
}
if (state.value != NULL) {
get_error(&state, lens, "get left unused value %s", state.value);
- free((char *) state.value);
+ free(state.value);
}
} else {
get_error(&state, lens, "get can not process entire input");
@@ -823,11 +823,11 @@
}
if (state.key != NULL) {
get_error(&state, lens, "parse left unused key %s", state.key);
- free((char *) state.key);
+ free(state.key);
}
if (state.value != NULL) {
get_error(&state, lens, "parse left unused value %s", state.value);
- free((char *) state.value);
+ free(state.value);
}
} else {
// This should never happen during lns_parse
diff -r 51525a865e2f -r 84ed3d061a2a src/internal.h
--- a/src/internal.h Thu Jun 05 15:31:46 2008 -0700
+++ b/src/internal.h Fri Jun 06 11:38:49 2008 -0700
@@ -235,17 +235,16 @@
*/
struct tree {
struct tree *next;
- const char *label; /* Last component of PATH */
+ char *label; /* Last component of PATH */
struct tree *children; /* List of children through NEXT */
- const char *value;
+ char *value;
int dirty;
};
/* Allocate a new tree node with the given LABEL, VALUE, and CHILDREN,
* which are not copied. The new tree is marked as dirty
*/
-struct tree *make_tree(const char *label, const char *value,
- struct tree *children);
+struct tree *make_tree(char *label, char *value, struct tree *children);
int aug_tree_replace(struct augeas *aug, const char *path, struct tree *sub);
diff -r 51525a865e2f -r 84ed3d061a2a src/lens.c
--- a/src/lens.c Thu Jun 05 15:31:46 2008 -0700
+++ b/src/lens.c Fri Jun 06 11:38:49 2008 -0700
@@ -438,7 +438,7 @@
make_ref(regexp->pattern);
regexp->info = ref(info);
CALLOC(regexp->pattern->str, len);
- snprintf((char *) regexp->pattern->str, len, "(%s)/", pat);
+ snprintf(regexp->pattern->str, len, "(%s)/", pat);
return regexp;
}
@@ -452,7 +452,7 @@
*/
static struct regexp *lns_key_regexp(struct lens *l, struct value **exn) {
static const struct string leaf_key_string = {
- .ref = UINT_MAX, .str = "/"
+ .ref = UINT_MAX, .str = (char *) "/"
};
static const struct string *const leaf_key_pat = &leaf_key_string;
@@ -488,7 +488,7 @@
unref(r, regexp);
return NULL;
}
- strcat((char *) r->pattern->str, "/");
+ strcat(r->pattern->str, "/");
return r;
}
case L_CONCAT:
diff -r 51525a865e2f -r 84ed3d061a2a src/lens.h
--- a/src/lens.h Thu Jun 05 15:31:46 2008 -0700
+++ b/src/lens.h Fri Jun 06 11:38:49 2008 -0700
@@ -89,7 +89,7 @@
struct lens *lens;
enum lens_tag tag;
union {
- const char *text; /* L_DEL */
+ char *text; /* L_DEL */
struct skel *skels; /* L_CONCAT, L_STAR, L_MAYBE */
};
/* Also tag == L_SUBTREE, with no data in the union */
@@ -104,7 +104,7 @@
struct dict {
struct dict *next;
- const char *key;
+ char *key;
struct dict_entry *entry; /* This will change as entries are looked up */
struct dict_entry *mark; /* Pointer to initial entry, will never change */
};
diff -r 51525a865e2f -r 84ed3d061a2a src/lexer.l
--- a/src/lexer.l Thu Jun 05 15:31:46 2008 -0700
+++ b/src/lexer.l Fri Jun 06 11:38:49 2008 -0700
@@ -7,6 +7,7 @@
%{
#include <config.h>
+#include <string.h>
#include "syntax.h"
diff -r 51525a865e2f -r 84ed3d061a2a src/parser.y
--- a/src/parser.y Thu Jun 05 15:31:46 2008 -0700
+++ b/src/parser.y Fri Jun 06 11:38:49 2008 -0700
@@ -104,14 +104,14 @@
/* TERM construction */
static struct info *clone_info(struct info *locp);
- static struct term *make_module(const char *ident, const char *autoload,
+ static struct term *make_module(char *ident, char *autoload,
struct term *decls,
struct info *locp);
- static struct term *make_bind(const char *ident, struct term *params,
+ static struct term *make_bind(char *ident, struct term *params,
struct term *exp, struct term *decls,
struct info *locp);
- static struct term *make_let(const char *ident, struct term *params,
+ static struct term *make_let(char *ident, struct term *params,
struct term *exp, struct term *body,
struct info *locp);
static struct term *make_binop(enum term_tag tag,
@@ -119,9 +119,9 @@
struct info *locp);
static struct term *make_unop(enum term_tag tag,
struct term *exp, struct info *locp);
- static struct term *make_ident(const char *qname, struct info *locp);
- static struct term *make_value_term(enum value_tag tag, const char *value,
- struct info *locp);
+ static struct term *make_ident(char *qname, struct info *locp);
+ static struct term *make_value_term(enum value_tag tag, char *value,
+ struct info *locp);
static struct term *make_rep(struct term *exp, enum quant_tag quant,
struct info *locp);
@@ -356,7 +356,7 @@
return make_term(tag, info);
}
-static struct term *make_module(const char *ident, const char *autoload,
+static struct term *make_module(char *ident, char *autoload,
struct term *decls,
struct info *locp) {
struct term *term = make_term_locp(A_MODULE, locp);
@@ -366,7 +366,7 @@
return term;
}
-static struct term *make_bind(const char *ident, struct term *params,
+static struct term *make_bind(char *ident, struct term *params,
struct term *exp, struct term *decls,
struct info *locp) {
struct term *term = make_term_locp(A_BIND, locp);
@@ -379,7 +379,7 @@
return decls;
}
-static struct term *make_let(const char *ident, struct term *params,
+static struct term *make_let(char *ident, struct term *params,
struct term *exp, struct term *body,
struct info *locp) {
/* let f (x:string) = "f " . x in
@@ -416,13 +416,13 @@
return term;
}
-static struct term *make_ident(const char *qname, struct info *locp) {
+static struct term *make_ident(char *qname, struct info *locp) {
struct term *term = make_term_locp(A_IDENT, locp);
term->ident = make_string(qname);
return term;
}
-static struct term *make_value_term(enum value_tag tag, const char *value,
+static struct term *make_value_term(enum value_tag tag, char *value,
struct info *locp) {
assert(tag == V_STRING || tag == V_REGEXP);
struct term *term = make_term_locp(A_VALUE, locp);
diff -r 51525a865e2f -r 84ed3d061a2a src/put.c
--- a/src/put.c Thu Jun 05 15:31:46 2008 -0700
+++ b/src/put.c Fri Jun 06 11:38:49 2008 -0700
@@ -45,7 +45,7 @@
struct split *next;
struct tree *tree;
struct tree *follow;
- const char *labels;
+ char *labels;
size_t start;
size_t end;
};
@@ -128,13 +128,13 @@
if (split == NULL)
return;
- free((char *) split->labels);
+ free(split->labels);
free(split);
}
static void split_append(struct split **split,
struct tree *tree, struct tree *follow,
- const char *labels, size_t start, size_t end) {
+ char *labels, size_t start, size_t end) {
struct split *sp;
CALLOC(sp, 1);
sp->tree = tree;
diff -r 51525a865e2f -r 84ed3d061a2a src/regexp.c
--- a/src/regexp.c Thu Jun 05 15:31:46 2008 -0700
+++ b/src/regexp.c Fri Jun 06 11:38:49 2008 -0700
@@ -26,7 +26,7 @@
#include "memory.h"
static const struct string empty_pattern_string = {
- .ref = REF_MAX, .str = "()"
+ .ref = REF_MAX, .str = (char *) "()"
};
static const struct string *const empty_pattern = &empty_pattern_string;
@@ -45,7 +45,7 @@
fputc('/', out);
}
-struct regexp *make_regexp(struct info *info, const char *pat) {
+struct regexp *make_regexp(struct info *info, char *pat) {
struct regexp *regexp;
make_ref(regexp);
diff -r 51525a865e2f -r 84ed3d061a2a src/syntax.c
--- a/src/syntax.c Thu Jun 05 15:31:46 2008 -0700
+++ b/src/syntax.c Fri Jun 06 11:38:49 2008 -0700
@@ -154,7 +154,7 @@
if (string == NULL)
return;
assert(string->ref == 0);
- free((char *) string->str);
+ free(string->str);
free(string);
}
@@ -182,12 +182,12 @@
assert(term->ref == 0);
switch(term->tag) {
case A_MODULE:
- free((char *) term->mname);
- free((char *) term->autoload);
+ free(term->mname);
+ free(term->autoload);
unref(term->decls, term);
break;
case A_BIND:
- free((char *) term->bname);
+ free(term->bname);
unref(term->exp, term);
break;
case A_COMPOSE:
@@ -244,7 +244,7 @@
if (module == NULL)
return;
assert(module->ref == 0);
- free((char *) module->name);
+ free(module->name);
unref(module->next, module);
unref(module->bindings, binding);
unref(module->autoload, transform);
@@ -333,8 +333,7 @@
return term;
}
-struct term *make_param(const char *name, struct type *type,
- struct info *info) {
+struct term *make_param(char *name, struct type *type, struct info *info) {
struct term *term = make_term(A_FUNC, info);
make_ref(term->param);
term->param->info = ref(term->info);
@@ -352,7 +351,7 @@
return value;
}
-struct string *make_string(const char *str) {
+struct string *make_string(char *str) {
struct string *string;
make_ref(string);
string->str = str;
@@ -367,8 +366,7 @@
return app;
}
-struct term *make_app_ident(const char *id, struct term *arg,
- struct info *info) {
+struct term *make_app_ident(char *id, struct term *arg, struct info *info) {
struct term *ident = make_term(A_IDENT, ref(info));
ident->ident = make_string(id);
return make_app_term(ident, arg, info);
@@ -578,12 +576,12 @@
static void dump_bindings(struct binding *bnds) {
list_for_each(b, bnds) {
- const char *st = type_string(b->type);
+ char *st = type_string(b->type);
fprintf(stderr, " %s: %s", b->ident->str, st);
fprintf(stderr, " = ");
print_value(stderr, b->value);
fputc('\n', stderr);
- free((char *) st);
+ free(st);
}
}
@@ -745,14 +743,14 @@
if (t->tag == T_ARROW) {
char *s = NULL;
int r;
- const char *sd = type_string(t->dom);
- const char *si = type_string(t->img);
+ char *sd = type_string(t->dom);
+ char *si = type_string(t->img);
if (t->dom->tag == T_ARROW)
r = asprintf(&s, "(%s) -> %s", sd, si);
else
r = asprintf(&s, "%s -> %s", sd, si);
- free((char *) sd);
- free((char *) si);
+ free(sd);
+ free(si);
return (r == -1) ? NULL : s;
} else {
return strdup(type_name(t));
@@ -988,30 +986,30 @@
}
static void type_error1(struct info *info, const char *msg, struct type *type) {
- const char *s = type_string(type);
+ char *s = type_string(type);
syntax_error(info, "Type error: ");
syntax_error(info, msg, s);
- free((char *) s);
+ free(s);
}
static void type_error2(struct info *info, const char *msg,
struct type *type1, struct type *type2) {
- const char *s1 = type_string(type1);
- const char *s2 = type_string(type2);
+ char *s1 = type_string(type1);
+ char *s2 = type_string(type2);
syntax_error(info, "Type error: ");
syntax_error(info, msg, s1, s2);
- free((char *) s1);
- free((char *) s2);
+ free(s1);
+ free(s2);
}
static void type_error_binop(struct info *info, const char *opname,
struct type *type1, struct type *type2) {
- const char *s1 = type_string(type1);
- const char *s2 = type_string(type2);
+ char *s1 = type_string(type1);
+ char *s2 = type_string(type2);
syntax_error(info, "Type error: ");
syntax_error(info, "%s of %s and %s is not possible", opname, s1, s2);
- free((char *) s1);
- free((char *) s2);
+ free(s1);
+ free(s2);
}
static int check_exp(struct term *term, struct ctx *ctx);
@@ -1422,7 +1420,7 @@
v = make_value(V_STRING, ref(info));
make_ref(v->string);
CALLOC(v->string->str, strlen(s1) + strlen(s2) + 1);
- char *s = (char *) v->string->str;
+ char *s = v->string->str;
strcpy(s, s1);
strcat(s, s2);
} else if (t->tag == T_REGEXP) {
diff -r 51525a865e2f -r 84ed3d061a2a src/syntax.h
--- a/src/syntax.h Thu Jun 05 15:31:46 2008 -0700
+++ b/src/syntax.h Fri Jun 06 11:38:49 2008 -0700
@@ -90,12 +90,12 @@
enum term_tag tag;
union {
struct { /* A_MODULE */
- const char *mname;
- const char *autoload;
+ char *mname;
+ char *autoload;
struct term *decls;
};
struct { /* A_BIND */
- const char *bname;
+ char *bname;
struct term *exp;
};
struct { /* A_COMPOSE, A_UNION, A_CONCAT, A_APP, A_LET */
@@ -130,7 +130,7 @@
struct string {
unsigned int ref;
- const char *str;
+ char *str;
};
struct regexp {
@@ -147,7 +147,7 @@
/* Make a regexp with pattern PAT, which is not copied. Ownership
* of INFO is taken.
*/
-struct regexp *make_regexp(struct info *info, const char *pat);
+struct regexp *make_regexp(struct info *info, char *pat);
/* Make a regexp that matches TEXT literally; the string TEXT
* is not used by the returned rgexp and must be freed by the caller
@@ -336,7 +336,7 @@
unsigned int ref;
struct module *next; /* Only used for the global list of modules */
struct transform *autoload;
- const char *name;
+ char *name;
struct binding *bindings;
};
@@ -349,14 +349,12 @@
* arguments without incrementing. Caller owns returned objects.
*/
struct term *make_term(enum term_tag tag, struct info *info);
-struct term *make_param(const char *name, struct type *type,
- struct info *info);
+struct term *make_param(char *name, struct type *type, struct info *info);
struct value *make_value(enum value_tag tag, struct info *info);
-struct string *make_string(const char *str);
+struct string *make_string(char *str);
struct term *make_app_term(struct term *func, struct term *arg,
struct info *info);
-struct term *make_app_ident(const char *id, struct term *func,
- struct info *info);
+struct term *make_app_ident(char *id, struct term *func, struct info *info);
/* Make an EXN value
* Receive ownership of INFO
diff -r 51525a865e2f -r 84ed3d061a2a src/transform.c
--- a/src/transform.c Thu Jun 05 15:31:46 2008 -0700
+++ b/src/transform.c Fri Jun 06 11:38:49 2008 -0700
@@ -302,8 +302,7 @@
return result;
}
-static int load_file(struct augeas *aug, struct lens *lens,
- const char *filename) {
+static int load_file(struct augeas *aug, struct lens *lens, char *filename) {
char *text = NULL;
const char *err_status = NULL;
struct aug_file *file = NULL;
More information about the augeas-devel
mailing list