Skip to content

Commit

Permalink
- Changed dynload.c to Dynload_rml.cpp and fixed the compilation erro…
Browse files Browse the repository at this point in the history
…rs that were warnings in C

  - Added a (stub) Dynload_omc.cpp


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7127 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 20, 2010
1 parent 3b3e492 commit 363d69a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 1,007 deletions.
2 changes: 1 addition & 1 deletion Compiler/DynLoad.mo
Expand Up @@ -45,7 +45,7 @@ of values."
input list<Values.Value> inValLst;
output Values.Value outVal;

external "C" ;
external "C" outVal=DynLoad_executeFunction(inFuncHandle,inValLst) annotation(Library = "omcruntime");
end executeFunction;

end DynLoad;
@@ -1,9 +1,9 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Copyright (c) 1998-2010, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
Expand All @@ -14,7 +14,7 @@
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköpings University, either from the above address,
* from Linköpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
Expand All @@ -28,21 +28,14 @@
*
*/

#ifndef __DYNLOAD_TRY__H
#define __DYNLOAD_TRY__H

#include "read_write.h"

#ifdef __cplusplus
extern "C" {
#endif

int execute_function_try_catch(int (* func)(type_description *, type_description *),
type_description *arglst,
type_description *retarg);
#include <stdio.h>

#ifdef __cplusplus
extern void* Dynload_executeFunction(int _inFuncHandle, void* _inValLst)
{
fprintf(stderr, "Dynload_executeFunction NYI\n");
throw 1;
}
#endif

#endif
}
56 changes: 32 additions & 24 deletions Compiler/runtime/dynload.c → Compiler/runtime/Dynload_rml.cpp
Expand Up @@ -34,12 +34,15 @@
#endif

#include "errorext.h"
#include "systemimpl.h"
#include "meta_modelica.h"

extern "C" {

#include "systemimpl.h"
#include "rtopts.h"
#include "rml.h"
#include "Absyn.h"
#include "Values.h"
#include "dynload_try.h"

void *type_desc_to_value(type_description *desc);
static int execute_function(void *in_arg, void **out_arg,
Expand Down Expand Up @@ -90,31 +93,31 @@ void *generate_array(enum type_desc_e type, int curdim, int ndims,

switch (type) {
case TYPE_DESC_REAL: {
modelica_real *ptr = *data;
modelica_real *ptr = *((modelica_real**)data);
for (i = 0; i < cur_dim_size; ++i, --ptr) {
tmp.data.real = *ptr;
lst = (void *) mk_cons(type_desc_to_value(&tmp), lst);
}
*data = ptr;
}; break;
case TYPE_DESC_INT: {
modelica_integer *ptr = *data;
modelica_integer *ptr = *((modelica_integer**)data);
for (i = 0; i < cur_dim_size; ++i, --ptr) {
tmp.data.integer = *ptr;
lst = (void *) mk_cons(type_desc_to_value(&tmp), lst);
}
*data = ptr;
}; break;
case TYPE_DESC_BOOL: {
modelica_boolean *ptr = *data;
modelica_boolean *ptr = *((modelica_boolean**)data);
for (i = 0; i < cur_dim_size; ++i, --ptr) {
tmp.data.boolean = *ptr;
lst = (void *) mk_cons(type_desc_to_value(&tmp), lst);
}
*data = ptr;
}; break;
case TYPE_DESC_STRING: {
modelica_string_t *ptr = *data;
modelica_string_const *ptr = *((modelica_string_const**)data);
for (i = 0; i < cur_dim_size; ++i, --ptr) {
tmp.data.string = *ptr;
lst = (void *) mk_cons(type_desc_to_value(&tmp), lst);
Expand Down Expand Up @@ -169,7 +172,7 @@ char* path_to_name(void* path, char del)
}
}

buf = bufstart = malloc((length+1)*sizeof(char));
buf = bufstart = (char*) malloc((length+1)*sizeof(char));
if (buf == NULL) {
return "path_to_name: malloc failed";
}
Expand Down Expand Up @@ -237,7 +240,7 @@ static void *name_to_path(const char *name)
return Absyn__IDENT(ident);
} else {
size_t len = pos - name;
tmp = malloc(len + 1);
tmp = (char*) malloc(len + 1);
memcpy(tmp, name, len);
tmp[len] = '\0';
if (need_replace) {
Expand Down Expand Up @@ -303,13 +306,13 @@ int mmc_to_value(void* mmc, void** res)
if (numslots>0 && ctor > 1) { /* RECORD */
void *namelst = (void *) mk_nil();
void *varlst = (void *) mk_nil();
struct record_description* desc = RML_FETCH(RML_OFFSET(RML_UNTAGPTR(mmc),1));
struct record_description* desc = (struct record_description*) RML_FETCH(RML_OFFSET(RML_UNTAGPTR(mmc),1));
assert(desc != NULL);
for (i=numslots; i>1; i--) {
assert(0 == mmc_to_value(RML_FETCH(RML_OFFSET(RML_UNTAGPTR(mmc),i)),&t));
varlst = mk_cons(t, varlst);
t = (void*) desc->fieldNames[i-2];
namelst = mk_cons(mk_scon(t != NULL ? t : "(null)"), namelst);
namelst = mk_cons(mk_scon(t != NULL ? (const char*) t : "(null)"), namelst);
}
*res = (void *) Values__RECORD(name_to_path(desc->path),
varlst, namelst, mk_icon(ctor-3));
Expand Down Expand Up @@ -377,7 +380,7 @@ void *value_to_mmc(void* value)
int i=0;
void *tmp = names;
void **data_mmc;
struct record_description* desc = malloc(sizeof(struct record_description));
struct record_description* desc = (struct record_description*) malloc(sizeof(struct record_description));
if (desc == NULL) {
fprintf(stderr, "value_to_mmc: malloc failed\n");
return 0;
Expand All @@ -388,8 +391,8 @@ void *value_to_mmc(void* value)
/* duplicate string? will this give problems with GC? */
desc->path = path_to_name(path, '_');
desc->name = path_to_name(path, '.');
desc->fieldNames = malloc(i*sizeof(char*));
data_mmc = malloc((i+1)*sizeof(void*));
desc->fieldNames = (const char**) malloc(i*sizeof(char*));
data_mmc = (void**) malloc((i+1)*sizeof(void*));
i=0;
data_mmc[0] = desc;
while (!MMC_NILTEST(names)) {
Expand Down Expand Up @@ -426,7 +429,7 @@ void *value_to_mmc(void* value)
while (!MMC_NILTEST(tmp)) {
len++; tmp = RML_CDR(tmp);
}
data_mmc = malloc(len*sizeof(void*));
data_mmc = (void**) malloc(len*sizeof(void*));
len = 0;
tmp = data;
while (!MMC_NILTEST(tmp)) {
Expand Down Expand Up @@ -471,8 +474,7 @@ static int value_to_type_desc(void *value, type_description *desc)
void *data = RML_STRUCTDATA(value)[0];
int len = RML_HDRSTRLEN(RML_GETHDR(data));
desc->type = TYPE_DESC_STRING;
desc->data.string = alloc_modelica_string(len);
memcpy(desc->data.string, RML_STRINGDATA(data), len + 1);
desc->data.string = init_modelica_string(RML_STRINGDATA(data));
}; break;
case Values__ARRAY_3dBOX2: {
void *data = RML_STRUCTDATA(value)[0];
Expand Down Expand Up @@ -694,36 +696,35 @@ static int get_array_data(int curdim, int dims, const int *dim_size,

switch (type) {
case TYPE_DESC_REAL: {
modelica_real *ptr = *data;
modelica_real *ptr = *((modelica_real**)data);
if (RML_HDRCTOR(RML_GETHDR(item)) != Values__REAL_3dBOX1)
return -1;
*ptr = rml_prim_get_real(RML_STRUCTDATA(item)[0]);
*data = ++ptr;
}; break;
case TYPE_DESC_INT: {
modelica_integer *ptr = *data;
modelica_integer *ptr = *((modelica_integer**)data);
if (RML_HDRCTOR(RML_GETHDR(item)) != Values__INTEGER_3dBOX1)
return -1;
*ptr = RML_UNTAGFIXNUM(RML_STRUCTDATA(item)[0]);
*data = ++ptr;
}; break;
case TYPE_DESC_BOOL: {
modelica_boolean *ptr = *data;
modelica_boolean *ptr = *((modelica_boolean**)data);
if (RML_HDRCTOR(RML_GETHDR(item)) != Values__BOOL_3dBOX1)
return -1;
*ptr = (RML_STRUCTDATA(item)[0] == RML_TRUE);
*data = ++ptr;
}; break;
case TYPE_DESC_STRING: {
modelica_string_t *ptr = *data;
modelica_string_const *ptr = *((modelica_string_const**)data);
int len;
void *str;
if (RML_HDRCTOR(RML_GETHDR(item)) != Values__STRING_3dBOX1)
return -1;
str = RML_STRUCTDATA(item)[0];
len = RML_HDRSTRLEN(RML_GETHDR(str));
*ptr = alloc_modelica_string(len);
memcpy(*ptr, RML_STRINGDATA(str), len + 1);
*ptr = init_modelica_string(RML_STRINGDATA(str));
*data = ++ptr;
}; break;
default:
Expand Down Expand Up @@ -760,7 +761,7 @@ int parse_array(type_description *desc, void *arrdata, void *dimLst)
printf("dims: %d\n", dims);
return -1;
}
dim_size = malloc(sizeof(int) * dims);
dim_size = (int*) malloc(sizeof(int) * dims);
switch (desc->type) {
case TYPE_DESC_REAL_ARRAY:
desc->data.real_array.ndims = dims;
Expand Down Expand Up @@ -853,7 +854,12 @@ static int execute_function(void *in_arg, void **out_arg,
if (debugFlag) { fprintf(stderr, "calling the function\n"); fflush(stderr); }

/* call our function pointer! */
retval = execute_function_try_catch(func, arglst, &retarg);
try {
func(arglst, &retarg);
retval = 0;
} catch (...) {
retval = 1;
}
/* Flush all buffers for deterministic behaviour; in particular for the testsuite */
fflush(NULL);

Expand Down Expand Up @@ -887,3 +893,5 @@ static int execute_function(void *in_arg, void **out_arg,
return 0;
}
}

}
8 changes: 4 additions & 4 deletions Compiler/runtime/Makefile.common
Expand Up @@ -11,19 +11,19 @@ builddir_lib=$(top_builddir)/build/lib
builddir_inc=$(top_builddir)/build/include
builddir_doc=$(top_builddir)/build/doc

SRC = RTOpts_rml.c Print_rml.c System_rml.c Settings_rml.c dynload.c \
SRC = RTOpts_rml.c Print_rml.c System_rml.c Settings_rml.c \
SimulationResults.c IOStreamExt_rml.c rtclock.c Database.c Socket_rml.c

CPPSRC = unitparser.cpp UnitParserExt_rml.cpp ptolemyio.cpp \
BackendDAEEXT_rml.cpp ErrorMessage.cpp Error_rml.cpp optmanager.cpp \
systemimplmisc.cpp dynload_try.o $(CORBASRC)
systemimplmisc.cpp Dynload_rml.cpp $(CORBASRC)

OBJ = $(SRC:.c=.o) $(CPPSRC:.cpp=.o) $(CPPSRC:.cc=.o)

OMC_OBJ = Error_omc.o Print_omc.o RTOpts_omc.o System_omc.o Settings_omc.o \
IOStreamExt_omc.o ErrorMessage.o systemimplmisc.o rtclock.o \
UnitParserExt_omc.o unitparser.o BackendDAEEXT_omc.o Socket_omc.o \
corbaimpl_stub_omc.o
corbaimpl_stub_omc.o Dynload_omc.o

all: runtime.a install
.PHONY: all install
Expand All @@ -43,7 +43,7 @@ omc_communication.h: omc_communication_impl.cpp corbaimpl.cpp

omc_communication_impl.o: omc_communication.h
corbaimpl.o: omc_communication.h
dynload.o: systemimpl.h ../Absyn.h ../Values.h dynload_try.h
Dynload_rml.o: systemimpl.h errorext.h rtopts.h ../Absyn.h ../Values.h
Print_rml.o : printimpl.c
Print_omc.o : printimpl.c
Error_rml.o : errorext.cpp
Expand Down

0 comments on commit 363d69a

Please sign in to comment.