//! 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_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() -> !;
}

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