Opened 12 years ago

Closed 12 years ago

#2032 closed defect (fixed)

Implement loadResource

Reported by: Martin Sjölund Owned by: Martin Sjölund
Priority: high Milestone: 1.9.0
Component: Frontend Version: trunk
Keywords: Cc: Christian Schubert, Adrian Pop

Description

ModelicaServices.ExternalReferences.loadResource has a default implementation fileReference:=Modelica.Utilities.Files.fullPathName(uri). We should support modelica:// and file:// as well.

Change History (16)

comment:1 by Martin Sjölund, 12 years ago

Owner: changed from somebody to Martin Sjölund
Status: newaccepted

comment:2 by Martin Sjölund, 12 years ago

Works in r14920 (I think).

comment:3 by Martin Sjölund, 12 years ago

Resolution: fixed
Status: acceptedclosed

comment:4 by Christian Schubert, 12 years ago

Resolution: fixed
Status: closedreopened

Now, building with +target=msvc does not work anymore since the linker fails to find the required function

int System_regexModelica(const char* str, const char* re, int maxn, int extended, int sensitive, char **matches)

which is defined in

Compiler/Runtime/System_omc.c

Unfortunately the "libomcruntime" is not being build for Visual Studio.
I tried building a "minimalistic" omcruntime for Visual Studio but failed miserably, since I do not understand the rml dependencies.
This is as far as I got in CMake (added to SimulationRuntime/c/CMakeListst.txt):

# Generate minimalistic omcruntime for visual studio
IF(MSVC)

  # includes
  INCLUDE_DIRECTORIES(${OMCTRUNCHOME})
  INCLUDE_DIRECTORIES(${OMCTRUNCHOME}/Compiler)
  INCLUDE_DIRECTORIES(${OMCTRUNCHOME}/SimulationRuntime/c)
  INCLUDE_DIRECTORIES(${OMCTRUNCHOME}/SimulationRuntime/c/meta)
  INCLUDE_DIRECTORIES(${OMCTRUNCHOME}/SimulationRuntime/c/meta/gc)
  INCLUDE_DIRECTORIES(${OMCTRUNCHOME}/SimulationRuntime/c/ModelicaExternalC)
  INCLUDE_DIRECTORIES(${OMCTRUNCHOME}/SimulationRuntime/c/simulation/libf2c)
  INCLUDE_DIRECTORIES(${OMCTRUNCHOME}/SimulationRuntime/c/util) 
  
  # OMDEV PATH
  IF(NOT OMDEV)
    SET(OMDEV $ENV{OMDEV})
  ENDIF(NOT OMDEV)

  INCLUDE_DIRECTORIES(${OMDEV}/compile-here/liblpsolve5)

  # Sources and Headers
  SET(OMCRUNTIME_SRC ${OMCTRUNCHOME}/Compiler/runtime/System_omc.c
                     ${OMCTRUNCHOME}/Compiler/runtime/errorext.cpp )
  SET_SOURCE_FILES_PROPERTIES( ${OMCTRUNCHOME}/Compiler/runtime/System_omc.c PROPERTIES LANGUAGE CXX )
  
  # Library omcruntime
  add_library(omcruntime  ${OMCRUNTIME_SRC})
  TARGET_LINK_LIBRARIES(omcruntime util f2c meta ModelicaExternalC)

  # Install
  INSTALL(TARGETS omcruntime
	  	  ARCHIVE DESTINATION lib/omc)				
ENDIF(MSVC)

Maybe Adrian can have a look at it?

comment:5 by Adrian Pop, 12 years ago

Cc: Adrian Pop added

comment:6 by Adrian Pop, 12 years ago

Oh.
Compiling Compiler/runtime with Visual Studio is not
easy and it will take quite some time to setup properly.

Why is this function needed in System_omc.c and why cannot be moved in the runtime system?
We anyway link omc with the runtime system so why not have it there?

comment:7 by Adrian Pop, 12 years ago

Also I don't think we have libregex compiled with VS or any of the other Compiler dependencies.

Last edited 12 years ago by Adrian Pop (previous) (diff)

comment:8 by Adrian Pop, 12 years ago

From sytemimpl.c:

extern void* SystemImpl__regex(const char* str, const char* re, int maxn, int extended, int sensitive, int *nmatch)
{
  void *lst = mk_nil();
#if !defined(_MSC_VER) /* crap compiler doesn't have regex */

so you cannot use it for VS.
One would need to compile libregex with VS and add it to OMDev.

comment:9 by Martin Sjölund, 12 years ago

Yes, you could move regex to the regular runtime and always link against it. I'm fine with that. But then you would need regex dependencies for the simulation runtime.

The alternative would be to rewrite the URI parsing without using regex. But regex is so useful it should be used everywhere.

comment:10 by Adrian Pop, 12 years ago

Agreed. I looked a bit on what's available for VS for regular expressions and
it seems is a bit of confusion there. As far as I know it should be in STL:
http://stackoverflow.com/questions/4716098/regular-expressions-in-c-stl
so we might use that for VS. I'll look more to see if I can find a better way.

comment:11 by Adrian Pop, 12 years ago

I now added trunk/3rdParty/regex-0.12 to be used with Visual Studio (compiled in with the SimulationRuntime system).
Martin will move the regex stuff in the SimulationRuntime and hopefully we'll have this working in VS too.

comment:12 by Adrian Pop, 12 years ago

Christian, can you change the msvc compilation of SimulationRuntime to include also trunk/3rdParty/regex-0.12/regex.c.
I just checked and it will compile with VS (made some small changes so that it does).

comment:13 by Martin Sjölund, 12 years ago

It will be required to compile this in now since utility.c now depends on regex.h

comment:14 by Christian Schubert, 12 years ago

done and it seems to work now

comment:15 by Martin Sjölund, 12 years ago

Noooo.... Never ever change a VLA (variable-length array) to malloc+free. Replace it with an #ifdef for MSVC only. Malloc is a hell we can avoid easily on other OS'es.

comment:16 by Martin Sjölund, 12 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.