junrushao opened a new pull request, #492: URL: https://github.com/apache/tvm-ffi/pull/492
## Summary - Add `Function.__init__` constructor to the Cython `Function` class, enabling direct construction via `tvm_ffi.Function(callable)` instead of requiring `tvm_ffi.convert(callable)` - Support two input modes: wrap a plain Python callable, or copy-construct from an existing `Function` (with ref-count increment) - Reject non-callable inputs with `TypeError` and moved-from `Function` objects with `ValueError` ## Architecture - Implementation lives in `function.pxi` (`__init__` on the Cython `Function` extension type). For plain callables, delegates to the existing `_convert_to_ffi_func_handle` helper. For `Function`-to-`Function` copies, increments the C-level ref count via `TVMFFIObjectIncRef` and shares the handle. - No changes to the C ABI, C++ layer, or global registry. ## Public Interfaces - **New**: `tvm_ffi.Function(func: Callable[..., Any]) -> Function` constructor. - Type stub updated in `core.pyi`. ## Behavioral Changes - Previously, `tvm_ffi.Function` could only be obtained via `tvm_ffi.convert()` or the global function registry. Now it can be constructed directly. - Copy-constructing from a `Function` produces a second ref to the **same** underlying packed function (verified via `same_as`). ## Tests - `test_pyfunc_init` covers: wrapping a Python callable, copy-constructing from `Function`, `ValueError` on moved-from source, `TypeError` on non-callable input. ## Untested Edge Cases - Thread-safety of concurrent `__init__` calls (covered by GIL in CPython). - Interaction with `release_gil` property on the newly constructed function (inherits default). -- 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]
