Skip to content

Commit 12d6f2f

Browse files
committed
- fix bug "Memory performance issue in 1.9.0 beta 2" reported by MathCore.
+ use internal RML allocation for Print.getString and Print.getErrorString + do not use strdup in Print_omc.cpp for Print.getString and Print.getErrorString git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14730 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 73a3f4f commit 12d6f2f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Compiler/runtime/Print_omc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ extern const char* Print_getString(void)
6464
if (res == NULL)
6565
MMC_THROW();
6666
// fprintf(stderr, "Print_getString: %s##\n", res);fflush(NULL);
67-
return strdup(res);
67+
return res; // strdup(res);
6868
}
6969

7070
extern const char* Print_getErrorString(void)
7171
{
7272
const char* res = PrintImpl__getErrorString();
7373
if (res == NULL)
7474
MMC_THROW();
75-
return strdup(res);
75+
return res; // strdup(res);
7676
}
7777

7878
extern void Print_clearErrorBuf(void)

Compiler/runtime/Print_rml.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ RML_END_LABEL
7777
RML_BEGIN_LABEL(Print__getErrorString)
7878
{
7979
const char* str = PrintImpl__getErrorString();
80+
rml_uint_t nbytes = strlen(str);
81+
struct rml_string *retval;
8082
if (str == NULL)
8183
RML_TAILCALLK(rmlFC);
82-
rmlA0=(void*)mk_scon((char*)str);
84+
// use internal RML to allocate the string memory!
85+
retval = rml_prim_mkstring(nbytes,0);
86+
memcpy(retval->data, str, nbytes+1); /* including terminating '\0' */
87+
rmlA0 = RML_TAGPTR(retval);
8388
RML_TAILCALLK(rmlSC);
8489
}
8590
RML_END_LABEL
@@ -104,9 +109,14 @@ RML_END_LABEL
104109
RML_BEGIN_LABEL(Print__getString)
105110
{
106111
const char* str = PrintImpl__getString();
112+
rml_uint_t nbytes = strlen(str);
113+
struct rml_string *retval;
107114
if (str == NULL)
108115
RML_TAILCALLK(rmlFC);
109-
rmlA0=(void*)mk_scon((char*)str);
116+
// use internal RML to allocate the string memory!
117+
retval = rml_prim_mkstring(nbytes,0);
118+
memcpy(retval->data, str, nbytes+1); /* including terminating '\0' */
119+
rmlA0 = RML_TAGPTR(retval);
110120
RML_TAILCALLK(rmlSC);
111121
}
112122
RML_END_LABEL

0 commit comments

Comments
 (0)