This is an automated email from the ASF dual-hosted git repository.
junrushao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git
The following commit(s) were added to refs/heads/main by this push:
new f98ce6d5 feat(cython): expose additional C API symbols in base.pxi
(#502)
f98ce6d5 is described below
commit f98ce6d56a522b5e6b00865735643934af0e184d
Author: Junru Shao <[email protected]>
AuthorDate: Tue Mar 10 16:12:38 2026 -0700
feat(cython): expose additional C API symbols in base.pxi (#502)
## Summary
- Add Cython declarations for type-registration functions
(`TVMFFITypeGetOrAllocIndex`, `TVMFFITypeRegisterField`,
`TVMFFITypeRegisterMetadata`, `TVMFFITypeRegisterAttr`,
`TVMFFIErrorSetRaisedFromCStr`) so Python-side type registration can
call these symbols directly through Cython
- Add missing field-flag constants (`SEqHashIgnore`, `SEqHashDef`,
`ReprOff`, `CompareOff`, `HashOff`) and the `TVMFFISEqHashKind` enum
- Fix `TVMFFITypeMetadata.total_size` type (`int64_t` -> `int32_t`) and
add `structural_eq_hash_kind` field to match the C struct layout
- Add `cause_chain` and `extra_context` fields to the error info struct
## Test plan
- [ ] Existing CI tests pass (no behavioral change, declarations only)
- [ ] Verify Cython compilation succeeds with the new declarations via
`uv pip install --force-reinstall --verbose -e .`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---
python/tvm_ffi/cython/base.pxi | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/python/tvm_ffi/cython/base.pxi b/python/tvm_ffi/cython/base.pxi
index 9c1d4b4d..007aa0a9 100644
--- a/python/tvm_ffi/cython/base.pxi
+++ b/python/tvm_ffi/cython/base.pxi
@@ -195,6 +195,8 @@ cdef extern from "tvm/ffi/c_api.h":
void (*update_backtrace)(
TVMFFIObjectHandle self, const TVMFFIByteArray* backtrace, int32_t
update_mode
)
+ TVMFFIObjectHandle cause_chain
+ TVMFFIObjectHandle extra_context
ctypedef int (*TVMFFISafeCallType)(
void* handle, const TVMFFIAny* args, int32_t num_args,
@@ -204,7 +206,12 @@ cdef extern from "tvm/ffi/c_api.h":
kTVMFFIFieldFlagBitMaskWritable = 1 << 0
kTVMFFIFieldFlagBitMaskHasDefault = 1 << 1
kTVMFFIFieldFlagBitMaskIsStaticMethod = 1 << 2
+ kTVMFFIFieldFlagBitMaskSEqHashIgnore = 1 << 3
+ kTVMFFIFieldFlagBitMaskSEqHashDef = 1 << 4
kTVMFFIFieldFlagBitMaskDefaultFromFactory = 1 << 5
+ kTVMFFIFieldFlagBitMaskReprOff = 1 << 6
+ kTVMFFIFieldFlagBitMaskCompareOff = 1 << 7
+ kTVMFFIFieldFlagBitMaskHashOff = 1 << 8
kTVMFFIFieldFlagBitMaskInitOff = 1 << 9
kTVMFFIFieldFlagBitMaskKwOnly = 1 << 10
kTVMFFIFieldFlagBitSetterIsFunctionObj = 1 << 11
@@ -233,10 +240,19 @@ cdef extern from "tvm/ffi/c_api.h":
int64_t flags
TVMFFIAny method
+ cdef enum TVMFFISEqHashKind:
+ kTVMFFISEqHashKindUnsupported = 0
+ kTVMFFISEqHashKindTreeNode = 1
+ kTVMFFISEqHashKindFreeVar = 2
+ kTVMFFISEqHashKindDAGNode = 3
+ kTVMFFISEqHashKindConstTreeNode = 4
+ kTVMFFISEqHashKindUniqueInstance = 5
+
ctypedef struct TVMFFITypeMetadata:
TVMFFIByteArray doc
TVMFFIObjectCreator creator
- int64_t total_size
+ int32_t total_size
+ TVMFFISEqHashKind structural_eq_hash_kind
ctypedef struct TVMFFITypeInfo:
int32_t type_index
@@ -298,6 +314,20 @@ cdef extern from "tvm/ffi/c_api.h":
DLDevice TVMFFIDLDeviceFromIntPair(int32_t device_type, int32_t device_id)
nogil
const TVMFFITypeAttrColumn* TVMFFIGetTypeAttrColumn(const TVMFFIByteArray*
attr_name) nogil
+ int32_t TVMFFITypeGetOrAllocIndex(
+ const TVMFFIByteArray* type_key,
+ int32_t static_type_index,
+ int32_t type_depth,
+ int32_t num_child_slots,
+ int32_t child_slots_can_overflow,
+ int32_t parent_type_index
+ ) nogil
+ int TVMFFITypeRegisterField(int32_t type_index, const TVMFFIFieldInfo*
info) nogil
+ int TVMFFITypeRegisterMetadata(int32_t type_index, const
TVMFFITypeMetadata* metadata) nogil
+ int TVMFFITypeRegisterAttr(int32_t type_index, const TVMFFIByteArray*
attr_name,
+ const TVMFFIAny* attr_value) nogil
+ void TVMFFIErrorSetRaisedFromCStr(const char* kind, const char* message)
nogil
+
cdef extern from "tvm/ffi/extra/c_env_api.h":
ctypedef void* TVMFFIStreamHandle