[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/native-comp 93f92cf 1/2: Zero stale pointer when unloading comp
From: |
Andrea Corallo |
Subject: |
feature/native-comp 93f92cf 1/2: Zero stale pointer when unloading comp units (bug#46256) |
Date: |
Tue, 9 Mar 2021 03:26:19 -0500 (EST) |
branch: feature/native-comp
commit 93f92cf1ba37f8b9abaee4b9487705bae464c4e0
Author: Pip Cet <pipcet@gmail.com>
Commit: Andrea Corallo <akrl@sdf.org>
Zero stale pointer when unloading comp units (bug#46256)
* src/alloc.c (cleanup_vector): Call unload_comp_unit.
* src/comp.c (unload_comp_unit): New function.
---
src/alloc.c | 3 +--
src/comp.c | 14 ++++++++++++++
src/comp.h | 2 ++
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/alloc.c b/src/alloc.c
index af08336..fee8cc0 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3157,8 +3157,7 @@ cleanup_vector (struct Lisp_Vector *vector)
{
struct Lisp_Native_Comp_Unit *cu =
PSEUDOVEC_STRUCT (vector, Lisp_Native_Comp_Unit);
- eassert (cu->handle);
- dynlib_close (cu->handle);
+ unload_comp_unit (cu);
}
else if (NATIVE_COMP_FLAG
&& PSEUDOVECTOR_TYPEP (&vector->header, PVEC_SUBR))
diff --git a/src/comp.c b/src/comp.c
index e6f672d..e180978 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -4949,6 +4949,20 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u,
bool loading_dump,
return res;
}
+void
+unload_comp_unit (struct Lisp_Native_Comp_Unit *cu)
+{
+ if (cu->handle == NULL)
+ return;
+
+ Lisp_Object *saved_cu = dynlib_sym (cu->handle, COMP_UNIT_SYM);
+ Lisp_Object this_cu;
+ XSETNATIVE_COMP_UNIT (this_cu, cu);
+ if (EQ (this_cu, *saved_cu))
+ *saved_cu = Qnil;
+ dynlib_close (cu->handle);
+}
+
Lisp_Object
native_function_doc (Lisp_Object function)
{
diff --git a/src/comp.h b/src/comp.h
index f7d17f3..d01bc17 100644
--- a/src/comp.h
+++ b/src/comp.h
@@ -78,6 +78,8 @@ extern void hash_native_abi (void);
extern Lisp_Object load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u,
bool loading_dump, bool late_load);
+extern void unload_comp_unit (struct Lisp_Native_Comp_Unit *);
+
extern Lisp_Object native_function_doc (Lisp_Object function);
extern void syms_of_comp (void);