|
1 | 1 | # cython: language_level=3
|
2 | 2 | import ctypes
|
3 | 3 | import itertools
|
| 4 | +import os |
4 | 5 | from libcpp.vector cimport vector
|
5 | 6 | from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t
|
6 | 7 | from libc.stdlib cimport malloc, free
|
@@ -407,7 +408,13 @@ cdef class PyAny:
|
407 | 408 | func = _vtable_get_func_ptr(vtable, type_index, True)
|
408 | 409 | except Exception as e: # no-cython-lint
|
409 | 410 | raise TypeError(f"Cannot find method `{name}` for type: {cls}") from e
|
410 |
| - _func_call_impl(func, args, &c_ret) |
| 411 | + if CXX_STACKTRACE_ENABLED: |
| 412 | + _func_call_impl(func, args, &c_ret) |
| 413 | + else: |
| 414 | + try: |
| 415 | + _func_call_impl(func, args, &c_ret) |
| 416 | + except Exception as e: # no-cython-lint |
| 417 | + raise e.with_traceback(None) |
411 | 418 | return _any_c2py_no_inc_ref(c_ret)
|
412 | 419 |
|
413 | 420 | cdef class Str(str):
|
@@ -1699,6 +1706,16 @@ cpdef list type_table():
|
1699 | 1706 | return list(TYPE_INDEX_TO_INFO)
|
1700 | 1707 |
|
1701 | 1708 |
|
| 1709 | +cpdef void toggle_cxx_stacktrace(bint enable): |
| 1710 | + global CXX_STACKTRACE_ENABLED |
| 1711 | + CXX_STACKTRACE_ENABLED = enable |
| 1712 | + |
| 1713 | + |
| 1714 | +cpdef bint cxx_stacktrace_enabled(): |
| 1715 | + global CXX_STACKTRACE_ENABLED |
| 1716 | + return CXX_STACKTRACE_ENABLED |
| 1717 | + |
| 1718 | + |
1702 | 1719 | cdef const char* _DLPACK_CAPSULE_NAME = "dltensor"
|
1703 | 1720 | cdef const char* _DLPACK_CAPSULE_NAME_USED = "used_dltensor"
|
1704 | 1721 | cdef const char* _DLPACK_CAPSULE_NAME_VER = "dltensor_versioned"
|
@@ -1735,3 +1752,4 @@ cdef MLCFunc* _OPAQUE_INIT = _vtable_get_func_ptr(_VTABLE_INIT, kMLCOpaque, Fals
|
1735 | 1752 | cdef MLCFunc* _TENSOR_INIT = _vtable_get_func_ptr(_vtable_get_global(b"__init_DLManagedTensor"), kMLCTensor, False)
|
1736 | 1753 | cdef MLCFunc* _TENSOR_INIT_VER = _vtable_get_func_ptr(_vtable_get_global(b"__init_DLManagedTensorVersioned"), kMLCTensor, False) # no-cython-lint
|
1737 | 1754 | cdef tuple _OPAQUE_TYPES = ()
|
| 1755 | +cdef bint CXX_STACKTRACE_ENABLED = os.environ.get("MLC_SHOW_CPP_STACKTRACES", "0") == "1" |
0 commit comments