Skip to content

Commit 9cf996c

Browse files
committed
Format codes.
1 parent 4592d6b commit 9cf996c

File tree

10 files changed

+32
-30
lines changed

10 files changed

+32
-30
lines changed

examples/http-client/src/client.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ use crate::{
22
errors::HttpClientError,
33
response::{ReadiedResponse, RESPONSE_CLASS_NAME},
44
};
5-
use anyhow::Context;
5+
66
use phper::{classes::DynamicClass, functions::Argument, objects::Object};
77
use reqwest::{
88
blocking::{Client, ClientBuilder},
9-
Response,
109
};
11-
use std::{mem::MaybeUninit, time::Duration};
10+
use std::{time::Duration};
1211

1312
const HTTP_CLIENT_CLASS_NAME: &'static str = "HttpClient\\HttpClient";
1413

examples/http-client/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use phper::{
22
classes::{ClassEntry, DynamicClass, StatelessClassEntry},
3-
errors::{Error::ClassNotFound, Throwable},
3+
errors::{Throwable},
44
};
55

66
const EXCEPTION_CLASS_NAME: &'static str = "HttpClient\\HttpClientException";

examples/http-client/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::{
22
client::make_client_class, errors::make_exception_class, response::make_response_class,
33
};
4-
use anyhow::Context;
5-
use phper::{classes::DynamicClass, modules::Module, php_get_module};
4+
use phper::{modules::Module, php_get_module};
65

76
pub mod client;
87
pub mod errors;

examples/http-client/src/response.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use bytes::Bytes;
22
use indexmap::map::IndexMap;
3-
use phper::{arrays::Array, classes::DynamicClass};
4-
use reqwest::{blocking::Response, header::HeaderMap, StatusCode};
3+
use phper::{classes::DynamicClass};
4+
use reqwest::{header::HeaderMap, StatusCode};
55
use std::{
6-
collections::BTreeMap,
76
convert::Infallible,
8-
mem::{zeroed, MaybeUninit},
97
net::SocketAddr,
108
};
119

@@ -19,13 +17,13 @@ pub struct ReadiedResponse {
1917
}
2018

2119
pub fn make_response_class() -> DynamicClass<Option<ReadiedResponse>> {
22-
let mut class = DynamicClass::new_with_constructor(RESPONSE_CLASS_NAME, || unsafe {
20+
let mut class = DynamicClass::new_with_constructor(RESPONSE_CLASS_NAME, || {
2321
Ok::<Option<ReadiedResponse>, Infallible>(None)
2422
});
2523

2624
class.add_method(
2725
"body",
28-
|this, arguments| {
26+
|this, _arguments| {
2927
let readied_response = this.as_state().as_ref().unwrap();
3028
let body: &[u8] = readied_response.body.as_ref();
3129
body.to_vec()
@@ -35,7 +33,7 @@ pub fn make_response_class() -> DynamicClass<Option<ReadiedResponse>> {
3533

3634
class.add_method(
3735
"status",
38-
|this, arguments| {
36+
|this, _arguments| {
3937
let readied_response = this.as_state().as_ref().unwrap();
4038
readied_response.status.as_u16() as i64
4139
},
@@ -44,7 +42,7 @@ pub fn make_response_class() -> DynamicClass<Option<ReadiedResponse>> {
4442

4543
class.add_method(
4644
"headers",
47-
|this, arguments| {
45+
|this, _arguments| {
4846
let readied_response = this.as_state().as_ref().unwrap();
4947
let headers_map =
5048
readied_response

phper-test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn test_php_scripts_with_condition(
8989
}
9090

9191
println!(
92-
"===== command =====\n{} {}\n\n===== stdout =====\n{}\n\n===== stderr =====\n{}\n",
92+
"===== command =====\n{} {}\n===== stdout ======\n{}\n===== stderr ======\n{}",
9393
&context.php_bin,
9494
args.join(" "),
9595
stdout,

phper/src/classes.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Apis relate to [crate::sys::zend_class_entry].
22
3+
use crate::alloc::EBox;
34
use once_cell::sync::OnceCell;
45
use std::{
56
any::Any,
@@ -14,8 +15,6 @@ use std::{
1415
},
1516
};
1617

17-
use phper_alloc::EBox;
18-
1918
use crate::{
2019
errors::{ClassNotFoundError, StateTypeError, Throwable},
2120
functions::{Argument, FunctionEntity, FunctionEntry, Method},
@@ -25,7 +24,7 @@ use crate::{
2524
values::{SetVal, Val},
2625
};
2726
use dashmap::DashMap;
28-
use std::{any::TypeId, iter::Once};
27+
use std::{any::TypeId};
2928

3029
pub trait Classifiable {
3130
fn state_constructor(&self) -> Box<StateConstructor<Box<dyn Any>>>;
@@ -71,7 +70,7 @@ impl<T: Send + Sync + 'static> DynamicClass<T> {
7170
F: Fn() -> Result<T, E> + Send + Sync + 'static,
7271
E: Throwable + 'static,
7372
{
74-
let mut dyn_class = Self {
73+
let dyn_class = Self {
7574
class_name: class_name.to_string(),
7675
state_constructor: Arc::new(move || state_constructor().map_err(|e| Box::new(e) as _)),
7776
method_entities: Vec::new(),
@@ -156,7 +155,7 @@ impl<T: 'static> ClassEntry<T> {
156155
crate::Error::ClassNotFound(ClassNotFoundError::new(name.to_string()))
157156
})
158157
};
159-
Self::check_type_id(ptr);
158+
Self::check_type_id(ptr)?;
160159
r
161160
}
162161

@@ -189,7 +188,11 @@ impl<T: 'static> ClassEntry<T> {
189188

190189
pub fn create_object(&self) -> EBox<Object<T>> {
191190
unsafe {
192-
let f = self.inner.__bindgen_anon_2.create_object.unwrap();
191+
let f = self
192+
.inner
193+
.__bindgen_anon_2
194+
.create_object
195+
.unwrap_or(zend_objects_new);
193196
let object = f(self.as_ptr() as *mut _);
194197
EBox::from_raw(object.cast())
195198
}
@@ -244,7 +247,7 @@ impl ClassEntity {
244247
}
245248
None => zend_register_internal_class(&mut class_ce).cast(),
246249
};
247-
// self.entry.store(class, Ordering::SeqCst);
250+
self.entry.store(class.cast(), Ordering::SeqCst);
248251

249252
(*class).inner.__bindgen_anon_2.create_object = Some(create_object);
250253

phper/src/errors.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
};
88
use anyhow::anyhow;
99
use std::{
10-
any::TypeId, convert::Infallible, error, ffi::FromBytesWithNulError, io, str::Utf8Error,
10+
convert::Infallible, error, ffi::FromBytesWithNulError, io, str::Utf8Error,
1111
};
1212

1313
/// PHP Throwable, can cause throwing an exception when setting to [crate::values::Val].
@@ -55,6 +55,9 @@ pub enum Error {
5555
#[error(transparent)]
5656
ArgumentCount(#[from] ArgumentCountError),
5757

58+
#[error(transparent)]
59+
StateType(#[from] StateTypeError),
60+
5861
#[error(transparent)]
5962
Other(#[from] anyhow::Error),
6063
}

phper/src/objects.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use crate::{
44
alloc::{EAllocatable, EBox},
55
classes::ClassEntry,
6-
errors::ClassNotFoundError,
76
sys::*,
87
values::Val,
98
};
@@ -148,8 +147,12 @@ impl Object<()> {
148147
impl<T> EAllocatable for Object<T> {
149148
fn free(ptr: *mut Self) {
150149
unsafe {
151-
zend_objects_store_call_destructors(ptr.cast());
152-
zend_objects_store_free_object_storage(ptr.cast(), true.into());
150+
let handlers = (*ptr).inner.handlers;
151+
(*handlers).dtor_obj.unwrap()(ptr.cast());
152+
(*handlers).free_obj.unwrap()(ptr.cast());
153+
154+
// zend_objects_store_call_destructors(ptr.cast());
155+
// zend_objects_store_free_object_storage(ptr.cast(), true.into());
153156
}
154157
}
155158
}

phper/src/strings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
use std::{os::raw::c_char, slice::from_raw_parts, str, str::Utf8Error};
88

99
/// Wrapper of [crate::sys::zend_string].
10+
/// TODO Refactor to ZendString(EBox<zend_string>).
1011
#[repr(transparent)]
1112
pub struct ZendString {
1213
inner: zend_string,

phper/src/values.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,8 @@ impl SetVal for &str {
294294

295295
impl SetVal for String {
296296
fn set_val(self, val: &mut Val) {
297-
unsafe {
298297
let s: &str = &self;
299298
SetVal::set_val(s, val)
300-
}
301299
}
302300
}
303301

@@ -312,10 +310,8 @@ impl SetVal for &[u8] {
312310

313311
impl SetVal for Vec<u8> {
314312
fn set_val(self, val: &mut Val) {
315-
unsafe {
316313
let v: &[u8] = &self;
317314
SetVal::set_val(v, val)
318-
}
319315
}
320316
}
321317

0 commit comments

Comments
 (0)