Skip to content

Commit 8fb70cf

Browse files
authored
Fix array to zval problem.
1 parent 5e3347f commit 8fb70cf

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030

3131
runs-on: ${{ matrix.os }}
3232
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v2
35+
3336
- name: Setup PHP
3437
uses: shivammathur/setup-php@v2
3538
with:
@@ -39,9 +42,6 @@ jobs:
3942
- name: PHP version
4043
run: php-config --version && php-config --phpapi && php --version
4144

42-
- name: Checkout
43-
uses: actions/checkout@v2
44-
4545
- name: Install Rust Nightly
4646
uses: actions-rs/toolchain@v1
4747
with:

examples/hello/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ license = "Unlicense"
1212
crate-type = ["cdylib"]
1313

1414
[dependencies]
15-
once_cell = "1.7.2"
1615
phper = { version = "0.2", path = "../../phper" }
1716

1817
[dev-dependencies]

phper-sys/php_wrapper.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ void phper_zval_arr(zval *return_value, zend_array *arr) {
2222
ZVAL_ARR(return_value, arr);
2323
}
2424

25+
void phper_zval_new_arr(zval *return_value) {
26+
ZVAL_NEW_ARR(return_value);
27+
}
28+
2529
void phper_zval_stringl(zval *return_value, const char *s, size_t len) {
2630
ZVAL_STRINGL(return_value, s, len);
2731
}
@@ -46,6 +50,10 @@ void phper_zval_copy(zval *return_value, zval *zv) {
4650
ZVAL_COPY(return_value, zv);
4751
}
4852

53+
void phper_zval_copy_value(zval *return_value, zval *zv) {
54+
ZVAL_COPY_VALUE(return_value, zv);
55+
}
56+
4957
zend_string *phper_zval_get_string(zval *op) {
5058
return zval_get_string(op);
5159
}

phper-sys/php_wrapper.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@ typedef ZEND_INI_MH(phper_zend_ini_mh);
1010

1111
zend_string *zend_new_interned_string_(zend_string *str);
1212
zend_class_entry phper_init_class_entry_ex(const char *class_name, size_t class_name_len, const zend_function_entry *functions);
13-
void phper_zval_string(zval *return_value, const char *s);
1413
zend_uchar phper_zval_get_type(const zval* pz);
14+
15+
void phper_zval_string(zval *return_value, const char *s);
1516
void phper_zval_arr(zval *return_value, zend_array *arr);
17+
void phper_zval_new_arr(zval *return_value);
1618
void phper_zval_stringl(zval *return_value, const char *s, size_t len);
19+
1720
char *phper_z_strval_p(const zval *v);
1821
zval *phper_get_this(zend_execute_data *execute_data);
1922
void phper_zval_zval(zval *return_value, zval *zv, int copy, int dtor);
2023
void phper_zval_dup(zval *return_value, zval *zv);
2124
void phper_zval_copy(zval *return_value, zval *zv);
25+
void phper_zval_copy_value(zval *return_value, zval *zv);
26+
2227
zend_string *phper_zval_get_string(zval *op);
2328
void phper_zend_string_release(zend_string *s);
2429
zend_long phper_zval_get_long(zval *op);

phper/src/arrays.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ impl Array {
1212
pub fn new() -> Self {
1313
let mut inner = Box::new(unsafe { zeroed::<zend_array>() });
1414
unsafe {
15+
// TODO should destroy in module shutdown hook.
1516
_zend_hash_init(&mut *inner, 0, None, true.into());
1617
}
1718
Self { inner }
@@ -58,10 +59,10 @@ impl AsMut<zend_array> for Array {
5859
}
5960
}
6061

61-
impl Drop for Array {
62-
fn drop(&mut self) {
63-
unsafe {
64-
zend_hash_destroy(&mut *self.inner);
65-
}
66-
}
67-
}
62+
// impl Drop for Array {
63+
// fn drop(&mut self) {
64+
// unsafe {
65+
// zend_hash_graceful_destroy(&mut *self.inner);
66+
// }
67+
// }
68+
// }

phper/src/values.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl SetVal for String {
195195
impl SetVal for Array {
196196
fn set_val(&self, val: &mut Val) {
197197
unsafe {
198-
phper_zval_arr(val.as_mut(), self.as_ptr() as *mut _);
198+
phper_zval_arr(&mut val.inner, self.as_ptr() as *mut _);
199199
}
200200
}
201201
}
@@ -233,7 +233,7 @@ impl<T: SetVal, E: Throwable> SetVal for Result<T, E> {
233233
impl SetVal for Val {
234234
fn set_val(&self, val: &mut Val) {
235235
unsafe {
236-
phper_zval_copy(val.as_mut(), &self.inner as *const _ as *mut _);
236+
phper_zval_copy_value(val.as_mut(), &self.inner as *const _ as *mut _);
237237
}
238238
}
239239
}

0 commit comments

Comments
 (0)