Skip to content

Commit 961a8ad

Browse files
committed
Break change for values, strings, arrays.
1 parent ebedaef commit 961a8ad

File tree

20 files changed

+544
-517
lines changed

20 files changed

+544
-517
lines changed

examples/hello/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99
// See the Mulan PSL v2 for more details.
1010

1111
use phper::{
12-
arrays::Array,
12+
arrays::ZArray,
1313
classes::{DynamicClass, Visibility},
1414
functions::Argument,
1515
ini::{Ini, Policy},
1616
modules::{Module, ModuleContext},
1717
objects::Object,
1818
php_get_module,
19-
values::Val,
19+
values::ZVal,
2020
};
2121

2222
fn module_init(_args: ModuleContext) -> bool {
2323
true
2424
}
2525

26-
fn say_hello(arguments: &mut [Val]) -> phper::Result<String> {
26+
fn say_hello(arguments: &mut [ZVal]) -> phper::Result<String> {
2727
let name = arguments[0].as_string_value()?;
2828
Ok(format!("Hello, {}!\n", name))
2929
}
3030

31-
fn throw_exception(_: &mut [Val]) -> phper::Result<()> {
31+
fn throw_exception(_: &mut [ZVal]) -> phper::Result<()> {
3232
Err(phper::Error::other("I am sorry"))
3333
}
3434

@@ -57,13 +57,13 @@ pub fn get_module() -> Module {
5757
module.add_function("hello_throw_exception", throw_exception, vec![]);
5858
module.add_function(
5959
"hello_get_all_ini",
60-
|_: &mut [Val]| {
61-
let mut arr = Array::new();
60+
|_: &mut [ZVal]| {
61+
let mut arr = ZArray::new();
6262

63-
let hello_enable = Val::new(Ini::get::<bool>("hello.enable"));
63+
let hello_enable = ZVal::new(Ini::get::<bool>("hello.enable"));
6464
arr.insert("hello.enable", hello_enable);
6565

66-
let hello_description = Val::new(Ini::get::<String>("hello.description"));
66+
let hello_description = ZVal::new(Ini::get::<String>("hello.description"));
6767
arr.insert("hello.description", hello_description);
6868

6969
arr
@@ -77,7 +77,7 @@ pub fn get_module() -> Module {
7777
foo_class.add_method(
7878
"getFoo",
7979
Visibility::Public,
80-
|this: &mut Object<()>, _: &mut [Val]| {
80+
|this: &mut Object<()>, _: &mut [ZVal]| {
8181
let prop = this.get_property("foo");
8282
Ok::<_, phper::Error>(prop.as_string_value()?)
8383
},
@@ -86,8 +86,8 @@ pub fn get_module() -> Module {
8686
foo_class.add_method(
8787
"setFoo",
8888
Visibility::Public,
89-
|this: &mut Object<()>, arguments: &mut [Val]| -> phper::Result<()> {
90-
this.set_property("foo", Val::new(arguments[0].as_string_value()?));
89+
|this: &mut Object<()>, arguments: &mut [ZVal]| -> phper::Result<()> {
90+
this.set_property("foo", ZVal::new(arguments[0].as_string_value()?));
9191
Ok(())
9292
},
9393
vec![Argument::by_val("foo")],

examples/http-server/src/server.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use phper::{
2121
classes::{ClassEntry, DynamicClass, StatelessClassEntry, Visibility},
2222
errors::Error::Throw,
2323
functions::Argument,
24-
values::Val,
24+
values::ZVal,
2525
};
2626
use std::{convert::Infallible, mem::replace, net::SocketAddr, sync::Arc};
2727
use tokio::{runtime::Handle, sync::Mutex};
@@ -41,8 +41,8 @@ pub fn make_server_class() -> DynamicClass<Option<Builder<AddrIncoming>>> {
4141
|this, arguments| {
4242
let host = arguments[0].to_string()?;
4343
let port = arguments[1].as_long()?;
44-
this.set_property("host", Val::new(&*host));
45-
this.set_property("port", Val::new(port));
44+
this.set_property("host", ZVal::new(&*host));
45+
this.set_property("port", ZVal::new(port));
4646
let addr = format!("{}:{}", host, port).parse::<SocketAddr>()?;
4747
let builder = Server::bind(&addr);
4848
*this.as_mut_state() = Some(builder);
@@ -55,7 +55,7 @@ pub fn make_server_class() -> DynamicClass<Option<Builder<AddrIncoming>>> {
5555
"onRequest",
5656
Visibility::Public,
5757
|this, arguments| {
58-
this.set_property("onRequestHandle", Val::new(arguments[0].duplicate()?));
58+
this.set_property("onRequestHandle", ZVal::new(arguments[0].duplicate()?));
5959
Ok::<_, phper::Error>(())
6060
},
6161
vec![Argument::by_val("handle")],
@@ -84,14 +84,14 @@ pub fn make_server_class() -> DynamicClass<Option<Builder<AddrIncoming>>> {
8484
let request =
8585
StatelessClassEntry::from_globals(HTTP_REQUEST_CLASS_NAME)?
8686
.new_object([])?;
87-
let request = Val::new(request);
87+
let request = ZVal::new(request);
8888

8989
let mut response = ClassEntry::<Response<Body>>::from_globals(
9090
HTTP_RESPONSE_CLASS_NAME,
9191
)?
9292
.new_object([])?;
9393
let response_val = response.duplicate();
94-
let response_val = Val::new(response_val);
94+
let response_val = ZVal::new(response_val);
9595

9696
match handle.call([request, response_val]) {
9797
Err(Throw(ex)) => {

examples/logging/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use phper::{
1212
deprecated, echo, error, functions::Argument, modules::Module, notice, php_get_module,
13-
values::Val, warning,
13+
values::ZVal, warning,
1414
};
1515

1616
#[php_get_module]
@@ -23,7 +23,7 @@ pub fn get_module() -> Module {
2323

2424
module.add_function(
2525
"log_say",
26-
|params: &mut [Val]| -> phper::Result<()> {
26+
|params: &mut [ZVal]| -> phper::Result<()> {
2727
let message = params[0].as_string_value()?;
2828
echo!("Hello, {}!", message);
2929
Ok(())
@@ -33,7 +33,7 @@ pub fn get_module() -> Module {
3333

3434
module.add_function(
3535
"log_notice",
36-
|params: &mut [Val]| -> phper::Result<()> {
36+
|params: &mut [ZVal]| -> phper::Result<()> {
3737
let message = params[0].as_string_value()?;
3838
notice!("Something happened: {}", message);
3939
Ok(())
@@ -43,7 +43,7 @@ pub fn get_module() -> Module {
4343

4444
module.add_function(
4545
"log_warning",
46-
|params: &mut [Val]| -> phper::Result<()> {
46+
|params: &mut [ZVal]| -> phper::Result<()> {
4747
let message = params[0].as_string_value()?;
4848
warning!("Something warning: {}", message);
4949
Ok(())
@@ -53,7 +53,7 @@ pub fn get_module() -> Module {
5353

5454
module.add_function(
5555
"log_error",
56-
|params: &mut [Val]| -> phper::Result<()> {
56+
|params: &mut [ZVal]| -> phper::Result<()> {
5757
let message = params[0].as_string_value()?;
5858
error!("Something gone failed: {}", message);
5959
Ok(())
@@ -63,7 +63,7 @@ pub fn get_module() -> Module {
6363

6464
module.add_function(
6565
"log_deprecated",
66-
|params: &mut [Val]| -> phper::Result<()> {
66+
|params: &mut [ZVal]| -> phper::Result<()> {
6767
let message = params[0].as_string_value()?;
6868
deprecated!("Something deprecated: {}", message);
6969
Ok(())

phper-sys/php_wrapper.c

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,24 @@ zend_class_entry phper_init_class_entry_ex(const char *class_name, size_t class_
3131
return class_container;
3232
}
3333

34-
void phper_zval_string(zval *return_value, const char *s) {
35-
ZVAL_STRING(return_value, s);
36-
}
37-
3834
zend_uchar phper_zval_get_type(const zval* pz) {
3935
return zval_get_type(pz);
4036
}
4137

42-
void phper_zval_arr(zval *return_value, zend_array *arr) {
43-
ZVAL_ARR(return_value, arr);
38+
void phper_zval_arr(zval *val, zend_array *arr) {
39+
ZVAL_ARR(val, arr);
4440
}
4541

46-
void phper_zval_new_arr(zval *return_value) {
42+
void phper_zval_new_arr(zval *val) {
4743
#if PHP_VERSION_ID < 80100
48-
ZVAL_NEW_ARR(return_value);
44+
ZVAL_NEW_ARR(val);
4945
#else
50-
array_init(return_value);
46+
array_init(val);
5147
#endif
5248
}
5349

54-
void phper_zval_stringl(zval *return_value, const char *s, size_t len) {
55-
ZVAL_STRINGL(return_value, s, len);
50+
void phper_zval_stringl(zval *val, const char *s, size_t len) {
51+
ZVAL_STRINGL(val, s, len);
5652
}
5753

5854
char *phper_z_strval_p(const zval *v) {
@@ -63,20 +59,16 @@ zval *phper_get_this(zend_execute_data *execute_data) {
6359
return getThis();
6460
}
6561

66-
void phper_zval_zval(zval *return_value, zval *zv, int copy, int dtor) {
67-
ZVAL_ZVAL(return_value, zv, copy, dtor);
68-
}
69-
70-
void phper_zval_dup(zval *return_value, const zval *zv) {
71-
ZVAL_DUP(return_value, zv);
62+
void phper_zval_zval(zval *val, zval *zv, int copy, int dtor) {
63+
ZVAL_ZVAL(val, zv, copy, dtor);
7264
}
7365

74-
void phper_zval_copy(zval *return_value, zval *zv) {
75-
ZVAL_COPY(return_value, zv);
66+
void phper_zval_copy(zval *val, const zval *zv) {
67+
ZVAL_COPY(val, zv);
7668
}
7769

78-
void phper_zval_copy_value(zval *return_value, zval *zv) {
79-
ZVAL_COPY_VALUE(return_value, zv);
70+
void phper_zval_copy_value(zval *val, const zval *zv) {
71+
ZVAL_COPY_VALUE(val, zv);
8072
}
8173

8274
zend_string *phper_zval_get_string(zval *op) {
@@ -159,8 +151,8 @@ zend_string *phper_get_function_or_method_name(const zend_function *func) {
159151
#endif
160152
}
161153

162-
void phper_zval_ptr_dtor(zval *pDest) {
163-
ZVAL_PTR_DTOR(pDest);
154+
void phper_zval_ptr_dtor(zval *zv) {
155+
ZVAL_PTR_DTOR(zv);
164156
}
165157

166158
size_t phper_zend_object_properties_size(zend_class_entry *ce) {
@@ -229,3 +221,47 @@ void *phper_emalloc(size_t size) {
229221
void phper_efree(void *ptr) {
230222
return efree(ptr);
231223
}
224+
225+
void phper_separate_string(zval *zv) {
226+
SEPARATE_STRING(zv);
227+
}
228+
229+
void phper_separate_array(zval *zv) {
230+
SEPARATE_ARRAY(zv);
231+
}
232+
233+
void phper_zval_null(zval *zv) {
234+
ZVAL_NULL(zv);
235+
}
236+
237+
void phper_zval_true(zval *zv) {
238+
ZVAL_TRUE(zv);
239+
}
240+
241+
void phper_zval_false(zval *zv) {
242+
ZVAL_FALSE(zv);
243+
}
244+
245+
void phper_zval_long(zval *zv, zend_long l) {
246+
ZVAL_LONG(zv, l);
247+
}
248+
249+
void phper_zval_double(zval *zv, double d) {
250+
ZVAL_DOUBLE(zv, d);
251+
}
252+
253+
int phper_z_type_info_p(zval *zv) {
254+
return Z_TYPE_INFO_P(zv);
255+
}
256+
257+
int phper_z_type_p(zval *zv) {
258+
return Z_TYPE_P(zv);
259+
}
260+
261+
void phper_zval_str(zval *zv, zend_string *s) {
262+
ZVAL_STR(zv, s);
263+
}
264+
265+
zend_array *phper_zend_new_array(uint32_t nSize) {
266+
return zend_new_array(nSize);
267+
}

phper/build.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
99
// See the Mulan PSL v2 for more details.
1010

11+
use phper_sys::*;
12+
1113
fn main() {
1214
phper_build::register_configures();
15+
assert_eq!(
16+
PHP_DEBUG, 0,
17+
"PHPER not support DEBUG mode now (php built with `--enable-debug`)."
18+
);
19+
assert_eq!(
20+
USING_ZTS, 0,
21+
"PHPER not support ZTS mode now (php built with `--enable-maintainer-zts` or \
22+
`--enable-zts`)."
23+
);
1324
}

0 commit comments

Comments
 (0)