summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-06 21:05:53 +0000
committerGerrit Code Review <review@openstack.org>2017-06-06 21:05:53 +0000
commit4e0f35a34d4aa10fd98ae8d3bbc9cecaf43601d4 (patch)
tree4a560734811092b3e6ba35461a2a55a35ec721bb
parent6768ad4403bcb533801ab5c31e170684bd66cfa7 (diff)
parent47493a0fc86ea0798a68cd644058fa345fa6861c (diff)
downloadpyeclib-4e0f35a34d4aa10fd98ae8d3bbc9cecaf43601d4.tar.gz
Merge "Change the version reference"
-rw-r--r--src/c/pyeclib_c/pyeclib_c.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/c/pyeclib_c/pyeclib_c.c b/src/c/pyeclib_c/pyeclib_c.c
index e3374bf..4e2646c 100644
--- a/src/c/pyeclib_c/pyeclib_c.c
+++ b/src/c/pyeclib_c/pyeclib_c.c
@@ -1186,7 +1186,32 @@ pyeclib_c_check_backend_available(PyObject *self, PyObject *args)
static PyObject*
pyeclib_c_liberasurecode_version(PyObject *self, PyObject *args) {
- return PyInt_FromLong(LIBERASURECODE_VERSION);
+ void *hLib;
+ char *err;
+ uint32_t (*hGetVersion)(void);
+
+ dlerror();
+ hLib = dlopen("liberasurecode.so", RTLD_LAZY);
+ /* It's important that we clear the last error before calling dysym */
+ err = dlerror();
+ if (err) {
+ /* This should never actually get hit; since we're using various
+ symbols already, liberasurecode.so should *already* be loaded. */
+ return PyInt_FromLong(LIBERASURECODE_VERSION);
+ }
+
+ hGetVersion = dlsym(hLib, "liberasurecode_get_version");
+ err = dlerror();
+ if (err) {
+ /* This is the important bit. Old version, doesn't have get_version
+ support; fall back to old behavior. */
+ dlclose(hLib);
+ return PyInt_FromLong(LIBERASURECODE_VERSION);
+ }
+
+ uint32_t version = (*hGetVersion)();
+ dlclose(hLib);
+ return Py_BuildValue("k", version);
}
static PyMethodDef PyECLibMethods[] = {