From a5a1d99bb649c363955cc4833a919edc9a7aea22 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sun, 10 Apr 2022 23:22:24 -0500 Subject: [PATCH] Debug CI crash 6/n [skip ci] --- src/engine/function.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/engine/function.cpp b/src/engine/function.cpp index b39777e77..e9bbef66d 100644 --- a/src/engine/function.cpp +++ b/src/engine/function.cpp @@ -426,6 +426,9 @@ struct _stack s->data = (char *)s->data + ( n * sizeof(remove_cref_t) ); s->check_alignment(); } + + template + void cleanup_push(int32_t n, T*_ = nullptr); }; template <> @@ -446,8 +449,7 @@ remove_cref_t & _stack::push( T&& v ) check_alignment(); data = (char *)data - sizeof(U); check_alignment(); - cleanup_info ci = { (cleanup_f)&_stack::cleanup_item, this, 1 }; - cleanups[cleanups_size++] = ci; + cleanup_push( 1 ); return top() = v; } @@ -459,11 +461,24 @@ remove_cref_t * _stack::push( T v, int32_t n ) data = (char *)data - ( n * sizeof(U) ); check_alignment(); std::uninitialized_fill_n( reinterpret_cast( data ), n, v ); - cleanup_info ci = { (cleanup_f)&_stack::cleanup_item, this, n }; - cleanups[cleanups_size++] = ci; + cleanup_push( n ); return reinterpret_cast( data ); } +template +void _stack::cleanup_push( int32_t n, T*_ ) +{ + if ( cleanups_size == cleanups.max_size() ) + { + err_puts( "Function stack cleanup overflow.\n" ); + err_flush(); + b2::clean_exit( b2::exit_result::failure ); + return; + } + cleanup_info ci = { (cleanup_f)&_stack::cleanup_item, this, n }; + cleanups[cleanups_size++] = ci; +} + STACK * stack_global() { static STACK result;