Skip to content

Commit

Permalink
fix layouts AGAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
p-avital authored and JEnoch committed Sep 28, 2022
1 parent 44ee345 commit 88cf8bd
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 42 deletions.
9 changes: 0 additions & 9 deletions include/zenoh.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ extern "C" {
#define ZENOH_C_MINOR 6
#define ZENOH_C_PATCH 0

#define _Z_OWNED_REPLY_N_USIZE 18
#if defined(__x86_64__) || defined(_M_X64) || defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86)
#define _Z_OWNED_REPLY_N_U128 1
#define _Z_OWNED_REPLY_N_U64 3
#else
#define _Z_OWNED_REPLY_N_U128 4
#define _Z_OWNED_REPLY_N_U64 0
#endif

#define _z_u128 long double // used for alignment.

#include "zenoh_concrete.h"
Expand Down
10 changes: 5 additions & 5 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ typedef struct z_owned_closure_query_t {
* To check if `val` is still valid, you may use `z_X_check(&val)` (or `z_check(val)` if your compiler supports `_Generic`), which will return `true` if `val` is valid.
*/
typedef struct z_owned_reply_t {
_z_u128 _align[_Z_OWNED_REPLY_N_U128];
uint64_t _pad_u64[_Z_OWNED_REPLY_N_U64];
uintptr_t _pad_usize[_Z_OWNED_REPLY_N_USIZE];
_z_u128 _0;
struct _zc_res_s_v _1;
uint8_t _2;
} z_owned_reply_t;
/**
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
Expand Down Expand Up @@ -406,8 +406,8 @@ typedef struct z_owned_keyexpr_t {
* To check if `val` is still valid, you may use `z_X_check(&val)` or `z_check(val)` if your compiler supports `_Generic`, which will return `true` if `val` is valid.
*/
typedef struct z_owned_publisher_t {
uint64_t _align[1];
uintptr_t _padding[6];
struct _zc_stack_ke _ke;
uintptr_t _padding[3];
} z_owned_publisher_t;
/**
* Options passed to the :c:func:`z_declare_publisher` function.
Expand Down
14 changes: 14 additions & 0 deletions include/zenoh_concrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ typedef struct z_owned_session_t {
typedef struct z_query_t {
void *_0;
} z_query_t;
typedef struct _zc_stack_ke {
uint64_t _0;
uintptr_t _1[2];
uint32_t _2;
uint16_t _3;
uint8_t _4;
} _zc_stack_ke;
typedef struct _zc_res_s_v {
uint8_t __0;
_z_u128 _0;
struct _zc_stack_ke _1;
uintptr_t _2[12];
uint8_t _3;
} _zc_res_s_v;
/**
* A loaned zenoh session.
*/
Expand Down
2 changes: 2 additions & 0 deletions splitguide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ zenoh_concrete.h:
- z_owned_pull_subscriber_t!
- z_query_t!
- z_owned_queryable_t!
- _zc_stack_ke!
- _zc_res_s_v!
37 changes: 13 additions & 24 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,12 @@ use zenoh::{
use zenoh_util::core::SyncResolve;

use crate::{
z_bytes_t, z_closure_reply_call, z_encoding_t, z_keyexpr_t, z_owned_closure_reply_t,
z_sample_t, z_session_t, LOG_INVALID_SESSION,
_zc_stack_ke, z_bytes_t, z_closure_reply_call, z_encoding_t, z_keyexpr_t,
z_owned_closure_reply_t, z_sample_t, z_session_t, LOG_INVALID_SESSION,
};

type ReplyInner = Option<Reply>;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub(crate) mod _z_owned_reply_layout {
pub const _Z_OWNED_REPLY_N_U128: usize = 1;
pub const _Z_OWNED_REPLY_N_U64: usize = 3;
pub const _Z_OWNED_REPLY_N_USIZE: usize = 18;
}
#[cfg(any(
target_arch = "aarch64",
target_arch = "arm",
target_arch = "mips",
target_arch = "powerpc",
target_arch = "powerpc64"
))]
pub(crate) mod _z_owned_reply_layout {
pub const _Z_OWNED_REPLY_N_U128: usize = 4;
pub const _Z_OWNED_REPLY_N_U64: usize = 0;
pub const _Z_OWNED_REPLY_N_USIZE: usize = 18;
}
pub use _z_owned_reply_layout::*;
#[allow(non_camel_case_types)]
pub type _z_u128 = u128;
/// An owned reply to a :c:func:`z_get`.
Expand All @@ -64,9 +45,17 @@ pub type _z_u128 = u128;
/// To check if `val` is still valid, you may use `z_X_check(&val)` (or `z_check(val)` if your compiler supports `_Generic`), which will return `true` if `val` is valid.
#[repr(C)]
pub struct z_owned_reply_t {
_align: [_z_u128; _Z_OWNED_REPLY_N_U128],
_pad_u64: [u64; _Z_OWNED_REPLY_N_U64],
_pad_usize: [usize; _Z_OWNED_REPLY_N_USIZE],
_0: _z_u128,
_1: _zc_res_s_v,
_2: u8,
}
#[repr(C)]
pub struct _zc_res_s_v {
__0: u8,
_0: _z_u128,
_1: _zc_stack_ke,
_2: [usize; 12],
_3: u8,
}

impl From<ReplyInner> for z_owned_reply_t {
Expand Down
17 changes: 17 additions & 0 deletions src/keyexpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ impl z_owned_keyexpr_t {
}
}

#[repr(C)]
pub struct _zc_stack_ke {
_0: u64,
_1: [usize; 2],
_2: u32,
_3: u16,
_4: u8,
}
fn _zc_stack_ke_size_check() {
use core::mem::MaybeUninit;
unsafe {
core::mem::transmute::<MaybeUninit<KeyExpr>, MaybeUninit<_zc_stack_ke>>(
MaybeUninit::uninit(),
);
}
}

/// Constructs a :c:type:`z_keyexpr_t` departing from a string, copying the passed string.
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
Expand Down
8 changes: 4 additions & 4 deletions src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use zenoh_protocol_core::CongestionControl;
use zenoh_util::core::SyncResolve;

use crate::{
z_congestion_control_t, z_encoding_default, z_encoding_t, z_keyexpr_t, z_priority_t,
z_session_t, LOG_INVALID_SESSION,
_zc_stack_ke, z_congestion_control_t, z_encoding_default, z_encoding_t, z_keyexpr_t,
z_priority_t, z_session_t, LOG_INVALID_SESSION,
};

/// Options passed to the :c:func:`z_declare_publisher` function.
Expand Down Expand Up @@ -58,8 +58,8 @@ pub extern "C" fn z_publisher_options_default() -> z_publisher_options_t {
/// To check if `val` is still valid, you may use `z_X_check(&val)` or `z_check(val)` if your compiler supports `_Generic`, which will return `true` if `val` is valid.
#[repr(C)]
pub struct z_owned_publisher_t {
pub _align: [u64; 1],
pub _padding: [usize; 6],
pub _ke: _zc_stack_ke,
pub _padding: [usize; 3],
}
impl<'a> From<Option<Publisher<'a>>> for z_owned_publisher_t {
fn from(val: Option<Publisher>) -> Self {
Expand Down

0 comments on commit 88cf8bd

Please sign in to comment.