Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#1766 closed defect (fixed)

Locale changes cause real to string conversion to fail

Reported by: Frenkel TUD Owned by: sjoelund.se
Priority: critical Milestone: 1.9.0
Component: Frontend Version: trunk
Keywords: Cc: sjoelund.se, perost

Description

For the msl3.1 example
Modelica.Mechanics.Rotational.Examples.LossyGearDemo1
instantiation fails for the parameter gear.lossTable

in Example:
Rotational.Components.LossyGear gear(ratio=2, lossTable=[0, 0.5, 0.5, 0, 0],useSupport=true)

instantiation Result:

parameter Real gear.lossTable[1,1] = 0.0 \"Array for mesh efficiencies and bearing friction depending on speed\";
parameter Real gear.lossTable[1,2] = 0.0 \"Array for mesh efficiencies and bearing friction depending on speed\";
parameter Real gear.lossTable[1,3] = 0.0 \"Array for mesh efficiencies and bearing friction depending on speed\";
parameter Real gear.lossTable[1,4] = 0.0 \"Array for mesh efficiencies and bearing friction depending on speed\";
parameter Real gear.lossTable[1,5] = 0.0 \"Array for mesh efficiencies and bearing friction depending on speed\";

Change History (12)

comment:1 Changed 12 years ago by Frenkel TUD

  • Summary changed from instantiateModel(Modelica.Mechanics.Rotational.Examples.LossyGearDemo1) fails for gear.gear.lossTable to instantiateModel(Modelica.Mechanics.Rotational.Examples.LossyGearDemo1) fails for gear.lossTable

comment:2 Changed 12 years ago by sjoelund.se

  • Cc sjoelund.se perost added
  • Owner changed from adrpo,perost to adrpo
  • Status changed from new to assigned

Note there can be only one owner of a ticker, use cc instead

comment:3 Changed 12 years ago by Frenkel TUD

  • On linux it works, but on Windows not

comment:4 Changed 12 years ago by perost

It's broken for me on linux too, but it was broken very recently so you probably just don't have the lastest revision on linux. Apparently it was broken in r12389, which was a commit by Martin for some translation stuff. I don't know how that's possible, perhaps some flag stuff, but I'm investigating.

comment:5 Changed 12 years ago by Frenkel TUD

  • I checked the commit versions from 12380 up to 12389 and It happens since 12389

comment:6 Changed 12 years ago by perost

  • Owner changed from adrpo to sjoelund.se

Ok, so calling System.gettextInit with an empty string (the default) or something like sv_SE.utf8 causes the compiler to output zeroes instead of the correct values for this particular case. This is too weird for me, reassigning to Martin.

comment:7 Changed 12 years ago by Frenkel TUD

I checked on my local machine the locale information and I assume the problem is that the decimal point symbol is changed.

Locale is: C
Date is: 08/02/12 20:37:58
decimal_point symbol is: .
Locale is: German_Germany.1252
Date is: 02.08.2012 20:37:58
decimal_point symbol is: ,

void SystemImplgettextInit(const char *locale)
{
#if defined(_MSC_VER)
#else

const char *omhome = SettingsImplgetInstallationDirectoryPath();
char *localedir;
int omlen;
time_t rawtime;
struct tm * timeinfo;
char buffer [80];

struct lconv * lc;

time ( &rawtime );
timeinfo = localtime ( &rawtime );

printf ("Locale is: %s\n", setlocale(LC_ALL,NULL) );

strftime (buffer,80,"%c",timeinfo);
printf ("Date is: %s\n",buffer);

lc = localeconv ();
printf ("Currency symbol is: %s\n-\n",lc->currency_symbol);
printf ("decimal_point symbol is: %s\n-\n",lc->decimal_point);

if (!setlocale(LC_ALL, locale)) {

const char *c_tokens[1]={locale};
c_add_message(85, /* ERROR_OPENING_FILE */

ErrorType_scripting,
ErrorLevel_warning,
"Failed to set locale: '%s'.",
c_tokens,
1);

}
omlen = strlen(omhome);
localedir = (char*) malloc(omlen + 25);
sprintf(localedir, "%s/share/locale", omhome);
bindtextdomain ("openmodelica", localedir);
textdomain ("openmodelica");
free(localedir);

printf ("Locale is: %s\n", setlocale(LC_ALL,NULL) );

strftime (buffer,80,"%c",timeinfo);
printf ("Date is: %s\n",buffer);

lc = localeconv ();
printf ("Currency symbol is: %s\n-\n",lc->currency_symbol);
printf ("decimal_point symbol is: %s\n-\n",lc->decimal_point);

#endif
}

comment:8 Changed 12 years ago by Frenkel TUD

If I call omc with +locale=C all is fine, so I guess we should change the default value of the ConfigFlag locale to "C".

comment:9 Changed 12 years ago by sjoelund.se

It is default C when running the testsuite. I'll also fix it to only set LC_MESSAGES instead of the other stuff in locale, but my local copy is weird because I upgraded gcc.

comment:10 Changed 12 years ago by sjoelund.se

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in r12417.

comment:11 Changed 12 years ago by sjoelund.se

  • Milestone set to 1.9.0
  • Summary changed from instantiateModel(Modelica.Mechanics.Rotational.Examples.LossyGearDemo1) fails for gear.lossTable to Locale changes cause real to string conversion to fail

comment:12 Changed 12 years ago by sjoelund.se

  • Component changed from Instantiation to Frontend
Note: See TracTickets for help on using tickets.