Skip to content

Commit

Permalink
- Changed printimpl.c from having static "global" variables since the…
Browse files Browse the repository at this point in the history
…y got unpredictable behaviour when dynamically loading bootstrapping examples in the bootstrapped omc.

  - Now, all copies will share the _same_ print buffer, which means using Dynload.mo to run a function may change the internal state of the compiler (mainly print buffers).
  - Debug flags, etc are not shared though (I think). We don't test these much anyway.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7622 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 2, 2011
1 parent be2e4a0 commit aca8e5a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Compiler/Template/Tpl.mo
Expand Up @@ -753,7 +753,7 @@ algorithm
Print.clearBuf();
textStringBuf(txt);
str = Print.getString();
Print.clearBuf();
Print.clearBuf();
then
str;

Expand Down
1 change: 1 addition & 0 deletions Compiler/Template/TplMain.mo
Expand Up @@ -33,6 +33,7 @@ algorithm
case ( file )
equation
failure("SusanTest.tpl" = file);
Print.clearBuf();
translateFile(file);
strErrBuf = Print.getErrorString();
strErrBuf = Util.if_(strErrBuf ==& "","",
Expand Down
4 changes: 3 additions & 1 deletion Compiler/runtime/Print_omc.cpp
Expand Up @@ -43,7 +43,7 @@ extern void Print_printErrorBuf(const char* str)

extern void Print_printBuf(const char* str)
{
//fprintf(stderr, "Print_writeBuf %s\n", str);
// fprintf(stderr, "Print_printBuf: %s\n", str);
if (PrintImpl__printBuf(str))
MMC_THROW();
}
Expand All @@ -63,6 +63,7 @@ extern const char* Print_getString(void)
const char* res = PrintImpl__getString();
if (res == NULL)
MMC_THROW();
// fprintf(stderr, "Print_getString: %s##\n", res);fflush(NULL);
return strdup(res);
}

Expand All @@ -81,6 +82,7 @@ extern void Print_clearErrorBuf(void)

extern void Print_clearBuf(void)
{
// fprintf(stderr, "Print_clearBuf\n");
PrintImpl__clearBuf();
}

Expand Down
1 change: 1 addition & 0 deletions Compiler/runtime/Print_rml.c
Expand Up @@ -28,6 +28,7 @@
*
*/


#include <stdlib.h>
#include "printimpl.c"
#include "rml.h"
Expand Down
27 changes: 17 additions & 10 deletions Compiler/runtime/printimpl.c
Expand Up @@ -40,19 +40,27 @@ extern int showErrorMessages;

#define GROWTH_FACTOR 1.4 /* According to some roumours of buffer growth */
#define INITIAL_BUFSIZE 4000 /* Seems reasonable */
static char *buf = NULL;
static char *errorBuf = NULL;

static int nfilled=0;
static int cursize=0;
#define buf Print_var_buf
#define errorBuf Print_var_errorBuf
#define nfilled Print_var_nfilled
#define cursize Print_var_cursize
#define errorNfilled Print_var_errorNfilled
#define errorCursize Print_var_errorCursize

static int errorNfilled=0;
static int errorCursize=0;
char *buf = NULL;
char *errorBuf = NULL;

int nfilled=0;
int cursize=0;

int errorNfilled=0;
int errorCursize=0;

static int increase_buffer(void)
{

char * new_buf;
char *new_buf;
int new_size;
if (cursize == 0) {
new_buf = (char*)malloc(INITIAL_BUFSIZE*sizeof(char));
Expand Down Expand Up @@ -213,7 +221,6 @@ static int PrintImpl__printBuf(const char* str)
nfilled += len;
buf[nfilled] = '\0';

/* printf("%s",str); */
return 0;
}

Expand Down Expand Up @@ -300,9 +307,9 @@ static int PrintImpl__printBufSpace(long nSpaces)
{
if (nSpaces > 0) {
while (nfilled + nSpaces + 1 > cursize) {
if(increase_buffer()!= 0) {
if(increase_buffer()!= 0) {
return 1;
}
}
}
memset(buf+nfilled,' ',(size_t)nSpaces);
nfilled += nSpaces;
Expand Down

0 comments on commit aca8e5a

Please sign in to comment.