Skip to content

Develop #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:

runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -39,9 +42,6 @@ jobs:
- name: PHP version
run: php-config --version && php-config --phpapi && php --version

- name: Checkout
uses: actions/checkout@v2

- name: Install Rust Nightly
uses: actions-rs/toolchain@v1
with:
Expand Down
1 change: 0 additions & 1 deletion examples/hello/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ license = "Unlicense"
crate-type = ["cdylib"]

[dependencies]
once_cell = "1.7.2"
phper = { version = "0.2", path = "../../phper" }

[dev-dependencies]
Expand Down
8 changes: 8 additions & 0 deletions phper-sys/php_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ void phper_zval_arr(zval *return_value, zend_array *arr) {
ZVAL_ARR(return_value, arr);
}

void phper_zval_new_arr(zval *return_value) {
ZVAL_NEW_ARR(return_value);
}

void phper_zval_stringl(zval *return_value, const char *s, size_t len) {
ZVAL_STRINGL(return_value, s, len);
}
Expand All @@ -46,6 +50,10 @@ void phper_zval_copy(zval *return_value, zval *zv) {
ZVAL_COPY(return_value, zv);
}

void phper_zval_copy_value(zval *return_value, zval *zv) {
ZVAL_COPY_VALUE(return_value, zv);
}

zend_string *phper_zval_get_string(zval *op) {
return zval_get_string(op);
}
Expand Down
7 changes: 6 additions & 1 deletion phper-sys/php_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ typedef ZEND_INI_MH(phper_zend_ini_mh);

zend_string *zend_new_interned_string_(zend_string *str);
zend_class_entry phper_init_class_entry_ex(const char *class_name, size_t class_name_len, const zend_function_entry *functions);
void phper_zval_string(zval *return_value, const char *s);
zend_uchar phper_zval_get_type(const zval* pz);

void phper_zval_string(zval *return_value, const char *s);
void phper_zval_arr(zval *return_value, zend_array *arr);
void phper_zval_new_arr(zval *return_value);
void phper_zval_stringl(zval *return_value, const char *s, size_t len);

char *phper_z_strval_p(const zval *v);
zval *phper_get_this(zend_execute_data *execute_data);
void phper_zval_zval(zval *return_value, zval *zv, int copy, int dtor);
void phper_zval_dup(zval *return_value, zval *zv);
void phper_zval_copy(zval *return_value, zval *zv);
void phper_zval_copy_value(zval *return_value, zval *zv);

zend_string *phper_zval_get_string(zval *op);
void phper_zend_string_release(zend_string *s);
zend_long phper_zval_get_long(zval *op);
Expand Down
15 changes: 8 additions & 7 deletions phper/src/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impl Array {
pub fn new() -> Self {
let mut inner = Box::new(unsafe { zeroed::<zend_array>() });
unsafe {
// TODO should destroy in module shutdown hook.
_zend_hash_init(&mut *inner, 0, None, true.into());
}
Self { inner }
Expand Down Expand Up @@ -58,10 +59,10 @@ impl AsMut<zend_array> for Array {
}
}

impl Drop for Array {
fn drop(&mut self) {
unsafe {
zend_hash_destroy(&mut *self.inner);
}
}
}
// impl Drop for Array {
// fn drop(&mut self) {
// unsafe {
// zend_hash_graceful_destroy(&mut *self.inner);
// }
// }
// }
4 changes: 2 additions & 2 deletions phper/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl SetVal for String {
impl SetVal for Array {
fn set_val(&self, val: &mut Val) {
unsafe {
phper_zval_arr(val.as_mut(), self.as_ptr() as *mut _);
phper_zval_arr(&mut val.inner, self.as_ptr() as *mut _);
}
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ impl<T: SetVal, E: Throwable> SetVal for Result<T, E> {
impl SetVal for Val {
fn set_val(&self, val: &mut Val) {
unsafe {
phper_zval_copy(val.as_mut(), &self.inner as *const _ as *mut _);
phper_zval_copy_value(val.as_mut(), &self.inner as *const _ as *mut _);
}
}
}
Expand Down