@@ -18,14 +18,11 @@ use crate::{
1818 check_brace_level, decr_brace_level, enough_text_chars, name_scan_for_and,
1919 von_name_ends_and_last_name_starts_stuff, von_token_found, QUOTE_NEXT_FN ,
2020 } ,
21- xbuf:: { SafelyZero , XBuf } ,
2221 ASCIICode , Bibtex , BibtexError , BufPointer , GlobalItems , HashPointer , PoolPointer , StrIlk ,
2322 StrNumber ,
2423} ;
2524use std:: ops:: Index ;
2625
27- const LIT_STK_SIZE : usize = 100 ;
28-
2926#[ derive( Copy , Clone , PartialEq , Eq ) ]
3027pub ( crate ) enum StkType {
3128 Integer ,
@@ -56,14 +53,10 @@ impl ExecVal {
5653 }
5754}
5855
59- // SAFETY: We require our zero discriminant to be an integer, which is valid for any bit pattern, including 0
60- unsafe impl SafelyZero for ExecVal { }
61-
6256pub ( crate ) struct ExecCtx < ' a , ' bib , ' cbs > {
6357 pub glbl_ctx : & ' a mut Bibtex < ' bib , ' cbs > ,
6458 pub _default : HashPointer ,
65- pub ( crate ) lit_stack : Box < XBuf < ExecVal > > ,
66- pub lit_stk_ptr : usize ,
59+ pub ( crate ) lit_stack : Vec < ExecVal > ,
6760 pub mess_with_entries : bool ,
6861 /// Pointer to the current top of the string pool, used to optimize certain string operations
6962 pub bib_str_ptr : StrNumber ,
@@ -74,35 +67,22 @@ impl<'a, 'bib, 'cbs> ExecCtx<'a, 'bib, 'cbs> {
7467 ExecCtx {
7568 glbl_ctx,
7669 _default : 0 ,
77- lit_stack : Box :: new ( XBuf :: new ( LIT_STK_SIZE + 1 ) ) ,
78- lit_stk_ptr : 0 ,
70+ lit_stack : Vec :: new ( ) ,
7971 mess_with_entries : false ,
8072 bib_str_ptr : 0 ,
8173 }
8274 }
8375
8476 pub ( crate ) fn push_stack ( & mut self , val : ExecVal ) {
85- self . lit_stack [ self . lit_stk_ptr ] = val;
86-
87- if self . lit_stk_ptr >= self . lit_stack . len ( ) {
88- self . grow_stack ( ) ;
89- }
90-
91- self . lit_stk_ptr += 1 ;
77+ self . lit_stack . push ( val) ;
9278 }
9379
9480 pub ( crate ) fn pop_stack (
9581 & mut self ,
9682 pool : & mut StringPool ,
9783 cites : & CiteInfo ,
9884 ) -> Result < ExecVal , BibtexError > {
99- if self . lit_stk_ptr == 0 {
100- write_logs ( "You can't pop an empty literal stack" ) ;
101- bst_ex_warn_print ( self , pool, cites) ?;
102- Ok ( ExecVal :: Illegal )
103- } else {
104- self . lit_stk_ptr -= 1 ;
105- let pop = self . lit_stack [ self . lit_stk_ptr ] ;
85+ if let Some ( pop) = self . lit_stack . pop ( ) {
10686 if let ExecVal :: String ( str) = pop {
10787 if str >= self . bib_str_ptr {
10888 if str != pool. str_ptr ( ) - 1 {
@@ -115,13 +95,13 @@ impl<'a, 'bib, 'cbs> ExecCtx<'a, 'bib, 'cbs> {
11595 }
11696 }
11797 Ok ( pop)
98+ } else {
99+ write_logs ( "You can't pop an empty literal stack" ) ;
100+ bst_ex_warn_print ( self , pool, cites) ?;
101+ Ok ( ExecVal :: Illegal )
118102 }
119103 }
120104
121- fn grow_stack ( & mut self ) {
122- self . lit_stack . grow ( LIT_STK_SIZE ) ;
123- }
124-
125105 pub ( crate ) fn glbl_ctx ( & self ) -> & Bibtex < ' bib , ' cbs > {
126106 & * self . glbl_ctx
127107 }
@@ -278,7 +258,7 @@ fn pop_whole_stack(
278258 hash : & HashData ,
279259 cites : & CiteInfo ,
280260) -> Result < ( ) , BibtexError > {
281- while ctx. lit_stk_ptr > 0 {
261+ while ! ctx. lit_stack . is_empty ( ) {
282262 pop_top_and_print ( ctx, pool, hash, cites) ?;
283263 }
284264 Ok ( ( ) )
@@ -632,8 +612,8 @@ pub(crate) fn check_command_execution(
632612 hash : & HashData ,
633613 cites : & CiteInfo ,
634614) -> Result < ( ) , BibtexError > {
635- if ctx. lit_stk_ptr != 0 {
636- write_logs ( & format ! ( "ptr={}, stack=\n " , ctx. lit_stk_ptr ) ) ;
615+ if ! ctx. lit_stack . is_empty ( ) {
616+ write_logs ( & format ! ( "ptr={}, stack=\n " , ctx. lit_stack . len ( ) ) ) ;
637617 pop_whole_stack ( ctx, pool, hash, cites) ?;
638618 write_logs ( "---the literal stack isn't empty" ) ;
639619 bst_ex_warn_print ( ctx, pool, cites) ?;
0 commit comments