ext-php-rs 0.16.4

Bindings for the Zend API to build PHP extensions natively in Rust.
Documentation
//! Raw FFI bindings to the Zend API.

#![allow(clippy::all)]
#![allow(warnings)]

use std::{ffi::c_void, os::raw::c_char};

pub const ZEND_MM_ALIGNMENT: isize = 8;
pub const ZEND_MM_ALIGNMENT_MASK: isize = -8;

// These are not generated by Bindgen as everything in `bindings.rs` will have
// the `#[link(name = "php")]` attribute appended. This will cause the wrapper
// functions to fail to link.
#[link(name = "wrapper")]
unsafe extern "C" {
    pub fn ext_php_rs_zend_string_init(
        str_: *const c_char,
        len: usize,
        persistent: bool,
    ) -> *mut zend_string;
    pub fn ext_php_rs_zend_string_release(zs: *mut zend_string);
    pub fn ext_php_rs_is_known_valid_utf8(zs: *const zend_string) -> bool;
    pub fn ext_php_rs_set_known_valid_utf8(zs: *mut zend_string);

    pub fn ext_php_rs_php_build_id() -> *const c_char;
    pub fn ext_php_rs_zend_object_alloc(obj_size: usize, ce: *mut zend_class_entry) -> *mut c_void;
    pub fn ext_php_rs_zend_object_release(obj: *mut zend_object);
    pub fn ext_php_rs_executor_globals() -> *mut zend_executor_globals;
    pub fn ext_php_rs_compiler_globals() -> *mut zend_compiler_globals;
    pub fn ext_php_rs_process_globals() -> *mut php_core_globals;
    pub fn ext_php_rs_sapi_globals() -> *mut sapi_globals_struct;
    pub fn ext_php_rs_file_globals() -> *mut php_file_globals;
    pub fn ext_php_rs_sapi_module() -> *mut sapi_module_struct;
    pub fn ext_php_rs_output_activated() -> bool;
    pub fn ext_php_rs_zend_try_catch(
        func: unsafe extern "C" fn(*const c_void) -> *const c_void,
        ctx: *const c_void,
        result: *mut *mut c_void,
    ) -> bool;

    pub fn ext_php_rs_zend_first_try_catch(
        func: unsafe extern "C" fn(*const c_void) -> *const c_void,
        ctx: *const c_void,
        result: *mut *mut c_void,
    ) -> bool;

    pub fn ext_php_rs_zend_bailout() -> !;
    pub fn ext_php_rs_zend_compile_string(
        source: *mut zend_string,
        filename: *const c_char,
    ) -> *mut zend_op_array;
    pub fn ext_php_rs_zend_execute(op_array: *mut zend_op_array);
}

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

#[cfg(php86)]
pub use php86::*;

#[cfg(php86)]
mod php86 {
    use super::{
        HashTable, zend_call_known_function_ex, zend_class_entry, zend_function,
        zend_is_callable_ex, zend_object, zend_string, zval,
    };
    use std::ptr;

    pub use super::{
        zend_result_FAILURE as ZEND_RESULT_CODE_FAILURE,
        zend_result_SUCCESS as ZEND_RESULT_CODE_SUCCESS,
    };

    pub const ZEND_INTERNAL_FUNCTION: u32 = 1;
    pub const ZEND_USER_FUNCTION: u32 = 2;
    pub const ZEND_EVAL_CODE: u32 = 4;

    pub unsafe fn zend_call_known_function(
        fn_: *mut zend_function,
        object: *mut zend_object,
        called_scope: *mut zend_class_entry,
        retval_ptr: *mut zval,
        param_count: u32,
        params: *mut zval,
        named_params: *mut HashTable,
    ) {
        unsafe {
            zend_call_known_function_ex(
                fn_,
                object,
                called_scope,
                retval_ptr,
                param_count,
                params,
                named_params,
                0,
            );
        }
    }

    pub unsafe fn zend_is_callable(
        callable: *const zval,
        check_flags: u32,
        callable_name: *mut *mut zend_string,
    ) -> bool {
        unsafe {
            zend_is_callable_ex(
                callable,
                ptr::null_mut(),
                check_flags,
                callable_name,
                ptr::null_mut(),
                ptr::null_mut(),
            )
        }
    }
}