From 2beb175e92947b0818ce87dd540b1015ff709bfc Mon Sep 17 00:00:00 2001 From: Alistair-Afton Date: Tue, 15 Sep 2026 18:50:49 +0200 Subject: [PATCH] Job::removeJob: call job_handlerst_remove_job instead of the vmethod The globals table has provided job_handlerst_remove_job for years, so the indirect vmethod call (with the GCC workaround) is no longer needed. Same pattern as Buildings::completeBuild. Fixes #5903 --- library/modules/Job.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/library/modules/Job.cpp b/library/modules/Job.cpp index cbcfebcc23..9d1c6ed2eb 100644 --- a/library/modules/Job.cpp +++ b/library/modules/Job.cpp @@ -58,6 +58,7 @@ distribution. #include #include #include +#include #include using namespace DFHack; @@ -402,27 +403,23 @@ bool DFHack::Job::disconnectJobGeneralRef(df::job *job, df::general_ref *ref) { } bool DFHack::Job::removeJob(df::job* job) { - using df::global::world; CHECK_NULL_POINTER(job); - // cancel_job below does not clean up all refs, so we have to do some work + // remove_job below does not clean up all refs, so we have to do some work for (auto &item_ref : job->items) { disconnectJobItem(job, item_ref); if (item_ref) delete item_ref; } job->items.resize(0); - // call the job cancel vmethod graciously provided by The Toady One. - // job_handler::cancel_job calls job::~job, and then deletes job (this has + // job_handlerst_remove_job calls job::~job, and then deletes job (this has // been confirmed by disassembly). + auto fp = df::global::job_handlerst_remove_job; + CHECK_NULL_POINTER(fp); - // HACK: GCC (starting around GCC 10 targeting C++20 as of v50.09) optimizes - // out the vmethod call here regardless of optimization level, so we need to - // invoke the vmethod manually through a pointer, as the Lua wrapper does. - // `volatile` does not seem to be necessary but is included for good - // measure. - volatile auto cancel_job_method = &df::job_handler::cancel_job; - (world->jobs.*cancel_job_method)(job); + using FT = std::function; + auto f = reinterpret_cast(fp); + (*f)(job); return true; }