Skip to content

Commit

Permalink
resolving c++ linter
Browse files Browse the repository at this point in the history
Using C-style cast.  Use static_cast<XXXX>(...) instead  [readability/casting]
  • Loading branch information
ruck314 committed Jun 29, 2024
1 parent 7106799 commit 49a7451
Show file tree
Hide file tree
Showing 26 changed files with 92 additions and 92 deletions.
2 changes: 1 addition & 1 deletion include/rogue/interfaces/stream/FrameAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FrameAccessor {
public:
//! Creator
FrameAccessor(rogue::interfaces::stream::FrameIterator& iter, uint32_t size) {
data_ = (T*)iter.ptr();
data_ = reinterpret_cast<T*>(iter.ptr());
size_ = size;

if (size * sizeof(T) > iter.remBuffer())
Expand Down
2 changes: 1 addition & 1 deletion src/rogue/GeneralError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void rogue::GeneralError::setup_python() {

bp::class_<rogue::GeneralError>("GeneralError", bp::init<std::string, std::string>());

PyObject* typeObj = PyErr_NewException((char*)"rogue.GeneralError", PyExc_Exception, 0);
PyObject* typeObj = PyErr_NewException(const_cast<char*>("rogue.GeneralError"), PyExc_Exception, 0);
bp::scope().attr("GeneralError") = bp::handle<>(bp::borrowed(typeObj));

rogue::generalErrorObj = typeObj;
Expand Down
8 changes: 4 additions & 4 deletions src/rogue/hardware/MemMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ rh::MemMap::MemMap(uint64_t base, uint32_t size) : rim::Slave(4, 0xFFFFFFFF) {

if (fd_ < 0) throw(rogue::GeneralError::create("MemMap::MemMap", "Failed to open device file: %s", MAP_DEVICE));

if ((map_ = (uint8_t*)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, base)) == (void*)-1)
if ((map_ = reinterpret_cast<uint8_t*>(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, base))) == reinterpret_cast<void*>(-1))
throw(rogue::GeneralError::create("MemMap::MemMap", "Failed to map memory to user space."));

log_->debug("Created map to 0x%" PRIx64 " with size 0x%" PRIx32, base, size);
Expand All @@ -81,7 +81,7 @@ void rh::MemMap::stop() {
threadEn_ = false;
queue_.stop();
thread_->join();
munmap((void*)map_, size_);
munmap(reinterpret_cast<void*>(const_cast<uint8_t*>(map_)), size_);
::close(fd_);
}
}
Expand Down Expand Up @@ -129,8 +129,8 @@ void rh::MemMap::runThread() {
continue;
}

tPtr = (uint32_t*)tran->begin();
mPtr = (uint32_t*)(map_ + tran->address());
tPtr = reinterpret_cast<uint32_t*>(tran->begin());
mPtr = const_cast<uint32_t*>(reinterpret_cast<volatile uint32_t*>(map_ + tran->address()));

while (count != tran->size()) {
// Write or post
Expand Down
2 changes: 1 addition & 1 deletion src/rogue/hardware/axi/AxiMemMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void rha::AxiMemMap::runThread() {
uint8_t* ptr;

dataSize = sizeof(uint32_t);
ptr = (uint8_t*)(&data);
ptr = reinterpret_cast<uint8_t*>(&data);

log_->logThreadId();

Expand Down
4 changes: 2 additions & 2 deletions src/rogue/interfaces/ZmqClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ std::string rogue::interfaces::ZmqClient::sendString(std::string path, std::stri
while (1) {
zmq_msg_init(&msg);
if (zmq_recvmsg(this->zmqReq_, &msg, 0) <= 0) {
seconds += (float)timeout_ / 1000.0;
seconds += static_cast<float>(timeout_) / 1000.0;
if (waitRetry_) {
log_->error("Timeout waiting for response after %f Seconds, server may be busy! Waiting...", seconds);
zmq_msg_close(&msg);
Expand Down Expand Up @@ -249,7 +249,7 @@ bp::object rogue::interfaces::ZmqClient::send(bp::object value) {
while (1) {
zmq_msg_init(&rxMsg);
if (zmq_recvmsg(this->zmqReq_, &rxMsg, 0) <= 0) {
seconds += (float)timeout_ / 1000.0;
seconds += static_cast<float>(timeout_) / 1000.0;
if (waitRetry_) {
log_->error("Timeout waiting for response after %f Seconds, server may be busy! Waiting...",
seconds);
Expand Down
52 changes: 26 additions & 26 deletions src/rogue/interfaces/memory/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ rim::Block::Block(uint64_t offset, uint32_t size) {
verifyBase_ = 0; // Verify Range
verifySize_ = 0; // Verify Range

blockData_ = (uint8_t*)malloc(size_);
blockData_ = reinterpret_cast<uint8_t*>(malloc(size_));
memset(blockData_, 0, size_);

verifyData_ = (uint8_t*)malloc(size_);
verifyData_ = reinterpret_cast<uint8_t*>(malloc(size_));
memset(verifyData_, 0, size_);

verifyMask_ = (uint8_t*)malloc(size_);
verifyMask_ = reinterpret_cast<uint8_t*>(malloc(size_));
memset(verifyMask_, 0, size_);
}

Expand Down Expand Up @@ -625,11 +625,11 @@ void rim::Block::setBytes(const uint8_t* data, rim::Variable* var, uint32_t inde

// Change byte order, need to make a copy
if (var->byteReverse_) {
buff = (uint8_t*)malloc(var->valueBytes_);
buff = reinterpret_cast<uint8_t*>(malloc(var->valueBytes_));
memcpy(buff, data, var->valueBytes_);
reverseBytes(buff, var->valueBytes_);
} else {
buff = (uint8_t*)data;
buff = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(data));
}

// List variable
Expand Down Expand Up @@ -770,7 +770,7 @@ void rim::Block::setPyFunc(bp::object& value, rim::Variable* var, int32_t index)
"Failed to extract byte array for %s",
var->name_.c_str()));

setBytes((uint8_t*)valueBuf.buf, var, index + x);
setBytes(reinterpret_cast<uint8_t*>(valueBuf.buf), var, index + x);
PyBuffer_Release(&valueBuf);
}

Expand All @@ -784,7 +784,7 @@ void rim::Block::setPyFunc(bp::object& value, rim::Variable* var, int32_t index)
"Failed to extract byte array from pyFunc return value for %s",
var->name_.c_str()));

setBytes((uint8_t*)valueBuf.buf, var, index);
setBytes(reinterpret_cast<uint8_t*>(valueBuf.buf), var, index);
PyBuffer_Release(&valueBuf);
}
}
Expand Down Expand Up @@ -838,7 +838,7 @@ void rim::Block::setByteArrayPy(bp::object& value, rim::Variable* var, int32_t i
"Failed to extract byte array for %s",
var->name_.c_str()));

setBytes((uint8_t*)valueBuf.buf, var, index);
setBytes(reinterpret_cast<uint8_t*>(valueBuf.buf), var, index);
PyBuffer_Release(&valueBuf);
}

Expand Down Expand Up @@ -1021,14 +1021,14 @@ void rim::Block::setUInt(const uint64_t& val, rim::Variable* var, int32_t index)
var->minValue_,
var->maxValue_));

setBytes((uint8_t*)&val, var, index);
setBytes(reinterpret_cast<uint8_t*>(const_cast<uint64_t*>(&val)), var, index);
}

// Get data using unsigned int
uint64_t rim::Block::getUInt(rim::Variable* var, int32_t index) {
uint64_t tmp = 0;

getBytes((uint8_t*)&tmp, var, index);
getBytes(reinterpret_cast<uint8_t*>(&tmp), var, index);

return tmp;
}
Expand Down Expand Up @@ -1180,14 +1180,14 @@ void rim::Block::setInt(const int64_t& val, rim::Variable* var, int32_t index) {
var->maxValue_));

// This works because all bits between the msb and bit 64 are set to '1' for a negative value
setBytes((uint8_t*)&val, var, index);
setBytes(reinterpret_cast<uint8_t*>(const_cast<int64_t*>(&val)), var, index);
}

// Get data using int
int64_t rim::Block::getInt(rim::Variable* var, int32_t index) {
int64_t tmp = 0;

getBytes((uint8_t*)&tmp, var, index);
getBytes(reinterpret_cast<uint8_t*>(&tmp), var, index);

if (var->valueBits_ != 64) {
if (tmp >= (uint64_t)pow(2, var->valueBits_ - 1)) tmp -= (uint64_t)pow(2, var->valueBits_);
Expand Down Expand Up @@ -1314,14 +1314,14 @@ bp::object rim::Block::getBoolPy(rim::Variable* var, int32_t index) {
// Set data using bool
void rim::Block::setBool(const bool& value, rim::Variable* var, int32_t index) {
uint8_t val = (uint8_t)value;
setBytes((uint8_t*)&val, var, index);
setBytes(reinterpret_cast<uint8_t*>(&val), var, index);
}

// Get data using bool
bool rim::Block::getBool(rim::Variable* var, int32_t index) {
uint8_t tmp = 0;

getBytes((uint8_t*)&tmp, var, index);
getBytes(reinterpret_cast<uint8_t*>(&tmp), var, index);

return tmp ? true : false;
}
Expand Down Expand Up @@ -1380,7 +1380,7 @@ void rim::Block::setString(const std::string& value, rim::Variable* var, int32_t

memset(getBuffer, 0, var->valueBytes_);

strncpy((char*)getBuffer, value.c_str(), var->valueBytes_ - 1);
strncpy(reinterpret_cast<char*>(getBuffer), value.c_str(), var->valueBytes_ - 1);

setBytes(getBuffer, var, index);
}
Expand All @@ -1398,7 +1398,7 @@ void rim::Block::getString(rim::Variable* var, std::string& retString, int32_t i

memset(getBuffer, 0, var->valueBytes_ + 1);

getBytes((uint8_t*)getBuffer, var, index);
getBytes(reinterpret_cast<uint8_t*>(getBuffer), var, index);

retString = getBuffer;
}
Expand Down Expand Up @@ -1536,14 +1536,14 @@ void rim::Block::setFloat(const float& val, rim::Variable* var, int32_t index) {
var->minValue_,
var->maxValue_));

setBytes((uint8_t*)&val, var, index);
setBytes(reinterpret_cast<uint8_t*>(const_cast<float*>(&val)), var, index);
}

// Get data using float
float rim::Block::getFloat(rim::Variable* var, int32_t index) {
float tmp = 0;

getBytes((uint8_t*)&tmp, var, index);
getBytes(reinterpret_cast<uint8_t*>(&tmp), var, index);

return tmp;
}
Expand Down Expand Up @@ -1681,14 +1681,14 @@ void rim::Block::setDouble(const double& val, rim::Variable* var, int32_t index)
var->minValue_,
var->maxValue_));

setBytes((uint8_t*)&val, var, index);
setBytes(reinterpret_cast<uint8_t*>(const_cast<double*>(&val)), var, index);
}

// Get data using double
double rim::Block::getDouble(rim::Variable* var, int32_t index) {
double tmp = 0;

getBytes((uint8_t*)&tmp, var, index);
getBytes(reinterpret_cast<uint8_t*>(&tmp), var, index);

return tmp;
}
Expand Down Expand Up @@ -1831,20 +1831,20 @@ void rim::Block::setFixed(const double& val, rim::Variable* var, int32_t index)
// Check for positive edge case
uint64_t mask = 1 << (var->valueBits_ - 1);
if (val > 0 && ((fPoint & mask) != 0)) { fPoint -= 1; }
setBytes((uint8_t*)&fPoint, var, index);
setBytes(reinterpret_cast<uint8_t*>(&fPoint), var, index);
}

// Get data using fixed point
double rim::Block::getFixed(rim::Variable* var, int32_t index) {
int64_t fPoint = 0;
double tmp;

getBytes((uint8_t*)&fPoint, var, index);
getBytes(reinterpret_cast<uint8_t*>(&fPoint), var, index);
// Do two-complement if negative
if ((fPoint & (1 << (var->valueBits_ - 1))) != 0) { fPoint = fPoint - (1 << var->valueBits_); }

// Convert to float
tmp = (double)fPoint;
tmp = static_cast<double>(fPoint);
tmp = tmp / pow(2, var->binPoint_);
return tmp;
}
Expand Down Expand Up @@ -1880,21 +1880,21 @@ void rim::Block::rateTest() {
gettimeofday(&etime, NULL);

timersub(&etime, &stime, &dtime);
durr = dtime.tv_sec + (float)dtime.tv_usec / 1.0e6;
durr = dtime.tv_sec + static_cast<float>(dtime.tv_usec) / 1.0e6;
rate = count / durr;

printf("\nBlock c++ raw: Read %" PRIu64 " times in %f seconds. Rate = %f\n", count, durr, rate);

gettimeofday(&stime, NULL);
waitTransaction(0);
for (x = 0; x < count; ++x) {
reqTransaction(0, 4, (uint8_t*)&count, rim::Write);
reqTransaction(0, 4, reinterpret_cast<uint8_t*>(&count), rim::Write);
waitTransaction(0);
}
gettimeofday(&etime, NULL);

timersub(&etime, &stime, &dtime);
durr = dtime.tv_sec + (float)dtime.tv_usec / 1.0e6;
durr = dtime.tv_sec + static_cast<float>(dtime.tv_usec) / 1.0e6;
rate = count / durr;

printf("\nBlock c++ raw: Wrote %" PRIu64 " times in %f seconds. Rate = %f\n", count, durr, rate);
Expand Down
2 changes: 1 addition & 1 deletion src/rogue/interfaces/memory/Emulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void rim::Emulate::doTransaction(rim::TransactionPtr tran) {
addr += size4k;

if (memMap_.find(addr4k) == memMap_.end()) {
memMap_.insert(std::make_pair(addr4k, (uint8_t*)malloc(0x1000)));
memMap_.insert(std::make_pair(addr4k, reinterpret_cast<uint8_t*>(malloc(0x1000))));
totSize_ += 0x1000;
totAlloc_ ++;
log_->debug("Allocating block at 0x%x. Total Blocks %i, Total Size = %i", addr4k, totAlloc_, totSize_);
Expand Down
2 changes: 1 addition & 1 deletion src/rogue/interfaces/memory/Hub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void rim::Hub::doTransaction(rim::TransactionPtr tran) {

for (unsigned int i = 0; i < numberOfTransactions; ++i) {
rim::TransactionPtr subTran = tran->createSubTransaction();
subTran->iter_ = (uint8_t*)(tran->begin() + i * maxAccess);
subTran->iter_ = reinterpret_cast<uint8_t*>(tran->begin() + i * maxAccess);
if (tran->size() >= ((i + 1) * maxAccess)) {
subTran->size_ = maxAccess;
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/rogue/interfaces/memory/Master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void rim::Master::setTimeout(uint64_t timeout) {
uint32_t rim::Master::reqTransaction(uint64_t address, uint32_t size, void* data, uint32_t type) {
rim::TransactionPtr tran = rim::Transaction::create(sumTime_);

tran->iter_ = (uint8_t*)data;
tran->iter_ = reinterpret_cast<uint8_t*>(data);
tran->size_ = size;
tran->address_ = address;
tran->type_ = type;
Expand Down Expand Up @@ -197,7 +197,7 @@ uint32_t rim::Master::reqTransactionPy(uint64_t address,
}

tran->pyValid_ = true;
tran->iter_ = ((uint8_t*)tran->pyBuf_.buf) + offset;
tran->iter_ = reinterpret_cast<uint8_t*>(tran->pyBuf_.buf) + offset;
tran->type_ = type;
tran->address_ = address;

Expand Down Expand Up @@ -335,7 +335,7 @@ void rim::Master::copyBitsPy(boost::python::object dst,
srcBuf.len * 8));
}

copyBits((uint8_t*)dstBuf.buf, dstLsb, (uint8_t*)srcBuf.buf, srcLsb, size);
copyBits(reinterpret_cast<uint8_t*>(dstBuf.buf), dstLsb, reinterpret_cast<uint8_t*>(srcBuf.buf), srcLsb, size);

PyBuffer_Release(&srcBuf);
PyBuffer_Release(&dstBuf);
Expand Down Expand Up @@ -392,7 +392,7 @@ void rim::Master::setBitsPy(boost::python::object dst, uint32_t lsb, uint32_t si
dstBuf.len * 8));
}

setBits((uint8_t*)dstBuf.buf, lsb, size);
setBits(reinterpret_cast<uint8_t*>(dstBuf.buf), lsb, size);

PyBuffer_Release(&dstBuf);
}
Expand Down Expand Up @@ -453,7 +453,7 @@ bool rim::Master::anyBitsPy(boost::python::object dst, uint32_t lsb, uint32_t si
dstBuf.len * 8));
}

ret = anyBits((uint8_t*)dstBuf.buf, lsb, size);
ret = anyBits(reinterpret_cast<uint8_t*>(dstBuf.buf), lsb, size);

PyBuffer_Release(&dstBuf);
return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/rogue/interfaces/memory/TcpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void rim::TcpClient::runThread() {
std::memcpy(&type, zmq_msg_data(&(msg[3])), 4);

memset(result, 0, 1000);
std::strncpy(result, (char*)zmq_msg_data(&(msg[5])), zmq_msg_size(&(msg[5])));
std::strncpy(result, reinterpret_cast<char*>(zmq_msg_data(&(msg[5]))), zmq_msg_size(&(msg[5])));

// Find Transaction
if ((tran = getTransaction(id)) == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/rogue/interfaces/memory/TcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void rim::TcpServer::runThread() {
}

// Data pointer
data = (uint8_t*)zmq_msg_data(&(msg[4]));
data = reinterpret_cast<uint8_t*>(zmq_msg_data(&(msg[4])));

bridgeLog_->debug("Starting transaction id=%" PRIu32 ", addr=0x%" PRIx64 ", size=%" PRIu32
", type=%" PRIu32,
Expand Down
4 changes: 2 additions & 2 deletions src/rogue/interfaces/memory/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void rim::Transaction::setData(boost::python::object p, uint32_t offset) {
size_));
}

std::memcpy(begin() + offset, (uint8_t*)pyBuf.buf, count);
std::memcpy(begin() + offset, reinterpret_cast<uint8_t*>(pyBuf.buf), count);
PyBuffer_Release(&pyBuf);
}

Expand All @@ -341,7 +341,7 @@ void rim::Transaction::getData(boost::python::object p, uint32_t offset) {
size_));
}

std::memcpy((uint8_t*)pyBuf.buf, begin() + offset, count);
std::memcpy(reinterpret_cast<uint8_t*>(pyBuf.buf), begin() + offset, count);
PyBuffer_Release(&pyBuf);
}

Expand Down
Loading

0 comments on commit 49a7451

Please sign in to comment.