@@ -432,8 +432,8 @@ impl RawLua {
432432 pub ( crate ) unsafe fn create_string ( & self , s : impl AsRef < [ u8 ] > ) -> Result < String > {
433433 let state = self . state ( ) ;
434434 if self . unlikely_memory_error ( ) {
435- push_string ( self . ref_thread ( ) , s. as_ref ( ) , false ) ?;
436- return Ok ( String ( self . pop_ref_thread ( ) ) ) ;
435+ push_string ( state , s. as_ref ( ) , false ) ?;
436+ return Ok ( String ( self . pop_ref ( ) ) ) ;
437437 }
438438
439439 let _sg = StackGuard :: new ( state) ;
@@ -444,12 +444,12 @@ impl RawLua {
444444
445445 /// See [`Lua::create_table_with_capacity`]
446446 pub ( crate ) unsafe fn create_table_with_capacity ( & self , narr : usize , nrec : usize ) -> Result < Table > {
447+ let state = self . state ( ) ;
447448 if self . unlikely_memory_error ( ) {
448- push_table ( self . ref_thread ( ) , narr, nrec, false ) ?;
449- return Ok ( Table ( self . pop_ref_thread ( ) ) ) ;
449+ push_table ( state , narr, nrec, false ) ?;
450+ return Ok ( Table ( self . pop_ref ( ) ) ) ;
450451 }
451452
452- let state = self . state ( ) ;
453453 let _sg = StackGuard :: new ( state) ;
454454 check_stack ( state, 3 ) ?;
455455 push_table ( state, narr, nrec, true ) ?;
@@ -734,6 +734,10 @@ impl RawLua {
734734
735735 pub ( crate ) unsafe fn drop_ref ( & self , vref : & ValueRef ) {
736736 let ref_thread = self . ref_thread ( ) ;
737+ mlua_debug_assert ! (
738+ ffi:: lua_gettop( ref_thread) >= vref. index,
739+ "GC finalizer is not allowed in ref_thread"
740+ ) ;
737741 ffi:: lua_pushnil ( ref_thread) ;
738742 ffi:: lua_replace ( ref_thread, vref. index ) ;
739743 ( * self . extra . get ( ) ) . ref_free . push ( vref. index ) ;
0 commit comments