Skip to content

Commit

Permalink
Use boehm GC_malloc for string allocation (TODO: Fix all weird workar…
Browse files Browse the repository at this point in the history
…ounds in the C codegen since we don't need them any longer)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17054 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Sep 3, 2013
1 parent ad97068 commit bbe882a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 31 deletions.
36 changes: 18 additions & 18 deletions SimulationRuntime/c/meta/meta_modelica.h
Expand Up @@ -235,7 +235,7 @@ struct mmc_string {
#define MMC_TRUE (mmc_mk_icon(1))
#define mmc_mk_bcon(X) ((X) != 0 ? MMC_TRUE : MMC_FALSE)

static void* mmc_mk_icon(mmc_sint_t i)
static inline void* mmc_mk_icon(mmc_sint_t i)
{
return MMC_IMMEDIATE(MMC_TAGFIXNUM(i));
}
Expand All @@ -246,7 +246,7 @@ union mmc_double_as_words {
double d;
mmc_uint_t data[2];
};
static double mmc_prim_get_real(void *p)
static inline double mmc_prim_get_real(void *p)
{
union mmc_double_as_words u;
mmc_uint_t *data = &(MMC_REALDATA(p)[0]);
Expand All @@ -256,7 +256,7 @@ static double mmc_prim_get_real(void *p)
return u.d;
}

static void mmc_prim_set_real(struct mmc_real *p, double d)
static inline void mmc_prim_set_real(struct mmc_real *p, double d)
{
union mmc_double_as_words u;
mmc_uint_t *data;
Expand All @@ -267,7 +267,7 @@ static void mmc_prim_set_real(struct mmc_real *p, double d)
*(data + 1) = u.data[1];
}

static void* mmc_mk_scon(const char *s)
static inline void* mmc_mk_scon(const char *s)
{
unsigned nbytes = strlen(s);
unsigned header = MMC_STRINGHDR(nbytes);
Expand All @@ -290,7 +290,7 @@ static void* mmc_mk_scon(const char *s)
return res;
}

static void* mmc_mk_scon_len(unsigned nbytes)
static inline void* mmc_mk_scon_len(unsigned nbytes)
{
unsigned header = MMC_STRINGHDR(nbytes);
unsigned nwords = MMC_HDRSLOTS(header) + 1;
Expand All @@ -304,7 +304,7 @@ static void* mmc_mk_scon_len(unsigned nbytes)

char* mmc_mk_scon_len_ret_ptr(size_t nbytes);

static void *mmc_mk_box0(unsigned ctor)
static inline void *mmc_mk_box0(unsigned ctor)
{
struct mmc_struct *p = (struct mmc_struct *) mmc_alloc_words(1);
p->header = MMC_STRUCTHDR(0, ctor);
Expand All @@ -314,7 +314,7 @@ static void *mmc_mk_box0(unsigned ctor)
return MMC_TAGPTR(p);
}

static void *mmc_mk_box1(unsigned ctor, void *x0)
static inline void *mmc_mk_box1(unsigned ctor, void *x0)
{
mmc_GC_add_roots(&x0, 1, 0, "");
{
Expand All @@ -330,7 +330,7 @@ static void *mmc_mk_box1(unsigned ctor, void *x0)

void printAny(void* any);

static void *mmc_mk_box2(unsigned ctor, void *x0, void *x1)
static inline void *mmc_mk_box2(unsigned ctor, void *x0, void *x1)
{
mmc_GC_add_roots(&x0, 1, 0, "");
mmc_GC_add_roots(&x1, 1, 0, "");
Expand All @@ -349,7 +349,7 @@ static void *mmc_mk_box2(unsigned ctor, void *x0, void *x1)
}
}

static void *mmc_mk_box3(unsigned ctor, void *x0, void *x1, void *x2)
static inline void *mmc_mk_box3(unsigned ctor, void *x0, void *x1, void *x2)
{
mmc_GC_add_roots(&x0, 1, 0, "");
mmc_GC_add_roots(&x1, 1, 0, "");
Expand All @@ -370,7 +370,7 @@ static void *mmc_mk_box3(unsigned ctor, void *x0, void *x1, void *x2)
}
}

static void *mmc_mk_box4(unsigned ctor, void *x0, void *x1, void *x2, void *x3)
static inline void *mmc_mk_box4(unsigned ctor, void *x0, void *x1, void *x2, void *x3)
{
mmc_GC_add_roots(&x0, 1, 0, "");
mmc_GC_add_roots(&x1, 1, 0, "");
Expand All @@ -392,7 +392,7 @@ static void *mmc_mk_box4(unsigned ctor, void *x0, void *x1, void *x2, void *x3)
}
}

static void *mmc_mk_box5(unsigned ctor, void *x0, void *x1, void *x2, void *x3, void *x4)
static inline void *mmc_mk_box5(unsigned ctor, void *x0, void *x1, void *x2, void *x3, void *x4)
{
mmc_GC_add_roots(&x0, 1, 0, "");
mmc_GC_add_roots(&x1, 1, 0, "");
Expand All @@ -416,7 +416,7 @@ static void *mmc_mk_box5(unsigned ctor, void *x0, void *x1, void *x2, void *x3,
}
}

static void *mmc_mk_box6(unsigned ctor, void *x0, void *x1, void *x2, void *x3, void *x4, void *x5)
static inline void *mmc_mk_box6(unsigned ctor, void *x0, void *x1, void *x2, void *x3, void *x4, void *x5)
{
mmc_GC_add_roots(&x0, 1, 0, "");
mmc_GC_add_roots(&x1, 1, 0, "");
Expand All @@ -442,7 +442,7 @@ static void *mmc_mk_box6(unsigned ctor, void *x0, void *x1, void *x2, void *x3,
}
}

static void *mmc_mk_box7(unsigned ctor, void *x0, void *x1, void *x2, void *x3, void *x4, void *x5, void *x6)
static inline void *mmc_mk_box7(unsigned ctor, void *x0, void *x1, void *x2, void *x3, void *x4, void *x5, void *x6)
{
mmc_GC_add_roots(&x0, 1, 0, "");
mmc_GC_add_roots(&x1, 1, 0, "");
Expand Down Expand Up @@ -470,7 +470,7 @@ static void *mmc_mk_box7(unsigned ctor, void *x0, void *x1, void *x2, void *x3,
}
}

static void *mmc_mk_box8(unsigned ctor, void *x0, void *x1, void *x2, void *x3, void *x4, void *x5, void *x6, void *x7)
static inline void *mmc_mk_box8(unsigned ctor, void *x0, void *x1, void *x2, void *x3, void *x4, void *x5, void *x6, void *x7)
{
mmc_GC_add_roots(&x0, 1, 0, "");
mmc_GC_add_roots(&x1, 1, 0, "");
Expand Down Expand Up @@ -500,7 +500,7 @@ static void *mmc_mk_box8(unsigned ctor, void *x0, void *x1, void *x2, void *x3,
}
}

static void *mmc_mk_box9(unsigned ctor, void *x0, void *x1, void *x2, void *x3, void *x4, void *x5, void *x6, void *x7, void *x8)
static inline void *mmc_mk_box9(unsigned ctor, void *x0, void *x1, void *x2, void *x3, void *x4, void *x5, void *x6, void *x7, void *x8)
{
mmc_GC_add_roots(&x0, 1, 0, "");
mmc_GC_add_roots(&x1, 1, 0, "");
Expand Down Expand Up @@ -532,7 +532,7 @@ static void *mmc_mk_box9(unsigned ctor, void *x0, void *x1, void *x2, void *x3,
}
}

static void *mmc_mk_box(int slots, unsigned ctor, ...)
static inline void *mmc_mk_box(int slots, unsigned ctor, ...)
{
int i;
va_list argp;
Expand Down Expand Up @@ -569,12 +569,12 @@ static const MMC_DEFSTRUCT0LIT(mmc_none,1);

#define MMC_CONS_CTOR 1

static void *mmc_mk_cons(void *car, void *cdr)
static inline void *mmc_mk_cons(void *car, void *cdr)
{
return mmc_mk_box2(MMC_CONS_CTOR, car, cdr);
}

static void *mmc_mk_some(void *x)
static inline void *mmc_mk_some(void *x)
{
return mmc_mk_box1(1, x);
}
Expand Down
5 changes: 4 additions & 1 deletion SimulationRuntime/c/util/ModelicaUtilities.c
Expand Up @@ -32,6 +32,9 @@
#include "ModelicaUtilities.h"
#include "modelica_string.h"

#define THREAD_LOCAL_ALLOC
#include "gc.h"

#include <stdio.h>
#include <stdlib.h>
#include "omc_error.h"
Expand Down Expand Up @@ -79,5 +82,5 @@ char* ModelicaAllocateString(size_t len) {
}

char* ModelicaAllocateStringWithErrorReturn(size_t len) {
return OpenModelica_ExternalC_allocation_function(len);
return GC_malloc(len+1);
}
2 changes: 1 addition & 1 deletion SimulationRuntime/c/util/index_spec.c
Expand Up @@ -102,7 +102,7 @@ void create_index_spec(index_spec_t* dest, int nridx, ...)
dest->ndims = nridx;
dest->dim_size = size_alloc(nridx);
dest->index = index_alloc(nridx);
dest->index_type = char_alloc(nridx);
dest->index_type = GC_malloc(nridx+1);
for(i = 0; i < nridx; ++i) {
dest->dim_size[i] = va_arg(ap, _index_t);
dest->index[i] = va_arg(ap, _index_t*);
Expand Down
5 changes: 0 additions & 5 deletions SimulationRuntime/c/util/memory_pool.c
Expand Up @@ -168,11 +168,6 @@ _index_t** index_alloc(int n)
return alloc_elements(n,sizeof(_index_t*));
}

char* char_alloc(int n)
{
return alloc_elements(n,sizeof(char));
}

/* allocates n elements of size sze */
void* generic_alloc(int n, size_t sze)
{
Expand Down
1 change: 0 additions & 1 deletion SimulationRuntime/c/util/memory_pool.h
Expand Up @@ -53,7 +53,6 @@ extern m_string* string_alloc(int n);
extern m_boolean* boolean_alloc(int n);
extern _index_t* size_alloc(int n);
extern _index_t** index_alloc(int n);
extern char* char_alloc(int n);

extern void* push_memory_states(int maxThreads);
extern void pop_memory_states(void* new_states);
Expand Down
4 changes: 1 addition & 3 deletions SimulationRuntime/c/util/modelica_string.c
Expand Up @@ -140,15 +140,13 @@ modelica_string_const init_modelica_string(modelica_string_const str)
modelica_string_t alloc_modelica_string(int length)
{
/* Reserve place for null terminator too.*/
modelica_string_t dest = (modelica_string_t) char_alloc(length+1);
modelica_string_t dest = (modelica_string_t) GC_malloc(length+1);
if (dest != 0) {
dest[length]=0;
}
return dest;
}

extern char*(*OpenModelica_ExternalC_allocation_function)(size_t) = alloc_modelica_string;

void free_modelica_string(modelica_string_t* a)
{
/* int length; */
Expand Down
2 changes: 0 additions & 2 deletions SimulationRuntime/c/util/modelica_string.h
Expand Up @@ -49,8 +49,6 @@ extern int modelica_string_length(modelica_string_const a);
extern modelica_string_const init_modelica_string(modelica_string_const str);

extern modelica_string_t alloc_modelica_string(int length);
/* In case we do not use the memory pool in the runtime */
extern char* (*OpenModelica_ExternalC_allocation_function)(size_t length);

/* formatting String functions */
extern modelica_string_const modelica_real_to_modelica_string_format(modelica_real r, modelica_string_const format);
Expand Down

0 comments on commit bbe882a

Please sign in to comment.