Mercurial > pub > dyncall > bindings
comparison python/pydc/pydcext.c @ 33:ba47a3d709d7
- pydc: added support to get libhandle's path
author | Tassilo Philipp |
---|---|
date | Sat, 11 Apr 2020 20:00:25 +0200 |
parents | 2089026debae |
children | 2682a627168c |
comparison
equal
deleted
inserted
replaced
32:2089026debae | 33:ba47a3d709d7 |
---|---|
129 | 129 |
130 //don't think I need to release it, as the pyobj is not equivalent to the held handle | 130 //don't think I need to release it, as the pyobj is not equivalent to the held handle |
131 //Py_XDECREF(pcobj); // release ref from pydc_load() | 131 //Py_XDECREF(pcobj); // release ref from pydc_load() |
132 | 132 |
133 Py_RETURN_NONE; | 133 Py_RETURN_NONE; |
134 } | |
135 | |
136 /* get_path function */ | |
137 | |
138 static PyObject* | |
139 pydc_get_path(PyObject* self, PyObject* args) | |
140 { | |
141 PyObject* pcobj; | |
142 PyObject* retobj; | |
143 void* libhandle; | |
144 char* path; | |
145 int path_bufSize; | |
146 | |
147 if (!PyArg_ParseTuple(args, "O", &pcobj)) | |
148 return PyErr_Format(PyExc_RuntimeError, "argument mismatch"); | |
149 | |
150 libhandle = (pcobj == Py_None)?NULL:DcPyCObject_AsVoidPtr(pcobj); | |
151 path_bufSize = dlGetLibraryPath(libhandle, NULL, 0); | |
152 if (!path_bufSize) | |
153 return PyErr_Format(PyExc_RuntimeError, "library path cannot be found"); | |
154 | |
155 path = malloc(path_bufSize); | |
156 if (path_bufSize != dlGetLibraryPath(libhandle, path, path_bufSize)) { | |
157 free(path); | |
158 return PyErr_Format(PyExc_RuntimeError, "library path cannot be queried"); | |
159 } | |
160 | |
161 retobj = Py_BuildValue("s", path); // !new ref! @@@ UTF-8 input... | |
162 free(path); | |
163 return retobj; | |
134 } | 164 } |
135 | 165 |
136 | 166 |
137 #include "dyncall.h" | 167 #include "dyncall.h" |
138 #include "dyncall_signature.h" | 168 #include "dyncall_signature.h" |
399 | 429 |
400 PyMODINIT_FUNC | 430 PyMODINIT_FUNC |
401 PY_MOD_INIT_FUNC_NAME(void) | 431 PY_MOD_INIT_FUNC_NAME(void) |
402 { | 432 { |
403 static PyMethodDef pydcMethods[] = { | 433 static PyMethodDef pydcMethods[] = { |
404 {"load", pydc_load, METH_VARARGS, "load library"}, | 434 {"load", pydc_load, METH_VARARGS, "load library" }, |
405 {"find", pydc_find, METH_VARARGS, "find symbols"}, | 435 {"find", pydc_find, METH_VARARGS, "find symbols" }, |
406 {"free", pydc_free, METH_VARARGS, "free library"}, | 436 {"free", pydc_free, METH_VARARGS, "free library" }, |
407 {"call", pydc_call, METH_VARARGS, "call function"}, | 437 {"get_path", pydc_get_path, METH_VARARGS, "get library path"}, |
438 {"call", pydc_call, METH_VARARGS, "call function" }, | |
408 {NULL,NULL,0,NULL} | 439 {NULL,NULL,0,NULL} |
409 }; | 440 }; |
410 | 441 |
411 PyObject* m; | 442 PyObject* m; |
412 #if PY_MAJOR_VERSION >= 3 | 443 #if PY_MAJOR_VERSION >= 3 |