Skip to content

Commit

Permalink
- Fixed System.toupper segfaults
Browse files Browse the repository at this point in the history
- Added System.tolower


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5525 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed May 14, 2010
1 parent d775b15 commit f2e9e45
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Compiler/System.mo
Expand Up @@ -112,6 +112,13 @@ public function toupper
external "C" ;
end toupper;

public function tolower
input String inString;
output String outString;

external "C" ;
end tolower;

public function strtok
input String inString1;
input String inString2;
Expand Down
35 changes: 25 additions & 10 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -114,6 +114,8 @@
#endif
#endif

/* errorext.h is a C++ header... */
void c_add_message(int errorID, char* type, char* severity, char* message, char** ctokens, int nTokens);

#define MAX_PTR_INDEX 10000
static struct modelica_ptr_s ptr_vector[MAX_PTR_INDEX];
Expand Down Expand Up @@ -271,12 +273,29 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__toupper)
{
char *str = strdup(RML_STRINGDATA(rmlA0));
char *res=str;
while (*str!= '\0')
{
*str=toupper(*str++);
}
char *base = RML_STRINGDATA(rmlA0);
long len = strlen(base);
char *res = (char*) malloc(len);
int i;
for (i=0; i<len; i++)
res[i] = toupper(base[i]);
rmlA0 = (void*) mk_scon(res);

/* adrpo added 2004-10-29 */
free(res);

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__tolower)
{
char *base = RML_STRINGDATA(rmlA0);
long len = strlen(base);
char *res = (char*) malloc(len);
int i;
for (i=0; i<len; i++)
res[i] = tolower(base[i]);
rmlA0 = (void*) mk_scon(res);

/* adrpo added 2004-10-29 */
Expand Down Expand Up @@ -2467,10 +2486,6 @@ RML_BEGIN_LABEL(System__getDllExt)
}
RML_END_LABEL

/* errorext.h is a C++ header... */
void c_add_message(int errorID, char* type, char* severity,
char* message, char** ctokens, int nTokens);

RML_BEGIN_LABEL(System__loadLibrary)
{
const char *str = RML_STRINGDATA(rmlA0);
Expand Down

0 comments on commit f2e9e45

Please sign in to comment.