Skip to content

Commit 6e5d260

Browse files
committed
Occur no understand SIGSEGV.
1 parent 3b3de01 commit 6e5d260

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

examples/hello/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use phper::{
22
arrays::Array,
33
classes::{DynamicClass, Visibility},
44
functions::Argument,
5-
ini::Policy,
5+
ini::{Ini, Policy},
66
modules::{Module, ModuleArgs},
77
objects::Object,
88
php_get_module,
@@ -31,10 +31,10 @@ pub fn get_module() -> Module {
3131
);
3232

3333
// register module ini
34-
module.add_ini("hello.enable", false, Policy::All);
35-
module.add_ini("hello.num", 100, Policy::All);
36-
module.add_ini("hello.ratio", 1.5, Policy::All);
37-
module.add_ini("hello.description", "hello world.".to_owned(), Policy::All);
34+
Ini::add("hello.enable", false, Policy::All);
35+
Ini::add("hello.num", 100, Policy::All);
36+
Ini::add("hello.ratio", 1.5, Policy::All);
37+
Ini::add("hello.description", "hello world.".to_owned(), Policy::All);
3838

3939
// register hook functions
4040
module.on_module_init(module_init);
@@ -50,10 +50,10 @@ pub fn get_module() -> Module {
5050
|_: &mut [Val]| {
5151
let mut arr = Array::new();
5252

53-
let hello_enable = Val::new(Module::get_ini::<bool>("hello.enable"));
53+
let hello_enable = Val::new(Ini::get::<bool>("hello.enable"));
5454
arr.insert("hello.enable", hello_enable);
5555

56-
let hello_description = Val::new(Module::get_ini::<String>("hello.description"));
56+
let hello_description = Val::new(Ini::get::<String>("hello.description"));
5757
arr.insert("hello.description", hello_description);
5858

5959
arr

phper/src/ini.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{
1414
collections::HashMap,
1515
convert::TryFrom,
1616
ffi::CStr,
17-
mem::{size_of, transmute, transmute_copy, zeroed},
17+
mem::{forget, size_of, transmute, transmute_copy, zeroed},
1818
os::raw::{c_char, c_void},
1919
ptr::null_mut,
2020
str,
@@ -23,7 +23,9 @@ use std::{
2323
pub struct Ini;
2424

2525
impl Ini {
26+
// TODO Remove thread_local.
2627
thread_local! {
28+
static REGISTERED: bool = false;
2729
static INI_ENTITIES: DashMap<String, IniEntity> = DashMap::new();
2830
}
2931

@@ -36,7 +38,7 @@ impl Ini {
3638
});
3739
}
3840

39-
fn get<T: TransformIniValue>(name: &str) -> Option<T> {
41+
pub fn get<T: TransformIniValue>(name: &str) -> Option<T> {
4042
Self::INI_ENTITIES.with(|ini_entities| {
4143
ini_entities
4244
.get(name)
@@ -48,8 +50,8 @@ impl Ini {
4850
let mut entries = Vec::new();
4951

5052
Self::INI_ENTITIES.with(|ini_entities| {
51-
for entity in ini_entities {
52-
entries.push(entity.value().entry());
53+
for mut entity in ini_entities.iter_mut() {
54+
entries.push(entity.value_mut().entry());
5355
}
5456
});
5557

@@ -234,8 +236,14 @@ pub(crate) fn create_ini_entry_ex(
234236
))]
235237
let (modifiable, name_length) = (modifiable as std::os::raw::c_int, name.len() as u32);
236238

239+
let name = name.to_string();
240+
let boxed_name = name.into_boxed_str();
241+
let name = boxed_name.as_ptr().cast();
242+
forget(boxed_name);
243+
237244
zend_ini_entry_def {
238-
name: name.as_ptr().cast(),
245+
// name: name.as_ptr().cast(),
246+
name,
239247
on_modify,
240248
mh_arg1: null_mut(),
241249
mh_arg2: arg2,

phper/src/modules.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ impl ModuleArgs {
221221

222222
pub(crate) fn register_ini_entries(&self, ini_entries: *const zend_ini_entry_def) {
223223
unsafe {
224-
zend_register_ini_entries(ini_entries, self.module_number);
224+
// zend_register_ini_entries(ini_entries, self.module_number);
225225
}
226226
}
227227

228228
pub(crate) fn unregister_ini_entries(&self) {
229229
unsafe {
230-
zend_unregister_ini_entries(self.module_number);
230+
// zend_unregister_ini_entries(self.module_number);
231231
}
232232
}
233233
}

tests/integration/src/arguments.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
use phper::{
2-
alloc::EBox, arrays::Array, functions::Argument, modules::Module, objects::Object, values::Val,
2+
alloc::EBox,
3+
arrays::Array,
4+
functions::Argument,
5+
ini::{Ini, Policy},
6+
modules::Module,
7+
objects::Object,
8+
values::Val,
39
};
410

511
pub fn integrate(module: &mut Module) {

0 commit comments

Comments
 (0)