dlite-pyembed#
Shared code between plugins that embed Python.
Defines
-
PYFAILCODE(code, msg)#
-
PYFAILCODE1(code, msg, a1)#
-
PYFAILCODE2(code, msg, a1, a2)#
-
PYFAILCODE3(code, msg, a1, a2, a3)#
-
PYFAILCODE4(code, msg, a1, a2, a3, a4)#
Functions
-
void dlite_pyembed_initialise(void)#
Initialises the embedded Python environment.
-
int dlite_pyembed_finalise(void)#
Finalises the embedded Python environment.
-
const char *dlite_pyembed_classname(PyObject *cls)#
Returns a static pointer to the class name of python object cls or NULL on error.
-
DLiteErrCode dlite_pyembed_errcode(PyObject *type)#
Return DLite error code given Python exception type.
-
PyObject *dlite_pyembed_exception(DLiteErrCode code)#
Return Python exception class corresponding to given DLite error code. Returns NULL if
code
is zero.
-
int dlite_pyembed_errmsg(char *errmsg, size_t errlen)#
Writes Python error message to
errmsg
(of lengthlen
) if an Python error has occured.On return the The Python error indicator is reset.
Returns 0 if no error has occured, otherwise return the number of bytes written to
errmsg
. On error -1 is returned.
-
int dlite_pyembed_err(int eval, const char *msg, ...)#
Reports and restes Python error.
If an Python error has occured, an error message is appended to
msg
, containing the type, value and traceback.Returns
eval
.
-
int dlite_pyembed_verr(int eval, const char *msg, va_list ap)#
Like dlite_pyembed_err() but takes a
va_list
as input.
-
int dlite_pyembed_err_check(const char *msg, ...)#
Checks if an Python error has occured. Returns zero if no error has occured. Otherwise dlite_pyembed_err() is called and non-zero is returned.
-
int dlite_pyembed_verr_check(const char *msg, va_list ap)#
Like dlite_pyembed_err_check() but takes a
va_list
as input.
-
void *dlite_pyembed_get_address(const char *symbol)#
Loads the Python C extension module “_dlite” and returns the address of
symbol
, within this module. Returns NULL on error or ifsymbol
cannot be found.
-
PyObject *dlite_pyembed_from_instance(const char *id)#
Returns a Python representation of dlite instance with given id or NULL on error.
-
DLiteInstance *dlite_pyembed_get_instance(PyObject *pyinst)#
Returns a new reference to DLite instance from Python representation or NULL on error.
-
PyObject *dlite_pyembed_load_plugins(FUPaths *paths, PyObject *baseclass, char ***failed_paths, size_t *failed_len)#
This function loads all Python modules found in
paths
and returns a list of plugin objects.A Python plugin is a subclass of
baseclassname
that implements the expected functionality.If
failed_paths
is given, it should be a pointer to a NULL-terminated array of pointers to paths to plugins that failed to load. In case a plugin fails to load, this array will be updated.If
failed_paths
is given,failed_len
must also be given. It should be a pointer to the allocated length of*failed_paths
.Returns NULL on error.
-
PyObject *dlite_python_dlitedict(void)#
Return borrowed reference to the
__dict__
object in the dlite module or NULL on error.
-
PyObject *dlite_python_plugindict(const char *plugin_name)#
Return borrowed reference to a dict serving as a namespace for the given plugin.
The returned dict is accessable from Python as
dlite._plugindict[plugin_name]
. The dict will be created if it doesn’t already exists.Returns NULL on error.