use crate::runtime::Sel;
use crate::{__sel_data, __sel_inner};
#[inline]
pub fn alloc_sel() -> Sel {
__sel_inner!(__sel_data!(alloc), "alloc")
}
#[inline]
pub fn init_sel() -> Sel {
__sel_inner!(__sel_data!(init), "init")
}
#[inline]
pub fn new_sel() -> Sel {
__sel_inner!(__sel_data!(new), "new")
}
#[inline]
pub fn dealloc_sel() -> Sel {
__sel_inner!(__sel_data!(dealloc), "dealloc")
}
#[inline]
#[allow(dead_code)] fn cxx_construct_sel() -> Sel {
__sel_inner!(".cxx_construct\0", ".cxx_construct")
}
#[inline]
#[allow(dead_code)] fn cxx_destruct_sel() -> Sel {
__sel_inner!(".cxx_destruct\0", ".cxx_destruct")
}
#[cfg(test)]
mod tests {
use core::sync::atomic::{AtomicBool, Ordering};
use crate::rc::Retained;
use crate::runtime::ClassBuilder;
use crate::runtime::NSObject;
use crate::{msg_send_id, ClassType};
use super::*;
#[test]
fn test_destruct_dynamic() {
static HAS_RUN: AtomicBool = AtomicBool::new(false);
let mut builder = ClassBuilder::new("TestCxxDestruct", NSObject::class()).unwrap();
unsafe extern "C" fn destruct(_: *mut NSObject, _: Sel) {
HAS_RUN.store(true, Ordering::Relaxed);
}
unsafe { builder.add_method(cxx_destruct_sel(), destruct as unsafe extern "C" fn(_, _)) };
let cls = builder.register();
let obj: Retained<NSObject> = unsafe { msg_send_id![cls, new] };
drop(obj);
let has_run_destruct = HAS_RUN.load(Ordering::Relaxed);
if cfg!(feature = "gnustep-1-7") {
assert!(has_run_destruct);
} else {
assert!(!has_run_destruct);
}
}
}