Skip to content

Commit 1b71d5a

Browse files
committed
chore(clippy): warning: implicit borrow as raw pointer
1 parent 1aef03b commit 1b71d5a

File tree

12 files changed

+56
-53
lines changed

12 files changed

+56
-53
lines changed

src/builders/class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl ClassBuilder {
303303

304304
let class = unsafe {
305305
zend_register_internal_class_ex(
306-
&mut self.ce,
306+
&raw mut self.ce,
307307
match self.extends {
308308
Some((ptr, _)) => ptr::from_ref(ptr()).cast_mut(),
309309
None => std::ptr::null_mut(),

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![allow(non_upper_case_globals)]
44
#![allow(non_camel_case_types)]
55
#![allow(non_snake_case)]
6+
#![warn(clippy::pedantic)]
67
#![cfg_attr(docs, feature(doc_cfg))]
78
#![cfg_attr(windows, feature(abi_vectorcall))]
89

src/types/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl ZendHashTable {
378378
V: IntoZval,
379379
{
380380
let mut val = val.into_zval(false)?;
381-
unsafe { zend_hash_str_update(self, CString::new(key)?.as_ptr(), key.len(), &mut val) };
381+
unsafe { zend_hash_str_update(self, CString::new(key)?.as_ptr(), key.len(), &raw mut val) };
382382
val.release();
383383
Ok(())
384384
}
@@ -416,7 +416,7 @@ impl ZendHashTable {
416416
V: IntoZval,
417417
{
418418
let mut val = val.into_zval(false)?;
419-
unsafe { zend_hash_index_update(self, key, &mut val) };
419+
unsafe { zend_hash_index_update(self, key, &raw mut val) };
420420
val.release();
421421
Ok(())
422422
}
@@ -453,7 +453,7 @@ impl ZendHashTable {
453453
V: IntoZval,
454454
{
455455
let mut val = val.into_zval(false)?;
456-
unsafe { zend_hash_next_index_insert(self, &mut val) };
456+
unsafe { zend_hash_next_index_insert(self, &raw mut val) };
457457
val.release();
458458

459459
Ok(())

src/types/callable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ impl<'a> ZendCallable<'a> {
131131
let result = unsafe {
132132
#[allow(clippy::used_underscore_items)]
133133
_call_user_function_impl(
134-
std::ptr::null_mut(),
134+
ptr::null_mut(),
135135
ptr::from_ref(self.0.as_ref()).cast_mut(),
136-
&mut retval,
136+
&raw mut retval,
137137
len.try_into()?,
138138
packed.as_ptr().cast_mut(),
139-
std::ptr::null_mut(),
139+
ptr::null_mut(),
140140
)
141141
};
142142

src/types/class_object.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ impl<T: RegisteredClass> ZendClassObject<T> {
115115
.as_mut()
116116
.expect("Failed to allocate for new Zend object");
117117

118-
zend_object_std_init(&mut obj.std, ce);
119-
object_properties_init(&mut obj.std, ce);
118+
zend_object_std_init(&raw mut obj.std, ce);
119+
object_properties_init(&raw mut obj.std, ce);
120120

121121
// SAFETY: `obj` is non-null and well aligned as it is a reference.
122122
// As the data in `obj.obj` is uninitialized, we don't want to drop
123123
// the data, but directly override it.
124-
ptr::write(&mut obj.obj, val);
124+
ptr::write(&raw mut obj.obj, val);
125125

126126
obj.std.handlers = meta.handlers();
127127
ZBox::from_raw(obj)
@@ -239,7 +239,7 @@ unsafe impl<T: RegisteredClass> ZBoxable for ZendClassObject<T> {
239239
// SAFETY: All constructors guarantee that `self` contains a valid pointer.
240240
// Further, all constructors guarantee that the `std` field of
241241
// `ZendClassObject` will be initialized.
242-
unsafe { ext_php_rs_zend_object_release(&mut self.std) }
242+
unsafe { ext_php_rs_zend_object_release(&raw mut self.std) }
243243
}
244244
}
245245

@@ -276,7 +276,7 @@ impl<T: RegisteredClass + Clone> Clone for ZBox<ZendClassObject<T>> {
276276
// therefore we can dereference both safely.
277277
unsafe {
278278
let mut new = ZendClassObject::new((***self).clone());
279-
zend_objects_clone_members(&mut new.std, (&raw const self.std).cast_mut());
279+
zend_objects_clone_members(&raw mut new.std, (&raw const self.std).cast_mut());
280280
new
281281
}
282282
}

src/types/iterator.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl ZendIterator {
3939
/// `\Iterator` interface. see <https://www.php.net/manual/en/iterator.valid.php>
4040
pub fn valid(&mut self) -> bool {
4141
if let Some(valid) = unsafe { (*self.funcs).valid } {
42-
let valid = unsafe { valid(&mut *self) == ZEND_RESULT_CODE_SUCCESS };
42+
let valid = unsafe { valid(&raw mut *self) == ZEND_RESULT_CODE_SUCCESS };
4343

4444
if ExecutorGlobals::has_exception() {
4545
return false;
@@ -63,7 +63,7 @@ impl ZendIterator {
6363
pub fn rewind(&mut self) -> bool {
6464
if let Some(rewind) = unsafe { (*self.funcs).rewind } {
6565
unsafe {
66-
rewind(&mut *self);
66+
rewind(&raw mut *self);
6767
}
6868
}
6969

@@ -82,7 +82,7 @@ impl ZendIterator {
8282
pub fn move_forward(&mut self) -> bool {
8383
if let Some(move_forward) = unsafe { (*self.funcs).move_forward } {
8484
unsafe {
85-
move_forward(&mut *self);
85+
move_forward(&raw mut *self);
8686
}
8787
}
8888

@@ -97,7 +97,7 @@ impl ZendIterator {
9797
/// , [`None`] otherwise.
9898
pub fn get_current_data<'a>(&mut self) -> Option<&'a Zval> {
9999
let get_current_data = unsafe { (*self.funcs).get_current_data }?;
100-
let value = unsafe { &*get_current_data(&mut *self) };
100+
let value = unsafe { &*get_current_data(&raw mut *self) };
101101

102102
if ExecutorGlobals::has_exception() {
103103
return None;
@@ -117,7 +117,7 @@ impl ZendIterator {
117117
let mut key = Zval::new();
118118

119119
unsafe {
120-
get_current_key(&mut *self, &mut key);
120+
get_current_key(&raw mut *self, &raw mut key);
121121
}
122122

123123
if ExecutorGlobals::has_exception() {

src/types/object.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl ZendObject {
179179

180180
unsafe {
181181
let res = zend_hash_str_find_ptr_lc(
182-
&(*self.ce).function_table,
182+
&raw const (*self.ce).function_table,
183183
name.as_ptr().cast::<c_char>(),
184184
name.len(),
185185
)
@@ -193,7 +193,7 @@ impl ZendObject {
193193
res,
194194
ptr::from_ref(self).cast_mut(),
195195
self.ce,
196-
&mut retval,
196+
&raw mut retval,
197197
len.try_into()?,
198198
packed.as_ptr().cast_mut(),
199199
std::ptr::null_mut(),
@@ -230,10 +230,10 @@ impl ZendObject {
230230
let zv = unsafe {
231231
self.handlers()?.read_property.ok_or(Error::InvalidScope)?(
232232
self.mut_ptr(),
233-
&mut *name,
233+
&raw mut *name,
234234
1,
235-
std::ptr::null_mut(),
236-
&mut rv,
235+
ptr::null_mut(),
236+
&raw mut rv,
237237
)
238238
.as_ref()
239239
}
@@ -260,9 +260,9 @@ impl ZendObject {
260260
unsafe {
261261
self.handlers()?.write_property.ok_or(Error::InvalidScope)?(
262262
self,
263-
&mut *name,
264-
&mut value,
265-
std::ptr::null_mut(),
263+
&raw mut *name,
264+
&raw mut value,
265+
ptr::null_mut(),
266266
)
267267
.as_ref()
268268
}
@@ -289,7 +289,7 @@ impl ZendObject {
289289
Ok(unsafe {
290290
self.handlers()?.has_property.ok_or(Error::InvalidScope)?(
291291
self.mut_ptr(),
292-
&mut *name,
292+
&raw mut *name,
293293
query as _,
294294
std::ptr::null_mut(),
295295
)
@@ -440,10 +440,10 @@ impl FromZendObject<'_> for String {
440440
(*obj.ce).__tostring,
441441
ptr::from_ref(obj).cast_mut(),
442442
obj.ce,
443-
&mut ret,
443+
&raw mut ret,
444444
0,
445-
std::ptr::null_mut(),
446-
std::ptr::null_mut(),
445+
ptr::null_mut(),
446+
ptr::null_mut(),
447447
);
448448
}
449449

src/zend/class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl ClassEntry {
2727
ExecutorGlobals::get().class_table()?;
2828
let mut name = ZendStr::new(name, false);
2929

30-
unsafe { crate::ffi::zend_lookup_class_ex(&mut *name, std::ptr::null_mut(), 0).as_ref() }
30+
unsafe { crate::ffi::zend_lookup_class_ex(&raw mut *name, std::ptr::null_mut(), 0).as_ref() }
3131
}
3232

3333
/// Creates a new [`ZendObject`], returned inside an [`ZBox<ZendObject>`]

src/zend/function.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Function {
8383
None => None,
8484
Some(ce) => unsafe {
8585
let res = zend_hash_str_find_ptr_lc(
86-
&ce.function_table,
86+
&raw const ce.function_table,
8787
name.as_ptr().cast::<c_char>(),
8888
name.len(),
8989
)
@@ -139,12 +139,12 @@ impl Function {
139139
unsafe {
140140
zend_call_known_function(
141141
ptr::from_ref(self).cast_mut(),
142-
std::ptr::null_mut(),
143-
std::ptr::null_mut(),
144-
&mut retval,
142+
ptr::null_mut(),
143+
ptr::null_mut(),
144+
&raw mut retval,
145145
len.try_into()?,
146146
packed.as_ptr().cast_mut(),
147-
std::ptr::null_mut(),
147+
ptr::null_mut(),
148148
);
149149
};
150150

src/zend/globals.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl ExecutorGlobals {
5555

5656
cfg_if::cfg_if! {
5757
if #[cfg(php_zts)] {
58-
let guard = lock::GLOBALS_LOCK.with(|l| l.read_arc());
58+
let guard = lock::GLOBALS_LOCK.with(RwLock::read_arc);
5959
} else {
6060
let guard = lock::GLOBALS_LOCK.read_arc();
6161
}
@@ -83,7 +83,7 @@ impl ExecutorGlobals {
8383

8484
cfg_if::cfg_if! {
8585
if #[cfg(php_zts)] {
86-
let guard = lock::GLOBALS_LOCK.with(|l| l.write_arc());
86+
let guard = lock::GLOBALS_LOCK.with(RwLock::write_arc);
8787
} else {
8888
let guard = lock::GLOBALS_LOCK.write_arc();
8989
}
@@ -201,7 +201,7 @@ impl ExecutorGlobals {
201201
cfg_if::cfg_if! {
202202
if #[cfg(php82)] {
203203
unsafe {
204-
zend_atomic_bool_store(&mut self.vm_interrupt, true);
204+
zend_atomic_bool_store(&raw mut self.vm_interrupt, true);
205205
}
206206
} else {
207207
self.vm_interrupt = true;
@@ -214,7 +214,7 @@ impl ExecutorGlobals {
214214
cfg_if::cfg_if! {
215215
if #[cfg(php82)] {
216216
unsafe {
217-
zend_atomic_bool_store(&mut self.vm_interrupt, false);
217+
zend_atomic_bool_store(&raw mut self.vm_interrupt, false);
218218
}
219219
} else {
220220
self.vm_interrupt = true;
@@ -245,7 +245,7 @@ impl CompilerGlobals {
245245

246246
cfg_if::cfg_if! {
247247
if #[cfg(php_zts)] {
248-
let guard = lock::GLOBALS_LOCK.with(|l| l.read_arc());
248+
let guard = lock::GLOBALS_LOCK.with(RwLock::read_arc);
249249
} else {
250250
let guard = lock::GLOBALS_LOCK.read_arc();
251251
}
@@ -273,7 +273,7 @@ impl CompilerGlobals {
273273

274274
cfg_if::cfg_if! {
275275
if #[cfg(php_zts)] {
276-
let guard = lock::GLOBALS_LOCK.with(|l| l.write_arc());
276+
let guard = lock::GLOBALS_LOCK.with(RwLock::write_arc);
277277
} else {
278278
let guard = lock::GLOBALS_LOCK.write_arc();
279279
}
@@ -346,7 +346,7 @@ impl ProcessGlobals {
346346

347347
cfg_if::cfg_if! {
348348
if #[cfg(php_zts)] {
349-
let guard = lock::PROCESS_GLOBALS_LOCK.with(|l| l.read_arc());
349+
let guard = lock::PROCESS_GLOBALS_LOCK.with(RwLock::read_arc);
350350
} else {
351351
let guard = lock::PROCESS_GLOBALS_LOCK.read_arc();
352352
}
@@ -369,7 +369,7 @@ impl ProcessGlobals {
369369

370370
cfg_if::cfg_if! {
371371
if #[cfg(php_zts)] {
372-
let guard = lock::PROCESS_GLOBALS_LOCK.with(|l| l.write_arc());
372+
let guard = lock::PROCESS_GLOBALS_LOCK.with(RwLock::write_arc);
373373
} else {
374374
let guard = lock::PROCESS_GLOBALS_LOCK.write_arc();
375375
}
@@ -506,14 +506,15 @@ impl SapiGlobals {
506506
/// Attempting to retrieve the globals while already holding the global
507507
/// guard will lead to a deadlock. Dropping the globals guard will release
508508
/// the lock.
509+
#[must_use]
509510
pub fn get() -> GlobalReadGuard<Self> {
510511
// SAFETY: PHP executor globals are statically declared therefore should never
511512
// return an invalid pointer.
512513
let globals = unsafe { &*ext_php_rs_sapi_globals() };
513514

514515
cfg_if::cfg_if! {
515516
if #[cfg(php_zts)] {
516-
let guard = lock::SAPI_GLOBALS_LOCK.with(|l| l.read_arc());
517+
let guard = lock::SAPI_GLOBALS_LOCK.with(RwLock::read_arc);
517518
} else {
518519
let guard = lock::SAPI_GLOBALS_LOCK.read_arc();
519520
}
@@ -536,7 +537,7 @@ impl SapiGlobals {
536537

537538
cfg_if::cfg_if! {
538539
if #[cfg(php_zts)] {
539-
let guard = lock::SAPI_GLOBALS_LOCK.with(|l| l.write_arc());
540+
let guard = lock::SAPI_GLOBALS_LOCK.with(RwLock::write_arc);
540541
} else {
541542
let guard = lock::SAPI_GLOBALS_LOCK.write_arc();
542543
}
@@ -777,7 +778,7 @@ impl FileGlobals {
777778

778779
cfg_if::cfg_if! {
779780
if #[cfg(php_zts)] {
780-
let guard = lock::FILE_GLOBALS_LOCK.with(|l| l.read_arc());
781+
let guard = lock::FILE_GLOBALS_LOCK.with(RwLock::read_arc);
781782
} else {
782783
let guard = lock::FILE_GLOBALS_LOCK.read_arc();
783784
}
@@ -793,14 +794,15 @@ impl FileGlobals {
793794
/// Attempting to retrieve the globals while already holding the global
794795
/// guard will lead to a deadlock. Dropping the globals guard will release
795796
/// the lock.
797+
#[must_use]
796798
pub fn get_mut() -> GlobalWriteGuard<Self> {
797799
// SAFETY: PHP executor globals are statically declared therefore should never
798800
// return an invalid pointer.
799801
let globals = unsafe { &mut *ext_php_rs_file_globals() };
800802

801803
cfg_if::cfg_if! {
802804
if #[cfg(php_zts)] {
803-
let guard = lock::FILE_GLOBALS_LOCK.with(|l| l.write_arc());
805+
let guard = lock::FILE_GLOBALS_LOCK.with(RwLock::write_arc);
804806
} else {
805807
let guard = lock::FILE_GLOBALS_LOCK.write_arc();
806808
}

0 commit comments

Comments
 (0)