mirror of
https://github.com/icewind1991/ivory.git
synced 2026-06-03 18:54:07 +02:00
throw errors on argument passing errors
This commit is contained in:
parent
7dc5d2841a
commit
74d59ad9ee
3 changed files with 37 additions and 4 deletions
|
|
@ -62,7 +62,7 @@ fn export_fn(item: ItemFn) -> TokenStream {
|
||||||
match opt {
|
match opt {
|
||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
None => {
|
None => {
|
||||||
::ivory::externs::printf("invalid argument type,");
|
::ivory::externs::error(::ivory::externs::ErrorLevel::Error, "invalid argument type,");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +75,7 @@ fn export_fn(item: ItemFn) -> TokenStream {
|
||||||
pub extern "C" fn #name(data: *const ::ivory::zend::ExecuteData, retval: *mut ::ivory::zend::ZVal) {
|
pub extern "C" fn #name(data: *const ::ivory::zend::ExecuteData, retval: *mut ::ivory::zend::ZVal) {
|
||||||
let data: &::ivory::zend::ExecuteData = unsafe { data.as_ref() }.unwrap();
|
let data: &::ivory::zend::ExecuteData = unsafe { data.as_ref() }.unwrap();
|
||||||
if data.num_args() != #arg_count {
|
if data.num_args() != #arg_count {
|
||||||
::ivory::externs::printf(format!("unexpected number of arguments, expected {}, got {}", #arg_count, data.num_args()));
|
::ivory::externs::error(::ivory::externs::ErrorLevel::Error, format!("unexpected number of arguments, expected {}, got {}", #arg_count, data.num_args()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut args: Vec<::ivory::zend::PhpVal> = data.args().collect();
|
let mut args: Vec<::ivory::zend::PhpVal> = data.args().collect();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
use std::ffi::{CString};
|
use std::ffi::CString;
|
||||||
|
use std::intrinsics::transmute;
|
||||||
|
|
||||||
use libc::*;
|
use libc::*;
|
||||||
|
|
||||||
|
use crate::zend::bindings::zend_error;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn php_printf(format: *const c_char, ...) -> size_t;
|
pub fn php_printf(format: *const c_char, ...) -> size_t;
|
||||||
}
|
}
|
||||||
|
|
@ -9,4 +12,34 @@ extern "C" {
|
||||||
pub fn printf<T: Into<Vec<u8>>>(string: T) {
|
pub fn printf<T: Into<Vec<u8>>>(string: T) {
|
||||||
let cstr = CString::new(string).unwrap();
|
let cstr = CString::new(string).unwrap();
|
||||||
unsafe { php_printf(cstr.as_ptr()); }
|
unsafe { php_printf(cstr.as_ptr()); }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(i32)]
|
||||||
|
pub enum ErrorLevel {
|
||||||
|
Error = 1,
|
||||||
|
Warning = 2,
|
||||||
|
Parse = 4,
|
||||||
|
Notice = 8,
|
||||||
|
CoreError = 16,
|
||||||
|
CoreWarning = 32,
|
||||||
|
CompilerError = 64,
|
||||||
|
CompilerWarning = 128,
|
||||||
|
UserError = 256,
|
||||||
|
UserWarning = 512,
|
||||||
|
UserNotice = 1024,
|
||||||
|
Strict = 2048,
|
||||||
|
RecoverableError = 4096,
|
||||||
|
Deprecated = 8192,
|
||||||
|
UserDeprecated = 16384,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ErrorLevel> for i32 {
|
||||||
|
fn from(from: ErrorLevel) -> Self {
|
||||||
|
unsafe { transmute(from) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn error<T: Into<Vec<u8>>>(level: ErrorLevel, message: T) {
|
||||||
|
let cstr = CString::new(message).unwrap();
|
||||||
|
unsafe { zend_error(level.into(), cstr.as_ptr()); }
|
||||||
}
|
}
|
||||||
|
|
@ -5,4 +5,4 @@ pub use self::zval::{ExecuteData, ZVal, PhpVal};
|
||||||
mod module;
|
mod module;
|
||||||
mod function;
|
mod function;
|
||||||
mod zval;
|
mod zval;
|
||||||
mod bindings;
|
pub mod bindings;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue