Skip to content

Commit 6ad5417

Browse files
committed
Fix some compatibility problems.
1 parent e261b66 commit 6ad5417

File tree

8 files changed

+50
-22
lines changed

8 files changed

+50
-22
lines changed

examples/hello/tests/php/test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616

1717
assert_eq(hello_get_all_ini(), [
18-
"hello.enable" => true,
18+
"hello.enable" => false,
1919
"hello.description" => "hello world.",
2020
]);
2121

@@ -27,6 +27,6 @@
2727

2828
function assert_eq($left, $right) {
2929
if ($left !== $right) {
30-
throw new Exception("left != right,\n left: {$left},\n right: {$right};");
30+
throw new Exception(sprintf("left != right,\n left: %s,\n right: %s", var_export($left, true), var_export($right, true)));
3131
}
3232
}

phper-sys/php_wrapper.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,8 @@ zend_string *phper_zend_string_alloc(size_t len, int persistent) {
6464

6565
void phper_zend_string_release(zend_string *s) {
6666
return zend_string_release(s);
67-
}
67+
}
68+
69+
void phper_zend_hash_str_update(HashTable *ht, const char *key, size_t len, zval *pData) {
70+
zend_hash_str_update(ht, key, len, pData);
71+
}

phper-sys/php_wrapper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ zend_string *phper_zend_string_init(const char *str, size_t len, int persistent)
2727
zend_string *phper_zend_string_alloc(size_t len, int persistent);
2828
void phper_zend_string_release(zend_string *s);
2929

30+
void phper_zend_hash_str_update(HashTable *ht, const char *key, size_t len, zval *pData);
31+
32+
33+
3034
#endif //PHPER_PHP_WRAPPER_H

phper-test/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,15 @@ fn php_context() -> &'static Context {
8888
"echo php_ini_scanned_files();",
8989
]);
9090

91-
ini_content.push_str(&read_to_string(ini_file).unwrap());
92-
for file in ini_files.split(',') {
93-
let file = file.trim();
94-
if !file.is_empty() {
95-
ini_content.push_str(&read_to_string(file).unwrap());
91+
if !ini_file.is_empty() {
92+
ini_content.push_str(&read_to_string(ini_file).unwrap());
93+
}
94+
if !ini_files.is_empty() {
95+
for file in ini_files.split(',') {
96+
let file = file.trim();
97+
if !file.is_empty() {
98+
ini_content.push_str(&read_to_string(file).unwrap());
99+
}
96100
}
97101
}
98102

phper/src/arrays.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Array {
1212
pub fn new() -> Self {
1313
let mut inner = Box::new(unsafe { zeroed::<zend_array>() });
1414
unsafe {
15-
_zend_hash_init(&mut *inner, 0, None, 1);
15+
_zend_hash_init(&mut *inner, 0, None, true.into());
1616
}
1717
Self { inner }
1818
}
@@ -24,7 +24,7 @@ impl Array {
2424
pub fn insert(&mut self, key: impl AsRef<str>, value: &mut Val) {
2525
let key = key.as_ref();
2626
unsafe {
27-
zend_hash_str_update(
27+
phper_zend_hash_str_update(
2828
self.inner.deref_mut(),
2929
key.as_ptr().cast(),
3030
key.len(),

phper/src/classes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl This {
181181
self.val as *mut _,
182182
name.as_ptr().cast(),
183183
name.len(),
184-
0,
184+
false.into(),
185185
null_mut(),
186186
);
187187
Val::from_mut(prop)

phper/src/functions.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ pub(crate) unsafe extern "C" fn invoke(
170170
execute_data.common_required_num_args(),
171171
execute_data.num_args()
172172
);
173-
php_error_docref(null(), E_WARNING as i32, s.as_ptr().cast());
173+
php_error_docref1(
174+
null(),
175+
"\0".as_ptr().cast(),
176+
E_WARNING as i32,
177+
s.as_ptr().cast(),
178+
);
174179
return_value.set(());
175180
return;
176181
}
@@ -190,10 +195,21 @@ pub(crate) unsafe extern "C" fn invoke(
190195

191196
pub const fn create_zend_arg_info(
192197
name: *const c_char,
193-
pass_by_ref: bool,
198+
_pass_by_ref: bool,
194199
) -> zend_internal_arg_info {
200+
#[cfg(phper_php_version = "8.0")]
201+
{
202+
zend_internal_arg_info {
203+
name,
204+
type_: zend_type {
205+
ptr: null_mut(),
206+
type_mask: 0,
207+
},
208+
default_value: null_mut(),
209+
}
210+
}
211+
195212
#[cfg(any(
196-
phper_php_version = "8.0",
197213
phper_php_version = "7.4",
198214
phper_php_version = "7.3",
199215
phper_php_version = "7.2"
@@ -202,7 +218,7 @@ pub const fn create_zend_arg_info(
202218
zend_internal_arg_info {
203219
name,
204220
type_: 0 as crate::sys::zend_type,
205-
pass_by_reference: pass_by_ref as zend_uchar,
221+
pass_by_reference: _pass_by_ref as zend_uchar,
206222
is_variadic: 0,
207223
}
208224
}
@@ -214,7 +230,7 @@ pub const fn create_zend_arg_info(
214230
class_name: std::ptr::null(),
215231
type_hint: 0,
216232
allow_null: 0,
217-
pass_by_reference: pass_by_ref as zend_uchar,
233+
pass_by_reference: _pass_by_ref as zend_uchar,
218234
is_variadic: 0,
219235
}
220236
}

phper/src/values.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{arrays::Array, errors::Throwable, sys::*};
2-
use std::{mem::zeroed, os::raw::c_int, slice::from_raw_parts, str, sync::atomic::Ordering};
2+
use std::{mem::zeroed, slice::from_raw_parts, str, sync::atomic::Ordering};
33

44
#[repr(transparent)]
55
pub struct ExecuteData {
@@ -26,8 +26,8 @@ impl ExecuteData {
2626
}
2727

2828
#[inline]
29-
pub unsafe fn common_required_num_args(&self) -> u32 {
30-
(*self.inner.func).common.required_num_args
29+
pub unsafe fn common_required_num_args(&self) -> u16 {
30+
(*self.inner.func).common.required_num_args as u16
3131
}
3232

3333
#[inline]
@@ -36,8 +36,8 @@ impl ExecuteData {
3636
}
3737

3838
#[inline]
39-
pub unsafe fn num_args(&self) -> u32 {
40-
self.inner.This.u2.num_args
39+
pub unsafe fn num_args(&self) -> u16 {
40+
self.inner.This.u2.num_args as u16
4141
}
4242

4343
#[inline]
@@ -48,7 +48,7 @@ impl ExecuteData {
4848
pub unsafe fn get_parameters_array(&mut self) -> Vec<Val> {
4949
let num_args = self.num_args();
5050
let mut arguments = vec![zeroed::<zval>(); num_args as usize];
51-
_zend_get_parameters_array_ex(num_args as c_int, arguments.as_mut_ptr());
51+
_zend_get_parameters_array_ex(num_args.into(), arguments.as_mut_ptr());
5252
arguments.into_iter().map(Val::from_inner).collect()
5353
}
5454
}

0 commit comments

Comments
 (0)