/*--------------------------------------------------------------------------*/ BOOL LoadFunctionsJVM(char *filedynlib) { #ifdef _MSC_VER if (filedynlib == NULL) { hLibJVM = LoadDynLibraryW(L"jvm.dll"); } else { wchar_t * wcfiledynlib = to_wide_string(filedynlib); if (wcfiledynlib) { hLibJVM = LoadDynLibraryW(wcfiledynlib); FREE(wcfiledynlib); wcfiledynlib = NULL; } } #else #ifdef __APPLE__ /* ** After MacOSX 10.6.8 manually load libjava.jnilib make JNI_* functions crash ** Rely on OS by using dlopen(NULL) to find correct symbol with dlsym */ hLibJVM = LoadDynLibrary(NULL); #else if (filedynlib == NULL) { hLibJVM = LoadDynLibrary(NULL); } else { hLibJVM = LoadDynLibrary(filedynlib); } #endif #endif if (hLibJVM) { ptr_JNI_GetDefaultJavaVMInitArgs = (JNI_GetDefaultJavaVMInitArgsPROC) GetDynLibFuncPtr(hLibJVM, "JNI_GetDefaultJavaVMInitArgs" ); ptr_JNI_CreateJavaVM = (JNI_CreateJavaVMPROC) GetDynLibFuncPtr(hLibJVM, "JNI_CreateJavaVM" ); ptr_JNI_GetCreatedJavaVMs = (JNI_GetCreatedJavaVMsPROC) GetDynLibFuncPtr(hLibJVM, "JNI_GetCreatedJavaVMs" ); if (ptr_JNI_GetDefaultJavaVMInitArgs && ptr_JNI_CreateJavaVM && ptr_JNI_GetCreatedJavaVMs) { bSymbolsLoaded = TRUE; return TRUE; } } return FALSE; }
/*---------------------------------------------------------------------------*/ int Sci_dlopen( char *loaded_file) { static DynLibHandle hd1 = NULL; int i = 0; #ifdef _MSC_VER { wchar_t *wcfilename = to_wide_string(loaded_file); if (wcfilename) { hd1 = LoadDynLibraryW(wcfilename); FREE(wcfilename); wcfilename = NULL; } } #else hd1 = LoadDynLibrary (loaded_file); #endif if ( hd1 == NULL ) { return -1 ; /* the shared archive was not loaded. */ } for ( i = 0 ; i < Nshared ; i++ ) { if ( hd[i].ok == FALSE) { hd[i].shl = (unsigned long long)hd1; hd[i].ok = TRUE; return(i); } } if ( Nshared == ENTRYMAX ) { if (getIlibVerboseLevel() != ILIB_VERBOSE_NO_OUTPUT) { sciprint(_("Cannot open shared files max entry %d reached.\n"), ENTRYMAX); } return(FALSE); } hd[Nshared].shl = (unsigned long long)hd1; hd[Nshared].ok = TRUE; Nshared ++; return Nshared - 1; }
/*--------------------------------------------------------------------------*/ dynamic_gateway_error_code callDynamicGateway(char *moduleName, char *dynLibName, char *gw_name, DynLibHandle *hlib, PROC_GATEWAY *ptrGateway) { if (*hlib == NULL) { #ifdef _MSC_VER wchar_t *wcdynLibName = to_wide_string(dynLibName); if (wcdynLibName) { *hlib = LoadDynLibraryW(wcdynLibName); FREE(wcdynLibName); wcdynLibName = NULL; } if (*hlib == NULL) { return DYN_GW_LOAD_LIBRARY_ERROR; } #else /* First step, we are considering that we are in the source tree. * Therefor, the lib should be in modules/xxx/.libs/ * * Otherwise, dlopen will search in various places (for example, the install specified * by --prefix). * This leads to serious and unexpected bugs like #8883 * The original bug report for this issue was the bug #2875 */ char *SciPath = getSCIpath(); #define PATHTOMODULE "/modules/" #ifndef LT_OBJDIR #define LT_OBJDIR ".libs/" #endif /* Build the full path to the library */ char *pathToLib = (char*) MALLOC((strlen(SciPath) + strlen(PATHTOMODULE) + strlen(moduleName) + strlen("/") + strlen(LT_OBJDIR) + strlen(dynLibName) + 1) * sizeof(char)); sprintf(pathToLib, "%s%s%s/%s%s", SciPath, PATHTOMODULE, moduleName, LT_OBJDIR, dynLibName); /* Load the library with the Scilab source-tree paths */ *hlib = LoadDynLibrary(pathToLib); if (*hlib == NULL) /* Load of the hardcoded path to the lib failed */ { if (FileExist(pathToLib)) { /* It fails but the file exists */ char *previousError = GetLastDynLibError(); if (previousError != NULL) { sciprint("A previous error has been detected while loading %s: %s\n", dynLibName, previousError); } } /* Under Linux/Unix, load thanks to dlopen on the system. * In the binary, the LD_LIBRARY_PATH is declared in the startup script (ie bin/scilab*) * Note that it is not possible to update the LD_LIBRARY_PATH at run time. */ *hlib = LoadDynLibrary(dynLibName); if (*hlib == NULL) { char *previousError = GetLastDynLibError(); if (previousError != NULL) { sciprint("A previous error has been detected while loading %s: %s\n", dynLibName, previousError); } if (SciPath) { FREE(SciPath); SciPath = NULL; } if (pathToLib) { FREE(pathToLib); pathToLib = NULL; } return DYN_GW_LOAD_LIBRARY_ERROR; } } if (SciPath) { FREE(SciPath); SciPath = NULL; } if (pathToLib) { FREE(pathToLib); pathToLib = NULL; } #endif } if (*ptrGateway == NULL) { *ptrGateway = (PROC_GATEWAY) GetDynLibFuncPtr(*hlib, gw_name); if (*ptrGateway == NULL) { return DYN_GW_PTR_FUNCTION_ERROR ; } } if ( (*hlib) && (*ptrGateway) ) { (*ptrGateway)(); return DYN_GW_NO_ERROR; } return DYN_GW_CALL_FUNCTION_ERROR; }