Skip to content

Commit

Permalink
Add possibility of const-correctness
Browse files Browse the repository at this point in the history
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 6, 2010
1 parent 5d977ca commit eaccf4d
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion acc_user.h
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion libveriuser/a_fetch_type_str.c
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions vpi/sys_display.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion vpi/sys_fileio.c
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion vpi/sys_finish.c
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions vpi/sys_priv.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
4 changes: 2 additions & 2 deletions vpi/sys_priv.h
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion vpi/sys_random.c
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions vpi/sys_readmem.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion vpi/sys_scanf.c
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions vpi/v2005_math.c
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions vpi/va_math.c
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions vpi/vcd_priv.c
Expand Up @@ -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);
}
Expand Down

0 comments on commit eaccf4d

Please sign in to comment.