[MIRROR] More lua harddel fixes [MDB IGNORE] (#23064)

* More lua harddel fixes (#77556)

## About The Pull Request
Fixes some more lua harddel problems with lingering refs on the gc_guard
variable. This variable has been changed to a list instead and will get
cleared every time the SSlua subsystem fires so that lua instantiated
objects that are not tracked by the subsystem will essentially delete
themselves on the next tick, aka whenever the lua script sleeps.

Also removed the unnecessary and not completely functional
lua_reference_cleanup proc which wasn't even being called reliably
because the signal handler was the datum itself.

## Why It's Good For The Game
Fixes more harddel bugs, increases consistency.

Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>

* More lua harddel fixes

---------

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>
This commit is contained in:
SkyratBot
2023-08-14 00:37:01 +02:00
committed by GitHub
parent 3a4be7c458
commit 30f436724b
3 changed files with 5 additions and 21 deletions
+2 -6
View File
@@ -12,9 +12,7 @@
else
ret = HandleUserlessProcCall("lua", thing_to_call, proc_name, arguments)
if(isdatum(ret))
SSlua.gc_guard = ret
var/datum/ret_datum = ret
ret_datum.RegisterSignal(ret_datum, COMSIG_QDELETING, TYPE_PROC_REF(/datum, lua_reference_cleanup), override = TRUE)
SSlua.gc_guard += ret
return ret
/proc/wrap_lua_global_proc_call(proc_name, list/arguments)
@@ -27,9 +25,7 @@
else
ret = HandleUserlessProcCall("lua", GLOBAL_PROC, proc_name, arguments)
if(isdatum(ret))
SSlua.gc_guard = ret
var/datum/ret_datum = ret
ret_datum.RegisterSignal(ret_datum, COMSIG_QDELETING, TYPE_PROC_REF(/datum, lua_reference_cleanup), override = TRUE)
SSlua.gc_guard += ret
return ret
/proc/wrap_lua_print(state_id, list/arguments)
-14
View File
@@ -34,17 +34,3 @@
#undef PROMISE_PENDING
#undef PROMISE_RESOLVED
#undef PROMISE_REJECTED
/**
* When a datum is created from lua, it gets held in `SSlua.gc_guard`, and later,
* in the calling state datum's `var/list/references`, just in case it would be garbage
* collected due to there not being any references that BYOND recognizes. To avoid harddels,
* we register this proc as a signal handler any time a DM function called from lua returns
* a datum.
*/
/datum/proc/lua_reference_cleanup()
SIGNAL_HANDLER
if(SSlua.gc_guard == src)
SSlua.gc_guard = null
for(var/datum/lua_state/state in SSlua.states)
state.references -= src