@@ -64,7 +64,6 @@ pub use ::libc::INT_MAX;
6464use libc:: { c_char, c_int, c_long, c_uint, c_ulong, c_ushort, c_void, size_t, ptrdiff_t, memcpy, memcmp, memmove, memset} ;
6565use num_traits:: { ToPrimitive , FromPrimitive } ;
6666
67- use std:: collections:: TryReserveError ;
6867use fallible_collections:: FallibleBox ;
6968
7069use std:: alloc:: { self , Layout } ;
@@ -1462,9 +1461,19 @@ pub unsafe extern "C" fn XML_ParserCreate_MM(
14621461}
14631462
14641463impl < ' scf > XML_ParserStruct < ' scf > {
1465- fn new ( use_namespaces : bool ) -> Result < Self , TryReserveError > {
1466- let m_dataBuf = Box :: try_new ( [ 0 ; INIT_DATA_BUF_SIZE as usize ] ) ?;
1467- Ok ( Self {
1464+ unsafe fn create (
1465+ mut encodingName : * const XML_Char ,
1466+ mut nameSep : * const XML_Char ,
1467+ mut dtd : * mut DTD < ' scf > ,
1468+ ) -> XML_Parser {
1469+ let use_namespaces = !nameSep. is_null ( ) ;
1470+
1471+ let m_dataBuf = match Box :: try_new ( [ 0 ; INIT_DATA_BUF_SIZE as usize ] ) {
1472+ Ok ( b) => b,
1473+ Err ( _) => return ptr:: null_mut ( ) ,
1474+ } ;
1475+
1476+ let parser = Self {
14681477 m_userData : ptr:: null_mut ( ) ,
14691478 m_buffer : Vec :: new ( ) ,
14701479 // index of first character to be parsed
@@ -1537,7 +1546,7 @@ impl<'scf> XML_ParserStruct<'scf> {
15371546 m_temp2Pool : STRING_POOL :: new ( ) ,
15381547 m_groupConnector : ptr:: null_mut ( ) ,
15391548 m_groupSize : 0 ,
1540- m_namespaceSeparator : 0 ,
1549+ m_namespaceSeparator : ASCII_EXCL as XML_Char ,
15411550 m_parentParser : ptr:: null_mut ( ) ,
15421551 m_parsingStatus : XML_ParsingStatus :: default ( ) ,
15431552 m_isParamEntity : false ,
@@ -1546,17 +1555,9 @@ impl<'scf> XML_ParserStruct<'scf> {
15461555
15471556 #[ cfg( feature = "mozilla" ) ]
15481557 m_mismatch : ptr:: null ( ) ,
1549- } )
1550- }
1551-
1552- unsafe fn create (
1553- mut encodingName : * const XML_Char ,
1554- mut nameSep : * const XML_Char ,
1555- mut dtd : * mut DTD ,
1556- ) -> XML_Parser {
1557- let use_namespaces = !nameSep. is_null ( ) ;
1558+ } ;
15581559
1559- let mut parser = match XML_ParserStruct :: new ( use_namespaces ) . and_then ( Box :: try_new) {
1560+ let mut parser = match Box :: try_new ( parser ) {
15601561 Ok ( p) => p,
15611562 Err ( _) => return ptr:: null_mut ( ) ,
15621563 } ;
@@ -1568,30 +1569,11 @@ impl<'scf> XML_ParserStruct<'scf> {
15681569 if parser. typed_atts . try_reserve ( INIT_ATTS_SIZE as usize ) . is_err ( ) {
15691570 return ptr:: null_mut ( ) ;
15701571 }
1571- parser. m_dataBuf = MALLOC ! [ XML_Char ; INIT_DATA_BUF_SIZE ] ;
1572- if parser. m_dataBuf . is_null ( ) {
1572+
1573+ parser. m_dtd = if !dtd. is_null ( ) { dtd } else { dtdCreate ( ) } ;
1574+ if parser. m_dtd . is_null ( ) {
15731575 return ptr:: null_mut ( ) ;
15741576 }
1575- parser. m_dataBufEnd = parser. m_dataBuf . offset ( INIT_DATA_BUF_SIZE as isize ) ;
1576- if !dtd. is_null ( ) {
1577- parser. m_dtd = dtd
1578- } else {
1579- parser. m_dtd = dtdCreate ( ) ;
1580- if parser. m_dtd . is_null ( ) {
1581- return ptr:: null_mut ( ) ;
1582- }
1583- }
1584- parser. m_freeBindingList = ptr:: null_mut ( ) ;
1585- parser. m_freeTagList = None ;
1586- parser. m_freeInternalEntities = ptr:: null_mut ( ) ;
1587- parser. m_groupSize = 0 ;
1588- parser. m_groupConnector = ptr:: null_mut ( ) ;
1589- parser. m_initEncoding = None ;
1590- parser. m_unknownEncoding = None ;
1591- parser. m_namespaceSeparator = ASCII_EXCL as XML_Char ;
1592- parser. m_ns = false ;
1593- parser. m_ns_triplets = false ;
1594- parser. m_protocolEncodingName = ptr:: null ( ) ;
15951577 parser. m_tempPool . init ( ) ;
15961578 parser. m_temp2Pool . init ( ) ;
15971579 parser. init ( encodingName) ;
@@ -1607,6 +1589,7 @@ impl<'scf> XML_ParserStruct<'scf> {
16071589 {
16081590 parser. m_mismatch = ptr:: null ( ) ;
16091591 }
1592+
16101593 Box :: into_raw ( parser)
16111594 }
16121595
0 commit comments