Skip to content

Commit 2bb08c2

Browse files
committed
Remove as_[mut_]ptr from impl_array_newtype macros
For interfacing with the FFI layer we implement `ffi::CPtr`, there is not need to provide methods `as_ptr` and `as_mut_ptr` as well.
1 parent 3e28070 commit 2bb08c2

File tree

3 files changed

+12
-50
lines changed

3 files changed

+12
-50
lines changed

secp256k1-sys/src/macros.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@ macro_rules! impl_array_newtype {
2020
impl Copy for $thing {}
2121

2222
impl $thing {
23-
/// Converts the object to a raw pointer for FFI interfacing.
24-
#[inline]
25-
pub fn as_ptr(&self) -> *const $ty {
26-
let &$thing(ref dat) = self;
27-
dat.as_ptr()
28-
}
29-
30-
/// Converts the object to a mutable raw pointer for FFI interfacing.
31-
#[inline]
32-
pub fn as_mut_ptr(&mut self) -> *mut $ty {
33-
let &mut $thing(ref mut dat) = self;
34-
dat.as_mut_ptr()
35-
}
36-
3723
/// Returns the length of the object as an array.
3824
#[inline]
3925
pub fn len(&self) -> usize { $len }
@@ -101,20 +87,15 @@ macro_rules! impl_array_newtype {
10187

10288
impl $crate::CPtr for $thing {
10389
type Target = $ty;
90+
10491
fn as_c_ptr(&self) -> *const Self::Target {
105-
if self.is_empty() {
106-
core::ptr::null()
107-
} else {
108-
self.as_ptr()
109-
}
92+
let &$thing(ref dat) = self;
93+
dat.as_ptr()
11094
}
11195

11296
fn as_mut_c_ptr(&mut self) -> *mut Self::Target {
113-
if self.is_empty() {
114-
core::ptr::null::<Self::Target>() as *mut _
115-
} else {
116-
self.as_mut_ptr()
117-
}
97+
let &mut $thing(ref mut dat) = self;
98+
dat.as_mut_ptr()
11899
}
119100
}
120101
}

src/ecdh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn shared_secret_point(point: &PublicKey, scalar: &SecretKey) -> [u8; 64] {
146146
ffi::secp256k1_context_no_precomp,
147147
xy.as_mut_ptr(),
148148
point.as_c_ptr(),
149-
scalar.as_ptr(),
149+
scalar.as_c_ptr(),
150150
Some(c_callback),
151151
ptr::null_mut(),
152152
)

src/macros.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@ macro_rules! impl_array_newtype {
2020
impl Copy for $thing {}
2121

2222
impl $thing {
23-
/// Converts the object to a raw pointer for FFI interfacing.
24-
#[inline]
25-
pub fn as_ptr(&self) -> *const $ty {
26-
let &$thing(ref dat) = self;
27-
dat.as_ptr()
28-
}
29-
30-
/// Converts the object to a mutable raw pointer for FFI interfacing.
31-
#[inline]
32-
pub fn as_mut_ptr(&mut self) -> *mut $ty {
33-
let &mut $thing(ref mut dat) = self;
34-
dat.as_mut_ptr()
35-
}
36-
3723
/// Returns the length of the object as an array.
3824
#[inline]
3925
pub fn len(&self) -> usize { $len }
@@ -99,22 +85,17 @@ macro_rules! impl_array_newtype {
9985
fn index(&self, index: I) -> &Self::Output { &self.0[index] }
10086
}
10187

102-
impl $crate::CPtr for $thing {
88+
impl $crate::ffi::CPtr for $thing {
10389
type Target = $ty;
90+
10491
fn as_c_ptr(&self) -> *const Self::Target {
105-
if self.is_empty() {
106-
core::ptr::null()
107-
} else {
108-
self.as_ptr()
109-
}
92+
let &$thing(ref dat) = self;
93+
dat.as_ptr()
11094
}
11195

11296
fn as_mut_c_ptr(&mut self) -> *mut Self::Target {
113-
if self.is_empty() {
114-
core::ptr::null::<Self::Target>() as *mut _
115-
} else {
116-
self.as_mut_ptr()
117-
}
97+
let &mut $thing(ref mut dat) = self;
98+
dat.as_mut_ptr()
11899
}
119100
}
120101
}

0 commit comments

Comments
 (0)