Skip to content

Commit

Permalink
fix static code analysis (#710)
Browse files Browse the repository at this point in the history
Signed-off-by: szc321 <[email protected]>
  • Loading branch information
szc321 authored Jun 7, 2023
1 parent 8c233f5 commit 76227f0
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 20 deletions.
3 changes: 2 additions & 1 deletion prebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(self, sourcedir, targetdir):
if self.from_cd_action and self.from_poetry else ["cmake"]
self.cmake_args = []
self.build_args = []
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
self.parallel = multiprocessing.cpu_count()

def _check_poetry(self):
exec_code = self.env.get('_', "").rsplit('/')[-1]
Expand Down Expand Up @@ -67,7 +69,6 @@ def _set_cmake_args(self):
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
self.parallel = multiprocessing.cpu_count()
self.build_args += [f"-j{self.parallel}"]

def run(self):
Expand Down
2 changes: 1 addition & 1 deletion src/lava/magma/runtime/_c_message_infrastructure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ Also users could choose to use poetry to enbale the whole environment.
$ export CMAKE_ARGS="..."
$ poetry install
$ source .venv/bin/activate
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ MetaDataPtr CycloneDDSSubscriber::Recv(bool keep) {
topic_name_.c_str());
dds::sub::LoanedSamples<ddsmetadata::msg::DDSMetaData> samples;
if (keep) {
while ((samples = selector_->read()).length() <= 0) {
while ((samples = selector_->read()).length() <= 0) { // Flawfinder: ignore
helper::Sleep();
}
} else {
while ((samples = selector_->take()).length() <= 0) {
while ((samples = selector_->take()).length() <= 0) { // Flawfinder: ignore
helper::Sleep();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ MetaDataPtr FastDDSSubscriber::Recv(bool keep) {
if (keep) {
LAVA_DEBUG(LOG_DDS, "Keep the data recieved\n");
while (ReturnCode_t::RETCODE_OK !=
reader_->read(mdata_seq, infos, 1)) {
reader_->read(mdata_seq, infos, 1)) { // Flawfinder: ignore
helper::Sleep();
}
} else {
Expand Down Expand Up @@ -307,7 +307,8 @@ bool FastDDSSubscriber::Probe() {
MDataSeq mdata_seq;
SampleInfoSeq infos;
bool res = false;
if (ReturnCode_t::RETCODE_OK == reader_->read(mdata_seq, infos, 1)) {
if (ReturnCode_t::RETCODE_OK ==
reader_->read(mdata_seq, infos, 1)) { // Flawfinder: ignore
reader_->return_loan(mdata_seq, infos);
res = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ void RwSharedMemory::Close() {
void SharedMemManager::DeleteAllSharedMemory() {
if (alloc_pid_ != getpid())
return;
int result = 0;
LAVA_DEBUG(LOG_SMMP, "Delete: Number of shm to free: %zd.\n",
shm_fd_strs_.size());
LAVA_DEBUG(LOG_SMMP, "Delete: Number of sem to free: %zd.\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ void MessageInfrastructureLog::Clear() {
// multithread unsafe
void MessageInfrastructureLog::WriteDown() {
if (log_queue_.empty()) return;
int i = 0;
signed int pid = GetPid();
std::stringstream log_file_name;
log_file_name << log_path_ << "/" << DEBUG_LOG_MODULE << "_pid_" << pid \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ The Send port will connect to the recv port in initialization and write to the s

Therefore,
1. The send port can only be initialized after corresponding Recv port called `start()`
2. In each round, the send port is used one-off. One needs to create a new `TempChannel()` and get the send port from it each time. (The send port will be initialized when accessing the .dst_port property at the first time)
2. In each round, the send port is used one-off. One needs to create a new `TempChannel()` and get the send port from it each time. (The send port will be initialized when accessing the .dst_port property at the first time)
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def nparray_to_metadata(np_array):
metadata.elsize = np_array.itemsize
metadata.total_size = np_array.size
shape_list = list(np_array.shape)
for i in range(5 - len(shape_list)):
for _ in range(5 - len(shape_list)):
shape_list.append(0)
metadata.dims = shape_list
strides_list = list(np_array.strides)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_ddschannel():

recv_port = dds_channel.dst_port
recv_port.start()
for i in range(100):
for _ in range(100):
res = recv_port.recv()
print(res)
recv_port.join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_ddschannel():

send_port = dds_channel.src_port
send_port.start()
for i in range(100):
for _ in range(100):
send_port.send(prepare_data())
time.sleep(0.1)
send_port.join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_ddschannel():

recv_port = dds_channel.dst_port
recv_port.start()
for i in range(100):
for _ in range(100):
res = recv_port.recv()
print(res)
recv_port.join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_ddschannel():

send_port = dds_channel.src_port
send_port.start()
for i in range(100):
for _ in range(100):
send_port.send(prepare_data())
time.sleep(0.1)
send_port.join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def run(self):
tb = traceback.format_exc()
self._cconn.send((e, tb))

def join(self):
def join(self, timeout=None):
if not self._is_done:
super().join()
super().close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def build(self):
def ddschannel_protocol(transfer_type, backend, topic_name):
from lava.magma.runtime.message_infrastructure import (
GetDDSChannel,
DDSBackendType,
ChannelQueueSize)
from lava.magma.runtime.message_infrastructure \
.multiprocessing import MultiProcessing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def send_proc(*args, **kwargs):
if not isinstance(port, SendPort):
raise AssertionError()
port.start()
for i in range(QUEUE_SIZE + 1):
for _ in range(QUEUE_SIZE + 1):
data = generate_data()
port.send(data)

Expand All @@ -38,7 +38,7 @@ def recv_proc(*args, **kwargs):
if not isinstance(port, RecvPort):
raise AssertionError()
time.sleep(1)
for i in range(QUEUE_SIZE + 1):
for _ in range(QUEUE_SIZE + 1):
port.recv()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def actor_stop(name):
def recv_proc(*args, **kwargs):
port = kwargs.pop("port")
port.start()
for i in range(loop_number):
for _ in range(loop_number):
path, recv_port = getTempRecvPort()
recv_port.start()
port.send(np.array([path]))
Expand All @@ -46,7 +46,7 @@ def recv_proc(*args, **kwargs):
def send_proc(*args, **kwargs):
port = kwargs.pop("port")
port.start()
for i in range(loop_number):
for _ in range(loop_number):
path = port.recv()
send_port = getTempSendPort(str(path[0]))
send_port.start()
Expand Down

0 comments on commit 76227f0

Please sign in to comment.