Skip to content

Commit

Permalink
Keep track of more memory allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Apr 5, 2016
1 parent 8287b0b commit d89da7c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Compiler/runtime/Error_omc.cpp
Expand Up @@ -71,13 +71,13 @@ extern void* Error_getMessages(threadData_t *threadData)
extern const char* Error_printErrorsNoWarning(threadData_t *threadData)
{
std::string res = ErrorImpl__printErrorsNoWarning(threadData);
return GC_strdup(res.c_str());
return omc_alloc_interface.malloc_strdup(res.c_str());
}

extern const char* Error_printMessagesStr(threadData_t *threadData,int warningsAsErrors)
{
std::string res = ErrorImpl__printMessagesStr(threadData,warningsAsErrors);
return GC_strdup(res.c_str());
return omc_alloc_interface.malloc_strdup(res.c_str());
}

extern void Error_addSourceMessage(threadData_t *threadData,int _id, void *msg_type, void *severity, int _sline, int _scol, int _eline, int _ecol, int _read_only, const char* _filename, const char* _msg, void* tokenlst)
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/SimulationResultsCmp.c
Expand Up @@ -83,7 +83,7 @@ static char ** getVars(void *vars, unsigned int* nvars)

/* Copy the variable names from the MetaModelica list to the string array. */
for(; MMC_NILHDR != MMC_GETHDR(vars); vars = MMC_CDR(vars)) {
cmpvars[i++] = GC_strdup(MMC_STRINGDATA(MMC_CAR(vars)));
cmpvars[i++] = omc_alloc_interface.malloc_strdup(MMC_STRINGDATA(MMC_CAR(vars)));
}

*nvars = ncmpvars;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/SimulationResultsCmpTubes.c
Expand Up @@ -800,7 +800,7 @@ fprintf(fout, "{title: '%s',\n"

fclose(fout);
if (isHtml) {
*htmlOut = GC_strdup(html);
*htmlOut = omc_alloc_interface.malloc_strdup(html);
free(html);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Compiler/runtime/System_omc.c
Expand Up @@ -204,7 +204,7 @@ extern const char* System_basename(const char* str)

extern const char* System_dirname(const char* str)
{
char *cpy = GC_strdup(str);
char *cpy = omc_alloc_interface.malloc_strdup(str);
char *res = NULL;
#if defined(_MSC_VER)
char drive[_MAX_DRIVE], dir[_MAX_DIR], filename[_MAX_FNAME], extension[_MAX_EXT];
Expand Down Expand Up @@ -318,7 +318,7 @@ extern void* System_strtok(const char *str0, const char *delimit)
{
char *s;
void *res = mmc_mk_nil();
char *str = GC_strdup(str0);
char *str = omc_alloc_interface.malloc_strdup(str0);
char *saveptr;
s=strtok_r(str,delimit,&saveptr);
if (s == NULL) {
Expand Down Expand Up @@ -395,7 +395,7 @@ const char* System_getClassnamesForSimulation()

void System_setClassnamesForSimulation(const char *class_names)
{
class_names_for_simulation = GC_strdup(class_names);
class_names_for_simulation = omc_alloc_interface.malloc_strdup(class_names);
}

extern double System_getVariableValue(double _timeStamp, void* _timeValues, void* _varValues)
Expand Down Expand Up @@ -727,7 +727,7 @@ extern const char* System_realpath(const char *path)
if (realpath(path, buf) == NULL) {
MMC_THROW();
}
return GC_strdup(buf);
return omc_alloc_interface.malloc_strdup(buf);
}

extern int System_fileIsNewerThan(const char *file1, const char *file2)
Expand Down
12 changes: 6 additions & 6 deletions Compiler/runtime/settingsimpl.c
Expand Up @@ -118,7 +118,7 @@ const char* SettingsImpl__getInstallationDirectoryPath(void) {
fprintf(stderr, "proc_pidpath() failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
} else {
omhome = GC_strdup(info.dli_fname);
omhome = omc_alloc_interface.malloc_strdup(info.dli_fname);
stripbinpath(omhome);
}
init = 1;
Expand Down Expand Up @@ -214,7 +214,7 @@ char* Settings_getHomeDir(int runningTestsuite)
if (homePath == NULL || runningTestsuite) {
return "";
}
return GC_strdup(homePath);
return omc_alloc_interface.malloc_strdup(homePath);
}

// Do not free the returned variable. It's malloc'ed
Expand All @@ -237,7 +237,7 @@ char* SettingsImpl__getModelicaPath(int runningTestsuite) {
#if !(defined(_MSC_VER) || defined(__MINGW32__))
} else {
int lenHome = strlen(homePath);
buffer = (char*) GC_malloc_atomic(lenOmhome+lenHome+41);
buffer = (char*) omc_alloc_interface.malloc_atomic(lenOmhome+lenHome+41);
snprintf(buffer,lenOmhome+lenHome+41,"%s/lib/omlibrary:%s/.openmodelica/libraries/",omhome,homePath);
}
#endif
Expand All @@ -247,11 +247,11 @@ char* SettingsImpl__getModelicaPath(int runningTestsuite) {
#if defined(__MINGW32__) || defined(_MSC_VER)
/* adrpo: translate this to forward slashes! */
/* duplicate the path */
winLibPath = GC_strdup(path);
winLibPath = omc_alloc_interface.malloc_strdup(path);

/* ?? not enough memory for duplication */
if (!winLibPath)
return GC_strdup(path);
return omc_alloc_interface.malloc_strdup(path);

/* convert \\ to / */
while(winLibPath[i] != '\0')
Expand All @@ -262,7 +262,7 @@ char* SettingsImpl__getModelicaPath(int runningTestsuite) {
return winLibPath;
#endif

return GC_strdup(path);
return omc_alloc_interface.malloc_strdup(path);
}

static const char* SettingsImpl__getCompileCommand(void)
Expand Down
32 changes: 16 additions & 16 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -233,35 +233,35 @@ static int filterString(char* buf,char* bufRes)

extern int SystemImpl__setCCompiler(const char *str)
{
cc = GC_strdup(str);
cc = omc_alloc_interface.malloc_strdup(str);
if (cc == NULL) return -1;
return 0;
}

extern int SystemImpl__setCXXCompiler(const char *str)
{
cxx = GC_strdup(str);
cxx = omc_alloc_interface.malloc_strdup(str);
if (cxx == NULL) return -1;
return 0;
}

extern int SystemImpl__setLinker(const char *str)
{
linker = GC_strdup(str);
linker = omc_alloc_interface.malloc_strdup(str);
if (linker == NULL) return -1;
return 0;
}

extern int SystemImpl__setCFlags(const char *str)
{
cflags = GC_strdup(str);
cflags = omc_alloc_interface.malloc_strdup(str);
if (cflags == NULL) return -1;
return 0;
}

extern int SystemImpl__setLDFlags(const char *str)
{
ldflags = GC_strdup(str);
ldflags = omc_alloc_interface.malloc_strdup(str);
if (ldflags == NULL) return -1;
return 0;
}
Expand All @@ -281,13 +281,13 @@ extern char* SystemImpl__pwd(void)
for (i=0; i<MAXPATHLEN && buf[i]; i++) {
if (buf[i] == '\\') buf[i] = '/';
}
return GC_strdup(buf);
return omc_alloc_interface.malloc_strdup(buf);
#else
if (NULL == getcwd(buf,MAXPATHLEN)) {
fprintf(stderr, "System.pwd failed\n");
return NULL;
}
return GC_strdup(buf);
return omc_alloc_interface.malloc_strdup(buf);
#endif
}

Expand Down Expand Up @@ -683,7 +683,7 @@ char* System_popen(threadData_t *threadData, const char* command, int *status)
fprintf(stderr, "System.pipe: returned\n"); fflush(NULL);
}

char *res = GC_strdup(-1 == pclose(pipe) ? strerror(errno) : Print_getString(threadData));
char *res = omc_alloc_interface.malloc_strdup(-1 == pclose(pipe) ? strerror(errno) : Print_getString(threadData));
Print_restoreBuf(threadData, handle);

if (debug) {
Expand Down Expand Up @@ -994,7 +994,7 @@ extern int SystemImpl__removeDirectory(const char *path)
if (res == NULL)
{
/* basepath is finally found */
pattern = GC_strdup(str);
pattern = omc_alloc_interface.malloc_strdup(str);
break;
}
else
Expand All @@ -1008,7 +1008,7 @@ extern int SystemImpl__removeDirectory(const char *path)
else
{
/* basepath is finally found */
pattern = GC_strdup(str);
pattern = omc_alloc_interface.malloc_strdup(str);
sub = res;
len_sub = strlen(sub);
break;
Expand Down Expand Up @@ -1863,7 +1863,7 @@ void splitVersion(const char *version, long *versionNum, char **versionExtra)
buf = next;
} while (cont && ++i < MODELICAPATH_LEVELS);
if (*buf == ' ') buf++;
*versionExtra = GC_strdup(buf);
*versionExtra = omc_alloc_interface.malloc_strdup(buf);
len = strlen(*versionExtra);
/* fprintf(stderr, "have len %ld versionExtra %s\n", len, *versionExtra); */
if (len >= 2 && 0==strcmp("mo", *versionExtra+len-2)) {
Expand Down Expand Up @@ -1947,7 +1947,7 @@ static modelicaPathEntry* getAllModelicaPaths(const char *name, size_t nlen, voi
if (!ok)
continue;
res[i].dir = mp;
res[i].file = GC_strdup(ent->d_name);
res[i].file = omc_alloc_interface.malloc_strdup(ent->d_name);
if (res[i].file[nlen] == ' ') {
splitVersion(res[i].file+nlen+1, res[i].version, &res[i].versionExtra);
} else {
Expand Down Expand Up @@ -2348,7 +2348,7 @@ void SystemImpl__gettextInit(const char *locale)
char *old_ctype_default = setlocale(LC_CTYPE, "");
if (!old_ctype_default)
old_ctype_default = "UTF-8";
char *old_ctype = GC_strdup(old_ctype_default);
char *old_ctype = omc_alloc_interface.malloc_strdup(old_ctype_default);
int old_ctype_is_utf8 = strcmp(nl_langinfo(CODESET), "UTF-8") == 0;

int res =
Expand Down Expand Up @@ -2799,7 +2799,7 @@ char* SystemImpl__ctime(double time)
{
char buf[64] = {0}; /* needs to be >=26 char */
time_t t = (time_t) time;
return GC_strdup(ctime_r(&t,buf));
return omc_alloc_interface.malloc_strdup(ctime_r(&t,buf));
}

#if defined(__MINGW32__)
Expand Down Expand Up @@ -3000,8 +3000,8 @@ void SystemImpl__dladdr(void *symbol, const char **file, const char **name)
*file = "dladdr failed";
*name = "";
} else {
*file = GC_strdup(info.dli_fname);
*name = GC_strdup(info.dli_sname);
*file = omc_alloc_interface.malloc_strdup(info.dli_fname);
*name = omc_alloc_interface.malloc_strdup(info.dli_sname);
}
#endif
}
Expand Down
6 changes: 6 additions & 0 deletions SimulationRuntime/c/meta/gc/mmc_gc.h
Expand Up @@ -112,11 +112,17 @@ static inline void* mmc_alloc_words(unsigned int nwords) {

/* for arrays only */
static inline void* mmc_alloc_words_atomic_ignore_off_page(unsigned int nwords) {
#if defined(OMC_RECORD_ALLOC_WORDS)
mmc_record_alloc_words((nwords) * sizeof(void*));
#endif
return GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE((nwords) * sizeof(void*));
}

/* for arrays only */
static inline void* mmc_alloc_words_ignore_off_page(unsigned int nwords) {
#if defined(OMC_RECORD_ALLOC_WORDS)
mmc_record_alloc_words((nwords) * sizeof(void*));
#endif
return GC_MALLOC_IGNORE_OFF_PAGE((nwords) * sizeof(void*));
}

Expand Down

0 comments on commit d89da7c

Please sign in to comment.