32 #include "structmember.h" 36 PyObject *modena_SurrogateFunction = NULL;
40 PyObject *pFunctionName =
41 PyObject_GetAttrString(self->pFunction,
"functionName");
42 if(!pFunctionName){ Modena_PyErr_Print(); }
44 PyObject *pLibraryName =
45 PyObject_GetAttrString(self->pFunction,
"libraryName");
46 if(!pLibraryName){ Modena_PyErr_Print(); }
48 self->handle = lt_dlopen(PyString_AsString(pLibraryName));
54 "lt_dlopen: Could not open library %s\nlt_dlopen: %s",
55 PyString_AsString(pLibraryName),
61 self->function = lt_dlsym(self->handle, PyString_AsString(pFunctionName));
66 "lt_dlsym: Could not find function %s in library %s" 68 PyString_AsString(pFunctionName),
69 PyString_AsString(pLibraryName),
72 lt_dlclose(self->handle);
76 Py_DECREF(pFunctionName);
77 Py_DECREF(pLibraryName);
80 PyObject_GetAttrString(self->pFunction,
"inputs");
81 if(!pInputs){ Modena_PyErr_Print(); }
82 self->inputs_size = PyObject_Size(pInputs);
86 PyObject_GetAttrString(self->pFunction,
"outputs");
87 if(!pOutputs){ Modena_PyErr_Print(); }
88 self->outputs_size = PyObject_Size(pOutputs);
91 PyObject *pParameters =
92 PyObject_GetAttrString(self->pFunction,
"parameters");
93 if(!pParameters){ Modena_PyErr_Print(); }
94 self->parameters_size = PyObject_Size(pParameters);
95 Py_DECREF(pParameters);
101 const char *functionId
107 if(!Py_IsInitialized())
115 PyObject *args = PyTuple_New(0);
116 PyObject *kw = Py_BuildValue(
"{s:s}",
"functionId", functionId);
118 PyObject *pNewObj = PyObject_Call
120 (PyObject *) &modena_function_tType,
129 if(PyErr_ExceptionMatches(modena_DoesNotExist))
133 PyObject *pRet = PyObject_CallMethod
135 modena_SurrogateFunction,
140 if(!pRet){ Modena_PyErr_Print(); }
141 int ret = PyInt_AsLong(pRet);
144 modena_error_code = ret;
149 Modena_PyErr_Print();
158 Modena_Error_Print(
"lt_dlinit: %s", lt_dlerror());
162 modena_function_load_library(
self);
178 Modena_Error_Print(
"lt_dlinit: %s", lt_dlerror());
183 PyObject_GetAttrString(m->
pModel,
"surrogateFunction");
184 if(!self->pFunction){ Modena_PyErr_Print(); }
186 modena_function_load_library(
self);
197 PyObject *pRet = PyObject_CallMethod
204 if(!pRet){ Modena_PyErr_Print(); }
206 PyObject *args = PyTuple_New(0);
207 PyObject *kw = Py_BuildValue(
"{s:O}",
"indexSet", pRet);
209 PyObject *pNewObj = PyObject_Call
211 (PyObject *) &modena_index_set_tType,
220 Modena_PyErr_Print();
230 lt_dlclose(self->handle);
232 Py_XDECREF(self->pFunction);
240 modena_function_destroy(
self);
258 static PyMemberDef modena_function_t_members[] = {
275 static PyMethodDef modena_function_t_methods[] = {
281 static int modena_function_t_init
288 PyObject *pFunction=NULL;
289 char *functionId=NULL;
291 static char *kwlist[] = {
"function",
"functionId", NULL};
295 !PyArg_ParseTupleAndKeywords
306 Modena_PyErr_Print();
311 self->pFunction = PyObject_CallMethod
313 modena_SurrogateFunction,
321 PyErr_SetString(modena_DoesNotExist,
"Function does not exist");
323 Modena_PyErr_Print();
328 Py_INCREF(pFunction);
329 self->pFunction = pFunction;
334 PyObject *pParameters =
335 PyObject_GetAttrString(self->pFunction,
"parameters");
336 if(!pParameters){ Modena_PyErr_Print(); }
337 self->parameters_size = PyObject_Size(pParameters);
338 Py_DECREF(pParameters);
345 static PyObject *modena_function_t_new
357 self->pFunction = NULL;
358 self->parameters_size = 0;
361 return (PyObject *)
self;
366 PyTypeObject modena_function_tType = {
367 PyObject_HEAD_INIT(NULL)
369 "modena.modena_function_t",
372 (destructor)modena_function_t_dealloc,
387 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
388 "modena_function_t objects",
395 modena_function_t_methods,
396 modena_function_t_members,
403 (initproc)modena_function_t_init,
405 modena_function_t_new,
PyObject_HEAD PyObject * pModel
struct modena_function_t modena_function_t
m
Bubble Growth Application Recipe.