# HG changeset patch # User Tassilo Philipp # Date 1586628025 -7200 # Node ID ba47a3d709d78672d641b157505e5e3768a29661 # Parent 2089026debae17b09c14024dde02ff72535f9911 - pydc: added support to get libhandle's path diff -r 2089026debae -r ba47a3d709d7 python/pydc/pydc.py --- a/python/pydc/pydc.py Sat Apr 11 18:02:33 2020 +0200 +++ b/python/pydc/pydc.py Sat Apr 11 20:00:25 2020 +0200 @@ -9,6 +9,9 @@ def free(libhandle): pydcext.free(libhandle) +def get_path(libhandle): + return pydcext.get_path(libhandle) + def call(funcptr,signature,*arguments): return pydcext.call(funcptr,signature,arguments) diff -r 2089026debae -r ba47a3d709d7 python/pydc/pydcext.c --- a/python/pydc/pydcext.c Sat Apr 11 18:02:33 2020 +0200 +++ b/python/pydc/pydcext.c Sat Apr 11 20:00:25 2020 +0200 @@ -133,6 +133,36 @@ Py_RETURN_NONE; } +/* get_path function */ + +static PyObject* +pydc_get_path(PyObject* self, PyObject* args) +{ + PyObject* pcobj; + PyObject* retobj; + void* libhandle; + char* path; + int path_bufSize; + + if (!PyArg_ParseTuple(args, "O", &pcobj)) + return PyErr_Format(PyExc_RuntimeError, "argument mismatch"); + + libhandle = (pcobj == Py_None)?NULL:DcPyCObject_AsVoidPtr(pcobj); + path_bufSize = dlGetLibraryPath(libhandle, NULL, 0); + if (!path_bufSize) + return PyErr_Format(PyExc_RuntimeError, "library path cannot be found"); + + path = malloc(path_bufSize); + if (path_bufSize != dlGetLibraryPath(libhandle, path, path_bufSize)) { + free(path); + return PyErr_Format(PyExc_RuntimeError, "library path cannot be queried"); + } + + retobj = Py_BuildValue("s", path); // !new ref! @@@ UTF-8 input... + free(path); + return retobj; +} + #include "dyncall.h" #include "dyncall_signature.h" @@ -401,10 +431,11 @@ PY_MOD_INIT_FUNC_NAME(void) { static PyMethodDef pydcMethods[] = { - {"load", pydc_load, METH_VARARGS, "load library"}, - {"find", pydc_find, METH_VARARGS, "find symbols"}, - {"free", pydc_free, METH_VARARGS, "free library"}, - {"call", pydc_call, METH_VARARGS, "call function"}, + {"load", pydc_load, METH_VARARGS, "load library" }, + {"find", pydc_find, METH_VARARGS, "find symbols" }, + {"free", pydc_free, METH_VARARGS, "free library" }, + {"get_path", pydc_get_path, METH_VARARGS, "get library path"}, + {"call", pydc_call, METH_VARARGS, "call function" }, {NULL,NULL,0,NULL} };