From a9a6fb7d0f435cb351ccb5f298a5320453542b88 Mon Sep 17 00:00:00 2001 From: meowking Date: Fri, 6 Sep 2024 09:02:20 +0800 Subject: [PATCH] fix: disable type.context automatically free --- example/el_psy_congaroo.py | 2 +- src/llvm/Core/type.cpp | 4 +++- src/llvm/types_priv/PymContext.h | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/example/el_psy_congaroo.py b/example/el_psy_congaroo.py index eb461de..e200e77 100644 --- a/example/el_psy_congaroo.py +++ b/example/el_psy_congaroo.py @@ -26,6 +26,6 @@ m = utils.parse_assembly(asm_str) -print(m.context) # FIXME +print(m.context) # with core.Context.get_global_context() as ctx: # print(ctx) diff --git a/src/llvm/Core/type.cpp b/src/llvm/Core/type.cpp index d220fa8..f79fa47 100644 --- a/src/llvm/Core/type.cpp +++ b/src/llvm/Core/type.cpp @@ -57,7 +57,9 @@ void bindTypeClasses(nb::module_ &m) { "Whether the type has a known size.\n\n" "Things that don't have a size are abstract types, labels, and void.a") .def_prop_ro("context", - [](PymType &t) { return PymContext(LLVMGetTypeContext(t.get())); }, + [](PymType &t) { + return PymContext(LLVMGetTypeContext(t.get()), true); + }, "Obtain the context to which this type instance is associated.") .def_prop_ro("sub_type_number", [](PymType &t) { diff --git a/src/llvm/types_priv/PymContext.h b/src/llvm/types_priv/PymContext.h index 1083084..2c93525 100644 --- a/src/llvm/types_priv/PymContext.h +++ b/src/llvm/types_priv/PymContext.h @@ -11,6 +11,10 @@ class PymContext : public PymLLVMObject { public: explicit PymContext(); + /* + is_global_context: whether this context is a global context; Or true if you + don't want automatically delete the context. + */ explicit PymContext(LLVMContextRef context, bool is_global_context); explicit PymContext(LLVMContextRef context); static PymContext getGlobalContext();