diff --git a/.CI/common.groovy b/.CI/common.groovy index e98d64724fe..56a9eefda55 100644 --- a/.CI/common.groovy +++ b/.CI/common.groovy @@ -201,8 +201,16 @@ void buildOMC(CC, CXX, extraFlags, Boolean buildCpp, Boolean clean) { echo rm -rf ./M* ./OMCppM* echo cd .. echo rm -rf .sanity-check + echo echo Testing some models from testsuite, ffi, meta echo cd testsuite/flattening/libraries/biochem echo ../../../rtest --return-with-error-code EnzMM.mos + echo cd \${MSYS_WORKSPACE} + echo cd testsuite/flattening/modelica/ffi + echo ../../../rtest --return-with-error-code ModelicaInternal_countLines.mos + echo ../../../rtest --return-with-error-code Integer1.mos + echo cd \${MSYS_WORKSPACE} + echo cd testsuite/metamodelica/meta + echo ../../rtest --return-with-error-code AlgPatternm.mos echo echo Testing if we can compile in a path with spaces echo cd \${MSYS_WORKSPACE} echo mkdir -p ./path\\ with\\ space/ diff --git a/OMCompiler/Compiler/boot/Makefile.omdev.mingw b/OMCompiler/Compiler/boot/Makefile.omdev.mingw index 57723781dd8..926f216a46c 100644 --- a/OMCompiler/Compiler/boot/Makefile.omdev.mingw +++ b/OMCompiler/Compiler/boot/Makefile.omdev.mingw @@ -47,7 +47,7 @@ LDFLAGS=-L./ $(LOMPARSE) $(LCOMPILERRUNTIME) -L"$(OMHOME)/lib/omc" \ -lzmq \ $(OMENCRYPTIONLIBS) \ $(LDFLAGS_CURL) \ -$(EXTRA_LD_FLAGS) +$(EXTRA_LD_FLAGS) -Wl,--export-all-symbols FMILIB = -L$(TOP_DIR)/3rdParty/FMIL/install/lib -lfmilib CPPFLAGS=-I"$(OMHOME)/include/omc/c" -I../Util/ -DADD_METARECORD_DEFINITIONS= diff --git a/OMCompiler/Compiler/runtime/systemimpl.c b/OMCompiler/Compiler/runtime/systemimpl.c index 4edd5882744..be176f3eee1 100644 --- a/OMCompiler/Compiler/runtime/systemimpl.c +++ b/OMCompiler/Compiler/runtime/systemimpl.c @@ -79,6 +79,7 @@ typedef void* iconv_t; #if defined(__MINGW32__) || defined(_MSC_VER) #include +#include #define getFunctionPointerFromDLL GetProcAddress #define FreeLibraryFromHandle !FreeLibrary @@ -1325,8 +1326,8 @@ static const char* SystemImpl__getUUIDStr(void) { static char uuidStr[37] = "8c4e810f-3df3-4a00-8276-176fa3c9f9e0"; #if defined(__MINGW32__) || defined(_MSC_VER) - unsigned char *tmp; - UUID uuid; + unsigned char *tmp = NULL; + UUID uuid = {0}; if (UuidCreate(&uuid) == RPC_S_OK) UuidToString(&uuid, &tmp); tmp[36] = '\0'; @@ -1372,7 +1373,9 @@ int SystemImpl__loadLibrary(const char *str, int relativePath, int printDebug) } h = LoadLibrary(libname); - } else { + } else { /* no library name, fetch current module handle */ + /* set the libname */ + strcpy(libname, "[own process]"); h = GetModuleHandle(0); } @@ -1394,16 +1397,6 @@ int SystemImpl__loadLibrary(const char *str, int relativePath, int printDebug) return -1; } - /* adrpo, pass the mmc_GC_state pointer from the current process! - mmc_GC_set_state_lib_function = (mmc_GC_function_set_gc_state)getFunctionPointerFromDLL(h, "mmc_GC_set_state"); - if (mmc_GC_set_state_lib_function == NULL) { - fprintf(stderr, "Unable to get pointer for mmc_GC_set_state in %s!\n", libname); - fflush(stderr); - return -1; - } - mmc_GC_set_state_lib_function(mmc_GC_state); - */ - libIndex = alloc_ptr(); if (libIndex < 0) { //fprintf(stderr, "Error loading library %s!\n", libname); fflush(stderr); @@ -1450,16 +1443,6 @@ int SystemImpl__loadLibrary(const char *str, int relativePath, int printDebug) return -1; } - /* adrpo, pass the mmc_GC_state pointer from the current process! - mmc_GC_set_state_lib_function = (mmc_GC_function_set_gc_state)getFunctionPointerFromDLL(h, "mmc_GC_set_state"); - if (mmc_GC_set_state_lib_function == NULL) { - fprintf(stderr, "Unable to get pointer for mmc_GC_set_state in %s!\n", libname); - fflush(stderr); - return -1; - } - mmc_GC_set_state_lib_function(mmc_GC_state); - */ - libIndex = alloc_ptr(); if (libIndex < 0) { fprintf(stderr, "Error loading library %s!\n", libname); fflush(stderr); @@ -1535,6 +1518,7 @@ int SystemImpl__lookupFunction(int libIndex, const char *str) modelica_ptr_t lib = NULL, func = NULL; function_t funcptr; int funcIndex; + long lastError = 0; lib = lookup_ptr(libIndex); @@ -1542,12 +1526,56 @@ int SystemImpl__lookupFunction(int libIndex, const char *str) return -1; funcptr = (int (*)(threadData_t*, type_description*, type_description*)) getFunctionPointerFromDLL(lib->data.lib, str); + lastError = GetLastError(); + +#if defined(__MINGW32__) || defined(_MSC_VER) + /* windows is special :) + * if we didn't find the function, search it in all the loaded DLLs as Linux does + */ + if (funcptr == NULL) { + HMODULE hMods[1024]; + HMODULE hProcess = GetCurrentProcess(); + DWORD cbNeeded; + unsigned int i; + char szModName[MAX_PATH]; + + /* see if the GetModuleHandle(0) is in the current process and an executable */ + if ( GetModuleFileNameEx( hProcess, lib->data.lib, szModName, sizeof(szModName) / sizeof(char)) ) + { + // if strcmp(szModName[strlen(szModName)-4], ".exe") + if ( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded) ) + { + for ( i = 0; i < (cbNeeded / sizeof(modelica_integer)); i++ ) + { + funcptr = (int (*)(threadData_t*, type_description*, type_description*)) getFunctionPointerFromDLL(hMods[i], str); + if (funcptr != NULL) + { + break; + } + + /* // uncomment for debugging + { + if ( GetModuleFileNameEx( hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(char)) ) + { + fprintf(stderr, "function %s in %s handle:[%p][%d] funcptr[%p] GetLastError:%d\n", str, szModName, hMods[i], i, funcptr, GetLastError()); fflush(NULL); + } + } + */ + } + } + } + } +#endif if (funcptr == NULL) { const char* err_toks[2]; char id_buf[11]; - snprintf(id_buf, 11, "%lu", GetLastError()); + snprintf(id_buf, 11, "%lu", lastError); +#if defined(__MINGW32__) || defined(_MSC_VER) err_toks[0] = id_buf; +#else + err_toks[0] = dlerror(); +#endif err_toks[1] = str; c_add_message(NULL, -1, ErrorType_runtime, ErrorLevel_error, gettext("Unable to find `%s': %s.\n"), err_toks, 2); return -1;