Skip to content

Commit

Permalink
- Some fixes for bootstrapped System.{substring,regex}
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8382 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
EDGAR ALONSO LOPEZ ROJAS committed Mar 28, 2011
1 parent f21a9ed commit 5de12e9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Compiler/Util/System.mo
Expand Up @@ -113,7 +113,7 @@ public function regex "Fails and sets Error.mo if the regex does not compile.
output Integer numMatches "0 means no match, else returns a number 1..maxMatches (1 if maxMatches<0)";
output list<String> strs "This list has length = maxMatches. Substrings that did not match are filled with the empty string";

external "C" numMatches=System_regex(str,re,maxMatches,extended,sensitive,strs) annotation(Library = "omcruntime");
external "C" strs=System_regex(str,re,maxMatches,extended,sensitive,numMatches) annotation(Library = "omcruntime");
end regex;

public function strncmp
Expand Down
25 changes: 6 additions & 19 deletions Compiler/runtime/System_omc.cpp
Expand Up @@ -245,9 +245,9 @@ extern void* System_strtok(const char *str0, const char *delimit)
return listReverse(res);
}

extern void* System_substring(const char *inStr, int start, int stop)
extern char* System_substring(const char *inStr, int start, int stop)
{
char* substring = NULL;
static char* substring = NULL; // This function is not re-entrant... Note that the result will be overwritten at each call to substring...
char* str = strdup(inStr);
int startIndex = start;
int stopIndex = stop;
Expand All @@ -258,7 +258,7 @@ extern void* System_substring(const char *inStr, int start, int stop)
/* Check arguments */
if ( startIndex < 1 )
{
free(str);
free(str);
MMC_THROW();
}
if ( stopIndex == -999 )
Expand All @@ -273,15 +273,13 @@ extern void* System_substring(const char *inStr, int start, int stop)
}

/* Allocate memory and copy string */
if (substring) free(substring);
len2 = stopIndex - startIndex + 1;
substring = (char*)malloc(len2);
strncpy(substring, &str[startIndex-1], len2);
substring[len2] = '\0';

res = mmc_mk_scon(substring);

free(substring);
return res;
return substring;
}

const char* System_getClassnamesForSimulation()
Expand Down Expand Up @@ -497,6 +495,7 @@ extern const char* System_getCorbaLibs()

extern void* System_regex(const char* str, const char* re, int maxn, int extended, int sensitive, int *nmatch)
{
*nmatch = 0;
void *res = SystemImpl__regex(str,re,maxn,extended,sensitive,nmatch);
if (res==NULL) MMC_THROW();
return res;
Expand All @@ -523,16 +522,4 @@ extern char* System_unquoteIdentifier(char *str)
return res;
}

extern int System_intMaxLit()
{
return (LONG_MAX / 2);
}

extern void* System_realMaxLit()
{
return mmc_mk_rcon(DBL_MAX / 2048);
}



}
2 changes: 1 addition & 1 deletion Compiler/runtime/System_rml.c
Expand Up @@ -1937,7 +1937,7 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__regex)
{
int nmatch;
int nmatch = 0;
rmlA1 = SystemImpl__regex(RML_STRINGDATA(rmlA0),RML_STRINGDATA(rmlA1),RML_UNTAGFIXNUM(rmlA2),RML_UNTAGFIXNUM(rmlA3),RML_UNTAGFIXNUM(rmlA4),&nmatch);
rmlA0 = mk_icon(nmatch);
if (rmlA1)
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/systemimpl.c
Expand Up @@ -1106,7 +1106,7 @@ extern void* SystemImpl__regex(const char* str, const char* re, int maxn, int ex
lst = mk_nil();
*nmatch = 0;
if (!maxn)
(*nmatch)+= res == 0;
(*nmatch)+= res == 0 ? 1 : 0;
else {
if (maxn) {
dup = strdup(str);
Expand Down

0 comments on commit 5de12e9

Please sign in to comment.