use core::ffi::c_void;
use std::os::raw::{c_char, c_int, c_uint};
use crate::abi::callbacks::{xmlGenericErrorFunc, xmlStructuredErrorFunc};
use crate::abi::types::xmlChar;
static LAST_ERROR_MIRROR_LOCK: parking_lot::Mutex<()> = parking_lot::Mutex::new(());
#[no_mangle]
pub static mut xmlDoValidityCheckingDefaultValue: c_int = 0;
#[no_mangle]
pub static mut xmlGetWarningsDefaultValue: c_int = 1;
#[no_mangle]
pub static mut xmlLoadExtDtdDefaultValue: c_int = 0;
#[no_mangle]
pub static mut xmlPedanticParserDefaultValue: c_int = 0;
#[no_mangle]
pub static mut xmlLineNumbersDefaultValue: c_int = 1;
#[no_mangle]
pub static mut xmlKeepBlanksDefaultValue: c_int = 1;
#[no_mangle]
pub static mut xmlSubstituteEntitiesDefaultValue: c_int = 0;
#[no_mangle]
pub static mut xmlParserDebugEntities: c_int = 0;
#[no_mangle]
pub static mut xmlIndentTreeOutput: c_int = 1;
#[no_mangle]
pub static mut xmlTreeIndentString: *const xmlChar = {
static S: [u8; 3] = *b" \0";
S.as_ptr()
};
#[no_mangle]
pub static mut xmlSaveNoEmptyTags: c_int = 0;
#[no_mangle]
pub static mut xmlRegisterNodeDefaultValue: Option<
unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode),
> = None;
pub static XML_REGISTER_CALLBACKS: core::sync::atomic::AtomicBool =
core::sync::atomic::AtomicBool::new(false);
pub fn register_node_hook(node: *mut crate::abi::structs::_xmlNode) {
if !XML_REGISTER_CALLBACKS.load(core::sync::atomic::Ordering::Relaxed) {
return;
}
let hook = unsafe { xmlRegisterNodeDefaultValue };
if let Some(h) = hook {
if !node.is_null() {
unsafe { h(node) };
}
}
}
pub fn deregister_node_hook(node: *mut crate::abi::structs::_xmlNode) {
if !XML_REGISTER_CALLBACKS.load(core::sync::atomic::Ordering::Relaxed) {
return;
}
let hook = unsafe { xmlDeregisterNodeDefaultValue };
if let Some(h) = hook {
if !node.is_null() {
unsafe { h(node) };
}
}
}
#[no_mangle]
pub static mut xmlDeregisterNodeDefaultValue: Option<
unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode),
> = None;
#[no_mangle]
pub static mut xmlParserVersion: *const c_char = {
static V: [u8; 17] = *b"21503-GITv2.15.3\0";
V.as_ptr() as *const c_char
};
#[no_mangle]
pub static mut xmlParserMaxDepth: c_int = 256;
#[no_mangle]
pub static mut xmlDefaultBufferSize: c_int = 4096;
#[no_mangle]
pub static mut xmlBufferAllocScheme: c_int = 1;
#[cfg(target_arch = "x86_64")]
#[no_mangle]
pub static mut xmlGenericError: Option<xmlGenericErrorFunc> = Some(XML_GENERIC_ERROR_DEFAULT);
#[cfg(not(target_arch = "x86_64"))]
#[no_mangle]
pub static mut xmlGenericError: Option<xmlGenericErrorFunc> = None;
#[no_mangle]
pub static mut xmlGenericErrorContext: *mut c_void = core::ptr::null_mut();
#[no_mangle]
pub static mut xmlStructuredError: Option<xmlStructuredErrorFunc> = None;
#[no_mangle]
pub static mut xmlStructuredErrorContext: *mut c_void = core::ptr::null_mut();
#[cfg(target_arch = "x86_64")]
#[repr(C)]
#[derive(Clone, Copy)]
struct VaListTag {
gp_offset: c_uint,
fp_offset: c_uint,
overflow_arg_area: *mut c_void,
reg_save_area: *mut c_void,
}
#[cfg(target_arch = "x86_64")]
unsafe extern "C" {
fn vfprintf(stream: *mut c_void, format: *const c_char, ap: *mut VaListTag) -> c_int;
}
#[cfg(target_arch = "x86_64")]
unsafe fn stderr_file() -> *mut c_void {
extern "C" {
static stderr: *mut c_void;
}
unsafe { stderr }
}
#[cfg(target_arch = "x86_64")]
#[no_mangle]
pub unsafe extern "C" fn xmlGenericErrorDefaultFuncV(
_ctx: *mut c_void,
msg: *const c_char,
ap: *mut VaListTag,
) -> c_int {
unsafe {
if crate::abi::data_globals::xmlGenericErrorContext.is_null() {
crate::abi::data_globals::xmlGenericErrorContext = stderr_file();
}
let stream = crate::abi::data_globals::xmlGenericErrorContext;
if msg.is_null() || stream.is_null() {
return 0;
}
vfprintf(stream, msg, ap)
}
}
#[cfg(target_arch = "x86_64")]
pub unsafe extern "C" fn xmlGenericErrorDefaultFunc() -> c_int {
unsafe {
core::arch::asm!(
"sub rsp, 240",
"mov [rsp+0], rdi",
"mov [rsp+8], rsi",
"mov [rsp+16], rdx",
"mov [rsp+24], rcx",
"mov [rsp+32], r8",
"mov [rsp+40], r9",
"movaps [rsp+48], xmm0",
"movaps [rsp+64], xmm1",
"movaps [rsp+80], xmm2",
"movaps [rsp+96], xmm3",
"movaps [rsp+112], xmm4",
"movaps [rsp+128], xmm5",
"movaps [rsp+144], xmm6",
"movaps [rsp+160], xmm7",
"mov dword ptr [rsp+176], 16",
"mov dword ptr [rsp+180], 48",
"lea rax, [rsp+256]",
"mov [rsp+184], rax",
"lea rax, [rsp]",
"mov [rsp+192], rax",
"lea rdx, [rsp+176]",
"call xmlGenericErrorDefaultFuncV",
"add rsp, 240",
"add rsp, 8",
"ret",
options(noreturn),
);
}
}
#[cfg(target_arch = "x86_64")]
const XML_GENERIC_ERROR_DEFAULT: xmlGenericErrorFunc = unsafe {
core::mem::transmute::<
unsafe extern "C" fn() -> c_int,
unsafe extern "C" fn(*mut c_void, *const c_char),
>(xmlGenericErrorDefaultFunc)
};
#[cfg(target_arch = "x86_64")]
#[no_mangle]
pub unsafe extern "C" fn xsltGenericErrorDefaultFuncV(
_ctx: *mut c_void,
msg: *const c_char,
ap: *mut VaListTag,
) -> c_int {
unsafe {
if crate::abi::data_globals::xsltGenericErrorContext.is_null() {
crate::abi::data_globals::xsltGenericErrorContext = stderr_file();
}
let stream = crate::abi::data_globals::xsltGenericErrorContext;
if msg.is_null() || stream.is_null() {
return 0;
}
vfprintf(stream, msg, ap)
}
}
#[cfg(target_arch = "x86_64")]
pub unsafe extern "C" fn xsltGenericErrorDefaultFunc() -> c_int {
unsafe {
core::arch::asm!(
"sub rsp, 240",
"mov [rsp+0], rdi",
"mov [rsp+8], rsi",
"mov [rsp+16], rdx",
"mov [rsp+24], rcx",
"mov [rsp+32], r8",
"mov [rsp+40], r9",
"movaps [rsp+48], xmm0",
"movaps [rsp+64], xmm1",
"movaps [rsp+80], xmm2",
"movaps [rsp+96], xmm3",
"movaps [rsp+112], xmm4",
"movaps [rsp+128], xmm5",
"movaps [rsp+144], xmm6",
"movaps [rsp+160], xmm7",
"mov dword ptr [rsp+176], 16",
"mov dword ptr [rsp+180], 48",
"lea rax, [rsp+256]",
"mov [rsp+184], rax",
"lea rax, [rsp]",
"mov [rsp+192], rax",
"lea rdx, [rsp+176]",
"call xsltGenericErrorDefaultFuncV",
"add rsp, 240",
"add rsp, 8",
"ret",
options(noreturn),
);
}
}
#[cfg(target_arch = "x86_64")]
const XSLT_GENERIC_ERROR_DEFAULT: xmlGenericErrorFunc = unsafe {
core::mem::transmute::<
unsafe extern "C" fn() -> c_int,
unsafe extern "C" fn(*mut c_void, *const c_char),
>(xsltGenericErrorDefaultFunc)
};
pub fn default_generic_error_func() -> Option<xmlGenericErrorFunc> {
#[cfg(target_arch = "x86_64")]
{
Some(XML_GENERIC_ERROR_DEFAULT)
}
#[cfg(not(target_arch = "x86_64"))]
{
None
}
}
#[no_mangle]
pub static xmlStringText: [xmlChar; 5] = [b't', b'e', b'x', b't', 0];
#[no_mangle]
pub static xmlStringTextNoenc: [xmlChar; 9] =
[b't', b'e', b'x', b't', b'n', b'o', b'e', b'n', b'c'];
#[no_mangle]
pub static xmlStringComment: [xmlChar; 8] = [b'c', b'o', b'm', b'm', b'e', b'n', b't', 0];
#[no_mangle]
pub static xmlXPathNAN: f64 = f64::NAN;
#[no_mangle]
pub static xmlXPathPINF: f64 = f64::INFINITY;
#[no_mangle]
pub static xmlXPathNINF: f64 = f64::NEG_INFINITY;
#[no_mangle]
pub static xsltLibxmlVersion: c_int = 21503;
#[cfg(target_arch = "x86_64")]
#[no_mangle]
pub static mut xsltGenericError: Option<xmlGenericErrorFunc> = Some(XSLT_GENERIC_ERROR_DEFAULT);
#[cfg(not(target_arch = "x86_64"))]
#[no_mangle]
pub static mut xsltGenericError: Option<xmlGenericErrorFunc> = None;
#[no_mangle]
pub static mut xsltGenericErrorContext: *mut c_void = core::ptr::null_mut();
#[no_mangle]
pub static mut xsltGenericDebugContext: *mut c_void = core::ptr::null_mut();
#[no_mangle]
pub static xsltExtMarker: [xmlChar; 1] = [0];
#[no_mangle]
pub static mut xsltDocDefaultLoader: Option<
unsafe extern "C" fn(
*const xmlChar,
*mut c_void,
c_int,
*mut crate::abi::structs::_xsltStylesheet,
*mut crate::abi::structs::_xsltTransformContext,
) -> *mut crate::abi::structs::_xmlDoc,
> = None;
#[no_mangle]
pub static mut xmlParserInputBufferCreateFilenameValue: Option<
unsafe extern "C" fn(*const c_char, c_int) -> *mut crate::abi::structs::_xmlParserInputBuffer,
> = None;
#[no_mangle]
pub static mut xmlOutputBufferCreateFilenameValue: Option<
unsafe extern "C" fn(
*const c_char,
crate::abi::structs::xmlCharEncodingHandlerPtr,
c_int,
) -> *mut crate::abi::structs::_xmlOutputBuffer,
> = None;
#[no_mangle]
pub static xmlDefaultSAXHandler: crate::abi::structs::_xmlSAXHandlerV1 =
crate::abi::structs::_xmlSAXHandlerV1 {
internalSubset: Some(crate::abi::exports_xml2::xmlSAX2InternalSubset),
isStandalone: Some(crate::abi::exports_xml2::xmlSAX2IsStandalone),
hasInternalSubset: Some(crate::abi::exports_xml2::xmlSAX2HasInternalSubset),
hasExternalSubset: Some(crate::abi::exports_xml2::xmlSAX2HasExternalSubset),
resolveEntity: Some(crate::abi::exports_xml2::xmlSAX2ResolveEntity),
getEntity: Some(crate::abi::exports_xml2::xmlSAX2GetEntity),
entityDecl: Some(crate::abi::exports_xml2::xmlSAX2EntityDecl),
notationDecl: Some(crate::abi::exports_xml2::xmlSAX2NotationDecl),
attributeDecl: Some(crate::abi::exports_xml2::xmlSAX2AttributeDecl),
elementDecl: Some(crate::abi::exports_xml2::xmlSAX2ElementDecl),
unparsedEntityDecl: Some(crate::abi::exports_xml2::xmlSAX2UnparsedEntityDecl),
setDocumentLocator: Some(crate::abi::exports_xml2::xmlSAX2SetDocumentLocator),
startDocument: Some(crate::abi::exports_xml2::xmlSAX2StartDocument),
endDocument: Some(crate::abi::exports_xml2::xmlSAX2EndDocument),
startElement: Some(crate::abi::exports_xml2::xmlSAX2StartElement),
endElement: Some(crate::abi::exports_xml2::xmlSAX2EndElement),
reference: Some(crate::abi::exports_xml2::xmlSAX2Reference),
characters: Some(crate::abi::exports_xml2::xmlSAX2Characters),
ignorableWhitespace: Some(crate::abi::exports_xml2::xmlSAX2IgnorableWhitespace),
processingInstruction: Some(crate::abi::exports_xml2::xmlSAX2ProcessingInstruction),
comment: Some(crate::abi::exports_xml2::xmlSAX2Comment),
warning: Some(crate::xml::errors::xmlParserWarning),
error: Some(crate::xml::errors::xmlParserError),
fatalError: Some(crate::xml::errors::xmlParserError),
getParameterEntity: Some(crate::abi::exports_xml2::xmlSAX2GetParameterEntity),
cdataBlock: Some(crate::abi::exports_xml2::xmlSAX2CDataBlock),
externalSubset: Some(crate::abi::exports_xml2::xmlSAX2ExternalSubset),
initialized: 1,
};
#[no_mangle]
pub static htmlDefaultSAXHandler: crate::abi::structs::_xmlSAXHandlerV1 =
crate::abi::structs::_xmlSAXHandlerV1 {
internalSubset: Some(crate::abi::exports_xml2::xmlSAX2InternalSubset),
isStandalone: None,
hasInternalSubset: None,
hasExternalSubset: None,
resolveEntity: None,
getEntity: Some(crate::abi::exports_xml2::xmlSAX2GetEntity),
entityDecl: None,
notationDecl: None,
attributeDecl: None,
elementDecl: None,
unparsedEntityDecl: None,
setDocumentLocator: Some(crate::abi::exports_xml2::xmlSAX2SetDocumentLocator),
startDocument: Some(crate::abi::exports_xml2::xmlSAX2StartDocument),
endDocument: Some(crate::abi::exports_xml2::xmlSAX2EndDocument),
startElement: Some(crate::abi::exports_xml2::xmlSAX2StartElement),
endElement: Some(crate::abi::exports_xml2::xmlSAX2EndElement),
reference: None,
characters: Some(crate::abi::exports_xml2::xmlSAX2Characters),
ignorableWhitespace: Some(crate::abi::exports_xml2::xmlSAX2IgnorableWhitespace),
processingInstruction: Some(crate::abi::exports_xml2::xmlSAX2ProcessingInstruction),
comment: Some(crate::abi::exports_xml2::xmlSAX2Comment),
warning: Some(crate::xml::errors::xmlParserWarning),
error: Some(crate::xml::errors::xmlParserError),
fatalError: Some(crate::xml::errors::xmlParserError),
getParameterEntity: None,
cdataBlock: Some(crate::abi::exports_xml2::xmlSAX2CDataBlock),
externalSubset: None,
initialized: 1,
};
#[no_mangle]
pub static xmlDefaultSAXLocator: crate::abi::callbacks::_xmlSAXLocator =
crate::abi::callbacks::_xmlSAXLocator {
getPublicId: Some(crate::abi::exports_xml2::xmlSAX2GetPublicId),
getSystemId: Some(crate::abi::exports_xml2::xmlSAX2GetSystemId),
getLineNumber: Some(crate::abi::exports_xml2::xmlSAX2GetLineNumber),
getColumnNumber: Some(crate::abi::exports_xml2::xmlSAX2GetColumnNumber),
};
#[no_mangle]
pub static mut xmlLastError: crate::abi::structs::_xmlError = crate::abi::structs::_xmlError {
domain: 0,
code: 0,
message: core::ptr::null_mut(),
level: 0,
file: core::ptr::null_mut(),
line: 0,
str1: core::ptr::null_mut(),
str2: core::ptr::null_mut(),
str3: core::ptr::null_mut(),
int1: 0,
int2: 0,
ctxt: core::ptr::null_mut(),
node: core::ptr::null_mut(),
};
pub unsafe fn sync_xml_last_error(err: *const crate::abi::structs::_xmlError) {
if err.is_null() {
return;
}
let _guard = LAST_ERROR_MIRROR_LOCK.lock();
unsafe { sync_xml_last_error_locked(err) };
}
unsafe fn sync_xml_last_error_locked(err: *const crate::abi::structs::_xmlError) {
unsafe {
reset_xml_last_error_locked();
let src = &*err;
let dst = core::ptr::addr_of_mut!(xmlLastError);
(*dst).domain = src.domain;
(*dst).code = src.code;
(*dst).level = src.level;
(*dst).line = src.line;
(*dst).int1 = src.int1;
(*dst).int2 = src.int2;
(*dst).ctxt = src.ctxt;
(*dst).node = src.node;
(*dst).message = dup_cstr(src.message as *const u8);
(*dst).file = dup_cstr(src.file as *const u8);
(*dst).str1 = dup_cstr(src.str1 as *const u8);
(*dst).str2 = dup_cstr(src.str2 as *const u8);
(*dst).str3 = dup_cstr(src.str3 as *const u8);
}
}
pub unsafe fn reset_xml_last_error() {
let _guard = LAST_ERROR_MIRROR_LOCK.lock();
unsafe { reset_xml_last_error_locked() };
}
unsafe fn reset_xml_last_error_locked() {
unsafe {
let dst = core::ptr::addr_of_mut!(xmlLastError);
if !(*dst).message.is_null() {
libc::free((*dst).message as *mut libc::c_void);
}
if !(*dst).file.is_null() {
libc::free((*dst).file as *mut libc::c_void);
}
if !(*dst).str1.is_null() {
libc::free((*dst).str1 as *mut libc::c_void);
}
if !(*dst).str2.is_null() {
libc::free((*dst).str2 as *mut libc::c_void);
}
if !(*dst).str3.is_null() {
libc::free((*dst).str3 as *mut libc::c_void);
}
*dst = crate::abi::structs::_xmlError {
domain: 0,
code: 0,
message: core::ptr::null_mut(),
level: 0,
file: core::ptr::null_mut(),
line: 0,
str1: core::ptr::null_mut(),
str2: core::ptr::null_mut(),
str3: core::ptr::null_mut(),
int1: 0,
int2: 0,
ctxt: core::ptr::null_mut(),
node: core::ptr::null_mut(),
};
}
}
unsafe fn dup_cstr(s: *const u8) -> *mut c_char {
if s.is_null() {
return core::ptr::null_mut();
}
unsafe {
let len = libc::strlen(s as *const libc::c_char) as usize;
let p = libc::malloc(len + 1) as *mut u8;
if p.is_null() {
return core::ptr::null_mut();
}
libc::memcpy(p as *mut libc::c_void, s as *const libc::c_void, len + 1);
p as *mut c_char
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlKeepBlanksDefault(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlKeepBlanksDefaultValue = v;
}
xmlKeepBlanksDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlLineNumbersDefault(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlLineNumbersDefaultValue = v;
}
xmlLineNumbersDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlSubstituteEntitiesDefault(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlSubstituteEntitiesDefaultValue = v;
}
xmlSubstituteEntitiesDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlPedanticParserDefault(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlPedanticParserDefaultValue = v;
}
xmlPedanticParserDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlRegisterNodeDefault(
func: Option<unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode)>,
) -> Option<unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode)> {
unsafe {
XML_REGISTER_CALLBACKS.store(true, core::sync::atomic::Ordering::Relaxed);
if func.is_some() {
xmlRegisterNodeDefaultValue = func;
}
xmlRegisterNodeDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlDeregisterNodeDefault(
func: Option<unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode)>,
) -> Option<unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode)> {
unsafe {
XML_REGISTER_CALLBACKS.store(true, core::sync::atomic::Ordering::Relaxed);
if func.is_some() {
xmlDeregisterNodeDefaultValue = func;
}
xmlDeregisterNodeDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn __xmlIndentTreeOutput() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlIndentTreeOutput) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlSaveNoEmptyTags() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlSaveNoEmptyTags) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlTreeIndentString() -> *mut *const xmlChar {
unsafe { core::ptr::addr_of_mut!(xmlTreeIndentString) }
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefDoValidityCheckingDefaultValue(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlDoValidityCheckingDefaultValue = v;
}
xmlDoValidityCheckingDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefGetWarningsDefaultValue(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlGetWarningsDefaultValue = v;
}
xmlGetWarningsDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefLoadExtDtdDefaultValue(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlLoadExtDtdDefaultValue = v;
}
xmlLoadExtDtdDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefPedanticParserDefaultValue(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlPedanticParserDefaultValue = v;
}
xmlPedanticParserDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefLineNumbersDefaultValue(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlLineNumbersDefaultValue = v;
}
xmlLineNumbersDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefKeepBlanksDefaultValue(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlKeepBlanksDefaultValue = v;
}
xmlKeepBlanksDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefSubstituteEntitiesDefaultValue(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlSubstituteEntitiesDefaultValue = v;
}
xmlSubstituteEntitiesDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefParserDebugEntities(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlParserDebugEntities = v;
}
xmlParserDebugEntities
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefIndentTreeOutput(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlIndentTreeOutput = v;
}
xmlIndentTreeOutput
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefTreeIndentString(v: *const c_char) -> *const c_char {
unsafe {
if !v.is_null() {
xmlTreeIndentString = v as *const xmlChar;
}
xmlTreeIndentString as *const c_char
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefSaveNoEmptyTags(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlSaveNoEmptyTags = v;
}
xmlSaveNoEmptyTags
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefRegisterNodeDefault(
func: Option<unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode)>,
) -> Option<unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode)> {
unsafe {
if func.is_some() {
xmlRegisterNodeDefaultValue = func;
}
xmlRegisterNodeDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefDeregisterNodeDefault(
func: Option<unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode)>,
) -> Option<unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode)> {
unsafe {
if func.is_some() {
xmlDeregisterNodeDefaultValue = func;
}
xmlDeregisterNodeDefaultValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefSetGenericErrorFunc(
ctx: *mut c_void,
func: Option<xmlGenericErrorFunc>,
) {
unsafe {
xmlGenericErrorContext = ctx;
xmlGenericError = func;
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefSetStructuredErrorFunc(
ctx: *mut c_void,
func: Option<xmlStructuredErrorFunc>,
) {
unsafe {
xmlStructuredErrorContext = ctx;
xmlStructuredError = func;
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefDefaultBufferSize(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlDefaultBufferSize = v;
}
xmlDefaultBufferSize
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefBufferAllocScheme(v: c_int) -> c_int {
unsafe {
if v != 0 {
xmlBufferAllocScheme = v;
}
xmlBufferAllocScheme
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefParserInputBufferCreateFilenameDefault(
func: Option<
unsafe extern "C" fn(
*const c_char,
c_int,
) -> *mut crate::abi::structs::_xmlParserInputBuffer,
>,
) -> Option<
unsafe extern "C" fn(*const c_char, c_int) -> *mut crate::abi::structs::_xmlParserInputBuffer,
> {
unsafe {
if func.is_some() {
xmlParserInputBufferCreateFilenameValue = func;
}
xmlParserInputBufferCreateFilenameValue
}
}
#[no_mangle]
pub unsafe extern "C" fn xmlThrDefOutputBufferCreateFilenameDefault(
func: Option<
unsafe extern "C" fn(
*const c_char,
crate::abi::structs::xmlCharEncodingHandlerPtr,
c_int,
) -> *mut crate::abi::structs::_xmlOutputBuffer,
>,
) -> Option<
unsafe extern "C" fn(
*const c_char,
crate::abi::structs::xmlCharEncodingHandlerPtr,
c_int,
) -> *mut crate::abi::structs::_xmlOutputBuffer,
> {
unsafe {
if func.is_some() {
xmlOutputBufferCreateFilenameValue = func;
}
xmlOutputBufferCreateFilenameValue
}
}
#[no_mangle]
pub unsafe extern "C" fn __xmlBufferAllocScheme() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlBufferAllocScheme) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlDefaultBufferSize() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlDefaultBufferSize) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlDeregisterNodeDefaultValue(
) -> *mut Option<unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode)> {
unsafe { core::ptr::addr_of_mut!(xmlDeregisterNodeDefaultValue) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlDoValidityCheckingDefaultValue() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlDoValidityCheckingDefaultValue) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlGenericError() -> *mut Option<xmlGenericErrorFunc> {
unsafe { core::ptr::addr_of_mut!(xmlGenericError) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlGenericErrorContext() -> *mut *mut c_void {
unsafe { core::ptr::addr_of_mut!(xmlGenericErrorContext) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlGetWarningsDefaultValue() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlGetWarningsDefaultValue) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlKeepBlanksDefaultValue() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlKeepBlanksDefaultValue) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlLineNumbersDefaultValue() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlLineNumbersDefaultValue) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlLoadExtDtdDefaultValue() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlLoadExtDtdDefaultValue) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlOutputBufferCreateFilenameValue() -> *mut Option<
unsafe extern "C" fn(
*const c_char,
crate::abi::structs::xmlCharEncodingHandlerPtr,
c_int,
) -> *mut crate::abi::structs::_xmlOutputBuffer,
> {
unsafe { core::ptr::addr_of_mut!(xmlOutputBufferCreateFilenameValue) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlParserDebugEntities() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlParserDebugEntities) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlParserInputBufferCreateFilenameValue() -> *mut Option<
unsafe extern "C" fn(*const c_char, c_int) -> *mut crate::abi::structs::_xmlParserInputBuffer,
> {
unsafe { core::ptr::addr_of_mut!(xmlParserInputBufferCreateFilenameValue) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlParserVersion() -> *mut *const c_char {
unsafe { core::ptr::addr_of_mut!(xmlParserVersion) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlPedanticParserDefaultValue() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlPedanticParserDefaultValue) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlRegisterNodeDefaultValue(
) -> *mut Option<unsafe extern "C" fn(*mut crate::abi::structs::_xmlNode)> {
unsafe { core::ptr::addr_of_mut!(xmlRegisterNodeDefaultValue) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlStructuredError() -> *mut Option<xmlStructuredErrorFunc> {
unsafe { core::ptr::addr_of_mut!(xmlStructuredError) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlStructuredErrorContext() -> *mut *mut c_void {
unsafe { core::ptr::addr_of_mut!(xmlStructuredErrorContext) }
}
#[no_mangle]
pub unsafe extern "C" fn __xmlSubstituteEntitiesDefaultValue() -> *mut c_int {
unsafe { core::ptr::addr_of_mut!(xmlSubstituteEntitiesDefaultValue) }
}
#[cfg(test)]
mod tests {
use super::*;
use crate::abi::allocator::xmlMallocImpl;
use crate::abi::structs::_xmlError;
use crate::xml::globals;
use core::ptr;
unsafe fn alloc_cstr(s: &str) -> *mut c_char {
let bytes = s.as_bytes();
let p = unsafe { xmlMallocImpl(bytes.len() + 1) as *mut c_char };
assert!(!p.is_null(), "alloc_cstr: xmlMallocImpl failed");
unsafe {
ptr::copy_nonoverlapping(bytes.as_ptr(), p as *mut u8, bytes.len());
*((p as *mut u8).add(bytes.len())) = 0;
}
p
}
unsafe fn build_error(tag: &str) -> _xmlError {
_xmlError {
domain: 1,
code: 2,
message: unsafe { alloc_cstr(&format!("msg {tag}")) },
level: 3,
file: unsafe { alloc_cstr(&format!("file {tag}")) },
line: 4,
str1: unsafe { alloc_cstr(&format!("str1 {tag}")) },
str2: ptr::null_mut(),
str3: ptr::null_mut(),
int1: 0,
int2: 0,
ctxt: ptr::null_mut(),
node: ptr::null_mut(),
}
}
#[test]
fn test_last_error_mirror_concurrent_sync_reset() {
let sync = std::thread::spawn(|| {
for i in 0..400 {
unsafe { globals::set_last_error(build_error(&format!("sync {i}"))) };
}
});
let reset = std::thread::spawn(|| {
for _ in 0..400 {
globals::reset_last_error();
}
});
sync.join().unwrap();
reset.join().unwrap();
globals::reset_last_error();
}
#[test]
fn test_last_error_mirror_many_threads() {
let mut handles = Vec::new();
for t in 0..8 {
handles.push(std::thread::spawn(move || {
for i in 0..150 {
unsafe { globals::set_last_error(build_error(&format!("t{t} i{i}"))) };
if i % 7 == 0 {
globals::reset_last_error();
}
}
}));
}
for h in handles {
h.join().unwrap();
}
globals::reset_last_error();
}
}