You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This feature simplifies C++ library integration of MLC by avoiding
double registration.
**What is and when double registration happens**. Originally, macro
`MLC_DEF_{DYN/STATIC}_TYPE` and `MLC_DEF_OBJ_REF` registers an MLC
object's type key and reflection information into the global type table,
and those macros are idiomatically used in public header files. It
means, if there's a different DLL that includes MLC headers, the
registration of MLC objects will be performed again at loading time of
this DLL.
**Implication of double registration**. Double registration is
practically harmless in most of the cases, as long as libraries are not
dynamically unloaded, and in our case, ABI issue is carefully avoided.
However, it may take a significant hit in compilation time and is not
usually best practice for potential ABI issues.
**Solution**. This PR introduces a new parameter `IS_EXPORT` to the
three macros above, as part of the practice where we define macros like
`MLC_EXPORTS` already in C++. When it is set to `False`, all the
registrations are skipped and the macros instead look up the type table
for already-existed information.
Note that while setting `IS_EXPORT` can be tedious, it could be resolved
by wrapping it with a simpler macro:
```C++
// Step 1. Check `MY_LIB_EXPORTS`
#ifndef MY_LIB_EXPORTS
#define MY_LIB_EXPORTS 0
#else
#undef MY_LIB_EXPORTS
#define MY_LIB_EXPORTS 1
#endif
// Step 2. Wrap `MLC_*` macros using new macros
#define MY_LIB_DEF_OBJ(A, B, C) \
MLC_DEF_DYN_TYPE(MY_LIB_EXPORTS, A, B, C)
#define MY_LIB_DEF_OBJ_REF(A, B, C) \
MLC_DEF_OBJ_REF(MY_LIB_EXPORTS, A, B, C)
```
This PR also refactors the existing approach accessing `libmlc.so`,
limiting the access to MLC C APIs via `mlc::Lib` defined in `lib.h`,
which exposes a global MLC type table handle as an inline static member.
0 commit comments