This commit is contained in:
Robin Appelman 2019-03-18 17:22:32 +01:00
commit 2c6fc98b87
7 changed files with 50 additions and 51 deletions

View file

@ -9,7 +9,7 @@ repository = "https://github.com/rethinkphp/php-rs"
edition = "2018"
[dependencies]
libc = "0.2.0"
libc = "0.2.50"
[lib]
name = "php"

View file

@ -1,45 +1,39 @@
#![allow(unused_variables)]
use libc::*;
use php::*;
use php::zend::*;
use php::info::*;
use php::zend::*;
use php::*;
extern {
pub fn php_printf(format: *const c_char , ...) -> size_t;
extern "C" {
pub fn php_printf(format: *const c_char, ...) -> size_t;
}
#[no_mangle]
pub extern fn php_module_startup(type_: c_int, module_number: c_int) -> c_int {
pub extern "C" fn php_module_startup(type_: c_int, module_number: c_int) -> c_int {
0
}
#[no_mangle]
pub extern fn php_module_shutdown(type_: c_int, module_number: c_int) -> c_int {
pub extern "C" fn php_module_shutdown(type_: c_int, module_number: c_int) -> c_int {
0
}
#[no_mangle]
pub extern fn php_module_info() {
pub extern "C" fn php_module_info() {
print_table_start();
print_table_row(&["A demo PHP extension written in Rust", "enabled"]);
print_table_end();
}
#[no_mangle]
pub extern fn helloworld(data: &ExecuteData, retval: &Value) {
unsafe {
php_printf(c_str!("Hello world, Rust!"))
};
pub extern "C" fn helloworld(data: &ExecuteData, retval: &Value) {
unsafe { php_printf(c_str!("Hello world, Rust!")) };
}
#[no_mangle]
pub extern fn get_module() -> *mut zend::Module {
let mut entry = Box::new(zend::Module::new(
c_str!("demo"),
c_str!("0.1.0-dev"),
));
pub extern "C" fn get_module() -> *mut zend::Module {
let mut entry = Box::new(zend::Module::new(c_str!("demo"), c_str!("0.1.0-dev")));
entry.set_info_func(php_module_info);

View file

@ -1,7 +1,7 @@
use libc::*;
use std::ffi::CString;
extern {
extern "C" {
pub fn php_info_print_table_start();
pub fn php_info_print_table_row(num_cols: c_int, ...) -> c_void;
pub fn php_info_print_table_end();
@ -29,4 +29,3 @@ pub fn print_table_start() {
pub fn print_table_end() {
unsafe { php_info_print_table_end() }
}

View file

@ -1,11 +1,10 @@
#![allow(dead_code)]
#![allow(unused_variables)]
extern crate libc;
#[macro_use]
pub mod macros;
pub mod zend;
pub mod info;
pub mod zend;

View file

@ -1,7 +1,6 @@
#[macro_export]
macro_rules! c_str {
($s:expr) => { {
($s:expr) => {{
concat!($s, "\0").as_ptr() as *const c_char
} }
}};
}

View file

@ -1,14 +1,14 @@
use libc::*;
use std;
use std::mem;
use libc::*;
type StartupFunc = extern fn (type_: c_int, module_number: c_int) -> c_int;
type ShutdownFunc = extern fn (type_: c_int, module_number: c_int) -> c_int;
type InfoFunc = extern fn () ;
type GlobalsCtorFunc = extern fn (global: *const c_void) -> c_void;
type GlobalsDtorFunc = extern fn (global: *const c_void) -> c_void;
type PostDeactivateFunc = extern fn () -> c_int;
type HandlerFunc = extern fn (execute_data: &ExecuteData, retval: &Value);
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();
type GlobalsCtorFunc = extern "C" fn(global: *const c_void) -> c_void;
type GlobalsDtorFunc = extern "C" fn(global: *const c_void) -> c_void;
type PostDeactivateFunc = extern "C" fn() -> c_int;
type HandlerFunc = extern "C" fn(execute_data: &ExecuteData, retval: &Value);
pub struct ExecuteData {}
pub struct Value {}
@ -25,7 +25,12 @@ pub struct ArgInfo {
}
impl ArgInfo {
pub fn new(name: *const c_char, allow_null: c_uchar, is_variadic: c_uchar, by_reference: c_uchar) -> ArgInfo {
pub fn new(
name: *const c_char,
allow_null: c_uchar,
is_variadic: c_uchar,
by_reference: c_uchar,
) -> ArgInfo {
ArgInfo {
name: name,
class_name: std::ptr::null(),
@ -57,7 +62,11 @@ impl Function {
}
}
pub fn new_with_args(name: *const c_char, handler: HandlerFunc, args: Box<[ArgInfo]>) -> Function {
pub fn new_with_args(
name: *const c_char,
handler: HandlerFunc,
args: Box<[ArgInfo]>,
) -> Function {
let num_args = args.len() as u32;
Function {
@ -78,7 +87,6 @@ impl Function {
flags: 0,
}
}
}
pub struct INI {}