From 0dd3047efbef69d898ee6c3e11cd0a637def73c3 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 19 Oct 2012 00:47:51 -0400 Subject: [PATCH] python: Add Module.versions attribute. --- libkmod/python/kmod/_libkmod_h.pxd | 11 +++++++++++ libkmod/python/kmod/module.pyx | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/libkmod/python/kmod/_libkmod_h.pxd b/libkmod/python/kmod/_libkmod_h.pxd index 457cfbc..ef948dd 100644 --- a/libkmod/python/kmod/_libkmod_h.pxd +++ b/libkmod/python/kmod/_libkmod_h.pxd @@ -9,14 +9,19 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +cimport libc.stdint as _stdint + + cdef extern from *: ctypedef char* const_char_ptr 'const char *' ctypedef char* const_char_const_ptr 'const char const *' ctypedef void* const_void_ptr 'const void *' + cdef extern from 'errno.h': enum: EEXIST + cdef extern from 'stdbool.h': ctypedef struct bool: pass @@ -94,3 +99,9 @@ cdef extern from 'libkmod.h': # returned by kernel int kmod_module_get_refcnt(const_kmod_module_ptr mod) long kmod_module_get_size(const_kmod_module_ptr mod) + + # Information retrieved from ELF headers and section + int kmod_module_get_versions(const_kmod_module_ptr mod, kmod_list **list) + const_char_ptr kmod_module_version_get_symbol(const_kmod_list_ptr entry) + _stdint.uint64_t kmod_module_version_get_crc(const_kmod_list_ptr entry) + void kmod_module_versions_free_list(kmod_list *list) diff --git a/libkmod/python/kmod/module.pyx b/libkmod/python/kmod/module.pyx index 3c1f023..379a75d 100644 --- a/libkmod/python/kmod/module.pyx +++ b/libkmod/python/kmod/module.pyx @@ -67,6 +67,24 @@ cdef class Module (object): return _libkmod_h.kmod_module_get_size(self.module) size = property(fget=_size_get) + def _versions_get(self): + cdef _list.ModList ml = _list.ModList() + cdef _list.ModListItem mli + err = _libkmod_h.kmod_module_get_versions(self.module, &ml.list) + if err < 0: + raise _KmodError('Could not get versions') + try: + for item in ml: + mli = <_list.ModListItem> item + symbol = _util.char_ptr_to_str( + _libkmod_h.kmod_module_version_get_symbol(mli.list)) + crc = _libkmod_h.kmod_module_version_get_crc(mli.list) + yield {'symbol': symbol, 'crc': crc} + finally: + _libkmod_h.kmod_module_versions_free_list(ml.list) + ml.list = NULL + versions = property(fget=_versions_get) + def insert(self, flags=0, extra_options=None, install_callback=None, data=None, print_action_callback=None): cdef char *opt = NULL -- 2.7.4