Skip to content

Commit

Permalink
iox-#70 Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Sep 17, 2023
1 parent f7573d8 commit 2559c28
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 93 deletions.
16 changes: 8 additions & 8 deletions iceoryx-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ fn make_and_install(source_dir: &str, build_dir: &str, install_dir: &str) -> std
let cmake_install_prefix = format!("-DCMAKE_INSTALL_PREFIX={}", install_dir);
let cmake_prefix_path = format!("-DCMAKE_PREFIX_PATH={}", install_dir);

for iceoryx_component in &["iceoryx_hoofs", "iceoryx_posh"] {
for iceoryx_component in ["iceoryx_hoofs", "iceoryx_posh"] {
let component_source_dir = format!("{}/{}", source_dir, iceoryx_component);
let component_build_dir = format!("{}/{}", build_dir, iceoryx_component);

if !Command::new("mkdir")
.args(&["-p", &component_build_dir])
.args(["-p", &component_build_dir])
.status()?
.success()
{
Expand All @@ -30,7 +30,7 @@ fn make_and_install(source_dir: &str, build_dir: &str, install_dir: &str) -> std

if !Command::new("cmake")
.current_dir(&component_build_dir)
.args(&[
.args([
"-DCMAKE_BUILD_TYPE=Release",
"-DBUILD_SHARED_LIBS=OFF",
"-DROUDI_ENVIRONMENT=ON",
Expand All @@ -49,7 +49,7 @@ fn make_and_install(source_dir: &str, build_dir: &str, install_dir: &str) -> std

if !Command::new("cmake")
.current_dir(&component_build_dir)
.args(&["--build", ".", "--target", "install"])
.args(["--build", ".", "--target", "install"])
.status()?
.success()
{
Expand All @@ -65,7 +65,7 @@ fn make_and_install(source_dir: &str, build_dir: &str, install_dir: &str) -> std

fn extract_archive(archive_dir: &str, source_dir: &str, version: &str) -> std::io::Result<()> {
if !Command::new("mkdir")
.args(&["-p", &source_dir])
.args(["-p", source_dir])
.status()?
.success()
{
Expand All @@ -76,11 +76,11 @@ fn extract_archive(archive_dir: &str, source_dir: &str, version: &str) -> std::i
}

if !Command::new("tar")
.args(&[
.args([
"-xf",
&format!("{}/{}.tar.gz", archive_dir, version),
"-C",
&source_dir,
source_dir,
"--strip-components=1",
])
.status()?
Expand Down Expand Up @@ -149,7 +149,7 @@ fn main() -> std::io::Result<()> {

#[cfg(not(any(target_os = "windows", target_os = "macos")))]
println!("cargo:rustc-link-lib=stdc++");
#[cfg(any(target_os = "macos"))]
#[cfg(target_os = "macos")]
println!("cargo:rustc-link-lib=c++");

Ok(())
Expand Down
10 changes: 6 additions & 4 deletions iceoryx-sys/src/chunk_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ impl ChunkHeader {

pub fn get_user_payload_size(&self) -> usize {
unsafe {
cpp!([self as "ChunkHeader*"] -> u32 as "uint32_t" {
return self->userPayloadSize();
let this_ptr = self as *const Self;
cpp!([this_ptr as "ChunkHeader*"] -> u32 as "uint32_t" {
return this_ptr->userPayloadSize();
}) as usize
}
}

pub fn get_user_payload_alignment(&self) -> usize {
unsafe {
cpp!([self as "ChunkHeader*"] -> u32 as "uint32_t" {
return self->userPayloadAlignment();
let this_ptr = self as *const Self;
cpp!([this_ptr as "ChunkHeader*"] -> u32 as "uint32_t" {
return this_ptr->userPayloadAlignment();
}) as usize
}
}
Expand Down
22 changes: 12 additions & 10 deletions iceoryx-sys/src/introspection/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ impl MemorySegment {

pub fn writer_group(&self) -> Option<String> {
unsafe {
let group_name = cpp!([self as "const MemPoolIntrospectionInfo*"] -> *const c_char as "const char*" {
return self->m_writerGroupName.c_str();
let this_ptr = self as *const Self;
let group_name = cpp!([this_ptr as "const MemPoolIntrospectionInfo*"] -> *const c_char as "const char*" {
return this_ptr->m_writerGroupName.c_str();
});
CStr::from_ptr(group_name)
.to_str()
Expand All @@ -59,8 +60,9 @@ impl MemorySegment {

pub fn reader_group(&self) -> Option<String> {
unsafe {
let group_name = cpp!([self as "const MemPoolIntrospectionInfo*"] -> *const c_char as "const char*" {
return self->m_readerGroupName.c_str();
let this_ptr = self as *const Self;
let group_name = cpp!([this_ptr as "const MemPoolIntrospectionInfo*"] -> *const c_char as "const char*" {
return this_ptr->m_readerGroupName.c_str();
});
CStr::from_ptr(group_name)
.to_str()
Expand All @@ -70,7 +72,7 @@ impl MemorySegment {

pub fn mempools(&self) -> MemPoolInfoContainer {
MemPoolInfoContainer {
memory_segment: &*self,
memory_segment: self,
mempool_index: 0,
}
}
Expand All @@ -80,7 +82,7 @@ impl<'a> Iterator for MemPoolInfoContainer<'a> {
type Item = &'a MemPoolInfo;

fn next(&mut self) -> Option<Self::Item> {
let memory_segment = self.memory_segment;
let memory_segment = self.memory_segment as *const MemorySegment;
let mempool_index = self.mempool_index;
unsafe {
let mempool_info = cpp!([memory_segment as "const MemPoolIntrospectionInfo*", mempool_index as "size_t"] -> *const MemPoolInfo as "const MemPoolInfo*" {
Expand All @@ -100,7 +102,7 @@ impl<'a> Iterator for MemPoolInfoContainer<'a> {
}

fn size_hint(&self) -> (usize, Option<usize>) {
let memory_segment = self.memory_segment;
let memory_segment = self.memory_segment as *const MemorySegment;
unsafe {
let size = cpp!([memory_segment as "const MemPoolIntrospectionInfo*"] -> usize as "size_t" {
return memory_segment->m_mempoolInfo.size();
Expand All @@ -124,7 +126,7 @@ pub struct MemPoolIntrospectionTopic {
impl MemPoolIntrospectionTopic {
pub fn memory_segments(&self) -> MemorySegmentContainer {
MemorySegmentContainer {
memory_segments: &*self,
memory_segments: self,
segment_index: 0,
}
}
Expand All @@ -134,7 +136,7 @@ impl<'a> Iterator for MemorySegmentContainer<'a> {
type Item = &'a MemorySegment;

fn next(&mut self) -> Option<Self::Item> {
let memory_segments = self.memory_segments;
let memory_segments = self.memory_segments as *const MemPoolIntrospectionTopic;
let segment_index = self.segment_index;
unsafe {
let segment = cpp!([memory_segments as "const MemPoolIntrospectionInfoContainer*", segment_index as "size_t"] -> *const MemorySegment as "const MemPoolIntrospectionInfo*" {
Expand All @@ -154,7 +156,7 @@ impl<'a> Iterator for MemorySegmentContainer<'a> {
}

fn size_hint(&self) -> (usize, Option<usize>) {
let memory_segments = self.memory_segments;
let memory_segments = self.memory_segments as *const MemPoolIntrospectionTopic;
unsafe {
let size = cpp!([memory_segments as "const MemPoolIntrospectionInfoContainer*"] -> usize as "size_t" {
return memory_segments->size();
Expand Down
42 changes: 26 additions & 16 deletions iceoryx-sys/src/introspection/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct PublisherPortData {

fn process_name<Port>(port: &Port) -> Option<String> {
unsafe {
let port = port as *const Port;
let name = cpp!([port as "const PortData*"] -> *const c_char as "const char*" {
return port->m_name.c_str();
});
Expand All @@ -49,6 +50,7 @@ fn process_name<Port>(port: &Port) -> Option<String> {

fn service_id<Port>(port: &Port) -> Option<String> {
unsafe {
let port = port as *const Port;
let name = cpp!([port as "const PortData*"] -> *const c_char as "const char*" {
return port->m_caproServiceID.c_str();
});
Expand All @@ -60,6 +62,7 @@ fn service_id<Port>(port: &Port) -> Option<String> {

fn instance_id<Port>(port: &Port) -> Option<String> {
unsafe {
let port = port as *const Port;
let name = cpp!([port as "const PortData*"] -> *const c_char as "const char*" {
return port->m_caproInstanceID.c_str();
});
Expand All @@ -71,6 +74,7 @@ fn instance_id<Port>(port: &Port) -> Option<String> {

fn event_id<Port>(port: &Port) -> Option<String> {
unsafe {
let port = port as *const Port;
let name = cpp!([port as "const PortData*"] -> *const c_char as "const char*" {
return port->m_caproEventMethodID.c_str();
});
Expand All @@ -82,6 +86,7 @@ fn event_id<Port>(port: &Port) -> Option<String> {

fn node_name<Port>(port: &Port) -> Option<String> {
unsafe {
let port = port as *const Port;
let name = cpp!([port as "const PortData*"] -> *const c_char as "const char*" {
return port->m_node.c_str();
});
Expand Down Expand Up @@ -134,8 +139,9 @@ impl PublisherPortData {

pub fn internal_publisher_port_id(&self) -> u64 {
unsafe {
cpp!([self as "const PublisherPortData*"] -> u64 as "uint64_t" {
return self->m_publisherPortID;
let this_ptr = self as *const Self;
cpp!([this_ptr as "const PublisherPortData*"] -> u64 as "uint64_t" {
return this_ptr->m_publisherPortID;
})
}
}
Expand All @@ -161,41 +167,44 @@ pub struct PortIntrospectionTopic {
impl PortIntrospectionTopic {
pub fn subscriber_ports(&self) -> SubscriberPortIntrospectionContainer {
SubscriberPortIntrospectionContainer {
parent: &*self,
parent: self,
index: 0,
}
}

pub fn publisher_ports(&self) -> PublisherPortIntrospectionContainer {
PublisherPortIntrospectionContainer {
parent: &*self,
parent: self,
index: 0,
}
}

pub fn subscriber_port_count(&self) -> usize {
unsafe {
cpp!([self as "const PortIntrospectionFieldTopic*"] -> usize as "size_t" {
return self->m_subscriberList.size();
let this_ptr = self as *const Self;
cpp!([this_ptr as "const PortIntrospectionFieldTopic*"] -> usize as "size_t" {
return this_ptr->m_subscriberList.size();
})
}
}

pub fn publisher_port_count(&self) -> usize {
unsafe {
cpp!([self as "const PortIntrospectionFieldTopic*"] -> usize as "size_t" {
return self->m_publisherList.size();
let this_ptr = self as *const Self;
cpp!([this_ptr as "const PortIntrospectionFieldTopic*"] -> usize as "size_t" {
return this_ptr->m_publisherList.size();
})
}
}

pub fn get_subscriber_port(&self, index: usize) -> Option<&SubscriberPortData> {
unsafe {
let port = cpp!([self as "const PortIntrospectionFieldTopic*", index as "size_t"] -> *const SubscriberPortData as "const SubscriberPortData*" {
if (index >= self->m_subscriberList.size()) {
let this_ptr = self as *const Self;
let port = cpp!([this_ptr as "const PortIntrospectionFieldTopic*", index as "size_t"] -> *const SubscriberPortData as "const SubscriberPortData*" {
if (index >= this_ptr->m_subscriberList.size()) {
return nullptr;
}
return &self->m_subscriberList[index];
return &this_ptr->m_subscriberList[index];
});

if !port.is_null() {
Expand All @@ -208,11 +217,12 @@ impl PortIntrospectionTopic {

pub fn get_publisher_port(&self, index: usize) -> Option<&PublisherPortData> {
unsafe {
let port = cpp!([self as "const PortIntrospectionFieldTopic*", index as "size_t"] -> *const PublisherPortData as "const PublisherPortData*" {
if (index >= self->m_publisherList.size()) {
let this_ptr = self as *const Self;
let port = cpp!([this_ptr as "const PortIntrospectionFieldTopic*", index as "size_t"] -> *const PublisherPortData as "const PublisherPortData*" {
if (index >= this_ptr->m_publisherList.size()) {
return nullptr;
}
return &self->m_publisherList[index];
return &this_ptr->m_publisherList[index];
});

if !port.is_null() {
Expand All @@ -236,7 +246,7 @@ impl<'a> Iterator for SubscriberPortIntrospectionContainer<'a> {
}

fn size_hint(&self) -> (usize, Option<usize>) {
let topic = self.parent;
let topic = self.parent as *const PortIntrospectionTopic;
unsafe {
let size = cpp!([topic as "const PortIntrospectionFieldTopic*"] -> usize as "size_t" {
return topic->m_subscriberList.size();
Expand All @@ -259,7 +269,7 @@ impl<'a> Iterator for PublisherPortIntrospectionContainer<'a> {
}

fn size_hint(&self) -> (usize, Option<usize>) {
let topic = self.parent;
let topic = self.parent as *const PortIntrospectionTopic;
unsafe {
let size = cpp!([topic as "const PortIntrospectionFieldTopic*"] -> usize as "size_t" {
return topic->m_publisherList.size();
Expand Down
26 changes: 15 additions & 11 deletions iceoryx-sys/src/introspection/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ impl ProcessIntrospectionData {

pub fn name(&self) -> Option<String> {
unsafe {
let name = cpp!([self as "const ProcessIntrospectionData*"] -> *const c_char as "const char*" {
return self->m_name.c_str();
let this_ptr = self as *const Self;
let name = cpp!([this_ptr as "const ProcessIntrospectionData*"] -> *const c_char as "const char*" {
return this_ptr->m_name.c_str();
});
CStr::from_ptr(name)
.to_str()
Expand All @@ -40,8 +41,9 @@ impl ProcessIntrospectionData {

pub fn node_count(&self) -> usize {
unsafe {
cpp!([self as "const ProcessIntrospectionData*"] -> usize as "size_t" {
return self->m_nodes.size();
let this_ptr = self as *const Self;
cpp!([this_ptr as "const ProcessIntrospectionData*"] -> usize as "size_t" {
return this_ptr->m_nodes.size();
})
}
}
Expand All @@ -62,26 +64,28 @@ pub struct ProcessIntrospectionTopic {
impl ProcessIntrospectionTopic {
pub fn processes(&self) -> ProcessIntrospectionContainer {
ProcessIntrospectionContainer {
parent: &*self,
parent: self,
index: 0,
}
}

pub fn process_count(&self) -> usize {
unsafe {
cpp!([self as "const ProcessIntrospectionFieldTopic*"] -> usize as "size_t" {
return self->m_processList.size();
let this_ptr = self as *const Self;
cpp!([this_ptr as "const ProcessIntrospectionFieldTopic*"] -> usize as "size_t" {
return this_ptr->m_processList.size();
})
}
}

pub fn get_process(&self, index: usize) -> Option<&ProcessIntrospectionData> {
unsafe {
let process = cpp!([self as "const ProcessIntrospectionFieldTopic*", index as "size_t"] -> *const ProcessIntrospectionData as "const ProcessIntrospectionData*" {
if (index >= self->m_processList.size()) {
let this_ptr = self as *const Self;
let process = cpp!([this_ptr as "const ProcessIntrospectionFieldTopic*", index as "size_t"] -> *const ProcessIntrospectionData as "const ProcessIntrospectionData*" {
if (index >= this_ptr->m_processList.size()) {
return nullptr;
}
return &self->m_processList[index];
return &this_ptr->m_processList[index];
});

if !process.is_null() {
Expand All @@ -105,7 +109,7 @@ impl<'a> Iterator for ProcessIntrospectionContainer<'a> {
}

fn size_hint(&self) -> (usize, Option<usize>) {
let topic = self.parent;
let topic = self.parent as *const ProcessIntrospectionTopic;
unsafe {
let size = cpp!([topic as "const ProcessIntrospectionFieldTopic*"] -> usize as "size_t" {
return topic->m_processList.size();
Expand Down
Loading

0 comments on commit 2559c28

Please sign in to comment.