Permalink
Browse files

Add possibility of const-correctness

Follow-up to "Brainless start to const-correct changes"
Still actually does nothing, but now if the #define ICARUS_VPI_CONST
in vpi_user.h is changed to const, Icarus is almost const-correct,
as checked with gcc flags -Wcast-qual -Wwrite-strings.

Choosing when to #define ICARUS_VPI_CONST const is left as an
exercise for the reader.

With these two patches applied, and the const define, there are
still about a dozen const problems left.
  • Loading branch information...
ldoolitt authored and steveicarus committed Oct 4, 2010
1 parent 5d977ca commit eaccf4d64f272fdbf00b2324d9e4902a63d8ff17
Showing with 30 additions and 29 deletions.
  1. +1 −1 acc_user.h
  2. +1 −1 libveriuser/a_fetch_type_str.c
  3. +7 −7 vpi/sys_display.c
  4. +2 −1 vpi/sys_fileio.c
  5. +1 −1 vpi/sys_finish.c
  6. +2 −2 vpi/sys_priv.c
  7. +2 −2 vpi/sys_priv.h
  8. +1 −1 vpi/sys_random.c
  9. +2 −2 vpi/sys_readmem.c
  10. +1 −1 vpi/sys_scanf.c
  11. +4 −4 vpi/v2005_math.c
  12. +4 −4 vpi/va_math.c
  13. +2 −2 vpi/vcd_priv.c
View
@@ -229,7 +229,7 @@ extern PLI_INT32 acc_fetch_size(handle obj);
extern PLI_INT32 acc_fetch_type(handle obj);
extern PLI_INT32 acc_fetch_fulltype(handle obj);
extern PLI_INT32 acc_fetch_range(handle object, int *msb, int *lsb);
-extern char* acc_fetch_type_str(PLI_INT32 type);
+extern const char* acc_fetch_type_str(PLI_INT32 type);
extern char* acc_fetch_value(handle obj, const char*fmt, s_acc_value*value);
@@ -22,7 +22,7 @@
#include <acc_user.h>
-char* acc_fetch_type_str(PLI_INT32 type)
+const char* acc_fetch_type_str(PLI_INT32 type)
{
switch (type) {
case accNet:
View
@@ -50,7 +50,7 @@ static PLI_INT32 my_mcd_printf(PLI_UINT32 mcd, const char *fmt, ...)
struct timeformat_info_s timeformat_info = { 0, 0, 0, 20 };
struct strobe_cb_info {
- char*name;
+ const char*name;
char*filename;
int lineno;
int default_format;
@@ -129,7 +129,7 @@ static void array_from_iterator(struct strobe_cb_info*info, vpiHandle argv)
}
}
-static int get_default_format(char *name)
+static int get_default_format(const char *name)
{
int default_format;
@@ -256,7 +256,7 @@ static void get_time_real(char *rtn, double value, int prec,
static unsigned int get_format_char(char **rtn, int ljust, int plus,
int ld_zero, int width, int prec,
- char fmt, struct strobe_cb_info *info,
+ char fmt, const struct strobe_cb_info *info,
unsigned int *idx)
{
s_vpi_value value;
@@ -804,7 +804,7 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
/* We can't use the normal str functions on the return value since
* %u and %z can insert NULL characters into the stream. */
static unsigned int get_format(char **rtn, char *fmt,
- struct strobe_cb_info *info, unsigned int *idx)
+ const struct strobe_cb_info *info, unsigned int *idx)
{
char *cp = fmt;
unsigned int size;
@@ -851,7 +851,7 @@ static unsigned int get_format(char **rtn, char *fmt,
return size - 1;
}
-static unsigned int get_numeric(char **rtn, struct strobe_cb_info *info,
+static unsigned int get_numeric(char **rtn, const struct strobe_cb_info *info,
vpiHandle item)
{
int size;
@@ -875,7 +875,7 @@ static unsigned int get_numeric(char **rtn, struct strobe_cb_info *info,
/* In many places we can't use the normal str functions since %u and %z
* can insert NULL characters into the stream. */
-static char *get_display(unsigned int *rtnsz, struct strobe_cb_info *info)
+static char *get_display(unsigned int *rtnsz, const struct strobe_cb_info *info)
{
char *result, *fmt, *rtn, *func_name;
const char *cresult;
@@ -1012,7 +1012,7 @@ static char *get_display(unsigned int *rtnsz, struct strobe_cb_info *info)
return rtn;
}
-static int sys_check_args(vpiHandle callh, vpiHandle argv, PLI_BYTE8*name,
+static int sys_check_args(vpiHandle callh, vpiHandle argv, const PLI_BYTE8*name,
int no_auto, int is_monitor)
{
vpiHandle arg;
View
@@ -182,7 +182,8 @@ static PLI_INT32 sys_fopenrwa_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, callh);
s_vpi_value val;
- char *mode, *fname;
+ char *fname;
+ const char *mode;
errno = 0;
/* Get the mode. */
View
@@ -37,7 +37,7 @@ static PLI_INT32 sys_finish_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name)
diag_msg = val.value.integer;
}
- if (strcmp((char*)name, "$stop") == 0) {
+ if (strcmp((const char*)name, "$stop") == 0) {
vpi_control(vpiStop, diag_msg);
return 0;
}
View
@@ -60,7 +60,7 @@ char *as_escaped(char *arg)
* The result is duplicated so call free when the name is no
* longer needed. Returns 0 (NULL) for an error.
*/
-char *get_filename(vpiHandle callh, char *name, vpiHandle file)
+char *get_filename(vpiHandle callh, const char *name, vpiHandle file)
{
s_vpi_value val;
unsigned len, idx;
@@ -101,7 +101,7 @@ char *get_filename(vpiHandle callh, char *name, vpiHandle file)
return strdup(val.value.str);
}
-void check_for_extra_args(vpiHandle argv, vpiHandle callh, char *name,
+void check_for_extra_args(vpiHandle argv, vpiHandle callh, const char *name,
const char *arg_str, unsigned opt)
{
/* Check that there are no extra arguments. */
View
@@ -36,9 +36,9 @@ extern unsigned long genrand(struct context_s *context);
extern PLI_UINT64 timerec_to_time64(const struct t_vpi_time*timerec);
extern char *as_escaped(char *arg);
-extern char *get_filename(vpiHandle callh, char *name, vpiHandle file);
+extern char *get_filename(vpiHandle callh, const char *name, vpiHandle file);
-extern void check_for_extra_args(vpiHandle argv, vpiHandle callh, char *name,
+extern void check_for_extra_args(vpiHandle argv, vpiHandle callh, const char *name,
const char *arg_str, unsigned opt);
struct timeformat_info_s {
View
@@ -365,7 +365,7 @@ static double erlangian(long *seed, long k, long mean)
}
/* A seed can only be an integer/time variable or a register. */
-static unsigned is_seed_obj(vpiHandle obj, vpiHandle callh, char *name)
+static unsigned is_seed_obj(vpiHandle obj, vpiHandle callh, const char *name)
{
unsigned rtn = 0;
View
@@ -29,7 +29,7 @@
char **search_list = NULL;
unsigned sl_count = 0;
-static void get_mem_params(vpiHandle argv, vpiHandle callh, char *name,
+static void get_mem_params(vpiHandle argv, vpiHandle callh, const char *name,
char **fname, vpiHandle *mitem,
vpiHandle *start_item, vpiHandle *stop_item)
{
@@ -82,7 +82,7 @@ static void get_mem_params(vpiHandle argv, vpiHandle callh, char *name,
static int process_params(vpiHandle mitem,
vpiHandle start_item, vpiHandle stop_item,
- vpiHandle callh, char *name,
+ vpiHandle callh, const char *name,
int *start_addr, int *stop_addr, int *addr_incr,
int *min_addr, int *max_addr)
{
View
@@ -561,7 +561,7 @@ static int is_assignable_obj(vpiHandle obj)
return rtn;
}
-static int sys_check_args(vpiHandle callh, vpiHandle argv, PLI_BYTE8 *name)
+static int sys_check_args(vpiHandle callh, vpiHandle argv, const PLI_BYTE8 *name)
{
vpiHandle arg;
int cnt = 3, rtn = 0;
View
@@ -162,15 +162,15 @@ vpiHandle va_process_argument(vpiHandle callh, const char *name,
static PLI_INT32 va_single_argument_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
{
vpiHandle callh, argv, arg;
- t_single_data *data;
+ const t_single_data *data;
const char *name;
va_single_t* fun_data;
assert(ud != 0);
callh = vpi_handle(vpiSysTfCall, 0);
assert(callh != 0);
argv = vpi_iterate(vpiArgument, callh);
- data = (t_single_data *) ud;
+ data = (const t_single_data *) ud;
name = data->name;
fun_data = malloc(sizeof(va_single_t));
@@ -244,15 +244,15 @@ static PLI_INT32 va_single_argument_calltf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
static PLI_INT32 va_double_argument_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
{
vpiHandle callh, argv, arg;
- t_double_data *data;
+ const t_double_data *data;
const char *name;
va_double_t* fun_data;
assert(ud != 0);
callh = vpi_handle(vpiSysTfCall, 0);
assert(callh != 0);
argv = vpi_iterate(vpiArgument, callh);
- data = (t_double_data *) ud;
+ data = (const t_double_data *) ud;
name = data->name;
fun_data = malloc(sizeof(va_double_t));
View
@@ -189,15 +189,15 @@ vpiHandle va_process_argument(vpiHandle callh, const char *name,
static PLI_INT32 va_single_argument_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
{
vpiHandle callh, argv, arg;
- t_single_data *data;
+ const t_single_data *data;
const char *name;
va_single_t* fun_data;
assert(ud != 0);
callh = vpi_handle(vpiSysTfCall, 0);
assert(callh != 0);
argv = vpi_iterate(vpiArgument, callh);
- data = (t_single_data *) ud;
+ data = (const t_single_data *) ud;
name = data->name;
fun_data = malloc(sizeof(va_single_t));
@@ -271,15 +271,15 @@ static PLI_INT32 va_single_argument_calltf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
static PLI_INT32 va_double_argument_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
{
vpiHandle callh, argv, arg;
- t_double_data *data;
+ const t_double_data *data;
const char *name;
va_double_t* fun_data;
assert(ud != 0);
callh = vpi_handle(vpiSysTfCall, 0);
assert(callh != 0);
argv = vpi_iterate(vpiArgument, callh);
- data = (t_double_data *) ud;
+ data = (const t_double_data *) ud;
name = data->name;
fun_data = malloc(sizeof(va_double_t));
View
@@ -80,8 +80,8 @@ void vcd_names_delete(struct vcd_names_list_s*tab)
static int vcd_names_compare(const void *s1, const void *s2)
{
- const char *v1 = *(const char **) s1;
- const char *v2 = *(const char **) s2;
+ const char *v1 = *(const char * const *) s1;
+ const char *v2 = *(const char * const *) s2;
return strcmp(v1, v2);
}

0 comments on commit eaccf4d

Please sign in to comment.