Skip to content

Commit

Permalink
Remove the memory pool, using GC_malloc in more places (including the…
Browse files Browse the repository at this point in the history
… bootstrapped compiler)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17776 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 21, 2013
1 parent d634810 commit 1161177
Show file tree
Hide file tree
Showing 28 changed files with 226 additions and 1,258 deletions.
175 changes: 20 additions & 155 deletions Compiler/Template/CodegenC.tpl

Large diffs are not rendered by default.

43 changes: 0 additions & 43 deletions Compiler/Util/System.mo
Expand Up @@ -39,14 +39,6 @@ encapsulated package System
This module contain a set of system calls, for e.g. compiling and
executing stuff, reading and writing files and so on."

/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
public function removeFirstAndLastChar
input String inString;
output String outString;
external "C" outString=System_removeFirstAndLastChar(inString) annotation(Library = "omcruntime");
end removeFirstAndLastChar;*/

public function trim
"removes chars in charsToRemove from begin and end of inString"
input String inString;
Expand Down Expand Up @@ -409,14 +401,6 @@ public function renameFile "Renames a file, returns 0 if suceeds, implemented us
external "C" res=rename(fileName1,fileName2) annotation(Include="#include <stdio.h>");
end renameFile;

/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
public function getPackageFileNames
input String inString1;
input String inString2;
output String outString;
external "C" outString=System_getPackageFileNames(inString1,inString2) annotation(Library = "omcruntime");
end getPackageFileNames;*/

public function directoryExists
input String inString;
output Boolean outBool;
Expand Down Expand Up @@ -494,27 +478,6 @@ using the asctime() function in time.h (libc)
external "C" timeStr=System_getCurrentTimeStr() annotation(Library = "omcruntime");
end getCurrentTimeStr;

/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
public function isSameFile "Checks if two filenames points to the same file"
input String fileName1;
input String fileName2;
external "C" System_isSameFile(fileName1,fileName2) annotation(Library = "omcruntime");
end isSameFile;*/

/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
public function isIdenticalFile "Checks if two filenames points to the exact same file"
input String fileName1;
input String fileName2;
output Boolean same;
external "C" same=System_isIdenticalFile(fileName1,fileName2) annotation(Library = "omcruntime");
end isIdenticalFile;*/

/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
public function windowsNewline "returns /r/n, since MetaModelica has a bug for representing this as a literal"
output String str;
external "C" str=System_windowsNewline() annotation(Library = "omcruntime");
end windowsNewline;*/

public function os "Returns a string with the operating system name
For linux: 'linux'
Expand All @@ -525,12 +488,6 @@ For Windows : 'Windows_NT' (the name of env var OS )
external "C" str = System_os() annotation(Library = "omcruntime");
end os;

/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
public function compileCFile
input String inString;
external "C" System_compileCFile(inString) annotation(Library = "omcruntime");
end compileCFile;*/

public function readFileNoNumeric
input String inString;
output String outString;
Expand Down
6 changes: 0 additions & 6 deletions Compiler/runtime/Dynload.cpp
Expand Up @@ -164,9 +164,6 @@ static int execute_function(void *in_arg, void **out_arg,
type_description crashbufretarg, retarg;
void *v = NULL;
int retval = 0;
void *states = push_memory_states(1);
state mem_state = get_memory_state();
// fprintf(stderr, "states-ix: %d\n", mem_state);

if (printDebug) { fprintf(stderr, "[dynload]: input parameters:\n"); fflush(stderr); }

Expand All @@ -176,7 +173,6 @@ static int execute_function(void *in_arg, void **out_arg,
while (!listEmpty(v)) {
void *val = RML_CAR(v);
if (value_to_type_desc(val, arg)) {
restore_memory_state(mem_state);
if (printDebug)
{
puttype(arg);
Expand Down Expand Up @@ -215,8 +211,6 @@ static int execute_function(void *in_arg, void **out_arg,
++arg;
}

pop_memory_states(states);

if (retval) {
*out_arg = Values__META_5fFAIL;
return 0;
Expand Down
8 changes: 0 additions & 8 deletions Compiler/runtime/ModelicaExternalC_rml.c
Expand Up @@ -66,9 +66,6 @@ RML_END_LABEL

RML_BEGIN_LABEL(ModelicaExternalC__Streams_5freadLine)
{
state mem_state;

mem_state = get_memory_state();
char* fileName = RML_STRINGDATA(rmlA0), *res = 0;
long line = RML_UNTAGFIXNUM(rmlA1);
int endOfFile = 0, fail = 1;
Expand All @@ -79,7 +76,6 @@ RML_BEGIN_LABEL(ModelicaExternalC__Streams_5freadLine)
if (fail) RML_TAILCALLK(rmlFC);
rmlA0 = mk_scon(res);
rmlA1 = mk_icon(endOfFile);
restore_memory_state(mem_state);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand All @@ -99,9 +95,6 @@ RML_END_LABEL

RML_BEGIN_LABEL(ModelicaExternalC__File_5ffullPathName)
{
state mem_state;

mem_state = get_memory_state();
char* fileName = RML_STRINGDATA(rmlA0), *res = 0;
int fail = 1;
MMC_TRY_TOP();
Expand All @@ -110,7 +103,6 @@ RML_BEGIN_LABEL(ModelicaExternalC__File_5ffullPathName)
MMC_CATCH_TOP();
if (fail) RML_TAILCALLK(rmlFC);
rmlA0 = mk_scon(res);
restore_memory_state(mem_state);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand Down
20 changes: 6 additions & 14 deletions Compiler/runtime/System_omc.c
Expand Up @@ -185,7 +185,7 @@ extern const char* System_basename(const char* str)

extern const char* System_dirname(const char* str)
{
char *cpy = strdup(str);
char *cpy = GC_strdup(str);
char *res = NULL;
#if defined(_MSC_VER)
char drive[_MAX_DRIVE], dir[_MAX_DIR], filename[_MAX_FNAME], extension[_MAX_EXT];
Expand All @@ -195,8 +195,7 @@ extern const char* System_dirname(const char* str)
#else
res = dirname(cpy);
#endif
res = strcpy(ModelicaAllocateString(strlen(res)), res);
free(cpy);
res = GC_strdup(res);
return res;
}

Expand Down Expand Up @@ -292,19 +291,15 @@ extern void* System_strtok(const char *str0, const char *delimit)
{
char *s;
void *res = mmc_mk_nil();
char *str = strdup(str0);
char *str = GC_strdup(str0);
s=strtok(str,delimit);
if (s == NULL)
{
free(str);
if (s == NULL) {
return res;
}
res = mmc_mk_cons(mmc_mk_scon(s),res);
while ((s=strtok(NULL,delimit)))
{
while ((s=strtok(NULL,delimit))) {
res = mmc_mk_cons(mmc_mk_scon(s),res);
}
free(str);
return listReverse(res);
}

Expand Down Expand Up @@ -372,9 +367,7 @@ const char* System_getClassnamesForSimulation()

void System_setClassnamesForSimulation(const char *class_names)
{
if(class_names_for_simulation)
free(class_names_for_simulation);
class_names_for_simulation = strdup(class_names);
class_names_for_simulation = GC_strdup(class_names);
}

extern double System_getVariableValue(double _timeStamp, void* _timeValues, void* _varValues)
Expand Down Expand Up @@ -670,7 +663,6 @@ extern void System_getLoadModelPath(const char *className, void *prios, void *mp
*name = NULL;
if (SystemImpl__getLoadModelPath(className,prios,mps,dir,name,isDir)) MMC_THROW();
char *res = strcpy(ModelicaAllocateString(strlen(*name)),*name);
free(*name);
*name = res;
}

Expand Down

0 comments on commit 1161177

Please sign in to comment.