Don't lie to the c++ about some pointer alignment
Second try cleaning up cast-alignment problems surrounding need_result_buf(). Clang gave a bunch of warnings like vvp/vpi_const.cc:196:34: warning: cast from 'char *' to 'p_vpi_vecval' (aka 't_vpi_vecval *') increases required alignment from 1 to 4 [-Wcast-align] This version is verbose and changes the prototype for need_result_buf(). But it is semantically (c++) correct, and makes need_result_buf() feel like malloc().
This commit is contained in:
parent
529e029abd
commit
6a45a0d570
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -760,7 +760,7 @@ void vvp_signal_value::get_signal_value(struct t_vpi_value*vp)
|
|||
|
||||
static void real_signal_value(struct t_vpi_value*vp, double rval)
|
||||
{
|
||||
char*rbuf = need_result_buf(64 + 1, RBUF_VAL);
|
||||
char*rbuf = (char *) need_result_buf(64 + 1, RBUF_VAL);
|
||||
|
||||
switch (vp->format) {
|
||||
case vpiObjTypeVal:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2012 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -131,7 +131,7 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp)
|
|||
vp->format = vpiStringVal;
|
||||
|
||||
case vpiStringVal:
|
||||
rbuf = need_result_buf(size + 1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(size + 1, RBUF_VAL);
|
||||
strcpy(rbuf, value_);
|
||||
vp->value.str = rbuf;
|
||||
break;
|
||||
|
|
@ -143,7 +143,7 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp)
|
|||
fprintf(stderr, "Warning (vpi_const.cc): %%d on constant strings only looks "
|
||||
"at first 4 bytes!\n");
|
||||
}
|
||||
rbuf = need_result_buf(size + 1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(size + 1, RBUF_VAL);
|
||||
uint_value = 0;
|
||||
for(unsigned i=0; i<size; i += 1){
|
||||
uint_value <<=8;
|
||||
|
|
@ -154,7 +154,7 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp)
|
|||
break;
|
||||
|
||||
case vpiBinStrVal:
|
||||
rbuf = need_result_buf(8 * size + 1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(8 * size + 1, RBUF_VAL);
|
||||
cp = rbuf;
|
||||
for(unsigned i=0; i<size; i += 1){
|
||||
for(int bit=7; bit>=0; bit -= 1){
|
||||
|
|
@ -166,7 +166,7 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp)
|
|||
break;
|
||||
|
||||
case vpiHexStrVal:
|
||||
rbuf = need_result_buf(2 * size + 1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(2 * size + 1, RBUF_VAL);
|
||||
cp = rbuf;
|
||||
for(unsigned i=0; i<size; i += 1){
|
||||
for(int nibble=1; nibble>=0; nibble -= 1){
|
||||
|
|
@ -571,7 +571,7 @@ int __vpiDecConst::vpi_get(int code)
|
|||
|
||||
void __vpiDecConst::vpi_get_value(p_vpi_value vp)
|
||||
{
|
||||
char*rbuf = need_result_buf(64 + 1, RBUF_VAL);
|
||||
char*rbuf = (char *) need_result_buf(64 + 1, RBUF_VAL);
|
||||
char*cp = rbuf;
|
||||
|
||||
switch (vp->format) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2008-2014 Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -584,7 +584,7 @@ static void vec4_get_value_string(const vvp_vector4_t&word_val, unsigned width,
|
|||
unsigned nchar = width / 8;
|
||||
unsigned tail = width % 8;
|
||||
|
||||
char*rbuf = need_result_buf(nchar + 1, RBUF_VAL);
|
||||
char*rbuf = (char *) need_result_buf(nchar + 1, RBUF_VAL);
|
||||
char*cp = rbuf;
|
||||
|
||||
if (tail > 0) {
|
||||
|
|
@ -636,7 +636,7 @@ void vpip_vec4_get_value(const vvp_vector4_t&word_val, unsigned width,
|
|||
break;
|
||||
|
||||
case vpiBinStrVal:
|
||||
rbuf = need_result_buf(width+1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(width+1, RBUF_VAL);
|
||||
for (unsigned idx = 0 ; idx < width ; idx += 1) {
|
||||
vvp_bit4_t bit = word_val.value(idx);
|
||||
rbuf[width-idx-1] = vvp_bit4_to_ascii(bit);
|
||||
|
|
@ -647,7 +647,7 @@ void vpip_vec4_get_value(const vvp_vector4_t&word_val, unsigned width,
|
|||
|
||||
case vpiOctStrVal: {
|
||||
unsigned hwid = ((width+2) / 3) + 1;
|
||||
rbuf = need_result_buf(hwid, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(hwid, RBUF_VAL);
|
||||
vpip_vec4_to_oct_str(word_val, rbuf, hwid);
|
||||
vp->value.str = rbuf;
|
||||
break;
|
||||
|
|
@ -655,7 +655,7 @@ void vpip_vec4_get_value(const vvp_vector4_t&word_val, unsigned width,
|
|||
|
||||
case vpiDecStrVal: {
|
||||
// HERE need a better estimate.
|
||||
rbuf = need_result_buf(width+1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(width+1, RBUF_VAL);
|
||||
vpip_vec4_to_dec_str(word_val, rbuf, width+1, signed_flag);
|
||||
vp->value.str = rbuf;
|
||||
break;
|
||||
|
|
@ -663,7 +663,7 @@ void vpip_vec4_get_value(const vvp_vector4_t&word_val, unsigned width,
|
|||
|
||||
case vpiHexStrVal: {
|
||||
unsigned hwid = ((width + 3) / 4) + 1;
|
||||
rbuf = need_result_buf(hwid, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(hwid, RBUF_VAL);
|
||||
vpip_vec4_to_hex_str(word_val, rbuf, hwid);
|
||||
vp->value.str = rbuf;
|
||||
break;
|
||||
|
|
@ -714,7 +714,7 @@ void vpip_vec4_get_value(const vvp_vector4_t&word_val, unsigned width,
|
|||
case vpiVectorVal: {
|
||||
unsigned hwid = (width + 31)/32;
|
||||
|
||||
rbuf = need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);
|
||||
s_vpi_vecval *op = (p_vpi_vecval)rbuf;
|
||||
vp->value.vector = op;
|
||||
|
||||
|
|
@ -779,7 +779,7 @@ void vpip_vec2_get_value(const vvp_vector2_t&word_val, unsigned width,
|
|||
case vpiVectorVal: {
|
||||
unsigned hwid = (width + 31)/32;
|
||||
|
||||
rbuf = need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);
|
||||
s_vpi_vecval *op = (p_vpi_vecval)rbuf;
|
||||
vp->value.vector = op;
|
||||
|
||||
|
|
@ -860,7 +860,7 @@ void vpip_real_get_value(double real, s_vpi_value*vp)
|
|||
break;
|
||||
|
||||
case vpiDecStrVal:
|
||||
rbuf = need_result_buf(1025, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(1025, RBUF_VAL);
|
||||
vpip_vec4_to_dec_str(vvp_vector4_t(1024, real), rbuf, 1025, true);
|
||||
vp->value.str = rbuf;
|
||||
break;
|
||||
|
|
@ -934,7 +934,7 @@ void vpip_string_get_value(const string&val, s_vpi_value*vp)
|
|||
vp->format = vpiStringVal;
|
||||
|
||||
case vpiStringVal:
|
||||
rbuf = need_result_buf(val.size() + 1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(val.size() + 1, RBUF_VAL);
|
||||
strcpy(rbuf, val.c_str());
|
||||
vp->value.str = rbuf;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -789,7 +789,7 @@ enum vpi_rbuf_t {
|
|||
RBUF_DEL
|
||||
/* Delete the storage for both buffers. */
|
||||
};
|
||||
extern char *need_result_buf(unsigned cnt, vpi_rbuf_t type);
|
||||
extern void *need_result_buf(unsigned cnt, vpi_rbuf_t type);
|
||||
/* following two routines use need_result_buf(, RBUF_STR) */
|
||||
extern char *simple_set_rbuf_str(const char *s1);
|
||||
extern char *generic_get_str(int code, vpiHandle ref, const char *name, const char *index);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -62,9 +62,9 @@ extern const char oct_digits[64];
|
|||
* buffer can be reused for that purpose. Whenever I have a need, the
|
||||
* need_result_buf function makes sure that need can be met.
|
||||
*/
|
||||
char *need_result_buf(unsigned cnt, vpi_rbuf_t type)
|
||||
void *need_result_buf(unsigned cnt, vpi_rbuf_t type)
|
||||
{
|
||||
static char*result_buf[2] = {0, 0};
|
||||
static void*result_buf[2] = {0, 0};
|
||||
static size_t result_buf_size[2] = {0, 0};
|
||||
|
||||
if (type == RBUF_DEL) {
|
||||
|
|
@ -82,10 +82,10 @@ char *need_result_buf(unsigned cnt, vpi_rbuf_t type)
|
|||
cnt = (cnt + 0x0fff) & ~0x0fff;
|
||||
|
||||
if (result_buf_size[type] == 0) {
|
||||
result_buf[type] = (char*)malloc(cnt);
|
||||
result_buf[type] = malloc(cnt);
|
||||
result_buf_size[type] = cnt;
|
||||
} else if (result_buf_size[type] < cnt) {
|
||||
result_buf[type] = (char*)realloc(result_buf[type], cnt);
|
||||
result_buf[type] = realloc(result_buf[type], cnt);
|
||||
result_buf_size[type] = cnt;
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ char *need_result_buf(unsigned cnt, vpi_rbuf_t type)
|
|||
|
||||
char *simple_set_rbuf_str(const char *s1)
|
||||
{
|
||||
char *res = need_result_buf(strlen(s1)+1, RBUF_STR);
|
||||
char *res = (char *) need_result_buf(strlen(s1)+1, RBUF_STR);
|
||||
if (res) strcpy(res,s1);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ char *generic_get_str(int code, vpiHandle ref, const char *name, const char *ind
|
|||
}
|
||||
if (index != NULL) len += strlen(index) + 2; /* include space for brackets */
|
||||
|
||||
char *res = need_result_buf(len, RBUF_STR);
|
||||
char *res = (char *) need_result_buf(len, RBUF_STR);
|
||||
if (!res) {
|
||||
free(bn);
|
||||
return NULL;
|
||||
|
|
@ -143,7 +143,7 @@ static vpiHandle fill_in_net4(struct __vpiSignal*obj,
|
|||
static void format_vpiBinStrVal(vvp_signal_value*sig, int base, unsigned wid,
|
||||
s_vpi_value*vp)
|
||||
{
|
||||
char *rbuf = need_result_buf(wid+1, RBUF_VAL);
|
||||
char *rbuf = (char *) need_result_buf(wid+1, RBUF_VAL);
|
||||
long end = base + (signed)wid;
|
||||
long offset = end - 1;
|
||||
long ssize = (signed)sig->value_size();
|
||||
|
|
@ -164,7 +164,7 @@ static void format_vpiOctStrVal(vvp_signal_value*sig, int base, unsigned wid,
|
|||
s_vpi_value*vp)
|
||||
{
|
||||
unsigned dwid = (wid + 2) / 3;
|
||||
char *rbuf = need_result_buf(dwid+1, RBUF_VAL);
|
||||
char *rbuf = (char *) need_result_buf(dwid+1, RBUF_VAL);
|
||||
long end = base + (signed)wid;
|
||||
long ssize = (signed)sig->value_size();
|
||||
unsigned val = 0;
|
||||
|
|
@ -220,7 +220,7 @@ static void format_vpiHexStrVal(vvp_signal_value*sig, int base, unsigned wid,
|
|||
s_vpi_value*vp)
|
||||
{
|
||||
unsigned dwid = (wid + 3) / 4;
|
||||
char *rbuf = need_result_buf(dwid+1, RBUF_VAL);
|
||||
char *rbuf = (char *) need_result_buf(dwid+1, RBUF_VAL);
|
||||
long end = base + (signed)wid;
|
||||
long ssize = (signed)sig->value_size();
|
||||
unsigned val = 0;
|
||||
|
|
@ -280,7 +280,7 @@ static void format_vpiDecStrVal(vvp_signal_value*sig, int base, unsigned wid,
|
|||
int signed_flag, s_vpi_value*vp)
|
||||
{
|
||||
unsigned hwid = (sig->value_size()+2) / 3 + 1;
|
||||
char *rbuf = need_result_buf(hwid, RBUF_VAL);
|
||||
char *rbuf = (char *) need_result_buf(hwid, RBUF_VAL);
|
||||
long ssize = (signed)sig->value_size();
|
||||
long end = base + (signed)wid;
|
||||
|
||||
|
|
@ -366,7 +366,7 @@ static void format_vpiStringVal(vvp_signal_value*sig, int base, unsigned wid,
|
|||
/* The result will use a character for each 8 bits of the
|
||||
vector. Add one extra character for the highest bits that
|
||||
don't form an 8 bit group. */
|
||||
char *rbuf = need_result_buf(wid/8 + ((wid&7)!=0) + 1, RBUF_VAL);
|
||||
char *rbuf = (char *) need_result_buf(wid/8 + ((wid&7)!=0) + 1, RBUF_VAL);
|
||||
char *cp = rbuf;
|
||||
|
||||
char tmp = 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2012-2014 Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -63,7 +63,7 @@ void __vpiStringVar::vpi_get_value(p_vpi_value val)
|
|||
string str = fun->get_string();
|
||||
|
||||
if (val->format == vpiStringVal || val->format == vpiObjTypeVal) {
|
||||
char*rbuf = need_result_buf(str.size()+1, RBUF_VAL);
|
||||
char*rbuf = (char *) need_result_buf(str.size()+1, RBUF_VAL);
|
||||
strcpy(rbuf, str.c_str());
|
||||
val->format = vpiStringVal;
|
||||
val->value.str = rbuf;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2012 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -106,7 +106,7 @@ static void timevar_get_value(vpiHandle ref, s_vpi_value*vp, bool is_int_func,
|
|||
vvp_time64_t x, simtime = schedule_simtime();
|
||||
int units = rfp->scope? rfp->scope->time_units : vpi_time_precision;
|
||||
|
||||
char*rbuf = need_result_buf(128, RBUF_VAL);
|
||||
char*rbuf = (char *) need_result_buf(128, RBUF_VAL);
|
||||
|
||||
/* Calculate the divisor needed to scale the simulation time
|
||||
(in time_precision units) to time units of the scope. */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2001 Stephan Boettcher <stephan@nevis.columbia.edu>
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
|
|
@ -124,7 +124,7 @@ static char* vthr_vec_get_str(int code, vpiHandle ref)
|
|||
static void vthr_vec_DecStrVal(struct __vpiVThrVec*rfp, s_vpi_value*vp)
|
||||
{
|
||||
int nbuf = (rfp->wid+2)/3 + 1;
|
||||
char *rbuf = need_result_buf(nbuf, RBUF_VAL);
|
||||
char *rbuf = (char *) need_result_buf(nbuf, RBUF_VAL);
|
||||
|
||||
vvp_vector4_t tmp (rfp->wid);
|
||||
for (unsigned idx = 0 ; idx < rfp->wid ; idx += 1)
|
||||
|
|
@ -139,7 +139,7 @@ static void vthr_vec_DecStrVal(struct __vpiVThrVec*rfp, s_vpi_value*vp)
|
|||
static void vthr_vec_StringVal(struct __vpiVThrVec*rfp, s_vpi_value*vp)
|
||||
{
|
||||
char tmp = 0;
|
||||
char *rbuf = need_result_buf((rfp->wid / 8) + 1, RBUF_VAL);
|
||||
char *rbuf = (char *) need_result_buf((rfp->wid / 8) + 1, RBUF_VAL);
|
||||
char *cp = rbuf;
|
||||
|
||||
for(int bitnr=rfp->wid-1; bitnr>=0; bitnr--){
|
||||
|
|
@ -186,7 +186,7 @@ static void vthr_vec_get_value(vpiHandle ref, s_vpi_value*vp)
|
|||
switch (vp->format) {
|
||||
|
||||
case vpiBinStrVal:
|
||||
rbuf = need_result_buf(wid+1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(wid+1, RBUF_VAL);
|
||||
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
||||
rbuf[wid-idx-1] = vvp_bit4_to_ascii(get_bit(rfp, idx));
|
||||
}
|
||||
|
|
@ -197,7 +197,7 @@ static void vthr_vec_get_value(vpiHandle ref, s_vpi_value*vp)
|
|||
case vpiHexStrVal: {
|
||||
unsigned hval, hwid;
|
||||
hwid = (wid + 3) / 4;
|
||||
rbuf = need_result_buf(hwid+1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(hwid+1, RBUF_VAL);
|
||||
rbuf[hwid] = 0;
|
||||
hval = 0;
|
||||
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
||||
|
|
@ -237,7 +237,7 @@ static void vthr_vec_get_value(vpiHandle ref, s_vpi_value*vp)
|
|||
case vpiOctStrVal: {
|
||||
unsigned hval, hwid;
|
||||
hwid = (wid + 2) / 3;
|
||||
rbuf = need_result_buf(hwid+1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(hwid+1, RBUF_VAL);
|
||||
rbuf[hwid] = 0;
|
||||
hval = 0;
|
||||
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
||||
|
|
@ -521,7 +521,7 @@ static int vthr_word_get(int code, vpiHandle ref)
|
|||
static void vthr_real_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||
{
|
||||
struct __vpiVThrWord*obj = dynamic_cast<__vpiVThrWord*>(ref);
|
||||
char *rbuf = need_result_buf(66, RBUF_VAL);
|
||||
char *rbuf = (char *) need_result_buf(66, RBUF_VAL);
|
||||
|
||||
double val = 0.0;
|
||||
|
||||
|
|
@ -689,7 +689,7 @@ void __vpiVThrStrStack::vpi_get_value(p_vpi_value vp)
|
|||
case vpiObjTypeVal:
|
||||
vp->format = vpiStringVal;
|
||||
case vpiStringVal:
|
||||
rbuf = need_result_buf(val.size()+1, RBUF_VAL);
|
||||
rbuf = (char *) need_result_buf(val.size()+1, RBUF_VAL);
|
||||
strcpy(rbuf, val.c_str());
|
||||
vp->value.str = rbuf;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue