androidNoDemangleStub top-level constant
String
const androidNoDemangleStub
Tail of every dart_api_dl.c copy (nitro's src/native one included):
keeps libc++abi's demangler out of an Android plugin library (#68).
Implementation
const String androidNoDemangleStub = r'''
/* Android links libc++ statically into each plugin library, and its default
* terminate handler is the one caller of __cxa_demangle: that call alone pulls
* the whole demangler (about 170 KB per ABI) into the library. This definition
* keeps it out and hands the name back unchanged, in a buffer the caller frees
* as usual, so a caller that never checks the result still gets a string. The
* visible change: names stay mangled, e.g. an uncaught C++ exception aborts
* with St13runtime_error in the log. Build with -DNITRO_KEEP_DEMANGLER if your
* own native code needs readable names from abi::__cxa_demangle. */
#if defined(__ANDROID__) && !defined(NITRO_KEEP_DEMANGLER)
#include <stdlib.h>
#ifdef __cplusplus
extern "C"
#endif
__attribute__((weak, visibility("hidden"))) char* __cxa_demangle(
const char* mangled, char* out, size_t* length, int* status) {
if (mangled == NULL || (out != NULL && length == NULL)) {
if (status) *status = -3;
return NULL;
}
size_t need = strlen(mangled) + 1;
if (out == NULL || *length < need) {
out = (char*)realloc(out, need);
if (out == NULL) {
if (status) *status = -1;
return NULL;
}
if (length) *length = need;
}
memcpy(out, mangled, need);
if (status) *status = 0;
return out;
}
#endif
''';