@@ -6501,14 +6501,18 @@ bool TCling::LibraryLoadingFailed(const std::string& errmessage, const std::stri
65016501 return false ;
65026502}
65036503
6504- static void * LazyFunctionCreatorAutoloadForModule (const std::string &mangled_name,
6505- const cling::DynamicLibraryManager &DLM) {
6504+ // //////////////////////////////////////////////////////////////////////////////
6505+ // / Autoload a library based on a missing symbol.
6506+
6507+ void * TCling::LazyFunctionCreatorAutoload (const std::string& mangled_name) {
6508+
6509+ const cling::DynamicLibraryManager &DLM = *GetInterpreterImpl ()->getDynamicLibraryManager ();
65066510 R__LOCKGUARD (gInterpreterMutex );
65076511
65086512 auto LibLoader = [](const std::string& LibName) -> bool {
65096513 if (gSystem ->Load (LibName.c_str (), " " , false ) < 0 ) {
6510- Error (" TCling__LazyFunctionCreatorAutoloadForModule" ,
6511- " Failed to load library %s" , LibName.c_str ());
6514+ :: Error (" TCling__LazyFunctionCreatorAutoloadForModule" ,
6515+ " Failed to load library %s" , LibName.c_str());
65126516 return false ;
65136517 }
65146518 return true ; // success.
@@ -6536,103 +6540,6 @@ static void* LazyFunctionCreatorAutoloadForModule(const std::string &mangled_nam
65366540 return nullptr ;
65376541
65386542 return llvm::sys::DynamicLibrary::SearchForAddressOfSymbol (mangled_name);
6539-
6540- }
6541-
6542- // //////////////////////////////////////////////////////////////////////////////
6543- // / Autoload a library based on a missing symbol.
6544-
6545- void * TCling::LazyFunctionCreatorAutoload (const std::string& mangled_name) {
6546- if (fCxxModulesEnabled )
6547- return LazyFunctionCreatorAutoloadForModule (mangled_name,
6548- *GetInterpreterImpl ()->getDynamicLibraryManager ());
6549-
6550- // First see whether the symbol is in the library that we are currently
6551- // loading. It will have access to the symbols of its dependent libraries,
6552- // thus checking "back()" is sufficient.
6553- if (!fRegisterModuleDyLibs .empty ()) {
6554- if (void * addr = dlsym (fRegisterModuleDyLibs .back (),
6555- mangled_name.c_str ())) {
6556- return addr;
6557- }
6558- }
6559-
6560- int err = 0 ;
6561- char * demangled_name_c = TClassEdit::DemangleName (mangled_name.c_str (), err);
6562- if (err) {
6563- return 0 ;
6564- }
6565-
6566- std::string name (demangled_name_c);
6567- free (demangled_name_c);
6568-
6569- // fprintf(stderr, "demangled name: '%s'\n", demangled_name);
6570- //
6571- // Separate out the class or namespace part of the
6572- // function name.
6573- //
6574-
6575- std::string::size_type pos = name.find (" __thiscall " );
6576- if (pos != std::string::npos) {
6577- name.erase (0 , pos + sizeof (" __thiscall " )-1 );
6578- }
6579- pos = name.find (" __cdecl " );
6580- if (pos != std::string::npos) {
6581- name.erase (0 , pos + sizeof (" __cdecl " )-1 );
6582- }
6583- if (!strncmp (name.c_str (), " typeinfo for " , sizeof (" typeinfo for " )-1 )) {
6584- name.erase (0 , sizeof (" typeinfo for " )-1 );
6585- } else if (!strncmp (name.c_str (), " vtable for " , sizeof (" vtable for " )-1 )) {
6586- name.erase (0 , sizeof (" vtable for " )-1 );
6587- } else if (!strncmp (name.c_str (), " operator" , sizeof (" operator" )-1 )
6588- && !isalnum (name[sizeof (" operator" )])) {
6589- // operator...(A, B) - let's try with A!
6590- name.erase (0 , sizeof (" operator" )-1 );
6591- pos = name.rfind (' (' );
6592- if (pos != std::string::npos) {
6593- name.erase (0 , pos + 1 );
6594- pos = name.find (" ," );
6595- if (pos != std::string::npos) {
6596- // remove next arg up to end, leaving only the first argument type.
6597- name.erase (pos);
6598- }
6599- pos = name.rfind (" const" );
6600- if (pos != std::string::npos) {
6601- name.erase (pos, strlen (" const" ));
6602- }
6603- while (!name.empty () && strchr (" &*" , name.back ()))
6604- name.erase (name.length () - 1 );
6605- }
6606- } else {
6607- TClassEdit::FunctionSplitInfo fsi;
6608- TClassEdit::SplitFunction (name, fsi);
6609- name = fsi.fScopeName ;
6610- }
6611- // fprintf(stderr, "name: '%s'\n", name.c_str());
6612- // Now we have the class or namespace name, so do the lookup.
6613- TString libs = GetClassSharedLibs (name.c_str ());
6614- if (libs.IsNull ()) {
6615- // Not found in the map, all done.
6616- return 0 ;
6617- }
6618- // fprintf(stderr, "library: %s\n", iter->second.c_str());
6619- // Now we have the name of the libraries to load, so load them.
6620-
6621- TString lib;
6622- Ssiz_t posLib = 0 ;
6623- while (libs.Tokenize (lib, posLib)) {
6624- if (gSystem ->Load (lib, " " , kFALSE /* system*/ ) < 0 ) {
6625- // The library load failed, all done.
6626- // fprintf(stderr, "load failed: %s\n", errmsg.c_str());
6627- return 0 ;
6628- }
6629- }
6630-
6631- // fprintf(stderr, "load succeeded.\n");
6632- // Get the address of the function being called.
6633- void * addr = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol (mangled_name.c_str ());
6634- // fprintf(stderr, "addr: %016lx\n", reinterpret_cast<unsigned long>(addr));
6635- return addr;
66366543}
66376544
66386545// //////////////////////////////////////////////////////////////////////////////
0 commit comments