gemini-code-assist[bot] commented on code in PR #492:
URL: https://github.com/apache/tvm-ffi/pull/492#discussion_r2869997163


##########
tests/python/test_function.py:
##########
@@ -153,6 +153,33 @@ def fapply(f: Any, *args: Any) -> Any:
     assert fapply(add, 1, 3.3) == 4.3
 
 
+def test_pyfunc_init() -> None:
+    def add(a: int, b: int) -> int:
+        return a + b
+
+    # Test creating from a Python callable
+    fadd = tvm_ffi.Function(add)
+    assert isinstance(fadd, tvm_ffi.Function)
+    assert fadd(1, 2) == 3
+
+    # Test creating from an existing tvm_ffi.Function
+    fadd2 = tvm_ffi.Function(fadd)
+    assert isinstance(fadd2, tvm_ffi.Function)
+    assert fadd2(3, 4) == 7
+    assert fadd.same_as(fadd2)
+
+    # Test creating from a moved-from function raises ValueError
+    f_source = tvm_ffi.Function(add)
+    f_dest = tvm_ffi.Function(add)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   This line creates a `Function` object with a new handle, which is then 
immediately overwritten by `__move_handle_from__` on the next line. This leaks 
the handle created for `f_dest`. To avoid the leak, you can create `f_dest` 
without a handle using `__new__`.
   
   ```suggestion
       f_dest = tvm_ffi.Function.__new__(tvm_ffi.Function)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to