Skip to content

Commit

Permalink
- fix calls of assertStreamPrint() and throwStreamPrint()
Browse files Browse the repository at this point in the history
- fix some warnings
- reduce scope of objects
- "unsigned" -> "unsigned int" for better readability

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18630 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Henning Kiel committed Jan 13, 2014
1 parent c702a47 commit f7b8c01
Show file tree
Hide file tree
Showing 23 changed files with 287 additions and 281 deletions.
5 changes: 2 additions & 3 deletions SimulationRuntime/c/linearization/linearize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ string array2string(double* array, int row, int col){
int j=0;
ostringstream retVal(ostringstream::out);
retVal.precision(16);
int k;
for(i=0;i<row;i++){
k = i;
int k = i;
for(j=0;j<col-1;j++){
retVal << array[k] << ",";
k += row;
Expand Down Expand Up @@ -233,7 +232,7 @@ int linearize(DATA* data)
double* matrixB = (double*)calloc(size_A*size_Inputs,sizeof(double));
double* matrixC = (double*)calloc(size_Outputs*size_A,sizeof(double));
double* matrixD = (double*)calloc(size_Outputs*size_Inputs,sizeof(double));
string strA, strB, strC, strD, strX, strU, filename, linearModel;
string strA, strB, strC, strD, strX, strU, filename;

assertStreamPrint(0!=matrixA,"calloc failed");
assertStreamPrint(0!=matrixB,"calloc failed");
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/c/meta/gc/marksweep.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,19 +422,19 @@ int compareSize (const void* a, const void* b)
/* try to join all possible slots in the list! */
mmc_GC_pages_type free_list_compact(mmc_GC_pages_type pages)
{
size_t i = 0, j = 0, k = 0;
size_t i;

for (i = 0; i < pages.current; i++)
{
size_t j, k;
size_t len = pages.start[i].free->szLarge.current;
mmc_GC_free_slot_type* freeArr = (mmc_GC_free_slot_type*)malloc(sizeof(mmc_GC_free_slot_type) * len);
mmc_GC_free_slot_type slot = {0, 0}, joinSlot = {0, 0};
mmc_GC_free_slot_type joinSlot;
memcpy(freeArr, pages.start[i].free->szLarge.start, len * sizeof(mmc_GC_free_slot_type));
/* sort the array in the order of addresses */
qsort (freeArr, len, sizeof(mmc_GC_free_slot_type), compareAddress);
/* join the slots */
k = 0;
slot = freeArr[0];
joinSlot = freeArr[0];
for (j = 1; j < len; j++)
{
Expand Down
1 change: 0 additions & 1 deletion SimulationRuntime/c/meta/gc/roots.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ mmc_GC_roots_type roots_decrease(mmc_GC_roots_type roots, size_t default_roots_s
/* add pointers to roots */
void mmc_GC_add_roots_fallback(modelica_metatype* p, int n, mmc_GC_local_state_type local_GC_state, const char* name)
{
int i;
/* init GC if is not already done
if (!mmc_GC_state)
{
Expand Down
64 changes: 29 additions & 35 deletions SimulationRuntime/c/meta/meta_modelica.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
*
* The OpenModelica software and the OSMC (Open Source Modelica Consortium)
* Public License (OSMC-PL) are obtained from OSMC, either from the above
* address, from the URLs: http://www.openmodelica.org or
Expand Down Expand Up @@ -66,7 +66,7 @@ void* mmc_mk_rcon(double d)
return MMC_TAGPTR(p);
}

void *mmc_mk_box_arr(int slots, unsigned ctor, void** args)
void *mmc_mk_box_arr(int slots, unsigned int ctor, void** args)
{
int i;
struct mmc_struct *p = (struct mmc_struct*)mmc_alloc_words(slots + 1);
Expand All @@ -80,7 +80,7 @@ void *mmc_mk_box_arr(int slots, unsigned ctor, void** args)
return MMC_TAGPTR(p);
}

void *mmc_mk_box_no_assign(int slots, unsigned ctor)
void *mmc_mk_box_no_assign(int slots, unsigned int ctor)
{
struct mmc_struct *p = (struct mmc_struct*)mmc_alloc_words(slots+1);
p->header = MMC_STRUCTHDR(slots, ctor);
Expand All @@ -92,8 +92,8 @@ void *mmc_mk_box_no_assign(int slots, unsigned ctor)

char* mmc_mk_scon_len_ret_ptr(size_t nbytes)
{
unsigned header = MMC_STRINGHDR(nbytes);
unsigned nwords = MMC_HDRSLOTS(header) + 1;
unsigned int header = MMC_STRINGHDR(nbytes);
unsigned int nwords = MMC_HDRSLOTS(header) + 1;
struct mmc_string *p;
void *res;
p = (struct mmc_string *) mmc_alloc_words(nwords);
Expand All @@ -107,10 +107,8 @@ modelica_boolean valueEq(modelica_metatype lhs, modelica_metatype rhs)
mmc_uint_t h_lhs;
mmc_uint_t h_rhs;
int numslots;
unsigned ctor;
unsigned int ctor;
int i;
void *lhs_data, *rhs_data;
struct record_description *lhs_desc,*rhs_desc;

if (lhs == rhs) {
return 1;
Expand Down Expand Up @@ -149,15 +147,15 @@ modelica_boolean valueEq(modelica_metatype lhs, modelica_metatype rhs)
ctor = 255 & (h_lhs >> 2);

if (numslots>0 && ctor > 1) { /* RECORD */
/* lhs_desc = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(lhs),1));
rhs_desc = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(rhs),1));
/* struct record_description * lhs_desc = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(lhs),1));
struct record_description * rhs_desc = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(rhs),1));
Slow; not needed
if (0 != strcmp(lhs_desc->name,rhs_desc->name))
return 0;
*/
for (i=2; i<=numslots; i++) {
lhs_data = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(lhs),i));
rhs_data = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(rhs),i));
void * lhs_data = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(lhs),i));
void * rhs_data = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(rhs),i));
if (0 == valueEq(lhs_data,rhs_data)) {
return 0;
}
Expand Down Expand Up @@ -200,7 +198,7 @@ modelica_boolean valueEq(modelica_metatype lhs, modelica_metatype rhs)
}


fprintf(stderr, "%s:%d: %d slots; ctor %d - FAILED to detect the type\n", __FILE__, __LINE__, numslots, ctor);
fprintf(stderr, "%s:%d: %d slots; ctor %u - FAILED to detect the type\n", __FILE__, __LINE__, numslots, ctor);
EXIT(1);
}

Expand Down Expand Up @@ -234,10 +232,9 @@ inline static int anyStringWork(void* any, int ix)
{
mmc_uint_t hdr;
int numslots;
unsigned ctor;
unsigned int ctor;
int i;
void *data;
struct record_description *desc;
/* char buf[34] = {0}; */

if (MMC_IS_INTEGER(any)) {
Expand Down Expand Up @@ -286,7 +283,7 @@ inline static int anyStringWork(void* any, int ix)

if (numslots>0 && ctor == MMC_FREE_OBJECT_CTOR) { /* FREE OBJECT! */
checkAnyStringBufSize(ix,100);
ix += sprintf(anyStringBuf+ix, "FREE(%u)", numslots);
ix += sprintf(anyStringBuf+ix, "FREE(%d)", numslots);
return ix;
}
if (numslots>=0 && ctor == MMC_ARRAY_TAG) { /* MetaModelica-style array */
Expand All @@ -305,7 +302,7 @@ inline static int anyStringWork(void* any, int ix)
return ix;
}
if (numslots>0 && ctor > 1) { /* RECORD */
desc = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),1));
struct record_description * desc = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),1));
checkAnyStringBufSize(ix,strlen(desc->name)+2);
ix += sprintf(anyStringBuf+ix, "%s(", desc->name);
for (i=2; i<=numslots; i++) {
Expand Down Expand Up @@ -369,14 +366,14 @@ inline static int anyStringWork(void* any, int ix)
return ix;
}

fprintf(stderr, "%s:%d: %d slots; ctor %d - FAILED to detect the type\n", __FILE__, __LINE__, numslots, ctor);
fprintf(stderr, "%s:%d: %d slots; ctor %u - FAILED to detect the type\n", __FILE__, __LINE__, numslots, ctor);
/* fprintf(stderr, "object: %032s||", ltoa((int)hdr, buf, 2)); */
checkAnyStringBufSize(ix,5);
ix += sprintf(anyStringBuf+ix, "UNK(");
for (i=1; i<=numslots; i++)
{
ix = anyStringWork(MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),i)),ix);
data = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),i));
ix = anyStringWork(data,ix);
/* fprintf(stderr, "%032s|", ltoa((int)data, buf, 2)); */
}
checkAnyStringBufSize(ix,2);
Expand Down Expand Up @@ -423,10 +420,9 @@ inline static int anyStringWorkCode(void* any, int ix, int id)
{
mmc_uint_t hdr;
int numslots;
unsigned ctor;
unsigned int ctor;
int i;
void *data;
struct record_description *desc;
int base_id;
/* char buf[34] = {0}; */

Expand Down Expand Up @@ -491,13 +487,13 @@ inline static int anyStringWorkCode(void* any, int ix, int id)
if (numslots>0 && ctor > 1) { /* RECORD */
int base_id = globalId;
globalId += numslots-1;
desc = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),1));
struct record_description * desc = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),1));
for (i=2; i<=numslots; i++) {
data = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),i));
ix = anyStringWorkCode(data,ix,base_id+i-1);
}
checkAnyStringBufSize(ix,numslots*100+400);
ix += sprintf(anyStringBuf+ix, "static const MMC_DEFSTRUCTLIT(omc_tmp%d_data,%d,%d) {&%s__desc", id, numslots, ctor, desc->path);
ix += sprintf(anyStringBuf+ix, "static const MMC_DEFSTRUCTLIT(omc_tmp%d_data,%d,%u) {&%s__desc", id, numslots, ctor, desc->path);
for (i=2; i<=numslots; i++) {
ix += sprintf(anyStringBuf+ix, ",omc_tmp%d", base_id+i-1);
}
Expand All @@ -513,7 +509,7 @@ inline static int anyStringWorkCode(void* any, int ix, int id)
ix = anyStringWorkCode(data,ix,base_id+i);
}
checkAnyStringBufSize(ix,numslots*100+400);
ix += sprintf(anyStringBuf+ix, "static const MMC_DEFSTRUCTLIT(omc_tmp%d_data,%d,%d) {", id, numslots, ctor);
ix += sprintf(anyStringBuf+ix, "static const MMC_DEFSTRUCTLIT(omc_tmp%d_data,%d,%u) {", id, numslots, ctor);
for (i=1; i<=numslots; i++) {
ix += sprintf(anyStringBuf+ix, "%somc_tmp%d", i==1 ? "" : ",", base_id+i);
}
Expand Down Expand Up @@ -543,10 +539,8 @@ void printTypeOfAny(void* any) /* for debugging */
{
mmc_uint_t hdr;
int numslots;
unsigned ctor;
int i;
unsigned int ctor;
void *data;
struct record_description *desc;

if ((0 == ((mmc_sint_t)any & 1))) {
fprintf(stderr, "Integer");
Expand Down Expand Up @@ -592,7 +586,8 @@ void printTypeOfAny(void* any) /* for debugging */
}

if (numslots>0 && ctor > 1) { /* RECORD */
desc = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),1));
int i;
struct record_description * desc = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),1));
fprintf(stderr, "%s(", desc->name);
for (i=2; i<=numslots; i++) {
data = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),i));
Expand Down Expand Up @@ -631,17 +626,16 @@ void printTypeOfAny(void* any) /* for debugging */
return;
}

fprintf(stderr, "%s:%d: %d slots; ctor %d - FAILED to detect the type\n", __FILE__, __LINE__, numslots, ctor);
fprintf(stderr, "%s:%d: %d slots; ctor %u - FAILED to detect the type\n", __FILE__, __LINE__, numslots, ctor);
EXIT(1);
}

inline static int getTypeOfAnyWork(void* any, int ix) /* for debugging */
{
mmc_uint_t hdr;
int numslots;
unsigned ctor;
unsigned int ctor;
int i;
struct record_description *desc;

if (any == NULL) {
checkAnyStringBufSize(ix,21);
Expand Down Expand Up @@ -697,7 +691,7 @@ inline static int getTypeOfAnyWork(void* any, int ix) /* for debugging */
}

if (numslots>0 && ctor > 1) { /* RECORD */
desc = MMC_CAR(any);
struct record_description * desc = MMC_CAR(any);
checkAnyStringBufSize(ix,strlen(desc->name)+8);
ix += sprintf(anyStringBuf+ix, "record<%s>", desc->name);
return ix;
Expand Down Expand Up @@ -748,7 +742,7 @@ inline static int getTypeOfAnyWork(void* any, int ix) /* for debugging */
return ix;
}

ix = sprintf(anyStringBuf+ix, "%s:%d: %d slots; ctor %d - FAILED to detect the type\n", __FILE__, __LINE__, numslots, ctor);
ix = sprintf(anyStringBuf+ix, "%s:%d: %d slots; ctor %u - FAILED to detect the type\n", __FILE__, __LINE__, numslots, ctor);
return ix;
}

Expand Down Expand Up @@ -794,7 +788,7 @@ void changeStdStreamBuffer(void) {

static inline unsigned long djb2_hash_iter(const unsigned char *str /* data; not null-terminated */, int len, unsigned long hash /* start at 5381 */)
{
int c,i;
int i;
for (i=0; i<len; i++) {
hash = ((hash << 5) + hash) + str[i]; /* hash * 33 + c */
}
Expand All @@ -816,7 +810,7 @@ unsigned long mmc_prim_hash(void *p,unsigned long hash /* start at 5381 */)
phdr = MMC_GETHDR(p);

if( phdr == MMC_REALHDR )
{
{
double d = mmc_unbox_real(p);
return djb2_hash_iter((unsigned char*)&d, sizeof(double), hash);
}
Expand Down

0 comments on commit f7b8c01

Please sign in to comment.