This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 08d75197e1 [Cython][FFI] Fix crash when call del operator for handle 
(#17190)
08d75197e1 is described below

commit 08d75197e1033d64cba5da0407a7489759c5dba5
Author: Egor Churaev <[email protected]>
AuthorDate: Thu Jul 25 16:44:55 2024 +0300

    [Cython][FFI] Fix crash when call del operator for handle (#17190)
    
    * [Cython][FFI] Fix crash when call del operator for handle
    
    In case of cython when we create a set function for property then the
    following code will be generated:
    ```
    static int __pyx_setprop_4test_9TestClass_handle(PyObject *o, PyObject *v, 
CYTHON_UNUSED void *x) {
      if (v) {
        return __pyx_pw_4test_9TestClass_6handle_3__set__(o, v);
      }
      else {
        PyErr_SetString(PyExc_NotImplementedError, "__del__");
        return -1;
      }
    }
    ```
    
    And when we call operator `del` for this handler, then the memory will
    be released and operator `__set__` will be called for NULL object. In
    this case an exception that operator `__del__` is not implemented will
    be generated. To avoid this problem we need to declare `__del__`
    function for each property where we define operator `__set__`.
    
    * Apply comments
    
    * Set dref.handle to None instead of using __del__ functions
---
 python/tvm/runtime/disco/session.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/python/tvm/runtime/disco/session.py 
b/python/tvm/runtime/disco/session.py
index 38c4f2a235..89ef549df3 100644
--- a/python/tvm/runtime/disco/session.py
+++ b/python/tvm/runtime/disco/session.py
@@ -92,7 +92,7 @@ class DModule(DRef):
 
     def __init__(self, dref: DRef, session: "Session") -> None:
         self.handle = dref.handle
-        del dref.handle
+        dref.handle = None
         self.session = session
 
     def __getitem__(self, name: str) -> DPackedFunc:

Reply via email to