mirror of
https://github.com/icewind1991/ivory.git
synced 2026-06-03 18:54:07 +02:00
vecs instead of boxed arrays
This commit is contained in:
parent
dc9e396c1f
commit
b68d1a445d
5 changed files with 33 additions and 23 deletions
|
|
@ -12,5 +12,5 @@ edition = "2018"
|
|||
libc = "0.2.50"
|
||||
|
||||
[lib]
|
||||
name = "php"
|
||||
name = "php_rs"
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.50"
|
||||
php-rs = { path = "../.." }
|
||||
php-rs = { path = "../..", version = "0.1.0" }
|
||||
|
||||
[lib]
|
||||
name = "helloworld"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use libc::*;
|
||||
use php::info::*;
|
||||
use php::zend::*;
|
||||
use php::*;
|
||||
use php_rs::info::{print_table_start, print_table_row, print_table_end};
|
||||
use php_rs::zend::*;
|
||||
use php_rs::*;
|
||||
|
||||
extern "C" {
|
||||
pub fn php_printf(format: *const c_char, ...) -> size_t;
|
||||
|
|
@ -35,16 +35,15 @@ pub extern "C" fn get_module() -> *mut zend::Module {
|
|||
|
||||
entry.set_info_func(php_module_info);
|
||||
|
||||
let args = Box::new([
|
||||
ArgInfo::new(1 as *const c_char, 0, 0, 0),
|
||||
let args = vec![
|
||||
ArgInfo::new(c_str!("name"), 0, 0, 0),
|
||||
]);
|
||||
ArgInfo::new(c_str!("foo"), 0, 0, 0),
|
||||
];
|
||||
|
||||
let funcs = Box::new([
|
||||
let funcs = vec![
|
||||
Function::new(c_str!("helloworld"), helloworld),
|
||||
Function::new_with_args(c_str!("helloworld2"), helloworld, args),
|
||||
Function::end(),
|
||||
]);
|
||||
];
|
||||
|
||||
entry.set_functions(funcs);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use libc::*;
|
||||
use std;
|
||||
use std::mem;
|
||||
|
||||
use libc::*;
|
||||
|
||||
type StartupFunc = extern "C" fn(type_: c_int, module_number: c_int) -> c_int;
|
||||
type ShutdownFunc = extern "C" fn(type_: c_int, module_number: c_int) -> c_int;
|
||||
type InfoFunc = extern "C" fn();
|
||||
|
|
@ -11,7 +12,9 @@ type PostDeactivateFunc = extern "C" fn() -> c_int;
|
|||
type HandlerFunc = extern "C" fn(execute_data: &ExecuteData, retval: &Value);
|
||||
|
||||
pub struct ExecuteData {}
|
||||
|
||||
pub struct Value {}
|
||||
|
||||
pub struct ModuleDep {}
|
||||
|
||||
#[repr(C)]
|
||||
|
|
@ -32,12 +35,12 @@ impl ArgInfo {
|
|||
by_reference: c_uchar,
|
||||
) -> ArgInfo {
|
||||
ArgInfo {
|
||||
name: name,
|
||||
name,
|
||||
class_name: std::ptr::null(),
|
||||
type_hint: 0,
|
||||
pass_by_reference: by_reference,
|
||||
allow_null: allow_null,
|
||||
is_variadic: is_variadic,
|
||||
allow_null,
|
||||
is_variadic,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -65,20 +68,26 @@ impl Function {
|
|||
pub fn new_with_args(
|
||||
name: *const c_char,
|
||||
handler: HandlerFunc,
|
||||
args: Box<[ArgInfo]>,
|
||||
mut args: Vec<ArgInfo>,
|
||||
) -> Function {
|
||||
let num_args = args.len() as u32;
|
||||
|
||||
let arg_count = ArgInfo::new(num_args as *const c_char, 0, 0, 0);
|
||||
args.insert(0, arg_count);
|
||||
|
||||
let arg_ptr = args.as_ptr();
|
||||
mem::forget(args);
|
||||
|
||||
Function {
|
||||
fname: name,
|
||||
handler: Some(handler),
|
||||
arg_info: Box::into_raw(args) as *const ArgInfo,
|
||||
num_args: num_args - 1,
|
||||
arg_info: arg_ptr,
|
||||
num_args,
|
||||
flags: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn end() -> Function {
|
||||
fn end() -> Function {
|
||||
Function {
|
||||
fname: std::ptr::null(),
|
||||
handler: None,
|
||||
|
|
@ -128,14 +137,14 @@ impl Module {
|
|||
zts: 0,
|
||||
ini_entry: std::ptr::null(),
|
||||
deps: std::ptr::null(),
|
||||
name: name,
|
||||
name,
|
||||
functions: std::ptr::null(),
|
||||
module_startup_func: None,
|
||||
module_shutdown_func: None,
|
||||
request_startup_func: None,
|
||||
request_shutdown_func: None,
|
||||
info_func: None,
|
||||
version: version,
|
||||
version,
|
||||
globals_size: 0,
|
||||
globals_ptr: std::ptr::null(),
|
||||
globals_ctor: None,
|
||||
|
|
@ -161,8 +170,10 @@ impl Module {
|
|||
self.info_func = Some(func);
|
||||
}
|
||||
|
||||
pub fn set_functions(&mut self, funcs: Box<[Function]>) {
|
||||
self.functions = Box::into_raw(funcs) as *const Function;
|
||||
pub fn set_functions(&mut self, mut funcs: Vec<Function>) {
|
||||
funcs.push(Function::end());
|
||||
self.functions = funcs.as_ptr();
|
||||
mem::forget(funcs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
0
tests/tests.rs
Normal file
0
tests/tests.rs
Normal file
Loading…
Add table
Add a link
Reference in a new issue