diff options
author | Kota Tsuyuzaki <tsuyuzaki.kota@lab.ntt.co.jp> | 2016-12-01 21:47:51 -0800 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2017-03-01 20:43:17 +0000 |
commit | 47493a0fc86ea0798a68cd644058fa345fa6861c (patch) | |
tree | e6b4909ee512c6ee0b7928fc3fe57a89ef295008 | |
parent | cc6f4bba26ee2a1e2dc18e17131ff5b5fbe7d6d9 (diff) | |
download | pyeclib-47493a0fc86ea0798a68cd644058fa345fa6861c.tar.gz |
Change the version reference
Now, if liberasurecode.so exposes a liberasurecode_get_version function,
we'll use that; otherwise, we'll fall back to reporting the version that
PyECLib was built against.
Note that if your liberasurecode.so doesn't support
the liberasurecode_get_verion function, pyeclib will the version at built
as well as older behavior.
Co-Authored-By: Tim Burke <tim.burke@gmail.com>
Change-Id: I54823183cce6775a83e913baf6bb1eeb94aabc13
-rw-r--r-- | src/c/pyeclib_c/pyeclib_c.c | 27 |
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 8e1a23c..5ba5770 100644 --- a/src/c/pyeclib_c/pyeclib_c.c +++ b/src/c/pyeclib_c/pyeclib_c.c @@ -1213,7 +1213,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[] = { |